@gjsify/vite-plugin-gjsify 0.64.2-next.252 → 0.64.2-next.253

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 CHANGED
@@ -43,6 +43,8 @@ export default defineConfig({
43
43
 
44
44
  Both presets resolve `@girs/*` / `gi://` imports to an empty module (those are GJS-only specifiers that leak transitively) and apply the gjsify alias layer for Node built-ins and polyfills.
45
45
 
46
+ Both presets also embed `*.gresource.xml` imports ([ADR 0116](../../../docs/adr/0116-app-gresources-are-embedded-at-build-time-for-web-and-nativescript.md) §§ 1, 7): `import bytes from './data/app.data.gresource.xml'` yields the `Uint8Array` that `gjsify build` yields, ready for `Gio.resources_register(Gio.Resource.new_from_data(bytes))`. `glib-compile-resources` must be on the build host, `compressed="true"` is dropped (the web and NativeScript cannot inflate synchronously), and the dev server reloads the module when the XML or a file it lists changes. Type the import with `@gjsify/rolldown-plugin-gjsify/types`.
47
+
46
48
  ## License
47
49
 
48
50
  MIT
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@
19
19
  // which is the one kind of difference no amount of
20
20
  // matching aliases and conditions can paper over.
21
21
  // - blueprintPlugin() → compile `.blp` GNOME Blueprint files to XML
22
+ // - gresourcePlugin() → `import bytes from './x.gresource.xml'` (ADR 0116)
22
23
  // - deepkitPlugin() → optional Deepkit type reflection (opt-in)
23
24
  // - an inline Vite config hook supplying the browser-target resolve aliases,
24
25
  // conditions, mainFields, defines and build target.
@@ -38,7 +39,7 @@
38
39
  import { createRequire } from 'node:module';
39
40
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
40
41
  import * as nodePath from 'node:path';
41
- import { gjsImportsEmptyPlugin, giRendererPlugin, platformResolvePlugin, nativescriptSuffixChain, browserSuffixChain, BROWSER_REFUSED_SUFFIXES, detectNativescriptPlatform, nativescriptPlatformDefines, cssAsStringPlugin, } from '@gjsify/rolldown-plugin-gjsify';
42
+ import { gjsImportsEmptyPlugin, giRendererPlugin, platformResolvePlugin, nativescriptSuffixChain, browserSuffixChain, BROWSER_REFUSED_SUFFIXES, detectNativescriptPlatform, nativescriptPlatformDefines, cssAsStringPlugin, gresourcePlugin, } from '@gjsify/rolldown-plugin-gjsify';
42
43
  import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
43
44
  import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
44
45
  import { ALIASES_NODE_FOR_NATIVESCRIPT, GI_RENDERERS } from '@gjsify/resolve-npm';
@@ -134,6 +135,9 @@ export function gjsifyBrowser(options = {}) {
134
135
  }),
135
136
  gjsImportsEmptyPlugin(),
136
137
  blueprintPlugin(),
138
+ // `import bytes from './x.gresource.xml'` (ADR 0116 §§ 1, 7): the same `Uint8Array` as
139
+ // `--app browser`, with `compressed="true"` stripped (no synchronous inflate on the web).
140
+ gresourcePlugin({ compressed: 'strip' }),
137
141
  deepkitPlugin({ reflection: options.reflection }),
138
142
  // Opt-in: mirror `--app browser`'s css-as-string so `import css from
139
143
  // './x.css'` yields the CSS string in dev too (unify with the native
@@ -291,6 +295,88 @@ function nativescriptXmlnsBarrelsPlugin() {
291
295
  },
292
296
  };
293
297
  }
298
+ /**
299
+ * The app modules that pick the GObject engine (ADR 0110): those importing
300
+ * `@gjsify/adwaita-gobject-native` or calling `usePureJsGObjectEngine`. Root-relative
301
+ * specs, sorted, so the generated import order is deterministic.
302
+ */
303
+ function collectEngineOptIns(appDir, root) {
304
+ const optInRe = /from\s*["']@gjsify\/adwaita-gobject-native["']|\busePureJsGObjectEngine\s*\(/;
305
+ const specs = [];
306
+ const walk = (dir) => {
307
+ let entries;
308
+ try {
309
+ entries = readdirSync(dir);
310
+ }
311
+ catch {
312
+ return;
313
+ }
314
+ for (const entry of entries) {
315
+ if (entry === 'node_modules')
316
+ continue;
317
+ const full = nodePath.join(dir, entry);
318
+ let isDir;
319
+ try {
320
+ isDir = statSync(full).isDirectory();
321
+ }
322
+ catch {
323
+ continue;
324
+ }
325
+ if (isDir) {
326
+ walk(full);
327
+ continue;
328
+ }
329
+ if (!/\.(?:[cm]?[jt]s)$/.test(entry) || /\.d\.[cm]?ts$/.test(entry))
330
+ continue;
331
+ let src;
332
+ try {
333
+ src = readFileSync(full, 'utf8');
334
+ }
335
+ catch {
336
+ continue;
337
+ }
338
+ if (optInRe.test(src))
339
+ specs.push('/' + nodePath.relative(root, full).split(nodePath.sep).join('/'));
340
+ }
341
+ };
342
+ walk(appDir);
343
+ return specs.sort();
344
+ }
345
+ /**
346
+ * Evaluate the app's GObject-engine opt-in before ANY other app module.
347
+ *
348
+ * ADR 0110 makes an Android app pick its engine in a module evaluated before
349
+ * `@gjsify/adwaita-nativescript`. The natural place — `app.ts`'s first import — is too
350
+ * late: `@nativescript/vite`'s generated entry imports `virtual:ns-bundler-context`
351
+ * BEFORE the main module, and that context eagerly imports every XML page, its
352
+ * code-behind and (via the xmlns plugin) every barrel — all of which reach the port.
353
+ * So the port read the empty slot and the app died at launch with "No GObject engine
354
+ * was registered", whatever `app.ts` did. Measured in Learn6502 on 2026-10-17.
355
+ *
356
+ * Prepends a side-effect import of each opt-in module to the bundler context; it is
357
+ * registered after the xmlns plugin, so its import ends up first.
358
+ */
359
+ function nativescriptEngineFirstPlugin() {
360
+ const BUNDLER_CONTEXT_ID = '\0virtual:ns-bundler-context';
361
+ let root = process.cwd();
362
+ let appDir;
363
+ return {
364
+ name: 'gjsify-nativescript-engine-first',
365
+ configResolved(config) {
366
+ root = config.root || process.cwd();
367
+ appDir = ['app', 'src'].map((dir) => nodePath.join(root, dir)).find((dir) => existsSync(dir));
368
+ },
369
+ transform(code, id) {
370
+ if (id !== BUNDLER_CONTEXT_ID || !appDir)
371
+ return null;
372
+ const optIns = collectEngineOptIns(appDir, root);
373
+ if (optIns.length === 0)
374
+ return null;
375
+ const imports = optIns.map((spec) => `import ${JSON.stringify(spec)};`).join('\n');
376
+ return { code: `${imports}\n${code}`, map: null };
377
+ },
378
+ };
379
+ }
294
380
  /**
295
381
  * Returns the Vite plugin array that brings `gjsify build --app nativescript`'s
296
382
  * NS-target transforms to a Vite project (dev + build). Spread it into a
@@ -366,8 +452,14 @@ export function gjsifyNativescript(options = {}) {
366
452
  // ns-bundler-context leaves unregistered (its tree-shaking gap for
367
453
  // barrels with no `.xml` sibling). Reproduces webpack's xml-namespace-loader.
368
454
  nativescriptXmlnsBarrelsPlugin(),
455
+ // The app's GObject-engine opt-in (ADR 0110) ahead of everything the bundler
456
+ // context imports. AFTER the xmlns plugin, so its prepend lands on top.
457
+ nativescriptEngineFirstPlugin(),
369
458
  // NO blueprintPlugin — Blueprint is GTK-specific
370
459
  // NO cssAsStringPlugin — NS handles CSS via @nativescript/core
460
+ // `import bytes from './x.gresource.xml'` (ADR 0116 §§ 1, 7), as `--app nativescript`;
461
+ // no synchronous inflate on NativeScript either, so `compressed="true"` is stripped.
462
+ gresourcePlugin({ compressed: 'strip' }),
371
463
  deepkitPlugin({ reflection: options.reflection }),
372
464
  configPlugin,
373
465
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/vite-plugin-gjsify",
3
- "version": "0.64.2-next.252",
3
+ "version": "0.64.2-next.253",
4
4
  "description": "Vite plugin presets mirroring `gjsify build --app browser` / `--app nativescript` — dev (Vite/HMR) parity with the gjsify CLI targets.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -43,11 +43,11 @@
43
43
  ],
44
44
  "license": "MIT",
45
45
  "dependencies": {
46
- "@gjsify/empty": "0.64.2-next.252",
47
- "@gjsify/resolve-npm": "0.64.2-next.252",
48
- "@gjsify/rolldown-plugin-deepkit": "0.64.2-next.252",
49
- "@gjsify/rolldown-plugin-gjsify": "0.64.2-next.252",
50
- "@gjsify/vite-plugin-blueprint": "0.64.2-next.252"
46
+ "@gjsify/empty": "0.64.2-next.253",
47
+ "@gjsify/resolve-npm": "0.64.2-next.253",
48
+ "@gjsify/rolldown-plugin-deepkit": "0.64.2-next.253",
49
+ "@gjsify/rolldown-plugin-gjsify": "0.64.2-next.253",
50
+ "@gjsify/vite-plugin-blueprint": "0.64.2-next.253"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "vite": "^8.1.3"
@@ -58,8 +58,8 @@
58
58
  }
59
59
  },
60
60
  "devDependencies": {
61
- "@gjsify/cli": "0.64.2-next.252",
62
- "@gjsify/unit": "0.64.2-next.252",
61
+ "@gjsify/cli": "0.64.2-next.253",
62
+ "@gjsify/unit": "0.64.2-next.253",
63
63
  "@types/node": "^25.9.2",
64
64
  "typescript": "^6.0.3",
65
65
  "vite": "^8.1.3"
@@ -67,5 +67,5 @@
67
67
  "gjsify": {
68
68
  "tier": 1
69
69
  },
70
- "gitHead": "3853c65f772d30460e3894ff08a6079a70d7b206"
70
+ "gitHead": "84c860498d8dd191285353b116e60aa90d71776c"
71
71
  }