Skip to content

Commit 1574c33

Browse files
authored
add --install-strategy=hoisted|nested|shallow, remove --global-style, --legacy-bundling (#5709)
* feat: add --install-strategy config, replace --global-style with "shallow" style * feat: replace --legacy-bundling with --install-strategy=nested * chore: add --legacy-bundling and --global-style as deprecated remappings BREAKING CHANGE: remove boolean install flags in favor of `--install-strategy` * remove --global-style, --global now sets --install-strategy=shallow * removed --legacy-bundling config
1 parent 353b5bb commit 1574c33

File tree

17 files changed

+193
-113
lines changed

17 files changed

+193
-113
lines changed

lib/commands/dedupe.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ 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',
13+
'global-style',
1314
'strict-peer-deps',
1415
'package-lock',
1516
'omit',

lib/commands/find-dupes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ 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',
10+
'global-style',
1011
'strict-peer-deps',
1112
'package-lock',
1213
'omit',

lib/commands/install.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ class Install extends ArboristWorkspaceCmd {
2020
'save',
2121
'save-exact',
2222
'global',
23-
'global-style',
23+
'install-strategy',
2424
'legacy-bundling',
25+
'global-style',
2526
'omit',
2627
'strict-peer-deps',
2728
'package-lock',

lib/commands/link.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ class Link extends ArboristWorkspaceCmd {
2222
'save',
2323
'save-exact',
2424
'global',
25-
'global-style',
25+
'install-strategy',
2626
'legacy-bundling',
27+
'global-style',
2728
'strict-peer-deps',
2829
'package-lock',
2930
'omit',

lib/commands/update.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class Update extends ArboristWorkspaceCmd {
1414
static params = [
1515
'save',
1616
'global',
17-
'global-style',
17+
'install-strategy',
1818
'legacy-bundling',
19+
'global-style',
1920
'omit',
2021
'strict-peer-deps',
2122
'package-lock',

lib/utils/config/definitions.js

+50-21
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,
@@ -851,6 +837,25 @@ define('globalconfig', {
851837
flatten,
852838
})
853839

840+
define('global-style', {
841+
default: false,
842+
type: Boolean,
843+
description: `
844+
Only install direct dependencies in the top level \`node_modules\`,
845+
but hoist on deeper dependendencies.
846+
Sets \`--install-strategy=shallow\`.
847+
`,
848+
deprecated: `
849+
This option has been deprecated in favor of \`--install-strategy=shallow\`
850+
`,
851+
flatten (key, obj, flatOptions) {
852+
if (obj[key]) {
853+
obj['install-strategy'] = 'shallow'
854+
flatOptions.installStrategy = 'shallow'
855+
}
856+
},
857+
})
858+
854859
define('heading', {
855860
default: 'npm',
856861
type: String,
@@ -1076,6 +1081,21 @@ define('install-links', {
10761081
flatten,
10771082
})
10781083

1084+
define('install-strategy', {
1085+
default: 'hoisted',
1086+
type: ['hoisted', 'nested', 'shallow'],
1087+
description: `
1088+
Sets the strategy for installing packages in node_modules.
1089+
hoisted (default): Install non-duplicated in top-level, and duplicated as
1090+
necessary within directory structure.
1091+
nested: (formerly --legacy-bundling) install in place, no hoisting.
1092+
shallow (formerly --global-style) only install direct deps at top-level.
1093+
linked: (coming soon) install in node_modules/.store, link in place,
1094+
unhoisted.
1095+
`,
1096+
flatten,
1097+
})
1098+
10791099
define('json', {
10801100
default: false,
10811101
type: Boolean,
@@ -1111,12 +1131,21 @@ define('legacy-bundling', {
11111131
default: false,
11121132
type: Boolean,
11131133
description: `
1114-
Causes npm to install the package such that versions of npm prior to 1.4,
1115-
such as the one included with node 0.8, can install the package. This
1116-
eliminates all automatic deduping. If used with \`global-style\` this
1117-
option will be preferred.
1134+
Instead of hoisting package installs in \`node_modules\`, install packages
1135+
in the same manner that they are depended on. This may cause very deep
1136+
directory structures and duplicate package installs as there is no
1137+
de-duplicating.
1138+
Sets \`--install-strategy=nested\`.
11181139
`,
1119-
flatten,
1140+
deprecated: `
1141+
This option has been deprecated in favor of \`--install-strategy=nested\`
1142+
`,
1143+
flatten (key, obj, flatOptions) {
1144+
if (obj[key]) {
1145+
obj['install-strategy'] = 'nested'
1146+
flatOptions.installStrategy = 'nested'
1147+
}
1148+
},
11201149
})
11211150

11221151
define('legacy-peer-deps', {
@@ -1523,8 +1552,8 @@ define('prefix', {
15231552
short: 'C',
15241553
default: '',
15251554
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
1555+
In global mode, the folder where the node executable is installed.
1556+
Otherwise, the nearest parent folder containing either a package.json
15281557
file or a node_modules folder.
15291558
`,
15301559
description: `

smoke-tests/tap-snapshots/test/index.js.test.cjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ npm ERR! npm ci
5656
npm ERR!
5757
npm ERR! Options:
5858
npm ERR! [-S|--save|--no-save|--save-prod|--save-dev|--save-optional|--save-peer|--save-bundle]
59-
npm ERR! [-E|--save-exact] [-g|--global] [--global-style] [--legacy-bundling]
59+
npm ERR! [-E|--save-exact] [-g|--global] [--install-strategy <hoisted|nested|shallow>]
60+
npm ERR! [--legacy-bundling] [--global-style]
6061
npm ERR! [--omit <dev|optional|peer> [--omit <dev|optional|peer> ...]]
6162
npm ERR! [--strict-peer-deps] [--no-package-lock] [--foreground-scripts]
6263
npm ERR! [--ignore-scripts] [--no-audit] [--no-bin-links] [--no-fund] [--dry-run]

tap-snapshots/test/lib/commands/config.js.test.cjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
6060
"git": "git",
6161
"git-tag-version": true,
6262
"global": false,
63-
"global-style": false,
6463
"globalconfig": "{GLOBALPREFIX}/npmrc",
64+
"global-style": false,
6565
"heading": "npm",
6666
"https-proxy": null,
6767
"if-present": false,
@@ -82,6 +82,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
8282
"init.module": "{HOME}/.npm-init.js",
8383
"init.version": "1.0.0",
8484
"install-links": true,
85+
"install-strategy": "hoisted",
8586
"key": null,
8687
"legacy-bundling": false,
8788
"legacy-peer-deps": false,
@@ -234,6 +235,7 @@ init.license = "ISC"
234235
init.module = "{HOME}/.npm-init.js"
235236
init.version = "1.0.0"
236237
install-links = true
238+
install-strategy = "hoisted"
237239
json = false
238240
key = null
239241
legacy-bundling = false

0 commit comments

Comments
 (0)