Skip to content

Commit

Permalink
fix: audit should work when the project's package.json has no version (
Browse files Browse the repository at this point in the history
  • Loading branch information
lvqq committed Dec 2, 2022
1 parent a9d59d8 commit dd83e59
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/flat-pets-repair.md
@@ -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)
2 changes: 1 addition & 1 deletion lockfile/audit/src/lockfileToAuditTree.ts
Expand Up @@ -40,7 +40,7 @@ export async function lockfileToAuditTree (
dependencies[depName] = {
dependencies: importerDeps,
requires: toRequires(importerDeps),
version: manifest.version,
version: manifest.version ?? '0.0.0',
}
})
)
Expand Down
@@ -0,0 +1,3 @@
{
"name": "pkg"
}
66 changes: 66 additions & 0 deletions lockfile/audit/test/index.ts
Expand Up @@ -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
Expand Down

0 comments on commit dd83e59

Please sign in to comment.