yarn-version 1.0.0-pre → 1.1.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 +118 -0
- package/README.md +161 -0
- package/build/index-node18.mjs +152 -114
- package/build/index-node18.mjs.map +1 -1
- package/package.json +10 -9
- 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 +691 -655
- package/src/utils/UsageError.ts +6 -1
- package/src/utils/conventionalChangelogUtils.ts +4 -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,787 @@ 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: changedWorkspace
|
|
460
|
+
? bumpReasons.slice(1)
|
|
461
|
+
: bumpReasons,
|
|
462
|
+
newVersion,
|
|
463
|
+
newTag: tagName,
|
|
464
|
+
hasChanged: changedWorkspace !== undefined,
|
|
465
|
+
dependenciesToBump,
|
|
466
|
+
});
|
|
533
467
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
// bumpReasons,
|
|
549
|
-
// });
|
|
550
|
-
}
|
|
468
|
+
logger.info(
|
|
469
|
+
`${workspaceName}: ${currentVersion} -> ${
|
|
470
|
+
!isMonorepo || isMonorepoVersionIndependent ? newVersion : "bump"
|
|
471
|
+
} (${bumpReason.replace("\n", " ; ")})`,
|
|
472
|
+
);
|
|
473
|
+
// TODO Json only:
|
|
474
|
+
// logger.info({
|
|
475
|
+
// cwd: npath.fromPortablePath(workspace.cwd),
|
|
476
|
+
// ident: workspaceName,
|
|
477
|
+
// oldVersion: currentVersion,
|
|
478
|
+
// ...(isMonorepoVersionIndependent ? { newVersion } : {}),
|
|
479
|
+
// bumpType,
|
|
480
|
+
// bumpReasons,
|
|
481
|
+
// });
|
|
551
482
|
}
|
|
552
483
|
}
|
|
553
484
|
}
|
|
485
|
+
}
|
|
554
486
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
487
|
+
// TODO ask for confirmation
|
|
488
|
+
// if (!this.yes) {
|
|
489
|
+
// }
|
|
558
490
|
|
|
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
|
-
);
|
|
491
|
+
// TODO do this entire phase here, not override for not independent only
|
|
492
|
+
if (isMonorepo && !isMonorepoVersionIndependent) {
|
|
493
|
+
const currentVersion = rootWorkspace.pkg.version!;
|
|
494
|
+
const highestBumpType = getHighestBumpType(
|
|
495
|
+
[...bumpedWorkspaces.values()].map(({ bumpType }) => bumpType),
|
|
496
|
+
);
|
|
497
|
+
const newVersion = incrementVersion(
|
|
498
|
+
rootWorkspace,
|
|
499
|
+
currentVersion,
|
|
500
|
+
highestBumpType,
|
|
501
|
+
);
|
|
502
|
+
rootNewVersion = newVersion;
|
|
503
|
+
rootNewTag = buildTagName(rootWorkspace, newVersion);
|
|
584
504
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
);
|
|
595
|
-
});
|
|
596
|
-
});
|
|
505
|
+
[...bumpedWorkspaces.entries()].forEach(([workspace, bumpedWorkspace]) => {
|
|
506
|
+
const isRoot = workspace === rootWorkspace;
|
|
507
|
+
if (isRoot) {
|
|
508
|
+
throw new Error("Unexpected root found in bumped workspaces");
|
|
509
|
+
}
|
|
510
|
+
bumpedWorkspace.bumpType = highestBumpType;
|
|
511
|
+
bumpedWorkspace.newVersion = newVersion;
|
|
512
|
+
bumpedWorkspace.newTag = null;
|
|
513
|
+
});
|
|
597
514
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
515
|
+
[
|
|
516
|
+
...bumpedWorkspaces.entries(),
|
|
517
|
+
...noVersionToUpdateWorkspaces.entries(),
|
|
518
|
+
].forEach(([workspace, { dependenciesToBump }]) => {
|
|
519
|
+
dependenciesToBump.forEach((dependencyToBump) => {
|
|
520
|
+
dependencyToBump[2] = calcBumpRange(
|
|
521
|
+
workspace,
|
|
522
|
+
dependencyToBump[1].selector,
|
|
523
|
+
newVersion,
|
|
524
|
+
);
|
|
605
525
|
});
|
|
526
|
+
});
|
|
606
527
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
528
|
+
bumpedWorkspaces.set(rootWorkspace, {
|
|
529
|
+
currentVersion,
|
|
530
|
+
bumpType: highestBumpType,
|
|
531
|
+
hasChanged: true,
|
|
532
|
+
newVersion: rootNewVersion,
|
|
533
|
+
newTag: rootNewTag,
|
|
534
|
+
dependenciesToBump: [],
|
|
535
|
+
});
|
|
615
536
|
|
|
616
|
-
|
|
537
|
+
logger.info(
|
|
538
|
+
`${currentVersion} -> ${newVersion}`,
|
|
539
|
+
// TODO Json only:
|
|
540
|
+
// {
|
|
541
|
+
// oldVersion: currentVersion,
|
|
542
|
+
// newVersion, },
|
|
543
|
+
);
|
|
544
|
+
}
|
|
617
545
|
|
|
618
|
-
|
|
619
|
-
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
620
|
-
spawnSync("yarn install", { cwd: options.cwd, stdio: "inherit" });
|
|
546
|
+
// do modifications
|
|
621
547
|
|
|
622
|
-
|
|
548
|
+
// Update yarn.lock ; must be done to make sure preversion script can be ran
|
|
549
|
+
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
550
|
+
spawnSync("yarn install", { cwd: options.cwd, stdio: "inherit" });
|
|
623
551
|
|
|
624
|
-
|
|
625
|
-
spawnSync("yarn run preversion", {
|
|
626
|
-
cwd: rootWorkspace.cwd,
|
|
627
|
-
stdio: "inherit",
|
|
628
|
-
});
|
|
629
|
-
}
|
|
552
|
+
logger.info("Lifecycle script: preversion");
|
|
630
553
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
554
|
+
if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.preversion) {
|
|
555
|
+
spawnSync("yarn run preversion", {
|
|
556
|
+
cwd: rootWorkspace.cwd,
|
|
557
|
+
stdio: "inherit",
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (!options.dryRun) {
|
|
562
|
+
// lifecycle: preversion
|
|
563
|
+
for (const workspace of bumpedWorkspaces.keys()) {
|
|
564
|
+
if (workspace.pkg.scripts?.preversion) {
|
|
565
|
+
spawnSync("yarn run preversion", {
|
|
566
|
+
cwd: workspace.cwd,
|
|
567
|
+
stdio: "inherit",
|
|
568
|
+
});
|
|
640
569
|
}
|
|
570
|
+
}
|
|
641
571
|
|
|
642
|
-
|
|
643
|
-
|
|
572
|
+
logger.info("Modifying versions in package.json");
|
|
573
|
+
// update versions
|
|
644
574
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
575
|
+
await Promise.all(
|
|
576
|
+
[...bumpedWorkspaces.entries()].map(
|
|
577
|
+
([workspace, { newVersion, dependenciesToBump }]) => {
|
|
578
|
+
workspace.pkg.version = newVersion;
|
|
649
579
|
|
|
650
|
-
|
|
651
|
-
|
|
580
|
+
for (const [
|
|
581
|
+
dependencyType,
|
|
582
|
+
dependencyDescriptor,
|
|
583
|
+
dependencyNewRange,
|
|
584
|
+
] of dependenciesToBump) {
|
|
585
|
+
const newDescriptor = PackageDependencyDescriptorUtils.make(
|
|
652
586
|
dependencyDescriptor,
|
|
653
587
|
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
|
-
);
|
|
588
|
+
);
|
|
589
|
+
const [key, newValue] =
|
|
590
|
+
PackageDependencyDescriptorUtils.stringify(newDescriptor);
|
|
591
|
+
workspace.pkg[dependencyType]![key] = newValue;
|
|
592
|
+
}
|
|
668
593
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
stdio: "inherit",
|
|
674
|
-
});
|
|
594
|
+
return writePkg(workspace);
|
|
595
|
+
},
|
|
596
|
+
),
|
|
597
|
+
);
|
|
675
598
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
599
|
+
// Update yarn.lock ; must be done before running again lifecycle scripts
|
|
600
|
+
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
601
|
+
spawnSync("yarn install", {
|
|
602
|
+
cwd: options.cwd,
|
|
603
|
+
stdio: "inherit",
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
// lifecycle: version
|
|
607
|
+
logger.info("Lifecycle script: version");
|
|
608
|
+
for (const workspace of bumpedWorkspaces.keys()) {
|
|
609
|
+
if (workspace.pkg.scripts?.version) {
|
|
610
|
+
spawnSync("yarn run version", {
|
|
611
|
+
cwd: workspace.cwd,
|
|
612
|
+
stdio: "inherit",
|
|
613
|
+
});
|
|
685
614
|
}
|
|
686
615
|
}
|
|
616
|
+
}
|
|
687
617
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
618
|
+
if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.version) {
|
|
619
|
+
spawnSync("yarn run version", {
|
|
620
|
+
cwd: rootWorkspace.cwd,
|
|
621
|
+
stdio: "inherit",
|
|
622
|
+
});
|
|
623
|
+
}
|
|
694
624
|
|
|
695
|
-
|
|
625
|
+
const changelogs = new Map<Workspace, string>();
|
|
696
626
|
|
|
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
|
-
|
|
627
|
+
await Promise.all(
|
|
628
|
+
[...bumpedWorkspaces.entries()].map(
|
|
629
|
+
async ([
|
|
630
|
+
workspace,
|
|
631
|
+
{ newTag, hasChanged, bumpReason, bumpForDependenciesReasons },
|
|
632
|
+
]) => {
|
|
633
|
+
const workspaceRelativePath =
|
|
634
|
+
rootWorkspace === workspace
|
|
635
|
+
? undefined
|
|
636
|
+
: path.relative(rootWorkspace.cwd, workspace.cwd);
|
|
637
|
+
|
|
638
|
+
let changelog = await generateChangelog(
|
|
639
|
+
rootWorkspace,
|
|
640
|
+
workspace.pkg,
|
|
641
|
+
conventionalCommitConfig,
|
|
642
|
+
newTag,
|
|
643
|
+
{
|
|
644
|
+
path: workspaceRelativePath,
|
|
645
|
+
previousTag: previousTagByWorkspace.get(workspace),
|
|
646
|
+
verbose: options.verbose,
|
|
647
|
+
tagPrefix: options.tagVersionPrefix,
|
|
648
|
+
lernaPackage:
|
|
649
|
+
rootWorkspace === workspace || !isMonorepoVersionIndependent
|
|
650
|
+
? undefined
|
|
651
|
+
: getWorkspaceName(workspace),
|
|
652
|
+
},
|
|
653
|
+
);
|
|
724
654
|
|
|
725
|
-
|
|
726
|
-
|
|
655
|
+
if (bumpForDependenciesReasons && workspace !== rootWorkspace) {
|
|
656
|
+
if (bumpForDependenciesReasons.length > 0) {
|
|
657
|
+
changelog += `${!changelog.endsWith("\n\n") ? "\n" : ""}${bumpForDependenciesReasons.join("\n")}\n\n`;
|
|
727
658
|
}
|
|
659
|
+
}
|
|
728
660
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
661
|
+
if (changelog.slice(changelog.indexOf("\n")).trim().length === 0) {
|
|
662
|
+
changelog += `${!changelog.endsWith("\n\n") ? "\n" : ""}Note: no notable changes\n\n`;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
changelogs.set(workspace, changelog);
|
|
732
666
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
`${workspace.cwd}/${options.changelog}`,
|
|
747
|
-
);
|
|
748
|
-
}
|
|
667
|
+
if (options.changelog) {
|
|
668
|
+
if (options.dryRun) {
|
|
669
|
+
logger.info(
|
|
670
|
+
`${getWorkspaceName(workspace)}: ${
|
|
671
|
+
options.changelog
|
|
672
|
+
}\n${changelog}`,
|
|
673
|
+
);
|
|
674
|
+
} else {
|
|
675
|
+
await updateChangelogFile(
|
|
676
|
+
changelog,
|
|
677
|
+
options.tagVersionPrefix,
|
|
678
|
+
`${workspace.cwd}/${options.changelog}`,
|
|
679
|
+
);
|
|
749
680
|
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
)
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
),
|
|
684
|
+
);
|
|
753
685
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
686
|
+
if (!options.dryRun) {
|
|
687
|
+
// TODO nightingale separator
|
|
688
|
+
console.log();
|
|
757
689
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
690
|
+
// install to update versions in lock file
|
|
691
|
+
logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
|
|
692
|
+
spawnSync("yarn install", {
|
|
693
|
+
cwd: options.cwd,
|
|
694
|
+
stdio: "inherit",
|
|
695
|
+
});
|
|
764
696
|
|
|
765
|
-
|
|
766
|
-
|
|
697
|
+
// TODO nightingale separator
|
|
698
|
+
console.log();
|
|
767
699
|
|
|
768
|
-
|
|
700
|
+
logger.info("Commit, tag and push");
|
|
769
701
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
702
|
+
const tagsSet = new Set<string>(
|
|
703
|
+
[...bumpedWorkspaces.values()]
|
|
704
|
+
.map(({ newTag }) => newTag)
|
|
705
|
+
.filter((newTag) => newTag !== null) as string[],
|
|
706
|
+
);
|
|
775
707
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
708
|
+
const tagsInCommitMessage = [...tagsSet]
|
|
709
|
+
.map((tag) => `- ${tag}`)
|
|
710
|
+
.join("\n");
|
|
711
|
+
const message = options.commitMessage
|
|
712
|
+
.replace(/\\n/g, "\n")
|
|
713
|
+
.replace(
|
|
714
|
+
/%a/g,
|
|
715
|
+
isMonorepoVersionIndependent
|
|
716
|
+
? `\n\n${tagsInCommitMessage}`
|
|
717
|
+
: rootNewVersion,
|
|
718
|
+
)
|
|
719
|
+
.replace(/%s/g, rootNewTag)
|
|
720
|
+
.replace(/%v/g, rootNewVersion)
|
|
721
|
+
.replace(/%t/g, tagsInCommitMessage);
|
|
722
|
+
await createGitCommit(rootWorkspace, message);
|
|
723
|
+
|
|
724
|
+
for (const [workspace, { newTag }] of bumpedWorkspaces.entries()) {
|
|
725
|
+
if (newTag === null) continue;
|
|
726
|
+
await createGitTag(workspace, newTag);
|
|
727
|
+
}
|
|
796
728
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
729
|
+
if (
|
|
730
|
+
await isBehindRemote(rootWorkspace, options.gitRemote, gitCurrentBranch)
|
|
731
|
+
) {
|
|
732
|
+
logger.error("Remote is ahead, aborting");
|
|
733
|
+
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
734
|
+
process.exit(1);
|
|
735
|
+
}
|
|
804
736
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
737
|
+
// run postversion
|
|
738
|
+
if (rootWorkspace.pkg.scripts?.postversion) {
|
|
739
|
+
spawnSync("yarn run postversion", {
|
|
740
|
+
cwd: rootWorkspace.cwd,
|
|
741
|
+
stdio: "inherit",
|
|
742
|
+
});
|
|
743
|
+
}
|
|
812
744
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
745
|
+
await pushCommitsAndTags(
|
|
746
|
+
rootWorkspace,
|
|
747
|
+
options.gitRemote,
|
|
748
|
+
gitCurrentBranch,
|
|
749
|
+
);
|
|
818
750
|
|
|
819
|
-
|
|
751
|
+
// TODO open github PR
|
|
820
752
|
|
|
821
|
-
|
|
822
|
-
|
|
753
|
+
if (options.createRelease && githubClient && parsedRepoUrl) {
|
|
754
|
+
logger.info("Create git release");
|
|
823
755
|
|
|
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,
|
|
756
|
+
await Promise.all(
|
|
757
|
+
[...bumpedWorkspaces.entries()].map(([workspace, { newTag }]) => {
|
|
758
|
+
if (newTag === null) return undefined;
|
|
759
|
+
const changelog = changelogs.get(workspace);
|
|
760
|
+
if (!changelog) {
|
|
761
|
+
logger.warn(
|
|
762
|
+
`No changelog found for workspace: ${getWorkspaceName(
|
|
763
|
+
workspace,
|
|
764
|
+
)}`,
|
|
842
765
|
);
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
return createGitRelease(
|
|
769
|
+
githubClient,
|
|
770
|
+
parsedRepoUrl,
|
|
771
|
+
newTag,
|
|
772
|
+
changelog,
|
|
773
|
+
!!options.prerelease,
|
|
774
|
+
);
|
|
775
|
+
}),
|
|
776
|
+
);
|
|
846
777
|
}
|
|
778
|
+
}
|
|
847
779
|
|
|
780
|
+
if (process.env.NODE_ENV !== "test") {
|
|
781
|
+
// issue in @conventional-changelog/git-client
|
|
848
782
|
// eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
|
|
849
783
|
process.exit(0);
|
|
850
|
-
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
export const Defaults: VersionCommandOptions = {
|
|
788
|
+
cwd: process.cwd(),
|
|
789
|
+
includesRoot: false,
|
|
790
|
+
dryRun: false,
|
|
791
|
+
json: false,
|
|
792
|
+
preset: "conventional-changelog-conventionalcommits",
|
|
793
|
+
tagVersionPrefix: "v",
|
|
794
|
+
changelog: "CHANGELOG.md",
|
|
795
|
+
commitMessage: "chore: release %a",
|
|
796
|
+
createRelease: false,
|
|
797
|
+
bumpDependentsHighestAs: "major",
|
|
798
|
+
alwaysBumpPeerDependencies: false,
|
|
799
|
+
gitRemote: "origin",
|
|
800
|
+
verbose: false,
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
export default program
|
|
804
|
+
.command("version")
|
|
805
|
+
.usage("Bump package version using conventional commit")
|
|
806
|
+
.addOption(
|
|
807
|
+
new Option("--includes-root", "Release root workspace [untested]").default(
|
|
808
|
+
Defaults.includesRoot,
|
|
809
|
+
),
|
|
810
|
+
)
|
|
811
|
+
.addOption(new Option("--cwd", "working directory").default(process.cwd()))
|
|
812
|
+
.addOption(
|
|
813
|
+
new Option(
|
|
814
|
+
"--dry-run",
|
|
815
|
+
"Print the versions without actually generating the package archive",
|
|
816
|
+
).default(Defaults.dryRun),
|
|
817
|
+
)
|
|
818
|
+
.addOption(new Option("-v,--verbose").default(Defaults.verbose))
|
|
819
|
+
.addOption(
|
|
820
|
+
new Option("--force <type>", "Specify the release type").choices([
|
|
821
|
+
"major",
|
|
822
|
+
"minor",
|
|
823
|
+
"patch",
|
|
824
|
+
]),
|
|
825
|
+
)
|
|
826
|
+
.addOption(
|
|
827
|
+
new Option(
|
|
828
|
+
"--prerelease [releaseType]",
|
|
829
|
+
"Add a prerelease identifier to new versions",
|
|
830
|
+
),
|
|
831
|
+
)
|
|
832
|
+
.addOption(
|
|
833
|
+
new Option(
|
|
834
|
+
"--preset <presetName>",
|
|
835
|
+
"Conventional Changelog preset to require. Defaults to conventional-changelog-conventionalcommits.",
|
|
836
|
+
).default("conventional-changelog-conventionalcommits"),
|
|
837
|
+
)
|
|
838
|
+
.addOption(
|
|
839
|
+
new Option("--tag-version-prefix <prefix>", "Tag version prefix").default(
|
|
840
|
+
Defaults.tagVersionPrefix,
|
|
841
|
+
),
|
|
842
|
+
)
|
|
843
|
+
.addOption(
|
|
844
|
+
new Option(
|
|
845
|
+
"--changelog <path>",
|
|
846
|
+
"Changelog path. Default to CHANGELOG.md.",
|
|
847
|
+
).default(Defaults.changelog),
|
|
848
|
+
)
|
|
849
|
+
.addOption(
|
|
850
|
+
new Option(
|
|
851
|
+
"-m,--commit-message <message>",
|
|
852
|
+
'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.',
|
|
853
|
+
).default(Defaults.commitMessage),
|
|
854
|
+
)
|
|
855
|
+
.addOption(
|
|
856
|
+
new Option("--create-release <type>", "Create a release").choices([
|
|
857
|
+
"github",
|
|
858
|
+
]),
|
|
859
|
+
)
|
|
860
|
+
.addOption(
|
|
861
|
+
new Option(
|
|
862
|
+
"--bump-dependents-highest-as <type>",
|
|
863
|
+
"Bump dependents highest version as major, minor or patch",
|
|
864
|
+
)
|
|
865
|
+
.choices(["major", "minor", "patch"])
|
|
866
|
+
.default(Defaults.bumpDependentsHighestAs),
|
|
867
|
+
)
|
|
868
|
+
.addOption(
|
|
869
|
+
new Option(
|
|
870
|
+
"--always-bump-peer-dependencies",
|
|
871
|
+
"Always bump peer dependencies. Default to bumping only if the version doesn't satisfies the peer dependency range.",
|
|
872
|
+
).default(Defaults.alwaysBumpPeerDependencies),
|
|
873
|
+
)
|
|
874
|
+
.addOption(
|
|
875
|
+
new Option(
|
|
876
|
+
"--git-remote <remote-name>",
|
|
877
|
+
"Git remote to push commits and tags to",
|
|
878
|
+
).default(Defaults.gitRemote),
|
|
879
|
+
)
|
|
880
|
+
.addOption(
|
|
881
|
+
new Option(
|
|
882
|
+
"--ignore-changes <glob>",
|
|
883
|
+
'Ignore changes in files matching the glob. Example: "**/*.test.js"',
|
|
884
|
+
),
|
|
885
|
+
)
|
|
886
|
+
.action((options) => versionCommandAction(options));
|