@smoothbricks/nx-plugin 0.7.9 → 0.7.11

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.
package/README.md CHANGED
@@ -1160,25 +1160,27 @@ Concrete targets come from concrete files:
1160
1160
  produced. The emit sets `TTSC_WRITE_IF_CHANGED=1`, with which ttsc writes an output only when its bytes differ (the
1161
1161
  managed ttsc patch), so an emit after one source edit leaves every output whose bytes did not change as it was, inode
1162
1162
  and mtime included: rewriting identical bytes is file churn that every copy-on-write clone of the checkout pays for.
1163
- The emit runs with `--verbose`, whose summary lists every file the emit produced on both of ttsc's lanes, and after a
1164
- successful emit the executor removes each file under `outDir` that the list does not name, other than its own
1165
- `.build-inputs.json`, and each directory that leaves empty. A file an earlier build wrote and this one no longer does
1166
- (a bin moved to another package, a deleted module) is gone before Nx captures the output, so no cache artifact carries
1167
- it. A summary that lists no files, or fewer or more than it counts, fails the emit rather than read as one that
1168
- produced nothing, and a list that names a file the emit did not leave prunes nothing and fails the emit, so Nx caches
1169
- no output it emptied. Execute bits are set only on a bin that lacks them, since a chmod moves the file's ctime even
1170
- when its mode stays. A failed emit removes nothing, and an `outDir` that holds a TypeScript source is refused before
1171
- the compiler runs. It writes `.build-inputs.json` into the `outDir`, only when the record changed: the SHA-256 of
1172
- every file the config's `include` matches less its `exclude`, taken before the emit, and those globs as Git pathspecs.
1173
- Native targets write the same record from rustc's dep-info through `@smoothbricks/build-inputs`: macOS uses its
1174
- `smoo-nx-build-inputs` CLI and Linux's `cargo-zigbuild` executor calls that same collector. A record produced under Nx
1175
- also carries its producer's project, target and optional configuration, taken from the actual task environment. Shell
1176
- entry uses that identity to judge the selected development receipts, including inferred targets absent from package
1177
- manifests, and name their actual cached rebuild. It constructs no Nx graph, shadow output registry or second
1178
- interpolation policy. The record is inside the target's outputs, so a cache hit restores it with them; a live
1179
- developer link (`@smoothbricks/cli`, "Declared Links") checks it to tell a current build from a stale one by content.
1180
- The shell entry that bootstraps the plugin (`tooling/direnv/enter-shell.ts`) keeps its build marker under
1181
- `node_modules/.cache`, not under `outDir`, where the executor would remove it as a file its emit did not write.
1163
+ The emit runs with `--verbose`, whose summary lists every file the emit produced, and every file a linked plugin
1164
+ reported writing beside them (ttsc's `PluginContext.ReportHostOutput`), on each of ttsc's lanes (its own host, the
1165
+ direct-tsgo lane, the utility-plugin host and typia's), and after a successful emit the executor removes each file
1166
+ under `outDir` that the list does not name, other than its own `.build-inputs.json`, and each directory that leaves
1167
+ empty. A file an earlier build wrote and this one no longer does (a bin moved to another package, a deleted module) is
1168
+ gone before Nx captures the output, so no cache artifact carries it. A summary that lists no files, or fewer or more
1169
+ than it counts, fails the emit rather than read as one that produced nothing, and a list that names a file the emit
1170
+ did not leave prunes nothing and fails the emit, so Nx caches no output it emptied. Execute bits are set only on a bin
1171
+ that lacks them, since a chmod moves the file's ctime even when its mode stays. A failed emit removes nothing, and an
1172
+ `outDir` that holds a TypeScript source is refused before the compiler runs. It writes `.build-inputs.json` into the
1173
+ `outDir`, only when the record changed: the SHA-256 of every file the config's `include` matches less its `exclude`,
1174
+ taken before the emit, and those globs as Git pathspecs. Native targets write the same record from rustc's dep-info
1175
+ through `@smoothbricks/build-inputs`: macOS uses its `smoo-nx-build-inputs` CLI and Linux's `cargo-zigbuild` executor
1176
+ calls that same collector. A record produced under Nx also carries its producer's project, target and optional
1177
+ configuration, taken from the actual task environment. Shell entry uses that identity to judge the selected
1178
+ development receipts, including inferred targets absent from package manifests, and name their actual cached rebuild.
1179
+ It constructs no Nx graph, shadow output registry or second interpolation policy. The record is inside the target's
1180
+ outputs, so a cache hit restores it with them; a live developer link (`@smoothbricks/cli`, "Declared Links") checks it
1181
+ to tell a current build from a stale one by content. The shell entry that bootstraps the plugin
1182
+ (`tooling/direnv/enter-shell.ts`) keeps its build marker under `node_modules/.cache`, not under `outDir`, where the
1183
+ executor would remove it as a file its emit did not write.
1182
1184
  - `scriptc-<arch>-<family>` (`scriptc-arm64-macos`, `scriptc-x64-macos`, `scriptc-arm64-linux`, `scriptc-x64-linux`) are
1183
1185
  inferred for a package that lists `scriptc` in `devDependencies` (that pin is the compiler the targets run; the
1184
1186
  workspace root lists `scriptc` in `trustedDependencies` so its install links the platform compiler) together with each
@@ -41,7 +41,7 @@
41
41
  "packages/nx-plugin/src/executors/bounded-exec/executor.ts": "49c29558c8b4f3db21a807d6c2e453ca5805ffd8b41f8f79d3837fde33a92396",
42
42
  "packages/nx-plugin/src/executors/bounded-exec/gateway-lease.ts": "f3f73bd92db30e4857f98fb8bd2b9a75b2a5a2a318f094e075ed803c1f9a0117",
43
43
  "packages/nx-plugin/src/executors/bounded-exec/hang-diagnostics.ts": "bcaa9e52384f6c481a9cc2835ba6e8ffe167afa3cb51623fdf8dc3493876f335",
44
- "packages/nx-plugin/src/executors/bounded-exec/host-memory.darwin.ts": "c27868c1240ec9c782f80c7848f5eee1bc59146e3a56a6c8c0fc05bcf82b2931",
44
+ "packages/nx-plugin/src/executors/bounded-exec/host-memory.darwin.ts": "235ea2aaaee024d750ffe8fae5570c04d607b0eeb2fa2f0fc4309812c95692c1",
45
45
  "packages/nx-plugin/src/executors/bounded-exec/host-memory.linux.ts": "d473dc8475066d4914c419b6b803b6937ebb2577348f0dda8f9ed9def60e8584",
46
46
  "packages/nx-plugin/src/executors/bounded-exec/host-memory.ts": "cc7e94023adad2c3645c7a4ba18d07545426ae8d02840a2cf8117494d0915234",
47
47
  "packages/nx-plugin/src/executors/bounded-exec/leaf-peak.ts": "0b1b94992b2cbb9e3759785424ceb202667053c5571edf3a79cdd0b206e54a1d",
@@ -77,7 +77,7 @@
77
77
  "packages/nx-plugin/src/executors/shard-timings/executor.ts": "b5a84156fe2b71022603990a9c3e7721de7995987770b14ae60bd7e8117b1adf",
78
78
  "packages/nx-plugin/src/executors/shard-timings/schema.ts": "e509fc7be7a5752f1636f3006440e747d8381c40a46229627b11d7cdad633f69",
79
79
  "packages/nx-plugin/src/executors/typescript-emit/emit-overrides.ts": "3021aeb756492632d3e5da7a7ae15dded0a9399f73734c0d1fea1c69a2bd4b85",
80
- "packages/nx-plugin/src/executors/typescript-emit/executor.ts": "2084b56a932d418558454d23cb5fa0a7ece86cc8a2f442568dcd8aa8f6cf4d7e",
80
+ "packages/nx-plugin/src/executors/typescript-emit/executor.ts": "318e6b8e90b6e811ecb45158586d4ab481fc40eb72950dc4600d5c065acbae86",
81
81
  "packages/nx-plugin/src/executors/typescript-emit/schema.ts": "20edee20fee80198bbfbb743848d4ac3e41e734050abd511fceafcea9cd6da28",
82
82
  "packages/nx-plugin/src/executors/wrangler-deploy/deploy-hash.ts": "0ebcf8d795e703f98e43e6e89c474f71f8bde0e09a807564480dbc73ce30cd8a",
83
83
  "packages/nx-plugin/src/executors/wrangler-deploy/executor.ts": "de8a8b2c069692b1280b779b48069f7c0cd30cd394c416c821d635130c365a5a",
@@ -1 +1 @@
1
- {"version":3,"file":"host-memory.darwin.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/host-memory.darwin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAgJrE,eAAO,MAAM,YAAY,EAAE,UAAgF,CAAC"}
1
+ {"version":3,"file":"host-memory.darwin.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/host-memory.darwin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,kBAAkB,CAAC;AAqIrE,eAAO,MAAM,YAAY,EAAE,UAAgF,CAAC"}
@@ -1,41 +1,28 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
1
+ import { totalmem } from 'node:os';
3
2
  /**
4
3
  * macOS's memory mechanisms. A run's memory is the host's, `hw.memsize`: macOS confines no job to a memory limit of
5
4
  * its own. Bun reports a leaf's `ru_maxrss` in bytes, as macOS does.
6
5
  */
7
- const run = promisify(execFile);
8
6
  const HW_MEMSIZE = 'hw.memsize';
9
- async function readRunMemory() {
10
- let stdout;
11
- try {
12
- ({ stdout } = await run('sysctl', ['-n', HW_MEMSIZE]));
13
- }
14
- catch (error) {
15
- return {
16
- ok: false,
17
- error: {
18
- operation: 'read-run-memory',
19
- code: 'unreadable',
20
- subject: HW_MEMSIZE,
21
- cause: error instanceof Error ? error.message : String(error),
22
- },
23
- };
24
- }
25
- const value = stdout.trim();
26
- const bytes = Number(value);
27
- if (!/^\d+$/.test(value) || !Number.isSafeInteger(bytes) || bytes === 0) {
28
- return {
7
+ /**
8
+ * `hw.memsize`, read in this process: `os.totalmem()` is that sysctl under Node (libuv) and Bun alike. A child `sysctl`
9
+ * cost each run a process, and under `bun test` its exit sometimes never settled, so the pool a run serves never
10
+ * started: eight concurrent runs of the pool-silence cases at load ~50 hung there 6 times out of 24.
11
+ */
12
+ function readRunMemory() {
13
+ const bytes = totalmem();
14
+ if (!Number.isSafeInteger(bytes) || bytes <= 0) {
15
+ return Promise.resolve({
29
16
  ok: false,
30
17
  error: {
31
18
  operation: 'read-run-memory',
32
19
  code: 'malformed',
33
20
  subject: HW_MEMSIZE,
34
- cause: `sysctl printed ${JSON.stringify(value)}, not a byte count`,
21
+ cause: `os.totalmem() answered ${String(bytes)}, not a byte count`,
35
22
  },
36
- };
23
+ });
37
24
  }
38
- return { ok: true, memory: { bytes, source: HW_MEMSIZE } };
25
+ return Promise.resolve({ ok: true, memory: { bytes, source: HW_MEMSIZE } });
39
26
  }
40
27
  /**
41
28
  * Bun's FFI, as the peak waiter reaches it. Node, which runs the executor, loads this module too and has no `bun:ffi`;
@@ -31,8 +31,9 @@ export interface VerboseEmit {
31
31
  }
32
32
  /**
33
33
  * Reads the emitted-file list of ttsc's `--verbose` summary. ttsc's own host and its direct-tsgo lane
34
- * (cmd/ttsc/build.go, BuildExecution `verboseBuildSummary`) and a plugin's transform host (typia's
35
- * `ttsc-typia`) all print it in one shape under their own label: a header `// <label>: tsconfig=<config> cwd=<cwd>
34
+ * (cmd/ttsc/build.go, BuildExecution `verboseBuildSummary`), its utility-plugin host (utility/host.go, given the
35
+ * header and list by the managed ttsc patch) and a plugin's own transform host (typia's `ttsc-typia`) all print it
36
+ * in one shape under their own label: a header `// <label>: tsconfig=<config> cwd=<cwd>
36
37
  * … emit=true …`, then `// <label>: emitted=<count> files`, then one ` + <path>` line per file, relative to that
37
38
  * cwd. Pruning trusts this list, so output without one, or a list longer or shorter than its count, is refused rather
38
39
  * than read as an emit that produced nothing.
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/executor.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,kBAAkB,EASxB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;CAClB;AAQD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACvC;AAED,mHAAmH;AACnH,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAEtE,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;AAE1F,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAG/B;AAED,kGAAkG;AAClG,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,EACtB,QAAQ,CAAC,EAAE,kBAAkB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CAiD/B;AAoKD,sHAAsH;AACtH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC3D"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/executor.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,kBAAkB,EASxB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;CAClB;AAQD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,gEAAgE;IAChE,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACvC;AAED,mHAAmH;AACnH,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAEtE,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;AAE1F,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAG/B;AAED,kGAAkG;AAClG,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,EACtB,QAAQ,CAAC,EAAE,kBAAkB,GAC5B,OAAO,CAAC,oBAAoB,CAAC,CAiD/B;AAoKD,sHAAsH;AACtH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAiC3D"}
@@ -203,8 +203,9 @@ const VERBOSE_COUNT = /^\/\/ [^:]+: emitted=(\d+) files$/;
203
203
  const VERBOSE_FILE = /^ {2}\+ (.+)$/;
204
204
  /**
205
205
  * Reads the emitted-file list of ttsc's `--verbose` summary. ttsc's own host and its direct-tsgo lane
206
- * (cmd/ttsc/build.go, BuildExecution `verboseBuildSummary`) and a plugin's transform host (typia's
207
- * `ttsc-typia`) all print it in one shape under their own label: a header `// <label>: tsconfig=<config> cwd=<cwd>
206
+ * (cmd/ttsc/build.go, BuildExecution `verboseBuildSummary`), its utility-plugin host (utility/host.go, given the
207
+ * header and list by the managed ttsc patch) and a plugin's own transform host (typia's `ttsc-typia`) all print it
208
+ * in one shape under their own label: a header `// <label>: tsconfig=<config> cwd=<cwd>
208
209
  * … emit=true …`, then `// <label>: emitted=<count> files`, then one ` + <path>` line per file, relative to that
209
210
  * cwd. Pruning trusts this list, so output without one, or a list longer or shorter than its count, is refused rather
210
211
  * than read as an emit that produced nothing.
@@ -73,6 +73,130 @@ index 0000000000000000000000000000000000000000..97d1522f7979b488dc62b86cc1d78d72
73
73
  + t.Fatalf("forced emit did not rewrite the runtime import: %s", output["index.js"])
74
74
  + }
75
75
  +}
76
+ diff --git a/driver/emit_plugin.go b/driver/emit_plugin.go
77
+ index 3793b3a406c2bf2643567a755d34e66a26eac5c8..3c690ac3d9a99be7914ad9aed76e5890d236ea9b 100644
78
+ --- a/driver/emit_plugin.go
79
+ +++ b/driver/emit_plugin.go
80
+ @@ -427,7 +427,13 @@ func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, write
81
+ return diagnostics, err
82
+ }
83
+ }
84
+ - return diagnostics, output.flush()
85
+ + if err := output.flush(); err != nil {
86
+ + return diagnostics, err
87
+ + }
88
+ + // Files linked plugins reported writing beside these outputs follow them
89
+ + // through the host's writer, so the host lists them too (ReportHostOutput).
90
+ + _, err = p.writeHostOutputs(writeFile)
91
+ + return diagnostics, err
92
+ }
93
+
94
+ // writePluginEmitOutput writes one artifact of the hand-assembled emit, passing
95
+ diff --git a/driver/plugins.go b/driver/plugins.go
96
+ index 1778e250d80d1316e108f1f36b6e1a38724922d5..da2ec288afa9a4ae8ceebc1728f6119bae676c4a 100644
97
+ --- a/driver/plugins.go
98
+ +++ b/driver/plugins.go
99
+ @@ -169,6 +169,7 @@ type PluginContext struct {
100
+ reportFileDependencyRejected func(string)
101
+ reportFileComplete func(string)
102
+ reportEveryFileComplete func()
103
+ + reportHostOutput func(string)
104
+ }
105
+
106
+ // ReportObservationIncomplete declares that this hook's input population could
107
+ @@ -195,6 +196,24 @@ func (ctx PluginContext) ReportObservationIncomplete() {
108
+ }
109
+ }
110
+
111
+ +// ReportHostOutput declares a file this hook wrote beside the compiler's
112
+ +// outputs, such as a census or a manifest in outDir. A later emit of this
113
+ +// generation hands the file's bytes as they are then to the host's writer,
114
+ +// after the compiler's own outputs, so every host lists it with them: a caller
115
+ +// that keeps exactly the files an emit lists (a build that prunes its outDir by
116
+ +// that list) keeps it too. A relative file is resolved against Cwd. An emit
117
+ +// fails when a reported file cannot be read. A context without a driver
118
+ +// callback ignores the report.
119
+ +func (ctx PluginContext) ReportHostOutput(file string) {
120
+ + if ctx.reportHostOutput == nil || strings.TrimSpace(file) == "" {
121
+ + return
122
+ + }
123
+ + if !filepath.IsAbs(file) {
124
+ + file = filepath.Join(ctx.Cwd, file)
125
+ + }
126
+ + ctx.reportHostOutput(filepath.Clean(file))
127
+ +}
128
+ +
129
+ // ReportHostInputHash declares the exact file state consumed by a native
130
+ // plugin. hash is a lowercase SHA-256 digest for an observed file and nil for
131
+ // a missing candidate. Conflicting observations are retained as host inputs
132
+ @@ -511,6 +530,7 @@ type linkedPluginState struct {
133
+ declarations *pluginFileDeclarations
134
+ entries []PluginEntry
135
+ inputs *pluginHostInputScopes
136
+ + outputs *pluginHostOutputs
137
+ tsconfig string
138
+ }
139
+
140
+ @@ -800,6 +820,7 @@ func loadLinkedPluginState(cwd, tsconfigPath string) (linkedPluginState, error)
141
+ cwd: cwd,
142
+ declarations: newPluginFileDeclarations(),
143
+ inputs: newPluginHostInputScopes(),
144
+ + outputs: newPluginHostOutputs(),
145
+ tsconfig: tsconfigPath,
146
+ }, nil
147
+ }
148
+ @@ -812,6 +833,7 @@ func loadLinkedPluginState(cwd, tsconfigPath string) (linkedPluginState, error)
149
+ declarations: newPluginFileDeclarations(),
150
+ entries: entries,
151
+ inputs: newPluginHostInputScopes(),
152
+ + outputs: newPluginHostOutputs(),
153
+ tsconfig: tsconfigPath,
154
+ }, nil
155
+ }
156
+ @@ -931,7 +953,43 @@ func (state linkedPluginState) contextAt(index int, entry PluginEntry) PluginCon
157
+ reportFileDependencyRejected: declaration.rejectDependency,
158
+ reportFileComplete: declaration.addComplete,
159
+ reportEveryFileComplete: declaration.completeEveryFile,
160
+ + reportHostOutput: state.outputs.add,
161
+ + }
162
+ +}
163
+ +
164
+ +// pluginHostOutputs keeps the files linked plugins reported writing beside the
165
+ +// compiler's outputs in this generation (ReportHostOutput), each once, in the
166
+ +// order first reported.
167
+ +type pluginHostOutputs struct {
168
+ + mu sync.Mutex
169
+ + seen map[string]struct{}
170
+ + files []string
171
+ +}
172
+ +
173
+ +func newPluginHostOutputs() *pluginHostOutputs {
174
+ + return &pluginHostOutputs{seen: map[string]struct{}{}}
175
+ +}
176
+ +
177
+ +func (outputs *pluginHostOutputs) add(file string) {
178
+ + if outputs == nil {
179
+ + return
180
+ + }
181
+ + outputs.mu.Lock()
182
+ + defer outputs.mu.Unlock()
183
+ + if _, ok := outputs.seen[file]; ok {
184
+ + return
185
+ + }
186
+ + outputs.seen[file] = struct{}{}
187
+ + outputs.files = append(outputs.files, file)
188
+ +}
189
+ +
190
+ +func (outputs *pluginHostOutputs) list() []string {
191
+ + if outputs == nil {
192
+ + return nil
193
+ }
194
+ + outputs.mu.Lock()
195
+ + defer outputs.mu.Unlock()
196
+ + return append([]string(nil), outputs.files...)
197
+ }
198
+
199
+ // hostInputs returns the exact native configuration inputs reported in this
76
200
  diff --git a/driver/program.go b/driver/program.go
77
201
  index f6ee81fb1af41deea022b92e838a7c4665eb9778..112faf913ce38b1f4624b38db37839370b9c5e8b 100644
78
202
  --- a/driver/program.go
@@ -91,10 +215,73 @@ index f6ee81fb1af41deea022b92e838a7c4665eb9778..112faf913ce38b1f4624b38db3783937
91
215
 
92
216
  // forceNoEmit sets noEmit so the program type-checks without writing files.
93
217
  diff --git a/driver/rewrite.go b/driver/rewrite.go
94
- index 79be74d24e879da216ad680d23ecfeb5f11a29db..fb57c1ac6ef61f72abe75fd118915c7b632c5bb6 100644
218
+ index 79be74d24e879da216ad680d23ecfeb5f11a29db..6db9dddba05bd50e13ed92535ca442c3a4f0b28a 100644
95
219
  --- a/driver/rewrite.go
96
220
  +++ b/driver/rewrite.go
97
- @@ -317,22 +317,28 @@ func (p *Program) emitsBuildInfo() bool {
221
+ @@ -204,6 +204,9 @@ func (p *Program) EmitAllRaw(writeFile shimcompiler.WriteFile) (*shimcompiler.Em
222
+ result := p.emitProgram(shimcompiler.EmitOptions{
223
+ WriteFile: wf,
224
+ })
225
+ + if err := p.listHostOutputs(result, writeFile); err != nil {
226
+ + return result, p.convertProgramDiagnostics(result.Diagnostics), err
227
+ + }
228
+ return result, p.convertProgramDiagnostics(result.Diagnostics), nil
229
+ }
230
+
231
+ @@ -271,9 +274,52 @@ func (p *Program) emit(rs *RewriteSet, target *ast.SourceFile, writeFile shimcom
232
+ }
233
+
234
+ result := p.emitProgram(shimcompiler.TargetedEmitOptions(target, wf))
235
+ + if target == nil {
236
+ + if err := p.listHostOutputs(result, writeFile); err != nil {
237
+ + return result, p.convertProgramDiagnostics(result.Diagnostics), err
238
+ + }
239
+ + }
240
+ return result, p.convertProgramDiagnostics(result.Diagnostics), nil
241
+ }
242
+
243
+ +// listHostOutputs hands the files linked plugins reported writing beside a
244
+ +// whole-program emit's outputs to writeFile and lists them among the result's
245
+ +// EmittedFiles, unless the emit wrote nothing (noEmit, or noEmitOnError
246
+ +// withholding a failed program).
247
+ +func (p *Program) listHostOutputs(result *shimcompiler.EmitResult, writeFile shimcompiler.WriteFile) error {
248
+ + if result == nil || result.EmitSkipped || p.TSProgram.Options().NoEmit.IsTrue() {
249
+ + return nil
250
+ + }
251
+ + handed, err := p.writeHostOutputs(writeFile)
252
+ + result.EmittedFiles = append(result.EmittedFiles, handed...)
253
+ + return err
254
+ +}
255
+ +
256
+ +// writeHostOutputs hands each file a linked plugin reported writing beside the
257
+ +// compiler's outputs (PluginContext.ReportHostOutput) to writeFile, with its
258
+ +// bytes as they are now, after the compiler's own outputs, so a host lists it
259
+ +// with them. It answers the files handed, and fails on one it cannot read: a
260
+ +// plugin reported an output it did not leave.
261
+ +func (p *Program) writeHostOutputs(writeFile shimcompiler.WriteFile) ([]string, error) {
262
+ + var handed []string
263
+ + for _, file := range p.plugins.outputs.list() {
264
+ + text, err := os.ReadFile(file)
265
+ + if err != nil {
266
+ + return handed, fmt.Errorf("ttsc driver: a linked plugin reported the host output %s, which cannot be read: %w", file, err)
267
+ + }
268
+ + if writeFile != nil {
269
+ + err = writeFile(shimtspath.RootedFilePathFromAbsolute(file), string(text), nil)
270
+ + } else {
271
+ + err = DefaultWriteFile(file, string(text))
272
+ + }
273
+ + if err != nil {
274
+ + return handed, err
275
+ + }
276
+ + handed = append(handed, file)
277
+ + }
278
+ + return handed, nil
279
+ +}
280
+ +
281
+ // emitProgram runs one whole-program or single-file emit, taking tsgo's
282
+ // incremental lane when the resolved compiler options ask for build
283
+ // information.
284
+ @@ -317,22 +363,28 @@ func (p *Program) emitsBuildInfo() bool {
98
285
  }
99
286
 
100
287
  // DefaultWriteFile is the default disk writer used when EmitAll's caller does not
@@ -686,3 +873,46 @@ diff --git a/lib/plugin/internal/source/waitForPluginBinary.js b/lib/plugin/inte
686
873
  if (clock - startedAt >= opts.timeoutMs) {
687
874
  throw new Error(`ttsc: timed out after ${(0, formatDuration_1.formatDuration)(clock - startedAt)} waiting for ` +
688
875
  `${opts.lockInfo.label} "${opts.lockInfo.pluginName}" at ${opts.lockDir}; ` +
876
+ diff --git a/utility/host.go b/utility/host.go
877
+ index fab9fcc72897ec54540a5f5e93dfe115bba102a5..9d72bb780e5e104f6a41889a712efe677bdfe3d8 100644
878
+ --- a/utility/host.go
879
+ +++ b/utility/host.go
880
+ @@ -7,6 +7,7 @@ import (
881
+ "io"
882
+ "os"
883
+ "path/filepath"
884
+ + "sort"
885
+ "strings"
886
+
887
+ shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
888
+ @@ -234,7 +235,10 @@ func RunBuildWithIO(args []string, stdout, stderr io.Writer) int {
889
+ opts.quiet = false // --verbose overrides the default --quiet=true
890
+ }
891
+ if !opts.quiet {
892
+ - fmt.Fprintf(opts.stdout, "// ttsc utility: plugins=%d emit=%v\n", len(entries), !opts.noEmit)
893
+ + // The header and the " + <path>" list below are the summary shape ttsc's
894
+ + // build lane (cmd/ttsc/build.go) and ttsc-typia print, so a caller that
895
+ + // reads the emitted files from --verbose reads this lane the same way.
896
+ + fmt.Fprintf(opts.stdout, "// ttsc utility: tsconfig=%s cwd=%s emit=%v plugins=%d\n", opts.tsconfig, opts.cwd, !opts.noEmit, len(entries))
897
+ }
898
+ writeFile, finishPreamble := makeSourcePreambleWriteFile(prog)
899
+ var snapshot func() map[string][]string
900
+ @@ -284,6 +288,18 @@ func RunBuildWithIO(args []string, stdout, stderr io.Writer) int {
901
+ }
902
+ if !opts.quiet {
903
+ fmt.Fprintf(opts.stdout, "// ttsc utility: emitted=%d files\n", len(emittedFiles))
904
+ + listed := make([]string, 0, len(emittedFiles))
905
+ + for fileName := range emittedFiles {
906
+ + listed = append(listed, fileName)
907
+ + }
908
+ + sort.Strings(listed)
909
+ + for _, fileName := range listed {
910
+ + rel := fileName
911
+ + if relative, err := filepath.Rel(opts.cwd, fileName); err == nil {
912
+ + rel = relative
913
+ + }
914
+ + fmt.Fprintln(opts.stdout, " +", rel)
915
+ + }
916
+ }
917
+ return 0
918
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.7.9",
3
+ "version": "0.7.11",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -474,6 +474,7 @@
474
474
  "^dependencyDefault",
475
475
  "bunToolchain",
476
476
  "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
477
+ "{workspaceRoot}/packages/lmao-ttsc/plugin.cjs",
477
478
  {
478
479
  "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
479
480
  "transitive": false
@@ -501,6 +502,7 @@
501
502
  "^dependencyDefault",
502
503
  "bunToolchain",
503
504
  "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
505
+ "{workspaceRoot}/packages/lmao-ttsc/plugin.cjs",
504
506
  {
505
507
  "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
506
508
  "transitive": false
@@ -528,6 +530,7 @@
528
530
  "^dependencyDefault",
529
531
  "bunToolchain",
530
532
  "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
533
+ "{workspaceRoot}/packages/lmao-ttsc/plugin.cjs",
531
534
  {
532
535
  "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
533
536
  "transitive": false
@@ -555,6 +558,7 @@
555
558
  "^dependencyDefault",
556
559
  "bunToolchain",
557
560
  "{workspaceRoot}/packages/cowshed/crates/cowshed-core/src/port_zero.cjs",
561
+ "{workspaceRoot}/packages/lmao-ttsc/plugin.cjs",
558
562
  {
559
563
  "dependentTasksOutputFiles": "**/test-stream/archive.tar.zst",
560
564
  "transitive": false
@@ -652,7 +656,7 @@
652
656
  "@nx/js": "24.0.3",
653
657
  "@smoothbricks/build-inputs": "0.0.3",
654
658
  "@smoothbricks/cargo-retain": "0.0.2",
655
- "@smoothbricks/cowshed": "0.4.7",
659
+ "@smoothbricks/cowshed": "0.4.8",
656
660
  "@smoothbricks/nextest-extract": "0.0.2",
657
661
  "jsonc-parser": "^3.3.1",
658
662
  "minimatch": "10.2.5",
@@ -665,7 +669,7 @@
665
669
  "yaml": "^2.9.0"
666
670
  },
667
671
  "devDependencies": {
668
- "@smoothbricks/lmao": "0.6.0",
672
+ "@smoothbricks/lmao": "0.6.1",
669
673
  "@smoothbricks/validation": "0.1.13",
670
674
  "fast-check": "^4.4.0"
671
675
  }
@@ -1,5 +1,4 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
1
+ import { totalmem } from 'node:os';
3
2
  import type { HostMemory, RunMemoryReading } from './host-memory.js';
4
3
 
5
4
  /**
@@ -7,38 +6,27 @@ import type { HostMemory, RunMemoryReading } from './host-memory.js';
7
6
  * its own. Bun reports a leaf's `ru_maxrss` in bytes, as macOS does.
8
7
  */
9
8
 
10
- const run = promisify(execFile);
11
9
  const HW_MEMSIZE = 'hw.memsize';
12
10
 
13
- async function readRunMemory(): Promise<RunMemoryReading> {
14
- let stdout: string;
15
- try {
16
- ({ stdout } = await run('sysctl', ['-n', HW_MEMSIZE]));
17
- } catch (error) {
18
- return {
19
- ok: false,
20
- error: {
21
- operation: 'read-run-memory',
22
- code: 'unreadable',
23
- subject: HW_MEMSIZE,
24
- cause: error instanceof Error ? error.message : String(error),
25
- },
26
- };
27
- }
28
- const value = stdout.trim();
29
- const bytes = Number(value);
30
- if (!/^\d+$/.test(value) || !Number.isSafeInteger(bytes) || bytes === 0) {
31
- return {
11
+ /**
12
+ * `hw.memsize`, read in this process: `os.totalmem()` is that sysctl under Node (libuv) and Bun alike. A child `sysctl`
13
+ * cost each run a process, and under `bun test` its exit sometimes never settled, so the pool a run serves never
14
+ * started: eight concurrent runs of the pool-silence cases at load ~50 hung there 6 times out of 24.
15
+ */
16
+ function readRunMemory(): Promise<RunMemoryReading> {
17
+ const bytes = totalmem();
18
+ if (!Number.isSafeInteger(bytes) || bytes <= 0) {
19
+ return Promise.resolve({
32
20
  ok: false,
33
21
  error: {
34
22
  operation: 'read-run-memory',
35
23
  code: 'malformed',
36
24
  subject: HW_MEMSIZE,
37
- cause: `sysctl printed ${JSON.stringify(value)}, not a byte count`,
25
+ cause: `os.totalmem() answered ${String(bytes)}, not a byte count`,
38
26
  },
39
- };
27
+ });
40
28
  }
41
- return { ok: true, memory: { bytes, source: HW_MEMSIZE } };
29
+ return Promise.resolve({ ok: true, memory: { bytes, source: HW_MEMSIZE } });
42
30
  }
43
31
 
44
32
  /**
@@ -283,8 +283,9 @@ export interface VerboseEmit {
283
283
 
284
284
  /**
285
285
  * Reads the emitted-file list of ttsc's `--verbose` summary. ttsc's own host and its direct-tsgo lane
286
- * (cmd/ttsc/build.go, BuildExecution `verboseBuildSummary`) and a plugin's transform host (typia's
287
- * `ttsc-typia`) all print it in one shape under their own label: a header `// <label>: tsconfig=<config> cwd=<cwd>
286
+ * (cmd/ttsc/build.go, BuildExecution `verboseBuildSummary`), its utility-plugin host (utility/host.go, given the
287
+ * header and list by the managed ttsc patch) and a plugin's own transform host (typia's `ttsc-typia`) all print it
288
+ * in one shape under their own label: a header `// <label>: tsconfig=<config> cwd=<cwd>
288
289
  * … emit=true …`, then `// <label>: emitted=<count> files`, then one ` + <path>` line per file, relative to that
289
290
  * cwd. Pruning trusts this list, so output without one, or a list longer or shorter than its count, is refused rather
290
291
  * than read as an emit that produced nothing.