Skip to content

Commit 71a86f4

Browse files
authored
Merge branch 'main' into add-sbom
2 parents 82ea91b + cda2d91 commit 71a86f4

File tree

14 files changed

+391
-336
lines changed

14 files changed

+391
-336
lines changed

.dep-stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@socketregistry/is-unicode-supported": "^1.0.0",
1111
"@socketregistry/packageurl-js": "^1.0.2",
1212
"@socketsecurity/config": "^2.1.3",
13-
"@socketsecurity/registry": "^1.0.85",
13+
"@socketsecurity/registry": "^1.0.87",
1414
"@socketsecurity/sdk": "^1.4.5",
1515
"blessed": "^0.1.81",
1616
"blessed-contrib": "^4.11.0",

package-lock.json

Lines changed: 97 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"@socketregistry/is-unicode-supported": "^1.0.0",
7474
"@socketregistry/packageurl-js": "^1.0.2",
7575
"@socketsecurity/config": "^2.1.3",
76-
"@socketsecurity/registry": "^1.0.85",
76+
"@socketsecurity/registry": "^1.0.87",
7777
"@socketsecurity/sdk": "^1.4.5",
7878
"blessed": "^0.1.81",
7979
"blessed-contrib": "^4.11.0",
@@ -102,12 +102,12 @@
102102
"yoctocolors-cjs": "^2.1.2"
103103
},
104104
"devDependencies": {
105-
"@babel/core": "^7.26.7",
105+
"@babel/core": "^7.26.8",
106106
"@babel/plugin-proposal-export-default-from": "^7.25.9",
107107
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
108108
"@babel/plugin-transform-export-namespace-from": "^7.25.9",
109-
"@babel/plugin-transform-runtime": "^7.25.9",
110-
"@babel/preset-env": "^7.26.7",
109+
"@babel/plugin-transform-runtime": "^7.26.8",
110+
"@babel/preset-env": "^7.26.8",
111111
"@babel/preset-typescript": "^7.26.0",
112112
"@babel/runtime": "^7.26.7",
113113
"@biomejs/biome": "^1.9.4",

src/commands/analytics.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import { getDefaultToken, setupSdk } from '../utils/sdk'
2222
import type { CliSubcommand } from '../utils/meow-with-subcommands'
2323

2424
export const analytics: CliSubcommand = {
25-
description: `Look up analytics data \n
26-
Default parameters are set to show the organization-level analytics over the last 7 days.`,
25+
description: `Look up analytics data\n Default parameters are set to show the organization-level analytics over the last 7 days.`,
2726
async run(argv, importMeta, { parentName }) {
2827
const name = parentName + ' analytics'
2928

src/commands/fix.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
import { Spinner } from '@socketsecurity/registry/lib/spinner'
22

33
import constants from '../constants'
4-
import { shadowNpmInstall } from '../utils/shadow-npm'
4+
import { shadowNpmInstall } from '../utils/npm'
55

66
import type { CliSubcommand } from '../utils/meow-with-subcommands'
77

8-
const { SOCKET_CLI_FIX_PACKAGE_LOCK_FILE, SOCKET_IPC_HANDSHAKE } = constants
8+
const { SOCKET_CLI_IN_FIX_CMD, SOCKET_IPC_HANDSHAKE } = constants
9+
10+
// const prev = new Set(alerts.map(a => a.key))
11+
// let ret: SafeNode | undefined
12+
// /* eslint-disable no-await-in-loop */
13+
// while (alerts.length > 0) {
14+
// await updateAdvisoryNodes(this, alerts)
15+
// ret = await this[kRiskyReify](...args)
16+
// await this.loadActual()
17+
// await this.buildIdealTree()
18+
// needInfoOn = getPackagesToQueryFromDiff(this.diff, {
19+
// includeUnchanged: true
20+
// })
21+
// alerts = (
22+
// await getPackagesAlerts(needInfoOn, {
23+
// includeExisting: true,
24+
// includeUnfixable: true
25+
// })
26+
// ).filter(({ key }) => {
27+
// const unseen = !prev.has(key)
28+
// if (unseen) {
29+
// prev.add(key)
30+
// }
31+
// return unseen
32+
// })
33+
// }
34+
// /* eslint-enable no-await-in-loop */
35+
// return ret!
936

1037
export const fix: CliSubcommand = {
1138
description: 'Fix "fixable" Socket alerts',
@@ -16,7 +43,7 @@ export const fix: CliSubcommand = {
1643
await shadowNpmInstall({
1744
ipc: {
1845
[SOCKET_IPC_HANDSHAKE]: {
19-
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
46+
[SOCKET_CLI_IN_FIX_CMD]: true
2047
}
2148
}
2249
})

src/commands/optimize.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import { pluralize } from '@socketsecurity/registry/lib/words'
2828
import constants from '../constants'
2929
import { commonFlags } from '../flags'
3030
import { safeReadFile } from '../utils/fs'
31+
import { shadowNpmInstall } from '../utils/npm'
3132
import { getFlagListOutput } from '../utils/output-formatting'
3233
import { detect } from '../utils/package-manager-detector'
33-
import { shadowNpmInstall } from '../utils/shadow-npm'
3434

3535
import type { CliSubcommand } from '../utils/meow-with-subcommands'
3636
import type {
@@ -49,7 +49,7 @@ const {
4949
OVERRIDES,
5050
PNPM,
5151
RESOLUTIONS,
52-
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
52+
SOCKET_CLI_IN_OPTIMIZE_CMD,
5353
SOCKET_IPC_HANDSHAKE,
5454
VLT,
5555
YARN_BERRY,
@@ -62,7 +62,7 @@ const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025'
6262
const PNPM_FIELD_NAME = PNPM
6363
const PNPM_WORKSPACE = `${PNPM}-workspace`
6464

65-
const manifestNpmOverrides = getManifestData(NPM)!
65+
const manifestNpmOverrides = getManifestData(NPM)
6666

6767
type NpmOverrides = { [key: string]: string | StringKeyValueObject }
6868
type PnpmOrYarnOverrides = { [key: string]: string }
@@ -930,10 +930,13 @@ export const optimize: CliSubcommand = {
930930
if (isNpm) {
931931
const ipc = {
932932
[SOCKET_IPC_HANDSHAKE]: {
933-
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
933+
[SOCKET_CLI_IN_OPTIMIZE_CMD]: true
934934
}
935935
}
936-
await shadowNpmInstall({ ipc })
936+
await shadowNpmInstall({
937+
flags: ['--ignore-scripts'],
938+
ipc
939+
})
937940
// TODO: This is a temporary workaround for a `npm ci` bug where it
938941
// will error out after Socket Optimize generates a lock file. More
939942
// investigation is needed.

src/constants.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ type ENV = RegistryEnv &
3333
}>
3434

3535
type IPC = Readonly<{
36-
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE: boolean
37-
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
36+
SOCKET_CLI_IN_FIX_CMD: boolean
37+
SOCKET_CLI_IN_OPTIMIZE_CMD: boolean
3838
}>
3939

4040
type Constants = Omit<
@@ -56,9 +56,9 @@ type Constants = Omit<
5656
readonly PNPM: 'pnpm'
5757
readonly REQUIRE: 'require'
5858
readonly SOCKET_CLI_DEBUG: 'SOCKET_CLI_DEBUG'
59-
readonly SOCKET_CLI_FIX_PACKAGE_LOCK_FILE: 'SOCKET_CLI_FIX_PACKAGE_LOCK_FILE'
59+
readonly SOCKET_CLI_IN_FIX_CMD: 'SOCKET_CLI_IN_FIX_CMD'
60+
readonly SOCKET_CLI_IN_OPTIMIZE_CMD: 'SOCKET_CLI_IN_OPTIMIZE_CMD'
6061
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues'
61-
readonly SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE: 'SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE'
6262
readonly VLT: 'vlt'
6363
readonly YARN: 'yarn'
6464
readonly YARN_BERRY: 'yarn/berry'
@@ -85,10 +85,9 @@ const NPX = 'npx'
8585
const PNPM = 'pnpm'
8686
const REQUIRE = 'require'
8787
const SOCKET_CLI_DEBUG = 'SOCKET_CLI_DEBUG'
88-
const SOCKET_CLI_FIX_PACKAGE_LOCK_FILE = 'SOCKET_CLI_FIX_PACKAGE_LOCK_FILE'
88+
const SOCKET_CLI_IN_FIX_CMD = 'SOCKET_CLI_IN_FIX_CMD'
89+
const SOCKET_CLI_IN_OPTIMIZE_CMD = 'SOCKET_CLI_IN_OPTIMIZE_CMD'
8990
const SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues'
90-
const SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE =
91-
'SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE'
9291
const VLT = 'vlt'
9392
const YARN = 'yarn'
9493
const YARN_BERRY = `${YARN}/berry`
@@ -161,9 +160,9 @@ const constants = <Constants>createConstantsObject(
161160
PNPM,
162161
REQUIRE,
163162
SOCKET_CLI_DEBUG,
164-
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
163+
SOCKET_CLI_IN_FIX_CMD,
164+
SOCKET_CLI_IN_OPTIMIZE_CMD,
165165
SOCKET_CLI_ISSUES_URL,
166-
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
167166
VLT,
168167
YARN,
169168
YARN_BERRY,

src/shadow/arborist/lib/arborist/diff.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function getUrlOrigin(input: string): string {
1414

1515
export type PackageDetail = {
1616
node: SafeNode
17-
origin: string
1817
existing?: SafeNode | undefined
1918
}
2019

@@ -72,11 +71,12 @@ export function getPackagesToQueryFromDiff(
7271
keep = action !== 'REMOVE'
7372
}
7473
if (keep && pkgNode?.resolved && (!oldNode || oldNode.resolved)) {
75-
const origin = getUrlOrigin(pkgNode.resolved)
76-
if (includeUnknownOrigin || origin === NPM_REGISTRY_URL) {
74+
if (
75+
includeUnknownOrigin ||
76+
getUrlOrigin(pkgNode.resolved) === NPM_REGISTRY_URL
77+
) {
7778
details.push({
7879
node: pkgNode,
79-
origin,
8080
existing
8181
})
8282
}
@@ -90,11 +90,12 @@ export function getPackagesToQueryFromDiff(
9090
const { unchanged } = diff_!
9191
for (let i = 0, { length } = unchanged; i < length; i += 1) {
9292
const pkgNode = unchanged[i]!
93-
const origin = getUrlOrigin(pkgNode.resolved!)
94-
if (includeUnknownOrigin || origin === NPM_REGISTRY_URL) {
93+
if (
94+
includeUnknownOrigin ||
95+
getUrlOrigin(pkgNode.resolved!) === NPM_REGISTRY_URL
96+
) {
9597
details.push({
9698
node: pkgNode,
97-
origin,
9899
existing: pkgNode
99100
})
100101
}

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)