vue-go-tsc 0.1.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/README.md +3 -1
- package/bin/vue-go-tsc +63 -15
- package/bin/vue-go-tsc.test.js +39 -0
- package/install.js +44 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,10 +41,12 @@ See the full [CI integration guide](https://github.com/aidalinfo/vue-tsgo/blob/m
|
|
|
41
41
|
|
|
42
42
|
## Why vue-go-tsc?
|
|
43
43
|
|
|
44
|
-
-
|
|
44
|
+
- **~5–25× faster** than vue-tsc (project-dependent) — e.g. on the Pulse ERP
|
|
45
|
+
monorepo: app ~232s → **~49s** (~4.7×), docs site ~28s → **~1.5s** (~18×)
|
|
45
46
|
- **Lower memory usage** — native Go instead of Node.js
|
|
46
47
|
- **Drop-in replacement** for vue-tsc
|
|
47
48
|
- **Zero `.vue` file error delta** with vue-tsc on real-world projects
|
|
49
|
+
(verified 4 = 4 on Pulse ERP, 0 = 0 on its docs site)
|
|
48
50
|
|
|
49
51
|
## Documentation
|
|
50
52
|
|
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
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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/install.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { existsSync, mkdirSync, chmodSync } = require('fs');
|
|
3
|
+
const { existsSync, mkdirSync, chmodSync, copyFileSync } = require('fs');
|
|
4
4
|
const { join } = require('path');
|
|
5
|
+
const os = require('os');
|
|
5
6
|
const https = require('https');
|
|
6
7
|
const { createWriteStream } = require('fs');
|
|
7
8
|
|
|
@@ -10,6 +11,12 @@ const BINARY_NAME = process.platform === 'win32' ? 'tsgo.exe' : 'tsgo';
|
|
|
10
11
|
const BIN_DIR = join(__dirname, 'bin');
|
|
11
12
|
const BIN_PATH = join(BIN_DIR, BINARY_NAME);
|
|
12
13
|
|
|
14
|
+
// Shared on-disk cache keyed by version + platform asset name. Lets CI restore
|
|
15
|
+
// the binary across runs (cache ~/.cache/vue-go-tsc) and avoids re-downloading
|
|
16
|
+
// on local reinstalls. Override the location with VUE_GO_TSC_CACHE_DIR.
|
|
17
|
+
const CACHE_ROOT = process.env.VUE_GO_TSC_CACHE_DIR || join(os.homedir(), '.cache', 'vue-go-tsc');
|
|
18
|
+
const CACHE_DIR = join(CACHE_ROOT, `v${PACKAGE_VERSION}`);
|
|
19
|
+
|
|
13
20
|
// Platform mapping for GitHub releases
|
|
14
21
|
const PLATFORM_MAP = {
|
|
15
22
|
'darwin-x64': 'tsgo-darwin-amd64',
|
|
@@ -60,6 +67,13 @@ function download(url, dest) {
|
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
|
|
70
|
+
function finalizeBinary() {
|
|
71
|
+
// Make executable (Unix-like systems)
|
|
72
|
+
if (process.platform !== 'win32') {
|
|
73
|
+
chmodSync(BIN_PATH, 0o755);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
63
77
|
async function install() {
|
|
64
78
|
try {
|
|
65
79
|
// Check if binary already exists (useful for development)
|
|
@@ -68,24 +82,41 @@ async function install() {
|
|
|
68
82
|
return;
|
|
69
83
|
}
|
|
70
84
|
|
|
71
|
-
console.log('Installing vue-go-tsc...');
|
|
72
|
-
|
|
73
|
-
const platformBinary = getPlatformBinary();
|
|
74
|
-
const downloadUrl = `https://github.com/aidalinfo/vue-tsgo/releases/download/v${PACKAGE_VERSION}/${platformBinary}`;
|
|
75
|
-
|
|
76
|
-
console.log(`Downloading from: ${downloadUrl}`);
|
|
77
|
-
|
|
78
|
-
// Ensure bin directory exists
|
|
79
85
|
if (!existsSync(BIN_DIR)) {
|
|
80
86
|
mkdirSync(BIN_DIR, { recursive: true });
|
|
81
87
|
}
|
|
82
88
|
|
|
83
|
-
|
|
89
|
+
const platformBinary = getPlatformBinary();
|
|
90
|
+
const cachedBinary = join(CACHE_DIR, platformBinary);
|
|
91
|
+
|
|
92
|
+
// 1) Serve from the shared cache when present (best-effort — a cache miss or
|
|
93
|
+
// error just falls through to the download below).
|
|
94
|
+
try {
|
|
95
|
+
if (existsSync(cachedBinary)) {
|
|
96
|
+
copyFileSync(cachedBinary, BIN_PATH);
|
|
97
|
+
finalizeBinary();
|
|
98
|
+
console.log(`✓ vue-go-tsc restored from cache (${cachedBinary})`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
// ignore — download is the source of truth
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 2) Download from the GitHub Release for this version.
|
|
106
|
+
const downloadUrl = `https://github.com/aidalinfo/vue-tsgo/releases/download/v${PACKAGE_VERSION}/${platformBinary}`;
|
|
107
|
+
console.log('Installing vue-go-tsc...');
|
|
108
|
+
console.log(`Downloading from: ${downloadUrl}`);
|
|
84
109
|
await download(downloadUrl, BIN_PATH);
|
|
110
|
+
finalizeBinary();
|
|
85
111
|
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
|
|
112
|
+
// 3) Populate the cache for next time (never fail the install on this).
|
|
113
|
+
try {
|
|
114
|
+
if (!existsSync(CACHE_DIR)) {
|
|
115
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
116
|
+
}
|
|
117
|
+
copyFileSync(BIN_PATH, cachedBinary);
|
|
118
|
+
} catch {
|
|
119
|
+
// cache is an optimization only
|
|
89
120
|
}
|
|
90
121
|
|
|
91
122
|
console.log('✓ vue-go-tsc installed successfully!');
|