@socketsecurity/cli 0.14.29 → 0.14.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +2 -4
- package/bin/npm-cli.js +2 -4
- package/bin/npx-cli.js +2 -4
- package/dist/module-sync/cli.js +10 -8
- package/dist/module-sync/constants.d.ts +7 -2
- package/dist/module-sync/constants.js +17 -7
- package/dist/module-sync/npm-injection.js +47 -33
- package/dist/require/cli.js +10 -8
- package/dist/require/constants.d.ts +7 -2
- package/dist/require/constants.js +17 -7
- package/dist/require/npm-injection.js +48 -34
- package/package.json +2 -2
- package/translations.json +190 -287
package/bin/cli.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const distType = semver.satisfies(process.versions.node, '>=22.12')
|
|
4
|
+
const DIST_TYPE = require('semver').satisfies(process.versions.node, '>=22.12')
|
|
6
5
|
? 'module-sync'
|
|
7
6
|
: 'require'
|
|
8
|
-
|
|
9
|
-
require(`../dist/${distType}/cli.js`)
|
|
7
|
+
require(`../dist/${DIST_TYPE}/cli.js`)
|
package/bin/npm-cli.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const distType = semver.satisfies(process.versions.node, '>=22.12')
|
|
4
|
+
const DIST_TYPE = require('semver').satisfies(process.versions.node, '>=22.12')
|
|
6
5
|
? 'module-sync'
|
|
7
6
|
: 'require'
|
|
8
|
-
|
|
9
|
-
require(`../dist/${distType}/npm-cli.js`)
|
|
7
|
+
require(`../dist/${DIST_TYPE}/npm-cli.js`)
|
package/bin/npx-cli.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict'
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const distType = semver.satisfies(process.versions.node, '>=22.12')
|
|
4
|
+
const DIST_TYPE = require('semver').satisfies(process.versions.node, '>=22.12')
|
|
6
5
|
? 'module-sync'
|
|
7
6
|
: 'require'
|
|
8
|
-
|
|
9
|
-
require(`../dist/${distType}/npx-cli.js`)
|
|
7
|
+
require(`../dist/${DIST_TYPE}/npx-cli.js`)
|
package/dist/module-sync/cli.js
CHANGED
|
@@ -299,8 +299,9 @@ var _ponyCause$4 = require$$4$1;
|
|
|
299
299
|
var _errors$l = sdk.errors;
|
|
300
300
|
var _constants$5 = constants.constants;
|
|
301
301
|
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
302
|
-
|
|
303
|
-
const
|
|
302
|
+
// SocketSdkErrorType['error'] is not typed.
|
|
303
|
+
const resultErrorMessage = result.error?.message;
|
|
304
|
+
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
304
305
|
if (result.status === 401 || result.status === 403) {
|
|
305
306
|
spinner.stop();
|
|
306
307
|
throw new _errors$l.AuthError(message);
|
|
@@ -321,16 +322,16 @@ async function handleApiCall(value, description) {
|
|
|
321
322
|
}
|
|
322
323
|
async function handleAPIError(code) {
|
|
323
324
|
if (code === 400) {
|
|
324
|
-
return
|
|
325
|
+
return 'One of the options passed might be incorrect.';
|
|
325
326
|
} else if (code === 403) {
|
|
326
|
-
return
|
|
327
|
+
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
async function queryAPI(path, apiKey) {
|
|
330
331
|
return await fetch(`${_constants$5.API_V0_URL}/${path}`, {
|
|
331
332
|
method: 'GET',
|
|
332
333
|
headers: {
|
|
333
|
-
Authorization:
|
|
334
|
+
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
334
335
|
}
|
|
335
336
|
});
|
|
336
337
|
}
|
|
@@ -1145,6 +1146,7 @@ var _fs = fs;
|
|
|
1145
1146
|
var _packageManagerDetector = packageManagerDetector;
|
|
1146
1147
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1147
1148
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1149
|
+
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1148
1150
|
const PNPM_FIELD_NAME = 'pnpm';
|
|
1149
1151
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
1150
1152
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
@@ -1826,11 +1828,11 @@ const optimize = optimize$1.optimize = {
|
|
|
1826
1828
|
try {
|
|
1827
1829
|
if (isNpm) {
|
|
1828
1830
|
const wrapperPath = _nodePath$1.join(_constants$1.distPath, 'npm-cli.js');
|
|
1829
|
-
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--
|
|
1831
|
+
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--silent'], {
|
|
1830
1832
|
stdio: 'ignore',
|
|
1831
1833
|
env: {
|
|
1832
1834
|
...process.env,
|
|
1833
|
-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
|
|
1835
|
+
[_constants$1.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1834
1836
|
}
|
|
1835
1837
|
});
|
|
1836
1838
|
} else {
|
|
@@ -1841,7 +1843,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1841
1843
|
}
|
|
1842
1844
|
spinner.stop();
|
|
1843
1845
|
if (isNpm) {
|
|
1844
|
-
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships
|
|
1846
|
+
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
1845
1847
|
}
|
|
1846
1848
|
} catch {
|
|
1847
1849
|
spinner.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
declare const SUPPORTS_SYNC_ESM: boolean;
|
|
1
2
|
declare const API_V0_URL = "https://api.socket.dev/v0";
|
|
3
|
+
declare const DIST_TYPE: string;
|
|
4
|
+
declare const LOOP_SENTINEL = 1000000;
|
|
5
|
+
declare const NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
6
|
+
declare const SOCKET_CLI_ISSUES_URL = "https://github.com/SocketDev/socket-cli/issues";
|
|
7
|
+
declare const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = "UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE";
|
|
2
8
|
declare const ENV: Readonly<{
|
|
3
9
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean;
|
|
4
10
|
}>;
|
|
5
|
-
declare const SUPPORTS_SYNC_ESM: boolean;
|
|
6
11
|
declare const rootPath: string;
|
|
7
12
|
declare const rootDistPath: string;
|
|
8
13
|
declare const rootBinPath: string;
|
|
@@ -12,4 +17,4 @@ declare const cdxgenBinPath: string;
|
|
|
12
17
|
declare const distPath: string;
|
|
13
18
|
declare const shadowBinPath: string;
|
|
14
19
|
declare const synpBinPath: string;
|
|
15
|
-
export { API_V0_URL,
|
|
20
|
+
export { SUPPORTS_SYNC_ESM, API_V0_URL, DIST_TYPE, LOOP_SENTINEL, NPM_REGISTRY_URL, SOCKET_CLI_ISSUES_URL, UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE, ENV, rootPath, rootDistPath, rootBinPath, rootPkgJsonPath, nmBinPath, cdxgenBinPath, distPath, shadowBinPath, synpBinPath };
|
|
@@ -15,7 +15,7 @@ var constants = {};
|
|
|
15
15
|
Object.defineProperty(constants, "__esModule", {
|
|
16
16
|
value: true
|
|
17
17
|
});
|
|
18
|
-
constants.synpBinPath = constants.shadowBinPath = constants.rootPkgJsonPath = constants.rootPath = constants.rootDistPath = constants.rootBinPath = constants.nmBinPath = constants.distPath = constants.cdxgenBinPath = constants.SUPPORTS_SYNC_ESM = constants.ENV = constants.API_V0_URL = void 0;
|
|
18
|
+
constants.synpBinPath = constants.shadowBinPath = constants.rootPkgJsonPath = constants.rootPath = constants.rootDistPath = constants.rootBinPath = constants.nmBinPath = constants.distPath = constants.cdxgenBinPath = constants.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = constants.SUPPORTS_SYNC_ESM = constants.SOCKET_CLI_ISSUES_URL = constants.NPM_REGISTRY_URL = constants.LOOP_SENTINEL = constants.ENV = constants.DIST_TYPE = constants.API_V0_URL = void 0;
|
|
19
19
|
var _nodeFs = require$$0;
|
|
20
20
|
var _nodePath = require$$1;
|
|
21
21
|
var _env = require$$2;
|
|
@@ -24,20 +24,30 @@ var _semver = require$$4;
|
|
|
24
24
|
const {
|
|
25
25
|
PACKAGE_JSON
|
|
26
26
|
} = _constants;
|
|
27
|
+
const SUPPORTS_SYNC_ESM = constants.SUPPORTS_SYNC_ESM = _semver.satisfies(process.versions.node, '>=22.12');
|
|
27
28
|
constants.API_V0_URL = 'https://api.socket.dev/v0';
|
|
29
|
+
const DIST_TYPE = constants.DIST_TYPE = SUPPORTS_SYNC_ESM ? 'module-sync' : 'require';
|
|
30
|
+
constants.LOOP_SENTINEL = 1_000_000;
|
|
31
|
+
constants.NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
32
|
+
const SOCKET_CLI_ISSUES_URL = constants.SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues';
|
|
33
|
+
const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = constants.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE';
|
|
28
34
|
constants.ENV = Object.freeze({
|
|
29
35
|
// Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
|
|
30
|
-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: (0, _env.envAsBoolean)(process.env[
|
|
36
|
+
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: (0, _env.envAsBoolean)(process.env[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE])
|
|
31
37
|
});
|
|
32
|
-
|
|
38
|
+
|
|
39
|
+
// Dynamically detect the rootPath so constants.ts can be used in tests.
|
|
33
40
|
const rootPath = constants.rootPath = (() => {
|
|
34
41
|
let oldPath;
|
|
35
42
|
let currPath = (0, _nodeFs.realpathSync)(__dirname);
|
|
43
|
+
// Dirname stops when at the filepath root, e.g. '/' for posix and 'C:\\' for win32,
|
|
44
|
+
// so `currPath` equal `oldPath`.
|
|
36
45
|
while (currPath !== oldPath) {
|
|
37
46
|
const pkgJsonPath = _nodePath.join(currPath, PACKAGE_JSON);
|
|
38
47
|
if ((0, _nodeFs.existsSync)(pkgJsonPath)) {
|
|
39
48
|
try {
|
|
40
|
-
// @socketsecurity/cli is replaced by
|
|
49
|
+
// Content matching @socketsecurity/cli is replaced by
|
|
50
|
+
// the @rollup/plugin-replace plugin used in .config/rollup.base.config.mjs
|
|
41
51
|
// with either 'socket' or '@socketsecurity/cli'.
|
|
42
52
|
if (require(pkgJsonPath)?.name === '@socketsecurity/cli') {
|
|
43
53
|
return currPath;
|
|
@@ -47,15 +57,15 @@ const rootPath = constants.rootPath = (() => {
|
|
|
47
57
|
oldPath = currPath;
|
|
48
58
|
currPath = _nodePath.dirname(currPath);
|
|
49
59
|
}
|
|
50
|
-
throw new TypeError(
|
|
60
|
+
throw new TypeError(`Socket CLI initialization error: rootPath cannot be resolved.\n\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`);
|
|
51
61
|
})();
|
|
52
62
|
const rootDistPath = constants.rootDistPath = _nodePath.join(rootPath, 'dist');
|
|
53
63
|
constants.rootBinPath = _nodePath.join(rootPath, 'bin');
|
|
54
64
|
constants.rootPkgJsonPath = _nodePath.join(rootPath, PACKAGE_JSON);
|
|
55
65
|
const nmBinPath = constants.nmBinPath = _nodePath.join(rootPath, 'node_modules/.bin');
|
|
56
66
|
constants.cdxgenBinPath = _nodePath.join(nmBinPath, 'cdxgen');
|
|
57
|
-
constants.distPath = _nodePath.join(rootDistPath,
|
|
58
|
-
constants.shadowBinPath = _nodePath.join(rootPath, 'shadow',
|
|
67
|
+
constants.distPath = _nodePath.join(rootDistPath, DIST_TYPE);
|
|
68
|
+
constants.shadowBinPath = _nodePath.join(rootPath, 'shadow', DIST_TYPE);
|
|
59
69
|
constants.synpBinPath = _nodePath.join(nmBinPath, 'synp');
|
|
60
70
|
|
|
61
71
|
exports.constants = constants;
|
|
@@ -405,7 +405,7 @@ var _misc = sdk.misc;
|
|
|
405
405
|
var _pathResolve = pathResolve.pathResolve;
|
|
406
406
|
var _sdk = sdk.sdk;
|
|
407
407
|
var _settings = sdk.settings;
|
|
408
|
-
const
|
|
408
|
+
const POTENTIAL_BUG_ERROR_MESSAGE = `This is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${_constants$1.SOCKET_CLI_ISSUES_URL}.`;
|
|
409
409
|
const npmEntrypoint = (0, _nodeFs.realpathSync)(process.argv[1]);
|
|
410
410
|
const npmRootPath = (0, _pathResolve.findRoot)(_nodePath.dirname(npmEntrypoint));
|
|
411
411
|
function tryRequire(...ids) {
|
|
@@ -431,12 +431,9 @@ function tryRequire(...ids) {
|
|
|
431
431
|
return undefined;
|
|
432
432
|
}
|
|
433
433
|
if (npmRootPath === undefined) {
|
|
434
|
-
console.error(`Unable to find npm
|
|
435
|
-
console.error(`Searched parent directories of ${npmEntrypoint}`);
|
|
434
|
+
console.error(`Unable to find npm CLI install directory.\nSearched parent directories of ${npmEntrypoint}.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}`);
|
|
436
435
|
process.exit(127);
|
|
437
436
|
}
|
|
438
|
-
const LOOP_SENTINEL = 1_000_000;
|
|
439
|
-
const NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
440
437
|
const npmNmPath = _nodePath.join(npmRootPath, 'node_modules');
|
|
441
438
|
const arboristPkgPath = _nodePath.join(npmNmPath, '@npmcli/arborist');
|
|
442
439
|
const arboristClassPath = _nodePath.join(arboristPkgPath, 'lib/arborist/index.js');
|
|
@@ -449,7 +446,7 @@ const log = tryRequire([_nodePath.join(npmNmPath, 'proc-log/lib/index.js'),
|
|
|
449
446
|
// is really that of its export log.
|
|
450
447
|
mod => mod.log], _nodePath.join(npmNmPath, 'npmlog/lib/log.js'));
|
|
451
448
|
if (log === undefined) {
|
|
452
|
-
console.error(`Unable to integrate with npm
|
|
449
|
+
console.error(`Unable to integrate with npm CLI logging infrastructure.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}.`);
|
|
453
450
|
process.exit(127);
|
|
454
451
|
}
|
|
455
452
|
const pacote = tryRequire(_nodePath.join(npmNmPath, 'pacote'), 'pacote');
|
|
@@ -606,11 +603,16 @@ async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
|
606
603
|
if (pkgData.type === 'missing') {
|
|
607
604
|
result = true;
|
|
608
605
|
failures.push({
|
|
609
|
-
type: 'missingDependency'
|
|
606
|
+
type: 'missingDependency',
|
|
607
|
+
block: false,
|
|
608
|
+
raw: undefined
|
|
610
609
|
});
|
|
611
610
|
} else {
|
|
612
611
|
let blocked = false;
|
|
613
612
|
for (const failure of pkgData.value.issues) {
|
|
613
|
+
const {
|
|
614
|
+
type
|
|
615
|
+
} = failure;
|
|
614
616
|
// eslint-disable-next-line no-await-in-loop
|
|
615
617
|
const ux = await uxLookup({
|
|
616
618
|
package: {
|
|
@@ -618,33 +620,34 @@ async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
|
618
620
|
version
|
|
619
621
|
},
|
|
620
622
|
issue: {
|
|
621
|
-
type
|
|
623
|
+
type
|
|
622
624
|
}
|
|
623
625
|
});
|
|
624
|
-
if (ux.
|
|
626
|
+
if (ux.block) {
|
|
627
|
+
result = true;
|
|
628
|
+
blocked = true;
|
|
629
|
+
}
|
|
630
|
+
if (ux.display) {
|
|
631
|
+
displayWarning = true;
|
|
632
|
+
}
|
|
633
|
+
if (ux.block || ux.display) {
|
|
625
634
|
failures.push({
|
|
626
|
-
|
|
627
|
-
block: ux.block
|
|
635
|
+
type,
|
|
636
|
+
block: ux.block,
|
|
637
|
+
raw: failure
|
|
628
638
|
});
|
|
629
639
|
// Before we ask about problematic issues, check to see if they
|
|
630
640
|
// already existed in the old version if they did, be quiet.
|
|
631
641
|
const pkg = pkgs.find(p => p.pkgid === id && p.existing?.startsWith(`${name}@`));
|
|
632
642
|
if (pkg?.existing) {
|
|
643
|
+
const oldPkgData =
|
|
633
644
|
// eslint-disable-next-line no-await-in-loop
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
645
|
+
(await batchScan([pkg.existing]).next()).value;
|
|
646
|
+
if (oldPkgData.type === 'success') {
|
|
647
|
+
failures = failures.filter(issue => oldPkgData.value.issues.find(oldIssue => oldIssue.type === issue.type) === undefined);
|
|
638
648
|
}
|
|
639
649
|
}
|
|
640
650
|
}
|
|
641
|
-
if (ux.block) {
|
|
642
|
-
result = true;
|
|
643
|
-
blocked = true;
|
|
644
|
-
}
|
|
645
|
-
if (ux.display) {
|
|
646
|
-
displayWarning = true;
|
|
647
|
-
}
|
|
648
651
|
}
|
|
649
652
|
if (!blocked) {
|
|
650
653
|
const pkg = pkgs.find(p => p.pkgid === id);
|
|
@@ -660,15 +663,26 @@ async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
|
660
663
|
}
|
|
661
664
|
if (displayWarning) {
|
|
662
665
|
spinner.stop(`(socket) ${formatter.hyperlink(id, `https://socket.dev/npm/package/${name}/overview/${version}`)} contains risks:`);
|
|
663
|
-
|
|
666
|
+
// Filter issues for blessed packages.
|
|
667
|
+
if (name === 'socket' || name.startsWith('@socketregistry/') || name.startsWith('@socketsecurity/')) {
|
|
668
|
+
failures = failures.filter(({
|
|
669
|
+
type
|
|
670
|
+
}) => type !== 'unpopularPackage' && type !== 'unstableOwnership');
|
|
671
|
+
}
|
|
672
|
+
failures.sort((a, b) => a.type < b.type ? -1 : 1);
|
|
664
673
|
const lines = new Set();
|
|
665
674
|
for (const failure of failures) {
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
675
|
+
const {
|
|
676
|
+
type
|
|
677
|
+
} = failure;
|
|
678
|
+
// Based data from { pageProps: { alertTypes } } of:
|
|
679
|
+
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
|
|
680
|
+
const info = translations.issues[type];
|
|
681
|
+
const title = info?.title ?? type;
|
|
682
|
+
const maybeBlocking = failure.block ? '' : ' (non-blocking)';
|
|
683
|
+
const maybeDesc = info?.description ? ` - ${info.description}` : '';
|
|
684
|
+
// TODO: emoji seems to mis-align terminals sometimes
|
|
685
|
+
lines.add(` ${title}${maybeBlocking}${maybeDesc}\n`);
|
|
672
686
|
}
|
|
673
687
|
for (const line of lines) {
|
|
674
688
|
output?.write(line);
|
|
@@ -702,7 +716,7 @@ function walk(diff_, needInfoOn = []) {
|
|
|
702
716
|
length: queueLength
|
|
703
717
|
} = queue;
|
|
704
718
|
while (pos < queueLength) {
|
|
705
|
-
if (pos === LOOP_SENTINEL) {
|
|
719
|
+
if (pos === _constants$1.LOOP_SENTINEL) {
|
|
706
720
|
throw new Error('Detected infinite loop while walking Arborist diff');
|
|
707
721
|
}
|
|
708
722
|
const diff = queue[pos++];
|
|
@@ -1274,7 +1288,7 @@ class SafeOverrideSet extends OverrideSet {
|
|
|
1274
1288
|
length: queueLength
|
|
1275
1289
|
} = queue;
|
|
1276
1290
|
while (pos < queueLength) {
|
|
1277
|
-
if (pos === LOOP_SENTINEL) {
|
|
1291
|
+
if (pos === _constants$1.LOOP_SENTINEL) {
|
|
1278
1292
|
throw new Error('Detected infinite loop while comparing override sets');
|
|
1279
1293
|
}
|
|
1280
1294
|
const {
|
|
@@ -1416,10 +1430,10 @@ class SafeArborist extends Arborist {
|
|
|
1416
1430
|
options['save'] = old.save;
|
|
1417
1431
|
options['saveBundle'] = old.saveBundle;
|
|
1418
1432
|
// Nothing to check, mmm already installed or all private?
|
|
1419
|
-
if (diff.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1) {
|
|
1433
|
+
if (diff.findIndex(c => c.repository_url === _constants$1.NPM_REGISTRY_URL) === -1) {
|
|
1420
1434
|
return await this[kRiskyReify](...args);
|
|
1421
1435
|
}
|
|
1422
|
-
let proceed = _constants$1.ENV.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE;
|
|
1436
|
+
let proceed = _constants$1.ENV[_constants$1.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE];
|
|
1423
1437
|
if (!proceed) {
|
|
1424
1438
|
proceed = await ttyServer.captureTTY(async (input, output) => {
|
|
1425
1439
|
if (input && output) {
|
package/dist/require/cli.js
CHANGED
|
@@ -293,8 +293,9 @@ var _ponyCause$4 = require$$4$1;
|
|
|
293
293
|
var _errors$l = sdk.errors;
|
|
294
294
|
var _constants$5 = constants.constants;
|
|
295
295
|
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
296
|
-
|
|
297
|
-
const
|
|
296
|
+
// SocketSdkErrorType['error'] is not typed.
|
|
297
|
+
const resultErrorMessage = result.error?.message;
|
|
298
|
+
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
298
299
|
if (result.status === 401 || result.status === 403) {
|
|
299
300
|
spinner.stop();
|
|
300
301
|
throw new _errors$l.AuthError(message);
|
|
@@ -315,16 +316,16 @@ async function handleApiCall(value, description) {
|
|
|
315
316
|
}
|
|
316
317
|
async function handleAPIError(code) {
|
|
317
318
|
if (code === 400) {
|
|
318
|
-
return
|
|
319
|
+
return 'One of the options passed might be incorrect.';
|
|
319
320
|
} else if (code === 403) {
|
|
320
|
-
return
|
|
321
|
+
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
324
|
async function queryAPI(path, apiKey) {
|
|
324
325
|
return await fetch(`${_constants$5.API_V0_URL}/${path}`, {
|
|
325
326
|
method: 'GET',
|
|
326
327
|
headers: {
|
|
327
|
-
Authorization:
|
|
328
|
+
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
328
329
|
}
|
|
329
330
|
});
|
|
330
331
|
}
|
|
@@ -1139,6 +1140,7 @@ var _fs = fs;
|
|
|
1139
1140
|
var _packageManagerDetector = packageManagerDetector;
|
|
1140
1141
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1141
1142
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1143
|
+
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1142
1144
|
const PNPM_FIELD_NAME = 'pnpm';
|
|
1143
1145
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
1144
1146
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
@@ -1820,11 +1822,11 @@ const optimize = optimize$1.optimize = {
|
|
|
1820
1822
|
try {
|
|
1821
1823
|
if (isNpm) {
|
|
1822
1824
|
const wrapperPath = _nodePath$1.join(_constants$1.distPath, 'npm-cli.js');
|
|
1823
|
-
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--
|
|
1825
|
+
await _promiseSpawn$2(process.execPath, [wrapperPath, 'install', '--silent'], {
|
|
1824
1826
|
stdio: 'ignore',
|
|
1825
1827
|
env: {
|
|
1826
1828
|
...process.env,
|
|
1827
|
-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: '1'
|
|
1829
|
+
[_constants$1.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1828
1830
|
}
|
|
1829
1831
|
});
|
|
1830
1832
|
} else {
|
|
@@ -1835,7 +1837,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1835
1837
|
}
|
|
1836
1838
|
spinner.stop();
|
|
1837
1839
|
if (isNpm) {
|
|
1838
|
-
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships
|
|
1840
|
+
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
1839
1841
|
}
|
|
1840
1842
|
} catch {
|
|
1841
1843
|
spinner.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
declare const SUPPORTS_SYNC_ESM: boolean;
|
|
1
2
|
declare const API_V0_URL = "https://api.socket.dev/v0";
|
|
3
|
+
declare const DIST_TYPE: string;
|
|
4
|
+
declare const LOOP_SENTINEL = 1000000;
|
|
5
|
+
declare const NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
6
|
+
declare const SOCKET_CLI_ISSUES_URL = "https://github.com/SocketDev/socket-cli/issues";
|
|
7
|
+
declare const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = "UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE";
|
|
2
8
|
declare const ENV: Readonly<{
|
|
3
9
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean;
|
|
4
10
|
}>;
|
|
5
|
-
declare const SUPPORTS_SYNC_ESM: boolean;
|
|
6
11
|
declare const rootPath: string;
|
|
7
12
|
declare const rootDistPath: string;
|
|
8
13
|
declare const rootBinPath: string;
|
|
@@ -12,4 +17,4 @@ declare const cdxgenBinPath: string;
|
|
|
12
17
|
declare const distPath: string;
|
|
13
18
|
declare const shadowBinPath: string;
|
|
14
19
|
declare const synpBinPath: string;
|
|
15
|
-
export { API_V0_URL,
|
|
20
|
+
export { SUPPORTS_SYNC_ESM, API_V0_URL, DIST_TYPE, LOOP_SENTINEL, NPM_REGISTRY_URL, SOCKET_CLI_ISSUES_URL, UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE, ENV, rootPath, rootDistPath, rootBinPath, rootPkgJsonPath, nmBinPath, cdxgenBinPath, distPath, shadowBinPath, synpBinPath };
|
|
@@ -11,7 +11,7 @@ var constants = {};
|
|
|
11
11
|
Object.defineProperty(constants, "__esModule", {
|
|
12
12
|
value: true
|
|
13
13
|
});
|
|
14
|
-
constants.synpBinPath = constants.shadowBinPath = constants.rootPkgJsonPath = constants.rootPath = constants.rootDistPath = constants.rootBinPath = constants.nmBinPath = constants.distPath = constants.cdxgenBinPath = constants.SUPPORTS_SYNC_ESM = constants.ENV = constants.API_V0_URL = void 0;
|
|
14
|
+
constants.synpBinPath = constants.shadowBinPath = constants.rootPkgJsonPath = constants.rootPath = constants.rootDistPath = constants.rootBinPath = constants.nmBinPath = constants.distPath = constants.cdxgenBinPath = constants.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = constants.SUPPORTS_SYNC_ESM = constants.SOCKET_CLI_ISSUES_URL = constants.NPM_REGISTRY_URL = constants.LOOP_SENTINEL = constants.ENV = constants.DIST_TYPE = constants.API_V0_URL = void 0;
|
|
15
15
|
var _nodeFs = require$$0;
|
|
16
16
|
var _nodePath = require$$1;
|
|
17
17
|
var _env = require$$2;
|
|
@@ -20,20 +20,30 @@ var _semver = require$$4;
|
|
|
20
20
|
const {
|
|
21
21
|
PACKAGE_JSON
|
|
22
22
|
} = _constants;
|
|
23
|
+
const SUPPORTS_SYNC_ESM = constants.SUPPORTS_SYNC_ESM = _semver.satisfies(process.versions.node, '>=22.12');
|
|
23
24
|
constants.API_V0_URL = 'https://api.socket.dev/v0';
|
|
25
|
+
const DIST_TYPE = constants.DIST_TYPE = SUPPORTS_SYNC_ESM ? 'module-sync' : 'require';
|
|
26
|
+
constants.LOOP_SENTINEL = 1_000_000;
|
|
27
|
+
constants.NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
28
|
+
const SOCKET_CLI_ISSUES_URL = constants.SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues';
|
|
29
|
+
const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = constants.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE = 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE';
|
|
24
30
|
constants.ENV = Object.freeze({
|
|
25
31
|
// Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
|
|
26
|
-
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: (0, _env.envAsBoolean)(process.env[
|
|
32
|
+
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: (0, _env.envAsBoolean)(process.env[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE])
|
|
27
33
|
});
|
|
28
|
-
|
|
34
|
+
|
|
35
|
+
// Dynamically detect the rootPath so constants.ts can be used in tests.
|
|
29
36
|
const rootPath = constants.rootPath = (() => {
|
|
30
37
|
let oldPath;
|
|
31
38
|
let currPath = (0, _nodeFs.realpathSync)(__dirname);
|
|
39
|
+
// Dirname stops when at the filepath root, e.g. '/' for posix and 'C:\\' for win32,
|
|
40
|
+
// so `currPath` equal `oldPath`.
|
|
32
41
|
while (currPath !== oldPath) {
|
|
33
42
|
const pkgJsonPath = _nodePath.join(currPath, PACKAGE_JSON);
|
|
34
43
|
if ((0, _nodeFs.existsSync)(pkgJsonPath)) {
|
|
35
44
|
try {
|
|
36
|
-
// @socketsecurity/cli is replaced by
|
|
45
|
+
// Content matching @socketsecurity/cli is replaced by
|
|
46
|
+
// the @rollup/plugin-replace plugin used in .config/rollup.base.config.mjs
|
|
37
47
|
// with either 'socket' or '@socketsecurity/cli'.
|
|
38
48
|
if (require(pkgJsonPath)?.name === '@socketsecurity/cli') {
|
|
39
49
|
return currPath;
|
|
@@ -43,15 +53,15 @@ const rootPath = constants.rootPath = (() => {
|
|
|
43
53
|
oldPath = currPath;
|
|
44
54
|
currPath = _nodePath.dirname(currPath);
|
|
45
55
|
}
|
|
46
|
-
throw new TypeError(
|
|
56
|
+
throw new TypeError(`Socket CLI initialization error: rootPath cannot be resolved.\n\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`);
|
|
47
57
|
})();
|
|
48
58
|
const rootDistPath = constants.rootDistPath = _nodePath.join(rootPath, 'dist');
|
|
49
59
|
constants.rootBinPath = _nodePath.join(rootPath, 'bin');
|
|
50
60
|
constants.rootPkgJsonPath = _nodePath.join(rootPath, PACKAGE_JSON);
|
|
51
61
|
const nmBinPath = constants.nmBinPath = _nodePath.join(rootPath, 'node_modules/.bin');
|
|
52
62
|
constants.cdxgenBinPath = _nodePath.join(nmBinPath, 'cdxgen');
|
|
53
|
-
constants.distPath = _nodePath.join(rootDistPath,
|
|
54
|
-
constants.shadowBinPath = _nodePath.join(rootPath, 'shadow',
|
|
63
|
+
constants.distPath = _nodePath.join(rootDistPath, DIST_TYPE);
|
|
64
|
+
constants.shadowBinPath = _nodePath.join(rootPath, 'shadow', DIST_TYPE);
|
|
55
65
|
constants.synpBinPath = _nodePath.join(nmBinPath, 'synp');
|
|
56
66
|
|
|
57
67
|
exports.constants = constants;
|