@socketsecurity/cli 0.14.28 → 0.14.30
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 +7 -0
- package/bin/npm-cli.js +7 -0
- package/bin/npx-cli.js +7 -0
- package/bin/shadow/module-sync/npm +3 -0
- package/bin/shadow/module-sync/npx +3 -0
- package/bin/shadow/require/npm +3 -0
- package/bin/shadow/require/npx +3 -0
- package/dist/module-sync/cli.d.ts.map +1 -0
- package/dist/module-sync/cli.js +5258 -0
- package/dist/module-sync/constants.d.ts +20 -0
- package/dist/module-sync/constants.js +72 -0
- package/dist/module-sync/npm-cli.js +85 -0
- package/dist/module-sync/npm-injection.js +1609 -0
- package/dist/module-sync/npx-cli.js +61 -0
- package/dist/{sdk.d.ts → module-sync/sdk.d.ts} +1 -5
- package/dist/module-sync/sdk.js +253 -0
- package/dist/require/cli.d.ts +3 -0
- package/dist/require/cli.d.ts.map +1 -0
- package/dist/{cli.js → require/cli.js} +80 -82
- package/dist/require/color-or-markdown.d.ts +23 -0
- package/dist/require/constants.d.ts +20 -0
- package/dist/require/constants.js +67 -0
- package/dist/require/errors.d.ts +7 -0
- package/dist/require/link.d.ts +2 -0
- package/dist/require/link.js +45 -0
- package/dist/require/npm-cli.d.ts +2 -0
- package/dist/{npm-cli.js → require/npm-cli.js} +12 -10
- package/dist/require/npm-injection.d.ts +1 -0
- package/dist/{npm-injection.js → require/npm-injection.js} +169 -135
- package/dist/require/npx-cli.d.ts +2 -0
- package/dist/{npx-cli.js → require/npx-cli.js} +12 -12
- package/dist/require/path-resolve.d.ts +8 -0
- package/dist/require/path-resolve.js +183 -0
- package/dist/require/sdk.d.ts +9 -0
- package/dist/{sdk.js → require/sdk.js} +16 -36
- package/dist/require/settings.d.ts +9 -0
- package/dist/{vendor.js → require/vendor.js} +6 -1
- package/package.json +54 -19
- package/translations.json +190 -287
- package/bin/npm +0 -2
- package/bin/npx +0 -2
- package/dist/cli.d.ts.map +0 -1
- /package/dist/{cli.d.ts → module-sync/cli.d.ts} +0 -0
- /package/dist/{color-or-markdown.d.ts → module-sync/color-or-markdown.d.ts} +0 -0
- /package/dist/{errors.d.ts → module-sync/errors.d.ts} +0 -0
- /package/dist/{link.d.ts → module-sync/link.d.ts} +0 -0
- /package/dist/{link.js → module-sync/link.js} +0 -0
- /package/dist/{npm-cli.d.ts → module-sync/npm-cli.d.ts} +0 -0
- /package/dist/{npm-injection.d.ts → module-sync/npm-injection.d.ts} +0 -0
- /package/dist/{npx-cli.d.ts → module-sync/npx-cli.d.ts} +0 -0
- /package/dist/{path-resolve.d.ts → module-sync/path-resolve.d.ts} +0 -0
- /package/dist/{path-resolve.js → module-sync/path-resolve.js} +0 -0
- /package/dist/{settings.d.ts → module-sync/settings.d.ts} +0 -0
|
@@ -0,0 +1,1609 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constants = require('./constants.js');
|
|
4
|
+
var require$$0$2 = require('@babel/runtime/helpers/interopRequireWildcard');
|
|
5
|
+
var require$$0$1 = require('@babel/runtime/helpers/interopRequireDefault');
|
|
6
|
+
var require$$1$2 = require('node:events');
|
|
7
|
+
var require$$0 = require('node:fs');
|
|
8
|
+
var require$$3$3 = require('node:https');
|
|
9
|
+
var require$$1 = require('node:path');
|
|
10
|
+
var require$$3 = require('node:readline');
|
|
11
|
+
var require$$5 = require('node:stream');
|
|
12
|
+
var require$$7$1 = require('node:timers/promises');
|
|
13
|
+
var require$$3$1 = require('is-interactive');
|
|
14
|
+
var require$$5$1 = require('npm-package-arg');
|
|
15
|
+
var require$$3$2 = require('@socketregistry/yocto-spinner');
|
|
16
|
+
var require$$4 = require('semver');
|
|
17
|
+
var require$$6$1 = require('@socketsecurity/config');
|
|
18
|
+
var require$$7 = require('@socketsecurity/registry/lib/objects');
|
|
19
|
+
var require$$1$1 = require('node:net');
|
|
20
|
+
var require$$2 = require('node:os');
|
|
21
|
+
var require$$6 = require('../../package.json');
|
|
22
|
+
var sdk = require('./sdk.js');
|
|
23
|
+
var pathResolve = require('./path-resolve.js');
|
|
24
|
+
var link = require('./link.js');
|
|
25
|
+
|
|
26
|
+
var npmInjection$2 = {};
|
|
27
|
+
|
|
28
|
+
var npmInjection$1 = {};
|
|
29
|
+
|
|
30
|
+
var arborist = {};
|
|
31
|
+
|
|
32
|
+
var ttyServer$1 = {};
|
|
33
|
+
|
|
34
|
+
Object.defineProperty(ttyServer$1, "__esModule", {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
37
|
+
ttyServer$1.createTTYServer = createTTYServer;
|
|
38
|
+
var _nodeFs$1 = require$$0;
|
|
39
|
+
var _nodeNet = require$$1$1;
|
|
40
|
+
var _nodeOs = require$$2;
|
|
41
|
+
var _nodePath$1 = require$$1;
|
|
42
|
+
var _nodeReadline$1 = require$$3;
|
|
43
|
+
var _nodeStream$1 = require$$5;
|
|
44
|
+
var _package = require$$6;
|
|
45
|
+
var _misc$1 = sdk.misc;
|
|
46
|
+
const NEWLINE_CHAR_CODE = 10; /*'\n'*/
|
|
47
|
+
|
|
48
|
+
const TTY_IPC = process.env['SOCKET_SECURITY_TTY_IPC'];
|
|
49
|
+
const sock = _nodePath$1.join(_nodeOs.tmpdir(), `socket-security-tty-${process.pid}.sock`);
|
|
50
|
+
process.env['SOCKET_SECURITY_TTY_IPC'] = sock;
|
|
51
|
+
function createNonStandardTTYServer() {
|
|
52
|
+
return {
|
|
53
|
+
async captureTTY(mutexFn) {
|
|
54
|
+
return await new Promise((resolve, reject) => {
|
|
55
|
+
const conn = _nodeNet.createConnection({
|
|
56
|
+
path: TTY_IPC
|
|
57
|
+
}).on('error', reject);
|
|
58
|
+
let captured = false;
|
|
59
|
+
const buffs = [];
|
|
60
|
+
conn.on('data', function awaitCapture(chunk) {
|
|
61
|
+
buffs.push(chunk);
|
|
62
|
+
let lineBuff = Buffer.concat(buffs);
|
|
63
|
+
if (captured) return;
|
|
64
|
+
try {
|
|
65
|
+
const eolIndex = lineBuff.indexOf(NEWLINE_CHAR_CODE);
|
|
66
|
+
if (eolIndex !== -1) {
|
|
67
|
+
conn.removeListener('data', awaitCapture);
|
|
68
|
+
conn.push(lineBuff.slice(eolIndex + 1));
|
|
69
|
+
const {
|
|
70
|
+
capabilities: {
|
|
71
|
+
input: hasInput,
|
|
72
|
+
output: hasOutput
|
|
73
|
+
},
|
|
74
|
+
ipc_version: remote_ipc_version
|
|
75
|
+
} = JSON.parse(lineBuff.subarray(0, eolIndex).toString('utf-8'));
|
|
76
|
+
lineBuff = null;
|
|
77
|
+
captured = true;
|
|
78
|
+
if (remote_ipc_version !== _package.version) {
|
|
79
|
+
throw new Error('Mismatched STDIO tunnel IPC version, ensure you only have 1 version of socket CLI being called.');
|
|
80
|
+
}
|
|
81
|
+
const input = hasInput ? new _nodeStream$1.PassThrough() : null;
|
|
82
|
+
input?.pause();
|
|
83
|
+
if (input) conn.pipe(input);
|
|
84
|
+
const output = hasOutput ? new _nodeStream$1.PassThrough() : null;
|
|
85
|
+
if (output) {
|
|
86
|
+
output.pipe(conn)
|
|
87
|
+
// Make ora happy
|
|
88
|
+
;
|
|
89
|
+
output.isTTY = true;
|
|
90
|
+
output.cursorTo = function cursorTo(x, y, callback) {
|
|
91
|
+
_nodeReadline$1.cursorTo(this, x, y, callback);
|
|
92
|
+
};
|
|
93
|
+
output.clearLine = function clearLine(dir, callback) {
|
|
94
|
+
_nodeReadline$1.clearLine(this, dir, callback);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
mutexFn(hasInput ? input : undefined, hasOutput ? output : undefined).then(resolve, reject).finally(() => {
|
|
98
|
+
conn.unref();
|
|
99
|
+
conn.end();
|
|
100
|
+
input?.end();
|
|
101
|
+
output?.end();
|
|
102
|
+
// process.exit(13)
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
} catch (e) {
|
|
106
|
+
reject(e);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function createIPCServer(captureState, npmlog) {
|
|
114
|
+
const input = process.stdin;
|
|
115
|
+
const output = process.stderr;
|
|
116
|
+
return new Promise((resolve, reject) => {
|
|
117
|
+
const server = _nodeNet
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
119
|
+
.createServer(async conn => {
|
|
120
|
+
if (captureState.captured) {
|
|
121
|
+
await new Promise(resolve => {
|
|
122
|
+
captureState.pendingCaptures.push({
|
|
123
|
+
resolve() {
|
|
124
|
+
resolve();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
captureState.captured = true;
|
|
130
|
+
}
|
|
131
|
+
const wasProgressEnabled = npmlog.progressEnabled;
|
|
132
|
+
npmlog.pause();
|
|
133
|
+
if (wasProgressEnabled) {
|
|
134
|
+
npmlog.disableProgress();
|
|
135
|
+
}
|
|
136
|
+
conn.write(`${JSON.stringify({
|
|
137
|
+
ipc_version: _package.version,
|
|
138
|
+
capabilities: {
|
|
139
|
+
input: Boolean(input),
|
|
140
|
+
output: true
|
|
141
|
+
}
|
|
142
|
+
})}\n`);
|
|
143
|
+
conn.on('data', data => {
|
|
144
|
+
output.write(data);
|
|
145
|
+
}).on('error', e => {
|
|
146
|
+
output.write(`there was an error prompting from a sub shell (${e?.message}), socket npm closing`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
});
|
|
149
|
+
input.on('data', data => {
|
|
150
|
+
conn.write(data);
|
|
151
|
+
}).on('end', () => {
|
|
152
|
+
conn.unref();
|
|
153
|
+
conn.end();
|
|
154
|
+
if (wasProgressEnabled) {
|
|
155
|
+
npmlog.enableProgress();
|
|
156
|
+
}
|
|
157
|
+
npmlog.resume();
|
|
158
|
+
captureState.nextCapture();
|
|
159
|
+
});
|
|
160
|
+
}).listen(sock, () => resolve(server)).on('error', reject).unref();
|
|
161
|
+
process.on('exit', () => {
|
|
162
|
+
server.close();
|
|
163
|
+
tryUnlinkSync(sock);
|
|
164
|
+
});
|
|
165
|
+
resolve(server);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function createStandardTTYServer(isInteractive, npmlog) {
|
|
169
|
+
const captureState = {
|
|
170
|
+
captured: false,
|
|
171
|
+
nextCapture: () => {
|
|
172
|
+
if (captureState.pendingCaptures.length > 0) {
|
|
173
|
+
const pendingCapture = captureState.pendingCaptures.shift();
|
|
174
|
+
pendingCapture?.resolve();
|
|
175
|
+
} else {
|
|
176
|
+
captureState.captured = false;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
pendingCaptures: []
|
|
180
|
+
};
|
|
181
|
+
tryUnlinkSync(sock);
|
|
182
|
+
const input = isInteractive ? process.stdin : undefined;
|
|
183
|
+
const output = process.stderr;
|
|
184
|
+
let ipcServerPromise;
|
|
185
|
+
if (input) {
|
|
186
|
+
ipcServerPromise = createIPCServer(captureState, npmlog);
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
async captureTTY(mutexFn) {
|
|
190
|
+
await ipcServerPromise;
|
|
191
|
+
if (captureState.captured) {
|
|
192
|
+
const captured = new Promise(resolve => {
|
|
193
|
+
captureState.pendingCaptures.push({
|
|
194
|
+
resolve() {
|
|
195
|
+
resolve();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
await captured;
|
|
200
|
+
} else {
|
|
201
|
+
captureState.captured = true;
|
|
202
|
+
}
|
|
203
|
+
const wasProgressEnabled = npmlog.progressEnabled;
|
|
204
|
+
try {
|
|
205
|
+
npmlog.pause();
|
|
206
|
+
if (wasProgressEnabled) {
|
|
207
|
+
npmlog.disableProgress();
|
|
208
|
+
}
|
|
209
|
+
return await mutexFn(input, output);
|
|
210
|
+
} finally {
|
|
211
|
+
if (wasProgressEnabled) {
|
|
212
|
+
npmlog.enableProgress();
|
|
213
|
+
}
|
|
214
|
+
npmlog.resume();
|
|
215
|
+
captureState.nextCapture();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function tryUnlinkSync(filepath) {
|
|
221
|
+
try {
|
|
222
|
+
(0, _nodeFs$1.unlinkSync)(filepath);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
if ((0, _misc$1.isErrnoException)(e) && e.code !== 'ENOENT') {
|
|
225
|
+
throw e;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function createTTYServer(isInteractive, npmlog) {
|
|
230
|
+
return !isInteractive && TTY_IPC ? createNonStandardTTYServer() : createStandardTTYServer(isInteractive, npmlog);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
var issueRules = {};
|
|
234
|
+
|
|
235
|
+
Object.defineProperty(issueRules, "__esModule", {
|
|
236
|
+
value: true
|
|
237
|
+
});
|
|
238
|
+
issueRules.createIssueUXLookup = createIssueUXLookup;
|
|
239
|
+
//#region UX Constants
|
|
240
|
+
|
|
241
|
+
const IGNORE_UX = {
|
|
242
|
+
block: false,
|
|
243
|
+
display: false
|
|
244
|
+
};
|
|
245
|
+
const WARN_UX = {
|
|
246
|
+
block: false,
|
|
247
|
+
display: true
|
|
248
|
+
};
|
|
249
|
+
const ERROR_UX = {
|
|
250
|
+
block: true,
|
|
251
|
+
display: true
|
|
252
|
+
};
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region utils
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Iterates over all entries with ordered issue rule for deferral. Iterates over
|
|
258
|
+
* all issue rules and finds the first defined value that does not defer otherwise
|
|
259
|
+
* uses the defaultValue. Takes the value and converts into a UX workflow
|
|
260
|
+
*/
|
|
261
|
+
function resolveIssueRuleUX(entriesOrderedIssueRules, defaultValue) {
|
|
262
|
+
if (defaultValue === true || defaultValue == null) {
|
|
263
|
+
defaultValue = {
|
|
264
|
+
action: 'error'
|
|
265
|
+
};
|
|
266
|
+
} else if (defaultValue === false) {
|
|
267
|
+
defaultValue = {
|
|
268
|
+
action: 'ignore'
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
let block = false;
|
|
272
|
+
let display = false;
|
|
273
|
+
let needDefault = true;
|
|
274
|
+
iterate_entries: for (const issueRuleArr of entriesOrderedIssueRules) {
|
|
275
|
+
for (const rule of issueRuleArr) {
|
|
276
|
+
if (issueRuleValueDoesNotDefer(rule)) {
|
|
277
|
+
needDefault = false;
|
|
278
|
+
const narrowingFilter = uxForDefinedNonDeferValue(rule);
|
|
279
|
+
block = block || narrowingFilter.block;
|
|
280
|
+
display = display || narrowingFilter.display;
|
|
281
|
+
continue iterate_entries;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const narrowingFilter = uxForDefinedNonDeferValue(defaultValue);
|
|
285
|
+
block = block || narrowingFilter.block;
|
|
286
|
+
display = display || narrowingFilter.display;
|
|
287
|
+
}
|
|
288
|
+
if (needDefault) {
|
|
289
|
+
const narrowingFilter = uxForDefinedNonDeferValue(defaultValue);
|
|
290
|
+
block = block || narrowingFilter.block;
|
|
291
|
+
display = display || narrowingFilter.display;
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
block,
|
|
295
|
+
display
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Negative form because it is narrowing the type
|
|
301
|
+
*/
|
|
302
|
+
function issueRuleValueDoesNotDefer(issueRule) {
|
|
303
|
+
if (issueRule === undefined) {
|
|
304
|
+
return false;
|
|
305
|
+
} else if (typeof issueRule === 'object' && issueRule) {
|
|
306
|
+
const {
|
|
307
|
+
action
|
|
308
|
+
} = issueRule;
|
|
309
|
+
if (action === undefined || action === 'defer') {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Handles booleans for backwards compatibility
|
|
318
|
+
*/
|
|
319
|
+
function uxForDefinedNonDeferValue(issueRuleValue) {
|
|
320
|
+
if (typeof issueRuleValue === 'boolean') {
|
|
321
|
+
return issueRuleValue ? ERROR_UX : IGNORE_UX;
|
|
322
|
+
}
|
|
323
|
+
const {
|
|
324
|
+
action
|
|
325
|
+
} = issueRuleValue;
|
|
326
|
+
if (action === 'warn') {
|
|
327
|
+
return WARN_UX;
|
|
328
|
+
} else if (action === 'ignore') {
|
|
329
|
+
return IGNORE_UX;
|
|
330
|
+
}
|
|
331
|
+
return ERROR_UX;
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
|
+
|
|
335
|
+
//#region exports
|
|
336
|
+
|
|
337
|
+
function createIssueUXLookup(settings) {
|
|
338
|
+
const cachedUX = new Map();
|
|
339
|
+
return context => {
|
|
340
|
+
const key = context.issue.type;
|
|
341
|
+
let ux = cachedUX.get(key);
|
|
342
|
+
if (ux) {
|
|
343
|
+
return ux;
|
|
344
|
+
}
|
|
345
|
+
const entriesOrderedIssueRules = [];
|
|
346
|
+
for (const settingsEntry of settings.entries) {
|
|
347
|
+
const orderedIssueRules = [];
|
|
348
|
+
let target = settingsEntry.start;
|
|
349
|
+
while (target !== null) {
|
|
350
|
+
const resolvedTarget = settingsEntry.settings[target];
|
|
351
|
+
if (!resolvedTarget) {
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
const issueRuleValue = resolvedTarget.issueRules?.[key];
|
|
355
|
+
if (typeof issueRuleValue !== 'undefined') {
|
|
356
|
+
orderedIssueRules.push(issueRuleValue);
|
|
357
|
+
}
|
|
358
|
+
target = resolvedTarget.deferTo ?? null;
|
|
359
|
+
}
|
|
360
|
+
entriesOrderedIssueRules.push(orderedIssueRules);
|
|
361
|
+
}
|
|
362
|
+
const defaultValue = settings.defaults.issueRules[key];
|
|
363
|
+
let resolvedDefaultValue = {
|
|
364
|
+
action: 'error'
|
|
365
|
+
};
|
|
366
|
+
if (defaultValue === false) {
|
|
367
|
+
resolvedDefaultValue = {
|
|
368
|
+
action: 'ignore'
|
|
369
|
+
};
|
|
370
|
+
} else if (defaultValue && defaultValue !== true) {
|
|
371
|
+
resolvedDefaultValue = {
|
|
372
|
+
action: defaultValue.action ?? 'error'
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
ux = resolveIssueRuleUX(entriesOrderedIssueRules, resolvedDefaultValue);
|
|
376
|
+
cachedUX.set(key, ux);
|
|
377
|
+
return ux;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
var _interopRequireDefault = require$$0$1.default;
|
|
382
|
+
Object.defineProperty(arborist, "__esModule", {
|
|
383
|
+
value: true
|
|
384
|
+
});
|
|
385
|
+
arborist.SafeArborist = void 0;
|
|
386
|
+
arborist.installSafeArborist = installSafeArborist;
|
|
387
|
+
var _nodeEvents = require$$1$2;
|
|
388
|
+
var _nodeFs = require$$0;
|
|
389
|
+
var _nodeHttps = require$$3$3;
|
|
390
|
+
var _nodePath = require$$1;
|
|
391
|
+
var _nodeReadline = require$$3;
|
|
392
|
+
var _nodeStream = require$$5;
|
|
393
|
+
var _promises = require$$7$1;
|
|
394
|
+
var _isInteractive = _interopRequireDefault(require$$3$1);
|
|
395
|
+
var _npmPackageArg = require$$5$1;
|
|
396
|
+
var _yoctoSpinner = require$$3$2;
|
|
397
|
+
var _semver = require$$4;
|
|
398
|
+
var _config = require$$6$1;
|
|
399
|
+
var _objects = require$$7;
|
|
400
|
+
var _ttyServer = ttyServer$1;
|
|
401
|
+
var _constants$1 = constants.constants;
|
|
402
|
+
var _colorOrMarkdown = sdk.colorOrMarkdown;
|
|
403
|
+
var _issueRules = issueRules;
|
|
404
|
+
var _misc = sdk.misc;
|
|
405
|
+
var _pathResolve = pathResolve.pathResolve;
|
|
406
|
+
var _sdk = sdk.sdk;
|
|
407
|
+
var _settings = sdk.settings;
|
|
408
|
+
const POTENTIAL_BUG_ERROR_MESSAGE = `This is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${_constants$1.SOCKET_CLI_ISSUES_URL}.`;
|
|
409
|
+
const npmEntrypoint = (0, _nodeFs.realpathSync)(process.argv[1]);
|
|
410
|
+
const npmRootPath = (0, _pathResolve.findRoot)(_nodePath.dirname(npmEntrypoint));
|
|
411
|
+
function tryRequire(...ids) {
|
|
412
|
+
for (const data of ids) {
|
|
413
|
+
let id;
|
|
414
|
+
let transformer;
|
|
415
|
+
if (Array.isArray(data)) {
|
|
416
|
+
id = data[0];
|
|
417
|
+
transformer = data[1];
|
|
418
|
+
} else {
|
|
419
|
+
id = data;
|
|
420
|
+
transformer = mod => mod;
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
// Check that the transformed value isn't `undefined` because older
|
|
424
|
+
// versions of packages like 'proc-log' may not export a `log` method.
|
|
425
|
+
const exported = transformer(require(id));
|
|
426
|
+
if (exported !== undefined) {
|
|
427
|
+
return exported;
|
|
428
|
+
}
|
|
429
|
+
} catch {}
|
|
430
|
+
}
|
|
431
|
+
return undefined;
|
|
432
|
+
}
|
|
433
|
+
if (npmRootPath === undefined) {
|
|
434
|
+
console.error(`Unable to find npm CLI install directory.\nSearched parent directories of ${npmEntrypoint}.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}`);
|
|
435
|
+
process.exit(127);
|
|
436
|
+
}
|
|
437
|
+
const npmNmPath = _nodePath.join(npmRootPath, 'node_modules');
|
|
438
|
+
const arboristPkgPath = _nodePath.join(npmNmPath, '@npmcli/arborist');
|
|
439
|
+
const arboristClassPath = _nodePath.join(arboristPkgPath, 'lib/arborist/index.js');
|
|
440
|
+
const arboristDepValidPath = _nodePath.join(arboristPkgPath, 'lib/dep-valid.js');
|
|
441
|
+
const arboristEdgeClassPath = _nodePath.join(arboristPkgPath, 'lib/edge.js');
|
|
442
|
+
const arboristNodeClassPath = _nodePath.join(arboristPkgPath, 'lib/node.js');
|
|
443
|
+
const arboristOverrideSetClassPatch = _nodePath.join(arboristPkgPath, 'lib/override-set.js');
|
|
444
|
+
const log = tryRequire([_nodePath.join(npmNmPath, 'proc-log/lib/index.js'),
|
|
445
|
+
// The proc-log DefinitelyTyped definition is incorrect. The type definition
|
|
446
|
+
// is really that of its export log.
|
|
447
|
+
mod => mod.log], _nodePath.join(npmNmPath, 'npmlog/lib/log.js'));
|
|
448
|
+
if (log === undefined) {
|
|
449
|
+
console.error(`Unable to integrate with npm CLI logging infrastructure.\n\n${POTENTIAL_BUG_ERROR_MESSAGE}.`);
|
|
450
|
+
process.exit(127);
|
|
451
|
+
}
|
|
452
|
+
const pacote = tryRequire(_nodePath.join(npmNmPath, 'pacote'), 'pacote');
|
|
453
|
+
const {
|
|
454
|
+
tarball
|
|
455
|
+
} = pacote;
|
|
456
|
+
const translations = require(_nodePath.join(_constants$1.rootPath, 'translations.json'));
|
|
457
|
+
const abortController = new AbortController();
|
|
458
|
+
const {
|
|
459
|
+
signal: abortSignal
|
|
460
|
+
} = abortController;
|
|
461
|
+
const Arborist = require(arboristClassPath);
|
|
462
|
+
const depValid = require(arboristDepValidPath);
|
|
463
|
+
const Edge = require(arboristEdgeClassPath);
|
|
464
|
+
const Node = require(arboristNodeClassPath);
|
|
465
|
+
const OverrideSet = require(arboristOverrideSetClassPatch);
|
|
466
|
+
const kCtorArgs = Symbol('ctorArgs');
|
|
467
|
+
const kRiskyReify = Symbol('riskyReify');
|
|
468
|
+
const formatter = new _colorOrMarkdown.ColorOrMarkdown(false);
|
|
469
|
+
const pubToken = (0, _sdk.getDefaultKey)() ?? _sdk.FREE_API_KEY;
|
|
470
|
+
const ttyServer = (0, _ttyServer.createTTYServer)((0, _isInteractive.default)({
|
|
471
|
+
stream: process.stdin
|
|
472
|
+
}), log);
|
|
473
|
+
let _uxLookup;
|
|
474
|
+
async function uxLookup(settings) {
|
|
475
|
+
while (_uxLookup === undefined) {
|
|
476
|
+
// eslint-disable-next-line no-await-in-loop
|
|
477
|
+
await (0, _promises.setTimeout)(1, {
|
|
478
|
+
signal: abortSignal
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
return _uxLookup(settings);
|
|
482
|
+
}
|
|
483
|
+
async function* batchScan(pkgIds) {
|
|
484
|
+
const query = {
|
|
485
|
+
packages: pkgIds.map(id => {
|
|
486
|
+
const {
|
|
487
|
+
name,
|
|
488
|
+
version
|
|
489
|
+
} = pkgidParts(id);
|
|
490
|
+
return {
|
|
491
|
+
eco: 'npm',
|
|
492
|
+
pkg: name,
|
|
493
|
+
ver: version,
|
|
494
|
+
top: true
|
|
495
|
+
};
|
|
496
|
+
})
|
|
497
|
+
};
|
|
498
|
+
// TODO: Migrate to SDK.
|
|
499
|
+
const pkgDataReq = _nodeHttps.request(`${_constants$1.API_V0_URL}/scan/batch`, {
|
|
500
|
+
method: 'POST',
|
|
501
|
+
headers: {
|
|
502
|
+
Authorization: `Basic ${Buffer.from(`${pubToken}:`).toString('base64url')}`
|
|
503
|
+
},
|
|
504
|
+
signal: abortSignal
|
|
505
|
+
}).end(JSON.stringify(query));
|
|
506
|
+
const {
|
|
507
|
+
0: res
|
|
508
|
+
} = await _nodeEvents.once(pkgDataReq, 'response');
|
|
509
|
+
const ok = res.statusCode >= 200 && res.statusCode <= 299;
|
|
510
|
+
if (!ok) {
|
|
511
|
+
throw new Error(`Socket API Error: ${res.statusCode}`);
|
|
512
|
+
}
|
|
513
|
+
const rli = _nodeReadline.createInterface(res);
|
|
514
|
+
for await (const line of rli) {
|
|
515
|
+
yield JSON.parse(line);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Patch adding doOverrideSetsConflict is based on
|
|
520
|
+
// https://github.com/npm/cli/pull/7025.
|
|
521
|
+
function doOverrideSetsConflict(first, second) {
|
|
522
|
+
// If override sets contain one another then we can try to use the more specific
|
|
523
|
+
// one. However, if neither one is more specific, then we consider them to be
|
|
524
|
+
// in conflict.
|
|
525
|
+
return findSpecificOverrideSet(first, second) === undefined;
|
|
526
|
+
}
|
|
527
|
+
function findSocketYmlSync() {
|
|
528
|
+
let prevDir = null;
|
|
529
|
+
let dir = process.cwd();
|
|
530
|
+
while (dir !== prevDir) {
|
|
531
|
+
let ymlPath = _nodePath.join(dir, 'socket.yml');
|
|
532
|
+
let yml = maybeReadfileSync(ymlPath);
|
|
533
|
+
if (yml === undefined) {
|
|
534
|
+
ymlPath = _nodePath.join(dir, 'socket.yaml');
|
|
535
|
+
yml = maybeReadfileSync(ymlPath);
|
|
536
|
+
}
|
|
537
|
+
if (typeof yml === 'string') {
|
|
538
|
+
try {
|
|
539
|
+
return {
|
|
540
|
+
path: ymlPath,
|
|
541
|
+
parsed: _config.parseSocketConfig(yml)
|
|
542
|
+
};
|
|
543
|
+
} catch {
|
|
544
|
+
throw new Error(`Found file but was unable to parse ${ymlPath}`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
prevDir = dir;
|
|
548
|
+
dir = _nodePath.join(dir, '..');
|
|
549
|
+
}
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Patch adding findSpecificOverrideSet is based on
|
|
554
|
+
// https://github.com/npm/cli/pull/7025.
|
|
555
|
+
function findSpecificOverrideSet(first, second) {
|
|
556
|
+
let overrideSet = second;
|
|
557
|
+
while (overrideSet) {
|
|
558
|
+
if (overrideSet.isEqual(first)) {
|
|
559
|
+
return second;
|
|
560
|
+
}
|
|
561
|
+
overrideSet = overrideSet.parent;
|
|
562
|
+
}
|
|
563
|
+
overrideSet = first;
|
|
564
|
+
while (overrideSet) {
|
|
565
|
+
if (overrideSet.isEqual(second)) {
|
|
566
|
+
return first;
|
|
567
|
+
}
|
|
568
|
+
overrideSet = overrideSet.parent;
|
|
569
|
+
}
|
|
570
|
+
// The override sets are incomparable. Neither one contains the other.
|
|
571
|
+
log.silly('Conflicting override sets', first, second);
|
|
572
|
+
return undefined;
|
|
573
|
+
}
|
|
574
|
+
function maybeReadfileSync(filepath) {
|
|
575
|
+
try {
|
|
576
|
+
return (0, _nodeFs.readFileSync)(filepath, 'utf8');
|
|
577
|
+
} catch {}
|
|
578
|
+
return undefined;
|
|
579
|
+
}
|
|
580
|
+
async function packagesHaveRiskyIssues(safeArb, _registry, pkgs, output) {
|
|
581
|
+
const spinner = _yoctoSpinner({
|
|
582
|
+
stream: output
|
|
583
|
+
});
|
|
584
|
+
let result = false;
|
|
585
|
+
let {
|
|
586
|
+
length: remaining
|
|
587
|
+
} = pkgs;
|
|
588
|
+
if (!remaining) {
|
|
589
|
+
spinner.success('No changes detected');
|
|
590
|
+
return result;
|
|
591
|
+
}
|
|
592
|
+
const getText = () => `Looking up data for ${remaining} packages`;
|
|
593
|
+
spinner.start(getText());
|
|
594
|
+
try {
|
|
595
|
+
for await (const pkgData of batchScan(pkgs.map(p => p.pkgid))) {
|
|
596
|
+
const {
|
|
597
|
+
pkg: name,
|
|
598
|
+
ver: version
|
|
599
|
+
} = pkgData;
|
|
600
|
+
const id = `${name}@${version}`;
|
|
601
|
+
let displayWarning = false;
|
|
602
|
+
let failures = [];
|
|
603
|
+
if (pkgData.type === 'missing') {
|
|
604
|
+
result = true;
|
|
605
|
+
failures.push({
|
|
606
|
+
type: 'missingDependency',
|
|
607
|
+
block: false,
|
|
608
|
+
raw: undefined
|
|
609
|
+
});
|
|
610
|
+
} else {
|
|
611
|
+
let blocked = false;
|
|
612
|
+
for (const failure of pkgData.value.issues) {
|
|
613
|
+
const {
|
|
614
|
+
type
|
|
615
|
+
} = failure;
|
|
616
|
+
// eslint-disable-next-line no-await-in-loop
|
|
617
|
+
const ux = await uxLookup({
|
|
618
|
+
package: {
|
|
619
|
+
name,
|
|
620
|
+
version
|
|
621
|
+
},
|
|
622
|
+
issue: {
|
|
623
|
+
type
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
if (ux.block) {
|
|
627
|
+
result = true;
|
|
628
|
+
blocked = true;
|
|
629
|
+
}
|
|
630
|
+
if (ux.display) {
|
|
631
|
+
displayWarning = true;
|
|
632
|
+
}
|
|
633
|
+
if (ux.block || ux.display) {
|
|
634
|
+
failures.push({
|
|
635
|
+
type,
|
|
636
|
+
block: ux.block,
|
|
637
|
+
raw: failure
|
|
638
|
+
});
|
|
639
|
+
// Before we ask about problematic issues, check to see if they
|
|
640
|
+
// already existed in the old version if they did, be quiet.
|
|
641
|
+
const pkg = pkgs.find(p => p.pkgid === id && p.existing?.startsWith(`${name}@`));
|
|
642
|
+
if (pkg?.existing) {
|
|
643
|
+
const oldPkgData =
|
|
644
|
+
// eslint-disable-next-line no-await-in-loop
|
|
645
|
+
(await batchScan([pkg.existing]).next()).value;
|
|
646
|
+
if (oldPkgData.type === 'success') {
|
|
647
|
+
failures = failures.filter(issue => oldPkgData.value.issues.find(oldIssue => oldIssue.type === issue.type) === undefined);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (!blocked) {
|
|
653
|
+
const pkg = pkgs.find(p => p.pkgid === id);
|
|
654
|
+
if (pkg) {
|
|
655
|
+
await tarball.stream(id, stream => {
|
|
656
|
+
stream.resume();
|
|
657
|
+
return stream.promise();
|
|
658
|
+
}, {
|
|
659
|
+
...safeArb[kCtorArgs][0]
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (displayWarning) {
|
|
665
|
+
spinner.stop(`(socket) ${formatter.hyperlink(id, `https://socket.dev/npm/package/${name}/overview/${version}`)} contains risks:`);
|
|
666
|
+
// Filter issues for blessed packages.
|
|
667
|
+
if (name === 'socket' || name.startsWith('@socketregistry/') || name.startsWith('@socketsecurity/')) {
|
|
668
|
+
failures = failures.filter(({
|
|
669
|
+
type
|
|
670
|
+
}) => type !== 'unpopularPackage' && type !== 'unstableOwnership');
|
|
671
|
+
}
|
|
672
|
+
failures.sort((a, b) => a.type < b.type ? -1 : 1);
|
|
673
|
+
const lines = new Set();
|
|
674
|
+
for (const failure of failures) {
|
|
675
|
+
const {
|
|
676
|
+
type
|
|
677
|
+
} = failure;
|
|
678
|
+
// Based data from { pageProps: { alertTypes } } of:
|
|
679
|
+
// https://socket.dev/_next/data/94666139314b6437ee4491a0864e72b264547585/en-US.json
|
|
680
|
+
const info = translations.issues[type];
|
|
681
|
+
const title = info?.title ?? type;
|
|
682
|
+
const maybeBlocking = failure.block ? '' : ' (non-blocking)';
|
|
683
|
+
const maybeDesc = info?.description ? ` - ${info.description}` : '';
|
|
684
|
+
// TODO: emoji seems to mis-align terminals sometimes
|
|
685
|
+
lines.add(` ${title}${maybeBlocking}${maybeDesc}\n`);
|
|
686
|
+
}
|
|
687
|
+
for (const line of lines) {
|
|
688
|
+
output?.write(line);
|
|
689
|
+
}
|
|
690
|
+
spinner.start();
|
|
691
|
+
}
|
|
692
|
+
remaining -= 1;
|
|
693
|
+
spinner.text = remaining > 0 ? getText() : '';
|
|
694
|
+
}
|
|
695
|
+
return result;
|
|
696
|
+
} finally {
|
|
697
|
+
spinner.stop();
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
function pkgidParts(pkgid) {
|
|
701
|
+
const delimiter = pkgid.lastIndexOf('@');
|
|
702
|
+
const name = pkgid.slice(0, delimiter);
|
|
703
|
+
const version = pkgid.slice(delimiter + 1);
|
|
704
|
+
return {
|
|
705
|
+
name,
|
|
706
|
+
version
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
function toRepoUrl(resolved) {
|
|
710
|
+
return resolved.replace(/#[\s\S]*$/, '').replace(/\?[\s\S]*$/, '').replace(/\/[^/]*\/-\/[\s\S]*$/, '');
|
|
711
|
+
}
|
|
712
|
+
function walk(diff_, needInfoOn = []) {
|
|
713
|
+
const queue = [diff_];
|
|
714
|
+
let pos = 0;
|
|
715
|
+
let {
|
|
716
|
+
length: queueLength
|
|
717
|
+
} = queue;
|
|
718
|
+
while (pos < queueLength) {
|
|
719
|
+
if (pos === _constants$1.LOOP_SENTINEL) {
|
|
720
|
+
throw new Error('Detected infinite loop while walking Arborist diff');
|
|
721
|
+
}
|
|
722
|
+
const diff = queue[pos++];
|
|
723
|
+
if (!diff) {
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
if (diff.action) {
|
|
727
|
+
const sameVersion = diff.actual?.package.version === diff.ideal?.package.version;
|
|
728
|
+
let keep = false;
|
|
729
|
+
let existing = null;
|
|
730
|
+
if (diff.action === 'CHANGE') {
|
|
731
|
+
if (!sameVersion) {
|
|
732
|
+
existing = diff.actual.pkgid;
|
|
733
|
+
keep = true;
|
|
734
|
+
}
|
|
735
|
+
} else {
|
|
736
|
+
keep = diff.action !== 'REMOVE';
|
|
737
|
+
}
|
|
738
|
+
if (keep && diff.ideal?.pkgid && diff.ideal.resolved && (!diff.actual || diff.actual.resolved)) {
|
|
739
|
+
needInfoOn.push({
|
|
740
|
+
existing,
|
|
741
|
+
pkgid: diff.ideal.pkgid,
|
|
742
|
+
repository_url: toRepoUrl(diff.ideal.resolved)
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
if (diff.children) {
|
|
747
|
+
for (const child of diff.children) {
|
|
748
|
+
queue[queueLength++] = child;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
return needInfoOn;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// The Edge class makes heavy use of private properties which subclasses do NOT
|
|
756
|
+
// have access to. So we have to recreate any functionality that relies on those
|
|
757
|
+
// private properties and use our own "safe" prefixed non-conflicting private
|
|
758
|
+
// properties. Implementation code not related to patch https://github.com/npm/cli/pull/7025
|
|
759
|
+
// is based on https://github.com/npm/cli/blob/v10.9.0/workspaces/arborist/lib/edge.js.
|
|
760
|
+
//
|
|
761
|
+
// The npm application
|
|
762
|
+
// Copyright (c) npm, Inc. and Contributors
|
|
763
|
+
// Licensed on the terms of The Artistic License 2.0
|
|
764
|
+
//
|
|
765
|
+
// An edge in the dependency graph.
|
|
766
|
+
// Represents a dependency relationship of some kind.
|
|
767
|
+
class SafeEdge extends Edge {
|
|
768
|
+
#safeAccept;
|
|
769
|
+
#safeError;
|
|
770
|
+
#safeExplanation;
|
|
771
|
+
#safeFrom;
|
|
772
|
+
#safeName;
|
|
773
|
+
#safeTo;
|
|
774
|
+
constructor(options) {
|
|
775
|
+
const {
|
|
776
|
+
accept,
|
|
777
|
+
from,
|
|
778
|
+
name
|
|
779
|
+
} = options;
|
|
780
|
+
// Defer to supper to validate options and assign non-private values.
|
|
781
|
+
super(options);
|
|
782
|
+
if (accept !== undefined) {
|
|
783
|
+
this.#safeAccept = accept || '*';
|
|
784
|
+
}
|
|
785
|
+
this.#safeError = null;
|
|
786
|
+
this.#safeExplanation = null;
|
|
787
|
+
this.#safeFrom = from;
|
|
788
|
+
this.#safeName = name;
|
|
789
|
+
this.#safeTo = null;
|
|
790
|
+
this.reload(true);
|
|
791
|
+
}
|
|
792
|
+
get accept() {
|
|
793
|
+
return this.#safeAccept;
|
|
794
|
+
}
|
|
795
|
+
get bundled() {
|
|
796
|
+
return !!this.#safeFrom?.package?.bundleDependencies?.includes(this.name);
|
|
797
|
+
}
|
|
798
|
+
get error() {
|
|
799
|
+
if (!this.#safeError) {
|
|
800
|
+
if (!this.#safeTo) {
|
|
801
|
+
if (this.optional) {
|
|
802
|
+
this.#safeError = null;
|
|
803
|
+
} else {
|
|
804
|
+
this.#safeError = 'MISSING';
|
|
805
|
+
}
|
|
806
|
+
} else if (this.peer && this.#safeFrom === this.#safeTo.parent && !this.#safeFrom?.isTop) {
|
|
807
|
+
this.#safeError = 'PEER LOCAL';
|
|
808
|
+
} else if (!this.satisfiedBy(this.#safeTo)) {
|
|
809
|
+
this.#safeError = 'INVALID';
|
|
810
|
+
}
|
|
811
|
+
// Patch adding "else if" condition is based on
|
|
812
|
+
// https://github.com/npm/cli/pull/7025.
|
|
813
|
+
else if (this.overrides && this.#safeTo.edgesOut.size && doOverrideSetsConflict(this.overrides, this.#safeTo.overrides)) {
|
|
814
|
+
// Any inconsistency between the edge's override set and the target's
|
|
815
|
+
// override set is potentially problematic. But we only say the edge is
|
|
816
|
+
// in error if the override sets are plainly conflicting. Note that if
|
|
817
|
+
// the target doesn't have any dependencies of their own, then this
|
|
818
|
+
// inconsistency is irrelevant.
|
|
819
|
+
this.#safeError = 'INVALID';
|
|
820
|
+
} else {
|
|
821
|
+
this.#safeError = 'OK';
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
if (this.#safeError === 'OK') {
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
return this.#safeError;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
// @ts-ignore: Incorrectly typed as a property instead of an accessor.
|
|
831
|
+
get from() {
|
|
832
|
+
return this.#safeFrom;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// @ts-ignore: Incorrectly typed as a property instead of an accessor.
|
|
836
|
+
get spec() {
|
|
837
|
+
if (this.overrides?.value && this.overrides.value !== '*' && this.overrides.name === this.name) {
|
|
838
|
+
// Patch adding "if" condition is based on
|
|
839
|
+
// https://github.com/npm/cli/pull/7025.
|
|
840
|
+
//
|
|
841
|
+
// If this edge has the same overrides field as the source, then we're not
|
|
842
|
+
// applying an override for this edge.
|
|
843
|
+
if (this.overrides === this.#safeFrom?.overrides) {
|
|
844
|
+
// The Edge rawSpec getter will retrieve the private Edge #spec property.
|
|
845
|
+
return this.rawSpec;
|
|
846
|
+
}
|
|
847
|
+
if (this.overrides.value.startsWith('$')) {
|
|
848
|
+
const ref = this.overrides.value.slice(1);
|
|
849
|
+
// We may be a virtual root, if we are we want to resolve reference
|
|
850
|
+
// overrides from the real root, not the virtual one.
|
|
851
|
+
const pkg = this.#safeFrom?.sourceReference ? this.#safeFrom.sourceReference.root.package : this.#safeFrom?.root?.package;
|
|
852
|
+
if (pkg?.devDependencies?.[ref]) {
|
|
853
|
+
return pkg.devDependencies[ref];
|
|
854
|
+
}
|
|
855
|
+
if (pkg?.optionalDependencies?.[ref]) {
|
|
856
|
+
return pkg.optionalDependencies[ref];
|
|
857
|
+
}
|
|
858
|
+
if (pkg?.dependencies?.[ref]) {
|
|
859
|
+
return pkg.dependencies[ref];
|
|
860
|
+
}
|
|
861
|
+
if (pkg?.peerDependencies?.[ref]) {
|
|
862
|
+
return pkg.peerDependencies[ref];
|
|
863
|
+
}
|
|
864
|
+
throw new Error(`Unable to resolve reference ${this.overrides.value}`);
|
|
865
|
+
}
|
|
866
|
+
return this.overrides.value;
|
|
867
|
+
}
|
|
868
|
+
return this.rawSpec;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
// @ts-ignore: Incorrectly typed as a property instead of an accessor.
|
|
872
|
+
get to() {
|
|
873
|
+
return this.#safeTo;
|
|
874
|
+
}
|
|
875
|
+
detach() {
|
|
876
|
+
this.#safeExplanation = null;
|
|
877
|
+
// Patch replacing
|
|
878
|
+
// if (this.#safeTo) {
|
|
879
|
+
// this.#safeTo.edgesIn.delete(this)
|
|
880
|
+
// }
|
|
881
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
882
|
+
this.#safeTo?.deleteEdgeIn(this);
|
|
883
|
+
this.#safeFrom?.edgesOut.delete(this.name);
|
|
884
|
+
this.#safeTo = null;
|
|
885
|
+
this.#safeError = 'DETACHED';
|
|
886
|
+
this.#safeFrom = null;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// Return the edge data, and an explanation of how that edge came to be here.
|
|
890
|
+
// @ts-ignore: Edge#explain is defined with an unused `seen = []` param.
|
|
891
|
+
explain() {
|
|
892
|
+
if (!this.#safeExplanation) {
|
|
893
|
+
const explanation = {
|
|
894
|
+
type: this.type,
|
|
895
|
+
name: this.name,
|
|
896
|
+
spec: this.spec,
|
|
897
|
+
bundled: false,
|
|
898
|
+
overridden: false,
|
|
899
|
+
error: undefined,
|
|
900
|
+
from: undefined,
|
|
901
|
+
rawSpec: undefined
|
|
902
|
+
};
|
|
903
|
+
if (this.rawSpec !== this.spec) {
|
|
904
|
+
explanation.rawSpec = this.rawSpec;
|
|
905
|
+
explanation.overridden = true;
|
|
906
|
+
}
|
|
907
|
+
if (this.bundled) {
|
|
908
|
+
explanation.bundled = this.bundled;
|
|
909
|
+
}
|
|
910
|
+
if (this.error) {
|
|
911
|
+
explanation.error = this.error;
|
|
912
|
+
}
|
|
913
|
+
if (this.#safeFrom) {
|
|
914
|
+
explanation.from = this.#safeFrom.explain();
|
|
915
|
+
}
|
|
916
|
+
this.#safeExplanation = explanation;
|
|
917
|
+
}
|
|
918
|
+
return this.#safeExplanation;
|
|
919
|
+
}
|
|
920
|
+
reload(hard = false) {
|
|
921
|
+
this.#safeExplanation = null;
|
|
922
|
+
|
|
923
|
+
// Patch adding newOverrideSet and oldOverrideSet is based on
|
|
924
|
+
// https://github.com/npm/cli/pull/7025.
|
|
925
|
+
let newOverrideSet;
|
|
926
|
+
let oldOverrideSet;
|
|
927
|
+
if (this.#safeFrom?.overrides) {
|
|
928
|
+
// Patch replacing
|
|
929
|
+
// this.overrides = this.#safeFrom.overrides.getEdgeRule(this)
|
|
930
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
931
|
+
const newOverrideSet = this.#safeFrom.overrides.getEdgeRule(this);
|
|
932
|
+
if (newOverrideSet && !newOverrideSet.isEqual(this.overrides)) {
|
|
933
|
+
// If there's a new different override set we need to propagate it to
|
|
934
|
+
// the nodes. If we're deleting the override set then there's no point
|
|
935
|
+
// propagating it right now since it will be filled with another value
|
|
936
|
+
// later.
|
|
937
|
+
oldOverrideSet = this.overrides;
|
|
938
|
+
this.overrides = newOverrideSet;
|
|
939
|
+
}
|
|
940
|
+
} else {
|
|
941
|
+
this.overrides = undefined;
|
|
942
|
+
}
|
|
943
|
+
const newTo = this.#safeFrom?.resolve(this.name);
|
|
944
|
+
if (newTo !== this.#safeTo) {
|
|
945
|
+
if (this.#safeTo) {
|
|
946
|
+
// Patch replacing
|
|
947
|
+
// this.#safeTo.edgesIn.delete(this)
|
|
948
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
949
|
+
this.#safeTo.deleteEdgeIn(this);
|
|
950
|
+
}
|
|
951
|
+
this.#safeTo = newTo ?? null;
|
|
952
|
+
this.#safeError = null;
|
|
953
|
+
if (this.#safeTo) {
|
|
954
|
+
this.#safeTo.addEdgeIn(this);
|
|
955
|
+
}
|
|
956
|
+
} else if (hard) {
|
|
957
|
+
this.#safeError = null;
|
|
958
|
+
}
|
|
959
|
+
// Patch adding "else if" condition based on
|
|
960
|
+
// https://github.com/npm/cli/pull/7025
|
|
961
|
+
else if (oldOverrideSet) {
|
|
962
|
+
// Propagate the new override set to the target node.
|
|
963
|
+
this.#safeTo.updateOverridesEdgeInRemoved(oldOverrideSet);
|
|
964
|
+
this.#safeTo.updateOverridesEdgeInAdded(newOverrideSet);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
satisfiedBy(node) {
|
|
968
|
+
// Patch replacing
|
|
969
|
+
// if (node.name !== this.#name) {
|
|
970
|
+
// return false
|
|
971
|
+
// }
|
|
972
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
973
|
+
if (node.name !== this.#safeName || !this.#safeFrom) {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
// NOTE: this condition means we explicitly do not support overriding
|
|
977
|
+
// bundled or shrinkwrapped dependencies
|
|
978
|
+
if (node.hasShrinkwrap || node.inShrinkwrap || node.inBundle) {
|
|
979
|
+
return depValid(node, this.rawSpec, this.#safeAccept, this.#safeFrom);
|
|
980
|
+
}
|
|
981
|
+
// Patch replacing
|
|
982
|
+
// return depValid(node, this.spec, this.#accept, this.#from)
|
|
983
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
984
|
+
//
|
|
985
|
+
// If there's no override we just use the spec.
|
|
986
|
+
if (!this.overrides?.keySpec) {
|
|
987
|
+
return depValid(node, this.spec, this.#safeAccept, this.#safeFrom);
|
|
988
|
+
}
|
|
989
|
+
// There's some override. If the target node satisfies the overriding spec
|
|
990
|
+
// then it's okay.
|
|
991
|
+
if (depValid(node, this.spec, this.#safeAccept, this.#safeFrom)) {
|
|
992
|
+
return true;
|
|
993
|
+
}
|
|
994
|
+
// If it doesn't, then it should at least satisfy the original spec.
|
|
995
|
+
if (!depValid(node, this.rawSpec, this.#safeAccept, this.#safeFrom)) {
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
// It satisfies the original spec, not the overriding spec. We need to make
|
|
999
|
+
// sure it doesn't use the overridden spec.
|
|
1000
|
+
// For example, we might have an ^8.0.0 rawSpec, and an override that makes
|
|
1001
|
+
// keySpec=8.23.0 and the override value spec=9.0.0.
|
|
1002
|
+
// If the node is 9.0.0, then it's okay because it's consistent with spec.
|
|
1003
|
+
// If the node is 8.24.0, then it's okay because it's consistent with the rawSpec.
|
|
1004
|
+
// If the node is 8.23.0, then it's not okay because even though it's consistent
|
|
1005
|
+
// with the rawSpec, it's also consistent with the keySpec.
|
|
1006
|
+
// So we're looking for ^8.0.0 or 9.0.0 and not 8.23.0.
|
|
1007
|
+
return !depValid(node, this.overrides.keySpec, this.#safeAccept, this.#safeFrom);
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// Implementation code not related to patch https://github.com/npm/cli/pull/7025
|
|
1012
|
+
// is based on https://github.com/npm/cli/blob/v10.9.0/workspaces/arborist/lib/node.js:
|
|
1013
|
+
class SafeNode extends Node {
|
|
1014
|
+
// Return true if it's safe to remove this node, because anything that is
|
|
1015
|
+
// depending on it would be fine with the thing that they would resolve to if
|
|
1016
|
+
// it was removed, or nothing is depending on it in the first place.
|
|
1017
|
+
canDedupe(preferDedupe = false) {
|
|
1018
|
+
// Not allowed to mess with shrinkwraps or bundles.
|
|
1019
|
+
if (this.inDepBundle || this.inShrinkwrap) {
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
1022
|
+
// It's a top level pkg, or a dep of one.
|
|
1023
|
+
if (!this.resolveParent?.resolveParent) {
|
|
1024
|
+
return false;
|
|
1025
|
+
}
|
|
1026
|
+
// No one wants it, remove it.
|
|
1027
|
+
if (this.edgesIn.size === 0) {
|
|
1028
|
+
return true;
|
|
1029
|
+
}
|
|
1030
|
+
const other = this.resolveParent.resolveParent.resolve(this.name);
|
|
1031
|
+
// Nothing else, need this one.
|
|
1032
|
+
if (!other) {
|
|
1033
|
+
return false;
|
|
1034
|
+
}
|
|
1035
|
+
// If it's the same thing, then always fine to remove.
|
|
1036
|
+
if (other.matches(this)) {
|
|
1037
|
+
return true;
|
|
1038
|
+
}
|
|
1039
|
+
// If the other thing can't replace this, then skip it.
|
|
1040
|
+
if (!other.canReplace(this)) {
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
// Patch replacing
|
|
1044
|
+
// if (preferDedupe || semver.gte(other.version, this.version)) {
|
|
1045
|
+
// return true
|
|
1046
|
+
// }
|
|
1047
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
1048
|
+
//
|
|
1049
|
+
// If we prefer dedupe, or if the version is equal, take the other.
|
|
1050
|
+
if (preferDedupe || _semver.eq(other.version, this.version)) {
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
// If our current version isn't the result of an override, then prefer to
|
|
1054
|
+
// take the greater version.
|
|
1055
|
+
if (!this.overridden && _semver.gt(other.version, this.version)) {
|
|
1056
|
+
return true;
|
|
1057
|
+
}
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// Is it safe to replace one node with another? check the edges to
|
|
1062
|
+
// make sure no one will get upset. Note that the node might end up
|
|
1063
|
+
// having its own unmet dependencies, if the new node has new deps.
|
|
1064
|
+
// Note that there are cases where Arborist will opt to insert a node
|
|
1065
|
+
// into the tree even though this function returns false! This is
|
|
1066
|
+
// necessary when a root dependency is added or updated, or when a
|
|
1067
|
+
// root dependency brings peer deps along with it. In that case, we
|
|
1068
|
+
// will go ahead and create the invalid state, and then try to resolve
|
|
1069
|
+
// it with more tree construction, because it's a user request.
|
|
1070
|
+
canReplaceWith(node, ignorePeers) {
|
|
1071
|
+
if (this.name !== node.name || this.packageName !== node.packageName) {
|
|
1072
|
+
return false;
|
|
1073
|
+
}
|
|
1074
|
+
// Patch replacing
|
|
1075
|
+
// if (node.overrides !== this.overrides) {
|
|
1076
|
+
// return false
|
|
1077
|
+
// }
|
|
1078
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
1079
|
+
//
|
|
1080
|
+
// If this node has no dependencies, then it's irrelevant to check the
|
|
1081
|
+
// override rules of the replacement node.
|
|
1082
|
+
if (this.edgesOut.size) {
|
|
1083
|
+
// XXX need to check for two root nodes?
|
|
1084
|
+
if (node.overrides) {
|
|
1085
|
+
if (!node.overrides.isEqual(this.overrides)) {
|
|
1086
|
+
return false;
|
|
1087
|
+
}
|
|
1088
|
+
} else {
|
|
1089
|
+
if (this.overrides) {
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
// To satisfy the patch we ensure `node.overrides === this.overrides`
|
|
1095
|
+
// so that the condition we want to replace,
|
|
1096
|
+
// if (this.overrides !== node.overrides) {
|
|
1097
|
+
// , is not hit.`
|
|
1098
|
+
const oldOverrideSet = this.overrides;
|
|
1099
|
+
let result = true;
|
|
1100
|
+
if (oldOverrideSet !== node.overrides) {
|
|
1101
|
+
this.overrides = node.overrides;
|
|
1102
|
+
}
|
|
1103
|
+
try {
|
|
1104
|
+
result = super.canReplaceWith(node, ignorePeers);
|
|
1105
|
+
this.overrides = oldOverrideSet;
|
|
1106
|
+
} catch (e) {
|
|
1107
|
+
this.overrides = oldOverrideSet;
|
|
1108
|
+
throw e;
|
|
1109
|
+
}
|
|
1110
|
+
return result;
|
|
1111
|
+
}
|
|
1112
|
+
deleteEdgeIn(edge) {
|
|
1113
|
+
this.edgesIn.delete(edge);
|
|
1114
|
+
const {
|
|
1115
|
+
overrides
|
|
1116
|
+
} = edge;
|
|
1117
|
+
if (overrides) {
|
|
1118
|
+
this.updateOverridesEdgeInRemoved(overrides);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
addEdgeIn(edge) {
|
|
1122
|
+
// Patch replacing
|
|
1123
|
+
// if (edge.overrides) {
|
|
1124
|
+
// this.overrides = edge.overrides
|
|
1125
|
+
// }
|
|
1126
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
1127
|
+
//
|
|
1128
|
+
// We need to handle the case where the new edge in has an overrides field
|
|
1129
|
+
// which is different from the current value.
|
|
1130
|
+
if (!this.overrides || !this.overrides.isEqual(edge.overrides)) {
|
|
1131
|
+
this.updateOverridesEdgeInAdded(edge.overrides);
|
|
1132
|
+
}
|
|
1133
|
+
this.edgesIn.add(edge);
|
|
1134
|
+
// Try to get metadata from the yarn.lock file.
|
|
1135
|
+
this.root.meta?.addEdge(edge);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// @ts-ignore: Incorrectly typed as a property instead of an accessor.
|
|
1139
|
+
get overridden() {
|
|
1140
|
+
// Patch replacing
|
|
1141
|
+
// return !!(this.overrides && this.overrides.value && this.overrides.name === this.name)
|
|
1142
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
1143
|
+
if (!this.overrides || !this.overrides.value || this.overrides.name !== this.name) {
|
|
1144
|
+
return false;
|
|
1145
|
+
}
|
|
1146
|
+
// The overrides rule is for a package with this name, but some override rules
|
|
1147
|
+
// only apply to specific versions. To make sure this package was actually
|
|
1148
|
+
// overridden, we check whether any edge going in had the rule applied to it,
|
|
1149
|
+
// in which case its overrides set is different than its source node.
|
|
1150
|
+
for (const edge of this.edgesIn) {
|
|
1151
|
+
if (edge.overrides && edge.overrides.name === this.name && edge.overrides.value === this.version) {
|
|
1152
|
+
if (!edge.overrides?.isEqual(edge.from?.overrides)) {
|
|
1153
|
+
return true;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
return false;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// Patch adding recalculateOutEdgesOverrides is based on
|
|
1161
|
+
// https://github.com/npm/cli/pull/7025.
|
|
1162
|
+
recalculateOutEdgesOverrides() {
|
|
1163
|
+
// For each edge out propagate the new overrides through.
|
|
1164
|
+
for (const edge of this.edgesOut.values()) {
|
|
1165
|
+
edge.reload(true);
|
|
1166
|
+
if (edge.to) {
|
|
1167
|
+
edge.to.updateOverridesEdgeInAdded(edge.overrides);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
// @ts-ignore: Incorrectly typed to accept null.
|
|
1173
|
+
set root(newRoot) {
|
|
1174
|
+
// Patch removing
|
|
1175
|
+
// if (!this.overrides && this.parent && this.parent.overrides) {
|
|
1176
|
+
// this.overrides = this.parent.overrides.getNodeRule(this)
|
|
1177
|
+
// }
|
|
1178
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
1179
|
+
//
|
|
1180
|
+
// The "root" setter is a really large and complex function. To satisfy the
|
|
1181
|
+
// patch we add a dummy value to `this.overrides` so that the condition we
|
|
1182
|
+
// want to remove,
|
|
1183
|
+
// if (!this.overrides && this.parent && this.parent.overrides) {
|
|
1184
|
+
// , is not hit.
|
|
1185
|
+
if (!this.overrides) {
|
|
1186
|
+
this.overrides = new OverrideSet({
|
|
1187
|
+
overrides: ''
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
try {
|
|
1191
|
+
super.root = newRoot;
|
|
1192
|
+
this.overrides = undefined;
|
|
1193
|
+
} catch (e) {
|
|
1194
|
+
this.overrides = undefined;
|
|
1195
|
+
throw e;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
// Patch adding updateOverridesEdgeInAdded is based on
|
|
1200
|
+
// https://github.com/npm/cli/pull/7025.
|
|
1201
|
+
//
|
|
1202
|
+
// This logic isn't perfect either. When we have two edges in that have
|
|
1203
|
+
// different override sets, then we have to decide which set is correct. This
|
|
1204
|
+
// function assumes the more specific override set is applicable, so if we have
|
|
1205
|
+
// dependencies A->B->C and A->C and an override set that specifies what happens
|
|
1206
|
+
// for C under A->B, this will work even if the new A->C edge comes along and
|
|
1207
|
+
// tries to change the override set. The strictly correct logic is not to allow
|
|
1208
|
+
// two edges with different overrides to point to the same node, because even
|
|
1209
|
+
// if this node can satisfy both, one of its dependencies might need to be
|
|
1210
|
+
// different depending on the edge leading to it. However, this might cause a
|
|
1211
|
+
// lot of duplication, because the conflict in the dependencies might never
|
|
1212
|
+
// actually happen.
|
|
1213
|
+
updateOverridesEdgeInAdded(otherOverrideSet) {
|
|
1214
|
+
if (!otherOverrideSet) {
|
|
1215
|
+
// Assuming there are any overrides at all, the overrides field is never
|
|
1216
|
+
// undefined for any node at the end state of the tree. So if the new edge's
|
|
1217
|
+
// overrides is undefined it will be updated later. So we can wait with
|
|
1218
|
+
// updating the node's overrides field.
|
|
1219
|
+
return false;
|
|
1220
|
+
}
|
|
1221
|
+
if (!this.overrides) {
|
|
1222
|
+
this.overrides = otherOverrideSet;
|
|
1223
|
+
this.recalculateOutEdgesOverrides();
|
|
1224
|
+
return true;
|
|
1225
|
+
}
|
|
1226
|
+
if (this.overrides.isEqual(otherOverrideSet)) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
const newOverrideSet = findSpecificOverrideSet(this.overrides, otherOverrideSet);
|
|
1230
|
+
if (newOverrideSet) {
|
|
1231
|
+
if (this.overrides.isEqual(newOverrideSet)) {
|
|
1232
|
+
return false;
|
|
1233
|
+
}
|
|
1234
|
+
this.overrides = newOverrideSet;
|
|
1235
|
+
this.recalculateOutEdgesOverrides();
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
// This is an error condition. We can only get here if the new override set
|
|
1239
|
+
// is in conflict with the existing.
|
|
1240
|
+
log.silly('Conflicting override sets', this.name);
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
// Patch adding updateOverridesEdgeInRemoved is based on
|
|
1245
|
+
// https://github.com/npm/cli/pull/7025.
|
|
1246
|
+
updateOverridesEdgeInRemoved(otherOverrideSet) {
|
|
1247
|
+
// If this edge's overrides isn't equal to this node's overrides,
|
|
1248
|
+
// then removing it won't change newOverrideSet later.
|
|
1249
|
+
if (!this.overrides || !this.overrides.isEqual(otherOverrideSet)) {
|
|
1250
|
+
return false;
|
|
1251
|
+
}
|
|
1252
|
+
let newOverrideSet;
|
|
1253
|
+
for (const edge of this.edgesIn) {
|
|
1254
|
+
const {
|
|
1255
|
+
overrides: edgeOverrides
|
|
1256
|
+
} = edge;
|
|
1257
|
+
if (newOverrideSet && edgeOverrides) {
|
|
1258
|
+
newOverrideSet = findSpecificOverrideSet(edgeOverrides, newOverrideSet);
|
|
1259
|
+
} else {
|
|
1260
|
+
newOverrideSet = edgeOverrides;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
if (this.overrides.isEqual(newOverrideSet)) {
|
|
1264
|
+
return false;
|
|
1265
|
+
}
|
|
1266
|
+
this.overrides = newOverrideSet;
|
|
1267
|
+
if (newOverrideSet) {
|
|
1268
|
+
// Optimization: If there's any override set at all, then no non-extraneous
|
|
1269
|
+
// node has an empty override set. So if we temporarily have no override set
|
|
1270
|
+
// (for example, we removed all the edges in), there's no use updating all
|
|
1271
|
+
// the edges out right now. Let's just wait until we have an actual override
|
|
1272
|
+
// set later.
|
|
1273
|
+
this.recalculateOutEdgesOverrides();
|
|
1274
|
+
}
|
|
1275
|
+
return true;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
// Implementation code not related to patch https://github.com/npm/cli/pull/7025
|
|
1280
|
+
// is based on https://github.com/npm/cli/blob/v10.9.0/workspaces/arborist/lib/override-set.js:
|
|
1281
|
+
class SafeOverrideSet extends OverrideSet {
|
|
1282
|
+
// Patch adding childrenAreEqual is based on
|
|
1283
|
+
// https://github.com/npm/cli/pull/7025.
|
|
1284
|
+
childrenAreEqual(otherOverrideSet) {
|
|
1285
|
+
const queue = [[this, otherOverrideSet]];
|
|
1286
|
+
let pos = 0;
|
|
1287
|
+
let {
|
|
1288
|
+
length: queueLength
|
|
1289
|
+
} = queue;
|
|
1290
|
+
while (pos < queueLength) {
|
|
1291
|
+
if (pos === _constants$1.LOOP_SENTINEL) {
|
|
1292
|
+
throw new Error('Detected infinite loop while comparing override sets');
|
|
1293
|
+
}
|
|
1294
|
+
const {
|
|
1295
|
+
0: currSet,
|
|
1296
|
+
1: currOtherSet
|
|
1297
|
+
} = queue[pos++];
|
|
1298
|
+
const {
|
|
1299
|
+
children
|
|
1300
|
+
} = currSet;
|
|
1301
|
+
const {
|
|
1302
|
+
children: otherChildren
|
|
1303
|
+
} = currOtherSet;
|
|
1304
|
+
if (children.size !== otherChildren.size) {
|
|
1305
|
+
return false;
|
|
1306
|
+
}
|
|
1307
|
+
for (const key of children.keys()) {
|
|
1308
|
+
if (!otherChildren.has(key)) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
const child = children.get(key);
|
|
1312
|
+
const otherChild = otherChildren.get(key);
|
|
1313
|
+
if (child.value !== otherChild.value) {
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1316
|
+
queue[queueLength++] = [child, otherChild];
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
return true;
|
|
1320
|
+
}
|
|
1321
|
+
getEdgeRule(edge) {
|
|
1322
|
+
for (const rule of this.ruleset.values()) {
|
|
1323
|
+
if (rule.name !== edge.name) {
|
|
1324
|
+
continue;
|
|
1325
|
+
}
|
|
1326
|
+
// If keySpec is * we found our override.
|
|
1327
|
+
if (rule.keySpec === '*') {
|
|
1328
|
+
return rule;
|
|
1329
|
+
}
|
|
1330
|
+
// Patch replacing
|
|
1331
|
+
// let spec = npa(`${edge.name}@${edge.spec}`)
|
|
1332
|
+
// is based on https://github.com/npm/cli/pull/7025.
|
|
1333
|
+
//
|
|
1334
|
+
// We need to use the rawSpec here, because the spec has the overrides
|
|
1335
|
+
// applied to it already.
|
|
1336
|
+
let spec = _npmPackageArg(`${edge.name}@${edge.rawSpec}`);
|
|
1337
|
+
if (spec.type === 'alias') {
|
|
1338
|
+
spec = spec.subSpec;
|
|
1339
|
+
}
|
|
1340
|
+
if (spec.type === 'git') {
|
|
1341
|
+
if (spec.gitRange && rule.keySpec && _semver.intersects(spec.gitRange, rule.keySpec)) {
|
|
1342
|
+
return rule;
|
|
1343
|
+
}
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
if (spec.type === 'range' || spec.type === 'version') {
|
|
1347
|
+
if (rule.keySpec && _semver.intersects(spec.fetchSpec, rule.keySpec)) {
|
|
1348
|
+
return rule;
|
|
1349
|
+
}
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
// If we got this far, the spec type is one of tag, directory or file
|
|
1353
|
+
// which means we have no real way to make version comparisons, so we
|
|
1354
|
+
// just accept the override.
|
|
1355
|
+
return rule;
|
|
1356
|
+
}
|
|
1357
|
+
return this;
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
// Patch adding isEqual is based on
|
|
1361
|
+
// https://github.com/npm/cli/pull/7025.
|
|
1362
|
+
isEqual(otherOverrideSet) {
|
|
1363
|
+
if (this === otherOverrideSet) {
|
|
1364
|
+
return true;
|
|
1365
|
+
}
|
|
1366
|
+
if (!otherOverrideSet) {
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
if (this.key !== otherOverrideSet.key || this.value !== otherOverrideSet.value) {
|
|
1370
|
+
return false;
|
|
1371
|
+
}
|
|
1372
|
+
if (!this.childrenAreEqual(otherOverrideSet)) {
|
|
1373
|
+
return false;
|
|
1374
|
+
}
|
|
1375
|
+
if (!this.parent) {
|
|
1376
|
+
return !otherOverrideSet.parent;
|
|
1377
|
+
}
|
|
1378
|
+
return this.parent.isEqual(otherOverrideSet.parent);
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// Implementation code not related to our custom behavior is based on
|
|
1383
|
+
// https://github.com/npm/cli/blob/v10.9.0/workspaces/arborist/lib/arborist/index.js:
|
|
1384
|
+
class SafeArborist extends Arborist {
|
|
1385
|
+
constructor(...ctorArgs) {
|
|
1386
|
+
const mutedArguments = [{
|
|
1387
|
+
...ctorArgs[0],
|
|
1388
|
+
audit: true,
|
|
1389
|
+
dryRun: true,
|
|
1390
|
+
ignoreScripts: true,
|
|
1391
|
+
save: false,
|
|
1392
|
+
saveBundle: false,
|
|
1393
|
+
// progress: false,
|
|
1394
|
+
fund: false
|
|
1395
|
+
}, ctorArgs.slice(1)];
|
|
1396
|
+
super(...mutedArguments);
|
|
1397
|
+
this[kCtorArgs] = ctorArgs;
|
|
1398
|
+
}
|
|
1399
|
+
async [kRiskyReify](...args) {
|
|
1400
|
+
// SafeArborist has suffered side effects and must be rebuilt from scratch.
|
|
1401
|
+
const arb = new Arborist(...this[kCtorArgs]);
|
|
1402
|
+
const ret = await arb.reify(...args);
|
|
1403
|
+
Object.assign(this, arb);
|
|
1404
|
+
return ret;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// @ts-ignore Incorrectly typed.
|
|
1408
|
+
async reify(...args) {
|
|
1409
|
+
const options = args[0] ? {
|
|
1410
|
+
...args[0]
|
|
1411
|
+
} : {};
|
|
1412
|
+
if (options.dryRun) {
|
|
1413
|
+
return await this[kRiskyReify](...args);
|
|
1414
|
+
}
|
|
1415
|
+
const old = {
|
|
1416
|
+
...options,
|
|
1417
|
+
dryRun: false,
|
|
1418
|
+
save: Boolean(options['save'] ?? true),
|
|
1419
|
+
saveBundle: Boolean(options['saveBundle'] ?? false)
|
|
1420
|
+
};
|
|
1421
|
+
args[0] = options;
|
|
1422
|
+
options.dryRun = true;
|
|
1423
|
+
options['save'] = false;
|
|
1424
|
+
options['saveBundle'] = false;
|
|
1425
|
+
// TODO: Make this deal w/ any refactor to private fields by punching the
|
|
1426
|
+
// class itself.
|
|
1427
|
+
await super.reify(...args);
|
|
1428
|
+
const diff = walk(this['diff']);
|
|
1429
|
+
options.dryRun = old.dryRun;
|
|
1430
|
+
options['save'] = old.save;
|
|
1431
|
+
options['saveBundle'] = old.saveBundle;
|
|
1432
|
+
// Nothing to check, mmm already installed or all private?
|
|
1433
|
+
if (diff.findIndex(c => c.repository_url === _constants$1.NPM_REGISTRY_URL) === -1) {
|
|
1434
|
+
return await this[kRiskyReify](...args);
|
|
1435
|
+
}
|
|
1436
|
+
let proceed = _constants$1.ENV[_constants$1.UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE];
|
|
1437
|
+
if (!proceed) {
|
|
1438
|
+
proceed = await ttyServer.captureTTY(async (input, output) => {
|
|
1439
|
+
if (input && output) {
|
|
1440
|
+
const risky = await packagesHaveRiskyIssues(this, this['registry'], diff, output);
|
|
1441
|
+
if (!risky) {
|
|
1442
|
+
return true;
|
|
1443
|
+
}
|
|
1444
|
+
const rlin = new _nodeStream.PassThrough();
|
|
1445
|
+
input.pipe(rlin);
|
|
1446
|
+
const rlout = new _nodeStream.PassThrough();
|
|
1447
|
+
rlout.pipe(output, {
|
|
1448
|
+
end: false
|
|
1449
|
+
});
|
|
1450
|
+
const rli = _nodeReadline.createInterface(rlin, rlout);
|
|
1451
|
+
try {
|
|
1452
|
+
while (true) {
|
|
1453
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1454
|
+
const answer = await new Promise(resolve => {
|
|
1455
|
+
rli.question('Accept risks of installing these packages (y/N)?\n', {
|
|
1456
|
+
signal: abortSignal
|
|
1457
|
+
}, resolve);
|
|
1458
|
+
});
|
|
1459
|
+
if (/^\s*y(?:es)?\s*$/i.test(answer)) {
|
|
1460
|
+
return true;
|
|
1461
|
+
}
|
|
1462
|
+
if (/^(?:\s*no?\s*|)$/i.test(answer)) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
} finally {
|
|
1467
|
+
rli.close();
|
|
1468
|
+
}
|
|
1469
|
+
} else if (await packagesHaveRiskyIssues(this, this['registry'], diff, output)) {
|
|
1470
|
+
throw new Error('Socket npm Unable to prompt to accept risk, need TTY to do so');
|
|
1471
|
+
}
|
|
1472
|
+
return true;
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
if (proceed) {
|
|
1476
|
+
return await this[kRiskyReify](...args);
|
|
1477
|
+
} else {
|
|
1478
|
+
throw new Error('Socket npm exiting due to risks');
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
arborist.SafeArborist = SafeArborist;
|
|
1483
|
+
function installSafeArborist() {
|
|
1484
|
+
const cache = require.cache;
|
|
1485
|
+
cache[arboristClassPath] = {
|
|
1486
|
+
exports: SafeArborist
|
|
1487
|
+
};
|
|
1488
|
+
cache[arboristEdgeClassPath] = {
|
|
1489
|
+
exports: SafeEdge
|
|
1490
|
+
};
|
|
1491
|
+
cache[arboristNodeClassPath] = {
|
|
1492
|
+
exports: SafeNode
|
|
1493
|
+
};
|
|
1494
|
+
cache[arboristOverrideSetClassPatch] = {
|
|
1495
|
+
exports: SafeOverrideSet
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
void (async () => {
|
|
1499
|
+
const remoteSettings = await (async () => {
|
|
1500
|
+
try {
|
|
1501
|
+
const socketSdk = await (0, _sdk.setupSdk)(pubToken);
|
|
1502
|
+
const orgResult = await socketSdk.getOrganizations();
|
|
1503
|
+
if (!orgResult.success) {
|
|
1504
|
+
throw new Error(`Failed to fetch Socket organization info: ${orgResult.error.message}`);
|
|
1505
|
+
}
|
|
1506
|
+
const orgs = [];
|
|
1507
|
+
for (const org of Object.values(orgResult.data.organizations)) {
|
|
1508
|
+
if (org) {
|
|
1509
|
+
orgs.push(org);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
const result = await socketSdk.postSettings(orgs.map(org => ({
|
|
1513
|
+
organization: org.id
|
|
1514
|
+
})));
|
|
1515
|
+
if (!result.success) {
|
|
1516
|
+
throw new Error(`Failed to fetch API key settings: ${result.error.message}`);
|
|
1517
|
+
}
|
|
1518
|
+
return {
|
|
1519
|
+
orgs,
|
|
1520
|
+
settings: result.data
|
|
1521
|
+
};
|
|
1522
|
+
} catch (e) {
|
|
1523
|
+
if ((0, _objects.isObject)(e) && 'cause' in e) {
|
|
1524
|
+
const {
|
|
1525
|
+
cause
|
|
1526
|
+
} = e;
|
|
1527
|
+
if ((0, _misc.isErrnoException)(cause)) {
|
|
1528
|
+
if (cause.code === 'ENOTFOUND' || cause.code === 'ECONNREFUSED') {
|
|
1529
|
+
throw new Error('Unable to connect to socket.dev, ensure internet connectivity before retrying', {
|
|
1530
|
+
cause: e
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
throw e;
|
|
1536
|
+
}
|
|
1537
|
+
})();
|
|
1538
|
+
const {
|
|
1539
|
+
orgs,
|
|
1540
|
+
settings
|
|
1541
|
+
} = remoteSettings;
|
|
1542
|
+
const enforcedOrgs = (0, _settings.getSetting)('enforcedOrgs') ?? [];
|
|
1543
|
+
|
|
1544
|
+
// Remove any organizations not being enforced.
|
|
1545
|
+
for (const {
|
|
1546
|
+
0: i,
|
|
1547
|
+
1: org
|
|
1548
|
+
} of orgs.entries()) {
|
|
1549
|
+
if (!enforcedOrgs.includes(org.id)) {
|
|
1550
|
+
settings.entries.splice(i, 1);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
const socketYml = findSocketYmlSync();
|
|
1554
|
+
if (socketYml) {
|
|
1555
|
+
settings.entries.push({
|
|
1556
|
+
start: socketYml.path,
|
|
1557
|
+
settings: {
|
|
1558
|
+
[socketYml.path]: {
|
|
1559
|
+
deferTo: null,
|
|
1560
|
+
// TODO: TypeScript complains about the type not matching. We should
|
|
1561
|
+
// figure out why are providing
|
|
1562
|
+
// issueRules: { [issueName: string]: boolean }
|
|
1563
|
+
// but expecting
|
|
1564
|
+
// issueRules: { [issueName: string]: { action: 'defer' | 'error' | 'ignore' | 'monitor' | 'warn' } }
|
|
1565
|
+
issueRules: socketYml.parsed.issueRules
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
_uxLookup = (0, _issueRules.createIssueUXLookup)(settings);
|
|
1571
|
+
})();
|
|
1572
|
+
|
|
1573
|
+
var _constants = constants.constants;
|
|
1574
|
+
var _arborist = arborist;
|
|
1575
|
+
var _link = link.link;
|
|
1576
|
+
// Shadow `npm` and `npx` to mitigate subshells.
|
|
1577
|
+
(0, _link.installLinks)(_constants.shadowBinPath, 'npm');
|
|
1578
|
+
(0, _arborist.installSafeArborist)();
|
|
1579
|
+
|
|
1580
|
+
(function (exports) {
|
|
1581
|
+
|
|
1582
|
+
var _interopRequireWildcard = require$$0$2.default;
|
|
1583
|
+
Object.defineProperty(exports, "__esModule", {
|
|
1584
|
+
value: true
|
|
1585
|
+
});
|
|
1586
|
+
var _exportNames = {};
|
|
1587
|
+
Object.defineProperty(exports, "default", {
|
|
1588
|
+
enumerable: true,
|
|
1589
|
+
get: function () {
|
|
1590
|
+
return _npmInjection.default;
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
var _npmInjection = _interopRequireWildcard(npmInjection$1, true);
|
|
1594
|
+
Object.keys(_npmInjection).forEach(function (key) {
|
|
1595
|
+
if (key === "default" || key === "__esModule") return;
|
|
1596
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
1597
|
+
if (key in exports && exports[key] === _npmInjection[key]) return;
|
|
1598
|
+
Object.defineProperty(exports, key, {
|
|
1599
|
+
enumerable: true,
|
|
1600
|
+
get: function () {
|
|
1601
|
+
return _npmInjection[key];
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
});
|
|
1605
|
+
} (npmInjection$2));
|
|
1606
|
+
|
|
1607
|
+
var npmInjection = /*@__PURE__*/constants.getDefaultExportFromCjs(npmInjection$2);
|
|
1608
|
+
|
|
1609
|
+
module.exports = npmInjection;
|