Skip to content

Commit e272128

Browse files
committed
fix(control): keep npm pack JSON on stdout
1 parent 84171e8 commit e272128

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# npm pack JSON stdout fix
2+
3+
## Root cause
4+
5+
`npm pack ./control --json > pack.json` redirects the parent shell's stdout for
6+
the entire command, including the `prepack` child process. `prepack` runs
7+
`bun run build`, and `control/scripts/build.ts` wrote its informational
8+
`built 7 public entries into dist/` message with `console.log`. That message
9+
was therefore prepended to npm's JSON array and made `pack.json` unparsable.
10+
11+
The build message is progress information, not a machine-readable result. It
12+
now uses `console.error`, leaving stdout available for JSON-producing callers.
13+
14+
## Before
15+
16+
Command, from the repository root:
17+
18+
```text
19+
$ npm pack ./control --json > /tmp/pack-test-before.json 2>/tmp/pack-test-before.stderr
20+
$ node -p "require('/tmp/pack-test-before.json')[0].filename"
21+
SyntaxError: /tmp/pack-test-before.json: Unexpected token 'b', "built 7 pu"... is not valid JSON
22+
```
23+
24+
The captured stdout began:
25+
26+
```text
27+
built 7 public entries into dist/
28+
[
29+
{
30+
```
31+
32+
The command itself exited 0; the subsequent JSON consumer failed, matching the
33+
release workflow failure.
34+
35+
## Fix and after
36+
37+
`control/scripts/build.ts` line 150 changed from `console.log(...)` to
38+
`console.error(...)`. A complete search of `control/scripts/build.ts` found no
39+
other `console.log` calls. The neighboring tarball and consumer scripts use
40+
their logs as human-facing CLI output and do not produce the npm JSON stream.
41+
42+
```text
43+
$ npm pack ./control --json > /tmp/pack-test-after.json 2>/tmp/pack-test-after.stderr
44+
$ node -p "require('/tmp/pack-test-after.json')[0].filename"
45+
ceralive-modem-control-1.1.0.tgz
46+
$ node -p "require('/tmp/pack-test-after.json')[0].integrity"
47+
sha512-8Q7Qa0fFS8d42C0xcaWlOGswwE/3fuMk8+PHXCfED9DOhCP3LRPmrvdIyK47NUNaLZEcffN2z/BVTOekILAVfA==
48+
```
49+
50+
After the fix, the JSON file starts with `[` and the build progress line is in
51+
`/tmp/pack-test-after.stderr`.

control/scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ if (tsc.exitCode !== 0) {
147147
await fullySpecifyEmit();
148148
await verify();
149149

150-
console.log(`built ${PUBLIC_ENTRIES.length} public entries into dist/`);
150+
console.error(`built ${PUBLIC_ENTRIES.length} public entries into dist/`);

0 commit comments

Comments
 (0)