refactor(worker): remove ReturnType expression from worker.ts (#7889)

This commit is contained in:
Khải authored and GitHub committed 2024-04-10 14:55:22 +02:00
1 parent 6df750e834
commit 1cf763da04
2 files changed
+13 -4

No files matched your search

+9 -2
View File
@@ -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 {
+4 -2
View File
@@ -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<string, ReturnType<typeof createCafs>>()
const cafsStoreCache = new Map<string, ReturnType<typeof createCafsStore>>()
const cafsCache = new Map<string, CafsFunctions>()
const cafsStoreCache = new Map<string, Cafs>()
const cafsLocker = new Map<string, number>()
async function handleMessage (