-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
testDefaults.ts
83 lines (80 loc) · 1.93 KB
/
testDefaults.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
import * as path from 'path'
import { createClient } from '@pnpm/client'
import { createPackageStore } from '@pnpm/package-store'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { StoreController } from '@pnpm/store-controller-types'
import { getStorePath } from '@pnpm/store-path'
import { Registries } from '@pnpm/types'
import { InstallOptions } from '@pnpm/core'
const registry = `http://localhost:${REGISTRY_MOCK_PORT}/`
const retryOpts = {
retries: 4,
retryFactor: 10,
retryMaxtimeout: 60_000,
retryMintimeout: 10_000,
}
export async function testDefaults<T> (
opts?: T & {
fastUnpack?: boolean
storeDir?: string
prefix?: string
},
resolveOpts?: any, // eslint-disable-line
fetchOpts?: any, // eslint-disable-line
storeOpts?: any // eslint-disable-line
): Promise<
InstallOptions &
{
cacheDir: string
registries: Registries
storeController: StoreController
storeDir: string
} &
T
> {
const authConfig = { registry }
const cacheDir = path.resolve('cache')
const { resolve, fetchers } = createClient({
authConfig,
rawConfig: {},
retry: retryOpts,
cacheDir,
...resolveOpts,
...fetchOpts,
})
let storeDir = opts?.storeDir ?? path.resolve('.store')
storeDir = await getStorePath({
pkgRoot: opts?.prefix ?? process.cwd(),
storePath: storeDir,
pnpmHomeDir: '',
})
const storeController = await createPackageStore(
resolve,
fetchers,
{
ignoreFile: opts?.fastUnpack === false ? undefined : (filename) => filename !== 'package.json',
storeDir,
verifyStoreIntegrity: true,
...storeOpts,
}
)
const result = {
cacheDir,
registries: {
default: registry,
},
storeController,
storeDir,
...opts,
} as (
InstallOptions &
{
cacheDir: string
registries: Registries
storeController: StoreController
storeDir: string
} &
T
)
return result
}