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