@gjsify/cli 0.4.12 → 0.4.14
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/dist/cli.gjs.mjs +29 -23
- package/lib/actions/build.d.ts +11 -1
- package/lib/actions/build.js +79 -3
- package/lib/bundler-pick.d.ts +7 -0
- package/lib/bundler-pick.js +17 -0
- package/lib/commands/build.js +8 -0
- package/lib/commands/fix.d.ts +9 -0
- package/lib/commands/fix.js +60 -0
- package/lib/commands/flatpak/diff.d.ts +12 -0
- package/lib/commands/flatpak/diff.js +165 -0
- package/lib/commands/flatpak/index.d.ts +4 -1
- package/lib/commands/flatpak/index.js +11 -5
- package/lib/commands/flatpak/init.d.ts +1 -0
- package/lib/commands/flatpak/init.js +41 -7
- package/lib/commands/flatpak/release.d.ts +13 -0
- package/lib/commands/flatpak/release.js +152 -0
- package/lib/commands/flatpak/sync-flathub.d.ts +26 -0
- package/lib/commands/flatpak/sync-flathub.js +311 -0
- package/lib/commands/format.d.ts +12 -0
- package/lib/commands/format.js +98 -0
- package/lib/commands/index.d.ts +5 -0
- package/lib/commands/index.js +5 -0
- package/lib/commands/lint.d.ts +9 -0
- package/lib/commands/lint.js +60 -0
- package/lib/commands/test.d.ts +12 -0
- package/lib/commands/test.js +206 -0
- package/lib/commands/upgrade.d.ts +13 -0
- package/lib/commands/upgrade.js +402 -0
- package/lib/index.js +6 -1
- package/lib/templates/biome.json.tmpl +79 -0
- package/lib/types/cli-build-options.d.ts +7 -0
- package/lib/types/config-data.d.ts +47 -0
- package/lib/utils/biome-resolve.d.ts +47 -0
- package/lib/utils/biome-resolve.js +204 -0
- package/package.json +16 -16
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import yargs from 'yargs';
|
|
3
3
|
import { hideBin } from 'yargs/helpers';
|
|
4
|
-
import { buildCommand as build, runCommand as run, infoCommand as info, checkCommand as check, showcaseCommand as showcase, createCommand as create, gresourceCommand as gresource, gettextCommand as gettext, gsettingsCommand as gsettings, flatpakCommand as flatpak, dlxCommand as dlx, installCommand as install, foreachCommand as foreach, workspaceCommand as workspace, packCommand as pack, publishCommand as publish, selfUpdateCommand as selfUpdate, generateInstallerCommand as generateInstaller, uninstallCommand as uninstall, } from './commands/index.js';
|
|
4
|
+
import { buildCommand as build, testCommand as test, runCommand as run, infoCommand as info, checkCommand as check, showcaseCommand as showcase, createCommand as create, gresourceCommand as gresource, gettextCommand as gettext, gsettingsCommand as gsettings, flatpakCommand as flatpak, dlxCommand as dlx, installCommand as install, foreachCommand as foreach, workspaceCommand as workspace, packCommand as pack, publishCommand as publish, selfUpdateCommand as selfUpdate, generateInstallerCommand as generateInstaller, uninstallCommand as uninstall, formatCommand as format, lintCommand as lint, fixCommand as fix, upgradeCommand as upgrade, } from './commands/index.js';
|
|
5
5
|
import { APP_NAME } from './constants.js';
|
|
6
6
|
// `parseAsync()` instead of `.argv` so the top-level await keeps the
|
|
7
7
|
// process alive until command handlers complete. Under Node this is
|
|
@@ -14,6 +14,7 @@ await yargs(hideBin(process.argv))
|
|
|
14
14
|
.command(create.command, create.description, create.builder, create.handler)
|
|
15
15
|
.command(install.command, install.description, install.builder, install.handler)
|
|
16
16
|
.command(build.command, build.description, build.builder, build.handler)
|
|
17
|
+
.command(test.command, test.description, test.builder, test.handler)
|
|
17
18
|
.command(run.command, run.description, run.builder, run.handler)
|
|
18
19
|
.command(dlx.command, dlx.description, dlx.builder, dlx.handler)
|
|
19
20
|
.command(info.command, info.description, info.builder, info.handler)
|
|
@@ -30,6 +31,10 @@ await yargs(hideBin(process.argv))
|
|
|
30
31
|
.command(selfUpdate.command, selfUpdate.description, selfUpdate.builder, selfUpdate.handler)
|
|
31
32
|
.command(generateInstaller.command, generateInstaller.description, generateInstaller.builder, generateInstaller.handler)
|
|
32
33
|
.command(uninstall.command, uninstall.description, uninstall.builder, uninstall.handler)
|
|
34
|
+
.command(upgrade.command, upgrade.description, upgrade.builder, upgrade.handler)
|
|
35
|
+
.command(format.command, format.description, format.builder, format.handler)
|
|
36
|
+
.command(lint.command, lint.description, lint.builder, lint.handler)
|
|
37
|
+
.command(fix.command, fix.description, fix.builder, fix.handler)
|
|
33
38
|
.demandCommand(1)
|
|
34
39
|
.help()
|
|
35
40
|
.parseAsync();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.4.13/schema.json",
|
|
3
|
+
"formatter": {
|
|
4
|
+
"enabled": true,
|
|
5
|
+
"indentStyle": "space",
|
|
6
|
+
"indentWidth": 4,
|
|
7
|
+
"lineWidth": 120,
|
|
8
|
+
"lineEnding": "lf"
|
|
9
|
+
},
|
|
10
|
+
"linter": {
|
|
11
|
+
"enabled": true,
|
|
12
|
+
"rules": {
|
|
13
|
+
"recommended": true,
|
|
14
|
+
"style": {
|
|
15
|
+
"useImportType": "warn",
|
|
16
|
+
"useNodejsImportProtocol": "error",
|
|
17
|
+
"noNonNullAssertion": "off"
|
|
18
|
+
},
|
|
19
|
+
"suspicious": {
|
|
20
|
+
"noExplicitAny": "warn",
|
|
21
|
+
"noConsole": "off"
|
|
22
|
+
},
|
|
23
|
+
"correctness": {
|
|
24
|
+
"noUnusedImports": "warn"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"javascript": {
|
|
29
|
+
"formatter": {
|
|
30
|
+
"quoteStyle": "single",
|
|
31
|
+
"jsxQuoteStyle": "double",
|
|
32
|
+
"semicolons": "always",
|
|
33
|
+
"trailingCommas": "all",
|
|
34
|
+
"arrowParentheses": "always",
|
|
35
|
+
"bracketSpacing": true,
|
|
36
|
+
"bracketSameLine": false
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"json": {
|
|
40
|
+
"formatter": {
|
|
41
|
+
"indentWidth": 2,
|
|
42
|
+
"trailingCommas": "none",
|
|
43
|
+
"lineWidth": 120
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"css": {
|
|
47
|
+
"formatter": {
|
|
48
|
+
"indentWidth": 2,
|
|
49
|
+
"quoteStyle": "single"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": {
|
|
53
|
+
"includes": [
|
|
54
|
+
"**",
|
|
55
|
+
"!**/node_modules",
|
|
56
|
+
"!**/dist",
|
|
57
|
+
"!**/lib",
|
|
58
|
+
"!**/build",
|
|
59
|
+
"!**/build-dir",
|
|
60
|
+
"!**/builddir",
|
|
61
|
+
"!**/flatpak-build",
|
|
62
|
+
"!**/.flatpak-builder",
|
|
63
|
+
"!**/repo",
|
|
64
|
+
"!**/coverage",
|
|
65
|
+
"!**/refs",
|
|
66
|
+
"!**/@types",
|
|
67
|
+
"!**/templates",
|
|
68
|
+
"!**/prebuilds",
|
|
69
|
+
"!**/.yarn/cache",
|
|
70
|
+
"!**/.yarn/install-state.gz",
|
|
71
|
+
"!**/cli.gjs.mjs",
|
|
72
|
+
"!**/test.gjs.mjs",
|
|
73
|
+
"!**/test.node.mjs",
|
|
74
|
+
"!**/*.gresource",
|
|
75
|
+
"!**/*.compiled",
|
|
76
|
+
"!**/*.metainfo.xml"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -96,4 +96,11 @@ export interface CliBuildOptions {
|
|
|
96
96
|
* Example: `--exclude-globals fetch,XMLHttpRequest`
|
|
97
97
|
*/
|
|
98
98
|
excludeGlobals?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Watch source files and rebuild on change. Logs each rebuild with
|
|
101
|
+
* duration; SIGINT/SIGTERM cleanly closes the watcher. Only valid with
|
|
102
|
+
* `--app gjs|node|browser` (rejected with `--library`). Requires the
|
|
103
|
+
* npm `rolldown` engine — run under Node.
|
|
104
|
+
*/
|
|
105
|
+
watch?: boolean;
|
|
99
106
|
}
|
|
@@ -186,6 +186,38 @@ export interface ConfigData {
|
|
|
186
186
|
* declaratively. CLI flags override these values.
|
|
187
187
|
*/
|
|
188
188
|
flatpak?: ConfigDataFlatpak;
|
|
189
|
+
/**
|
|
190
|
+
* Format/lint config consumed by `gjsify format` / `gjsify lint` /
|
|
191
|
+
* `gjsify fix`. Thin shell — Biome's own `biome.json` is the real
|
|
192
|
+
* configuration file; we only need a pointer here.
|
|
193
|
+
*/
|
|
194
|
+
format?: ConfigDataFormat;
|
|
195
|
+
/**
|
|
196
|
+
* Test-runner configuration consumed by `gjsify test`. CLI flags
|
|
197
|
+
* (--entry, --outdir, --runtime) override these values.
|
|
198
|
+
*/
|
|
199
|
+
test?: ConfigDataTest;
|
|
200
|
+
}
|
|
201
|
+
/** Optional pointer to a non-default biome.json. */
|
|
202
|
+
export interface ConfigDataFormat {
|
|
203
|
+
/**
|
|
204
|
+
* Path to biome.json. Default: walks up from cwd to find one;
|
|
205
|
+
* falls back to the recommended template shipped with `gjsify`
|
|
206
|
+
* (writable via `gjsify format --init`).
|
|
207
|
+
*/
|
|
208
|
+
configPath?: string;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* `gjsify test` configuration. All fields optional — sensible defaults
|
|
212
|
+
* apply when missing.
|
|
213
|
+
*/
|
|
214
|
+
export interface ConfigDataTest {
|
|
215
|
+
/** Path to the test entry. Default: `src/test.mts`. */
|
|
216
|
+
entry?: string;
|
|
217
|
+
/** Output directory for the built test bundles. Default: `dist/`. */
|
|
218
|
+
outdir?: string;
|
|
219
|
+
/** Default runtimes when `--runtime` not specified. Default: `['gjs', 'node']`. */
|
|
220
|
+
runtimes?: Array<'gjs' | 'node'>;
|
|
189
221
|
}
|
|
190
222
|
/**
|
|
191
223
|
* Flatpak-toolchain config consumed by the `gjsify flatpak` subcommand
|
|
@@ -241,6 +273,14 @@ export interface ConfigDataFlatpak {
|
|
|
241
273
|
* `gjsify flatpak init`.
|
|
242
274
|
*/
|
|
243
275
|
kind?: 'app' | 'cli';
|
|
276
|
+
/**
|
|
277
|
+
* App display name (`.desktop` `Name=` + MetaInfo `<name>`). Defaults
|
|
278
|
+
* to a friendly derivation of `package.json#name` — that works when
|
|
279
|
+
* `name` is the reverse-DNS app id, but breaks when it's an npm
|
|
280
|
+
* package name like `learn6502`. Set this explicitly to the
|
|
281
|
+
* human-readable name shown in app stores (e.g. `"Learn 6502 Assembly"`).
|
|
282
|
+
*/
|
|
283
|
+
name?: string;
|
|
244
284
|
/**
|
|
245
285
|
* Developer attribution required by Flathub. `id` must be reverse-DNS.
|
|
246
286
|
* `email` (optional) becomes `<email>` inside `<developer>`.
|
|
@@ -409,6 +449,13 @@ export interface ConfigDataFlatpak {
|
|
|
409
449
|
displayLengthMin?: number;
|
|
410
450
|
controls?: Array<'keyboard' | 'pointing' | 'touch' | 'gamepad' | 'tablet' | 'console'>;
|
|
411
451
|
};
|
|
452
|
+
/**
|
|
453
|
+
* Flathub tracking-repo override for `gjsify flatpak sync-flathub` /
|
|
454
|
+
* `gjsify flatpak diff`. Default: `flathub/<appId>` (e.g.
|
|
455
|
+
* `flathub/eu.jumplink.Learn6502`). Set this when the upstream repo
|
|
456
|
+
* deviates from that convention.
|
|
457
|
+
*/
|
|
458
|
+
flathubRepo?: string;
|
|
412
459
|
}
|
|
413
460
|
/**
|
|
414
461
|
* A single block inside a MetaInfo `<description>`. Either a paragraph
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the absolute path to the biome native binary for the current
|
|
3
|
+
* platform. Walks cwd → workspace-root looking for the matching
|
|
4
|
+
* `@biomejs/cli-<platform>-<arch>` package.
|
|
5
|
+
*
|
|
6
|
+
* Throws with a clear install-hint when not found.
|
|
7
|
+
*/
|
|
8
|
+
export declare function findBiomeBin(cwd?: string): string;
|
|
9
|
+
export declare class BiomeNotFoundError extends Error {
|
|
10
|
+
pkg: string;
|
|
11
|
+
cwd: string;
|
|
12
|
+
constructor(pkg: string, cwd: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Walk up from a starting directory to find the nearest `biome.json` or
|
|
16
|
+
* `biome.jsonc`. Returns absolute path or null. Workspace-aware: also
|
|
17
|
+
* probes the workspace root.
|
|
18
|
+
*/
|
|
19
|
+
export declare function findBiomeConfig(cwd?: string): string | null;
|
|
20
|
+
export interface RunBiomeOptions {
|
|
21
|
+
cwd?: string;
|
|
22
|
+
verbose?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Spawn biome with the given args. Inherits stdio so biome's own output
|
|
26
|
+
* (formatted source, lint diagnostics, summary lines) reaches the user.
|
|
27
|
+
*
|
|
28
|
+
* Returns the exit code as a number; never throws on non-zero exit
|
|
29
|
+
* (callers check the code).
|
|
30
|
+
*/
|
|
31
|
+
export declare function runBiome(args: string[], opts?: RunBiomeOptions): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Lazy-load the embedded `biome.json.tmpl` content. The static-read-inliner
|
|
34
|
+
* matches this readFileSync(new URL(<lit>, import.meta.url), 'utf-8')
|
|
35
|
+
* shape at build time and inlines the file into the GJS bundle, so the
|
|
36
|
+
* template is available without runtime file I/O against the install dir.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadBiomeTemplate(): string;
|
|
39
|
+
/** Helper for callers to surface the install hint to the user cleanly. */
|
|
40
|
+
export declare function printBiomeNotFound(err: BiomeNotFoundError): void;
|
|
41
|
+
/**
|
|
42
|
+
* Has `@biomejs/biome` (the npm wrapper package) been declared in the
|
|
43
|
+
* project's `package.json` devDependencies or dependencies? Useful as a
|
|
44
|
+
* cheap pre-flight check — `gjsify flatpak init`'s G.2 post-format hook
|
|
45
|
+
* uses this to decide whether to auto-format its outputs.
|
|
46
|
+
*/
|
|
47
|
+
export declare function hasBiomeDevDep(cwd?: string): boolean;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// biome native-binary resolution + spawn helpers.
|
|
2
|
+
//
|
|
3
|
+
// Biome ships its real binary as per-platform optionalDependencies of
|
|
4
|
+
// `@biomejs/biome` (e.g. `@biomejs/cli-linux-x64/biome`). The published
|
|
5
|
+
// `bin/biome` script in @biomejs/biome is a Node.js launcher that picks
|
|
6
|
+
// the right platform package and spawns its binary. gjsify skips that
|
|
7
|
+
// Node launcher and resolves the platform-specific binary directly —
|
|
8
|
+
// same pattern as gjsify resolves @gjsify/<vala>-native prebuilds from
|
|
9
|
+
// node_modules at runtime.
|
|
10
|
+
//
|
|
11
|
+
// Resolution order (workspace-aware):
|
|
12
|
+
// 1. Project's local node_modules (cwd → cwd/node_modules)
|
|
13
|
+
// 2. Workspace root's node_modules (walk up via findWorkspaceRoot)
|
|
14
|
+
// 3. ENOENT → install hint
|
|
15
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
16
|
+
import { join, resolve } from 'node:path';
|
|
17
|
+
import { spawn } from 'node:child_process';
|
|
18
|
+
import { findWorkspaceRoot } from './workspace-root.js';
|
|
19
|
+
/** Map Node.js `process.platform` + `arch` to the biome platform-package suffix. */
|
|
20
|
+
function biomePackageSuffix() {
|
|
21
|
+
const platform = process.platform;
|
|
22
|
+
const arch = process.arch;
|
|
23
|
+
let plat;
|
|
24
|
+
if (platform === 'linux')
|
|
25
|
+
plat = 'linux';
|
|
26
|
+
else if (platform === 'darwin')
|
|
27
|
+
plat = 'darwin';
|
|
28
|
+
else if (platform === 'win32')
|
|
29
|
+
plat = 'win32';
|
|
30
|
+
else
|
|
31
|
+
throw new Error(`[gjsify biome] Unsupported platform: ${platform}`);
|
|
32
|
+
let a;
|
|
33
|
+
if (arch === 'x64')
|
|
34
|
+
a = 'x64';
|
|
35
|
+
else if (arch === 'arm64')
|
|
36
|
+
a = 'arm64';
|
|
37
|
+
else
|
|
38
|
+
throw new Error(`[gjsify biome] Unsupported arch on ${plat}: ${arch}`);
|
|
39
|
+
// musl detection on Linux — biome ships separate musl binaries.
|
|
40
|
+
// Standard approach (matches biome's own launcher): probe for the
|
|
41
|
+
// musl loader. glibc systems have `/lib/ld-linux-*`, musl has
|
|
42
|
+
// `/lib/ld-musl-*`.
|
|
43
|
+
if (plat === 'linux') {
|
|
44
|
+
try {
|
|
45
|
+
const { readdirSync } = require('node:fs');
|
|
46
|
+
const libEntries = readdirSync('/lib');
|
|
47
|
+
if (libEntries.some((e) => e.startsWith('ld-musl-'))) {
|
|
48
|
+
return `${plat}-${a}-musl`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// /lib unreadable — fall through, glibc is the safer default
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return `${plat}-${a}`;
|
|
56
|
+
}
|
|
57
|
+
/** Binary filename inside the platform package — `.exe` on Windows. */
|
|
58
|
+
function biomeBinFilename() {
|
|
59
|
+
return process.platform === 'win32' ? 'biome.exe' : 'biome';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Search a starting directory's `node_modules/<pkg>/<binFile>` for the
|
|
63
|
+
* biome binary. Returns absolute path or null if not present.
|
|
64
|
+
*/
|
|
65
|
+
function probeNodeModules(dir, pkg, binFile) {
|
|
66
|
+
const candidate = join(dir, 'node_modules', pkg, binFile);
|
|
67
|
+
return existsSync(candidate) ? candidate : null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolve the absolute path to the biome native binary for the current
|
|
71
|
+
* platform. Walks cwd → workspace-root looking for the matching
|
|
72
|
+
* `@biomejs/cli-<platform>-<arch>` package.
|
|
73
|
+
*
|
|
74
|
+
* Throws with a clear install-hint when not found.
|
|
75
|
+
*/
|
|
76
|
+
export function findBiomeBin(cwd = process.cwd()) {
|
|
77
|
+
const suffix = biomePackageSuffix();
|
|
78
|
+
const pkg = `@biomejs/cli-${suffix}`;
|
|
79
|
+
const binFile = biomeBinFilename();
|
|
80
|
+
// 1. Local node_modules
|
|
81
|
+
const local = probeNodeModules(cwd, pkg, binFile);
|
|
82
|
+
if (local)
|
|
83
|
+
return local;
|
|
84
|
+
// 2. Walk up to workspace root, probe its node_modules
|
|
85
|
+
const wsRoot = findWorkspaceRoot(cwd);
|
|
86
|
+
if (wsRoot && wsRoot !== cwd) {
|
|
87
|
+
const fromRoot = probeNodeModules(wsRoot, pkg, binFile);
|
|
88
|
+
if (fromRoot)
|
|
89
|
+
return fromRoot;
|
|
90
|
+
}
|
|
91
|
+
// 3. Walk parent dirs as a last resort (handles nested-without-workspace setups)
|
|
92
|
+
let dir = resolve(cwd, '..');
|
|
93
|
+
for (let i = 0; i < 6; i++) {
|
|
94
|
+
const found = probeNodeModules(dir, pkg, binFile);
|
|
95
|
+
if (found)
|
|
96
|
+
return found;
|
|
97
|
+
const parent = resolve(dir, '..');
|
|
98
|
+
if (parent === dir)
|
|
99
|
+
break;
|
|
100
|
+
dir = parent;
|
|
101
|
+
}
|
|
102
|
+
throw new BiomeNotFoundError(pkg, cwd);
|
|
103
|
+
}
|
|
104
|
+
export class BiomeNotFoundError extends Error {
|
|
105
|
+
pkg;
|
|
106
|
+
cwd;
|
|
107
|
+
constructor(pkg, cwd) {
|
|
108
|
+
super(`[gjsify biome] biome native binary not found.\n` +
|
|
109
|
+
` Expected: ${pkg}/biome in node_modules of ${cwd} or any workspace root above it.\n` +
|
|
110
|
+
` Install it via: gjsify install -D @biomejs/biome\n` +
|
|
111
|
+
` (this adds @biomejs/biome to devDependencies; the matching @biomejs/cli-<platform>-<arch> ` +
|
|
112
|
+
`package lands automatically as an optionalDependency.)`);
|
|
113
|
+
this.pkg = pkg;
|
|
114
|
+
this.cwd = cwd;
|
|
115
|
+
this.name = 'BiomeNotFoundError';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Walk up from a starting directory to find the nearest `biome.json` or
|
|
120
|
+
* `biome.jsonc`. Returns absolute path or null. Workspace-aware: also
|
|
121
|
+
* probes the workspace root.
|
|
122
|
+
*/
|
|
123
|
+
export function findBiomeConfig(cwd = process.cwd()) {
|
|
124
|
+
const candidates = ['biome.json', 'biome.jsonc'];
|
|
125
|
+
let dir = cwd;
|
|
126
|
+
for (let i = 0; i < 12; i++) {
|
|
127
|
+
for (const name of candidates) {
|
|
128
|
+
const path = join(dir, name);
|
|
129
|
+
if (existsSync(path))
|
|
130
|
+
return path;
|
|
131
|
+
}
|
|
132
|
+
const parent = resolve(dir, '..');
|
|
133
|
+
if (parent === dir)
|
|
134
|
+
break;
|
|
135
|
+
dir = parent;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Spawn biome with the given args. Inherits stdio so biome's own output
|
|
141
|
+
* (formatted source, lint diagnostics, summary lines) reaches the user.
|
|
142
|
+
*
|
|
143
|
+
* Returns the exit code as a number; never throws on non-zero exit
|
|
144
|
+
* (callers check the code).
|
|
145
|
+
*/
|
|
146
|
+
export function runBiome(args, opts = {}) {
|
|
147
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
148
|
+
const bin = findBiomeBin(cwd);
|
|
149
|
+
if (opts.verbose) {
|
|
150
|
+
console.log(`[gjsify biome] ${bin} ${args.join(' ')}`);
|
|
151
|
+
}
|
|
152
|
+
return new Promise((res, rej) => {
|
|
153
|
+
const spawnOpts = { stdio: 'inherit', cwd };
|
|
154
|
+
const child = spawn(bin, args, spawnOpts);
|
|
155
|
+
child.on('error', (err) => {
|
|
156
|
+
if (err.code === 'ENOENT') {
|
|
157
|
+
rej(new BiomeNotFoundError(`<resolved bin>`, cwd));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
rej(err);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
child.on('exit', (code, signal) => {
|
|
164
|
+
if (signal) {
|
|
165
|
+
console.error(`[gjsify biome] terminated by signal ${signal}`);
|
|
166
|
+
res(1);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
res(code ?? 0);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Lazy-load the embedded `biome.json.tmpl` content. The static-read-inliner
|
|
175
|
+
* matches this readFileSync(new URL(<lit>, import.meta.url), 'utf-8')
|
|
176
|
+
* shape at build time and inlines the file into the GJS bundle, so the
|
|
177
|
+
* template is available without runtime file I/O against the install dir.
|
|
178
|
+
*/
|
|
179
|
+
export function loadBiomeTemplate() {
|
|
180
|
+
return readFileSync(new URL('../templates/biome.json.tmpl', import.meta.url), 'utf-8');
|
|
181
|
+
}
|
|
182
|
+
/** Helper for callers to surface the install hint to the user cleanly. */
|
|
183
|
+
export function printBiomeNotFound(err) {
|
|
184
|
+
console.error(err.message);
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Has `@biomejs/biome` (the npm wrapper package) been declared in the
|
|
188
|
+
* project's `package.json` devDependencies or dependencies? Useful as a
|
|
189
|
+
* cheap pre-flight check — `gjsify flatpak init`'s G.2 post-format hook
|
|
190
|
+
* uses this to decide whether to auto-format its outputs.
|
|
191
|
+
*/
|
|
192
|
+
export function hasBiomeDevDep(cwd = process.cwd()) {
|
|
193
|
+
const pkgPath = join(cwd, 'package.json');
|
|
194
|
+
if (!existsSync(pkgPath))
|
|
195
|
+
return false;
|
|
196
|
+
try {
|
|
197
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
198
|
+
return Boolean(pkg?.devDependencies?.['@biomejs/biome'] ||
|
|
199
|
+
pkg?.dependencies?.['@biomejs/biome']);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.14",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"clear": "rm -rf lib dist tsconfig.tsbuildinfo || exit 0",
|
|
24
24
|
"check": "tsc --noEmit",
|
|
25
25
|
"start": "node lib/index.js",
|
|
26
|
-
"build": "tsc && mkdir -p lib/templates/flatpak && cp -L src/templates/install.mjs.tmpl lib/templates/install.mjs.tmpl && cp src/templates/flatpak/*.tmpl lib/templates/flatpak/ && gjsify run chmod",
|
|
26
|
+
"build": "tsc && mkdir -p lib/templates/flatpak && cp -L src/templates/install.mjs.tmpl lib/templates/install.mjs.tmpl && cp src/templates/flatpak/*.tmpl lib/templates/flatpak/ && cp src/templates/biome.json.tmpl lib/templates/biome.json.tmpl && gjsify run chmod",
|
|
27
27
|
"build:gjs-bundle": "node lib/index.js build src/index.ts --app gjs --outfile dist/cli.gjs.mjs --shebang",
|
|
28
28
|
"chmod": "chmod +x ./lib/index.js",
|
|
29
29
|
"build:test:node": "node lib/index.js build src/test.mts --app node --outfile dist/test.node.mjs",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"cli"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@gjsify/buffer": "^0.4.
|
|
41
|
-
"@gjsify/create-app": "^0.4.
|
|
42
|
-
"@gjsify/node-globals": "^0.4.
|
|
43
|
-
"@gjsify/node-polyfills": "^0.4.
|
|
44
|
-
"@gjsify/npm-registry": "^0.4.
|
|
45
|
-
"@gjsify/resolve-npm": "^0.4.
|
|
46
|
-
"@gjsify/rolldown-plugin-gjsify": "^0.4.
|
|
47
|
-
"@gjsify/rolldown-plugin-pnp": "^0.4.
|
|
48
|
-
"@gjsify/semver": "^0.4.
|
|
49
|
-
"@gjsify/tar": "^0.4.
|
|
50
|
-
"@gjsify/web-polyfills": "^0.4.
|
|
51
|
-
"@gjsify/workspace": "^0.4.
|
|
40
|
+
"@gjsify/buffer": "^0.4.14",
|
|
41
|
+
"@gjsify/create-app": "^0.4.14",
|
|
42
|
+
"@gjsify/node-globals": "^0.4.14",
|
|
43
|
+
"@gjsify/node-polyfills": "^0.4.14",
|
|
44
|
+
"@gjsify/npm-registry": "^0.4.14",
|
|
45
|
+
"@gjsify/resolve-npm": "^0.4.14",
|
|
46
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.4.14",
|
|
47
|
+
"@gjsify/rolldown-plugin-pnp": "^0.4.14",
|
|
48
|
+
"@gjsify/semver": "^0.4.14",
|
|
49
|
+
"@gjsify/tar": "^0.4.14",
|
|
50
|
+
"@gjsify/web-polyfills": "^0.4.14",
|
|
51
|
+
"@gjsify/workspace": "^0.4.14",
|
|
52
52
|
"cosmiconfig": "^9.0.1",
|
|
53
53
|
"get-tsconfig": "^4.14.0",
|
|
54
54
|
"pkg-types": "^2.3.1",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"yargs": "^18.0.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@gjsify/unit": "^0.4.
|
|
59
|
+
"@gjsify/unit": "^0.4.14",
|
|
60
60
|
"@types/yargs": "^17.0.35",
|
|
61
61
|
"typescript": "^6.0.3"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@gjsify/rolldown-native": "^0.4.
|
|
64
|
+
"@gjsify/rolldown-native": "^0.4.14"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@gjsify/rolldown-native": {
|