@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,56 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Module reachability checker.
4
+ *
5
+ * Reports the top-level modules of each package that no entry point reaches:
6
+ * mod.ts, the exports map, the package.json bin, main and module fields, and
7
+ * any module that runs as a program. Such a module is missing from the exports
8
+ * or is dead code.
9
+ *
10
+ * @module
11
+ */
12
+ import * as primitives from "@eserstack/primitives";
13
+ import * as span from "@eserstack/streams/span";
14
+ import * as cliSupport from "./cli-support.js";
15
+ import * as ffiClient from "./ffi-client.js";
16
+ export const checkModExports = async (options = {}) => {
17
+ const { root = "." } = options;
18
+ await ffiClient.ensureLib();
19
+ const lib = ffiClient.getLib();
20
+ if (lib === null) {
21
+ throw new Error("native library not available for checkModExports");
22
+ }
23
+ const result = lib.call("codebaseCheckModExports", {
24
+ dir: root,
25
+ });
26
+ if (result.error) {
27
+ throw new Error(result.error);
28
+ }
29
+ return result;
30
+ };
31
+ export const main = async (_cliArgs) => {
32
+ const { output: out } = cliSupport.getCliContext();
33
+ try {
34
+ const value = await checkModExports({ root: "." });
35
+ out.writeln(span.blue("ℹ"), span.text(` Checked ${value.packagesChecked} packages.`));
36
+ if (!value.isComplete) {
37
+ out.writeln(span.red("✗"), span.text(` Found ${value.missingExports.length} modules no entry point reaches (export them or remove them):`));
38
+ for (const missing of value.missingExports) {
39
+ out.writeln(span.yellow("⚠"), span.text(` ${missing.packageName}: ${missing.file}`));
40
+ }
41
+ return primitives.results.fail({ exitCode: 1 });
42
+ }
43
+ out.writeln(span.green("✓"), span.text(" Every module is reached from a package entry point."));
44
+ return primitives.results.ok(undefined);
45
+ }
46
+ catch (err) {
47
+ out.writeln(span.red("✗"), span.text(` ${String(err)}`));
48
+ return primitives.results.fail({ exitCode: 1 });
49
+ }
50
+ };
51
+ if (import.meta.main) {
52
+ // Entry point: the await only runs when this file is executed directly.
53
+ // oxlint-disable-next-line node/no-top-level-await
54
+ const result = await main();
55
+ cliSupport.runCliMain(result, cliSupport.getCliContext().output);
56
+ }
@@ -0,0 +1,5 @@
1
+ import type { FileTool } from "./file-tool.ts";
2
+ export declare const tool: FileTool;
3
+ export declare const run: FileTool["run"];
4
+ export declare const validator: FileTool["validator"];
5
+ export declare const main: FileTool["main"];
@@ -0,0 +1,70 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Naming and to-do comment checker for JavaScript and TypeScript source, for the two
4
+ * rules oxlint does not cover (decision-34):
5
+ *
6
+ * - declared names (after `const`, `let`, `var`, `function`, `class`,
7
+ * `interface`, `type` and `enum`) are camelCase, PascalCase or
8
+ * SCREAMING_SNAKE_CASE, apart from the names the `allowNames` option lists;
9
+ * - every to-do marker in a comment carries a task tag, as in
10
+ * `TODO(TASK-123)` or `FIXME(TASK-123)` (decision-21).
11
+ *
12
+ * The check runs in Go (codebasefx.ValidateNamingAndTodos), on a lexer that
13
+ * separates comments, string, template and regular expression literals and
14
+ * identifiers, so text inside literals is never read. It needs the native
15
+ * library.
16
+ *
17
+ * @module
18
+ */
19
+ import * as standards from "@eserstack/standards";
20
+ import * as cliSupport from "./cli-support.js";
21
+ import * as ffiClient from "./ffi-client.js";
22
+ import * as gitListing from "./git-listing.js";
23
+ import * as fileTool from "./file-tool.js";
24
+ /** The name the Go bridge knows this validator by. */
25
+ const GO_VALIDATOR_NAME = "naming-and-todos";
26
+ export const tool = fileTool.withGoValidator(fileTool.createFileTool({
27
+ name: "validate-naming-and-todos",
28
+ description: "Enforce camelCase declared names and task-tagged to-do comments",
29
+ canFix: false,
30
+ stacks: [],
31
+ defaults: {},
32
+ extensions: ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"],
33
+ checkAll: async (_files, options) => {
34
+ await ffiClient.ensureLib();
35
+ const lib = ffiClient.getLib();
36
+ if (lib === null) {
37
+ const cause = ffiClient.getLoadError();
38
+ throw new Error(`validate-naming-and-todos runs in Go and needs the native library${cause === null ? "" : `: ${cause.message}`}`);
39
+ }
40
+ const excludes = Array.isArray(options["exclude"])
41
+ ? options["exclude"].filter((e) => typeof e === "string")
42
+ : [];
43
+ const parsed = lib.call("codebaseValidateFiles", {
44
+ dir: options.root,
45
+ validators: [GO_VALIDATOR_NAME],
46
+ exclude: excludes,
47
+ validatorOptions: {
48
+ [GO_VALIDATOR_NAME]: { allowNames: options["allowNames"] ?? [] },
49
+ },
50
+ ...(await gitListing.bridgeGitOptions(lib, options.root)),
51
+ });
52
+ if (parsed.error !== undefined && parsed.error !== "") {
53
+ throw new Error(`validate-naming-and-todos: ${parsed.error}`);
54
+ }
55
+ return (parsed.results?.[0]?.issues ?? []).map((issue) => ({
56
+ path: issue.file,
57
+ line: issue.line,
58
+ message: issue.message,
59
+ }));
60
+ },
61
+ }), GO_VALIDATOR_NAME);
62
+ export const run = tool.run;
63
+ export const validator = tool.validator;
64
+ export const main = tool.main;
65
+ if (import.meta.main) {
66
+ // Entry point: the await only runs when this file is executed directly.
67
+ // oxlint-disable-next-line node/no-top-level-await
68
+ const result = await main(standards.crossRuntime.runtime.process.args);
69
+ cliSupport.runCliMain(result);
70
+ }
@@ -0,0 +1,5 @@
1
+ import type { FileTool } from "./file-tool.ts";
2
+ export declare const tool: FileTool;
3
+ export declare const run: FileTool["run"];
4
+ export declare const validator: FileTool["validator"];
5
+ export declare const main: FileTool["main"];
@@ -0,0 +1,78 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Runtime API portability checker. Library code reaches the file system, the
4
+ * environment and the process through `runtime` from
5
+ * `@eserstack/standards/cross-runtime` (javascript-practices: Cross-Runtime
6
+ * APIs). The rules:
7
+ *
8
+ * - `deno` and `bun`: every reference to the `Deno` or the `Bun` identifier in
9
+ * code, including `globalThis.Deno`, an alias such as `g.Bun`, a `typeof`
10
+ * check and test files;
11
+ * - `process`: any member of Node's global `process` (`process.env`,
12
+ * `process.exit`, `globalThis.process.argv`, ...), reached with optional
13
+ * chaining (`globalThis.process?.cwd()`) or through an alias of
14
+ * `globalThis` (`g.process.env`) too. A file that declares its
15
+ * own `process` binding (a child process handle, a parameter,
16
+ * `const { process } = runtime`) is only checked for `process.env` and
17
+ * `globalThis.process.*`.
18
+ *
19
+ * The check runs in Go (codebasefx.ValidateRuntimeJSAPIs) on the lexer that
20
+ * separates comments and string, template and regular expression literals
21
+ * from code, so text such as `"deno.json"` never counts. The cross-runtime
22
+ * layer itself (`standards/cross-runtime/`) is skipped; other exceptions go in
23
+ * the `exclude` option of the manifest step, each with the reason. There is
24
+ * no baseline: every violation fails. It needs the native library.
25
+ *
26
+ * @module
27
+ */
28
+ import * as standards from "@eserstack/standards";
29
+ import * as patterns from "@eserstack/standards/patterns";
30
+ import * as cliSupport from "./cli-support.js";
31
+ import * as ffiClient from "./ffi-client.js";
32
+ import * as gitListing from "./git-listing.js";
33
+ import * as fileTool from "./file-tool.js";
34
+ /** The name the Go bridge knows this validator by. */
35
+ const GO_VALIDATOR_NAME = "runtime-js-apis";
36
+ const TOOL_NAME = "validate-runtime-js-apis";
37
+ export const tool = fileTool.withGoValidator(fileTool.createFileTool({
38
+ name: TOOL_NAME,
39
+ description: "Detect runtime globals used instead of @eserstack/standards/cross-runtime",
40
+ canFix: false,
41
+ stacks: ["javascript"],
42
+ defaults: {},
43
+ extensions: patterns.JS_FILE_EXTENSIONS,
44
+ checkAll: async (_files, options) => {
45
+ await ffiClient.ensureLib();
46
+ const lib = ffiClient.getLib();
47
+ if (lib === null) {
48
+ const cause = ffiClient.getLoadError();
49
+ throw new Error(`${TOOL_NAME} runs in Go and needs the native library${cause === null ? "" : `: ${cause.message}`}`);
50
+ }
51
+ const excludes = Array.isArray(options["exclude"])
52
+ ? options["exclude"].filter((e) => typeof e === "string")
53
+ : [];
54
+ const parsed = lib.call("codebaseValidateFiles", {
55
+ dir: options.root,
56
+ validators: [GO_VALIDATOR_NAME],
57
+ exclude: excludes,
58
+ ...(await gitListing.bridgeGitOptions(lib, options.root)),
59
+ });
60
+ if (parsed.error !== undefined && parsed.error !== "") {
61
+ throw new Error(`${TOOL_NAME}: ${parsed.error}`);
62
+ }
63
+ return (parsed.results?.[0]?.issues ?? []).map((issue) => ({
64
+ path: issue.file,
65
+ line: issue.line,
66
+ message: issue.message,
67
+ }));
68
+ },
69
+ }), GO_VALIDATOR_NAME);
70
+ export const run = tool.run;
71
+ export const validator = tool.validator;
72
+ export const main = tool.main;
73
+ if (import.meta.main) {
74
+ // Entry point: the await only runs when this file is executed directly.
75
+ // oxlint-disable-next-line node/no-top-level-await
76
+ const result = await main(standards.crossRuntime.runtime.process.args);
77
+ cliSupport.runCliMain(result);
78
+ }
@@ -0,0 +1,5 @@
1
+ import type { FileTool } from "./file-tool.ts";
2
+ export declare const tool: FileTool;
3
+ export declare const run: FileTool["run"];
4
+ export declare const validator: FileTool["validator"];
5
+ export declare const main: FileTool["main"];
@@ -0,0 +1,82 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Secret checker — detects credentials and private keys in source files.
4
+ *
5
+ * Detects:
6
+ * - AWS access key IDs (AKIA...)
7
+ * - Private key PEM headers
8
+ * - High-entropy strings near secret-like keywords (with allowlist)
9
+ *
10
+ * @module
11
+ */
12
+ import * as standards from "@eserstack/standards";
13
+ import * as cliSupport from "./cli-support.js";
14
+ import * as fileTool from "./file-tool.js";
15
+ const SECRET_PATTERNS = [
16
+ {
17
+ name: "AWS Access Key ID",
18
+ pattern: /AKIA[0-9A-Z]{16}/,
19
+ },
20
+ {
21
+ name: "Private Key",
22
+ pattern: /-----BEGIN\s{1,5}(RSA\s{1,5}|EC\s{1,5}|DSA\s{1,5}|OPENSSH\s{1,5})?PRIVATE KEY-----/,
23
+ },
24
+ {
25
+ name: "Generic secret assignment",
26
+ pattern: /(?:secret|password|api_key|apikey|access_token|auth_token|private_key)\s{0,5}[=:]\s{0,5}["'][^"']{8,}["']/i,
27
+ },
28
+ ];
29
+ /** File patterns to always skip (test fixtures, lock files, etc.) */
30
+ const SKIP_FILE_PATTERNS = [
31
+ /\.lock$/,
32
+ /package-lock\.json$/,
33
+ /\.test\./,
34
+ /_test\.go$/,
35
+ /_test\.ts$/,
36
+ /testdata\//,
37
+ /\.snap$/,
38
+ /\.min\./,
39
+ ];
40
+ export const tool = fileTool.withGoValidator(fileTool.createFileTool({
41
+ name: "validate-secrets",
42
+ description: "Detect credentials and private keys",
43
+ canFix: false,
44
+ stacks: [],
45
+ defaults: {},
46
+ checkFile(file, content) {
47
+ if (content === undefined) {
48
+ return [];
49
+ }
50
+ // Skip known-safe files
51
+ for (const skipPattern of SKIP_FILE_PATTERNS) {
52
+ if (skipPattern.test(file.path)) {
53
+ return [];
54
+ }
55
+ }
56
+ const issues = [];
57
+ const lines = content.split("\n");
58
+ for (let i = 0; i < lines.length; i++) {
59
+ const line = lines[i];
60
+ for (const { name, pattern } of SECRET_PATTERNS) {
61
+ if (pattern.test(line)) {
62
+ issues.push({
63
+ path: file.path,
64
+ line: i + 1,
65
+ message: `potential ${name} detected`,
66
+ });
67
+ break; // One issue per line max
68
+ }
69
+ }
70
+ }
71
+ return issues;
72
+ },
73
+ }), "secrets");
74
+ export const run = tool.run;
75
+ export const validator = tool.validator;
76
+ export const main = tool.main;
77
+ if (import.meta.main) {
78
+ // Entry point: the await only runs when this file is executed directly.
79
+ // oxlint-disable-next-line node/no-top-level-await
80
+ const result = await main(standards.crossRuntime.runtime.process.args);
81
+ cliSupport.runCliMain(result);
82
+ }
@@ -0,0 +1,5 @@
1
+ import type { FileTool } from "./file-tool.ts";
2
+ export declare const tool: FileTool;
3
+ export declare const run: FileTool["run"];
4
+ export declare const validator: FileTool["validator"];
5
+ export declare const main: FileTool["main"];
@@ -0,0 +1,78 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Self-import checker — detects a workspace package importing itself through
4
+ * its own published name (`@eserstack/shell` importing `@eserstack/shell/env`).
5
+ *
6
+ * Locally that resolves through the workspace, so every check passes. When
7
+ * the libraries were published to JSR (frozen at 4.5.x, decision-5), the
8
+ * publish rewrote the specifier to `jsr:@eserstack/shell@^<version>/env` and
9
+ * resolved it against the registry, where that version did not exist yet; the
10
+ * dry run skipped that step, and it cost the v4.5.0 release three attempts.
11
+ *
12
+ * Inside a package, import your own modules by relative path.
13
+ *
14
+ * @module
15
+ */
16
+ import * as standards from "@eserstack/standards";
17
+ import * as patterns from "@eserstack/standards/patterns";
18
+ import * as cliSupport from "./cli-support.js";
19
+ import * as fileTool from "./file-tool.js";
20
+ const PACKAGE_DIR_PATTERN = /(?:^|\/)pkg\/@eserstack\/([^/]+)\//;
21
+ /**
22
+ * Lines that carry a module specifier: static imports/exports (including the
23
+ * closing `} from` line of a multi-line import) and dynamic `import(...)`.
24
+ */
25
+ const SPECIFIER_LINE_PATTERN = /^\s*(?:import\b|export\b|\})[^"'`]*?\bfrom\s*["']([^"']+)["']|^\s*import\s*["']([^"']+)["']|\bimport\(\s*["']([^"']+)["']\s*\)/;
26
+ const isCommentLine = (line) => {
27
+ const trimmed = line.trimStart();
28
+ return (trimmed.startsWith("//") ||
29
+ trimmed.startsWith("*") ||
30
+ trimmed.startsWith("/*"));
31
+ };
32
+ const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
33
+ export const tool = fileTool.createFileTool({
34
+ name: "validate-self-imports",
35
+ description: "Detect a package importing itself by its published name (breaks JSR publish; use a relative path)",
36
+ canFix: false,
37
+ stacks: ["javascript"],
38
+ defaults: {},
39
+ extensions: patterns.JS_FILE_EXTENSIONS,
40
+ checkFile(file, content) {
41
+ if (content === undefined)
42
+ return [];
43
+ const packageMatch = PACKAGE_DIR_PATTERN.exec(file.path);
44
+ const packageDir = packageMatch?.[1];
45
+ if (packageDir === undefined)
46
+ return [];
47
+ const ownName = `@eserstack/${packageDir}`;
48
+ const ownSpecifier = new RegExp(`^${escapeRe(ownName)}(?:/|$)`);
49
+ const issues = [];
50
+ const lines = content.split("\n");
51
+ for (let i = 0; i < lines.length; i++) {
52
+ const line = lines[i];
53
+ if (isCommentLine(line))
54
+ continue;
55
+ const match = SPECIFIER_LINE_PATTERN.exec(line);
56
+ if (match === null)
57
+ continue;
58
+ const specifier = match[1] ?? match[2] ?? match[3];
59
+ if (specifier === undefined || !ownSpecifier.test(specifier))
60
+ continue;
61
+ issues.push({
62
+ path: file.path,
63
+ line: i + 1,
64
+ message: `package imports itself as "${specifier}" — use a relative path; JSR cannot resolve jsr:${ownName} while that version is still being published`,
65
+ });
66
+ }
67
+ return issues;
68
+ },
69
+ });
70
+ export const run = tool.run;
71
+ export const validator = tool.validator;
72
+ export const main = tool.main;
73
+ if (import.meta.main) {
74
+ // Entry point: the await only runs when this file is executed directly.
75
+ // oxlint-disable-next-line node/no-top-level-await
76
+ const result = await main(standards.crossRuntime.runtime.process.args);
77
+ cliSupport.runCliMain(result);
78
+ }
@@ -0,0 +1,32 @@
1
+ import type * as shellArgs from "@eserstack/shell/args";
2
+ export type CheckServerLocOptions = {
3
+ readonly root?: string;
4
+ readonly directory: string;
5
+ readonly maxLines?: number;
6
+ readonly excludeSuffix?: string;
7
+ readonly extension?: string;
8
+ };
9
+ export type CheckServerLocResult = {
10
+ readonly violations: readonly {
11
+ path: string;
12
+ lines: number;
13
+ }[];
14
+ readonly checked: number;
15
+ readonly passed: boolean;
16
+ };
17
+ export declare const checkServerLoc: (options: CheckServerLocOptions) => Promise<CheckServerLocResult>;
18
+ /** The arguments of `eser codebase validate-server-loc`. */
19
+ export type ServerLocArgs = {
20
+ /** The `--directory` to check; empty when not given. */
21
+ readonly directory: string;
22
+ /** The `--max-lines` ceiling. */
23
+ readonly maxLines: number | undefined;
24
+ readonly excludeSuffix: string | undefined;
25
+ readonly extension: string | undefined;
26
+ };
27
+ /**
28
+ * Parse the validate-server-loc arguments: `--directory`, `--max-lines`,
29
+ * `--exclude-suffix`, `--extension`.
30
+ */
31
+ export declare const parseCliArgs: (cliArgs?: readonly string[]) => ServerLocArgs;
32
+ export declare const main: (cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
@@ -0,0 +1,94 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Server LOC ceiling validator.
4
+ *
5
+ * Fails if any non-test file in a directory exceeds the configured line limit.
6
+ *
7
+ * @module
8
+ */
9
+ import * as primitives from "@eserstack/primitives";
10
+ import * as shellFlags from "@eserstack/shell/args/flags";
11
+ import * as span from "@eserstack/streams/span";
12
+ import { runtime } from "@eserstack/standards/cross-runtime";
13
+ import * as cliSupport from "./cli-support.js";
14
+ export const checkServerLoc = async (options) => {
15
+ const { root = ".", directory, maxLines = 500, excludeSuffix = "_test.go", extension = "go", } = options;
16
+ const ext = extension.startsWith(".") ? extension.slice(1) : extension;
17
+ const dirPath = runtime.path.join(root, directory);
18
+ const violations = [];
19
+ let checked = 0;
20
+ for await (const entry of runtime.fs.walk(dirPath, {
21
+ exts: [ext],
22
+ includeDirs: false,
23
+ })) {
24
+ if (entry.path.endsWith(excludeSuffix)) {
25
+ continue;
26
+ }
27
+ const content = await runtime.fs.readTextFile(entry.path);
28
+ const lines = content.split("\n").length;
29
+ checked++;
30
+ if (lines > maxLines) {
31
+ violations.push({ path: entry.path, lines });
32
+ }
33
+ }
34
+ return { violations, checked, passed: violations.length === 0 };
35
+ };
36
+ const stringValue = (value) => typeof value === "string" ? value : undefined;
37
+ /**
38
+ * Parse the validate-server-loc arguments: `--directory`, `--max-lines`,
39
+ * `--exclude-suffix`, `--extension`.
40
+ */
41
+ export const parseCliArgs = (cliArgs) => {
42
+ const { values } = shellFlags.parseArgs(cliArgs ?? [], {
43
+ options: {
44
+ directory: { type: "string" },
45
+ "max-lines": { type: "string" },
46
+ "exclude-suffix": { type: "string" },
47
+ extension: { type: "string" },
48
+ },
49
+ });
50
+ const maxLines = stringValue(values["max-lines"]);
51
+ return {
52
+ directory: stringValue(values["directory"]) ?? "",
53
+ maxLines: maxLines !== undefined ? Number(maxLines) : undefined,
54
+ excludeSuffix: stringValue(values["exclude-suffix"]),
55
+ extension: stringValue(values["extension"]),
56
+ };
57
+ };
58
+ export const main = async (cliArgs) => {
59
+ const { output: out } = cliSupport.getCliContext();
60
+ const { directory, maxLines, excludeSuffix, extension } = parseCliArgs(cliArgs);
61
+ if (directory === "") {
62
+ out.writeln(span.red("✗"), span.text(" validate-server-loc requires a --directory argument"));
63
+ return primitives.results.fail({ exitCode: 1 });
64
+ }
65
+ try {
66
+ const result = await checkServerLoc({
67
+ root: ".",
68
+ directory,
69
+ maxLines,
70
+ excludeSuffix,
71
+ extension,
72
+ });
73
+ out.writeln(span.blue("ℹ"), span.text(` Checked ${result.checked} files in ${directory}.`));
74
+ if (!result.passed) {
75
+ out.writeln(span.red("✗"), span.text(` Found ${result.violations.length} file(s) exceeding the line ceiling:`));
76
+ for (const v of result.violations) {
77
+ out.writeln(span.yellow("⚠"), span.text(` ${v.path}: ${v.lines} lines (limit ${maxLines ?? 500})`));
78
+ }
79
+ return primitives.results.fail({ exitCode: 1 });
80
+ }
81
+ out.writeln(span.green("✓"), span.text(" All files within the line ceiling."));
82
+ return primitives.results.ok(undefined);
83
+ }
84
+ catch (err) {
85
+ out.writeln(span.red("✗"), span.text(` ${String(err)}`));
86
+ return primitives.results.fail({ exitCode: 1 });
87
+ }
88
+ };
89
+ if (import.meta.main) {
90
+ // Entry point: the await only runs when this file is executed directly.
91
+ // oxlint-disable-next-line node/no-top-level-await
92
+ const result = await main(runtime.process.args);
93
+ cliSupport.runCliMain(result, cliSupport.getCliContext().output);
94
+ }
@@ -0,0 +1,5 @@
1
+ import type { FileTool } from "./file-tool.ts";
2
+ export declare const tool: FileTool;
3
+ export declare const run: FileTool["run"];
4
+ export declare const validator: FileTool["validator"];
5
+ export declare const main: FileTool["main"];
@@ -0,0 +1,33 @@
1
+ // Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
2
+ /**
3
+ * Shebang checker — placeholder for future shebang/executable validation.
4
+ *
5
+ * The previous check flagged any non-.ts/.js file with a shebang, which
6
+ * produced false positives for shell scripts and other scripting languages.
7
+ * That check was removed. Cross-platform exec-bit checking is not currently
8
+ * implemented.
9
+ *
10
+ * @module
11
+ */
12
+ import * as standards from "@eserstack/standards";
13
+ import * as cliSupport from "./cli-support.js";
14
+ import * as fileTool from "./file-tool.js";
15
+ export const tool = fileTool.withGoValidator(fileTool.createFileTool({
16
+ name: "validate-shebangs",
17
+ description: "Validate shebang/executable consistency",
18
+ canFix: false,
19
+ stacks: [],
20
+ defaults: {},
21
+ checkFile(_file, _content) {
22
+ return [];
23
+ },
24
+ }), "shebangs");
25
+ export const run = tool.run;
26
+ export const validator = tool.validator;
27
+ export const main = tool.main;
28
+ if (import.meta.main) {
29
+ // Entry point: the await only runs when this file is executed directly.
30
+ // oxlint-disable-next-line node/no-top-level-await
31
+ const result = await main(standards.crossRuntime.runtime.process.args);
32
+ cliSupport.runCliMain(result);
33
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Streaming validator run via the Go FFI bridge.
3
+ *
4
+ * Returns an `AsyncIterable<ValidatorResult>` backed by the bridge's
5
+ * `codebaseValidateFilesStream` stream.
6
+ * Each yielded item is one validator's result. Supports `await using` / `Symbol.asyncDispose`.
7
+ *
8
+ * @module
9
+ */
10
+ import type * as ffiTypes from "@eserstack/ajan/ffi";
11
+ import type { ValidatorResult } from "./validation/types.ts";
12
+ export type ValidateStreamOptions = {
13
+ readonly dir?: string;
14
+ readonly validators?: readonly string[];
15
+ readonly extensions?: readonly string[];
16
+ readonly validatorOptions?: Record<string, unknown>;
17
+ readonly gitAware?: boolean;
18
+ };
19
+ export declare class ValidateStream implements AsyncIterable<ValidatorResult>, AsyncDisposable {
20
+ #private;
21
+ constructor(stream: ffiTypes.AjanStream<"codebaseValidateFilesStream">);
22
+ [Symbol.asyncIterator](): AsyncGenerator<ValidatorResult>;
23
+ [Symbol.asyncDispose](): Promise<void>;
24
+ }
25
+ export declare const validateFilesStream: (options?: ValidateStreamOptions) => Promise<ValidateStream>;
@@ -0,0 +1,62 @@
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
+ // ValidateStream
6
+ // =============================================================================
7
+ export class ValidateStream {
8
+ #stream;
9
+ constructor(stream) {
10
+ this.#stream = stream;
11
+ }
12
+ async *[Symbol.asyncIterator]() {
13
+ while (true) {
14
+ const chunk = this.#stream.read();
15
+ if (chunk === null) {
16
+ break;
17
+ }
18
+ const parsed = chunk;
19
+ if (parsed.error !== undefined) {
20
+ throw new Error(`validate stream error: ${parsed.error}`);
21
+ }
22
+ yield {
23
+ name: parsed.name ?? "",
24
+ passed: parsed.passed ?? true,
25
+ issues: (parsed.issues ?? []).map((iss) => ({
26
+ severity: (iss.severity ?? "error"),
27
+ message: iss.message ?? "",
28
+ file: iss.file,
29
+ line: iss.line,
30
+ })),
31
+ stats: { filesChecked: parsed.filesChecked ?? 0 },
32
+ };
33
+ }
34
+ }
35
+ [Symbol.asyncDispose]() {
36
+ this.#stream.close();
37
+ return Promise.resolve();
38
+ }
39
+ }
40
+ // =============================================================================
41
+ // Factory
42
+ // =============================================================================
43
+ export const validateFilesStream = async (options = {}) => {
44
+ await ffiClient.ensureLib();
45
+ const lib = ffiClient.getLib();
46
+ if (lib === null) {
47
+ throw new Error("FFI library unavailable — cannot create validate stream");
48
+ }
49
+ const dir = options.dir ?? ".";
50
+ const stream = lib.stream("codebaseValidateFilesStream", {
51
+ dir,
52
+ validators: options.validators,
53
+ extensions: options.extensions,
54
+ validatorOptions: options.validatorOptions,
55
+ ...(await gitListing.bridgeGitOptions(lib, dir, options.gitAware ?? false)),
56
+ });
57
+ const parsed = stream.opened;
58
+ if (parsed.error !== undefined || parsed.handle === undefined) {
59
+ throw new Error(`validate stream create failed: ${parsed.error ?? "no handle"}`);
60
+ }
61
+ return new ValidateStream(stream);
62
+ };
@@ -0,0 +1,5 @@
1
+ import type { FileTool } from "./file-tool.ts";
2
+ export declare const tool: FileTool;
3
+ export declare const run: FileTool["run"];
4
+ export declare const validator: FileTool["validator"];
5
+ export declare const main: FileTool["main"];