golar 0.1.2 → 0.1.4-beta.1

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/dist/addon.js CHANGED
@@ -1,16 +1,33 @@
1
1
  import process from "node:process";
2
2
  import os from "node:os";
3
- import worker_threads from "node:worker_threads";
4
3
  import url from "node:url";
4
+ import worker_threads from "node:worker_threads";
5
+ import { GLIBC, MUSL, family } from "detect-libc";
5
6
 
6
7
  //#region src/addon.ts
7
8
  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);
9
+ let addonPackageName = `@golar/${process.platform}-${process.arch}`;
10
+ let _isMusl = false;
11
+ if (process.platform === "linux") switch (await family()) {
12
+ case GLIBC: break;
13
+ case MUSL:
14
+ addonPackageName = `@golar/${process.platform}-${process.arch}-musl`;
15
+ _isMusl = true;
16
+ break;
17
+ default: throw new Error("Unknown Linux libc family");
18
+ }
19
+ const isMusl = _isMusl;
20
+ const golarAddonPath = url.fileURLToPath(import.meta.resolve(`${addonPackageName}/golar.node`));
21
+ let addonLoaded = false;
22
+ function loadAddon() {
23
+ if (addonLoaded) return;
24
+ addonLoaded = true;
25
+ process.dlopen(addonModule, golarAddonPath, os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
26
+ addon.setSyncBuffer(worker_threads.threadId, syncBuf);
27
+ }
10
28
  const { exports: addon } = addonModule;
11
29
  const syncBuf = /* @__PURE__ */ new ArrayBuffer(10 * 1024 * 1024);
12
30
  const syncView = new DataView(syncBuf);
13
- addon.setSyncBuffer(worker_threads.threadId, syncBuf);
14
31
 
15
32
  //#endregion
16
- export { addon, golarAddonPath, syncBuf, syncView };
33
+ export { addon, golarAddonPath, isMusl, loadAddon, syncBuf, syncView };
package/dist/bin.js CHANGED
@@ -1,134 +1,32 @@
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";
7
- import process from "node:process";
8
- import os from "node:os";
2
+ import { golarAddonPath, isMusl } from "./addon.js";
9
3
  import path from "node:path";
10
- import assert from "node:assert/strict";
11
- import worker_threads from "node:worker_threads";
12
- import fs from "node:fs";
4
+ import process from "node:process";
5
+ import child_process from "node:child_process";
13
6
 
14
7
  //#region src/bin.ts
15
- const argv = process.argv.slice(2);
16
- const cwd = process.cwd();
17
- let 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)) try {
38
- configPath = await Promise.any([
39
- "golar.config.mts",
40
- "golar.config.mjs",
41
- "golar.config.cts",
42
- "golar.config.cjs",
43
- "golar.config.js"
44
- ].map((p) => fs.promises.stat(p).then(() => path.join(cwd, p))));
45
- } catch {
46
- console.log(`${styleText("red", "Error:")} ./golar.config.ts not found`);
47
- process.exit(1);
48
- }
49
- console.log(`${styleText("dim", "Using config from")} ./${path.basename(configPath)}${styleText("dim", "...")}`);
50
- const config = await loadConfig(configPath);
51
- const hasJsCodegenPlugins = globalState.codegenPlugins.values().some((v) => v instanceof JsCodegenPlugin);
52
- const selfExtname = path.extname(import.meta.filename);
53
- const workerPath = path.join(import.meta.dirname, `worker${selfExtname}`);
54
- const textEncoder = new TextEncoder();
55
- if (argv[0] === "tsc") {
56
- for (const plugin of globalState.codegenPlugins.values()) plugin.register();
57
- const args = argv.slice(1);
58
- let offset = 0;
59
- syncView.setUint32(offset, args.length, true);
60
- offset += 4;
61
- for (const arg of args) {
62
- const { written: argLen } = textEncoder.encodeInto(arg, new Uint8Array(syncBuf, offset + 4));
63
- syncView.setUint32(offset, argLen, true);
64
- offset += 4 + argLen;
65
- }
66
- addon.tsc(worker_threads.threadId, (exitCode) => process.exit(exitCode));
67
- if (hasJsCodegenPlugins) {
68
- worker_threads.setEnvironmentData("golar-env", {
69
- configPath,
70
- cwd,
71
- mode: "codegen-only"
8
+ if (isMusl) {
9
+ const selfExtname = path.extname(import.meta.filename);
10
+ const cliPath = path.join(import.meta.dirname, `cli${selfExtname}`);
11
+ const env = {
12
+ ...process.env,
13
+ LD_PRELOAD: golarAddonPath + ((process.env.LD_PRELOAD?.length ?? 0) > 0 ? ` ${process.env.LD_PRELOAD}` : "")
14
+ };
15
+ process.execve?.(process.execPath, [
16
+ process.execPath,
17
+ cliPath,
18
+ ...process.argv.slice(2)
19
+ ], env);
20
+ try {
21
+ child_process.execFileSync(process.execPath, [cliPath, ...process.argv.slice(2)], {
22
+ stdio: "inherit",
23
+ env
72
24
  });
73
- const workersCount = Math.floor(Math.max(Math.min(os.availableParallelism() / 2, 4), 1)) - 1;
74
- const promises = [];
75
- for (let i = 0; i < workersCount; i++) {
76
- const w = new worker_threads.Worker(workerPath);
77
- promises.push(new Promise((resolve) => w.once("message", resolve)));
78
- }
79
- await Promise.all(promises);
80
- }
81
- } else {
82
- const lintOnly = argv[0] === "lint";
83
- const typecheckOnly = argv[0] === "typecheck";
84
- if (!lintOnly && !typecheckOnly && [
85
- "--noEmit",
86
- "-b",
87
- "--build",
88
- "--declaration",
89
- "--emitDeclarationOnly"
90
- ].some((flag) => argv.includes(flag))) {
91
- let message = `${styleText("red", "Error:")} Golar v0.1+ doesn't support passing tsc flags to the root subcommand.\n`;
92
- if (argv.includes("--declaration") || argv.includes("--emitDeclarationOnly")) message += `Instead, run: ${styleText("bold", `golar ${styleText("green", "tsc")} ${argv.join(" ")}`)}`;
93
- else message += `Instead, run ${styleText("bold", "golar")} without any arguments.`;
94
- console.log(message);
95
- process.exit(1);
96
- }
97
- for (const plugin of globalState.codegenPlugins.values()) plugin.register();
98
- const { files, builtinRulesByFile, nativeRulesByFile, jsFilesByWorker, jsRulesByFile, typecheckFiles } = resolveConfig(cwd, config);
99
- const { meta, workspace: wsPromise } = await Workspace.create(cwd, files);
100
- const ws = await wsPromise;
101
- if (!typecheckOnly) {
102
- ws.lintBuiltin(builtinRulesByFile);
103
- ws.lintNative(nativeRulesByFile, path.dirname(configPath));
104
- const promises = [];
105
- if (jsRulesByFile.size > 0) {
106
- worker_threads.setEnvironmentData("golar-env", {
107
- configPath,
108
- cwd,
109
- mode: "lint"
110
- });
111
- jsFilesByWorker.slice(0, -1).map((workerFiles) => {
112
- const worker = new worker_threads.Worker(workerPath);
113
- promises.push(new Promise((resolve) => worker.once("message", resolve)));
114
- worker.postMessage({
115
- meta,
116
- jsFiles: workerFiles
117
- });
118
- return worker;
119
- });
120
- }
121
- if (jsRulesByFile.size > 0) {
122
- const mainJsFiles = jsFilesByWorker.at(-1);
123
- assert.ok(mainJsFiles);
124
- ws.preloadRequestedFiles(mainJsFiles);
125
- ws.lintJs(new Map(mainJsFiles.map((file) => [file, Array.from(jsRulesByFile.get(file).values())])));
126
- }
127
- await Promise.all(promises);
25
+ } catch (e) {
26
+ if (e instanceof Error && "status" in e && typeof e.status === "number") process.exit(e.status);
27
+ throw e;
128
28
  }
129
- if (!lintOnly) process.exit(ws.typecheck(typecheckFiles));
130
- process.exit(0);
131
- }
29
+ } else await import("./cli.js");
132
30
 
133
31
  //#endregion
134
32
  export { };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.js ADDED
@@ -0,0 +1,134 @@
1
+ import { addon, loadAddon, syncBuf, syncView } from "./addon.js";
2
+ import { JsCodegenPlugin, globalState } from "./codegen-plugin.js";
3
+ import { loadConfig, resolveConfig } from "./config.js";
4
+ import { Workspace } from "./workspace.js";
5
+ import { styleText } from "./utils.js";
6
+ import path from "node:path";
7
+ import process from "node:process";
8
+ import os from "node:os";
9
+ import worker_threads from "node:worker_threads";
10
+ import assert from "node:assert/strict";
11
+ import fs from "node:fs";
12
+
13
+ //#region src/cli.ts
14
+ const argv = process.argv.slice(2);
15
+ const cwd = process.cwd();
16
+ let configPath = path.join(cwd, "golar.config.ts");
17
+ if (argv[0] === "--help") {
18
+ console.log(`
19
+ Usage: golar [command]
20
+
21
+ Commands:
22
+ golar Lint and typecheck the current workspace (recommended)
23
+ golar lint Run lint checks only
24
+ golar typecheck Run typechecking only
25
+ golar tsc [tsc args...] Forward arguments to TypeScript CLI
26
+
27
+ Options:
28
+ --help Show this help message
29
+ --version Print Golar version`);
30
+ process.exit(0);
31
+ } else if (argv[0] === "--version") {
32
+ const { default: { version } } = await import("../package.json", { with: { type: "json" } });
33
+ console.log(`Golar version ${version}`);
34
+ process.exit(0);
35
+ }
36
+ if (!fs.existsSync(configPath)) try {
37
+ configPath = await Promise.any([
38
+ "golar.config.mts",
39
+ "golar.config.mjs",
40
+ "golar.config.cts",
41
+ "golar.config.cjs",
42
+ "golar.config.js"
43
+ ].map((p) => fs.promises.stat(p).then(() => path.join(cwd, p))));
44
+ } catch {
45
+ console.log(`${styleText("red", "Error:")} ./golar.config.ts not found`);
46
+ process.exit(1);
47
+ }
48
+ console.log(`${styleText("dim", "Using config from")} ./${path.basename(configPath)}${styleText("dim", "...")}`);
49
+ loadAddon();
50
+ const config = await loadConfig(configPath);
51
+ const hasJsCodegenPlugins = globalState.codegenPlugins.values().some((v) => v instanceof JsCodegenPlugin);
52
+ const selfExtname = path.extname(import.meta.filename);
53
+ const workerPath = path.join(import.meta.dirname, `worker${selfExtname}`);
54
+ const textEncoder = new TextEncoder();
55
+ if (argv[0] === "tsc") {
56
+ for (const plugin of globalState.codegenPlugins.values()) plugin.register();
57
+ const args = argv.slice(1);
58
+ let offset = 0;
59
+ syncView.setUint32(offset, args.length, true);
60
+ offset += 4;
61
+ for (const arg of args) {
62
+ const { written: argLen } = textEncoder.encodeInto(arg, new Uint8Array(syncBuf, offset + 4));
63
+ syncView.setUint32(offset, argLen, true);
64
+ offset += 4 + argLen;
65
+ }
66
+ addon.tsc(worker_threads.threadId, (exitCode) => process.exit(exitCode));
67
+ if (hasJsCodegenPlugins) {
68
+ worker_threads.setEnvironmentData("golar-env", {
69
+ configPath,
70
+ cwd,
71
+ mode: "codegen-only"
72
+ });
73
+ const workersCount = Math.floor(Math.max(Math.min(os.availableParallelism() / 2, 4), 1)) - 1;
74
+ const promises = [];
75
+ for (let i = 0; i < workersCount; i++) {
76
+ const w = new worker_threads.Worker(workerPath);
77
+ promises.push(new Promise((resolve) => w.once("message", resolve)));
78
+ }
79
+ await Promise.all(promises);
80
+ }
81
+ } else {
82
+ const lintOnly = argv[0] === "lint";
83
+ const typecheckOnly = argv[0] === "typecheck";
84
+ if (!lintOnly && !typecheckOnly && [
85
+ "--noEmit",
86
+ "-b",
87
+ "--build",
88
+ "--declaration",
89
+ "--emitDeclarationOnly"
90
+ ].some((flag) => argv.includes(flag))) {
91
+ let message = `${styleText("red", "Error:")} Golar v0.1+ doesn't support passing tsc flags to the root subcommand.\n`;
92
+ if (argv.includes("--declaration") || argv.includes("--emitDeclarationOnly")) message += `Instead, run: ${styleText("bold", `golar ${styleText("green", "tsc")} ${argv.join(" ")}`)}`;
93
+ else message += `Instead, run ${styleText("bold", "golar")} without any arguments.`;
94
+ console.log(message);
95
+ process.exit(1);
96
+ }
97
+ for (const plugin of globalState.codegenPlugins.values()) plugin.register();
98
+ const { files, builtinRulesByFile, nativeRulesByFile, jsFilesByWorker, jsRulesByFile, typecheckFiles } = resolveConfig(cwd, config);
99
+ const { meta, workspace: wsPromise } = await Workspace.create(cwd, files);
100
+ const ws = await wsPromise;
101
+ if (!typecheckOnly) {
102
+ ws.lintBuiltin(builtinRulesByFile);
103
+ ws.lintNative(nativeRulesByFile, path.dirname(configPath));
104
+ const promises = [];
105
+ if (jsRulesByFile.size > 0) {
106
+ worker_threads.setEnvironmentData("golar-env", {
107
+ configPath,
108
+ cwd,
109
+ mode: "lint"
110
+ });
111
+ jsFilesByWorker.slice(0, -1).map((workerFiles) => {
112
+ const worker = new worker_threads.Worker(workerPath);
113
+ promises.push(new Promise((resolve) => worker.once("message", resolve)));
114
+ worker.postMessage({
115
+ meta,
116
+ jsFiles: workerFiles
117
+ });
118
+ return worker;
119
+ });
120
+ }
121
+ if (jsRulesByFile.size > 0) {
122
+ const mainJsFiles = jsFilesByWorker.at(-1);
123
+ assert.ok(mainJsFiles);
124
+ ws.preloadRequestedFiles(mainJsFiles);
125
+ ws.lintJs(new Map(mainJsFiles.map((file) => [file, Array.from(jsRulesByFile.get(file).values())])));
126
+ }
127
+ await Promise.all(promises);
128
+ }
129
+ if (!lintOnly) process.exit(ws.typecheck(typecheckFiles));
130
+ process.exit(0);
131
+ }
132
+
133
+ //#endregion
134
+ export { };
@@ -1,4 +1,4 @@
1
- import { addon, syncBuf, syncView } from "./addon.js";
1
+ import { addon, loadAddon, syncBuf, syncView } from "./addon.js";
2
2
  import os from "node:os";
3
3
  import worker_threads from "node:worker_threads";
4
4
 
@@ -43,6 +43,7 @@ var JsCodegenPlugin = class JsCodegenPlugin {
43
43
  const { written: initializationLen } = textEncoder.encodeInto(JSON.stringify({ extensions: this.extensions }), new Uint8Array(syncBuf, offset + 4));
44
44
  syncView.setUint32(offset, initializationLen, true);
45
45
  offset += 4 + initializationLen;
46
+ loadAddon();
46
47
  addon.registerJsCodegen(worker_threads.threadId, () => this.executeCreateServiceCode());
47
48
  }
48
49
  async executeCreateServiceCode() {
@@ -172,6 +173,7 @@ var IpcCodegenPlugin = class {
172
173
  extensions: this.extensions
173
174
  }), new Uint8Array(syncBuf, 4));
174
175
  syncView.setUint32(0, initializationLen, true);
176
+ loadAddon();
175
177
  addon.registerIpcCodegen();
176
178
  }
177
179
  };
package/dist/config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { globalState } from "./codegen-plugin.js";
2
2
  import path from "node:path";
3
- import fs from "node:fs";
4
3
  import url from "node:url";
4
+ import fs from "node:fs";
5
5
  import util from "node:util";
6
6
  import { Debug } from "@golar/util";
7
7
 
@@ -1,7 +1,7 @@
1
1
  //#region package.json
2
2
  var package_default = {
3
3
  name: "golar",
4
- version: "0.1.2",
4
+ version: "0.1.4-beta.1",
5
5
  type: "module",
6
6
  bin: "./src/bin.ts",
7
7
  exports: {
@@ -27,13 +27,18 @@ var package_default = {
27
27
  },
28
28
  "executableFiles": ["./dist/bin.js"]
29
29
  },
30
- dependencies: { "@golar/util": "workspace:*" },
30
+ dependencies: {
31
+ "@golar/util": "workspace:*",
32
+ "detect-libc": "^2.1.2"
33
+ },
31
34
  optionalDependencies: {
32
- "@golar/win32-x64": "workspace:*",
33
- "@golar/linux-x64": "workspace:*",
34
- "@golar/linux-arm64": "workspace:*",
35
+ "@golar/darwin-arm64": "workspace:*",
35
36
  "@golar/darwin-x64": "workspace:*",
36
- "@golar/darwin-arm64": "workspace:*"
37
+ "@golar/linux-arm64": "workspace:*",
38
+ "@golar/linux-arm64-musl": "workspace:*",
39
+ "@golar/linux-x64": "workspace:*",
40
+ "@golar/linux-x64-musl": "workspace:*",
41
+ "@golar/win32-x64": "workspace:*"
37
42
  }
38
43
  };
39
44
 
package/dist/worker.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { JsCodegenPlugin, globalState } from "./codegen-plugin.js";
2
2
  import { loadConfig, resolveConfig } from "./config.js";
3
3
  import { Workspace } from "./workspace.js";
4
- import assert from "node:assert/strict";
5
4
  import worker_threads from "node:worker_threads";
5
+ import assert from "node:assert/strict";
6
6
 
7
7
  //#region src/worker.ts
8
8
  const { parentPort } = worker_threads;
package/dist/workspace.js CHANGED
@@ -2,11 +2,11 @@ import { addon, golarAddonPath, syncBuf, syncView } from "./addon.js";
2
2
  import { RemoteSourceFile } from "./thirdparty/typescript-go/_packages/api/dist/node/node.js";
3
3
  import { Registry } from "./type-decoder.js";
4
4
  import { object } from "./node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js";
5
+ import path from "node:path";
5
6
  import process from "node:process";
6
7
  import os from "node:os";
7
- import path from "node:path";
8
- import assert from "node:assert/strict";
9
8
  import worker_threads from "node:worker_threads";
9
+ import assert from "node:assert/strict";
10
10
 
11
11
  //#region src/workspace.ts
12
12
  const textDecoder = new TextDecoder();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "golar",
3
- "version": "0.1.2",
3
+ "version": "0.1.4-beta.1",
4
4
  "type": "module",
5
5
  "bin": "./dist/bin.js",
6
6
  "exports": {
@@ -26,13 +26,16 @@
26
26
  ]
27
27
  },
28
28
  "dependencies": {
29
- "@golar/util": "0.1.2"
29
+ "detect-libc": "^2.1.2",
30
+ "@golar/util": "0.1.4-beta.1"
30
31
  },
31
32
  "optionalDependencies": {
32
- "@golar/win32-x64": "0.1.2",
33
- "@golar/linux-x64": "0.1.2",
34
- "@golar/linux-arm64": "0.1.2",
35
- "@golar/darwin-x64": "0.1.2",
36
- "@golar/darwin-arm64": "0.1.2"
33
+ "@golar/darwin-arm64": "0.1.4-beta.1",
34
+ "@golar/darwin-x64": "0.1.4-beta.1",
35
+ "@golar/linux-arm64-musl": "0.1.4-beta.1",
36
+ "@golar/linux-x64": "0.1.4-beta.1",
37
+ "@golar/win32-x64": "0.1.4-beta.1",
38
+ "@golar/linux-x64-musl": "0.1.4-beta.1",
39
+ "@golar/linux-arm64": "0.1.4-beta.1"
37
40
  }
38
41
  }