@gjsify/cli 0.1.1 → 0.1.3

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.
@@ -0,0 +1,54 @@
1
+ // Shared utility for running a GJS bundle with native package env vars.
2
+ // Used by both the `run` and `showcase` commands.
3
+
4
+ import { spawn } from 'node:child_process';
5
+ import { resolve } from 'node:path';
6
+ import { detectNativePackages, resolveNativePackages, buildNativeEnv } from './detect-native-packages.js';
7
+
8
+ /**
9
+ * Run a GJS bundle, automatically setting LD_LIBRARY_PATH and GI_TYPELIB_PATH
10
+ * for any installed native gjsify packages.
11
+ *
12
+ * Detection uses two strategies:
13
+ * 1. Filesystem walk from CWD (finds packages in the user's project)
14
+ * 2. require.resolve from the bundle's location (finds packages in the CLI's dependency tree)
15
+ */
16
+ export async function runGjsBundle(bundlePath: string, extraArgs: string[] = []): Promise<void> {
17
+ const cwd = process.cwd();
18
+ const resolvedBundle = resolve(bundlePath);
19
+
20
+ // Detect from CWD (filesystem walk) + bundle location (require.resolve)
21
+ const cwdPackages = detectNativePackages(cwd);
22
+ const bundlePackages = resolveNativePackages(resolvedBundle);
23
+
24
+ // Merge, deduplicating by name (CWD takes precedence)
25
+ const seen = new Set(cwdPackages.map(p => p.name));
26
+ const nativePackages = [
27
+ ...cwdPackages,
28
+ ...bundlePackages.filter(p => !seen.has(p.name)),
29
+ ];
30
+
31
+ const nativeEnv = buildNativeEnv(nativePackages);
32
+
33
+ const env = {
34
+ ...process.env,
35
+ ...nativeEnv,
36
+ };
37
+
38
+ const gjsArgs = ['-m', bundlePath, ...extraArgs];
39
+ const child = spawn('gjs', gjsArgs, { env, stdio: 'inherit' });
40
+
41
+ await new Promise<void>((resolvePromise, reject) => {
42
+ child.on('close', (code) => {
43
+ if (code !== 0) {
44
+ reject(new Error(`gjs exited with code ${code}`));
45
+ } else {
46
+ resolvePromise();
47
+ }
48
+ });
49
+ child.on('error', reject);
50
+ }).catch((err) => {
51
+ console.error(err.message);
52
+ process.exit(1);
53
+ });
54
+ }