Skip to content

Commit 71b286b

Browse files
committed
Expose dist-tags when fetching package information.
This allows the user to identify the #latest release, instead of the program assuming that it is the most recent in the list of versions.
1 parent e641f7f commit 71b286b

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

src/wizards/upgrade.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,38 @@ module.exports = async ({
8181
}
8282
]);
8383

84-
const npmVersions = await runCommand(
85-
`npm info ${targetDependency} versions --json`,
84+
const npmPackageInfoRaw = await runCommand(
85+
`npm info ${targetDependency} versions dist-tags --json`,
8686
{
8787
startMessage: `Fetching package information for "${targetDependency}"`,
8888
logOutput: false
8989
}
9090
);
9191

92-
const npmVersionsParsed = JSON.parse(npmVersions)
93-
.map(version => ({ name: version }))
94-
.reverse();
92+
const npmPackageInfo = JSON.parse(npmPackageInfoRaw);
93+
const npmVersions = npmPackageInfo.versions.reverse();
94+
const npmDistTags = npmPackageInfo["dist-tags"];
9595

9696
const highestInstalled = dependencyMap[targetDependency].versions
9797
.sort(semverCompare)
9898
.pop();
9999

100-
const { name: highestPublished } = npmVersionsParsed.shift();
101-
102100
const availableVersions = [
101+
...Object.entries(npmDistTags).map(([tag, version]) => ({
102+
name: `${version} ${chalk.bold(`#${tag}`)}`,
103+
value: version
104+
})),
103105
{
104-
name: `${chalk.white("Highest published version")} ${chalk.grey(
105-
`(${highestPublished})`
106-
)}`,
107-
value: highestPublished
108-
},
109-
{
110-
name: `${chalk.white("Highest installed version")} ${chalk.grey(
111-
`(${highestInstalled})`
112-
)}`,
106+
name: `${highestInstalled} ${chalk.bold("Highest installed")}`,
113107
value: highestInstalled
114108
},
115-
...npmVersionsParsed
109+
...npmVersions
110+
.filter(
111+
version =>
112+
version !== highestInstalled &&
113+
!Object.values(npmDistTags).includes(version)
114+
)
115+
.map(version => ({ name: version }))
116116
];
117117

118118
const { targetVersion } = await inquirer.prompt([

0 commit comments

Comments
 (0)