@gjsify/cli 0.4.22 → 0.4.24

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.
@@ -46,6 +46,14 @@ export interface PackWorkspaceOptions {
46
46
  * workflow has already produced the build artifacts.
47
47
  */
48
48
  lifecycleScripts?: readonly string[];
49
+ /**
50
+ * Stdio mode for lifecycle scripts. Default `'inherit'` — child output
51
+ * appears in the parent's terminal. Pass `'inherit-stderr'` to redirect
52
+ * the child's stdout → parent's stderr; used by `gjsify pack --json`
53
+ * and `gjsify publish` so the parent's stdout stays a clean
54
+ * machine-readable JSON stream.
55
+ */
56
+ lifecycleStdio?: 'inherit' | 'inherit-stderr' | 'pipe' | 'ignore';
49
57
  }
50
58
  /**
51
59
  * Programmatic equivalent of the `pack` command — used by `gjsify publish`
@@ -65,6 +65,11 @@ export const packCommand = {
65
65
  destination: args['pack-destination'],
66
66
  dryRun: args['dry-run'] === true,
67
67
  lifecycleScripts: args['ignore-scripts'] ? [] : ['prepack'],
68
+ // When emitting machine-readable JSON on stdout, the prepack
69
+ // script's chatty log lines must NOT land on the parent's
70
+ // stdout — `JSON.parse(stdout)` callers would otherwise fail
71
+ // with `Unexpected token …`. Route lifecycle output to stderr.
72
+ lifecycleStdio: args.json ? 'inherit-stderr' : 'inherit',
68
73
  });
69
74
  if (args.json) {
70
75
  process.stdout.write(`${JSON.stringify([result], null, 2)}\n`);
@@ -99,7 +104,10 @@ export async function packWorkspace(wsDir, opts = {}) {
99
104
  // post-install. Matches `npm pack` / `npm publish` semantics.
100
105
  const lifecycleScripts = opts.lifecycleScripts ?? ['prepack'];
101
106
  for (const scriptName of lifecycleScripts) {
102
- await runLifecycleScript(wsDir, pkg, scriptName, { optional: true });
107
+ await runLifecycleScript(wsDir, pkg, scriptName, {
108
+ optional: true,
109
+ stdio: opts.lifecycleStdio,
110
+ });
103
111
  }
104
112
  // Re-read package.json AFTER lifecycle scripts in case one of them
105
113
  // mutated it (e.g. a `prepack` that injects build metadata into
@@ -159,6 +159,10 @@ export const publishCommand = {
159
159
  const packOpts = {
160
160
  dryRun: true,
161
161
  lifecycleScripts: ['prepublishOnly', 'prepack'],
162
+ // `gjsify publish --json` emits the publish summary on stdout.
163
+ // Lifecycle scripts must not pollute that stream with their
164
+ // own log lines; redirect their stdout → parent's stderr.
165
+ lifecycleStdio: args.json ? 'inherit-stderr' : 'inherit',
162
166
  };
163
167
  const packed = await packWorkspace(wsDir, packOpts);
164
168
  // We need the raw bytes — re-run with destination=null and capture.
@@ -1,8 +1,15 @@
1
1
  export interface RunLifecycleScriptOptions {
2
2
  /** When true, do not throw on missing scripts — return `false` instead. */
3
3
  optional?: boolean;
4
- /** Stdio inheritance. Defaults to `'inherit'` so output goes to the parent. */
5
- stdio?: 'inherit' | 'pipe' | 'ignore';
4
+ /**
5
+ * Stdio inheritance for the spawned script. Default `'inherit'` so output
6
+ * appears in the parent's terminal. Pass `'inherit-stderr'` to mirror
7
+ * inheritance but redirect the child's stdout → parent's stderr — used by
8
+ * `gjsify pack --json` and `gjsify publish` so the parent's stdout stays
9
+ * a clean JSON stream (script log lines would otherwise corrupt the
10
+ * machine-readable output that callers `JSON.parse`).
11
+ */
12
+ stdio?: 'inherit' | 'inherit-stderr' | 'pipe' | 'ignore';
6
13
  /** Extra environment variables layered on top of the defaults. */
7
14
  env?: Record<string, string>;
8
15
  }
@@ -54,11 +54,20 @@ export async function runLifecycleScript(wsDir, pkg, name, opts = {}) {
54
54
  npm_package_version: pkg.version ?? '',
55
55
  ...(opts.env ?? {}),
56
56
  };
57
+ // `'inherit-stderr'` is our extension on top of node's stdio modes —
58
+ // child stdin inherits, child stdout → parent's stderr (fd 2), child
59
+ // stderr → parent's stderr. Used by `gjsify pack --json` so the
60
+ // prepack's log lines don't get interleaved with the JSON we emit on
61
+ // parent stdout. `spawn`'s `stdio` accepts numeric fds in array form
62
+ // and routes the child's matching stream to that fd.
63
+ const stdioConfig = opts.stdio === 'inherit-stderr'
64
+ ? ['inherit', 2, 2]
65
+ : (opts.stdio ?? 'inherit');
57
66
  await new Promise((resolveOk, reject) => {
58
67
  const child = spawn(literal, [], {
59
68
  cwd: wsDir,
60
69
  env: env,
61
- stdio: opts.stdio ?? 'inherit',
70
+ stdio: stdioConfig,
62
71
  shell: true,
63
72
  });
64
73
  child.on('close', (code) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/cli",
3
- "version": "0.4.22",
3
+ "version": "0.4.24",
4
4
  "description": "CLI for Gjsify",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -120,18 +120,18 @@
120
120
  "cli"
121
121
  ],
122
122
  "dependencies": {
123
- "@gjsify/buffer": "^0.4.22",
124
- "@gjsify/create-app": "^0.4.22",
125
- "@gjsify/node-globals": "^0.4.22",
126
- "@gjsify/node-polyfills": "^0.4.22",
127
- "@gjsify/npm-registry": "^0.4.22",
128
- "@gjsify/resolve-npm": "^0.4.22",
129
- "@gjsify/rolldown-plugin-gjsify": "^0.4.22",
130
- "@gjsify/rolldown-plugin-pnp": "^0.4.22",
131
- "@gjsify/semver": "^0.4.22",
132
- "@gjsify/tar": "^0.4.22",
133
- "@gjsify/web-polyfills": "^0.4.22",
134
- "@gjsify/workspace": "^0.4.22",
123
+ "@gjsify/buffer": "^0.4.24",
124
+ "@gjsify/create-app": "^0.4.24",
125
+ "@gjsify/node-globals": "^0.4.24",
126
+ "@gjsify/node-polyfills": "^0.4.24",
127
+ "@gjsify/npm-registry": "^0.4.24",
128
+ "@gjsify/resolve-npm": "^0.4.24",
129
+ "@gjsify/rolldown-plugin-gjsify": "^0.4.24",
130
+ "@gjsify/rolldown-plugin-pnp": "^0.4.24",
131
+ "@gjsify/semver": "^0.4.24",
132
+ "@gjsify/tar": "^0.4.24",
133
+ "@gjsify/web-polyfills": "^0.4.24",
134
+ "@gjsify/workspace": "^0.4.24",
135
135
  "cosmiconfig": "^9.0.1",
136
136
  "get-tsconfig": "^4.14.0",
137
137
  "pkg-types": "^2.3.1",
@@ -139,12 +139,12 @@
139
139
  "yargs": "^18.0.0"
140
140
  },
141
141
  "devDependencies": {
142
- "@gjsify/unit": "^0.4.22",
142
+ "@gjsify/unit": "^0.4.24",
143
143
  "@types/yargs": "^17.0.35",
144
144
  "typescript": "^6.0.3"
145
145
  },
146
146
  "peerDependencies": {
147
- "@gjsify/rolldown-native": "^0.4.22"
147
+ "@gjsify/rolldown-native": "^0.4.24"
148
148
  },
149
149
  "peerDependenciesMeta": {
150
150
  "@gjsify/rolldown-native": {