-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathinstall.ts
More file actions
392 lines (382 loc) · 12.7 KB
/
Copy pathinstall.ts
File metadata and controls
392 lines (382 loc) · 12.7 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
import type { CommandHandlerMap } from '@pnpm/cli.command'
import { FILTERING, OPTIONS, OUTPUT_OPTIONS, UNIVERSAL_OPTIONS } from '@pnpm/cli.common-cli-options-help'
import { docsUrl } from '@pnpm/cli.utils'
import { type Config, type ConfigContext, types as allTypes } from '@pnpm/config.reader'
import { WANTED_LOCKFILE } from '@pnpm/constants'
import { PnpmError } from '@pnpm/error'
import type { CreateStoreControllerOptions } from '@pnpm/store.connection-manager'
import { pick } from 'ramda'
import { renderHelp } from 'render-help'
import { getFetchFullMetadata } from './getFetchFullMetadata.js'
import { installDeps, type InstallDepsOptions } from './installDeps.js'
export function rcOptionsTypes (): Record<string, unknown> {
return pick([
'cache-dir',
'child-concurrency',
'cpu',
'dangerously-allow-all-builds',
'dev',
'engine-strict',
'fetch-retries',
'fetch-retry-factor',
'fetch-retry-maxtimeout',
'fetch-retry-mintimeout',
'fetch-timeout',
'frozen-lockfile',
'global-dir',
'global-pnpmfile',
'global',
'hoist',
'hoist-pattern',
'https-proxy',
'ignore-pnpmfile',
'ignore-scripts',
'optimistic-repeat-install',
'os',
'libc',
'link-workspace-packages',
'lockfile-dir',
'lockfile-only',
'lockfile',
'merge-git-branch-lockfiles',
'merge-git-branch-lockfiles-branch-pattern',
'modules-dir',
'network-concurrency',
'node-linker',
'noproxy',
'package-import-method',
'agent',
'pnpmfile',
'prefer-frozen-lockfile',
'prefer-offline',
'production',
'proxy',
'public-hoist-pattern',
'registry',
'reporter',
'runtime',
'save-workspace-protocol',
'scripts-prepend-node-path',
'shamefully-hoist',
'shared-workspace-lockfile',
'side-effects-cache-readonly',
'side-effects-cache',
'store-dir',
'strict-peer-dependencies',
'trust-policy',
'trust-policy-exclude',
'trust-policy-ignore-after',
'offline',
'only',
'optional',
'unsafe-perm',
'verify-store-integrity',
'virtual-store-dir',
'virtual-store-only',
], allTypes)
}
export const cliOptionsTypes = (): Record<string, unknown> => ({
...rcOptionsTypes(),
...pick(['force'], allTypes),
'fix-lockfile': Boolean,
'resolution-only': Boolean,
recursive: Boolean,
})
export const shorthands: Record<string, string> = {
D: '--dev',
P: '--production',
}
export const commandNames = ['install', 'i']
export const recursiveByDefault = true
export function help (): string {
return renderHelp({
aliases: ['i'],
description: 'Installs all dependencies of the project in the current working directory. \
When executed inside a workspace, installs all dependencies of all projects.',
descriptionLists: [
{
title: 'Options',
list: [
{
description: 'Run installation recursively in every package found in subdirectories. \
For options that may be used with `-r`, see "pnpm help recursive"',
name: '--recursive',
shortAlias: '-r',
},
OPTIONS.ignoreScripts,
OPTIONS.offline,
OPTIONS.preferOffline,
OPTIONS.globalDir,
{
description: "Packages in `devDependencies` won't be installed",
name: '--prod',
shortAlias: '-P',
},
{
description: 'Only `devDependencies` are installed',
name: '--dev',
shortAlias: '-D',
},
{
description: 'Skip reinstall if the workspace state is up-to-date',
name: '--optimistic-repeat-install',
},
{
description: '`optionalDependencies` are not installed',
name: '--no-optional',
},
{
description: 'Skip installing runtime entries (e.g. Node.js downloaded via `devEngines.runtime`). The lockfile is left untouched, so frozen installs still validate; only the runtime fetch and bin-linking are skipped. Useful in CI matrices where the runtime is provisioned externally.',
name: '--no-runtime',
},
{
description: `Don't read or generate a \`${WANTED_LOCKFILE}\` file`,
name: '--no-lockfile',
},
{
description: `Dependencies are not downloaded. Only \`${WANTED_LOCKFILE}\` is updated`,
name: '--lockfile-only',
},
{
description: "Don't generate a lockfile and fail if an update is needed. This setting is on by default in CI environments, so use --no-frozen-lockfile if you need to disable it for some reason",
name: '--[no-]frozen-lockfile',
},
{
description: `If the available \`${WANTED_LOCKFILE}\` satisfies the \`package.json\` then perform a headless installation`,
name: '--prefer-frozen-lockfile',
},
{
description: `The directory in which the ${WANTED_LOCKFILE} of the package will be created. Several projects may share a single lockfile.`,
name: '--lockfile-dir <dir>',
},
{
description: 'Fix broken lockfile entries automatically',
name: '--fix-lockfile',
},
{
description: 'Merge lockfiles were generated on git branch',
name: '--merge-git-branch-lockfiles',
},
{
description: 'The directory in which dependencies will be installed (instead of node_modules)',
name: '--modules-dir <dir>',
},
{
description: 'Dependencies inside the modules directory will have access only to their listed dependencies',
name: '--no-hoist',
},
{
description: 'All the subdeps will be hoisted into the root node_modules. Your code will have access to them',
name: '--shamefully-hoist',
},
{
description: 'Hoist all dependencies matching the pattern to `node_modules/.pnpm/node_modules`. \
The default pattern is * and matches everything. Hoisted packages can be required \
by any dependencies, so it is an emulation of a flat node_modules',
name: '--hoist-pattern <pattern>',
},
{
description: 'Hoist all dependencies matching the pattern to the root of the modules directory',
name: '--public-hoist-pattern <pattern>',
},
OPTIONS.storeDir,
OPTIONS.virtualStoreDir,
{
description: 'Maximum number of concurrent network requests',
name: '--network-concurrency <number>',
},
{
description: 'Controls the number of child processes run parallelly to build node modules',
name: '--child-concurrency <number>',
},
{
description: 'Disable pnpm hooks defined in .pnpmfile.cjs',
name: '--ignore-pnpmfile',
},
{
description: 'Ignore pnpm-workspace.yaml if exists in the parent directory, and treat the installation as normal non-workspace installation.',
name: '--ignore-workspace',
},
{
description: "If false, doesn't check whether packages in the store were mutated",
name: '--[no-]verify-store-integrity',
},
{
description: 'Fail on missing or invalid peer dependencies',
name: '--strict-peer-dependencies',
},
{
description: "Fail when a package's trust level is downgraded (e.g., from a trusted publisher to provenance only or no trust evidence)",
name: '--trust-policy no-downgrade',
},
{
description: 'Exclude specific packages from trust policy checks',
name: '--trust-policy-exclude <package-spec>',
},
{
description: 'Ignore trust downgrades for packages published more than specified minutes ago',
name: '--trust-policy-ignore-after <minutes>',
},
{
description: 'Clones/hardlinks or copies packages. The selected method depends from the file system',
name: '--package-import-method auto',
},
{
description: 'Hardlink packages from the store',
name: '--package-import-method hardlink',
},
{
description: 'Copy packages from the store',
name: '--package-import-method copy',
},
{
description: 'Clone (aka copy-on-write) packages from the store',
name: '--package-import-method clone',
},
{
description: 'Force reinstall dependencies: refetch packages modified in store, \
recreate a lockfile and/or modules directory created by a non-compatible version of pnpm. \
Install all optionalDependencies even when they don\'t satisfy the current environment(cpu, os, arch)',
name: '--force',
},
{
description: 'Use or cache the results of (pre/post)install hooks',
name: '--side-effects-cache',
},
{
description: 'Only use the side effects cache if present, do not create it for new packages',
name: '--side-effects-cache-readonly',
},
{
description: 'Re-runs resolution: useful for printing out peer dependency issues',
name: '--resolution-only',
},
...UNIVERSAL_OPTIONS,
],
},
OUTPUT_OPTIONS,
FILTERING,
],
url: docsUrl('install'),
usages: ['pnpm install [options]'],
})
}
export type InstallCommandOptions = Pick<Config,
| 'autoInstallPeers'
| 'bail'
| 'bin'
| 'catalogs'
| 'configDependencies'
| 'dedupeInjectedDeps'
| 'dedupeDirectDeps'
| 'dedupePeerDependents'
| 'dedupePeers'
| 'deployAllFiles'
| 'depth'
| 'dev'
| 'enableGlobalVirtualStore'
| 'engineStrict'
| 'excludeLinksFromLockfile'
| 'frozenLockfile'
| 'global'
| 'globalPnpmfile'
| 'hoistPattern'
| 'publicHoistPattern'
| 'ignorePnpmfile'
| 'ignoreScripts'
| 'injectWorkspacePackages'
| 'linkWorkspacePackages'
| 'lockfileDir'
| 'lockfileOnly'
| 'modulesDir'
| 'nodeLinker'
| 'patchedDependencies'
| 'preferFrozenLockfile'
| 'preferWorkspacePackages'
| 'production'
| 'registries'
| 'save'
| 'saveDev'
| 'saveExact'
| 'saveOptional'
| 'savePeer'
| 'savePrefix'
| 'saveProd'
| 'saveCatalogName'
| 'saveWorkspaceProtocol'
| 'lockfileIncludeTarballUrl'
| 'sideEffectsCache'
| 'sideEffectsCacheReadonly'
| 'sort'
| 'sharedWorkspaceLockfile'
| 'tag'
| 'allowBuilds'
| 'optional'
| 'virtualStoreDir'
| 'workspaceConcurrency'
| 'workspaceDir'
| 'workspacePackagePatterns'
| 'extraEnv'
| 'resolutionMode'
| 'ignoreWorkspaceCycles'
| 'disallowWorkspaceCycles'
| 'updateConfig'
| 'overrides'
| 'packageExtensions'
| 'agent'
| 'supportedArchitectures'
| 'packageConfigs'
> & Pick<ConfigContext,
| 'allProjects'
| 'cliOptions'
| 'hooks'
| 'rootProjectManifest'
| 'rootProjectManifestDir'
| 'allProjectsGraph'
| 'selectedProjectsGraph'
> & CreateStoreControllerOptions & Partial<Pick<Config, 'globalPkgDir'>> & {
argv: {
original: string[]
}
fixLockfile?: boolean
frozenLockfileIfExists?: boolean
useBetaCli?: boolean
pruneDirectDependencies?: boolean
pruneLockfileImporters?: boolean
pruneStore?: boolean
recursive?: boolean
resolutionOnly?: boolean
saveLockfile?: boolean
workspace?: boolean
includeOnlyPackageFiles?: boolean
confirmModulesPurge?: boolean
pnpmfile: string[]
} & Partial<Pick<Config, 'ci' | 'modulesCacheMaxAge' | 'pnpmHomeDir' | 'preferWorkspacePackages' | 'strictDepBuilds' | 'useLockfile' | 'symlink'>>
export async function handler (opts: InstallCommandOptions & { _calledFromLink?: boolean }, _params?: string[], commands?: CommandHandlerMap): Promise<void> {
if (opts.global && !opts._calledFromLink) {
throw new PnpmError('GLOBAL_INSTALL_NOT_SUPPORTED',
'"pnpm install -g" is not supported. Use "pnpm add -g <pkg>" to install global packages.')
}
const include = {
dependencies: opts.production !== false,
devDependencies: opts.dev !== false,
optionalDependencies: opts.optional !== false,
}
const installDepsOptions: InstallDepsOptions = {
...opts,
rebuildHandler: commands?.rebuild,
frozenLockfileIfExists: opts.frozenLockfileIfExists ?? (
opts.ci && !opts.lockfileOnly &&
typeof opts.frozenLockfile === 'undefined' &&
typeof opts.preferFrozenLockfile === 'undefined'
),
include,
includeDirect: include,
fetchFullMetadata: getFetchFullMetadata(opts),
}
if (opts.resolutionOnly) {
installDepsOptions.lockfileOnly = true
installDepsOptions.forceFullResolution = true
}
return installDeps(installDepsOptions, [])
}