vue-go-tsc 0.2.0 → 0.2.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/bin/vue-go-tsc CHANGED
@@ -1,15 +1,63 @@
1
- #!/usr/bin/env node
2
-
3
- const { spawnSync } = require('child_process');
4
- const { join } = require('path');
5
-
6
- const BINARY_NAME = process.platform === 'win32' ? 'tsgo.exe' : 'tsgo';
7
- const BIN_PATH = join(__dirname, BINARY_NAME);
8
-
9
- // Forward all arguments to the binary
10
- const result = spawnSync(BIN_PATH, process.argv.slice(2), {
11
- stdio: 'inherit',
12
- shell: false,
13
- });
14
-
15
- process.exit(result.status || 0);
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync } = require('child_process');
4
+ const { join } = require('path');
5
+ const os = require('os');
6
+
7
+ const GiB = 1024 ** 3;
8
+
9
+ // Fraction of total RAM used as the default soft Go heap ceiling. Half of RAM
10
+ // leaves ample headroom for the OS, Node, and any concurrent CI jobs on the
11
+ // same runner, and is reproducible across runs (unlike instantaneous free RAM).
12
+ const DEFAULT_MEM_FRACTION = 0.5;
13
+
14
+ // Compute a soft Go heap ceiling (in bytes) for tsgo based on total RAM.
15
+ //
16
+ // tsgo is the typescript-go native binary; its Go runtime defaults to GOGC=100,
17
+ // which lets the heap roughly double before the GC runs. On a large Nuxt
18
+ // project that transient spike can exceed physical RAM and get the process
19
+ // OOM-killed by the kernel. Setting GOMEMLIMIT makes the GC increasingly
20
+ // aggressive as the heap approaches the limit, trading CPU for staying under
21
+ // the ceiling. It is a *soft* limit — swap absorbs any remaining overshoot
22
+ // instead of a hard kill, and it can be raised via the GOMEMLIMIT env var when
23
+ // a project's live heap genuinely needs more.
24
+ //
25
+ // Returns null when total RAM is unknown/implausible (leave Go's default).
26
+ function computeGoMemLimit(totalBytes) {
27
+ if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
28
+ return null;
29
+ }
30
+ return Math.floor(totalBytes * DEFAULT_MEM_FRACTION);
31
+ }
32
+
33
+ // Return a copy of `env` with GOMEMLIMIT defaulted from total RAM. An explicit
34
+ // GOMEMLIMIT is always respected (never overridden).
35
+ function resolveEnv(env, totalBytes) {
36
+ const out = { ...env };
37
+ if (!out.GOMEMLIMIT) {
38
+ const limit = computeGoMemLimit(totalBytes);
39
+ if (limit) {
40
+ // A bare integer is interpreted by the Go runtime as a byte count.
41
+ out.GOMEMLIMIT = String(limit);
42
+ }
43
+ }
44
+ return out;
45
+ }
46
+
47
+ if (require.main === module) {
48
+ const BINARY_NAME = process.platform === 'win32' ? 'tsgo.exe' : 'tsgo';
49
+ const BIN_PATH = join(__dirname, BINARY_NAME);
50
+
51
+ const env = resolveEnv(process.env, os.totalmem());
52
+
53
+ // Forward all arguments to the binary
54
+ const result = spawnSync(BIN_PATH, process.argv.slice(2), {
55
+ stdio: 'inherit',
56
+ shell: false,
57
+ env,
58
+ });
59
+
60
+ process.exit(result.status || 0);
61
+ }
62
+
63
+ module.exports = { computeGoMemLimit, resolveEnv, GiB, DEFAULT_MEM_FRACTION };
@@ -0,0 +1,39 @@
1
+ // Run with: node --test cli/bin/vue-go-tsc.test.js
2
+ const { test } = require('node:test');
3
+ const assert = require('node:assert');
4
+
5
+ const { computeGoMemLimit, resolveEnv, GiB, DEFAULT_MEM_FRACTION } = require('./vue-go-tsc');
6
+
7
+ test('computeGoMemLimit defaults to half of total RAM', () => {
8
+ const total = 8 * GiB;
9
+ const limit = computeGoMemLimit(total);
10
+ assert.strictEqual(limit, Math.floor(total * DEFAULT_MEM_FRACTION)); // 4GiB
11
+ assert.ok(limit < total, 'limit must stay below physical RAM');
12
+ });
13
+
14
+ test('computeGoMemLimit scales with RAM', () => {
15
+ assert.strictEqual(computeGoMemLimit(16 * GiB), 8 * GiB);
16
+ assert.strictEqual(computeGoMemLimit(4 * GiB), 2 * GiB);
17
+ });
18
+
19
+ test('computeGoMemLimit returns null for unknown/implausible RAM', () => {
20
+ assert.strictEqual(computeGoMemLimit(0), null);
21
+ assert.strictEqual(computeGoMemLimit(-1), null);
22
+ assert.strictEqual(computeGoMemLimit(NaN), null);
23
+ });
24
+
25
+ test('resolveEnv defaults GOMEMLIMIT (in bytes) when unset', () => {
26
+ const env = resolveEnv({ PATH: '/usr/bin' }, 8 * GiB);
27
+ assert.strictEqual(env.GOMEMLIMIT, String(4 * GiB));
28
+ assert.strictEqual(env.PATH, '/usr/bin', 'existing env is preserved');
29
+ });
30
+
31
+ test('resolveEnv never overrides an explicit GOMEMLIMIT', () => {
32
+ const env = resolveEnv({ GOMEMLIMIT: '6GiB' }, 8 * GiB);
33
+ assert.strictEqual(env.GOMEMLIMIT, '6GiB');
34
+ });
35
+
36
+ test('resolveEnv leaves GOMEMLIMIT unset when RAM is unknown', () => {
37
+ const env = resolveEnv({}, 0);
38
+ assert.strictEqual('GOMEMLIMIT' in env, false);
39
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-go-tsc",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Blazingly fast Vue 3 type checker powered by typescript-go — a Go-native alternative to vue-tsc",
5
5
  "keywords": [
6
6
  "vue",