Skip to content

Commit 6960649

Browse files
committed
registry path for scoped package tarball should include scope subdirectory under dash directory
The JSON sent by `npm publish` contains the property `versions.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 in `body.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. See: #68 Fixes: #122 Fixes: nodeschool/discussions#1561 Fixes: nodeschool/discussions#2049
1 parent 45a4f99 commit 6960649

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/registry.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ function receivePublishPut (req, res) {
195195
att = att && att.data
196196
var dir = path.resolve(assetdir, data._id)
197197
var jsonFile = path.resolve(dir, 'body.json')
198-
var tgzDir = path.resolve(dir, '-')
199-
var tgzFile = path.resolve(tgzDir, tgzBase)
198+
var tgzFile = path.resolve(dir, '-', tgzBase)
200199

201200
if (!att) {
202201
return _403(req, res, {
@@ -216,7 +215,7 @@ function receivePublishPut (req, res) {
216215
existing = {}
217216
}
218217

219-
mkdirp.sync(tgzDir)
218+
mkdirp.sync(path.dirname(tgzFile))
220219

221220
if (existing && existing.time && existing.time[ver]) {
222221
return _403(req, res, {
@@ -243,7 +242,7 @@ function receivePublishPut (req, res) {
243242
existing.time.modified = now
244243

245244
try {
246-
fs.writeFileSync(tgzFile.replace(/(-\/)@.*?\//, '$1'), att, { encoding: 'base64' })
245+
fs.writeFileSync(tgzFile, att, { encoding: 'base64' })
247246
} catch (er) {
248247
return _500(req, res, er)
249248
}

0 commit comments

Comments
 (0)