Skip to content

Commit 6d82835

Browse files
committed
feat: add --install-strategy config, replace --global-style with
"shallow" style BREAKING CHANGE: remove --global-style, --global now sets --install-strategy=shallow
1 parent 32336f6 commit 6d82835

File tree

13 files changed

+48
-38
lines changed

13 files changed

+48
-38
lines changed

lib/commands/dedupe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Dedupe extends ArboristWorkspaceCmd {
88
static description = 'Reduce duplication in the package tree'
99
static name = 'dedupe'
1010
static params = [
11-
'global-style',
11+
'install-strategy',
1212
'legacy-bundling',
1313
'strict-peer-deps',
1414
'package-lock',

lib/commands/find-dupes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class FindDupes extends ArboristWorkspaceCmd {
55
static description = 'Find duplication in the package tree'
66
static name = 'find-dupes'
77
static params = [
8-
'global-style',
8+
'install-strategy',
99
'legacy-bundling',
1010
'strict-peer-deps',
1111
'package-lock',

lib/commands/install.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Install extends ArboristWorkspaceCmd {
2020
'save',
2121
'save-exact',
2222
'global',
23-
'global-style',
23+
'install-strategy',
2424
'legacy-bundling',
2525
'omit',
2626
'strict-peer-deps',

lib/commands/link.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Link extends ArboristWorkspaceCmd {
2222
'save',
2323
'save-exact',
2424
'global',
25-
'global-style',
25+
'install-strategy',
2626
'legacy-bundling',
2727
'strict-peer-deps',
2828
'package-lock',

lib/commands/update.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Update extends ArboristWorkspaceCmd {
1414
static params = [
1515
'save',
1616
'global',
17-
'global-style',
17+
'install-strategy',
1818
'legacy-bundling',
1919
'omit',
2020
'strict-peer-deps',

lib/utils/config/definitions.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -823,20 +823,6 @@ define('global', {
823823
},
824824
})
825825

826-
define('global-style', {
827-
default: false,
828-
type: Boolean,
829-
description: `
830-
Causes npm to install the package into your local \`node_modules\` folder
831-
with the same layout it uses with the global \`node_modules\` folder.
832-
Only your direct dependencies will show in \`node_modules\` and
833-
everything they depend on will be flattened in their \`node_modules\`
834-
folders. This obviously will eliminate some deduping. If used with
835-
\`legacy-bundling\`, \`legacy-bundling\` will be preferred.
836-
`,
837-
flatten,
838-
})
839-
840826
// the globalconfig has its default defined outside of this module
841827
define('globalconfig', {
842828
type: path,
@@ -1076,6 +1062,21 @@ define('install-links', {
10761062
flatten,
10771063
})
10781064

1065+
define('install-strategy', {
1066+
default: 'hoisted',
1067+
type: ['hoisted', 'nested', 'shallow'],
1068+
description: `
1069+
Sets the strategy for installing packages in node_modules.
1070+
hoisted (default): Install non-duplicated in top-level, and duplicated as
1071+
necessary within directory structure.
1072+
nested: (formerly --legacy-bundling) install in place, no hoisting.
1073+
shallow (formerly --global-style) only install direct deps at top-level.
1074+
linked: (coming soon) install in node_modules/.store, link in place,
1075+
unhoisted.
1076+
`,
1077+
flatten,
1078+
})
1079+
10791080
define('json', {
10801081
default: false,
10811082
type: Boolean,
@@ -1523,8 +1524,8 @@ define('prefix', {
15231524
short: 'C',
15241525
default: '',
15251526
defaultDescription: `
1526-
In global mode, the folder where the node executable is installed. In
1527-
local mode, the nearest parent folder containing either a package.json
1527+
In global mode, the folder where the node executable is installed.
1528+
Otherwise, the nearest parent folder containing either a package.json
15281529
file or a node_modules folder.
15291530
`,
15301531
description: `

workspaces/arborist/lib/arborist/build-ideal-tree.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const _loadFailures = Symbol('loadFailures')
7979
const _pruneFailedOptional = Symbol('pruneFailedOptional')
8080
const _linkNodes = Symbol('linkNodes')
8181
const _follow = Symbol('follow')
82-
const _globalStyle = Symbol('globalStyle')
82+
const _installStrategy = Symbol('installStrategy')
8383
const _globalRootNode = Symbol('globalRootNode')
8484
const _usePackageLock = Symbol.for('usePackageLock')
8585
const _rpcache = Symbol.for('realpathCache')
@@ -114,7 +114,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
114114
follow = false,
115115
force = false,
116116
global = false,
117-
globalStyle = false,
117+
installStrategy = 'hoisted',
118118
idealTree = null,
119119
includeWorkspaceRoot = false,
120120
installLinks = false,
@@ -134,7 +134,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
134134

135135
this[_usePackageLock] = packageLock
136136
this[_global] = !!global
137-
this[_globalStyle] = this[_global] || globalStyle
137+
this[_installStrategy] = global ? 'shallow' : installStrategy
138138
this[_follow] = !!follow
139139

140140
if (this[_workspaces].length && this[_global]) {
@@ -956,7 +956,7 @@ This is a one-time fix-up, please be patient...
956956
strictPeerDeps: this[_strictPeerDeps],
957957
installLinks: this.installLinks,
958958
legacyPeerDeps: this.legacyPeerDeps,
959-
globalStyle: this[_globalStyle],
959+
installStrategy: this[_installStrategy],
960960
}))
961961

962962
const promises = []

workspaces/arborist/lib/arborist/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Arborist extends Base {
7676
workspacesEnabled: options.workspacesEnabled !== false,
7777
replaceRegistryHost: options.replaceRegistryHost,
7878
lockfileVersion: lockfileVersion(options.lockfileVersion),
79+
installStrategy: options.global ? 'shallow' : (options.installStrategy ? options.installStrategy : 'hoisted'),
7980
}
8081
this.replaceRegistryHost = this.options.replaceRegistryHost =
8182
(!this.options.replaceRegistryHost || this.options.replaceRegistryHost === 'npmjs') ?

workspaces/arborist/lib/place-dep.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class PlaceDep {
4747
strictPeerDeps,
4848
installLinks,
4949
legacyPeerDeps,
50-
globalStyle,
50+
installStrategy,
5151
} = parent || options
5252
Object.assign(this, {
5353
preferDedupe,
@@ -58,8 +58,8 @@ class PlaceDep {
5858
legacyBundling,
5959
strictPeerDeps,
6060
installLinks,
61+
installStrategy,
6162
legacyPeerDeps,
62-
globalStyle,
6363
})
6464

6565
this.children = []
@@ -78,10 +78,10 @@ class PlaceDep {
7878
edge,
7979
dep,
8080
preferDedupe,
81-
globalStyle,
8281
legacyBundling,
8382
explicitRequest,
8483
updateNames,
84+
installStrategy,
8585
checks,
8686
} = this
8787

@@ -176,7 +176,7 @@ class PlaceDep {
176176

177177
// when installing globally, or just in global style, we never place
178178
// deps above the first level.
179-
if (globalStyle) {
179+
if (installStrategy === 'shallow') {
180180
const rp = target.resolveParent
181181
if (rp && rp.isProjectRoot) {
182182
break

workspaces/arborist/test/arborist/build-ideal-tree.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ t.test('link dep within node_modules and outside root', t => {
607607
})
608608

609609
t.test('global style', t => t.resolveMatchSnapshot(printIdeal(t.testdir(), {
610-
globalStyle: true,
610+
installStrategy: 'shallow',
611611
add: ['rimraf'],
612612
})))
613613

@@ -1136,7 +1136,7 @@ t.test('resolve links in global mode', async t => {
11361136

11371137
t.test('dont get confused if root matches duped metadep', async t => {
11381138
const path = resolve(fixtures, 'test-root-matches-metadep')
1139-
const arb = new Arborist({ path, ...OPT })
1139+
const arb = new Arborist({ path, installStrategy: 'hoisted', ...OPT })
11401140
const tree = await arb.buildIdealTree()
11411141
t.matchSnapshot(printTree(tree))
11421142
})
@@ -2154,7 +2154,7 @@ t.test('properly assign fsParent when paths have .. in them', async t => {
21542154
}
21552155
})
21562156

2157-
t.test('update global', async t => {
2157+
t.only('update global', async t => {
21582158
// global root
21592159
// ├─┬ @isaacs/testing-dev-optional-flags@1.0.0
21602160
// │ ├── own-or@1.0.0

workspaces/arborist/test/arborist/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ t.test('excludeSet includes nonworkspace metadeps', async t => {
213213
spec: 'file:pkgs/b',
214214
})
215215

216-
const arb = new Arborist()
216+
const arb = new Arborist({})
217217
const filter = arb.excludeWorkspacesDependencySet(tree)
218218

219219
t.equal(filter.size, 3)
@@ -245,3 +245,11 @@ t.test('valid replaceRegistryHost values', t => {
245245
t.equal(new Arborist({ replaceRegistryHost: 'never' }).options.replaceRegistryHost, 'never')
246246
t.end()
247247
})
248+
249+
t.test('valid global/installStrategy values', t => {
250+
t.equal(new Arborist({ global: true }).options.installStrategy, 'shallow')
251+
t.equal(new Arborist({ global: false }).options.installStrategy, 'hoisted')
252+
t.equal(new Arborist({}).options.installStrategy, 'hoisted')
253+
t.equal(new Arborist({ installStrategy: 'hoisted' }).options.installStrategy, 'hoisted')
254+
t.end()
255+
})

workspaces/arborist/test/arborist/reify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ t.test('global style', t => {
11161116
const rbinPart = '.bin/rimraf' +
11171117
(process.platform === 'win32' ? '.cmd' : '')
11181118
const rbin = resolve(nm, rbinPart)
1119-
return reify(path, { add: ['rimraf@2'], globalStyle: true })
1119+
return reify(path, { add: ['rimraf@2'], installStrategy: 'shallow' })
11201120
.then(() => fs.statSync(rbin))
11211121
.then(() => t.strictSame(fs.readdirSync(nm).sort(), ['.bin', '.package-lock.json', 'rimraf']))
11221122
})

workspaces/arborist/test/place-dep.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ t.test('placement tests', t => {
4646
// --legacy-peer-deps set?
4747
legacyPeerDeps = false,
4848
// installing with --global or --global-style?
49-
globalStyle = false,
49+
installStrategy = 'hoisted',
5050
} = options
5151

5252
const node = tree.inventory.get(nodeLoc)
@@ -83,7 +83,7 @@ t.test('placement tests', t => {
8383
legacyBundling,
8484
strictPeerDeps,
8585
legacyPeerDeps,
86-
globalStyle,
86+
installStrategy,
8787
})
8888
}
8989

@@ -291,7 +291,7 @@ t.test('placement tests', t => {
291291
}),
292292
dep: new Node({ pkg: { name: 'bar', version: '1.0.0' } }),
293293
nodeLoc: 'node_modules/foo',
294-
globalStyle: true,
294+
installStrategy: 'shallow',
295295
test: (t, tree) => {
296296
const foobar = tree.children.get('foo').resolve('bar')
297297
t.equal(foobar.location, 'node_modules/foo/node_modules/bar')
@@ -323,7 +323,7 @@ t.test('placement tests', t => {
323323
}),
324324
dep: new Node({ pkg: { name: 'baz', version: '1.0.0' } }),
325325
nodeLoc: 'node_modules/foo/node_modules/bar',
326-
globalStyle: true,
326+
installStrategy: 'shallow',
327327
test: (t, tree) => {
328328
const foobar = tree.children.get('foo').resolve('bar')
329329
const foobarbaz = foobar.resolve('baz')

0 commit comments

Comments
 (0)