Skip to content

Commit

Permalink
feat: sort duplicated deps by package name
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed Sep 11, 2023
1 parent 426cdfe commit 9fc0160
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default createUnplugin<Options | undefined>((options) => {
* }
* }
*/
const packageToVersionsMap = new Map<string, Map<string, Set<string>>>();
let packageToVersionsMap = new Map<string, Map<string, Set<string>>>();

const resolveId: RollupPlugin['resolveId'] = async function (source, importer, options) {
if (!importer || options.isEntry) return;
Expand Down Expand Up @@ -158,6 +158,10 @@ export default createUnplugin<Options | undefined>((options) => {

const buildEnd: RollupPlugin['buildEnd'] = async function () {
const duplicatedPackages: string[] = [];
// sort by package name
packageToVersionsMap = new Map(
[...packageToVersionsMap.entries()].sort((a, b) => (a[0] > b[0] ? 1 : -1)),
);
for (const [packageName, versionsMap] of packageToVersionsMap.entries()) {
if (versionsMap.size > 1) {
duplicatedPackages.push(packageName);
Expand Down

0 comments on commit 9fc0160

Please sign in to comment.