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