@socketsecurity/cli 0.14.42 → 0.14.44
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/README.md +16 -38
- package/bin/cli.js +17 -7
- package/bin/npm-cli.js +1 -1
- package/bin/npx-cli.js +1 -1
- package/dist/constants.d.ts +121 -11
- package/dist/constants.js +91 -10
- package/dist/constants.js.map +1 -0
- package/dist/init.gradle +250 -0
- package/dist/module-sync/cli.js +6115 -3836
- package/dist/module-sync/cli.js.map +1 -0
- package/dist/module-sync/edge.d.ts +66 -0
- package/dist/module-sync/errors.d.ts +6 -1
- package/dist/module-sync/index.d.ts +192 -0
- package/dist/module-sync/index.js +1879 -0
- package/dist/module-sync/index.js.map +1 -0
- package/dist/module-sync/logging.d.ts +3 -3
- package/dist/module-sync/node.d.ts +84 -0
- package/dist/module-sync/npm-injection.js +7 -1495
- package/dist/module-sync/npm-injection.js.map +1 -0
- package/dist/module-sync/npm-paths.d.ts +3 -2
- package/dist/module-sync/npm-paths.js +91 -42
- package/dist/module-sync/npm-paths.js.map +1 -0
- package/dist/module-sync/npm.d.ts +24 -0
- package/dist/module-sync/npm.js +99 -0
- package/dist/module-sync/npm.js.map +1 -0
- package/dist/module-sync/path-resolve.d.ts +1 -1
- package/dist/module-sync/proc-log.d.ts +3 -0
- package/dist/module-sync/reify.d.ts +1018 -0
- package/dist/module-sync/sdk.d.ts +5 -0
- package/dist/module-sync/settings.d.ts +5 -4
- package/dist/module-sync/shadow-bin.d.ts +1 -1
- package/dist/module-sync/shadow-bin.js +33 -12
- package/dist/module-sync/shadow-bin.js.map +1 -0
- package/dist/module-sync/types.d.ts +45 -0
- package/dist/require/cli.js +6114 -3836
- package/dist/require/constants.js +1 -1
- package/dist/require/index.js +3 -0
- package/dist/require/npm.js +3 -0
- package/dist/require/vendor.js +2336 -6
- package/package.json +69 -42
- package/dist/constants.d.ts.map +0 -1
- package/dist/module-sync/socket-url.d.ts +0 -40
- package/dist/module-sync/socket-url.js +0 -301
- package/dist/require/socket-url.js +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm-injection.js","sources":["../../src/shadow/arborist/index.ts","../../src/shadow/npm-injection.ts"],"sourcesContent":["import { SafeArborist } from './lib/arborist'\nimport { SafeEdge } from './lib/edge'\nimport { SafeNode } from './lib/node'\nimport { SafeOverrideSet } from './lib/override-set'\nimport {\n getArboristClassPath,\n getArboristEdgeClassPath,\n getArboristNodeClassPath,\n getArboristOverrideSetClassPath\n} from '../npm-paths'\n\nexport function installSafeArborist() {\n // Override '@npmcli/arborist' module exports with patched variants based on\n // https://github.com/npm/cli/pull/7025.\n const cache: { [key: string]: any } = require.cache\n cache[getArboristClassPath()] = { exports: SafeArborist }\n cache[getArboristEdgeClassPath()] = { exports: SafeEdge }\n cache[getArboristNodeClassPath()] = { exports: SafeNode }\n cache[getArboristOverrideSetClassPath()] = { exports: SafeOverrideSet }\n}\n","import { installSafeArborist } from './arborist'\n\ninstallSafeArborist()\n"],"names":["cache","exports","installSafeArborist"],"mappings":";;;;;AAWO;AACL;AACA;AACA;AACAA;AAAkCC;;AAClCD;AAAsCC;;AACtCD;AAAsCC;;AACtCD;AAA6CC;;AAC/C;;ACjBAC","debugId":"dac61d14-9648-405b-a9b5-46614799a46c"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
declare function directoryPatterns(): string[];
|
|
2
3
|
declare function getNpmBinPath(): string;
|
|
3
4
|
declare function isNpmBinPathShadowed(): boolean;
|
|
4
5
|
declare function getNpxBinPath(): string;
|
|
5
6
|
declare function isNpxBinPathShadowed(): boolean;
|
|
6
7
|
declare function getNpmPath(): string;
|
|
7
|
-
declare function
|
|
8
|
+
declare function getNpmRequire(): NodeJS.Require;
|
|
8
9
|
declare function getArboristPackagePath(): string;
|
|
9
10
|
declare function getArboristClassPath(): string;
|
|
10
11
|
declare function getArboristDepValidPath(): string;
|
|
11
12
|
declare function getArboristEdgeClassPath(): string;
|
|
12
13
|
declare function getArboristNodeClassPath(): string;
|
|
13
14
|
declare function getArboristOverrideSetClassPath(): string;
|
|
14
|
-
export { directoryPatterns, getNpmBinPath, isNpmBinPathShadowed, getNpxBinPath, isNpxBinPathShadowed, getNpmPath,
|
|
15
|
+
export { directoryPatterns, getNpmBinPath, isNpmBinPathShadowed, getNpxBinPath, isNpxBinPathShadowed, getNpmPath, getNpmRequire, getArboristPackagePath, getArboristClassPath, getArboristDepValidPath, getArboristEdgeClassPath, getArboristNodeClassPath, getArboristOverrideSetClassPath };
|
|
@@ -10,8 +10,10 @@ function _socketInterop(e) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
var fs = require('node:fs');
|
|
13
|
+
var Module = require('node:module');
|
|
13
14
|
var path = require('node:path');
|
|
14
15
|
var process = require('node:process');
|
|
16
|
+
var path$1 = require('@socketsecurity/registry/lib/path');
|
|
15
17
|
var constants = require('./constants.js');
|
|
16
18
|
var ignore = _socketInterop(require('ignore'));
|
|
17
19
|
var micromatch = _socketInterop(require('micromatch'));
|
|
@@ -21,19 +23,25 @@ var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
|
21
23
|
var isUnicodeSupported = require('@socketregistry/is-unicode-supported/index.cjs');
|
|
22
24
|
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
let _logSymbols;
|
|
27
|
+
function getLogSymbols() {
|
|
28
|
+
if (_logSymbols === undefined) {
|
|
29
|
+
_logSymbols = isUnicodeSupported() ? {
|
|
30
|
+
__proto__: null,
|
|
31
|
+
info: colors.blue('ℹ'),
|
|
32
|
+
success: colors.green('✔'),
|
|
33
|
+
warning: colors.yellow('⚠'),
|
|
34
|
+
error: colors.red('✖️')
|
|
35
|
+
} : {
|
|
36
|
+
__proto__: null,
|
|
37
|
+
info: colors.blue('i'),
|
|
38
|
+
success: colors.green('√'),
|
|
39
|
+
warning: colors.yellow('‼'),
|
|
40
|
+
error: colors.red('×')
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return _logSymbols;
|
|
44
|
+
}
|
|
37
45
|
class Logger {
|
|
38
46
|
#spinnerLogger;
|
|
39
47
|
constructor() {
|
|
@@ -57,7 +65,7 @@ function isDebug() {
|
|
|
57
65
|
}
|
|
58
66
|
function debugLog(...args) {
|
|
59
67
|
if (isDebug()) {
|
|
60
|
-
console.error(
|
|
68
|
+
console.error(getLogSymbols().info, ...args);
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
|
|
@@ -89,11 +97,12 @@ function directoryPatterns() {
|
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
const {
|
|
100
|
+
NODE_MODULES: NODE_MODULES$1,
|
|
92
101
|
NPM: NPM$1,
|
|
93
102
|
shadowBinPath
|
|
94
103
|
} = constants;
|
|
95
104
|
async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
|
|
96
|
-
const patterns = ['golang', NPM$1, 'pypi'].reduce((r, n) => {
|
|
105
|
+
const patterns = ['golang', NPM$1, 'maven', 'pypi'].reduce((r, n) => {
|
|
97
106
|
const supported = supportedFiles[n];
|
|
98
107
|
r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
|
|
99
108
|
return r;
|
|
@@ -131,6 +140,9 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
131
140
|
const {
|
|
132
141
|
absolute
|
|
133
142
|
} = globOptions;
|
|
143
|
+
|
|
144
|
+
// Note: the input files must be INSIDE the cwd. If you get strange looking
|
|
145
|
+
// relative path errors here, most likely your path is outside the given cwd.
|
|
134
146
|
const filtered = ignore().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
|
|
135
147
|
return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
|
|
136
148
|
}
|
|
@@ -187,31 +199,59 @@ function findBinPathDetailsSync(binName) {
|
|
|
187
199
|
all: true,
|
|
188
200
|
nothrow: true
|
|
189
201
|
}) ?? [];
|
|
190
|
-
|
|
202
|
+
let binPath;
|
|
203
|
+
for (let i = 0, {
|
|
204
|
+
length
|
|
205
|
+
} = bins; i < length; i += 1) {
|
|
206
|
+
const bin = fs.realpathSync.native(bins[i]);
|
|
191
207
|
// Skip our bin directory if it's in the front.
|
|
192
|
-
if (
|
|
208
|
+
if (path.dirname(bin) === shadowBinPath) {
|
|
193
209
|
shadowIndex = i;
|
|
194
|
-
|
|
210
|
+
} else {
|
|
211
|
+
binPath = bin;
|
|
212
|
+
break;
|
|
195
213
|
}
|
|
196
|
-
|
|
197
|
-
});
|
|
214
|
+
}
|
|
198
215
|
return {
|
|
199
216
|
name: binName,
|
|
200
217
|
path: binPath,
|
|
201
218
|
shadowed: shadowIndex !== -1
|
|
202
219
|
};
|
|
203
220
|
}
|
|
204
|
-
function findNpmPathSync(
|
|
205
|
-
let
|
|
221
|
+
function findNpmPathSync(npmBinPath) {
|
|
222
|
+
let thePath = npmBinPath;
|
|
206
223
|
while (true) {
|
|
207
|
-
|
|
208
|
-
|
|
224
|
+
const nmPath = path.join(thePath, NODE_MODULES$1);
|
|
225
|
+
if (
|
|
226
|
+
// npm bin paths may look like:
|
|
227
|
+
// /usr/local/share/npm/bin/npm
|
|
228
|
+
// /Users/SomeUsername/.nvm/versions/node/vX.X.X/bin/npm
|
|
229
|
+
// C:\Users\SomeUsername\AppData\Roaming\npm\bin\npm.cmd
|
|
230
|
+
// OR
|
|
231
|
+
// C:\Program Files\nodejs\npm.cmd
|
|
232
|
+
//
|
|
233
|
+
// In all cases the npm path contains a node_modules folder:
|
|
234
|
+
// /usr/local/share/npm/bin/npm/node_modules
|
|
235
|
+
// C:\Program Files\nodejs\node_modules
|
|
236
|
+
//
|
|
237
|
+
// Use existsSync here because statsSync, even with { throwIfNoEntry: false },
|
|
238
|
+
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
|
|
239
|
+
// See https://github.com/nodejs/node/issues/56993.
|
|
240
|
+
fs.existsSync(nmPath) && fs.statSync(nmPath, {
|
|
241
|
+
throwIfNoEntry: false
|
|
242
|
+
})?.isDirectory() && (
|
|
243
|
+
// Optimistically look for the default location.
|
|
244
|
+
path.basename(thePath) === NPM$1 ||
|
|
245
|
+
// Chocolatey installs npm bins in the same directory as node bins.
|
|
246
|
+
// Lazily access constants.WIN32.
|
|
247
|
+
constants.WIN32 && fs.existsSync(path.join(thePath, `${NPM$1}.cmd`)))) {
|
|
248
|
+
return thePath;
|
|
209
249
|
}
|
|
210
|
-
const parent = path.dirname(
|
|
211
|
-
if (parent ===
|
|
250
|
+
const parent = path.dirname(thePath);
|
|
251
|
+
if (parent === thePath) {
|
|
212
252
|
return undefined;
|
|
213
253
|
}
|
|
214
|
-
|
|
254
|
+
thePath = parent;
|
|
215
255
|
}
|
|
216
256
|
}
|
|
217
257
|
async function getPackageFiles(cwd, inputPaths, config, supportedFiles) {
|
|
@@ -291,14 +331,15 @@ function isNpxBinPathShadowed() {
|
|
|
291
331
|
let _npmPath;
|
|
292
332
|
function getNpmPath() {
|
|
293
333
|
if (_npmPath === undefined) {
|
|
294
|
-
const
|
|
295
|
-
_npmPath = findNpmPathSync(
|
|
334
|
+
const npmBinPath = getNpmBinPath();
|
|
335
|
+
_npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined;
|
|
296
336
|
if (!_npmPath) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
337
|
+
let message = 'Unable to find npm CLI install directory.';
|
|
338
|
+
if (npmBinPath) {
|
|
339
|
+
message += `\nSearched parent directories of ${path.dirname(npmBinPath)}.`;
|
|
340
|
+
}
|
|
341
|
+
message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`;
|
|
342
|
+
console.error(message);
|
|
302
343
|
// The exit code 127 indicates that the command or binary being executed
|
|
303
344
|
// could not be found.
|
|
304
345
|
process.exit(127);
|
|
@@ -306,17 +347,23 @@ function getNpmPath() {
|
|
|
306
347
|
}
|
|
307
348
|
return _npmPath;
|
|
308
349
|
}
|
|
309
|
-
let
|
|
310
|
-
function
|
|
311
|
-
if (
|
|
312
|
-
|
|
350
|
+
let _npmRequire;
|
|
351
|
+
function getNpmRequire() {
|
|
352
|
+
if (_npmRequire === undefined) {
|
|
353
|
+
const npmPath = getNpmPath();
|
|
354
|
+
const npmNmPath = path.join(npmPath, NODE_MODULES, NPM);
|
|
355
|
+
_npmRequire = Module.createRequire(path.join(fs.existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'));
|
|
313
356
|
}
|
|
314
|
-
return
|
|
357
|
+
return _npmRequire;
|
|
315
358
|
}
|
|
316
359
|
let _arboristPkgPath;
|
|
317
360
|
function getArboristPackagePath() {
|
|
318
361
|
if (_arboristPkgPath === undefined) {
|
|
319
|
-
|
|
362
|
+
const pkgName = '@npmcli/arborist';
|
|
363
|
+
const mainPathWithForwardSlashes = path$1.normalizePath(getNpmRequire().resolve(pkgName));
|
|
364
|
+
const arboristPkgPathWithForwardSlashes = mainPathWithForwardSlashes.slice(0, mainPathWithForwardSlashes.lastIndexOf(pkgName) + pkgName.length);
|
|
365
|
+
// Lazily access constants.WIN32.
|
|
366
|
+
_arboristPkgPath = constants.WIN32 ? path.normalize(arboristPkgPathWithForwardSlashes) : arboristPkgPathWithForwardSlashes;
|
|
320
367
|
}
|
|
321
368
|
return _arboristPkgPath;
|
|
322
369
|
}
|
|
@@ -362,13 +409,15 @@ exports.getArboristDepValidPath = getArboristDepValidPath;
|
|
|
362
409
|
exports.getArboristEdgeClassPath = getArboristEdgeClassPath;
|
|
363
410
|
exports.getArboristNodeClassPath = getArboristNodeClassPath;
|
|
364
411
|
exports.getArboristOverrideSetClassPath = getArboristOverrideSetClassPath;
|
|
412
|
+
exports.getLogSymbols = getLogSymbols;
|
|
365
413
|
exports.getNpmBinPath = getNpmBinPath;
|
|
366
|
-
exports.
|
|
414
|
+
exports.getNpmRequire = getNpmRequire;
|
|
367
415
|
exports.getNpxBinPath = getNpxBinPath;
|
|
368
416
|
exports.getPackageFiles = getPackageFiles;
|
|
369
417
|
exports.getPackageFilesFullScans = getPackageFilesFullScans;
|
|
370
418
|
exports.isDebug = isDebug;
|
|
371
419
|
exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
|
|
372
420
|
exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
|
|
373
|
-
exports.logSymbols = logSymbols;
|
|
374
421
|
exports.logger = logger;
|
|
422
|
+
//# debugId=86fc9821-b01f-4210-8d26-6d3ece42c533
|
|
423
|
+
//# sourceMappingURL=npm-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm-paths.js","sources":["../../src/utils/logging.ts","../../src/utils/debug.ts","../../src/utils/ignore-by-default.ts","../../src/utils/path-resolve.ts","../../src/shadow/npm-paths.ts"],"sourcesContent":["import colors from 'yoctocolors-cjs'\n\nimport isUnicodeSupported from '@socketregistry/is-unicode-supported/index.cjs'\nimport { Spinner } from '@socketsecurity/registry/lib/spinner'\n\nexport type LogSymbols = {\n info: string\n success: string\n warning: string\n error: string\n}\n\nlet _logSymbols: LogSymbols | undefined\nexport function getLogSymbols() {\n if (_logSymbols === undefined) {\n _logSymbols = <LogSymbols>(isUnicodeSupported()\n ? {\n __proto__: null,\n info: colors.blue('ℹ'),\n success: colors.green('✔'),\n warning: colors.yellow('⚠'),\n error: colors.red('✖️')\n }\n : {\n __proto__: null,\n info: colors.blue('i'),\n success: colors.green('√'),\n warning: colors.yellow('‼'),\n error: colors.red('×')\n })\n }\n return _logSymbols\n}\n\nexport class Logger {\n #spinnerLogger: ReturnType<typeof Spinner>\n constructor() {\n this.#spinnerLogger = new Spinner()\n }\n\n error(text: string) {\n this.#spinnerLogger.error(text)\n }\n\n info(text: string) {\n this.#spinnerLogger.info(text)\n }\n\n warn(text: string) {\n this.#spinnerLogger.warning(text)\n }\n}\n\nexport const logger = new Logger()\n","import { getLogSymbols } from './logging'\nimport constants from '../constants'\n\nexport function isDebug() {\n // Lazily access constants.ENV.\n return constants.ENV.SOCKET_CLI_DEBUG\n}\n\nexport function debugLog(...args: any[]) {\n if (isDebug()) {\n console.error(getLogSymbols().info, ...args)\n }\n}\n","const ignoredDirs = [\n // Taken from ignore-by-default:\n // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js\n '.git', // Git repository files, see <https://git-scm.com/>\n '.log', // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>\n '.nyc_output', // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>\n '.sass-cache', // Cache folder for node-sass, see <https://github.com/sass/node-sass>\n '.yarn', // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>\n 'bower_components', // Where Bower packages are installed, see <http://bower.io/>\n 'coverage', // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>\n 'node_modules', // Where Node modules are installed, see <https://nodejs.org/>\n // Taken from globby:\n // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16\n 'flow-typed'\n] as const\n\nconst ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`)\n\nexport function directoryPatterns() {\n return [...ignoredDirPatterns]\n}\n","import { existsSync, promises as fs, realpathSync, statSync } from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\n\nimport ignore from 'ignore'\nimport micromatch from 'micromatch'\nimport { glob as tinyGlob } from 'tinyglobby'\nimport which from 'which'\n\nimport { debugLog } from './debug'\nimport { directoryPatterns } from './ignore-by-default'\nimport constants from '../constants'\n\nimport type { SocketYml } from '@socketsecurity/config'\nimport type { SocketSdkReturnType } from '@socketsecurity/sdk'\nimport type { GlobOptions } from 'tinyglobby'\n\ntype GlobWithGitIgnoreOptions = GlobOptions & {\n socketConfig?: SocketYml | undefined\n}\n\nconst { NODE_MODULES, NPM, shadowBinPath } = constants\n\nasync function filterGlobResultToSupportedFiles(\n entries: string[],\n supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']\n): Promise<string[]> {\n const patterns = ['golang', NPM, 'maven', 'pypi'].reduce(\n (r: string[], n: string) => {\n const supported = supportedFiles[n]\n r.push(\n ...(supported\n ? Object.values(supported).map(p => `**/${p.pattern}`)\n : [])\n )\n return r\n },\n []\n )\n return entries.filter(p => micromatch.some(p, patterns))\n}\n\nasync function globWithGitIgnore(\n patterns: string[],\n options: GlobWithGitIgnoreOptions\n) {\n const {\n cwd = process.cwd(),\n socketConfig,\n ...additionalOptions\n } = <GlobWithGitIgnoreOptions>{ __proto__: null, ...options }\n const projectIgnorePaths = socketConfig?.projectIgnorePaths\n const ignoreFiles = await tinyGlob(['**/.gitignore'], {\n absolute: true,\n cwd,\n expandDirectories: true\n })\n const ignores = [\n ...directoryPatterns(),\n ...(Array.isArray(projectIgnorePaths)\n ? ignoreFileLinesToGlobPatterns(\n projectIgnorePaths,\n path.join(cwd, '.gitignore'),\n cwd\n )\n : []),\n ...(\n await Promise.all(\n ignoreFiles.map(async filepath =>\n ignoreFileToGlobPatterns(\n await fs.readFile(filepath, 'utf8'),\n filepath,\n cwd\n )\n )\n )\n ).flat()\n ]\n const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/)\n const globOptions = {\n absolute: true,\n cwd,\n expandDirectories: false,\n ignore: hasNegatedPattern ? [] : ignores,\n ...additionalOptions\n }\n const result = await tinyGlob(patterns, globOptions)\n if (!hasNegatedPattern) {\n return result\n }\n const { absolute } = globOptions\n\n // Note: the input files must be INSIDE the cwd. If you get strange looking\n // relative path errors here, most likely your path is outside the given cwd.\n const filtered = ignore()\n .add(ignores)\n .filter(absolute ? result.map(p => path.relative(cwd, p)) : result)\n return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered\n}\n\nfunction ignoreFileLinesToGlobPatterns(\n lines: string[],\n filepath: string,\n cwd: string\n): string[] {\n const base = path.relative(cwd, path.dirname(filepath)).replace(/\\\\/g, '/')\n const patterns = []\n for (let i = 0, { length } = lines; i < length; i += 1) {\n const pattern = lines[i]!.trim()\n if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {\n patterns.push(\n ignorePatternToMinimatch(\n pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/\n ? `!${path.posix.join(base, pattern.slice(1))}`\n : path.posix.join(base, pattern)\n )\n )\n }\n }\n return patterns\n}\n\nfunction ignoreFileToGlobPatterns(\n content: string,\n filepath: string,\n cwd: string\n): string[] {\n return ignoreFileLinesToGlobPatterns(content.split(/\\r?\\n/), filepath, cwd)\n}\n\n// Based on `@eslint/compat` convertIgnorePatternToMinimatch.\n// Apache v2.0 licensed\n// Copyright Nicholas C. Zakas\n// https://github.com/eslint/rewrite/blob/compat-v1.2.1/packages/compat/src/ignore-file.js#L28\nfunction ignorePatternToMinimatch(pattern: string): string {\n const isNegated = pattern.startsWith('!')\n const negatedPrefix = isNegated ? '!' : ''\n const patternToTest = (isNegated ? pattern.slice(1) : pattern).trimEnd()\n // Special cases.\n if (\n patternToTest === '' ||\n patternToTest === '**' ||\n patternToTest === '/**' ||\n patternToTest === '**'\n ) {\n return `${negatedPrefix}${patternToTest}`\n }\n const firstIndexOfSlash = patternToTest.indexOf('/')\n const matchEverywherePrefix =\n firstIndexOfSlash === -1 || firstIndexOfSlash === patternToTest.length - 1\n ? '**/'\n : ''\n const patternWithoutLeadingSlash =\n firstIndexOfSlash === 0 ? patternToTest.slice(1) : patternToTest\n // Escape `{` and `(` because in gitignore patterns they are just\n // literal characters without any specific syntactic meaning,\n // while in minimatch patterns they can form brace expansion or extglob syntax.\n //\n // For example, gitignore pattern `src/{a,b}.js` ignores file `src/{a,b}.js`.\n // But, the same minimatch pattern `src/{a,b}.js` ignores files `src/a.js` and `src/b.js`.\n // Minimatch pattern `src/\\{a,b}.js` is equivalent to gitignore pattern `src/{a,b}.js`.\n const escapedPatternWithoutLeadingSlash =\n patternWithoutLeadingSlash.replaceAll(\n /(?=((?:\\\\.|[^{(])*))\\1([{(])/guy,\n '$1\\\\$2'\n )\n const matchInsideSuffix = patternToTest.endsWith('/**') ? '/*' : ''\n return `${negatedPrefix}${matchEverywherePrefix}${escapedPatternWithoutLeadingSlash}${matchInsideSuffix}`\n}\n\nfunction pathsToPatterns(paths: string[]): string[] {\n // TODO: Does not support `~/` paths.\n return paths.map(p => (p === '.' ? '**/*' : p))\n}\n\nexport function findBinPathDetailsSync(binName: string): {\n name: string\n path: string | undefined\n shadowed: boolean\n} {\n let shadowIndex = -1\n const bins =\n which.sync(binName, {\n all: true,\n nothrow: true\n }) ?? []\n let binPath: string | undefined\n for (let i = 0, { length } = bins; i < length; i += 1) {\n const bin = realpathSync.native(bins[i]!)\n // Skip our bin directory if it's in the front.\n if (path.dirname(bin) === shadowBinPath) {\n shadowIndex = i\n } else {\n binPath = bin\n break\n }\n }\n return { name: binName, path: binPath, shadowed: shadowIndex !== -1 }\n}\n\nexport function findNpmPathSync(npmBinPath: string): string | undefined {\n let thePath = npmBinPath\n while (true) {\n const nmPath = path.join(thePath, NODE_MODULES)\n if (\n // npm bin paths may look like:\n // /usr/local/share/npm/bin/npm\n // /Users/SomeUsername/.nvm/versions/node/vX.X.X/bin/npm\n // C:\\Users\\SomeUsername\\AppData\\Roaming\\npm\\bin\\npm.cmd\n // OR\n // C:\\Program Files\\nodejs\\npm.cmd\n //\n // In all cases the npm path contains a node_modules folder:\n // /usr/local/share/npm/bin/npm/node_modules\n // C:\\Program Files\\nodejs\\node_modules\n //\n // Use existsSync here because statsSync, even with { throwIfNoEntry: false },\n // will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.\n // See https://github.com/nodejs/node/issues/56993.\n existsSync(nmPath) &&\n statSync(nmPath, { throwIfNoEntry: false })?.isDirectory() &&\n // Optimistically look for the default location.\n (path.basename(thePath) === NPM ||\n // Chocolatey installs npm bins in the same directory as node bins.\n // Lazily access constants.WIN32.\n (constants.WIN32 && existsSync(path.join(thePath, `${NPM}.cmd`))))\n ) {\n return thePath\n }\n const parent = path.dirname(thePath)\n if (parent === thePath) {\n return undefined\n }\n thePath = parent\n }\n}\n\nexport async function getPackageFiles(\n cwd: string,\n inputPaths: string[],\n config: SocketYml | undefined,\n supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']\n): Promise<string[]> {\n debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths)\n\n const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {\n cwd,\n socketConfig: config\n })\n\n debugLog(\n `Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`,\n entries\n )\n\n const packageFiles = await filterGlobResultToSupportedFiles(\n entries,\n supportedFiles\n )\n\n debugLog(\n `Mapped ${entries.length} entries to ${packageFiles.length} files:`,\n packageFiles\n )\n\n return packageFiles\n}\n\nexport async function getPackageFilesFullScans(\n cwd: string,\n inputPaths: string[],\n supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'],\n debugLog: typeof console.error = () => {}\n): Promise<string[]> {\n debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths)\n\n const entries = await globWithGitIgnore(pathsToPatterns(inputPaths), {\n cwd\n })\n\n debugLog(\n `Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`,\n entries\n )\n\n const packageFiles = await filterGlobResultToSupportedFiles(\n entries,\n supportedFiles\n )\n\n debugLog(\n `Mapped ${entries.length} entries to ${packageFiles.length} files:`,\n packageFiles\n )\n\n return packageFiles\n}\n","import { existsSync } from 'node:fs'\nimport Module from 'node:module'\nimport path from 'node:path'\nimport process from 'node:process'\n\nimport { normalizePath } from '@socketsecurity/registry/lib/path'\n\nimport constants from '../constants'\nimport { findBinPathDetailsSync, findNpmPathSync } from '../utils/path-resolve'\n\nconst { NODE_MODULES, NPM, NPX, SOCKET_CLI_ISSUES_URL } = constants\n\nfunction exitWithBinPathError(binName: string): never {\n console.error(\n `Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`\n )\n // The exit code 127 indicates that the command or binary being executed\n // could not be found.\n process.exit(127)\n}\n\nlet _npmBinPathDetails: ReturnType<typeof findBinPathDetailsSync> | undefined\nfunction getNpmBinPathDetails(): ReturnType<typeof findBinPathDetailsSync> {\n if (_npmBinPathDetails === undefined) {\n _npmBinPathDetails = findBinPathDetailsSync(NPM)\n }\n return _npmBinPathDetails\n}\n\nlet _npxBinPathDetails: ReturnType<typeof findBinPathDetailsSync> | undefined\nfunction getNpxBinPathDetails(): ReturnType<typeof findBinPathDetailsSync> {\n if (_npxBinPathDetails === undefined) {\n _npxBinPathDetails = findBinPathDetailsSync(NPX)\n }\n return _npxBinPathDetails\n}\n\nlet _npmBinPath: string | undefined\nexport function getNpmBinPath(): string {\n if (_npmBinPath === undefined) {\n _npmBinPath = getNpmBinPathDetails().path\n if (!_npmBinPath) {\n exitWithBinPathError(NPM)\n }\n }\n return _npmBinPath\n}\n\nexport function isNpmBinPathShadowed() {\n return getNpmBinPathDetails().shadowed\n}\n\nlet _npxBinPath: string | undefined\nexport function getNpxBinPath(): string {\n if (_npxBinPath === undefined) {\n _npxBinPath = getNpxBinPathDetails().path\n if (!_npxBinPath) {\n exitWithBinPathError(NPX)\n }\n }\n return _npxBinPath\n}\n\nexport function isNpxBinPathShadowed() {\n return getNpxBinPathDetails().shadowed\n}\n\nlet _npmPath: string | undefined\nexport function getNpmPath() {\n if (_npmPath === undefined) {\n const npmBinPath = getNpmBinPath()\n _npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined\n if (!_npmPath) {\n let message = 'Unable to find npm CLI install directory.'\n if (npmBinPath) {\n message += `\\nSearched parent directories of ${path.dirname(npmBinPath)}.`\n }\n message += `\\n\\nThis is may be a bug with socket-npm related to changes to the npm CLI.\\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`\n console.error(message)\n // The exit code 127 indicates that the command or binary being executed\n // could not be found.\n process.exit(127)\n }\n }\n return _npmPath\n}\n\nlet _npmRequire: NodeJS.Require | undefined\nexport function getNpmRequire(): NodeJS.Require {\n if (_npmRequire === undefined) {\n const npmPath = getNpmPath()\n const npmNmPath = path.join(npmPath, NODE_MODULES, NPM)\n _npmRequire = Module.createRequire(\n path.join(existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>')\n )\n }\n return _npmRequire\n}\n\nlet _arboristPkgPath: string | undefined\nexport function getArboristPackagePath() {\n if (_arboristPkgPath === undefined) {\n const pkgName = '@npmcli/arborist'\n const mainPathWithForwardSlashes = normalizePath(\n getNpmRequire().resolve(pkgName)\n )\n const arboristPkgPathWithForwardSlashes = mainPathWithForwardSlashes.slice(\n 0,\n mainPathWithForwardSlashes.lastIndexOf(pkgName) + pkgName.length\n )\n // Lazily access constants.WIN32.\n _arboristPkgPath = constants.WIN32\n ? path.normalize(arboristPkgPathWithForwardSlashes)\n : arboristPkgPathWithForwardSlashes\n }\n return _arboristPkgPath\n}\n\nlet _arboristClassPath: string | undefined\nexport function getArboristClassPath() {\n if (_arboristClassPath === undefined) {\n _arboristClassPath = path.join(\n getArboristPackagePath(),\n 'lib/arborist/index.js'\n )\n }\n return _arboristClassPath\n}\n\nlet _arboristDepValidPath: string | undefined\nexport function getArboristDepValidPath() {\n if (_arboristDepValidPath === undefined) {\n _arboristDepValidPath = path.join(\n getArboristPackagePath(),\n 'lib/dep-valid.js'\n )\n }\n return _arboristDepValidPath\n}\n\nlet _arboristEdgeClassPath: string | undefined\nexport function getArboristEdgeClassPath() {\n if (_arboristEdgeClassPath === undefined) {\n _arboristEdgeClassPath = path.join(getArboristPackagePath(), 'lib/edge.js')\n }\n return _arboristEdgeClassPath\n}\n\nlet _arboristNodeClassPath: string | undefined\nexport function getArboristNodeClassPath() {\n if (_arboristNodeClassPath === undefined) {\n _arboristNodeClassPath = path.join(getArboristPackagePath(), 'lib/node.js')\n }\n return _arboristNodeClassPath\n}\n\nlet _arboristOverrideSetClassPath: string | undefined\nexport function getArboristOverrideSetClassPath() {\n if (_arboristOverrideSetClassPath === undefined) {\n _arboristOverrideSetClassPath = path.join(\n getArboristPackagePath(),\n 'lib/override-set.js'\n )\n }\n return _arboristOverrideSetClassPath\n}\n"],"names":["_logSymbols","__proto__","info","success","warning","error","constructor","shadowBinPath","cwd","absolute","expandDirectories","ignore","length","all","nothrow","shadowIndex","binPath","name","path","existsSync","throwIfNoEntry","constants","thePath","socketConfig","debugLog","SOCKET_CLI_ISSUES_URL","console","process","_npmBinPathDetails","_npxBinPathDetails","_npmBinPath","_npxBinPath","_arboristPkgPath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AACO;;AAEHA;AAEMC;AACAC;AACAC;AACAC;AACAC;AACF;AAEEJ;AACAC;AACAC;AACAC;AACAC;;AAER;AACA;AACF;AAEO;AACL;AACAC;AACE;AACF;;AAGE;AACF;;AAGE;AACF;;AAGE;AACF;AACF;;;AChDO;AACL;AACA;AACF;AAEO;;;AAGL;AACF;;ACZA;AACE;AACA;AACA;AAAQ;AACR;AAAQ;AACR;AAAe;AACf;AAAe;AACf;AAAS;AACT;AAAoB;AACpB;AAAY;AACZ;AAAgB;AAChB;AACA;AACA;AAGF;AAEO;;AAEP;;ACCA;;;AAA2BC;AAAc;AAEzC;AAIE;AAEI;;AAMA;;AAIJ;AACF;AAEA;;AAKIC;;;AAGF;AAAgCP;;;AAChC;;AAEEQ;;AAEAC;AACF;AACA;AAqBA;AACA;AACED;;AAEAC;AACAC;;;;;AAKA;AACF;;AACQF;AAAS;;AAEjB;AACA;AACA;AAGA;AACF;AAEA;;;AAOE;AAAkBG;;;AAEhB;;AAQA;AACF;AACA;AACF;AAEA;AAKE;AACF;;AAEA;AACA;AACA;AACA;AACA;AACE;AACA;AACA;AACA;AACA;AAME;AACF;AACA;AACA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AAQF;AAEA;AACE;AACA;AACF;AAEO;;AAML;AAEIC;AACAC;;AAEJ;AACA;AAAkBF;;;AAEhB;;AAEEG;AACF;AACEC;AACA;AACF;AACF;;AACSC;AAAeC;;;AAC1B;AAEO;;AAEL;;AAEE;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAC;AACmBC;AAAsB;AACzC;AACCF;AACC;AACA;AACCG;AAEH;AACF;AACA;;AAEE;AACF;AACAC;AACF;AACF;AAEO;;;;AAUHC;AACF;AAEAC;;AAUAA;AAKA;AACF;AAEO;;;AASHhB;AACF;AAEAgB;;AAUAA;AAKA;AACF;;AC9RA;;;;AAAgCC;AAAsB;AAEtD;AACEC;AAGA;AACA;AACAC;AACF;AAEA;AACA;;AAEIC;AACF;AACA;AACF;AAEA;AACA;;AAEIC;AACF;AACA;AACF;AAEA;AACO;;AAEHC;;;AAGA;AACF;AACA;AACF;AAEO;AACL;AACF;AAEA;AACO;;AAEHC;;;AAGA;AACF;AACA;AACF;AAEO;AACL;AACF;AAEA;AACO;;AAEH;;;;AAIE;;AAEA;;AAEAL;AACA;AACA;AACAC;AACF;AACF;AACA;AACF;AAEA;AACO;;AAEH;;;AAKF;AACA;AACF;AAEA;AACO;;;AAGH;AAGA;AAIA;AACAK;AAGF;AACA;AACF;AAEA;AACO;;;AAML;AACA;AACF;AAEA;AACO;;;AAML;AACA;AACF;AAEA;AACO;;;AAGL;AACA;AACF;AAEA;AACO;;;AAGL;AACA;AACF;AAEA;AACO;;;AAML;AACA;AACF;;;;;;;;;;;;;;;;;","debugId":"86fc9821-b01f-4210-8d26-6d3ece42c533"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="npmcli__promise-spawn" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import spawn from '@npmcli/promise-spawn';
|
|
4
|
+
declare function isAuditFlag(cmdArg: string): boolean;
|
|
5
|
+
declare function isFundFlag(cmdArg: string): boolean;
|
|
6
|
+
declare function isLoglevelFlag(cmdArg: string): boolean;
|
|
7
|
+
declare function isProgressFlag(cmdArg: string): boolean;
|
|
8
|
+
type SpawnOption = Exclude<Parameters<typeof spawn>[2], undefined>;
|
|
9
|
+
type SafeNpmInstallOptions = SpawnOption & {
|
|
10
|
+
args?: string[];
|
|
11
|
+
ipc?: object;
|
|
12
|
+
};
|
|
13
|
+
declare function safeNpmInstall(opts?: SafeNpmInstallOptions): Promise<{
|
|
14
|
+
cmd: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
code: number;
|
|
17
|
+
signal: NodeJS.Signals | null;
|
|
18
|
+
stdout: string;
|
|
19
|
+
stderr: string;
|
|
20
|
+
} & Record<any, any>> & {
|
|
21
|
+
process: import("child_process").ChildProcess;
|
|
22
|
+
stdio: [import("stream").Writable | null, import("stream").Readable | null, import("stream").Readable | null, import("stream").Writable | import("stream").Readable | null | undefined, import("stream").Writable | import("stream").Readable | null | undefined];
|
|
23
|
+
};
|
|
24
|
+
export { isAuditFlag, isFundFlag, isLoglevelFlag, isProgressFlag, safeNpmInstall };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _socketInterop(e) {
|
|
4
|
+
let c = 0
|
|
5
|
+
for (const k in e ?? {}) {
|
|
6
|
+
c = c === 0 && k === 'default' ? 1 : 0
|
|
7
|
+
if (!c && k !== '__esModule') break
|
|
8
|
+
}
|
|
9
|
+
return c ? e.default : e
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var process = require('node:process');
|
|
13
|
+
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
14
|
+
var objects = require('@socketsecurity/registry/lib/objects');
|
|
15
|
+
var npmPaths = require('./npm-paths.js');
|
|
16
|
+
var constants = require('./constants.js');
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
SOCKET_IPC_HANDSHAKE,
|
|
20
|
+
abortSignal
|
|
21
|
+
} = constants;
|
|
22
|
+
const auditFlags = new Set(['--audit', '--no-audit']);
|
|
23
|
+
const fundFlags = new Set(['--fund', '--no-fund']);
|
|
24
|
+
|
|
25
|
+
// https://docs.npmjs.com/cli/v11/using-npm/logging#aliases
|
|
26
|
+
const logFlags = new Set(['--loglevel', '-d', '--dd', '--ddd', '-q', '--quiet', '-s', '--silent']);
|
|
27
|
+
const progressFlags = new Set(['--progress', '--no-progress']);
|
|
28
|
+
function isAuditFlag(cmdArg) {
|
|
29
|
+
return auditFlags.has(cmdArg);
|
|
30
|
+
}
|
|
31
|
+
function isFundFlag(cmdArg) {
|
|
32
|
+
return fundFlags.has(cmdArg);
|
|
33
|
+
}
|
|
34
|
+
function isLoglevelFlag(cmdArg) {
|
|
35
|
+
// https://docs.npmjs.com/cli/v11/using-npm/logging#setting-log-levels
|
|
36
|
+
return cmdArg.startsWith('--loglevel=') || logFlags.has(cmdArg);
|
|
37
|
+
}
|
|
38
|
+
function isProgressFlag(cmdArg) {
|
|
39
|
+
return progressFlags.has(cmdArg);
|
|
40
|
+
}
|
|
41
|
+
function safeNpmInstall(opts) {
|
|
42
|
+
const {
|
|
43
|
+
args = [],
|
|
44
|
+
ipc,
|
|
45
|
+
...spawnOptions
|
|
46
|
+
} = {
|
|
47
|
+
__proto__: null,
|
|
48
|
+
...opts
|
|
49
|
+
};
|
|
50
|
+
const terminatorPos = args.indexOf('--');
|
|
51
|
+
const npmArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !isAuditFlag(a) && !isFundFlag(a) && !isProgressFlag(a));
|
|
52
|
+
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
53
|
+
const useIpc = objects.isObject(ipc);
|
|
54
|
+
const useDebug = npmPaths.isDebug();
|
|
55
|
+
const spawnPromise = spawn(
|
|
56
|
+
// Lazily access constants.execPath.
|
|
57
|
+
constants.execPath, [
|
|
58
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
59
|
+
...constants.nodeNoWarningsFlags, '--require',
|
|
60
|
+
// Lazily access constants.npmInjectionPath.
|
|
61
|
+
constants.npmInjectionPath, npmPaths.getNpmBinPath(), 'install',
|
|
62
|
+
// Even though the '--silent' flag is passed npm will still run through
|
|
63
|
+
// code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
|
|
64
|
+
// flags are passed.
|
|
65
|
+
'--no-audit', '--no-fund',
|
|
66
|
+
// Add `--no-progress` and `--silent` flags to fix input being swallowed
|
|
67
|
+
// by the spinner when running the command with recent versions of npm.
|
|
68
|
+
'--no-progress',
|
|
69
|
+
// Add the '--silent' flag if a loglevel flag is not provided and the
|
|
70
|
+
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
71
|
+
...(useDebug || npmArgs.some(isLoglevelFlag) ? [] : ['--silent']), ...npmArgs, ...otherArgs], {
|
|
72
|
+
signal: abortSignal,
|
|
73
|
+
// Set stdio to include 'ipc'.
|
|
74
|
+
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
75
|
+
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
76
|
+
stdio: useDebug ?
|
|
77
|
+
// 'inherit'
|
|
78
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit' :
|
|
79
|
+
// 'ignore'
|
|
80
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore',
|
|
81
|
+
...spawnOptions,
|
|
82
|
+
env: {
|
|
83
|
+
...process.env,
|
|
84
|
+
...spawnOptions.env
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (useIpc) {
|
|
88
|
+
spawnPromise.process.send({
|
|
89
|
+
[SOCKET_IPC_HANDSHAKE]: ipc
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return spawnPromise;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
exports.isLoglevelFlag = isLoglevelFlag;
|
|
96
|
+
exports.isProgressFlag = isProgressFlag;
|
|
97
|
+
exports.safeNpmInstall = safeNpmInstall;
|
|
98
|
+
//# debugId=73c2e7c8-ac5f-4a8a-8343-be29aaec8a8a
|
|
99
|
+
//# sourceMappingURL=npm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"npm.js","sources":["../../src/utils/npm.ts"],"sourcesContent":["import process from 'node:process'\n\nimport spawn from '@npmcli/promise-spawn'\n\nimport { isObject } from '@socketsecurity/registry/lib/objects'\n\nimport { isDebug } from './debug'\nimport constants from '../constants'\nimport { getNpmBinPath } from '../shadow/npm-paths'\n\nconst { SOCKET_IPC_HANDSHAKE, abortSignal } = constants\n\nconst auditFlags = new Set(['--audit', '--no-audit'])\n\nconst fundFlags = new Set(['--fund', '--no-fund'])\n\n// https://docs.npmjs.com/cli/v11/using-npm/logging#aliases\nconst logFlags = new Set([\n '--loglevel',\n '-d',\n '--dd',\n '--ddd',\n '-q',\n '--quiet',\n '-s',\n '--silent'\n])\n\nconst progressFlags = new Set(['--progress', '--no-progress'])\n\nexport function isAuditFlag(cmdArg: string) {\n return auditFlags.has(cmdArg)\n}\n\nexport function isFundFlag(cmdArg: string) {\n return fundFlags.has(cmdArg)\n}\n\nexport function isLoglevelFlag(cmdArg: string) {\n // https://docs.npmjs.com/cli/v11/using-npm/logging#setting-log-levels\n return cmdArg.startsWith('--loglevel=') || logFlags.has(cmdArg)\n}\n\nexport function isProgressFlag(cmdArg: string) {\n return progressFlags.has(cmdArg)\n}\n\ntype SpawnOption = Exclude<Parameters<typeof spawn>[2], undefined>\n\ntype SafeNpmInstallOptions = SpawnOption & {\n args?: string[]\n ipc?: object\n}\n\nexport function safeNpmInstall(opts?: SafeNpmInstallOptions) {\n const { args = [], ipc, ...spawnOptions } = { __proto__: null, ...opts }\n const terminatorPos = args.indexOf('--')\n const npmArgs = (\n terminatorPos === -1 ? args : args.slice(0, terminatorPos)\n ).filter(a => !isAuditFlag(a) && !isFundFlag(a) && !isProgressFlag(a))\n const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)\n const useIpc = isObject(ipc)\n const useDebug = isDebug()\n const spawnPromise = spawn(\n // Lazily access constants.execPath.\n constants.execPath,\n [\n // Lazily access constants.nodeNoWarningsFlags.\n ...constants.nodeNoWarningsFlags,\n '--require',\n // Lazily access constants.npmInjectionPath.\n constants.npmInjectionPath,\n getNpmBinPath(),\n 'install',\n // Even though the '--silent' flag is passed npm will still run through\n // code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'\n // flags are passed.\n '--no-audit',\n '--no-fund',\n // Add `--no-progress` and `--silent` flags to fix input being swallowed\n // by the spinner when running the command with recent versions of npm.\n '--no-progress',\n // Add the '--silent' flag if a loglevel flag is not provided and the\n // SOCKET_CLI_DEBUG environment variable is not truthy.\n ...(useDebug || npmArgs.some(isLoglevelFlag) ? [] : ['--silent']),\n ...npmArgs,\n ...otherArgs\n ],\n {\n signal: abortSignal,\n // Set stdio to include 'ipc'.\n // See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166\n // and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.\n stdio: useDebug\n ? // 'inherit'\n useIpc\n ? [0, 1, 2, 'ipc']\n : 'inherit'\n : // 'ignore'\n useIpc\n ? ['ignore', 'ignore', 'ignore', 'ipc']\n : 'ignore',\n ...spawnOptions,\n env: {\n ...process.env,\n ...spawnOptions.env\n }\n }\n )\n if (useIpc) {\n spawnPromise.process.send({ [SOCKET_IPC_HANDSHAKE]: ipc })\n }\n return spawnPromise\n}\n"],"names":["abortSignal","args","__proto__","constants","signal","stdio","env","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;AAUA;;AAA8BA;AAAY;AAE1C;AAEA;;AAEA;AACA;AAWA;AAEO;AACL;AACF;AAEO;AACL;AACF;AAEO;AACL;AACA;AACF;AAEO;AACL;AACF;AASO;;AACGC;;;AAAgC;AAAMC;;;AAC9C;AACA;AAGA;AACA;AACA;;AAEE;;AAGE;AACA;AAEA;AACAC;AAGA;AACA;AACA;AACA;AAEA;AACA;;AAEA;AACA;;AAMAC;AACA;AACA;AACA;AACAC;AACI;;AAIA;;AAIJ;AACAC;;AAEE;AACF;AACF;AAEF;AACEC;AAA4B;AAA4B;AAC1D;AACA;AACF;;;;","debugId":"73c2e7c8-ac5f-4a8a-8343-be29aaec8a8a"}
|
|
@@ -6,7 +6,7 @@ declare function findBinPathDetailsSync(binName: string): {
|
|
|
6
6
|
path: string | undefined;
|
|
7
7
|
shadowed: boolean;
|
|
8
8
|
};
|
|
9
|
-
declare function findNpmPathSync(
|
|
9
|
+
declare function findNpmPathSync(npmBinPath: string): string | undefined;
|
|
10
10
|
declare function getPackageFiles(cwd: string, inputPaths: string[], config: SocketYml | undefined, supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']): Promise<string[]>;
|
|
11
11
|
declare function getPackageFilesFullScans(cwd: string, inputPaths: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], debugLog?: typeof console.error): Promise<string[]>;
|
|
12
12
|
export { findBinPathDetailsSync, findNpmPathSync, getPackageFiles, getPackageFilesFullScans };
|