-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: using npm 9 with lockfileVersion 3
Fix for issue #99
- Loading branch information
Showing
6 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { getPackageFileDeps } from '@ic/helpers/get-package-file-deps'; | ||
|
||
describe(`get package.json file deps`, () => { | ||
const packageFileContent = { | ||
name: 'name', | ||
version: '1.2.3', | ||
dependencies: { | ||
'dep-a': '0.0.1', | ||
'dep-b': '^1.0.5', | ||
}, | ||
devDependencies: { | ||
'@dev/dep-a': '~2.0.0', | ||
'@dev/dep-b': '8.1.0', | ||
}, | ||
}; | ||
|
||
it('should return deps and devDeps', () => { | ||
const expectedDeps = ['@dev/dep-a', '@dev/dep-b', 'dep-a', 'dep-b']; | ||
expect(getPackageFileDeps(packageFileContent)).toEqual(expectedDeps); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { getLockFileVersion } from '@ic/helpers/get-lock-file-version'; | ||
import { getPackageLockFileDeps } from '@ic/helpers/get-package-lock-file-deps'; | ||
|
||
describe(`get package-lock.json file deps`, () => { | ||
it('should return deps with lockfileVersion < 3', () => { | ||
const packageLockFileContentVersion2 = JSON.parse(`{ | ||
"name": "lockfile version 2", | ||
"version": "1.2.3", | ||
"lockfileVersion": 2, | ||
"dependencies": { | ||
"dep-a": "0.0.1", | ||
"dep-b": "^1.0.5" | ||
} | ||
}`); | ||
const expectedDeps = ['dep-a', 'dep-b']; | ||
expect(getLockFileVersion(packageLockFileContentVersion2)).toBe(2); | ||
expect(getPackageLockFileDeps(packageLockFileContentVersion2)).toEqual(expectedDeps); | ||
}); | ||
|
||
it('should return deps with lockfileVersion = 3', () => { | ||
const packageLockFileContentVersion3 = JSON.parse(`{ | ||
"name": "lockfile version 3", | ||
"version": "1.2.3", | ||
"lockfileVersion": 3, | ||
"packages": { | ||
"": { | ||
"dependencies": { | ||
"dep-a": "0.0.1", | ||
"dep-b": "^1.0.5" | ||
} | ||
} | ||
} | ||
}`); | ||
const expectedDeps = ['dep-a', 'dep-b']; | ||
expect(getLockFileVersion(packageLockFileContentVersion3)).toBe(3); | ||
expect(getPackageLockFileDeps(packageLockFileContentVersion3)).toEqual(expectedDeps); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getLockFileVersion(packageLockContent: any) { | ||
return packageLockContent?.lockfileVersion ?? -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function getPackageFileDeps(packageContent: any): string[] { | ||
const { dependencies, devDependencies } = packageContent; | ||
return Object.keys(devDependencies).concat(Object.keys(dependencies)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { getLockFileVersion } from './get-lock-file-version'; | ||
|
||
export function getPackageLockFileDeps(packageLockContent: any): string[] { | ||
const lockFileVersion = getLockFileVersion(packageLockContent); | ||
if (lockFileVersion < 3) { | ||
return Object.keys(packageLockContent.dependencies); | ||
} | ||
return Object.keys(packageLockContent.packages[''].dependencies); | ||
} |