diff --git a/.changeset/plain-streets-flash.md b/.changeset/plain-streets-flash.md new file mode 100644 index 0000000000..3a3b439139 --- /dev/null +++ b/.changeset/plain-streets-flash.md @@ -0,0 +1,6 @@ +--- +"@pnpm/lockfile.fs": patch +"pnpm": patch +--- + +Fixed the `time` field in `pnpm-lock.yaml` being entirely wiped on every install. An incorrect dependency path format was used when matching entries to prune, causing all entries to always be removed. diff --git a/lockfile/fs/src/lockfileFormatConverters.ts b/lockfile/fs/src/lockfileFormatConverters.ts index c2315b4603..e0a2668135 100644 --- a/lockfile/fs/src/lockfileFormatConverters.ts +++ b/lockfile/fs/src/lockfileFormatConverters.ts @@ -1,5 +1,5 @@ import { LOCKFILE_VERSION } from '@pnpm/constants' -import { removeSuffix } from '@pnpm/dependency-path' +import { refToRelative, removeSuffix } from '@pnpm/dependency-path' import type { LockfileFile, LockfileFileProjectResolvedDependencies, @@ -124,22 +124,6 @@ function pruneTimeInLockfile (time: Record, importers: Record rootDepPaths.has(depPath), time) } -function refToRelative ( - reference: string, - pkgName: string -): string | null { - if (reference.startsWith('link:')) { - return null - } - if (reference.startsWith('file:')) { - return reference - } - if (!reference.includes('/') || !reference.replace(/(?:\([^)]+\))+$/, '').includes('/')) { - return `/${pkgName}@${reference}` - } - return reference -} - export function convertToLockfileObject (lockfile: LockfileFile): LockfileObject { const { importers, ...rest } = lockfile diff --git a/lockfile/fs/test/normalizeLockfile.test.ts b/lockfile/fs/test/normalizeLockfile.test.ts index 463858aa35..bf7106f38e 100644 --- a/lockfile/fs/test/normalizeLockfile.test.ts +++ b/lockfile/fs/test/normalizeLockfile.test.ts @@ -57,10 +57,10 @@ test('redundant fields are removed from "time"', () => { }, }, time: { - '/bar@1.0.0': '2021-02-11T22:54:29.120Z', - '/foo@1.0.0': '2021-02-11T22:54:29.120Z', - '/qar@1.0.0': '2021-02-11T22:54:29.120Z', - '/zoo@1.0.0': '2021-02-11T22:54:29.120Z', + 'bar@1.0.0': '2021-02-11T22:54:29.120Z', + 'foo@1.0.0': '2021-02-11T22:54:29.120Z', + 'qar@1.0.0': '2021-02-11T22:54:29.120Z', + 'zoo@1.0.0': '2021-02-11T22:54:29.120Z', }, })).toStrictEqual({ lockfileVersion: LOCKFILE_VERSION, @@ -87,9 +87,9 @@ test('redundant fields are removed from "time"', () => { }, }, time: { - '/bar@1.0.0': '2021-02-11T22:54:29.120Z', - '/foo@1.0.0': '2021-02-11T22:54:29.120Z', - '/qar@1.0.0': '2021-02-11T22:54:29.120Z', + 'bar@1.0.0': '2021-02-11T22:54:29.120Z', + 'foo@1.0.0': '2021-02-11T22:54:29.120Z', + 'qar@1.0.0': '2021-02-11T22:54:29.120Z', }, }) })