-
-
Notifications
You must be signed in to change notification settings - Fork 933
/
rebuild.ts
135 lines (128 loc) · 3.42 KB
/
rebuild.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
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
import { docsUrl, readProjectManifestOnly } from '@pnpm/cli-utils'
import { FILTERING, UNIVERSAL_OPTIONS } from '@pnpm/common-cli-options-help'
import { Config, types as allTypes } from '@pnpm/config'
import { LogBase } from '@pnpm/logger'
import {
createOrConnectStoreController,
CreateStoreControllerOptions,
} from '@pnpm/store-connection-manager'
import pick from 'ramda/src/pick'
import renderHelp from 'render-help'
import {
rebuildProjects,
rebuildSelectedPkgs,
} from './implementation'
import { recursiveRebuild } from './recursive'
export function rcOptionsTypes () {
return {
...pick([
'npm-path',
'reporter',
'scripts-prepend-node-path',
'unsafe-perm',
'store-dir',
], allTypes),
}
}
export function cliOptionsTypes () {
return {
...rcOptionsTypes(),
pending: Boolean,
recursive: Boolean,
}
}
export const commandNames = ['rebuild', 'rb']
export function help () {
return renderHelp({
aliases: ['rb'],
description: 'Rebuild a package.',
descriptionLists: [
{
title: 'Options',
list: [
{
description: 'Rebuild every package found in subdirectories \
or every workspace package, when executed inside a workspace. \
For options that may be used with `-r`, see "pnpm help recursive"',
name: '--recursive',
shortAlias: '-r',
},
{
description: 'Rebuild packages that were not build during installation. Packages are not build when installing with the --ignore-scripts flag',
name: '--pending',
},
{
description: 'The directory in which all the packages are saved on the disk',
name: '--store-dir <dir>',
},
...UNIVERSAL_OPTIONS,
],
},
FILTERING,
],
url: docsUrl('rebuild'),
usages: ['pnpm rebuild [<pkg> ...]'],
})
}
export async function handler (
opts: Pick<Config,
| 'allProjects'
| 'dir'
| 'engineStrict'
| 'hooks'
| 'lockfileDir'
| 'nodeLinker'
| 'rawLocalConfig'
| 'registries'
| 'scriptShell'
| 'selectedProjectsGraph'
| 'sideEffectsCache'
| 'sideEffectsCacheReadonly'
| 'scriptsPrependNodePath'
| 'shellEmulator'
| 'workspaceDir'
> &
CreateStoreControllerOptions &
{
recursive?: boolean
reporter?: (logObj: LogBase) => void
pending: boolean
},
params: string[]
) {
if (opts.recursive && (opts.allProjects != null) && (opts.selectedProjectsGraph != null) && opts.workspaceDir) {
await recursiveRebuild(opts.allProjects, params, { ...opts, selectedProjectsGraph: opts.selectedProjectsGraph, workspaceDir: opts.workspaceDir })
return
}
const store = await createOrConnectStoreController(opts)
const rebuildOpts = Object.assign(opts, {
sideEffectsCacheRead: opts.sideEffectsCache ?? opts.sideEffectsCacheReadonly,
sideEffectsCacheWrite: opts.sideEffectsCache,
storeController: store.ctrl,
storeDir: store.dir,
})
if (params.length === 0) {
await rebuildProjects(
[
{
buildIndex: 0,
manifest: await readProjectManifestOnly(rebuildOpts.dir, opts),
rootDir: rebuildOpts.dir,
},
],
rebuildOpts
)
return
}
await rebuildSelectedPkgs(
[
{
buildIndex: 0,
manifest: await readProjectManifestOnly(rebuildOpts.dir, opts),
rootDir: rebuildOpts.dir,
},
],
params,
rebuildOpts
)
}