-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add lock file to external nodes mapper
- Loading branch information
Showing
7 changed files
with
263 additions
and
70 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
124 changes: 124 additions & 0 deletions
124
packages/nx/src/utils/lock-file/__snapshots__/lock-file.spec.ts.snap
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,124 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`lock-file mapLockFileDataToExternalNodes should map npm lock file data to external nodes 1`] = ` | ||
Object { | ||
"data": Object { | ||
"dependencies": Object { | ||
"cliui": Array [ | ||
"^7.0.2", | ||
"7.0.4", | ||
], | ||
"escalade": Array [ | ||
"^3.1.1", | ||
"3.1.1", | ||
], | ||
"get-caller-file": Array [ | ||
"^2.0.5", | ||
"2.0.5", | ||
], | ||
"require-directory": Array [ | ||
"^2.1.1", | ||
"2.1.1", | ||
], | ||
"string-width": Array [ | ||
"^4.2.3", | ||
"4.2.3", | ||
], | ||
"y18n": Array [ | ||
"^5.0.5", | ||
"5.0.8", | ||
], | ||
"yargs-parser": Array [ | ||
"^21.0.0", | ||
"21.0.1", | ||
], | ||
}, | ||
"packageName": "yargs", | ||
"version": "17.5.1", | ||
}, | ||
"name": "npm:yargs", | ||
"type": "npm", | ||
} | ||
`; | ||
|
||
exports[`lock-file mapLockFileDataToExternalNodes should map pnpm lock file data to external nodes 1`] = ` | ||
Object { | ||
"data": Object { | ||
"dependencies": Object { | ||
"cliui": Array [ | ||
"7.0.4", | ||
"7.0.4", | ||
], | ||
"escalade": Array [ | ||
"3.1.1", | ||
"3.1.1", | ||
], | ||
"get-caller-file": Array [ | ||
"2.0.5", | ||
"2.0.5", | ||
], | ||
"require-directory": Array [ | ||
"2.1.1", | ||
"2.1.1", | ||
], | ||
"string-width": Array [ | ||
"4.2.3", | ||
"4.2.3", | ||
], | ||
"y18n": Array [ | ||
"5.0.8", | ||
"5.0.8", | ||
], | ||
"yargs-parser": Array [ | ||
"21.1.1", | ||
"21.1.1", | ||
], | ||
}, | ||
"packageName": "yargs", | ||
"version": "17.5.1", | ||
}, | ||
"name": "npm:yargs", | ||
"type": "npm", | ||
} | ||
`; | ||
|
||
exports[`lock-file mapLockFileDataToExternalNodes should map yarn lock file data to external nodes 1`] = ` | ||
Object { | ||
"data": Object { | ||
"dependencies": Object { | ||
"cliui": Array [ | ||
"^7.0.2", | ||
"7.0.4", | ||
], | ||
"escalade": Array [ | ||
"^3.1.1", | ||
"3.1.1", | ||
], | ||
"get-caller-file": Array [ | ||
"^2.0.5", | ||
"2.0.5", | ||
], | ||
"require-directory": Array [ | ||
"^2.1.1", | ||
"2.1.1", | ||
], | ||
"string-width": Array [ | ||
"^4.2.3", | ||
"4.2.3", | ||
], | ||
"y18n": Array [ | ||
"^5.0.5", | ||
"5.0.8", | ||
], | ||
"yargs-parser": Array [ | ||
"^21.0.0", | ||
"21.1.1", | ||
], | ||
}, | ||
"packageName": "yargs", | ||
"version": "17.5.1", | ||
}, | ||
"name": "npm:yargs", | ||
"type": "npm", | ||
} | ||
`; |
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 |
---|---|---|
|
@@ -3,6 +3,11 @@ | |
exports[`pnpm LockFile utility lock file with inline specifiers should parse lockfile (IS) 1`] = ` | ||
Object { | ||
"@ampproject/[email protected]": Object { | ||
"dependencies": Object { | ||
"@jridgewell/gen-mapping": "0.1.1", | ||
"@jridgewell/trace-mapping": "0.3.15", | ||
}, | ||
"dev": true, | ||
"engines": Object { | ||
"node": ">=6.0.0", | ||
}, | ||
|
@@ -13,7 +18,6 @@ Object { | |
"@jridgewell/gen-mapping": "0.1.1", | ||
"@jridgewell/trace-mapping": "0.3.15", | ||
}, | ||
"dev": true, | ||
}, | ||
"isDependency": false, | ||
"isDevDependency": false, | ||
|
@@ -32,15 +36,14 @@ Object { | |
exports[`pnpm LockFile utility lock file with inline specifiers should parse lockfile (IS) 2`] = ` | ||
Object { | ||
"[email protected]": Object { | ||
"dev": true, | ||
"engines": Object { | ||
"node": ">=4.2.0", | ||
}, | ||
"hasBin": true, | ||
"packageMeta": Array [ | ||
Object { | ||
"dependencyDetails": Object { | ||
"dev": true, | ||
"hasBin": true, | ||
}, | ||
"dependencyDetails": Object {}, | ||
"isDependency": false, | ||
"isDevDependency": true, | ||
"key": "/typescript/4.8.3", | ||
|
@@ -58,6 +61,11 @@ Object { | |
exports[`pnpm LockFile utility standard lock file should parse lockfile correctly 1`] = ` | ||
Object { | ||
"@ampproject/[email protected]": Object { | ||
"dependencies": Object { | ||
"@jridgewell/gen-mapping": "0.1.1", | ||
"@jridgewell/trace-mapping": "0.3.15", | ||
}, | ||
"dev": true, | ||
"engines": Object { | ||
"node": ">=6.0.0", | ||
}, | ||
|
@@ -68,7 +76,6 @@ Object { | |
"@jridgewell/gen-mapping": "0.1.1", | ||
"@jridgewell/trace-mapping": "0.3.15", | ||
}, | ||
"dev": true, | ||
}, | ||
"isDependency": false, | ||
"isDevDependency": false, | ||
|
@@ -87,15 +94,14 @@ Object { | |
exports[`pnpm LockFile utility standard lock file should parse lockfile correctly 2`] = ` | ||
Object { | ||
"[email protected]": Object { | ||
"dev": true, | ||
"engines": Object { | ||
"node": ">=4.2.0", | ||
}, | ||
"hasBin": true, | ||
"packageMeta": Array [ | ||
Object { | ||
"dependencyDetails": Object { | ||
"dev": true, | ||
"hasBin": true, | ||
}, | ||
"dependencyDetails": Object {}, | ||
"isDependency": false, | ||
"isDevDependency": true, | ||
"key": "/typescript/4.8.3", | ||
|
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 |
---|---|---|
@@ -1,54 +1,40 @@ | ||
import { mapLockFileDataToExternalNodes } from './lock-file'; | ||
import { LockFileData } from './lock-file-type'; | ||
import { parseNpmLockFile } from './npm'; | ||
import { parsePnpmLockFile } from './pnpm'; | ||
import { parseYarnLockFile } from './yarn'; | ||
import { lockFileYargsOnly } from './__fixtures__/npm.lock'; | ||
import { lockFileYargsOnly as pnpmLockFileYargsOnly } from './__fixtures__/pnpm.lock'; | ||
import { lockFileDevkitAndYargs } from './__fixtures__/yarn.lock'; | ||
|
||
describe('lock-file', () => { | ||
describe('mapLockFileDataToExternalNodes', () => { | ||
it('should map lock file data to external nodes', () => { | ||
const lockFileData: LockFileData = { | ||
dependencies: { | ||
'happy-nrwl': { | ||
'[email protected]': { | ||
version: '1.0.0', | ||
resolved: | ||
'https://registry.npmjs.org/happy-nrwl/-/happy-nrwl-1.0.0.tgz', | ||
integrity: 'sha512-1', | ||
packageMeta: ['[email protected]'], | ||
}, | ||
}, | ||
'happy-nrwl2': { | ||
'happy-nrwl2@^1.0.0': { | ||
version: '1.2.0', | ||
resolved: | ||
'https://registry.npmjs.org/happy-nrwl2/-/happy-nrwl2-1.2.0.tgz', | ||
integrity: 'sha512-2', | ||
packageMeta: ['happy-nrwl@^1.0.0'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
const externalNodes = mapLockFileDataToExternalNodes(lockFileData); | ||
expect(externalNodes).toEqual({ | ||
'npm:happy-nrwl': { | ||
type: 'npm', | ||
name: 'npm:happy-nrwl', | ||
data: { | ||
version: '1.0.0', | ||
resolved: | ||
'https://registry.npmjs.org/happy-nrwl/-/happy-nrwl-1.0.0.tgz', | ||
integrity: 'sha512-1', | ||
}, | ||
}, | ||
'npm:happy-nrwl2': { | ||
type: 'npm', | ||
name: 'npm:happy-nrwl2', | ||
data: { | ||
version: '1.2.0', | ||
resolved: | ||
'https://registry.npmjs.org/happy-nrwl2/-/happy-nrwl2-1.2.0.tgz', | ||
integrity: 'sha512-2', | ||
}, | ||
}, | ||
}); | ||
it('should map yarn lock file data to external nodes', () => { | ||
const lockFileData = parseYarnLockFile(lockFileDevkitAndYargs); | ||
|
||
const mappedExernalNodes = mapLockFileDataToExternalNodes(lockFileData); | ||
|
||
expect(mappedExernalNodes['npm:yargs']).toMatchSnapshot(); | ||
}); | ||
|
||
it('should map npm lock file data to external nodes', () => { | ||
const lockFileData = parseNpmLockFile(lockFileYargsOnly); | ||
|
||
const mappedExernalNodes = mapLockFileDataToExternalNodes(lockFileData); | ||
|
||
expect(mappedExernalNodes['npm:yargs']).toMatchSnapshot(); | ||
}); | ||
|
||
it('should map pnpm lock file data to external nodes', () => { | ||
const lockFileData = parsePnpmLockFile(pnpmLockFileYargsOnly); | ||
|
||
const mappedExernalNodes = mapLockFileDataToExternalNodes(lockFileData); | ||
|
||
console.log(JSON.stringify(lockFileData.dependencies['yargs'], null, 2)); | ||
|
||
console.log(JSON.stringify(mappedExernalNodes['npm:yargs'], null, 2)); | ||
|
||
expect(mappedExernalNodes['npm:yargs']).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.