feat!: make the package index file more extendable

Move all the info in the package index file into a "files" property.
This will allow to store more information without breaking changes
in the future.

PR #2541
This commit is contained in:
Zoltan Kochan
2020-05-10 12:02:13 +03:00
committed by GitHub
parent ab662e604f
commit 471149e669
7 changed files with 21 additions and 13 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/cafs": major
"@pnpm/package-requester": major
"@pnpm/plugin-commands-store": major
---
Change the format of the package index file. Move all the files info into a "files" property.

View File

@@ -15,11 +15,11 @@ export type PackageFileInfo = {
size: number,
}
export type PackageFilesIndex = Record<string, PackageFileInfo>
export type PackageFilesIndex = { files: Record<string, PackageFileInfo> }
export default async function (
cafsDir: string,
pkgIndex: PackageFilesIndex,
pkgIndex: Record<string, PackageFileInfo>,
manifest?: DeferredManifestPromise,
) {
let verified = true

View File

@@ -3,6 +3,7 @@ import createCafs, {
FileType,
getFilePathByModeInCafs as _getFilePathByModeInCafs,
getFilePathInCafs as _getFilePathInCafs,
PackageFileInfo,
PackageFilesIndex,
} from '@pnpm/cafs'
import { fetchingProgressLogger } from '@pnpm/core-loggers'
@@ -255,7 +256,7 @@ type FetchLock = {
function fetchToStore (
ctx: {
checkFilesIntegrity: (
pkgIndex: PackageFilesIndex,
pkgIndex: Record<string, PackageFileInfo>,
manifest?: DeferredManifestPromise,
) => Promise<boolean>,
fetch: (
@@ -396,14 +397,14 @@ function fetchToStore (
}
// if target exists and it wasn't modified, then no need to refetch it
if (pkgFilesIndex) {
if (pkgFilesIndex && pkgFilesIndex.files) {
const manifest = opts.fetchRawManifest
? safeDeferredPromise<DependencyManifest>()
: undefined
const verified = await ctx.checkFilesIntegrity(pkgFilesIndex, manifest)
const verified = await ctx.checkFilesIntegrity(pkgFilesIndex.files, manifest)
if (verified) {
files.resolve({
filesIndex: pkgFilesIndex,
filesIndex: pkgFilesIndex.files,
fromStore: true,
})
if (manifest) {
@@ -480,7 +481,7 @@ function fetchToStore (
}
}),
)
await writeJsonFile(pkgIndexFilePath, integrity)
await writeJsonFile(pkgIndexFilePath, { files: integrity }, { indent: undefined })
finishing.resolve(undefined)
if (isLocalTarballDep && opts.resolution['integrity']) { // tslint:disable-line:no-string-literal

View File

@@ -349,8 +349,8 @@ test('refetch local tarball if its integrity has changed. The requester does not
files: () => Promise<PackageFilesResponse>,
finishing: () => Promise<void>,
}
await response.files
await response.finishing
await response.files()
await response.finishing()
t.ok((await response.files!()).fromStore, 'do not reunpack tarball if its integrity is up-to-date')
t.ok(await response.bundledManifest!())

View File

@@ -36,7 +36,7 @@ export default async function prune (storeDir: string) {
let pkgCounter = 0
for (const pkgIndexFilePath of pkgIndexFiles) {
const pkgFilesIndex = await loadJsonFile<object>(pkgIndexFilePath)
const { files: pkgFilesIndex } = await loadJsonFile<{ files: object }>(pkgIndexFilePath)
if (removedHashes.has(pkgFilesIndex['package.json'].integrity)) {
await fs.unlink(pkgIndexFilePath)
pkgCounter++

View File

@@ -46,8 +46,8 @@ export default async function (maybeOpts: StoreStatusOptions) {
const pkgIndexFilePath = integrity
? getFilePathInCafs(cafsDir, integrity, 'index')
: path.join(storeDir, pkgPath, 'integrity.json')
const pkgIndex = await loadJsonFile(pkgIndexFilePath)
return (await dint.check(path.join(virtualStoreDir, pkgIdToFilename(pkgPath, opts.dir), 'node_modules', name), pkgIndex)) === false
const { files } = await loadJsonFile(pkgIndexFilePath)
return (await dint.check(path.join(virtualStoreDir, pkgIdToFilename(pkgPath, opts.dir), 'node_modules', name), files)) === false
})
if (reporter) {

View File

@@ -160,7 +160,7 @@ test("don't fail on case insensitive filesystems when package has 2 files with s
await project.has('with-same-file-in-different-cases')
const integrityFile = await loadJsonFile(await project.getPkgIndexFilePath('with-same-file-in-different-cases', '1.0.0'))
const { files: integrityFile } = await loadJsonFile(await project.getPkgIndexFilePath('with-same-file-in-different-cases', '1.0.0'))
const packageFiles = Object.keys(integrityFile).sort()
t.deepEqual(packageFiles, ['Foo.js', 'foo.js', 'package.json'])