@vltpkg/run 1.0.0-rc.3 → 1.0.0-rc.31

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,6 +1,7 @@
1
1
  import { PackageJson } from '@vltpkg/package-json';
2
2
  import type { PromiseSpawnOptions, SpawnResultNoStdio, SpawnResultStdioStrings } from '@vltpkg/promise-spawn';
3
3
  import type { Manifest } from '@vltpkg/types';
4
+ export * from './node-gyp.ts';
4
5
  /** options shared by run() and exec() */
5
6
  export type SharedOptions = PromiseSpawnOptions & {
6
7
  /** additional arguments to pass to the command */
@@ -127,5 +128,3 @@ export declare const runExec: (options: RunExecOptions) => Promise<RunResult | S
127
128
  * execFG()
128
129
  */
129
130
  export declare const runExecFG: (options: RunExecOptions) => Promise<RunFGResult | SpawnResultNoStdio>;
130
- export { getNodeGypShim, getNodeGypShimDir, hasNodeGypReference, } from './aliasRunner.ts';
131
- //# sourceMappingURL=index.d.ts.map
@@ -6,7 +6,9 @@ import { proxySignals } from 'foreground-child/proxy-signals';
6
6
  import { statSync } from 'node:fs';
7
7
  import { delimiter, resolve, sep } from 'node:path';
8
8
  import { walkUp } from 'walk-up-path';
9
- import { getNodeGypShimDir, hasNodeGypReference, } from "./aliasRunner.js";
9
+ import { getNodeGypShimDir, hasNodeGypReference, hasNodeGypBinding, } from "./node-gyp.js";
10
+ // Re-export all named exports from node-gyp.ts
11
+ export * from "./node-gyp.js";
10
12
  /** map of which node_modules/.bin folders exist */
11
13
  const dotBins = new Map();
12
14
  /** Check if a directory exists, and cache result */
@@ -102,21 +104,46 @@ const runImpl = async (options, execImpl, empty) => {
102
104
  const pj = (untrustworthy ? undefined : manifest) ??
103
105
  packageJson.read(options.cwd);
104
106
  const { scripts } = pj;
105
- const command = scripts?.[arg0];
106
- if (!command) {
107
+ const command = scripts?.[arg0] ??
108
+ // npm's implicit install behavior: "If there is a binding.gyp file in the
109
+ // root of your package and you haven't defined your own install or preinstall
110
+ // scripts, npm will default the install command to compile using node-gyp
111
+ // via node-gyp rebuild"
112
+ ((arg0 === 'install' &&
113
+ !scripts?.install &&
114
+ !scripts?.preinstall &&
115
+ hasNodeGypBinding(options.cwd)) ?
116
+ 'node-gyp rebuild'
117
+ : undefined);
118
+ // Check for pre/post commands even if main command doesn't exist for cases
119
+ // like packages that have only a preinstall or postinstall script.
120
+ const precommand = !options.ignorePrePost && scripts?.[`pre${arg0}`];
121
+ const postcommand = !options.ignorePrePost && scripts?.[`post${arg0}`];
122
+ const emptyResult = () => ({
123
+ command: '',
124
+ args: execArgs.args ?? [],
125
+ cwd: options.cwd,
126
+ status: 0,
127
+ signal: null,
128
+ stdout: empty,
129
+ stderr: empty,
130
+ });
131
+ const execCommand = (command, preOrPost) => execImpl({
132
+ arg0: command,
133
+ ...execArgs,
134
+ 'script-shell': shell,
135
+ // pre/post scripts always have empty args, main script uses execArgs.args
136
+ args: preOrPost ? [] : (execArgs.args ?? []),
137
+ env: {
138
+ ...execArgs.env,
139
+ npm_package_json: pjPath,
140
+ npm_lifecycle_event: `${preOrPost ?? ''}${arg0}`,
141
+ npm_lifecycle_script: command,
142
+ },
143
+ });
144
+ if (!command && !precommand && !postcommand) {
107
145
  if (ignoreMissing) {
108
- return {
109
- command: '',
110
- /* c8 ignore next */
111
- args: execArgs.args ?? [],
112
- cwd: options.cwd,
113
- status: 0,
114
- signal: null,
115
- stdout: empty,
116
- stderr: empty,
117
- // `as` to workaround "could be instantiated with arbitrary type".
118
- // it's private and used in 2 places, we know that it isn't.
119
- };
146
+ return emptyResult();
120
147
  }
121
148
  throw error('Script not defined in package.json', {
122
149
  name: arg0,
@@ -126,67 +153,71 @@ const runImpl = async (options, execImpl, empty) => {
126
153
  manifest: pj,
127
154
  });
128
155
  }
129
- const precommand = !options.ignorePrePost && scripts[`pre${arg0}`];
130
- const pre = precommand ?
131
- await execImpl({
132
- arg0: precommand,
133
- ...execArgs,
134
- 'script-shell': shell,
135
- args: [],
136
- env: {
137
- ...execArgs.env,
138
- npm_package_json: pjPath,
139
- npm_lifecycle_event: `pre${arg0}`,
140
- npm_lifecycle_script: precommand,
141
- },
142
- })
143
- : undefined;
144
- if (pre && (pre.status || pre.signal)) {
145
- return pre;
156
+ const pre = precommand ? await execCommand(precommand, 'pre') : undefined;
157
+ if (pre?.status || pre?.signal) {
158
+ return {
159
+ ...pre,
160
+ };
146
161
  }
147
- const result = await execImpl({
148
- arg0: command,
149
- ...execArgs,
150
- 'script-shell': shell,
151
- env: {
152
- ...execArgs.env,
153
- npm_package_json: pjPath,
154
- npm_lifecycle_event: arg0,
155
- npm_lifecycle_script: command,
156
- },
157
- });
158
- result.pre = pre;
159
- if (result.signal || result.status) {
160
- return result;
162
+ const main = command ? await execCommand(command) : emptyResult();
163
+ if (main.signal || main.status) {
164
+ return {
165
+ ...main,
166
+ ...(pre ? { pre } : {}),
167
+ };
161
168
  }
162
- const postcommand = !options.ignorePrePost && scripts[`post${arg0}`];
163
- if (!postcommand)
164
- return result;
165
- const post = await execImpl({
166
- arg0: postcommand,
167
- ...execArgs,
168
- 'script-shell': shell,
169
- args: [],
170
- env: {
171
- ...execArgs.env,
172
- npm_package_json: pjPath,
173
- npm_lifecycle_event: `post${arg0}`,
174
- npm_lifecycle_script: postcommand,
175
- },
176
- });
177
- if (post.status || post.signal) {
178
- const { status, signal } = post;
179
- return Object.assign(result, { post, status, signal });
169
+ const post = postcommand ? await execCommand(postcommand, 'post') : undefined;
170
+ if (post?.signal || post?.status) {
171
+ return {
172
+ ...main,
173
+ ...(pre ? { pre } : {}),
174
+ post,
175
+ signal: post.signal,
176
+ status: post.status,
177
+ };
180
178
  }
181
- result.post = post;
182
- return result;
179
+ return {
180
+ ...main,
181
+ ...(pre ? { pre } : {}),
182
+ ...(post ? { post } : {}),
183
+ };
184
+ };
185
+ /**
186
+ * Escapes a string for safe inclusion in a POSIX shell command.
187
+ * Wraps in single quotes and escapes any embedded single quotes.
188
+ */
189
+ const shellEscape = (s) => `'${s.replace(/'/g, "'\\''")}'`;
190
+ const isPosixShell = (shell) => {
191
+ if (typeof shell === 'string')
192
+ return !/(^|\\)cmd\.exe$/i.test(shell);
193
+ return process.platform !== 'win32';
194
+ };
195
+ /**
196
+ * When running through a POSIX shell, Node.js joins `spawn(cmd, args)`
197
+ * into a single string without escaping (DEP0190). This means
198
+ * characters like `#` are interpreted as shell comments, silently
199
+ * swallowing the rest of the command line.
200
+ *
201
+ * Fix: append shell-escaped args directly to the command string
202
+ * so the script is still shell-interpreted but args are passed
203
+ * literally.
204
+ *
205
+ * On Windows with cmd.exe, these characters are not special, so
206
+ * we leave args as-is to avoid injecting POSIX quotes that cmd.exe
207
+ * would pass through literally.
208
+ */
209
+ const withShellArgs = (shell, arg0, args) => {
210
+ if (!shell || args.length === 0 || !isPosixShell(shell))
211
+ return [arg0, args];
212
+ return [`${arg0} ${args.map(shellEscape).join(' ')}`, []];
183
213
  };
184
214
  /**
185
215
  * Execute an arbitrary command in the background
186
216
  */
187
217
  export const exec = async (options) => {
188
218
  const { arg0, args = [], cwd, env = {}, projectRoot, 'script-shell': shell = false, color = false, signal, ...spawnOptions } = options;
189
- const p = promiseSpawn(arg0, args, {
219
+ const [spawnCmd, spawnArgs] = withShellArgs(shell, arg0, args);
220
+ const p = promiseSpawn(spawnCmd, spawnArgs, {
190
221
  ...spawnOptions,
191
222
  shell,
192
223
  stdio: 'pipe',
@@ -195,7 +226,7 @@ export const exec = async (options) => {
195
226
  env: await addPaths(projectRoot, cwd, {
196
227
  ...process.env,
197
228
  ...env,
198
- FORCE_COLOR: color ? '1' : '0',
229
+ FORCE_COLOR: color && process.stdout.isTTY ? '1' : '0',
199
230
  }, arg0),
200
231
  windowsHide: true,
201
232
  });
@@ -207,13 +238,14 @@ export const exec = async (options) => {
207
238
  */
208
239
  export const execFG = async (options) => {
209
240
  const { arg0, args = [], cwd, projectRoot, env = {}, 'script-shell': shell = false, color = true, signal, ...spawnOptions } = options;
241
+ const [spawnCmd, spawnArgs] = withShellArgs(shell, arg0, args);
210
242
  const processEnv = await addPaths(projectRoot, cwd, {
211
243
  ...process.env,
212
244
  ...env,
213
245
  FORCE_COLOR: color ? '1' : '0',
214
246
  }, arg0);
215
247
  return new Promise(res => {
216
- foregroundChild(arg0, args, {
248
+ foregroundChild(spawnCmd, spawnArgs, {
217
249
  ...spawnOptions,
218
250
  shell,
219
251
  cwd,
@@ -253,6 +285,3 @@ export const runExec = async (options) => runExecImpl(options, run, exec);
253
285
  * execFG()
254
286
  */
255
287
  export const runExecFG = async (options) => runExecImpl(options, runFG, execFG);
256
- // Export shim utilities
257
- export { getNodeGypShim, getNodeGypShimDir, hasNodeGypReference, } from "./aliasRunner.js";
258
- //# sourceMappingURL=index.js.map
@@ -12,4 +12,7 @@ export declare function getNodeGypShimDir(): Promise<string>;
12
12
  * Check if a command contains node-gyp references
13
13
  */
14
14
  export declare function hasNodeGypReference(command: string): boolean;
15
- //# sourceMappingURL=aliasRunner.d.ts.map
15
+ /**
16
+ * Check if a binding.gyp file exists
17
+ */
18
+ export declare function hasNodeGypBinding(cwd: string): boolean;
@@ -1,4 +1,5 @@
1
1
  import { XDG } from '@vltpkg/xdg';
2
+ import { statSync } from 'node:fs';
2
3
  import { chmod, mkdir, stat, writeFile } from 'node:fs/promises';
3
4
  import { dirname, join } from 'node:path';
4
5
  const xdg = new XDG('vlt');
@@ -27,8 +28,8 @@ export async function getNodeGypShim() {
27
28
  // Create shim that calls vlx
28
29
  /* c8 ignore start - ignore platform-dependent coverage */
29
30
  const shimContent = process.platform === 'win32' ?
30
- `@echo off\nvlx node-gyp@latest %*\n`
31
- : `#!/bin/sh\nexec vlx node-gyp@latest "$@"\n`;
31
+ `@echo off\nvlx --yes node-gyp@latest %*\n`
32
+ : `#!/bin/sh\nexec vlx --yes node-gyp@latest "$@"\n`;
32
33
  /* c8 ignore stop */
33
34
  await writeFile(shimFile, shimContent, 'utf8');
34
35
  // Make executable on Unix systems
@@ -54,4 +55,14 @@ export async function getNodeGypShimDir() {
54
55
  export function hasNodeGypReference(command) {
55
56
  return command.includes('node-gyp');
56
57
  }
57
- //# sourceMappingURL=aliasRunner.js.map
58
+ /**
59
+ * Check if a binding.gyp file exists
60
+ */
61
+ export function hasNodeGypBinding(cwd) {
62
+ try {
63
+ return statSync(join(cwd, 'binding.gyp')).isFile();
64
+ }
65
+ catch {
66
+ return false;
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,75 +1,66 @@
1
1
  {
2
2
  "name": "@vltpkg/run",
3
3
  "description": "Run package.json scripts and execute commands",
4
- "version": "1.0.0-rc.3",
4
+ "version": "1.0.0-rc.31",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/run"
9
9
  },
10
- "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
11
- "tshy": {
12
- "selfLink": false,
13
- "liveDev": true,
14
- "dialects": [
15
- "esm"
16
- ],
17
- "exports": {
18
- "./package.json": "./package.json",
19
- ".": "./src/index.ts"
20
- }
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh",
13
+ "url": "http://vlt.sh"
21
14
  },
22
15
  "dependencies": {
16
+ "@vltpkg/error-cause": "1.0.0-rc.31",
17
+ "@vltpkg/package-json": "1.0.0-rc.31",
18
+ "@vltpkg/promise-spawn": "1.0.0-rc.31",
19
+ "@vltpkg/types": "1.0.0-rc.31",
20
+ "@vltpkg/xdg": "1.0.0-rc.31",
23
21
  "foreground-child": "^3.3.1",
24
- "walk-up-path": "^4.0.0",
25
- "@vltpkg/error-cause": "1.0.0-rc.3",
26
- "@vltpkg/promise-spawn": "1.0.0-rc.3",
27
- "@vltpkg/package-json": "1.0.0-rc.3",
28
- "@vltpkg/types": "1.0.0-rc.3",
29
- "@vltpkg/xdg": "1.0.0-rc.3"
22
+ "walk-up-path": "^4.0.0"
30
23
  },
31
24
  "devDependencies": {
32
- "@eslint/js": "^9.34.0",
33
- "@types/node": "^22.17.2",
34
- "eslint": "^9.34.0",
35
- "prettier": "^3.6.2",
36
- "tap": "^21.1.0",
37
- "tshy": "^3.0.2",
25
+ "@eslint/js": "^9.39.1",
26
+ "@types/node": "^22.19.2",
27
+ "eslint": "^9.39.1",
28
+ "prettier": "^3.7.4",
29
+ "tap": "^21.5.0",
38
30
  "typedoc": "~0.27.9",
39
31
  "typescript": "5.7.3",
40
- "typescript-eslint": "^8.40.0"
32
+ "typescript-eslint": "^8.49.0"
41
33
  },
42
34
  "license": "BSD-2-Clause-Patent",
43
35
  "engines": {
44
- "node": ">=22"
36
+ "node": ">=22.22.0"
37
+ },
38
+ "scripts": {
39
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
40
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
41
+ "lint": "eslint . --fix",
42
+ "lint:check": "eslint .",
43
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
44
+ "snap": "tap",
45
+ "test": "tap",
46
+ "posttest": "tsc --noEmit",
47
+ "typecheck": "tsc --noEmit"
45
48
  },
46
49
  "tap": {
47
50
  "extends": "../../tap-config.yaml"
48
51
  },
49
52
  "prettier": "../../.prettierrc.js",
50
- "module": "./dist/esm/index.js",
53
+ "module": "./dist/index.js",
51
54
  "type": "module",
52
55
  "exports": {
53
56
  "./package.json": "./package.json",
54
57
  ".": {
55
58
  "import": {
56
- "types": "./dist/esm/index.d.ts",
57
- "default": "./dist/esm/index.js"
59
+ "default": "./dist/index.js"
58
60
  }
59
61
  }
60
62
  },
61
63
  "files": [
62
64
  "dist"
63
- ],
64
- "scripts": {
65
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
66
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
67
- "lint": "eslint . --fix",
68
- "lint:check": "eslint .",
69
- "snap": "tap",
70
- "test": "tap",
71
- "posttest": "tsc --noEmit",
72
- "tshy": "tshy",
73
- "typecheck": "tsc --noEmit"
74
- }
75
- }
65
+ ]
66
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"aliasRunner.d.ts","sourceRoot":"","sources":["../../src/aliasRunner.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAsCtD;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAGzD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAE5D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"aliasRunner.js","sourceRoot":"","sources":["../../src/aliasRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEzC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;AAC1B,IAAI,QAA4B,CAAA;AAEhC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAClC,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAE7B,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAE7C,+BAA+B;IAC/B,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAA;QACpB,qCAAqC;QACrC,QAAQ,GAAG,QAAQ,CAAA;QACnB,OAAO,QAAQ,CAAA;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,gCAAgC;IAClC,CAAC;IAED,qCAAqC;IACrC,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAE5C,6BAA6B;IAC7B,0DAA0D;IAC1D,MAAM,WAAW,GACf,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;QAC5B,qCAAqC;QACvC,CAAC,CAAC,4CAA4C,CAAA;IAChD,oBAAoB;IAEpB,MAAM,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;IAE9C,kCAAkC;IAClC,iCAAiC;IACjC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IAC9B,CAAC;IACD,oBAAoB;IAEpB,QAAQ,GAAG,QAAQ,CAAA;IACnB,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,MAAM,IAAI,GAAG,MAAM,cAAc,EAAE,CAAA;IACnC,OAAO,OAAO,CAAC,IAAI,CAAC,CAAA;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAe;IACjD,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import { XDG } from '@vltpkg/xdg'\nimport { chmod, mkdir, stat, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\n\nconst xdg = new XDG('vlt')\nlet shimPath: string | undefined\n\n/**\n * Get or create the node-gyp shim file path\n * The shim redirects node-gyp calls to vlx node-gyp@latest\n */\nexport async function getNodeGypShim(): Promise<string> {\n if (shimPath) return shimPath\n\n const runtimeDir = xdg.runtime('run')\n const shimFile = join(runtimeDir, 'node-gyp')\n\n // Check if shim already exists\n try {\n await stat(shimFile)\n /* c8 ignore next 2 - hard to test */\n shimPath = shimFile\n return shimPath\n } catch {\n // Shim doesn't exist, create it\n }\n\n // Create runtime directory if needed\n await mkdir(runtimeDir, { recursive: true })\n\n // Create shim that calls vlx\n /* c8 ignore start - ignore platform-dependent coverage */\n const shimContent =\n process.platform === 'win32' ?\n `@echo off\\nvlx node-gyp@latest %*\\n`\n : `#!/bin/sh\\nexec vlx node-gyp@latest \"$@\"\\n`\n /* c8 ignore stop */\n\n await writeFile(shimFile, shimContent, 'utf8')\n\n // Make executable on Unix systems\n /* c8 ignore start - unix-only */\n if (process.platform !== 'win32') {\n await chmod(shimFile, 0o755)\n }\n /* c8 ignore stop */\n\n shimPath = shimFile\n return shimPath\n}\n\n/**\n * Get the directory containing the node-gyp shim\n * This can be prepended to PATH to make the shim available\n */\nexport async function getNodeGypShimDir(): Promise<string> {\n const shim = await getNodeGypShim()\n return dirname(shim)\n}\n\n/**\n * Check if a command contains node-gyp references\n */\nexport function hasNodeGypReference(command: string): boolean {\n return command.includes('node-gyp')\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAiF7C,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG;IAChD,kDAAkD;IAClD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;IACf,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAA;IAEnB,qEAAqE;IACrE,GAAG,EAAE,MAAM,CAAA;IACX;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IACvB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAEjC;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG;IACvC,oDAAoD;IACpD,I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AAW,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACxC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,CAAA;IACtB,MAAM,OAAO,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,EAAE,GAAG,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;IAChD,CAAC;SAAM,CAAC;QACN,OAAO,QAAQ,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACpC,CAAC;AACH,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAC1B,OAAuB,EACuB,EAAE,CAChD,WAAW,CAA0B,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAA;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,OAAuB,EACoB,EAAE,CAC7C,WAAW,CAAqB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AAEzD,wBAAwB;AACxB,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,kBAAkB,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { PackageJson } from '@vltpkg/package-json'\nimport type {\n PromiseSpawnOptions,\n SpawnResultNoStdio,\n SpawnResultStdioStrings,\n} from '@vltpkg/promise-spawn'\nimport { promiseSpawn } from '@vltpkg/promise-spawn'\nimport type { Manifest } from '@vltpkg/types'\nimport { foregroundChild } from 'foreground-child'\nimport { proxySignals } from 'foreground-child/proxy-signals'\nimport { statSync } from 'node:fs'\nimport { delimiter, resolve, sep } from 'node:path'\nimport { walkUp } from 'walk-up-path'\nimport {\n getNodeGypShimDir,\n hasNodeGypReference,\n} from './aliasRunner.ts'\n\n/** map of which node_modules/.bin folders exist */\nconst dotBins = new Map<string, boolean>()\n\n/** Check if a directory exists, and cache result */\nconst dirExists = (p: string) => {\n const cached = dotBins.get(p)\n if (cached !== undefined) return cached\n try {\n const isDir = statSync(p).isDirectory()\n dotBins.set(p, isDir)\n return isDir\n } catch {\n dotBins.set(p, false)\n return false\n }\n}\n\nconst nmBin = `${sep}node_modules${sep}.bin`\n\n/**\n * Add all existing `node_modules/.bin` folders to the PATH that\n * exist between the cwd and the projectRoot, so dependency bins\n * are found, with closer paths higher priority.\n *\n * If command contains node-gyp reference, also inject the shim directory\n * as a fallback (after all existing PATH entries).\n */\nconst addPaths = async (\n projectRoot: string,\n cwd: string,\n env: NodeJS.ProcessEnv,\n command?: string,\n): Promise<NodeJS.ProcessEnv> => {\n const { PATH = '' } = env\n const PATHsplit = PATH.split(delimiter)\n const paths = new Set<string>()\n\n // anything in the PATH that already has node_modules/.bin is a thing\n // we put there, perhaps for the vlx exec cache usage\n for (const p of PATHsplit) {\n if (p.endsWith(nmBin)) {\n paths.add(p)\n }\n }\n for (const p of walkUp(cwd)) {\n const dotBin = resolve(p, 'node_modules/.bin')\n if (dirExists(dotBin)) paths.add(dotBin)\n if (p === projectRoot) break\n }\n for (const p of PATH.split(delimiter)) {\n /* c8 ignore next - pretty rare to have an empty entry */\n if (p) paths.add(p)\n }\n\n // If command has node-gyp, inject shim directory as fallback (last)\n if (command && hasNodeGypReference(command)) {\n try {\n const shimDir = await getNodeGypShimDir()\n paths.add(shimDir)\n /* c8 ignore start */\n } catch {\n // Ignore shim creation errors, command will fail naturally if node-gyp is needed\n }\n /* c8 ignore stop */\n }\n\n env.PATH = [...paths].join(delimiter)\n return env\n}\n\n/** options shared by run() and exec() */\nexport type SharedOptions = PromiseSpawnOptions & {\n /** additional arguments to pass to the command */\n args?: string[]\n /** the root of the project, which we don't walk up past */\n projectRoot: string\n\n /** the directory where the package.json lives and the script runs */\n cwd: string\n /**\n * environment variables to set. `process.env` is always included,\n * to omit fields, set them explicitly to undefined.\n *\n * vlt will add some of its own, as well:\n * - npm_lifecycle_event: the event name\n * - npm_lifecycle_script: the command in package.json#scripts\n * - npm_package_json: path to the package.json file\n * - VLT_* envs for all vlt configuration values that are set\n */\n env?: NodeJS.ProcessEnv\n /**\n * the shell to run the script in. If not set, then the default\n * platform-specific shell will be used.\n */\n 'script-shell'?: boolean | string\n\n /**\n * If true, then `FORCE_COLOR=1` will be set in the environment so that\n * scripts will typically have colored output enablled, even if the output\n * is not a tty.\n */\n color?: boolean\n}\n\n/**\n * Options for run() and runFG()\n */\nexport type RunOptions = SharedOptions & {\n /** the name of the thing in package.json#scripts */\n arg0: string\n /**\n * pass in a @vltpkg/package-json.PackageJson instance, and\n * it'll be used for reading the package.json file. Optional,\n * may improve performance somewhat.\n */\n packageJson?: PackageJson\n\n /**\n * Pass in a manifest to avoid having to read it at all\n */\n manifest?: Pick<Manifest, 'scripts' | 'gypfile'>\n\n /**\n * if the script is not defined in package.json#scripts, just ignore it and\n * treat as success. Otherwise, treat as an error. Default false.\n */\n ignoreMissing?: boolean\n\n /**\n * skip the pre/post commands, just run the one specified.\n * This can be used to run JUST the specified script, without any\n * pre/post commands.\n */\n ignorePrePost?: boolean\n}\n\n/**\n * Options for exec() and execFG()\n */\nexport type ExecOptions = SharedOptions & {\n /** the command to execute */\n arg0: string\n}\n\n/**\n * Options for runExec() and runExecFG()\n */\nexport type RunExecOptions = SharedOptions & {\n /**\n * Either the command to be executed, or the event to be run\n */\n arg0: string\n /**\n * pass in a @vltpkg/package-json.PackageJson instance, and\n * it'll be used for reading the package.json file. Optional,\n * may improve performance somewhat.\n */\n packageJson?: PackageJson\n}\n\n/**\n * Run a package.json#scripts event in the background\n */\nexport const run = async (options: RunOptions): Promise<RunResult> =>\n runImpl(options, exec, '')\n\n/**\n * Run a package.json#scripts event in the foreground\n */\nexport const runFG = async (\n options: RunOptions,\n): Promise<RunFGResult> => runImpl(options, execFG, null)\n\n/** Return type of {@link run} */\nexport type RunResult = SpawnResultStdioStrings & {\n pre?: SpawnResultStdioStrings\n post?: SpawnResultStdioStrings\n}\n\n/** Return type of {@link runFG} */\nexport type RunFGResult = SpawnResultNoStdio & {\n pre?: SpawnResultNoStdio\n post?: SpawnResultNoStdio\n}\n\nexport const isRunResult = (v: unknown): v is RunResult =>\n !!v &&\n typeof v === 'object' &&\n !Array.isArray(v) &&\n 'stdout' in v &&\n 'stderr' in v &&\n 'status' in v &&\n 'signal' in v\n\n/**\n * Return type of {@link run} or {@link runFG}, as determined by their base\n * type\n * @internal\n */\nexport type RunImplResult<\n R extends SpawnResultNoStdio | SpawnResultStdioStrings,\n> = R & { pre?: R; post?: R }\n\n/**\n * Internal implementation of run() and runFG(), since they're mostly identical\n */\nconst runImpl = async <\n R extends SpawnResultNoStdio | SpawnResultStdioStrings,\n>(\n options: RunOptions,\n execImpl: (options: ExecOptions) => Promise<R>,\n empty: R['stdout'],\n): Promise<RunImplResult<R>> => {\n const {\n arg0,\n packageJson = new PackageJson(),\n ignoreMissing = false,\n manifest,\n 'script-shell': shell = true,\n ...execArgs\n } = options\n const pjPath = resolve(options.cwd, 'package.json')\n // npm adds a `\"install\": \"node-gyp rebuild\"` if a binding.gyp\n // is present at the time of publish, EVEN IF it's not included\n // in the package. So, we need to read the actual package.json\n // in those cases.\n const untrustworthy = !!(\n manifest?.gypfile &&\n arg0 === 'install' &&\n manifest.scripts?.install === 'node-gyp rebuild'\n )\n const pj =\n (untrustworthy ? undefined : manifest) ??\n packageJson.read(options.cwd)\n const { scripts } = pj\n const command = scripts?.[arg0]\n if (!command) {\n if (ignoreMissing) {\n return {\n command: '',\n /* c8 ignore next */\n args: execArgs.args ?? [],\n cwd: options.cwd,\n status: 0,\n signal: null,\n stdout: empty,\n stderr: empty,\n // `as` to workaround \"could be instantiated with arbitrary type\".\n // it's private and used in 2 places, we know that it isn't.\n } as R\n }\n throw error('Script not defined in package.json', {\n name: arg0,\n cwd: options.cwd,\n args: options.args,\n path: pjPath,\n manifest: pj,\n })\n }\n\n const precommand = !options.ignorePrePost && scripts[`pre${arg0}`]\n const pre =\n precommand ?\n await execImpl({\n arg0: precommand,\n ...execArgs,\n 'script-shell': shell,\n args: [],\n env: {\n ...execArgs.env,\n npm_package_json: pjPath,\n npm_lifecycle_event: `pre${arg0}`,\n npm_lifecycle_script: precommand,\n },\n })\n : undefined\n if (pre && (pre.status || pre.signal)) {\n return pre as RunImplResult<R>\n }\n const result: RunImplResult<R> = await execImpl({\n arg0: command,\n ...execArgs,\n 'script-shell': shell,\n env: {\n ...execArgs.env,\n npm_package_json: pjPath,\n npm_lifecycle_event: arg0,\n npm_lifecycle_script: command,\n },\n })\n result.pre = pre\n if (result.signal || result.status) {\n return result\n }\n\n const postcommand = !options.ignorePrePost && scripts[`post${arg0}`]\n if (!postcommand) return result\n\n const post = await execImpl({\n arg0: postcommand,\n ...execArgs,\n 'script-shell': shell,\n args: [],\n env: {\n ...execArgs.env,\n npm_package_json: pjPath,\n npm_lifecycle_event: `post${arg0}`,\n npm_lifecycle_script: postcommand,\n },\n })\n\n if (post.status || post.signal) {\n const { status, signal } = post\n return Object.assign(result, { post, status, signal })\n }\n result.post = post\n return result\n}\n\n/**\n * Execute an arbitrary command in the background\n */\nexport const exec = async (\n options: ExecOptions,\n): Promise<SpawnResultStdioStrings> => {\n const {\n arg0,\n args = [],\n cwd,\n env = {},\n projectRoot,\n 'script-shell': shell = false,\n color = false,\n signal,\n ...spawnOptions\n } = options\n\n const p = promiseSpawn(arg0, args, {\n ...spawnOptions,\n shell,\n stdio: 'pipe',\n stdioString: true,\n cwd,\n env: await addPaths(\n projectRoot,\n cwd,\n {\n ...process.env,\n ...env,\n FORCE_COLOR: color ? '1' : '0',\n },\n arg0,\n ),\n windowsHide: true,\n })\n proxySignals(p.process)\n return await p\n}\n\n/**\n * Execute an arbitrary command in the foreground\n */\nexport const execFG = async (\n options: ExecOptions,\n): Promise<SpawnResultNoStdio> => {\n const {\n arg0,\n args = [],\n cwd,\n projectRoot,\n env = {},\n 'script-shell': shell = false,\n color = true,\n signal,\n ...spawnOptions\n } = options\n\n const processEnv = await addPaths(\n projectRoot,\n cwd,\n {\n ...process.env,\n ...env,\n FORCE_COLOR: color ? '1' : '0',\n },\n arg0,\n )\n\n return new Promise<SpawnResultNoStdio>(res => {\n foregroundChild(\n arg0,\n args,\n {\n ...spawnOptions,\n shell,\n cwd,\n env: processEnv,\n },\n (status, signal) => {\n res({\n command: arg0,\n args,\n cwd,\n stdout: null,\n stderr: null,\n status,\n signal,\n })\n return false\n },\n )\n })\n}\n\nconst runExecImpl = async <\n R extends SpawnResultNoStdio | SpawnResultStdioStrings,\n>(\n options: RunExecOptions,\n runImpl: (options: RunOptions) => Promise<RunImplResult<R>>,\n execImpl: (options: ExecOptions) => Promise<R>,\n): Promise<R | RunImplResult<R>> => {\n const { arg0, packageJson = new PackageJson(), ...args } = options\n const pj = packageJson.read(options.cwd)\n const { scripts } = pj\n const command = scripts?.[arg0]\n if (command) {\n return runImpl({ ...args, packageJson, arg0 })\n } else {\n return execImpl({ ...args, arg0 })\n }\n}\n\n/**\n * If the arg0 is a defined package.json script, then run(), otherwise exec()\n */\nexport const runExec = async (\n options: RunExecOptions,\n): Promise<RunResult | SpawnResultStdioStrings> =>\n runExecImpl<SpawnResultStdioStrings>(options, run, exec)\n\n/**\n * If the arg0 is a defined package.json script, then runFG(), otherwise\n * execFG()\n */\nexport const runExecFG = async (\n options: RunExecOptions,\n): Promise<RunFGResult | SpawnResultNoStdio> =>\n runExecImpl<SpawnResultNoStdio>(options, runFG, execFG)\n\n// Export shim utilities\nexport {\n getNodeGypShim,\n getNodeGypShimDir,\n hasNodeGypReference,\n} from './aliasRunner.ts'\n"]}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }