Skip to content

Commit

Permalink
fix: sort aliases to ensure priority is given to more specific aliases (
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored and WinterYukky committed Nov 1, 2022
1 parent cb72ab7 commit 2aa2638
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ export function readPackageJson (
}
}

export function resolveAliases (aliases: Record<string, string>) {
export function resolveAliases (_aliases: Record<string, string>) {
// Sort aliases from specific to general (ie. fs/promises before fs)
const aliases = Object.fromEntries(Object.entries(_aliases).sort(([a], [b]) =>
(b.split('/').length - a.split('/').length) || (b.length - a.length)
))
// Resolve alias values in relation to each other
for (const key in aliases) {
for (const alias in aliases) {
if (!['~', '@', '#'].includes(alias[0])) { continue }
Expand Down

0 comments on commit 2aa2638

Please sign in to comment.