@socketsecurity/cli 0.14.35 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAEtE,KAAK,WAAW,GAAG,OAAO,iBAAiB,CAAC,GAAG,CAAA;AAE/C,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAA;IAChD,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG;QAC1B,4CAA4C,EAAE,OAAO,CAAA;KACtD,CAAA;IACD,QAAQ,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAA;IACvD,QAAQ,CAAC,qBAAqB,EAAE,gDAAgD,CAAA;IAChF,QAAQ,CAAC,4CAA4C,EAAE,8CAA8C,CAAA;IACrG,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,iBAAiB,CAAA;AAyC5B,QAAA,MAAM,SAAS,WA0Bd,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,C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dk.js');
30
30
  var constants = require('./constants.js');
31
31
  var pathResolve = require('./path-resolve.js');
32
32
 
33
- var version = "0.14.35";
33
+ var version = "0.14.36";
34
34
 
35
35
  const NEWLINE_CHAR_CODE = 10; /*'\n'*/
36
36
 
@@ -9,11 +9,13 @@ function _socketInterop(e) {
9
9
  return c ? e.default : e
10
10
  }
11
11
 
12
- var fs = require('node:fs/promises');
12
+ var fs = require('node:fs');
13
13
  var path = require('node:path');
14
14
  var ignore = _socketInterop(require('ignore'));
15
15
  var micromatch = _socketInterop(require('micromatch'));
16
16
  var tinyglobby = _socketInterop(require('tinyglobby'));
17
+ var which = _socketInterop(require('which'));
18
+ var constants = require('./constants.js');
17
19
 
18
20
  const ignoredDirs = [
19
21
  // Taken from ignore-by-default:
@@ -42,8 +44,12 @@ function directoryPatterns() {
42
44
  return [...ignoredDirPatterns];
43
45
  }
44
46
 
47
+ const {
48
+ NPM,
49
+ shadowBinPath
50
+ } = constants;
45
51
  async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
46
- const patterns = ['golang', 'npm', 'pypi'].reduce((r, n) => {
52
+ const patterns = ['golang', NPM, 'pypi'].reduce((r, n) => {
47
53
  const supported = supportedFiles[n];
48
54
  r.push(...(supported ? Object.values(supported).map(p => `**/${p.pattern}`) : []));
49
55
  return r;
@@ -65,7 +71,7 @@ async function globWithGitIgnore(patterns, options) {
65
71
  cwd,
66
72
  expandDirectories: true
67
73
  });
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()];
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()];
69
75
  const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
70
76
  const globOptions = {
71
77
  absolute: true,
@@ -133,7 +139,7 @@ function pathsToPatterns(paths) {
133
139
  function findRoot(filepath) {
134
140
  let curPath = filepath;
135
141
  while (true) {
136
- if (path.basename(curPath) === 'npm') {
142
+ if (path.basename(curPath) === NPM) {
137
143
  return curPath;
138
144
  }
139
145
  const parent = path.dirname(curPath);
@@ -143,6 +149,26 @@ function findRoot(filepath) {
143
149
  curPath = parent;
144
150
  }
145
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
+ }
146
172
  async function getPackageFiles(cwd, inputPaths, config, supportedFiles, debugLog = () => {}) {
147
173
  debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
148
174
 
@@ -169,6 +195,7 @@ async function getPackageFilesFullScans(cwd, inputPaths, supportedFiles, debugLo
169
195
  return packageFiles;
170
196
  }
171
197
 
198
+ exports.findBinPathDetails = findBinPathDetails;
172
199
  exports.findRoot = findRoot;
173
200
  exports.getPackageFiles = getPackageFiles;
174
201
  exports.getPackageFilesFullScans = getPackageFilesFullScans;
@@ -14,7 +14,6 @@ var path = require('node:path');
14
14
  var spawn = _socketInterop(require('@npmcli/promise-spawn'));
15
15
  var constants = require('./constants.js');
16
16
  var cmdShim = _socketInterop(require('cmd-shim'));
17
- var which = _socketInterop(require('which'));
18
17
  var pathResolve = require('./path-resolve.js');
19
18
 
20
19
  const {
@@ -23,23 +22,14 @@ const {
23
22
  } = constants;
24
23
  async function installLinks(realBinPath, binName) {
25
24
  // 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
- });
25
+ const {
26
+ path: binPath,
27
+ shadowed
28
+ } = await pathResolve.findBinPathDetails(binName);
39
29
  if (!binPath) {
40
- console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable`);
41
30
  // The exit code 127 indicates that the command or binary being executed
42
31
  // could not be found.
32
+ console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
43
33
  process.exit(127);
44
34
  }
45
35
  // TODO: Is this early exit needed?
@@ -47,23 +37,24 @@ async function installLinks(realBinPath, binName) {
47
37
  return binPath;
48
38
  }
49
39
  // Move our bin directory to front of PATH so its found first.
50
- if (shadowIndex === -1) {
40
+ if (!shadowed) {
51
41
  if (WIN32) {
52
42
  await cmdShim(path.join(rootDistPath, `${binName}-cli.js`), path.join(realBinPath, binName));
53
43
  }
54
- process.env['PATH'] = `${realBinPath}${WIN32 ? ';' : ':'}${process.env['PATH']}`;
44
+ process.env['PATH'] = `${realBinPath}${path.delimiter}${process.env['PATH']}`;
55
45
  }
56
46
  return binPath;
57
47
  }
58
48
 
59
49
  const {
50
+ NPM,
60
51
  abortSignal,
61
52
  distPath,
62
53
  execPath,
63
54
  shadowBinPath
64
55
  } = constants;
65
56
  const injectionPath = path.join(distPath, 'npm-injection.js');
66
- async function shadow(binName) {
57
+ async function shadow(binName, binArgs = process.argv.slice(2)) {
67
58
  const binPath = await installLinks(shadowBinPath, binName);
68
59
  if (abortSignal.aborted) {
69
60
  return;
@@ -71,8 +62,7 @@ async function shadow(binName) {
71
62
  // Adding the `--quiet` and `--no-progress` flags when the `proc-log` module
72
63
  // is found to fix a UX issue when running the command with recent versions of
73
64
  // 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')) {
65
+ if (binName === NPM && binArgs.includes('install') && !binArgs.includes('--no-progress') && !binArgs.includes('--quiet')) {
76
66
  const npmEntrypoint = fs.realpathSync(binPath);
77
67
  const npmRootPath = pathResolve.findRoot(path.dirname(npmEntrypoint));
78
68
  if (npmRootPath === undefined) {
@@ -96,9 +86,13 @@ async function shadow(binName) {
96
86
  signal: abortSignal,
97
87
  stdio: 'inherit'
98
88
  });
99
- spawnPromise.process.on('exit', (code, signal) => {
100
- if (signal) {
101
- process.kill(process.pid, signal);
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);
102
96
  } else if (code !== null) {
103
97
  process.exit(code);
104
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@socketsecurity/cli",
3
- "version": "0.14.35",
3
+ "version": "0.14.36",
4
4
  "description": "CLI tool for Socket.dev",
5
5
  "homepage": "http://github.com/SocketDev/socket-cli",
6
6
  "license": "MIT",
@@ -62,7 +62,7 @@
62
62
  "@socketregistry/hyrious__bun.lockb": "1.0.6",
63
63
  "@socketregistry/yocto-spinner": "^1.0.2",
64
64
  "@socketsecurity/config": "^2.1.3",
65
- "@socketsecurity/registry": "^1.0.52",
65
+ "@socketsecurity/registry": "^1.0.56",
66
66
  "@socketsecurity/sdk": "^1.3.0",
67
67
  "blessed": "^0.1.81",
68
68
  "blessed-contrib": "^4.11.0",
@@ -120,21 +120,21 @@
120
120
  "eslint": "^9.17.0",
121
121
  "eslint-import-resolver-oxc": "^0.6.0",
122
122
  "eslint-plugin-depend": "^0.12.0",
123
- "eslint-plugin-import-x": "^4.5.0",
123
+ "eslint-plugin-import-x": "^4.6.1",
124
124
  "eslint-plugin-n": "^17.15.0",
125
125
  "eslint-plugin-sort-destructure-keys": "^2.0.0",
126
126
  "eslint-plugin-unicorn": "^56.0.1",
127
127
  "husky": "^9.1.7",
128
128
  "is-interactive": "^2.0.0",
129
129
  "is-unicode-supported": "^2.1.0",
130
- "knip": "^5.41.0",
130
+ "knip": "^5.41.1",
131
131
  "magic-string": "^0.30.17",
132
132
  "meow": "^13.2.0",
133
133
  "mock-fs": "^5.4.1",
134
134
  "nock": "^13.5.6",
135
135
  "npm-run-all2": "^7.0.2",
136
136
  "open": "^10.1.0",
137
- "oxlint": "0.15.2",
137
+ "oxlint": "0.15.3",
138
138
  "prettier": "3.4.2",
139
139
  "read-package-up": "^11.0.0",
140
140
  "rollup": "4.28.1",