@devscholar/node-with-gjs 0.0.0 → 0.0.2
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 +5 -75
- package/__tests__/basic.test.ts +41 -0
- package/__tests__/glib.test.ts +72 -0
- package/__tests__/gtk4.test.ts +73 -0
- package/dist/index.js +211 -0
- package/dist/ipc.js +103 -0
- package/docs/testing.md +100 -0
- package/hook.js +44 -42
- package/jest.config.js +32 -0
- package/package.json +23 -14
- package/scripts/host.js +3 -1
- package/src/index.ts +40 -2
- package/tsconfig.json +22 -11
- package/types/index.d.ts +4 -0
- package/types/ipc.d.ts +10 -0
- package/examples/adwaita/counter/counter.ts +0 -66
- package/examples/console/await-delay/await-delay.ts +0 -11
- package/examples/console/console-input/console-input.ts +0 -27
- package/examples/gtk/counter/counter.ts +0 -62
- package/examples/gtk/drag-box/drag-box.ts +0 -77
- package/examples/gtk-webkit/counter/counter.html +0 -47
- package/examples/gtk-webkit/counter/counter.ts +0 -101
- package/gi-loader.ts +0 -13
- package/start.js +0 -105
package/gi-loader.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// gi-loader.ts
|
|
2
|
-
// Universal GI namespace loader for Node.js, Bun, and Deno
|
|
3
|
-
// Usage:
|
|
4
|
-
// import { loadGi } from './gi-loader.ts';
|
|
5
|
-
// const Gtk = loadGi('Gtk', '4.0');
|
|
6
|
-
|
|
7
|
-
import { init, loadGiNamespace } from './src/index.ts';
|
|
8
|
-
|
|
9
|
-
init();
|
|
10
|
-
|
|
11
|
-
export function loadGi(namespace: string, version: string = '') {
|
|
12
|
-
return loadGiNamespace(namespace, version);
|
|
13
|
-
}
|
package/start.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// start.js
|
|
2
|
-
import { spawn } from 'child_process';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath } from 'url';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
const args = process.argv.slice(2);
|
|
9
|
-
|
|
10
|
-
if (args.length === 0) {
|
|
11
|
-
console.error('Usage: node start.js <script.ts> [--runtime=node|bun|deno]');
|
|
12
|
-
console.error(' bun start.js <script.ts> [--runtime=node|bun|deno]');
|
|
13
|
-
console.error(' deno run start.js <script.ts> [--runtime=node|bun|deno]');
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
let runtime = null;
|
|
18
|
-
let targetScript = null;
|
|
19
|
-
|
|
20
|
-
for (let i = 0; i < args.length; i++) {
|
|
21
|
-
if (args[i] === '--runtime' && args[i + 1]) {
|
|
22
|
-
runtime = args[i + 1].toLowerCase();
|
|
23
|
-
i++;
|
|
24
|
-
} else if (!args[i].startsWith('--')) {
|
|
25
|
-
targetScript = args[i];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!targetScript) {
|
|
30
|
-
console.error('Error: No script specified');
|
|
31
|
-
process.exit(1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
targetScript = path.resolve(targetScript);
|
|
35
|
-
const hookUrl = new URL('./hook.js', import.meta.url).href;
|
|
36
|
-
|
|
37
|
-
if (!runtime) {
|
|
38
|
-
runtime = detectRuntime();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const validRuntimes = ['node', 'bun', 'deno'];
|
|
42
|
-
if (!validRuntimes.includes(runtime)) {
|
|
43
|
-
console.error(`Error: Invalid runtime "${runtime}". Must be one of: ${validRuntimes.join(', ')}`);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
console.log(`Starting ${runtime.charAt(0).toUpperCase() + runtime.slice(1)}-GJS execution context...`);
|
|
48
|
-
|
|
49
|
-
let proc;
|
|
50
|
-
|
|
51
|
-
switch (runtime) {
|
|
52
|
-
case 'bun':
|
|
53
|
-
proc = spawnBun(targetScript);
|
|
54
|
-
break;
|
|
55
|
-
case 'deno':
|
|
56
|
-
proc = spawnDeno(targetScript);
|
|
57
|
-
break;
|
|
58
|
-
case 'node':
|
|
59
|
-
default:
|
|
60
|
-
proc = spawnNode(targetScript, hookUrl);
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
proc.on('exit', (code) => {
|
|
65
|
-
process.exit(code || 0);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
function detectRuntime() {
|
|
69
|
-
if (typeof Bun !== 'undefined') return 'bun';
|
|
70
|
-
if (typeof Deno !== 'undefined') return 'deno';
|
|
71
|
-
return 'node';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function spawnNode(targetScript, hookUrl) {
|
|
75
|
-
return spawn(process.execPath, [
|
|
76
|
-
'--no-warnings',
|
|
77
|
-
'--experimental-loader', hookUrl,
|
|
78
|
-
'--experimental-transform-types',
|
|
79
|
-
targetScript
|
|
80
|
-
], {
|
|
81
|
-
stdio: 'inherit',
|
|
82
|
-
env: process.env
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function spawnBun(targetScript) {
|
|
87
|
-
return spawn('bun', [
|
|
88
|
-
'run',
|
|
89
|
-
targetScript
|
|
90
|
-
], {
|
|
91
|
-
stdio: 'inherit',
|
|
92
|
-
env: process.env
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function spawnDeno(targetScript) {
|
|
97
|
-
return spawn('deno', [
|
|
98
|
-
'run',
|
|
99
|
-
'--allow-all',
|
|
100
|
-
targetScript
|
|
101
|
-
], {
|
|
102
|
-
stdio: 'inherit',
|
|
103
|
-
env: process.env
|
|
104
|
-
});
|
|
105
|
-
}
|