/
index.ts
42 lines (39 loc) · 1.35 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import path from 'path'
import { Cafs, DeferredManifestPromise } from '@pnpm/fetcher-base'
import preparePackage from '@pnpm/prepare-package'
import rimraf from '@zkochan/rimraf'
import execa from 'execa'
export default () => {
return {
git: async function fetchFromGit (
cafs: Cafs,
resolution: {
commit: string
repo: string
type: 'git'
},
opts: {
manifest?: DeferredManifestPromise
}
) {
const tempLocation = await cafs.tempDir()
await execGit(['clone', resolution.repo, tempLocation])
await execGit(['checkout', resolution.commit], { cwd: tempLocation })
await preparePackage(tempLocation)
// removing /.git to make directory integrity calculation faster
await rimraf(path.join(tempLocation, '.git'))
const filesIndex = await cafs.addFilesFromDir(tempLocation, opts.manifest)
// 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 }
},
}
}
function prefixGitArgs (): string[] {
return process.platform === 'win32' ? ['-c', 'core.longpaths=true'] : []
}
function execGit (args: string[], opts?: object) {
const fullArgs = prefixGitArgs().concat(args || [])
return execa('git', fullArgs, opts)
}