@vltpkg/run 1.0.0-rc.18 → 1.0.0-rc.22

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.
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@vltpkg/run",
3
3
  "description": "Run package.json scripts and execute commands",
4
- "version": "1.0.0-rc.18",
4
+ "version": "1.0.0-rc.22",
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)",
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh"
13
+ },
11
14
  "dependencies": {
15
+ "@vltpkg/error-cause": "1.0.0-rc.22",
16
+ "@vltpkg/package-json": "1.0.0-rc.22",
17
+ "@vltpkg/promise-spawn": "1.0.0-rc.22",
18
+ "@vltpkg/types": "1.0.0-rc.22",
19
+ "@vltpkg/xdg": "1.0.0-rc.22",
12
20
  "foreground-child": "^3.3.1",
13
- "walk-up-path": "^4.0.0",
14
- "@vltpkg/error-cause": "1.0.0-rc.18",
15
- "@vltpkg/promise-spawn": "1.0.0-rc.18",
16
- "@vltpkg/package-json": "1.0.0-rc.18",
17
- "@vltpkg/types": "1.0.0-rc.18",
18
- "@vltpkg/xdg": "1.0.0-rc.18"
21
+ "walk-up-path": "^4.0.0"
19
22
  },
20
23
  "devDependencies": {
21
24
  "@eslint/js": "^9.39.1",
@@ -29,33 +32,34 @@
29
32
  },
30
33
  "license": "BSD-2-Clause-Patent",
31
34
  "engines": {
32
- "node": ">=22.9.0"
35
+ "node": ">=22.22.0"
36
+ },
37
+ "scripts": {
38
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
39
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
40
+ "lint": "eslint . --fix",
41
+ "lint:check": "eslint .",
42
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
43
+ "snap": "tap",
44
+ "test": "tap",
45
+ "posttest": "tsc --noEmit",
46
+ "typecheck": "tsc --noEmit"
33
47
  },
34
48
  "tap": {
35
49
  "extends": "../../tap-config.yaml"
36
50
  },
37
51
  "prettier": "../../.prettierrc.js",
38
- "module": "./dist/index.js",
52
+ "module": "./src/index.ts",
39
53
  "type": "module",
40
54
  "exports": {
41
55
  "./package.json": "./package.json",
42
56
  ".": {
43
57
  "import": {
44
- "default": "./dist/index.js"
58
+ "default": "./src/index.ts"
45
59
  }
46
60
  }
47
61
  },
48
62
  "files": [
49
63
  "dist"
50
- ],
51
- "scripts": {
52
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
53
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
54
- "lint": "eslint . --fix",
55
- "lint:check": "eslint .",
56
- "snap": "tap",
57
- "test": "tap",
58
- "posttest": "tsc --noEmit",
59
- "typecheck": "tsc --noEmit"
60
- }
61
- }
64
+ ]
65
+ }
package/dist/index.d.ts DELETED
@@ -1,131 +0,0 @@
1
- import { PackageJson } from '@vltpkg/package-json';
2
- import type { PromiseSpawnOptions, SpawnResultNoStdio, SpawnResultStdioStrings } from '@vltpkg/promise-spawn';
3
- import type { Manifest } from '@vltpkg/types';
4
- export * from './node-gyp.ts';
5
- /** options shared by run() and exec() */
6
- export type SharedOptions = PromiseSpawnOptions & {
7
- /** additional arguments to pass to the command */
8
- args?: string[];
9
- /** the root of the project, which we don't walk up past */
10
- projectRoot: string;
11
- /** the directory where the package.json lives and the script runs */
12
- cwd: string;
13
- /**
14
- * environment variables to set. `process.env` is always included,
15
- * to omit fields, set them explicitly to undefined.
16
- *
17
- * vlt will add some of its own, as well:
18
- * - npm_lifecycle_event: the event name
19
- * - npm_lifecycle_script: the command in package.json#scripts
20
- * - npm_package_json: path to the package.json file
21
- * - VLT_* envs for all vlt configuration values that are set
22
- */
23
- env?: NodeJS.ProcessEnv;
24
- /**
25
- * the shell to run the script in. If not set, then the default
26
- * platform-specific shell will be used.
27
- */
28
- 'script-shell'?: boolean | string;
29
- /**
30
- * If true, then `FORCE_COLOR=1` will be set in the environment so that
31
- * scripts will typically have colored output enablled, even if the output
32
- * is not a tty.
33
- */
34
- color?: boolean;
35
- };
36
- /**
37
- * Options for run() and runFG()
38
- */
39
- export type RunOptions = SharedOptions & {
40
- /** the name of the thing in package.json#scripts */
41
- arg0: string;
42
- /**
43
- * pass in a @vltpkg/package-json.PackageJson instance, and
44
- * it'll be used for reading the package.json file. Optional,
45
- * may improve performance somewhat.
46
- */
47
- packageJson?: PackageJson;
48
- /**
49
- * Pass in a manifest to avoid having to read it at all
50
- */
51
- manifest?: Pick<Manifest, 'scripts' | 'gypfile'>;
52
- /**
53
- * if the script is not defined in package.json#scripts, just ignore it and
54
- * treat as success. Otherwise, treat as an error. Default false.
55
- */
56
- ignoreMissing?: boolean;
57
- /**
58
- * skip the pre/post commands, just run the one specified.
59
- * This can be used to run JUST the specified script, without any
60
- * pre/post commands.
61
- */
62
- ignorePrePost?: boolean;
63
- };
64
- /**
65
- * Options for exec() and execFG()
66
- */
67
- export type ExecOptions = SharedOptions & {
68
- /** the command to execute */
69
- arg0: string;
70
- };
71
- /**
72
- * Options for runExec() and runExecFG()
73
- */
74
- export type RunExecOptions = SharedOptions & {
75
- /**
76
- * Either the command to be executed, or the event to be run
77
- */
78
- arg0: string;
79
- /**
80
- * pass in a @vltpkg/package-json.PackageJson instance, and
81
- * it'll be used for reading the package.json file. Optional,
82
- * may improve performance somewhat.
83
- */
84
- packageJson?: PackageJson;
85
- };
86
- /**
87
- * Run a package.json#scripts event in the background
88
- */
89
- export declare const run: (options: RunOptions) => Promise<RunResult>;
90
- /**
91
- * Run a package.json#scripts event in the foreground
92
- */
93
- export declare const runFG: (options: RunOptions) => Promise<RunFGResult>;
94
- /** Return type of {@link run} */
95
- export type RunResult = SpawnResultStdioStrings & {
96
- pre?: SpawnResultStdioStrings;
97
- post?: SpawnResultStdioStrings;
98
- };
99
- /** Return type of {@link runFG} */
100
- export type RunFGResult = SpawnResultNoStdio & {
101
- pre?: SpawnResultNoStdio;
102
- post?: SpawnResultNoStdio;
103
- };
104
- export declare const isRunResult: (v: unknown) => v is RunResult;
105
- /**
106
- * Return type of {@link run} or {@link runFG}, as determined by their base
107
- * type
108
- * @internal
109
- */
110
- export type RunImplResult<R extends SpawnResultNoStdio | SpawnResultStdioStrings> = R & {
111
- pre?: R;
112
- post?: R;
113
- };
114
- /**
115
- * Execute an arbitrary command in the background
116
- */
117
- export declare const exec: (options: ExecOptions) => Promise<SpawnResultStdioStrings>;
118
- /**
119
- * Execute an arbitrary command in the foreground
120
- */
121
- export declare const execFG: (options: ExecOptions) => Promise<SpawnResultNoStdio>;
122
- /**
123
- * If the arg0 is a defined package.json script, then run(), otherwise exec()
124
- */
125
- export declare const runExec: (options: RunExecOptions) => Promise<RunResult | SpawnResultStdioStrings>;
126
- /**
127
- * If the arg0 is a defined package.json script, then runFG(), otherwise
128
- * execFG()
129
- */
130
- export declare const runExecFG: (options: RunExecOptions) => Promise<RunFGResult | SpawnResultNoStdio>;
131
- //# sourceMappingURL=index.d.ts.map
@@ -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;AAa7C,cAAc,eAAe,CAAA;AAwE7B,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,EA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AAE,kBAAkB,CAAA;IACxB,IAAI,CAAC,EAAE,kBAAkB,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,WAAW,MAAO,OAAO,KAAG,CAAC,IAAI,SAO/B,CAAA;AAEf;;;;GAIG;AACH,MAAM,MAAM,aAAa,CACvB,CAAC,SAAS,kBAAkB,GAAG,uBAAuB,IACpD,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAA;CAAE,CAAA;AAqI7B;;GAEG;AACH,eAAO,MAAM,IAAI,YACN,WAAW,KACnB,OAAO,CAAC,uBAAuB,CAiCjC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,YACR,WAAW,KACnB,OAAO,CAAC,kBAAkB,CAgD5B,CAAA;AAoBD;;GAEG;AACH,eAAO,MAAM,OAAO,YACT,cAAc,KACtB,OAAO,CAAC,SAAS,GAAG,uBAAuB,CACY,CAAA;AAE1D;;;GAGG;AACH,eAAO,MAAM,SAAS,YACX,cAAc,KACtB,OAAO,CAAC,WAAW,GAAG,kBAAkB,CACc,CAAA"}
package/dist/index.js DELETED
@@ -1,257 +0,0 @@
1
- import { error } from '@vltpkg/error-cause';
2
- import { PackageJson } from '@vltpkg/package-json';
3
- import { promiseSpawn } from '@vltpkg/promise-spawn';
4
- import { foregroundChild } from 'foreground-child';
5
- import { proxySignals } from 'foreground-child/proxy-signals';
6
- import { statSync } from 'node:fs';
7
- import { delimiter, resolve, sep } from 'node:path';
8
- import { walkUp } from 'walk-up-path';
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";
12
- /** map of which node_modules/.bin folders exist */
13
- const dotBins = new Map();
14
- /** Check if a directory exists, and cache result */
15
- const dirExists = (p) => {
16
- const cached = dotBins.get(p);
17
- if (cached !== undefined)
18
- return cached;
19
- try {
20
- const isDir = statSync(p).isDirectory();
21
- dotBins.set(p, isDir);
22
- return isDir;
23
- }
24
- catch {
25
- dotBins.set(p, false);
26
- return false;
27
- }
28
- };
29
- const nmBin = `${sep}node_modules${sep}.bin`;
30
- /**
31
- * Add all existing `node_modules/.bin` folders to the PATH that
32
- * exist between the cwd and the projectRoot, so dependency bins
33
- * are found, with closer paths higher priority.
34
- *
35
- * If command contains node-gyp reference, also inject the shim directory
36
- * as a fallback (after all existing PATH entries).
37
- */
38
- const addPaths = async (projectRoot, cwd, env, command) => {
39
- const { PATH = '' } = env;
40
- const PATHsplit = PATH.split(delimiter);
41
- const paths = new Set();
42
- // anything in the PATH that already has node_modules/.bin is a thing
43
- // we put there, perhaps for the vlx exec cache usage
44
- for (const p of PATHsplit) {
45
- if (p.endsWith(nmBin)) {
46
- paths.add(p);
47
- }
48
- }
49
- for (const p of walkUp(cwd)) {
50
- const dotBin = resolve(p, 'node_modules/.bin');
51
- if (dirExists(dotBin))
52
- paths.add(dotBin);
53
- if (p === projectRoot)
54
- break;
55
- }
56
- for (const p of PATH.split(delimiter)) {
57
- /* c8 ignore next - pretty rare to have an empty entry */
58
- if (p)
59
- paths.add(p);
60
- }
61
- // If command has node-gyp, inject shim directory as fallback (last)
62
- if (command && hasNodeGypReference(command)) {
63
- try {
64
- const shimDir = await getNodeGypShimDir();
65
- paths.add(shimDir);
66
- /* c8 ignore start */
67
- }
68
- catch {
69
- // Ignore shim creation errors, command will fail naturally if node-gyp is needed
70
- }
71
- /* c8 ignore stop */
72
- }
73
- env.PATH = [...paths].join(delimiter);
74
- return env;
75
- };
76
- /**
77
- * Run a package.json#scripts event in the background
78
- */
79
- export const run = async (options) => runImpl(options, exec, '');
80
- /**
81
- * Run a package.json#scripts event in the foreground
82
- */
83
- export const runFG = async (options) => runImpl(options, execFG, null);
84
- export const isRunResult = (v) => !!v &&
85
- typeof v === 'object' &&
86
- !Array.isArray(v) &&
87
- 'stdout' in v &&
88
- 'stderr' in v &&
89
- 'status' in v &&
90
- 'signal' in v;
91
- /**
92
- * Internal implementation of run() and runFG(), since they're mostly identical
93
- */
94
- const runImpl = async (options, execImpl, empty) => {
95
- const { arg0, packageJson = new PackageJson(), ignoreMissing = false, manifest, 'script-shell': shell = true, ...execArgs } = options;
96
- const pjPath = resolve(options.cwd, 'package.json');
97
- // npm adds a `"install": "node-gyp rebuild"` if a binding.gyp
98
- // is present at the time of publish, EVEN IF it's not included
99
- // in the package. So, we need to read the actual package.json
100
- // in those cases.
101
- const untrustworthy = !!(manifest?.gypfile &&
102
- arg0 === 'install' &&
103
- manifest.scripts?.install === 'node-gyp rebuild');
104
- const pj = (untrustworthy ? undefined : manifest) ??
105
- packageJson.read(options.cwd);
106
- const { scripts } = pj;
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) {
145
- if (ignoreMissing) {
146
- return emptyResult();
147
- }
148
- throw error('Script not defined in package.json', {
149
- name: arg0,
150
- cwd: options.cwd,
151
- args: options.args,
152
- path: pjPath,
153
- manifest: pj,
154
- });
155
- }
156
- const pre = precommand ? await execCommand(precommand, 'pre') : undefined;
157
- if (pre?.status || pre?.signal) {
158
- return {
159
- ...pre,
160
- };
161
- }
162
- const main = command ? await execCommand(command) : emptyResult();
163
- if (main.signal || main.status) {
164
- return {
165
- ...main,
166
- ...(pre ? { pre } : {}),
167
- };
168
- }
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
- };
178
- }
179
- return {
180
- ...main,
181
- ...(pre ? { pre } : {}),
182
- ...(post ? { post } : {}),
183
- };
184
- };
185
- /**
186
- * Execute an arbitrary command in the background
187
- */
188
- export const exec = async (options) => {
189
- const { arg0, args = [], cwd, env = {}, projectRoot, 'script-shell': shell = false, color = false, signal, ...spawnOptions } = options;
190
- const p = promiseSpawn(arg0, args, {
191
- ...spawnOptions,
192
- shell,
193
- stdio: 'pipe',
194
- stdioString: true,
195
- cwd,
196
- env: await addPaths(projectRoot, cwd, {
197
- ...process.env,
198
- ...env,
199
- FORCE_COLOR: color ? '1' : '0',
200
- }, arg0),
201
- windowsHide: true,
202
- });
203
- proxySignals(p.process);
204
- return await p;
205
- };
206
- /**
207
- * Execute an arbitrary command in the foreground
208
- */
209
- export const execFG = async (options) => {
210
- const { arg0, args = [], cwd, projectRoot, env = {}, 'script-shell': shell = false, color = true, signal, ...spawnOptions } = options;
211
- const processEnv = await addPaths(projectRoot, cwd, {
212
- ...process.env,
213
- ...env,
214
- FORCE_COLOR: color ? '1' : '0',
215
- }, arg0);
216
- return new Promise(res => {
217
- foregroundChild(arg0, args, {
218
- ...spawnOptions,
219
- shell,
220
- cwd,
221
- env: processEnv,
222
- }, (status, signal) => {
223
- res({
224
- command: arg0,
225
- args,
226
- cwd,
227
- stdout: null,
228
- stderr: null,
229
- status,
230
- signal,
231
- });
232
- return false;
233
- });
234
- });
235
- };
236
- const runExecImpl = async (options, runImpl, execImpl) => {
237
- const { arg0, packageJson = new PackageJson(), ...args } = options;
238
- const pj = packageJson.read(options.cwd);
239
- const { scripts } = pj;
240
- const command = scripts?.[arg0];
241
- if (command) {
242
- return runImpl({ ...args, packageJson, arg0 });
243
- }
244
- else {
245
- return execImpl({ ...args, arg0 });
246
- }
247
- };
248
- /**
249
- * If the arg0 is a defined package.json script, then run(), otherwise exec()
250
- */
251
- export const runExec = async (options) => runExecImpl(options, run, exec);
252
- /**
253
- * If the arg0 is a defined package.json script, then runFG(), otherwise
254
- * execFG()
255
- */
256
- export const runExecFG = async (options) => runExecImpl(options, runFG, execFG);
257
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAMlD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,eAAe,CAAA;AAEtB,+CAA+C;AAC/C,cAAc,eAAe,CAAA;AAE7B,mDAAmD;AACnD,MAAM,OAAO,GAAG,IAA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AAE,CAC7C,WAAW,CAAqB,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,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 hasNodeGypBinding,\n} from './node-gyp.ts'\n\n// Re-export all named exports from node-gyp.ts\nexport * from './node-gyp.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\n const command =\n scripts?.[arg0] ??\n // npm's implicit install behavior: \"If there is a binding.gyp file in the\n // root of your package and you haven't defined your own install or preinstall\n // scripts, npm will default the install command to compile using node-gyp\n // via node-gyp rebuild\"\n ((\n arg0 === 'install' &&\n !scripts?.install &&\n !scripts?.preinstall &&\n hasNodeGypBinding(options.cwd)\n ) ?\n 'node-gyp rebuild'\n : undefined)\n\n // Check for pre/post commands even if main command doesn't exist for cases\n // like packages that have only a preinstall or postinstall script.\n const precommand = !options.ignorePrePost && scripts?.[`pre${arg0}`]\n const postcommand =\n !options.ignorePrePost && scripts?.[`post${arg0}`]\n\n const emptyResult = () =>\n ({\n command: '',\n args: execArgs.args ?? [],\n cwd: options.cwd,\n status: 0,\n signal: null,\n stdout: empty,\n stderr: empty,\n }) as R\n\n const execCommand = (command: string, preOrPost?: 'pre' | 'post') =>\n execImpl({\n arg0: command,\n ...execArgs,\n 'script-shell': shell,\n // pre/post scripts always have empty args, main script uses execArgs.args\n args: preOrPost ? [] : (execArgs.args ?? []),\n env: {\n ...execArgs.env,\n npm_package_json: pjPath,\n npm_lifecycle_event: `${preOrPost ?? ''}${arg0}`,\n npm_lifecycle_script: command,\n },\n })\n\n if (!command && !precommand && !postcommand) {\n if (ignoreMissing) {\n return emptyResult()\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 pre =\n precommand ? await execCommand(precommand, 'pre') : undefined\n\n if (pre?.status || pre?.signal) {\n return {\n ...pre,\n }\n }\n\n const main = command ? await execCommand(command) : emptyResult()\n\n if (main.signal || main.status) {\n return {\n ...main,\n ...(pre ? { pre } : {}),\n }\n }\n\n const post =\n postcommand ? await execCommand(postcommand, 'post') : undefined\n\n if (post?.signal || post?.status) {\n return {\n ...main,\n ...(pre ? { pre } : {}),\n post,\n signal: post.signal,\n status: post.status,\n } as RunImplResult<R>\n }\n\n return {\n ...main,\n ...(pre ? { pre } : {}),\n ...(post ? { post } : {}),\n }\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"]}
@@ -1,19 +0,0 @@
1
- /**
2
- * Get or create the node-gyp shim file path
3
- * The shim redirects node-gyp calls to vlx node-gyp@latest
4
- */
5
- export declare function getNodeGypShim(): Promise<string>;
6
- /**
7
- * Get the directory containing the node-gyp shim
8
- * This can be prepended to PATH to make the shim available
9
- */
10
- export declare function getNodeGypShimDir(): Promise<string>;
11
- /**
12
- * Check if a command contains node-gyp references
13
- */
14
- export declare function hasNodeGypReference(command: string): boolean;
15
- /**
16
- * Check if a binding.gyp file exists
17
- */
18
- export declare function hasNodeGypBinding(cwd: string): boolean;
19
- //# sourceMappingURL=node-gyp.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-gyp.d.ts","sourceRoot":"","sources":["../src/node-gyp.ts"],"names":[],"mappings":"AAQA;;;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;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAMtD"}
package/dist/node-gyp.js DELETED
@@ -1,69 +0,0 @@
1
- import { XDG } from '@vltpkg/xdg';
2
- import { statSync } from 'node:fs';
3
- import { chmod, mkdir, stat, writeFile } from 'node:fs/promises';
4
- import { dirname, join } from 'node:path';
5
- const xdg = new XDG('vlt');
6
- let shimPath;
7
- /**
8
- * Get or create the node-gyp shim file path
9
- * The shim redirects node-gyp calls to vlx node-gyp@latest
10
- */
11
- export async function getNodeGypShim() {
12
- if (shimPath)
13
- return shimPath;
14
- const runtimeDir = xdg.runtime('run');
15
- const shimFile = join(runtimeDir, 'node-gyp');
16
- // Check if shim already exists
17
- try {
18
- await stat(shimFile);
19
- /* c8 ignore next 2 - hard to test */
20
- shimPath = shimFile;
21
- return shimPath;
22
- }
23
- catch {
24
- // Shim doesn't exist, create it
25
- }
26
- // Create runtime directory if needed
27
- await mkdir(runtimeDir, { recursive: true });
28
- // Create shim that calls vlx
29
- /* c8 ignore start - ignore platform-dependent coverage */
30
- const shimContent = process.platform === 'win32' ?
31
- `@echo off\nvlx --yes node-gyp@latest %*\n`
32
- : `#!/bin/sh\nexec vlx --yes node-gyp@latest "$@"\n`;
33
- /* c8 ignore stop */
34
- await writeFile(shimFile, shimContent, 'utf8');
35
- // Make executable on Unix systems
36
- /* c8 ignore start - unix-only */
37
- if (process.platform !== 'win32') {
38
- await chmod(shimFile, 0o755);
39
- }
40
- /* c8 ignore stop */
41
- shimPath = shimFile;
42
- return shimPath;
43
- }
44
- /**
45
- * Get the directory containing the node-gyp shim
46
- * This can be prepended to PATH to make the shim available
47
- */
48
- export async function getNodeGypShimDir() {
49
- const shim = await getNodeGypShim();
50
- return dirname(shim);
51
- }
52
- /**
53
- * Check if a command contains node-gyp references
54
- */
55
- export function hasNodeGypReference(command) {
56
- return command.includes('node-gyp');
57
- }
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
- }
69
- //# sourceMappingURL=node-gyp.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-gyp.js","sourceRoot":"","sources":["../src/node-gyp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,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,2CAA2C;QAC7C,CAAC,CAAC,kDAAkD,CAAA;IACtD,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;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,MAAM,EAAE,CAAA;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC","sourcesContent":["import { XDG } from '@vltpkg/xdg'\nimport { statSync } from 'node:fs'\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 --yes node-gyp@latest %*\\n`\n : `#!/bin/sh\\nexec vlx --yes 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\n/**\n * Check if a binding.gyp file exists\n */\nexport function hasNodeGypBinding(cwd: string): boolean {\n try {\n return statSync(join(cwd, 'binding.gyp')).isFile()\n } catch {\n return false\n }\n}\n"]}