diff --git a/.changeset/blue-crabs-sparkle.md b/.changeset/blue-crabs-sparkle.md new file mode 100644 index 00000000000..9e556f7385c --- /dev/null +++ b/.changeset/blue-crabs-sparkle.md @@ -0,0 +1,9 @@ +--- +"@pnpm/git-fetcher": patch +"@pnpm/tarball-fetcher": patch +"pnpm": patch +--- + +Fixes a regression introduced in pnpm v6.23.3 via [#4044](https://github.com/pnpm/pnpm/pull/4044). + +The temporary directory to which the Git-hosted package is downloaded should not be removed prematurely [#4064](https://github.com/pnpm/pnpm/issues/4064). diff --git a/packages/git-fetcher/src/index.ts b/packages/git-fetcher/src/index.ts index 1574a9d85ce..b5f9bf9d721 100644 --- a/packages/git-fetcher/src/index.ts +++ b/packages/git-fetcher/src/index.ts @@ -24,7 +24,9 @@ export default () => { // removing /.git to make directory integrity calculation faster await rimraf(path.join(tempLocation, '.git')) const filesIndex = await cafs.addFilesFromDir(tempLocation, opts.manifest) - await rimraf(tempLocation) + // Important! We cannot remove the temp location at this stage. + // Even though we have the index of the package, + // the linking of files to the store is in progress. return { filesIndex } }, } diff --git a/packages/git-fetcher/test/index.ts b/packages/git-fetcher/test/index.ts index ed495b34f91..8c5589be420 100644 --- a/packages/git-fetcher/test/index.ts +++ b/packages/git-fetcher/test/index.ts @@ -63,4 +63,18 @@ test('fetch a package without a package.json', async () => { } ) expect(filesIndex['denolib.json']).toBeTruthy() -}) \ No newline at end of file +}) + +// Covers the regression reported in https://github.com/pnpm/pnpm/issues/4064 +test('fetch a big repository', async () => { + const cafsDir = tempy.directory() + const fetch = createFetcher().git + const manifest = pDefer() + const { filesIndex } = await fetch(createCafsStore(cafsDir), + { + commit: 'a65fbf5a90f53c9d72fed4daaca59da50f074355', + repo: 'https://github.com/sveltejs/action-deploy-docs.git', + type: 'git', + }, { manifest }) + await Promise.all(Object.values(filesIndex).map(({ writeResult }) => writeResult)) +}) diff --git a/packages/tarball-fetcher/package.json b/packages/tarball-fetcher/package.json index d6b0437d7c5..b2768bcbaac 100644 --- a/packages/tarball-fetcher/package.json +++ b/packages/tarball-fetcher/package.json @@ -41,7 +41,6 @@ "@pnpm/graceful-fs": "workspace:1.0.0", "@pnpm/prepare-package": "workspace:1.0.7", "@zkochan/retry": "^0.2.0", - "@zkochan/rimraf": "^2.1.1", "ramda": "^0.27.1", "ssri": "^8.0.1" }, diff --git a/packages/tarball-fetcher/src/createDownloader.ts b/packages/tarball-fetcher/src/createDownloader.ts index a0fb2388978..d145d02cd85 100644 --- a/packages/tarball-fetcher/src/createDownloader.ts +++ b/packages/tarball-fetcher/src/createDownloader.ts @@ -12,7 +12,6 @@ import { import { FetchFromRegistry } from '@pnpm/fetching-types' import preparePackage from '@pnpm/prepare-package' import * as retry from '@zkochan/retry' -import rimraf from '@zkochan/rimraf' import fromPairs from 'ramda/src/fromPairs' import omit from 'ramda/src/omit' import ssri from 'ssri' @@ -248,7 +247,9 @@ async function prepareGitHostedPkg (filesIndex: FilesIndex, cafs: Cafs) { }) await preparePackage(tempLocation) const newFilesIndex = await cafs.addFilesFromDir(tempLocation) - await rimraf(tempLocation) + // Important! We cannot remove the temp location at this stage. + // Even though we have the index of the package, + // the linking of files to the store is in progress. return newFilesIndex } diff --git a/packages/tarball-fetcher/test/download.ts b/packages/tarball-fetcher/test/download.ts index 0346f06b351..e35ca2edb03 100644 --- a/packages/tarball-fetcher/test/download.ts +++ b/packages/tarball-fetcher/test/download.ts @@ -353,3 +353,16 @@ test('accessing private packages', async () => { async function getFileIntegrity (filename: string) { return (await ssri.fromStream(fs.createReadStream(filename))).toString() } + +// Covers the regression reported in https://github.com/pnpm/pnpm/issues/4064 +test('fetch a big repository', async () => { + process.chdir(tempy.directory()) + + const resolution = { tarball: 'https://codeload.github.com/sveltejs/action-deploy-docs/tar.gz/a65fbf5a90f53c9d72fed4daaca59da50f074355' } + + const result = await fetch.tarball(cafs, resolution, { + lockfileDir: process.cwd(), + }) + + expect(result.filesIndex).toBeTruthy() +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e120b877971..cbc5d9797c8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3253,7 +3253,6 @@ importers: '@types/retry': ^0.12.0 '@types/ssri': ^7.1.0 '@zkochan/retry': ^0.2.0 - '@zkochan/rimraf': ^2.1.1 cp-file: ^9.0.0 nock: 12.0.3 ramda: ^0.27.1 @@ -3267,7 +3266,6 @@ importers: '@pnpm/graceful-fs': link:../graceful-fs '@pnpm/prepare-package': link:../prepare-package '@zkochan/retry': 0.2.0 - '@zkochan/rimraf': 2.1.1 ramda: 0.27.1 ssri: 8.0.1 devDependencies: