mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-07 14:38:32 -05:00
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:
7
.changeset/three-moles-end.md
Normal file
7
.changeset/three-moles-end.md
Normal 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.
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!())
|
||||
|
||||
@@ -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++
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user