Skip to content

Commit bb0c487

Browse files
committed
feat: support {packageManager: 'npm@...'} and {packageManager:{name: '...'}}
1 parent 129a63a commit bb0c487

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ const hasYarnOrPnpmFiles = () => {
141141
*/
142142
function shouldSortDependenciesLikeNpm(packageJson) {
143143
const packageManager = packageJson.packageManager
144-
if (
145-
packageJson.pnpm ||
146-
(typeof packageManager === 'string' &&
147-
(packageManager.startsWith('yarn@') ||
148-
packageManager.startsWith('pnpm@')))
149-
) {
144+
if (packageManager) {
145+
if (typeof packageManager === 'string') {
146+
return packageManager.startsWith('npm@')
147+
}
148+
149+
return packageManager.name === 'npm'
150+
}
151+
152+
if (packageJson.pnpm) {
150153
return false
151154
}
152155

tests/dependency-sorting.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ test('npm', (t) => {
5454
npmSortedResult,
5555
)
5656

57+
// packageManager
58+
t.deepEqual(
59+
getDependencyOrders({ packageManager: 'npm@1.0.0' }, () => {
60+
t.fail()
61+
}),
62+
npmSortedResult,
63+
)
64+
t.deepEqual(
65+
getDependencyOrders({ packageManager: { name: 'npm' } }, () => {
66+
t.fail()
67+
}),
68+
npmSortedResult,
69+
)
70+
5771
// Should not call `fs.existsSync()`
5872
getDependencyOrders({ dependencies: { 'one-dependency': '1.0.0' } }, () => {
5973
t.fail()
@@ -85,6 +99,12 @@ test('pnpm', (t) => {
8599
}),
86100
nonNpmSortedResult,
87101
)
102+
t.deepEqual(
103+
getDependencyOrders({ packageManager: { name: 'pnpm' } }, () => {
104+
t.fail()
105+
}),
106+
nonNpmSortedResult,
107+
)
88108

89109
// pnpm file exists
90110
let fsExistsSyncCalled
@@ -106,6 +126,12 @@ test('yarn', (t) => {
106126
}),
107127
nonNpmSortedResult,
108128
)
129+
t.deepEqual(
130+
getDependencyOrders({ packageManager: { name: 'yarn' } }, () => {
131+
t.fail()
132+
}),
133+
nonNpmSortedResult,
134+
)
109135

110136
// yarn file exists
111137
let fsExistsSyncCalled

0 commit comments

Comments
 (0)