Skip to content

Commit 70dd086

Browse files
committed
Reuse safeOptOverrides
1 parent b604029 commit 70dd086

File tree

1 file changed

+21
-22
lines changed
  • src/shadow/arborist/lib/arborist

1 file changed

+21
-22
lines changed

src/shadow/arborist/lib/arborist/index.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ export const Arborist: ArboristClass = require(getArboristClassPath())
88

99
export const kCtorArgs = Symbol('ctorArgs')
1010

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+
1123
// Implementation code not related to our custom behavior is based on
1224
// https://github.com/npm/cli/blob/v11.0.0/workspaces/arborist/lib/arborist/index.js:
1325
export class SafeArborist extends Arborist {
1426
constructor(...ctorArgs: ConstructorParameters<ArboristClass>) {
1527
super(
1628
{
1729
...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
2531
},
2632
...ctorArgs.slice(1)
2733
)
@@ -31,9 +37,8 @@ export class SafeArborist extends Arborist {
3137
async [kRiskyReify](
3238
...args: Parameters<InstanceType<ArboristClass>['reify']>
3339
): Promise<SafeNode> {
34-
// SafeArborist has suffered side effects and must be rebuilt from scratch.
3540
const arb = new Arborist(...(this as any)[kCtorArgs])
36-
arb.idealTree = this.idealTree
41+
//arb.idealTree = this.idealTree
3742
const ret = await arb.reify(...args)
3843
Object.assign(this, arb)
3944
return ret
@@ -44,24 +49,18 @@ export class SafeArborist extends Arborist {
4449
this: SafeArborist,
4550
...args: Parameters<InstanceType<ArboristClass>['reify']>
4651
): Promise<SafeNode> {
47-
const options = <ArboristReifyOptions>(args[0] ? { ...args[0] } : {})
52+
const options = <ArboristReifyOptions>{
53+
__proto__: null,
54+
...(args.length ? args[0] : undefined)
55+
}
4856
if (options.dryRun) {
4957
return await this[kRiskyReify](...args)
5058
}
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]
5761
args[0] = options
58-
options.dryRun = true
59-
options.save = false
60-
options.saveBundle = false
6162
await super.reify(...args)
62-
options.dryRun = old.dryRun
63-
options.save = old.save
64-
options.saveBundle = old.saveBundle
63+
args[0] = old
6564
return await Reflect.apply(reify, this, args)
6665
}
6766
}

0 commit comments

Comments
 (0)