@eserstack/codebase 0.0.0-bootstrap.0 → 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 +302 -0
  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 +225 -1
@@ -0,0 +1,144 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Per-file violation baselines for validators that enforce a rule on new code
4
+ * while existing code is migrated.
5
+ *
6
+ * A baseline records, per rule, how many violations each file had when it was
7
+ * written. A file fails a rule only when it has more violations than its
8
+ * baseline allows, so new code follows the rule from the start and the counts
9
+ * only ever shrink. `validate-code-conventions` and `validate-runtime-js-apis`
10
+ * keep their baselines under `.eser/baselines/`.
11
+ *
12
+ * @module
13
+ */
14
+ import { runtime } from "@eserstack/standards/cross-runtime";
15
+ import * as shared from "./file-tools-shared.js";
16
+ const emptyCounts = (rules) => {
17
+ const counts = {};
18
+ for (const rule of rules) {
19
+ counts[rule] = {};
20
+ }
21
+ return counts;
22
+ };
23
+ /** A baseline that allows no violation of any of `rules`. */
24
+ export const emptyBaseline = (rules) => emptyCounts(rules);
25
+ /** `file` relative to `root`, with `/` separators on every platform. */
26
+ export const relativePath = (root, file) => runtime.path
27
+ .relative(runtime.path.resolve(root), file)
28
+ .split(runtime.path.sep)
29
+ .join("/");
30
+ /**
31
+ * Resolves the `baseline` option of a validator against the scanned root.
32
+ * Throws when the option is not a path, so a typo in the manifest fails loudly
33
+ * instead of silently allowing nothing.
34
+ */
35
+ export const resolveBaselinePath = (validatorName, root, option) => {
36
+ if (typeof option !== "string" || option === "") {
37
+ throw new Error(`${validatorName}: the baseline option must be a file path relative to the root, got ${JSON.stringify(option)}; fix the ${validatorName} step options in .eser/manifest.yml`);
38
+ }
39
+ return runtime.path.resolve(root, option);
40
+ };
41
+ /**
42
+ * Reads a baseline file. A missing file is an empty baseline, so a validator
43
+ * without one fails on every violation.
44
+ */
45
+ export const readBaseline = async (file, rules) => {
46
+ if (!(await runtime.fs.exists(file))) {
47
+ return emptyBaseline(rules);
48
+ }
49
+ const text = await runtime.fs.readTextFile(file);
50
+ let parsed;
51
+ try {
52
+ parsed = JSON.parse(text);
53
+ }
54
+ catch (error) {
55
+ const reason = error instanceof Error ? error.message : String(error);
56
+ throw new Error(`baseline ${file} is not valid JSON (${reason}); regenerate it with --write-baseline`);
57
+ }
58
+ return { ...emptyBaseline(rules), ...parsed };
59
+ };
60
+ /**
61
+ * Loads each file and returns the violations `find` reports, leaving out the
62
+ * files `skip` names and the files with none.
63
+ */
64
+ export const collectViolations = async (root, files, find, skip) => {
65
+ const found = [];
66
+ for (const file of files) {
67
+ const relPath = relativePath(root, file.path);
68
+ if (skip(relPath))
69
+ continue;
70
+ // Files load one at a time: reading thousands at once can exhaust the
71
+ // open file handle limit.
72
+ // oxlint-disable-next-line no-await-in-loop
73
+ const content = await shared.loadContent(file);
74
+ if (content === undefined)
75
+ continue;
76
+ const violations = find(content);
77
+ if (violations.length === 0)
78
+ continue;
79
+ found.push({ path: file.path, relPath, violations });
80
+ }
81
+ return found;
82
+ };
83
+ /**
84
+ * The violations of one file above its baseline. When a rule is over its
85
+ * count, every violation of that rule in the file is reported, since the
86
+ * baseline cannot tell which of them is new.
87
+ */
88
+ export const issuesAboveBaseline = (baseline, file) => {
89
+ const byRule = new Map();
90
+ for (const violation of file.violations) {
91
+ const list = byRule.get(violation.rule) ?? [];
92
+ list.push(violation);
93
+ byRule.set(violation.rule, list);
94
+ }
95
+ const issues = [];
96
+ for (const [rule, found] of byRule) {
97
+ const allowed = baseline[rule][file.relPath] ?? 0;
98
+ if (found.length <= allowed)
99
+ continue;
100
+ for (const violation of found) {
101
+ issues.push({
102
+ path: file.path,
103
+ line: violation.line,
104
+ message: allowed === 0
105
+ ? violation.message
106
+ : `${violation.message} [${found.length} in this file, baseline allows ${allowed}]`,
107
+ });
108
+ }
109
+ }
110
+ return issues;
111
+ };
112
+ /** Counts the given violations into a baseline for `rules`. */
113
+ export const buildBaseline = (rules, files) => {
114
+ const counts = emptyCounts(rules);
115
+ for (const file of files) {
116
+ for (const violation of file.violations) {
117
+ const byFile = counts[violation.rule];
118
+ byFile[file.relPath] = (byFile[file.relPath] ?? 0) + 1;
119
+ }
120
+ }
121
+ return counts;
122
+ };
123
+ /** The number of violations a baseline allows in total. */
124
+ export const baselineTotal = (baseline) => {
125
+ let total = 0;
126
+ for (const byFile of Object.values(baseline)) {
127
+ for (const count of Object.values(byFile)) {
128
+ total += count;
129
+ }
130
+ }
131
+ return total;
132
+ };
133
+ /**
134
+ * Writes a baseline with its files sorted, so regenerating an unchanged
135
+ * baseline produces no diff.
136
+ */
137
+ export const writeBaselineFile = async (file, baseline) => {
138
+ const sorted = Object.fromEntries(Object.entries(baseline).map(([rule, byFile]) => [
139
+ rule,
140
+ Object.fromEntries(Object.entries(byFile).sort(([a], [b]) => a.localeCompare(b))),
141
+ ]));
142
+ await runtime.fs.mkdir(runtime.path.dirname(file), { recursive: true });
143
+ await runtime.fs.writeTextFile(file, `${JSON.stringify(sorted, null, 2)}\n`);
144
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Streaming file walk via the Go FFI bridge.
3
+ *
4
+ * Returns an `AsyncIterable<FileEntry>` backed by the bridge's
5
+ * `codebaseWalkFilesStream` stream.
6
+ * Supports `await using` / `Symbol.asyncDispose` for deterministic cleanup.
7
+ *
8
+ * @module
9
+ */
10
+ import type * as ffiTypes from "@eserstack/ajan/ffi";
11
+ import type { FileEntry } from "./file-tools-shared.ts";
12
+ export type WalkStreamOptions = {
13
+ readonly dir?: string;
14
+ readonly extensions?: readonly string[];
15
+ readonly exclude?: readonly string[];
16
+ readonly gitAware?: boolean;
17
+ };
18
+ export declare class WalkStream implements AsyncIterable<FileEntry>, AsyncDisposable {
19
+ #private;
20
+ constructor(stream: ffiTypes.AjanStream<"codebaseWalkFilesStream">);
21
+ [Symbol.asyncIterator](): AsyncGenerator<FileEntry>;
22
+ [Symbol.asyncDispose](): Promise<void>;
23
+ }
24
+ export declare const walkFilesStream: (options?: WalkStreamOptions) => Promise<WalkStream>;
@@ -0,0 +1,55 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ import * as ffiClient from "./ffi-client.js";
3
+ import * as gitListing from "./git-listing.js";
4
+ // =============================================================================
5
+ // WalkStream
6
+ // =============================================================================
7
+ export class WalkStream {
8
+ #stream;
9
+ constructor(stream) {
10
+ this.#stream = stream;
11
+ }
12
+ async *[Symbol.asyncIterator]() {
13
+ while (true) {
14
+ const parsed = this.#stream.read();
15
+ if (parsed === null) {
16
+ break;
17
+ }
18
+ if (parsed.error !== undefined) {
19
+ throw new Error(`walk stream error: ${parsed.error}`);
20
+ }
21
+ yield {
22
+ path: parsed.path ?? "",
23
+ name: parsed.name ?? "",
24
+ size: parsed.size ?? 0,
25
+ isSymlink: parsed.isSymlink ?? false,
26
+ };
27
+ }
28
+ }
29
+ [Symbol.asyncDispose]() {
30
+ this.#stream.close();
31
+ return Promise.resolve();
32
+ }
33
+ }
34
+ // =============================================================================
35
+ // Factory
36
+ // =============================================================================
37
+ export const walkFilesStream = async (options = {}) => {
38
+ await ffiClient.ensureLib();
39
+ const lib = ffiClient.getLib();
40
+ if (lib === null) {
41
+ throw new Error("FFI library unavailable — cannot create walk stream");
42
+ }
43
+ const dir = options.dir ?? ".";
44
+ const stream = lib.stream("codebaseWalkFilesStream", {
45
+ dir,
46
+ extensions: options.extensions,
47
+ exclude: options.exclude,
48
+ ...(await gitListing.bridgeGitOptions(lib, dir, options.gitAware ?? false)),
49
+ });
50
+ const parsed = stream.opened;
51
+ if (parsed.error !== undefined || parsed.handle === undefined) {
52
+ throw new Error(`walk stream create failed: ${parsed.error ?? "no handle"}`);
53
+ }
54
+ return new WalkStream(stream);
55
+ };
@@ -0,0 +1,60 @@
1
+ import type { PackageConfig, WorkspaceModule } from "./package/types.ts";
2
+ /**
3
+ * Information about a discovered package.
4
+ */
5
+ export type DiscoveredPackage = {
6
+ /** Package name (e.g., "@eserstack/config") */
7
+ readonly name: string;
8
+ /** Package version */
9
+ readonly version: string;
10
+ /** Absolute path to package directory */
11
+ readonly path: string;
12
+ /** Package configuration */
13
+ readonly config: PackageConfig;
14
+ /** Package entrypoints (export paths) */
15
+ readonly entrypoints: string[];
16
+ };
17
+ /**
18
+ * Discovers all packages in a workspace.
19
+ *
20
+ * @param root - Root directory containing workspace configuration
21
+ * @returns Array of discovered packages with their configurations
22
+ */
23
+ export declare const discoverPackages: (root?: string) => Promise<DiscoveredPackage[]>;
24
+ /**
25
+ * Extracts all entrypoint paths from a package configuration.
26
+ *
27
+ * Entrypoints are derived from the package's exports field.
28
+ *
29
+ * @param config - Package configuration
30
+ * @returns Array of entrypoint file paths (relative to package directory)
31
+ */
32
+ export declare const extractEntrypoints: (config: PackageConfig) => string[];
33
+ /**
34
+ * Resolves a module specifier to an absolute path.
35
+ *
36
+ * @param specifier - Module specifier (relative or absolute)
37
+ * @param basePath - Base path for resolution
38
+ * @returns Resolved absolute path
39
+ */
40
+ export declare const resolveModulePath: (specifier: string, basePath: string) => string;
41
+ /**
42
+ * Gets all TypeScript files in a package directory.
43
+ *
44
+ * Excludes test and benchmark files (`*.test.ts` and `*.bench.ts`, and the
45
+ * older `*_test.ts` and `*_bench.ts` forms, for every JS and TS extension),
46
+ * private files (`_*.ts`) and `testdata/` directories.
47
+ *
48
+ * @param packagePath - Path to package directory
49
+ * @returns Array of TypeScript file paths (relative to package directory)
50
+ */
51
+ export declare const getPackageFiles: (packagePath: string) => Promise<string[]>;
52
+ /**
53
+ * Gets the root package configuration and all workspace modules.
54
+ *
55
+ * This is a convenience wrapper around pkg.getWorkspaceModules.
56
+ *
57
+ * @param root - Root directory
58
+ * @returns Tuple of [root config, workspace modules]
59
+ */
60
+ export declare const getWorkspace: (root?: string) => Promise<[PackageConfig, WorkspaceModule[]]>;
@@ -0,0 +1,130 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Workspace discovery utilities for codebase validation tools.
4
+ *
5
+ * Provides functions to discover packages, extract entrypoints, and resolve
6
+ * module paths within a workspace.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import * as discovery from "@eserstack/codebase/workspace-discovery";
11
+ *
12
+ * // Discover all packages in workspace
13
+ * const packages = await discovery.discoverPackages(".");
14
+ *
15
+ * // Extract entrypoints from a package
16
+ * const entrypoints = discovery.extractEntrypoints(packageConfig);
17
+ *
18
+ * // Resolve a module path
19
+ * const resolved = discovery.resolveModulePath("./utils.ts", "/path/to/package");
20
+ * ```
21
+ *
22
+ * @module
23
+ */
24
+ import * as patterns from "@eserstack/standards/patterns";
25
+ import { runtime } from "@eserstack/standards/cross-runtime";
26
+ import * as pkg from "./package/mod.js";
27
+ /**
28
+ * Discovers all packages in a workspace.
29
+ *
30
+ * @param root - Root directory containing workspace configuration
31
+ * @returns Array of discovered packages with their configurations
32
+ */
33
+ export const discoverPackages = async (root = ".") => {
34
+ const [_rootConfig, modules] = await pkg.getWorkspaceModules(root);
35
+ return modules.map((module) => ({
36
+ name: module.name,
37
+ version: module.version,
38
+ path: pkg.getBaseDir(module.config),
39
+ config: module.config,
40
+ entrypoints: extractEntrypoints(module.config),
41
+ }));
42
+ };
43
+ /**
44
+ * Extracts all entrypoint paths from a package configuration.
45
+ *
46
+ * Entrypoints are derived from the package's exports field.
47
+ *
48
+ * @param config - Package configuration
49
+ * @returns Array of entrypoint file paths (relative to package directory)
50
+ */
51
+ export const extractEntrypoints = (config) => {
52
+ const exports = config.exports?.value;
53
+ if (exports === null || exports === undefined) {
54
+ return [];
55
+ }
56
+ if (typeof exports === "string") {
57
+ return [exports];
58
+ }
59
+ if (exports !== null && typeof exports === "object") {
60
+ const paths = [];
61
+ for (const value of Object.values(exports)) {
62
+ if (typeof value === "string") {
63
+ paths.push(value);
64
+ }
65
+ }
66
+ return paths;
67
+ }
68
+ return [];
69
+ };
70
+ /**
71
+ * Resolves a module specifier to an absolute path.
72
+ *
73
+ * @param specifier - Module specifier (relative or absolute)
74
+ * @param basePath - Base path for resolution
75
+ * @returns Resolved absolute path
76
+ */
77
+ export const resolveModulePath = (specifier, basePath) => {
78
+ if (runtime.path.isAbsolute(specifier)) {
79
+ return specifier;
80
+ }
81
+ return runtime.path.resolve(basePath, specifier);
82
+ };
83
+ /** `x.test.ts`, `x.bench.tsx`, `x_test.js` and the other test and bench names. */
84
+ const TEST_OR_BENCH_FILE = /[._](?:test|bench)\.[cm]?[jt]sx?$/;
85
+ /**
86
+ * Gets all TypeScript files in a package directory.
87
+ *
88
+ * Excludes test and benchmark files (`*.test.ts` and `*.bench.ts`, and the
89
+ * older `*_test.ts` and `*_bench.ts` forms, for every JS and TS extension),
90
+ * private files (`_*.ts`) and `testdata/` directories.
91
+ *
92
+ * @param packagePath - Path to package directory
93
+ * @returns Array of TypeScript file paths (relative to package directory)
94
+ */
95
+ export const getPackageFiles = async (packagePath) => {
96
+ const files = [];
97
+ for await (const entry of runtime.fs.walk(packagePath, {
98
+ exts: patterns.JS_FILE_EXTENSIONS,
99
+ includeDirs: false,
100
+ skip: [/node_modules/, /\.git/],
101
+ })) {
102
+ const relativePath = runtime.path.relative(packagePath, entry.path);
103
+ const fileName = runtime.path.basename(relativePath);
104
+ if (TEST_OR_BENCH_FILE.test(fileName)) {
105
+ continue;
106
+ }
107
+ // Skip private files (starting with _)
108
+ if (fileName.startsWith("_")) {
109
+ continue;
110
+ }
111
+ // Skip testdata directories. Split on both separators so the check also
112
+ // holds for the backslash paths runtime.path.relative returns on Windows.
113
+ if (relativePath.split(/[\\/]/).includes("testdata")) {
114
+ continue;
115
+ }
116
+ files.push(`./${relativePath}`);
117
+ }
118
+ return files.sort();
119
+ };
120
+ /**
121
+ * Gets the root package configuration and all workspace modules.
122
+ *
123
+ * This is a convenience wrapper around pkg.getWorkspaceModules.
124
+ *
125
+ * @param root - Root directory
126
+ * @returns Tuple of [root config, workspace modules]
127
+ */
128
+ export const getWorkspace = (root = ".") => {
129
+ return pkg.getWorkspaceModules(root);
130
+ };
package/package.json CHANGED
@@ -1 +1,225 @@
1
- {"name":"@eserstack/codebase","version":"0.0.0-bootstrap.0","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/eser/stack.git"}}
1
+ {
2
+ "name": "@eserstack/codebase",
3
+ "version": "5.0.0",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/eser/stack",
8
+ "directory": "pkg/@eserstack/codebase"
9
+ },
10
+ "files": [
11
+ "dist/**/*.js",
12
+ "dist/**/*.d.ts",
13
+ "dist/**/*.json"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/main.d.ts",
18
+ "import": "./dist/main.js"
19
+ },
20
+ "./mod": {
21
+ "types": "./dist/mod.d.ts",
22
+ "import": "./dist/mod.js"
23
+ },
24
+ "./module": {
25
+ "types": "./dist/module.d.ts",
26
+ "import": "./dist/module.js"
27
+ },
28
+ "./directive-analysis": {
29
+ "types": "./dist/directive-analysis.d.ts",
30
+ "import": "./dist/directive-analysis.js"
31
+ },
32
+ "./git": {
33
+ "types": "./dist/git.d.ts",
34
+ "import": "./dist/git.js"
35
+ },
36
+ "./native-functions": {
37
+ "types": "./dist/native-functions.d.ts",
38
+ "import": "./dist/native-functions.js"
39
+ },
40
+ "./package": {
41
+ "types": "./dist/package/mod.d.ts",
42
+ "import": "./dist/package/mod.js"
43
+ },
44
+ "./validation": {
45
+ "types": "./dist/validation/mod.d.ts",
46
+ "import": "./dist/validation/mod.js"
47
+ },
48
+ "./workspace-discovery": {
49
+ "types": "./dist/workspace-discovery.d.ts",
50
+ "import": "./dist/workspace-discovery.js"
51
+ },
52
+ "./validate-circular-deps": {
53
+ "types": "./dist/validate-circular-deps.d.ts",
54
+ "import": "./dist/validate-circular-deps.js"
55
+ },
56
+ "./validate-mod-exports": {
57
+ "types": "./dist/validate-mod-exports.d.ts",
58
+ "import": "./dist/validate-mod-exports.js"
59
+ },
60
+ "./validate-export-names": {
61
+ "types": "./dist/validate-export-names.d.ts",
62
+ "import": "./dist/validate-export-names.js"
63
+ },
64
+ "./validate-docs": {
65
+ "types": "./dist/validate-docs.d.ts",
66
+ "import": "./dist/validate-docs.js"
67
+ },
68
+ "./validate-licenses": {
69
+ "types": "./dist/validate-licenses.d.ts",
70
+ "import": "./dist/validate-licenses.js"
71
+ },
72
+ "./npm-externals": {
73
+ "types": "./dist/npm-externals.d.ts",
74
+ "import": "./dist/npm-externals.js"
75
+ },
76
+ "./npm-workspace-specifiers": {
77
+ "types": "./dist/npm-workspace-specifiers.d.ts",
78
+ "import": "./dist/npm-workspace-specifiers.js"
79
+ },
80
+ "./versions": {
81
+ "types": "./dist/versions.d.ts",
82
+ "import": "./dist/versions.js"
83
+ },
84
+ "./gh": {
85
+ "types": "./dist/gh.d.ts",
86
+ "import": "./dist/gh.js"
87
+ },
88
+ "./gh-contributors": {
89
+ "types": "./dist/gh-contributors.d.ts",
90
+ "import": "./dist/gh-contributors.js"
91
+ },
92
+ "./release-tag": {
93
+ "types": "./dist/release-tag.d.ts",
94
+ "import": "./dist/release-tag.js"
95
+ },
96
+ "./release-notes": {
97
+ "types": "./dist/release-notes.d.ts",
98
+ "import": "./dist/release-notes.js"
99
+ },
100
+ "./changelog-gen": {
101
+ "types": "./dist/changelog-gen.d.ts",
102
+ "import": "./dist/changelog-gen.js"
103
+ },
104
+ "./commitmsg": {
105
+ "types": "./dist/commitmsg.d.ts",
106
+ "import": "./dist/commitmsg.js"
107
+ },
108
+ "./release": {
109
+ "types": "./dist/release.d.ts",
110
+ "import": "./dist/release.js"
111
+ },
112
+ "./cli-support": {
113
+ "types": "./dist/cli-support.d.ts",
114
+ "import": "./dist/cli-support.js"
115
+ },
116
+ "./file-tool": {
117
+ "types": "./dist/file-tool.d.ts",
118
+ "import": "./dist/file-tool.js"
119
+ },
120
+ "./file-tools-shared": {
121
+ "types": "./dist/file-tools-shared.d.ts",
122
+ "import": "./dist/file-tools-shared.js"
123
+ },
124
+ "./walk-stream": {
125
+ "types": "./dist/walk-stream.d.ts",
126
+ "import": "./dist/walk-stream.js"
127
+ },
128
+ "./validate-stream": {
129
+ "types": "./dist/validate-stream.d.ts",
130
+ "import": "./dist/validate-stream.js"
131
+ },
132
+ "./validate-eof": {
133
+ "types": "./dist/validate-eof.d.ts",
134
+ "import": "./dist/validate-eof.js"
135
+ },
136
+ "./validate-trailing-whitespace": {
137
+ "types": "./dist/validate-trailing-whitespace.d.ts",
138
+ "import": "./dist/validate-trailing-whitespace.js"
139
+ },
140
+ "./validate-bom": {
141
+ "types": "./dist/validate-bom.d.ts",
142
+ "import": "./dist/validate-bom.js"
143
+ },
144
+ "./validate-line-endings": {
145
+ "types": "./dist/validate-line-endings.d.ts",
146
+ "import": "./dist/validate-line-endings.js"
147
+ },
148
+ "./validate-large-files": {
149
+ "types": "./dist/validate-large-files.d.ts",
150
+ "import": "./dist/validate-large-files.js"
151
+ },
152
+ "./validate-case-conflict": {
153
+ "types": "./dist/validate-case-conflict.d.ts",
154
+ "import": "./dist/validate-case-conflict.js"
155
+ },
156
+ "./validate-merge-conflict": {
157
+ "types": "./dist/validate-merge-conflict.d.ts",
158
+ "import": "./dist/validate-merge-conflict.js"
159
+ },
160
+ "./validate-json": {
161
+ "types": "./dist/validate-json.d.ts",
162
+ "import": "./dist/validate-json.js"
163
+ },
164
+ "./validate-toml": {
165
+ "types": "./dist/validate-toml.d.ts",
166
+ "import": "./dist/validate-toml.js"
167
+ },
168
+ "./validate-yaml": {
169
+ "types": "./dist/validate-yaml.d.ts",
170
+ "import": "./dist/validate-yaml.js"
171
+ },
172
+ "./validate-symlinks": {
173
+ "types": "./dist/validate-symlinks.d.ts",
174
+ "import": "./dist/validate-symlinks.js"
175
+ },
176
+ "./validate-shebangs": {
177
+ "types": "./dist/validate-shebangs.d.ts",
178
+ "import": "./dist/validate-shebangs.js"
179
+ },
180
+ "./validate-secrets": {
181
+ "types": "./dist/validate-secrets.d.ts",
182
+ "import": "./dist/validate-secrets.js"
183
+ },
184
+ "./validate-filenames": {
185
+ "types": "./dist/validate-filenames.d.ts",
186
+ "import": "./dist/validate-filenames.js"
187
+ },
188
+ "./validate-submodules": {
189
+ "types": "./dist/validate-submodules.d.ts",
190
+ "import": "./dist/validate-submodules.js"
191
+ },
192
+ "./validate-commit-msg": {
193
+ "types": "./dist/validate-commit-msg.d.ts",
194
+ "import": "./dist/validate-commit-msg.js"
195
+ },
196
+ "./install": {
197
+ "types": "./dist/install.d.ts",
198
+ "import": "./dist/install.js"
199
+ }
200
+ },
201
+ "dependencies": {
202
+ "jsonc-parser": "^3.3.1",
203
+ "semver": "^7.8.6",
204
+ "smol-toml": "^1.9.1",
205
+ "yaml": "^2.9.1",
206
+ "@eserstack/ai": "5.0.0",
207
+ "@eserstack/ajan": "5.0.0",
208
+ "@eserstack/config": "5.0.0",
209
+ "@eserstack/fp": "5.0.0",
210
+ "@eserstack/functions": "5.0.0",
211
+ "@eserstack/primitives": "5.0.0",
212
+ "@eserstack/shell": "5.0.0",
213
+ "@eserstack/standards": "5.0.0",
214
+ "@eserstack/streams": "5.0.0",
215
+ "@eserstack/workflows": "5.0.0"
216
+ },
217
+ "devDependencies": {
218
+ "@types/semver": "^7.8.0",
219
+ "@eserstack/test-kit": "5.0.0",
220
+ "@eserstack/logging": "5.0.0"
221
+ },
222
+ "scripts": {
223
+ "build": "node ../../../etc/scripts/build-library.ts"
224
+ }
225
+ }