@socketsecurity/cli 0.14.27 → 0.14.29

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