@gjsify/cli 0.24.1 → 0.25.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.
@@ -0,0 +1,69 @@
1
+ // Build-time guard: a `--app node` bundle that USES the GJS ambient globals
2
+ // must also have been given `@gjsify/node-gi/globals`.
3
+ //
4
+ // `print`/`printerr`/`log`/`logError`/`ARGV`/`imports` exist implicitly under
5
+ // gjs and nowhere else. On the node target they are seeded by the side-effect
6
+ // shim `@gjsify/node-gi/globals`, which the CLI injects when — and only when —
7
+ // `detectNodeGiGlobals` finds one of them in an analysis bundle. Injecting it
8
+ // unconditionally is not an option: it eagerly loads the native node-gi addon,
9
+ // so a cross-platform package's node bundle would stop loading on plain Node.
10
+ //
11
+ // That makes the decision a PREDICTION about an artifact that does not exist
12
+ // yet, and a prediction can be wrong. It was: the analysis pass used to run
13
+ // before the explicit-`--globals` register stub was resolved, and that stub is
14
+ // one of the two signals `isGjsSourceBuild()` reads — so the analysis bundle
15
+ // routed `/register` subpaths to `@gjsify/empty` and emptied `@girs/*` while the
16
+ // REAL build resolved them for real. Every ambient global reachable only through
17
+ // a register module was therefore invisible to the detector. The build exited 0
18
+ // and the emitted bundle died at its first canvas op with
19
+ //
20
+ // ReferenceError: imports is not defined
21
+ // at CanvasRenderingContext2D._toDataURL
22
+ //
23
+ // on node AND bun (the excalibur-jelly-jumper showcase), while gjs — where the
24
+ // globals are ambient — ran fine. Nothing between `gjsify build --app node` and
25
+ // a user running the bundle ever looked at the artifact.
26
+ //
27
+ // So this is a POST-condition on what was actually emitted: whatever the
28
+ // detector predicted, check it against the bundle. It is deliberately NOT a
29
+ // second detector — it runs the SAME `detectGjsAmbientGlobals` over the SAME
30
+ // kind of input (bundled, tree-shaken output, parsed by acorn, bare identifiers
31
+ // only). Two passes over one oracle that must agree; when they don't, the graph
32
+ // they saw differed, which is a bug in the build pipeline, not in user code.
33
+ //
34
+ // Scope: only when the CLI decided NOT to inject (`--globals auto`, no shim).
35
+ // `--globals none` opts out of the whole mechanism explicitly and is skipped.
36
+ import { detectGjsAmbientGlobals } from '@gjsify/rolldown-plugin-gjsify/globals';
37
+ /**
38
+ * The GJS ambient globals referenced as BARE identifiers in `code`, sorted.
39
+ *
40
+ * Empty for a bundle that only uses the `globalThis.imports` isomorphic-guard
41
+ * shape — that form is a runtime probe, not a dependency, and the detector
42
+ * ignores it for exactly that reason.
43
+ */
44
+ export function findUnshimmedGjsGlobals(code) {
45
+ return [...detectGjsAmbientGlobals(code)].sort();
46
+ }
47
+ /**
48
+ * Throw when a `--app node` bundle references GJS ambient globals but was built
49
+ * without the `@gjsify/node-gi/globals` shim.
50
+ *
51
+ * @param code the emitted bundle source
52
+ * @param outfile path of the bundle, for the error message
53
+ */
54
+ export function assertNodeBundleGlobalsShimmed(code, outfile) {
55
+ const offenders = findUnshimmedGjsGlobals(code);
56
+ if (offenders.length === 0)
57
+ return;
58
+ throw new Error(`gjsify build --app node: ${outfile} references ${offenders.length} GJS ambient global(s) that ` +
59
+ 'nothing installs on node/bun/deno, so the bundle throws `ReferenceError: <name> is not defined` ' +
60
+ 'the first time that code runs:\n' +
61
+ offenders.map((s) => ` - ${s}`).join('\n') +
62
+ '\n\nThe `@gjsify/node-gi/globals` shim seeds them, but it is injected only when the pre-build ' +
63
+ 'detection pass finds them — and that pass did not. The two passes therefore disagreed about the ' +
64
+ 'module graph. Either the detection ran against a different graph than the one emitted (check that ' +
65
+ 'anything feeding `isGjsSourceBuild()` — the `--globals` register stub, `nodeGiGlobalsInject` — is ' +
66
+ 'settled BEFORE `detectNodeGiGlobals`), or the offending package should stop reaching for the ' +
67
+ 'legacy `imports` object: `gi://<Ns>` and the bare `system`/`gettext`/`cairo` built-ins resolve on ' +
68
+ 'both runtimes, `imports` does not.');
69
+ }
@@ -24,7 +24,6 @@ export function normalizeBundlerOptions(configData) {
24
24
  raw['define'] !== null) {
25
25
  if (!warnedDefineOnce) {
26
26
  warnedDefineOnce = true;
27
- // eslint-disable-next-line no-console
28
27
  console.warn("[gjsify] WARNING: 'bundler.define' is not a valid Rolldown option and would be " +
29
28
  "silently ignored — it has been auto-mapped to 'bundler.transform.define'. " +
30
29
  "Move 'define' under 'bundler.transform.define' in your config to suppress " +
@@ -46,7 +45,6 @@ export function normalizeBundlerOptions(configData) {
46
45
  return fromBundler;
47
46
  if (!warnedOnce) {
48
47
  warnedOnce = true;
49
- // eslint-disable-next-line no-console
50
48
  console.warn("[gjsify] DEPRECATION: the 'esbuild' config key is deprecated and will be removed in 0.5.0. " +
51
49
  "Rename it to 'bundler' (typed as RolldownOptions). See the migration notes in the gjsify CHANGELOG.");
52
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.24.1",
3
+ "version": "0.25.1",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -130,19 +130,19 @@
130
130
  "cli"
131
131
  ],
132
132
  "dependencies": {
133
- "@gjsify/buffer": "^0.24.1",
134
- "@gjsify/create-app": "^0.24.1",
135
- "@gjsify/node-globals": "^0.24.1",
136
- "@gjsify/node-polyfills": "^0.24.1",
137
- "@gjsify/npm-registry": "^0.24.1",
138
- "@gjsify/resolve-npm": "^0.24.1",
139
- "@gjsify/rolldown-plugin-gjsify": "^0.24.1",
140
- "@gjsify/rolldown-plugin-pnp": "^0.24.1",
141
- "@gjsify/semver": "^0.24.1",
142
- "@gjsify/tar": "^0.24.1",
143
- "@gjsify/tsc": "^0.24.1",
144
- "@gjsify/web-polyfills": "^0.24.1",
145
- "@gjsify/workspace": "^0.24.1",
133
+ "@gjsify/buffer": "^0.25.1",
134
+ "@gjsify/create-app": "^0.25.1",
135
+ "@gjsify/node-globals": "^0.25.1",
136
+ "@gjsify/node-polyfills": "^0.25.1",
137
+ "@gjsify/npm-registry": "^0.25.1",
138
+ "@gjsify/resolve-npm": "^0.25.1",
139
+ "@gjsify/rolldown-plugin-gjsify": "^0.25.1",
140
+ "@gjsify/rolldown-plugin-pnp": "^0.25.1",
141
+ "@gjsify/semver": "^0.25.1",
142
+ "@gjsify/tar": "^0.25.1",
143
+ "@gjsify/tsc": "^0.25.1",
144
+ "@gjsify/web-polyfills": "^0.25.1",
145
+ "@gjsify/workspace": "^0.25.1",
146
146
  "cosmiconfig": "^9.0.2",
147
147
  "get-tsconfig": "^4.14.0",
148
148
  "pkg-types": "^2.3.1",
@@ -150,13 +150,13 @@
150
150
  "yargs": "^18.0.0"
151
151
  },
152
152
  "devDependencies": {
153
- "@gjsify/unit": "^0.24.1",
153
+ "@gjsify/unit": "^0.25.1",
154
154
  "@types/yargs": "^17.0.35",
155
155
  "typescript": "^6.0.3"
156
156
  },
157
157
  "peerDependencies": {
158
- "@gjsify/oxfmt-native": "^0.24.1",
159
- "@gjsify/rolldown-native": "^0.24.1"
158
+ "@gjsify/oxfmt-native": "^0.25.1",
159
+ "@gjsify/rolldown-native": "^0.25.1"
160
160
  },
161
161
  "peerDependenciesMeta": {
162
162
  "@gjsify/oxfmt-native": {