@gjsify/cli 0.3.20 → 0.4.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.
Files changed (67) hide show
  1. package/dist/cli.gjs.mjs +798 -0
  2. package/lib/actions/build.js +4 -17
  3. package/lib/bundler-pick.d.ts +79 -0
  4. package/lib/bundler-pick.js +428 -0
  5. package/lib/commands/foreach.d.ts +16 -0
  6. package/lib/commands/foreach.js +268 -0
  7. package/lib/commands/index.d.ts +2 -0
  8. package/lib/commands/index.js +2 -0
  9. package/lib/commands/install.d.ts +1 -0
  10. package/lib/commands/install.js +222 -26
  11. package/lib/commands/run.d.ts +1 -1
  12. package/lib/commands/run.js +133 -20
  13. package/lib/commands/workspace.d.ts +8 -0
  14. package/lib/commands/workspace.js +69 -0
  15. package/lib/config.js +26 -0
  16. package/lib/index.js +11 -3
  17. package/lib/types/config-data.d.ts +10 -1
  18. package/lib/utils/install-backend-native.d.ts +5 -1
  19. package/lib/utils/install-backend-native.js +88 -11
  20. package/lib/utils/install-backend.d.ts +11 -1
  21. package/lib/utils/install-backend.js +4 -2
  22. package/lib/utils/pkg-json-edit.d.ts +47 -0
  23. package/lib/utils/pkg-json-edit.js +108 -0
  24. package/package.json +36 -12
  25. package/src/actions/build.ts +0 -431
  26. package/src/actions/index.ts +0 -1
  27. package/src/commands/build.ts +0 -146
  28. package/src/commands/check.ts +0 -87
  29. package/src/commands/create.ts +0 -63
  30. package/src/commands/dlx.ts +0 -195
  31. package/src/commands/flatpak/build.ts +0 -225
  32. package/src/commands/flatpak/ci.ts +0 -173
  33. package/src/commands/flatpak/deps.ts +0 -120
  34. package/src/commands/flatpak/index.ts +0 -53
  35. package/src/commands/flatpak/init.ts +0 -191
  36. package/src/commands/flatpak/utils.ts +0 -76
  37. package/src/commands/gettext.ts +0 -258
  38. package/src/commands/gresource.ts +0 -97
  39. package/src/commands/gsettings.ts +0 -87
  40. package/src/commands/index.ts +0 -12
  41. package/src/commands/info.ts +0 -70
  42. package/src/commands/install.ts +0 -195
  43. package/src/commands/run.ts +0 -33
  44. package/src/commands/showcase.ts +0 -149
  45. package/src/config.ts +0 -289
  46. package/src/constants.ts +0 -1
  47. package/src/index.ts +0 -37
  48. package/src/types/cli-build-options.ts +0 -100
  49. package/src/types/command.ts +0 -10
  50. package/src/types/config-data-library.ts +0 -5
  51. package/src/types/config-data-typescript.ts +0 -6
  52. package/src/types/config-data.ts +0 -225
  53. package/src/types/cosmiconfig-result.ts +0 -5
  54. package/src/types/index.ts +0 -6
  55. package/src/utils/check-system-deps.ts +0 -480
  56. package/src/utils/detect-native-packages.ts +0 -153
  57. package/src/utils/discover-showcases.ts +0 -75
  58. package/src/utils/dlx-cache.ts +0 -135
  59. package/src/utils/install-backend-native.ts +0 -363
  60. package/src/utils/install-backend.ts +0 -88
  61. package/src/utils/install-global.ts +0 -182
  62. package/src/utils/normalize-bundler-options.ts +0 -129
  63. package/src/utils/parse-spec.ts +0 -48
  64. package/src/utils/resolve-gjs-entry.ts +0 -96
  65. package/src/utils/resolve-plugin-by-name.ts +0 -106
  66. package/src/utils/run-gjs.ts +0 -90
  67. package/tsconfig.json +0 -16
package/src/index.ts DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
- import yargs from 'yargs'
3
- import { hideBin } from 'yargs/helpers'
4
-
5
- import {
6
- buildCommand as build,
7
- runCommand as run,
8
- infoCommand as info,
9
- checkCommand as check,
10
- showcaseCommand as showcase,
11
- createCommand as create,
12
- gresourceCommand as gresource,
13
- gettextCommand as gettext,
14
- gsettingsCommand as gsettings,
15
- flatpakCommand as flatpak,
16
- dlxCommand as dlx,
17
- installCommand as install,
18
- } from './commands/index.js'
19
- import { APP_NAME } from './constants.js'
20
-
21
- void yargs(hideBin(process.argv))
22
- .scriptName(APP_NAME)
23
- .strict()
24
- .command(create.command, create.description, create.builder, create.handler)
25
- .command(install.command, install.description, install.builder, install.handler)
26
- .command(build.command, build.description, build.builder, build.handler)
27
- .command(run.command, run.description, run.builder, run.handler)
28
- .command(dlx.command, dlx.description, dlx.builder, dlx.handler)
29
- .command(info.command, info.description, info.builder, info.handler)
30
- .command(check.command, check.description, check.builder, check.handler)
31
- .command(showcase.command, showcase.description, showcase.builder, showcase.handler)
32
- .command(gresource.command, gresource.description, gresource.builder, gresource.handler)
33
- .command(gettext.command, gettext.description, gettext.builder, gettext.handler)
34
- .command(gsettings.command, gsettings.description, gsettings.builder, gsettings.handler)
35
- .command(flatpak.command, flatpak.description, flatpak.builder, flatpak.handler)
36
- .demandCommand(1)
37
- .help().argv
@@ -1,100 +0,0 @@
1
- import type { App } from '@gjsify/rolldown-plugin-gjsify';
2
-
3
- export interface CliBuildOptions {
4
- /**
5
- * This is an array of files that each serve as an input to the bundling algorithm.
6
- * @see https://esbuild.github.io/api/#entry-points
7
- */
8
- entryPoints?: string[];
9
- /** Switch on the verbose mode */
10
- verbose?: boolean;
11
- /**
12
- * When enabled, the generated code will be minified instead of pretty-printed.
13
- * @see https://esbuild.github.io/api/#minify
14
- */
15
- minify?: boolean;
16
- /**
17
- * Override the default output format.
18
- * @see https://esbuild.github.io/api/#format
19
- */
20
- format?: 'iife' | 'esm' | 'cjs';
21
- /** Use this if you want to build an application or test, the platform node is usually only used internally to build the tests for Gjsify */
22
- app?: App;
23
- /** Use this if you want to build a library for Gjsify */
24
- library?: boolean;
25
- /**
26
- * This option sets the output file name for the build operation.
27
- * This is only applicable if there is a single entry point.
28
- * If there are multiple entry points, you must use the outdir option instead to specify an output directory.
29
- * @see https://esbuild.github.io/api/#outfile
30
- */
31
- outfile?: string;
32
- /**
33
- * This option sets the output directory for the build operation.
34
- * @see https://esbuild.github.io/api/#outdir
35
- */
36
- outdir?: string;
37
- /** Enables TypeScript types on runtime using Deepkit's type compiler */
38
- reflection?: boolean;
39
- /**
40
- * The log level can be changed to prevent esbuild from printing warning and/or error messages to the terminal
41
- * @see https://esbuild.github.io/api/#log-level
42
- */
43
- logLevel: 'silent' | 'error' | 'warning' | 'info' | 'debug' | 'verbose';
44
- /** An array of glob patterns to exclude matches and aliases */
45
- exclude?: string[];
46
- /**
47
- * Inject a console shim into GJS builds for clean output (no GLib prefix, ANSI colors work).
48
- * Use --no-console-shim to disable. Only applies to GJS app builds. Default: true.
49
- */
50
- consoleShim?: boolean;
51
- /**
52
- * Comma-separated list of global identifiers your code needs (e.g.
53
- * `"fetch,Buffer,process,URL,crypto"`). Each identifier is mapped to the
54
- * corresponding `@gjsify/<pkg>/register` module and injected into the
55
- * bundle. Only applies to GJS app builds.
56
- */
57
- globals?: string;
58
- /**
59
- * Prepend a `#!/usr/bin/env -S gjs -m` shebang to the output file and mark
60
- * it executable (chmod 755). Only applies to GJS app builds with a single
61
- * `--outfile`. Default: false.
62
- */
63
- shebang?: boolean;
64
- /**
65
- * Module names that should NOT be bundled. Each name remains as a literal
66
- * `import`/`require` in the output and is resolved by the runtime against
67
- * its own `node_modules` (or equivalent) at execution time.
68
- *
69
- * Repeat the flag or pass a comma-separated value:
70
- * `--external typedoc,prettier --external typescript`. Glob-style wildcards
71
- * (`@inquirer/*`, `lodash-*`) are forwarded as-is to esbuild.
72
- *
73
- * @see https://esbuild.github.io/api/#external
74
- */
75
- external?: string[];
76
- /**
77
- * Substitute compile-time constants in the bundle. Each entry is a
78
- * `KEY=VALUE` pair where `VALUE` is an arbitrary JS expression — string
79
- * literals must be quoted (`--define VERSION='"1.2.3"'`). Useful for
80
- * upstream packages that read a build-time constant via
81
- * `typeof __FOO__ !== 'undefined'`.
82
- *
83
- * @see https://esbuild.github.io/api/#define
84
- */
85
- define?: string[];
86
- /**
87
- * Map module specifiers to alternative targets at bundle time. Each entry
88
- * is `FROM=TO` where `FROM` is the imported package name and `TO` is the
89
- * substitute (typically `@gjsify/empty` to drop a heavy dep that the test
90
- * scenario never executes). Layered on top of the built-in alias map.
91
- */
92
- alias?: string[];
93
- /**
94
- * Comma-separated global identifiers to remove from the auto-detected set.
95
- * Useful for false positives from dead browser-compat code in npm deps
96
- * whose polyfills require unavailable native libraries.
97
- * Example: `--exclude-globals fetch,XMLHttpRequest`
98
- */
99
- excludeGlobals?: string[];
100
- }
@@ -1,10 +0,0 @@
1
- import type { ArgumentsCamelCase, MiddlewareFunction, BuilderCallback } from 'yargs';
2
-
3
- export interface Command <T = any, U = T> {
4
- command: string | ReadonlyArray<string>,
5
- description: string,
6
- builder?: BuilderCallback<T, U>,
7
- handler?: (args: ArgumentsCamelCase<U>) => void | Promise<void>,
8
- middlewares?: MiddlewareFunction[],
9
- deprecated?: boolean | string,
10
- }
@@ -1,5 +0,0 @@
1
- import type { PackageJson } from 'pkg-types';
2
-
3
- export interface ConfigDataLibrary extends PackageJson {
4
-
5
- }
@@ -1,6 +0,0 @@
1
- import type { TsConfigJsonResolved } from 'get-tsconfig';
2
-
3
- export interface ConfigDataTypescript extends TsConfigJsonResolved {
4
- /** Enables TypeScript types on runtime using Deepkit's type compiler */
5
- reflection?: boolean;
6
- }
@@ -1,225 +0,0 @@
1
- import type { RolldownOptions, OutputOptions, RolldownPluginOption } from 'rolldown';
2
- import type { ConfigDataLibrary, ConfigDataTypescript } from './index.js';
3
-
4
- /**
5
- * Plugin entry resolvable by package name from the project's `node_modules`.
6
- * Lets users describe the plugin chain in `package.json#gjsify` without
7
- * dropping to a JS-form config file. The CLI imports the named module,
8
- * picks the chosen export (defaults to `default`), and calls it with
9
- * `options`.
10
- *
11
- * Example:
12
- * ```jsonc
13
- * { "name": "@gjsify/vite-plugin-blueprint", "options": { "minify": true } }
14
- * { "name": "@gjsify/vite-plugin-gettext", "export": "msgfmtPlugin", "options": { ... } }
15
- * ```
16
- */
17
- export interface BundlerPluginByName {
18
- name: string;
19
- export?: string;
20
- options?: unknown;
21
- }
22
-
23
- /**
24
- * Subset of `RolldownOptions` accepted in `.gjsifyrc.js`. Mirrors the legacy
25
- * `esbuild?: BuildOptions` field — a thin pass-through. The orchestrator
26
- * applies platform defaults on top of these, so most projects only need
27
- * `output.file` / `output.dir` here.
28
- *
29
- * `output` is constrained to a single `OutputOptions` object (Rolldown also
30
- * accepts an array for multi-output builds, but the CLI surface targets the
31
- * single-output use case).
32
- *
33
- * `plugins` is widened to also accept `BundlerPluginByName` entries — these
34
- * are resolved by the CLI from the project's `node_modules` before the
35
- * Rolldown call.
36
- */
37
- export type BundlerOptions = Omit<RolldownOptions, 'output' | 'plugins'> & {
38
- output?: OutputOptions;
39
- plugins?: Array<RolldownPluginOption | BundlerPluginByName>;
40
- };
41
-
42
- /**
43
- * Legacy `esbuild?: BuildOptions` shape — kept as a compatibility shim for
44
- * one minor release. Setting it logs a deprecation warning; the supported
45
- * subset of fields is mapped into `bundler` at config-load time.
46
- *
47
- * Drop in 0.5.0.
48
- */
49
- export interface LegacyEsbuildOptions {
50
- outfile?: string;
51
- outdir?: string;
52
- format?: 'esm' | 'cjs' | 'iife';
53
- external?: string[];
54
- define?: Record<string, string>;
55
- inject?: string[];
56
- banner?: { js?: string };
57
- target?: string | string[];
58
- minify?: boolean;
59
- sourcemap?: boolean | 'inline' | 'external' | 'both';
60
- mainFields?: string[];
61
- conditions?: string[];
62
- platform?: 'browser' | 'node' | 'neutral';
63
- loader?: Record<string, string>;
64
- }
65
-
66
- export interface ConfigData {
67
- /** Switch on the verbose mode */
68
- verbose?: boolean;
69
- /**
70
- * Bundler-level options forwarded to Rolldown. Replaces the legacy
71
- * `esbuild` field. The orchestrator applies platform-specific defaults
72
- * on top — most projects only need to set `output.file` / `output.dir`.
73
- */
74
- bundler?: BundlerOptions;
75
- /**
76
- * @deprecated Use `bundler` instead. Will be removed in 0.5.0. The shim
77
- * maps the supported subset of esbuild fields into the equivalent
78
- * Rolldown shape and logs a deprecation warning.
79
- */
80
- esbuild?: LegacyEsbuildOptions;
81
- library?: ConfigDataLibrary;
82
- typescript?: ConfigDataTypescript;
83
- /** An array of glob patterns to exclude matches and aliases */
84
- exclude?: string[];
85
- /**
86
- * Inject a console shim into GJS builds for clean output (no GLib prefix, ANSI colors work).
87
- * Only applies to GJS app builds. Default: true.
88
- */
89
- consoleShim?: boolean;
90
- /**
91
- * Comma-separated list of global identifiers to register in the bundle.
92
- * See CliBuildOptions for format.
93
- */
94
- globals?: string;
95
- /**
96
- * Prepend a shebang to the output bundle and mark it executable.
97
- *
98
- * `true` → use the default `#!/usr/bin/env -S gjs -m` line
99
- * `false` → no shebang (default)
100
- * `"…"` → custom line. Supports `${env:NAME}` and `${env:NAME:-default}`
101
- * placeholders against `process.env`. The leading `#!` is
102
- * added automatically if omitted. Useful when an outer
103
- * build tool (Meson, Flatpak) exports the GJS interpreter
104
- * path as `GJS_CONSOLE` (e.g. `/usr/bin/gjs-console`).
105
- *
106
- * Example: `"shebang": "${env:GJS_CONSOLE:-/usr/bin/env -S gjs} -m"`
107
- *
108
- * See also `CliBuildOptions.shebang`.
109
- */
110
- shebang?: boolean | string;
111
- /**
112
- * Extra module aliases layered on top of the built-in alias map.
113
- * Comes from `gjsify build --alias FROM=TO`.
114
- */
115
- aliases?: Record<string, string>;
116
- /**
117
- * Global identifiers to remove from the auto-detected set before writing
118
- * the inject stub. Useful for false positives from dead browser-compat
119
- * code in npm dependencies whose polyfills require unavailable native libs.
120
- * Example: `["fetch", "XMLHttpRequest"]` excludes the HTTP polyfill stack.
121
- */
122
- excludeGlobals?: string[];
123
- /**
124
- * Compile-time defines populated from `package.json` fields. Each entry
125
- * maps a JS identifier (the define key) to a dotted package.json path.
126
- * Values are JSON-stringified before merging into `bundler.transform.define`.
127
- *
128
- * Example:
129
- * ```jsonc
130
- * "defineFromPackageJson": {
131
- * "__PACKAGE_VERSION__": { "field": "version" },
132
- * "__PACKAGE_NAME__": { "field": "name" }
133
- * }
134
- * ```
135
- *
136
- * Replaces the wrapper-script pattern (`spawnSync('gjsify', ['build',
137
- * '--define', '__VERSION__=' + JSON.stringify(pkg.version)])`) used by
138
- * `@ts-for-gir/cli` before this option existed.
139
- */
140
- defineFromPackageJson?: Record<string, { field: string }>;
141
- /**
142
- * Compile-time defines populated from `process.env` at config-load time.
143
- * Each entry maps a JS identifier to an environment variable name with an
144
- * optional default. Values are JSON-stringified before merging into
145
- * `bundler.transform.define`. When the variable is unset and no default
146
- * is provided, the identifier is replaced with the literal `undefined`
147
- * so consumer code can safely guard with `typeof X === 'undefined'` or
148
- * `X ?? fallback`.
149
- *
150
- * Example:
151
- * ```jsonc
152
- * "defineFromEnv": {
153
- * "__APPLICATION_ID__": { "env": "APPLICATION_ID", "default": "org.example.App" },
154
- * "__PREFIX__": { "env": "PREFIX" }
155
- * }
156
- * ```
157
- *
158
- * Designed for projects whose build is driven by an outer tool (Meson,
159
- * Make, CI) that exports environment variables — avoids a wrapper script
160
- * just to thread them through to the bundler.
161
- */
162
- defineFromEnv?: Record<string, { env: string; default?: string }>;
163
- /**
164
- * Extension → loader-kind map for files Rolldown does not classify
165
- * natively. Currently only `'text'` is implemented — the file's content
166
- * becomes the JS string default export (`export default "<content>"`).
167
- * Replaces the legacy esbuild `loader: { '.ui': 'text' }` pattern.
168
- *
169
- * Example:
170
- * ```jsonc
171
- * "loaders": { ".ui": "text", ".asm": "text" }
172
- * ```
173
- *
174
- * Lives at the top level (not under `bundler`) so it doesn't leak into
175
- * Rolldown's options on pass-through; the CLI converts it into a
176
- * `text-loader` plugin prepended to the bundler's plugin chain.
177
- */
178
- loaders?: Record<string, 'text'>;
179
- /**
180
- * Flatpak-related configuration consumed by `gjsify flatpak <sub>`.
181
- * Lives in its own top-level namespace so the bundler config doesn't
182
- * accumulate concerns and `flatpak init` / `flatpak ci` can read defaults
183
- * declaratively. CLI flags override these values.
184
- */
185
- flatpak?: ConfigDataFlatpak;
186
- }
187
-
188
- /**
189
- * Flatpak-toolchain config consumed by the `gjsify flatpak` subcommand
190
- * group. All fields optional — sensible defaults apply when missing.
191
- */
192
- export interface ConfigDataFlatpak {
193
- /** Reverse-DNS app id, e.g. `eu.jumplink.Learn6502`. Defaults to `package.json#name` if it looks like a reverse-DNS id. */
194
- appId?: string;
195
- /**
196
- * Runtime family. Default `'gnome'` — needed at runtime by GJS bundles
197
- * for GLib/GObject/GIO. `'freedesktop'` is only suitable for non-gjsify
198
- * CLI tools (no GJS interpreter ships in the Freedesktop runtime).
199
- */
200
- runtime?: 'gnome' | 'freedesktop';
201
- /** Runtime/SDK version, e.g. `'50'` for GNOME or `'24.08'` for Freedesktop. */
202
- runtimeVersion?: string;
203
- /** Extra SDK extensions, e.g. `['org.freedesktop.Sdk.Extension.node24']` for build-time `yarn install`. */
204
- sdkExtensions?: string[];
205
- /** Path components prepended to PATH inside the build sandbox. */
206
- appendPath?: string[];
207
- /** The binary name to run (`/app/bin/<command>`). Defaults to `appId`. */
208
- command?: string;
209
- /** Finish-args (capabilities). Default depends on `runtime` + `--cli-only`. */
210
- finishArgs?: string[];
211
- /** Extra Flatpak modules prepended before the app's own meson/simple module (e.g. `blueprint-compiler` build). */
212
- extraModules?: unknown[];
213
- /** Cleanup glob patterns applied to the final manifest, e.g. `['/include', '/lib/pkgconfig']`. */
214
- cleanup?: string[];
215
- /** Source-of-truth lockfile for `gjsify flatpak deps` — `yarn.lock` or `package-lock.json`. */
216
- lockfile?: string;
217
- /**
218
- * GitHub-Actions container image override for `gjsify flatpak ci`.
219
- * Default derived from runtime + runtimeVersion:
220
- * gnome+50 → `ghcr.io/flathub-infra/flatpak-github-actions:gnome-50`
221
- */
222
- ciContainer?: string;
223
- /** Branches the generated workflow triggers on. Default `['main']`. */
224
- ciBranches?: string[];
225
- }
@@ -1,5 +0,0 @@
1
- export type CosmiconfigResult<C = any> = {
2
- config: C;
3
- filepath: string;
4
- isEmpty?: boolean;
5
- } | null;
@@ -1,6 +0,0 @@
1
- export * from './cli-build-options.js';
2
- export * from './command.js';
3
- export * from './config-data-library.js';
4
- export * from './config-data-typescript.js';
5
- export * from './config-data.js';
6
- export * from './cosmiconfig-result.js';