@trebired/code-discipline 1.4.1 → 1.5.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/CHANGELOG.md +8 -0
- package/README.md +147 -6
- package/dist/checks/index.d.ts.map +1 -1
- package/dist/checks/index.js +5 -0
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/rules/max-function-lines.d.ts +6 -0
- package/dist/checks/rules/max-function-lines.d.ts.map +1 -0
- package/dist/checks/rules/max-function-lines.js +103 -0
- package/dist/checks/rules/max-function-lines.js.map +1 -0
- package/dist/checks/types.d.ts +43 -1
- package/dist/checks/types.d.ts.map +1 -1
- package/dist/cli/run-cli.d.ts.map +1 -1
- package/dist/cli/run-cli.js +10 -12
- package/dist/cli/run-cli.js.map +1 -1
- package/dist/config/index.d.ts +4 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +29 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/normalize-check-options.d.ts.map +1 -1
- package/dist/config/normalize-check-options.js +2 -1
- package/dist/config/normalize-check-options.js.map +1 -1
- package/dist/config/normalize-rule-options.d.ts +6 -2
- package/dist/config/normalize-rule-options.d.ts.map +1 -1
- package/dist/config/normalize-rule-options.js +16 -1
- package/dist/config/normalize-rule-options.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts +3 -3
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +28 -8
- package/dist/run.js.map +1 -1
- package/dist/runtime/orchestrate.d.ts +20 -0
- package/dist/runtime/orchestrate.d.ts.map +1 -0
- package/dist/runtime/orchestrate.js +60 -0
- package/dist/runtime/orchestrate.js.map +1 -0
- package/dist/runtime/runtime-imports-sync.d.ts +13 -0
- package/dist/runtime/runtime-imports-sync.d.ts.map +1 -0
- package/dist/runtime/runtime-imports-sync.js +87 -0
- package/dist/runtime/runtime-imports-sync.js.map +1 -0
- package/dist/runtime/tsconfig-paths.d.ts +21 -0
- package/dist/runtime/tsconfig-paths.d.ts.map +1 -0
- package/dist/runtime/tsconfig-paths.js +89 -0
- package/dist/runtime/tsconfig-paths.js.map +1 -0
- package/dist/shared/discipline-types.d.ts +1 -1
- package/dist/shared/discipline-types.d.ts.map +1 -1
- package/package.json +9 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { InvalidTsconfigPathError } from "../shared/errors.js";
|
|
4
|
+
import { parseTsconfigJson, pathExists, stableSerialize, toPosixPath, toStableJson } from "../shared/utils.js";
|
|
5
|
+
function resolveTsconfigPath(projectRoot, tsconfigPath) {
|
|
6
|
+
const input = tsconfigPath || "tsconfig.json";
|
|
7
|
+
return path.isAbsolute(input) ? path.resolve(input) : path.resolve(projectRoot, input);
|
|
8
|
+
}
|
|
9
|
+
function normalizePathsValue(value, mode) {
|
|
10
|
+
if (mode === "none")
|
|
11
|
+
return value;
|
|
12
|
+
if (path.isAbsolute(value))
|
|
13
|
+
return toPosixPath(value);
|
|
14
|
+
const normalized = toPosixPath(value);
|
|
15
|
+
if (mode === "relative-dot-prefix") {
|
|
16
|
+
if (normalized.startsWith("./") || normalized.startsWith("../") || normalized.startsWith("/")) {
|
|
17
|
+
return normalized;
|
|
18
|
+
}
|
|
19
|
+
return `./${normalized.replace(/^\/+/g, "")}`;
|
|
20
|
+
}
|
|
21
|
+
if (mode === "strip-dot-prefix") {
|
|
22
|
+
return normalized.startsWith("./") ? normalized.slice(2) : normalized;
|
|
23
|
+
}
|
|
24
|
+
return normalized;
|
|
25
|
+
}
|
|
26
|
+
function rewriteCompilerPaths(config, mode) {
|
|
27
|
+
const compilerOptions = { ...(config.compilerOptions || {}) };
|
|
28
|
+
const existingPaths = compilerOptions.paths;
|
|
29
|
+
if (!existingPaths || typeof existingPaths !== "object") {
|
|
30
|
+
return {
|
|
31
|
+
...config,
|
|
32
|
+
compilerOptions,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const nextPaths = Object.fromEntries(Object.entries(existingPaths).map(([aliasId, targets]) => [
|
|
36
|
+
aliasId,
|
|
37
|
+
Array.isArray(targets)
|
|
38
|
+
? targets.map((target) => normalizePathsValue(String(target), mode))
|
|
39
|
+
: targets,
|
|
40
|
+
]));
|
|
41
|
+
return {
|
|
42
|
+
...config,
|
|
43
|
+
compilerOptions: {
|
|
44
|
+
...compilerOptions,
|
|
45
|
+
paths: nextPaths,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function prepareTsconfigPaths(projectRoot, options, mode) {
|
|
50
|
+
const normalize = options?.normalize || "none";
|
|
51
|
+
if (normalize === "none")
|
|
52
|
+
return null;
|
|
53
|
+
const tsconfigPath = resolveTsconfigPath(projectRoot, options?.tsconfigPath);
|
|
54
|
+
if (!await pathExists(tsconfigPath)) {
|
|
55
|
+
throw new InvalidTsconfigPathError(tsconfigPath);
|
|
56
|
+
}
|
|
57
|
+
const originalText = await fs.readFile(tsconfigPath, "utf8");
|
|
58
|
+
const originalConfig = parseTsconfigJson(originalText, tsconfigPath);
|
|
59
|
+
const nextConfig = rewriteCompilerPaths(originalConfig, normalize);
|
|
60
|
+
const changed = stableSerialize(originalConfig) !== stableSerialize(nextConfig);
|
|
61
|
+
if (changed) {
|
|
62
|
+
await fs.writeFile(tsconfigPath, toStableJson(nextConfig));
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
changed,
|
|
66
|
+
originalText,
|
|
67
|
+
restoreAfterRun: Boolean(options?.restoreAfterRun),
|
|
68
|
+
restoreOnExit: Boolean(options?.restoreAfterRun) && mode !== "sync" && mode !== "startup",
|
|
69
|
+
tsconfigPath,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async function restoreTsconfigPaths(prepared) {
|
|
73
|
+
if (!prepared)
|
|
74
|
+
return null;
|
|
75
|
+
let restored = false;
|
|
76
|
+
if (prepared.restoreOnExit && prepared.originalText != null && prepared.changed) {
|
|
77
|
+
await fs.writeFile(prepared.tsconfigPath, prepared.originalText);
|
|
78
|
+
restored = true;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
changed: prepared.changed,
|
|
82
|
+
restored,
|
|
83
|
+
restoreAfterRun: prepared.restoreAfterRun,
|
|
84
|
+
restoreOnExit: prepared.restoreOnExit,
|
|
85
|
+
tsconfigPath: prepared.tsconfigPath,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export { prepareTsconfigPaths, resolveTsconfigPath, restoreTsconfigPaths };
|
|
89
|
+
//# sourceMappingURL=tsconfig-paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsconfig-paths.js","sourceRoot":"","sources":["../../src/runtime/tsconfig-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAmB/G,SAAS,mBAAmB,CAAC,WAAmB,EAAE,YAAqB;IACrE,MAAM,KAAK,GAAG,YAAY,IAAI,eAAe,CAAC;IAC9C,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AACzF,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa,EAAE,IAAkE;IAC5G,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IAClC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC,K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AAC;AACJ,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,QAA4C;IAC9E,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,YAAY,IAAI,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QAChF,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;QACjE,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;IAED,OAAO;QACL,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ;QACR,eAAe,EAAE,QAAQ,CAAC,eAAe;QACzC,aAAa,EAAE,QAAQ,CAAC,aAAa;QACrC,YAAY,EAAE,QAAQ,CAAC,YAAY;KACpC,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type CodeDisciplineSeverity = "error" | "warning";
|
|
2
|
-
type CodeDisciplineRuleName = "max-file-lines" | "folderize-compound-files" | "sync-imports";
|
|
2
|
+
type CodeDisciplineRuleName = "max-file-lines" | "max-function-lines" | "folderize-compound-files" | "sync-imports";
|
|
3
3
|
type CodeDisciplineViolation = {
|
|
4
4
|
rule: CodeDisciplineRuleName;
|
|
5
5
|
severity: CodeDisciplineSeverity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discipline-types.d.ts","sourceRoot":"","sources":["../../src/shared/discipline-types.ts"],"names":[],"mappings":"AAAA,KAAK,sBAAsB,GAAG,OAAO,GAAG,SAAS,CAAC;AAElD,KAAK,sBAAsB,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"discipline-types.d.ts","sourceRoot":"","sources":["../../src/shared/discipline-types.ts"],"names":[],"mappings":"AAAA,KAAK,sBAAsB,GAAG,OAAO,GAAG,SAAS,CAAC;AAElD,KAAK,sBAAsB,GAAG,gBAAgB,GAAG,oBAAoB,GAAG,0BAA0B,GAAG,cAAc,CAAC;AAEpH,KAAK,uBAAuB,GAAG;IAC7B,IAAI,EAAE,sBAAsB,CAAC;IAC7B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,uBAAuB,EAAE,CAAC;CACvC,CAAC;AAEF,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,uBAAuB,GACxB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trebired/code-discipline",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Configurable codebase discipline checks and import syncing for Bun and Node.js projects.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"keywords": [
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
"node",
|
|
11
11
|
"bun"
|
|
12
12
|
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/Trebired/code-discipline"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Trebired/code-discipline/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/Trebired/code-discipline#readme",
|
|
13
21
|
"type": "module",
|
|
14
22
|
"engines": {
|
|
15
23
|
"node": ">=18",
|