Closed vobarian closed 7 years ago
Thanks for the patch! As you said the patch including the scope name should be resolved by the path module. Will do test on my local and ship it.
This patch was released as how-to-npm@2.4.3
🎉
Thanks again for putting this together.
The JSON sent by
npm publish
contains the propertyversions.XXX.dist.tarball
which contains the scope name twice for a scoped package; for example:"http://localhost:15443/@chad/myhowtonpm/-/@chad/myhowtonpm-1.0.0.tgz"
. The mock registry server attempts to remove the second occurrence of@scope
from the file path, which causes an error if users try to create another package into which they install the package created in the workshopper using the mock server. The path should be left as-is to match the tarball property inbody.json
so npm can GET it. Removing this code has the additional benefit of fixing a bug on Windows because the regex does not consider backslashes in the path.Fixes: https://github.com/workshopper/how-to-npm/issues/122 Fixes: https://github.com/nodeschool/discussions/issues/1561 Fixes: https://github.com/nodeschool/discussions/issues/2049
Please note this would supersede PR https://github.com/workshopper/how-to-npm/pull/68
Additional Explanation
Given a package
@chad/myhowtonpm
, runningnpm publish
with npm 5.0.3 will PUT JSON something like this:Note that the
tarball
property contains two subdirectories following the pattern@scope
. In order for a user to be able tonpm install
the package the file has to be found at this location. Hence the current code which attempts to strip the second occurrence of@scope
is not correct; in fact I have verified that attempting to install the package into a second package causes an error because of this.With the new code, the variables trace out as follows:
The path
tgzFile
matches thetarball
property and the correct directory is created in themkdirp
call. It is possible to install the package created in the workshopper into a second package later on (assuming the user copies.npmrc
to use the mock server). Also, since the regex is no longer needed, the bug that breaks publishing on Windows is simply gone.