File tree Expand file tree Collapse file tree 30 files changed +139
-101
lines changed Expand file tree Collapse file tree 30 files changed +139
-101
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ class Audit extends ArboristWorkspaceCmd {
58
58
audit : true ,
59
59
path : this . npm . prefix ,
60
60
reporter,
61
- workspaces : this . workspaces ,
61
+ workspaces : this . workspaceNames ,
62
62
}
63
63
64
64
const arb = new Arborist ( opts )
Original file line number Diff line number Diff line change 1
1
// Base class for npm.commands[cmd]
2
2
const usageUtil = require ( './utils/usage.js' )
3
3
const ConfigDefinitions = require ( './utils/config/definitions.js' )
4
+ const getWorkspaces = require ( './workspaces/get-workspaces.js' )
4
5
5
6
class BaseCommand {
6
7
constructor ( npm ) {
@@ -72,5 +73,13 @@ class BaseCommand {
72
73
{ code : 'ENOWORKSPACES' }
73
74
)
74
75
}
76
+
77
+ async setWorkspaces ( filters ) {
78
+ // TODO npm guards workspaces/global mode so we should use this.npm.prefix?
79
+ const ws = await getWorkspaces ( filters , { path : this . npm . localPrefix } )
80
+ this . workspaces = ws
81
+ this . workspaceNames = [ ...ws . keys ( ) ]
82
+ this . workspacePaths = [ ...ws . values ( ) ]
83
+ }
75
84
}
76
85
module . exports = BaseCommand
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ class CI extends ArboristWorkspaceCmd {
55
55
path : where ,
56
56
log : this . npm . log ,
57
57
save : false , // npm ci should never modify the lockfile or package.json
58
- workspaces : this . workspaces ,
58
+ workspaces : this . workspaceNames ,
59
59
}
60
60
61
61
const arb = new Arborist ( opts )
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ class Dedupe extends ArboristWorkspaceCmd {
50
50
log : this . npm . log ,
51
51
path : where ,
52
52
dryRun,
53
- workspaces : this . workspaces ,
53
+ workspaces : this . workspaceNames ,
54
54
}
55
55
const arb = new Arborist ( opts )
56
56
await arb . dedupe ( opts )
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ const npmlog = require('npmlog')
8
8
const pacote = require ( 'pacote' )
9
9
const pickManifest = require ( 'npm-pick-manifest' )
10
10
11
- const getWorkspaces = require ( './workspaces/get-workspaces.js' )
12
11
const readPackageName = require ( './utils/read-package-name.js' )
13
12
const BaseCommand = require ( './base-command.js' )
14
13
@@ -90,9 +89,8 @@ class Diff extends BaseCommand {
90
89
}
91
90
92
91
async diffWorkspaces ( args , filters ) {
93
- const workspaces =
94
- await getWorkspaces ( filters , { path : this . npm . localPrefix } )
95
- for ( const workspacePath of workspaces . values ( ) ) {
92
+ await this . setWorkspaces ( filters )
93
+ for ( const workspacePath of this . workspacePaths ) {
96
94
this . top = workspacePath
97
95
this . prefix = workspacePath
98
96
await this . diff ( args )
@@ -104,7 +102,6 @@ class Diff extends BaseCommand {
104
102
async packageName ( path ) {
105
103
let name
106
104
try {
107
- // TODO this won't work as expected in global mode
108
105
name = await readPackageName ( this . prefix )
109
106
} catch ( e ) {
110
107
npmlog . verbose ( 'diff' , 'could not read project dir package.json' )
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ const semver = require('semver')
5
5
6
6
const otplease = require ( './utils/otplease.js' )
7
7
const readPackageName = require ( './utils/read-package-name.js' )
8
- const getWorkspaces = require ( './workspaces/get-workspaces.js' )
9
8
const BaseCommand = require ( './base-command.js' )
10
9
11
10
class DistTag extends BaseCommand {
@@ -180,10 +179,9 @@ class DistTag extends BaseCommand {
180
179
}
181
180
182
181
async listWorkspaces ( filters ) {
183
- const workspaces =
184
- await getWorkspaces ( filters , { path : this . npm . localPrefix } )
182
+ await this . setWorkspaces ( filters )
185
183
186
- for ( const [ name ] of workspaces ) {
184
+ for ( const name of this . workspaceNames ) {
187
185
try {
188
186
this . npm . output ( `${ name } :` )
189
187
await this . list ( npa ( name ) , this . npm . flatOptions )
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ const log = require('npmlog')
2
2
const pacote = require ( 'pacote' )
3
3
const openUrl = require ( './utils/open-url.js' )
4
4
const hostedFromMani = require ( './utils/hosted-git-info-from-manifest.js' )
5
- const getWorkspaces = require ( './workspaces/get-workspaces.js' )
6
5
7
6
const BaseCommand = require ( './base-command.js' )
8
7
class Docs extends BaseCommand {
@@ -42,9 +41,8 @@ class Docs extends BaseCommand {
42
41
}
43
42
44
43
async docsWorkspaces ( args , filters ) {
45
- const workspaces =
46
- await getWorkspaces ( filters , { path : this . npm . localPrefix } )
47
- return this . docs ( [ ...workspaces . values ( ) ] )
44
+ await this . setWorkspaces ( filters )
45
+ return this . docs ( this . workspacePaths )
48
46
}
49
47
50
48
async getDocs ( pkg ) {
Original file line number Diff line number Diff line change 1
1
const libexec = require ( 'libnpmexec' )
2
2
const BaseCommand = require ( './base-command.js' )
3
3
const getLocationMsg = require ( './exec/get-workspace-location-msg.js' )
4
- const getWorkspaces = require ( './workspaces/get-workspaces.js' )
5
4
6
5
// it's like this:
7
6
//
@@ -105,16 +104,15 @@ class Exec extends BaseCommand {
105
104
}
106
105
107
106
async _execWorkspaces ( args , filters ) {
108
- const workspaces =
109
- await getWorkspaces ( filters , { path : this . npm . localPrefix } )
107
+ await this . setWorkspaces ( filters )
110
108
const color = this . npm . config . get ( 'color' )
111
109
112
- for ( const workspacePath of workspaces . values ( ) ) {
113
- const locationMsg = await getLocationMsg ( { color, path : workspacePath } )
110
+ for ( const path of this . workspacePaths ) {
111
+ const locationMsg = await getLocationMsg ( { color, path } )
114
112
await this . _exec ( args , {
115
113
locationMsg,
116
- path : workspacePath ,
117
- runPath : workspacePath ,
114
+ path,
115
+ runPath : path ,
118
116
} )
119
117
}
120
118
}
Original file line number Diff line number Diff line change @@ -46,8 +46,8 @@ class Explain extends ArboristWorkspaceCmd {
46
46
const arb = new Arborist ( { path : this . npm . prefix , ...this . npm . flatOptions } )
47
47
const tree = await arb . loadActual ( )
48
48
49
- if ( this . workspaces && this . workspaces . length )
50
- this . filterSet = arb . workspaceDependencySet ( tree , this . workspaces )
49
+ if ( this . workspaceNames && this . workspaceNames . length )
50
+ this . filterSet = arb . workspaceDependencySet ( tree , this . workspaceNames )
51
51
52
52
const nodes = new Set ( )
53
53
for ( const arg of args ) {
Original file line number Diff line number Diff line change @@ -95,7 +95,7 @@ class Fund extends ArboristWorkspaceCmd {
95
95
const fundingInfo = getFundingInfo ( tree , {
96
96
...this . flatOptions ,
97
97
log : this . npm . log ,
98
- workspaces : this . workspaces ,
98
+ workspaces : this . workspaceNames ,
99
99
} )
100
100
101
101
if ( this . npm . config . get ( 'json' ) )
You can’t perform that action at this time.
0 commit comments