allow for rebuilding by path · npm/cli@a9c4b15 (original) (raw)

Original file line number Diff line number Diff line change
@@ -174,8 +174,48 @@ t.test('filter by pkg@', t => {
174 174 })
175 175 })
176 176
177 -t.test('filter must be a semver version/range', t => {
178 -rebuild(['b:git+ssh://github.com/npm/arborist'], err => {
177 +t.test('filter by directory', t => {
178 +const path = t.testdir({
179 +node_modules: {
180 +a: {
181 +'index.js': '',
182 +'package.json': JSON.stringify({
183 +name: 'a',
184 +version: '1.0.0',
185 +bin: 'index.js',
186 +}),
187 +},
188 +b: {
189 +'index.js': '',
190 +'package.json': JSON.stringify({
191 +name: 'b',
192 +version: '1.0.0',
193 +bin: 'index.js',
194 +}),
195 +},
196 +},
197 +})
198 +
199 +npm.prefix = path
200 +
201 +const aBinFile = resolve(path, 'node_modules/.bin/a')
202 +const bBinFile = resolve(path, 'node_modules/.bin/b')
203 +t.throws(() => fs.statSync(aBinFile))
204 +t.throws(() => fs.statSync(bBinFile))
205 +
206 +rebuild(['file:node_modules/b'], err => {
207 +if (err)
208 +throw err
209 +
210 +t.throws(() => fs.statSync(aBinFile), 'should not link a bin')
211 +t.ok(() => fs.statSync(bBinFile), 'should link filtered pkg bin')
212 +
213 +t.end()
214 +})
215 +})
216 +
217 +t.test('filter must be a semver version/range, or directory', t => {
218 +rebuild(['git+ssh://github.com/npm/arborist'], err => {
179 219 t.match(
180 220 err,
181 221 /Error: `npm rebuild` only supports SemVer version\/range specifiers/,