@socketsecurity/cli 0.14.33 → 0.14.35

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