@multiplatform.one/vite-plugin-gnome 9.0.11 → 9.2.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/lib/index.cjs CHANGED
@@ -318,6 +318,48 @@ function gnomeShimsOf(options, root) {
318
318
  };
319
319
  }
320
320
  /**
321
+ * Wraps a path-matching `manualChunks` so it never names a chunk for a module
322
+ * the entries reach only through `import()`. A named chunk is a static import
323
+ * of whatever uses it, so a lazy module caught by a rule like
324
+ * `id.includes("public/components")` would evaluate at startup: shiki's
325
+ * `import("shiki/wasm")` then runs `atob` at the top of the GJS import and
326
+ * the bundle dies before the first frame (FZ-11149). Such a module returns
327
+ * null instead and keeps the default lazy chunk. A module with no importers
328
+ * that isn't an entry, or one the bundler can't describe, keeps the wrapped
329
+ * answer.
330
+ */
331
+ function keepLazyModulesLazy(manualChunks) {
332
+ const eager = /* @__PURE__ */ new Map();
333
+ const isEager = (id, meta) => {
334
+ const seen = new Set([id]);
335
+ const queue = [id];
336
+ while (queue.length > 0) {
337
+ const current = queue.pop();
338
+ const known = eager.get(current);
339
+ if (known === true) return markEager(id);
340
+ if (known === false) continue;
341
+ const info = meta.getModuleInfo(current);
342
+ if (!info || info.isEntry) return markEager(id);
343
+ if (info.importers.length === 0 && info.dynamicImporters.length === 0) return markEager(id);
344
+ for (const importer of info.importers) if (!seen.has(importer)) {
345
+ seen.add(importer);
346
+ queue.push(importer);
347
+ }
348
+ }
349
+ for (const lazy of seen) eager.set(lazy, false);
350
+ return false;
351
+ };
352
+ const markEager = (id) => {
353
+ eager.set(id, true);
354
+ return true;
355
+ };
356
+ return (id, meta) => {
357
+ const name = manualChunks(id, meta);
358
+ if (!name || !meta?.getModuleInfo) return name;
359
+ return eager.get(id) ?? isEager(id, meta) ? name : null;
360
+ };
361
+ }
362
+ /**
321
363
  * Resolution for a GNOME build, in one plugin. It turns the
322
364
  * {@link gnomeCondition} condition on, after the config's own
323
365
  * `resolve.conditions` (which it requires), applies the config's
@@ -349,6 +391,13 @@ function gnomeResolve() {
349
391
  configResolved(config) {
350
392
  resolver = gnomeShimResolver(gnomeShimsOf(config.gnome, config.root));
351
393
  },
394
+ outputOptions(options) {
395
+ if (typeof options.manualChunks !== "function") return null;
396
+ return {
397
+ ...options,
398
+ manualChunks: keepLazyModulesLazy(options.manualChunks)
399
+ };
400
+ },
352
401
  async resolveId(source, importer) {
353
402
  const shim = resolver.shimFor(source, importer);
354
403
  if (shim) return shim;
@@ -366,6 +415,7 @@ exports.gnomePlatformExtensions = gnomePlatformExtensions;
366
415
  exports.gnomeResolve = gnomeResolve;
367
416
  exports.gnomeShimResolver = gnomeShimResolver;
368
417
  exports.gnomeShimsOf = gnomeShimsOf;
418
+ exports.keepLazyModulesLazy = keepLazyModulesLazy;
369
419
  exports.tamaguiAliases = tamaguiAliases;
370
420
  exports.tamaguiLinkedAliases = tamaguiLinkedAliases;
371
421
  exports.tamaguiPatchAnchors = tamaguiPatchAnchors;
package/lib/index.mjs CHANGED
@@ -317,6 +317,48 @@ function gnomeShimsOf(options, root) {
317
317
  };
318
318
  }
319
319
  /**
320
+ * Wraps a path-matching `manualChunks` so it never names a chunk for a module
321
+ * the entries reach only through `import()`. A named chunk is a static import
322
+ * of whatever uses it, so a lazy module caught by a rule like
323
+ * `id.includes("public/components")` would evaluate at startup: shiki's
324
+ * `import("shiki/wasm")` then runs `atob` at the top of the GJS import and
325
+ * the bundle dies before the first frame (FZ-11149). Such a module returns
326
+ * null instead and keeps the default lazy chunk. A module with no importers
327
+ * that isn't an entry, or one the bundler can't describe, keeps the wrapped
328
+ * answer.
329
+ */
330
+ function keepLazyModulesLazy(manualChunks) {
331
+ const eager = /* @__PURE__ */ new Map();
332
+ const isEager = (id, meta) => {
333
+ const seen = new Set([id]);
334
+ const queue = [id];
335
+ while (queue.length > 0) {
336
+ const current = queue.pop();
337
+ const known = eager.get(current);
338
+ if (known === true) return markEager(id);
339
+ if (known === false) continue;
340
+ const info = meta.getModuleInfo(current);
341
+ if (!info || info.isEntry) return markEager(id);
342
+ if (info.importers.length === 0 && info.dynamicImporters.length === 0) return markEager(id);
343
+ for (const importer of info.importers) if (!seen.has(importer)) {
344
+ seen.add(importer);
345
+ queue.push(importer);
346
+ }
347
+ }
348
+ for (const lazy of seen) eager.set(lazy, false);
349
+ return false;
350
+ };
351
+ const markEager = (id) => {
352
+ eager.set(id, true);
353
+ return true;
354
+ };
355
+ return (id, meta) => {
356
+ const name = manualChunks(id, meta);
357
+ if (!name || !meta?.getModuleInfo) return name;
358
+ return eager.get(id) ?? isEager(id, meta) ? name : null;
359
+ };
360
+ }
361
+ /**
320
362
  * Resolution for a GNOME build, in one plugin. It turns the
321
363
  * {@link gnomeCondition} condition on, after the config's own
322
364
  * `resolve.conditions` (which it requires), applies the config's
@@ -348,6 +390,13 @@ function gnomeResolve() {
348
390
  configResolved(config) {
349
391
  resolver = gnomeShimResolver(gnomeShimsOf(config.gnome, config.root));
350
392
  },
393
+ outputOptions(options) {
394
+ if (typeof options.manualChunks !== "function") return null;
395
+ return {
396
+ ...options,
397
+ manualChunks: keepLazyModulesLazy(options.manualChunks)
398
+ };
399
+ },
351
400
  async resolveId(source, importer) {
352
401
  const shim = resolver.shimFor(source, importer);
353
402
  if (shim) return shim;
@@ -360,4 +409,4 @@ function gnomeResolve() {
360
409
  }
361
410
 
362
411
  //#endregion
363
- export { gnomeCondition, gnomePlatformExtensions, gnomeResolve, gnomeShimResolver, gnomeShimsOf, tamaguiAliases, tamaguiLinkedAliases, tamaguiPatchAnchors, tamaguiPlugin };
412
+ export { gnomeCondition, gnomePlatformExtensions, gnomeResolve, gnomeShimResolver, gnomeShimsOf, keepLazyModulesLazy, tamaguiAliases, tamaguiLinkedAliases, tamaguiPatchAnchors, tamaguiPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/vite-plugin-gnome",
3
- "version": "9.0.11",
3
+ "version": "9.2.0",
4
4
  "description": "Vite plugin that makes Tamagui render under react-gnome (GTK4/GJS) — bundle patches for @tamagui/core's native lazy-init chains, the sheet/portal native builds, the hover/animation gates, plus the Tamagui-specific resolver aliases. Pairs with @react-gnome/vite-plugin (generic GJS aliases/conditions/define).",
5
5
  "keywords": [
6
6
  "gjs",
package/src/index.ts CHANGED
@@ -586,6 +586,66 @@ export function gnomeShimsOf(
586
586
  return { dir: resolve(root, shims.dir), packages: shims.packages };
587
587
  }
588
588
 
589
+ /** The slice of a bundler's module info {@link keepLazyModulesLazy} reads. */
590
+ export interface LazyChunkModuleInfo {
591
+ isEntry: boolean;
592
+ importers: readonly string[];
593
+ dynamicImporters: readonly string[];
594
+ }
595
+
596
+ /** The `meta` argument Rollup and Rolldown pass to `output.manualChunks`. */
597
+ export interface LazyChunkMeta {
598
+ getModuleInfo(id: string): LazyChunkModuleInfo | null;
599
+ }
600
+
601
+ /** A function-form `output.manualChunks`. */
602
+ export type ManualChunks = (id: string, meta: LazyChunkMeta) => string | null | undefined | void;
603
+
604
+ /**
605
+ * Wraps a path-matching `manualChunks` so it never names a chunk for a module
606
+ * the entries reach only through `import()`. A named chunk is a static import
607
+ * of whatever uses it, so a lazy module caught by a rule like
608
+ * `id.includes("public/components")` would evaluate at startup: shiki's
609
+ * `import("shiki/wasm")` then runs `atob` at the top of the GJS import and
610
+ * the bundle dies before the first frame (FZ-11149). Such a module returns
611
+ * null instead and keeps the default lazy chunk. A module with no importers
612
+ * that isn't an entry, or one the bundler can't describe, keeps the wrapped
613
+ * answer.
614
+ */
615
+ export function keepLazyModulesLazy(manualChunks: ManualChunks): ManualChunks {
616
+ const eager = new Map<string, boolean>();
617
+ const isEager = (id: string, meta: LazyChunkMeta): boolean => {
618
+ const seen = new Set<string>([id]);
619
+ const queue = [id];
620
+ while (queue.length > 0) {
621
+ const current = queue.pop() as string;
622
+ const known = eager.get(current);
623
+ if (known === true) return markEager(id);
624
+ if (known === false) continue;
625
+ const info = meta.getModuleInfo(current);
626
+ if (!info || info.isEntry) return markEager(id);
627
+ if (info.importers.length === 0 && info.dynamicImporters.length === 0) return markEager(id);
628
+ for (const importer of info.importers) {
629
+ if (!seen.has(importer)) {
630
+ seen.add(importer);
631
+ queue.push(importer);
632
+ }
633
+ }
634
+ }
635
+ for (const lazy of seen) eager.set(lazy, false);
636
+ return false;
637
+ };
638
+ const markEager = (id: string): true => {
639
+ eager.set(id, true);
640
+ return true;
641
+ };
642
+ return (id, meta) => {
643
+ const name = manualChunks(id, meta);
644
+ if (!name || !meta?.getModuleInfo) return name;
645
+ return (eager.get(id) ?? isEager(id, meta)) ? name : null;
646
+ };
647
+ }
648
+
589
649
  /**
590
650
  * Resolution for a GNOME build, in one plugin. It turns the
591
651
  * {@link gnomeCondition} condition on, after the config's own
@@ -627,6 +687,13 @@ export function gnomeResolve(): Plugin {
627
687
  gnomeShimsOf((config as { gnome?: GnomeOptions }).gnome, config.root),
628
688
  );
629
689
  },
690
+ outputOptions(options) {
691
+ if (typeof options.manualChunks !== "function") return null;
692
+ return {
693
+ ...options,
694
+ manualChunks: keepLazyModulesLazy(options.manualChunks as ManualChunks),
695
+ };
696
+ },
630
697
  async resolveId(source, importer) {
631
698
  const shim = resolver.shimFor(source, importer);
632
699
  if (shim) return shim;
package/types/index.d.ts CHANGED
@@ -126,6 +126,30 @@ export interface GnomeShimResolver {
126
126
  export declare function gnomeShimResolver(shims: GnomeShims | undefined): GnomeShimResolver;
127
127
  /** A config's `gnome.shims` with `dir` resolved against `root`, or undefined. */
128
128
  export declare function gnomeShimsOf(options: GnomeOptions | undefined, root: string): GnomeShims | undefined;
129
+ /** The slice of a bundler's module info {@link keepLazyModulesLazy} reads. */
130
+ export interface LazyChunkModuleInfo {
131
+ isEntry: boolean;
132
+ importers: readonly string[];
133
+ dynamicImporters: readonly string[];
134
+ }
135
+ /** The `meta` argument Rollup and Rolldown pass to `output.manualChunks`. */
136
+ export interface LazyChunkMeta {
137
+ getModuleInfo(id: string): LazyChunkModuleInfo | null;
138
+ }
139
+ /** A function-form `output.manualChunks`. */
140
+ export type ManualChunks = (id: string, meta: LazyChunkMeta) => string | null | undefined | void;
141
+ /**
142
+ * Wraps a path-matching `manualChunks` so it never names a chunk for a module
143
+ * the entries reach only through `import()`. A named chunk is a static import
144
+ * of whatever uses it, so a lazy module caught by a rule like
145
+ * `id.includes("public/components")` would evaluate at startup: shiki's
146
+ * `import("shiki/wasm")` then runs `atob` at the top of the GJS import and
147
+ * the bundle dies before the first frame (FZ-11149). Such a module returns
148
+ * null instead and keeps the default lazy chunk. A module with no importers
149
+ * that isn't an entry, or one the bundler can't describe, keeps the wrapped
150
+ * answer.
151
+ */
152
+ export declare function keepLazyModulesLazy(manualChunks: ManualChunks): ManualChunks;
129
153
  /**
130
154
  * Resolution for a GNOME build, in one plugin. It turns the
131
155
  * {@link gnomeCondition} condition on, after the config's own
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAOpD,CAAC;AAEF,oEAAoE;AACpE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;IAC/D,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA+PD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,kBAAkB,EAK5D,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MA8E3B,CAAC;AA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