Skip to content

Commit

Permalink
fix: installing big git-hosted packages
Browse files Browse the repository at this point in the history
close #4064
  • Loading branch information
zkochan committed Dec 4, 2021
1 parent b83756b commit 0c11b17
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .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).
4 changes: 3 additions & 1 deletion packages/git-fetcher/src/index.ts
Expand Up @@ -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 }
},
}
Expand Down
16 changes: 15 additions & 1 deletion packages/git-fetcher/test/index.ts
Expand Up @@ -63,4 +63,18 @@ test('fetch a package without a package.json', async () => {
}
)
expect(filesIndex['denolib.json']).toBeTruthy()
})
})

// 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<DependencyManifest>()
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))
})
1 change: 0 additions & 1 deletion packages/tarball-fetcher/package.json
Expand Up @@ -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"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/tarball-fetcher/src/createDownloader.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions packages/tarball-fetcher/test/download.ts
Expand Up @@ -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()
})
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c11b17

Please sign in to comment.