Skip to content

Commit c42fcd8

Browse files
authored
Include pre-release versions to compute package diff (#1598)
Via #1593 (comment) The `npm install` command ignores pre-release versions. The only way to have it to install a pre-release version is to specify the version. To take pre-release versions into account when computing the diff with the latest published version, the code now first retrieves available versions through `npm view`.
1 parent a5de9b6 commit c42fcd8

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tools/prepare-release.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,33 @@ async function computeDiff(type) {
6767
const majorVersion = majorVersionMatch ? '@' + majorVersionMatch[1] : '';
6868

6969
// Install @webref package in tmp folder
70+
// If package is pinned to a major version, we'll use that one.
71+
// If not, what we want is to install the latest version of the package,
72+
// where "latest" includes pre-releases. The `npm install` command skips
73+
// pre-releases, so we need to retrieve the latest published version first
74+
// through a call to `npm view`.
7075
const tmpFolder = fs.mkdtempSync(path.join(os.tmpdir(), "webref-"));
76+
let versionToInstall = null;
77+
if (majorVersion) {
78+
versionToInstall = majorVersion;
79+
}
80+
else {
81+
try {
82+
const versionsStr = execSync(`npm view --json @webref/${packageName} versions`);
83+
const versions = JSON.parse(versionsStr);
84+
versionToInstall = versions.pop();
85+
}
86+
catch (err) {
87+
throw new MissingPackageError(`No version found for package @webref/${packageName}.`);
88+
}
89+
}
7190
try {
72-
execSync(`npm install @webref/${packageName}${majorVersion}`, {
91+
execSync(`npm install @webref/${packageName}${versionToInstall}`, {
7392
cwd: tmpFolder
7493
});
7594
}
7695
catch (err) {
77-
throw new MissingPackageError(`Package @webref/${packageName}${majorVersion} does not exist or could not be installed.`);
96+
throw new MissingPackageError(`Package @webref/${packageName}${versionToInstall} does not exist or could not be installed.`);
7897
}
7998

8099
// Extract released version (will be used in the body of the pre-release PR)

0 commit comments

Comments
 (0)