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 version check for cases where no version with a certain tag was published #25

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
Empty output of npm version means no version was published.
Closes #24
  • Loading branch information
RubenVerborgh committed Dec 7, 2020
commit 38b9715ff3ebd93a04d230f30b22db0e19ebf0cf
22 changes: 8 additions & 14 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

26 changes: 9 additions & 17 deletions src/npm.ts
Original file line number Diff line number Diff line change
@@ -20,41 +20,33 @@ export const npm = {
// Update the NPM config with the specified registry and token
await setNpmConfig(options);

try {
let command = ["npm", "view"];

if (options.tag === "latest") {
command.push(name);
}
else {
command.push(`${name}@${options.tag}`);
}
let taggedName = options.tag === "latest" ? name : `${name}@${options.tag}`;

command.push("version");
try {
let command = ["npm", "view", taggedName, "version"];

// Get the environment variables to pass to NPM
let env = getNpmEnvironment(options);

// Run NPM to get the latest published version of the package
options.debug(`Running command: npm view ${name} version`, { command, env });
options.debug(`Running command: ${command.join(" ")}`, { command, env });
let { stdout, stderr } = await ezSpawn.async(command, { env });
let version = stdout.trim();

// If the package was not previously published, return version 0.0.0.
if (stderr && stderr.includes("E404")) {
options.debug(`The latest version of ${name} is at v0.0.0, as it was never published.`);
if (stderr && stderr.includes("E404") || !version) {
options.debug(`The latest version of ${taggedName} is at v0.0.0, as it was never published.`);
return new SemVer("0.0.0");
}

let version = stdout.trim();

// Parse/validate the version number
let semver = new SemVer(version);

options.debug(`The latest version of ${name} is at v${semver}`);
options.debug(`The latest version of ${taggedName} is at v${semver}`);
return semver;
}
catch (error) {
throw ono(error, `Unable to determine the current version of ${name} on NPM.`);
throw ono(error, `Unable to determine the current version of ${taggedName} on NPM.`);
}
},