@gjsify/rolldown-plugin-gjsify 0.9.0 → 0.11.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/globals.d.ts +1 -1
- package/lib/globals.js +1 -1
- package/lib/utils/auto-globals.d.ts +15 -0
- package/lib/utils/auto-globals.js +100 -9
- package/package.json +7 -7
package/lib/globals.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { resolveGlobalsList, writeRegisterInjectFile, isRegisterPathResolvable, filterResolvableRegisterPaths } from './utils/scan-globals.js';
|
|
2
2
|
export { detectFreeGlobals } from './utils/detect-free-globals.js';
|
|
3
|
-
export { detectAutoGlobals } from './utils/auto-globals.js';
|
|
3
|
+
export { detectAutoGlobals, describeGiBackedInjection } from './utils/auto-globals.js';
|
|
4
4
|
export type { AutoGlobalsResult, DetectAutoGlobalsOptions, AnalysisOptions } from './utils/auto-globals.js';
|
package/lib/globals.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
// "Tree-shakeable Globals" section in AGENTS.md for the architecture.
|
|
7
7
|
export { resolveGlobalsList, writeRegisterInjectFile, isRegisterPathResolvable, filterResolvableRegisterPaths } from './utils/scan-globals.js';
|
|
8
8
|
export { detectFreeGlobals } from './utils/detect-free-globals.js';
|
|
9
|
-
export { detectAutoGlobals } from './utils/auto-globals.js';
|
|
9
|
+
export { detectAutoGlobals, describeGiBackedInjection } from './utils/auto-globals.js';
|
|
@@ -21,6 +21,21 @@ export interface AutoGlobalsResult {
|
|
|
21
21
|
/** Path to the generated inject stub, or undefined if no globals needed */
|
|
22
22
|
injectPath: string | undefined;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the build-time note for any GI-backed register modules in a final
|
|
26
|
+
* inject set, or null when none are GI-backed. Pure (no I/O) so it is
|
|
27
|
+
* unit-testable; `emitGiBackedDiagnostic` is the side-effecting wrapper.
|
|
28
|
+
*
|
|
29
|
+
* `--globals auto` injecting a GI-backed register makes the bundle
|
|
30
|
+
* hard-require a GTK/GNOME runtime at load — under a GTK-less host (headless
|
|
31
|
+
* type-check container, SSR generator, plain CI) it throws `Typelib … not
|
|
32
|
+
* found`. The note names which globals triggered the injection so that
|
|
33
|
+
* otherwise-silent runtime crash is traceable at build time.
|
|
34
|
+
*
|
|
35
|
+
* @param registerPaths the final register paths to be injected
|
|
36
|
+
* @param detected the converged detected-global set (for naming trigger refs)
|
|
37
|
+
*/
|
|
38
|
+
export declare function describeGiBackedInjection(registerPaths: Set<string>, detected: Set<string>): string | null;
|
|
24
39
|
export interface DetectAutoGlobalsOptions {
|
|
25
40
|
/**
|
|
26
41
|
* Extra explicit identifiers (or group aliases like `dom`/`web`/`node`)
|
|
@@ -37,11 +37,12 @@ const defaultBundler = async ({ rolldownInput, format }) => {
|
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
39
|
import { detectFreeGlobals } from './detect-free-globals.js';
|
|
40
|
-
import { resolveGlobalsList, writeRegisterInjectFile, filterResolvableRegisterPaths } from './scan-globals.js';
|
|
41
|
-
import { GJS_GLOBALS_MAP } from '@gjsify/resolve-npm/globals-map';
|
|
40
|
+
import { resolveGlobalsList, writeRegisterInjectFile, filterResolvableRegisterPaths, isRegisterPathResolvable, } from './scan-globals.js';
|
|
41
|
+
import { GJS_GLOBALS_MAP, GJS_GI_BACKED_REGISTERS } from '@gjsify/resolve-npm/globals-map';
|
|
42
42
|
import { REGISTER_GLOBALS_CLOSURE } from '@gjsify/resolve-npm/register-globals-closure';
|
|
43
43
|
const GLOBALS_MAP = GJS_GLOBALS_MAP;
|
|
44
44
|
const CLOSURE_MAP = REGISTER_GLOBALS_CLOSURE;
|
|
45
|
+
const GI_BACKED = GJS_GI_BACKED_REGISTERS;
|
|
45
46
|
/** Maximum iterations to prevent runaway loops on pathological inputs. */
|
|
46
47
|
const MAX_ITERATIONS = 5;
|
|
47
48
|
/**
|
|
@@ -90,15 +91,23 @@ function isSubset(a, b) {
|
|
|
90
91
|
return true;
|
|
91
92
|
}
|
|
92
93
|
async function applyExcludeGlobals(detected, currentInject, extraRegisterPaths, excludeGlobals, cwd) {
|
|
94
|
+
if (excludeGlobals?.length) {
|
|
95
|
+
for (const id of excludeGlobals)
|
|
96
|
+
detected.delete(id);
|
|
97
|
+
}
|
|
98
|
+
// Final register set that will be injected (detected → register paths,
|
|
99
|
+
// plus any --globals auto,<extras>). Computed for BOTH paths so the
|
|
100
|
+
// GI-backed diagnostic below fires whether or not excludeGlobals is set.
|
|
101
|
+
const finalPaths = detectedToRegisterPaths(detected);
|
|
102
|
+
for (const p of extraRegisterPaths)
|
|
103
|
+
finalPaths.add(p);
|
|
104
|
+
emitGiBackedDiagnostic(finalPaths, detected, cwd);
|
|
105
|
+
// No exclude: `currentInject` already reflects `finalPaths` (built in the
|
|
106
|
+
// loop), so reuse it — re-running filterResolvableRegisterPaths here would
|
|
107
|
+
// emit its skip warnings a second time.
|
|
93
108
|
if (!excludeGlobals?.length)
|
|
94
109
|
return { detected, injectPath: currentInject };
|
|
95
|
-
|
|
96
|
-
detected.delete(id);
|
|
97
|
-
let filtered = detectedToRegisterPaths(detected);
|
|
98
|
-
for (const p of extraRegisterPaths)
|
|
99
|
-
filtered.add(p);
|
|
100
|
-
if (cwd)
|
|
101
|
-
filtered = filterResolvableRegisterPaths(filtered, cwd);
|
|
110
|
+
const filtered = cwd ? filterResolvableRegisterPaths(finalPaths, cwd) : finalPaths;
|
|
102
111
|
const injectPath = filtered.size > 0 ? ((await writeRegisterInjectFile(filtered, cwd)) ?? undefined) : undefined;
|
|
103
112
|
return { detected, injectPath };
|
|
104
113
|
}
|
|
@@ -111,6 +120,88 @@ function detectedToRegisterPaths(detected) {
|
|
|
111
120
|
}
|
|
112
121
|
return paths;
|
|
113
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* GI namespaces a register path pulls at import, or null when it is not
|
|
125
|
+
* GI-backed. Prefix match against `GJS_GI_BACKED_REGISTERS` so one entry per
|
|
126
|
+
* package covers every granular subpath (`…/register/document`, `…/register/canvas`).
|
|
127
|
+
*/
|
|
128
|
+
function giNamespacesForRegister(registerPath) {
|
|
129
|
+
for (const prefix of Object.keys(GI_BACKED)) {
|
|
130
|
+
if (registerPath === prefix || registerPath.startsWith(prefix + '/')) {
|
|
131
|
+
return GI_BACKED[prefix];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Build the build-time note for any GI-backed register modules in a final
|
|
138
|
+
* inject set, or null when none are GI-backed. Pure (no I/O) so it is
|
|
139
|
+
* unit-testable; `emitGiBackedDiagnostic` is the side-effecting wrapper.
|
|
140
|
+
*
|
|
141
|
+
* `--globals auto` injecting a GI-backed register makes the bundle
|
|
142
|
+
* hard-require a GTK/GNOME runtime at load — under a GTK-less host (headless
|
|
143
|
+
* type-check container, SSR generator, plain CI) it throws `Typelib … not
|
|
144
|
+
* found`. The note names which globals triggered the injection so that
|
|
145
|
+
* otherwise-silent runtime crash is traceable at build time.
|
|
146
|
+
*
|
|
147
|
+
* @param registerPaths the final register paths to be injected
|
|
148
|
+
* @param detected the converged detected-global set (for naming trigger refs)
|
|
149
|
+
*/
|
|
150
|
+
export function describeGiBackedInjection(registerPaths, detected) {
|
|
151
|
+
const giRegisters = new Set();
|
|
152
|
+
const namespaces = new Set();
|
|
153
|
+
for (const path of registerPaths) {
|
|
154
|
+
const gi = giNamespacesForRegister(path);
|
|
155
|
+
if (!gi)
|
|
156
|
+
continue;
|
|
157
|
+
giRegisters.add(path);
|
|
158
|
+
for (const ns of gi)
|
|
159
|
+
namespaces.add(ns);
|
|
160
|
+
}
|
|
161
|
+
if (giRegisters.size === 0)
|
|
162
|
+
return null;
|
|
163
|
+
const triggers = [...detected]
|
|
164
|
+
.filter((id) => {
|
|
165
|
+
const p = GLOBALS_MAP[id];
|
|
166
|
+
return !!p && giRegisters.has(p);
|
|
167
|
+
})
|
|
168
|
+
.sort();
|
|
169
|
+
const giList = [...namespaces]
|
|
170
|
+
.sort()
|
|
171
|
+
.map((n) => `gi://${n}`)
|
|
172
|
+
.join(', ');
|
|
173
|
+
return ('[gjsify] note: --globals auto injected GTK/GNOME-backed register(s) — this bundle now requires ' +
|
|
174
|
+
`${giList} at load.` +
|
|
175
|
+
(triggers.length ? ` Triggered by: ${triggers.join(', ')}.` : '') +
|
|
176
|
+
' If it runs headless / SSR / in a GTK-less container it will throw "Typelib … not found"; drop those ' +
|
|
177
|
+
'globals via excludeGlobals or pin an explicit --globals allowlist (e.g. node).');
|
|
178
|
+
}
|
|
179
|
+
/** Emitted at most once per process so multi-pass / multi-build runs stay quiet. */
|
|
180
|
+
let giNoteEmitted = false;
|
|
181
|
+
/**
|
|
182
|
+
* console.warn the GI-backed-injection note once per process. Pre-filters
|
|
183
|
+
* `registerPaths` to the ones that will ACTUALLY be injected — GI-backed AND
|
|
184
|
+
* (quietly) resolvable from the project — so the note never mentions a
|
|
185
|
+
* register that gets dropped. Uses `isRegisterPathResolvable` (no warning),
|
|
186
|
+
* not `filterResolvableRegisterPaths`, to avoid duplicating its skip warnings.
|
|
187
|
+
*/
|
|
188
|
+
function emitGiBackedDiagnostic(registerPaths, detected, cwd) {
|
|
189
|
+
if (giNoteEmitted)
|
|
190
|
+
return;
|
|
191
|
+
const candidates = new Set();
|
|
192
|
+
for (const path of registerPaths) {
|
|
193
|
+
if (!giNamespacesForRegister(path))
|
|
194
|
+
continue;
|
|
195
|
+
if (cwd && !isRegisterPathResolvable(path, cwd))
|
|
196
|
+
continue;
|
|
197
|
+
candidates.add(path);
|
|
198
|
+
}
|
|
199
|
+
const note = describeGiBackedInjection(candidates, detected);
|
|
200
|
+
if (!note)
|
|
201
|
+
return;
|
|
202
|
+
giNoteEmitted = true;
|
|
203
|
+
console.warn(note);
|
|
204
|
+
}
|
|
114
205
|
function isFullConfig(v) {
|
|
115
206
|
return v !== null && typeof v === 'object' && !Array.isArray(v) && 'plugins' in v && 'options' in v;
|
|
116
207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/rolldown-plugin-gjsify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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.
|
|
59
|
-
"@gjsify/resolve-npm": "^0.
|
|
60
|
-
"@gjsify/rolldown-plugin-deepkit": "^0.
|
|
61
|
-
"@gjsify/rolldown-plugin-pnp": "^0.
|
|
62
|
-
"@gjsify/vite-plugin-blueprint": "^0.
|
|
58
|
+
"@gjsify/console": "^0.11.0",
|
|
59
|
+
"@gjsify/resolve-npm": "^0.11.0",
|
|
60
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.11.0",
|
|
61
|
+
"@gjsify/rolldown-plugin-pnp": "^0.11.0",
|
|
62
|
+
"@gjsify/vite-plugin-blueprint": "^0.11.0",
|
|
63
63
|
"@rollup/pluginutils": "^5.4.0",
|
|
64
64
|
"acorn": "^8.16.0",
|
|
65
65
|
"acorn-walk": "^8.3.5",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"lightningcss": "^1.32.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@gjsify/lightningcss-native": "^0.
|
|
70
|
+
"@gjsify/lightningcss-native": "^0.11.0",
|
|
71
71
|
"rolldown": "^1.1.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|