socket 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 +49 -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 +50 -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
|
-
// socket is replaced by
|
|
49
|
+
// Content matching socket 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 === 'socket') {
|
|
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;
|
|
@@ -16,6 +16,7 @@ var require$$3$2 = require('@socketregistry/yocto-spinner');
|
|
|
16
16
|
var require$$4 = require('semver');
|
|
17
17
|
var require$$6$1 = require('@socketsecurity/config');
|
|
18
18
|
var require$$7 = require('@socketsecurity/registry/lib/objects');
|
|
19
|
+
var require$$8 = require('@socketsecurity/registry/lib/packages');
|
|
19
20
|
var require$$1$1 = require('node:net');
|
|
20
21
|
var require$$2 = require('node:os');
|
|
21
22
|
var require$$6 = require('../../package.json');
|
|
@@ -397,6 +398,7 @@ var _yoctoSpinner = require$$3$2;
|
|
|
397
398
|
var _semver = require$$4;
|
|
398
399
|
var _config = require$$6$1;
|
|
399
400
|
var _objects = require$$7;
|
|
401
|
+
var _packages = require$$8;
|
|
400
402
|
var _ttyServer = ttyServer$1;
|
|
401
403
|
var _constants$1 = constants.constants;
|
|
402
404
|
var _colorOrMarkdown = sdk.colorOrMarkdown;
|
|
@@ -405,7 +407,7 @@ var _misc = sdk.misc;
|
|
|
405
407
|
var _pathResolve = pathResolve.pathResolve;
|
|
406
408
|
var _sdk = sdk.sdk;
|
|
407
409
|
var _settings = sdk.settings;
|
|
408
|
-
const
|
|
410
|
+
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
411
|
const npmEntrypoint = (0, _nodeFs.realpathSync)(process.argv[1]);
|
|
410
412
|
const npmRootPath = (0, _pathResolve.findRoot)(_nodePath.dirname(npmEntrypoint));
|
|
411
413
|
function tryRequire(...ids) {
|
|
@@ -431,12 +433,9 @@ function tryRequire(...ids) {
|
|
|
431
433
|
return undefined;
|
|
432
434
|
}
|
|
433
435
|
if (npmRootPath === undefined) {
|
|
434
|
-
console.error(`Unable to find npm
|
|
435
|
-
console.error(`Searched parent directories of ${npmEntrypoint}`);
|
|
436
|
+
console.error(`Unable to find npm CLI install directory.\nSearched parent directories of ${npmEntrypoint}.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}`);
|
|
436
437
|
process.exit(127);
|
|
437
438
|
}
|
|
438
|
-
const LOOP_SENTINEL = 1_000_000;
|
|
439
|
-
const NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
440
439
|
const npmNmPath = _nodePath.join(npmRootPath, 'node_modules');
|
|
441
440
|
const arboristPkgPath = _nodePath.join(npmNmPath, '@npmcli/arborist');
|
|
442
441
|
const arboristClassPath = _nodePath.join(arboristPkgPath, 'lib/arborist/index.js');
|
|
@@ -449,7 +448,7 @@ const log = tryRequire([_nodePath.join(npmNmPath, 'proc-log/lib/index.js'),
|
|
|
449
448
|
// is really that of its export log.
|
|
450
449
|
mod => mod.log], _nodePath.join(npmNmPath, 'npmlog/lib/log.js'));
|
|
451
450
|
if (log === undefined) {
|
|
452
|
-
console.error(`Unable to integrate with npm
|
|
451
|
+
console.error(`Unable to integrate with npm CLI logging infrastructure.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}.`);
|
|
453
452
|
process.exit(127);
|
|
454
453
|
}
|
|
455
454
|
const pacote = tryRequire(_nodePath.join(npmNmPath, 'pacote'), 'pacote');
|
|
@@ -606,11 +605,16 @@ async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
|
606
605
|
if (pkgData.type === 'missing') {
|
|
607
606
|
result = true;
|
|
608
607
|
failures.push({
|
|
609
|
-
type: 'missingDependency'
|
|
608
|
+
type: 'missingDependency',
|
|
609
|
+
block: false,
|
|
610
|
+
raw: undefined
|
|
610
611
|
});
|
|
611
612
|
} else {
|
|
612
613
|
let blocked = false;
|
|
613
614
|
for (const failure of pkgData.value.issues) {
|
|
615
|
+
const {
|
|
616
|
+
type
|
|
617
|
+
} = failure;
|
|
614
618
|
// eslint-disable-next-line no-await-in-loop
|
|
615
619
|
const ux = await uxLookup({
|
|
616
620
|
package: {
|
|
@@ -618,33 +622,34 @@ async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
|
618
622
|
version
|
|
619
623
|
},
|
|
620
624
|
issue: {
|
|
621
|
-
type
|
|
625
|
+
type
|
|
622
626
|
}
|
|
623
627
|
});
|
|
624
|
-
if (ux.
|
|
628
|
+
if (ux.block) {
|
|
629
|
+
result = true;
|
|
630
|
+
blocked = true;
|
|
631
|
+
}
|
|
632
|
+
if (ux.display) {
|
|
633
|
+
displayWarning = true;
|
|
634
|
+
}
|
|
635
|
+
if (ux.block || ux.display) {
|
|
625
636
|
failures.push({
|
|
626
|
-
|
|
627
|
-
block: ux.block
|
|
637
|
+
type,
|
|
638
|
+
block: ux.block,
|
|
639
|
+
raw: failure
|
|
628
640
|
});
|
|
629
641
|
// Before we ask about problematic issues, check to see if they
|
|
630
642
|
// already existed in the old version if they did, be quiet.
|
|
631
643
|
const pkg = pkgs.find(p => p.pkgid === id && p.existing?.startsWith(`${name}@`));
|
|
632
644
|
if (pkg?.existing) {
|
|
645
|
+
const oldPkgData =
|
|
633
646
|
// eslint-disable-next-line no-await-in-loop
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
647
|
+
(await batchScan([pkg.existing]).next()).value;
|
|
648
|
+
if (oldPkgData.type === 'success') {
|
|
649
|
+
failures = failures.filter(issue => oldPkgData.value.issues.find(oldIssue => oldIssue.type === issue.type) === undefined);
|
|
638
650
|
}
|
|
639
651
|
}
|
|
640
652
|
}
|
|
641
|
-
if (ux.block) {
|
|
642
|
-
result = true;
|
|
643
|
-
blocked = true;
|
|
644
|
-
}
|
|
645
|
-
if (ux.display) {
|
|
646
|
-
displayWarning = true;
|
|
647
|
-
}
|
|
648
653
|
}
|
|
649
654
|
if (!blocked) {
|
|
650
655
|
const pkg = pkgs.find(p => p.pkgid === id);
|
|
@@ -660,15 +665,26 @@ async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
|
660
665
|
}
|
|
661
666
|
if (displayWarning) {
|
|
662
667
|
spinner.stop(`(socket) ${formatter.hyperlink(id, `https://socket.dev/npm/package/${name}/overview/${version}`)} contains risks:`);
|
|
663
|
-
|
|
668
|
+
// Filter issues for blessed packages.
|
|
669
|
+
if ((0, _packages.isBlessedPackageName)(name)) {
|
|
670
|
+
failures = failures.filter(({
|
|
671
|
+
type
|
|
672
|
+
}) => type !== 'unpopularPackage' && type !== 'unstableOwnership');
|
|
673
|
+
}
|
|
674
|
+
failures.sort((a, b) => a.type < b.type ? -1 : 1);
|
|
664
675
|
const lines = new Set();
|
|
665
676
|
for (const failure of failures) {
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
677
|
+
const {
|
|
678
|
+
type
|
|
679
|
+
} = failure;
|
|
680
|
+
// Based data from { pageProps: { alertTypes } } of:
|
|
681
|
+
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
|
|
682
|
+
const info = translations.issues[type];
|
|
683
|
+
const title = info?.title ?? type;
|
|
684
|
+
const maybeBlocking = failure.block ? '' : ' (non-blocking)';
|
|
685
|
+
const maybeDesc = info?.description ? ` - ${info.description}` : '';
|
|
686
|
+
// TODO: emoji seems to mis-align terminals sometimes
|
|
687
|
+
lines.add(` ${title}${maybeBlocking}${maybeDesc}\n`);
|
|
672
688
|
}
|
|
673
689
|
for (const line of lines) {
|
|
674
690
|
output?.write(line);
|
|
@@ -702,7 +718,7 @@ function walk(diff_, needInfoOn = []) {
|
|
|
702
718
|
length: queueLength
|
|
703
719
|
} = queue;
|
|
704
720
|
while (pos < queueLength) {
|
|
705
|
-
if (pos === LOOP_SENTINEL) {
|
|
721
|
+
if (pos === _constants$1.LOOP_SENTINEL) {
|
|
706
722
|
throw new Error('Detected infinite loop while walking Arborist diff');
|
|
707
723
|
}
|
|
708
724
|
const diff = queue[pos++];
|
|
@@ -1274,7 +1290,7 @@ class SafeOverrideSet extends OverrideSet {
|
|
|
1274
1290
|
length: queueLength
|
|
1275
1291
|
} = queue;
|
|
1276
1292
|
while (pos < queueLength) {
|
|
1277
|
-
if (pos === LOOP_SENTINEL) {
|
|
1293
|
+
if (pos === _constants$1.LOOP_SENTINEL) {
|
|
1278
1294
|
throw new Error('Detected infinite loop while comparing override sets');
|
|
1279
1295
|
}
|
|
1280
1296
|
const {
|
|
@@ -1416,10 +1432,10 @@ class SafeArborist extends Arborist {
|
|
|
1416
1432
|
options['save'] = old.save;
|
|
1417
1433
|
options['saveBundle'] = old.saveBundle;
|
|
1418
1434
|
// Nothing to check, mmm already installed or all private?
|
|
1419
|
-
if (diff.findIndex(c => c.repository_url === NPM_REGISTRY_URL) === -1) {
|
|
1435
|
+
if (diff.findIndex(c => c.repository_url === _constants$1.NPM_REGISTRY_URL) === -1) {
|
|
1420
1436
|
return await this[kRiskyReify](...args);
|
|
1421
1437
|
}
|
|
1422
|
-
let proceed = _constants$1.ENV.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE;
|
|
1438
|
+
let proceed = _constants$1.ENV[_constants$1.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE];
|
|
1423
1439
|
if (!proceed) {
|
|
1424
1440
|
proceed = await ttyServer.captureTTY(async (input, output) => {
|
|
1425
1441
|
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
|
-
// socket is replaced by
|
|
45
|
+
// Content matching socket 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 === 'socket') {
|
|
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;
|