perf: do not relink local dependencies (#6895)

This commit is contained in:
Zoltan Kochan
2023-08-05 01:03:19 +03:00
committed by GitHub
parent ec50dc98cc
commit 92f42224c6
5 changed files with 39 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/store-connection-manager": minor
"@pnpm/package-requester": minor
"@pnpm/package-store": minor
---
New option added: `relinkLocalDirDeps`. It is `true` by default. When `false`, local directory dependencies are not relinked on repeat install.

View File

@@ -1,4 +1,4 @@
import { promises as fs } from 'fs'
import fss, { promises as fs } from 'fs'
import path from 'path'
import { LOCKFILE_VERSION_V6 as LOCKFILE_VERSION } from '@pnpm/constants'
import { type Lockfile } from '@pnpm/lockfile-file'
@@ -480,3 +480,26 @@ test('re-install should update local file dependency', async () => {
lockfileVersion: LOCKFILE_VERSION,
})
})
test('local directory is not relinked if relinkLocalDirDeps is set to false', async () => {
prepareEmpty()
fss.mkdirSync('pkg')
fss.writeFileSync('pkg/index.js', 'hello', 'utf8')
fss.writeFileSync('pkg/package.json', '{"name": "pkg"}', 'utf8')
const manifest = await addDependenciesToPackage({}, ['file:./pkg'], await testDefaults())
fss.writeFileSync('pkg/new.js', 'hello', 'utf8')
await addDependenciesToPackage(manifest, ['is-odd@1.0.0'], await testDefaults({}, {}, {}, {
relinkLocalDirDeps: false,
}))
expect(fss.readdirSync('node_modules/pkg').sort()).toStrictEqual(['index.js', 'package.json'])
await install(manifest, await testDefaults({ frozenLockfile: true }, {}, {}, {
relinkLocalDirDeps: false,
}))
expect(fss.readdirSync('node_modules/pkg').sort()).toStrictEqual(['index.js', 'package.json'])
})

View File

@@ -95,6 +95,7 @@ export function createPackageRequester (
networkConcurrency?: number
storeDir: string
verifyStoreIntegrity: boolean
relinkLocalDirDeps?: boolean
}
): RequestPackageFunction & {
fetchPackageToStore: FetchPackageToStoreFunction
@@ -126,6 +127,7 @@ export function createPackageRequester (
counter: 0,
concurrency: networkConcurrency,
}),
relinkLocalDirDeps: opts.relinkLocalDirDeps ?? true,
storeDir: opts.storeDir,
})
const requestPackage = resolveAndFetch.bind(null, {
@@ -341,6 +343,7 @@ function fetchToStore (
counter: number
concurrency: number
}
relinkLocalDirDeps: boolean
storeDir: string
},
opts: FetchPackageToStoreOptions
@@ -608,7 +611,7 @@ Actual package in the store by the given integrity: ${pkgFilesIndex.name}@${pkgF
} else {
filesResult = {
local: true,
fromStore: false,
fromStore: !ctx.relinkLocalDirDeps,
filesIndex: fetchedPackage.filesIndex,
packageImportMethod: (fetchedPackage as DirectoryFetcherResult).packageImportMethod,
}

View File

@@ -31,6 +31,7 @@ export async function createPackageStore (
storeDir: string
networkConcurrency?: number
packageImportMethod?: 'auto' | 'hardlink' | 'copy' | 'clone' | 'clone-or-copy'
relinkLocalDirDeps?: boolean
verifyStoreIntegrity: boolean
}
): Promise<StoreController> {
@@ -48,6 +49,7 @@ export async function createPackageStore (
networkConcurrency: initOpts.networkConcurrency,
storeDir: initOpts.storeDir,
verifyStoreIntegrity: initOpts.verifyStoreIntegrity,
relinkLocalDirDeps: initOpts.relinkLocalDirDeps,
})
return {

View File

@@ -44,6 +44,7 @@ export type CreateNewStoreControllerOptions = CreateResolverOptions & Pick<Confi
> & {
cafsLocker?: CafsLocker
ignoreFile?: (filename: string) => boolean
relinkLocalDirDeps?: boolean
} & Partial<Pick<Config, 'userConfig' | 'deployAllFiles'>> & Pick<ClientOptions, 'resolveSymlinksInInjectedDirs'>
export async function createNewStoreController (
@@ -101,6 +102,7 @@ export async function createNewStoreController (
packageImportMethod: opts.packageImportMethod,
cacheDir: opts.cacheDir,
storeDir: opts.storeDir,
relinkLocalDirDeps: opts.relinkLocalDirDeps,
verifyStoreIntegrity: typeof opts.verifyStoreIntegrity === 'boolean'
? opts.verifyStoreIntegrity
: true,