@@ -74,20 +74,26 @@ class Arborist extends Base {
74
74
Arborist : this . constructor ,
75
75
binLinks : 'binLinks' in options ? ! ! options . binLinks : true ,
76
76
cache : options . cache || `${ homedir ( ) } /.npm/_cacache` ,
77
+ dryRun : ! ! options . dryRun ,
78
+ formatPackageLock : 'formatPackageLock' in options ? ! ! options . formatPackageLock : true ,
77
79
force : ! ! options . force ,
78
80
global : ! ! options . global ,
79
81
ignoreScripts : ! ! options . ignoreScripts ,
80
82
installStrategy : options . global ? 'shallow' : ( options . installStrategy ? options . installStrategy : 'hoisted' ) ,
81
83
lockfileVersion : lockfileVersion ( options . lockfileVersion ) ,
84
+ packageLockOnly : ! ! options . packageLockOnly ,
82
85
packumentCache : options . packumentCache || new Map ( ) ,
83
86
path : options . path || '.' ,
84
87
rebuildBundle : 'rebuildBundle' in options ? ! ! options . rebuildBundle : true ,
85
88
replaceRegistryHost : options . replaceRegistryHost ,
89
+ savePrefix : 'savePrefix' in options ? options . savePrefix : '^' ,
86
90
scriptShell : options . scriptShell ,
87
91
workspaces : options . workspaces || [ ] ,
88
92
workspacesEnabled : options . workspacesEnabled !== false ,
89
93
}
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
91
97
this . replaceRegistryHost = this . options . replaceRegistryHost =
92
98
( ! this . options . replaceRegistryHost || this . options . replaceRegistryHost === 'npmjs' ) ?
93
99
'registry.npmjs.org' : this . options . replaceRegistryHost
@@ -96,6 +102,7 @@ class Arborist extends Base {
96
102
throw new Error ( `Invalid saveType ${ options . saveType } ` )
97
103
}
98
104
this . cache = resolve ( this . options . cache )
105
+ this . diff = null
99
106
this . path = resolve ( this . options . path )
100
107
timeEnd ( )
101
108
}
@@ -250,6 +257,24 @@ class Arborist extends Base {
250
257
this . finishTracker ( 'audit' )
251
258
return ret
252
259
}
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
+ }
253
278
}
254
279
255
280
module . exports = Arborist
0 commit comments