Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle missing latest tag during version check #90

Merged
merged 8 commits into from
May 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: fix suppressed error bug
  • Loading branch information
mcous committed May 1, 2023
commit 8e39a3612b13505a162a8ba3423f2a7b69808564
30 changes: 30 additions & 0 deletions src/compare-and-publish/__tests__/compare-and-publish.test.ts
Original file line number Diff line number Diff line change
@@ -222,4 +222,34 @@ describe("compareAndPublish", () => {
type: "major",
});
});

it("should raise if the retried npm view call fails", async () => {
td.when(getViewArguments("fizzbuzz", normalizedOptions, true)).thenReturn([
"fizzbuzz@cool-tag",
]);

td.when(
callNpmCli("view", ["fizzbuzz"], { logger, environment })
).thenResolve({
successData: undefined,
errorCode: undefined,
error: undefined,
});

td.when(
callNpmCli("view", ["fizzbuzz@cool-tag"], { logger, environment })
).thenResolve({
successData: undefined,
errorCode: "E500",
error: new errors.NpmCallError("view", 1, "oh no"),
});

const result = subject.compareAndPublish(
manifest,
normalizedOptions,
environment
);

await expect(result).rejects.toThrow(errors.NpmCallError);
});
});
8 changes: 4 additions & 4 deletions src/compare-and-publish/compare-and-publish.ts
Original file line number Diff line number Diff line change
@@ -41,10 +41,6 @@ export async function compareAndPublish(
const publishArguments = getPublishArguments(packageSpec, options);
let viewCall = await callNpmCli(VIEW, viewArguments, cliOptions);

if (viewCall.error && viewCall.errorCode !== E404) {
throw viewCall.error;
}

// `npm view` will succeed with no output the package exists in the registry
// with no `latest` tag. This is only possible with third-party registries.
// https://github.com/npm/cli/issues/6408
@@ -55,6 +51,10 @@ export async function compareAndPublish(
viewCall = await callNpmCli(VIEW, viewWithTagArguments, cliOptions);
}

if (viewCall.error && viewCall.errorCode !== E404) {
throw viewCall.error;
}

const comparison = compareVersions(version, viewCall.successData, options);
const publishCall = comparison.type
? await callNpmCli(PUBLISH, publishArguments, cliOptions)