@socketsecurity/cli 0.14.34 → 0.14.36

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