Skip to content

Commit 5094bc6

Browse files
committed
wip: global installs, save in proper locations
Relies on npm/arborist#49, land that first.
1 parent a1891b2 commit 5094bc6

23 files changed

Lines changed: 480 additions & 280 deletions

lib/config/flat-options.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,16 @@ const flatOptions = npm => npm.flatOptions || Object.freeze({
161161

162162
// used to build up the appropriate {add:{...}} options to Arborist.reify
163163
save: npm.config.get('save'),
164-
saveBundle: npm.config.get('save-bundle'),
165-
saveDev: npm.config.get('save-dev'),
166-
saveOptional: npm.config.get('save-optional'),
167-
savePeer: npm.config.get('save-peer'),
168-
saveProd: npm.config.get('save-prod'),
169-
saveExact: npm.config.get('save-exact'),
170-
savePrefix: npm.config.get('save-prefix'),
164+
saveBundle: npm.config.get('save-bundle') && !npm.config.get('save-peer'),
165+
saveType: npm.config.get('save-optional') && npm.config.get('save-peer')
166+
? 'peerOptional'
167+
: npm.config.get('save-optional') ? 'optional'
168+
: npm.config.get('save-dev') ? 'dev'
169+
: npm.config.get('save-peer') ? 'peer'
170+
: npm.config.get('save-prod') ? 'prod'
171+
: null,
172+
savePrefix: npm.config.get('save-exact') ? ''
173+
: npm.config.get('save-prefix'),
171174

172175
// configs for npm-registry-fetch
173176
otp: npm.config.get('otp'),

lib/install.js

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ function install (where, args, cb) {
123123
where = null
124124
}
125125
// the /path/to/node_modules/..
126-
var globalTop = path.resolve(npm.globalDir, '..')
126+
const globalTop = path.resolve(npm.globalDir, '..')
127127
if (!where) {
128128
where = npm.flatOptions.global
129129
? globalTop
130130
: npm.prefix
131131
}
132-
const {dryRun} = npm.flatOptions.dryRun
132+
const {dryRun} = npm.flatOptions
133133

134134
// TODO: Add warnings for other deprecated flags
135135
if (npm.config.get('dev')) {
@@ -141,33 +141,6 @@ function install (where, args, cb) {
141141
}
142142
args = args.filter(a => path.resolve(a) !== npm.prefix)
143143

144-
const saveWhere = npm.flatOptions.saveProd ? 'dependencies'
145-
: npm.flatOptions.saveDev ? 'devDependencies'
146-
: npm.flatOptions.saveOptional ? 'optionalDependencies'
147-
: npm.flatOptions.savePeer ? 'peerDependencies'
148-
: 'dependencies'
149-
150-
const {saveBundled} = npm.flatOptions
151-
const add = !args.length ? null : args.reduce((add, a) => {
152-
// npm install foo
153-
// npm install @foo/bar
154-
// npm install foo@bar
155-
// npm install @foo/bar@baz
156-
// npm install git+ssh://foogit.com:bar/baz#boo
157-
const spec = npa(a, where)
158-
add[saveWhere].push(spec)
159-
160-
// XXX need to fix this npm install http://foo.com/bar.tgz --save-bundled
161-
// TODO: arborist should take saveBundled boolean
162-
// Point of research: can you bundle any dep other than production? If not,
163-
// we can pass `bundleDependencies: [array, of, specs]` to arborist,
164-
// it'll do {dependencies:{name:spec, ...}, bundleDependencies:[name,...]}
165-
if (saveBundled && spec.name) {
166-
add.bundleDependencies.push(spec.name)
167-
}
168-
return add
169-
}, { [saveWhere]: [], bundleDependencies: [] })
170-
171144
const arb = new Arborist({
172145
...this.flatOptions,
173146
path: where,
@@ -181,7 +154,7 @@ function install (where, args, cb) {
181154

182155
const opt = {
183156
...this.flatOptions,
184-
add,
157+
add: args,
185158
}
186159
arb[dryRun ? 'buildIdealTree' : 'reify'](opt).then(tree => {
187160
output('TREEEEEEEE', tree)

node_modules/@npmcli/arborist/README.md

Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@npmcli/arborist/lib/add-rm-pkg-deps.js

Lines changed: 81 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)