@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.
- package/README.md +301 -2
- package/dist/changelog-gen.d.ts +105 -0
- package/dist/changelog-gen.js +498 -0
- package/dist/changelog-text.d.ts +39 -0
- package/dist/changelog-text.js +82 -0
- package/dist/cli-support.d.ts +140 -0
- package/dist/cli-support.js +244 -0
- package/dist/cli-system/app-opts.d.ts +15 -0
- package/dist/cli-system/app-opts.js +13 -0
- package/dist/cli-system/app.d.ts +29 -0
- package/dist/cli-system/app.js +12 -0
- package/dist/cli-system/handlers/completions-setup.d.ts +14 -0
- package/dist/cli-system/handlers/completions-setup.js +139 -0
- package/dist/cli-system/handlers/completions.d.ts +3 -0
- package/dist/cli-system/handlers/completions.js +79 -0
- package/dist/cli-system/handlers/doctor.d.ts +8 -0
- package/dist/cli-system/handlers/doctor.js +146 -0
- package/dist/cli-system/handlers/info.d.ts +3 -0
- package/dist/cli-system/handlers/info.js +69 -0
- package/dist/cli-system/handlers/install.d.ts +8 -0
- package/dist/cli-system/handlers/install.js +137 -0
- package/dist/cli-system/handlers/mod.d.ts +12 -0
- package/dist/cli-system/handlers/mod.js +13 -0
- package/dist/cli-system/handlers/uninstall.d.ts +3 -0
- package/dist/cli-system/handlers/uninstall.js +60 -0
- package/dist/cli-system/handlers/update.d.ts +76 -0
- package/dist/cli-system/handlers/update.js +310 -0
- package/dist/cli-system/handlers/version-check.d.ts +16 -0
- package/dist/cli-system/handlers/version-check.js +176 -0
- package/dist/cli-system/handlers/version.d.ts +3 -0
- package/dist/cli-system/handlers/version.js +45 -0
- package/dist/cli-system/mod.d.ts +19 -0
- package/dist/cli-system/mod.js +52 -0
- package/dist/commitmsg.d.ts +28 -0
- package/dist/commitmsg.js +232 -0
- package/dist/directive-analysis.d.ts +75 -0
- package/dist/directive-analysis.js +223 -0
- package/dist/ffi-client.d.ts +11 -0
- package/dist/ffi-client.js +12 -0
- package/dist/file-tool.d.ts +96 -0
- package/dist/file-tool.js +274 -0
- package/dist/file-tools-shared.d.ts +81 -0
- package/dist/file-tools-shared.js +276 -0
- package/dist/gh-contributors.d.ts +89 -0
- package/dist/gh-contributors.js +205 -0
- package/dist/gh.d.ts +3 -0
- package/dist/gh.js +64 -0
- package/dist/git-listing.d.ts +27 -0
- package/dist/git-listing.js +69 -0
- package/dist/git.d.ts +172 -0
- package/dist/git.js +277 -0
- package/dist/install.d.ts +34 -0
- package/dist/install.js +421 -0
- package/dist/main.d.ts +22 -0
- package/dist/main.js +14 -0
- package/dist/mod.d.ts +25 -0
- package/dist/mod.js +8 -0
- package/dist/module.d.ts +10 -0
- package/dist/module.js +221 -0
- package/dist/native-functions.d.ts +1088 -0
- package/dist/native-functions.js +2 -0
- package/dist/npm-externals.d.ts +27 -0
- package/dist/npm-externals.js +34 -0
- package/dist/npm-workspace-specifiers.d.ts +6 -0
- package/dist/npm-workspace-specifiers.js +45 -0
- package/dist/package/loader.d.ts +34 -0
- package/dist/package/loader.js +203 -0
- package/dist/package/mod.d.ts +36 -0
- package/dist/package/mod.js +5 -0
- package/dist/package/types.d.ts +142 -0
- package/dist/package/types.js +32 -0
- package/dist/package/workspace.d.ts +33 -0
- package/dist/package/workspace.js +158 -0
- package/dist/package/writer.d.ts +52 -0
- package/dist/package/writer.js +278 -0
- package/dist/package.json +275 -0
- package/dist/release-notes.d.ts +90 -0
- package/dist/release-notes.js +236 -0
- package/dist/release-tag.d.ts +46 -0
- package/dist/release-tag.js +95 -0
- package/dist/release.d.ts +145 -0
- package/dist/release.js +584 -0
- package/dist/source-mask.d.ts +3 -0
- package/dist/source-mask.js +185 -0
- package/dist/validate-bom.d.ts +5 -0
- package/dist/validate-bom.js +43 -0
- package/dist/validate-case-conflict.d.ts +5 -0
- package/dist/validate-case-conflict.js +43 -0
- package/dist/validate-circular-deps.d.ts +11 -0
- package/dist/validate-circular-deps.js +53 -0
- package/dist/validate-code-conventions.d.ts +22 -0
- package/dist/validate-code-conventions.js +166 -0
- package/dist/validate-commit-msg.d.ts +50 -0
- package/dist/validate-commit-msg.js +182 -0
- package/dist/validate-docs.d.ts +20 -0
- package/dist/validate-docs.js +78 -0
- package/dist/validate-eof.d.ts +5 -0
- package/dist/validate-eof.js +61 -0
- package/dist/validate-error-coverage.d.ts +28 -0
- package/dist/validate-error-coverage.js +93 -0
- package/dist/validate-export-names.d.ts +17 -0
- package/dist/validate-export-names.js +56 -0
- package/dist/validate-filenames.d.ts +5 -0
- package/dist/validate-filenames.js +151 -0
- package/dist/validate-json.d.ts +5 -0
- package/dist/validate-json.js +71 -0
- package/dist/validate-large-files.d.ts +5 -0
- package/dist/validate-large-files.js +41 -0
- package/dist/validate-laroux-boundaries.d.ts +19 -0
- package/dist/validate-laroux-boundaries.js +59 -0
- package/dist/validate-licenses.d.ts +5 -0
- package/dist/validate-licenses.js +137 -0
- package/dist/validate-line-endings.d.ts +5 -0
- package/dist/validate-line-endings.js +47 -0
- package/dist/validate-merge-conflict.d.ts +5 -0
- package/dist/validate-merge-conflict.js +46 -0
- package/dist/validate-mod-exports.d.ts +16 -0
- package/dist/validate-mod-exports.js +56 -0
- package/dist/validate-naming-and-todos.d.ts +5 -0
- package/dist/validate-naming-and-todos.js +70 -0
- package/dist/validate-runtime-js-apis.d.ts +5 -0
- package/dist/validate-runtime-js-apis.js +78 -0
- package/dist/validate-secrets.d.ts +5 -0
- package/dist/validate-secrets.js +82 -0
- package/dist/validate-self-imports.d.ts +5 -0
- package/dist/validate-self-imports.js +78 -0
- package/dist/validate-server-loc.d.ts +32 -0
- package/dist/validate-server-loc.js +94 -0
- package/dist/validate-shebangs.d.ts +5 -0
- package/dist/validate-shebangs.js +33 -0
- package/dist/validate-stream.d.ts +25 -0
- package/dist/validate-stream.js +62 -0
- package/dist/validate-submodules.d.ts +5 -0
- package/dist/validate-submodules.js +43 -0
- package/dist/validate-symlinks.d.ts +5 -0
- package/dist/validate-symlinks.js +46 -0
- package/dist/validate-toml.d.ts +5 -0
- package/dist/validate-toml.js +40 -0
- package/dist/validate-trailing-whitespace.d.ts +5 -0
- package/dist/validate-trailing-whitespace.js +49 -0
- package/dist/validate-yaml.d.ts +5 -0
- package/dist/validate-yaml.js +40 -0
- package/dist/validation/config.d.ts +17 -0
- package/dist/validation/config.js +30 -0
- package/dist/validation/mod.d.ts +71 -0
- package/dist/validation/mod.js +479 -0
- package/dist/validation/registry.d.ts +57 -0
- package/dist/validation/registry.js +256 -0
- package/dist/validation/types.d.ts +101 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/validators/circular-deps.d.ts +7 -0
- package/dist/validation/validators/circular-deps.js +31 -0
- package/dist/validation/validators/docs.d.ts +7 -0
- package/dist/validation/validators/docs.js +38 -0
- package/dist/validation/validators/error-coverage.d.ts +2 -0
- package/dist/validation/validators/error-coverage.js +46 -0
- package/dist/validation/validators/export-names.d.ts +7 -0
- package/dist/validation/validators/export-names.js +31 -0
- package/dist/validation/validators/laroux-boundaries.d.ts +2 -0
- package/dist/validation/validators/laroux-boundaries.js +29 -0
- package/dist/validation/validators/mod-exports.d.ts +7 -0
- package/dist/validation/validators/mod-exports.js +32 -0
- package/dist/validation/validators/mod.d.ts +11 -0
- package/dist/validation/validators/mod.js +12 -0
- package/dist/validation/validators/server-loc.d.ts +2 -0
- package/dist/validation/validators/server-loc.js +48 -0
- package/dist/versions.d.ts +166 -0
- package/dist/versions.js +349 -0
- package/dist/violation-baseline.d.ts +58 -0
- package/dist/violation-baseline.js +144 -0
- package/dist/walk-stream.d.ts +24 -0
- package/dist/walk-stream.js +55 -0
- package/dist/workspace-discovery.d.ts +60 -0
- package/dist/workspace-discovery.js +130 -0
- package/package.json +222 -3
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Filename convention checker — enforces kebab-case/snake_case per directory.
|
|
4
|
+
*
|
|
5
|
+
* Rules:
|
|
6
|
+
* - `apps/services/` → snake_case only
|
|
7
|
+
* - Everything else → kebab-case only
|
|
8
|
+
* - Also checks for Windows-reserved names (CON, PRN, AUX, NUL, etc.)
|
|
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
|
+
// =============================================================================
|
|
16
|
+
// Naming rules
|
|
17
|
+
// =============================================================================
|
|
18
|
+
/** Windows reserved names (case-insensitive) */
|
|
19
|
+
const WINDOWS_RESERVED = new Set([
|
|
20
|
+
"con",
|
|
21
|
+
"prn",
|
|
22
|
+
"aux",
|
|
23
|
+
"nul",
|
|
24
|
+
"com1",
|
|
25
|
+
"com2",
|
|
26
|
+
"com3",
|
|
27
|
+
"com4",
|
|
28
|
+
"com5",
|
|
29
|
+
"com6",
|
|
30
|
+
"com7",
|
|
31
|
+
"com8",
|
|
32
|
+
"com9",
|
|
33
|
+
"lpt1",
|
|
34
|
+
"lpt2",
|
|
35
|
+
"lpt3",
|
|
36
|
+
"lpt4",
|
|
37
|
+
"lpt5",
|
|
38
|
+
"lpt6",
|
|
39
|
+
"lpt7",
|
|
40
|
+
"lpt8",
|
|
41
|
+
"lpt9",
|
|
42
|
+
]);
|
|
43
|
+
/** snake_case pattern: lowercase letters, digits, underscores, dots */
|
|
44
|
+
const SNAKE_CASE = /^[a-z0-9_./[\]@-]+$/;
|
|
45
|
+
/** kebab-case pattern: lowercase letters, digits, hyphens, dots */
|
|
46
|
+
const KEBAB_CASE = /^[a-z0-9./[\]@-]+$/;
|
|
47
|
+
/** Default excluded paths (fallback when no .eser/manifest.yml config) */
|
|
48
|
+
const DEFAULT_EXCLUDES = [
|
|
49
|
+
".claude/",
|
|
50
|
+
".github/",
|
|
51
|
+
".git/",
|
|
52
|
+
"CLAUDE.md",
|
|
53
|
+
"AGENTS.md",
|
|
54
|
+
"CHANGELOG.md",
|
|
55
|
+
"Makefile",
|
|
56
|
+
"Dockerfile",
|
|
57
|
+
"LICENSE",
|
|
58
|
+
"README.md",
|
|
59
|
+
"VERSION",
|
|
60
|
+
];
|
|
61
|
+
/** Check if a path matches any exclude pattern */
|
|
62
|
+
const isExcluded = (path, excludes) => {
|
|
63
|
+
for (const pattern of excludes) {
|
|
64
|
+
if (pattern.includes("*")) {
|
|
65
|
+
// Simple glob: "pkg/*/README.md" or "etc/templates/*/Makefile"
|
|
66
|
+
const regexStr = pattern
|
|
67
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
68
|
+
.replace(/\*/g, "[^/]+");
|
|
69
|
+
if (new RegExp(regexStr).test(path)) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (path.includes(pattern) || path.endsWith(pattern)) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
|
79
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
80
|
+
name: "validate-filenames",
|
|
81
|
+
description: "Enforce filename conventions (kebab-case / snake_case)",
|
|
82
|
+
canFix: false,
|
|
83
|
+
stacks: [],
|
|
84
|
+
defaults: {},
|
|
85
|
+
checkAll(files, options) {
|
|
86
|
+
const issues = [];
|
|
87
|
+
// Read config-driven rules or use defaults
|
|
88
|
+
const configRules = options["rules"];
|
|
89
|
+
// Build exclude list from config or defaults
|
|
90
|
+
const globalExcludes = options["exclude"] ?? DEFAULT_EXCLUDES;
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
// Skip globally excluded paths
|
|
93
|
+
if (isExcluded(file.path, globalExcludes)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const basename = file.name;
|
|
97
|
+
const baseWithoutExt = basename.replace(/\.[^.]+$/, "");
|
|
98
|
+
// Check for Windows reserved names
|
|
99
|
+
if (WINDOWS_RESERVED.has(baseWithoutExt.toLowerCase())) {
|
|
100
|
+
issues.push({
|
|
101
|
+
path: file.path,
|
|
102
|
+
message: `Windows-reserved filename: ${basename}`,
|
|
103
|
+
});
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
// Find matching rule from config
|
|
107
|
+
if (configRules !== undefined) {
|
|
108
|
+
let matched = false;
|
|
109
|
+
for (const rule of configRules) {
|
|
110
|
+
if (rule.directory === "*" || file.path.includes(rule.directory)) {
|
|
111
|
+
// Check rule-level excludes
|
|
112
|
+
if (rule.exclude !== undefined &&
|
|
113
|
+
isExcluded(file.path, rule.exclude)) {
|
|
114
|
+
matched = true;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
const pattern = rule.convention === "snake_case" ? SNAKE_CASE : KEBAB_CASE;
|
|
118
|
+
if (!pattern.test(basename)) {
|
|
119
|
+
issues.push({
|
|
120
|
+
path: file.path,
|
|
121
|
+
message: `filename must be ${rule.convention}`,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
matched = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (matched) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Default: kebab-case for everything (no hardcoded directory rules)
|
|
133
|
+
if (!KEBAB_CASE.test(basename)) {
|
|
134
|
+
issues.push({
|
|
135
|
+
path: file.path,
|
|
136
|
+
message: "filename must be kebab-case",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return issues;
|
|
141
|
+
},
|
|
142
|
+
}), "filenames");
|
|
143
|
+
export const run = tool.run;
|
|
144
|
+
export const validator = tool.validator;
|
|
145
|
+
export const main = tool.main;
|
|
146
|
+
if (import.meta.main) {
|
|
147
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
148
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
149
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
150
|
+
cliSupport.runCliMain(result);
|
|
151
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* JSON syntax checker — validates .json and .jsonc files.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as jsonc from "jsonc-parser";
|
|
8
|
+
import * as standards from "@eserstack/standards";
|
|
9
|
+
import * as cliSupport from "./cli-support.js";
|
|
10
|
+
import * as fileTool from "./file-tool.js";
|
|
11
|
+
/**
|
|
12
|
+
* Parses JSON with comments and trailing commas. jsonc-parser recovers from
|
|
13
|
+
* errors and reports them in a list instead of throwing, so the first one is
|
|
14
|
+
* raised here as a SyntaxError, the way JSON.parse fails.
|
|
15
|
+
*/
|
|
16
|
+
const parseJsonc = (text) => {
|
|
17
|
+
const errors = [];
|
|
18
|
+
const value = jsonc.parse(text, errors, {
|
|
19
|
+
allowTrailingComma: true,
|
|
20
|
+
disallowComments: false,
|
|
21
|
+
allowEmptyContent: false,
|
|
22
|
+
});
|
|
23
|
+
const first = errors[0];
|
|
24
|
+
if (first !== undefined) {
|
|
25
|
+
const before = text.slice(0, first.offset).split("\n");
|
|
26
|
+
const line = before.length;
|
|
27
|
+
const column = (before.at(-1)?.length ?? 0) + 1;
|
|
28
|
+
throw new SyntaxError(`Cannot parse JSONC: ${jsonc.printParseErrorCode(first.error)} at line ${line}, column ${column}`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
33
|
+
name: "validate-json",
|
|
34
|
+
description: "Validate JSON syntax",
|
|
35
|
+
canFix: false,
|
|
36
|
+
stacks: [],
|
|
37
|
+
defaults: {},
|
|
38
|
+
extensions: ["json", "jsonc"],
|
|
39
|
+
checkFile(file, content, options) {
|
|
40
|
+
if (content === undefined) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
// Check excludes from .eser/manifest.yml config
|
|
44
|
+
const excludes = options["exclude"] ?? [];
|
|
45
|
+
if (excludes.some((pattern) => file.path.includes(pattern))) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
if (file.name.endsWith(".jsonc")) {
|
|
50
|
+
parseJsonc(content);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
JSON.parse(content);
|
|
54
|
+
}
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const message = error instanceof SyntaxError ? error.message : "invalid JSON";
|
|
59
|
+
return [{ path: file.path, message }];
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
}), "json");
|
|
63
|
+
export const run = tool.run;
|
|
64
|
+
export const validator = tool.validator;
|
|
65
|
+
export const main = tool.main;
|
|
66
|
+
if (import.meta.main) {
|
|
67
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
68
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
69
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
70
|
+
cliSupport.runCliMain(result);
|
|
71
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Large file checker — fails if any file exceeds a size limit.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as standards from "@eserstack/standards";
|
|
8
|
+
import * as cliSupport from "./cli-support.js";
|
|
9
|
+
import * as fileTool from "./file-tool.js";
|
|
10
|
+
const DEFAULT_MAX_KB = 1024;
|
|
11
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
12
|
+
name: "validate-large-files",
|
|
13
|
+
description: "Detect files exceeding size limit",
|
|
14
|
+
canFix: false,
|
|
15
|
+
stacks: [],
|
|
16
|
+
defaults: { maxKb: DEFAULT_MAX_KB },
|
|
17
|
+
checkAll(files, options) {
|
|
18
|
+
const maxKb = options["maxKb"] ?? DEFAULT_MAX_KB;
|
|
19
|
+
const maxBytes = maxKb * 1024;
|
|
20
|
+
const issues = [];
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
if (file.size > maxBytes) {
|
|
23
|
+
const sizeKb = Math.round(file.size / 1024);
|
|
24
|
+
issues.push({
|
|
25
|
+
path: file.path,
|
|
26
|
+
message: `file is ${sizeKb}KB (max: ${maxKb}KB)`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return issues;
|
|
31
|
+
},
|
|
32
|
+
}), "large-file");
|
|
33
|
+
export const run = tool.run;
|
|
34
|
+
export const validator = tool.validator;
|
|
35
|
+
export const main = tool.main;
|
|
36
|
+
if (import.meta.main) {
|
|
37
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
38
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
39
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
40
|
+
cliSupport.runCliMain(result);
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as shellArgs from "@eserstack/shell/args";
|
|
2
|
+
export type CheckLarouxBoundariesOptions = {
|
|
3
|
+
readonly root?: string;
|
|
4
|
+
/** The allowlist file, relative to the root. */
|
|
5
|
+
readonly allowlist?: string;
|
|
6
|
+
readonly exclude?: readonly string[];
|
|
7
|
+
};
|
|
8
|
+
export type LarouxBoundaryIssue = {
|
|
9
|
+
readonly severity: "error";
|
|
10
|
+
readonly file: string;
|
|
11
|
+
readonly line?: number;
|
|
12
|
+
readonly message: string;
|
|
13
|
+
};
|
|
14
|
+
export type CheckLarouxBoundariesResult = {
|
|
15
|
+
readonly issues: readonly LarouxBoundaryIssue[];
|
|
16
|
+
readonly filesChecked: number;
|
|
17
|
+
};
|
|
18
|
+
export declare const checkLarouxBoundaries: (options?: CheckLarouxBoundariesOptions) => Promise<CheckLarouxBoundariesResult>;
|
|
19
|
+
export declare const main: (_cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* The import rules of the laroux packages (decision-46, decision-53).
|
|
4
|
+
*
|
|
5
|
+
* The check runs in Go (codebasefx.CheckLarouxBoundaries), on the shared lexer,
|
|
6
|
+
* so text in comments and string literals is never taken for an import. It
|
|
7
|
+
* needs the native library.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import * as primitives from "@eserstack/primitives";
|
|
12
|
+
import * as span from "@eserstack/streams/span";
|
|
13
|
+
import * as cliSupport from "./cli-support.js";
|
|
14
|
+
import * as ffiClient from "./ffi-client.js";
|
|
15
|
+
import * as gitListing from "./git-listing.js";
|
|
16
|
+
export const checkLarouxBoundaries = 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 checkLarouxBoundaries");
|
|
22
|
+
}
|
|
23
|
+
const result = lib.call("codebaseCheckLarouxBoundaries", {
|
|
24
|
+
dir: root,
|
|
25
|
+
allowlist: options.allowlist,
|
|
26
|
+
exclude: options.exclude,
|
|
27
|
+
...(await gitListing.bridgeGitOptions(lib, root)),
|
|
28
|
+
});
|
|
29
|
+
if (result.error !== undefined && result.error !== "") {
|
|
30
|
+
throw new Error(result.error);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
export const main = async (_cliArgs) => {
|
|
35
|
+
const { output: out } = cliSupport.getCliContext();
|
|
36
|
+
try {
|
|
37
|
+
const value = await checkLarouxBoundaries({ root: "." });
|
|
38
|
+
out.writeln(span.blue("ℹ"), span.text(` Checked ${value.filesChecked} files.`));
|
|
39
|
+
if (value.issues.length > 0) {
|
|
40
|
+
for (const issue of value.issues) {
|
|
41
|
+
const location = issue.line === undefined ? issue.file : `${issue.file}:${issue.line}`;
|
|
42
|
+
out.writeln(span.red("✗"), span.text(` ${location}: ${issue.message}`));
|
|
43
|
+
}
|
|
44
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
45
|
+
}
|
|
46
|
+
out.writeln(span.green("✓"), span.text(" The laroux boundaries hold."));
|
|
47
|
+
return primitives.results.ok(undefined);
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
out.writeln(span.red("✗"), span.text(` ${String(err)}`));
|
|
51
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
if (import.meta.main) {
|
|
55
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
56
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
57
|
+
const result = await main();
|
|
58
|
+
cliSupport.runCliMain(result, cliSupport.getCliContext().output);
|
|
59
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* License header validation tool.
|
|
4
|
+
*
|
|
5
|
+
* Validates that all JavaScript/TypeScript files have the correct copyright header.
|
|
6
|
+
* Can be used as a library or as a standalone script.
|
|
7
|
+
*
|
|
8
|
+
* Library usage:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import * as licenses from "@eserstack/codebase/validate-licenses";
|
|
11
|
+
*
|
|
12
|
+
* // Check licenses
|
|
13
|
+
* const result = await licenses.run();
|
|
14
|
+
* if (result.issues.length > 0) {
|
|
15
|
+
* console.log("Missing headers:", result.issues);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* // Fix licenses
|
|
19
|
+
* await licenses.run({ fix: true });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* CLI usage:
|
|
23
|
+
* node ./validate-licenses.ts # Check licenses
|
|
24
|
+
* node ./validate-licenses.ts --fix # Auto-fix missing/incorrect headers
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
28
|
+
import * as standards from "@eserstack/standards";
|
|
29
|
+
import * as crossRuntime from "@eserstack/standards/cross-runtime";
|
|
30
|
+
import * as patterns from "@eserstack/standards/patterns";
|
|
31
|
+
import * as cliSupport from "./cli-support.js";
|
|
32
|
+
import * as fileTool from "./file-tool.js";
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// Constants
|
|
35
|
+
// =============================================================================
|
|
36
|
+
const BASE_YEAR = "2023";
|
|
37
|
+
const RX_COPYRIGHT = new RegExp(`// Copyright ([0-9]{4})-present Eser Ozvataf and other contributors\\. All rights reserved\\. ([0-9A-Za-z-.]+) license\\.\n`);
|
|
38
|
+
const COPYRIGHT = `// Copyright ${BASE_YEAR}-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.`;
|
|
39
|
+
/**
|
|
40
|
+
* Tool-specific paths that are always skipped, regardless of user `exclude` config.
|
|
41
|
+
* These are not user-configurable — they represent files that should never have
|
|
42
|
+
* license headers (generated files, doc files, templates).
|
|
43
|
+
*
|
|
44
|
+
* Note: common directories (node_modules, .git, dist, etc.) are handled by
|
|
45
|
+
* DEFAULT_EXCLUDES in file-tools-shared.ts.
|
|
46
|
+
*/
|
|
47
|
+
const SKIP_PATTERNS = [/docs\//, /etc\/templates\//, /manifest\.gen\.ts$/];
|
|
48
|
+
// SKIP_PATTERNS are written with POSIX "/" separators. File paths arrive in the
|
|
49
|
+
// OS-native form ("\" on Windows), so normalize to forward slashes before testing
|
|
50
|
+
// — otherwise patterns like /docs\// never match on Windows. No-op on POSIX.
|
|
51
|
+
const shouldSkip = (path) => {
|
|
52
|
+
const normalized = crossRuntime.toPosix(path);
|
|
53
|
+
return SKIP_PATTERNS.some((p) => p.test(normalized));
|
|
54
|
+
};
|
|
55
|
+
// =============================================================================
|
|
56
|
+
// Check function
|
|
57
|
+
// =============================================================================
|
|
58
|
+
const checkLicenseHeader = (file, content, options) => {
|
|
59
|
+
if (content === undefined || shouldSkip(file.path)) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const hasShebang = content.startsWith("#!");
|
|
63
|
+
const shebangEnd = hasShebang ? content.indexOf("\n") + 1 : 0;
|
|
64
|
+
const afterShebang = content.slice(shebangEnd);
|
|
65
|
+
const match = afterShebang.match(RX_COPYRIGHT);
|
|
66
|
+
if (match !== null) {
|
|
67
|
+
if (match[1] === BASE_YEAR) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
path: file.path,
|
|
73
|
+
message: "incorrect copyright year",
|
|
74
|
+
fixed: options.fix,
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
path: file.path,
|
|
81
|
+
message: "missing copyright header",
|
|
82
|
+
fixed: options.fix,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
};
|
|
86
|
+
// =============================================================================
|
|
87
|
+
// Fix function
|
|
88
|
+
// =============================================================================
|
|
89
|
+
const fixLicenseHeader = (file, content, _options) => {
|
|
90
|
+
if (shouldSkip(file.path)) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
const hasShebang = content.startsWith("#!");
|
|
94
|
+
const shebangEnd = hasShebang ? content.indexOf("\n") + 1 : 0;
|
|
95
|
+
const afterShebang = content.slice(shebangEnd);
|
|
96
|
+
const match = afterShebang.match(RX_COPYRIGHT);
|
|
97
|
+
if (match !== null && match[1] === BASE_YEAR) {
|
|
98
|
+
return undefined; // Already correct
|
|
99
|
+
}
|
|
100
|
+
let newContent;
|
|
101
|
+
if (match !== null) {
|
|
102
|
+
// Incorrect year — replace existing header in full content
|
|
103
|
+
const shebang = content.slice(0, shebangEnd);
|
|
104
|
+
const rest = afterShebang.replace(match[0], "");
|
|
105
|
+
newContent = `${shebang}${COPYRIGHT}\n${rest}`;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// Missing header — insert after shebang if present
|
|
109
|
+
newContent = hasShebang
|
|
110
|
+
? `${content.slice(0, shebangEnd)}${COPYRIGHT}\n${afterShebang}`
|
|
111
|
+
: `${COPYRIGHT}\n${content}`;
|
|
112
|
+
}
|
|
113
|
+
return { path: file.path, oldContent: content, newContent };
|
|
114
|
+
};
|
|
115
|
+
// =============================================================================
|
|
116
|
+
// Tool
|
|
117
|
+
// =============================================================================
|
|
118
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
119
|
+
name: "validate-licenses",
|
|
120
|
+
description: "Validate license headers",
|
|
121
|
+
canFix: true,
|
|
122
|
+
stacks: ["javascript"],
|
|
123
|
+
defaults: {},
|
|
124
|
+
// Dotted format required — matches path.extname() output in walkSourceFiles git-aware path
|
|
125
|
+
extensions: patterns.JS_FILE_EXTENSIONS,
|
|
126
|
+
checkFile: checkLicenseHeader,
|
|
127
|
+
fixFile: fixLicenseHeader,
|
|
128
|
+
}), "license");
|
|
129
|
+
export const run = tool.run;
|
|
130
|
+
export const validator = tool.validator;
|
|
131
|
+
export const main = tool.main;
|
|
132
|
+
if (import.meta.main) {
|
|
133
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
134
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
135
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
136
|
+
cliSupport.runCliMain(result);
|
|
137
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Line ending fixer — normalizes all line endings to LF.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as standards from "@eserstack/standards";
|
|
8
|
+
import * as cliSupport from "./cli-support.js";
|
|
9
|
+
import * as fileTool from "./file-tool.js";
|
|
10
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
11
|
+
name: "validate-line-endings",
|
|
12
|
+
description: "Normalize line endings to LF",
|
|
13
|
+
canFix: true,
|
|
14
|
+
stacks: [],
|
|
15
|
+
defaults: {},
|
|
16
|
+
checkFile(file, content) {
|
|
17
|
+
if (content === undefined) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
if (content.includes("\r")) {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
path: file.path,
|
|
24
|
+
message: "file contains CRLF or CR line endings",
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
return [];
|
|
29
|
+
},
|
|
30
|
+
fixFile(file, content) {
|
|
31
|
+
// Replace CRLF first, then standalone CR
|
|
32
|
+
const fixed = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
33
|
+
if (fixed === content) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return { path: file.path, oldContent: content, newContent: fixed };
|
|
37
|
+
},
|
|
38
|
+
}), "line-endings");
|
|
39
|
+
export const run = tool.run;
|
|
40
|
+
export const validator = tool.validator;
|
|
41
|
+
export const main = tool.main;
|
|
42
|
+
if (import.meta.main) {
|
|
43
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
44
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
45
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
46
|
+
cliSupport.runCliMain(result);
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Merge conflict checker — detects conflict markers in files.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as standards from "@eserstack/standards";
|
|
8
|
+
import * as cliSupport from "./cli-support.js";
|
|
9
|
+
import * as fileTool from "./file-tool.js";
|
|
10
|
+
const CONFLICT_PATTERNS = [/^<{7}\s/, /^={7}$/, /^>{7}\s/];
|
|
11
|
+
export const tool = fileTool.withGoValidator(fileTool.createFileTool({
|
|
12
|
+
name: "validate-merge-conflict",
|
|
13
|
+
description: "Detect merge conflict markers",
|
|
14
|
+
canFix: false,
|
|
15
|
+
stacks: [],
|
|
16
|
+
defaults: {},
|
|
17
|
+
checkFile(file, content) {
|
|
18
|
+
if (content === undefined) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const issues = [];
|
|
22
|
+
const lines = content.split("\n");
|
|
23
|
+
for (let i = 0; i < lines.length; i++) {
|
|
24
|
+
for (const pattern of CONFLICT_PATTERNS) {
|
|
25
|
+
if (pattern.test(lines[i])) {
|
|
26
|
+
issues.push({
|
|
27
|
+
path: file.path,
|
|
28
|
+
line: i + 1,
|
|
29
|
+
message: `merge conflict marker: ${lines[i].slice(0, 20)}`,
|
|
30
|
+
});
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return issues;
|
|
36
|
+
},
|
|
37
|
+
}), "merge-conflicts");
|
|
38
|
+
export const run = tool.run;
|
|
39
|
+
export const validator = tool.validator;
|
|
40
|
+
export const main = tool.main;
|
|
41
|
+
if (import.meta.main) {
|
|
42
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
43
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
44
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
45
|
+
cliSupport.runCliMain(result);
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as shellArgs from "@eserstack/shell/args";
|
|
2
|
+
export type CheckModExportsOptions = {
|
|
3
|
+
readonly root?: string;
|
|
4
|
+
readonly failFast?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type MissingExport = {
|
|
7
|
+
readonly packageName: string;
|
|
8
|
+
readonly file: string;
|
|
9
|
+
};
|
|
10
|
+
export type CheckModExportsResult = {
|
|
11
|
+
readonly isComplete: boolean;
|
|
12
|
+
readonly missingExports: MissingExport[];
|
|
13
|
+
readonly packagesChecked: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const checkModExports: (options?: CheckModExportsOptions) => Promise<CheckModExportsResult>;
|
|
16
|
+
export declare const main: (_cliArgs?: readonly string[]) => Promise<shellArgs.CliResult<void>>;
|