Skip to content

Commit abcbc54

Browse files
authored
fix(reify): cleanup of Symbols (#7430)
This starts the long process of cleaning reify.js up. All of the remaining symbols are used either elsewhere in arborist, or in tests. A single use function was inlined, and `dedupe` was moved to the main arborist class.
1 parent d679ce8 commit abcbc54

File tree

2 files changed

+275
-314
lines changed

2 files changed

+275
-314
lines changed

workspaces/arborist/lib/arborist/index.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,26 @@ class Arborist extends Base {
7474
Arborist: this.constructor,
7575
binLinks: 'binLinks' in options ? !!options.binLinks : true,
7676
cache: options.cache || `${homedir()}/.npm/_cacache`,
77+
dryRun: !!options.dryRun,
78+
formatPackageLock: 'formatPackageLock' in options ? !!options.formatPackageLock : true,
7779
force: !!options.force,
7880
global: !!options.global,
7981
ignoreScripts: !!options.ignoreScripts,
8082
installStrategy: options.global ? 'shallow' : (options.installStrategy ? options.installStrategy : 'hoisted'),
8183
lockfileVersion: lockfileVersion(options.lockfileVersion),
84+
packageLockOnly: !!options.packageLockOnly,
8285
packumentCache: options.packumentCache || new Map(),
8386
path: options.path || '.',
8487
rebuildBundle: 'rebuildBundle' in options ? !!options.rebuildBundle : true,
8588
replaceRegistryHost: options.replaceRegistryHost,
89+
savePrefix: 'savePrefix' in options ? options.savePrefix : '^',
8690
scriptShell: options.scriptShell,
8791
workspaces: options.workspaces || [],
8892
workspacesEnabled: options.workspacesEnabled !== false,
8993
}
90-
// TODO is this even used? If not is that a bug?
94+
// TODO we only ever look at this.options.replaceRegistryHost, not
95+
// this.replaceRegistryHost. Defaulting needs to be written back to
96+
// this.options to work properly
9197
this.replaceRegistryHost = this.options.replaceRegistryHost =
9298
(!this.options.replaceRegistryHost || this.options.replaceRegistryHost === 'npmjs') ?
9399
'registry.npmjs.org' : this.options.replaceRegistryHost
@@ -96,6 +102,7 @@ class Arborist extends Base {
96102
throw new Error(`Invalid saveType ${options.saveType}`)
97103
}
98104
this.cache = resolve(this.options.cache)
105+
this.diff = null
99106
this.path = resolve(this.options.path)
100107
timeEnd()
101108
}
@@ -250,6 +257,24 @@ class Arborist extends Base {
250257
this.finishTracker('audit')
251258
return ret
252259
}
260+
261+
async dedupe (options = {}) {
262+
// allow the user to set options on the ctor as well.
263+
// XXX: deprecate separate method options objects.
264+
options = { ...this.options, ...options }
265+
const tree = await this.loadVirtual().catch(() => this.loadActual())
266+
const names = []
267+
for (const name of tree.inventory.query('name')) {
268+
if (tree.inventory.query('name', name).size > 1) {
269+
names.push(name)
270+
}
271+
}
272+
return this.reify({
273+
...options,
274+
preferDedupe: true,
275+
update: { names },
276+
})
277+
}
253278
}
254279

255280
module.exports = Arborist

0 commit comments

Comments
 (0)