@astra-kit/rp 0.0.0-stage → 0.10.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +352 -2
  4. package/bin/astra-rp.js +51 -0
  5. package/package.json +93 -4
  6. package/src/build-gate.js +157 -0
  7. package/src/changelog-blocks.js +53 -0
  8. package/src/changelog.js +108 -0
  9. package/src/constants/build-gate.js +30 -0
  10. package/src/constants/changelog-draft.js +180 -0
  11. package/src/constants/changelog.js +74 -0
  12. package/src/constants/ci-release.js +346 -0
  13. package/src/constants/cli.js +12 -0
  14. package/src/constants/create-version.js +523 -0
  15. package/src/constants/guard-publish.js +29 -0
  16. package/src/constants/index.js +18 -0
  17. package/src/constants/monorepo.js +57 -0
  18. package/src/constants/package-manager.js +56 -0
  19. package/src/constants/registry.js +72 -0
  20. package/src/constants/terminal-ui.js +93 -0
  21. package/src/constants/version-files.js +63 -0
  22. package/src/constants/versions.js +60 -0
  23. package/src/create-version/artifact.js +343 -0
  24. package/src/create-version/changelog-draft-workspace.js +124 -0
  25. package/src/create-version/changelog-draft.js +380 -0
  26. package/src/create-version/changelog.js +264 -0
  27. package/src/create-version/ci-config.js +54 -0
  28. package/src/create-version/ci-publication-history.js +113 -0
  29. package/src/create-version/ci-release-identity-step.js +58 -0
  30. package/src/create-version/ci-setup.js +794 -0
  31. package/src/create-version/ci.js +555 -0
  32. package/src/create-version/committed-tree.js +75 -0
  33. package/src/create-version/config.js +489 -0
  34. package/src/create-version/errors.js +46 -0
  35. package/src/create-version/github-workflow.js +199 -0
  36. package/src/create-version/index.js +54 -0
  37. package/src/create-version/json.js +32 -0
  38. package/src/create-version/jsonc.js +76 -0
  39. package/src/create-version/jsr.js +96 -0
  40. package/src/create-version/local-changes.js +178 -0
  41. package/src/create-version/npm-auth.js +142 -0
  42. package/src/create-version/npm.js +812 -0
  43. package/src/create-version/plan.js +1200 -0
  44. package/src/create-version/process.js +334 -0
  45. package/src/create-version/registry-config.js +121 -0
  46. package/src/create-version/registry-http.js +62 -0
  47. package/src/create-version/registry.js +220 -0
  48. package/src/create-version/release-execution.js +45 -0
  49. package/src/create-version/release-tag-config.js +76 -0
  50. package/src/create-version/run.js +2087 -0
  51. package/src/create-version/state.js +461 -0
  52. package/src/create-version/strict-utf8.js +11 -0
  53. package/src/create-version/templates/release.yml +52 -0
  54. package/src/create-version/templates/vercel-ignore-build.mjs +66 -0
  55. package/src/guard-publish.js +77 -0
  56. package/src/index.js +42 -0
  57. package/src/monorepo/plan.js +475 -0
  58. package/src/monorepo/release-commit.js +46 -0
  59. package/src/monorepo/run.js +927 -0
  60. package/src/monorepo/state.js +206 -0
  61. package/src/monorepo/workspaces.js +327 -0
  62. package/src/package-manager.js +107 -0
  63. package/src/terminal-ui.js +548 -0
  64. package/src/testing.js +70 -0
  65. package/src/version-files.js +142 -0
  66. package/src/versions.js +303 -0
  67. package/types/build-gate.d.ts +43 -0
  68. package/types/changelog-blocks.d.ts +33 -0
  69. package/types/changelog.d.ts +61 -0
  70. package/types/constants/build-gate.d.ts +23 -0
  71. package/types/constants/changelog-draft.d.ts +138 -0
  72. package/types/constants/changelog.d.ts +56 -0
  73. package/types/constants/ci-release.d.ts +284 -0
  74. package/types/constants/cli.d.ts +11 -0
  75. package/types/constants/create-version.d.ts +397 -0
  76. package/types/constants/guard-publish.d.ts +25 -0
  77. package/types/constants/index.d.ts +17 -0
  78. package/types/constants/monorepo.d.ts +45 -0
  79. package/types/constants/package-manager.d.ts +40 -0
  80. package/types/constants/registry.d.ts +79 -0
  81. package/types/constants/terminal-ui.d.ts +73 -0
  82. package/types/constants/version-files.d.ts +51 -0
  83. package/types/constants/versions.d.ts +47 -0
  84. package/types/create-version/artifact.d.ts +113 -0
  85. package/types/create-version/changelog-draft-workspace.d.ts +33 -0
  86. package/types/create-version/changelog-draft.d.ts +127 -0
  87. package/types/create-version/changelog.d.ts +141 -0
  88. package/types/create-version/ci-config.d.ts +33 -0
  89. package/types/create-version/ci-publication-history.d.ts +51 -0
  90. package/types/create-version/ci-release-identity-step.d.ts +12 -0
  91. package/types/create-version/ci-setup.d.ts +148 -0
  92. package/types/create-version/ci.d.ts +145 -0
  93. package/types/create-version/committed-tree.d.ts +55 -0
  94. package/types/create-version/config.d.ts +128 -0
  95. package/types/create-version/errors.d.ts +39 -0
  96. package/types/create-version/github-workflow.d.ts +41 -0
  97. package/types/create-version/index.d.ts +28 -0
  98. package/types/create-version/json.d.ts +21 -0
  99. package/types/create-version/jsonc.d.ts +21 -0
  100. package/types/create-version/jsr.d.ts +52 -0
  101. package/types/create-version/local-changes.d.ts +52 -0
  102. package/types/create-version/npm-auth.d.ts +60 -0
  103. package/types/create-version/npm.d.ts +331 -0
  104. package/types/create-version/plan.d.ts +369 -0
  105. package/types/create-version/process.d.ts +151 -0
  106. package/types/create-version/registry-config.d.ts +56 -0
  107. package/types/create-version/registry-http.d.ts +22 -0
  108. package/types/create-version/registry.d.ts +86 -0
  109. package/types/create-version/release-execution.d.ts +22 -0
  110. package/types/create-version/release-tag-config.d.ts +18 -0
  111. package/types/create-version/run.d.ts +407 -0
  112. package/types/create-version/state.d.ts +204 -0
  113. package/types/create-version/strict-utf8.d.ts +10 -0
  114. package/types/guard-publish.d.ts +49 -0
  115. package/types/index.d.ts +23 -0
  116. package/types/monorepo/plan.d.ts +68 -0
  117. package/types/monorepo/release-commit.d.ts +29 -0
  118. package/types/monorepo/run.d.ts +68 -0
  119. package/types/monorepo/state.d.ts +96 -0
  120. package/types/monorepo/workspaces.d.ts +86 -0
  121. package/types/package-manager.d.ts +58 -0
  122. package/types/terminal-ui.d.ts +196 -0
  123. package/types/testing.d.ts +31 -0
  124. package/types/version-files.d.ts +59 -0
  125. package/types/versions.d.ts +158 -0
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Package managers a project may use and how each one runs its scripts.
3
+ *
4
+ * @module constants/package-manager
5
+ */
6
+
7
+ /** Package managers astra-rp recognizes. */
8
+ export const PACKAGE_MANAGER = Object.freeze({
9
+ pnpm: "pnpm",
10
+ npm: "npm",
11
+ yarn: "yarn",
12
+ bun: "bun",
13
+ });
14
+
15
+ /** Package manager assumed when a project declares none and has no lockfile: the historical default. */
16
+ export const DEFAULT_PACKAGE_MANAGER = PACKAGE_MANAGER.pnpm;
17
+
18
+ /** `packageManager` field of `package.json` (Corepack format, `<name>@<version>`). */
19
+ export const PACKAGE_MANAGER_FIELD = "packageManager";
20
+
21
+ /** Name part of a `packageManager` value such as `bun@1.3.11`. */
22
+ export const PACKAGE_MANAGER_FIELD_PATTERN = /^(pnpm|npm|yarn|bun)@/u;
23
+
24
+ /**
25
+ * Lockfiles of each package manager, checked in order to reveal the package manager when
26
+ * `packageManager` is missing. The generated CI workflow installs with a frozen lockfile, so it
27
+ * also needs one of its package manager's lockfiles committed.
28
+ */
29
+ export const LOCKFILE_PACKAGE_MANAGERS = Object.freeze([
30
+ ["bun.lock", PACKAGE_MANAGER.bun],
31
+ ["bun.lockb", PACKAGE_MANAGER.bun],
32
+ ["pnpm-lock.yaml", PACKAGE_MANAGER.pnpm],
33
+ ["yarn.lock", PACKAGE_MANAGER.yarn],
34
+ ["package-lock.json", PACKAGE_MANAGER.npm],
35
+ ["npm-shrinkwrap.json", PACKAGE_MANAGER.npm],
36
+ ]);
37
+
38
+ /** Every lockfile name in {@link LOCKFILE_PACKAGE_MANAGERS}, whatever its package manager. */
39
+ export const LOCKFILE_NAMES = Object.freeze(LOCKFILE_PACKAGE_MANAGERS.map(([lockfileName]) => lockfileName));
40
+
41
+ /**
42
+ * Prefix that runs a `package.json` script by name. `bun create-version` would run `bun create`
43
+ * and `npm create-version` is not a command, so both need `run`; pnpm and yarn run scripts directly.
44
+ */
45
+ export const SCRIPT_RUNNER = Object.freeze({
46
+ [PACKAGE_MANAGER.pnpm]: "pnpm",
47
+ [PACKAGE_MANAGER.npm]: "npm run",
48
+ [PACKAGE_MANAGER.yarn]: "yarn",
49
+ [PACKAGE_MANAGER.bun]: "bun run",
50
+ });
51
+
52
+ /** `package.json` script projects declare to run `astra-rp create-version`. */
53
+ export const CREATE_VERSION_SCRIPT = "create-version";
54
+
55
+ /** How a pnpm project runs `astra-rp create-version`: the default quoted by messages when no project is known. */
56
+ export const DEFAULT_CREATE_VERSION_COMMAND = `${SCRIPT_RUNNER[DEFAULT_PACKAGE_MANAGER]} ${CREATE_VERSION_SCRIPT}`;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Defines providers, authentication modes and transport defaults for one-registry releases.
3
+ *
4
+ * @module constants/registry
5
+ */
6
+
7
+ /** npm package registry provider. */
8
+ export const NPM_REGISTRY_PROVIDER = "npm";
9
+ /** GitHub Packages provider. */
10
+ export const GITHUB_REGISTRY_PROVIDER = "github";
11
+ /** GitLab package registry provider. */
12
+ export const GITLAB_REGISTRY_PROVIDER = "gitlab";
13
+ /** Native JSR provider. */
14
+ export const JSR_REGISTRY_PROVIDER = "jsr";
15
+ /** Providers that can publish without a project-defined hook. */
16
+ export const REGISTRY_PROVIDERS = Object.freeze([NPM_REGISTRY_PROVIDER, GITHUB_REGISTRY_PROVIDER, GITLAB_REGISTRY_PROVIDER, JSR_REGISTRY_PROVIDER]);
17
+
18
+ /** Token-based authentication mode. */
19
+ export const TOKEN_AUTHENTICATION = "token";
20
+ /** Tokenless CI authentication mode. */
21
+ export const OIDC_AUTHENTICATION = "oidc";
22
+ /** Interactive JSR browser authentication mode. */
23
+ export const BROWSER_AUTHENTICATION = "browser";
24
+ /** Authentication modes accepted in project configuration. */
25
+ export const REGISTRY_AUTHENTICATION_MODES = Object.freeze([TOKEN_AUTHENTICATION, OIDC_AUTHENTICATION, BROWSER_AUTHENTICATION]);
26
+
27
+ /** Provider names used in terminal feedback. */
28
+ export const REGISTRY_LABELS = Object.freeze({ npm: "npm", github: "GitHub Packages", gitlab: "GitLab", jsr: "JSR" });
29
+ /** Host of the GitHub Packages npm endpoint. */
30
+ export const GITHUB_PACKAGES_HOST = "npm.pkg.github.com";
31
+ /** Public GitHub Packages npm endpoint. */
32
+ export const GITHUB_PACKAGES_REGISTRY_URL = `https://${GITHUB_PACKAGES_HOST}/`;
33
+ /** Public native JSR endpoint. */
34
+ export const JSR_REGISTRY_URL = "https://jsr.io/";
35
+ /** Hostname of JSR's npm compatibility endpoint, which installs JSR packages but cannot publish them. */
36
+ export const JSR_NPM_COMPATIBILITY_HOSTNAME = "npm.jsr.io";
37
+ /** Default credential variable for each provider. */
38
+ export const NPM_REGISTRY_TOKEN_VARIABLE = "NPM_TOKEN";
39
+ /** GitHub Actions token or a classic PAT stored under this variable. */
40
+ export const GITHUB_REGISTRY_TOKEN_VARIABLE = "GITHUB_TOKEN";
41
+ /** GitLab access token; a project may configure CI_JOB_TOKEN instead. */
42
+ export const GITLAB_REGISTRY_TOKEN_VARIABLE = "GITLAB_TOKEN";
43
+ /** Personal JSR publishing token. */
44
+ export const JSR_REGISTRY_TOKEN_VARIABLE = "JSR_TOKEN";
45
+ /** Default token variables indexed by the selected provider. */
46
+ export const REGISTRY_TOKEN_VARIABLES = Object.freeze({ npm: NPM_REGISTRY_TOKEN_VARIABLE, github: GITHUB_REGISTRY_TOKEN_VARIABLE, gitlab: GITLAB_REGISTRY_TOKEN_VARIABLE, jsr: JSR_REGISTRY_TOKEN_VARIABLE });
47
+ /** Variable names safe to reference from npm configuration and child-process environments. */
48
+ export const REGISTRY_TOKEN_VARIABLE_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
49
+ /** Distribution tags safe to pass as one npm CLI operand. */
50
+ export const REGISTRY_DIST_TAG_PATTERN = /^[A-Za-z][A-Za-z0-9._-]*$/u;
51
+ /** npm access modes supported by registry publishers. */
52
+ export const REGISTRY_ACCESS_MODES = Object.freeze(["public", "restricted"]);
53
+ /** HTTP timeout for direct metadata lookups, in milliseconds. */
54
+ export const REGISTRY_LOOKUP_TIMEOUT_MS = 15_000;
55
+ /** GitLab publishing uses a project endpoint, including on self-managed instances. */
56
+ export const GITLAB_PROJECT_REGISTRY_PATTERN = /\/api\/v4\/projects\/[^/]+\/packages\/npm\/?$/u;
57
+ /** JSR configuration filenames, in preferred lookup order. */
58
+ export const JSR_CONFIG_FILES = Object.freeze(["jsr.json", "jsr.jsonc", "deno.json", "deno.jsonc"]);
59
+ /** Scoped JSR names with command-line-safe scope and package components. */
60
+ export const JSR_PACKAGE_NAME_PATTERN = /^@[a-z0-9][a-z0-9-]*\/[a-z0-9][a-z0-9-]*$/u;
61
+ /** Pinned official npm client used when JSR does not use an installed Deno client. */
62
+ export const JSR_NPM_CLIENT_SPEC = "jsr@0.14.3";
63
+ /** JSR client choices. */
64
+ export const JSR_CLIENTS = Object.freeze(["npx", "deno"]);
65
+ /** Child-only JSR token variable expanded by the command shell, never logged by astra-rp. */
66
+ export const JSR_CHILD_TOKEN_VARIABLE = "ASTRA_RP_JSR_TOKEN";
67
+ /** Opaque JSR tokens safe to substitute as one shell-quoted operand. */
68
+ export const JSR_SHELL_SAFE_TOKEN_PATTERN = /^[A-Za-z0-9._~+/=-]+$/u;
69
+ /** Minimum npm CLI version that implements trusted publishing. */
70
+ export const NPM_OIDC_MINIMUM_VERSION = "11.5.1";
71
+ /** Minimum Node version needed by npm trusted publishing. */
72
+ export const NPM_OIDC_MINIMUM_NODE_VERSION = "22.14.0";
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Layout, ANSI and key contracts of the dependency-free terminal UI.
3
+ *
4
+ * @module constants/terminal-ui
5
+ */
6
+
7
+ /** Widest box drawn, so lines stay readable on large terminals. */
8
+ export const MAX_BOX_WIDTH = 84;
9
+
10
+ /** Width assumed when stdout does not report its columns. */
11
+ export const FALLBACK_TERMINAL_WIDTH = 80;
12
+
13
+ /** Columns kept free at the right of the terminal when sizing a box. */
14
+ export const TERMINAL_RIGHT_MARGIN = 2;
15
+
16
+ /** Horizontal padding inside a box, per side. */
17
+ export const BOX_PADDING = 1;
18
+
19
+ /** Width of the label column of status rows. */
20
+ export const ROW_LABEL_WIDTH = 16;
21
+
22
+ /** Spinner animation frames. */
23
+ export const SPINNER_FRAMES = Object.freeze(["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]);
24
+
25
+ /** Delay between spinner frames. */
26
+ export const SPINNER_INTERVAL_MS = 80;
27
+
28
+ /** Exit code conventionally used after Ctrl+C. */
29
+ export const INTERRUPTED_EXIT_CODE = 130;
30
+
31
+ /** Splits styled text into ANSI escape sequences and single code points. */
32
+ export const ANSI_TOKEN_PATTERN = /\x1b\[[0-9;]*m|[\s\S]/gu;
33
+
34
+ /** First character of every ANSI escape sequence. */
35
+ export const ANSI_ESCAPE = "\x1b";
36
+
37
+ /** ANSI control sequences used by boxes, spinners and prompts. */
38
+ export const ANSI_SEQUENCE = Object.freeze({
39
+ reset: "\x1b[0m",
40
+ hideCursor: "\x1b[?25l",
41
+ showCursor: "\x1b[?25h",
42
+ clearLine: "\r\x1b[2K",
43
+ clearBelow: "\x1b[0J",
44
+ });
45
+
46
+ /** Border color of each box tone. */
47
+ export const BOX_TONE = Object.freeze({
48
+ neutral: "gray",
49
+ info: "cyan",
50
+ success: "green",
51
+ warning: "yellow",
52
+ danger: "red",
53
+ accent: "magenta",
54
+ });
55
+
56
+ /** Nerd Font glyphs (Font Awesome and Octicons sets) used as status icons. */
57
+ export const ICON_GLYPH = Object.freeze({
58
+ success: "", // nf-fa-check
59
+ failure: "", // nf-fa-times
60
+ warning: "", // nf-fa-warning
61
+ info: "", // nf-fa-info_circle
62
+ pending: "", // nf-fa-circle_o
63
+ arrow: "", // nf-fa-chevron_right
64
+ bullet: "", // nf-oct-dot_fill
65
+ star: "", // nf-fa-star
66
+ rocket: "", // nf-fa-rocket
67
+ });
68
+
69
+ /** Label/value rows (`renderRow`): the value starts after a gap of two or more spaces. */
70
+ export const VALUE_COLUMN_PATTERN = /^\s*\S(?:.*?\S)?\s{2,}(?=\S)/u;
71
+
72
+ /** Leading marker (icon, arrow, bullet or `1.`, never a word) followed by a space, used as hanging indent. */
73
+ export const HANGING_MARKER_PATTERN = /^(\s*)((?:[^\p{L}\p{N}\s]{1,2}|\d{1,2}\.)\s+)?/u;
74
+
75
+ /** Options that can be picked with a single digit key (1-9). */
76
+ export const MAX_NUMBERED_OPTIONS = 9;
77
+
78
+ /** A single digit key that picks a numbered option. */
79
+ export const NUMBER_KEY_PATTERN = /^[1-9]$/u;
80
+
81
+ /** Seconds in a minute, used to format durations. */
82
+ export const SECONDS_PER_MINUTE = 60;
83
+
84
+ /** Milliseconds in a second, used to format durations. */
85
+ export const MILLISECONDS_PER_SECOND = 1000;
86
+
87
+ /** Key names (`readline` keypress events) handled by the select prompt. */
88
+ export const PROMPT_KEY = Object.freeze({
89
+ interrupt: "c",
90
+ previous: Object.freeze(["up", "k"]),
91
+ next: Object.freeze(["down", "j", "tab"]),
92
+ confirm: Object.freeze(["return", "enter"]),
93
+ });
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Markers of `versionFiles`: lines and blocks whose version `create-version`
3
+ * rewrites in the release commit, besides `package.json`.
4
+ *
5
+ * @module constants/version-files
6
+ */
7
+
8
+ import { PACKAGE_MANIFEST_FILE } from "./build-gate.js";
9
+ import { CHANGELOG_FILE } from "./changelog.js";
10
+
11
+ /**
12
+ * Comment marking a single line whose version is rewritten. The release-please marker is also
13
+ * accepted, so a project moving from release-please keeps its files untouched.
14
+ */
15
+ export const VERSION_LINE_MARKERS = Object.freeze(["astra-rp-version", "x-release-please-version"]);
16
+
17
+ /** Comments opening a block whose every version is rewritten, paired by index with {@link VERSION_BLOCK_END_MARKERS}. */
18
+ export const VERSION_BLOCK_START_MARKERS = Object.freeze(["astra-rp-start-version", "x-release-please-start-version"]);
19
+
20
+ /** Comments closing a version block, paired by index with {@link VERSION_BLOCK_START_MARKERS}. */
21
+ export const VERSION_BLOCK_END_MARKERS = Object.freeze(["astra-rp-end", "x-release-please-end"]);
22
+
23
+ /**
24
+ * Ways a file can pair its version block markers wrongly. Any of them stops the rewrite, since
25
+ * guessing where a block ends could rewrite versions outside the intended section.
26
+ *
27
+ * - `unterminated`: a start marker without its end marker before the end of the file.
28
+ * - `unopened`: an end marker outside any block.
29
+ * - `nested`: a start marker inside a block that is still open.
30
+ * - `mismatched`: an end marker of the other tool (`x-release-please-end` closing `astra-rp-start-version`, or the reverse).
31
+ */
32
+ export const VERSION_BLOCK_PROBLEM = Object.freeze({
33
+ unterminated: "unterminated",
34
+ unopened: "unopened",
35
+ nested: "nested",
36
+ mismatched: "mismatched",
37
+ });
38
+
39
+ /**
40
+ * A semantic version inside a marked line (`1.2.3`, `1.2.3-beta.1`, `1.2.3+build`), not glued to
41
+ * other version-like digits (`10.0.0.1`, `1.2.3.4`). A period that ends a sentence (`is 1.2.3.`)
42
+ * is not part of the version and is kept. Global: every version of a marked line is rewritten.
43
+ */
44
+ export const MARKED_VERSION_PATTERN =
45
+ /(?<![\d.])\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?!\.?\d)/gu;
46
+
47
+ /**
48
+ * Splits a versioned file into lines right after each terminator (`\r\n`, `\n` or a lone `\r`),
49
+ * so every line keeps its own terminator and joining the lines gives back the original content.
50
+ */
51
+ export const LINE_TERMINATOR_BOUNDARY_PATTERN = /(?<=\n)|(?<=\r)(?!\n)/u;
52
+
53
+ /**
54
+ * Files the release owns: the bumped `package.json` and the CHANGELOG whose `[Unreleased]` it closes.
55
+ * `versionFiles` cannot list either: rewriting them would undo the bump or the closed section.
56
+ */
57
+ export const RELEASE_COMMIT_BUILT_IN_FILES = Object.freeze([PACKAGE_MANIFEST_FILE, CHANGELOG_FILE]);
58
+
59
+ /**
60
+ * Git pathspec magic that matches a configured path literally, so names starting with `:` or
61
+ * holding `*`/`?` are never read as pathspec syntax.
62
+ */
63
+ export const GIT_LITERAL_PATHSPEC_PREFIX = ":(literal)";
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Release version rules shared by `create-version` and the Vercel build gate.
3
+ *
4
+ * @module constants/versions
5
+ */
6
+
7
+ /** Semver release types, from the smallest to the largest change. */
8
+ export const RELEASE_TYPE = Object.freeze({
9
+ patch: "patch",
10
+ minor: "minor",
11
+ major: "major",
12
+ });
13
+
14
+ /**
15
+ * Suggested release type before `1.0.0` with `preMajorShift`: one level down, the `0.x` convention
16
+ * where a minor carries breaking changes and a patch carries features (release-please's
17
+ * `bump-minor-pre-major` plus `bump-patch-for-minor-pre-major`).
18
+ */
19
+ export const PRE_MAJOR_SHIFTED_RELEASE_TYPE = Object.freeze({
20
+ patch: RELEASE_TYPE.patch,
21
+ minor: RELEASE_TYPE.patch,
22
+ major: RELEASE_TYPE.minor,
23
+ });
24
+
25
+ /** Major version of the `0.x` line, where `preMajorShift` applies. */
26
+ export const PRE_MAJOR_VERSION = 0;
27
+
28
+ /**
29
+ * Version of a package that was never released (the release-please placeholder): the commit that
30
+ * sets it is not a release, and its first release keeps the unshifted suggestion (a feature gives
31
+ * `0.1.0`, not `0.0.1`).
32
+ */
33
+ export const UNRELEASED_PLACEHOLDER_VERSION = "0.0.0";
34
+
35
+ /** Release types in the order they are offered: patch, minor, major. */
36
+ export const RELEASE_TYPE_ORDER = Object.freeze([RELEASE_TYPE.patch, RELEASE_TYPE.minor, RELEASE_TYPE.major]);
37
+
38
+ /** Stable `X.Y.Z` release version: no prerelease, build metadata, prefix or leading zeros. */
39
+ export const RELEASE_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
40
+
41
+ /** Any semver version, capturing its `X.Y.Z` core and optional prerelease. */
42
+ export const SEMVER_PATTERN = /^((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
43
+
44
+ /** Prefix of the annotated Git tags that mark each release (`v0.93.0`). */
45
+ export const RELEASE_TAG_PREFIX = "v";
46
+
47
+ /** `git log --grep` pattern of release commit subjects (`0.93.0`). */
48
+ export const RELEASE_COMMIT_SUBJECT_GREP = String.raw`^[0-9]+\.[0-9]+\.[0-9]+$`;
49
+
50
+ /** Conventional commit header: `type(scope)!: subject`. */
51
+ export const CONVENTIONAL_HEADER_PATTERN = /^(?<type>[a-z]+)(?:\([^)]*\))?(?<breaking>!)?:\s/i;
52
+
53
+ /** Footer that marks a breaking change in a conventional commit body. */
54
+ export const BREAKING_CHANGE_FOOTER_PATTERN = /^BREAKING[ -]CHANGE:/m;
55
+
56
+ /** Conventional commit type that ships user-visible features. */
57
+ export const FEATURE_COMMIT_TYPE = "feat";
58
+
59
+ /** Imperative verbs used by legacy, non-conventional feature subjects. */
60
+ export const LEGACY_FEATURE_SUBJECT_PATTERN = /^(add|implement|introduce|support|enable|create|allow)\b/i;