nx 17.0.3 → 17.0.5
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/LICENSE +1 -1
- package/README.md +9 -4
- package/bin/init-local.js +10 -60
- package/bin/nx-cloud.js +6 -0
- package/bin/nx.js +1 -9
- package/bin/post-install.js +5 -1
- package/bin/run-executor.js +1 -1
- package/migrations.json +18 -0
- package/package.json +21 -18
- package/plugins/package-json.js +1 -1
- package/{changelog-renderer → release/changelog-renderer}/index.d.ts +18 -3
- package/{changelog-renderer → release/changelog-renderer}/index.js +78 -34
- package/release/index.d.ts +4 -0
- package/release/index.js +11 -0
- package/schemas/nx-schema.json +203 -19
- package/schemas/project-schema.json +20 -0
- package/src/adapter/angular-json.js +28 -18
- package/src/adapter/compat.d.ts +2 -2
- package/src/adapter/compat.js +6 -1
- package/src/adapter/ngcli-adapter.d.ts +16 -4
- package/src/adapter/ngcli-adapter.js +85 -28
- package/src/command-line/add/add.d.ts +2 -0
- package/src/command-line/add/add.js +169 -0
- package/src/command-line/add/command-object.d.ts +7 -0
- package/src/command-line/add/command-object.js +24 -0
- package/src/command-line/affected/affected.js +0 -3
- package/src/command-line/affected/command-object.d.ts +4 -4
- package/src/command-line/affected/command-object.js +53 -26
- package/src/command-line/affected/print-affected.js +10 -1
- package/src/command-line/connect/command-object.d.ts +1 -2
- package/src/command-line/connect/command-object.js +3 -7
- package/src/command-line/connect/connect-to-nx-cloud.d.ts +4 -5
- package/src/command-line/connect/connect-to-nx-cloud.js +43 -31
- package/src/command-line/connect/view-logs.js +5 -21
- package/src/command-line/examples.js +18 -0
- package/src/command-line/exec/command-object.js +2 -1
- package/src/command-line/exec/exec.d.ts +1 -1
- package/src/command-line/exec/exec.js +78 -35
- package/src/command-line/format/format.js +13 -4
- package/src/command-line/generate/generate.js +9 -9
- package/src/command-line/generate/generator-utils.d.ts +3 -2
- package/src/command-line/generate/generator-utils.js +5 -5
- package/src/command-line/graph/graph.d.ts +1 -1
- package/src/command-line/graph/graph.js +82 -37
- package/src/command-line/init/command-object.js +70 -43
- package/src/command-line/init/implementation/add-nx-to-monorepo.d.ts +4 -2
- package/src/command-line/init/implementation/add-nx-to-monorepo.js +11 -2
- package/src/command-line/init/implementation/add-nx-to-nest.d.ts +1 -1
- package/src/command-line/init/implementation/add-nx-to-nest.js +9 -6
- package/src/command-line/init/implementation/add-nx-to-npm-repo.d.ts +4 -2
- package/src/command-line/init/implementation/add-nx-to-npm-repo.js +14 -4
- package/src/command-line/init/implementation/angular/index.js +4 -1
- package/src/command-line/init/implementation/angular/legacy-angular-versions.js +10 -5
- package/src/command-line/init/implementation/angular/standalone-workspace.js +1 -1
- package/src/command-line/init/implementation/angular/types.d.ts +1 -1
- package/src/command-line/init/implementation/dot-nx/nxw.js +47 -16
- package/src/command-line/init/implementation/react/index.d.ts +1 -1
- package/src/command-line/init/implementation/react/index.js +4 -2
- package/src/command-line/init/implementation/react/rename-js-to-jsx.js +4 -2
- package/src/command-line/init/implementation/utils.d.ts +5 -5
- package/src/command-line/init/implementation/utils.js +46 -44
- package/src/command-line/init/{init.js → init-v1.js} +5 -13
- package/src/command-line/init/init-v2.d.ts +7 -0
- package/src/command-line/init/init-v2.js +201 -0
- package/src/command-line/list/list.js +6 -5
- package/src/command-line/migrate/command-object.js +19 -4
- package/src/command-line/migrate/migrate.js +21 -17
- package/src/command-line/new/new.js +1 -1
- package/src/command-line/nx-commands.js +4 -1
- package/src/command-line/release/changelog.d.ts +22 -1
- package/src/command-line/release/changelog.js +459 -257
- package/src/command-line/release/command-object.d.ts +29 -7
- package/src/command-line/release/command-object.js +120 -20
- package/src/command-line/release/config/config.d.ts +26 -21
- package/src/command-line/release/config/config.js +416 -59
- package/src/command-line/release/config/conventional-commits.d.ts +2 -0
- package/src/command-line/release/config/conventional-commits.js +98 -0
- package/src/command-line/release/config/filter-release-groups.d.ts +1 -2
- package/src/command-line/release/config/filter-release-groups.js +38 -1
- package/src/command-line/release/index.d.ts +16 -0
- package/src/command-line/release/index.js +23 -0
- package/src/command-line/release/publish.d.ts +7 -3
- package/src/command-line/release/publish.js +89 -37
- package/src/command-line/release/release.d.ts +4 -0
- package/src/command-line/release/release.js +176 -0
- package/src/command-line/release/utils/batch-projects-by-generator-config.d.ts +7 -0
- package/src/command-line/release/utils/batch-projects-by-generator-config.js +37 -0
- package/src/command-line/release/utils/exec-command.d.ts +1 -0
- package/src/command-line/release/utils/exec-command.js +34 -0
- package/src/command-line/release/utils/git.d.ts +34 -1
- package/src/command-line/release/utils/git.js +238 -34
- package/src/command-line/release/utils/github.d.ts +5 -5
- package/src/command-line/release/utils/github.js +155 -8
- package/src/command-line/release/utils/markdown.js +6 -1
- package/src/command-line/release/utils/print-changes.d.ts +1 -1
- package/src/command-line/release/utils/print-changes.js +3 -3
- package/src/command-line/release/utils/resolve-nx-json-error-message.js +4 -1
- package/src/command-line/release/utils/resolve-semver-specifier.d.ts +4 -0
- package/src/command-line/release/utils/resolve-semver-specifier.js +58 -0
- package/src/command-line/release/utils/semver.d.ts +8 -0
- package/src/command-line/release/utils/semver.js +30 -1
- package/src/command-line/release/utils/shared.d.ts +39 -0
- package/src/command-line/release/utils/shared.js +213 -0
- package/src/command-line/release/version.d.ts +37 -3
- package/src/command-line/release/version.js +312 -117
- package/src/command-line/repair/repair.js +13 -9
- package/src/command-line/report/report.d.ts +3 -0
- package/src/command-line/report/report.js +22 -5
- package/src/command-line/run/command-object.d.ts +4 -0
- package/src/command-line/run/command-object.js +18 -2
- package/src/command-line/run/executor-utils.d.ts +2 -1
- package/src/command-line/run/executor-utils.js +4 -4
- package/src/command-line/run/run-one.js +3 -6
- package/src/command-line/run/run.js +34 -9
- package/src/command-line/run-many/command-object.js +4 -1
- package/src/command-line/run-many/run-many.js +0 -3
- package/src/command-line/show/command-object.d.ts +3 -0
- package/src/command-line/show/command-object.js +29 -2
- package/src/command-line/show/show.js +9 -0
- package/src/command-line/yargs-utils/shared-options.d.ts +4 -1
- package/src/command-line/yargs-utils/shared-options.js +23 -9
- package/src/commands-runner/command-graph.d.ts +13 -0
- package/src/commands-runner/command-graph.js +2 -0
- package/src/commands-runner/create-command-graph.d.ts +4 -0
- package/src/commands-runner/create-command-graph.js +44 -0
- package/src/commands-runner/get-command-projects.d.ts +3 -0
- package/src/commands-runner/get-command-projects.js +19 -0
- package/src/config/nx-json.d.ts +160 -25
- package/src/config/project-graph.d.ts +3 -3
- package/src/config/workspace-json-project-json.d.ts +23 -1
- package/src/config/workspaces.d.ts +1 -1
- package/src/config/workspaces.js +4 -6
- package/src/core/graph/3rdpartylicenses.txt +144 -74
- package/src/core/graph/environment.js +1 -1
- package/src/core/graph/index.html +4 -6
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/runtime.js +1 -1
- package/src/core/graph/styles.css +3 -3
- package/src/core/graph/styles.js +1 -1
- package/src/daemon/client/client.d.ts +5 -1
- package/src/daemon/client/client.js +27 -8
- package/src/daemon/client/{socket-messenger.d.ts → daemon-socket-messenger.d.ts} +1 -1
- package/src/daemon/client/{socket-messenger.js → daemon-socket-messenger.js} +3 -3
- package/src/daemon/daemon-project-graph-error.d.ts +8 -0
- package/src/daemon/daemon-project-graph-error.js +13 -0
- package/src/daemon/server/handle-hash-tasks.js +12 -2
- package/src/daemon/server/handle-request-project-graph.js +1 -1
- package/src/daemon/server/project-graph-incremental-recomputation.d.ts +14 -13
- package/src/daemon/server/project-graph-incremental-recomputation.js +98 -33
- package/src/daemon/server/shutdown-utils.js +2 -4
- package/src/daemon/server/watcher.js +0 -3
- package/src/daemon/socket-utils.d.ts +2 -1
- package/src/daemon/socket-utils.js +15 -4
- package/src/daemon/tmp-dir.d.ts +1 -0
- package/src/daemon/tmp-dir.js +4 -4
- package/src/devkit-exports.d.ts +2 -2
- package/src/devkit-exports.js +3 -2
- package/src/devkit-internals.d.ts +3 -0
- package/src/devkit-internals.js +7 -1
- package/src/executors/noop/schema.json +1 -1
- package/src/executors/run-commands/run-commands.impl.d.ts +10 -2
- package/src/executors/run-commands/run-commands.impl.js +152 -48
- package/src/executors/run-commands/schema.json +11 -1
- package/src/executors/run-script/run-script.impl.js +43 -11
- package/src/executors/utils/convert-nx-executor.js +1 -1
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.d.ts +3 -1
- package/src/generators/internal-utils/format-changed-files-with-prettier-if-available.js +4 -2
- package/src/generators/testing-utils/create-tree-with-empty-workspace.js +0 -6
- package/src/generators/tree.d.ts +1 -0
- package/src/generators/utils/glob.js +2 -2
- package/src/generators/utils/project-configuration.js +28 -9
- package/src/hasher/create-task-hasher.d.ts +4 -0
- package/src/hasher/create-task-hasher.js +16 -0
- package/src/hasher/hash-task.js +9 -3
- package/src/hasher/native-task-hasher-impl.d.ts +19 -0
- package/src/hasher/native-task-hasher-impl.js +37 -0
- package/src/hasher/node-task-hasher-impl.d.ts +49 -0
- package/src/hasher/node-task-hasher-impl.js +431 -0
- package/src/hasher/task-hasher.d.ts +33 -21
- package/src/hasher/task-hasher.js +30 -428
- package/src/migrations/update-15-0-0/migrate-to-inputs.js +5 -5
- package/src/migrations/update-15-1-0/set-project-names.js +2 -1
- package/src/migrations/update-15-8-2/update-nxw.js +2 -6
- package/src/migrations/update-17-0-0/rm-default-collection-npm-scope.js +3 -3
- package/src/migrations/update-17-0-0/use-minimal-config-for-tasks-runner-options.js +49 -13
- package/src/migrations/update-17-2-0/move-default-base.d.ts +5 -0
- package/src/migrations/update-17-2-0/move-default-base.js +21 -0
- package/src/migrations/update-17-3-0/nx-release-path.d.ts +3 -0
- package/src/migrations/update-17-3-0/nx-release-path.js +48 -0
- package/src/migrations/update-17-3-0/update-nxw.d.ts +2 -0
- package/src/migrations/update-17-3-0/update-nxw.js +7 -0
- package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.d.ts +2 -0
- package/src/migrations/update-18-0-0/disable-crystal-for-existing-workspaces.js +9 -0
- package/src/native/index.d.ts +65 -15
- package/src/native/index.js +6 -2
- package/src/native/transform-objects.js +2 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.d.ts +1 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +13 -12
- package/src/nx-cloud/generators/connect-to-nx-cloud/schema.json +6 -1
- package/src/nx-cloud/update-manager.js +2 -1
- package/src/plugins/js/index.d.ts +1 -1
- package/src/plugins/js/index.js +3 -3
- package/src/plugins/js/lock-file/lock-file.d.ts +2 -2
- package/src/plugins/js/lock-file/lock-file.js +15 -3
- package/src/plugins/js/package-json/create-package-json.js +1 -1
- package/src/plugins/js/project-graph/build-dependencies/strip-source-code.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/strip-source-code.js +1 -1
- package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.d.ts +1 -1
- package/src/plugins/js/project-graph/build-dependencies/typescript-import-locator.js +1 -1
- package/src/plugins/js/utils/register.d.ts +1 -1
- package/src/plugins/js/utils/register.js +28 -8
- package/src/plugins/js/versions.d.ts +1 -1
- package/src/plugins/js/versions.js +1 -1
- package/{plugins/package-json-workspaces.d.ts → src/plugins/package-json-workspaces/create-nodes.d.ts} +4 -4
- package/{plugins/package-json-workspaces.js → src/plugins/package-json-workspaces/create-nodes.js} +34 -12
- package/src/plugins/package-json-workspaces/index.d.ts +1 -0
- package/src/plugins/package-json-workspaces/index.js +4 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.d.ts +2 -0
- package/src/plugins/project-json/build-nodes/package-json-next-to-project-json.js +47 -0
- package/src/plugins/project-json/build-nodes/project-json.d.ts +2 -5
- package/src/plugins/project-json/build-nodes/project-json.js +6 -44
- package/src/plugins/target-defaults/target-defaults-plugin.d.ts +66 -0
- package/src/plugins/target-defaults/target-defaults-plugin.js +182 -0
- package/src/project-graph/affected/locators/project-glob-changes.js +3 -3
- package/src/project-graph/affected/locators/workspace-projects.d.ts +0 -2
- package/src/project-graph/affected/locators/workspace-projects.js +16 -29
- package/src/project-graph/build-project-graph.d.ts +20 -1
- package/src/project-graph/build-project-graph.js +91 -33
- package/src/project-graph/file-map-utils.d.ts +9 -5
- package/src/project-graph/file-map-utils.js +16 -63
- package/src/project-graph/file-utils.d.ts +1 -1
- package/src/project-graph/file-utils.js +44 -2
- package/src/project-graph/nx-deps-cache.js +1 -1
- package/src/project-graph/project-graph-builder.d.ts +1 -1
- package/src/project-graph/project-graph-builder.js +1 -1
- package/src/project-graph/project-graph.d.ts +32 -1
- package/src/project-graph/project-graph.js +147 -23
- package/src/project-graph/utils/build-all-workspace-files.d.ts +2 -0
- package/src/project-graph/utils/build-all-workspace-files.js +15 -0
- package/src/project-graph/utils/normalize-project-nodes.d.ts +2 -3
- package/src/project-graph/utils/normalize-project-nodes.js +7 -33
- package/src/project-graph/utils/project-configuration-utils.d.ts +66 -4
- package/src/project-graph/utils/project-configuration-utils.js +509 -62
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +12 -31
- package/src/project-graph/utils/retrieve-workspace-files.js +27 -90
- package/src/tasks-runner/batch/run-batch.js +3 -3
- package/src/tasks-runner/cache.js +6 -3
- package/src/tasks-runner/create-task-graph.js +1 -1
- package/src/tasks-runner/fork.d.ts +1 -0
- package/src/tasks-runner/fork.js +23 -0
- package/src/tasks-runner/forked-process-task-runner.d.ts +13 -5
- package/src/tasks-runner/forked-process-task-runner.js +112 -21
- package/src/tasks-runner/init-tasks-runner.js +1 -1
- package/src/tasks-runner/life-cycles/dynamic-run-many-terminal-output-life-cycle.js +28 -28
- package/src/tasks-runner/life-cycles/dynamic-run-one-terminal-output-life-cycle.js +19 -22
- package/src/tasks-runner/life-cycles/empty-terminal-output-life-cycle.js +1 -3
- package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +1 -3
- package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js +2 -4
- package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +1 -0
- package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js +11 -5
- package/src/tasks-runner/life-cycles/view-logs-utils.js +1 -1
- package/src/tasks-runner/pseudo-ipc.d.ts +49 -0
- package/src/tasks-runner/pseudo-ipc.js +140 -0
- package/src/tasks-runner/pseudo-terminal.d.ts +43 -0
- package/src/tasks-runner/pseudo-terminal.js +159 -0
- package/src/tasks-runner/run-command.d.ts +1 -1
- package/src/tasks-runner/run-command.js +13 -19
- package/src/tasks-runner/task-env.js +1 -2
- package/src/tasks-runner/task-graph-utils.d.ts +7 -3
- package/src/tasks-runner/task-graph-utils.js +15 -15
- package/src/tasks-runner/task-orchestrator.js +68 -12
- package/src/tasks-runner/tasks-schedule.js +3 -3
- package/src/tasks-runner/utils.d.ts +16 -7
- package/src/tasks-runner/utils.js +30 -16
- package/src/utils/ab-testing.d.ts +36 -2
- package/src/utils/ab-testing.js +34 -16
- package/src/utils/assert-workspace-validity.js +1 -1
- package/src/utils/cache-directory.d.ts +1 -0
- package/src/utils/cache-directory.js +5 -1
- package/src/utils/child-process.d.ts +15 -1
- package/src/utils/child-process.js +91 -1
- package/src/utils/command-line-utils.js +2 -1
- package/src/utils/exit-codes.d.ts +6 -0
- package/src/utils/exit-codes.js +20 -0
- package/src/utils/fileutils.d.ts +1 -0
- package/src/utils/find-matching-projects.js +5 -5
- package/src/utils/find-workspace-root.js +1 -0
- package/src/utils/ignore.js +8 -1
- package/src/utils/json-diff.d.ts +1 -0
- package/src/utils/json-diff.js +2 -1
- package/src/utils/json.js +3 -1
- package/src/utils/logger.js +1 -1
- package/src/utils/nx-cloud-utils.d.ts +1 -1
- package/src/utils/nx-cloud-utils.js +9 -4
- package/src/utils/nx-plugin.d.ts +32 -15
- package/src/utils/nx-plugin.deprecated.d.ts +10 -5
- package/src/utils/nx-plugin.deprecated.js +23 -0
- package/src/utils/nx-plugin.js +71 -80
- package/src/utils/output.d.ts +4 -2
- package/src/utils/output.js +44 -9
- package/src/utils/package-json.d.ts +4 -4
- package/src/utils/package-json.js +18 -12
- package/src/utils/package-manager.d.ts +7 -0
- package/src/utils/package-manager.js +24 -4
- package/src/utils/params.d.ts +12 -4
- package/src/utils/params.js +37 -4
- package/src/utils/plugins/core-plugins.js +8 -0
- package/src/utils/plugins/installed-plugins.d.ts +2 -1
- package/src/utils/plugins/installed-plugins.js +2 -2
- package/src/utils/plugins/local-plugins.js +1 -1
- package/src/utils/plugins/plugin-capabilities.d.ts +3 -2
- package/src/utils/plugins/plugin-capabilities.js +7 -7
- package/src/utils/typescript.js +1 -1
- package/src/utils/update-nxw.d.ts +2 -0
- package/src/utils/update-nxw.js +12 -0
- package/src/utils/workspace-configuration-check.js +1 -1
- package/src/utils/workspace-context.d.ts +6 -4
- package/src/utils/workspace-context.js +19 -9
- package/src/core/graph/polyfills.js +0 -1
- /package/src/command-line/init/{init.d.ts → init-v1.d.ts} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execCommand = void 0;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
async function execCommand(cmd, args, options) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const child = (0, node_child_process_1.spawn)(cmd, args, {
|
|
8
|
+
...options,
|
|
9
|
+
stdio: ['pipe', 'pipe', 'pipe'], // stdin, stdout, stderr
|
|
10
|
+
encoding: 'utf-8',
|
|
11
|
+
});
|
|
12
|
+
let stdout = '';
|
|
13
|
+
let stderr = '';
|
|
14
|
+
child.stdout.on('data', (chunk) => {
|
|
15
|
+
stdout += chunk;
|
|
16
|
+
});
|
|
17
|
+
child.stderr.on('data', (chunk) => {
|
|
18
|
+
stderr += chunk;
|
|
19
|
+
});
|
|
20
|
+
child.on('error', (error) => {
|
|
21
|
+
reject(error);
|
|
22
|
+
});
|
|
23
|
+
child.on('close', (code) => {
|
|
24
|
+
if (code !== 0) {
|
|
25
|
+
reject(stderr ||
|
|
26
|
+
`Unknown error occurred while running "${cmd} ${args.join(' ')}"`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
resolve(stdout);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.execCommand = execCommand;
|
|
@@ -19,8 +19,41 @@ export interface GitCommit extends RawGitCommit {
|
|
|
19
19
|
references: Reference[];
|
|
20
20
|
authors: GitCommitAuthor[];
|
|
21
21
|
isBreaking: boolean;
|
|
22
|
+
affectedFiles: string[];
|
|
23
|
+
revertedHashes: string[];
|
|
22
24
|
}
|
|
23
|
-
export declare function
|
|
25
|
+
export declare function getLatestGitTagForPattern(releaseTagPattern: string, additionalInterpolationData?: {}): Promise<{
|
|
26
|
+
tag: string;
|
|
27
|
+
extractedVersion: string;
|
|
28
|
+
} | null>;
|
|
24
29
|
export declare function getGitDiff(from: string | undefined, to?: string): Promise<RawGitCommit[]>;
|
|
30
|
+
export declare function gitAdd({ changedFiles, dryRun, verbose, logFn, }: {
|
|
31
|
+
changedFiles: string[];
|
|
32
|
+
dryRun?: boolean;
|
|
33
|
+
verbose?: boolean;
|
|
34
|
+
logFn?: (...messages: string[]) => void;
|
|
35
|
+
}): Promise<string>;
|
|
36
|
+
export declare function gitCommit({ messages, additionalArgs, dryRun, verbose, logFn, }: {
|
|
37
|
+
messages: string[];
|
|
38
|
+
additionalArgs?: string;
|
|
39
|
+
dryRun?: boolean;
|
|
40
|
+
verbose?: boolean;
|
|
41
|
+
logFn?: (message: string) => void;
|
|
42
|
+
}): Promise<string>;
|
|
43
|
+
export declare function gitTag({ tag, message, additionalArgs, dryRun, verbose, logFn, }: {
|
|
44
|
+
tag: string;
|
|
45
|
+
message?: string;
|
|
46
|
+
additionalArgs?: string;
|
|
47
|
+
dryRun?: boolean;
|
|
48
|
+
verbose?: boolean;
|
|
49
|
+
logFn?: (message: string) => void;
|
|
50
|
+
}): Promise<string>;
|
|
51
|
+
export declare function gitPush({ gitRemote, dryRun, verbose, }: {
|
|
52
|
+
gitRemote?: string;
|
|
53
|
+
dryRun?: boolean;
|
|
54
|
+
verbose?: boolean;
|
|
55
|
+
}): Promise<void>;
|
|
25
56
|
export declare function parseCommits(commits: RawGitCommit[]): GitCommit[];
|
|
26
57
|
export declare function parseGitCommit(commit: RawGitCommit): GitCommit | null;
|
|
58
|
+
export declare function getCommitHash(ref: string): Promise<string>;
|
|
59
|
+
export declare function getFirstGitCommit(): Promise<string>;
|
|
@@ -1,21 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseGitCommit = exports.parseCommits = exports.getGitDiff = exports.
|
|
3
|
+
exports.getFirstGitCommit = exports.getCommitHash = exports.parseGitCommit = exports.parseCommits = exports.gitPush = exports.gitTag = exports.gitCommit = exports.gitAdd = exports.getGitDiff = exports.getLatestGitTagForPattern = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Special thanks to changelogen for the original inspiration for many of these utilities:
|
|
6
6
|
* https://github.com/unjs/changelogen
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.catch(() => []);
|
|
13
|
-
return r.at(-1);
|
|
8
|
+
const utils_1 = require("../../../tasks-runner/utils");
|
|
9
|
+
const exec_command_1 = require("./exec-command");
|
|
10
|
+
function escapeRegExp(string) {
|
|
11
|
+
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
14
12
|
}
|
|
15
|
-
|
|
13
|
+
// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
|
|
14
|
+
const SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/g;
|
|
15
|
+
async function getLatestGitTagForPattern(releaseTagPattern, additionalInterpolationData = {}) {
|
|
16
|
+
try {
|
|
17
|
+
let tags;
|
|
18
|
+
tags = await (0, exec_command_1.execCommand)('git', [
|
|
19
|
+
'tag',
|
|
20
|
+
'--sort',
|
|
21
|
+
'-v:refname',
|
|
22
|
+
'--merged',
|
|
23
|
+
]).then((r) => r
|
|
24
|
+
.trim()
|
|
25
|
+
.split('\n')
|
|
26
|
+
.map((t) => t.trim())
|
|
27
|
+
.filter(Boolean));
|
|
28
|
+
if (!tags.length) {
|
|
29
|
+
// try again, but include all tags on the repo instead of just --merged ones
|
|
30
|
+
tags = await (0, exec_command_1.execCommand)('git', ['tag', '--sort', '-v:refname']).then((r) => r
|
|
31
|
+
.trim()
|
|
32
|
+
.split('\n')
|
|
33
|
+
.map((t) => t.trim())
|
|
34
|
+
.filter(Boolean));
|
|
35
|
+
}
|
|
36
|
+
if (!tags.length) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const interpolatedTagPattern = (0, utils_1.interpolate)(releaseTagPattern, {
|
|
40
|
+
version: '%v%',
|
|
41
|
+
projectName: '%p%',
|
|
42
|
+
...additionalInterpolationData,
|
|
43
|
+
});
|
|
44
|
+
const tagRegexp = `^${escapeRegExp(interpolatedTagPattern)
|
|
45
|
+
.replace('%v%', '(.+)')
|
|
46
|
+
.replace('%p%', '(.+)')}`;
|
|
47
|
+
const matchingSemverTags = tags.filter((tag) =>
|
|
48
|
+
// Do the match against SEMVER_REGEX to ensure that we skip tags that aren't valid semver versions
|
|
49
|
+
!!tag.match(tagRegexp) &&
|
|
50
|
+
tag.match(tagRegexp).some((r) => r.match(SEMVER_REGEX)));
|
|
51
|
+
if (!matchingSemverTags.length) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const [latestMatchingTag, ...rest] = matchingSemverTags[0].match(tagRegexp);
|
|
55
|
+
const version = rest.filter((r) => {
|
|
56
|
+
return r.match(SEMVER_REGEX);
|
|
57
|
+
})[0];
|
|
58
|
+
return {
|
|
59
|
+
tag: latestMatchingTag,
|
|
60
|
+
extractedVersion: version,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.getLatestGitTagForPattern = getLatestGitTagForPattern;
|
|
16
68
|
async function getGitDiff(from, to = 'HEAD') {
|
|
17
69
|
// https://git-scm.com/docs/pretty-formats
|
|
18
|
-
const r = await execCommand('git', [
|
|
70
|
+
const r = await (0, exec_command_1.execCommand)('git', [
|
|
19
71
|
'--no-pager',
|
|
20
72
|
'log',
|
|
21
73
|
`${from ? `${from}...` : ''}${to}`,
|
|
@@ -38,6 +90,141 @@ async function getGitDiff(from, to = 'HEAD') {
|
|
|
38
90
|
});
|
|
39
91
|
}
|
|
40
92
|
exports.getGitDiff = getGitDiff;
|
|
93
|
+
async function gitAdd({ changedFiles, dryRun, verbose, logFn, }) {
|
|
94
|
+
logFn = logFn || console.log;
|
|
95
|
+
let ignoredFiles = [];
|
|
96
|
+
let filesToAdd = [];
|
|
97
|
+
for (const f of changedFiles) {
|
|
98
|
+
const isFileIgnored = await isIgnored(f);
|
|
99
|
+
if (isFileIgnored) {
|
|
100
|
+
ignoredFiles.push(f);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
filesToAdd.push(f);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (verbose && ignoredFiles.length) {
|
|
107
|
+
logFn(`Will not add the following files because they are ignored by git:`);
|
|
108
|
+
ignoredFiles.forEach((f) => logFn(f));
|
|
109
|
+
}
|
|
110
|
+
if (!filesToAdd.length) {
|
|
111
|
+
logFn('\nNo files to stage. Skipping git add.');
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const commandArgs = ['add', ...filesToAdd];
|
|
115
|
+
const message = dryRun
|
|
116
|
+
? `Would stage files in git with the following command, but --dry-run was set:`
|
|
117
|
+
: `Staging files in git with the following command:`;
|
|
118
|
+
if (verbose) {
|
|
119
|
+
logFn(message);
|
|
120
|
+
logFn(`git ${commandArgs.join(' ')}`);
|
|
121
|
+
}
|
|
122
|
+
if (dryRun) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
return (0, exec_command_1.execCommand)('git', commandArgs);
|
|
126
|
+
}
|
|
127
|
+
exports.gitAdd = gitAdd;
|
|
128
|
+
async function isIgnored(filePath) {
|
|
129
|
+
try {
|
|
130
|
+
// This command will error if the file is not ignored
|
|
131
|
+
await (0, exec_command_1.execCommand)('git', ['check-ignore', filePath]);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function gitCommit({ messages, additionalArgs, dryRun, verbose, logFn, }) {
|
|
139
|
+
logFn = logFn || console.log;
|
|
140
|
+
const commandArgs = ['commit'];
|
|
141
|
+
for (const message of messages) {
|
|
142
|
+
commandArgs.push('--message', message);
|
|
143
|
+
}
|
|
144
|
+
if (additionalArgs) {
|
|
145
|
+
commandArgs.push(...additionalArgs.split(' '));
|
|
146
|
+
}
|
|
147
|
+
if (verbose) {
|
|
148
|
+
logFn(dryRun
|
|
149
|
+
? `Would commit all previously staged files in git with the following command, but --dry-run was set:`
|
|
150
|
+
: `Committing files in git with the following command:`);
|
|
151
|
+
logFn(`git ${commandArgs.join(' ')}`);
|
|
152
|
+
}
|
|
153
|
+
if (dryRun) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
let hasStagedFiles = false;
|
|
157
|
+
try {
|
|
158
|
+
// This command will error if there are staged changes
|
|
159
|
+
await (0, exec_command_1.execCommand)('git', ['diff-index', '--quiet', 'HEAD', '--cached']);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
hasStagedFiles = true;
|
|
163
|
+
}
|
|
164
|
+
if (!hasStagedFiles) {
|
|
165
|
+
logFn('\nNo staged files found. Skipping commit.');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return (0, exec_command_1.execCommand)('git', commandArgs);
|
|
169
|
+
}
|
|
170
|
+
exports.gitCommit = gitCommit;
|
|
171
|
+
async function gitTag({ tag, message, additionalArgs, dryRun, verbose, logFn, }) {
|
|
172
|
+
logFn = logFn || console.log;
|
|
173
|
+
const commandArgs = [
|
|
174
|
+
'tag',
|
|
175
|
+
// Create an annotated tag (recommended for releases here: https://git-scm.com/docs/git-tag)
|
|
176
|
+
'--annotate',
|
|
177
|
+
tag,
|
|
178
|
+
'--message',
|
|
179
|
+
message || tag,
|
|
180
|
+
];
|
|
181
|
+
if (additionalArgs) {
|
|
182
|
+
commandArgs.push(...additionalArgs.split(' '));
|
|
183
|
+
}
|
|
184
|
+
if (verbose) {
|
|
185
|
+
logFn(dryRun
|
|
186
|
+
? `Would tag the current commit in git with the following command, but --dry-run was set:`
|
|
187
|
+
: `Tagging the current commit in git with the following command:`);
|
|
188
|
+
logFn(`git ${commandArgs.join(' ')}`);
|
|
189
|
+
}
|
|
190
|
+
if (dryRun) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
return await (0, exec_command_1.execCommand)('git', commandArgs);
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
throw new Error(`Unexpected error when creating tag ${tag}:\n\n${err}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.gitTag = gitTag;
|
|
201
|
+
async function gitPush({ gitRemote, dryRun, verbose, }) {
|
|
202
|
+
const commandArgs = [
|
|
203
|
+
'push',
|
|
204
|
+
// NOTE: It's important we use --follow-tags, and not --tags, so that we are precise about what we are pushing
|
|
205
|
+
'--follow-tags',
|
|
206
|
+
'--no-verify',
|
|
207
|
+
'--atomic',
|
|
208
|
+
// Set custom git remote if provided
|
|
209
|
+
...(gitRemote ? [gitRemote] : []),
|
|
210
|
+
];
|
|
211
|
+
if (verbose) {
|
|
212
|
+
console.log(dryRun
|
|
213
|
+
? `Would push the current branch to the remote with the following command, but --dry-run was set:`
|
|
214
|
+
: `Pushing the current branch to the remote with the following command:`);
|
|
215
|
+
console.log(`git ${commandArgs.join(' ')}`);
|
|
216
|
+
}
|
|
217
|
+
if (dryRun) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
await (0, exec_command_1.execCommand)('git', commandArgs);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
throw new Error(`Unexpected git push error: ${err}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
exports.gitPush = gitPush;
|
|
41
228
|
function parseCommits(commits) {
|
|
42
229
|
return commits.map((commit) => parseGitCommit(commit)).filter(Boolean);
|
|
43
230
|
}
|
|
@@ -48,14 +235,15 @@ const ConventionalCommitRegex = /(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!
|
|
|
48
235
|
const CoAuthoredByRegex = /co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim;
|
|
49
236
|
const PullRequestRE = /\([ a-z]*(#\d+)\s*\)/gm;
|
|
50
237
|
const IssueRE = /(#\d+)/gm;
|
|
238
|
+
const ChangedFileRegex = /(A|M|D|R\d*|C\d*)\t([^\t\n]*)\t?(.*)?/gm;
|
|
239
|
+
const RevertHashRE = /This reverts commit (?<hash>[\da-f]{40})./gm;
|
|
51
240
|
function parseGitCommit(commit) {
|
|
52
241
|
const match = commit.message.match(ConventionalCommitRegex);
|
|
53
242
|
if (!match) {
|
|
54
243
|
return null;
|
|
55
244
|
}
|
|
56
|
-
const type = match.groups.type;
|
|
57
245
|
const scope = match.groups.scope || '';
|
|
58
|
-
const isBreaking = Boolean(match.groups.breaking);
|
|
246
|
+
const isBreaking = Boolean(match.groups.breaking) || commit.body.includes('BREAKING CHANGE:');
|
|
59
247
|
let description = match.groups.description;
|
|
60
248
|
// Extract references from message
|
|
61
249
|
const references = [];
|
|
@@ -70,6 +258,17 @@ function parseGitCommit(commit) {
|
|
|
70
258
|
references.push({ value: commit.shortHash, type: 'hash' });
|
|
71
259
|
// Remove references and normalize
|
|
72
260
|
description = description.replace(PullRequestRE, '').trim();
|
|
261
|
+
let type = match.groups.type;
|
|
262
|
+
// Extract any reverted hashes, if applicable
|
|
263
|
+
const revertedHashes = [];
|
|
264
|
+
const matchedHashes = commit.body.matchAll(RevertHashRE);
|
|
265
|
+
for (const matchedHash of matchedHashes) {
|
|
266
|
+
revertedHashes.push(matchedHash.groups.hash);
|
|
267
|
+
}
|
|
268
|
+
if (revertedHashes.length) {
|
|
269
|
+
type = 'revert';
|
|
270
|
+
description = commit.message;
|
|
271
|
+
}
|
|
73
272
|
// Find all authors
|
|
74
273
|
const authors = [commit.author];
|
|
75
274
|
for (const match of commit.body.matchAll(CoAuthoredByRegex)) {
|
|
@@ -78,6 +277,10 @@ function parseGitCommit(commit) {
|
|
|
78
277
|
email: (match.groups.email || '').trim(),
|
|
79
278
|
});
|
|
80
279
|
}
|
|
280
|
+
// Extract file changes from commit body
|
|
281
|
+
const affectedFiles = Array.from(commit.body.matchAll(ChangedFileRegex)).reduce((prev, [fullLine, changeType, file1, file2]) =>
|
|
282
|
+
// file2 only exists for some change types, such as renames
|
|
283
|
+
file2 ? [...prev, file1, file2] : [...prev, file1], []);
|
|
81
284
|
return {
|
|
82
285
|
...commit,
|
|
83
286
|
authors,
|
|
@@ -86,30 +289,31 @@ function parseGitCommit(commit) {
|
|
|
86
289
|
scope,
|
|
87
290
|
references,
|
|
88
291
|
isBreaking,
|
|
292
|
+
revertedHashes,
|
|
293
|
+
affectedFiles,
|
|
89
294
|
};
|
|
90
295
|
}
|
|
91
296
|
exports.parseGitCommit = parseGitCommit;
|
|
92
|
-
async function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
});
|
|
297
|
+
async function getCommitHash(ref) {
|
|
298
|
+
try {
|
|
299
|
+
return (await (0, exec_command_1.execCommand)('git', ['rev-parse', ref])).trim();
|
|
300
|
+
}
|
|
301
|
+
catch (e) {
|
|
302
|
+
throw new Error(`Unknown revision: ${ref}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
exports.getCommitHash = getCommitHash;
|
|
306
|
+
async function getFirstGitCommit() {
|
|
307
|
+
try {
|
|
308
|
+
return (await (0, exec_command_1.execCommand)('git', [
|
|
309
|
+
'rev-list',
|
|
310
|
+
'--max-parents=0',
|
|
311
|
+
'HEAD',
|
|
312
|
+
'--first-parent',
|
|
313
|
+
])).trim();
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
throw new Error(`Unable to find first commit in git history`);
|
|
317
|
+
}
|
|
115
318
|
}
|
|
319
|
+
exports.getFirstGitCommit = getFirstGitCommit;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Reference } from './git';
|
|
2
|
+
import { ReleaseVersion } from './shared';
|
|
2
3
|
export type RepoSlug = `${string}/${string}`;
|
|
3
4
|
export interface GithubRequestConfig {
|
|
4
5
|
repo: string;
|
|
@@ -7,17 +8,16 @@ export interface GithubRequestConfig {
|
|
|
7
8
|
export interface GithubRelease {
|
|
8
9
|
id?: string;
|
|
9
10
|
tag_name: string;
|
|
11
|
+
target_commitish?: string;
|
|
10
12
|
name?: string;
|
|
11
13
|
body?: string;
|
|
12
14
|
draft?: boolean;
|
|
13
15
|
prerelease?: boolean;
|
|
14
16
|
}
|
|
15
17
|
export declare function getGitHubRepoSlug(remoteName?: string): RepoSlug;
|
|
16
|
-
export declare function createOrUpdateGithubRelease(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
prerelease: boolean;
|
|
20
|
-
}, existingGithubReleaseForVersion?: GithubRelease): Promise<void>;
|
|
18
|
+
export declare function createOrUpdateGithubRelease(releaseVersion: ReleaseVersion, changelogContents: string, latestCommit: string, { dryRun }: {
|
|
19
|
+
dryRun: boolean;
|
|
20
|
+
}): Promise<void>;
|
|
21
21
|
export declare function resolveGithubToken(): Promise<string | null>;
|
|
22
22
|
export declare function getGithubReleaseByTag(config: GithubRequestConfig, tag: string): Promise<GithubRelease>;
|
|
23
23
|
export declare function formatReferences(references: Reference[], repoSlug: RepoSlug): string;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatReferences = exports.getGithubReleaseByTag = exports.resolveGithubToken = exports.createOrUpdateGithubRelease = exports.getGitHubRepoSlug = void 0;
|
|
4
4
|
const chalk = require("chalk");
|
|
5
|
+
const enquirer_1 = require("enquirer");
|
|
5
6
|
const node_child_process_1 = require("node:child_process");
|
|
6
7
|
const node_fs_1 = require("node:fs");
|
|
7
8
|
const node_os_1 = require("node:os");
|
|
8
|
-
const
|
|
9
|
+
const output_1 = require("../../../utils/output");
|
|
10
|
+
const path_1 = require("../../../utils/path");
|
|
11
|
+
const print_changes_1 = require("./print-changes");
|
|
12
|
+
const shared_1 = require("./shared");
|
|
9
13
|
// axios types and values don't seem to match
|
|
10
14
|
const _axios = require("axios");
|
|
11
15
|
const axios = _axios;
|
|
@@ -16,7 +20,7 @@ function getGitHubRepoSlug(remoteName = 'origin') {
|
|
|
16
20
|
stdio: 'pipe',
|
|
17
21
|
}).trim();
|
|
18
22
|
// Extract the 'user/repo' part from the URL
|
|
19
|
-
const regex = /github\.com[/:]([\w-]+\/[\w-]+)
|
|
23
|
+
const regex = /github\.com[/:]([\w-]+\/[\w-]+)/;
|
|
20
24
|
const match = remoteUrl.match(regex);
|
|
21
25
|
if (match && match[1]) {
|
|
22
26
|
return match[1];
|
|
@@ -30,8 +34,109 @@ function getGitHubRepoSlug(remoteName = 'origin') {
|
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
exports.getGitHubRepoSlug = getGitHubRepoSlug;
|
|
33
|
-
async function createOrUpdateGithubRelease(
|
|
37
|
+
async function createOrUpdateGithubRelease(releaseVersion, changelogContents, latestCommit, { dryRun }) {
|
|
38
|
+
const githubRepoSlug = getGitHubRepoSlug();
|
|
39
|
+
if (!githubRepoSlug) {
|
|
40
|
+
output_1.output.error({
|
|
41
|
+
title: `Unable to create a GitHub release because the GitHub repo slug could not be determined.`,
|
|
42
|
+
bodyLines: [
|
|
43
|
+
`Please ensure you have a valid GitHub remote configured. You can run \`git remote -v\` to list your current remotes.`,
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
const token = await resolveGithubToken();
|
|
49
|
+
const githubRequestConfig = {
|
|
50
|
+
repo: githubRepoSlug,
|
|
51
|
+
token,
|
|
52
|
+
};
|
|
53
|
+
let existingGithubReleaseForVersion;
|
|
54
|
+
try {
|
|
55
|
+
existingGithubReleaseForVersion = await getGithubReleaseByTag(githubRequestConfig, releaseVersion.gitTag);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
if (err.response?.status === 401) {
|
|
59
|
+
output_1.output.error({
|
|
60
|
+
title: `Unable to resolve data via the GitHub API. You can use any of the following options to resolve this:`,
|
|
61
|
+
bodyLines: [
|
|
62
|
+
'- Set the `GITHUB_TOKEN` or `GH_TOKEN` environment variable to a valid GitHub token with `repo` scope',
|
|
63
|
+
'- Have an active session via the official gh CLI tool (https://cli.github.com) in your current terminal',
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
if (err.response?.status === 404) {
|
|
69
|
+
// No existing release found, this is fine
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Rethrow unknown errors for now
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const logTitle = `https://github.com/${githubRepoSlug}/releases/tag/${releaseVersion.gitTag}`;
|
|
77
|
+
if (existingGithubReleaseForVersion) {
|
|
78
|
+
console.error(`${chalk.white('UPDATE')} ${logTitle}${dryRun ? chalk.keyword('orange')(' [dry-run]') : ''}`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.error(`${chalk.green('CREATE')} ${logTitle}${dryRun ? chalk.keyword('orange')(' [dry-run]') : ''}`);
|
|
82
|
+
}
|
|
83
|
+
console.log('');
|
|
84
|
+
(0, print_changes_1.printDiff)(existingGithubReleaseForVersion ? existingGithubReleaseForVersion.body : '', changelogContents, 3, shared_1.noDiffInChangelogMessage);
|
|
85
|
+
if (!dryRun) {
|
|
86
|
+
await createOrUpdateGithubReleaseInternal(githubRequestConfig, {
|
|
87
|
+
version: releaseVersion.gitTag,
|
|
88
|
+
prerelease: releaseVersion.isPrerelease,
|
|
89
|
+
body: changelogContents,
|
|
90
|
+
commit: latestCommit,
|
|
91
|
+
}, existingGithubReleaseForVersion);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.createOrUpdateGithubRelease = createOrUpdateGithubRelease;
|
|
95
|
+
async function createOrUpdateGithubReleaseInternal(githubRequestConfig, release, existingGithubReleaseForVersion) {
|
|
34
96
|
const result = await syncGithubRelease(githubRequestConfig, release, existingGithubReleaseForVersion);
|
|
97
|
+
/**
|
|
98
|
+
* If something went wrong POSTing to Github we can still pre-populate the web form on github.com
|
|
99
|
+
* to allow the user to manually complete the release if they so choose.
|
|
100
|
+
*/
|
|
101
|
+
if (result.status === 'manual') {
|
|
102
|
+
if (result.error) {
|
|
103
|
+
process.exitCode = 1;
|
|
104
|
+
if (result.error.response?.data) {
|
|
105
|
+
// There's a nicely formatted error from GitHub we can display to the user
|
|
106
|
+
output_1.output.error({
|
|
107
|
+
title: `A GitHub API Error occurred when creating/updating the release`,
|
|
108
|
+
bodyLines: [
|
|
109
|
+
`GitHub Error: ${JSON.stringify(result.error.response.data)}`,
|
|
110
|
+
`---`,
|
|
111
|
+
`Request Data:`,
|
|
112
|
+
`Repo: ${githubRequestConfig.repo}`,
|
|
113
|
+
`Token: ${githubRequestConfig.token}`,
|
|
114
|
+
`Body: ${JSON.stringify(result.requestData)}`,
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log(result.error);
|
|
120
|
+
console.error(`An unknown error occurred while trying to create a release on GitHub, please report this on https://github.com/nrwl/nx (NOTE: make sure to redact your GitHub token from the error message!)`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const shouldContinueInGitHub = await promptForContinueInGitHub();
|
|
124
|
+
if (!shouldContinueInGitHub) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const open = require('open');
|
|
128
|
+
await open(result.url)
|
|
129
|
+
.then(() => {
|
|
130
|
+
console.info(`\nFollow up in the browser to manually create the release:\n\n` +
|
|
131
|
+
chalk.underline(chalk.cyan(result.url)) +
|
|
132
|
+
`\n`);
|
|
133
|
+
})
|
|
134
|
+
.catch(() => {
|
|
135
|
+
console.info(`Open this link to manually create a release: \n` +
|
|
136
|
+
chalk.underline(chalk.cyan(result.url)) +
|
|
137
|
+
'\n');
|
|
138
|
+
});
|
|
139
|
+
}
|
|
35
140
|
/**
|
|
36
141
|
* If something went wrong POSTing to Github we can still pre-populate the web form on github.com
|
|
37
142
|
* to allow the user to manually complete the release.
|
|
@@ -53,7 +158,32 @@ async function createOrUpdateGithubRelease(githubRequestConfig, release, existin
|
|
|
53
158
|
});
|
|
54
159
|
}
|
|
55
160
|
}
|
|
56
|
-
|
|
161
|
+
async function promptForContinueInGitHub() {
|
|
162
|
+
try {
|
|
163
|
+
const reply = await (0, enquirer_1.prompt)([
|
|
164
|
+
{
|
|
165
|
+
name: 'open',
|
|
166
|
+
message: 'Do you want to finish creating the release manually in your browser?',
|
|
167
|
+
type: 'autocomplete',
|
|
168
|
+
choices: [
|
|
169
|
+
{
|
|
170
|
+
name: 'Yes',
|
|
171
|
+
hint: 'It will pre-populate the form for you',
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'No',
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
initial: 0,
|
|
178
|
+
},
|
|
179
|
+
]);
|
|
180
|
+
return reply.open === 'Yes';
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
// Handle the case where the user exits the prompt with ctrl+c
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
57
187
|
async function syncGithubRelease(githubRequestConfig, release, existingGithubReleaseForVersion) {
|
|
58
188
|
const ghRelease = {
|
|
59
189
|
tag_name: release.version,
|
|
@@ -64,7 +194,10 @@ async function syncGithubRelease(githubRequestConfig, release, existingGithubRel
|
|
|
64
194
|
try {
|
|
65
195
|
const newGhRelease = await (existingGithubReleaseForVersion
|
|
66
196
|
? updateGithubRelease(githubRequestConfig, existingGithubReleaseForVersion.id, ghRelease)
|
|
67
|
-
: createGithubRelease(githubRequestConfig,
|
|
197
|
+
: createGithubRelease(githubRequestConfig, {
|
|
198
|
+
...ghRelease,
|
|
199
|
+
target_commitish: release.commit,
|
|
200
|
+
}));
|
|
68
201
|
return {
|
|
69
202
|
status: existingGithubReleaseForVersion ? 'updated' : 'created',
|
|
70
203
|
id: newGhRelease.id,
|
|
@@ -76,6 +209,7 @@ async function syncGithubRelease(githubRequestConfig, release, existingGithubRel
|
|
|
76
209
|
status: 'manual',
|
|
77
210
|
error,
|
|
78
211
|
url: githubNewReleaseURL(githubRequestConfig, release),
|
|
212
|
+
requestData: ghRelease,
|
|
79
213
|
};
|
|
80
214
|
}
|
|
81
215
|
}
|
|
@@ -86,12 +220,25 @@ async function resolveGithubToken() {
|
|
|
86
220
|
return tokenFromEnv;
|
|
87
221
|
}
|
|
88
222
|
// Try and resolve from gh CLI installation
|
|
89
|
-
const ghCLIPath = (0,
|
|
223
|
+
const ghCLIPath = (0, path_1.joinPathFragments)(process.env.XDG_CONFIG_HOME || (0, path_1.joinPathFragments)((0, node_os_1.homedir)(), '.config'), 'gh', 'hosts.yml');
|
|
90
224
|
if ((0, node_fs_1.existsSync)(ghCLIPath)) {
|
|
91
225
|
const yamlContents = await node_fs_1.promises.readFile(ghCLIPath, 'utf8');
|
|
92
226
|
const { load } = require('@zkochan/js-yaml');
|
|
93
227
|
const ghCLIConfig = load(yamlContents);
|
|
94
|
-
|
|
228
|
+
if (ghCLIConfig['github.com']) {
|
|
229
|
+
// Web based session (the token is already embedded in the config)
|
|
230
|
+
if (ghCLIConfig['github.com'].oauth_token) {
|
|
231
|
+
return ghCLIConfig['github.com'].oauth_token;
|
|
232
|
+
}
|
|
233
|
+
// SSH based session (we need to dynamically resolve a token using the CLI)
|
|
234
|
+
if (ghCLIConfig['github.com'].user &&
|
|
235
|
+
ghCLIConfig['github.com'].git_protocol === 'ssh') {
|
|
236
|
+
return (0, node_child_process_1.execSync)(`gh auth token`, {
|
|
237
|
+
encoding: 'utf8',
|
|
238
|
+
stdio: 'pipe',
|
|
239
|
+
}).trim();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
95
242
|
}
|
|
96
243
|
return null;
|
|
97
244
|
}
|
|
@@ -123,7 +270,7 @@ async function updateGithubRelease(config, id, body) {
|
|
|
123
270
|
});
|
|
124
271
|
}
|
|
125
272
|
function githubNewReleaseURL(config, release) {
|
|
126
|
-
return `https://github.com/${config.repo}/releases/new?tag
|
|
273
|
+
return `https://github.com/${config.repo}/releases/new?tag=${release.version}&title=${release.version}&body=${encodeURIComponent(release.body)}`;
|
|
127
274
|
}
|
|
128
275
|
const providerToRefSpec = {
|
|
129
276
|
github: { 'pull-request': 'pull', hash: 'commit', issue: 'issues' },
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseChangelogMarkdown = void 0;
|
|
4
4
|
function parseChangelogMarkdown(contents) {
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The release header may include prerelease identifiers (e.g., -alpha.13),
|
|
7
|
+
* and major releases may use a single #, instead of the standard ## used
|
|
8
|
+
* for minor and patch releases. This regex matches all of these cases.
|
|
9
|
+
*/
|
|
10
|
+
const CHANGELOG_RELEASE_HEAD_RE = new RegExp('^#+\\s*\\[?(\\d+\\.\\d+\\.\\d+(?:-[a-zA-Z0-9\\.]+)?)\\]?', 'gm');
|
|
6
11
|
const headings = [...contents.matchAll(CHANGELOG_RELEASE_HEAD_RE)];
|
|
7
12
|
const releases = [];
|
|
8
13
|
for (let i = 0; i < headings.length; i++) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Tree } from '../../../generators/tree';
|
|
3
3
|
export declare function printDiff(before: string, after: string, contextLines?: number, noDiffMessage?: string): void;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function printAndFlushChanges(tree: Tree, isDryRun: boolean, diffContextLines?: number, shouldPrintDryRunMessage?: boolean, noDiffMessage?: string, changePredicate?: (f: {
|
|
5
5
|
path: string;
|
|
6
6
|
content?: Buffer;
|
|
7
7
|
}) => boolean): void;
|