yarn-version 1.0.0-pre → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +106 -0
- package/README.md +161 -0
- package/build/index-node18.mjs +139 -109
- package/build/index-node18.mjs.map +1 -1
- package/package.json +8 -7
- package/src/__fixtures__/basic/package.json +4 -0
- package/src/__fixtures__/basic/yarn.lock +12 -0
- package/src/__fixtures__/monorepo/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-1/package.json +4 -0
- package/src/__fixtures__/monorepo/packages/package-2/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-3/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-4/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-5/package.json +8 -0
- package/src/__fixtures__/monorepo/yarn.lock +0 -0
- package/src/__fixtures__/no-version/package.json +3 -0
- package/src/__fixtures__/no-version/yarn.lock +0 -0
- package/src/__fixtures__/with-lifecycle/.yarn/install-state.gz +0 -0
- package/src/__fixtures__/with-lifecycle/package.json +7 -0
- package/src/__fixtures__/with-lifecycle/yarn.lock +11 -0
- package/src/commands/version.test.ts +63 -61
- package/src/commands/version.ts +688 -656
- package/src/utils/UsageError.ts +6 -1
- package/src/utils/conventionalChangelogUtils.ts +0 -0
- package/src/utils/packageDependenciesUtils.test.ts +18 -7
- package/src/utils/packageDependenciesUtils.ts +9 -2
- package/src/utils/updateChangelog.ts +0 -0
- package/src/utils/workspaceUtils.ts +0 -0
package/src/commands/version.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
import type { Workspace } from "../utils/packageUtils";
|
|
43
43
|
import {
|
|
44
44
|
createProjectWorkspace,
|
|
45
|
+
createWorkspace,
|
|
45
46
|
findRootWorkspace,
|
|
46
47
|
writePkg,
|
|
47
48
|
} from "../utils/packageUtils";
|
|
@@ -53,7 +54,7 @@ import {
|
|
|
53
54
|
getWorkspaceName,
|
|
54
55
|
} from "../utils/workspaceUtils";
|
|
55
56
|
|
|
56
|
-
interface
|
|
57
|
+
export interface VersionCommandOptions {
|
|
57
58
|
cwd: string;
|
|
58
59
|
includesRoot: boolean;
|
|
59
60
|
dryRun: boolean;
|
|
@@ -70,6 +71,7 @@ interface Options {
|
|
|
70
71
|
gitRemote: string;
|
|
71
72
|
ignoreChanges?: string;
|
|
72
73
|
verbose?: boolean;
|
|
74
|
+
cwdIsRoot?: boolean;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
interface BumpableWorkspace {
|
|
@@ -98,753 +100,783 @@ interface BumpedWorkspace extends ChangedWorkspace, NoVersionToUpdateWorkspace {
|
|
|
98
100
|
newTag: string | null;
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
export
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
).default(false),
|
|
115
|
-
)
|
|
116
|
-
.addOption(new Option("-v,--verbose").default(false))
|
|
117
|
-
.addOption(
|
|
118
|
-
new Option("--force <type>", "Specify the release type").choices([
|
|
119
|
-
"major",
|
|
120
|
-
"minor",
|
|
121
|
-
"patch",
|
|
122
|
-
]),
|
|
123
|
-
)
|
|
124
|
-
.addOption(
|
|
125
|
-
new Option(
|
|
126
|
-
"--prerelease [releaseType]",
|
|
127
|
-
"Add a prerelease identifier to new versions",
|
|
128
|
-
),
|
|
129
|
-
)
|
|
130
|
-
.addOption(
|
|
131
|
-
new Option(
|
|
132
|
-
"--preset <presetName>",
|
|
133
|
-
"Conventional Changelog preset to require. Defaults to conventional-changelog-conventionalcommits.",
|
|
134
|
-
).default("conventional-changelog-conventionalcommits"),
|
|
135
|
-
)
|
|
136
|
-
.addOption(
|
|
137
|
-
new Option("--tag-version-prefix <prefix>", "Tag version prefix").default(
|
|
138
|
-
"v",
|
|
139
|
-
),
|
|
140
|
-
)
|
|
141
|
-
.addOption(
|
|
142
|
-
new Option(
|
|
143
|
-
"--changelog <path>",
|
|
144
|
-
"Changelog path. Default to CHANGELOG.md.",
|
|
145
|
-
).default("CHANGELOG.md"),
|
|
146
|
-
)
|
|
147
|
-
.addOption(
|
|
148
|
-
new Option(
|
|
149
|
-
"-m,--commit-message <message>",
|
|
150
|
-
'Commit message. Default to "chore: release %a". You can use %v for the version, %s for the version with prefix, %t to list tags, %a for auto best display.',
|
|
151
|
-
).default("chore: release %a"),
|
|
152
|
-
)
|
|
153
|
-
.addOption(
|
|
154
|
-
new Option("--create-release <type>", "Create a release").choices([
|
|
155
|
-
"github",
|
|
156
|
-
]),
|
|
157
|
-
)
|
|
158
|
-
.addOption(
|
|
159
|
-
new Option(
|
|
160
|
-
"--bump-dependents-highest-as <type>",
|
|
161
|
-
"Bump dependents highest version as major, minor or patch",
|
|
162
|
-
)
|
|
163
|
-
.choices(["major", "minor", "patch"])
|
|
164
|
-
.default("major"),
|
|
165
|
-
)
|
|
166
|
-
.addOption(
|
|
167
|
-
new Option(
|
|
168
|
-
"--always-bump-peer-dependencies",
|
|
169
|
-
"Always bump peer dependencies. Default to bumping only if the version doesn't satisfies the peer dependency range.",
|
|
170
|
-
).default(false),
|
|
171
|
-
)
|
|
172
|
-
.addOption(
|
|
173
|
-
new Option(
|
|
174
|
-
"--git-remote <remote-name>",
|
|
175
|
-
"Git remote to push commits and tags to",
|
|
176
|
-
).default("origin"),
|
|
177
|
-
)
|
|
178
|
-
.addOption(
|
|
179
|
-
new Option(
|
|
180
|
-
"--ignore-changes <glob>",
|
|
181
|
-
'Ignore changes in files matching the glob. Example: "**/*.test.js"',
|
|
182
|
-
),
|
|
183
|
-
)
|
|
184
|
-
.action(async (options: Options) => {
|
|
185
|
-
// todo nightingale-cli
|
|
186
|
-
if (options.json) {
|
|
187
|
-
process.env.NIGHTINGALE_CONSOLE_FORMATTER = "json";
|
|
188
|
-
}
|
|
103
|
+
export const versionCommandAction = async (
|
|
104
|
+
options: VersionCommandOptions,
|
|
105
|
+
{ nightingaleHandler = new ConsoleHandler(Level.INFO) } = {},
|
|
106
|
+
): Promise<void> => {
|
|
107
|
+
// todo nightingale-cli
|
|
108
|
+
if (options.json) {
|
|
109
|
+
process.env.NIGHTINGALE_CONSOLE_FORMATTER = "json";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
addConfig({
|
|
113
|
+
pattern: /^yarn-version/,
|
|
114
|
+
handler: nightingaleHandler,
|
|
115
|
+
});
|
|
189
116
|
|
|
190
|
-
|
|
191
|
-
pattern: /^yarn-version/,
|
|
192
|
-
handler: new ConsoleHandler(Level.INFO),
|
|
193
|
-
});
|
|
117
|
+
const logger = new Logger("yarn-version");
|
|
194
118
|
|
|
195
|
-
|
|
119
|
+
const rootWorkspace = await (options.cwdIsRoot
|
|
120
|
+
? createWorkspace(options.cwd)
|
|
121
|
+
: findRootWorkspace(options.cwd));
|
|
196
122
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
123
|
+
if (!rootWorkspace) {
|
|
124
|
+
throw new UsageError("Could not find root workspace from this path.");
|
|
125
|
+
}
|
|
201
126
|
|
|
202
|
-
|
|
127
|
+
const project = await createProjectWorkspace(rootWorkspace);
|
|
203
128
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
129
|
+
if (!options.dryRun) {
|
|
130
|
+
const dirtyFiles = await getDirtyFiles(project.root);
|
|
131
|
+
if (dirtyFiles) {
|
|
132
|
+
throw new Error(
|
|
133
|
+
`Dirty Files:\n${dirtyFiles}\n\nThere are uncommitted changes in the git repository. Please commit or stash them first.`,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const rootWorkspaceChildren = [...project.children.values()];
|
|
139
|
+
let rootNewVersion = "";
|
|
140
|
+
let rootNewTag = "";
|
|
141
|
+
const isMonorepo = rootWorkspaceChildren.length > 0;
|
|
142
|
+
const isMonorepoVersionIndependent = isMonorepo && !rootWorkspace.pkg.version;
|
|
143
|
+
const workspaces =
|
|
144
|
+
!isMonorepo || options.includesRoot
|
|
145
|
+
? [rootWorkspace, ...rootWorkspaceChildren]
|
|
146
|
+
: rootWorkspaceChildren;
|
|
147
|
+
|
|
148
|
+
if (options.prerelease) {
|
|
149
|
+
throw new UsageError("--prerelease is not supported yet.");
|
|
150
|
+
}
|
|
151
|
+
if (options.ignoreChanges) {
|
|
152
|
+
throw new UsageError("--ignore-changes is not supported yet.");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const conventionalGitClient = new ConventionalGitClient(rootWorkspace.cwd);
|
|
156
|
+
|
|
157
|
+
const rootPreviousVersionTagPromise = options.force
|
|
158
|
+
? null
|
|
159
|
+
: conventionalGitClient.getLastSemverTag({
|
|
160
|
+
prefix: options.tagVersionPrefix,
|
|
161
|
+
skipUnstable: true,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const [
|
|
165
|
+
conventionalCommitConfig,
|
|
166
|
+
githubClient,
|
|
167
|
+
parsedRepoUrl,
|
|
168
|
+
gitCurrentBranch,
|
|
169
|
+
] = await Promise.all([
|
|
170
|
+
loadConventionalCommitConfig(rootWorkspace, options.preset),
|
|
171
|
+
// create client early to fail fast if necessary
|
|
172
|
+
options.createRelease ? createGitHubClient() : undefined,
|
|
173
|
+
options.createRelease ? parseGithubRepoUrl(rootWorkspace) : undefined,
|
|
174
|
+
getGitCurrentBranch(rootWorkspace),
|
|
175
|
+
]);
|
|
176
|
+
|
|
177
|
+
const buildTagName = (workspace: Workspace, version: string): string =>
|
|
178
|
+
`${
|
|
179
|
+
isMonorepo && workspace !== rootWorkspace
|
|
180
|
+
? `${getWorkspaceName(workspace)}@`
|
|
181
|
+
: options.tagVersionPrefix
|
|
182
|
+
}${version}`;
|
|
183
|
+
|
|
184
|
+
const changedWorkspaces = new Map<Workspace, ChangedWorkspace>();
|
|
185
|
+
const dependenciesMap = isMonorepo ? buildDependenciesMaps(project) : null;
|
|
186
|
+
|
|
187
|
+
// todo logger.group
|
|
188
|
+
logger.info(
|
|
189
|
+
options.force
|
|
190
|
+
? "Check all workspaces (force option)"
|
|
191
|
+
: "Finding changed workspaces",
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// check workspaces and create bumpableWorkspaces
|
|
195
|
+
|
|
196
|
+
const bumpableWorkspaces: BumpableWorkspace[] = [];
|
|
197
|
+
for (const workspace of workspaces) {
|
|
198
|
+
const workspaceName = getWorkspaceName(workspace);
|
|
199
|
+
const isRoot = workspace === rootWorkspace;
|
|
200
|
+
if (isRoot && isMonorepo) continue;
|
|
201
|
+
|
|
202
|
+
const version = workspace.pkg.version;
|
|
203
|
+
|
|
204
|
+
if (!version || version === "0.0.0") {
|
|
205
|
+
if (
|
|
206
|
+
(isRoot || isMonorepoVersionIndependent) &&
|
|
207
|
+
(!isMonorepo || !isMonorepoVersionIndependent)
|
|
208
|
+
) {
|
|
209
|
+
throw new UsageError(
|
|
210
|
+
'package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
|
|
209
211
|
);
|
|
210
212
|
}
|
|
211
|
-
}
|
|
212
213
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
let rootNewTag = "";
|
|
216
|
-
const isMonorepo = rootWorkspaceChildren.length > 0;
|
|
217
|
-
const isMonorepoVersionIndependent =
|
|
218
|
-
isMonorepo && !rootWorkspace.pkg.version;
|
|
219
|
-
const workspaces =
|
|
220
|
-
!isMonorepo || options.includesRoot
|
|
221
|
-
? [rootWorkspace, ...rootWorkspaceChildren]
|
|
222
|
-
: rootWorkspaceChildren;
|
|
223
|
-
|
|
224
|
-
if (options.prerelease) {
|
|
225
|
-
throw new UsageError("--prerelease is not supported yet.");
|
|
226
|
-
}
|
|
227
|
-
if (options.ignoreChanges) {
|
|
228
|
-
throw new UsageError("--ignore-changes is not supported yet.");
|
|
214
|
+
logger.info(`${workspaceName}: skipped (no version)`);
|
|
215
|
+
continue;
|
|
229
216
|
}
|
|
230
217
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
});
|
|
218
|
+
bumpableWorkspaces.push({
|
|
219
|
+
workspace,
|
|
220
|
+
workspaceName,
|
|
221
|
+
isRoot,
|
|
222
|
+
version,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
239
225
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
] = await Promise.all([
|
|
246
|
-
loadConventionalCommitConfig(rootWorkspace, options.preset),
|
|
247
|
-
// create client early to fail fast if necessary
|
|
248
|
-
options.createRelease ? createGitHubClient() : undefined,
|
|
249
|
-
options.createRelease ? parseGithubRepoUrl(rootWorkspace) : undefined,
|
|
250
|
-
getGitCurrentBranch(rootWorkspace),
|
|
251
|
-
]);
|
|
252
|
-
|
|
253
|
-
const buildTagName = (workspace: Workspace, version: string): string =>
|
|
254
|
-
`${
|
|
255
|
-
isMonorepo && workspace !== rootWorkspace
|
|
256
|
-
? `${getWorkspaceName(workspace)}@`
|
|
257
|
-
: options.tagVersionPrefix
|
|
258
|
-
}${version}`;
|
|
259
|
-
|
|
260
|
-
const changedWorkspaces = new Map<Workspace, ChangedWorkspace>();
|
|
261
|
-
const dependenciesMap = isMonorepo ? buildDependenciesMaps(project) : null;
|
|
262
|
-
|
|
263
|
-
// todo logger.group
|
|
264
|
-
logger.info("Finding changed workspaces");
|
|
265
|
-
|
|
266
|
-
// check workspaces and create bumpableWorkspaces
|
|
267
|
-
|
|
268
|
-
const bumpableWorkspaces: BumpableWorkspace[] = [];
|
|
269
|
-
for (const workspace of workspaces) {
|
|
270
|
-
const workspaceName = getWorkspaceName(workspace);
|
|
271
|
-
const isRoot = workspace === rootWorkspace;
|
|
272
|
-
if (isRoot && isMonorepo) continue;
|
|
226
|
+
if (bumpableWorkspaces.length > 0) {
|
|
227
|
+
logger.info("Found bumpable workspaces", {
|
|
228
|
+
count: bumpableWorkspaces.length,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
273
231
|
|
|
274
|
-
|
|
232
|
+
const previousTagByWorkspace = new Map<Workspace, string | undefined>(
|
|
233
|
+
await Promise.all(
|
|
234
|
+
bumpableWorkspaces.map(async ({ workspace, workspaceName, isRoot }) => {
|
|
235
|
+
const packageOption =
|
|
236
|
+
isMonorepo && isMonorepoVersionIndependent
|
|
237
|
+
? workspaceName
|
|
238
|
+
: undefined;
|
|
239
|
+
|
|
240
|
+
const previousVersionTagPrefix = packageOption
|
|
241
|
+
? `${packageOption}@`
|
|
242
|
+
: options.tagVersionPrefix;
|
|
243
|
+
|
|
244
|
+
const previousTag = await (isRoot || !isMonorepoVersionIndependent
|
|
245
|
+
? rootPreviousVersionTagPromise
|
|
246
|
+
: conventionalGitClient.getLastSemverTag({
|
|
247
|
+
prefix: previousVersionTagPrefix,
|
|
248
|
+
skipUnstable: true,
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
return [workspace, previousTag || undefined] as const;
|
|
252
|
+
}),
|
|
253
|
+
),
|
|
254
|
+
);
|
|
275
255
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
'package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
|
|
283
|
-
);
|
|
284
|
-
}
|
|
256
|
+
const commitsByWorkspace = options.force
|
|
257
|
+
? undefined
|
|
258
|
+
: new Map(
|
|
259
|
+
await Promise.all(
|
|
260
|
+
bumpableWorkspaces.map(async ({ workspace }) => {
|
|
261
|
+
const previousTag = previousTagByWorkspace.get(workspace);
|
|
285
262
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
263
|
+
const workspaceRelativePath = path.relative(
|
|
264
|
+
rootWorkspace.cwd,
|
|
265
|
+
workspace.cwd,
|
|
266
|
+
);
|
|
267
|
+
return [
|
|
268
|
+
workspace,
|
|
269
|
+
await asyncIterableToArray(
|
|
270
|
+
conventionalGitClient.getCommits(
|
|
271
|
+
{ path: workspaceRelativePath, from: previousTag },
|
|
272
|
+
conventionalCommitConfig.parser,
|
|
273
|
+
),
|
|
274
|
+
),
|
|
275
|
+
] as const;
|
|
276
|
+
}),
|
|
277
|
+
),
|
|
278
|
+
);
|
|
289
279
|
|
|
290
|
-
|
|
291
|
-
workspace,
|
|
292
|
-
workspaceName,
|
|
293
|
-
isRoot,
|
|
294
|
-
version,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
280
|
+
// find changed workspaces
|
|
297
281
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const packageOption =
|
|
302
|
-
isMonorepo && isMonorepoVersionIndependent
|
|
303
|
-
? workspaceName
|
|
304
|
-
: undefined;
|
|
305
|
-
|
|
306
|
-
const previousVersionTagPrefix = packageOption
|
|
307
|
-
? `${packageOption}@`
|
|
308
|
-
: options.tagVersionPrefix;
|
|
309
|
-
|
|
310
|
-
const previousTag = await (isRoot || !isMonorepoVersionIndependent
|
|
311
|
-
? rootPreviousVersionTagPromise
|
|
312
|
-
: conventionalGitClient.getLastSemverTag({
|
|
313
|
-
prefix: previousVersionTagPrefix,
|
|
314
|
-
skipUnstable: true,
|
|
315
|
-
}));
|
|
316
|
-
|
|
317
|
-
return [workspace, previousTag || undefined] as const;
|
|
318
|
-
}),
|
|
319
|
-
),
|
|
320
|
-
);
|
|
282
|
+
for (const { workspace, workspaceName } of bumpableWorkspaces) {
|
|
283
|
+
let bumpType: BumpType | null = null;
|
|
284
|
+
let bumpReason: string | undefined;
|
|
321
285
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const previousTag = previousTagByWorkspace.get(workspace);
|
|
328
|
-
|
|
329
|
-
const workspaceRelativePath = path.relative(
|
|
330
|
-
rootWorkspace.cwd,
|
|
331
|
-
workspace.cwd,
|
|
332
|
-
);
|
|
333
|
-
return [
|
|
334
|
-
workspace,
|
|
335
|
-
await asyncIterableToArray(
|
|
336
|
-
conventionalGitClient.getCommits(
|
|
337
|
-
{ path: workspaceRelativePath, from: previousTag },
|
|
338
|
-
conventionalCommitConfig.parser,
|
|
339
|
-
),
|
|
340
|
-
),
|
|
341
|
-
] as const;
|
|
342
|
-
}),
|
|
343
|
-
),
|
|
344
|
-
);
|
|
286
|
+
if (options.force) {
|
|
287
|
+
bumpType = options.force;
|
|
288
|
+
bumpReason = "forced by --force flag";
|
|
289
|
+
} else {
|
|
290
|
+
const commits = commitsByWorkspace?.get(workspace);
|
|
345
291
|
|
|
346
|
-
|
|
292
|
+
// No changes found for this package
|
|
293
|
+
if (!commits || commits.length === 0) {
|
|
294
|
+
logger.info(`${workspaceName}: skipped (no changes)`);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
347
297
|
|
|
348
|
-
|
|
349
|
-
|
|
298
|
+
const { releaseType, reason } = await recommendBump(
|
|
299
|
+
commits,
|
|
300
|
+
conventionalCommitConfig,
|
|
301
|
+
);
|
|
302
|
+
bumpReason = reason;
|
|
350
303
|
|
|
351
|
-
|
|
352
|
-
|
|
304
|
+
if (releaseType) {
|
|
305
|
+
bumpType = releaseType as BumpType;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
353
308
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
const commits = commitsByWorkspace?.get(workspace);
|
|
309
|
+
if (bumpType) {
|
|
310
|
+
if (isMonorepo && !workspace.pkg.name) {
|
|
311
|
+
throw new Error("Workspace name is required");
|
|
312
|
+
}
|
|
359
313
|
|
|
360
|
-
|
|
361
|
-
if (!commits || commits.length === 0) {
|
|
362
|
-
logger.info(`${workspaceName}: skipped (no changes)`);
|
|
363
|
-
continue;
|
|
364
|
-
}
|
|
314
|
+
const currentVersion = workspace.pkg.version;
|
|
365
315
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
316
|
+
if (!currentVersion) {
|
|
317
|
+
throw new UsageError(
|
|
318
|
+
`Invalid "${getWorkspaceName(workspace)}" version`,
|
|
369
319
|
);
|
|
370
|
-
bumpReason = reason;
|
|
371
|
-
|
|
372
|
-
if (releaseType) {
|
|
373
|
-
bumpType = releaseType as BumpType;
|
|
374
|
-
}
|
|
375
320
|
}
|
|
376
321
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
322
|
+
changedWorkspaces.set(workspace, {
|
|
323
|
+
bumpType,
|
|
324
|
+
bumpReason,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (changedWorkspaces.size === 0) {
|
|
330
|
+
logger.info("No changed workspaces");
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
logger.info("Preparing bumping");
|
|
335
|
+
|
|
336
|
+
const bumpedWorkspaces = new Map<Workspace, BumpedWorkspace>();
|
|
337
|
+
const noVersionToUpdateWorkspaces = new Map<
|
|
338
|
+
Workspace,
|
|
339
|
+
NoVersionToUpdateWorkspace
|
|
340
|
+
>();
|
|
341
|
+
const batches = dependenciesMap
|
|
342
|
+
? buildTopologicalOrderBatches(project, dependenciesMap)
|
|
343
|
+
: [[rootWorkspace]];
|
|
344
|
+
|
|
345
|
+
for (const batch of batches) {
|
|
346
|
+
for (const workspace of batch) {
|
|
347
|
+
const currentVersion = workspace.pkg.version;
|
|
348
|
+
|
|
349
|
+
if (!currentVersion && !workspace.pkg.private) {
|
|
350
|
+
throw new UsageError(
|
|
351
|
+
`Invalid "${getWorkspaceName(workspace)}" version`,
|
|
352
|
+
);
|
|
353
|
+
}
|
|
383
354
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
355
|
+
const changedWorkspace = changedWorkspaces.get(workspace);
|
|
356
|
+
let bumpType: BumpType | null = null;
|
|
357
|
+
const bumpReasons: string[] = [];
|
|
358
|
+
const dependenciesToBump: BumpedWorkspace["dependenciesToBump"] = [];
|
|
389
359
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
});
|
|
360
|
+
if (changedWorkspace) {
|
|
361
|
+
bumpType = changedWorkspace.bumpType;
|
|
362
|
+
bumpReasons.push(changedWorkspace.bumpReason || "by commits");
|
|
394
363
|
}
|
|
395
|
-
}
|
|
396
364
|
|
|
397
|
-
|
|
398
|
-
logger.info("No changed workspaces");
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
365
|
+
const dependencies = dependenciesMap?.get(workspace);
|
|
401
366
|
|
|
402
|
-
|
|
367
|
+
if (dependencies) {
|
|
368
|
+
for (const [
|
|
369
|
+
dependencyWorkspace,
|
|
370
|
+
dependencyType,
|
|
371
|
+
dependencyDescriptor,
|
|
372
|
+
] of dependencies) {
|
|
373
|
+
const dependencyBumpedWorkspace =
|
|
374
|
+
bumpedWorkspaces.get(dependencyWorkspace);
|
|
403
375
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
NoVersionToUpdateWorkspace
|
|
408
|
-
>();
|
|
409
|
-
const batches = dependenciesMap
|
|
410
|
-
? buildTopologicalOrderBatches(project, dependenciesMap)
|
|
411
|
-
: [[rootWorkspace]];
|
|
376
|
+
if (!dependencyBumpedWorkspace) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
412
379
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
380
|
+
if (
|
|
381
|
+
dependencyType === "peerDependencies" &&
|
|
382
|
+
!options.alwaysBumpPeerDependencies &&
|
|
383
|
+
// skip when peerdependency with a new version satisfied by the existing range.
|
|
384
|
+
satisfies(
|
|
385
|
+
dependencyBumpedWorkspace.newVersion,
|
|
386
|
+
dependencyDescriptor.selector,
|
|
387
|
+
{ includePrerelease: true },
|
|
388
|
+
)
|
|
389
|
+
) {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
416
392
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
393
|
+
const newRange = calcBumpRange(
|
|
394
|
+
workspace,
|
|
395
|
+
dependencyDescriptor.selector,
|
|
396
|
+
dependencyBumpedWorkspace.newVersion,
|
|
420
397
|
);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
const changedWorkspace = changedWorkspaces.get(workspace);
|
|
424
|
-
let bumpType: BumpType | null = null;
|
|
425
|
-
const bumpReasons: string[] = [];
|
|
426
|
-
const dependenciesToBump: BumpedWorkspace["dependenciesToBump"] = [];
|
|
427
398
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
const dependencies = dependenciesMap?.get(workspace);
|
|
399
|
+
if (dependencyDescriptor.selector === newRange) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
434
402
|
|
|
435
|
-
|
|
436
|
-
for (const [
|
|
437
|
-
dependencyWorkspace,
|
|
403
|
+
dependenciesToBump.push([
|
|
438
404
|
dependencyType,
|
|
439
405
|
dependencyDescriptor,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
)
|
|
457
|
-
) {
|
|
458
|
-
continue;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const newRange = calcBumpRange(
|
|
462
|
-
workspace,
|
|
463
|
-
dependencyDescriptor.selector,
|
|
464
|
-
dependencyBumpedWorkspace.newVersion,
|
|
465
|
-
);
|
|
406
|
+
newRange,
|
|
407
|
+
]);
|
|
408
|
+
|
|
409
|
+
bumpType = getHighestBumpType([
|
|
410
|
+
bumpType ?? "patch",
|
|
411
|
+
calcBumpType(
|
|
412
|
+
dependencyBumpedWorkspace.bumpType,
|
|
413
|
+
options.bumpDependentsHighestAs,
|
|
414
|
+
),
|
|
415
|
+
]);
|
|
416
|
+
|
|
417
|
+
bumpReasons.push(
|
|
418
|
+
`Version bump for dependency: ${PackageDescriptorNameUtils.stringify(dependencyDescriptor.name)}`,
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
466
422
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
423
|
+
const workspaceName = getWorkspaceName(workspace);
|
|
424
|
+
if (!currentVersion) {
|
|
425
|
+
logger.info(`${workspaceName}: skipped (no version)`);
|
|
426
|
+
if (workspace !== rootWorkspace) {
|
|
427
|
+
noVersionToUpdateWorkspaces.set(workspace, {
|
|
428
|
+
dependenciesToBump,
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
} else if (!bumpType) {
|
|
432
|
+
logger.info(
|
|
433
|
+
`${workspaceName}: skipped (${
|
|
434
|
+
changedWorkspace
|
|
435
|
+
? `no bump recommended by ${options.preset}`
|
|
436
|
+
: "no changes"
|
|
437
|
+
})`,
|
|
438
|
+
);
|
|
439
|
+
} else {
|
|
440
|
+
const newVersion = incrementVersion(
|
|
441
|
+
workspace,
|
|
442
|
+
currentVersion,
|
|
443
|
+
bumpType,
|
|
444
|
+
);
|
|
470
445
|
|
|
471
|
-
|
|
472
|
-
dependencyType,
|
|
473
|
-
dependencyDescriptor,
|
|
474
|
-
newRange,
|
|
475
|
-
]);
|
|
476
|
-
|
|
477
|
-
bumpType = getHighestBumpType([
|
|
478
|
-
bumpType ?? "patch",
|
|
479
|
-
calcBumpType(
|
|
480
|
-
dependencyBumpedWorkspace.bumpType,
|
|
481
|
-
options.bumpDependentsHighestAs,
|
|
482
|
-
),
|
|
483
|
-
]);
|
|
446
|
+
const tagName = buildTagName(workspace, newVersion);
|
|
484
447
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
448
|
+
if (workspace === rootWorkspace) {
|
|
449
|
+
rootNewVersion = newVersion;
|
|
450
|
+
rootNewTag = tagName;
|
|
489
451
|
}
|
|
490
452
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (workspace !== rootWorkspace) {
|
|
495
|
-
noVersionToUpdateWorkspaces.set(workspace, {
|
|
496
|
-
dependenciesToBump,
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
} else if (!bumpType) {
|
|
500
|
-
logger.info(
|
|
501
|
-
`${workspaceName}: skipped (${
|
|
502
|
-
changedWorkspace
|
|
503
|
-
? `no bump recommended by ${options.preset}`
|
|
504
|
-
: "no changes"
|
|
505
|
-
})`,
|
|
506
|
-
);
|
|
507
|
-
} else {
|
|
508
|
-
const newVersion = incrementVersion(
|
|
509
|
-
workspace,
|
|
453
|
+
if (workspace !== rootWorkspace || !isMonorepo) {
|
|
454
|
+
const bumpReason = bumpReasons.join("\n");
|
|
455
|
+
bumpedWorkspaces.set(workspace, {
|
|
510
456
|
currentVersion,
|
|
511
457
|
bumpType,
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
if (workspace !== rootWorkspace || !isMonorepo) {
|
|
522
|
-
const bumpReason = bumpReasons.join("\n");
|
|
523
|
-
bumpedWorkspaces.set(workspace, {
|
|
524
|
-
currentVersion,
|
|
525
|
-
bumpType,
|
|
526
|
-
bumpReason,
|
|
527
|
-
bumpForDependenciesReasons: bumpReasons.slice(1),
|
|
528
|
-
newVersion,
|
|
529
|
-
newTag: tagName,
|
|
530
|
-
hasChanged: changedWorkspace !== undefined,
|
|
531
|
-
dependenciesToBump,
|
|
532
|
-
});
|
|
458
|
+
bumpReason,
|
|
459
|
+
bumpForDependenciesReasons: bumpReasons.slice(1),
|
|
460
|
+
newVersion,
|
|
461
|
+
newTag: tagName,
|
|
462
|
+
hasChanged: changedWorkspace !== undefined,
|
|
463
|
+
dependenciesToBump,
|
|
464
|
+
});
|
|
533
465
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
// bumpReasons,
|
|
549
|
-
// });
|
|
550
|
-
}
|
|
466
|
+
logger.info(
|
|
467
|
+
`${workspaceName}: ${currentVersion} -> ${
|
|
468
|
+
!isMonorepo || isMonorepoVersionIndependent ? newVersion : "bump"
|
|
469
|
+
} (${bumpReason.replace("\n", " ; ")})`,
|
|
470
|
+
);
|
|
471
|
+
// TODO Json only:
|
|
472
|
+
// logger.info({
|
|
473
|
+
// cwd: npath.fromPortablePath(workspace.cwd),
|
|
474
|
+
// ident: workspaceName,
|
|
475
|
+
// oldVersion: currentVersion,
|
|
476
|
+
// ...(isMonorepoVersionIndependent ? { newVersion } : {}),
|
|
477
|
+
// bumpType,
|
|
478
|
+
// bumpReasons,
|
|
479
|
+
// });
|
|
551
480
|
}
|
|
552
481
|
}
|
|
553
482
|
}
|
|
483
|
+
}
|
|
554
484
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
485
|
+
// TODO ask for confirmation
|
|
486
|
+
// if (!this.yes) {
|
|
487
|
+
// }
|
|
558
488
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
[...bumpedWorkspaces.entries()].forEach(
|
|
574
|
-
([workspace, bumpedWorkspace]) => {
|
|
575
|
-
const isRoot = workspace === rootWorkspace;
|
|
576
|
-
if (isRoot) {
|
|
577
|
-
throw new Error("Unexpected root found in bumped workspaces");
|
|
578
|
-
}
|
|
579
|
-
bumpedWorkspace.bumpType = highestBumpType;
|
|
580
|
-
bumpedWorkspace.newVersion = newVersion;
|
|
581
|
-
bumpedWorkspace.newTag = null;
|
|
582
|
-
},
|
|
583
|
-
);
|
|
489
|
+
// TODO do this entire phase here, not override for not independent only
|
|
490
|
+
if (isMonorepo && !isMonorepoVersionIndependent) {
|
|
491
|
+
const currentVersion = rootWorkspace.pkg.version!;
|
|
492
|
+
const highestBumpType = getHighestBumpType(
|
|
493
|
+
[...bumpedWorkspaces.values()].map(({ bumpType }) => bumpType),
|
|
494
|
+
);
|
|
495
|
+
const newVersion = incrementVersion(
|
|
496
|
+
rootWorkspace,
|
|
497
|
+
currentVersion,
|
|
498
|
+
highestBumpType,
|
|
499
|
+
);
|
|
500
|
+
rootNewVersion = newVersion;
|
|
501
|
+
rootNewTag = buildTagName(rootWorkspace, newVersion);
|
|
584
502
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
);
|
|
595
|
-
});
|
|
596
|
-
});
|
|
503
|
+
[...bumpedWorkspaces.entries()].forEach(([workspace, bumpedWorkspace]) => {
|
|
504
|
+
const isRoot = workspace === rootWorkspace;
|
|
505
|
+
if (isRoot) {
|
|
506
|
+
throw new Error("Unexpected root found in bumped workspaces");
|
|
507
|
+
}
|
|
508
|
+
bumpedWorkspace.bumpType = highestBumpType;
|
|
509
|
+
bumpedWorkspace.newVersion = newVersion;
|
|
510
|
+
bumpedWorkspace.newTag = null;
|
|
511
|
+
});
|
|
597
512
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
513
|
+
[
|
|
514
|
+
...bumpedWorkspaces.entries(),
|
|
515
|
+
...noVersionToUpdateWorkspaces.entries(),
|
|
516
|
+
].forEach(([workspace, { dependenciesToBump }]) => {
|
|
517
|
+
dependenciesToBump.forEach((dependencyToBump) => {
|
|
518
|
+
dependencyToBump[2] = calcBumpRange(
|
|
519
|
+
workspace,
|
|
520
|
+
dependencyToBump[1].selector,
|
|
521
|
+
newVersion,
|
|
522
|
+
);
|
|
605
523
|
});
|
|
524
|
+
});
|
|
606
525
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
526
|
+
bumpedWorkspaces.set(rootWorkspace, {
|
|
527
|
+
currentVersion,
|
|
528
|
+
bumpType: highestBumpType,
|
|
529
|
+
hasChanged: true,
|
|
530
|
+
newVersion: rootNewVersion,
|
|
531
|
+
newTag: rootNewTag,
|
|
532
|
+
dependenciesToBump: [],
|
|
533
|
+
});
|
|
615
534
|
|
|
616
|
-
|
|
535
|
+
logger.info(
|
|
536
|
+
`${currentVersion} -> ${newVersion}`,
|
|
537
|
+
// TODO Json only:
|
|
538
|
+
// {
|
|
539
|
+
// oldVersion: currentVersion,
|
|
540
|
+
// newVersion, },
|
|
541
|
+
);
|
|
542
|
+
}
|
|
617
543
|
|
|
618
|
-
|
|
619
|
-
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
620
|
-
spawnSync("yarn install", { cwd: options.cwd, stdio: "inherit" });
|
|
544
|
+
// do modifications
|
|
621
545
|
|
|
622
|
-
|
|
546
|
+
// Update yarn.lock ; must be done to make sure preversion script can be ran
|
|
547
|
+
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
548
|
+
spawnSync("yarn install", { cwd: options.cwd, stdio: "inherit" });
|
|
623
549
|
|
|
624
|
-
|
|
625
|
-
spawnSync("yarn run preversion", {
|
|
626
|
-
cwd: rootWorkspace.cwd,
|
|
627
|
-
stdio: "inherit",
|
|
628
|
-
});
|
|
629
|
-
}
|
|
550
|
+
logger.info("Lifecycle script: preversion");
|
|
630
551
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
552
|
+
if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.preversion) {
|
|
553
|
+
spawnSync("yarn run preversion", {
|
|
554
|
+
cwd: rootWorkspace.cwd,
|
|
555
|
+
stdio: "inherit",
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (!options.dryRun) {
|
|
560
|
+
// lifecycle: preversion
|
|
561
|
+
for (const workspace of bumpedWorkspaces.keys()) {
|
|
562
|
+
if (workspace.pkg.scripts?.preversion) {
|
|
563
|
+
spawnSync("yarn run preversion", {
|
|
564
|
+
cwd: workspace.cwd,
|
|
565
|
+
stdio: "inherit",
|
|
566
|
+
});
|
|
640
567
|
}
|
|
568
|
+
}
|
|
641
569
|
|
|
642
|
-
|
|
643
|
-
|
|
570
|
+
logger.info("Modifying versions in package.json");
|
|
571
|
+
// update versions
|
|
644
572
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
573
|
+
await Promise.all(
|
|
574
|
+
[...bumpedWorkspaces.entries()].map(
|
|
575
|
+
([workspace, { newVersion, dependenciesToBump }]) => {
|
|
576
|
+
workspace.pkg.version = newVersion;
|
|
649
577
|
|
|
650
|
-
|
|
651
|
-
|
|
578
|
+
for (const [
|
|
579
|
+
dependencyType,
|
|
580
|
+
dependencyDescriptor,
|
|
581
|
+
dependencyNewRange,
|
|
582
|
+
] of dependenciesToBump) {
|
|
583
|
+
const newDescriptor = PackageDependencyDescriptorUtils.make(
|
|
652
584
|
dependencyDescriptor,
|
|
653
585
|
dependencyNewRange,
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
const [key, newValue] =
|
|
660
|
-
PackageDependencyDescriptorUtils.stringify(newDescriptor);
|
|
661
|
-
workspace.pkg[dependencyType]![key] = newValue;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
return writePkg(workspace);
|
|
665
|
-
},
|
|
666
|
-
),
|
|
667
|
-
);
|
|
586
|
+
);
|
|
587
|
+
const [key, newValue] =
|
|
588
|
+
PackageDependencyDescriptorUtils.stringify(newDescriptor);
|
|
589
|
+
workspace.pkg[dependencyType]![key] = newValue;
|
|
590
|
+
}
|
|
668
591
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
stdio: "inherit",
|
|
674
|
-
});
|
|
592
|
+
return writePkg(workspace);
|
|
593
|
+
},
|
|
594
|
+
),
|
|
595
|
+
);
|
|
675
596
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
597
|
+
// Update yarn.lock ; must be done before running again lifecycle scripts
|
|
598
|
+
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
599
|
+
spawnSync("yarn install", {
|
|
600
|
+
cwd: options.cwd,
|
|
601
|
+
stdio: "inherit",
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
// lifecycle: version
|
|
605
|
+
logger.info("Lifecycle script: version");
|
|
606
|
+
for (const workspace of bumpedWorkspaces.keys()) {
|
|
607
|
+
if (workspace.pkg.scripts?.version) {
|
|
608
|
+
spawnSync("yarn run version", {
|
|
609
|
+
cwd: workspace.cwd,
|
|
610
|
+
stdio: "inherit",
|
|
611
|
+
});
|
|
685
612
|
}
|
|
686
613
|
}
|
|
614
|
+
}
|
|
687
615
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
616
|
+
if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.version) {
|
|
617
|
+
spawnSync("yarn run version", {
|
|
618
|
+
cwd: rootWorkspace.cwd,
|
|
619
|
+
stdio: "inherit",
|
|
620
|
+
});
|
|
621
|
+
}
|
|
694
622
|
|
|
695
|
-
|
|
623
|
+
const changelogs = new Map<Workspace, string>();
|
|
696
624
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
625
|
+
await Promise.all(
|
|
626
|
+
[...bumpedWorkspaces.entries()].map(
|
|
627
|
+
async ([
|
|
628
|
+
workspace,
|
|
629
|
+
{ newTag, hasChanged, bumpReason, bumpForDependenciesReasons },
|
|
630
|
+
]) => {
|
|
631
|
+
const workspaceRelativePath =
|
|
632
|
+
rootWorkspace === workspace
|
|
633
|
+
? undefined
|
|
634
|
+
: path.relative(rootWorkspace.cwd, workspace.cwd);
|
|
635
|
+
|
|
636
|
+
let changelog = await generateChangelog(
|
|
637
|
+
rootWorkspace,
|
|
638
|
+
workspace.pkg,
|
|
639
|
+
conventionalCommitConfig,
|
|
640
|
+
newTag,
|
|
641
|
+
{
|
|
642
|
+
path: workspaceRelativePath,
|
|
643
|
+
previousTag: previousTagByWorkspace.get(workspace),
|
|
644
|
+
verbose: options.verbose,
|
|
645
|
+
tagPrefix: options.tagVersionPrefix,
|
|
646
|
+
lernaPackage:
|
|
647
|
+
rootWorkspace === workspace || !isMonorepoVersionIndependent
|
|
648
|
+
? undefined
|
|
649
|
+
: getWorkspaceName(workspace),
|
|
650
|
+
},
|
|
651
|
+
);
|
|
724
652
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
653
|
+
if (changelog.slice(changelog.indexOf("\n")).trim().length === 0) {
|
|
654
|
+
changelog += "Note: no notable changes\n\n";
|
|
655
|
+
}
|
|
728
656
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
657
|
+
if (bumpForDependenciesReasons && workspace !== rootWorkspace) {
|
|
658
|
+
changelog += `${bumpForDependenciesReasons.join("\n")}\n\n`;
|
|
659
|
+
}
|
|
732
660
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
}
|
|
661
|
+
changelogs.set(workspace, changelog);
|
|
662
|
+
|
|
663
|
+
if (options.changelog) {
|
|
664
|
+
if (options.dryRun) {
|
|
665
|
+
logger.info(
|
|
666
|
+
`${getWorkspaceName(workspace)}: ${
|
|
667
|
+
options.changelog
|
|
668
|
+
}\n${changelog}`,
|
|
669
|
+
);
|
|
670
|
+
} else {
|
|
671
|
+
await updateChangelogFile(
|
|
672
|
+
changelog,
|
|
673
|
+
options.tagVersionPrefix,
|
|
674
|
+
`${workspace.cwd}/${options.changelog}`,
|
|
675
|
+
);
|
|
749
676
|
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
)
|
|
677
|
+
}
|
|
678
|
+
},
|
|
679
|
+
),
|
|
680
|
+
);
|
|
753
681
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
682
|
+
if (!options.dryRun) {
|
|
683
|
+
// TODO nightingale separator
|
|
684
|
+
console.log();
|
|
757
685
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
686
|
+
// install to update versions in lock file
|
|
687
|
+
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
688
|
+
spawnSync("yarn install", {
|
|
689
|
+
cwd: options.cwd,
|
|
690
|
+
stdio: "inherit",
|
|
691
|
+
});
|
|
764
692
|
|
|
765
|
-
|
|
766
|
-
|
|
693
|
+
// TODO nightingale separator
|
|
694
|
+
console.log();
|
|
767
695
|
|
|
768
|
-
|
|
696
|
+
logger.info("Commit, tag and push");
|
|
769
697
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
698
|
+
const tagsSet = new Set<string>(
|
|
699
|
+
[...bumpedWorkspaces.values()]
|
|
700
|
+
.map(({ newTag }) => newTag)
|
|
701
|
+
.filter((newTag) => newTag !== null) as string[],
|
|
702
|
+
);
|
|
775
703
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
704
|
+
const tagsInCommitMessage = [...tagsSet]
|
|
705
|
+
.map((tag) => `- ${tag}`)
|
|
706
|
+
.join("\n");
|
|
707
|
+
const message = options.commitMessage
|
|
708
|
+
.replace(/\\n/g, "\n")
|
|
709
|
+
.replace(
|
|
710
|
+
/%a/g,
|
|
711
|
+
isMonorepoVersionIndependent
|
|
712
|
+
? `\n\n${tagsInCommitMessage}`
|
|
713
|
+
: rootNewVersion,
|
|
714
|
+
)
|
|
715
|
+
.replace(/%s/g, rootNewTag)
|
|
716
|
+
.replace(/%v/g, rootNewVersion)
|
|
717
|
+
.replace(/%t/g, tagsInCommitMessage);
|
|
718
|
+
await createGitCommit(rootWorkspace, message);
|
|
719
|
+
|
|
720
|
+
for (const [workspace, { newTag }] of bumpedWorkspaces.entries()) {
|
|
721
|
+
if (newTag === null) continue;
|
|
722
|
+
await createGitTag(workspace, newTag);
|
|
723
|
+
}
|
|
796
724
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
725
|
+
if (
|
|
726
|
+
await isBehindRemote(rootWorkspace, options.gitRemote, gitCurrentBranch)
|
|
727
|
+
) {
|
|
728
|
+
logger.error("Remote is ahead, aborting");
|
|
729
|
+
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
730
|
+
process.exit(1);
|
|
731
|
+
}
|
|
804
732
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
733
|
+
// run postversion
|
|
734
|
+
if (rootWorkspace.pkg.scripts?.postversion) {
|
|
735
|
+
spawnSync("yarn run postversion", {
|
|
736
|
+
cwd: rootWorkspace.cwd,
|
|
737
|
+
stdio: "inherit",
|
|
738
|
+
});
|
|
739
|
+
}
|
|
812
740
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
741
|
+
await pushCommitsAndTags(
|
|
742
|
+
rootWorkspace,
|
|
743
|
+
options.gitRemote,
|
|
744
|
+
gitCurrentBranch,
|
|
745
|
+
);
|
|
818
746
|
|
|
819
|
-
|
|
747
|
+
// TODO open github PR
|
|
820
748
|
|
|
821
|
-
|
|
822
|
-
|
|
749
|
+
if (options.createRelease && githubClient && parsedRepoUrl) {
|
|
750
|
+
logger.info("Create git release");
|
|
823
751
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
);
|
|
834
|
-
return undefined;
|
|
835
|
-
}
|
|
836
|
-
return createGitRelease(
|
|
837
|
-
githubClient,
|
|
838
|
-
parsedRepoUrl,
|
|
839
|
-
newTag,
|
|
840
|
-
changelog,
|
|
841
|
-
!!options.prerelease,
|
|
752
|
+
await Promise.all(
|
|
753
|
+
[...bumpedWorkspaces.entries()].map(([workspace, { newTag }]) => {
|
|
754
|
+
if (newTag === null) return undefined;
|
|
755
|
+
const changelog = changelogs.get(workspace);
|
|
756
|
+
if (!changelog) {
|
|
757
|
+
logger.warn(
|
|
758
|
+
`No changelog found for workspace: ${getWorkspaceName(
|
|
759
|
+
workspace,
|
|
760
|
+
)}`,
|
|
842
761
|
);
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
762
|
+
return undefined;
|
|
763
|
+
}
|
|
764
|
+
return createGitRelease(
|
|
765
|
+
githubClient,
|
|
766
|
+
parsedRepoUrl,
|
|
767
|
+
newTag,
|
|
768
|
+
changelog,
|
|
769
|
+
!!options.prerelease,
|
|
770
|
+
);
|
|
771
|
+
}),
|
|
772
|
+
);
|
|
846
773
|
}
|
|
774
|
+
}
|
|
847
775
|
|
|
776
|
+
if (process.env.NODE_ENV !== "test") {
|
|
777
|
+
// issue in @conventional-changelog/git-client
|
|
848
778
|
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
849
779
|
process.exit(0);
|
|
850
|
-
}
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
export const Defaults: VersionCommandOptions = {
|
|
784
|
+
cwd: process.cwd(),
|
|
785
|
+
includesRoot: false,
|
|
786
|
+
dryRun: false,
|
|
787
|
+
json: false,
|
|
788
|
+
preset: "conventional-changelog-conventionalcommits",
|
|
789
|
+
tagVersionPrefix: "v",
|
|
790
|
+
changelog: "CHANGELOG.md",
|
|
791
|
+
commitMessage: "chore: release %a",
|
|
792
|
+
createRelease: false,
|
|
793
|
+
bumpDependentsHighestAs: "major",
|
|
794
|
+
alwaysBumpPeerDependencies: false,
|
|
795
|
+
gitRemote: "origin",
|
|
796
|
+
verbose: false,
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
export default program
|
|
800
|
+
.command("version")
|
|
801
|
+
.usage("Bump package version using conventional commit")
|
|
802
|
+
.addOption(
|
|
803
|
+
new Option("--includes-root", "Release root workspace [untested]").default(
|
|
804
|
+
Defaults.includesRoot,
|
|
805
|
+
),
|
|
806
|
+
)
|
|
807
|
+
.addOption(new Option("--cwd", "working directory").default(process.cwd()))
|
|
808
|
+
.addOption(
|
|
809
|
+
new Option(
|
|
810
|
+
"--dry-run",
|
|
811
|
+
"Print the versions without actually generating the package archive",
|
|
812
|
+
).default(Defaults.dryRun),
|
|
813
|
+
)
|
|
814
|
+
.addOption(new Option("-v,--verbose").default(Defaults.verbose))
|
|
815
|
+
.addOption(
|
|
816
|
+
new Option("--force <type>", "Specify the release type").choices([
|
|
817
|
+
"major",
|
|
818
|
+
"minor",
|
|
819
|
+
"patch",
|
|
820
|
+
]),
|
|
821
|
+
)
|
|
822
|
+
.addOption(
|
|
823
|
+
new Option(
|
|
824
|
+
"--prerelease [releaseType]",
|
|
825
|
+
"Add a prerelease identifier to new versions",
|
|
826
|
+
),
|
|
827
|
+
)
|
|
828
|
+
.addOption(
|
|
829
|
+
new Option(
|
|
830
|
+
"--preset <presetName>",
|
|
831
|
+
"Conventional Changelog preset to require. Defaults to conventional-changelog-conventionalcommits.",
|
|
832
|
+
).default("conventional-changelog-conventionalcommits"),
|
|
833
|
+
)
|
|
834
|
+
.addOption(
|
|
835
|
+
new Option("--tag-version-prefix <prefix>", "Tag version prefix").default(
|
|
836
|
+
Defaults.tagVersionPrefix,
|
|
837
|
+
),
|
|
838
|
+
)
|
|
839
|
+
.addOption(
|
|
840
|
+
new Option(
|
|
841
|
+
"--changelog <path>",
|
|
842
|
+
"Changelog path. Default to CHANGELOG.md.",
|
|
843
|
+
).default(Defaults.changelog),
|
|
844
|
+
)
|
|
845
|
+
.addOption(
|
|
846
|
+
new Option(
|
|
847
|
+
"-m,--commit-message <message>",
|
|
848
|
+
'Commit message. Default to "chore: release %a". You can use %v for the version, %s for the version with prefix, %t to list tags, %a for auto best display.',
|
|
849
|
+
).default(Defaults.commitMessage),
|
|
850
|
+
)
|
|
851
|
+
.addOption(
|
|
852
|
+
new Option("--create-release <type>", "Create a release").choices([
|
|
853
|
+
"github",
|
|
854
|
+
]),
|
|
855
|
+
)
|
|
856
|
+
.addOption(
|
|
857
|
+
new Option(
|
|
858
|
+
"--bump-dependents-highest-as <type>",
|
|
859
|
+
"Bump dependents highest version as major, minor or patch",
|
|
860
|
+
)
|
|
861
|
+
.choices(["major", "minor", "patch"])
|
|
862
|
+
.default(Defaults.bumpDependentsHighestAs),
|
|
863
|
+
)
|
|
864
|
+
.addOption(
|
|
865
|
+
new Option(
|
|
866
|
+
"--always-bump-peer-dependencies",
|
|
867
|
+
"Always bump peer dependencies. Default to bumping only if the version doesn't satisfies the peer dependency range.",
|
|
868
|
+
).default(Defaults.alwaysBumpPeerDependencies),
|
|
869
|
+
)
|
|
870
|
+
.addOption(
|
|
871
|
+
new Option(
|
|
872
|
+
"--git-remote <remote-name>",
|
|
873
|
+
"Git remote to push commits and tags to",
|
|
874
|
+
).default(Defaults.gitRemote),
|
|
875
|
+
)
|
|
876
|
+
.addOption(
|
|
877
|
+
new Option(
|
|
878
|
+
"--ignore-changes <glob>",
|
|
879
|
+
'Ignore changes in files matching the glob. Example: "**/*.test.js"',
|
|
880
|
+
),
|
|
881
|
+
)
|
|
882
|
+
.action((options) => versionCommandAction(options));
|