golar 0.0.17 → 0.1.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 (109) hide show
  1. package/dist/addon.js +16 -0
  2. package/dist/bin.d.ts +1 -0
  3. package/dist/bin.js +114 -34
  4. package/dist/builtin-rules.d.ts +10 -0
  5. package/dist/builtin-rules.generated.d.ts +12 -0
  6. package/dist/builtin-rules.generated.js +7 -0
  7. package/dist/builtin-rules.js +10 -0
  8. package/dist/codegen-plugin.d.ts +78 -0
  9. package/dist/codegen-plugin.js +187 -0
  10. package/dist/config.d.ts +33 -0
  11. package/dist/config.js +71 -0
  12. package/dist/internal/linter/rule-creator.d.ts +11 -0
  13. package/dist/internal/linter/rule-creator.js +46 -0
  14. package/dist/internal/linter/rules/explicit-anys/config.js +14 -0
  15. package/dist/lint.d.ts +32 -0
  16. package/dist/lint.js +16 -0
  17. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.d.ts +22 -0
  18. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js +29 -0
  19. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/iso.js +37 -0
  20. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/parse.d.ts +16 -0
  21. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/parse.js +19 -0
  22. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.d.ts +208 -0
  23. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js +578 -0
  24. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/api.d.ts +32 -0
  25. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/api.js +470 -0
  26. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.ts +64 -0
  27. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.js +225 -0
  28. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.ts +47 -0
  29. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js +61 -0
  30. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/doc.js +33 -0
  31. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.ts +127 -0
  32. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js +62 -0
  33. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema-processors.js +214 -0
  34. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.ts +69 -0
  35. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.js +109 -0
  36. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/regexes.js +58 -0
  37. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.ts +31 -0
  38. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js +49 -0
  39. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.ts +805 -0
  40. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.js +1096 -0
  41. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.ts +120 -0
  42. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.ts +96 -0
  43. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.js +289 -0
  44. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.ts +41 -0
  45. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js +304 -0
  46. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.ts +8 -0
  47. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.js +9 -0
  48. package/dist/packages/golar/package.js +41 -0
  49. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/elementFlags.enum.d.ts +14 -0
  50. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/elementFlags.enum.js +16 -0
  51. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/objectFlags.enum.d.ts +50 -0
  52. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/objectFlags.enum.js +52 -0
  53. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/signatureFlags.enum.d.ts +17 -0
  54. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/signatureFlags.enum.js +19 -0
  55. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/symbolFlags.enum.d.ts +73 -0
  56. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/symbolFlags.enum.js +75 -0
  57. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/typeFlags.enum.d.ts +78 -0
  58. package/dist/thirdparty/typescript-go/_packages/api/dist/enums/typeFlags.enum.js +80 -0
  59. package/dist/thirdparty/typescript-go/_packages/api/dist/node/msgpack.js +69 -0
  60. package/dist/thirdparty/typescript-go/_packages/api/dist/node/node.d.ts +214 -0
  61. package/dist/thirdparty/typescript-go/_packages/api/dist/node/node.js +1167 -0
  62. package/dist/thirdparty/typescript-go/_packages/api/dist/node/protocol.d.ts +6 -0
  63. package/dist/thirdparty/typescript-go/_packages/api/dist/node/protocol.js +472 -0
  64. package/dist/thirdparty/typescript-go/_packages/ast/dist/astnav.d.ts +22 -0
  65. package/dist/thirdparty/typescript-go/_packages/ast/dist/astnav.js +391 -0
  66. package/dist/thirdparty/typescript-go/_packages/ast/dist/clone.d.ts +19 -0
  67. package/dist/thirdparty/typescript-go/_packages/ast/dist/clone.js +83 -0
  68. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/characterCodes.enum.d.ts +168 -0
  69. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/characterCodes.js +133 -0
  70. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/commentDirectiveType.enum.d.ts +7 -0
  71. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/commentDirectiveType.js +9 -0
  72. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/languageVariant.enum.d.ts +7 -0
  73. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/languageVariant.js +9 -0
  74. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/modifierFlags.enum.d.ts +44 -0
  75. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/modifierFlags.js +46 -0
  76. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/nodeFlags.enum.d.ts +41 -0
  77. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/nodeFlags.js +43 -0
  78. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/regularExpressionFlags.enum.d.ts +15 -0
  79. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/regularExpressionFlags.js +17 -0
  80. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/scriptKind.enum.d.ts +13 -0
  81. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/scriptKind.js +15 -0
  82. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/scriptTarget.enum.d.ts +19 -0
  83. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/scriptTarget.js +21 -0
  84. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/syntaxKind.enum.d.ts +395 -0
  85. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/syntaxKind.js +397 -0
  86. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/tokenFlags.enum.d.ts +32 -0
  87. package/dist/thirdparty/typescript-go/_packages/ast/dist/enums/tokenFlags.js +34 -0
  88. package/dist/thirdparty/typescript-go/_packages/ast/dist/factory.js +2960 -0
  89. package/dist/thirdparty/typescript-go/_packages/ast/dist/index.js +19 -0
  90. package/dist/thirdparty/typescript-go/_packages/ast/dist/is.d.ts +276 -0
  91. package/dist/thirdparty/typescript-go/_packages/ast/dist/is.js +944 -0
  92. package/dist/thirdparty/typescript-go/_packages/ast/dist/nodes.d.ts +1479 -0
  93. package/dist/thirdparty/typescript-go/_packages/ast/dist/nodes.js +4 -0
  94. package/dist/thirdparty/typescript-go/_packages/ast/dist/scanner.d.ts +99 -0
  95. package/dist/thirdparty/typescript-go/_packages/ast/dist/scanner.js +4637 -0
  96. package/dist/thirdparty/typescript-go/_packages/ast/dist/utils.d.ts +8 -0
  97. package/dist/thirdparty/typescript-go/_packages/ast/dist/utils.js +28 -0
  98. package/dist/thirdparty/typescript-go/_packages/ast/dist/visitor.d.ts +51 -0
  99. package/dist/thirdparty/typescript-go/_packages/ast/dist/visitor.js +536 -0
  100. package/dist/type-decoder.d.ts +74 -0
  101. package/dist/type-decoder.js +303 -0
  102. package/dist/unstable-tsgo.d.ts +24 -0
  103. package/dist/unstable-tsgo.js +25 -0
  104. package/dist/unstable.d.ts +6 -0
  105. package/dist/unstable.js +7 -0
  106. package/dist/utils.js +15 -0
  107. package/dist/workspace.d.ts +48 -0
  108. package/dist/workspace.js +255 -0
  109. package/package.json +13 -27
package/dist/addon.js ADDED
@@ -0,0 +1,16 @@
1
+ import process from "node:process";
2
+ import os from "node:os";
3
+ import worker_threads from "node:worker_threads";
4
+ import url from "node:url";
5
+
6
+ //#region src/addon.ts
7
+ const addonModule = { exports: {} };
8
+ const golarAddonPath = url.fileURLToPath(import.meta.resolve(`@golar/${process.platform}-${process.arch}/golar.node`));
9
+ process.dlopen(addonModule, golarAddonPath, os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
10
+ const { exports: addon } = addonModule;
11
+ const syncBuf = /* @__PURE__ */ new ArrayBuffer(10 * 1024 * 1024);
12
+ const syncView = new DataView(syncBuf);
13
+ addon.setSyncBuffer(worker_threads.threadId, syncBuf);
14
+
15
+ //#endregion
16
+ export { addon, golarAddonPath, syncBuf, syncView };
package/dist/bin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/bin.js CHANGED
@@ -1,45 +1,125 @@
1
1
  #!/usr/bin/env node
2
+ import { addon, syncBuf, syncView } from "./addon.js";
3
+ import { JsCodegenPlugin, globalState } from "./codegen-plugin.js";
4
+ import { loadConfig, resolveConfig } from "./config.js";
5
+ import { Workspace } from "./workspace.js";
6
+ import { styleText } from "./utils.js";
2
7
  import process from "node:process";
3
- import fs from "node:fs/promises";
4
- import child_process from "node:child_process";
8
+ import os from "node:os";
5
9
  import path from "node:path";
6
- import { fileURLToPath } from "node:url";
10
+ import assert from "node:assert/strict";
11
+ import worker_threads from "node:worker_threads";
12
+ import fs from "node:fs";
7
13
 
8
14
  //#region src/bin.ts
9
- const plugins = /* @__PURE__ */ new Map();
10
- const filename = import.meta.filename.replaceAll("\\", "/");
11
- await Promise.all(filename.matchAll(/\/node_modules\//g).map(async (nodeModulesMatch) => {
12
- const nodeModulesPath = filename.slice(0, nodeModulesMatch.index + nodeModulesMatch[0].length);
13
- for (const orgName of await fs.readdir(nodeModulesPath)) {
14
- if (!orgName.startsWith("@")) continue;
15
- for (const packageName of await fs.readdir(path.join(nodeModulesPath, orgName))) {
16
- if ((orgName !== "@golar" || ![
17
- "astro",
18
- "ember",
19
- "svelte",
20
- "vue"
21
- ].includes(packageName)) && !/^golar-plugin(-.+)?$/.exec(packageName)) continue;
22
- const packageSpecifier = `${orgName}/${packageName}`;
23
- const mod = await import(`${packageSpecifier}/golar-entry`);
24
- if (typeof mod.getGolarEntry !== "function") continue;
25
- plugins.set(packageSpecifier, await mod.getGolarEntry());
15
+ const argv = process.argv.slice(2);
16
+ const cwd = process.cwd();
17
+ const configPath = path.join(cwd, "golar.config.ts");
18
+ if (argv[0] === "--help") {
19
+ console.log(`
20
+ Usage: golar [command]
21
+
22
+ Commands:
23
+ golar Lint and typecheck the current workspace (recommended)
24
+ golar lint Run lint checks only
25
+ golar typecheck Run typechecking only
26
+ golar tsc [tsc args...] Forward arguments to TypeScript CLI
27
+
28
+ Options:
29
+ --help Show this help message
30
+ --version Print Golar version`);
31
+ process.exit(0);
32
+ } else if (argv[0] === "--version") {
33
+ const { default: { version } } = await import("../package.json", { with: { type: "json" } });
34
+ console.log(`Golar version ${version}`);
35
+ process.exit(0);
36
+ }
37
+ if (!fs.existsSync(configPath)) {
38
+ console.log(`${styleText("red", "Error:")} ./golar.config.ts not found`);
39
+ process.exit(1);
40
+ }
41
+ console.log(`${styleText("dim", "Using config from")} ./golar.config.ts${styleText("dim", "...")}`);
42
+ const config = await loadConfig(configPath);
43
+ const hasJsCodegenPlugins = globalState.codegenPlugins.values().some((v) => v instanceof JsCodegenPlugin);
44
+ const selfExtname = path.extname(import.meta.filename);
45
+ const workerPath = path.join(import.meta.dirname, `worker${selfExtname}`);
46
+ const textEncoder = new TextEncoder();
47
+ if (argv[0] === "tsc") {
48
+ for (const plugin of globalState.codegenPlugins.values()) plugin.register();
49
+ const args = argv.slice(1);
50
+ let offset = 0;
51
+ syncView.setUint32(offset, args.length, true);
52
+ offset += 4;
53
+ for (const arg of args) {
54
+ const { written: argLen } = textEncoder.encodeInto(arg, new Uint8Array(syncBuf, offset + 4));
55
+ syncView.setUint32(offset, argLen, true);
56
+ offset += 4 + argLen;
57
+ }
58
+ addon.tsc(worker_threads.threadId, (exitCode) => process.exit(exitCode));
59
+ if (hasJsCodegenPlugins) {
60
+ worker_threads.setEnvironmentData("golar-env", {
61
+ configPath,
62
+ cwd,
63
+ mode: "codegen-only"
64
+ });
65
+ const workersCount = Math.floor(Math.max(Math.min(os.availableParallelism() / 2, 4), 1)) - 1;
66
+ const promises = [];
67
+ for (let i = 0; i < workersCount; i++) {
68
+ const w = new worker_threads.Worker(workerPath);
69
+ promises.push(new Promise((resolve) => w.once("message", resolve)));
26
70
  }
71
+ await Promise.all(promises);
72
+ }
73
+ } else {
74
+ const lintOnly = argv[0] === "lint";
75
+ const typecheckOnly = argv[0] === "typecheck";
76
+ if (!lintOnly && !typecheckOnly && [
77
+ "--noEmit",
78
+ "-b",
79
+ "--build",
80
+ "--declaration",
81
+ "--emitDeclarationOnly"
82
+ ].some((flag) => argv.includes(flag))) {
83
+ let message = `${styleText("red", "Error:")} Golar v0.1+ doesn't support passing tsc flags to the root subcommand.\n`;
84
+ if (argv.includes("--declaration") || argv.includes("--emitDeclarationOnly")) message += `Instead, run: ${styleText("bold", `golar ${styleText("green", "tsc")} ${argv.join(" ")}`)}`;
85
+ else message += `Instead, run ${styleText("bold", "golar")} without any arguments.`;
86
+ console.log(message);
87
+ process.exit(1);
27
88
  }
28
- }));
29
- const exePath = fileURLToPath(import.meta.resolve(`@golar/${process.platform}-${process.arch}/golar${process.platform === "win32" ? ".exe" : ""}`));
30
- try {
31
- child_process.execFileSync(exePath, process.argv.slice(2), {
32
- env: {
33
- GOLAR_PLUGINS: Array.from(plugins.values().map((args) => args.join(""))).join(""),
34
- ...process.env
35
- },
36
- stdio: "inherit"
37
- });
38
- } catch (e) {
39
- if (e instanceof Error) {
40
- if ("status" in e && typeof e.status === "number") process.exit(e.status);
89
+ for (const plugin of globalState.codegenPlugins.values()) plugin.register();
90
+ const { files, builtinRulesByFile, nativeRulesByFile, jsFilesByWorker, jsRulesByFile, typecheckFiles } = resolveConfig(cwd, config);
91
+ const { meta, workspace: wsPromise } = await Workspace.create(cwd, files);
92
+ const ws = await wsPromise;
93
+ if (!typecheckOnly) {
94
+ ws.lintBuiltin(builtinRulesByFile);
95
+ ws.lintNative(nativeRulesByFile, path.dirname(configPath));
96
+ const promises = [];
97
+ if (jsRulesByFile.size > 0) {
98
+ worker_threads.setEnvironmentData("golar-env", {
99
+ configPath,
100
+ cwd,
101
+ mode: "lint"
102
+ });
103
+ jsFilesByWorker.slice(0, -1).map((workerFiles) => {
104
+ const worker = new worker_threads.Worker(workerPath);
105
+ promises.push(new Promise((resolve) => worker.once("message", resolve)));
106
+ worker.postMessage({
107
+ meta,
108
+ jsFiles: workerFiles
109
+ });
110
+ return worker;
111
+ });
112
+ }
113
+ if (jsRulesByFile.size > 0) {
114
+ const mainJsFiles = jsFilesByWorker.at(-1);
115
+ assert.ok(mainJsFiles);
116
+ ws.preloadRequestedFiles(mainJsFiles);
117
+ ws.lintJs(new Map(mainJsFiles.map((file) => [file, Array.from(jsRulesByFile.get(file).values())])));
118
+ }
119
+ await Promise.all(promises);
41
120
  }
42
- throw e;
121
+ if (!lintOnly) process.exit(ws.typecheck(typecheckFiles));
122
+ process.exit(0);
43
123
  }
44
124
 
45
125
  //#endregion
@@ -0,0 +1,10 @@
1
+ import { input } from "./node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js";
2
+ import { ZodObject } from "./node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js";
3
+ import { GolarBrand } from "./internal/linter/rule-creator.js";
4
+ import { LintConfiguredRule } from "./config.js";
5
+ import { rules as rules$1 } from "./builtin-rules.generated.js";
6
+
7
+ //#region src/builtin-rules.d.ts
8
+ declare const rules: (configs: { [TRule in keyof typeof rules$1]?: true | undefined | input<ZodObject<(typeof rules$1)[TRule][typeof GolarBrand]['options']>> }) => LintConfiguredRule[];
9
+ //#endregion
10
+ export { rules };
@@ -0,0 +1,12 @@
1
+ import { ZodBoolean, ZodDefault } from "./node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js";
2
+ import { RuleDefinition } from "./internal/linter/rule-creator.js";
3
+
4
+ //#region src/builtin-rules.generated.d.ts
5
+ declare const rules: {
6
+ readonly 'explicit-anys': RuleDefinition<{
7
+ fixToUnknown: ZodDefault<ZodBoolean>;
8
+ ignoreRestArgs: ZodDefault<ZodBoolean>;
9
+ }>;
10
+ };
11
+ //#endregion
12
+ export { rules };
@@ -0,0 +1,7 @@
1
+ import { rule } from "./internal/linter/rules/explicit-anys/config.js";
2
+
3
+ //#region src/builtin-rules.generated.ts
4
+ const rules = { "explicit-anys": rule };
5
+
6
+ //#endregion
7
+ export { rules };
@@ -0,0 +1,10 @@
1
+ import { rules as rules$1 } from "./builtin-rules.generated.js";
2
+
3
+ //#region src/builtin-rules.ts
4
+ const rules = (configs) => Object.entries(configs).map(([name, config]) => ({
5
+ rule: rules$1[name],
6
+ options: config === true ? {} : config
7
+ }));
8
+
9
+ //#endregion
10
+ export { rules };
@@ -0,0 +1,78 @@
1
+ //#region src/codegen-plugin.d.ts
2
+ type FileExtension = {
3
+ /** Include the leading dot, e.g. '.vue'. */extension: string;
4
+ stripFromDeclarationFileName: boolean;
5
+ allowExtensionlessImports: boolean;
6
+ };
7
+ type Promisable<T> = T | Promise<T>;
8
+ type CodegenMapping = {
9
+ sourceOffset: number;
10
+ serviceOffset: number;
11
+ sourceLength: number;
12
+ serviceLength?: number | undefined;
13
+ suppressedDiagnostics?: number[] | undefined;
14
+ };
15
+ type IgnoreDirectiveCodegenMapping = {
16
+ serviceOffset: number;
17
+ serviceLength: number;
18
+ };
19
+ type ExpectErrorDirectiveCodegenMapping = {
20
+ sourceOffset: number;
21
+ serviceOffset: number;
22
+ sourceLength: number;
23
+ serviceLength: number;
24
+ };
25
+ type CodegenScriptKind = 'js' | 'jsx' | 'ts' | 'tsx';
26
+ type ServiceCodeError = {
27
+ message: string;
28
+ start: number;
29
+ end: number;
30
+ };
31
+ type ServiceCode = {
32
+ mappings: CodegenMapping[];
33
+ errors?: never;
34
+ serviceText: string;
35
+ scriptKind: CodegenScriptKind; /** @default false */
36
+ declarationFile?: boolean | undefined;
37
+ ignoreMappings?: IgnoreDirectiveCodegenMapping[] | undefined;
38
+ expectErrorMappings?: ExpectErrorDirectiveCodegenMapping[] | undefined;
39
+ ignoreNotMappedDiagnostics?: boolean | undefined;
40
+ } | {
41
+ mappings?: never;
42
+ errors: ServiceCodeError[];
43
+ };
44
+ type CodegenPlugin = JsCodegenPlugin | IpcCodegenPlugin;
45
+ declare const globalState: {
46
+ codegenPlugins: Map<string, CodegenPlugin>;
47
+ };
48
+ type CreateServiceCodeFn = (cwd: string, configFileName: string | null, fileName: string, sourceText: string) => Promisable<ServiceCode>;
49
+ type JsCodegenPluginOptions = {
50
+ id: string;
51
+ extensions: FileExtension[];
52
+ createServiceCode: CreateServiceCodeFn;
53
+ };
54
+ declare class JsCodegenPlugin {
55
+ readonly id: string;
56
+ readonly idNumeric: number;
57
+ readonly extensions: FileExtension[];
58
+ readonly createServiceCode: CreateServiceCodeFn;
59
+ static pluginIdCounter: number;
60
+ constructor(opts: JsCodegenPluginOptions);
61
+ register(): void;
62
+ executeCreateServiceCode(): Promise<void>;
63
+ private processCreatedServiceCode;
64
+ }
65
+ type IpcCodegenPluginOptions = {
66
+ id: string;
67
+ cmd: readonly string[];
68
+ extensions: FileExtension[];
69
+ };
70
+ declare class IpcCodegenPlugin {
71
+ readonly id: string;
72
+ readonly cmd: readonly string[];
73
+ readonly extensions: FileExtension[];
74
+ constructor(opts: IpcCodegenPluginOptions);
75
+ register(): void;
76
+ }
77
+ //#endregion
78
+ export { CodegenMapping, CodegenPlugin, CodegenScriptKind, CreateServiceCodeFn, ExpectErrorDirectiveCodegenMapping, FileExtension, IgnoreDirectiveCodegenMapping, IpcCodegenPlugin, IpcCodegenPluginOptions, JsCodegenPlugin, JsCodegenPluginOptions, Promisable, ServiceCode, ServiceCodeError, globalState };
@@ -0,0 +1,187 @@
1
+ import { addon, syncBuf, syncView } from "./addon.js";
2
+ import os from "node:os";
3
+ import worker_threads from "node:worker_threads";
4
+
5
+ //#region src/codegen-plugin.ts
6
+ const textDecoder = new TextDecoder();
7
+ const textEncoder = new TextEncoder();
8
+ const SERVICE_CODE_PROPERTIES = {
9
+ ERROR: 1,
10
+ DECLARATION_FILE: 2,
11
+ IGNORE_NOT_MAPPED_DIAGNOSTICS: 4
12
+ };
13
+ const SCRIPT_KIND = {
14
+ js: 0,
15
+ jsx: 1,
16
+ ts: 2,
17
+ tsx: 3
18
+ };
19
+ const stateSymbol = Symbol.for("golar-global-state");
20
+ const globalTyped = globalThis;
21
+ const globalState = globalTyped[stateSymbol] ??= { codegenPlugins: /* @__PURE__ */ new Map() };
22
+ function registerCodegenPlugin(plugin) {
23
+ if (globalState.codegenPlugins.get(plugin.id)) throw new Error(`Duplicate ${plugin.id} codegen plugin`);
24
+ globalState.codegenPlugins.set(plugin.id, plugin);
25
+ }
26
+ var JsCodegenPlugin = class JsCodegenPlugin {
27
+ id;
28
+ idNumeric;
29
+ extensions;
30
+ createServiceCode;
31
+ static pluginIdCounter = 0;
32
+ constructor(opts) {
33
+ this.id = opts.id;
34
+ this.idNumeric = JsCodegenPlugin.pluginIdCounter++;
35
+ this.extensions = opts.extensions;
36
+ this.createServiceCode = opts.createServiceCode;
37
+ registerCodegenPlugin(this);
38
+ }
39
+ register() {
40
+ let offset = 0;
41
+ syncView.setUint32(offset, this.idNumeric, true);
42
+ offset += 4;
43
+ const { written: initializationLen } = textEncoder.encodeInto(JSON.stringify({ extensions: this.extensions }), new Uint8Array(syncBuf, offset + 4));
44
+ syncView.setUint32(offset, initializationLen, true);
45
+ offset += 4 + initializationLen;
46
+ addon.registerJsCodegen(worker_threads.threadId, () => this.executeCreateServiceCode());
47
+ }
48
+ async executeCreateServiceCode() {
49
+ let offset = 0;
50
+ const codegenPluginPtr = syncView.getBigUint64(offset, true);
51
+ offset += 8;
52
+ const cwdLen = syncView.getUint32(offset, true);
53
+ const cwd = textDecoder.decode(new Uint8Array(syncBuf, offset += 4, cwdLen));
54
+ offset += cwdLen;
55
+ const configFileNameLen = syncView.getUint32(offset, true);
56
+ const configFileName = textDecoder.decode(new Uint8Array(syncBuf, offset += 4, configFileNameLen));
57
+ offset += configFileNameLen;
58
+ const fileNameLen = syncView.getUint32(offset, true);
59
+ const fileName = textDecoder.decode(new Uint8Array(syncBuf, offset += 4, fileNameLen));
60
+ offset += fileNameLen;
61
+ const sourceTextLen = syncView.getUint32(offset, true);
62
+ const sourceText = textDecoder.decode(new Uint8Array(syncBuf, offset += 4, sourceTextLen));
63
+ offset += sourceTextLen;
64
+ const resp = this.createServiceCode(cwd, configFileName === "/dev/null/inferred" ? null : configFileName, fileName, sourceText);
65
+ if (resp instanceof Promise) return resp.then((resp) => this.processCreatedServiceCode(sourceText, codegenPluginPtr, resp));
66
+ return this.processCreatedServiceCode(sourceText, codegenPluginPtr, resp);
67
+ }
68
+ processCreatedServiceCode(sourceText, codegenPluginPtr, resp) {
69
+ let offset = 0;
70
+ let properties = 0;
71
+ if ("errors" in resp) {
72
+ const errorLocationsUtf8 = mapIndicesToUtf8(sourceText, resp.errors[Symbol.iterator]().flatMap((e) => [e.start, e.end]));
73
+ syncView.setBigUint64(offset, codegenPluginPtr, true);
74
+ syncView.setUint8(offset += 8, properties | SERVICE_CODE_PROPERTIES.ERROR);
75
+ syncView.setUint32(offset += 1, resp.errors.length, true);
76
+ offset += 4;
77
+ for (const err of resp.errors) {
78
+ const { written: msgLen } = textEncoder.encodeInto(err.message, new Uint8Array(syncBuf, offset + 4));
79
+ syncView.setUint32(offset, msgLen, true);
80
+ offset += 4 + msgLen;
81
+ syncView.setUint32(offset, errorLocationsUtf8(err.start), true);
82
+ syncView.setUint32(offset += 4, errorLocationsUtf8(err.end), true);
83
+ offset += 4;
84
+ }
85
+ return;
86
+ }
87
+ if (resp.declarationFile) properties |= SERVICE_CODE_PROPERTIES.DECLARATION_FILE;
88
+ if (resp.ignoreNotMappedDiagnostics) properties |= SERVICE_CODE_PROPERTIES.IGNORE_NOT_MAPPED_DIAGNOSTICS;
89
+ const writeUint32 = os.endianness() === "LE" ? (offset, value) => syncView.setUint32(offset, value, true) : (offset, value) => syncView.setUint32(offset, value, false);
90
+ syncView.setBigUint64(offset, codegenPluginPtr, true);
91
+ syncView.setUint8(offset += 8, properties);
92
+ syncView.setUint8(offset += 1, SCRIPT_KIND[resp.scriptKind]);
93
+ offset += 1;
94
+ const { written: serviceTextLen } = textEncoder.encodeInto(resp.serviceText, new Uint8Array(syncBuf, offset + 4));
95
+ syncView.setUint32(offset, serviceTextLen, true);
96
+ offset += 4 + serviceTextLen;
97
+ const sourceIndicesUtf8 = mapIndicesToUtf8(sourceText, (function* () {
98
+ for (const m of resp.mappings) {
99
+ yield m.sourceOffset;
100
+ yield m.sourceOffset + m.sourceLength;
101
+ }
102
+ for (const m of resp.expectErrorMappings ?? []) {
103
+ yield m.sourceOffset;
104
+ yield m.sourceOffset + m.sourceLength;
105
+ }
106
+ })());
107
+ const serviceIndicesUtf8 = mapIndicesToUtf8(resp.serviceText, (function* () {
108
+ for (const m of resp.mappings) {
109
+ yield m.serviceOffset;
110
+ yield m.serviceOffset + (m.serviceLength ?? m.sourceLength);
111
+ }
112
+ for (const m of resp.ignoreMappings ?? []) {
113
+ yield m.serviceOffset;
114
+ yield m.serviceOffset + m.serviceLength;
115
+ }
116
+ for (const m of resp.expectErrorMappings ?? []) {
117
+ yield m.serviceOffset;
118
+ yield m.serviceOffset + m.serviceLength;
119
+ }
120
+ })());
121
+ syncView.setUint32(offset, resp.mappings.length, true);
122
+ offset += 4;
123
+ for (const m of resp.mappings) {
124
+ const sourceOffsetUtf8 = sourceIndicesUtf8(m.sourceOffset);
125
+ const serviceOffsetUtf8 = serviceIndicesUtf8(m.serviceOffset);
126
+ writeUint32(offset, sourceOffsetUtf8);
127
+ writeUint32(offset += 4, serviceOffsetUtf8);
128
+ writeUint32(offset += 4, sourceIndicesUtf8(m.sourceOffset + m.sourceLength) - sourceOffsetUtf8);
129
+ writeUint32(offset += 4, serviceIndicesUtf8(m.serviceOffset + (m.serviceLength ?? m.sourceLength)) - serviceOffsetUtf8);
130
+ const suppressedDiagnostics = m.suppressedDiagnostics ?? [];
131
+ writeUint32(offset += 4, suppressedDiagnostics.length);
132
+ offset += 4;
133
+ for (const code of suppressedDiagnostics) {
134
+ writeUint32(offset, code);
135
+ offset += 4;
136
+ }
137
+ }
138
+ syncView.setUint32(offset, resp.ignoreMappings?.length ?? 0, true);
139
+ offset += 4;
140
+ for (const m of resp.ignoreMappings ?? []) {
141
+ const serviceOffsetUtf8 = serviceIndicesUtf8(m.serviceOffset);
142
+ writeUint32(offset, serviceOffsetUtf8);
143
+ writeUint32(offset += 4, serviceIndicesUtf8(m.serviceOffset + m.serviceLength) - serviceOffsetUtf8);
144
+ offset += 4;
145
+ }
146
+ syncView.setUint32(offset, resp.expectErrorMappings?.length ?? 0, true);
147
+ offset += 4;
148
+ for (const m of resp.expectErrorMappings ?? []) {
149
+ const sourceOffsetUtf8 = sourceIndicesUtf8(m.sourceOffset);
150
+ const serviceOffsetUtf8 = serviceIndicesUtf8(m.serviceOffset);
151
+ writeUint32(offset, sourceOffsetUtf8);
152
+ writeUint32(offset += 4, serviceOffsetUtf8);
153
+ writeUint32(offset += 4, sourceIndicesUtf8(m.sourceOffset + m.sourceLength) - sourceOffsetUtf8);
154
+ writeUint32(offset += 4, serviceIndicesUtf8(m.serviceOffset + m.serviceLength) - serviceOffsetUtf8);
155
+ offset += 4;
156
+ }
157
+ }
158
+ };
159
+ var IpcCodegenPlugin = class {
160
+ id;
161
+ cmd;
162
+ extensions;
163
+ constructor(opts) {
164
+ this.id = opts.id;
165
+ this.cmd = opts.cmd;
166
+ this.extensions = opts.extensions;
167
+ registerCodegenPlugin(this);
168
+ }
169
+ register() {
170
+ const { written: initializationLen } = textEncoder.encodeInto(JSON.stringify({
171
+ cmd: this.cmd,
172
+ extensions: this.extensions
173
+ }), new Uint8Array(syncBuf, 4));
174
+ syncView.setUint32(0, initializationLen, true);
175
+ addon.registerIpcCodegen();
176
+ }
177
+ };
178
+ function mapIndicesToUtf8(text, indices) {
179
+ const mapped = /* @__PURE__ */ new Map();
180
+ const sorted = Array.from(new Set(indices)).sort((a, b) => a - b);
181
+ let utf8Offset = 0;
182
+ for (const [i, idx] of sorted.entries()) mapped.set(idx, utf8Offset += Buffer.byteLength(text.slice(sorted[i - 1] ?? 0, idx)));
183
+ return mapped.get.bind(mapped);
184
+ }
185
+
186
+ //#endregion
187
+ export { IpcCodegenPlugin, JsCodegenPlugin, globalState };
@@ -0,0 +1,33 @@
1
+ import { GolarBrand } from "./internal/linter/rule-creator.js";
2
+
3
+ //#region src/config.d.ts
4
+ type LintConfiguredRule = {
5
+ [GolarBrand]: {
6
+ rule: true;
7
+ };
8
+ };
9
+ type LintConfigUseDefinition = {
10
+ files: string[];
11
+ rules: LintConfiguredRule[];
12
+ };
13
+ type Config = {
14
+ lint?: {
15
+ use: LintConfigUseDefinition[];
16
+ } | undefined;
17
+ typecheck?: {
18
+ include: string[];
19
+ exclude?: string[] | undefined;
20
+ };
21
+ };
22
+ declare function defineConfig(config: Config): Config;
23
+ declare function loadConfig(configPath: string): Promise<Config>;
24
+ declare function resolveConfig(cwd: string, config: Config): {
25
+ files: string[];
26
+ builtinRulesByFile: Map<string, LintConfiguredRule[]>;
27
+ jsFilesByWorker: string[][];
28
+ jsRulesByFile: Map<string, Map<any, LintConfiguredRule>>;
29
+ nativeRulesByFile: Map<string, LintConfiguredRule[]>;
30
+ typecheckFiles: string[];
31
+ };
32
+ //#endregion
33
+ export { Config, LintConfigUseDefinition, LintConfiguredRule, defineConfig, loadConfig, resolveConfig };
package/dist/config.js ADDED
@@ -0,0 +1,71 @@
1
+ import { globalState } from "./codegen-plugin.js";
2
+ import path from "node:path";
3
+ import fs from "node:fs";
4
+ import url from "node:url";
5
+ import util from "node:util";
6
+ import { Debug } from "@golar/util";
7
+
8
+ //#region src/config.ts
9
+ const debug = Debug.create("config");
10
+ function defineConfig(config) {
11
+ return config;
12
+ }
13
+ async function loadConfig(configPath) {
14
+ const { default: config } = await import(url.pathToFileURL(configPath).href);
15
+ return config;
16
+ }
17
+ function resolveConfig(cwd, config) {
18
+ const allFiles = /* @__PURE__ */ new Set();
19
+ const builtinEffectiveRulesByFile = /* @__PURE__ */ new Map();
20
+ const jsEffectiveRulesByFile = /* @__PURE__ */ new Map();
21
+ const nativeEffectiveRulesByFile = /* @__PURE__ */ new Map();
22
+ for (const group of config.lint?.use ?? []) for (const file of new Set(fs.globSync(group.files, {
23
+ cwd,
24
+ withFileTypes: true
25
+ }).filter((entry) => entry.isFile()).map((entry) => path.resolve(cwd, entry.parentPath, entry.name)))) {
26
+ allFiles.add(file);
27
+ for (const rule of group.rules) {
28
+ let rulesByFile;
29
+ if (rule.rule.isBuiltin) rulesByFile = builtinEffectiveRulesByFile;
30
+ else if (rule.rule.isCustomJs) rulesByFile = jsEffectiveRulesByFile;
31
+ else if (rule.rule.isNative) rulesByFile = nativeEffectiveRulesByFile;
32
+ else throw new Error(`Invalid rule: ${util.inspect(rule)}`);
33
+ let effectiveRules = rulesByFile.get(file);
34
+ if (effectiveRules == null) rulesByFile.set(file, effectiveRules = /* @__PURE__ */ new Map());
35
+ effectiveRules.set(rule.rule, rule);
36
+ }
37
+ }
38
+ const builtinRulesByFile = new Map(builtinEffectiveRulesByFile.entries().map(([file, rulesById]) => [file, Array.from(rulesById.values())]));
39
+ const jsFiles = Array.from(jsEffectiveRulesByFile.keys());
40
+ const jsWorkersCount = Math.min(jsFiles.length, 4);
41
+ const jsFilesPerThread = Math.ceil(jsFiles.length / jsWorkersCount);
42
+ const jsEffectiveRulesIter = jsEffectiveRulesByFile.keys();
43
+ const jsFilesByWorker = Array(jsWorkersCount).fill(null).map(() => Array.from(jsEffectiveRulesIter.take(jsFilesPerThread)));
44
+ const nativeRulesByFile = new Map(nativeEffectiveRulesByFile.entries().map(([file, rulesById]) => [file, Array.from(rulesById.values())]));
45
+ let typecheckFiles = null;
46
+ const typecheckInclude = config.typecheck == null ? ["**/*.{ts,tsx}", ...globalState.codegenPlugins.values().flatMap((plugin) => plugin.extensions).map(({ extension }) => `**/*${extension}`).toArray()] : config.typecheck.include;
47
+ const typecheckExclude = [
48
+ ...config.typecheck?.exclude ?? [],
49
+ "**/node_modules",
50
+ "**/.git",
51
+ "**/.jj"
52
+ ];
53
+ typecheckFiles = fs.globSync(typecheckInclude, {
54
+ cwd,
55
+ exclude: typecheckExclude,
56
+ withFileTypes: true
57
+ }).filter((entry) => entry.isFile()).map((entry) => path.resolve(cwd, entry.parentPath, entry.name));
58
+ for (const file of typecheckFiles) allFiles.add(file);
59
+ debug.print("typecheck files:\n" + typecheckFiles.join("\n"));
60
+ return {
61
+ files: Array.from(allFiles),
62
+ builtinRulesByFile,
63
+ jsFilesByWorker,
64
+ jsRulesByFile: jsEffectiveRulesByFile,
65
+ nativeRulesByFile,
66
+ typecheckFiles
67
+ };
68
+ }
69
+
70
+ //#endregion
71
+ export { defineConfig, loadConfig, resolveConfig };
@@ -0,0 +1,11 @@
1
+ import { ZodDefault } from "../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js";
2
+
3
+ //#region ../../internal/linter/rule-creator.d.ts
4
+ declare const GolarBrand: unique symbol;
5
+ type RuleDefinition<TOptions extends Record<string, ZodDefault>> = {
6
+ [GolarBrand]: {
7
+ options: TOptions;
8
+ };
9
+ };
10
+ //#endregion
11
+ export { GolarBrand, RuleDefinition };
@@ -0,0 +1,46 @@
1
+ import { array, discriminatedUnion, literal, strictObject, string, union } from "../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js";
2
+ import path from "node:path";
3
+
4
+ //#region ../../internal/linter/rule-creator.ts
5
+ function ruleConfig(config) {
6
+ return {
7
+ ...config,
8
+ isBuiltin: true,
9
+ name: path.basename(config.dirname)
10
+ };
11
+ }
12
+ const typeOrValueSpecifier = array(discriminatedUnion("from", [
13
+ strictObject({
14
+ from: literal("file"),
15
+ name: union([string(), array(string())]),
16
+ path: string().optional()
17
+ }),
18
+ strictObject({
19
+ from: literal("lib"),
20
+ name: union([string(), array(string())])
21
+ }),
22
+ strictObject({
23
+ from: literal("package"),
24
+ name: union([string(), array(string())]),
25
+ package: string()
26
+ })
27
+ ]).transform((v) => {
28
+ const res = {
29
+ from: v.from,
30
+ name: Array.isArray(v.name) ? v.name : [v.name]
31
+ };
32
+ switch (v.from) {
33
+ case "file": return {
34
+ ...res,
35
+ filePath: v.path ?? ""
36
+ };
37
+ case "lib": return res;
38
+ case "package": return {
39
+ ...res,
40
+ package: v.package ?? ""
41
+ };
42
+ }
43
+ }));
44
+
45
+ //#endregion
46
+ export { ruleConfig };
@@ -0,0 +1,14 @@
1
+ import { boolean } from "../../../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js";
2
+ import { ruleConfig } from "../../rule-creator.js";
3
+
4
+ //#region ../../internal/linter/rules/explicit-anys/config.ts
5
+ const rule = ruleConfig({
6
+ dirname: import.meta.dirname,
7
+ options: {
8
+ fixToUnknown: boolean().default(false).describe("Whether to enable auto-fixing in which the `any` type is converted to the `unknown` type."),
9
+ ignoreRestArgs: boolean().default(false).describe("Whether to ignore rest parameter arrays.")
10
+ }
11
+ });
12
+
13
+ //#endregion
14
+ export { rule };