@gjsify/cli 0.4.14 → 0.4.15

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.
@@ -0,0 +1,31 @@
1
+ export type BarrelExtension = 'js' | 'ts' | 'none';
2
+ export interface BarrelsArgs {
3
+ /** Directories to scan. Each gets an `index.ts` re-exporting its sibling source files. */
4
+ paths: string[];
5
+ /** Import-specifier extension. `js`/`ts`/`none`. */
6
+ extension: BarrelExtension;
7
+ /** Resolve `paths` against this directory. Default: `process.cwd()`. */
8
+ baseDir: string;
9
+ /** Skip files whose names match any regex. */
10
+ exclude: RegExp[];
11
+ /** Header comment prepended to every generated file. */
12
+ header: string;
13
+ /** Omit trailing `;` on each export line. */
14
+ noSemicolon: boolean;
15
+ /** Use `'` quotes (default). When false, uses `"`. */
16
+ singleQuotes: boolean;
17
+ /** Report drift without writing. Returns drift count from generator. */
18
+ check: boolean;
19
+ /** Log each file scanned + written. */
20
+ verbose: boolean;
21
+ }
22
+ export declare const DEFAULT_BARRELS_HEADER = "// Auto-generated by `gjsify barrels` \u2014 do not edit by hand.";
23
+ export declare const DEFAULT_BARRELS_EXCLUDES: readonly string[];
24
+ /**
25
+ * Regenerate `index.ts` in every directory in `args.paths`.
26
+ *
27
+ * Returns the number of files that drifted from the canonical output —
28
+ * always 0 when `check` is false (drift is rewritten in-place); non-zero
29
+ * under `check: true` signals CI failure.
30
+ */
31
+ export declare function generateBarrels(args: BarrelsArgs): Promise<number>;
@@ -0,0 +1,78 @@
1
+ // `gjsify barrels` action — regenerate `index.ts` barrel files for one or
2
+ // more directories. Pure async generator, decoupled from yargs so it can
3
+ // be unit-tested in isolation.
4
+ //
5
+ // Adapted from beabee-communityrm/monorepo apps/dev-cli's `generate-index`
6
+ // action (refs/dev-cli — not vendored here): same separation of action vs.
7
+ // command module, same `types/`-dir auto-detection that emits
8
+ // `export type *`, same `export {};` fallback for empty directories,
9
+ // same sorted-output principle. Rewritten for gjsify's yargs CommandModule
10
+ // and `@gjsify/unit` test framework; no external deps. Replaces
11
+ // `barrelsby` (unmaintained since 2022) at consumer sites.
12
+ //
13
+ // Original: Copyright (c) Beabee Community Repo contributors. AGPL-3.0.
14
+ // Reimplemented for gjsify under the project's MIT license.
15
+ import { readdir, readFile, writeFile } from 'node:fs/promises';
16
+ import { basename, extname, join, resolve } from 'node:path';
17
+ export const DEFAULT_BARRELS_HEADER = '// Auto-generated by `gjsify barrels` — do not edit by hand.';
18
+ export const DEFAULT_BARRELS_EXCLUDES = [
19
+ '\\.test\\.',
20
+ '\\.spec\\.',
21
+ '\\.test-data\\.',
22
+ ];
23
+ const SOURCE_FILE_RE = /\.(ts|tsx|mts|cts)$/;
24
+ /**
25
+ * Regenerate `index.ts` in every directory in `args.paths`.
26
+ *
27
+ * Returns the number of files that drifted from the canonical output —
28
+ * always 0 when `check` is false (drift is rewritten in-place); non-zero
29
+ * under `check: true` signals CI failure.
30
+ */
31
+ export async function generateBarrels(args) {
32
+ const quote = args.singleQuotes ? "'" : '"';
33
+ const semicolon = args.noSemicolon ? '' : ';';
34
+ const extSuffix = args.extension === 'none' ? '' : `.${args.extension}`;
35
+ let drift = 0;
36
+ for (const p of args.paths) {
37
+ const dir = resolve(args.baseDir, p);
38
+ const isTypesDir = basename(dir) === 'types';
39
+ let entries;
40
+ try {
41
+ entries = (await readdir(dir, { withFileTypes: true }))
42
+ .filter((e) => e.isFile())
43
+ .filter((e) => SOURCE_FILE_RE.test(e.name))
44
+ .filter((e) => e.name !== 'index.ts')
45
+ .filter((e) => !args.exclude.some((r) => r.test(e.name)))
46
+ .sort((a, b) => a.name.localeCompare(b.name));
47
+ }
48
+ catch (err) {
49
+ if (args.verbose)
50
+ console.error(`[gjsify barrels] skip ${dir}: ${err.message}`);
51
+ continue;
52
+ }
53
+ const lines = entries.map((e) => {
54
+ const stem = basename(e.name, extname(e.name));
55
+ const keyword = isTypesDir ? 'export type *' : 'export *';
56
+ return `${keyword} from ${quote}./${stem}${extSuffix}${quote}${semicolon}`;
57
+ });
58
+ const body = lines.length ? `${lines.join('\n')}\n` : 'export {};\n';
59
+ const out = `${args.header}\n\n${body}`;
60
+ const indexPath = join(dir, 'index.ts');
61
+ const previous = await readFile(indexPath, 'utf-8').catch(() => '');
62
+ if (previous === out) {
63
+ if (args.verbose)
64
+ console.log(`[gjsify barrels] up-to-date: ${indexPath}`);
65
+ continue;
66
+ }
67
+ if (args.check) {
68
+ console.error(`[gjsify barrels] drift: ${indexPath}`);
69
+ drift++;
70
+ }
71
+ else {
72
+ await writeFile(indexPath, out, 'utf-8');
73
+ if (args.verbose)
74
+ console.log(`[gjsify barrels] wrote: ${indexPath}`);
75
+ }
76
+ }
77
+ return drift;
78
+ }
@@ -0,0 +1,15 @@
1
+ import type { Command } from '../types/index.js';
2
+ import { type BarrelExtension } from '../actions/barrels-generate.js';
3
+ interface BarrelsOptions {
4
+ paths?: string[];
5
+ ext?: BarrelExtension;
6
+ baseDir?: string;
7
+ exclude?: string[];
8
+ header?: string;
9
+ semicolon?: boolean;
10
+ singleQuotes?: boolean;
11
+ check?: boolean;
12
+ verbose?: boolean;
13
+ }
14
+ export declare const barrelsCommand: Command<unknown, BarrelsOptions>;
15
+ export {};
@@ -0,0 +1,103 @@
1
+ // `gjsify barrels` — regenerate `index.ts` barrel files for a set of
2
+ // directories. Drop-in replacement for `barrelsby` (unmaintained 2022+).
3
+ //
4
+ // Examples:
5
+ // gjsify barrels src/systems src/components # regenerate two barrels
6
+ // gjsify barrels --check src/types # CI guard — exit 1 on drift
7
+ // gjsify barrels --ext js src/utils # NodeNext-style import-extensions
8
+ //
9
+ // Conventions:
10
+ // - A directory literally named `types/` emits `export type *` (type-only
11
+ // re-export) — avoids dragging value imports through type-only barrels.
12
+ // - An empty directory yields `export {};` so TypeScript still parses the
13
+ // file as a module.
14
+ // - Output is sorted by file name (locale-compare) — deterministic diffs.
15
+ // - `--check` exits non-zero on drift without writing (pre-commit / CI use).
16
+ import { DEFAULT_BARRELS_EXCLUDES, DEFAULT_BARRELS_HEADER, generateBarrels, } from '../actions/barrels-generate.js';
17
+ export const barrelsCommand = {
18
+ command: 'barrels [paths..]',
19
+ description: 'Regenerate `index.ts` barrel files for the given directories. Drop-in replacement for `barrelsby`.',
20
+ builder: (yargs) => {
21
+ return yargs
22
+ .positional('paths', {
23
+ description: 'Directories whose `index.ts` to (re)generate. May also be passed via `--paths`.',
24
+ type: 'string',
25
+ array: true,
26
+ })
27
+ .option('paths', {
28
+ alias: 'p',
29
+ description: 'Alternative to positional — repeatable list of directories.',
30
+ type: 'string',
31
+ array: true,
32
+ })
33
+ .option('ext', {
34
+ description: 'Import-specifier extension. Default: `none` (bundler-mode resolution).',
35
+ type: 'string',
36
+ choices: ['js', 'ts', 'none'],
37
+ default: 'none',
38
+ })
39
+ .option('base-dir', {
40
+ alias: 'b',
41
+ description: 'Resolve `paths` against this directory. Default: cwd.',
42
+ type: 'string',
43
+ })
44
+ .option('exclude', {
45
+ description: 'Regex(es) of file names to skip. Repeatable. Defaults: `\\.test\\.`, `\\.spec\\.`, `\\.test-data\\.`.',
46
+ type: 'string',
47
+ array: true,
48
+ })
49
+ .option('header', {
50
+ description: 'Header comment prepended to every generated file.',
51
+ type: 'string',
52
+ })
53
+ .option('semicolon', {
54
+ description: 'Emit trailing `;` on each export line. Negate with `--no-semicolon`. Default: omitted.',
55
+ type: 'boolean',
56
+ default: false,
57
+ })
58
+ .option('single-quotes', {
59
+ description: 'Use `\'` for import specifiers. Default: true. Pass `--no-single-quotes` for `"`.',
60
+ type: 'boolean',
61
+ default: true,
62
+ })
63
+ .option('check', {
64
+ description: 'Report drift without modifying files; exit non-zero if any barrel is stale.',
65
+ type: 'boolean',
66
+ default: false,
67
+ })
68
+ .option('verbose', {
69
+ description: 'Log each file scanned + written.',
70
+ type: 'boolean',
71
+ default: false,
72
+ });
73
+ },
74
+ handler: async (args) => {
75
+ // Both positional (`gjsify barrels src/a src/b`) and the named option
76
+ // (`--paths src/a --paths src/b`) land in `args.paths` since they share
77
+ // the same name. Yargs concatenates when both are present.
78
+ const paths = Array.from(new Set((args.paths ?? []).filter(Boolean)));
79
+ if (paths.length === 0) {
80
+ console.error('[gjsify barrels] no paths provided. Pass directories as positional arguments or via --paths.');
81
+ process.exitCode = 1;
82
+ return;
83
+ }
84
+ const excludePatterns = args.exclude?.length
85
+ ? args.exclude
86
+ : [...DEFAULT_BARRELS_EXCLUDES];
87
+ const drift = await generateBarrels({
88
+ paths,
89
+ extension: args.ext ?? 'none',
90
+ baseDir: args.baseDir ?? process.cwd(),
91
+ exclude: excludePatterns.map((src) => new RegExp(src)),
92
+ header: args.header ?? DEFAULT_BARRELS_HEADER,
93
+ noSemicolon: args.semicolon === false || args.semicolon === undefined,
94
+ singleQuotes: args.singleQuotes !== false,
95
+ check: args.check ?? false,
96
+ verbose: args.verbose ?? false,
97
+ });
98
+ if (args.check && drift > 0) {
99
+ console.error(`[gjsify barrels] ${drift} barrel file(s) drifted. Run without --check to fix.`);
100
+ process.exitCode = 1;
101
+ }
102
+ },
103
+ };
@@ -22,3 +22,4 @@ export * from './format.js';
22
22
  export * from './lint.js';
23
23
  export * from './fix.js';
24
24
  export * from './upgrade.js';
25
+ export * from './barrels.js';
@@ -22,3 +22,4 @@ export * from './format.js';
22
22
  export * from './lint.js';
23
23
  export * from './fix.js';
24
24
  export * from './upgrade.js';
25
+ export * from './barrels.js';
@@ -11,9 +11,12 @@
11
11
  // subprocess flow (useful as escape-hatch for projects that hit a
12
12
  // missing native-backend feature).
13
13
  //
14
- // Workspace-aware install (`gjsify install` in a monorepo root with a
15
- // `"workspaces"` field) is Phase D.3 for now we detect and surface a
16
- // clear error pointing at the in-progress work.
14
+ // Workspace install (`gjsify install` in a monorepo root with a
15
+ // `"workspaces"` field) hoists every workspace's externals into the root
16
+ // `node_modules/` and symlinks `workspace:*` / `workspace:^` / `workspace:~`
17
+ // refs to their target source. Open follow-ups (see STATUS.md "Open TODOs"):
18
+ // per-workspace dedup of conflicting transitive version ranges (first-match
19
+ // wins today).
17
20
  import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
18
21
  import { dirname, join, relative } from 'node:path';
19
22
  import { spawn } from 'node:child_process';
@@ -115,7 +118,7 @@ async function projectInstallNative(args) {
115
118
  'not PnP-aware yet. Use `yarn install` or set ' +
116
119
  'GJSIFY_INSTALL_BACKEND=npm.');
117
120
  }
118
- // Workspace install (no args, root pkg.json has `workspaces`) — Phase D.3.
121
+ // Workspace install (no args, root pkg.json has `workspaces`).
119
122
  // Project-local `gjsify install <pkg>` inside a workspace child still
120
123
  // goes through the single-package code path below (this branch only
121
124
  // fires for the root no-args case, which is the `yarn install`
@@ -199,8 +202,7 @@ function syncLockfileRequested(cwd, specs) {
199
202
  }
200
203
  }
201
204
  /**
202
- * Phase D.3 — workspace-aware install. Mirrors what `yarn install` does
203
- * at a monorepo root:
205
+ * Workspace-aware install. Mirrors what `yarn install` does at a monorepo root:
204
206
  * 1. Discover every workspace under the root.
205
207
  * 2. Aggregate the union of their external (non-`workspace:`) deps.
206
208
  * 3. Run the native install backend ONCE at the root prefix so all
@@ -211,9 +213,9 @@ function syncLockfileRequested(cwd, specs) {
211
213
  * directory into the requesting workspace's `node_modules/<dep>`
212
214
  * so `import '@gjsify/utils'` resolves to the local source.
213
215
  *
214
- * Hoisting strategy is intentionally minimal — D.3 ships the working
215
- * baseline; per-workspace dedup + nested `node_modules/` for version
216
- * conflicts are tracked as a follow-up in STATUS.md "Open TODOs".
216
+ * Hoisting strategy is intentionally minimal — per-workspace dedup +
217
+ * nested `node_modules/` for version conflicts are tracked as a follow-up
218
+ * in STATUS.md "Open TODOs".
217
219
  */
218
220
  async function workspaceInstall(cwd, args) {
219
221
  const workspaces = discoverWorkspaces(cwd, { includeRoot: true });
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, 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';
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, barrelsCommand as barrels, } 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
@@ -35,6 +35,7 @@ await yargs(hideBin(process.argv))
35
35
  .command(format.command, format.description, format.builder, format.handler)
36
36
  .command(lint.command, lint.description, lint.builder, lint.handler)
37
37
  .command(fix.command, fix.description, fix.builder, fix.handler)
38
+ .command(barrels.command, barrels.description, barrels.builder, barrels.handler)
38
39
  .demandCommand(1)
39
40
  .help()
40
41
  .parseAsync();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -37,18 +37,18 @@
37
37
  "cli"
38
38
  ],
39
39
  "dependencies": {
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",
40
+ "@gjsify/buffer": "^0.4.15",
41
+ "@gjsify/create-app": "^0.4.15",
42
+ "@gjsify/node-globals": "^0.4.15",
43
+ "@gjsify/node-polyfills": "^0.4.15",
44
+ "@gjsify/npm-registry": "^0.4.15",
45
+ "@gjsify/resolve-npm": "^0.4.15",
46
+ "@gjsify/rolldown-plugin-gjsify": "^0.4.15",
47
+ "@gjsify/rolldown-plugin-pnp": "^0.4.15",
48
+ "@gjsify/semver": "^0.4.15",
49
+ "@gjsify/tar": "^0.4.15",
50
+ "@gjsify/web-polyfills": "^0.4.15",
51
+ "@gjsify/workspace": "^0.4.15",
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.14",
59
+ "@gjsify/unit": "^0.4.15",
60
60
  "@types/yargs": "^17.0.35",
61
61
  "typescript": "^6.0.3"
62
62
  },
63
63
  "peerDependencies": {
64
- "@gjsify/rolldown-native": "^0.4.14"
64
+ "@gjsify/rolldown-native": "^0.4.15"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@gjsify/rolldown-native": {
package/showcases.json CHANGED
@@ -29,6 +29,20 @@
29
29
  "description": "Three.js postprocessing pixel demo",
30
30
  "needsWebgl": true
31
31
  },
32
+ {
33
+ "name": "webrtc-loopback",
34
+ "category": "dom",
35
+ "package": "@gjsify/example-dom-webrtc-loopback",
36
+ "description": "WebRTC data-channel loopback: two local peers exchange offer/answer + ICE, then echo messages over an RTCDataChannel",
37
+ "needsWebgl": false
38
+ },
39
+ {
40
+ "name": "minimalist-browser",
41
+ "category": "dom",
42
+ "package": "@gjsify/example-dom-minimalist-browser",
43
+ "description": "Minimalist browser with URL bar + back/forward + iframe content area; same code runs in browser (real iframe) and GJS (IFrameBridge over WebKit.WebView)",
44
+ "needsWebgl": false
45
+ },
32
46
  {
33
47
  "name": "express-webserver",
34
48
  "category": "node",