@gjsify/cli 0.3.21 → 0.4.3

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 (69) hide show
  1. package/dist/cli.gjs.mjs +791 -0
  2. package/lib/actions/build.js +4 -17
  3. package/lib/bundler-pick.d.ts +79 -0
  4. package/lib/bundler-pick.js +436 -0
  5. package/lib/commands/foreach.d.ts +17 -0
  6. package/lib/commands/foreach.js +341 -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 +401 -27
  11. package/lib/commands/run.d.ts +1 -1
  12. package/lib/commands/run.js +113 -20
  13. package/lib/commands/workspace.d.ts +8 -0
  14. package/lib/commands/workspace.js +79 -0
  15. package/lib/config.js +12 -1
  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 +329 -70
  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/lib/utils/workspace-root.d.ts +1 -0
  25. package/lib/utils/workspace-root.js +46 -0
  26. package/package.json +70 -44
  27. package/src/actions/build.ts +0 -431
  28. package/src/actions/index.ts +0 -1
  29. package/src/commands/build.ts +0 -146
  30. package/src/commands/check.ts +0 -87
  31. package/src/commands/create.ts +0 -63
  32. package/src/commands/dlx.ts +0 -195
  33. package/src/commands/flatpak/build.ts +0 -225
  34. package/src/commands/flatpak/ci.ts +0 -173
  35. package/src/commands/flatpak/deps.ts +0 -120
  36. package/src/commands/flatpak/index.ts +0 -53
  37. package/src/commands/flatpak/init.ts +0 -191
  38. package/src/commands/flatpak/utils.ts +0 -76
  39. package/src/commands/gettext.ts +0 -258
  40. package/src/commands/gresource.ts +0 -97
  41. package/src/commands/gsettings.ts +0 -87
  42. package/src/commands/index.ts +0 -12
  43. package/src/commands/info.ts +0 -70
  44. package/src/commands/install.ts +0 -195
  45. package/src/commands/run.ts +0 -33
  46. package/src/commands/showcase.ts +0 -149
  47. package/src/config.ts +0 -304
  48. package/src/constants.ts +0 -1
  49. package/src/index.ts +0 -37
  50. package/src/types/cli-build-options.ts +0 -100
  51. package/src/types/command.ts +0 -10
  52. package/src/types/config-data-library.ts +0 -5
  53. package/src/types/config-data-typescript.ts +0 -6
  54. package/src/types/config-data.ts +0 -225
  55. package/src/types/cosmiconfig-result.ts +0 -5
  56. package/src/types/index.ts +0 -6
  57. package/src/utils/check-system-deps.ts +0 -480
  58. package/src/utils/detect-native-packages.ts +0 -153
  59. package/src/utils/discover-showcases.ts +0 -75
  60. package/src/utils/dlx-cache.ts +0 -135
  61. package/src/utils/install-backend-native.ts +0 -363
  62. package/src/utils/install-backend.ts +0 -88
  63. package/src/utils/install-global.ts +0 -182
  64. package/src/utils/normalize-bundler-options.ts +0 -129
  65. package/src/utils/parse-spec.ts +0 -48
  66. package/src/utils/resolve-gjs-entry.ts +0 -96
  67. package/src/utils/resolve-plugin-by-name.ts +0 -106
  68. package/src/utils/run-gjs.ts +0 -90
  69. package/tsconfig.json +0 -16
@@ -0,0 +1,79 @@
1
+ // `gjsify workspace <name> <script> [args..]` — yarn-workspace shortcut.
2
+ //
3
+ // Equivalent to `yarn workspace <name> run <script>`: locates the named
4
+ // workspace in the current monorepo, then runs the script there. Used
5
+ // extensively in gjsify's own root `package.json` (17 call sites).
6
+ import { spawn } from 'node:child_process';
7
+ import { discoverWorkspaces } from '@gjsify/workspace';
8
+ import { findWorkspaceRoot } from '../utils/workspace-root.js';
9
+ export const workspaceCommand = {
10
+ command: 'workspace <name> <script> [args..]',
11
+ description: 'Run a workspace script (`yarn workspace <name> run <script>` equivalent).',
12
+ builder: (yargs) => yargs
13
+ .positional('name', {
14
+ description: 'Workspace name (matches package.json `name` field).',
15
+ type: 'string',
16
+ demandOption: true,
17
+ })
18
+ .positional('script', {
19
+ description: 'Script name to run inside that workspace.',
20
+ type: 'string',
21
+ demandOption: true,
22
+ })
23
+ .positional('args', {
24
+ description: 'Extra arguments forwarded to the script.',
25
+ type: 'string',
26
+ array: true,
27
+ }),
28
+ handler: async (args) => {
29
+ // Walk up to the monorepo root — `gjsify workspace` is often
30
+ // invoked from a child workspace's script (e.g. website's
31
+ // `build:deps` calls `gjsify workspace @gjsify/adwaita-web …`),
32
+ // where process.cwd() is the child workspace, not the monorepo root.
33
+ const root = findWorkspaceRoot(process.cwd()) ?? process.cwd();
34
+ const workspaces = discoverWorkspaces(root);
35
+ const target = workspaces.find((w) => w.name === args.name);
36
+ if (!target) {
37
+ console.error(`gjsify workspace: no workspace named "${args.name}" — discovered ${workspaces.length} workspace(s)`);
38
+ process.exit(1);
39
+ }
40
+ const scripts = target.manifest.scripts ?? {};
41
+ if (typeof scripts[args.script] !== 'string') {
42
+ console.error(`gjsify workspace: workspace "${args.name}" has no script "${args.script}"`);
43
+ process.exit(1);
44
+ }
45
+ const runner = detectPackageManager();
46
+ const argv = runner === 'gjsify'
47
+ ? ['run', args.script, ...(args.args ?? [])]
48
+ : ['run', args.script, ...(args.args && args.args.length > 0 ? ['--', ...args.args] : [])];
49
+ await new Promise((resolve, reject) => {
50
+ const child = spawn(runner, argv, {
51
+ cwd: target.location,
52
+ stdio: 'inherit',
53
+ env: process.env,
54
+ });
55
+ child.on('close', (code) => {
56
+ if (code === 0)
57
+ resolve();
58
+ else
59
+ reject(new Error(`${runner} ${argv.join(' ')} exited with code ${code}`));
60
+ });
61
+ child.on('error', reject);
62
+ }).catch((err) => {
63
+ console.error(err.message);
64
+ process.exit(1);
65
+ });
66
+ // ensureMainLoop() (called inside spawn) keeps GJS alive after the
67
+ // child exits — without an explicit process.exit() the success path
68
+ // would park the loop forever.
69
+ process.exit(0);
70
+ },
71
+ };
72
+ function detectPackageManager() {
73
+ const ua = process.env.npm_config_user_agent ?? '';
74
+ if (ua.startsWith('yarn/'))
75
+ return 'yarn';
76
+ if (ua.startsWith('gjsify/'))
77
+ return 'gjsify';
78
+ return 'npm';
79
+ }
package/lib/config.js CHANGED
@@ -247,7 +247,18 @@ export class Config {
247
247
  if (output.minify === undefined)
248
248
  output.minify = true;
249
249
  if (output.minify === true) {
250
- output.minify = { mangle: { keepNames: { function: true, class: true } } };
250
+ // `keepNames: true` on output is the top-level BundlerOptions
251
+ // path: rolldown wires it into both `mangle.keepNames.all_true()`
252
+ // (function+class) AND `compress.keepNames.all_true()` for us.
253
+ // The previous `minify: { mangle: { keepNames: {...} } }` shape
254
+ // worked under npm rolldown's JS API but rolldown's serde
255
+ // `deserialize_minify` (deserialize_minify_options.rs:311) only
256
+ // accepts SimpleMinifyOptions (bool/string), so the object form
257
+ // was rejected by the native facade's JSON-deserializer with
258
+ // "data did not match any variant of untagged enum
259
+ // SimpleMinifyOptions". `output.keepNames` reaches the binding
260
+ // through the documented top-level path in both engines.
261
+ output.keepNames = true;
251
262
  }
252
263
  if (cliArgs.logLevel) {
253
264
  // Map esbuild log levels to Rolldown's narrower set:
package/lib/index.js CHANGED
@@ -1,9 +1,14 @@
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, } from './commands/index.js';
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, } from './commands/index.js';
5
5
  import { APP_NAME } from './constants.js';
6
- void yargs(hideBin(process.argv))
6
+ // `parseAsync()` instead of `.argv` so the top-level await keeps the
7
+ // process alive until command handlers complete. Under Node this is
8
+ // cosmetic — the event loop holds the process up — but under GJS the
9
+ // script ends as soon as the top-level synchronous flow finishes, and
10
+ // fire-and-forget handlers silently exit before any async work runs.
11
+ await yargs(hideBin(process.argv))
7
12
  .scriptName(APP_NAME)
8
13
  .strict()
9
14
  .command(create.command, create.description, create.builder, create.handler)
@@ -18,5 +23,8 @@ void yargs(hideBin(process.argv))
18
23
  .command(gettext.command, gettext.description, gettext.builder, gettext.handler)
19
24
  .command(gsettings.command, gsettings.description, gsettings.builder, gsettings.handler)
20
25
  .command(flatpak.command, flatpak.description, flatpak.builder, flatpak.handler)
26
+ .command(foreach.command, foreach.description, foreach.builder, foreach.handler)
27
+ .command(workspace.command, workspace.description, workspace.builder, workspace.handler)
21
28
  .demandCommand(1)
22
- .help().argv;
29
+ .help()
30
+ .parseAsync();
@@ -202,7 +202,16 @@ export interface ConfigDataFlatpak {
202
202
  runtime?: 'gnome' | 'freedesktop';
203
203
  /** Runtime/SDK version, e.g. `'50'` for GNOME or `'24.08'` for Freedesktop. */
204
204
  runtimeVersion?: string;
205
- /** Extra SDK extensions, e.g. `['org.freedesktop.Sdk.Extension.node24']` for build-time `yarn install`. */
205
+ /**
206
+ * Extra SDK extensions to include in the manifest, e.g.
207
+ * `['org.freedesktop.Sdk.Extension.llvm17']` for projects with native
208
+ * code that needs a specific toolchain. Leave empty (the default) for
209
+ * pure gjsify projects — the GNOME runtime already ships GJS + GLib
210
+ * + libsoup, and `gjsify build` produces a self-contained bundle that
211
+ * needs no build-time Node anymore. (Before Phase D-3 we added
212
+ * `org.freedesktop.Sdk.Extension.node24` here by default for the
213
+ * yarn-install + esbuild build step — that's no longer required.)
214
+ */
206
215
  sdkExtensions?: string[];
207
216
  /** Path components prepended to PATH inside the build sandbox. */
208
217
  appendPath?: string[];
@@ -1,2 +1,6 @@
1
1
  import type { InstallOptions } from "./install-backend.ts";
2
- export declare function installPackagesNative(opts: InstallOptions): Promise<void>;
2
+ export interface InstalledTopLevel {
3
+ name: string;
4
+ version: string;
5
+ }
6
+ export declare function installPackagesNative(opts: InstallOptions): Promise<InstalledTopLevel[]>;