@smoothbricks/nx-plugin 0.7.10 → 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 +21 -20
- package/managed/raw/patches/ttsc@0.34.1.patch +189 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1160,26 +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
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
record from rustc's dep-info
|
|
1175
|
-
Linux's `cargo-zigbuild` executor
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
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.
|
|
1183
1184
|
- `scriptc-<arch>-<family>` (`scriptc-arm64-macos`, `scriptc-x64-macos`, `scriptc-arm64-linux`, `scriptc-x64-linux`) are
|
|
1184
1185
|
inferred for a package that lists `scriptc` in `devDependencies` (that pin is the compiler the targets run; the
|
|
1185
1186
|
workspace root lists `scriptc` in `trustedDependencies` so its install links the platform compiler) together with each
|
|
@@ -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..
|
|
218
|
+
index 79be74d24e879da216ad680d23ecfeb5f11a29db..6db9dddba05bd50e13ed92535ca442c3a4f0b28a 100644
|
|
95
219
|
--- a/driver/rewrite.go
|
|
96
220
|
+++ b/driver/rewrite.go
|
|
97
|
-
@@ -
|
|
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
|