@gjsify/cli 0.1.8 → 0.1.9
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 +13 -0
- package/lib/actions/build.js +60 -18
- package/lib/commands/build.js +2 -2
- package/lib/commands/check.js +41 -12
- package/lib/commands/showcase.js +6 -4
- package/lib/utils/check-system-deps.d.ts +14 -2
- package/lib/utils/check-system-deps.js +214 -46
- package/lib/utils/detect-native-packages.d.ts +4 -0
- package/lib/utils/detect-native-packages.js +12 -0
- package/package.json +10 -9
- package/src/actions/build.ts +72 -20
- package/src/commands/build.ts +2 -2
- package/src/commands/check.ts +45 -12
- package/src/commands/showcase.ts +6 -4
- package/src/utils/check-system-deps.ts +264 -45
- package/src/utils/detect-native-packages.ts +12 -0
package/lib/actions/build.d.ts
CHANGED
|
@@ -7,10 +7,23 @@ export declare class BuildAction {
|
|
|
7
7
|
getEsBuildDefaults(): BuildOptions;
|
|
8
8
|
/** Library mode */
|
|
9
9
|
buildLibrary(): Promise<BuildResult<BuildOptions>[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Parse the `--globals` value into { autoMode, extras }.
|
|
12
|
+
* - `auto` → { autoMode: true, extras: '' }
|
|
13
|
+
* - `auto,dom` → { autoMode: true, extras: 'dom' }
|
|
14
|
+
* - `auto,dom,fetch` → { autoMode: true, extras: 'dom,fetch' }
|
|
15
|
+
* - `dom,fetch` → { autoMode: false, extras: 'dom,fetch' }
|
|
16
|
+
* - `none` / `` → { autoMode: false, extras: '' }
|
|
17
|
+
* - `undefined` → { autoMode: true, extras: '' } (default)
|
|
18
|
+
*/
|
|
19
|
+
private parseGlobalsValue;
|
|
10
20
|
/**
|
|
11
21
|
* Resolve the `--globals` CLI list into a pre-computed inject stub path
|
|
12
22
|
* that the esbuild plugin will append to its `inject` list. Only runs
|
|
13
23
|
* for `--app gjs` — Node and browser builds rely on native globals.
|
|
24
|
+
*
|
|
25
|
+
* Used only for the explicit-only path (no `auto` token in the value).
|
|
26
|
+
* The auto path is handled in `buildApp` via the two-pass build.
|
|
14
27
|
*/
|
|
15
28
|
private resolveGlobalsInject;
|
|
16
29
|
/** Application mode */
|
package/lib/actions/build.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { build } from 'esbuild';
|
|
2
2
|
import { gjsifyPlugin } from '@gjsify/esbuild-plugin-gjsify';
|
|
3
|
-
import { resolveGlobalsList, writeRegisterInjectFile } from '@gjsify/esbuild-plugin-gjsify/globals';
|
|
3
|
+
import { resolveGlobalsList, writeRegisterInjectFile, detectAutoGlobals } from '@gjsify/esbuild-plugin-gjsify/globals';
|
|
4
4
|
import { dirname, extname } from 'path';
|
|
5
5
|
export class BuildAction {
|
|
6
6
|
configData;
|
|
@@ -64,13 +64,37 @@ export class BuildAction {
|
|
|
64
64
|
}
|
|
65
65
|
return results;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Parse the `--globals` value into { autoMode, extras }.
|
|
69
|
+
* - `auto` → { autoMode: true, extras: '' }
|
|
70
|
+
* - `auto,dom` → { autoMode: true, extras: 'dom' }
|
|
71
|
+
* - `auto,dom,fetch` → { autoMode: true, extras: 'dom,fetch' }
|
|
72
|
+
* - `dom,fetch` → { autoMode: false, extras: 'dom,fetch' }
|
|
73
|
+
* - `none` / `` → { autoMode: false, extras: '' }
|
|
74
|
+
* - `undefined` → { autoMode: true, extras: '' } (default)
|
|
75
|
+
*/
|
|
76
|
+
parseGlobalsValue(value) {
|
|
77
|
+
if (value === undefined)
|
|
78
|
+
return { autoMode: true, extras: '' };
|
|
79
|
+
if (value === 'none' || value === '')
|
|
80
|
+
return { autoMode: false, extras: '' };
|
|
81
|
+
const tokens = value.split(',').map(t => t.trim()).filter(Boolean);
|
|
82
|
+
const hasAuto = tokens.includes('auto');
|
|
83
|
+
const extras = tokens.filter(t => t !== 'auto').join(',');
|
|
84
|
+
return { autoMode: hasAuto, extras };
|
|
85
|
+
}
|
|
67
86
|
/**
|
|
68
87
|
* Resolve the `--globals` CLI list into a pre-computed inject stub path
|
|
69
88
|
* that the esbuild plugin will append to its `inject` list. Only runs
|
|
70
89
|
* for `--app gjs` — Node and browser builds rely on native globals.
|
|
90
|
+
*
|
|
91
|
+
* Used only for the explicit-only path (no `auto` token in the value).
|
|
92
|
+
* The auto path is handled in `buildApp` via the two-pass build.
|
|
71
93
|
*/
|
|
72
94
|
async resolveGlobalsInject(app, globals, verbose) {
|
|
73
|
-
if (app !== 'gjs'
|
|
95
|
+
if (app !== 'gjs')
|
|
96
|
+
return undefined;
|
|
97
|
+
if (!globals)
|
|
74
98
|
return undefined;
|
|
75
99
|
const registerPaths = resolveGlobalsList(globals);
|
|
76
100
|
if (registerPaths.size === 0)
|
|
@@ -85,36 +109,54 @@ export class BuildAction {
|
|
|
85
109
|
async buildApp(app = 'gjs') {
|
|
86
110
|
const { verbose, esbuild, typescript, exclude, library: pgk } = this.configData;
|
|
87
111
|
const format = esbuild?.format ?? (esbuild?.outfile?.endsWith('.cjs') ? 'cjs' : 'esm');
|
|
88
|
-
// Set default outfile if no outdir is set
|
|
112
|
+
// Set default outfile if no outdir is set
|
|
89
113
|
if (esbuild && !esbuild?.outfile && !esbuild?.outdir && (pgk?.main || pgk?.module)) {
|
|
90
114
|
esbuild.outfile = esbuild?.format === 'cjs' ? pgk.main || pgk.module : pgk.module || pgk.main;
|
|
91
115
|
}
|
|
92
116
|
const { consoleShim, globals } = this.configData;
|
|
93
|
-
const
|
|
117
|
+
const pluginOpts = {
|
|
118
|
+
debug: verbose,
|
|
119
|
+
app,
|
|
120
|
+
format,
|
|
121
|
+
exclude,
|
|
122
|
+
reflection: typescript?.reflection,
|
|
123
|
+
consoleShim,
|
|
124
|
+
};
|
|
125
|
+
const { autoMode, extras } = this.parseGlobalsValue(globals);
|
|
126
|
+
// --- Auto mode (with optional extras): iterative multi-pass build ---
|
|
127
|
+
// The extras token is used for cases where the detector cannot
|
|
128
|
+
// statically see a global (e.g. Excalibur indirects globalThis via
|
|
129
|
+
// BrowserComponent.nativeComponent). Common pattern: --globals auto,dom
|
|
130
|
+
if (app === 'gjs' && autoMode) {
|
|
131
|
+
const { injectPath } = await detectAutoGlobals({ ...this.getEsBuildDefaults(), ...esbuild, format }, pluginOpts, verbose, { extraGlobalsList: extras });
|
|
132
|
+
const result = await build({
|
|
133
|
+
...this.getEsBuildDefaults(),
|
|
134
|
+
...esbuild,
|
|
135
|
+
format,
|
|
136
|
+
plugins: [
|
|
137
|
+
gjsifyPlugin({
|
|
138
|
+
...pluginOpts,
|
|
139
|
+
autoGlobalsInject: injectPath,
|
|
140
|
+
}),
|
|
141
|
+
],
|
|
142
|
+
});
|
|
143
|
+
return [result];
|
|
144
|
+
}
|
|
145
|
+
// --- Explicit list (no `auto` token) or none mode ---
|
|
146
|
+
const autoGlobalsInject = extras
|
|
147
|
+
? await this.resolveGlobalsInject(app, extras, verbose)
|
|
148
|
+
: undefined;
|
|
94
149
|
const result = await build({
|
|
95
150
|
...this.getEsBuildDefaults(),
|
|
96
151
|
...esbuild,
|
|
97
152
|
format,
|
|
98
153
|
plugins: [
|
|
99
154
|
gjsifyPlugin({
|
|
100
|
-
|
|
101
|
-
app,
|
|
102
|
-
format,
|
|
103
|
-
exclude,
|
|
104
|
-
reflection: typescript?.reflection,
|
|
105
|
-
consoleShim,
|
|
155
|
+
...pluginOpts,
|
|
106
156
|
autoGlobalsInject,
|
|
107
157
|
}),
|
|
108
158
|
]
|
|
109
159
|
});
|
|
110
|
-
// See https://esbuild.github.io/api/#metafile
|
|
111
|
-
// TODO add cli options for this
|
|
112
|
-
// if(result.metafile) {
|
|
113
|
-
// const outFile = esbuild?.outfile ? esbuild.outfile + '.meta.json' : 'meta.json';
|
|
114
|
-
// await writeFile(outFile, JSON.stringify(result.metafile));
|
|
115
|
-
// let text = await analyzeMetafile(result.metafile)
|
|
116
|
-
// console.log(text)
|
|
117
|
-
// }
|
|
118
160
|
return [result];
|
|
119
161
|
}
|
|
120
162
|
async start(buildType = { app: 'gjs' }) {
|
package/lib/commands/build.js
CHANGED
|
@@ -87,10 +87,10 @@ export const buildCommand = {
|
|
|
87
87
|
default: true
|
|
88
88
|
})
|
|
89
89
|
.option('globals', {
|
|
90
|
-
description: "Comma-separated list of global identifiers
|
|
90
|
+
description: "Comma-separated list of global identifiers, 'auto' (default) to detect automatically from the bundled output, or 'none' to disable. The 'auto' token may be combined with explicit identifiers/groups (e.g. 'auto,dom') for cases where the detector cannot statically see a global because it's accessed via indirection. Each identifier is mapped to the corresponding `@gjsify/<pkg>/register` module and injected into the bundle. See the CLI Reference docs for the full list of known identifiers. Only applies to GJS app builds.",
|
|
91
91
|
type: 'string',
|
|
92
92
|
normalize: true,
|
|
93
|
-
default: ''
|
|
93
|
+
default: 'auto'
|
|
94
94
|
});
|
|
95
95
|
},
|
|
96
96
|
handler: async (args) => {
|
package/lib/commands/check.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { runAllChecks, detectPackageManager, buildInstallCommand } from '../utils/check-system-deps.js';
|
|
2
2
|
export const checkCommand = {
|
|
3
3
|
command: 'check',
|
|
4
|
-
description: 'Check that
|
|
4
|
+
description: 'Check that required system dependencies (GJS, GTK4, libsoup3, …) are installed. Optional dependencies are detected only when their @gjsify/* package is in your project.',
|
|
5
5
|
builder: (yargs) => {
|
|
6
6
|
return yargs
|
|
7
7
|
.option('json', {
|
|
@@ -13,31 +13,60 @@ export const checkCommand = {
|
|
|
13
13
|
handler: async (args) => {
|
|
14
14
|
const results = runAllChecks(process.cwd());
|
|
15
15
|
const pm = detectPackageManager();
|
|
16
|
-
const
|
|
16
|
+
const missingRequired = results.filter(r => !r.found && r.severity === 'required');
|
|
17
|
+
const missingOptional = results.filter(r => !r.found && r.severity === 'optional');
|
|
18
|
+
const allMissing = [...missingRequired, ...missingOptional];
|
|
17
19
|
if (args.json) {
|
|
18
20
|
console.log(JSON.stringify({ packageManager: pm, deps: results }, null, 2));
|
|
19
|
-
|
|
21
|
+
// Only required deps influence the exit code.
|
|
22
|
+
process.exit(missingRequired.length > 0 ? 1 : 0);
|
|
20
23
|
return;
|
|
21
24
|
}
|
|
22
25
|
console.log('System dependency check\n');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log(
|
|
26
|
+
const required = results.filter(r => r.severity === 'required');
|
|
27
|
+
const optional = results.filter(r => r.severity === 'optional');
|
|
28
|
+
if (required.length > 0) {
|
|
29
|
+
console.log('Required:');
|
|
30
|
+
for (const dep of required) {
|
|
31
|
+
const icon = dep.found ? '✓' : '✗';
|
|
32
|
+
const ver = dep.version ? ` (${dep.version})` : '';
|
|
33
|
+
console.log(` ${icon} ${dep.name}${ver}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (optional.length > 0) {
|
|
37
|
+
console.log('\nOptional:');
|
|
38
|
+
for (const dep of optional) {
|
|
39
|
+
// ⚠ for missing-but-needed-by-installed-packages, ○ for missing-but-not-needed (shouldn't appear in conditional mode)
|
|
40
|
+
const icon = dep.found ? '✓' : '⚠';
|
|
41
|
+
const ver = dep.version ? ` (${dep.version})` : '';
|
|
42
|
+
const requiredBy = dep.requiredBy && dep.requiredBy.length > 0
|
|
43
|
+
? ` — needed by ${dep.requiredBy.join(', ')}`
|
|
44
|
+
: '';
|
|
45
|
+
console.log(` ${icon} ${dep.name}${ver}${requiredBy}`);
|
|
46
|
+
}
|
|
27
47
|
}
|
|
28
48
|
console.log(`\nPackage manager: ${pm}`);
|
|
29
|
-
if (
|
|
49
|
+
if (allMissing.length === 0) {
|
|
30
50
|
console.log('\nAll dependencies found.');
|
|
31
51
|
return;
|
|
32
52
|
}
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
if (missingRequired.length > 0) {
|
|
54
|
+
console.log(`\nMissing required: ${missingRequired.map(d => d.name).join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
if (missingOptional.length > 0) {
|
|
57
|
+
console.log(`Missing optional: ${missingOptional.map(d => d.name).join(', ')}`);
|
|
58
|
+
}
|
|
59
|
+
const cmd = buildInstallCommand(pm, allMissing);
|
|
35
60
|
if (cmd) {
|
|
36
|
-
console.log(`\nTo install
|
|
61
|
+
console.log(`\nTo install:\n ${cmd}`);
|
|
37
62
|
}
|
|
38
63
|
else {
|
|
39
64
|
console.log('\nNo install command available for your package manager. Install manually.');
|
|
40
65
|
}
|
|
41
|
-
|
|
66
|
+
// Exit non-zero ONLY if a required dependency is missing.
|
|
67
|
+
// Optional deps that are missing but needed by an installed @gjsify/*
|
|
68
|
+
// package generate a warning but keep exit code 0 — the user can still
|
|
69
|
+
// build/run code paths that don't touch the optional library.
|
|
70
|
+
process.exit(missingRequired.length > 0 ? 1 : 0);
|
|
42
71
|
},
|
|
43
72
|
};
|
package/lib/commands/showcase.js
CHANGED
|
@@ -68,14 +68,16 @@ export const showcaseCommand = {
|
|
|
68
68
|
if (needsWebgl) {
|
|
69
69
|
results.push(checkGwebgl(process.cwd()));
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
// Hard-fail only on missing REQUIRED deps (gjs, gwebgl is required if needsWebgl).
|
|
72
|
+
// For showcase, gwebgl is treated as required because the bundle won't run without it.
|
|
73
|
+
const missingHard = results.filter(r => !r.found && (r.severity === 'required' || r.id === 'gwebgl'));
|
|
74
|
+
if (missingHard.length > 0) {
|
|
73
75
|
console.error('Missing system dependencies:\n');
|
|
74
|
-
for (const dep of
|
|
76
|
+
for (const dep of missingHard) {
|
|
75
77
|
console.error(` ✗ ${dep.name}`);
|
|
76
78
|
}
|
|
77
79
|
const pm = detectPackageManager();
|
|
78
|
-
const cmd = buildInstallCommand(pm,
|
|
80
|
+
const cmd = buildInstallCommand(pm, missingHard);
|
|
79
81
|
if (cmd) {
|
|
80
82
|
console.error(`\nInstall with:\n ${cmd}`);
|
|
81
83
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type DepSeverity = 'required' | 'optional';
|
|
1
2
|
export interface DepCheck {
|
|
2
3
|
/** Stable key used for install command lookup, e.g. "gjs" */
|
|
3
4
|
id: string;
|
|
@@ -6,19 +7,30 @@ export interface DepCheck {
|
|
|
6
7
|
found: boolean;
|
|
7
8
|
/** Version string when found, e.g. "1.86.0" */
|
|
8
9
|
version?: string;
|
|
10
|
+
/** required = exit 1 if missing, optional = warn only */
|
|
11
|
+
severity: DepSeverity;
|
|
12
|
+
/** For optional deps: which @gjsify/* packages need this lib */
|
|
13
|
+
requiredBy?: string[];
|
|
9
14
|
}
|
|
10
15
|
export type PackageManager = 'apt' | 'dnf' | 'pacman' | 'zypper' | 'apk' | 'unknown';
|
|
11
16
|
export declare function detectPackageManager(): PackageManager;
|
|
12
17
|
/**
|
|
13
18
|
* Run all dependency checks. Used by `gjsify check` to show full system status.
|
|
19
|
+
*
|
|
20
|
+
* Required deps (gjs, gtk4, libsoup3, libadwaita, gobject-introspection,
|
|
21
|
+
* blueprint-compiler, pkg-config, meson) are always checked.
|
|
22
|
+
*
|
|
23
|
+
* Optional deps are checked conditionally based on which @gjsify/* packages
|
|
24
|
+
* the project (resolved from cwd) actually consumes. If no project context
|
|
25
|
+
* is available, all optional deps are checked.
|
|
14
26
|
*/
|
|
15
27
|
export declare function runAllChecks(cwd: string): DepCheck[];
|
|
16
28
|
/**
|
|
17
|
-
* Minimal checks needed to run any GJS example (GJS
|
|
29
|
+
* Minimal checks needed to run any GJS example (Node + GJS binaries only).
|
|
18
30
|
* Used by `gjsify showcase` for examples that have no native deps.
|
|
19
31
|
*/
|
|
20
32
|
export declare function runMinimalChecks(): DepCheck[];
|
|
21
|
-
/** Check gwebgl npm package (project first, CLI fallback). */
|
|
33
|
+
/** Check gwebgl npm package (project first, CLI fallback). Optional — only needed by @gjsify/webgl users. */
|
|
22
34
|
export declare function checkGwebgl(cwd: string): DepCheck;
|
|
23
35
|
/**
|
|
24
36
|
* Build a suggested install command for missing dependencies.
|