Skip to content

Commit b5b7a3f

Browse files
Merge pull request #19 from ZitRos/master
Fix initial package publishing, once again
2 parents 8f98748 + 0b85b91 commit b5b7a3f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/npm.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,26 @@ export const npm = {
3737

3838
// Run NPM to get the latest published version of the package
3939
options.debug(`Running command: npm view ${name} version`, { command, env });
40-
let { stdout, stderr } = await ezSpawn.async(command, { env });
40+
let result: ezSpawn.Process<string>|Error;
41+
try {
42+
result = await ezSpawn.async(command, { env });
43+
}
44+
catch (e) {
45+
result = e as Error;
46+
}
47+
// In case ezSpawn.async throws, it still has stdout and stderr properties.
48+
const { stdout, stderr } = result as ezSpawn.Process<string>;
4149

4250
// If the package was not previously published, return version 0.0.0.
4351
if (stderr && stderr.includes("E404")) {
4452
options.debug(`The latest version of ${name} is at v0.0.0, as it was never published.`);
4553
return new SemVer("0.0.0");
4654
}
55+
else if (stderr) {
56+
// Rethrow an error. See https://github.com/JS-DevTools/npm-publish/issues/14 for more details.
57+
const error = result as Error;
58+
throw error;
59+
}
4760

4861
let version = stdout.trim();
4962

test/specs/cli/success.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ describe("CLI - success tests", () => {
6363
npm.mock({
6464
args: ["view", "my-lib", "version"],
6565
stdout: `${EOL}`,
66-
stderr: `npm ERR! code E404${EOL}`
66+
stderr: `npm ERR! code E404${EOL}`,
67+
exitCode: 1,
6768
});
6869

6970
npm.mock({

0 commit comments

Comments
 (0)