@gjsify/tsc 0.4.34 → 0.4.36
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 +19 -1
- package/dist/tsc.gjs.mjs +67 -67
- package/package.json +15 -5
- package/src/index.gjs.spec.ts +111 -0
- package/src/index.ts +8 -1
- package/src/test.mts +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/tsc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.36",
|
|
4
4
|
"description": "TypeScript compiler for GJS — bundles upstream `typescript` to a single GJS module + ships a Node-free `tsc` bin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -27,7 +27,10 @@
|
|
|
27
27
|
"clear": "rm -rf dist tsconfig.tsbuildinfo || exit 0",
|
|
28
28
|
"check": "tsc --noEmit",
|
|
29
29
|
"build": "node scripts/build-bundle.mjs",
|
|
30
|
-
"build:gjsify": "node scripts/build-bundle.mjs"
|
|
30
|
+
"build:gjsify": "node scripts/build-bundle.mjs",
|
|
31
|
+
"build:test:gjs": "gjsify build src/test.mts --app gjs --outfile dist/test.gjs.mjs",
|
|
32
|
+
"test": "gjsify run build:test:gjs && gjsify run test:gjs",
|
|
33
|
+
"test:gjs": "gjs -m dist/test.gjs.mjs"
|
|
31
34
|
},
|
|
32
35
|
"keywords": [
|
|
33
36
|
"gjs",
|
|
@@ -46,9 +49,16 @@
|
|
|
46
49
|
},
|
|
47
50
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/tsc#readme",
|
|
48
51
|
"license": "MIT",
|
|
49
|
-
"dependencies": {
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@gjsify/console": "^0.4.36",
|
|
54
|
+
"@gjsify/node-globals": "^0.4.36",
|
|
55
|
+
"@gjsify/web-globals": "^0.4.36"
|
|
56
|
+
},
|
|
50
57
|
"devDependencies": {
|
|
51
|
-
"@gjsify/cli": "
|
|
52
|
-
"
|
|
58
|
+
"@gjsify/cli": "^0.4.36",
|
|
59
|
+
"@gjsify/unit": "^0.4.36",
|
|
60
|
+
"@girs/gio-2.0": "2.88.0-4.0.4",
|
|
61
|
+
"@girs/glib-2.0": "2.88.0-4.0.4",
|
|
62
|
+
"typescript": "^5.9.3"
|
|
53
63
|
}
|
|
54
64
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// GJS-only smoke tests for the committed @gjsify/tsc bundle (dist/tsc.gjs.mjs).
|
|
2
|
+
//
|
|
3
|
+
// The bundle is the actual artifact consumers reach for (via `gjsify-tsc`
|
|
4
|
+
// or the `./bundle` subpath). We exercise it end-to-end through a child
|
|
5
|
+
// `gjs -m <bundle> …` subprocess so the test mirrors how downstream
|
|
6
|
+
// integrations invoke it — `--version` and `-p <tsconfig>` against both a
|
|
7
|
+
// clean project (exit 0) and a buggy one (exit 2 + TS2322 diagnostic).
|
|
8
|
+
//
|
|
9
|
+
// .gjs.spec.ts because the bundle is a GJS executable; there is no Node
|
|
10
|
+
// target for `@gjsify/tsc` (the runtime triplet is
|
|
11
|
+
// `{gjs: "polyfill", node: "none", browser: "none"}`).
|
|
12
|
+
|
|
13
|
+
import { describe, it, expect, on } from '@gjsify/unit';
|
|
14
|
+
import Gio from 'gi://Gio?version=2.0';
|
|
15
|
+
import GLib from 'gi://GLib?version=2.0';
|
|
16
|
+
import { TSC_BUNDLE_PATH, TYPESCRIPT_VERSION } from './index.ts';
|
|
17
|
+
|
|
18
|
+
/** Run the committed bundle as `gjs -m <bundle> <args>` and capture stdio. */
|
|
19
|
+
function runTsc(args: string[]): { stdout: string; stderr: string; status: number } {
|
|
20
|
+
const proc = Gio.Subprocess.new(
|
|
21
|
+
['gjs', '-m', TSC_BUNDLE_PATH, ...args],
|
|
22
|
+
Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE,
|
|
23
|
+
);
|
|
24
|
+
const [, stdout, stderr] = proc.communicate_utf8(null, null);
|
|
25
|
+
return {
|
|
26
|
+
stdout: stdout ?? '',
|
|
27
|
+
stderr: stderr ?? '',
|
|
28
|
+
status: proc.get_exit_status(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Create a throwaway tsconfig + source-file fixture, return its absolute path. */
|
|
33
|
+
function makeProject(filename: string, source: string): string {
|
|
34
|
+
const tmp = GLib.dir_make_tmp('gjsify-tsc-spec-XXXXXX');
|
|
35
|
+
if (!tmp) {
|
|
36
|
+
throw new Error('GLib.dir_make_tmp returned null');
|
|
37
|
+
}
|
|
38
|
+
const tsconfig = JSON.stringify({
|
|
39
|
+
compilerOptions: {
|
|
40
|
+
noEmit: true,
|
|
41
|
+
strict: true,
|
|
42
|
+
target: 'ES2020',
|
|
43
|
+
module: 'ESNext',
|
|
44
|
+
moduleResolution: 'bundler',
|
|
45
|
+
},
|
|
46
|
+
include: ['*.ts'],
|
|
47
|
+
});
|
|
48
|
+
GLib.file_set_contents(`${tmp}/tsconfig.json`, tsconfig);
|
|
49
|
+
GLib.file_set_contents(`${tmp}/${filename}`, source);
|
|
50
|
+
return tmp;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Recursive rmdir for the fixture; failure to clean up should not break the test. */
|
|
54
|
+
function cleanupProject(dir: string): void {
|
|
55
|
+
try {
|
|
56
|
+
const file = Gio.File.new_for_path(dir);
|
|
57
|
+
const enumerator = file.enumerate_children(
|
|
58
|
+
'standard::name',
|
|
59
|
+
Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
|
|
60
|
+
null,
|
|
61
|
+
);
|
|
62
|
+
for (
|
|
63
|
+
let info = enumerator.next_file(null);
|
|
64
|
+
info !== null;
|
|
65
|
+
info = enumerator.next_file(null)
|
|
66
|
+
) {
|
|
67
|
+
file.get_child(info.get_name()).delete(null);
|
|
68
|
+
}
|
|
69
|
+
enumerator.close(null);
|
|
70
|
+
file.delete(null);
|
|
71
|
+
} catch {
|
|
72
|
+
// Best-effort cleanup; the OS will eventually reap /tmp.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default async () => {
|
|
77
|
+
await on('Gjs', async () => {
|
|
78
|
+
await describe('@gjsify/tsc bundle (dist/tsc.gjs.mjs) — smoke tests', async () => {
|
|
79
|
+
await it('--version returns the pinned TYPESCRIPT_VERSION', async () => {
|
|
80
|
+
const { stdout, status } = runTsc(['--version']);
|
|
81
|
+
expect(status).toBe(0);
|
|
82
|
+
expect(stdout.trim()).toBe(`Version ${TYPESCRIPT_VERSION}`);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await it('-p on a clean project exits 0 with no diagnostics on stdout', async () => {
|
|
86
|
+
const tmp = makeProject('ok.ts', 'const x: number = 42;\nconsole.log(x);\n');
|
|
87
|
+
try {
|
|
88
|
+
const { stdout, status } = runTsc(['-p', tmp]);
|
|
89
|
+
expect(status).toBe(0);
|
|
90
|
+
// tsc only emits diagnostics-style lines on failure; a clean run is silent.
|
|
91
|
+
expect(stdout.includes('error TS')).toBe(false);
|
|
92
|
+
} finally {
|
|
93
|
+
cleanupProject(tmp);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await it('-p on a buggy project exits 2 with a TS2322 diagnostic', async () => {
|
|
98
|
+
const tmp = makeProject('bad.ts', 'const x: number = "string";\n');
|
|
99
|
+
try {
|
|
100
|
+
const { stdout, status } = runTsc(['-p', tmp]);
|
|
101
|
+
// tsc exits 2 when type errors are found (1 = bad CLI args).
|
|
102
|
+
expect(status).toBe(2);
|
|
103
|
+
expect(stdout).toContain('TS2322');
|
|
104
|
+
expect(stdout).toContain('bad.ts');
|
|
105
|
+
} finally {
|
|
106
|
+
cleanupProject(tmp);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -25,5 +25,12 @@ export const TSC_BUNDLE_PATH: string = resolve(
|
|
|
25
25
|
'tsc.gjs.mjs',
|
|
26
26
|
);
|
|
27
27
|
|
|
28
|
-
/** Pinned upstream TypeScript version the shipped bundle was built from.
|
|
28
|
+
/** Pinned upstream TypeScript version the shipped bundle was built from.
|
|
29
|
+
*
|
|
30
|
+
* NOTE: this is the version actually bundled into `dist/tsc.gjs.mjs`, which
|
|
31
|
+
* may lag the declared `typescript` devDep range when `gjsify install`
|
|
32
|
+
* resolves to an older satisfying version (the typescript@5.9.x and 6.0.x
|
|
33
|
+
* ranges currently coexist in the workspace; the install resolves to the
|
|
34
|
+
* highest version that satisfies every declared range — 5.9.3 today).
|
|
35
|
+
*/
|
|
29
36
|
export const TYPESCRIPT_VERSION = '5.9.3' as const;
|
package/src/test.mts
ADDED