Skip to content

Commit 4cb696c

Browse files
committed
Add safe overrides to arborist use
1 parent 5e4ace0 commit 4cb696c

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

src/commands/fix/agent-fix.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export async function agentFix(
286286
)
287287

288288
if (!oldVersions.length) {
289-
debugFn('notice', `skip: ${name} not found\n`)
289+
debugFn('notice', `skip: ${name} not found`)
290290
cleanupInfoEntriesLoop()
291291
// Skip to next package.
292292
continue infoEntriesLoop
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import {
2-
Arborist,
3-
SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
4-
} from '../../shadow/npm/arborist/index.mts'
1+
import { Arborist } from '../../shadow/npm/arborist/index.mts'
2+
import { SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES } from '../../shadow/npm/arborist/lib/arborist/index.mts'
53

64
import type { NodeClass } from '../../shadow/npm/arborist/types.mts'
75

@@ -14,7 +12,7 @@ export async function getActualTree(
1412
// of the node_modules folder.
1513
const arb = new Arborist({
1614
path: cwd,
17-
...SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
15+
...SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
1816
})
1917
return await arb.loadActual()
2018
}

src/commands/fix/npm-fix.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { agentFix } from './agent-fix.mts'
44
import { getActualTree } from './get-actual-tree.mts'
55
import { getFixAlertsMapOptions } from './shared.mts'
66
import { Arborist } from '../../shadow/npm/arborist/index.mts'
7+
import { SAFE_WITH_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES } from '../../shadow/npm/arborist/lib/arborist/index.mts'
78
import {
89
findPackageNode,
910
getAlertsMapFromArborist,
@@ -67,6 +68,7 @@ export async function npmFix(
6768
const arb = new Arborist({
6869
path: pkgEnvDetails.pkgPath,
6970
...flatConfig,
71+
...SAFE_WITH_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
7072
})
7173
actualTree = await arb.reify()
7274
// Calling arb.reify() creates the arb.diff object, nulls-out arb.idealTree,
@@ -114,6 +116,7 @@ export async function npmFix(
114116
const arb = new Arborist({
115117
path: pkgEnvDetails.pkgPath,
116118
...flatConfig,
119+
...SAFE_WITH_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
117120
})
118121
const idealTree = await arb.buildIdealTree()
119122
const node = findPackageNode(idealTree, packument.name, oldVersion)

src/shadow/npm/arborist/index.mts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ import type { EdgeClass, NodeClass, OverrideSetClass } from './types.mts'
1919

2020
const require = createRequire(import.meta.url)
2121

22-
export const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
23-
__proto__: null,
24-
audit: false,
25-
dryRun: true,
26-
fund: false,
27-
ignoreScripts: true,
28-
progress: false,
29-
save: false,
30-
saveBundle: false,
31-
silent: true,
32-
}
33-
3422
export { Arborist, SafeArborist }
3523

3624
export const Edge: EdgeClass = UntypedEdge

src/shadow/npm/arborist/lib/arborist/index.mts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: { getIpc },
2525
} = constants
2626

27-
export const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
27+
export const SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
2828
__proto__: null,
2929
audit: false,
3030
dryRun: true,
@@ -36,6 +36,14 @@ export const SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
3636
silent: true,
3737
}
3838

39+
export const SAFE_WITH_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES = {
40+
// @ts-ignore
41+
__proto__: null,
42+
...SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
43+
dryRun: false,
44+
save: true,
45+
}
46+
3947
export const kCtorArgs = Symbol('ctorArgs')
4048

4149
export const kRiskyReify = Symbol('riskyReify')
@@ -51,7 +59,7 @@ export class SafeArborist extends Arborist {
5159
path:
5260
(ctorArgs.length ? ctorArgs[0]?.path : undefined) ?? process.cwd(),
5361
...(ctorArgs.length ? ctorArgs[0] : undefined),
54-
...SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
62+
...SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
5563
},
5664
...ctorArgs.slice(1),
5765
)
@@ -97,7 +105,7 @@ export class SafeArborist extends Arborist {
97105
await super.reify(
98106
{
99107
...options,
100-
...SAFE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
108+
...SAFE_NO_SAVE_ARBORIST_REIFY_OPTIONS_OVERRIDES,
101109
progress: false,
102110
},
103111
// @ts-ignore: TypeScript gets grumpy about rest parameters.

0 commit comments

Comments
 (0)