Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornlf <quitlahok@gmail.com>2020-12-14 18:35:18 +0300
committernlf <quitlahok@gmail.com>2020-12-15 22:15:48 +0300
commita9c4b158c46dd0d0c8d8744a97750ffd0c30cc09 (patch)
tree301aeb7d9c64389ec071d7aabe7337535d731543
parentd45e181d17dd88d82b3a97f8d9cd5fa5b6230e48 (diff)
allow for rebuilding by path
PR-URL: https://github.com/npm/cli/pull/2342 Credit: @nlf Close: #2342 Reviewed-by: @ruyadorno
-rw-r--r--lib/rebuild.js13
-rw-r--r--test/lib/rebuild.js44
2 files changed, 53 insertions, 4 deletions
diff --git a/lib/rebuild.js b/lib/rebuild.js
index e02c89bd7..ab34b7f3d 100644
--- a/lib/rebuild.js
+++ b/lib/rebuild.js
@@ -39,16 +39,25 @@ const getFilterFn = args => {
const spec = npa(arg)
if (spec.type === 'tag' && spec.rawSpec === '')
return spec
- if (spec.type !== 'range' && spec.type !== 'version')
+
+ if (spec.type !== 'range' && spec.type !== 'version' && spec.type !== 'directory')
throw new Error('`npm rebuild` only supports SemVer version/range specifiers')
+
return spec
})
+
return node => specs.some(spec => {
- const { version } = node.package
+ if (spec.type === 'directory')
+ return node.path === spec.fetchSpec
+
if (spec.name !== node.name)
return false
+
if (spec.rawSpec === '' || spec.rawSpec === '*')
return true
+
+ const { version } = node.package
+ // TODO: add tests for a package with missing version
return semver.satisfies(version, spec.fetchSpec)
})
}
diff --git a/test/lib/rebuild.js b/test/lib/rebuild.js
index dbc37d57a..d9df048d9 100644
--- a/test/lib/rebuild.js
+++ b/test/lib/rebuild.js
@@ -174,8 +174,48 @@ t.test('filter by pkg@<range>', t => {
})
})
-t.test('filter must be a semver version/range', t => {
- rebuild(['b:git+ssh://github.com/npm/arborist'], err => {
+t.test('filter by directory', t => {
+ const path = t.testdir({
+ node_modules: {
+ a: {
+ 'index.js': '',
+ 'package.json': JSON.stringify({
+ name: 'a',
+ version: '1.0.0',
+ bin: 'index.js',
+ }),
+ },
+ b: {
+ 'index.js': '',
+ 'package.json': JSON.stringify({
+ name: 'b',
+ version: '1.0.0',
+ bin: 'index.js',
+ }),
+ },
+ },
+ })
+
+ npm.prefix = path
+
+ const aBinFile = resolve(path, 'node_modules/.bin/a')
+ const bBinFile = resolve(path, 'node_modules/.bin/b')
+ t.throws(() => fs.statSync(aBinFile))
+ t.throws(() => fs.statSync(bBinFile))
+
+ rebuild(['file:node_modules/b'], err => {
+ if (err)
+ throw err
+
+ t.throws(() => fs.statSync(aBinFile), 'should not link a bin')
+ t.ok(() => fs.statSync(bBinFile), 'should link filtered pkg bin')
+
+ t.end()
+ })
+})
+
+t.test('filter must be a semver version/range, or directory', t => {
+ rebuild(['git+ssh://github.com/npm/arborist'], err => {
t.match(
err,
/Error: `npm rebuild` only supports SemVer version\/range specifiers/,