@socketsecurity/cli-with-sentry 0.14.47 → 0.14.49
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/dist/constants.d.ts +6 -3
- package/dist/constants.js +2 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +399 -301
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/edge.d.ts +0 -1
- package/dist/module-sync/index.d.ts +5 -5
- package/dist/module-sync/index.js +114 -131
- package/dist/module-sync/index.js.map +1 -1
- package/dist/module-sync/node.d.ts +5 -3
- package/dist/module-sync/npm-injection.js +2 -2
- package/dist/module-sync/npm-injection.js.map +1 -1
- package/dist/module-sync/npm.d.ts +5 -3
- package/dist/module-sync/npm.js +23 -9
- package/dist/module-sync/npm.js.map +1 -1
- package/dist/require/cli.js +399 -301
- package/dist/require/cli.js.map +1 -1
- package/package.json +7 -4
package/dist/module-sync/npm.js
CHANGED
|
@@ -38,21 +38,27 @@ function isLoglevelFlag(cmdArg) {
|
|
|
38
38
|
function isProgressFlag(cmdArg) {
|
|
39
39
|
return progressFlags.has(cmdArg);
|
|
40
40
|
}
|
|
41
|
-
function safeNpmInstall(
|
|
41
|
+
function safeNpmInstall(options) {
|
|
42
42
|
const {
|
|
43
43
|
args = [],
|
|
44
44
|
ipc,
|
|
45
|
+
spinner,
|
|
45
46
|
...spawnOptions
|
|
46
47
|
} = {
|
|
47
48
|
__proto__: null,
|
|
48
|
-
...
|
|
49
|
+
...options
|
|
49
50
|
};
|
|
50
51
|
const terminatorPos = args.indexOf('--');
|
|
51
52
|
const npmArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !isAuditFlag(a) && !isFundFlag(a) && !isProgressFlag(a));
|
|
52
53
|
const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
|
|
53
54
|
const useIpc = objects.isObject(ipc);
|
|
54
55
|
const useDebug = npmPaths.isDebug();
|
|
55
|
-
const
|
|
56
|
+
const isSilent = !useDebug && !npmArgs.some(isLoglevelFlag);
|
|
57
|
+
const isSpinning = spinner?.isSpinning ?? false;
|
|
58
|
+
if (!isSilent) {
|
|
59
|
+
spinner?.stop();
|
|
60
|
+
}
|
|
61
|
+
let spawnPromise = spawn(
|
|
56
62
|
// Lazily access constants.execPath.
|
|
57
63
|
constants.execPath, [
|
|
58
64
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
@@ -68,16 +74,16 @@ function safeNpmInstall(opts) {
|
|
|
68
74
|
'--no-progress',
|
|
69
75
|
// Add the '--silent' flag if a loglevel flag is not provided and the
|
|
70
76
|
// SOCKET_CLI_DEBUG environment variable is not truthy.
|
|
71
|
-
...(
|
|
77
|
+
...(isSilent ? ['--silent'] : []), ...npmArgs, ...otherArgs], {
|
|
72
78
|
signal: abortSignal,
|
|
73
79
|
// Set stdio to include 'ipc'.
|
|
74
80
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
75
81
|
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
76
|
-
stdio:
|
|
77
|
-
// 'inherit'
|
|
78
|
-
useIpc ? [0, 1, 2, 'ipc'] : 'inherit' :
|
|
82
|
+
stdio: isSilent ?
|
|
79
83
|
// 'ignore'
|
|
80
|
-
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore'
|
|
84
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore' :
|
|
85
|
+
// 'inherit'
|
|
86
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit',
|
|
81
87
|
...spawnOptions,
|
|
82
88
|
env: {
|
|
83
89
|
...process.env,
|
|
@@ -89,11 +95,19 @@ function safeNpmInstall(opts) {
|
|
|
89
95
|
[SOCKET_IPC_HANDSHAKE]: ipc
|
|
90
96
|
});
|
|
91
97
|
}
|
|
98
|
+
if (!isSilent && isSpinning) {
|
|
99
|
+
const oldSpawnPromise = spawnPromise;
|
|
100
|
+
spawnPromise = spawnPromise.finally(() => {
|
|
101
|
+
spinner?.start();
|
|
102
|
+
});
|
|
103
|
+
spawnPromise.process = oldSpawnPromise.process;
|
|
104
|
+
spawnPromise.stdin = spawnPromise.stdin;
|
|
105
|
+
}
|
|
92
106
|
return spawnPromise;
|
|
93
107
|
}
|
|
94
108
|
|
|
95
109
|
exports.isLoglevelFlag = isLoglevelFlag;
|
|
96
110
|
exports.isProgressFlag = isProgressFlag;
|
|
97
111
|
exports.safeNpmInstall = safeNpmInstall;
|
|
98
|
-
//# debugId=
|
|
112
|
+
//# debugId=e284aad0-2f5e-4bba-a5e4-010813e648a3
|
|
99
113
|
//# sourceMappingURL=npm.js.map
|
|
@@ -1 +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(
|
|
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\nimport type { Spinner } from '@socketsecurity/registry/lib/spinner'\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[] | undefined\n ipc?: object | undefined\n spinner?: Spinner | undefined\n}\n\nexport function safeNpmInstall(options?: SafeNpmInstallOptions) {\n const {\n args = [],\n ipc,\n spinner,\n ...spawnOptions\n } = <SafeNpmInstallOptions>{ __proto__: null, ...options }\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 isSilent = !useDebug && !npmArgs.some(isLoglevelFlag)\n const isSpinning = spinner?.isSpinning ?? false\n if (!isSilent) {\n spinner?.stop()\n }\n let 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 ...(isSilent ? ['--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: isSilent\n ? // 'ignore'\n useIpc\n ? ['ignore', 'ignore', 'ignore', 'ipc']\n : 'ignore'\n : // 'inherit'\n useIpc\n ? [0, 1, 2, 'ipc']\n : 'inherit',\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 if (!isSilent && isSpinning) {\n const oldSpawnPromise = spawnPromise\n spawnPromise = <typeof oldSpawnPromise>spawnPromise.finally(() => {\n spinner?.start()\n })\n spawnPromise.process = oldSpawnPromise.process\n ;(spawnPromise as any).stdin = (spawnPromise as any).stdin\n }\n return spawnPromise\n}\n"],"names":["abortSignal","args","__proto__","constants","signal","stdio","env","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;AAYA;;AAA8BA;AAAY;AAE1C;AAEA;;AAEA;AACA;AAWA;AAEO;AACL;AACF;AAEO;AACL;AACF;AAEO;AACL;AACA;AACF;AAEO;AACL;AACF;AAUO;;AAEHC;;;;AAIF;AAA6BC;;;AAC7B;AACA;AAGA;AACA;AACA;;AAEA;;;AAGA;;AAEE;;AAGE;AACA;AAEA;AACAC;AAGA;AACA;AACA;AACA;AAEA;AACA;;AAEA;AACA;AACA;AAKAC;AACA;AACA;AACA;AACAC;AACI;;AAIA;;AAIJ;AACAC;;AAEE;AACF;AACF;AAEF;AACEC;AAA4B;AAA4B;AAC1D;AACA;;AAEEA;;AAEA;AACAA;AACEA;AACJ;AACA;AACF;;;;","debugId":"e284aad0-2f5e-4bba-a5e4-010813e648a3"}
|