@gjsify/cli 0.3.13 → 0.3.15
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/actions/build.d.ts +14 -93
- package/lib/actions/build.js +182 -154
- package/lib/commands/flatpak/build.d.ts +16 -0
- package/lib/commands/flatpak/build.js +187 -0
- package/lib/commands/flatpak/ci.d.ts +13 -0
- package/lib/commands/flatpak/ci.js +133 -0
- package/lib/commands/flatpak/deps.d.ts +12 -0
- package/lib/commands/flatpak/deps.js +96 -0
- package/lib/commands/flatpak/index.d.ts +7 -0
- package/lib/commands/flatpak/index.js +23 -0
- package/lib/commands/flatpak/init.d.ts +15 -0
- package/lib/commands/flatpak/init.js +154 -0
- package/lib/commands/flatpak/utils.d.ts +32 -0
- package/lib/commands/flatpak/utils.js +63 -0
- package/lib/commands/gsettings.d.ts +9 -0
- package/lib/commands/gsettings.js +72 -0
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +2 -0
- package/lib/commands/install.d.ts +1 -0
- package/lib/commands/install.js +66 -11
- package/lib/config.js +103 -11
- package/lib/index.js +3 -1
- package/lib/types/cli-build-options.d.ts +1 -1
- package/lib/types/config-data.d.ts +194 -4
- package/lib/utils/install-global.d.ts +54 -0
- package/lib/utils/install-global.js +153 -0
- package/lib/utils/normalize-bundler-options.d.ts +17 -0
- package/lib/utils/normalize-bundler-options.js +123 -0
- package/lib/utils/resolve-plugin-by-name.d.ts +21 -0
- package/lib/utils/resolve-plugin-by-name.js +75 -0
- package/package.json +11 -11
- package/src/actions/build.ts +406 -352
- package/src/commands/flatpak/build.ts +225 -0
- package/src/commands/flatpak/ci.ts +173 -0
- package/src/commands/flatpak/deps.ts +120 -0
- package/src/commands/flatpak/index.ts +53 -0
- package/src/commands/flatpak/init.ts +191 -0
- package/src/commands/flatpak/utils.ts +76 -0
- package/src/commands/gsettings.ts +87 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/install.ts +90 -11
- package/src/config.ts +103 -11
- package/src/index.ts +4 -0
- package/src/types/cli-build-options.ts +1 -1
- package/src/types/config-data.ts +191 -4
- package/src/utils/install-global.ts +182 -0
- package/src/utils/normalize-bundler-options.ts +129 -0
- package/src/utils/resolve-plugin-by-name.ts +106 -0
package/lib/actions/build.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { ConfigData } from "../types/index.js";
|
|
2
|
-
import type { App } from "@gjsify/
|
|
3
|
-
import {
|
|
2
|
+
import type { App } from "@gjsify/rolldown-plugin-gjsify";
|
|
3
|
+
import type { RolldownOutput } from "rolldown";
|
|
4
4
|
export declare class BuildAction {
|
|
5
5
|
readonly configData: ConfigData;
|
|
6
6
|
constructor(configData?: ConfigData);
|
|
7
|
-
getEsBuildDefaults(): BuildOptions;
|
|
8
7
|
/** Library mode */
|
|
9
|
-
buildLibrary(): Promise<
|
|
8
|
+
buildLibrary(): Promise<RolldownOutput[]>;
|
|
10
9
|
/**
|
|
11
10
|
* Parse the `--globals` value into { autoMode, extras }.
|
|
12
11
|
* - `auto` → { autoMode: true, extras: '' }
|
|
@@ -19,104 +18,26 @@ export declare class BuildAction {
|
|
|
19
18
|
private parseGlobalsValue;
|
|
20
19
|
/**
|
|
21
20
|
* Resolve the `--globals` CLI list into a pre-computed inject stub path
|
|
22
|
-
* that the
|
|
23
|
-
*
|
|
21
|
+
* that the orchestrator appends to its input list. Only runs for
|
|
22
|
+
* `--app gjs` — Node and browser builds rely on native globals.
|
|
24
23
|
*
|
|
25
24
|
* Used only for the explicit-only path (no `auto` token in the value).
|
|
26
|
-
* The auto path is handled in `buildApp` via the
|
|
25
|
+
* The auto path is handled in `buildApp` via the iterative multi-pass build.
|
|
27
26
|
*/
|
|
28
27
|
private resolveGlobalsInject;
|
|
29
28
|
/**
|
|
30
|
-
* Post-processing: prepend
|
|
31
|
-
* Only runs for GJS app builds with a
|
|
29
|
+
* Post-processing: prepend the resolved shebang line and mark the
|
|
30
|
+
* output executable. Only runs for GJS app builds with a single outfile.
|
|
31
|
+
* The shebang plugin in `@gjsify/rolldown-plugin-gjsify` already injects
|
|
32
|
+
* during bundling — this hook is the safety net for anything that
|
|
33
|
+
* bypassed the plugin (e.g. user-supplied banners that out-ordered it),
|
|
34
|
+
* plus the chmod.
|
|
32
35
|
*/
|
|
33
36
|
private applyShebang;
|
|
34
37
|
/** Application mode */
|
|
35
|
-
buildApp(app?: App): Promise<
|
|
36
|
-
format: "esm" | "cjs";
|
|
37
|
-
plugins: Plugin[];
|
|
38
|
-
bundle?: boolean;
|
|
39
|
-
splitting?: boolean;
|
|
40
|
-
preserveSymlinks?: boolean;
|
|
41
|
-
outfile?: string;
|
|
42
|
-
metafile?: boolean;
|
|
43
|
-
outdir?: string;
|
|
44
|
-
outbase?: string;
|
|
45
|
-
external?: string[];
|
|
46
|
-
packages?: "bundle" | "external";
|
|
47
|
-
alias?: Record<string, string>;
|
|
48
|
-
loader?: {
|
|
49
|
-
[ext: string]: import("esbuild").Loader;
|
|
50
|
-
};
|
|
51
|
-
resolveExtensions?: string[];
|
|
52
|
-
mainFields?: string[];
|
|
53
|
-
conditions?: string[];
|
|
54
|
-
write?: boolean;
|
|
55
|
-
allowOverwrite?: boolean;
|
|
56
|
-
tsconfig?: string;
|
|
57
|
-
outExtension?: {
|
|
58
|
-
[ext: string]: string;
|
|
59
|
-
};
|
|
60
|
-
publicPath?: string;
|
|
61
|
-
entryNames?: string;
|
|
62
|
-
chunkNames?: string;
|
|
63
|
-
assetNames?: string;
|
|
64
|
-
inject?: string[];
|
|
65
|
-
banner?: {
|
|
66
|
-
[type: string]: string;
|
|
67
|
-
};
|
|
68
|
-
footer?: {
|
|
69
|
-
[type: string]: string;
|
|
70
|
-
};
|
|
71
|
-
entryPoints?: (string | {
|
|
72
|
-
in: string;
|
|
73
|
-
out: string;
|
|
74
|
-
})[] | Record<string, string>;
|
|
75
|
-
stdin?: import("esbuild").StdinOptions;
|
|
76
|
-
absWorkingDir?: string;
|
|
77
|
-
nodePaths?: string[];
|
|
78
|
-
sourcemap?: boolean | "linked" | "inline" | "external" | "both";
|
|
79
|
-
legalComments?: "none" | "inline" | "eof" | "linked" | "external";
|
|
80
|
-
sourceRoot?: string;
|
|
81
|
-
sourcesContent?: boolean;
|
|
82
|
-
globalName?: string;
|
|
83
|
-
target?: string | string[];
|
|
84
|
-
supported?: Record<string, boolean>;
|
|
85
|
-
platform?: import("esbuild").Platform;
|
|
86
|
-
mangleProps?: RegExp;
|
|
87
|
-
reserveProps?: RegExp;
|
|
88
|
-
mangleQuoted?: boolean;
|
|
89
|
-
mangleCache?: Record<string, string | false>;
|
|
90
|
-
drop?: import("esbuild").Drop[];
|
|
91
|
-
dropLabels?: string[];
|
|
92
|
-
minify?: boolean;
|
|
93
|
-
minifyWhitespace?: boolean;
|
|
94
|
-
minifyIdentifiers?: boolean;
|
|
95
|
-
minifySyntax?: boolean;
|
|
96
|
-
lineLimit?: number;
|
|
97
|
-
charset?: import("esbuild").Charset;
|
|
98
|
-
treeShaking?: boolean;
|
|
99
|
-
ignoreAnnotations?: boolean;
|
|
100
|
-
jsx?: "transform" | "preserve" | "automatic";
|
|
101
|
-
jsxFactory?: string;
|
|
102
|
-
jsxFragment?: string;
|
|
103
|
-
jsxImportSource?: string;
|
|
104
|
-
jsxDev?: boolean;
|
|
105
|
-
jsxSideEffects?: boolean;
|
|
106
|
-
define?: {
|
|
107
|
-
[key: string]: string;
|
|
108
|
-
};
|
|
109
|
-
pure?: string[];
|
|
110
|
-
keepNames?: boolean;
|
|
111
|
-
absPaths?: import("esbuild").AbsPaths[];
|
|
112
|
-
color?: boolean;
|
|
113
|
-
logLevel?: import("esbuild").LogLevel;
|
|
114
|
-
logLimit?: number;
|
|
115
|
-
logOverride?: Record<string, import("esbuild").LogLevel>;
|
|
116
|
-
tsconfigRaw?: string | import("esbuild").TsconfigRaw;
|
|
117
|
-
}>[]>;
|
|
38
|
+
buildApp(app?: App): Promise<RolldownOutput[]>;
|
|
118
39
|
start(buildType?: {
|
|
119
40
|
library?: boolean;
|
|
120
41
|
app?: App;
|
|
121
|
-
}): Promise<
|
|
42
|
+
}): Promise<RolldownOutput[]>;
|
|
122
43
|
}
|
package/lib/actions/build.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { gjsifyPlugin } from "@gjsify/
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { rolldown } from "rolldown";
|
|
2
|
+
import { gjsifyPlugin, textLoaderPlugin, resolveShebangLine } from "@gjsify/rolldown-plugin-gjsify";
|
|
3
|
+
import { resolveUserPlugins } from "../utils/resolve-plugin-by-name.js";
|
|
4
|
+
import { resolveGlobalsList, writeRegisterInjectFile, detectAutoGlobals, } from "@gjsify/rolldown-plugin-gjsify/globals";
|
|
5
|
+
import { pnpPlugin } from "@gjsify/rolldown-plugin-pnp";
|
|
6
6
|
import { dirname, extname } from "node:path";
|
|
7
7
|
import { chmod, readFile, writeFile } from "node:fs/promises";
|
|
8
|
-
|
|
8
|
+
import { normalizeBundlerOptions, mergeBundlerOptions } from "../utils/normalize-bundler-options.js";
|
|
9
|
+
const DEFAULT_GJS_SHEBANG = "#!/usr/bin/env -S gjs -m";
|
|
9
10
|
/**
|
|
10
11
|
* `true` when `path` points at a location that's unsafe to use as a build
|
|
11
12
|
* outfile (would overwrite source). Currently catches:
|
|
@@ -26,104 +27,81 @@ function isUnsafeDefaultOutput(path) {
|
|
|
26
27
|
* @gjsify/{node,web}-polyfills) are resolvable for external consumers without
|
|
27
28
|
* each one having to be a direct devDep.
|
|
28
29
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* inside the pnp plugin's onLoad rather than as a separate registration.
|
|
30
|
+
* The path rewriter (`__filename`/`__dirname` + `import.meta.url` injection
|
|
31
|
+
* for node_modules code) is registered separately by the orchestrator —
|
|
32
|
+
* Rolldown's transform hooks all run sequentially, no shared `onLoad` race.
|
|
33
33
|
*/
|
|
34
34
|
async function buildPnpPlugin() {
|
|
35
|
-
return
|
|
36
|
-
issuerUrl: import.meta.url,
|
|
37
|
-
transformContentsFactory: (build) => {
|
|
38
|
-
const bundleDir = getBundleDir(build);
|
|
39
|
-
return (args, contents) => rewriteContents(args, contents, bundleDir);
|
|
40
|
-
},
|
|
41
|
-
});
|
|
35
|
+
return pnpPlugin({ issuerUrl: import.meta.url });
|
|
42
36
|
}
|
|
43
37
|
export class BuildAction {
|
|
44
38
|
configData;
|
|
45
39
|
constructor(configData = {}) {
|
|
46
40
|
this.configData = configData;
|
|
47
41
|
}
|
|
48
|
-
getEsBuildDefaults() {
|
|
49
|
-
const defaults = {
|
|
50
|
-
allowOverwrite: true,
|
|
51
|
-
};
|
|
52
|
-
return defaults;
|
|
53
|
-
}
|
|
54
42
|
/** Library mode */
|
|
55
43
|
async buildLibrary() {
|
|
56
|
-
|
|
57
|
-
library
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const mainOutExt = library.main ? extname(library.main) : ".js";
|
|
44
|
+
const { verbose, library, typescript, exclude, aliases } = this.configData;
|
|
45
|
+
const lib = library ?? {};
|
|
46
|
+
const userBundler = normalizeBundlerOptions(this.configData);
|
|
47
|
+
const moduleOutdir = lib.module ? dirname(lib.module) : undefined;
|
|
48
|
+
const mainOutdir = lib.main ? dirname(lib.main) : undefined;
|
|
49
|
+
const moduleOutExt = lib.module ? extname(lib.module) : ".js";
|
|
50
|
+
const mainOutExt = lib.main ? extname(lib.main) : ".js";
|
|
64
51
|
const multipleBuilds = moduleOutdir && mainOutdir && moduleOutdir !== mainOutdir;
|
|
65
|
-
const
|
|
66
|
-
const pnpPlugins =
|
|
52
|
+
const pnp = await buildPnpPlugin();
|
|
53
|
+
const pnpPlugins = pnp ? [pnp] : [];
|
|
67
54
|
const results = [];
|
|
68
55
|
if (multipleBuilds) {
|
|
69
56
|
const moduleFormat = moduleOutdir.includes("/cjs") || moduleOutExt === ".cjs"
|
|
70
57
|
? "cjs"
|
|
71
58
|
: "esm";
|
|
72
|
-
results.push(await
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
jsExtension: moduleOutExt,
|
|
85
|
-
}),
|
|
86
|
-
],
|
|
59
|
+
results.push(await runOneLibraryBuild({
|
|
60
|
+
pluginOpts: {
|
|
61
|
+
debug: verbose,
|
|
62
|
+
library: moduleFormat,
|
|
63
|
+
exclude,
|
|
64
|
+
reflection: typescript?.reflection,
|
|
65
|
+
jsExtension: moduleOutExt,
|
|
66
|
+
},
|
|
67
|
+
userBundler,
|
|
68
|
+
output: { dir: moduleOutdir },
|
|
69
|
+
userAliases: aliases,
|
|
70
|
+
pnpPlugins,
|
|
87
71
|
}));
|
|
88
72
|
const mainFormat = mainOutdir.includes("/cjs") || mainOutExt === ".cjs" ? "cjs" : "esm";
|
|
89
|
-
results.push(await
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
jsExtension: mainOutExt,
|
|
102
|
-
}),
|
|
103
|
-
],
|
|
73
|
+
results.push(await runOneLibraryBuild({
|
|
74
|
+
pluginOpts: {
|
|
75
|
+
debug: verbose,
|
|
76
|
+
library: mainFormat,
|
|
77
|
+
exclude,
|
|
78
|
+
reflection: typescript?.reflection,
|
|
79
|
+
jsExtension: mainOutExt,
|
|
80
|
+
},
|
|
81
|
+
userBundler,
|
|
82
|
+
output: { dir: mainOutdir },
|
|
83
|
+
userAliases: aliases,
|
|
84
|
+
pnpPlugins,
|
|
104
85
|
}));
|
|
105
86
|
}
|
|
106
87
|
else {
|
|
107
|
-
const outfilePath =
|
|
88
|
+
const outfilePath = userBundler.output?.file ?? lib.module ?? lib.main;
|
|
108
89
|
const outExt = outfilePath ? extname(outfilePath) : ".js";
|
|
109
|
-
const outdir =
|
|
110
|
-
const format =
|
|
90
|
+
const outdir = userBundler.output?.dir ?? (outfilePath ? dirname(outfilePath) : undefined);
|
|
91
|
+
const format = userBundler.output?.format ??
|
|
111
92
|
(outdir?.includes("/cjs") || outExt === ".cjs" ? "cjs" : "esm");
|
|
112
|
-
results.push(await
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
jsExtension: outExt,
|
|
125
|
-
}),
|
|
126
|
-
],
|
|
93
|
+
results.push(await runOneLibraryBuild({
|
|
94
|
+
pluginOpts: {
|
|
95
|
+
debug: verbose,
|
|
96
|
+
library: format,
|
|
97
|
+
exclude,
|
|
98
|
+
reflection: typescript?.reflection,
|
|
99
|
+
jsExtension: outExt,
|
|
100
|
+
},
|
|
101
|
+
userBundler,
|
|
102
|
+
output: { dir: outdir },
|
|
103
|
+
userAliases: aliases,
|
|
104
|
+
pnpPlugins,
|
|
127
105
|
}));
|
|
128
106
|
}
|
|
129
107
|
return results;
|
|
@@ -152,11 +130,11 @@ export class BuildAction {
|
|
|
152
130
|
}
|
|
153
131
|
/**
|
|
154
132
|
* Resolve the `--globals` CLI list into a pre-computed inject stub path
|
|
155
|
-
* that the
|
|
156
|
-
*
|
|
133
|
+
* that the orchestrator appends to its input list. Only runs for
|
|
134
|
+
* `--app gjs` — Node and browser builds rely on native globals.
|
|
157
135
|
*
|
|
158
136
|
* Used only for the explicit-only path (no `auto` token in the value).
|
|
159
|
-
* The auto path is handled in `buildApp` via the
|
|
137
|
+
* The auto path is handled in `buildApp` via the iterative multi-pass build.
|
|
160
138
|
*/
|
|
161
139
|
async resolveGlobalsInject(app, globals, verbose) {
|
|
162
140
|
if (app !== "gjs")
|
|
@@ -173,8 +151,12 @@ export class BuildAction {
|
|
|
173
151
|
return injectPath ?? undefined;
|
|
174
152
|
}
|
|
175
153
|
/**
|
|
176
|
-
* Post-processing: prepend
|
|
177
|
-
* Only runs for GJS app builds with a
|
|
154
|
+
* Post-processing: prepend the resolved shebang line and mark the
|
|
155
|
+
* output executable. Only runs for GJS app builds with a single outfile.
|
|
156
|
+
* The shebang plugin in `@gjsify/rolldown-plugin-gjsify` already injects
|
|
157
|
+
* during bundling — this hook is the safety net for anything that
|
|
158
|
+
* bypassed the plugin (e.g. user-supplied banners that out-ordered it),
|
|
159
|
+
* plus the chmod.
|
|
178
160
|
*/
|
|
179
161
|
async applyShebang(outfile, verbose) {
|
|
180
162
|
if (!outfile) {
|
|
@@ -182,44 +164,49 @@ export class BuildAction {
|
|
|
182
164
|
console.warn("[gjsify] --shebang skipped: no single outfile (use --outfile for GJS executables)");
|
|
183
165
|
return;
|
|
184
166
|
}
|
|
167
|
+
const line = resolveShebangLine(this.configData.shebang) ?? DEFAULT_GJS_SHEBANG;
|
|
185
168
|
const content = await readFile(outfile, "utf-8");
|
|
186
169
|
if (content.startsWith("#!")) {
|
|
187
170
|
if (verbose)
|
|
188
171
|
console.debug(`[gjsify] --shebang skipped: ${outfile} already starts with a shebang`);
|
|
189
172
|
}
|
|
190
173
|
else {
|
|
191
|
-
await writeFile(outfile,
|
|
174
|
+
await writeFile(outfile, line + "\n" + content);
|
|
192
175
|
}
|
|
193
176
|
await chmod(outfile, 0o755);
|
|
194
177
|
if (verbose)
|
|
195
|
-
console.debug(`[gjsify] --shebang: wrote
|
|
178
|
+
console.debug(`[gjsify] --shebang: wrote ${line} + chmod 0o755 to ${outfile}`);
|
|
196
179
|
}
|
|
197
180
|
/** Application mode */
|
|
198
181
|
async buildApp(app = "gjs") {
|
|
199
|
-
const { verbose,
|
|
200
|
-
const
|
|
201
|
-
|
|
182
|
+
const { verbose, typescript, exclude, library: pkg, aliases, excludeGlobals, } = this.configData;
|
|
183
|
+
const userBundler = normalizeBundlerOptions(this.configData);
|
|
184
|
+
const formatRaw = userBundler.output?.format ??
|
|
185
|
+
(userBundler.output?.file?.endsWith(".cjs") ? "cjs" : "esm");
|
|
186
|
+
// The orchestrator only handles esm/cjs (iife is not a GJS / Node /
|
|
187
|
+
// browser-bundle target we support). Coerce.
|
|
188
|
+
const format = formatRaw === "iife" ? "esm" : formatRaw;
|
|
202
189
|
// Set default outfile if no outdir is set
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
: pgk.module || pgk.main;
|
|
190
|
+
let outfile = userBundler.output?.file;
|
|
191
|
+
let outdir = userBundler.output?.dir;
|
|
192
|
+
if (!outfile && !outdir && (pkg?.main || pkg?.module)) {
|
|
193
|
+
const candidate = format === "cjs"
|
|
194
|
+
? pkg.main ?? pkg.module
|
|
195
|
+
: pkg.module ?? pkg.main;
|
|
210
196
|
if (candidate && isUnsafeDefaultOutput(candidate)) {
|
|
211
|
-
// `package.json#main`/`module` commonly points at a TypeScript
|
|
212
|
-
// source (e.g. `src/index.ts` for TS-direct workflows). Falling
|
|
213
|
-
// back to that value would have esbuild OVERWRITE the source.
|
|
214
|
-
// Surface a clear error and require an explicit outfile/outdir
|
|
215
|
-
// instead of silently destroying the user's code.
|
|
216
197
|
throw new Error(`gjsify build: refusing to default --outfile to ${candidate} ` +
|
|
217
198
|
`(would overwrite a TypeScript source file). Pass --outfile/--outdir ` +
|
|
218
|
-
`explicitly, or set "gjsify.
|
|
199
|
+
`explicitly, or set "gjsify.bundler.output.file" in package.json.`);
|
|
219
200
|
}
|
|
220
|
-
|
|
201
|
+
outfile = candidate;
|
|
221
202
|
}
|
|
222
203
|
const { consoleShim, globals } = this.configData;
|
|
204
|
+
const userExternal = Array.isArray(userBundler.external)
|
|
205
|
+
? userBundler.external
|
|
206
|
+
: undefined;
|
|
207
|
+
const userBanner = typeof userBundler.output?.banner === "string"
|
|
208
|
+
? userBundler.output.banner
|
|
209
|
+
: undefined;
|
|
223
210
|
const pluginOpts = {
|
|
224
211
|
debug: verbose,
|
|
225
212
|
app,
|
|
@@ -230,65 +217,106 @@ export class BuildAction {
|
|
|
230
217
|
...(aliases ? { aliases } : {}),
|
|
231
218
|
};
|
|
232
219
|
const { autoMode, extras } = this.parseGlobalsValue(globals);
|
|
233
|
-
const
|
|
234
|
-
const pnpPlugins =
|
|
220
|
+
const pnp = await buildPnpPlugin();
|
|
221
|
+
const pnpPlugins = pnp ? [pnp] : [];
|
|
222
|
+
// User-supplied text loaders need to be available during BOTH the
|
|
223
|
+
// auto-globals pre-build (`detectAutoGlobals`) and the final build —
|
|
224
|
+
// otherwise Rolldown's parser hits unknown extensions like `.ui` /
|
|
225
|
+
// `.asm` during the pre-build, fails to parse them as JS/JSX, and
|
|
226
|
+
// the auto-globals iteration aborts before the final plugin chain is
|
|
227
|
+
// ever assembled. Build the user-plugin chain once, up front, and
|
|
228
|
+
// pass it into both passes.
|
|
229
|
+
const userTextLoader = textLoaderPlugin({ loaders: this.configData.loaders });
|
|
230
|
+
const userPlugins = userTextLoader ? [userTextLoader] : [];
|
|
231
|
+
// User-supplied bundler.plugins (mix of plugin objects + by-name
|
|
232
|
+
// entries) — resolved from the project's node_modules. Same
|
|
233
|
+
// ordering rationale as the text loader: must be present during
|
|
234
|
+
// auto-globals pre-build to avoid claiming the same files via
|
|
235
|
+
// Rolldown's default classifier.
|
|
236
|
+
if (userBundler.plugins?.length) {
|
|
237
|
+
const resolved = await resolveUserPlugins(userBundler.plugins, process.cwd());
|
|
238
|
+
userPlugins.push(...resolved);
|
|
239
|
+
}
|
|
235
240
|
// --- Auto mode (with optional extras): iterative multi-pass build ---
|
|
236
|
-
// The extras token is used for cases where the detector cannot
|
|
237
|
-
// statically see a global (e.g. Excalibur indirects globalThis via
|
|
238
|
-
// BrowserComponent.nativeComponent). Common pattern: --globals auto,dom
|
|
239
241
|
if (app === "gjs" && autoMode) {
|
|
242
|
+
const gjsifyPluginFactory = async (opts) => {
|
|
243
|
+
const cfg = await gjsifyPlugin({
|
|
244
|
+
input: userBundler.input,
|
|
245
|
+
output: { file: outfile, dir: outdir },
|
|
246
|
+
userExternal,
|
|
247
|
+
userBanner,
|
|
248
|
+
userAliases: aliases,
|
|
249
|
+
shebang: this.configData.shebang,
|
|
250
|
+
}, opts);
|
|
251
|
+
return cfg.plugins;
|
|
252
|
+
};
|
|
240
253
|
const { injectPath } = await detectAutoGlobals({
|
|
241
|
-
|
|
242
|
-
...
|
|
254
|
+
input: userBundler.input,
|
|
255
|
+
plugins: [...pnpPlugins, ...userPlugins],
|
|
256
|
+
external: userBundler.external,
|
|
257
|
+
transform: userBundler.transform,
|
|
243
258
|
format,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
}, pluginOpts, gjsifyPluginFactory, verbose, { extraGlobalsList: extras, excludeGlobals });
|
|
260
|
+
pluginOpts.autoGlobalsInject = injectPath;
|
|
261
|
+
}
|
|
262
|
+
else if (extras) {
|
|
263
|
+
pluginOpts.autoGlobalsInject = await this.resolveGlobalsInject(app, extras, verbose);
|
|
264
|
+
}
|
|
265
|
+
// Final build: orchestrator → rolldown → write
|
|
266
|
+
const cfg = await gjsifyPlugin({
|
|
267
|
+
input: userBundler.input,
|
|
268
|
+
output: { file: outfile, dir: outdir },
|
|
269
|
+
userExternal,
|
|
270
|
+
userBanner,
|
|
271
|
+
userAliases: aliases,
|
|
272
|
+
shebang: this.configData.shebang,
|
|
273
|
+
}, pluginOpts);
|
|
274
|
+
const merged = mergeBundlerOptions(cfg.options, userBundler);
|
|
275
|
+
const finalOpts = {
|
|
276
|
+
...merged,
|
|
277
|
+
// Drop user-config plugins from `merged` — they survived
|
|
278
|
+
// mergeBundlerOptions via spread but have already been resolved
|
|
279
|
+
// and appended into `userPlugins` above. Re-emitting the raw
|
|
280
|
+
// entries (which may include `BundlerPluginByName` shapes
|
|
281
|
+
// Rolldown doesn't understand) would crash the build.
|
|
282
|
+
plugins: [...pnpPlugins, ...userPlugins, ...cfg.plugins],
|
|
283
|
+
};
|
|
284
|
+
const build = await rolldown(finalOpts);
|
|
285
|
+
let writeResult;
|
|
286
|
+
try {
|
|
287
|
+
writeResult = await build.write(finalOpts.output ?? {});
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
await build.close();
|
|
262
291
|
}
|
|
263
|
-
// --- Explicit list (no `auto` token) or none mode ---
|
|
264
|
-
const autoGlobalsInject = extras
|
|
265
|
-
? await this.resolveGlobalsInject(app, extras, verbose)
|
|
266
|
-
: undefined;
|
|
267
|
-
const result = await build({
|
|
268
|
-
...this.getEsBuildDefaults(),
|
|
269
|
-
...esbuild,
|
|
270
|
-
format,
|
|
271
|
-
plugins: [
|
|
272
|
-
...pnpPlugins,
|
|
273
|
-
gjsifyPlugin({
|
|
274
|
-
...pluginOpts,
|
|
275
|
-
autoGlobalsInject,
|
|
276
|
-
}),
|
|
277
|
-
],
|
|
278
|
-
});
|
|
279
292
|
if (app === "gjs" && this.configData.shebang) {
|
|
280
|
-
await this.applyShebang(
|
|
293
|
+
await this.applyShebang(outfile, verbose);
|
|
281
294
|
}
|
|
282
|
-
return [
|
|
295
|
+
return [writeResult];
|
|
283
296
|
}
|
|
284
297
|
async start(buildType = { app: "gjs" }) {
|
|
285
|
-
const results = [];
|
|
286
298
|
if (buildType.library) {
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
results.push(...(await this.buildApp(buildType.app)));
|
|
299
|
+
return await this.buildLibrary();
|
|
291
300
|
}
|
|
292
|
-
return
|
|
301
|
+
return await this.buildApp(buildType.app);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function runOneLibraryBuild(args) {
|
|
305
|
+
const cfg = await gjsifyPlugin({
|
|
306
|
+
input: args.userBundler.input,
|
|
307
|
+
output: args.output,
|
|
308
|
+
userAliases: args.userAliases,
|
|
309
|
+
}, args.pluginOpts);
|
|
310
|
+
const merged = mergeBundlerOptions(cfg.options, args.userBundler);
|
|
311
|
+
const finalOpts = {
|
|
312
|
+
...merged,
|
|
313
|
+
plugins: [...args.pnpPlugins, ...cfg.plugins],
|
|
314
|
+
};
|
|
315
|
+
const build = await rolldown(finalOpts);
|
|
316
|
+
try {
|
|
317
|
+
return await build.write(finalOpts.output ?? {});
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
await build.close();
|
|
293
321
|
}
|
|
294
322
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from '../../types/index.js';
|
|
2
|
+
interface FlatpakBuildOptions {
|
|
3
|
+
manifest?: string;
|
|
4
|
+
buildDir?: string;
|
|
5
|
+
install?: boolean;
|
|
6
|
+
repo?: string;
|
|
7
|
+
bundle?: string;
|
|
8
|
+
tarball?: string;
|
|
9
|
+
forceClean?: boolean;
|
|
10
|
+
sandbox?: boolean;
|
|
11
|
+
deleteBuildDirs?: boolean;
|
|
12
|
+
installDepsFrom?: string;
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const flatpakBuildCommand: Command<unknown, FlatpakBuildOptions>;
|
|
16
|
+
export {};
|