@gjsify/rolldown-plugin-gjsify 0.4.31 → 0.4.33

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.
@@ -8,6 +8,7 @@
8
8
  import { aliasPlugin } from '../plugins/alias.js';
9
9
  import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
10
10
  import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
11
+ import { getDerivedAliasesSync } from '@gjsify/resolve-npm';
11
12
  import { globToEntryPoints } from '../utils/entry-points.js';
12
13
  import { gjsImportsEmptyPlugin } from '../plugins/gjs-imports-empty.js';
13
14
  import { cssAsStringPlugin } from '../plugins/css-as-string.js';
@@ -27,7 +28,12 @@ export const setupForBrowser = async (input) => {
27
28
  assert: '@gjsify/assert',
28
29
  'node:assert': '@gjsify/assert',
29
30
  };
31
+ // Derived `@gjsify/<X>` aliases driven by per-package `gjsify.runtimes`
32
+ // triplet declarations. Merge order: derived (lowest priority) → hardcoded
33
+ // browser polyfills → user. Hardcoded entries WIN for the curated specifier
34
+ // set, preserving 100% backwards-compatible behavior.
30
35
  const aliasMap = {
36
+ ...getDerivedAliasesSync('browser'),
31
37
  ...browserPolyfillAliases,
32
38
  ...input.pluginOptions.aliases,
33
39
  ...input.userAliases,
package/lib/app/node.js CHANGED
@@ -11,22 +11,25 @@ import { getAliasesForNode } from '../utils/alias.js';
11
11
  import { globToEntryPoints } from '../utils/entry-points.js';
12
12
  import { nodeModulesPathRewritePlugin, getBundleDirFromOutput } from '../plugins/rewrite-node-modules-paths.js';
13
13
  import { cssAsStringPlugin } from '../plugins/css-as-string.js';
14
+ import { gjsImportsEmptyPlugin } from '../plugins/gjs-imports-empty.js';
14
15
  export const setupForNode = async (input) => {
15
16
  const userExternal = input.userExternal ?? [];
16
17
  // node-datachannel is a native C++ addon that cannot be bundled — its
17
18
  // `require('../build/Release/node_datachannel.node')` must resolve at
18
19
  // runtime against the real node_modules tree.
19
20
  //
20
- // Note: Rolldown's `external` array does NOT support glob patterns the
21
- // way esbuild's did (`gi://*`, `@girs/*`). We use a function predicate
22
- // instead so the gi:// URI scheme and the @girs/ namespace are matched
23
- // by prefix.
21
+ // GJS-specific specifiers (`gi://*`, `@girs/*`) are NOT externalised
22
+ // they are intercepted by `gjsImportsEmptyPlugin` (added to the plugins
23
+ // array below) and redirected to a virtual empty ESM module. Marking them
24
+ // external would leave bare `import 'gi://Gio?version=2.0'` strings in the
25
+ // output that Node's default ESM loader rejects with
26
+ // `ERR_UNSUPPORTED_ESM_URL_SCHEME`. The empty-module redirect makes node
27
+ // bundles of cross-platform packages (which transitively import @girs/*
28
+ // via *.gjs.spec / direct internal imports) loadable on Node — the GJS-
29
+ // only code paths are still gated at runtime by `on('Gjs', …)` or by
30
+ // `typeof globalThis.imports !== 'undefined'` guards.
24
31
  const exactExternal = [...EXTERNALS_NODE, 'node-datachannel', ...userExternal];
25
32
  const external = (id) => {
26
- if (id.startsWith('gi://'))
27
- return true;
28
- if (id.startsWith('@girs/'))
29
- return true;
30
33
  if (exactExternal.includes(id))
31
34
  return true;
32
35
  return false;
@@ -80,6 +83,12 @@ export const setupForNode = async (input) => {
80
83
  treeshake: true,
81
84
  };
82
85
  const plugins = [
86
+ // gjsImportsEmptyPlugin runs in `resolveId` order: 'pre', so it
87
+ // intercepts `@girs/*` and `gi://*` specifiers before `aliasPlugin`
88
+ // (and before the default resolver tries to read the @girs/* package
89
+ // entry, which contains a top-level `import 'gi://...'` that Node
90
+ // cannot resolve). Same composition order as `app/browser.ts`.
91
+ gjsImportsEmptyPlugin(),
83
92
  aliasPlugin({ entries: flattenAliases(aliasMap) }),
84
93
  deepkitPlugin({ reflection: input.pluginOptions.reflection }),
85
94
  cssAsStringPlugin(),
@@ -1,5 +1,16 @@
1
1
  import type { ResolveAliasOptions } from '../types/index.js';
2
2
  export declare const setNodeAliasPrefix: (ALIASES: Record<string, string>) => Record<string, string>;
3
+ /**
4
+ * Compose the alias map for a target runtime.
5
+ *
6
+ * Merge order — later entries WIN, so hardcoded `ALIASES_*` entries take
7
+ * precedence over derived ones. This preserves 100% backwards-compatible
8
+ * behavior for the curated set of bare specifiers (`webcrypto`, `assert`, …)
9
+ * encoded in the hardcoded maps. The derived layer fills in `@gjsify/<X>`
10
+ * direct-import routes for packages that have declared a `gjsify.runtimes`
11
+ * triplet, additively — when both sources mention the same key, hardcoded
12
+ * wins.
13
+ */
3
14
  export declare const getAliasesForGjs: (options: ResolveAliasOptions) => {
4
15
  [x: string]: string;
5
16
  };
@@ -1,4 +1,4 @@
1
- import { EXTERNALS_NODE, EXTERNALS_NPM, ALIASES_GENERAL_FOR_GJS, ALIASES_NODE_FOR_GJS, ALIASES_WEB_FOR_GJS, ALIASES_GENERAL_FOR_NODE, ALIASES_GJS_FOR_NODE, ALIASES_WEB_FOR_NODE, } from '@gjsify/resolve-npm';
1
+ import { EXTERNALS_NODE, EXTERNALS_NPM, ALIASES_GENERAL_FOR_GJS, ALIASES_NODE_FOR_GJS, ALIASES_WEB_FOR_GJS, ALIASES_GENERAL_FOR_NODE, ALIASES_GJS_FOR_NODE, ALIASES_WEB_FOR_NODE, getDerivedAliasesSync, } from '@gjsify/resolve-npm';
2
2
  export const setNodeAliasPrefix = (ALIASES) => {
3
3
  // Also resolve alias names with `node:${ALIAS}`
4
4
  for (const ALIAS in ALIASES) {
@@ -17,11 +17,33 @@ const getAliasesWebForGjs = (_options) => ALIASES_WEB_FOR_GJS;
17
17
  const getAliasesGeneralForNode = (_options) => ALIASES_GENERAL_FOR_NODE;
18
18
  const getAliasesGjsForNode = (_options) => ALIASES_GJS_FOR_NODE;
19
19
  const getAliasesWebForNode = (_options) => ALIASES_WEB_FOR_NODE;
20
+ /**
21
+ * Compose the alias map for a target runtime.
22
+ *
23
+ * Merge order — later entries WIN, so hardcoded `ALIASES_*` entries take
24
+ * precedence over derived ones. This preserves 100% backwards-compatible
25
+ * behavior for the curated set of bare specifiers (`webcrypto`, `assert`, …)
26
+ * encoded in the hardcoded maps. The derived layer fills in `@gjsify/<X>`
27
+ * direct-import routes for packages that have declared a `gjsify.runtimes`
28
+ * triplet, additively — when both sources mention the same key, hardcoded
29
+ * wins.
30
+ */
20
31
  export const getAliasesForGjs = (options) => {
21
- return { ...getAliasesGeneralForGjs(options), ...getAliasesNodeForGjs(options), ...getAliasesWebForGjs(options) };
32
+ return {
33
+ // Derived first → hardcoded overrides.
34
+ ...getDerivedAliasesSync('gjs'),
35
+ ...getAliasesGeneralForGjs(options),
36
+ ...getAliasesNodeForGjs(options),
37
+ ...getAliasesWebForGjs(options),
38
+ };
22
39
  };
23
40
  export const getAliasesForNode = (options) => {
24
- return { ...getAliasesGeneralForNode(options), ...getAliasesGjsForNode(options), ...getAliasesWebForNode(options) };
41
+ return {
42
+ ...getDerivedAliasesSync('node'),
43
+ ...getAliasesGeneralForNode(options),
44
+ ...getAliasesGjsForNode(options),
45
+ ...getAliasesWebForNode(options),
46
+ };
25
47
  };
26
48
  /** Array of Node.js build in module names (also with node: prefix) */
27
49
  export const externalNode = [...EXTERNALS_NODE, ...EXTERNALS_NODE.map((E) => `node:${E}`)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/rolldown-plugin-gjsify",
3
- "version": "0.4.31",
3
+ "version": "0.4.33",
4
4
  "description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -48,11 +48,11 @@
48
48
  ],
49
49
  "license": "MIT",
50
50
  "dependencies": {
51
- "@gjsify/console": "^0.4.31",
52
- "@gjsify/resolve-npm": "^0.4.31",
53
- "@gjsify/rolldown-plugin-deepkit": "^0.4.31",
54
- "@gjsify/rolldown-plugin-pnp": "^0.4.31",
55
- "@gjsify/vite-plugin-blueprint": "^0.4.31",
51
+ "@gjsify/console": "^0.4.33",
52
+ "@gjsify/resolve-npm": "^0.4.33",
53
+ "@gjsify/rolldown-plugin-deepkit": "^0.4.33",
54
+ "@gjsify/rolldown-plugin-pnp": "^0.4.33",
55
+ "@gjsify/vite-plugin-blueprint": "^0.4.33",
56
56
  "@rollup/pluginutils": "^5.3.0",
57
57
  "acorn": "^8.16.0",
58
58
  "acorn-walk": "^8.3.5",
@@ -60,7 +60,7 @@
60
60
  "lightningcss": "^1.32.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "@gjsify/lightningcss-native": "^0.4.31",
63
+ "@gjsify/lightningcss-native": "^0.4.33",
64
64
  "rolldown": "^1.0.0-rc.18"
65
65
  },
66
66
  "peerDependenciesMeta": {