diff --git a/store/cafs/src/index.ts b/store/cafs/src/index.ts index 1d737119dc..3ddf54b552 100644 --- a/store/cafs/src/index.ts +++ b/store/cafs/src/index.ts @@ -1,4 +1,4 @@ -import { type FileWriteResult, type PackageFileInfo, type FilesIndex } from '@pnpm/cafs-types' +import { type AddToStoreResult, type FileWriteResult, type PackageFileInfo, type FilesIndex } from '@pnpm/cafs-types' import ssri from 'ssri' import { addFilesFromDir } from './addFilesFromDir' import { addFilesFromTarball } from './addFilesFromTarball' @@ -41,7 +41,14 @@ export interface CreateCafsOpts { cafsLocker?: CafsLocker } -export function createCafs (cafsDir: string, { ignoreFile, cafsLocker }: CreateCafsOpts = {}) { +export interface CafsFunctions { + addFilesFromDir: (dirname: string, opts?: { files?: string[], readManifest?: boolean }) => AddToStoreResult + addFilesFromTarball: (tarballBuffer: Buffer, readManifest?: boolean) => AddToStoreResult + getFilePathInCafs: (integrity: string | ssri.IntegrityLike, fileType: FileType) => string + getFilePathByModeInCafs: (integrity: string | ssri.IntegrityLike, mode: number) => string +} + +export function createCafs (cafsDir: string, { ignoreFile, cafsLocker }: CreateCafsOpts = {}): CafsFunctions { const _writeBufferToCafs = writeBufferToCafs.bind(null, cafsLocker ?? new Map(), cafsDir) const addBuffer = addBufferToCafs.bind(null, _writeBufferToCafs) return { diff --git a/worker/src/worker.ts b/worker/src/worker.ts index 91eb76cecd..298c7adac8 100644 --- a/worker/src/worker.ts +++ b/worker/src/worker.ts @@ -2,10 +2,12 @@ import path from 'path' import fs from 'fs' import gfs from '@pnpm/graceful-fs' import * as crypto from 'crypto' +import { type Cafs } from '@pnpm/cafs-types' import { createCafsStore } from '@pnpm/create-cafs-store' import { pkgRequiresBuild } from '@pnpm/exec.pkg-requires-build' import { hardLinkDir } from '@pnpm/fs.hard-link-dir' import { + type CafsFunctions, checkPkgFilesIntegrity, createCafs, type PackageFileInfo, @@ -33,8 +35,8 @@ const INTEGRITY_REGEX: RegExp = /^([^-]+)-([A-Za-z0-9+/=]+)$/ parentPort!.on('message', handleMessage) -const cafsCache = new Map>() -const cafsStoreCache = new Map>() +const cafsCache = new Map() +const cafsStoreCache = new Map() const cafsLocker = new Map() async function handleMessage (