@socketsecurity/cli 0.14.35 → 0.14.36
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 +11 -7
- package/bin/npm-cli.js +2 -2
- package/bin/npx-cli.js +2 -2
- package/dist/constants.js +62 -22
- package/dist/module-sync/cli.js +194 -170
- package/dist/module-sync/constants.d.ts +7 -0
- package/dist/module-sync/constants.d.ts.map +1 -1
- package/dist/module-sync/npm-injection.js +1 -1
- package/dist/module-sync/path-resolve.d.ts +6 -1
- package/dist/module-sync/path-resolve.js +31 -4
- package/dist/module-sync/shadow-bin.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +17 -23
- package/dist/require/cli.js +194 -170
- package/dist/require/constants.d.ts.map +1 -1
- package/dist/require/npm-injection.js +1 -1
- package/dist/require/path-resolve.js +31 -4
- package/dist/require/shadow-bin.js +17 -23
- package/package.json +5 -5
|
@@ -2,13 +2,20 @@ import registryConstants from '@socketsecurity/registry/lib/constants';
|
|
|
2
2
|
type RegistryEnv = typeof registryConstants.ENV;
|
|
3
3
|
type Constants = {
|
|
4
4
|
readonly API_V0_URL: 'https://api.socket.dev/v0';
|
|
5
|
+
readonly BABEL_RUNTIME: '@babel/runtime';
|
|
6
|
+
readonly BUN: 'bun';
|
|
5
7
|
readonly ENV: RegistryEnv & {
|
|
6
8
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean;
|
|
7
9
|
};
|
|
8
10
|
readonly DIST_TYPE: 'module-sync' | 'require';
|
|
9
11
|
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org';
|
|
12
|
+
readonly NPX: 'npx';
|
|
13
|
+
readonly PNPM: 'pnpm';
|
|
10
14
|
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues';
|
|
11
15
|
readonly UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE';
|
|
16
|
+
readonly VLT: 'vlt';
|
|
17
|
+
readonly YARN_BERRY: 'yarn/berry';
|
|
18
|
+
readonly YARN_CLASSIC: 'yarn/classic';
|
|
12
19
|
readonly cdxgenBinPath: string;
|
|
13
20
|
readonly distPath: string;
|
|
14
21
|
readonly nmBinPath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAEtE,KAAK,WAAW,GAAG,OAAO,iBAAiB,CAAC,GAAG,CAAA;AAE/C,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAA;IAChD,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG;QAC1B,4CAA4C,EAAE,OAAO,CAAA;KACtD,CAAA;IACD,QAAQ,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAA;IACvD,QAAQ,CAAC,qBAAqB,EAAE,gDAAgD,CAAA;IAChF,QAAQ,CAAC,4CAA4C,EAAE,8CAA8C,CAAA;IACrG,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","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AAA;AAsE5B,QAAA,MAAM,SAAS,WA0Cd,CAAA"}
|
|
@@ -3,6 +3,11 @@ import { SocketYml } from '@socketsecurity/config';
|
|
|
3
3
|
import { SocketSdkReturnType } from '@socketsecurity/sdk';
|
|
4
4
|
declare function directoryPatterns(): string[];
|
|
5
5
|
declare function findRoot(filepath: string): string | undefined;
|
|
6
|
+
declare function findBinPathDetails(binName: string): Promise<{
|
|
7
|
+
name: string;
|
|
8
|
+
path: string | undefined;
|
|
9
|
+
shadowed: boolean;
|
|
10
|
+
}>;
|
|
6
11
|
declare function getPackageFiles(cwd: string, inputPaths: string[], config: SocketYml | undefined, supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], debugLog?: typeof console.error): Promise<string[]>;
|
|
7
12
|
declare function getPackageFilesFullScans(cwd: string, inputPaths: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], debugLog?: typeof console.error): Promise<string[]>;
|
|
8
|
-
export { directoryPatterns, findRoot, getPackageFiles, getPackageFilesFullScans };
|
|
13
|
+
export { directoryPatterns, findRoot, findBinPathDetails, getPackageFiles, getPackageFilesFullScans };
|
|
@@ -9,11 +9,13 @@ function _socketInterop(e) {
|
|
|
9
9
|
return c ? e.default : e
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
var fs = require('node:fs
|
|
12
|
+
var fs = require('node:fs');
|
|
13
13
|
var path = require('node:path');
|
|
14
14
|
var ignore = _socketInterop(require('ignore'));
|
|
15
15
|
var micromatch = _socketInterop(require('micromatch'));
|
|
16
16
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
17
|
+
var which = _socketInterop(require('which'));
|
|
18
|
+
var constants = require('./constants.js');
|
|
17
19
|
|
|
18
20
|
const ignoredDirs = [
|
|
19
21
|
// Taken from ignore-by-default:
|
|
@@ -42,8 +44,12 @@ function directoryPatterns() {
|
|
|
42
44
|
return [...ignoredDirPatterns];
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
const {
|
|
48
|
+
NPM,
|
|
49
|
+
shadowBinPath
|
|
50
|
+
} = constants;
|
|
45
51
|
async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
|
|
46
|
-
const patterns = ['golang',
|
|
52
|
+
const patterns = ['golang', NPM, 'pypi'].reduce((r, n) => {
|
|
47
53
|
const supported = supportedFiles[n];
|
|
48
54
|
r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
|
|
49
55
|
return r;
|
|
@@ -65,7 +71,7 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
65
71
|
cwd,
|
|
66
72
|
expandDirectories: true
|
|
67
73
|
});
|
|
68
|
-
const ignores = [...directoryPatterns(), ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns(await fs.readFile(filepath, 'utf8'), filepath, cwd)))).flat()];
|
|
74
|
+
const ignores = [...directoryPatterns(), ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns(await fs.promises.readFile(filepath, 'utf8'), filepath, cwd)))).flat()];
|
|
69
75
|
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
|
|
70
76
|
const globOptions = {
|
|
71
77
|
absolute: true,
|
|
@@ -133,7 +139,7 @@ function pathsToPatterns(paths) {
|
|
|
133
139
|
function findRoot(filepath) {
|
|
134
140
|
let curPath = filepath;
|
|
135
141
|
while (true) {
|
|
136
|
-
if (path.basename(curPath) ===
|
|
142
|
+
if (path.basename(curPath) === NPM) {
|
|
137
143
|
return curPath;
|
|
138
144
|
}
|
|
139
145
|
const parent = path.dirname(curPath);
|
|
@@ -143,6 +149,26 @@ function findRoot(filepath) {
|
|
|
143
149
|
curPath = parent;
|
|
144
150
|
}
|
|
145
151
|
}
|
|
152
|
+
async function findBinPathDetails(binName) {
|
|
153
|
+
let shadowIndex = -1;
|
|
154
|
+
const bins = (await which(binName, {
|
|
155
|
+
all: true,
|
|
156
|
+
nothrow: true
|
|
157
|
+
})) ?? [];
|
|
158
|
+
const binPath = bins.find((binPath, i) => {
|
|
159
|
+
// Skip our bin directory if it's in the front.
|
|
160
|
+
if (fs.realpathSync(path.dirname(binPath)) === shadowBinPath) {
|
|
161
|
+
shadowIndex = i;
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
name: binName,
|
|
168
|
+
path: binPath,
|
|
169
|
+
shadowed: shadowIndex !== -1
|
|
170
|
+
};
|
|
171
|
+
}
|
|
146
172
|
async function getPackageFiles(cwd, inputPaths, config, supportedFiles, debugLog = () => {}) {
|
|
147
173
|
debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
|
|
148
174
|
|
|
@@ -169,6 +195,7 @@ async function getPackageFilesFullScans(cwd, inputPaths, supportedFiles, debugLo
|
|
|
169
195
|
return packageFiles;
|
|
170
196
|
}
|
|
171
197
|
|
|
198
|
+
exports.findBinPathDetails = findBinPathDetails;
|
|
172
199
|
exports.findRoot = findRoot;
|
|
173
200
|
exports.getPackageFiles = getPackageFiles;
|
|
174
201
|
exports.getPackageFilesFullScans = getPackageFilesFullScans;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function shadow(binName: 'npm' | 'npx'): Promise<void>;
|
|
1
|
+
declare function shadow(binName: 'npm' | 'npx', binArgs?: string[]): Promise<void>;
|
|
2
2
|
export { shadow as default };
|
|
@@ -14,7 +14,6 @@ var path = require('node:path');
|
|
|
14
14
|
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
15
15
|
var constants = require('./constants.js');
|
|
16
16
|
var cmdShim = _socketInterop(require('cmd-shim'));
|
|
17
|
-
var which = _socketInterop(require('which'));
|
|
18
17
|
var pathResolve = require('./path-resolve.js');
|
|
19
18
|
|
|
20
19
|
const {
|
|
@@ -23,23 +22,14 @@ const {
|
|
|
23
22
|
} = constants;
|
|
24
23
|
async function installLinks(realBinPath, binName) {
|
|
25
24
|
// Find package manager being shadowed by this process.
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
let shadowIndex = -1;
|
|
31
|
-
const binPath = bins.find((binPath, i) => {
|
|
32
|
-
// Skip our bin directory if it's in the front.
|
|
33
|
-
if (fs.realpathSync(path.dirname(binPath)) === realBinPath) {
|
|
34
|
-
shadowIndex = i;
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
38
|
-
});
|
|
25
|
+
const {
|
|
26
|
+
path: binPath,
|
|
27
|
+
shadowed
|
|
28
|
+
} = await pathResolve.findBinPathDetails(binName);
|
|
39
29
|
if (!binPath) {
|
|
40
|
-
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
|
|
41
30
|
// The exit code 127 indicates that the command or binary being executed
|
|
42
31
|
// could not be found.
|
|
32
|
+
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
43
33
|
process.exit(127);
|
|
44
34
|
}
|
|
45
35
|
// TODO: Is this early exit needed?
|
|
@@ -47,23 +37,24 @@ async function installLinks(realBinPath, binName) {
|
|
|
47
37
|
return binPath;
|
|
48
38
|
}
|
|
49
39
|
// Move our bin directory to front of PATH so its found first.
|
|
50
|
-
if (
|
|
40
|
+
if (!shadowed) {
|
|
51
41
|
if (WIN32) {
|
|
52
42
|
await cmdShim(path.join(rootDistPath, `${binName}-cli.js`), path.join(realBinPath, binName));
|
|
53
43
|
}
|
|
54
|
-
process.env['PATH'] = `${realBinPath}${
|
|
44
|
+
process.env['PATH'] = `${realBinPath}${path.delimiter}${process.env['PATH']}`;
|
|
55
45
|
}
|
|
56
46
|
return binPath;
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
const {
|
|
50
|
+
NPM,
|
|
60
51
|
abortSignal,
|
|
61
52
|
distPath,
|
|
62
53
|
execPath,
|
|
63
54
|
shadowBinPath
|
|
64
55
|
} = constants;
|
|
65
56
|
const injectionPath = path.join(distPath, 'npm-injection.js');
|
|
66
|
-
async function shadow(binName) {
|
|
57
|
+
async function shadow(binName, binArgs = process.argv.slice(2)) {
|
|
67
58
|
const binPath = await installLinks(shadowBinPath, binName);
|
|
68
59
|
if (abortSignal.aborted) {
|
|
69
60
|
return;
|
|
@@ -71,8 +62,7 @@ async function shadow(binName) {
|
|
|
71
62
|
// Adding the `--quiet` and `--no-progress` flags when the `proc-log` module
|
|
72
63
|
// is found to fix a UX issue when running the command with recent versions of
|
|
73
64
|
// npm (input swallowed by the standard npm spinner)
|
|
74
|
-
|
|
75
|
-
if (binName === 'npm' && binArgs.includes('install') && !binArgs.includes('--no-progress') && !binArgs.includes('--quiet')) {
|
|
65
|
+
if (binName === NPM && binArgs.includes('install') && !binArgs.includes('--no-progress') && !binArgs.includes('--quiet')) {
|
|
76
66
|
const npmEntrypoint = fs.realpathSync(binPath);
|
|
77
67
|
const npmRootPath = pathResolve.findRoot(path.dirname(npmEntrypoint));
|
|
78
68
|
if (npmRootPath === undefined) {
|
|
@@ -96,9 +86,13 @@ async function shadow(binName) {
|
|
|
96
86
|
signal: abortSignal,
|
|
97
87
|
stdio: 'inherit'
|
|
98
88
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
// See https://nodejs.org/api/all.html#all_child_process_event-exit.
|
|
90
|
+
spawnPromise.process.on('exit', (code, signalName) => {
|
|
91
|
+
if (abortSignal.aborted) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (signalName) {
|
|
95
|
+
process.kill(process.pid, signalName);
|
|
102
96
|
} else if (code !== null) {
|
|
103
97
|
process.exit(code);
|
|
104
98
|
}
|