@gjsify/rolldown-plugin-gjsify 0.7.5 → 0.9.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/app/gjs.js +19 -2
- package/lib/plugins/css-as-string.js +2 -2
- package/lib/types/plugin-options.d.ts +13 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/runtime.d.ts +18 -0
- package/lib/utils/runtime.js +39 -0
- package/package.json +11 -7
package/lib/app/gjs.js
CHANGED
|
@@ -109,7 +109,9 @@ export const setupForGjs = async (input) => {
|
|
|
109
109
|
const sideEffectImports = [];
|
|
110
110
|
if (input.pluginOptions.autoGlobalsInject)
|
|
111
111
|
sideEffectImports.push(input.pluginOptions.autoGlobalsInject);
|
|
112
|
-
const virtualEntries = wrapInputWithSideEffects(entryPoints, sideEffectImports
|
|
112
|
+
const virtualEntries = wrapInputWithSideEffects(entryPoints, sideEffectImports, {
|
|
113
|
+
preserveDefaultExport: input.pluginOptions.preserveDefaultExport === true,
|
|
114
|
+
});
|
|
113
115
|
const finalInput = virtualEntries.input;
|
|
114
116
|
const options = {
|
|
115
117
|
input: finalInput,
|
|
@@ -230,7 +232,7 @@ export const setupForGjs = async (input) => {
|
|
|
230
232
|
* `\0`-prefixed ids are Rollup's convention for synthetic modules — Rolldown
|
|
231
233
|
* recognises and treats them as not-from-disk, skipping the default loader.
|
|
232
234
|
*/
|
|
233
|
-
function wrapInputWithSideEffects(input, sideEffects) {
|
|
235
|
+
function wrapInputWithSideEffects(input, sideEffects, opts = {}) {
|
|
234
236
|
if (sideEffects.length === 0 || input === undefined) {
|
|
235
237
|
return { input, plugin: null };
|
|
236
238
|
}
|
|
@@ -292,6 +294,21 @@ function wrapInputWithSideEffects(input, sideEffects) {
|
|
|
292
294
|
// resolveId-side `moduleSideEffects: 'no-treeshake'` mark
|
|
293
295
|
// forces the body to run — `run({...})` calls in test entries,
|
|
294
296
|
// top-level await, etc.
|
|
297
|
+
//
|
|
298
|
+
// `export *` also never carries the `default` export. For an
|
|
299
|
+
// executable that's irrelevant, but a library bundle imported for
|
|
300
|
+
// its default API (a bundler plugin) needs it preserved. When
|
|
301
|
+
// requested, import the target as a namespace (which also runs the
|
|
302
|
+
// body, so it doubles as the side-effect import) and re-export its
|
|
303
|
+
// `default` — safely `undefined` when the entry has none.
|
|
304
|
+
if (opts.preserveDefaultExport) {
|
|
305
|
+
const ns = '__gjsify_entry__';
|
|
306
|
+
return {
|
|
307
|
+
code: `${sideEffectImports}\nimport * as ${ns} from ${JSON.stringify(target)};\n` +
|
|
308
|
+
`export * from ${JSON.stringify(target)};\nexport default ${ns}.default;\n`,
|
|
309
|
+
moduleSideEffects: 'no-treeshake',
|
|
310
|
+
};
|
|
311
|
+
}
|
|
295
312
|
return {
|
|
296
313
|
code: `${sideEffectImports}\nimport ${JSON.stringify(target)};\nexport * from ${JSON.stringify(target)};\n`,
|
|
297
314
|
moduleSideEffects: 'no-treeshake',
|
|
@@ -39,6 +39,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
39
39
|
import { createRequire } from 'node:module';
|
|
40
40
|
import { dirname, isAbsolute, resolve as resolvePath } from 'node:path';
|
|
41
41
|
import { pathToFileURL } from 'node:url';
|
|
42
|
+
import { isGjs } from '../utils/runtime.js';
|
|
42
43
|
let _bundlerPromise = null;
|
|
43
44
|
async function pickBundler() {
|
|
44
45
|
const forced = globalThis.process?.env
|
|
@@ -58,8 +59,7 @@ async function tryLoadNativeBundler() {
|
|
|
58
59
|
// The native bridge only exists under GJS — `imports.gi` marker. Skip
|
|
59
60
|
// the dynamic import entirely on Node so it doesn't even register as a
|
|
60
61
|
// resolved dep, which would inflate the CLI's bundled output.
|
|
61
|
-
|
|
62
|
-
if (!isGjs)
|
|
62
|
+
if (!isGjs())
|
|
63
63
|
return null;
|
|
64
64
|
try {
|
|
65
65
|
// Indirect specifier so tsc + Rolldown don't try to resolve the
|
|
@@ -43,4 +43,17 @@ export interface PluginOptions {
|
|
|
43
43
|
* applies to `--app gjs`.
|
|
44
44
|
*/
|
|
45
45
|
autoGlobalsInject?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Preserve the entry module's `default` export through the `--app gjs`
|
|
48
|
+
* side-effect entry wrapper. The wrapper normally re-exports the entry with
|
|
49
|
+
* `export * from <entry>`, which carries named bindings but NOT `default`.
|
|
50
|
+
* That's correct for executables (run, not imported), but wrong when the
|
|
51
|
+
* bundle is imported as a library whose API is a default export — e.g. a
|
|
52
|
+
* bundler plugin bundled for GJS by `gjsify build`'s plugin loader, where
|
|
53
|
+
* the plugin factory IS the default export. When set, the wrapper also
|
|
54
|
+
* re-exports `default` (safely `undefined` when the entry has none).
|
|
55
|
+
* Only meaningful for `--app gjs` and only when globals injection forces
|
|
56
|
+
* the wrapper. Defaults to `false`.
|
|
57
|
+
*/
|
|
58
|
+
preserveDefaultExport?: boolean;
|
|
46
59
|
}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './alias.js';
|
|
2
2
|
export * from './entry-points.js';
|
|
3
3
|
export * from './extension.js';
|
|
4
|
+
export * from './runtime.js';
|
|
4
5
|
export * from './merge.js';
|
|
5
6
|
export { detectFreeGlobals } from './detect-free-globals.js';
|
|
6
7
|
export { resolveGlobalsList, writeRegisterInjectFile } from './scan-globals.js';
|
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './alias.js';
|
|
2
2
|
export * from './entry-points.js';
|
|
3
3
|
export * from './extension.js';
|
|
4
|
+
export * from './runtime.js';
|
|
4
5
|
export * from './merge.js';
|
|
5
6
|
export { detectFreeGlobals } from './detect-free-globals.js';
|
|
6
7
|
export { resolveGlobalsList, writeRegisterInjectFile } from './scan-globals.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `true` when running under GJS (GNOME JavaScript / SpiderMonkey).
|
|
3
|
+
*
|
|
4
|
+
* Detected via the GObject-Introspection bridge `globalThis.imports.gi`, which
|
|
5
|
+
* only exists under GJS — Node and browsers never expose it. This is the
|
|
6
|
+
* canonical gjsify host probe; prefer it over re-inlining the `imports.gi`
|
|
7
|
+
* check.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isGjs(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* `true` when running under Node.js.
|
|
12
|
+
*
|
|
13
|
+
* GJS is checked FIRST and short-circuits to `false`: `@gjsify/process` sets
|
|
14
|
+
* `process.versions.node` (for npm-package compatibility), so a bare
|
|
15
|
+
* `process.versions.node` probe is a false Node positive under GJS. Guarding
|
|
16
|
+
* with `isGjs()` keeps the two host predicates mutually exclusive.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isNode(): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Host-runtime detection for the gjsify build tooling.
|
|
2
|
+
//
|
|
3
|
+
// `@gjsify/cli` and `@gjsify/rolldown-plugin-gjsify` both run under BOTH Node
|
|
4
|
+
// and GJS — the CLI ships a Node entry (`lib/index.js`) AND a committed GJS
|
|
5
|
+
// bundle (`dist/cli.gjs.mjs`). Several code paths branch on the host: the
|
|
6
|
+
// bundler-engine pick (native rolldown vs npm crate), oxc resolution, plugin
|
|
7
|
+
// loading, CSS lowering. Before this module each of those re-inlined the same
|
|
8
|
+
// `typeof globalThis.imports?.gi !== 'undefined'` probe; this is the single
|
|
9
|
+
// source of truth for them.
|
|
10
|
+
//
|
|
11
|
+
// Kept deliberately pure — no `gi://` / `@girs/*` imports, no side effects —
|
|
12
|
+
// so it stays loadable on every host and so consumers can import it via the
|
|
13
|
+
// `@gjsify/rolldown-plugin-gjsify/runtime` subpath without pulling the rest of
|
|
14
|
+
// the plugin (which transitively loads blueprint-compiler, deepkit, etc.).
|
|
15
|
+
/**
|
|
16
|
+
* `true` when running under GJS (GNOME JavaScript / SpiderMonkey).
|
|
17
|
+
*
|
|
18
|
+
* Detected via the GObject-Introspection bridge `globalThis.imports.gi`, which
|
|
19
|
+
* only exists under GJS — Node and browsers never expose it. This is the
|
|
20
|
+
* canonical gjsify host probe; prefer it over re-inlining the `imports.gi`
|
|
21
|
+
* check.
|
|
22
|
+
*/
|
|
23
|
+
export function isGjs() {
|
|
24
|
+
return typeof globalThis.imports?.gi !== 'undefined';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `true` when running under Node.js.
|
|
28
|
+
*
|
|
29
|
+
* GJS is checked FIRST and short-circuits to `false`: `@gjsify/process` sets
|
|
30
|
+
* `process.versions.node` (for npm-package compatibility), so a bare
|
|
31
|
+
* `process.versions.node` probe is a false Node positive under GJS. Guarding
|
|
32
|
+
* with `isGjs()` keeps the two host predicates mutually exclusive.
|
|
33
|
+
*/
|
|
34
|
+
export function isNode() {
|
|
35
|
+
if (isGjs())
|
|
36
|
+
return false;
|
|
37
|
+
const proc = globalThis.process;
|
|
38
|
+
return typeof proc?.versions?.node === 'string';
|
|
39
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/rolldown-plugin-gjsify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"types": "./lib/globals.d.ts",
|
|
16
16
|
"default": "./lib/globals.js"
|
|
17
17
|
},
|
|
18
|
+
"./runtime": {
|
|
19
|
+
"types": "./lib/utils/runtime.d.ts",
|
|
20
|
+
"default": "./lib/utils/runtime.js"
|
|
21
|
+
},
|
|
18
22
|
"./shims/console-gjs": {
|
|
19
23
|
"default": "./lib/shims/console-gjs.js"
|
|
20
24
|
},
|
|
@@ -51,11 +55,11 @@
|
|
|
51
55
|
],
|
|
52
56
|
"license": "MIT",
|
|
53
57
|
"dependencies": {
|
|
54
|
-
"@gjsify/console": "^0.
|
|
55
|
-
"@gjsify/resolve-npm": "^0.
|
|
56
|
-
"@gjsify/rolldown-plugin-deepkit": "^0.
|
|
57
|
-
"@gjsify/rolldown-plugin-pnp": "^0.
|
|
58
|
-
"@gjsify/vite-plugin-blueprint": "^0.
|
|
58
|
+
"@gjsify/console": "^0.9.0",
|
|
59
|
+
"@gjsify/resolve-npm": "^0.9.0",
|
|
60
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.9.0",
|
|
61
|
+
"@gjsify/rolldown-plugin-pnp": "^0.9.0",
|
|
62
|
+
"@gjsify/vite-plugin-blueprint": "^0.9.0",
|
|
59
63
|
"@rollup/pluginutils": "^5.4.0",
|
|
60
64
|
"acorn": "^8.16.0",
|
|
61
65
|
"acorn-walk": "^8.3.5",
|
|
@@ -63,7 +67,7 @@
|
|
|
63
67
|
"lightningcss": "^1.32.0"
|
|
64
68
|
},
|
|
65
69
|
"peerDependencies": {
|
|
66
|
-
"@gjsify/lightningcss-native": "^0.
|
|
70
|
+
"@gjsify/lightningcss-native": "^0.9.0",
|
|
67
71
|
"rolldown": "^1.1.0"
|
|
68
72
|
},
|
|
69
73
|
"peerDependenciesMeta": {
|