-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspaces support to `npm fund` - Add lib/workspaces/arborist-cmd.js base class - Add ability to filter fund results to a specific set of workspaces - Added tests and docs Fixes: npm/statusboard#301 PR-URL: #3241 Credit: @ruyadorno Close: #3241 Reviewed-by: @isaacs
- Loading branch information
Showing
7 changed files
with
307 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This is the base for all commands whose execWorkspaces just gets | ||
// a list of workspace names and passes it on to new Arborist() to | ||
// be able to run a filtered Arborist.reify() at some point. | ||
|
||
const BaseCommand = require('../base-command.js') | ||
const getWorkspaces = require('../workspaces/get-workspaces.js') | ||
class ArboristCmd extends BaseCommand { | ||
/* istanbul ignore next - see test/lib/load-all-commands.js */ | ||
static get params () { | ||
return [ | ||
'workspace', | ||
] | ||
} | ||
|
||
execWorkspaces (args, filters, cb) { | ||
getWorkspaces(filters, { path: this.npm.localPrefix }) | ||
.then(workspaces => { | ||
this.workspaces = [...workspaces.keys()] | ||
this.exec(args, cb) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = ArboristCmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
const { resolve } = require('path') | ||
const t = require('tap') | ||
const ArboristCmd = require('../../../lib/workspaces/arborist-cmd.js') | ||
|
||
t.test('arborist-cmd', async t => { | ||
const path = t.testdir({ | ||
'package.json': JSON.stringify({ | ||
name: 'simple-workspaces-list', | ||
version: '1.1.1', | ||
workspaces: [ | ||
'a', | ||
'b', | ||
'group/*', | ||
], | ||
}), | ||
node_modules: { | ||
abbrev: { | ||
'package.json': JSON.stringify({ name: 'abbrev', version: '1.1.1' }), | ||
}, | ||
a: t.fixture('symlink', '../a'), | ||
b: t.fixture('symlink', '../b'), | ||
}, | ||
a: { | ||
'package.json': JSON.stringify({ name: 'a', version: '1.0.0' }), | ||
}, | ||
b: { | ||
'package.json': JSON.stringify({ name: 'b', version: '1.0.0' }), | ||
}, | ||
group: { | ||
c: { | ||
'package.json': JSON.stringify({ | ||
name: 'c', | ||
version: '1.0.0', | ||
dependencies: { | ||
abbrev: '^1.1.1', | ||
}, | ||
}), | ||
}, | ||
d: { | ||
'package.json': JSON.stringify({ name: 'd', version: '1.0.0' }), | ||
}, | ||
}, | ||
}) | ||
|
||
class TestCmd extends ArboristCmd {} | ||
|
||
const cmd = new TestCmd() | ||
cmd.npm = { localPrefix: path } | ||
|
||
// check filtering for a single workspace name | ||
cmd.exec = function (args, cb) { | ||
t.same(this.workspaces, ['a'], 'should set array with single ws name') | ||
t.same(args, ['foo'], 'should get received args') | ||
cb() | ||
} | ||
await new Promise(res => { | ||
cmd.execWorkspaces(['foo'], ['a'], res) | ||
}) | ||
|
||
// check filtering single workspace by path | ||
cmd.exec = function (args, cb) { | ||
t.same(this.workspaces, ['a'], | ||
'should set array with single ws name from path') | ||
cb() | ||
} | ||
await new Promise(res => { | ||
cmd.execWorkspaces([], ['./a'], res) | ||
}) | ||
|
||
// check filtering single workspace by full path | ||
cmd.exec = function (args, cb) { | ||
t.same(this.workspaces, ['a'], | ||
'should set array with single ws name from full path') | ||
cb() | ||
} | ||
await new Promise(res => { | ||
cmd.execWorkspaces([], [resolve(path, './a')], res) | ||
}) | ||
|
||
// filtering multiple workspaces by name | ||
cmd.exec = function (args, cb) { | ||
t.same(this.workspaces, ['a', 'c'], | ||
'should set array with multiple listed ws names') | ||
cb() | ||
} | ||
await new Promise(res => { | ||
cmd.execWorkspaces([], ['a', 'c'], res) | ||
}) | ||
|
||
// filtering multiple workspaces by path names | ||
cmd.exec = function (args, cb) { | ||
t.same(this.workspaces, ['a', 'c'], | ||
'should set array with multiple ws names from paths') | ||
cb() | ||
} | ||
await new Promise(res => { | ||
cmd.execWorkspaces([], ['./a', 'group/c'], res) | ||
}) | ||
|
||
// filtering multiple workspaces by parent path name | ||
cmd.exec = function (args, cb) { | ||
t.same(this.workspaces, ['c', 'd'], | ||
'should set array with multiple ws names from a parent folder name') | ||
cb() | ||
} | ||
await new Promise(res => { | ||
cmd.execWorkspaces([], ['./group'], res) | ||
}) | ||
}) |