fix: audit should work when the project's package.json has no version (#5731)

close #5728
This commit is contained in:
chlorine
2022-12-03 06:38:55 +08:00
committed by GitHub
parent a9d59d8bc2
commit dd83e5974b
4 changed files with 75 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/audit": patch
---
`pnpm audit` should work when the project's `package.json` has no `version` field [#5728](https://github.com/pnpm/pnpm/issues/5728)

View File

@@ -40,7 +40,7 @@ export async function lockfileToAuditTree (
dependencies[depName] = {
dependencies: importerDeps,
requires: toRequires(importerDeps),
version: manifest.version,
version: manifest.version ?? '0.0.0',
}
})
)

View File

@@ -0,0 +1,3 @@
{
"name": "pkg"
}

View File

@@ -74,6 +74,72 @@ describe('audit', () => {
})
})
test('lockfileToAuditTree() without specified version should use default version 0.0.0', async () => {
expect(await lockfileToAuditTree({
importers: {
'.': {
dependencies: {
foo: '1.0.0',
},
specifiers: {
foo: '^1.0.0',
},
},
},
lockfileVersion: LOCKFILE_VERSION,
packages: {
'/bar/1.0.0': {
resolution: {
integrity: 'bar-integrity',
},
},
'/foo/1.0.0': {
dependencies: {
bar: '1.0.0',
},
resolution: {
integrity: 'foo-integrity',
},
},
},
}, { lockfileDir: f.find('project-without-version') })).toEqual({
name: undefined,
version: undefined,
dependencies: {
'.': {
dependencies: {
foo: {
dependencies: {
bar: {
dev: false,
integrity: 'bar-integrity',
version: '1.0.0',
},
},
dev: false,
integrity: 'foo-integrity',
requires: {
bar: '1.0.0',
},
version: '1.0.0',
},
},
requires: {
foo: '1.0.0',
},
version: '0.0.0',
},
},
dev: false,
install: [],
integrity: undefined,
metadata: {},
remove: [],
requires: { '.': '0.0.0' },
})
})
test('an error is thrown if the audit endpoint responds with a non-OK code', async () => {
const registry = 'http://registry.registry/'
const getAuthHeader = () => undefined