@gjsify/rolldown-plugin-gjsify 0.4.0 → 0.4.4
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/package.json +71 -67
- package/src/app/browser.ts +0 -101
- package/src/app/gjs.ts +0 -334
- package/src/app/index.ts +0 -6
- package/src/app/node.ts +0 -127
- package/src/globals.ts +0 -11
- package/src/index.ts +0 -34
- package/src/library/index.ts +0 -2
- package/src/library/lib.ts +0 -141
- package/src/plugin.ts +0 -96
- package/src/plugins/alias.ts +0 -61
- package/src/plugins/css-as-string.ts +0 -189
- package/src/plugins/gjs-imports-empty.ts +0 -29
- package/src/plugins/process-stub.ts +0 -91
- package/src/plugins/rewrite-node-modules-paths.ts +0 -169
- package/src/plugins/shebang.ts +0 -93
- package/src/plugins/text-loader.ts +0 -54
- package/src/shims/console-gjs.ts +0 -25
- package/src/shims/unicorn-magic.ts +0 -75
- package/src/types/app.ts +0 -1
- package/src/types/index.ts +0 -3
- package/src/types/plugin-options.ts +0 -48
- package/src/types/resolve-alias-options.ts +0 -1
- package/src/utils/alias.ts +0 -46
- package/src/utils/auto-globals.ts +0 -321
- package/src/utils/detect-free-globals.ts +0 -284
- package/src/utils/entry-points.ts +0 -48
- package/src/utils/extension.ts +0 -7
- package/src/utils/index.ts +0 -7
- package/src/utils/inline-static-reads.ts +0 -541
- package/src/utils/merge.ts +0 -22
- package/src/utils/scan-globals.ts +0 -91
- package/tsconfig.json +0 -16
package/package.json
CHANGED
|
@@ -1,72 +1,76 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "@gjsify/rolldown-plugin-gjsify",
|
|
3
|
+
"version": "0.4.4",
|
|
4
|
+
"description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"default": "./lib/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./globals": {
|
|
15
|
+
"types": "./lib/globals.d.ts",
|
|
16
|
+
"default": "./lib/globals.js"
|
|
17
|
+
},
|
|
18
|
+
"./shims/console-gjs": {
|
|
19
|
+
"default": "./lib/shims/console-gjs.js"
|
|
20
|
+
}
|
|
13
21
|
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
"files": [
|
|
23
|
+
"lib"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"clear": "rm -rf lib tsconfig.tsbuildinfo || exit 0",
|
|
27
|
+
"check": "tsc --noEmit",
|
|
28
|
+
"build": "tsc"
|
|
17
29
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
"peerDependenciesMeta": {
|
|
60
|
-
"@gjsify/lightningcss-native": {
|
|
61
|
-
"optional": true
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/gjsify/gjsify.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/gjsify/gjsify/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/rolldown-plugin-gjsify#readme",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"gjs",
|
|
40
|
+
"rolldown",
|
|
41
|
+
"rollup",
|
|
42
|
+
"vite",
|
|
43
|
+
"plugin",
|
|
44
|
+
"gjsify"
|
|
45
|
+
],
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@gjsify/console": "^0.4.4",
|
|
49
|
+
"@gjsify/resolve-npm": "^0.4.4",
|
|
50
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.4.4",
|
|
51
|
+
"@gjsify/rolldown-plugin-pnp": "^0.4.4",
|
|
52
|
+
"@gjsify/vite-plugin-blueprint": "^0.4.4",
|
|
53
|
+
"@rollup/pluginutils": "^5.3.0",
|
|
54
|
+
"acorn": "^8.16.0",
|
|
55
|
+
"acorn-walk": "^8.3.5",
|
|
56
|
+
"fast-glob": "^3.3.3",
|
|
57
|
+
"lightningcss": "^1.32.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@gjsify/lightningcss-native": "^0.4.4",
|
|
61
|
+
"rolldown": "^1.0.0-rc.18"
|
|
62
|
+
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"@gjsify/lightningcss-native": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"rolldown": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
62
70
|
},
|
|
63
|
-
"
|
|
64
|
-
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/node": "^25.6.2",
|
|
73
|
+
"rolldown": "^1.0.0",
|
|
74
|
+
"typescript": "^6.0.3"
|
|
65
75
|
}
|
|
66
|
-
|
|
67
|
-
"devDependencies": {
|
|
68
|
-
"@types/node": "^25.6.2",
|
|
69
|
-
"rolldown": "^1.0.0",
|
|
70
|
-
"typescript": "^6.0.3"
|
|
71
|
-
}
|
|
72
|
-
}
|
|
76
|
+
}
|
package/src/app/browser.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// `--app browser` Rolldown configuration factory.
|
|
2
|
-
//
|
|
3
|
-
// Browser builds redirect `@girs/*` and `gi://*` to an empty virtual module
|
|
4
|
-
// (they appear transitively via `@gjsify/unit` and similar packages with
|
|
5
|
-
// GJS-specific code paths). Standard Node.js → browser polyfill aliases
|
|
6
|
-
// for `process` and `assert` keep `@gjsify/unit`'s top-level imports
|
|
7
|
-
// resolvable in a browser bundle.
|
|
8
|
-
|
|
9
|
-
import { aliasPlugin } from '../plugins/alias.js';
|
|
10
|
-
import type { RolldownOptions, RolldownPluginOption } from 'rolldown';
|
|
11
|
-
|
|
12
|
-
import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
|
|
13
|
-
import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
|
|
14
|
-
|
|
15
|
-
import type { PluginOptions } from '../types/plugin-options.js';
|
|
16
|
-
import { globToEntryPoints } from '../utils/entry-points.js';
|
|
17
|
-
import { gjsImportsEmptyPlugin } from '../plugins/gjs-imports-empty.js';
|
|
18
|
-
import { cssAsStringPlugin } from '../plugins/css-as-string.js';
|
|
19
|
-
|
|
20
|
-
export interface BrowserBuildConfig {
|
|
21
|
-
options: RolldownOptions;
|
|
22
|
-
plugins: RolldownPluginOption[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface BrowserFactoryInput {
|
|
26
|
-
input?: RolldownOptions['input'];
|
|
27
|
-
output: { file?: string; dir?: string };
|
|
28
|
-
userExternal?: string[];
|
|
29
|
-
userAliases?: Record<string, string>;
|
|
30
|
-
pluginOptions: PluginOptions;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const setupForBrowser = async (input: BrowserFactoryInput): Promise<BrowserBuildConfig> => {
|
|
34
|
-
const userExternal = input.userExternal ?? [];
|
|
35
|
-
const external = [...userExternal];
|
|
36
|
-
|
|
37
|
-
const exclude = input.pluginOptions.exclude ?? [];
|
|
38
|
-
const entryPoints = await globToEntryPoints(input.input, exclude);
|
|
39
|
-
|
|
40
|
-
// `@gjsify/unit` has `await import('process')` inside a try-catch that
|
|
41
|
-
// is unreachable in browser (typeof document check comes first), but
|
|
42
|
-
// Rolldown still resolves it statically. Map to `@gjsify/empty` so the
|
|
43
|
-
// build succeeds. `assert` → `@gjsify/assert` because `@gjsify/unit`
|
|
44
|
-
// imports `node:assert` at the top level.
|
|
45
|
-
const browserPolyfillAliases: Record<string, string> = {
|
|
46
|
-
process: '@gjsify/empty',
|
|
47
|
-
'node:process': '@gjsify/empty',
|
|
48
|
-
assert: '@gjsify/assert',
|
|
49
|
-
'node:assert': '@gjsify/assert',
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const aliasMap: Record<string, string> = {
|
|
53
|
-
...browserPolyfillAliases,
|
|
54
|
-
...(input.pluginOptions.aliases ?? {}),
|
|
55
|
-
...(input.userAliases ?? {}),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const options: RolldownOptions = {
|
|
59
|
-
input: entryPoints,
|
|
60
|
-
platform: 'browser',
|
|
61
|
-
external,
|
|
62
|
-
resolve: {
|
|
63
|
-
mainFields: ['browser', 'module', 'main'],
|
|
64
|
-
conditionNames: ['import', 'browser'],
|
|
65
|
-
},
|
|
66
|
-
transform: {
|
|
67
|
-
target: 'esnext',
|
|
68
|
-
define: {
|
|
69
|
-
global: 'globalThis',
|
|
70
|
-
window: 'globalThis',
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
output: {
|
|
74
|
-
...input.output,
|
|
75
|
-
format: 'esm',
|
|
76
|
-
sourcemap: false,
|
|
77
|
-
// Single-bundle output. `codeSplitting: false` replaces the
|
|
78
|
-
// deprecated `inlineDynamicImports: true`.
|
|
79
|
-
codeSplitting: false,
|
|
80
|
-
},
|
|
81
|
-
treeshake: true,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const plugins: RolldownPluginOption[] = [
|
|
85
|
-
gjsImportsEmptyPlugin(),
|
|
86
|
-
aliasPlugin({ entries: flattenAliases(aliasMap) }),
|
|
87
|
-
blueprintPlugin() as RolldownPluginOption,
|
|
88
|
-
deepkitPlugin({ reflection: input.pluginOptions.reflection }),
|
|
89
|
-
cssAsStringPlugin(),
|
|
90
|
-
];
|
|
91
|
-
|
|
92
|
-
return { options, plugins };
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
function flattenAliases(map: Record<string, string>): Record<string, string> {
|
|
96
|
-
const out: Record<string, string> = {};
|
|
97
|
-
for (const [from, to] of Object.entries(map)) {
|
|
98
|
-
if (to) out[from] = to;
|
|
99
|
-
}
|
|
100
|
-
return out;
|
|
101
|
-
}
|
package/src/app/gjs.ts
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
// `--app gjs` Rolldown configuration factory.
|
|
2
|
-
//
|
|
3
|
-
// Mirrors the esbuild predecessor's `setupForGjs` exactly in terms of the
|
|
4
|
-
// effective build behaviour: same externals, same alias map, same target
|
|
5
|
-
// (firefox140 for JS, firefox60 for CSS), same console-shim injection,
|
|
6
|
-
// same process-stub banner, same `random-access-file` fs-backed-fallback.
|
|
7
|
-
//
|
|
8
|
-
// Returns a partial `RolldownOptions` template plus the plugin array the
|
|
9
|
-
// caller should compose with their user-supplied options. Library mode is
|
|
10
|
-
// handled separately by `setupLib`.
|
|
11
|
-
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
|
-
import { dirname, resolve } from 'node:path';
|
|
14
|
-
import type { RolldownOptions, RolldownPluginOption } from 'rolldown';
|
|
15
|
-
import { aliasPlugin } from '../plugins/alias.js';
|
|
16
|
-
|
|
17
|
-
import { deepkitPlugin } from '@gjsify/rolldown-plugin-deepkit';
|
|
18
|
-
import blueprintPlugin from '@gjsify/vite-plugin-blueprint';
|
|
19
|
-
|
|
20
|
-
import type { PluginOptions } from '../types/plugin-options.js';
|
|
21
|
-
import { getAliasesForGjs } from '../utils/alias.js';
|
|
22
|
-
import { globToEntryPoints } from '../utils/entry-points.js';
|
|
23
|
-
import {
|
|
24
|
-
nodeModulesPathRewritePlugin,
|
|
25
|
-
getBundleDirFromOutput,
|
|
26
|
-
} from '../plugins/rewrite-node-modules-paths.js';
|
|
27
|
-
import { processStubPlugin } from '../plugins/process-stub.js';
|
|
28
|
-
import { cssAsStringPlugin } from '../plugins/css-as-string.js';
|
|
29
|
-
import { shebangPlugin, resolveShebangLine, inputShebangStripPlugin } from '../plugins/shebang.js';
|
|
30
|
-
|
|
31
|
-
const _shimDir = dirname(fileURLToPath(import.meta.url));
|
|
32
|
-
|
|
33
|
-
function resolveConsoleShim(): string {
|
|
34
|
-
// Preferred: relative to this module's directory. Works under the
|
|
35
|
-
// normal Node consumer flow where `_shimDir` = `<pkg>/lib/app/`.
|
|
36
|
-
const relative = resolve(_shimDir, '../shims/console-gjs.js');
|
|
37
|
-
let fs: typeof import('node:fs') | null = null;
|
|
38
|
-
try {
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
40
|
-
fs = require('node:fs') as typeof import('node:fs');
|
|
41
|
-
} catch { return relative; }
|
|
42
|
-
if (fs.existsSync(relative)) return relative;
|
|
43
|
-
// Fallback: when the orchestrator is bundled into a single .mjs
|
|
44
|
-
// (GJS-CLI self-host loop) `_shimDir` collapses to the bundle's
|
|
45
|
-
// own directory and the relative lookup misses. createRequire's
|
|
46
|
-
// resolver is `exports`-map-aware (Phase C), so the published
|
|
47
|
-
// subpath export `./shims/console-gjs` works under both Node and
|
|
48
|
-
// GJS without further walking.
|
|
49
|
-
try {
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
51
|
-
const Module = require('node:module') as typeof import('node:module');
|
|
52
|
-
const require_ = Module.createRequire(import.meta.url);
|
|
53
|
-
return require_.resolve('@gjsify/rolldown-plugin-gjsify/shims/console-gjs');
|
|
54
|
-
} catch {
|
|
55
|
-
return relative;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Resolved Rolldown configuration template + plugins for `--app gjs`. */
|
|
60
|
-
export interface GjsBuildConfig {
|
|
61
|
-
options: RolldownOptions;
|
|
62
|
-
plugins: RolldownPluginOption[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface GjsFactoryInput {
|
|
66
|
-
/** User entry points after CLI / config merging. */
|
|
67
|
-
input?: RolldownOptions['input'];
|
|
68
|
-
/** Output `file` or `dir` so `import.meta.url` rewriter knows the bundle path. */
|
|
69
|
-
output: { file?: string; dir?: string };
|
|
70
|
-
/** Caller-supplied externals (`gjsify build --external`). */
|
|
71
|
-
userExternal?: string[];
|
|
72
|
-
/** User-supplied banner string (may contain a leading `#!shebang`). */
|
|
73
|
-
userBanner?: string;
|
|
74
|
-
/** User-supplied resolve.alias overrides. */
|
|
75
|
-
userAliases?: Record<string, string>;
|
|
76
|
-
/**
|
|
77
|
-
* Shebang to prepend to the output bundle.
|
|
78
|
-
* `true` → default `#!/usr/bin/env -S gjs -m`
|
|
79
|
-
* `false` → no shebang
|
|
80
|
-
* `"…"` → custom line, supports `${env:NAME[:-default]}` placeholders
|
|
81
|
-
*/
|
|
82
|
-
shebang?: boolean | string;
|
|
83
|
-
/** Plugin options forwarded to sub-plugins (deepkit, css, …). */
|
|
84
|
-
pluginOptions: PluginOptions;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const setupForGjs = async (input: GjsFactoryInput): Promise<GjsBuildConfig> => {
|
|
88
|
-
const userExternal = input.userExternal ?? [];
|
|
89
|
-
// Rolldown's `external` array does not support glob patterns the way
|
|
90
|
-
// esbuild's did (`gi://*`). We use a function predicate so any
|
|
91
|
-
// `gi://Foo?version=…` URI matches by prefix and the GJS-built-in
|
|
92
|
-
// string specifiers stay externalised by name.
|
|
93
|
-
const exactExternal = ['cairo', 'gettext', 'system', ...userExternal];
|
|
94
|
-
const external = (id: string): boolean => {
|
|
95
|
-
if (id.startsWith('gi://')) return true;
|
|
96
|
-
if (exactExternal.includes(id)) return true;
|
|
97
|
-
return false;
|
|
98
|
-
};
|
|
99
|
-
const format = input.pluginOptions.format ?? 'esm';
|
|
100
|
-
|
|
101
|
-
const exclude = input.pluginOptions.exclude ?? [];
|
|
102
|
-
const entryPoints = await globToEntryPoints(input.input, exclude);
|
|
103
|
-
|
|
104
|
-
// unicorn-magic gates its full API behind the "node" conditional
|
|
105
|
-
// exports. We deliberately omit `node` from conditionNames (some
|
|
106
|
-
// packages ship genuinely Node-only code there — see comment
|
|
107
|
-
// around `conditionNames` below). Route the package to our
|
|
108
|
-
// bundled shim so the API is reachable under --app gjs without
|
|
109
|
-
// turning on the node condition globally.
|
|
110
|
-
const unicornMagicShim = resolve(_shimDir, '../shims/unicorn-magic.js');
|
|
111
|
-
|
|
112
|
-
const aliasMap = {
|
|
113
|
-
...getAliasesForGjs({ external }),
|
|
114
|
-
'unicorn-magic': unicornMagicShim,
|
|
115
|
-
...(input.pluginOptions.aliases ?? {}),
|
|
116
|
-
...(input.userAliases ?? {}),
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// The console shim replaces all `console` references with print()/printerr()-
|
|
120
|
-
// based implementations that bypass GLib.log_structured() — no prefix,
|
|
121
|
-
// ANSI codes work. Disabled via `pluginOptions.consoleShim === false`.
|
|
122
|
-
//
|
|
123
|
-
// Path resolution: `resolve(_shimDir, '../shims/...')` works in normal
|
|
124
|
-
// Node consumption (_shimDir = `<pkg>/lib/app/`). When the CLI is
|
|
125
|
-
// bundled into a single .mjs (e.g. the GJS-CLI self-host loop),
|
|
126
|
-
// `import.meta.url` collapses to the bundle's path and the relative
|
|
127
|
-
// resolution lands at a non-existent location. Walk up via
|
|
128
|
-
// createRequire's node_modules-aware resolver as a fallback.
|
|
129
|
-
const consoleShimEnabled = input.pluginOptions.consoleShim !== false;
|
|
130
|
-
const consoleShimPath = consoleShimEnabled
|
|
131
|
-
? resolveConsoleShim()
|
|
132
|
-
: null;
|
|
133
|
-
|
|
134
|
-
// The auto-globals inject stub (when present) is side-effect-imported
|
|
135
|
-
// via a virtual entry — its register modules write to globalThis, so
|
|
136
|
-
// the import chain matters but no name binding does. We can't use
|
|
137
|
-
// Rolldown's `inject` for this because the auto-globals invariant
|
|
138
|
-
// forbids source-AST rewrites for global identifiers (false positives
|
|
139
|
-
// from isomorphic guards / bracket access — see AGENTS.md).
|
|
140
|
-
const sideEffectImports: string[] = [];
|
|
141
|
-
if (input.pluginOptions.autoGlobalsInject) sideEffectImports.push(input.pluginOptions.autoGlobalsInject);
|
|
142
|
-
|
|
143
|
-
const virtualEntries = wrapInputWithSideEffects(entryPoints, sideEffectImports);
|
|
144
|
-
const finalInput = virtualEntries.input;
|
|
145
|
-
|
|
146
|
-
const options: RolldownOptions = {
|
|
147
|
-
input: finalInput,
|
|
148
|
-
platform: 'neutral',
|
|
149
|
-
external,
|
|
150
|
-
// 'browser' field is needed so packages like create-hash, create-hmac,
|
|
151
|
-
// randombytes use their pure-JS browser entry instead of index.js
|
|
152
|
-
// (which does require('crypto') and causes circular dependencies via
|
|
153
|
-
// the crypto → @gjsify/crypto alias).
|
|
154
|
-
resolve: {
|
|
155
|
-
mainFields: format === 'esm' ? ['browser', 'module', 'main'] : ['browser', 'main', 'module'],
|
|
156
|
-
// ESM: omit 'require' — packages listing 'require' before 'import'
|
|
157
|
-
// would silently route through their CJS entry.
|
|
158
|
-
//
|
|
159
|
-
// We deliberately do NOT add `'node'` here. Per Node's exports-map
|
|
160
|
-
// spec the resolver iterates keys in DECLARATION ORDER and picks
|
|
161
|
-
// the first one whose name is in `conditionNames` — the order of
|
|
162
|
-
// conditionNames itself is irrelevant. Packages like
|
|
163
|
-
// `cross-fetch-ponyfill` declare `"node"` first in their exports
|
|
164
|
-
// map and ship a Node-only entry that imports `blobFrom`/
|
|
165
|
-
// `fileFrom` (from native `node:fetch`). With `node` enabled,
|
|
166
|
-
// the resolver picks that branch over `browser` and the bundle
|
|
167
|
-
// breaks at link time. Packages that genuinely need their `node`
|
|
168
|
-
// export under GJS (rare — only one known case so far,
|
|
169
|
-
// `unicorn-magic`'s `traversePathUp`) are handled with explicit
|
|
170
|
-
// resolve aliases instead.
|
|
171
|
-
conditionNames: format === 'esm' ? ['browser', 'import'] : ['browser', 'require', 'import'],
|
|
172
|
-
},
|
|
173
|
-
transform: {
|
|
174
|
-
// Compile target: GJS 1.86 / SpiderMonkey 140 ≈ firefox140.
|
|
175
|
-
target: 'firefox140',
|
|
176
|
-
define: {
|
|
177
|
-
global: 'globalThis',
|
|
178
|
-
window: 'globalThis',
|
|
179
|
-
'process.env.READABLE_STREAM': '"disable"',
|
|
180
|
-
},
|
|
181
|
-
// Console shim: rewrite bare `console` references to a named
|
|
182
|
-
// import from our shim module. We use Rolldown's `inject`
|
|
183
|
-
// (Oxc-driven, lives under `transform`) because:
|
|
184
|
-
// 1. `globalThis.console` is non-configurable on SpiderMonkey
|
|
185
|
-
// 128 so a register-style global write throws.
|
|
186
|
-
// 2. We're replacing console unconditionally — there's no
|
|
187
|
-
// tree-shake-aware detection concern that motivated the
|
|
188
|
-
// auto-globals invariant.
|
|
189
|
-
...(consoleShimPath ? { inject: { console: [consoleShimPath, 'console'] } } : {}),
|
|
190
|
-
},
|
|
191
|
-
output: {
|
|
192
|
-
...input.output,
|
|
193
|
-
format,
|
|
194
|
-
sourcemap: false,
|
|
195
|
-
// App builds emit a single bundle file. Disable code-splitting
|
|
196
|
-
// so dynamic imports get inlined and the entire program lands
|
|
197
|
-
// in one chunk that matches `gjsify build --outfile foo.js`.
|
|
198
|
-
// (`codeSplitting: false` replaces the deprecated
|
|
199
|
-
// `inlineDynamicImports: true` in Rolldown ≥ 1.0-rc.18.)
|
|
200
|
-
codeSplitting: false,
|
|
201
|
-
},
|
|
202
|
-
treeshake: true,
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const bundleDir = getBundleDirFromOutput(input.output);
|
|
206
|
-
|
|
207
|
-
const plugins: RolldownPluginOption[] = [
|
|
208
|
-
// Virtual-entry plugin runs FIRST so its resolveId/load match the
|
|
209
|
-
// synthetic input ids that `wrapInputWithSideEffects` produces.
|
|
210
|
-
...(virtualEntries.plugin ? [virtualEntries.plugin] : []),
|
|
211
|
-
// Strip leading #! from any input module BEFORE bundling — otherwise
|
|
212
|
-
// a shebang in e.g. the CLI's own entry file ends up embedded
|
|
213
|
-
// mid-chunk after our process-stub banner, and acorn (auto-globals
|
|
214
|
-
// detector) rejects the `#` byte. Final-output shebang is composed
|
|
215
|
-
// by shebangPlugin's renderChunk hook.
|
|
216
|
-
inputShebangStripPlugin(),
|
|
217
|
-
// random-access-file's 'browser' field maps to a throwing stub; force
|
|
218
|
-
// the fs-backed Node entry. Implemented via the gjsify alias plugin
|
|
219
|
-
// as a direct entry-table override.
|
|
220
|
-
aliasPlugin({
|
|
221
|
-
entries: {
|
|
222
|
-
'random-access-file': 'random-access-file/index.js',
|
|
223
|
-
...flattenAliases(aliasMap),
|
|
224
|
-
},
|
|
225
|
-
}),
|
|
226
|
-
blueprintPlugin() as RolldownPluginOption,
|
|
227
|
-
deepkitPlugin({ reflection: input.pluginOptions.reflection }),
|
|
228
|
-
// GTK4's CSS engine is much older than browser engines — its
|
|
229
|
-
// parser predates nesting + many modern selectors. Targeting
|
|
230
|
-
// `firefox: 60 << 16` makes lightningcss flatten the source
|
|
231
|
-
// into the subset GTK4 understands.
|
|
232
|
-
cssAsStringPlugin({ targets: { firefox: 60 << 16 } }),
|
|
233
|
-
nodeModulesPathRewritePlugin({ bundleDir }),
|
|
234
|
-
processStubPlugin({ userBanner: input.userBanner }),
|
|
235
|
-
// resolveShebangLine returns null when disabled (false/undefined) and
|
|
236
|
-
// the resolved line otherwise — also handles `${env:…}` expansion.
|
|
237
|
-
(() => {
|
|
238
|
-
const line = resolveShebangLine(input.shebang);
|
|
239
|
-
return shebangPlugin({ enabled: line !== null, line: line ?? undefined });
|
|
240
|
-
})(),
|
|
241
|
-
];
|
|
242
|
-
|
|
243
|
-
return { options, plugins };
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
interface VirtualEntriesResult {
|
|
247
|
-
input: RolldownOptions['input'];
|
|
248
|
-
plugin: RolldownPluginOption | null;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* If there are side-effect imports to land alongside the user's entry,
|
|
253
|
-
* wrap each entry in a virtual module that imports them first then
|
|
254
|
-
* re-exports the entry. Returns the rewritten `input` plus the resolveId/load
|
|
255
|
-
* plugin that resolves the virtual ids.
|
|
256
|
-
*
|
|
257
|
-
* Single-input case: `'src/index.ts'` → `'\0gjsify-entry:src/index.ts'`.
|
|
258
|
-
* Array-input case: each element gets the same wrapper id.
|
|
259
|
-
* Record-input case: values get wrapped, keys preserved.
|
|
260
|
-
*
|
|
261
|
-
* `\0`-prefixed ids are Rollup's convention for synthetic modules — Rolldown
|
|
262
|
-
* recognises and treats them as not-from-disk, skipping the default loader.
|
|
263
|
-
*/
|
|
264
|
-
function wrapInputWithSideEffects(
|
|
265
|
-
input: RolldownOptions['input'],
|
|
266
|
-
sideEffects: string[],
|
|
267
|
-
): VirtualEntriesResult {
|
|
268
|
-
if (sideEffects.length === 0 || input === undefined) {
|
|
269
|
-
return { input, plugin: null };
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const userEntries = new Map<string, string>(); // virtualId → realPath
|
|
273
|
-
const PREFIX = '\0gjsify-entry:';
|
|
274
|
-
|
|
275
|
-
function wrap(realPath: string): string {
|
|
276
|
-
const id = PREFIX + realPath;
|
|
277
|
-
userEntries.set(id, realPath);
|
|
278
|
-
return id;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
let wrappedInput: RolldownOptions['input'];
|
|
282
|
-
if (typeof input === 'string') {
|
|
283
|
-
wrappedInput = wrap(input);
|
|
284
|
-
} else if (Array.isArray(input)) {
|
|
285
|
-
wrappedInput = input.map(wrap);
|
|
286
|
-
} else {
|
|
287
|
-
const out: Record<string, string> = {};
|
|
288
|
-
for (const [name, path] of Object.entries(input)) {
|
|
289
|
-
out[name] = wrap(path);
|
|
290
|
-
}
|
|
291
|
-
wrappedInput = out;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const sideEffectImports = sideEffects
|
|
295
|
-
.map((p) => `import ${JSON.stringify(p)};`)
|
|
296
|
-
.join('\n');
|
|
297
|
-
|
|
298
|
-
const plugin: RolldownPluginOption = {
|
|
299
|
-
name: 'gjsify-virtual-entry',
|
|
300
|
-
async resolveId(source, importer) {
|
|
301
|
-
if (source.startsWith(PREFIX)) return source;
|
|
302
|
-
return null;
|
|
303
|
-
},
|
|
304
|
-
async load(id) {
|
|
305
|
-
if (!id.startsWith(PREFIX)) return null;
|
|
306
|
-
const realPath = userEntries.get(id);
|
|
307
|
-
if (!realPath) return null;
|
|
308
|
-
// Resolve the user-provided entry path through the full
|
|
309
|
-
// resolver chain so the re-export targets a real on-disk
|
|
310
|
-
// module — otherwise Rolldown treats `src/foo.ts` as a bare
|
|
311
|
-
// specifier and emits it as an external import.
|
|
312
|
-
const resolved = await this.resolve(realPath, undefined, { skipSelf: true });
|
|
313
|
-
const target = resolved?.id ?? realPath;
|
|
314
|
-
return {
|
|
315
|
-
code: `${sideEffectImports}\nexport * from ${JSON.stringify(target)};\n`,
|
|
316
|
-
moduleSideEffects: true,
|
|
317
|
-
};
|
|
318
|
-
},
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
return { input: wrappedInput, plugin };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Flatten the legacy `Record<string, string>` alias map into the
|
|
326
|
-
* `@rollup/plugin-alias` `entries` array shape, dropping empty values.
|
|
327
|
-
*/
|
|
328
|
-
function flattenAliases(map: Record<string, string>): Record<string, string> {
|
|
329
|
-
const out: Record<string, string> = {};
|
|
330
|
-
for (const [from, to] of Object.entries(map)) {
|
|
331
|
-
if (to) out[from] = to;
|
|
332
|
-
}
|
|
333
|
-
return out;
|
|
334
|
-
}
|
package/src/app/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { setupForGjs } from './gjs.js';
|
|
2
|
-
export type { GjsBuildConfig, GjsFactoryInput } from './gjs.js';
|
|
3
|
-
export { setupForNode } from './node.js';
|
|
4
|
-
export type { NodeBuildConfig, NodeFactoryInput } from './node.js';
|
|
5
|
-
export { setupForBrowser } from './browser.js';
|
|
6
|
-
export type { BrowserBuildConfig, BrowserFactoryInput } from './browser.js';
|