socket 1.1.11 → 1.1.13
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/CHANGELOG.md +49 -28
- package/bin/cli.js +2 -1
- package/bin/npm-cli.js +2 -1
- package/bin/npx-cli.js +2 -1
- package/bin/pnpm-cli.js +29 -0
- package/bin/yarn-cli.js +29 -0
- package/dist/cli.js +728 -532
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +27 -5
- package/dist/constants.js.map +1 -1
- package/dist/npm-cli.js +26 -0
- package/dist/npm-cli.js.map +1 -0
- package/dist/npx-cli.js +26 -0
- package/dist/npx-cli.js.map +1 -0
- package/dist/pnpm-cli.js +26 -0
- package/dist/pnpm-cli.js.map +1 -0
- package/dist/shadow-npm-inject.js +2 -2
- package/dist/shadow-npm-inject.js.map +1 -1
- package/dist/shadow-pnpm-bin.js +235 -0
- package/dist/shadow-pnpm-bin.js.map +1 -0
- package/dist/shadow-yarn-bin.js +200 -0
- package/dist/shadow-yarn-bin.js.map +1 -0
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/coana-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/handle-fix.d.mts +3 -1
- package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/pull-request.d.mts.map +1 -1
- package/dist/types/commands/fix/types.d.mts +2 -0
- package/dist/types/commands/fix/types.d.mts.map +1 -1
- package/dist/types/commands/json/cmd-json.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-conda.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-setup.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest.d.mts.map +1 -1
- package/dist/types/commands/manifest/detect-manifest-actions.d.mts.map +1 -1
- package/dist/types/commands/manifest/generate_auto_manifest.d.mts.map +1 -1
- package/dist/types/commands/manifest/output-requirements.d.mts.map +1 -1
- package/dist/types/commands/manifest/run-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/manifest/setup-manifest-config.d.mts.map +1 -1
- package/dist/types/commands/npm/cmd-npm.d.mts.map +1 -1
- package/dist/types/commands/npx/cmd-npx.d.mts.map +1 -1
- package/dist/types/commands/pnpm/cmd-pnpm.d.mts +10 -0
- package/dist/types/commands/pnpm/cmd-pnpm.d.mts.map +1 -0
- package/dist/types/commands/scan/cmd-scan-setup.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts +1 -1
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/yarn/cmd-yarn.d.mts +10 -0
- package/dist/types/commands/yarn/cmd-yarn.d.mts.map +1 -0
- package/dist/types/commands.d.mts +10 -0
- package/dist/types/commands.d.mts.map +1 -1
- package/dist/types/constants.d.mts +15 -1
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/npm-cli.d.mts +3 -0
- package/dist/types/npm-cli.d.mts.map +1 -0
- package/dist/types/npx-cli.d.mts +3 -0
- package/dist/types/npx-cli.d.mts.map +1 -0
- package/dist/types/pnpm-cli.d.mts +3 -0
- package/dist/types/pnpm-cli.d.mts.map +1 -0
- package/dist/types/shadow/npm/install.d.mts +1 -1
- package/dist/types/shadow/npm/install.d.mts.map +1 -1
- package/dist/types/shadow/pnpm/bin.d.mts +10 -0
- package/dist/types/shadow/pnpm/bin.d.mts.map +1 -0
- package/dist/types/shadow/pnpm/link.d.mts +2 -0
- package/dist/types/shadow/pnpm/link.d.mts.map +1 -0
- package/dist/types/shadow/yarn/bin.d.mts +10 -0
- package/dist/types/shadow/yarn/bin.d.mts.map +1 -0
- package/dist/types/shadow/yarn/link.d.mts +2 -0
- package/dist/types/shadow/yarn/link.d.mts.map +1 -0
- package/dist/types/utils/alerts-map.d.mts.map +1 -1
- package/dist/types/utils/coana.d.mts.map +1 -1
- package/dist/types/utils/github.d.mts.map +1 -1
- package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
- package/dist/types/utils/package-environment.d.mts.map +1 -1
- package/dist/types/utils/pnpm-paths.d.mts +5 -0
- package/dist/types/utils/pnpm-paths.d.mts.map +1 -0
- package/dist/types/utils/socket-json.d.mts +3 -0
- package/dist/types/utils/socket-json.d.mts.map +1 -1
- package/dist/types/utils/yarn-paths.d.mts +5 -0
- package/dist/types/utils/yarn-paths.d.mts.map +1 -0
- package/dist/types/utils/yarn-version.d.mts +2 -0
- package/dist/types/utils/yarn-version.d.mts.map +1 -0
- package/dist/types/yarn-cli.d.mts +3 -0
- package/dist/types/yarn-cli.d.mts.map +1 -0
- package/dist/utils.js +242 -63
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +3622 -1386
- package/dist/yarn-cli.js +26 -0
- package/dist/yarn-cli.js.map +1 -0
- package/package.json +6 -2
- package/shadow-bin/npm +1 -1
- package/shadow-bin/npx +1 -1
- package/shadow-bin/pnpm +27 -0
- package/shadow-bin/yarn +27 -0
package/dist/utils.js
CHANGED
|
@@ -23,8 +23,8 @@ var fs$1 = require('node:fs');
|
|
|
23
23
|
var require$$13 = require('../external/@socketsecurity/registry/lib/url');
|
|
24
24
|
var promises = require('node:timers/promises');
|
|
25
25
|
var npm = require('../external/@socketsecurity/registry/lib/npm');
|
|
26
|
-
var globs = require('../external/@socketsecurity/registry/lib/globs');
|
|
27
26
|
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
27
|
+
var globs = require('../external/@socketsecurity/registry/lib/globs');
|
|
28
28
|
var streams = require('../external/@socketsecurity/registry/lib/streams');
|
|
29
29
|
|
|
30
30
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -565,7 +565,7 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
565
565
|
async function queryApi(path, apiToken) {
|
|
566
566
|
const baseUrl = getDefaultApiBaseUrl();
|
|
567
567
|
if (!baseUrl) {
|
|
568
|
-
throw new Error('Socket API
|
|
568
|
+
throw new Error('Socket API base URL is not configured.');
|
|
569
569
|
}
|
|
570
570
|
return await fetch(`${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}${path}`, {
|
|
571
571
|
method: 'GET',
|
|
@@ -1344,9 +1344,12 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1344
1344
|
//'json',
|
|
1345
1345
|
'license', 'login', 'logout', 'manifest', constants.NPM, constants.NPX, 'optimize', 'organization', 'package',
|
|
1346
1346
|
//'patch',
|
|
1347
|
+
// PNPM,
|
|
1347
1348
|
'raw-npm', 'raw-npx', 'repository', 'scan',
|
|
1348
1349
|
//'security',
|
|
1349
|
-
'threat-feed', 'uninstall', 'wrapper'
|
|
1350
|
+
'threat-feed', 'uninstall', 'wrapper'
|
|
1351
|
+
// YARN,
|
|
1352
|
+
]);
|
|
1350
1353
|
Object.entries(subcommands).filter(([_name, subcommand]) => !subcommand.hidden).map(([name]) => name).forEach(name => {
|
|
1351
1354
|
if (commands.has(name)) {
|
|
1352
1355
|
commands.delete(name);
|
|
@@ -1390,6 +1393,11 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1390
1393
|
}
|
|
1391
1394
|
lines.push(` ${getFlagListOutput({
|
|
1392
1395
|
...flags$1,
|
|
1396
|
+
// Explicitly document the negated --no-banner variant.
|
|
1397
|
+
noBanner: {
|
|
1398
|
+
...flags$1['banner'],
|
|
1399
|
+
hidden: false
|
|
1400
|
+
},
|
|
1393
1401
|
// Explicitly document the negated --no-spinner variant.
|
|
1394
1402
|
noSpinner: {
|
|
1395
1403
|
...flags$1['spinner'],
|
|
@@ -1400,7 +1408,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1400
1408
|
padName: HELP_PAD_NAME
|
|
1401
1409
|
})}`);
|
|
1402
1410
|
if (isRootCommand) {
|
|
1403
|
-
lines.push('', 'Environment variables', ' SOCKET_CLI_API_TOKEN Set the Socket API token', ' SOCKET_CLI_CONFIG A JSON stringified Socket configuration object', ' SOCKET_CLI_GITHUB_API_URL Change the base URL for GitHub REST API calls', ' SOCKET_CLI_GIT_USER_EMAIL The git config `user.email` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]@users.noreply.github.com`, ' SOCKET_CLI_GIT_USER_NAME The git config `user.name` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]`, ` SOCKET_CLI_GITHUB_TOKEN A classic or fine-grained ${vendor.terminalLinkExports('GitHub personal access token', 'https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens')}`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} GITHUB_TOKEN`, ' SOCKET_CLI_NO_API_TOKEN Make the default API token `undefined`', ' SOCKET_CLI_NPM_PATH The absolute location of the npm directory', ' SOCKET_CLI_ORG_SLUG Specify the Socket organization slug', '', ' SOCKET_CLI_ACCEPT_RISKS Accept risks of a Socket wrapped npm/npx run', ' SOCKET_CLI_VIEW_ALL_RISKS View all risks of a Socket wrapped npm/npx run', '', 'Environment variables for development', ' SOCKET_CLI_API_BASE_URL Change the base URL for Socket API calls', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} The "apiBaseUrl" value of socket/settings local app data`,
|
|
1411
|
+
lines.push('', 'Environment variables', ' SOCKET_CLI_API_TOKEN Set the Socket API token', ' SOCKET_CLI_CONFIG A JSON stringified Socket configuration object', ' SOCKET_CLI_GITHUB_API_URL Change the base URL for GitHub REST API calls', ' SOCKET_CLI_GIT_USER_EMAIL The git config `user.email` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]@users.noreply.github.com`, ' SOCKET_CLI_GIT_USER_NAME The git config `user.name` used by Socket CLI', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} github-actions[bot]`, ` SOCKET_CLI_GITHUB_TOKEN A classic or fine-grained ${vendor.terminalLinkExports('GitHub personal access token', 'https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens')}`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} GITHUB_TOKEN`, ' SOCKET_CLI_NO_API_TOKEN Make the default API token `undefined`', ' SOCKET_CLI_NPM_PATH The absolute location of the npm directory', ' SOCKET_CLI_ORG_SLUG Specify the Socket organization slug', '', ' SOCKET_CLI_ACCEPT_RISKS Accept risks of a Socket wrapped npm/npx run', ' SOCKET_CLI_VIEW_ALL_RISKS View all risks of a Socket wrapped npm/npx run', '', 'Environment variables for development', ' SOCKET_CLI_API_BASE_URL Change the base URL for Socket API calls', ` ${vendor.yoctocolorsCjsExports.italic('Defaults:')} The "apiBaseUrl" value of socket/settings local app data`, ` if present, else ${constants.API_V0_URL}`, ' SOCKET_CLI_API_PROXY Set the proxy Socket API requests are routed through, e.g. if set to', ` ${vendor.terminalLinkExports('http://127.0.0.1:9090', 'https://docs.proxyman.io/troubleshooting/couldnt-see-any-requests-from-3rd-party-network-libraries')} then all request are passed through that proxy`, ` ${vendor.yoctocolorsCjsExports.italic('Aliases:')} HTTPS_PROXY, https_proxy, HTTP_PROXY, and http_proxy`, ' SOCKET_CLI_API_TIMEOUT Set the timeout in milliseconds for Socket API requests', ' SOCKET_CLI_DEBUG Enable debug logging in Socket CLI', ` DEBUG Enable debug logging based on the ${vendor.terminalLinkExports('debug', `${constants.SOCKET_WEBSITE_URL}/npm/package/debug`)} package`);
|
|
1404
1412
|
}
|
|
1405
1413
|
|
|
1406
1414
|
// Parse it again. Config overrides should now be applied (may affect help).
|
|
@@ -1465,10 +1473,10 @@ function meowOrExit({
|
|
|
1465
1473
|
importMeta
|
|
1466
1474
|
});
|
|
1467
1475
|
const {
|
|
1468
|
-
help,
|
|
1476
|
+
help: helpFlag,
|
|
1469
1477
|
org: orgFlag,
|
|
1470
1478
|
spinner: spinnerFlag,
|
|
1471
|
-
version
|
|
1479
|
+
version: versionFlag
|
|
1472
1480
|
} = cli.flags;
|
|
1473
1481
|
const noSpinner = spinnerFlag === false;
|
|
1474
1482
|
|
|
@@ -1501,12 +1509,12 @@ function meowOrExit({
|
|
|
1501
1509
|
// })
|
|
1502
1510
|
// }
|
|
1503
1511
|
|
|
1504
|
-
if (
|
|
1512
|
+
if (helpFlag) {
|
|
1505
1513
|
cli.showHelp(0);
|
|
1506
1514
|
}
|
|
1507
1515
|
|
|
1508
1516
|
// Meow doesn't detect 'version' as an unknown flag, so we do the leg work here.
|
|
1509
|
-
if (
|
|
1517
|
+
if (versionFlag && !require$$11.hasOwn(config.flags, 'version')) {
|
|
1510
1518
|
// Use `console.error` here instead of `logger.error` to match Meow behavior.
|
|
1511
1519
|
console.error('Unknown flag\n--version');
|
|
1512
1520
|
// eslint-disable-next-line n/no-process-exit
|
|
@@ -2555,7 +2563,7 @@ async function getPackageFilesForScan(inputPaths, supportedFiles, options) {
|
|
|
2555
2563
|
return filterBySupportedScanFiles(filepaths, supportedFiles);
|
|
2556
2564
|
}
|
|
2557
2565
|
|
|
2558
|
-
function exitWithBinPathError(binName) {
|
|
2566
|
+
function exitWithBinPathError$2(binName) {
|
|
2559
2567
|
logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
|
|
2560
2568
|
// The exit code 127 indicates that the command or binary being executed
|
|
2561
2569
|
// could not be found.
|
|
@@ -2567,7 +2575,7 @@ function getNpmBinPath() {
|
|
|
2567
2575
|
if (_npmBinPath === undefined) {
|
|
2568
2576
|
_npmBinPath = getNpmBinPathDetails().path;
|
|
2569
2577
|
if (!_npmBinPath) {
|
|
2570
|
-
exitWithBinPathError(constants.NPM);
|
|
2578
|
+
exitWithBinPathError$2(constants.NPM);
|
|
2571
2579
|
}
|
|
2572
2580
|
}
|
|
2573
2581
|
return _npmBinPath;
|
|
@@ -2617,7 +2625,7 @@ function getNpxBinPath() {
|
|
|
2617
2625
|
if (_npxBinPath === undefined) {
|
|
2618
2626
|
_npxBinPath = getNpxBinPathDetails().path;
|
|
2619
2627
|
if (!_npxBinPath) {
|
|
2620
|
-
exitWithBinPathError('npx');
|
|
2628
|
+
exitWithBinPathError$2('npx');
|
|
2621
2629
|
}
|
|
2622
2630
|
}
|
|
2623
2631
|
return _npxBinPath;
|
|
@@ -2858,7 +2866,8 @@ async function spawnCoana(args, orgSlug, options, extra) {
|
|
|
2858
2866
|
};
|
|
2859
2867
|
} catch (e) {
|
|
2860
2868
|
const stderr = e?.stderr;
|
|
2861
|
-
const
|
|
2869
|
+
const cause = e?.message || constants.UNKNOWN_ERROR;
|
|
2870
|
+
const message = stderr ? stderr : cause;
|
|
2862
2871
|
return {
|
|
2863
2872
|
ok: false,
|
|
2864
2873
|
data: e,
|
|
@@ -2883,30 +2892,45 @@ function readOrDefaultSocketJson(cwd) {
|
|
|
2883
2892
|
// This should be unreachable but it makes TS happy.
|
|
2884
2893
|
getDefaultSocketJson();
|
|
2885
2894
|
}
|
|
2895
|
+
async function findSocketJsonUp(cwd) {
|
|
2896
|
+
return await findUp(constants.SOCKET_JSON, {
|
|
2897
|
+
onlyFiles: true,
|
|
2898
|
+
cwd
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
async function readOrDefaultSocketJsonUp(cwd) {
|
|
2902
|
+
const socketJsonPath = await findSocketJsonUp(cwd);
|
|
2903
|
+
if (socketJsonPath) {
|
|
2904
|
+
const socketJsonDir = path.dirname(socketJsonPath);
|
|
2905
|
+
const jsonCResult = readSocketJsonSync(socketJsonDir, true);
|
|
2906
|
+
return jsonCResult.ok ? jsonCResult.data : getDefaultSocketJson();
|
|
2907
|
+
}
|
|
2908
|
+
return getDefaultSocketJson();
|
|
2909
|
+
}
|
|
2886
2910
|
function getDefaultSocketJson() {
|
|
2887
2911
|
return {
|
|
2888
|
-
' _____ _ _ ':
|
|
2912
|
+
' _____ _ _ ': `Local config file for Socket CLI tool ( ${constants.SOCKET_WEBSITE_URL}/npm/package/${constants.SOCKET_JSON.replace('.json', '')} ), to work with ${constants.SOCKET_WEBSITE_URL}`,
|
|
2889
2913
|
'| __|___ ___| |_ ___| |_ ': ' The config in this file is used to set as defaults for flags or command args when using the CLI',
|
|
2890
2914
|
"|__ | . | _| '_| -_| _| ": ' in this dir, often a repo root. You can choose commit or .ignore this file, both works.',
|
|
2891
|
-
'|_____|___|___|_,_|___|_|.dev':
|
|
2915
|
+
'|_____|___|___|_,_|___|_|.dev': `Warning: This file may be overwritten without warning by \`${constants.SOCKET_JSON.replace('.json', '')} manifest setup\` or other commands`,
|
|
2892
2916
|
version: 1
|
|
2893
2917
|
};
|
|
2894
2918
|
}
|
|
2895
2919
|
function readSocketJsonSync(cwd, defaultOnError = false) {
|
|
2896
|
-
const sockJsonPath = path.join(cwd,
|
|
2920
|
+
const sockJsonPath = path.join(cwd, constants.SOCKET_JSON);
|
|
2897
2921
|
if (!fs$1.existsSync(sockJsonPath)) {
|
|
2898
|
-
require$$9.debugFn('notice', `miss:
|
|
2922
|
+
require$$9.debugFn('notice', `miss: ${constants.SOCKET_JSON} not found at ${cwd}`);
|
|
2899
2923
|
return {
|
|
2900
2924
|
ok: true,
|
|
2901
2925
|
data: getDefaultSocketJson()
|
|
2902
2926
|
};
|
|
2903
2927
|
}
|
|
2904
|
-
let
|
|
2928
|
+
let jsonContent = null;
|
|
2905
2929
|
try {
|
|
2906
|
-
|
|
2930
|
+
jsonContent = fs$1.readFileSync(sockJsonPath, 'utf8');
|
|
2907
2931
|
} catch (e) {
|
|
2908
2932
|
if (defaultOnError) {
|
|
2909
|
-
logger.logger.warn(
|
|
2933
|
+
logger.logger.warn(`Failed to read ${constants.SOCKET_JSON}, using default`);
|
|
2910
2934
|
require$$9.debugDir('inspect', {
|
|
2911
2935
|
error: e
|
|
2912
2936
|
});
|
|
@@ -2915,27 +2939,29 @@ function readSocketJsonSync(cwd, defaultOnError = false) {
|
|
|
2915
2939
|
data: getDefaultSocketJson()
|
|
2916
2940
|
};
|
|
2917
2941
|
}
|
|
2918
|
-
const
|
|
2942
|
+
const cause = e?.message;
|
|
2919
2943
|
require$$9.debugDir('inspect', {
|
|
2920
2944
|
error: e
|
|
2921
2945
|
});
|
|
2922
2946
|
return {
|
|
2923
2947
|
ok: false,
|
|
2924
|
-
message:
|
|
2925
|
-
cause: `An error occurred while trying to read
|
|
2948
|
+
message: `Failed to read ${constants.SOCKET_JSON}`,
|
|
2949
|
+
cause: `An error occurred while trying to read ${constants.SOCKET_JSON}${cause ? `: ${cause}` : ''}`
|
|
2926
2950
|
};
|
|
2927
2951
|
}
|
|
2928
|
-
let
|
|
2952
|
+
let jsonObj;
|
|
2929
2953
|
try {
|
|
2930
|
-
|
|
2954
|
+
jsonObj = JSON.parse(jsonContent);
|
|
2931
2955
|
} catch (e) {
|
|
2932
2956
|
require$$9.debugFn('error', 'caught: JSON.parse error');
|
|
2933
2957
|
require$$9.debugDir('inspect', {
|
|
2934
|
-
|
|
2935
|
-
|
|
2958
|
+
jsonContent
|
|
2959
|
+
});
|
|
2960
|
+
require$$9.debugDir('inspect', {
|
|
2961
|
+
error: e
|
|
2936
2962
|
});
|
|
2937
2963
|
if (defaultOnError) {
|
|
2938
|
-
logger.logger.warn(
|
|
2964
|
+
logger.logger.warn(`Failed to parse ${constants.SOCKET_JSON}, using default`);
|
|
2939
2965
|
return {
|
|
2940
2966
|
ok: true,
|
|
2941
2967
|
data: getDefaultSocketJson()
|
|
@@ -2943,11 +2969,11 @@ function readSocketJsonSync(cwd, defaultOnError = false) {
|
|
|
2943
2969
|
}
|
|
2944
2970
|
return {
|
|
2945
2971
|
ok: false,
|
|
2946
|
-
message:
|
|
2947
|
-
cause:
|
|
2972
|
+
message: `Failed to parse ${constants.SOCKET_JSON}`,
|
|
2973
|
+
cause: `${constants.SOCKET_JSON} does not contain valid JSON, please verify`
|
|
2948
2974
|
};
|
|
2949
2975
|
}
|
|
2950
|
-
if (!
|
|
2976
|
+
if (!jsonObj) {
|
|
2951
2977
|
logger.logger.warn('Warning: file contents was empty, using default');
|
|
2952
2978
|
return {
|
|
2953
2979
|
ok: true,
|
|
@@ -2955,17 +2981,17 @@ function readSocketJsonSync(cwd, defaultOnError = false) {
|
|
|
2955
2981
|
};
|
|
2956
2982
|
}
|
|
2957
2983
|
|
|
2958
|
-
// Do we
|
|
2959
|
-
// to check every step of the way regardless.
|
|
2984
|
+
// TODO: Do we need to validate? All properties are optional so code will have
|
|
2985
|
+
// to check every step of the way regardless.
|
|
2960
2986
|
return {
|
|
2961
2987
|
ok: true,
|
|
2962
|
-
data:
|
|
2988
|
+
data: jsonObj
|
|
2963
2989
|
};
|
|
2964
2990
|
}
|
|
2965
2991
|
async function writeSocketJson(cwd, sockJson) {
|
|
2966
|
-
let
|
|
2992
|
+
let jsonContent = '';
|
|
2967
2993
|
try {
|
|
2968
|
-
|
|
2994
|
+
jsonContent = JSON.stringify(sockJson, null, 2);
|
|
2969
2995
|
} catch (e) {
|
|
2970
2996
|
require$$9.debugFn('error', 'caught: JSON.stringify error');
|
|
2971
2997
|
require$$9.debugDir('inspect', {
|
|
@@ -2975,11 +3001,11 @@ async function writeSocketJson(cwd, sockJson) {
|
|
|
2975
3001
|
return {
|
|
2976
3002
|
ok: false,
|
|
2977
3003
|
message: 'Failed to serialize to JSON',
|
|
2978
|
-
cause:
|
|
3004
|
+
cause: `There was an unexpected problem converting the ${constants.SOCKET_JSON} object to a JSON string. Unable to store it.`
|
|
2979
3005
|
};
|
|
2980
3006
|
}
|
|
2981
|
-
const filepath = path.join(cwd,
|
|
2982
|
-
await fs$1.promises.writeFile(filepath,
|
|
3007
|
+
const filepath = path.join(cwd, constants.SOCKET_JSON);
|
|
3008
|
+
await fs$1.promises.writeFile(filepath, `${jsonContent}\n`, 'utf8');
|
|
2983
3009
|
return {
|
|
2984
3010
|
ok: true,
|
|
2985
3011
|
data: undefined
|
|
@@ -3065,7 +3091,11 @@ async function fetchGhsaDetails(ids) {
|
|
|
3065
3091
|
}
|
|
3066
3092
|
}
|
|
3067
3093
|
} catch (e) {
|
|
3068
|
-
|
|
3094
|
+
const cause = e?.message;
|
|
3095
|
+
require$$9.debugFn('error', `Failed to fetch GHSA details${cause ? `: ${cause}` : ''}`);
|
|
3096
|
+
require$$9.debugDir('inspect', {
|
|
3097
|
+
error: e
|
|
3098
|
+
});
|
|
3069
3099
|
}
|
|
3070
3100
|
return results;
|
|
3071
3101
|
}
|
|
@@ -3364,6 +3394,58 @@ function captureExceptionSync(exception, hint) {
|
|
|
3364
3394
|
return Sentry.captureException(exception, hint);
|
|
3365
3395
|
}
|
|
3366
3396
|
|
|
3397
|
+
function exitWithBinPathError$1(binName) {
|
|
3398
|
+
logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
|
|
3399
|
+
// The exit code 127 indicates that the command or binary being executed
|
|
3400
|
+
// could not be found.
|
|
3401
|
+
// eslint-disable-next-line n/no-process-exit
|
|
3402
|
+
process.exit(127);
|
|
3403
|
+
}
|
|
3404
|
+
let _yarnBinPath;
|
|
3405
|
+
function getYarnBinPath() {
|
|
3406
|
+
if (_yarnBinPath === undefined) {
|
|
3407
|
+
_yarnBinPath = getYarnBinPathDetails().path;
|
|
3408
|
+
if (!_yarnBinPath) {
|
|
3409
|
+
exitWithBinPathError$1(constants.default.YARN);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
return _yarnBinPath;
|
|
3413
|
+
}
|
|
3414
|
+
let _yarnBinPathDetails;
|
|
3415
|
+
function getYarnBinPathDetails() {
|
|
3416
|
+
if (_yarnBinPathDetails === undefined) {
|
|
3417
|
+
_yarnBinPathDetails = findBinPathDetailsSync(constants.default.YARN);
|
|
3418
|
+
}
|
|
3419
|
+
return _yarnBinPathDetails;
|
|
3420
|
+
}
|
|
3421
|
+
function isYarnBinPathShadowed() {
|
|
3422
|
+
return getYarnBinPathDetails().shadowed;
|
|
3423
|
+
}
|
|
3424
|
+
|
|
3425
|
+
let _isYarnBerry;
|
|
3426
|
+
function isYarnBerry() {
|
|
3427
|
+
if (_isYarnBerry === undefined) {
|
|
3428
|
+
try {
|
|
3429
|
+
const yarnBinPath = getYarnBinPath();
|
|
3430
|
+
const result = spawn.spawnSync(yarnBinPath, ['--version'], {
|
|
3431
|
+
encoding: 'utf8',
|
|
3432
|
+
shell: constants.default.WIN32
|
|
3433
|
+
});
|
|
3434
|
+
if (result.status === 0 && result.stdout) {
|
|
3435
|
+
const version = result.stdout;
|
|
3436
|
+
// Yarn Berry starts from version 2.x
|
|
3437
|
+
const majorVersion = parseInt(version.split('.')[0], 10);
|
|
3438
|
+
_isYarnBerry = majorVersion >= 2;
|
|
3439
|
+
} else {
|
|
3440
|
+
_isYarnBerry = false;
|
|
3441
|
+
}
|
|
3442
|
+
} catch {
|
|
3443
|
+
_isYarnBerry = false;
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
return _isYarnBerry;
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3367
3449
|
function npa(...args) {
|
|
3368
3450
|
try {
|
|
3369
3451
|
return Reflect.apply(vendor.npaExports, undefined, args);
|
|
@@ -3532,10 +3614,10 @@ const LOCKS = {
|
|
|
3532
3614
|
// will be ignored.
|
|
3533
3615
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#package-lockjson-vs-npm-shrinkwrapjson
|
|
3534
3616
|
'npm-shrinkwrap.json': NPM,
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
'pnpm-lock.yml': PNPM,
|
|
3538
|
-
[
|
|
3617
|
+
[constants.PACKAGE_LOCK_JSON]: NPM,
|
|
3618
|
+
[constants.PNPM_LOCK_YAML]: PNPM,
|
|
3619
|
+
['pnpm-lock.yml']: PNPM,
|
|
3620
|
+
[constants.YARN_LOCK]: YARN_CLASSIC,
|
|
3539
3621
|
'vlt-lock.json': VLT,
|
|
3540
3622
|
// Lastly, look for a hidden lock file which is present if .npmrc has package-lock=false:
|
|
3541
3623
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-lock-json#hidden-lockfiles
|
|
@@ -3807,6 +3889,105 @@ function getEcosystemChoicesForMeow() {
|
|
|
3807
3889
|
return [...ALL_ECOSYSTEMS];
|
|
3808
3890
|
}
|
|
3809
3891
|
|
|
3892
|
+
function exitWithBinPathError(binName) {
|
|
3893
|
+
logger.logger.fail(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
|
|
3894
|
+
// The exit code 127 indicates that the command or binary being executed
|
|
3895
|
+
// could not be found.
|
|
3896
|
+
// eslint-disable-next-line n/no-process-exit
|
|
3897
|
+
process.exit(127);
|
|
3898
|
+
}
|
|
3899
|
+
let _pnpmBinPath;
|
|
3900
|
+
function getPnpmBinPath() {
|
|
3901
|
+
if (_pnpmBinPath === undefined) {
|
|
3902
|
+
_pnpmBinPath = getPnpmBinPathDetails().path;
|
|
3903
|
+
if (!_pnpmBinPath) {
|
|
3904
|
+
exitWithBinPathError('pnpm');
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
return _pnpmBinPath;
|
|
3908
|
+
}
|
|
3909
|
+
let _pnpmBinPathDetails;
|
|
3910
|
+
function getPnpmBinPathDetails() {
|
|
3911
|
+
if (_pnpmBinPathDetails === undefined) {
|
|
3912
|
+
_pnpmBinPathDetails = findBinPathDetailsSync('pnpm');
|
|
3913
|
+
}
|
|
3914
|
+
return _pnpmBinPathDetails;
|
|
3915
|
+
}
|
|
3916
|
+
function isPnpmBinPathShadowed() {
|
|
3917
|
+
return getPnpmBinPathDetails().shadowed;
|
|
3918
|
+
}
|
|
3919
|
+
|
|
3920
|
+
function toFilterConfig(obj) {
|
|
3921
|
+
const normalized = {
|
|
3922
|
+
__proto__: null
|
|
3923
|
+
};
|
|
3924
|
+
const keys = require$$11.isObject(obj) ? Object.keys(obj) : [];
|
|
3925
|
+
for (const key of keys) {
|
|
3926
|
+
const value = obj[key];
|
|
3927
|
+
if (typeof value === 'boolean' || Array.isArray(value)) {
|
|
3928
|
+
normalized[key] = value;
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
return normalized;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
function idToNpmPurl(id) {
|
|
3935
|
+
return `pkg:${constants.NPM}/${id}`;
|
|
3936
|
+
}
|
|
3937
|
+
|
|
3938
|
+
async function extractPurlsFromPnpmLockfile(lockfile) {
|
|
3939
|
+
const packages = lockfile?.packages ?? {};
|
|
3940
|
+
const seen = new Set();
|
|
3941
|
+
const visit = pkgPath => {
|
|
3942
|
+
if (seen.has(pkgPath)) {
|
|
3943
|
+
return;
|
|
3944
|
+
}
|
|
3945
|
+
const pkg = packages[pkgPath];
|
|
3946
|
+
if (!pkg) {
|
|
3947
|
+
return;
|
|
3948
|
+
}
|
|
3949
|
+
seen.add(pkgPath);
|
|
3950
|
+
const deps = {
|
|
3951
|
+
__proto__: null,
|
|
3952
|
+
...pkg.dependencies,
|
|
3953
|
+
...pkg.optionalDependencies,
|
|
3954
|
+
...pkg.devDependencies
|
|
3955
|
+
};
|
|
3956
|
+
for (const depName in deps) {
|
|
3957
|
+
const ref = deps[depName];
|
|
3958
|
+
const subKey = isPnpmDepPath(ref) ? ref : `/${depName}@${ref}`;
|
|
3959
|
+
visit(subKey);
|
|
3960
|
+
}
|
|
3961
|
+
};
|
|
3962
|
+
for (const pkgPath of Object.keys(packages)) {
|
|
3963
|
+
visit(pkgPath);
|
|
3964
|
+
}
|
|
3965
|
+
return Array.from(seen).map(p => idToNpmPurl(stripPnpmPeerSuffix(stripLeadingPnpmDepPathSlash(p))));
|
|
3966
|
+
}
|
|
3967
|
+
function isPnpmDepPath(maybeDepPath) {
|
|
3968
|
+
return maybeDepPath.length > 0 && maybeDepPath.charCodeAt(0) === 47; /*'/'*/
|
|
3969
|
+
}
|
|
3970
|
+
function parsePnpmLockfile(lockfileContent) {
|
|
3971
|
+
let result;
|
|
3972
|
+
if (typeof lockfileContent === 'string') {
|
|
3973
|
+
try {
|
|
3974
|
+
result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
|
|
3975
|
+
} catch {}
|
|
3976
|
+
}
|
|
3977
|
+
return require$$11.isObjectObject(result) ? result : null;
|
|
3978
|
+
}
|
|
3979
|
+
async function readPnpmLockfile(lockfilePath) {
|
|
3980
|
+
return fs$1.existsSync(lockfilePath) ? await fs.readFileUtf8(lockfilePath) : undefined;
|
|
3981
|
+
}
|
|
3982
|
+
function stripLeadingPnpmDepPathSlash(depPath) {
|
|
3983
|
+
return isPnpmDepPath(depPath) ? depPath.slice(1) : depPath;
|
|
3984
|
+
}
|
|
3985
|
+
function stripPnpmPeerSuffix(depPath) {
|
|
3986
|
+
const parenIndex = depPath.indexOf('(');
|
|
3987
|
+
const index = parenIndex === -1 ? depPath.indexOf('_') : parenIndex;
|
|
3988
|
+
return index === -1 ? depPath : depPath.slice(0, index);
|
|
3989
|
+
}
|
|
3990
|
+
|
|
3810
3991
|
function isArtifactAlertCve(alert) {
|
|
3811
3992
|
const {
|
|
3812
3993
|
type
|
|
@@ -3870,20 +4051,6 @@ class ColorOrMarkdown {
|
|
|
3870
4051
|
}
|
|
3871
4052
|
}
|
|
3872
4053
|
|
|
3873
|
-
function toFilterConfig(obj) {
|
|
3874
|
-
const normalized = {
|
|
3875
|
-
__proto__: null
|
|
3876
|
-
};
|
|
3877
|
-
const keys = require$$11.isObject(obj) ? Object.keys(obj) : [];
|
|
3878
|
-
for (const key of keys) {
|
|
3879
|
-
const value = obj[key];
|
|
3880
|
-
if (typeof value === 'boolean' || Array.isArray(value)) {
|
|
3881
|
-
normalized[key] = value;
|
|
3882
|
-
}
|
|
3883
|
-
}
|
|
3884
|
-
return normalized;
|
|
3885
|
-
}
|
|
3886
|
-
|
|
3887
4054
|
const require$1 = require$$5.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('utils.js', document.baseURI).href)));
|
|
3888
4055
|
let _translations;
|
|
3889
4056
|
function getTranslations() {
|
|
@@ -4237,10 +4404,13 @@ function logAlertsMap(alertsMap, options) {
|
|
|
4237
4404
|
output.write('\n');
|
|
4238
4405
|
}
|
|
4239
4406
|
|
|
4240
|
-
function
|
|
4241
|
-
|
|
4407
|
+
async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
4408
|
+
const purls = await extractPurlsFromPnpmLockfile(lockfile);
|
|
4409
|
+
return await getAlertsMapFromPurls(purls, {
|
|
4410
|
+
overrides: lockfile.overrides,
|
|
4411
|
+
...options
|
|
4412
|
+
});
|
|
4242
4413
|
}
|
|
4243
|
-
|
|
4244
4414
|
async function getAlertsMapFromPurls(purls, options) {
|
|
4245
4415
|
const uniqPurls = arrays.arrayUnique(purls);
|
|
4246
4416
|
require$$9.debugDir('silly', {
|
|
@@ -4274,11 +4444,11 @@ async function getAlertsMapFromPurls(purls, options) {
|
|
|
4274
4444
|
});
|
|
4275
4445
|
if (!sockSdkCResult.ok) {
|
|
4276
4446
|
spinner?.stop();
|
|
4277
|
-
throw new Error('Auth error: Run `socket login` first');
|
|
4447
|
+
throw new Error('Auth error: Run `socket login` first.');
|
|
4278
4448
|
}
|
|
4279
4449
|
const sockSdk = sockSdkCResult.data;
|
|
4280
4450
|
const socketYmlResult = findSocketYmlSync();
|
|
4281
|
-
const socketYml = socketYmlResult.ok ? socketYmlResult.data.parsed : undefined;
|
|
4451
|
+
const socketYml = socketYmlResult.ok && socketYmlResult.data ? socketYmlResult.data.parsed : undefined;
|
|
4282
4452
|
const alertsMapOptions = {
|
|
4283
4453
|
consolidate: opts.consolidate,
|
|
4284
4454
|
filter: opts.filter,
|
|
@@ -4357,6 +4527,7 @@ exports.fetchGhsaDetails = fetchGhsaDetails;
|
|
|
4357
4527
|
exports.fetchOrganization = fetchOrganization;
|
|
4358
4528
|
exports.filterFlags = filterFlags;
|
|
4359
4529
|
exports.findUp = findUp;
|
|
4530
|
+
exports.getAlertsMapFromPnpmLockfile = getAlertsMapFromPnpmLockfile;
|
|
4360
4531
|
exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
|
|
4361
4532
|
exports.getBaseBranch = getBaseBranch;
|
|
4362
4533
|
exports.getBashrcDetails = getBashrcDetails;
|
|
@@ -4376,6 +4547,7 @@ exports.getOctokitGraphql = getOctokitGraphql;
|
|
|
4376
4547
|
exports.getOrgSlugs = getOrgSlugs;
|
|
4377
4548
|
exports.getOutputKind = getOutputKind;
|
|
4378
4549
|
exports.getPackageFilesForScan = getPackageFilesForScan;
|
|
4550
|
+
exports.getPnpmBinPath = getPnpmBinPath;
|
|
4379
4551
|
exports.getPublicApiToken = getPublicApiToken;
|
|
4380
4552
|
exports.getPurlObject = getPurlObject;
|
|
4381
4553
|
exports.getRepoInfo = getRepoInfo;
|
|
@@ -4384,6 +4556,7 @@ exports.getSocketDevPackageOverviewUrlFromPurl = getSocketDevPackageOverviewUrlF
|
|
|
4384
4556
|
exports.getSupportedConfigEntries = getSupportedConfigEntries;
|
|
4385
4557
|
exports.getSupportedConfigKeys = getSupportedConfigKeys;
|
|
4386
4558
|
exports.getVisibleTokenPrefix = getVisibleTokenPrefix;
|
|
4559
|
+
exports.getYarnBinPath = getYarnBinPath;
|
|
4387
4560
|
exports.gitBranch = gitBranch;
|
|
4388
4561
|
exports.gitCheckoutBranch = gitCheckoutBranch;
|
|
4389
4562
|
exports.gitCommit = gitCommit;
|
|
@@ -4402,10 +4575,13 @@ exports.idToNpmPurl = idToNpmPurl;
|
|
|
4402
4575
|
exports.isHelpFlag = isHelpFlag;
|
|
4403
4576
|
exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
|
|
4404
4577
|
exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
|
|
4578
|
+
exports.isPnpmBinPathShadowed = isPnpmBinPathShadowed;
|
|
4405
4579
|
exports.isReadOnlyConfig = isReadOnlyConfig;
|
|
4406
4580
|
exports.isReportSupportedFile = isReportSupportedFile;
|
|
4407
4581
|
exports.isSensitiveConfigKey = isSensitiveConfigKey;
|
|
4408
4582
|
exports.isSupportedConfigKey = isSupportedConfigKey;
|
|
4583
|
+
exports.isYarnBerry = isYarnBerry;
|
|
4584
|
+
exports.isYarnBinPathShadowed = isYarnBinPathShadowed;
|
|
4409
4585
|
exports.logAlertsMap = logAlertsMap;
|
|
4410
4586
|
exports.mapToObject = mapToObject;
|
|
4411
4587
|
exports.mdTable = mdTable;
|
|
@@ -4416,9 +4592,12 @@ exports.meowWithSubcommands = meowWithSubcommands;
|
|
|
4416
4592
|
exports.msAtHome = msAtHome;
|
|
4417
4593
|
exports.normalizePurl = normalizePurl;
|
|
4418
4594
|
exports.npa = npa;
|
|
4595
|
+
exports.parsePnpmLockfile = parsePnpmLockfile;
|
|
4419
4596
|
exports.queryApiSafeJson = queryApiSafeJson;
|
|
4420
4597
|
exports.queryApiSafeText = queryApiSafeText;
|
|
4421
4598
|
exports.readOrDefaultSocketJson = readOrDefaultSocketJson;
|
|
4599
|
+
exports.readOrDefaultSocketJsonUp = readOrDefaultSocketJsonUp;
|
|
4600
|
+
exports.readPnpmLockfile = readPnpmLockfile;
|
|
4422
4601
|
exports.readSocketJsonSync = readSocketJsonSync;
|
|
4423
4602
|
exports.runAgentInstall = runAgentInstall;
|
|
4424
4603
|
exports.sendApiRequest = sendApiRequest;
|
|
@@ -4432,5 +4611,5 @@ exports.toFilterConfig = toFilterConfig;
|
|
|
4432
4611
|
exports.updateConfigValue = updateConfigValue;
|
|
4433
4612
|
exports.walkNestedMap = walkNestedMap;
|
|
4434
4613
|
exports.writeSocketJson = writeSocketJson;
|
|
4435
|
-
//# debugId=
|
|
4614
|
+
//# debugId=1da7b4a0-f584-4be9-bf6b-9269a66c830
|
|
4436
4615
|
//# sourceMappingURL=utils.js.map
|