@gjsify/cli 0.17.0 → 0.19.0
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/dist/cli.gjs.mjs +158 -155
- package/lib/actions/build.d.ts +15 -4
- package/lib/actions/build.js +34 -6
- package/lib/cli-app.js +16 -8
- package/lib/commands/build.js +13 -3
- package/lib/commands/check.js +2 -13
- package/lib/commands/dlx.d.ts +17 -0
- package/lib/commands/dlx.js +7 -1
- package/lib/commands/install.js +10 -5
- package/lib/commands/run.d.ts +1 -0
- package/lib/commands/run.js +109 -4
- package/lib/commands/showcase.d.ts +1 -0
- package/lib/commands/showcase.js +125 -25
- package/lib/commands/storybook.js +48 -21
- package/lib/config.js +12 -1
- package/lib/index.js +2 -2
- package/lib/types/config-data.d.ts +9 -0
- package/lib/utils/detect-native-packages.js +2 -10
- package/lib/utils/discover-showcases.js +10 -2
- package/lib/utils/node-version.js +2 -2
- package/lib/utils/oxc-resolve.js +2 -4
- package/lib/utils/pkg-json-edit.d.ts +2 -0
- package/lib/utils/pkg-json.d.ts +6 -0
- package/lib/utils/pkg-json.js +24 -0
- package/lib/utils/resolve-gjs-entry.d.ts +11 -0
- package/lib/utils/resolve-gjs-entry.js +42 -0
- package/lib/utils/run-gjs.js +15 -2
- package/lib/utils/run-node.d.ts +21 -0
- package/lib/utils/run-node.js +62 -1
- package/lib/utils/runtimes.d.ts +66 -0
- package/lib/utils/runtimes.js +97 -0
- package/lib/utils/workspace-root.js +2 -9
- package/package.json +20 -17
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Shared runtime-selector tooling for running gjsify examples/showcases across
|
|
2
|
+
// the FOUR runtimes gjsify targets: gjs, node, bun, deno.
|
|
3
|
+
//
|
|
4
|
+
// This is the single source of truth generalized from the node-gi quad-runtime
|
|
5
|
+
// example's `harness.mjs`. Both the CLI (`gjsify run`/`gjsify showcase
|
|
6
|
+
// --runtime`) and the examples (the node-gi `harness.mjs`) consume it — so the
|
|
7
|
+
// RUNTIMES map, the runtime→build-target mapping and `availableRuntimes()` live
|
|
8
|
+
// in ONE place instead of a per-example copy.
|
|
9
|
+
//
|
|
10
|
+
// The module is intentionally PURE (only `node:child_process` and the pure,
|
|
11
|
+
// side-effect-free `@gjsify/rolldown-plugin-gjsify/runtime` host detector, no
|
|
12
|
+
// `gi://` / native imports) so an external example can deep-import it from the
|
|
13
|
+
// installed CLI (`@gjsify/cli/lib/utils/runtimes.js`) without pulling the whole
|
|
14
|
+
// bundler in. Mirrors the existing `@gjsify/cli/lib/utils/run-gjs.js`
|
|
15
|
+
// deep-import precedent used by the dlx e2e suites.
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { hostRuntime } from '@gjsify/rolldown-plugin-gjsify/runtime';
|
|
18
|
+
/** All runtimes, in canonical order (gjs first — it is the reference). */
|
|
19
|
+
export const EXAMPLE_RUNTIMES = ['gjs', 'node', 'bun', 'deno'];
|
|
20
|
+
/**
|
|
21
|
+
* The runtime map — the generalization of the node-gi harness's `RUNTIMES`.
|
|
22
|
+
* `deno` uses `--node-modules-dir=manual`: `auto` would re-resolve the example's
|
|
23
|
+
* heavy build-time dep tree (`@gjsify/cli` + platform binaries) and hang, when
|
|
24
|
+
* the app only needs the already-linked runtime dep `@gjsify/node-gi`.
|
|
25
|
+
*/
|
|
26
|
+
export const RUNTIMES = {
|
|
27
|
+
gjs: { probe: 'gjs', buildApp: 'gjs', launch: (e, a = []) => ['gjs', ['-m', e, ...a]] },
|
|
28
|
+
node: { probe: 'node', buildApp: 'node', launch: (e, a = []) => ['node', [e, ...a]] },
|
|
29
|
+
bun: { probe: 'bun', buildApp: 'node', launch: (e, a = []) => ['bun', [e, ...a]] },
|
|
30
|
+
deno: {
|
|
31
|
+
probe: 'deno',
|
|
32
|
+
buildApp: 'node',
|
|
33
|
+
launch: (e, a = []) => ['deno', ['run', '-A', '--node-modules-dir=manual', e, ...a]],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
/** Type guard: is `value` one of the four known runtimes? */
|
|
37
|
+
export function isExampleRuntime(value) {
|
|
38
|
+
return EXAMPLE_RUNTIMES.includes(value);
|
|
39
|
+
}
|
|
40
|
+
/** The `gjsify build --app <target>` a runtime consumes (`gjs`, else `node`). */
|
|
41
|
+
export function buildAppForRuntime(runtime) {
|
|
42
|
+
return RUNTIMES[runtime].buildApp;
|
|
43
|
+
}
|
|
44
|
+
/** Whether `<probe> --version` succeeds (i.e. the runtime binary is on PATH). */
|
|
45
|
+
export function isRuntimeOnPath(probe) {
|
|
46
|
+
try {
|
|
47
|
+
execFileSync(probe, ['--version'], { stdio: 'ignore', timeout: 15000 });
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether a specific runtime is runnable here. The HOST runtime (the one the
|
|
56
|
+
* CLI itself executes in — gjs / node / bun / deno) is always available: we are
|
|
57
|
+
* running on it, so no PATH probe is needed. Every other runtime is probed via
|
|
58
|
+
* `<binary> --version`.
|
|
59
|
+
*/
|
|
60
|
+
export function isRuntimeAvailable(runtime) {
|
|
61
|
+
return runtime === hostRuntime() ? true : isRuntimeOnPath(RUNTIMES[runtime].probe);
|
|
62
|
+
}
|
|
63
|
+
/** Which of gjs/node/bun/deno are runnable on this host. */
|
|
64
|
+
export function availableRuntimes() {
|
|
65
|
+
return EXAMPLE_RUNTIMES.filter((rt) => isRuntimeAvailable(rt));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Read a package's declared example runtimes. Returns the (validated) list, or
|
|
69
|
+
* `null` when the package declares none — the "unconstrained / permissive" case.
|
|
70
|
+
* Unknown entries in the list are dropped (so a future runtime name doesn't hard
|
|
71
|
+
* error against an older CLI).
|
|
72
|
+
*/
|
|
73
|
+
export function readDeclaredRuntimes(pkg) {
|
|
74
|
+
const list = pkg?.gjsify?.example?.runtimes;
|
|
75
|
+
if (!Array.isArray(list))
|
|
76
|
+
return null;
|
|
77
|
+
return list.filter((v) => typeof v === 'string' && isExampleRuntime(v));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Validate a requested runtime against a package's declaration. A `null`
|
|
81
|
+
* declaration is permissive (always ok). When the runtime is not in the
|
|
82
|
+
* declared set, returns a clear, actionable error message (never throws) so
|
|
83
|
+
* callers can print it and exit cleanly.
|
|
84
|
+
*/
|
|
85
|
+
export function checkRuntimeSupported(runtime, declared, name) {
|
|
86
|
+
if (declared === null)
|
|
87
|
+
return { ok: true };
|
|
88
|
+
if (declared.includes(runtime))
|
|
89
|
+
return { ok: true };
|
|
90
|
+
const supported = declared.length > 0 ? declared.join(', ') : '(none)';
|
|
91
|
+
return {
|
|
92
|
+
ok: false,
|
|
93
|
+
message: `"${name}" does not support --runtime ${runtime}.\n` +
|
|
94
|
+
` Declared runtimes: ${supported}.\n` +
|
|
95
|
+
` Run it on one of the declared runtimes, e.g. --runtime ${declared[0] ?? 'gjs'}.`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -11,17 +11,10 @@
|
|
|
11
11
|
// monorepo must actually contain `start` as one of its workspaces.
|
|
12
12
|
// Without this guard, a grand-parent monorepo unrelated to `start`
|
|
13
13
|
// could be picked up.
|
|
14
|
-
import { existsSync
|
|
14
|
+
import { existsSync } from 'node:fs';
|
|
15
15
|
import { join, resolve } from 'node:path';
|
|
16
16
|
import { discoverWorkspaces } from '@gjsify/workspace';
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
17
|
+
import { readPackageJson } from './pkg-json.js';
|
|
25
18
|
export function findWorkspaceRoot(start) {
|
|
26
19
|
let dir = start;
|
|
27
20
|
for (let i = 0; i < 12; i++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -113,6 +113,9 @@
|
|
|
113
113
|
"chmod": "chmod +x ./lib/index.js",
|
|
114
114
|
"build:test:node": "node lib/index.js build src/test.mts --app node --outfile dist/test.node.mjs",
|
|
115
115
|
"test:node": "node dist/test.node.mjs",
|
|
116
|
+
"test:bun": "bun dist/test.node.mjs",
|
|
117
|
+
"test:deno": "deno run -A --no-lock --node-modules-dir=none dist/test.node.mjs",
|
|
118
|
+
"test:cross-runtime": "gjsify run build:test:node && gjsify run test:node && gjsify run test:bun && gjsify run test:deno",
|
|
116
119
|
"test": "gjsify run build:test:node && gjsify run test:node"
|
|
117
120
|
},
|
|
118
121
|
"keywords": [
|
|
@@ -122,19 +125,19 @@
|
|
|
122
125
|
"cli"
|
|
123
126
|
],
|
|
124
127
|
"dependencies": {
|
|
125
|
-
"@gjsify/buffer": "^0.
|
|
126
|
-
"@gjsify/create-app": "^0.
|
|
127
|
-
"@gjsify/node-globals": "^0.
|
|
128
|
-
"@gjsify/node-polyfills": "^0.
|
|
129
|
-
"@gjsify/npm-registry": "^0.
|
|
130
|
-
"@gjsify/resolve-npm": "^0.
|
|
131
|
-
"@gjsify/rolldown-plugin-gjsify": "^0.
|
|
132
|
-
"@gjsify/rolldown-plugin-pnp": "^0.
|
|
133
|
-
"@gjsify/semver": "^0.
|
|
134
|
-
"@gjsify/tar": "^0.
|
|
135
|
-
"@gjsify/tsc": "^0.
|
|
136
|
-
"@gjsify/web-polyfills": "^0.
|
|
137
|
-
"@gjsify/workspace": "^0.
|
|
128
|
+
"@gjsify/buffer": "^0.19.0",
|
|
129
|
+
"@gjsify/create-app": "^0.19.0",
|
|
130
|
+
"@gjsify/node-globals": "^0.19.0",
|
|
131
|
+
"@gjsify/node-polyfills": "^0.19.0",
|
|
132
|
+
"@gjsify/npm-registry": "^0.19.0",
|
|
133
|
+
"@gjsify/resolve-npm": "^0.19.0",
|
|
134
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.19.0",
|
|
135
|
+
"@gjsify/rolldown-plugin-pnp": "^0.19.0",
|
|
136
|
+
"@gjsify/semver": "^0.19.0",
|
|
137
|
+
"@gjsify/tar": "^0.19.0",
|
|
138
|
+
"@gjsify/tsc": "^0.19.0",
|
|
139
|
+
"@gjsify/web-polyfills": "^0.19.0",
|
|
140
|
+
"@gjsify/workspace": "^0.19.0",
|
|
138
141
|
"cosmiconfig": "^9.0.2",
|
|
139
142
|
"get-tsconfig": "^4.14.0",
|
|
140
143
|
"pkg-types": "^2.3.1",
|
|
@@ -142,13 +145,13 @@
|
|
|
142
145
|
"yargs": "^18.0.0"
|
|
143
146
|
},
|
|
144
147
|
"devDependencies": {
|
|
145
|
-
"@gjsify/unit": "^0.
|
|
148
|
+
"@gjsify/unit": "^0.19.0",
|
|
146
149
|
"@types/yargs": "^17.0.35",
|
|
147
150
|
"typescript": "^6.0.3"
|
|
148
151
|
},
|
|
149
152
|
"peerDependencies": {
|
|
150
|
-
"@gjsify/oxfmt-native": "^0.
|
|
151
|
-
"@gjsify/rolldown-native": "^0.
|
|
153
|
+
"@gjsify/oxfmt-native": "^0.19.0",
|
|
154
|
+
"@gjsify/rolldown-native": "^0.19.0"
|
|
152
155
|
},
|
|
153
156
|
"peerDependenciesMeta": {
|
|
154
157
|
"@gjsify/oxfmt-native": {
|