@eserstack/codebase 0.0.0-stage → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +301 -2
  2. package/dist/changelog-gen.d.ts +105 -0
  3. package/dist/changelog-gen.js +498 -0
  4. package/dist/changelog-text.d.ts +39 -0
  5. package/dist/changelog-text.js +82 -0
  6. package/dist/cli-support.d.ts +140 -0
  7. package/dist/cli-support.js +244 -0
  8. package/dist/cli-system/app-opts.d.ts +15 -0
  9. package/dist/cli-system/app-opts.js +13 -0
  10. package/dist/cli-system/app.d.ts +29 -0
  11. package/dist/cli-system/app.js +12 -0
  12. package/dist/cli-system/handlers/completions-setup.d.ts +14 -0
  13. package/dist/cli-system/handlers/completions-setup.js +139 -0
  14. package/dist/cli-system/handlers/completions.d.ts +3 -0
  15. package/dist/cli-system/handlers/completions.js +79 -0
  16. package/dist/cli-system/handlers/doctor.d.ts +8 -0
  17. package/dist/cli-system/handlers/doctor.js +146 -0
  18. package/dist/cli-system/handlers/info.d.ts +3 -0
  19. package/dist/cli-system/handlers/info.js +69 -0
  20. package/dist/cli-system/handlers/install.d.ts +8 -0
  21. package/dist/cli-system/handlers/install.js +137 -0
  22. package/dist/cli-system/handlers/mod.d.ts +12 -0
  23. package/dist/cli-system/handlers/mod.js +13 -0
  24. package/dist/cli-system/handlers/uninstall.d.ts +3 -0
  25. package/dist/cli-system/handlers/uninstall.js +60 -0
  26. package/dist/cli-system/handlers/update.d.ts +76 -0
  27. package/dist/cli-system/handlers/update.js +310 -0
  28. package/dist/cli-system/handlers/version-check.d.ts +16 -0
  29. package/dist/cli-system/handlers/version-check.js +176 -0
  30. package/dist/cli-system/handlers/version.d.ts +3 -0
  31. package/dist/cli-system/handlers/version.js +45 -0
  32. package/dist/cli-system/mod.d.ts +19 -0
  33. package/dist/cli-system/mod.js +52 -0
  34. package/dist/commitmsg.d.ts +28 -0
  35. package/dist/commitmsg.js +232 -0
  36. package/dist/directive-analysis.d.ts +75 -0
  37. package/dist/directive-analysis.js +223 -0
  38. package/dist/ffi-client.d.ts +11 -0
  39. package/dist/ffi-client.js +12 -0
  40. package/dist/file-tool.d.ts +96 -0
  41. package/dist/file-tool.js +274 -0
  42. package/dist/file-tools-shared.d.ts +81 -0
  43. package/dist/file-tools-shared.js +276 -0
  44. package/dist/gh-contributors.d.ts +89 -0
  45. package/dist/gh-contributors.js +205 -0
  46. package/dist/gh.d.ts +3 -0
  47. package/dist/gh.js +64 -0
  48. package/dist/git-listing.d.ts +27 -0
  49. package/dist/git-listing.js +69 -0
  50. package/dist/git.d.ts +172 -0
  51. package/dist/git.js +277 -0
  52. package/dist/install.d.ts +34 -0
  53. package/dist/install.js +421 -0
  54. package/dist/main.d.ts +22 -0
  55. package/dist/main.js +14 -0
  56. package/dist/mod.d.ts +25 -0
  57. package/dist/mod.js +8 -0
  58. package/dist/module.d.ts +10 -0
  59. package/dist/module.js +221 -0
  60. package/dist/native-functions.d.ts +1088 -0
  61. package/dist/native-functions.js +2 -0
  62. package/dist/npm-externals.d.ts +27 -0
  63. package/dist/npm-externals.js +34 -0
  64. package/dist/npm-workspace-specifiers.d.ts +6 -0
  65. package/dist/npm-workspace-specifiers.js +45 -0
  66. package/dist/package/loader.d.ts +34 -0
  67. package/dist/package/loader.js +203 -0
  68. package/dist/package/mod.d.ts +36 -0
  69. package/dist/package/mod.js +5 -0
  70. package/dist/package/types.d.ts +142 -0
  71. package/dist/package/types.js +32 -0
  72. package/dist/package/workspace.d.ts +33 -0
  73. package/dist/package/workspace.js +158 -0
  74. package/dist/package/writer.d.ts +52 -0
  75. package/dist/package/writer.js +278 -0
  76. package/dist/package.json +275 -0
  77. package/dist/release-notes.d.ts +90 -0
  78. package/dist/release-notes.js +236 -0
  79. package/dist/release-tag.d.ts +46 -0
  80. package/dist/release-tag.js +95 -0
  81. package/dist/release.d.ts +145 -0
  82. package/dist/release.js +584 -0
  83. package/dist/source-mask.d.ts +3 -0
  84. package/dist/source-mask.js +185 -0
  85. package/dist/validate-bom.d.ts +5 -0
  86. package/dist/validate-bom.js +43 -0
  87. package/dist/validate-case-conflict.d.ts +5 -0
  88. package/dist/validate-case-conflict.js +43 -0
  89. package/dist/validate-circular-deps.d.ts +11 -0
  90. package/dist/validate-circular-deps.js +53 -0
  91. package/dist/validate-code-conventions.d.ts +22 -0
  92. package/dist/validate-code-conventions.js +166 -0
  93. package/dist/validate-commit-msg.d.ts +50 -0
  94. package/dist/validate-commit-msg.js +182 -0
  95. package/dist/validate-docs.d.ts +20 -0
  96. package/dist/validate-docs.js +78 -0
  97. package/dist/validate-eof.d.ts +5 -0
  98. package/dist/validate-eof.js +61 -0
  99. package/dist/validate-error-coverage.d.ts +28 -0
  100. package/dist/validate-error-coverage.js +93 -0
  101. package/dist/validate-export-names.d.ts +17 -0
  102. package/dist/validate-export-names.js +56 -0
  103. package/dist/validate-filenames.d.ts +5 -0
  104. package/dist/validate-filenames.js +151 -0
  105. package/dist/validate-json.d.ts +5 -0
  106. package/dist/validate-json.js +71 -0
  107. package/dist/validate-large-files.d.ts +5 -0
  108. package/dist/validate-large-files.js +41 -0
  109. package/dist/validate-laroux-boundaries.d.ts +19 -0
  110. package/dist/validate-laroux-boundaries.js +59 -0
  111. package/dist/validate-licenses.d.ts +5 -0
  112. package/dist/validate-licenses.js +137 -0
  113. package/dist/validate-line-endings.d.ts +5 -0
  114. package/dist/validate-line-endings.js +47 -0
  115. package/dist/validate-merge-conflict.d.ts +5 -0
  116. package/dist/validate-merge-conflict.js +46 -0
  117. package/dist/validate-mod-exports.d.ts +16 -0
  118. package/dist/validate-mod-exports.js +56 -0
  119. package/dist/validate-naming-and-todos.d.ts +5 -0
  120. package/dist/validate-naming-and-todos.js +70 -0
  121. package/dist/validate-runtime-js-apis.d.ts +5 -0
  122. package/dist/validate-runtime-js-apis.js +78 -0
  123. package/dist/validate-secrets.d.ts +5 -0
  124. package/dist/validate-secrets.js +82 -0
  125. package/dist/validate-self-imports.d.ts +5 -0
  126. package/dist/validate-self-imports.js +78 -0
  127. package/dist/validate-server-loc.d.ts +32 -0
  128. package/dist/validate-server-loc.js +94 -0
  129. package/dist/validate-shebangs.d.ts +5 -0
  130. package/dist/validate-shebangs.js +33 -0
  131. package/dist/validate-stream.d.ts +25 -0
  132. package/dist/validate-stream.js +62 -0
  133. package/dist/validate-submodules.d.ts +5 -0
  134. package/dist/validate-submodules.js +43 -0
  135. package/dist/validate-symlinks.d.ts +5 -0
  136. package/dist/validate-symlinks.js +46 -0
  137. package/dist/validate-toml.d.ts +5 -0
  138. package/dist/validate-toml.js +40 -0
  139. package/dist/validate-trailing-whitespace.d.ts +5 -0
  140. package/dist/validate-trailing-whitespace.js +49 -0
  141. package/dist/validate-yaml.d.ts +5 -0
  142. package/dist/validate-yaml.js +40 -0
  143. package/dist/validation/config.d.ts +17 -0
  144. package/dist/validation/config.js +30 -0
  145. package/dist/validation/mod.d.ts +71 -0
  146. package/dist/validation/mod.js +479 -0
  147. package/dist/validation/registry.d.ts +57 -0
  148. package/dist/validation/registry.js +256 -0
  149. package/dist/validation/types.d.ts +101 -0
  150. package/dist/validation/types.js +2 -0
  151. package/dist/validation/validators/circular-deps.d.ts +7 -0
  152. package/dist/validation/validators/circular-deps.js +31 -0
  153. package/dist/validation/validators/docs.d.ts +7 -0
  154. package/dist/validation/validators/docs.js +38 -0
  155. package/dist/validation/validators/error-coverage.d.ts +2 -0
  156. package/dist/validation/validators/error-coverage.js +46 -0
  157. package/dist/validation/validators/export-names.d.ts +7 -0
  158. package/dist/validation/validators/export-names.js +31 -0
  159. package/dist/validation/validators/laroux-boundaries.d.ts +2 -0
  160. package/dist/validation/validators/laroux-boundaries.js +29 -0
  161. package/dist/validation/validators/mod-exports.d.ts +7 -0
  162. package/dist/validation/validators/mod-exports.js +32 -0
  163. package/dist/validation/validators/mod.d.ts +11 -0
  164. package/dist/validation/validators/mod.js +12 -0
  165. package/dist/validation/validators/server-loc.d.ts +2 -0
  166. package/dist/validation/validators/server-loc.js +48 -0
  167. package/dist/versions.d.ts +166 -0
  168. package/dist/versions.js +349 -0
  169. package/dist/violation-baseline.d.ts +58 -0
  170. package/dist/violation-baseline.js +144 -0
  171. package/dist/walk-stream.d.ts +24 -0
  172. package/dist/walk-stream.js +55 -0
  173. package/dist/workspace-discovery.d.ts +60 -0
  174. package/dist/workspace-discovery.js +130 -0
  175. package/package.json +222 -3
package/dist/git.js ADDED
@@ -0,0 +1,277 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Git utility functions for working with git repositories.
4
+ * Uses @eserstack/standards/cross-runtime for cross-runtime command execution.
5
+ *
6
+ * @module
7
+ */
8
+ import * as shellExec from "@eserstack/shell/exec";
9
+ import * as ffiClient from "./ffi-client.js";
10
+ // A random separator that is unlikely to be in a commit message.
11
+ const COMMIT_SEPARATOR = "#%$".repeat(35);
12
+ /**
13
+ * Parses commit log output into Commit objects.
14
+ * Shared by getCommitsBetween and getCommitsSinceDate.
15
+ */
16
+ const parseCommitLog = (text) => {
17
+ const commits = text.split(COMMIT_SEPARATOR).map((commit) => {
18
+ const hash = commit.slice(0, 40);
19
+ commit = commit.slice(40);
20
+ const i = commit.indexOf("\n");
21
+ if (i < 0) {
22
+ return { hash, subject: commit.trim(), body: "" };
23
+ }
24
+ const subject = commit.slice(0, i).trim();
25
+ const body = commit.slice(i + 1).trim();
26
+ return { hash, subject, body };
27
+ });
28
+ commits.shift(); // drop the first empty item
29
+ return commits;
30
+ };
31
+ /**
32
+ * Restores the fields the bridge omits so both the FFI and the shell fallback
33
+ * path yield the same commit shape.
34
+ */
35
+ const normalizeWireCommits = (commits) => commits.map((commit) => ({
36
+ subject: commit.subject,
37
+ body: commit.body ?? "",
38
+ hash: commit.hash,
39
+ }));
40
+ /**
41
+ * Gets the latest tag in the current branch.
42
+ *
43
+ * @returns The latest tag name
44
+ * @throws If no tags are found or git command fails
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const tag = await getLatestTag();
49
+ * console.log(tag); // "v1.0.0"
50
+ * ```
51
+ */
52
+ export const getLatestTag = async () => {
53
+ await ffiClient.ensureLib();
54
+ const lib = ffiClient.getLib();
55
+ if (lib !== null) {
56
+ try {
57
+ const parsed = lib.call("codebaseGitLatestTag", {});
58
+ if (!parsed.error && parsed.tag !== undefined) {
59
+ return parsed.tag.trim();
60
+ }
61
+ }
62
+ catch {
63
+ /* fall through to TS */
64
+ }
65
+ }
66
+ return await shellExec.exec `git describe --tags --abbrev=0`.text();
67
+ };
68
+ /**
69
+ * Gets the name of the current git branch.
70
+ *
71
+ * @returns The current branch name
72
+ * @throws If not in a git repository or in detached HEAD state
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const branch = await getCurrentBranch();
77
+ * console.log(branch); // "main"
78
+ * ```
79
+ */
80
+ export const getCurrentBranch = async () => {
81
+ await ffiClient.ensureLib();
82
+ const lib = ffiClient.getLib();
83
+ if (lib !== null) {
84
+ try {
85
+ const parsed = lib.call("codebaseGitCurrentBranch", {});
86
+ if (!parsed.error && parsed.branch !== undefined) {
87
+ return parsed.branch.trim();
88
+ }
89
+ }
90
+ catch {
91
+ /* fall through to TS */
92
+ }
93
+ }
94
+ return await shellExec.exec `git branch --show-current`.text();
95
+ };
96
+ /**
97
+ * Checks out a specific git reference (branch, tag, or commit).
98
+ *
99
+ * @param ref - The reference to checkout (branch name, tag, or commit hash)
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * await checkout("main");
104
+ * await checkout("v1.0.0");
105
+ * await checkout("abc123");
106
+ * ```
107
+ */
108
+ export const checkout = async (ref) => {
109
+ await shellExec.exec `git checkout ${ref}`.spawn();
110
+ };
111
+ /**
112
+ * Checks out the previous git reference (equivalent to `git checkout -`).
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * await checkout("feature-branch");
117
+ * // do some work
118
+ * await checkoutPrevious(); // goes back to previous branch
119
+ * ```
120
+ */
121
+ export const checkoutPrevious = async () => {
122
+ await shellExec.exec `git checkout -`.spawn();
123
+ };
124
+ /**
125
+ * Creates a new branch and checks it out.
126
+ *
127
+ * @param name - The name of the new branch
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * await createAndCheckoutBranch("feature/new-feature");
132
+ * ```
133
+ */
134
+ export const createAndCheckoutBranch = async (name) => {
135
+ await shellExec.exec `git checkout -b ${name}`.spawn();
136
+ };
137
+ /**
138
+ * Gets all commits between two git references.
139
+ *
140
+ * @param start - The starting reference (exclusive)
141
+ * @param end - The ending reference (inclusive)
142
+ * @returns Array of commits with hash, subject, and body
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const commits = await getCommitsBetween("v1.0.0", "main");
147
+ * for (const commit of commits) {
148
+ * console.log(`${commit.hash}: ${commit.subject}`);
149
+ * }
150
+ * ```
151
+ */
152
+ export const getCommitsBetween = async (start, end) => {
153
+ await ffiClient.ensureLib();
154
+ const lib = ffiClient.getLib();
155
+ if (lib !== null) {
156
+ try {
157
+ const parsed = lib.call("codebaseGitLog", { start, end });
158
+ if (!parsed.error && parsed.commits !== undefined) {
159
+ return normalizeWireCommits(parsed.commits);
160
+ }
161
+ }
162
+ catch {
163
+ /* fall through to TS */
164
+ }
165
+ }
166
+ const format = `--pretty=format:${COMMIT_SEPARATOR}%H%B`;
167
+ const range = `${start}..${end}`;
168
+ const text = await shellExec.exec `git --no-pager log ${format} ${range}`.text();
169
+ return parseCommitLog(text);
170
+ };
171
+ /**
172
+ * Gets all commits since a specific date.
173
+ *
174
+ * @param date - The date in YYYY.MM.DD or YYYY-MM-DD format
175
+ * @returns Array of commits with hash, subject, and body
176
+ *
177
+ * @example
178
+ * ```typescript
179
+ * const commits = await getCommitsSinceDate("2024.07.16");
180
+ * for (const commit of commits) {
181
+ * console.log(`${commit.hash}: ${commit.subject}`);
182
+ * }
183
+ * ```
184
+ */
185
+ export const getCommitsSinceDate = async (date) => {
186
+ await ffiClient.ensureLib();
187
+ const lib = ffiClient.getLib();
188
+ if (lib !== null) {
189
+ try {
190
+ const parsed = lib.call("codebaseGitLog", { since: date });
191
+ if (!parsed.error && parsed.commits !== undefined) {
192
+ return normalizeWireCommits(parsed.commits);
193
+ }
194
+ }
195
+ catch {
196
+ /* fall through to TS */
197
+ }
198
+ }
199
+ // Convert YYYY.MM.DD to YYYY-MM-DD if needed
200
+ const gitDate = date.replace(/\./g, "-");
201
+ const after = `--after=${gitDate}`;
202
+ const format = `--pretty=format:${COMMIT_SEPARATOR}%H%B`;
203
+ const text = await shellExec.exec `git --no-pager log ${after} ${format}`.text();
204
+ return parseCommitLog(text);
205
+ };
206
+ /**
207
+ * Stages all changes in the working directory.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * await stageAll();
212
+ * ```
213
+ */
214
+ export const stageAll = async () => {
215
+ await shellExec.exec `git add .`.spawn();
216
+ };
217
+ /**
218
+ * Creates a commit with the specified message and user.
219
+ *
220
+ * @param message - The commit message
221
+ * @param user - The commit author (name and email)
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * await commit("feat: add new feature", {
226
+ * name: "John Doe",
227
+ * email: "john@example.com"
228
+ * });
229
+ * ```
230
+ */
231
+ export const commit = async (message, user) => {
232
+ const userName = `-c user.name=${user.name}`;
233
+ const userEmail = `-c user.email=${user.email}`;
234
+ await shellExec.exec `git ${userName} ${userEmail} commit -m ${message}`.spawn();
235
+ };
236
+ /**
237
+ * Pushes a branch to a remote repository.
238
+ *
239
+ * @param remote - The remote name (e.g., "origin")
240
+ * @param branch - The branch name to push
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * await push("origin", "feature-branch");
245
+ * ```
246
+ */
247
+ export const push = async (remote, branch) => {
248
+ await shellExec.exec `git push ${remote} ${branch}`.spawn();
249
+ };
250
+ /**
251
+ * Creates an annotated git tag.
252
+ *
253
+ * @param tag - The tag name (e.g., "v1.0.0")
254
+ * @param message - The tag annotation message
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * await createTag("v1.0.0", "Release v1.0.0");
259
+ * ```
260
+ */
261
+ export const createTag = async (tag, message) => {
262
+ await shellExec.exec `git tag -a ${tag} -m ${message}`.spawn();
263
+ };
264
+ /**
265
+ * Pushes a tag to a remote repository.
266
+ *
267
+ * @param remote - The remote name (e.g., "origin")
268
+ * @param tag - The tag name to push
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * await pushTag("origin", "v1.0.0");
273
+ * ```
274
+ */
275
+ export const pushTag = async (remote, tag) => {
276
+ await shellExec.exec `git push ${remote} ${tag}`.spawn();
277
+ };
@@ -0,0 +1,34 @@
1
+ import type * as shellArgs from "@eserstack/shell/args";
2
+ /**
3
+ * Generate the shell script content for a git hook.
4
+ */
5
+ export declare const generateHookScript: (cliCmd: string, event: string, args: string) => string;
6
+ /** The flags of `eser codebase install`. */
7
+ export type InstallArgs = {
8
+ readonly help: boolean;
9
+ readonly force: boolean;
10
+ readonly dryRun: boolean;
11
+ };
12
+ /** Parse the install arguments: `--force` (`-f`), `--dry-run` (`-n`), `--help` (`-h`). */
13
+ export declare const parseInstallArgs: (cliArgs?: readonly string[]) => InstallArgs;
14
+ /** Parse the arguments of `uninstall` and `status`, which only know `--help` (`-h`). */
15
+ export declare const parseHelpArgs: (cliArgs?: readonly string[]) => {
16
+ readonly help: boolean;
17
+ };
18
+ /**
19
+ * Install managed git hooks based on `.eser/manifest.yml` workflow events.
20
+ *
21
+ * Flags:
22
+ * --force Overwrite non-managed hooks
23
+ * --dry-run Show what would happen without writing
24
+ * --help Show usage
25
+ */
26
+ export declare const main: (cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
27
+ /**
28
+ * Remove all managed git hooks (those containing the `@eser managed hook` marker).
29
+ */
30
+ export declare const uninstallMain: (cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
31
+ /**
32
+ * Show the installation status of git hooks expected by the manifest.
33
+ */
34
+ export declare const statusMain: (cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;