@gjsify/cli 0.4.27 → 0.4.29

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.
Files changed (64) hide show
  1. package/dist/cli.gjs.mjs +34 -32
  2. package/lib/actions/barrels-generate.js +1 -5
  3. package/lib/actions/build.d.ts +3 -3
  4. package/lib/actions/build.js +56 -64
  5. package/lib/bundler-pick.d.ts +3 -3
  6. package/lib/bundler-pick.js +5 -6
  7. package/lib/commands/build.js +37 -31
  8. package/lib/commands/check.js +3 -3
  9. package/lib/commands/fix.js +33 -23
  10. package/lib/commands/flatpak/build.js +6 -2
  11. package/lib/commands/flatpak/check.js +9 -3
  12. package/lib/commands/flatpak/ci.js +1 -2
  13. package/lib/commands/flatpak/deps.js +1 -2
  14. package/lib/commands/flatpak/diff.js +2 -6
  15. package/lib/commands/flatpak/init.js +19 -19
  16. package/lib/commands/flatpak/release.js +2 -2
  17. package/lib/commands/flatpak/scaffold.js +3 -11
  18. package/lib/commands/flatpak/sync-flathub.js +4 -8
  19. package/lib/commands/flatpak/utils.js +1 -6
  20. package/lib/commands/foreach.js +5 -14
  21. package/lib/commands/format.js +54 -41
  22. package/lib/commands/gettext.js +2 -10
  23. package/lib/commands/gresource.js +2 -8
  24. package/lib/commands/gsettings.js +1 -3
  25. package/lib/commands/install.js +13 -6
  26. package/lib/commands/lint.d.ts +1 -1
  27. package/lib/commands/lint.js +22 -22
  28. package/lib/commands/pack.js +29 -17
  29. package/lib/commands/publish.d.ts +1 -0
  30. package/lib/commands/publish.js +113 -21
  31. package/lib/commands/run.js +2 -6
  32. package/lib/commands/self-update.js +36 -8
  33. package/lib/commands/showcase.js +1 -1
  34. package/lib/commands/system-check.js +8 -11
  35. package/lib/commands/test.js +12 -8
  36. package/lib/commands/uninstall.js +1 -3
  37. package/lib/commands/upgrade.d.ts +1 -1
  38. package/lib/commands/upgrade.js +109 -120
  39. package/lib/commands/workspace.js +1 -3
  40. package/lib/config.js +18 -13
  41. package/lib/index.js +21 -0
  42. package/lib/templates/install.mjs.tmpl +20 -14
  43. package/lib/templates/oxfmtrc.tmpl +54 -0
  44. package/lib/templates/oxlintrc.json.tmpl +35 -0
  45. package/lib/types/config-data.d.ts +23 -13
  46. package/lib/utils/check-system-deps.js +10 -4
  47. package/lib/utils/detect-native-packages.js +1 -1
  48. package/lib/utils/dlx-cache.js +2 -7
  49. package/lib/utils/install-backend-native.d.ts +2 -2
  50. package/lib/utils/install-backend-native.js +72 -63
  51. package/lib/utils/install-backend.d.ts +13 -0
  52. package/lib/utils/install-backend.js +2 -1
  53. package/lib/utils/install-global.js +1 -3
  54. package/lib/utils/normalize-bundler-options.js +52 -17
  55. package/lib/utils/oxc-resolve.d.ts +63 -0
  56. package/lib/utils/oxc-resolve.js +264 -0
  57. package/lib/utils/pkg-json-edit.js +1 -6
  58. package/lib/utils/run-gjs.js +1 -4
  59. package/lib/utils/run-lifecycle-script.js +3 -7
  60. package/lib/utils/workspace-root.js +3 -1
  61. package/package.json +17 -17
  62. package/lib/templates/biome.json.tmpl +0 -79
  63. package/lib/utils/biome-resolve.d.ts +0 -47
  64. package/lib/utils/biome-resolve.js +0 -204
@@ -1,47 +0,0 @@
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;
@@ -1,204 +0,0 @@
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
- }