@gjsify/rolldown-plugin-gjsify 0.22.0 → 0.24.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.
@@ -1,7 +1,18 @@
1
1
  import { BUNDLE_URL_BANNER } from './bundle-url-banner.js';
2
2
  import { GJS_WELLKNOWN_SYMBOLS_STUB } from './wellknown-symbols-banner.js';
3
+ // Every GJS ambient global is reached through `globalThis.` — NEVER as a bare
4
+ // identifier. The banner shares the module's top-level scope with the bundled
5
+ // code, so a bare `imports` binds to any top-level `const imports` a bundled
6
+ // module declares — and since the banner runs at byte 1, that binding is still
7
+ // in its temporal dead zone: `ReferenceError: can't access lexical declaration
8
+ // 'imports' before initialization`, thrown at load, before a single line of
9
+ // program code runs. `@girs/gjs`'s `gjs.js` declares exactly that
10
+ // (`const imports = globalThis.imports || {}`), so the failure is real and
11
+ // arrives whenever tree-shaking happens to retain that module. It was found
12
+ // via `@gjsify/web-streams`, whose GJS test leg died the moment `@gjsify/utils`
13
+ // became more shakeable — but nothing about it is specific to either package.
3
14
  export const GJS_PROCESS_STUB = 'if(typeof globalThis.process==="undefined"){' +
4
- 'const _s=imports.system,_G=imports.gi.GLib;' +
15
+ 'const _s=globalThis.imports.system,_G=globalThis.imports.gi.GLib;' +
5
16
  // process.hrtime needs a `.bigint` property attached to the function
6
17
  // itself (Node API shape: `process.hrtime.bigint()` — used by execa,
7
18
  // perf-tracking libs, …). Build it as a named local so we can
@@ -21,7 +32,7 @@ export const GJS_PROCESS_STUB = 'if(typeof globalThis.process==="undefined"){' +
21
32
  'versions:{},config:{},' +
22
33
  'cwd(){return _G.get_current_dir()||"/"},' +
23
34
  'exit(c){_s.exit(c??0)},' +
24
- 'stderr:{write(s){printerr(s)}},stdout:{write(s){print(s)}},stdin:null,' +
35
+ 'stderr:{write(s){globalThis.printerr(s)}},stdout:{write(s){globalThis.print(s)}},stdin:null,' +
25
36
  'exitCode:undefined,' +
26
37
  'nextTick(fn,...a){Promise.resolve().then(()=>fn(...a))},' +
27
38
  'hrtime:_h,' +
@@ -319,7 +319,12 @@ export async function detectAutoGlobals(analysisOptions, pluginOptions, gjsifyPl
319
319
  ?.GJSIFY_DEBUG_AUTO_GLOBALS) {
320
320
  const path = `/tmp/gjsify-auto-globals-failed-chunk-${i}.mjs`;
321
321
  try {
322
- // eslint-disable-next-line @typescript-eslint/no-require-imports
322
+ // Dynamic `import()` on purpose: this is a debug-only
323
+ // branch and the module graph should not carry
324
+ // `node:fs` for it. (It is NOT a `require` — it never
325
+ // was; the rule-disable comment that used to sit here
326
+ // named a rule that cannot apply to an import
327
+ // expression.)
323
328
  const fs = await import('node:fs');
324
329
  fs.writeFileSync(path, code);
325
330
  console.error(`[gjsify-auto-globals] parse failed on chunk #${i} — wrote ${path} for inspection`);
@@ -7,6 +7,7 @@
7
7
  // first, then re-exports the real entry. `\0`-prefixed ids are Rollup's
8
8
  // convention for synthetic modules — Rolldown treats them as not-from-disk and
9
9
  // skips the default loader.
10
+ import { GJSIFY_VIRTUAL_PREFIX } from './virtual-module-id.js';
10
11
  /**
11
12
  * If there are side-effect imports to land alongside the user's entry, wrap each
12
13
  * entry in a virtual module that imports them first then re-exports the entry.
@@ -22,7 +23,7 @@ export function wrapInputWithSideEffects(input, sideEffects, opts = {}) {
22
23
  return { input, plugin: null };
23
24
  }
24
25
  const userEntries = new Map(); // virtualId → realPath
25
- const PREFIX = '\0gjsify-entry:';
26
+ const PREFIX = `${GJSIFY_VIRTUAL_PREFIX}entry:`;
26
27
  function wrap(realPath) {
27
28
  const id = PREFIX + realPath;
28
29
  userEntries.set(id, realPath);
@@ -6,3 +6,4 @@ export * from './merge.js';
6
6
  export { detectFreeGlobals } from './detect-free-globals.js';
7
7
  export { resolveGlobalsList, writeRegisterInjectFile } from './scan-globals.js';
8
8
  export { inlineStaticReads } from './inline-static-reads.js';
9
+ export { GJSIFY_VIRTUAL_PREFIX, isGjsifyVirtualModuleId } from './virtual-module-id.js';
@@ -6,3 +6,4 @@ export * from './merge.js';
6
6
  export { detectFreeGlobals } from './detect-free-globals.js';
7
7
  export { resolveGlobalsList, writeRegisterInjectFile } from './scan-globals.js';
8
8
  export { inlineStaticReads } from './inline-static-reads.js';
9
+ export { GJSIFY_VIRTUAL_PREFIX, isGjsifyVirtualModuleId } from './virtual-module-id.js';
@@ -0,0 +1,14 @@
1
+ /** Shared prefix of every gjsify-generated (synthetic) module id. */
2
+ export declare const GJSIFY_VIRTUAL_PREFIX = "\0gjsify-";
3
+ /**
4
+ * Is `id` a module gjsify's own plugins generated (as opposed to a user/npm
5
+ * source file)?
6
+ *
7
+ * Used by `aliasPlugin` to scope the alias tables to REAL source: generated
8
+ * module bodies name the runtime module they need explicitly and must not be
9
+ * re-pointed by a user alias or a slot-routing entry.
10
+ *
11
+ * @param id A Rolldown module id — typically a `resolveId` `importer`, which is
12
+ * `undefined` for entry modules.
13
+ */
14
+ export declare function isGjsifyVirtualModuleId(id: string | undefined | null): boolean;
@@ -0,0 +1,36 @@
1
+ // The ONE prefix every synthetic module id emitted by a gjsify plugin carries.
2
+ //
3
+ // Rollup/Rolldown convention is that a `\0`-prefixed id is not-from-disk; every
4
+ // gjsify plugin that emits one additionally namespaces it with `gjsify-`
5
+ // (`\0gjsify-entry:`, `\0gjsify-gi-node:`, `\0gjsify-napi-addon:`,
6
+ // `\0gjsify-empty-gjs-import`). Deriving those ids from THIS constant turns that
7
+ // naming habit into an enforced invariant, which matters because the alias layer
8
+ // keys off it: a module whose SOURCE we generated must bind to the RUNTIME's real
9
+ // modules, never to whatever a user `--alias` retargets a specifier onto.
10
+ //
11
+ // Concretely (the bug that motivated this): `gjsGiNodePlugin`'s virtual module
12
+ // emits `import { createRequire } from 'node:module'`. Under the node-gi consumer
13
+ // harness — which builds `--alias node:module=@gjsify/module` to put the polyfill
14
+ // UNDER TEST behind the specifier — that import was rewritten onto the polyfill
15
+ // itself, so the bundle called `@gjsify/module`'s `createRequire` at top level
16
+ // before its lazy GLib namespace proxy existed (`TypeError: Cannot read
17
+ // properties of undefined (reading 'filename_from_uri')`), and past that hit a
18
+ // genuine cycle: the polyfill's Gio-backed CJS loader needs GLib, and GLib is
19
+ // reached through `@gjsify/node-gi/gi` — which is what the virtual module was
20
+ // loading in the first place.
21
+ /** Shared prefix of every gjsify-generated (synthetic) module id. */
22
+ export const GJSIFY_VIRTUAL_PREFIX = '\0gjsify-';
23
+ /**
24
+ * Is `id` a module gjsify's own plugins generated (as opposed to a user/npm
25
+ * source file)?
26
+ *
27
+ * Used by `aliasPlugin` to scope the alias tables to REAL source: generated
28
+ * module bodies name the runtime module they need explicitly and must not be
29
+ * re-pointed by a user alias or a slot-routing entry.
30
+ *
31
+ * @param id A Rolldown module id — typically a `resolveId` `importer`, which is
32
+ * `undefined` for entry modules.
33
+ */
34
+ export function isGjsifyVirtualModuleId(id) {
35
+ return typeof id === 'string' && id.startsWith(GJSIFY_VIRTUAL_PREFIX);
36
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/rolldown-plugin-gjsify",
3
- "version": "0.22.0",
3
+ "version": "0.24.1",
4
4
  "description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -55,11 +55,11 @@
55
55
  ],
56
56
  "license": "MIT",
57
57
  "dependencies": {
58
- "@gjsify/console": "^0.22.0",
59
- "@gjsify/resolve-npm": "^0.22.0",
60
- "@gjsify/rolldown-plugin-deepkit": "^0.22.0",
61
- "@gjsify/rolldown-plugin-pnp": "^0.22.0",
62
- "@gjsify/vite-plugin-blueprint": "^0.22.0",
58
+ "@gjsify/console": "^0.24.1",
59
+ "@gjsify/resolve-npm": "^0.24.1",
60
+ "@gjsify/rolldown-plugin-deepkit": "^0.24.1",
61
+ "@gjsify/rolldown-plugin-pnp": "^0.24.1",
62
+ "@gjsify/vite-plugin-blueprint": "^0.24.1",
63
63
  "@rollup/pluginutils": "^5.4.0",
64
64
  "acorn": "^8.17.0",
65
65
  "acorn-walk": "^8.3.5",
@@ -68,7 +68,7 @@
68
68
  "sass": "^1.101.0"
69
69
  },
70
70
  "peerDependencies": {
71
- "@gjsify/lightningcss-native": "^0.22.0",
71
+ "@gjsify/lightningcss-native": "^0.24.1",
72
72
  "rolldown": "^1.1.4"
73
73
  },
74
74
  "peerDependenciesMeta": {