Skip to content

Commit

Permalink
Merge branch 'main' into cli_improvments
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/snapshots/cli.js.snap
#	tests/snapshots/deps.js.snap
  • Loading branch information
fisker committed Mar 4, 2025
2 parents 10adfca + 24d9da5 commit c8ba931
Show file tree
Hide file tree
Showing 9 changed files with 7,486 additions and 7,383 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
/.nyc_output
/cjs
/coverage
/index.cjs
/coverage
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export default [
globals: { ...globals.builtin, ...globals.node },
},
},
{ ignores: ['cjs'] },
{ ignores: ['index.cjs'] },
]
20 changes: 7 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,17 @@ const sortObjectBySemver = sortObjectBy((a, b) => {
})

const getPackageName = (ident) => {
const parts = ident.split('@')

if (ident.startsWith('@')) {
// Handle cases where package name starts with '@'
return parts.length > 2 ? parts.slice(0, -1).join('@') : ident
}

// Handle cases where package name doesn't start with '@'
return parts.length > 1 ? parts.slice(0, -1).join('@') : ident
const index = ident.indexOf('@', ident.startsWith('@') ? 1 : 0)
// This should not happen, unless user manually edit the package.json file
return index === -1 ? ident : ident.slice(0, index)
}

const sortObjectByIdent = (a, b) => {
const PackageNameA = getPackageName(a)
const PackageNameB = getPackageName(b)
const packageNameA = getPackageName(a)
const packageNameB = getPackageName(b)

if (PackageNameA < PackageNameB) return -1
if (PackageNameA > PackageNameB) return 1
if (packageNameA < packageNameB) return -1
if (packageNameA > packageNameB) return 1
return 0
}

Expand Down
Loading

0 comments on commit c8ba931

Please sign in to comment.