feat: extend cafs object (#5186)

* feat: extend cafs object

* fixup: fix test

* fixup: fix name

* fixup: add changeset
This commit is contained in:
Dominic Elm
2022-08-10 11:05:02 +02:00
committed by GitHub
parent 2b2d93028e
commit 32915f0e43
38 changed files with 255 additions and 85 deletions

View File

@@ -0,0 +1,12 @@
---
"@pnpm/cafs-types": major
"@pnpm/cafs": minor
"@pnpm/create-cafs-store": minor
"@pnpm/fetcher-base": patch
"@pnpm/node.fetcher": patch
"@pnpm/package-requester": patch
"@pnpm/store-controller-types": patch
"@pnpm/tarball-fetcher": patch
---
Refactor cafs types into separate package and add additional properties including `cafsDir` and `getFilePathInCafs`.

View File

@@ -0,0 +1,28 @@
# @pnpm/cafs-types
> Types for the cafs
<!--@shields('npm')-->
[![npm version](https://img.shields.io/npm/v/@pnpm/types.svg)](https://www.npmjs.com/package/@pnpm/types)
<!--/@-->
## Installation
```sh
pnpm add @pnpm/types
```
## Usage
```ts
import { PackageManifest } from '@pnpm/types'
const pkg: PackageManifest = {
name: 'foo',
version: '1.0.0',
}
```
## License
MIT

View File

@@ -0,0 +1,40 @@
{
"name": "@pnpm/cafs-types",
"version": "0.0.0",
"description": "Types for the cafs",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"engines": {
"node": ">=14.6"
},
"files": [
"lib",
"!*.map"
],
"scripts": {
"test": "pnpm run compile",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix",
"lint": "eslint src/**/*.ts"
},
"repository": "https://github.com/pnpm/pnpm/blob/main/packages/cafs-types",
"keywords": [
"pnpm7",
"pnpm",
"types"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/pnpm/issues"
},
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/types": "workspace:*",
"@types/ssri": "^7.1.1"
},
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/cafs-types#readme",
"funding": "https://opencollective.com/pnpm",
"exports": {
".": "./lib/index.js"
}
}

View File

@@ -0,0 +1,62 @@
import type { IntegrityLike } from 'ssri'
import type { DependencyManifest } from '@pnpm/types'
export interface DeferredManifestPromise {
resolve: (manifest: DependencyManifest | undefined) => void
reject: (err: Error) => void
}
export interface PackageFileInfo {
checkedAt?: number // Nullable for backward compatibility
integrity: string
mode: number
size: number
}
export type PackageFilesResponse = {
fromStore: boolean
packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone' | 'clone-or-copy'
sideEffects?: Record<string, Record<string, PackageFileInfo>>
} & ({
local: true
filesIndex: Record<string, string>
} | {
local?: false
filesIndex: Record<string, PackageFileInfo>
})
export interface ImportPackageOpts {
requiresBuild?: boolean
sideEffectsCacheKey?: string
filesResponse: PackageFilesResponse
force: boolean
}
export type ImportPackageFunction = (
to: string,
opts: ImportPackageOpts
) => Promise<{ isBuilt: boolean, importMethod: undefined | string }>
export type FileType = 'exec' | 'nonexec' | 'index'
export interface FilesIndex {
[filename: string]: {
mode: number
size: number
writeResult: Promise<FileWriteResult>
}
}
export interface FileWriteResult {
checkedAt: number
integrity: IntegrityLike
}
export interface Cafs {
cafsDir: string
addFilesFromDir: (dir: string, manifest?: DeferredManifestPromise) => Promise<FilesIndex>
addFilesFromTarball: (stream: NodeJS.ReadableStream, manifest?: DeferredManifestPromise) => Promise<FilesIndex>
getFilePathInCafs: (integrity: string | IntegrityLike, fileType: FileType) => string
importPackage: ImportPackageFunction
tempDir: () => Promise<string>
}

View File

@@ -0,0 +1,16 @@
{
"extends": "@pnpm/tsconfig",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": [
"src/**/*.ts",
"../../typings/**/*.d.ts"
],
"references": [
{
"path": "../types"
}
]
}

View File

@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"test/**/*.ts",
"../../typings/**/*.d.ts"
]
}

View File

@@ -32,6 +32,7 @@
},
"devDependencies": {
"@pnpm/cafs": "workspace:*",
"@pnpm/cafs-types": "workspace:*",
"@pnpm/types": "workspace:*",
"@types/concat-stream": "^2.0.0",
"@types/node": "^14.18.22",

View File

@@ -1,10 +1,10 @@
import { promises as fs } from 'fs'
import path from 'path'
import {
import type {
DeferredManifestPromise,
FilesIndex,
FileWriteResult,
} from '@pnpm/fetcher-base'
} from '@pnpm/cafs-types'
import gfs from '@pnpm/graceful-fs'
import pLimit from 'p-limit'
import { parseJsonBuffer } from './parseJson'

View File

@@ -1,5 +1,5 @@
import { Duplex, PassThrough } from 'stream'
import { DeferredManifestPromise, FilesIndex, FileWriteResult } from '@pnpm/fetcher-base'
import type { DeferredManifestPromise, FilesIndex, FileWriteResult } from '@pnpm/cafs-types'
import decompress from 'decompress-maybe'
import tar from 'tar-stream'
import { parseJsonStream } from './parseJson'

View File

@@ -1,5 +1,5 @@
import { promises as fs } from 'fs'
import { DeferredManifestPromise, PackageFileInfo } from '@pnpm/fetcher-base'
import type { DeferredManifestPromise, PackageFileInfo } from '@pnpm/cafs-types'
import gfs from '@pnpm/graceful-fs'
import rimraf from '@zkochan/rimraf'
import pLimit from 'p-limit'

View File

@@ -1,6 +1,6 @@
import { promises as fs, Stats } from 'fs'
import path from 'path'
import { FileWriteResult, PackageFileInfo } from '@pnpm/fetcher-base'
import type { FileWriteResult, PackageFileInfo } from '@pnpm/cafs-types'
import getStream from 'get-stream'
import pathTemp from 'path-temp'
import renameOverwrite from 'rename-overwrite'
@@ -20,6 +20,8 @@ import getFilePathInCafs, {
} from './getFilePathInCafs'
import writeFile from './writeFile'
export { IntegrityLike } from 'ssri'
export {
checkFilesIntegrity,
readManifestFromStore,
@@ -38,6 +40,7 @@ export default function createCafs (cafsDir: string, ignore?: ((filename: string
return {
addFilesFromDir: addFilesFromDir.bind(null, { addBuffer, addStream }),
addFilesFromTarball: addFilesFromTarball.bind(null, addStream, ignore ?? null),
getFilePathInCafs: getFilePathInCafs.bind(null, cafsDir),
}
}

View File

@@ -1,5 +1,5 @@
import { PassThrough } from 'stream'
import { DeferredManifestPromise } from '@pnpm/fetcher-base'
import type { DeferredManifestPromise } from '@pnpm/cafs-types'
import concatStream from 'concat-stream'
import stripBom from 'strip-bom'

View File

@@ -1,4 +1,4 @@
import { DeferredManifestPromise, PackageFileInfo } from '@pnpm/fetcher-base'
import type { DeferredManifestPromise, PackageFileInfo } from '@pnpm/cafs-types'
import gfs from '@pnpm/graceful-fs'
import { getFilePathByModeInCafs } from './getFilePathInCafs'
import { parseJsonBuffer } from './parseJson'

View File

@@ -9,6 +9,9 @@
"../../typings/**/*.d.ts"
],
"references": [
{
"path": "../cafs-types"
},
{
"path": "../fetcher-base"
},

View File

@@ -23,6 +23,7 @@
"path-temp": "^2.0.0"
},
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/create-cafs-store": "workspace:*",
"@pnpm/logger": "^4.0.0",
"@pnpm/prepare": "workspace:*"

View File

@@ -3,7 +3,7 @@ import path from 'path'
import createCafs, {
getFilePathByModeInCafs,
} from '@pnpm/cafs'
import { PackageFilesResponse } from '@pnpm/fetcher-base'
import type { Cafs, PackageFilesResponse } from '@pnpm/cafs-types'
import { createIndexedPkgImporter } from '@pnpm/fs.indexed-pkg-importer'
import {
ImportIndexedPackage,
@@ -70,7 +70,7 @@ export default function createCafsStore (
importPackage?: ImportIndexedPackage
packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone' | 'clone-or-copy'
}
) {
): Cafs {
const cafsDir = path.join(storeDir, 'files')
const baseTempDir = path.join(storeDir, 'tmp')
const importPackage = createPackageImporter({
@@ -80,6 +80,7 @@ export default function createCafsStore (
})
return {
...createCafs(cafsDir, opts?.ignoreFile),
cafsDir,
importPackage,
tempDir: async () => {
const tmpDir = pathTemp(baseTempDir)

View File

@@ -15,6 +15,9 @@
{
"path": "../cafs"
},
{
"path": "../cafs-types"
},
{
"path": "../fetcher-base"
},

View File

@@ -36,6 +36,7 @@
},
"funding": "https://opencollective.com/pnpm",
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/fetcher-base": "workspace:*"
},
"exports": {

View File

@@ -1,44 +1,5 @@
import { Resolution, GitResolution, DirectoryResolution } from '@pnpm/resolver-base'
import { DependencyManifest } from '@pnpm/types'
import { IntegrityLike } from 'ssri'
export interface PackageFileInfo {
checkedAt?: number // Nullable for backward compatibility
integrity: string
mode: number
size: number
}
export type PackageFilesResponse = {
fromStore: boolean
packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone' | 'clone-or-copy'
sideEffects?: Record<string, Record<string, PackageFileInfo>>
} & ({
local: true
filesIndex: Record<string, string>
} | {
local?: false
filesIndex: Record<string, PackageFileInfo>
})
export interface ImportPackageOpts {
requiresBuild?: boolean
sideEffectsCacheKey?: string
filesResponse: PackageFilesResponse
force: boolean
}
export type ImportPackageFunction = (
to: string,
opts: ImportPackageOpts
) => Promise<{ isBuilt: boolean, importMethod: undefined | string }>
export interface Cafs {
addFilesFromDir: (dir: string, manifest?: DeferredManifestPromise) => Promise<FilesIndex>
addFilesFromTarball: (stream: NodeJS.ReadableStream, manifest?: DeferredManifestPromise) => Promise<FilesIndex>
importPackage: ImportPackageFunction
tempDir: () => Promise<string>
}
import type { DeferredManifestPromise, Cafs, FilesIndex } from '@pnpm/cafs-types'
export interface FetchOptions {
manifest?: DeferredManifestPromise
@@ -47,11 +8,6 @@ export interface FetchOptions {
onProgress?: (downloaded: number) => void
}
export interface DeferredManifestPromise {
resolve: (manifest: DependencyManifest | undefined) => void
reject: (err: Error) => void
}
export type FetchFunction<FetcherResolution = Resolution, Options = FetchOptions, Result = FetchResult> = (
cafs: Cafs,
resolution: FetcherResolution,
@@ -66,19 +22,6 @@ export type FetchResult = {
filesIndex: Record<string, string>
}
export interface FileWriteResult {
checkedAt: number
integrity: IntegrityLike
}
export interface FilesIndex {
[filename: string]: {
mode: number
size: number
writeResult: Promise<FileWriteResult>
}
}
export interface GitFetcherOptions {
manifest?: DeferredManifestPromise
}

View File

@@ -9,6 +9,9 @@
"../../typings/**/*.d.ts"
],
"references": [
{
"path": "../cafs-types"
},
{
"path": "../resolver-base"
},

View File

@@ -47,6 +47,7 @@
"tempy": "^1.0.1"
},
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/node.fetcher": "workspace:*",
"@pnpm/prepare": "workspace:*",
"@types/adm-zip": "^0.4.34",

View File

@@ -5,7 +5,7 @@ import {
FetchFromRegistry,
RetryTimeoutOptions,
} from '@pnpm/fetching-types'
import { FilesIndex } from '@pnpm/fetcher-base'
import type { FilesIndex } from '@pnpm/cafs-types'
import { pickFetcher } from '@pnpm/pick-fetcher'
import createCafsStore from '@pnpm/create-cafs-store'
import createFetcher, { waitForFilesIndex } from '@pnpm/tarball-fetcher'

View File

@@ -12,6 +12,9 @@
{
"path": "../../privatePackages/prepare"
},
{
"path": "../cafs-types"
},
{
"path": "../create-cafs-store"
},

View File

@@ -63,6 +63,7 @@
"ssri": "^8.0.1"
},
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/client": "workspace:*",
"@pnpm/create-cafs-store": "workspace:*",
"@pnpm/logger": "^4.0.0",

View File

@@ -2,5 +2,4 @@ import packageRequester from './packageRequester'
export default packageRequester
export { PackageFilesResponse } from '@pnpm/fetcher-base'
export { PackageResponse } from '@pnpm/store-controller-types'

View File

@@ -13,13 +13,11 @@ import { fetchingProgressLogger, progressLogger } from '@pnpm/core-loggers'
import { pickFetcher } from '@pnpm/pick-fetcher'
import PnpmError from '@pnpm/error'
import {
Cafs,
DeferredManifestPromise,
Fetchers,
FetchOptions,
FetchResult,
PackageFilesResponse,
} from '@pnpm/fetcher-base'
import type { Cafs, DeferredManifestPromise, PackageFilesResponse } from '@pnpm/cafs-types'
import gfs from '@pnpm/graceful-fs'
import logger from '@pnpm/logger'
import packageIsInstallable from '@pnpm/package-is-installable'

View File

@@ -4,7 +4,8 @@ import path from 'path'
import { getFilePathInCafs, PackageFilesIndex } from '@pnpm/cafs'
import createClient from '@pnpm/client'
import { streamParser } from '@pnpm/logger'
import createPackageRequester, { PackageFilesResponse, PackageResponse } from '@pnpm/package-requester'
import createPackageRequester, { PackageResponse } from '@pnpm/package-requester'
import type { PackageFilesResponse } from '@pnpm/cafs-types'
import createCafsStore from '@pnpm/create-cafs-store'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import fixtures from '@pnpm/test-fixtures'

View File

@@ -15,6 +15,9 @@
{
"path": "../cafs"
},
{
"path": "../cafs-types"
},
{
"path": "../client"
},

View File

@@ -35,6 +35,7 @@
},
"funding": "https://opencollective.com/pnpm",
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/store-controller-types": "workspace:*"
},
"exports": {

View File

@@ -5,11 +5,11 @@ import {
WantedDependency,
WorkspacePackages,
} from '@pnpm/resolver-base'
import {
import type {
ImportPackageFunction,
PackageFileInfo,
PackageFilesResponse,
} from '@pnpm/fetcher-base'
} from '@pnpm/cafs-types'
import {
DependencyManifest,
PackageManifest,

View File

@@ -9,6 +9,9 @@
"../../typings/**/*.d.ts"
],
"references": [
{
"path": "../cafs-types"
},
{
"path": "../fetcher-base"
},

View File

@@ -45,6 +45,7 @@
"ssri": "^8.0.1"
},
"devDependencies": {
"@pnpm/cafs-types": "workspace:*",
"@pnpm/create-cafs-store": "workspace:*",
"@pnpm/fetch": "workspace:*",
"@pnpm/logger": "^4.0.0",

View File

@@ -1,4 +1,5 @@
import { Cafs, FetchFunction, FetchOptions, FilesIndex, PackageFileInfo } from '@pnpm/fetcher-base'
import { FetchFunction, FetchOptions } from '@pnpm/fetcher-base'
import type { Cafs, FilesIndex, PackageFileInfo } from '@pnpm/cafs-types'
import preparePackage from '@pnpm/prepare-package'
import fromPairs from 'ramda/src/fromPairs'
import omit from 'ramda/src/omit'

View File

@@ -1,9 +1,9 @@
import PnpmError from '@pnpm/error'
import {
Cafs,
FetchFunction,
FetchOptions,
} from '@pnpm/fetcher-base'
import type { Cafs } from '@pnpm/cafs-types'
import {
FetchFromRegistry,
GetCredentials,

View File

@@ -1,5 +1,6 @@
import path from 'path'
import { Cafs, DeferredManifestPromise, FetchFunction, FetchOptions, FetchResult } from '@pnpm/fetcher-base'
import { FetchFunction, FetchOptions, FetchResult } from '@pnpm/fetcher-base'
import type { Cafs, DeferredManifestPromise } from '@pnpm/cafs-types'
import gfs from '@pnpm/graceful-fs'
import ssri from 'ssri'
import { TarballIntegrityError } from './remoteTarballFetcher'

View File

@@ -2,11 +2,8 @@ import { IncomingMessage } from 'http'
import urlLib from 'url'
import { requestRetryLogger } from '@pnpm/core-loggers'
import PnpmError, { FetchError } from '@pnpm/error'
import {
Cafs,
DeferredManifestPromise,
FetchResult,
} from '@pnpm/fetcher-base'
import { FetchResult } from '@pnpm/fetcher-base'
import type { Cafs, DeferredManifestPromise } from '@pnpm/cafs-types'
import { FetchFromRegistry } from '@pnpm/fetching-types'
import * as retry from '@zkochan/retry'
import ssri from 'ssri'

View File

@@ -12,6 +12,9 @@
{
"path": "../../privatePackages/test-fixtures"
},
{
"path": "../cafs-types"
},
{
"path": "../core-loggers"
},

36
pnpm-lock.yaml generated
View File

@@ -305,6 +305,9 @@ importers:
'@pnpm/cafs':
specifier: workspace:*
version: 'link:'
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/types':
specifier: workspace:*
version: link:../types
@@ -327,6 +330,18 @@ importers:
specifier: ^1.0.1
version: 1.0.1
packages/cafs-types:
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: 'link:'
'@pnpm/types':
specifier: workspace:*
version: link:../types
'@types/ssri':
specifier: ^7.1.1
version: 7.1.1
packages/calc-dep-state:
dependencies:
'@pnpm/constants':
@@ -811,6 +826,9 @@ importers:
specifier: ^2.0.0
version: 2.0.0
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/create-cafs-store':
specifier: workspace:*
version: 'link:'
@@ -1152,6 +1170,9 @@ importers:
specifier: ^7.1.1
version: 7.1.1
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/fetcher-base':
specifier: workspace:*
version: 'link:'
@@ -2372,6 +2393,9 @@ importers:
specifier: ^1.0.1
version: 1.0.1
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/node.fetcher':
specifier: workspace:*
version: 'link:'
@@ -2700,6 +2724,9 @@ importers:
specifier: ^8.0.1
version: 8.0.1
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/client':
specifier: workspace:*
version: link:../client
@@ -4926,6 +4953,9 @@ importers:
specifier: workspace:*
version: link:../types
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/store-controller-types':
specifier: workspace:*
version: 'link:'
@@ -5022,6 +5052,9 @@ importers:
specifier: ^8.0.1
version: 8.0.1
devDependencies:
'@pnpm/cafs-types':
specifier: workspace:*
version: link:../cafs-types
'@pnpm/create-cafs-store':
specifier: workspace:*
version: link:../create-cafs-store
@@ -7203,7 +7236,6 @@ packages:
/@types/node/18.6.3:
resolution: {integrity: sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg==}
dev: true
/@types/normalize-package-data/2.4.1:
resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==}
@@ -7273,7 +7305,7 @@ packages:
/@types/ssri/7.1.1:
resolution: {integrity: sha512-DPP/jkDaqGiyU75MyMURxLWyYLwKSjnAuGe9ZCsLp9QZOpXmDfuevk769F0BS86TmRuD5krnp06qw9nSoNO+0g==}
dependencies:
'@types/node': 18.6.2
'@types/node': 18.6.3
/@types/stack-utils/2.0.1:
resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==}