@vercel/build-utils 4.2.0 → 4.2.1

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.
@@ -44,6 +44,12 @@ export interface SpawnOptionsExtended extends SpawnOptions {
44
44
  * Pretty formatted command that is being spawned for logging purposes.
45
45
  */
46
46
  prettyCommand?: string;
47
+ /**
48
+ * Returns instead of throwing an error when the process exits with a
49
+ * non-0 exit code. When relevant, the returned object will include
50
+ * the error code, stdout and stderr.
51
+ */
52
+ ignoreNon0Exit?: boolean;
47
53
  }
48
54
  export declare function spawnAsync(command: string, args: string[], opts?: SpawnOptionsExtended): Promise<void>;
49
55
  export declare function execAsync(command: string, args: string[], opts?: SpawnOptionsExtended): Promise<{
@@ -53,9 +59,9 @@ export declare function execAsync(command: string, args: string[], opts?: SpawnO
53
59
  }>;
54
60
  export declare function spawnCommand(command: string, options?: SpawnOptions): import("child_process").ChildProcess;
55
61
  export declare function execCommand(command: string, options?: SpawnOptions): Promise<boolean>;
56
- export declare function getNodeBinPath({ cwd }: {
62
+ export declare function getNodeBinPath({ cwd, }: {
57
63
  cwd: string;
58
- }): Promise<string>;
64
+ }): Promise<string | undefined>;
59
65
  export declare function runShellScript(fsPath: string, args?: string[], spawnOpts?: SpawnOptions): Promise<boolean>;
60
66
  export declare function getSpawnOptions(meta: Meta, nodeVersion: NodeVersion): SpawnOptions;
61
67
  export declare function getNodeVersion(destPath: string, _nodeVersion?: string, config?: Config, meta?: Meta): Promise<NodeVersion>;
@@ -27,7 +27,7 @@ function spawnAsync(command, args, opts = {}) {
27
27
  }
28
28
  child.on('error', reject);
29
29
  child.on('close', (code, signal) => {
30
- if (code === 0) {
30
+ if (code === 0 || opts.ignoreNon0Exit) {
31
31
  return resolve();
32
32
  }
33
33
  const cmd = opts.prettyCommand
@@ -57,20 +57,20 @@ function execAsync(command, args, opts = {}) {
57
57
  });
58
58
  child.on('error', reject);
59
59
  child.on('close', (code, signal) => {
60
- if (code !== 0) {
61
- const cmd = opts.prettyCommand
62
- ? `Command "${opts.prettyCommand}"`
63
- : 'Command';
64
- return reject(new errors_1.NowBuildError({
65
- code: `BUILD_UTILS_EXEC_${code || signal}`,
66
- message: `${cmd} exited with ${code || signal}`,
67
- }));
60
+ if (code === 0 || opts.ignoreNon0Exit) {
61
+ return resolve({
62
+ code,
63
+ stdout: Buffer.concat(stdoutList).toString(),
64
+ stderr: Buffer.concat(stderrList).toString(),
65
+ });
68
66
  }
69
- return resolve({
70
- code,
71
- stdout: Buffer.concat(stdoutList).toString(),
72
- stderr: Buffer.concat(stderrList).toString(),
73
- });
67
+ const cmd = opts.prettyCommand
68
+ ? `Command "${opts.prettyCommand}"`
69
+ : 'Command';
70
+ return reject(new errors_1.NowBuildError({
71
+ code: `BUILD_UTILS_EXEC_${code || signal}`,
72
+ message: `${cmd} exited with ${code || signal}`,
73
+ }));
74
74
  });
75
75
  });
76
76
  }
@@ -94,9 +94,22 @@ async function execCommand(command, options = {}) {
94
94
  return true;
95
95
  }
96
96
  exports.execCommand = execCommand;
97
- async function getNodeBinPath({ cwd }) {
98
- const { stdout } = await execAsync('npm', ['bin'], { cwd });
99
- return stdout.trim();
97
+ async function getNodeBinPath({ cwd, }) {
98
+ const { code, stdout, stderr } = await execAsync('npm', ['bin'], {
99
+ cwd,
100
+ prettyCommand: 'npm bin',
101
+ // in some rare cases, we saw `npm bin` exit with a non-0 code, but still
102
+ // output the right bin path, so we ignore the exit code
103
+ ignoreNon0Exit: true,
104
+ });
105
+ const nodeBinPath = stdout.trim();
106
+ if (path_1.default.isAbsolute(nodeBinPath)) {
107
+ return nodeBinPath;
108
+ }
109
+ throw new errors_1.NowBuildError({
110
+ code: `BUILD_UTILS_GET_NODE_BIN_PATH`,
111
+ message: `Running \`npm bin\` failed to return a valid bin path (code=${code}, stdout=${stdout}, stderr=${stderr})`,
112
+ });
100
113
  }
101
114
  exports.getNodeBinPath = getNodeBinPath;
102
115
  async function chmodPlusX(fsPath) {
package/dist/index.js CHANGED
@@ -35855,7 +35855,7 @@ function spawnAsync(command, args, opts = {}) {
35855
35855
  }
35856
35856
  child.on('error', reject);
35857
35857
  child.on('close', (code, signal) => {
35858
- if (code === 0) {
35858
+ if (code === 0 || opts.ignoreNon0Exit) {
35859
35859
  return resolve();
35860
35860
  }
35861
35861
  const cmd = opts.prettyCommand
@@ -35885,20 +35885,20 @@ function execAsync(command, args, opts = {}) {
35885
35885
  });
35886
35886
  child.on('error', reject);
35887
35887
  child.on('close', (code, signal) => {
35888
- if (code !== 0) {
35889
- const cmd = opts.prettyCommand
35890
- ? `Command "${opts.prettyCommand}"`
35891
- : 'Command';
35892
- return reject(new errors_1.NowBuildError({
35893
- code: `BUILD_UTILS_EXEC_${code || signal}`,
35894
- message: `${cmd} exited with ${code || signal}`,
35895
- }));
35888
+ if (code === 0 || opts.ignoreNon0Exit) {
35889
+ return resolve({
35890
+ code,
35891
+ stdout: Buffer.concat(stdoutList).toString(),
35892
+ stderr: Buffer.concat(stderrList).toString(),
35893
+ });
35896
35894
  }
35897
- return resolve({
35898
- code,
35899
- stdout: Buffer.concat(stdoutList).toString(),
35900
- stderr: Buffer.concat(stderrList).toString(),
35901
- });
35895
+ const cmd = opts.prettyCommand
35896
+ ? `Command "${opts.prettyCommand}"`
35897
+ : 'Command';
35898
+ return reject(new errors_1.NowBuildError({
35899
+ code: `BUILD_UTILS_EXEC_${code || signal}`,
35900
+ message: `${cmd} exited with ${code || signal}`,
35901
+ }));
35902
35902
  });
35903
35903
  });
35904
35904
  }
@@ -35922,9 +35922,22 @@ async function execCommand(command, options = {}) {
35922
35922
  return true;
35923
35923
  }
35924
35924
  exports.execCommand = execCommand;
35925
- async function getNodeBinPath({ cwd }) {
35926
- const { stdout } = await execAsync('npm', ['bin'], { cwd });
35927
- return stdout.trim();
35925
+ async function getNodeBinPath({ cwd, }) {
35926
+ const { code, stdout, stderr } = await execAsync('npm', ['bin'], {
35927
+ cwd,
35928
+ prettyCommand: 'npm bin',
35929
+ // in some rare cases, we saw `npm bin` exit with a non-0 code, but still
35930
+ // output the right bin path, so we ignore the exit code
35931
+ ignoreNon0Exit: true,
35932
+ });
35933
+ const nodeBinPath = stdout.trim();
35934
+ if (path_1.default.isAbsolute(nodeBinPath)) {
35935
+ return nodeBinPath;
35936
+ }
35937
+ throw new errors_1.NowBuildError({
35938
+ code: `BUILD_UTILS_GET_NODE_BIN_PATH`,
35939
+ message: `Running \`npm bin\` failed to return a valid bin path (code=${code}, stdout=${stdout}, stderr=${stderr})`,
35940
+ });
35928
35941
  }
35929
35942
  exports.getNodeBinPath = getNodeBinPath;
35930
35943
  async function chmodPlusX(fsPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -50,5 +50,5 @@
50
50
  "typescript": "4.3.4",
51
51
  "yazl": "2.5.1"
52
52
  },
53
- "gitHead": "eed39913e1394477b224c38efe29429b17eeada6"
53
+ "gitHead": "547e88228e180e883e5f07ab815a16960767bbf5"
54
54
  }