-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
index.ts
85 lines (78 loc) · 2.2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { PnpmError } from '@pnpm/error'
import {
FetchFunction,
FetchOptions,
} from '@pnpm/fetcher-base'
import type { Cafs } from '@pnpm/cafs-types'
import {
FetchFromRegistry,
GetAuthHeader,
RetryTimeoutOptions,
} from '@pnpm/fetching-types'
import {
createDownloader,
DownloadFunction,
TarballIntegrityError,
} from './remoteTarballFetcher'
import { createLocalTarballFetcher } from './localTarballFetcher'
import { createGitHostedTarballFetcher, waitForFilesIndex } from './gitHostedTarballFetcher'
export { BadTarballError } from './errorTypes'
export { TarballIntegrityError, waitForFilesIndex }
export interface TarballFetchers {
localTarball: FetchFunction
remoteTarball: FetchFunction
gitHostedTarball: FetchFunction
}
export function createTarballFetcher (
fetchFromRegistry: FetchFromRegistry,
getAuthHeader: GetAuthHeader,
opts: {
rawConfig: object
timeout?: number
retry?: RetryTimeoutOptions
offline?: boolean
}
): TarballFetchers {
const download = createDownloader(fetchFromRegistry, {
retry: opts.retry,
timeout: opts.timeout,
})
const remoteTarballFetcher = fetchFromTarball.bind(null, {
download,
getAuthHeaderByURI: getAuthHeader,
offline: opts.offline,
}) as FetchFunction
return {
localTarball: createLocalTarballFetcher(),
remoteTarball: remoteTarballFetcher,
gitHostedTarball: createGitHostedTarballFetcher(remoteTarballFetcher, opts.rawConfig),
}
}
async function fetchFromTarball (
ctx: {
download: DownloadFunction
getAuthHeaderByURI: (registry: string) => string | undefined
offline?: boolean
},
cafs: Cafs,
resolution: {
integrity?: string
registry?: string
tarball: string
},
opts: FetchOptions
) {
if (ctx.offline) {
throw new PnpmError('NO_OFFLINE_TARBALL',
`A package is missing from the store but cannot download it in offline mode. The missing package may be downloaded from ${resolution.tarball}.`)
}
return ctx.download(resolution.tarball, {
getAuthHeaderByURI: ctx.getAuthHeaderByURI,
cafs,
integrity: resolution.integrity,
manifest: opts.manifest,
onProgress: opts.onProgress,
onStart: opts.onStart,
registry: resolution.registry,
})
}