@@ -8,20 +8,26 @@ export const Arborist: ArboristClass = require(getArboristClassPath())
8
8
9
9
export const kCtorArgs = Symbol ( 'ctorArgs' )
10
10
11
+ const safeOptOverrides = {
12
+ __proto__ : null ,
13
+ audit : false ,
14
+ dryRun : true ,
15
+ fund : false ,
16
+ ignoreScripts : true ,
17
+ progress : false ,
18
+ save : false ,
19
+ saveBundle : false ,
20
+ silent : true
21
+ }
22
+
11
23
// Implementation code not related to our custom behavior is based on
12
24
// https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/arborist/index.js:
13
25
export class SafeArborist extends Arborist {
14
26
constructor ( ...ctorArgs : ConstructorParameters < ArboristClass > ) {
15
27
super (
16
28
{
17
29
...ctorArgs [ 0 ] ,
18
- audit : true ,
19
- dryRun : true ,
20
- ignoreScripts : true ,
21
- save : false ,
22
- saveBundle : false ,
23
- // progress: false,
24
- fund : false
30
+ ...safeOptOverrides
25
31
} ,
26
32
...ctorArgs . slice ( 1 )
27
33
)
@@ -31,9 +37,8 @@ export class SafeArborist extends Arborist {
31
37
async [ kRiskyReify ] (
32
38
...args : Parameters < InstanceType < ArboristClass > [ 'reify' ] >
33
39
) : Promise < SafeNode > {
34
- // SafeArborist has suffered side effects and must be rebuilt from scratch.
35
40
const arb = new Arborist ( ...( this as any ) [ kCtorArgs ] )
36
- arb . idealTree = this . idealTree
41
+ // arb.idealTree = this.idealTree
37
42
const ret = await arb . reify ( ...args )
38
43
Object . assign ( this , arb )
39
44
return ret
@@ -44,24 +49,18 @@ export class SafeArborist extends Arborist {
44
49
this : SafeArborist ,
45
50
...args : Parameters < InstanceType < ArboristClass > [ 'reify' ] >
46
51
) : Promise < SafeNode > {
47
- const options = < ArboristReifyOptions > ( args [ 0 ] ? { ...args [ 0 ] } : { } )
52
+ const options = < ArboristReifyOptions > {
53
+ __proto__ : null ,
54
+ ...( args . length ? args [ 0 ] : undefined )
55
+ }
48
56
if ( options . dryRun ) {
49
57
return await this [ kRiskyReify ] ( ...args )
50
58
}
51
- const old = {
52
- ...options ,
53
- dryRun : false ,
54
- save : Boolean ( options . save ?? true ) ,
55
- saveBundle : Boolean ( options . saveBundle ?? false )
56
- }
59
+ Object . assign ( options , safeOptOverrides )
60
+ const old = args [ 0 ]
57
61
args [ 0 ] = options
58
- options . dryRun = true
59
- options . save = false
60
- options . saveBundle = false
61
62
await super . reify ( ...args )
62
- options . dryRun = old . dryRun
63
- options . save = old . save
64
- options . saveBundle = old . saveBundle
63
+ args [ 0 ] = old
65
64
return await Reflect . apply ( reify , this , args )
66
65
}
67
66
}
0 commit comments