@socketsecurity/cli 0.14.34 → 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 +37 -1
- package/bin/npm-cli.js +2 -1
- package/bin/npx-cli.js +2 -1
- package/dist/constants.js +69 -38
- package/dist/module-sync/cli.js +773 -1555
- package/dist/module-sync/constants.d.ts +16 -79
- package/dist/module-sync/constants.d.ts.map +1 -0
- package/dist/module-sync/npm-injection.js +77 -396
- package/dist/module-sync/path-resolve.d.ts +6 -1
- package/dist/module-sync/path-resolve.js +47 -38
- package/dist/module-sync/sdk.js +60 -110
- package/dist/module-sync/shadow-bin.d.ts +2 -0
- package/dist/module-sync/shadow-bin.js +103 -0
- package/dist/require/cli.js +768 -1549
- package/dist/require/constants.d.ts.map +1 -0
- package/dist/require/npm-injection.js +76 -394
- package/dist/require/path-resolve.js +47 -38
- package/dist/require/sdk.js +57 -106
- package/dist/require/shadow-bin.js +103 -0
- package/dist/require/vendor.js +8295 -8708
- package/package.json +30 -31
- package/shadow-bin/npm +4 -0
- package/shadow-bin/npx +4 -0
- package/bin/shadow/module-sync/npm +0 -3
- package/bin/shadow/module-sync/npx +0 -3
- package/bin/shadow/require/npm +0 -3
- package/bin/shadow/require/npx +0 -3
- package/dist/module-sync/link.d.ts +0 -2
- package/dist/module-sync/link.js +0 -54
- package/dist/module-sync/npm-cli.d.ts +0 -2
- package/dist/module-sync/npm-cli.js +0 -101
- package/dist/module-sync/npx-cli.d.ts +0 -2
- package/dist/module-sync/npx-cli.js +0 -77
- package/dist/module-sync/vendor.js +0 -70
- package/dist/require/link.js +0 -54
- package/dist/require/npm-cli.js +0 -101
- package/dist/require/npx-cli.js +0 -77
|
@@ -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 };
|
|
@@ -4,25 +4,19 @@ function _socketInterop(e) {
|
|
|
4
4
|
let c = 0
|
|
5
5
|
for (const k in e ?? {}) {
|
|
6
6
|
c = c === 0 && k === 'default' ? 1 : 0
|
|
7
|
-
if (!c) break
|
|
7
|
+
if (!c && k !== '__esModule') break
|
|
8
8
|
}
|
|
9
9
|
return c ? e.default : e
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
12
|
+
var fs = require('node:fs');
|
|
13
|
+
var path = require('node:path');
|
|
14
|
+
var ignore = _socketInterop(require('ignore'));
|
|
15
|
+
var micromatch = _socketInterop(require('micromatch'));
|
|
16
|
+
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
17
|
+
var which = _socketInterop(require('which'));
|
|
18
|
+
var constants = require('./constants.js');
|
|
17
19
|
|
|
18
|
-
var pathResolve = {};
|
|
19
|
-
|
|
20
|
-
var ignoreByDefault = {};
|
|
21
|
-
|
|
22
|
-
Object.defineProperty(ignoreByDefault, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
});
|
|
25
|
-
ignoreByDefault.directoryPatterns = directoryPatterns;
|
|
26
20
|
const ignoredDirs = [
|
|
27
21
|
// Taken from ignore-by-default:
|
|
28
22
|
// https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
|
|
@@ -50,25 +44,17 @@ function directoryPatterns() {
|
|
|
50
44
|
return [...ignoredDirPatterns];
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
pathResolve.getPackageFiles = getPackageFiles;
|
|
58
|
-
pathResolve.getPackageFilesFullScans = getPackageFilesFullScans;
|
|
59
|
-
var _promises = require$$1$1;
|
|
60
|
-
var _nodePath = require$$1;
|
|
61
|
-
var _ignore = require$$2;
|
|
62
|
-
var _micromatch = require$$3;
|
|
63
|
-
var _tinyglobby = require$$8;
|
|
64
|
-
var _ignoreByDefault = ignoreByDefault;
|
|
47
|
+
const {
|
|
48
|
+
NPM,
|
|
49
|
+
shadowBinPath
|
|
50
|
+
} = constants;
|
|
65
51
|
async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
|
|
66
|
-
const patterns = ['golang',
|
|
52
|
+
const patterns = ['golang', NPM, 'pypi'].reduce((r, n) => {
|
|
67
53
|
const supported = supportedFiles[n];
|
|
68
54
|
r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
|
|
69
55
|
return r;
|
|
70
56
|
}, []);
|
|
71
|
-
return entries.filter(p =>
|
|
57
|
+
return entries.filter(p => micromatch.some(p, patterns));
|
|
72
58
|
}
|
|
73
59
|
async function globWithGitIgnore(patterns, options) {
|
|
74
60
|
const {
|
|
@@ -80,12 +66,12 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
80
66
|
...options
|
|
81
67
|
};
|
|
82
68
|
const projectIgnorePaths = socketConfig?.projectIgnorePaths;
|
|
83
|
-
const ignoreFiles = await
|
|
69
|
+
const ignoreFiles = await tinyglobby.glob(['**/.gitignore'], {
|
|
84
70
|
absolute: true,
|
|
85
71
|
cwd,
|
|
86
72
|
expandDirectories: true
|
|
87
73
|
});
|
|
88
|
-
const ignores = [...
|
|
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()];
|
|
89
75
|
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
|
|
90
76
|
const globOptions = {
|
|
91
77
|
absolute: true,
|
|
@@ -94,25 +80,25 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
94
80
|
ignore: hasNegatedPattern ? [] : ignores,
|
|
95
81
|
...additionalOptions
|
|
96
82
|
};
|
|
97
|
-
const result = await
|
|
83
|
+
const result = await tinyglobby.glob(patterns, globOptions);
|
|
98
84
|
if (!hasNegatedPattern) {
|
|
99
85
|
return result;
|
|
100
86
|
}
|
|
101
87
|
const {
|
|
102
88
|
absolute
|
|
103
89
|
} = globOptions;
|
|
104
|
-
const filtered =
|
|
105
|
-
return absolute ? filtered.map(p =>
|
|
90
|
+
const filtered = ignore().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
|
|
91
|
+
return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
|
|
106
92
|
}
|
|
107
93
|
function ignoreFileLinesToGlobPatterns(lines, filepath, cwd) {
|
|
108
|
-
const base =
|
|
94
|
+
const base = path.relative(cwd, path.dirname(filepath)).replace(/\\/g, '/');
|
|
109
95
|
const patterns = [];
|
|
110
96
|
for (let i = 0, {
|
|
111
97
|
length
|
|
112
98
|
} = lines; i < length; i += 1) {
|
|
113
99
|
const pattern = lines[i].trim();
|
|
114
100
|
if (pattern.length > 0 && pattern.charCodeAt(0) !== 35 /*'#'*/) {
|
|
115
|
-
patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${
|
|
101
|
+
patterns.push(ignorePatternToMinimatch(pattern.length && pattern.charCodeAt(0) === 33 /*'!'*/ ? `!${path.posix.join(base, pattern.slice(1))}` : path.posix.join(base, pattern)));
|
|
116
102
|
}
|
|
117
103
|
}
|
|
118
104
|
return patterns;
|
|
@@ -153,16 +139,36 @@ function pathsToPatterns(paths) {
|
|
|
153
139
|
function findRoot(filepath) {
|
|
154
140
|
let curPath = filepath;
|
|
155
141
|
while (true) {
|
|
156
|
-
if (
|
|
142
|
+
if (path.basename(curPath) === NPM) {
|
|
157
143
|
return curPath;
|
|
158
144
|
}
|
|
159
|
-
const parent =
|
|
145
|
+
const parent = path.dirname(curPath);
|
|
160
146
|
if (parent === curPath) {
|
|
161
147
|
return undefined;
|
|
162
148
|
}
|
|
163
149
|
curPath = parent;
|
|
164
150
|
}
|
|
165
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
|
+
}
|
|
166
172
|
async function getPackageFiles(cwd, inputPaths, config, supportedFiles, debugLog = () => {}) {
|
|
167
173
|
debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
|
|
168
174
|
|
|
@@ -189,4 +195,7 @@ async function getPackageFilesFullScans(cwd, inputPaths, supportedFiles, debugLo
|
|
|
189
195
|
return packageFiles;
|
|
190
196
|
}
|
|
191
197
|
|
|
192
|
-
exports.
|
|
198
|
+
exports.findBinPathDetails = findBinPathDetails;
|
|
199
|
+
exports.findRoot = findRoot;
|
|
200
|
+
exports.getPackageFiles = getPackageFiles;
|
|
201
|
+
exports.getPackageFilesFullScans = getPackageFilesFullScans;
|
package/dist/module-sync/sdk.js
CHANGED
|
@@ -4,72 +4,53 @@ function _socketInterop(e) {
|
|
|
4
4
|
let c = 0
|
|
5
5
|
for (const k in e ?? {}) {
|
|
6
6
|
c = c === 0 && k === 'default' ? 1 : 0
|
|
7
|
-
if (!c) break
|
|
7
|
+
if (!c && k !== '__esModule') break
|
|
8
8
|
}
|
|
9
9
|
return c ? e.default : e
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var require$$5 = require('@socketsecurity/sdk');
|
|
12
|
+
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
13
|
+
var isUnicodeSupported = _socketInterop(require('is-unicode-supported'));
|
|
14
|
+
var terminalLink = _socketInterop(require('terminal-link'));
|
|
15
|
+
var hpagent = _socketInterop(require('hpagent'));
|
|
16
|
+
var isInteractive = _socketInterop(require('is-interactive'));
|
|
17
|
+
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
18
|
+
var strings = require('@socketsecurity/registry/lib/strings');
|
|
19
|
+
var sdk = require('@socketsecurity/sdk');
|
|
21
20
|
var constants = require('./constants.js');
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
21
|
+
var fs = require('node:fs');
|
|
22
|
+
var homedir = require('node:os');
|
|
23
|
+
var path = require('node:path');
|
|
24
|
+
var yoctoSpinner = require('@socketregistry/yocto-spinner');
|
|
26
25
|
|
|
27
|
-
var errors = {};
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(errors, "__esModule", {
|
|
30
|
-
value: true
|
|
31
|
-
});
|
|
32
|
-
errors.InputError = errors.AuthError = void 0;
|
|
33
26
|
class AuthError extends Error {}
|
|
34
|
-
errors.AuthError = AuthError;
|
|
35
27
|
class InputError extends Error {
|
|
36
28
|
constructor(message, body) {
|
|
37
29
|
super(message);
|
|
38
30
|
this.body = body;
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
|
-
errors.InputError = InputError;
|
|
42
|
-
|
|
43
|
-
var colorOrMarkdown = {};
|
|
44
33
|
|
|
45
|
-
var _interopRequireDefault$1 = vendor.interopRequireDefault.default;
|
|
46
|
-
Object.defineProperty(colorOrMarkdown, "__esModule", {
|
|
47
|
-
value: true
|
|
48
|
-
});
|
|
49
|
-
colorOrMarkdown.logSymbols = colorOrMarkdown.ColorOrMarkdown = void 0;
|
|
50
|
-
var _yoctocolorsCjs = require$$1;
|
|
51
|
-
var _isUnicodeSupported = _interopRequireDefault$1(require$$2);
|
|
52
|
-
var _terminalLink = _interopRequireDefault$1(require$$3);
|
|
53
34
|
// From the 'log-symbols' module
|
|
54
35
|
const unicodeLogSymbols = {
|
|
55
36
|
__proto__: null,
|
|
56
|
-
info:
|
|
57
|
-
success:
|
|
58
|
-
warning:
|
|
59
|
-
error:
|
|
37
|
+
info: colors.blue('ℹ'),
|
|
38
|
+
success: colors.green('✔'),
|
|
39
|
+
warning: colors.yellow('⚠'),
|
|
40
|
+
error: colors.red('✖')
|
|
60
41
|
};
|
|
61
42
|
|
|
62
43
|
// From the 'log-symbols' module
|
|
63
44
|
const fallbackLogSymbols = {
|
|
64
45
|
__proto__: null,
|
|
65
|
-
info:
|
|
66
|
-
success:
|
|
67
|
-
warning:
|
|
68
|
-
error:
|
|
46
|
+
info: colors.blue('i'),
|
|
47
|
+
success: colors.green('√'),
|
|
48
|
+
warning: colors.yellow('‼'),
|
|
49
|
+
error: colors.red('×')
|
|
69
50
|
};
|
|
70
51
|
|
|
71
52
|
// From the 'log-symbols' module
|
|
72
|
-
const logSymbols =
|
|
53
|
+
const logSymbols = isUnicodeSupported() ? unicodeLogSymbols : fallbackLogSymbols;
|
|
73
54
|
const markdownLogSymbols = {
|
|
74
55
|
__proto__: null,
|
|
75
56
|
info: ':information_source:',
|
|
@@ -82,20 +63,20 @@ class ColorOrMarkdown {
|
|
|
82
63
|
this.useMarkdown = !!useMarkdown;
|
|
83
64
|
}
|
|
84
65
|
header(text, level = 1) {
|
|
85
|
-
return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` :
|
|
66
|
+
return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : colors.underline(`\n${level === 1 ? colors.bold(text) : text}\n`);
|
|
86
67
|
}
|
|
87
68
|
bold(text) {
|
|
88
|
-
return this.useMarkdown ? `**${text}**` :
|
|
69
|
+
return this.useMarkdown ? `**${text}**` : colors.bold(`${text}`);
|
|
89
70
|
}
|
|
90
71
|
italic(text) {
|
|
91
|
-
return this.useMarkdown ? `_${text}_` :
|
|
72
|
+
return this.useMarkdown ? `_${text}_` : colors.italic(`${text}`);
|
|
92
73
|
}
|
|
93
74
|
hyperlink(text, url, {
|
|
94
75
|
fallback = true,
|
|
95
76
|
fallbackToUrl
|
|
96
77
|
} = {}) {
|
|
97
78
|
if (!url) return text;
|
|
98
|
-
return this.useMarkdown ? `[${text}](${url})` : (
|
|
79
|
+
return this.useMarkdown ? `[${text}](${url})` : terminalLink(text, url, {
|
|
99
80
|
fallback: fallbackToUrl ? (_text, url) => url : fallback
|
|
100
81
|
});
|
|
101
82
|
}
|
|
@@ -114,19 +95,9 @@ class ColorOrMarkdown {
|
|
|
114
95
|
return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
|
|
115
96
|
}
|
|
116
97
|
}
|
|
117
|
-
colorOrMarkdown.ColorOrMarkdown = ColorOrMarkdown;
|
|
118
|
-
|
|
119
|
-
var misc = {};
|
|
120
98
|
|
|
121
|
-
Object.defineProperty(misc, "__esModule", {
|
|
122
|
-
value: true
|
|
123
|
-
});
|
|
124
|
-
misc.createDebugLogger = createDebugLogger;
|
|
125
|
-
misc.isErrnoException = isErrnoException;
|
|
126
|
-
misc.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
|
|
127
|
-
var _colorOrMarkdown = colorOrMarkdown;
|
|
128
99
|
function createDebugLogger(printDebugLogs) {
|
|
129
|
-
return printDebugLogs ? (...params) => console.error(
|
|
100
|
+
return printDebugLogs ? (...params) => console.error(logSymbols.info, ...params) : () => {};
|
|
130
101
|
}
|
|
131
102
|
function isErrnoException(value) {
|
|
132
103
|
if (!(value instanceof Error)) {
|
|
@@ -143,36 +114,23 @@ function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
|
143
114
|
return values.join(', ') + separator + finalValue;
|
|
144
115
|
}
|
|
145
116
|
|
|
146
|
-
var sdk = {};
|
|
147
|
-
|
|
148
|
-
var settings$1 = {};
|
|
149
|
-
|
|
150
|
-
Object.defineProperty(settings$1, "__esModule", {
|
|
151
|
-
value: true
|
|
152
|
-
});
|
|
153
|
-
settings$1.getSetting = getSetting;
|
|
154
|
-
settings$1.updateSetting = updateSetting;
|
|
155
|
-
var _nodeFs = require$$0;
|
|
156
|
-
var _nodeOs = require$$2$1;
|
|
157
|
-
var _nodePath = require$$1$1;
|
|
158
|
-
var _yoctoSpinner = require$$3$1;
|
|
159
117
|
let dataHome = process.platform === 'win32' ? process.env['LOCALAPPDATA'] : process.env['XDG_DATA_HOME'];
|
|
160
118
|
if (!dataHome) {
|
|
161
119
|
if (process.platform === 'win32') throw new Error('missing %LOCALAPPDATA%');
|
|
162
|
-
const home =
|
|
163
|
-
dataHome =
|
|
120
|
+
const home = homedir.homedir();
|
|
121
|
+
dataHome = path.join(home, ...(process.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
|
|
164
122
|
}
|
|
165
|
-
const settingsPath =
|
|
123
|
+
const settingsPath = path.join(dataHome, 'socket', 'settings');
|
|
166
124
|
let settings = {};
|
|
167
|
-
if (
|
|
168
|
-
const raw =
|
|
125
|
+
if (fs.existsSync(settingsPath)) {
|
|
126
|
+
const raw = fs.readFileSync(settingsPath, 'utf8');
|
|
169
127
|
try {
|
|
170
128
|
settings = JSON.parse(Buffer.from(raw, 'base64').toString());
|
|
171
129
|
} catch {
|
|
172
|
-
|
|
130
|
+
yoctoSpinner().warning(`Failed to parse settings at ${settingsPath}`);
|
|
173
131
|
}
|
|
174
132
|
} else {
|
|
175
|
-
|
|
133
|
+
fs.mkdirSync(path.dirname(settingsPath), {
|
|
176
134
|
recursive: true
|
|
177
135
|
});
|
|
178
136
|
}
|
|
@@ -186,65 +144,51 @@ function updateSetting(key, value) {
|
|
|
186
144
|
pendingSave = true;
|
|
187
145
|
process.nextTick(() => {
|
|
188
146
|
pendingSave = false;
|
|
189
|
-
|
|
147
|
+
fs.writeFileSync(settingsPath, Buffer.from(JSON.stringify(settings)).toString('base64'));
|
|
190
148
|
});
|
|
191
149
|
}
|
|
192
150
|
}
|
|
193
151
|
|
|
194
|
-
var _interopRequireDefault = vendor.interopRequireDefault.default;
|
|
195
|
-
Object.defineProperty(sdk, "__esModule", {
|
|
196
|
-
value: true
|
|
197
|
-
});
|
|
198
|
-
sdk.getDefaultKey = getDefaultKey;
|
|
199
|
-
sdk.setupSdk = setupSdk;
|
|
200
|
-
var _hpagent = require$$1$2;
|
|
201
|
-
var _isInteractive = _interopRequireDefault(require$$2$2);
|
|
202
|
-
var _prompts = require$$1$3;
|
|
203
|
-
var _strings = require$$4;
|
|
204
|
-
var _sdk = require$$5;
|
|
205
|
-
var _constants = constants.constants;
|
|
206
|
-
var _errors = errors;
|
|
207
|
-
var _settings = settings$1;
|
|
208
152
|
const {
|
|
209
153
|
rootPkgJsonPath
|
|
210
|
-
} =
|
|
154
|
+
} = constants;
|
|
211
155
|
|
|
212
156
|
// This API key should be stored globally for the duration of the CLI execution.
|
|
213
157
|
let defaultKey;
|
|
214
158
|
function getDefaultKey() {
|
|
215
|
-
const key = process.env['SOCKET_SECURITY_API_KEY'] ||
|
|
216
|
-
defaultKey =
|
|
159
|
+
const key = process.env['SOCKET_SECURITY_API_KEY'] || getSetting('apiKey') || defaultKey;
|
|
160
|
+
defaultKey = strings.isNonEmptyString(key) ? key : undefined;
|
|
217
161
|
return defaultKey;
|
|
218
162
|
}
|
|
219
163
|
|
|
220
164
|
// The API server that should be used for operations.
|
|
221
165
|
function getDefaultAPIBaseUrl() {
|
|
222
|
-
const baseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] ||
|
|
223
|
-
return
|
|
166
|
+
const baseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] || getSetting('apiBaseUrl');
|
|
167
|
+
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
|
|
224
168
|
}
|
|
225
169
|
|
|
226
170
|
// The API server that should be used for operations.
|
|
227
171
|
function getDefaultHTTPProxy() {
|
|
228
|
-
const apiProxy = process.env['SOCKET_SECURITY_API_PROXY'] ||
|
|
229
|
-
return
|
|
172
|
+
const apiProxy = process.env['SOCKET_SECURITY_API_PROXY'] || getSetting('apiProxy');
|
|
173
|
+
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
|
|
230
174
|
}
|
|
231
175
|
async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBaseUrl(), proxy = getDefaultHTTPProxy()) {
|
|
232
|
-
if (typeof apiKey !== 'string' && (
|
|
233
|
-
apiKey = await
|
|
176
|
+
if (typeof apiKey !== 'string' && isInteractive()) {
|
|
177
|
+
apiKey = await prompts.password({
|
|
234
178
|
message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
235
179
|
});
|
|
236
180
|
defaultKey = apiKey;
|
|
237
181
|
}
|
|
238
182
|
if (!apiKey) {
|
|
239
|
-
throw new
|
|
183
|
+
throw new AuthError('You need to provide an API key');
|
|
240
184
|
}
|
|
241
185
|
let agent;
|
|
242
186
|
if (proxy) {
|
|
243
187
|
agent = {
|
|
244
|
-
http: new
|
|
188
|
+
http: new hpagent.HttpProxyAgent({
|
|
245
189
|
proxy
|
|
246
190
|
}),
|
|
247
|
-
https: new
|
|
191
|
+
https: new hpagent.HttpsProxyAgent({
|
|
248
192
|
proxy
|
|
249
193
|
})
|
|
250
194
|
};
|
|
@@ -252,13 +196,19 @@ async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBase
|
|
|
252
196
|
const sdkOptions = {
|
|
253
197
|
agent,
|
|
254
198
|
baseUrl: apiBaseUrl,
|
|
255
|
-
userAgent:
|
|
199
|
+
userAgent: sdk.createUserAgentFromPkgJson(require(rootPkgJsonPath))
|
|
256
200
|
};
|
|
257
|
-
return new
|
|
201
|
+
return new sdk.SocketSdk(apiKey || '', sdkOptions);
|
|
258
202
|
}
|
|
259
203
|
|
|
260
|
-
exports.
|
|
261
|
-
exports.
|
|
262
|
-
exports.
|
|
263
|
-
exports.
|
|
264
|
-
exports.
|
|
204
|
+
exports.AuthError = AuthError;
|
|
205
|
+
exports.ColorOrMarkdown = ColorOrMarkdown;
|
|
206
|
+
exports.InputError = InputError;
|
|
207
|
+
exports.createDebugLogger = createDebugLogger;
|
|
208
|
+
exports.getDefaultKey = getDefaultKey;
|
|
209
|
+
exports.getSetting = getSetting;
|
|
210
|
+
exports.isErrnoException = isErrnoException;
|
|
211
|
+
exports.logSymbols = logSymbols;
|
|
212
|
+
exports.setupSdk = setupSdk;
|
|
213
|
+
exports.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
|
|
214
|
+
exports.updateSetting = updateSetting;
|
|
@@ -0,0 +1,103 @@
|
|
|
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 fs = require('node:fs');
|
|
13
|
+
var path = require('node:path');
|
|
14
|
+
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
15
|
+
var constants = require('./constants.js');
|
|
16
|
+
var cmdShim = _socketInterop(require('cmd-shim'));
|
|
17
|
+
var pathResolve = require('./path-resolve.js');
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
WIN32,
|
|
21
|
+
rootDistPath
|
|
22
|
+
} = constants;
|
|
23
|
+
async function installLinks(realBinPath, binName) {
|
|
24
|
+
// Find package manager being shadowed by this process.
|
|
25
|
+
const {
|
|
26
|
+
path: binPath,
|
|
27
|
+
shadowed
|
|
28
|
+
} = await pathResolve.findBinPathDetails(binName);
|
|
29
|
+
if (!binPath) {
|
|
30
|
+
// The exit code 127 indicates that the command or binary being executed
|
|
31
|
+
// could not be found.
|
|
32
|
+
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
33
|
+
process.exit(127);
|
|
34
|
+
}
|
|
35
|
+
// TODO: Is this early exit needed?
|
|
36
|
+
if (WIN32 && binPath) {
|
|
37
|
+
return binPath;
|
|
38
|
+
}
|
|
39
|
+
// Move our bin directory to front of PATH so its found first.
|
|
40
|
+
if (!shadowed) {
|
|
41
|
+
if (WIN32) {
|
|
42
|
+
await cmdShim(path.join(rootDistPath, `${binName}-cli.js`), path.join(realBinPath, binName));
|
|
43
|
+
}
|
|
44
|
+
process.env['PATH'] = `${realBinPath}${path.delimiter}${process.env['PATH']}`;
|
|
45
|
+
}
|
|
46
|
+
return binPath;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
NPM,
|
|
51
|
+
abortSignal,
|
|
52
|
+
distPath,
|
|
53
|
+
execPath,
|
|
54
|
+
shadowBinPath
|
|
55
|
+
} = constants;
|
|
56
|
+
const injectionPath = path.join(distPath, 'npm-injection.js');
|
|
57
|
+
async function shadow(binName, binArgs = process.argv.slice(2)) {
|
|
58
|
+
const binPath = await installLinks(shadowBinPath, binName);
|
|
59
|
+
if (abortSignal.aborted) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// Adding the `--quiet` and `--no-progress` flags when the `proc-log` module
|
|
63
|
+
// is found to fix a UX issue when running the command with recent versions of
|
|
64
|
+
// npm (input swallowed by the standard npm spinner)
|
|
65
|
+
if (binName === NPM && binArgs.includes('install') && !binArgs.includes('--no-progress') && !binArgs.includes('--quiet')) {
|
|
66
|
+
const npmEntrypoint = fs.realpathSync(binPath);
|
|
67
|
+
const npmRootPath = pathResolve.findRoot(path.dirname(npmEntrypoint));
|
|
68
|
+
if (npmRootPath === undefined) {
|
|
69
|
+
// The exit code 127 indicates that the command or binary being executed
|
|
70
|
+
// could not be found.
|
|
71
|
+
process.exit(127);
|
|
72
|
+
}
|
|
73
|
+
const npmDepPath = path.join(npmRootPath, 'node_modules');
|
|
74
|
+
let procLog;
|
|
75
|
+
try {
|
|
76
|
+
procLog = require(path.join(npmDepPath, 'proc-log/lib/index.js')).log;
|
|
77
|
+
} catch {}
|
|
78
|
+
if (procLog) {
|
|
79
|
+
binArgs.push('--no-progress', '--quiet');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
process.exitCode = 1;
|
|
83
|
+
const spawnPromise = spawn(execPath, [
|
|
84
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
85
|
+
...constants.nodeNoWarningsFlags, '--require', injectionPath, binPath, ...binArgs], {
|
|
86
|
+
signal: abortSignal,
|
|
87
|
+
stdio: 'inherit'
|
|
88
|
+
});
|
|
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);
|
|
96
|
+
} else if (code !== null) {
|
|
97
|
+
process.exit(code);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
await spawnPromise;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = shadow;
|