fix: don't fail when publishedBy date cannot be calculated

This commit is contained in:
Zoltan Kochan
2022-09-02 23:38:13 +03:00
parent 6bc9caf8d5
commit 829b4d9248
3 changed files with 14 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
Don't fail when publishedBy date cannot be calculated.

View File

@@ -42,3 +42,8 @@ test('the lowest version of a direct dependency is installed when resolution mod
'@pnpm.e2e/foo': '^100.1.0',
})
})
test('time-based resolution mode should not fail when publishedBy date cannot be calculated', async () => {
prepareEmpty()
await install({}, await testDefaults({ resolutionMode: 'time-based' }))
})

View File

@@ -355,8 +355,10 @@ async function resolveDependenciesOfImporters (
let time: Record<string, string> | undefined
if (ctx.resolutionMode === 'time-based') {
const result = getPublishedByDate(resolveResults.map(({ pkgAddresses }) => pkgAddresses).flat(), ctx.wantedLockfile.time)
publishedBy = new Date(result.publishedBy.getTime() + 60 * 60 * 1000) // adding 1 hour delta
time = result.newTime
if (result.publishedBy) {
publishedBy = new Date(result.publishedBy.getTime() + 60 * 60 * 1000) // adding 1 hour delta
time = result.newTime
}
}
const pkgAddressesByImportersWithoutPeers = await Promise.all(zipWith(async (importer, { pkgAddresses, postponedResolutionsQueue }) => {
const newPreferredVersions = { ...importer.preferredVersions }