ttsc 0.34.3 → 0.35.0
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/lib/compiler/internal/build/BuildExecution.d.ts +26 -0
- package/lib/compiler/internal/build/BuildExecution.js +13 -3
- package/lib/compiler/internal/build/BuildExecution.js.map +1 -1
- package/lib/compiler/internal/build/RunBuildOptions.d.ts +2 -0
- package/lib/compiler/internal/build/RuntimeBuildCache.d.ts +47 -0
- package/lib/compiler/internal/build/RuntimeBuildCache.js +235 -0
- package/lib/compiler/internal/build/RuntimeBuildCache.js.map +1 -0
- package/lib/compiler/internal/build/RuntimeBuildInputs.d.ts +44 -0
- package/lib/compiler/internal/build/RuntimeBuildInputs.js +282 -0
- package/lib/compiler/internal/build/RuntimeBuildInputs.js.map +1 -0
- package/lib/compiler/internal/build/RuntimeInputProof.d.ts +50 -0
- package/lib/compiler/internal/build/RuntimeInputProof.js +315 -0
- package/lib/compiler/internal/build/RuntimeInputProof.js.map +1 -0
- package/lib/compiler/internal/build/TsgoArguments.d.ts +5 -4
- package/lib/compiler/internal/build/TsgoArguments.js +11 -5
- package/lib/compiler/internal/build/TsgoArguments.js.map +1 -1
- package/lib/compiler/internal/build/runBuild.d.ts +3 -3
- package/lib/compiler/internal/build/runBuild.js +17 -4
- package/lib/compiler/internal/build/runBuild.js.map +1 -1
- package/lib/compiler/internal/runNativeCheckWithObservations.d.ts +18 -14
- package/lib/compiler/internal/runNativeCheckWithObservations.js +42 -18
- package/lib/compiler/internal/runNativeCheckWithObservations.js.map +1 -1
- package/lib/flags/FLAG_SCHEMA.js +7 -0
- package/lib/flags/FLAG_SCHEMA.js.map +1 -1
- package/lib/launcher/internal/parseTtsxCLI.d.ts +1 -0
- package/lib/launcher/internal/parseTtsxCLI.js +1 -0
- package/lib/launcher/internal/parseTtsxCLI.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.d.ts +2 -0
- package/lib/launcher/internal/prepareExecution.js +6 -0
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/runTtsx.js +5 -0
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/launcher/internal/runtime/installRuntimeHooks.js +7 -0
- package/lib/launcher/internal/runtime/installRuntimeHooks.js.map +1 -1
- package/lib/plugin/internal/load/loadProjectPlugins.js +1 -0
- package/lib/plugin/internal/load/loadProjectPlugins.js.map +1 -1
- package/lib/plugin/internal/source/SourceBuildCacheLayout.d.ts +2 -0
- package/lib/plugin/internal/source/SourceBuildCacheLayout.js +3 -0
- package/lib/plugin/internal/source/SourceBuildCacheLayout.js.map +1 -1
- package/lib/structures/ITtscPluginCapabilities.d.ts +13 -2
- package/package.json +8 -8
- package/src/compiler/internal/build/BuildExecution.ts +32 -16
- package/src/compiler/internal/build/RunBuildOptions.ts +3 -0
- package/src/compiler/internal/build/RuntimeBuildCache.ts +252 -0
- package/src/compiler/internal/build/RuntimeBuildInputs.ts +349 -0
- package/src/compiler/internal/build/RuntimeInputProof.ts +346 -0
- package/src/compiler/internal/build/TsgoArguments.ts +11 -5
- package/src/compiler/internal/build/runBuild.ts +20 -5
- package/src/compiler/internal/runNativeCheckWithObservations.ts +41 -18
- package/src/flags/FLAG_SCHEMA.ts +7 -0
- package/src/launcher/internal/parseTtsxCLI.ts +1 -0
- package/src/launcher/internal/prepareExecution.ts +13 -0
- package/src/launcher/internal/runTtsx.ts +5 -0
- package/src/launcher/internal/runtime/installRuntimeHooks.ts +11 -0
- package/src/plugin/internal/load/loadProjectPlugins.ts +1 -0
- package/src/plugin/internal/source/SourceBuildCacheLayout.ts +4 -0
- package/src/structures/ITtscPluginCapabilities.ts +14 -2
- package/utility/host.go +22 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import type { ITtscCompilerTransformation } from "../../../structures/ITtscCompilerTransformation";
|
|
6
|
+
import type { TtscBuildResult } from "../../../structures/internal/TtscBuildResult";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Replay the compiler and native input witnesses of a completed runtime build.
|
|
10
|
+
* Read predicates keep their original text or raw-byte codec; absence, entry
|
|
11
|
+
* kind, physical target and directory membership remain independent predicates.
|
|
12
|
+
* Failed or unsupported observations withhold reuse.
|
|
13
|
+
*
|
|
14
|
+
* @evidence contracts/common.md#principled-implementation Replay compares generation witnesses with current existence, stat, decoded text, physical identity and directory membership. Native version-one file, optional-file, entry and directory codecs use explicit tags, raw file/link bytes and sorted nul-delimited records. Compiler text strips UTF-8 BOM or decodes even UTF-16LE/BE bytes before SHA-256; host directory presence uses its separate domain marker.
|
|
15
|
+
* @evidence contracts/common.md#clear-and-simple-design One namespace separates result admission, declared host inputs, compiler predicates and the native version-one codec. Private physical/absence and SHA-256 helpers serve the codecs without merging their meanings.
|
|
16
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Unknown codecs, failed reads and producer proof failures decline admission. Only ENOENT/ENOTDIR prove absence; other physical-resolution errors remain unavailable. Following stat classifies compiler views while lstat retains native link kinds; only the producer private output subtree is excluded.
|
|
17
|
+
* @evidence contracts/common.md#meaningful-documentation Native prose identifies generation proof, codec ownership and refusal semantics; private helper comments identify query, byte, decoded-text and null/error boundaries.
|
|
18
|
+
* @evidence contracts/portability.md#os-neutral-implementation Native stat, lstat and realpath retain actual kinds, targets and spellings without case assumptions. POSIX directory names/link targets stay raw bytes, Windows names follow the producer UTF-8 codec, and compiler directory entries sort by UTF-8 bytes.
|
|
19
|
+
* @evidence contracts/performance.md#efficient-algorithms Replay visits recorded predicates and their bytes or immediate directory entries rather than unrelated trees. Hashing and BOM decoding cost O(bytes), including a big-endian copy; directory codecs cost O(N log N) sorting plus encoded bytes and link queries. Physical resolution follows native path/link traversal.
|
|
20
|
+
* @evidence contracts/performance.md#reuse-equivalent-work Every retained predicate is observed anew to authorize completed-result reuse. Host capture and admission share the producer codec; no path memo, watcher silence or historical hash independently grants authority.
|
|
21
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources Read buffers, decoded text, paths and sorted directory members are call-local and have no proof-reader byte or entry cap. Synchronous calls retain no handle, watcher, process or historical population; only returned proof values escape.
|
|
22
|
+
*/
|
|
23
|
+
export namespace RuntimeInputProof {
|
|
24
|
+
/**
|
|
25
|
+
* Validate result-level host witnesses and every reported compiler predicate.
|
|
26
|
+
* The caller independently proves the selected compiler, project membership
|
|
27
|
+
* and plugin selection; an absent graph alone grants no completeness.
|
|
28
|
+
*
|
|
29
|
+
* @evidence contracts/common.md#principled-implementation Explicit incomplete observations and any graph failure reject reuse; host paths require both content and physical witnesses, and rich compiler predicates are replayed under their own codec.
|
|
30
|
+
* @evidence contracts/common.md#clear-and-simple-design One admission pass delegates individual compiler observations and native codecs.
|
|
31
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Missing witness fields never become an empty successful observation, and only the caller-owned private output subtree is excluded.
|
|
32
|
+
* @evidence contracts/common.md#meaningful-documentation Native prose identifies result admission and the caller's separate completeness obligations.
|
|
33
|
+
* @evidence contracts/portability.md#os-neutral-implementation Native path resolution anchors producer-relative graph keys, and current physical paths come from native realpath.
|
|
34
|
+
* @evidence contracts/performance.md#efficient-algorithms Input and predicate populations drive replay; each read hashes its actual bytes and directories sort immediate entry records.
|
|
35
|
+
* @evidence contracts/performance.md#reuse-equivalent-work Generation witnesses, rather than an identity-key match, decide whether a completed build remains reusable.
|
|
36
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources Temporary path and predicate records are invocation-owned without retained handles or history.
|
|
37
|
+
*/
|
|
38
|
+
export function holds(
|
|
39
|
+
result: TtscBuildResult,
|
|
40
|
+
projectRoot: string,
|
|
41
|
+
emitDir: string,
|
|
42
|
+
): boolean {
|
|
43
|
+
if (
|
|
44
|
+
result.observationsComplete === false ||
|
|
45
|
+
Object.keys(result.graph?.inputProofFailures ?? {}).length !== 0
|
|
46
|
+
)
|
|
47
|
+
return false;
|
|
48
|
+
try {
|
|
49
|
+
for (const file of result.hostInputs ?? []) {
|
|
50
|
+
const [currentPhysical, hash] = observeHostInput(file);
|
|
51
|
+
if (
|
|
52
|
+
!Object.hasOwn(result.hostInputHashes ?? {}, file) ||
|
|
53
|
+
!Object.hasOwn(result.hostInputRealpaths ?? {}, file) ||
|
|
54
|
+
currentPhysical !== result.hostInputRealpaths![file] ||
|
|
55
|
+
hash !== result.hostInputHashes![file]
|
|
56
|
+
)
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const graph = result.graph;
|
|
60
|
+
for (const [name, observed] of Object.entries(
|
|
61
|
+
graph?.inputObservations ?? {},
|
|
62
|
+
)) {
|
|
63
|
+
const file = path.resolve(projectRoot, name);
|
|
64
|
+
const relative = path.relative(emitDir, file);
|
|
65
|
+
if (
|
|
66
|
+
relative === "" ||
|
|
67
|
+
(!path.isAbsolute(relative) &&
|
|
68
|
+
relative !== ".." &&
|
|
69
|
+
!relative.startsWith(".." + path.sep))
|
|
70
|
+
)
|
|
71
|
+
continue;
|
|
72
|
+
if (!observationHolds(file, observed)) return false;
|
|
73
|
+
}
|
|
74
|
+
for (const [name, expected] of Object.entries(graph?.inputHashes ?? {})) {
|
|
75
|
+
if (Object.hasOwn(graph?.inputObservations ?? {}, name)) continue;
|
|
76
|
+
const file = path.resolve(projectRoot, name);
|
|
77
|
+
if (physical(file) !== graph?.inputRealpaths?.[name]) return false;
|
|
78
|
+
let current: string | null = null;
|
|
79
|
+
try {
|
|
80
|
+
if (fs.statSync(file).isFile())
|
|
81
|
+
current = textHash(fs.readFileSync(file));
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (!missing(error)) return false;
|
|
84
|
+
}
|
|
85
|
+
if (current !== expected) return false;
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Observe a declared host input under its existing raw-file or directory-kind
|
|
95
|
+
* codec. Descriptor resolution can declare directories as presence inputs;
|
|
96
|
+
* those are distinct from compiler source reads and directory enumeration.
|
|
97
|
+
* Native identity and metadata bracket the observation. Missing paths carry
|
|
98
|
+
* null witnesses, while unavailable or changing observations throw.
|
|
99
|
+
*
|
|
100
|
+
* @evidence contracts/common.md#principled-implementation Raw file bytes and the existing ttsc:host-input:directory domain marker reproduce the descriptor/native host-input contract, with physical identity and full native metadata checked before and after.
|
|
101
|
+
* @evidence contracts/common.md#clear-and-simple-design One observer supplies the same declared-host codec to input capture and retained-result admission, independently of compiler text and enumeration predicates.
|
|
102
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Only ENOENT/ENOTDIR establish absence; unsupported entry kinds, read failures and changing witnesses refuse reuse instead of becoming empty content.
|
|
103
|
+
* @evidence contracts/common.md#meaningful-documentation Native prose distinguishes directory presence from directory membership, states the producer codec and explains failure semantics.
|
|
104
|
+
* @evidence contracts/portability.md#os-neutral-implementation Native following stat, realpath and byte reads retain actual host links and physical spellings without OS-name or separator guesses.
|
|
105
|
+
* @evidence contracts/performance.md#efficient-algorithms File observations hash their complete byte buffer and bracket native metadata; directory presence hashes a fixed marker without scanning members.
|
|
106
|
+
* @evidence contracts/performance.md#reuse-equivalent-work Capture and admission share the producer's codec, but every invocation observes current witnesses and retains no path-only truth.
|
|
107
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources Read buffers and stat records are call-local; synchronous filesystem calls leave no retained handle or watcher.
|
|
108
|
+
*/
|
|
109
|
+
export function observeHostInput(
|
|
110
|
+
file: string,
|
|
111
|
+
): readonly [string | null, string | null] {
|
|
112
|
+
const beforePhysical = physical(file);
|
|
113
|
+
let before: fs.BigIntStats;
|
|
114
|
+
try {
|
|
115
|
+
before = fs.statSync(file, { bigint: true });
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!missing(error)) throw error;
|
|
118
|
+
if (beforePhysical !== null || physical(file) !== null)
|
|
119
|
+
throw new Error("Host input changed during absence observation.");
|
|
120
|
+
return [null, null];
|
|
121
|
+
}
|
|
122
|
+
if (!before.isFile() && !before.isDirectory())
|
|
123
|
+
throw new Error("Unsupported runtime host input kind.");
|
|
124
|
+
const hash = before.isDirectory()
|
|
125
|
+
? digest("ttsc:host-input:directory\0")
|
|
126
|
+
: digest(fs.readFileSync(file));
|
|
127
|
+
const after = fs.statSync(file, { bigint: true });
|
|
128
|
+
const signature = (stat: fs.BigIntStats): string =>
|
|
129
|
+
[stat.dev, stat.ino, stat.size, stat.mtimeNs, stat.ctimeNs].join(":");
|
|
130
|
+
if (
|
|
131
|
+
signature(before) !== signature(after) ||
|
|
132
|
+
beforePhysical !== physical(file)
|
|
133
|
+
)
|
|
134
|
+
throw new Error("Host input changed during observation.");
|
|
135
|
+
return [beforePhysical, hash];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Compare one compiler query record with the corresponding current queries. */
|
|
139
|
+
function observationHolds(
|
|
140
|
+
file: string,
|
|
141
|
+
observed: ITtscCompilerTransformation.IInputObservation,
|
|
142
|
+
): boolean {
|
|
143
|
+
for (const predicate of observed.nativePredicates ?? [])
|
|
144
|
+
if (
|
|
145
|
+
predicate.version !== 1 ||
|
|
146
|
+
!predicate.identityStable ||
|
|
147
|
+
physical(file) !== predicate.realpath ||
|
|
148
|
+
nativeDigest(file, predicate.kind) !== predicate.digest
|
|
149
|
+
)
|
|
150
|
+
return false;
|
|
151
|
+
let kind: "file" | "directory" | "missing" = "missing";
|
|
152
|
+
try {
|
|
153
|
+
const stat = fs.statSync(file);
|
|
154
|
+
kind = stat.isDirectory() ? "directory" : "file";
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (!missing(error)) return false;
|
|
157
|
+
}
|
|
158
|
+
if (
|
|
159
|
+
observed.fileExists !== undefined &&
|
|
160
|
+
observed.fileExists !== (kind === "file")
|
|
161
|
+
)
|
|
162
|
+
return false;
|
|
163
|
+
if (
|
|
164
|
+
observed.directoryExists !== undefined &&
|
|
165
|
+
observed.directoryExists !== (kind === "directory")
|
|
166
|
+
)
|
|
167
|
+
return false;
|
|
168
|
+
if (observed.stat !== undefined && observed.stat !== kind) return false;
|
|
169
|
+
if (observed.readFile !== undefined) {
|
|
170
|
+
let hash: string | null = null;
|
|
171
|
+
try {
|
|
172
|
+
if (kind !== "directory") hash = textHash(fs.readFileSync(file));
|
|
173
|
+
} catch {
|
|
174
|
+
/* Compiler read failed. */
|
|
175
|
+
}
|
|
176
|
+
if (
|
|
177
|
+
observed.readFile.ok ? hash !== observed.readFile.hash : hash !== null
|
|
178
|
+
)
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
if (observed.realpath !== undefined) {
|
|
182
|
+
const current = physical(file);
|
|
183
|
+
if (
|
|
184
|
+
observed.realpath.ok
|
|
185
|
+
? current !== observed.realpath.path
|
|
186
|
+
: current !== null
|
|
187
|
+
)
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (observed.accessibleEntries !== undefined) {
|
|
191
|
+
const directories: string[] = [];
|
|
192
|
+
const files: string[] = [];
|
|
193
|
+
let entries: fs.Dirent[] = [];
|
|
194
|
+
try {
|
|
195
|
+
entries = fs.readdirSync(file, { withFileTypes: true });
|
|
196
|
+
} catch {
|
|
197
|
+
/* Compiler enumeration returns an empty view. */
|
|
198
|
+
}
|
|
199
|
+
for (const entry of entries) {
|
|
200
|
+
try {
|
|
201
|
+
const stat = entry.isSymbolicLink()
|
|
202
|
+
? fs.statSync(path.join(file, entry.name))
|
|
203
|
+
: entry;
|
|
204
|
+
if (stat.isDirectory()) directories.push(entry.name);
|
|
205
|
+
else if (stat.isFile()) files.push(entry.name);
|
|
206
|
+
} catch {
|
|
207
|
+
/* Compiler enumeration omits inaccessible link targets. */
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const compare = (a: string, b: string): number =>
|
|
211
|
+
Buffer.compare(Buffer.from(a), Buffer.from(b));
|
|
212
|
+
if (
|
|
213
|
+
JSON.stringify({
|
|
214
|
+
directories: directories.sort(compare),
|
|
215
|
+
files: files.sort(compare),
|
|
216
|
+
}) !== JSON.stringify(observed.accessibleEntries)
|
|
217
|
+
)
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Reproduce native version-one file, optional-file, entry and directory
|
|
225
|
+
* bytes.
|
|
226
|
+
*/
|
|
227
|
+
function nativeDigest(file: string, kind: string): string {
|
|
228
|
+
if (kind === "file") return digest(fs.readFileSync(file));
|
|
229
|
+
if (kind === "optional-file") {
|
|
230
|
+
try {
|
|
231
|
+
return fs.statSync(file).isFile()
|
|
232
|
+
? digest(
|
|
233
|
+
Buffer.concat([Buffer.from("file\0"), fs.readFileSync(file)]),
|
|
234
|
+
)
|
|
235
|
+
: digest("missing\0");
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (missing(error)) return digest("missing\0");
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (kind === "entry") {
|
|
242
|
+
try {
|
|
243
|
+
const entry = fs.lstatSync(file);
|
|
244
|
+
return entry.isSymbolicLink()
|
|
245
|
+
? digest(
|
|
246
|
+
Buffer.concat([
|
|
247
|
+
Buffer.from("symlink\0"),
|
|
248
|
+
fs.readlinkSync(file, { encoding: "buffer" }),
|
|
249
|
+
]),
|
|
250
|
+
)
|
|
251
|
+
: digest(
|
|
252
|
+
(entry.isDirectory()
|
|
253
|
+
? "directory"
|
|
254
|
+
: entry.isFile()
|
|
255
|
+
? "file"
|
|
256
|
+
: "other") + "\0",
|
|
257
|
+
);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (missing(error)) return digest("missing\0");
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (kind !== "directory") throw new Error("unsupported native input codec");
|
|
264
|
+
const records: Buffer[] = [];
|
|
265
|
+
const names =
|
|
266
|
+
process.platform === "win32"
|
|
267
|
+
? fs.readdirSync(file).map((name) => Buffer.from(name))
|
|
268
|
+
: fs.readdirSync(file, { encoding: "buffer" });
|
|
269
|
+
for (const name of names) {
|
|
270
|
+
const target =
|
|
271
|
+
process.platform === "win32"
|
|
272
|
+
? path.join(file, name.toString())
|
|
273
|
+
: Buffer.concat([Buffer.from(file + path.sep), name]);
|
|
274
|
+
const entry = fs.lstatSync(target);
|
|
275
|
+
const entryKind = entry.isDirectory()
|
|
276
|
+
? "directory"
|
|
277
|
+
: entry.isFile()
|
|
278
|
+
? "file"
|
|
279
|
+
: entry.isSymbolicLink()
|
|
280
|
+
? "symlink"
|
|
281
|
+
: "other";
|
|
282
|
+
const link = entry.isSymbolicLink()
|
|
283
|
+
? fs.readlinkSync(target, { encoding: "buffer" })
|
|
284
|
+
: Buffer.alloc(0);
|
|
285
|
+
records.push(
|
|
286
|
+
Buffer.concat([name, Buffer.from("\0" + entryKind + "\0"), link]),
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
records.sort(Buffer.compare);
|
|
290
|
+
return digest(
|
|
291
|
+
Buffer.concat(
|
|
292
|
+
records.flatMap((record, index) =>
|
|
293
|
+
index === 0 ? [record] : [Buffer.from([0]), record],
|
|
294
|
+
),
|
|
295
|
+
),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Hash compiler-decoded text, retaining the BOM and UTF-16 producer policy. */
|
|
300
|
+
function textHash(bytes: Buffer): string {
|
|
301
|
+
if (
|
|
302
|
+
bytes.length >= 2 &&
|
|
303
|
+
((bytes[0] === 0xff && bytes[1] === 0xfe) ||
|
|
304
|
+
(bytes[0] === 0xfe && bytes[1] === 0xff))
|
|
305
|
+
) {
|
|
306
|
+
const text = Buffer.from(
|
|
307
|
+
bytes.subarray(2, 2 + Math.floor((bytes.length - 2) / 2) * 2),
|
|
308
|
+
);
|
|
309
|
+
if (bytes[0] === 0xfe) text.swap16();
|
|
310
|
+
return digest(Buffer.from(text.toString("utf16le"), "utf8"));
|
|
311
|
+
}
|
|
312
|
+
return digest(
|
|
313
|
+
bytes.length >= 3 &&
|
|
314
|
+
bytes[0] === 0xef &&
|
|
315
|
+
bytes[1] === 0xbb &&
|
|
316
|
+
bytes[2] === 0xbf
|
|
317
|
+
? bytes.subarray(3)
|
|
318
|
+
: bytes,
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** Obtain a current physical coordinate, with null only for native absence. */
|
|
323
|
+
function physical(file: string): string | null {
|
|
324
|
+
try {
|
|
325
|
+
return fs.realpathSync.native(file);
|
|
326
|
+
} catch (error) {
|
|
327
|
+
if (missing(error)) return null;
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Classify only native absent-path errors. */
|
|
333
|
+
function missing(error: unknown): boolean {
|
|
334
|
+
return (
|
|
335
|
+
typeof error === "object" &&
|
|
336
|
+
error !== null &&
|
|
337
|
+
"code" in error &&
|
|
338
|
+
(error.code === "ENOENT" || error.code === "ENOTDIR")
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** SHA-256 of supplied text or raw bytes. */
|
|
343
|
+
function digest(bytes: string | Buffer): string {
|
|
344
|
+
return crypto.createHash("sha256").update(bytes).digest("hex");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
@@ -195,11 +195,12 @@ export namespace TsgoArguments {
|
|
|
195
195
|
/**
|
|
196
196
|
* The forwarded-tsgo payload for a native `build`/`check` emit invocation.
|
|
197
197
|
*
|
|
198
|
-
* The sidecar builds its Program in-process, so
|
|
199
|
-
* travel the same channel
|
|
200
|
-
* set does not declare `--rootDir`, and `filterHostArgs` would
|
|
198
|
+
* The sidecar builds its Program in-process, so runtime source-map defaults
|
|
199
|
+
* and the pinned `rootDir` travel the same channel as other tsgo options —
|
|
200
|
+
* the host flag set does not declare `--rootDir`, and `filterHostArgs` would
|
|
201
|
+
* strip it.
|
|
201
202
|
*
|
|
202
|
-
* @evidence contracts/common.md#principled-implementation The same private layout root used by direct builds
|
|
203
|
+
* @evidence contracts/common.md#principled-implementation The same private layout root and forced runtime source-map default used by direct builds precede user arguments in the sidecar compiler-option channel, preserving explicit overrides and declared/composite containment without a new host flag.
|
|
203
204
|
* @evidence contracts/common.md#clear-and-simple-design Root pinning stays in one helper and general payload ordering/serialization stays in createNativeTsgoArgs.
|
|
204
205
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts The supported environment payload carries compiler options instead of injecting unknown flags into strict foreign host parsers.
|
|
205
206
|
* @evidence contracts/common.md#meaningful-documentation Native prose explains why rootDir travels with compiler options rather than through the host flag set.
|
|
@@ -215,7 +216,12 @@ export namespace TsgoArguments {
|
|
|
215
216
|
): string | undefined {
|
|
216
217
|
return createNativeTsgoArgs(
|
|
217
218
|
options,
|
|
218
|
-
|
|
219
|
+
[
|
|
220
|
+
...(options.forceRuntimeSourceMap === true
|
|
221
|
+
? ["--sourceMap", "true"]
|
|
222
|
+
: []),
|
|
223
|
+
...pinnedRootDirArgs(execution, options),
|
|
224
|
+
],
|
|
219
225
|
false,
|
|
220
226
|
);
|
|
221
227
|
}
|
|
@@ -2,6 +2,8 @@ import type { TtscBuildResult } from "../../../structures/internal/TtscBuildResu
|
|
|
2
2
|
import { BuildExecution } from "./BuildExecution";
|
|
3
3
|
import { BuildTiming } from "./BuildTiming";
|
|
4
4
|
import type { RunBuildOptions } from "./RunBuildOptions";
|
|
5
|
+
import { RuntimeBuildCache } from "./RuntimeBuildCache";
|
|
6
|
+
import { RuntimeBuildInputs } from "./RuntimeBuildInputs";
|
|
5
7
|
import { WatchInputPublication } from "./WatchInputPublication";
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -21,7 +23,7 @@ import { WatchInputPublication } from "./WatchInputPublication";
|
|
|
21
23
|
* @evidence contracts/common.md#meaningful-documentation Native prose distinguishes returned exit failures from thrown setup/launch errors and explains the project-free branch.
|
|
22
24
|
* @evidence contracts/portability.md#os-neutral-implementation Execution selection and spawning use the shared native path/process boundaries with cwd and separate argv, rather than constructing a shell command here.
|
|
23
25
|
* @evidence contracts/performance.md#efficient-algorithms Timing creation and terminal selection make their own flag projections before the selected preparation/execution path. Delegated configuration, plugin, native/provenance and diagnostic work follows its actual input/report sizes; timing formatting scans ledger labels and output. No measured dominance or duration/output ceiling is established by this wrapper.
|
|
24
|
-
* @evidence contracts/performance.md#reuse-equivalent-work A resolved execution context is carried through preparation and execution
|
|
26
|
+
* @evidence contracts/performance.md#reuse-equivalent-work A resolved execution context is carried through preparation and execution without another plugin load; private runtime requests delegate verified completed-emission reuse to RuntimeBuildCache with current input and producer proofs.
|
|
25
27
|
* @evidence contracts/performance.md#bound-retention-and-release-resources The ledger and execution state are build-owned, while returned output/proof/diagnostic records transfer to the caller; no resident handle or historical build is stored here. Delegated native/probe/artifact acquisition and cleanup may be best effort, and thrown setup can precede some cleanup boundaries. This wrapper supplies no duration/output bound or descendant-release certification.
|
|
26
28
|
*/
|
|
27
29
|
export function runBuild(options: RunBuildOptions = {}): TtscBuildResult {
|
|
@@ -36,8 +38,8 @@ export function runBuild(options: RunBuildOptions = {}): TtscBuildResult {
|
|
|
36
38
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts Awaiting changes only publication completion, preserves compiler/plugin selection and project-free terminal behavior, and sends publication failure through existing setup and cleanup rather than bypassing a pending baseline.
|
|
37
39
|
* @evidence contracts/common.md#meaningful-documentation Entry prose states the publication barrier, order before compilation and internal callers' obligation to complete the sequence and deliver rejection.
|
|
38
40
|
* @evidence contracts/portability.md#os-neutral-implementation BuildExecution retains native cwd, path identity and argument-array ownership across suspension; the namespace adds no independent native boundary.
|
|
39
|
-
* @evidence contracts/performance.md#efficient-algorithms Each selected terminal, context, discovery
|
|
40
|
-
* @evidence contracts/performance.md#reuse-equivalent-work One resolved execution context serves preparation and compilation without reloading plugins; the
|
|
41
|
+
* @evidence contracts/performance.md#efficient-algorithms Each selected terminal, context, discovery and preparation phase runs once; eligible runtime requests add native source/configuration queries and content proofs before restoring or compiling. Each publication adds one await and constant sequence state.
|
|
42
|
+
* @evidence contracts/performance.md#reuse-equivalent-work One resolved execution context serves preparation and compilation without reloading plugins; the delegated runtime store reuses completed bytes only under current equal input snapshots and valid producer witnesses, with ordinary compilation on any miss.
|
|
41
43
|
* @evidence contracts/performance.md#bound-retention-and-release-resources The invocation owns its sequence, ledger, context and current handoff while callbacks settle. Selected results transfer to the caller, delegated resource ownership and cleanup stay unchanged, and no resident history is retained.
|
|
42
44
|
*/
|
|
43
45
|
export namespace runBuild {
|
|
@@ -72,14 +74,27 @@ export namespace runBuild {
|
|
|
72
74
|
execution,
|
|
73
75
|
setupStartedAt,
|
|
74
76
|
);
|
|
75
|
-
const
|
|
76
|
-
prepared.result ??
|
|
77
|
+
const build = () =>
|
|
77
78
|
BuildExecution.runPreparedBuild(
|
|
78
79
|
options,
|
|
79
80
|
timing,
|
|
80
81
|
execution,
|
|
81
82
|
prepared.buildOptions,
|
|
82
83
|
);
|
|
84
|
+
const proof =
|
|
85
|
+
prepared.result === undefined
|
|
86
|
+
? RuntimeBuildInputs.create(prepared.buildOptions, execution)
|
|
87
|
+
: undefined;
|
|
88
|
+
const result =
|
|
89
|
+
prepared.result ??
|
|
90
|
+
(proof === undefined
|
|
91
|
+
? build()
|
|
92
|
+
: RuntimeBuildCache.run({
|
|
93
|
+
directory: options.runtimeCacheDir,
|
|
94
|
+
emitDir: options.isolateOutputsTo!,
|
|
95
|
+
...proof,
|
|
96
|
+
build,
|
|
97
|
+
}));
|
|
83
98
|
return BuildTiming.appendTimingOutput(result, timing);
|
|
84
99
|
}
|
|
85
100
|
}
|
|
@@ -7,36 +7,40 @@ import type { TtscBuildResult } from "../../structures/internal/TtscBuildResult"
|
|
|
7
7
|
import { parseReferenceGraph } from "./parseNativeTransformOutput";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Execute a check with
|
|
11
|
-
* selected host, original diagnostics, streams and status.
|
|
10
|
+
* Execute a check or opted-in build with same-generation input observations,
|
|
11
|
+
* preserving the selected host, original diagnostics, streams and status.
|
|
12
12
|
*
|
|
13
|
-
* The selected native verb must be check
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* The selected native verb must be check, or build with the separate
|
|
14
|
+
* emitObservations capability, before negotiating its generation channel. A
|
|
15
|
+
* check-stage descriptor can also serve effectful fix/format verbs; those
|
|
16
|
+
* retain their original result and never acquire an invented check graph. An
|
|
17
|
+
* opted-in host writes a private sidecar even when its check fails. Hosts
|
|
17
18
|
* without that transport run their original command under their existing
|
|
18
19
|
* descriptor and declared-input contract; omission does not assert complete
|
|
19
20
|
* driver observations. No check is rerun to infer what the earlier generation
|
|
20
21
|
* read. Missing metadata after an interrupted failed opted-in check likewise
|
|
21
|
-
* withholds reuse
|
|
22
|
-
* error
|
|
22
|
+
* withholds reuse. Missing or malformed successful check metadata is a protocol
|
|
23
|
+
* error. Build metadata is optional cache evidence: unavailable setup, records
|
|
24
|
+
* or cleanup retain the original build result with incomplete observations, so
|
|
25
|
+
* loss of caching cannot turn a fresh successful emit into failure.
|
|
23
26
|
*
|
|
24
27
|
* The callback receives only additional transport arguments. This operation
|
|
25
28
|
* owns their accepted canonical private directory and attempts file and empty
|
|
26
29
|
* directory removal without recursive deletion. Setup observes ownership before
|
|
27
30
|
* entering the cleanup boundary, so a setup observation failure can leave the
|
|
28
31
|
* allocation unclaimed. Cleanup failures retain the original thrown failure or
|
|
29
|
-
* completed result as their cause. Before reading and removing the
|
|
30
|
-
* the parent must still have its captured native identity; a replaced
|
|
31
|
-
* is left untouched and
|
|
32
|
-
* an atomic descriptor or ABA
|
|
32
|
+
* completed check result as their cause. Before reading and removing the
|
|
33
|
+
* artifact, the parent must still have its captured native identity; a replaced
|
|
34
|
+
* directory is left untouched and withholds build reuse or reports check
|
|
35
|
+
* failure. These observations do not provide an atomic descriptor or ABA
|
|
36
|
+
* guarantee.
|
|
33
37
|
*
|
|
34
|
-
* @evidence contracts/common.md#principled-implementation
|
|
38
|
+
* @evidence contracts/common.md#principled-implementation Actual check and build verbs negotiate independent declared observation capabilities; fix/format verbs retain their own result. Build witness IO/protocol failures preserve the one original build with incomplete observations, while checks retain their strict metadata contract. Legacy hosts keep their original command without fabricated completeness.
|
|
35
39
|
* @evidence contracts/common.md#clear-and-simple-design The actual verb and descriptor opt-in jointly select one adapter for strict wire decoding and private artifact lifetime; its callback retains command and diagnostic normalization ownership.
|
|
36
40
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts Neither a later project-input query nor a separate transform can reconstruct check observations; unknown hosts receive no guessed flag and malformed metadata cannot become a complete empty observation.
|
|
37
41
|
* @evidence contracts/common.md#meaningful-documentation Native paragraphs distinguish failed-check metadata, unavailable transport, protocol errors and cleanup ownership, with body and tags separated according to the documentation skill.
|
|
38
42
|
* @evidence contracts/portability.md#os-neutral-implementation Node native absolute paths locate the canonical private artifact, and an additional argv element conveys it without shell quoting or platform-specific filename guesses.
|
|
39
|
-
* @evidence contracts/performance.md#efficient-algorithms One original check callback runs; this adapter adds canonical temp acquisition/native ownership observations, complete sidecar read/JSON decoding and indexed input membership/witness validation. Work and temporary storage follow wire/path bytes and declared inputs plus delegated
|
|
43
|
+
* @evidence contracts/performance.md#efficient-algorithms One original check or build callback runs; this adapter adds canonical temp acquisition/native ownership observations, complete sidecar read/JSON decoding and indexed input membership/witness validation. Work and temporary storage follow wire/path bytes and declared inputs plus delegated producer runtime; it does not add a second compiler generation or source-content rehash, and supplies no callback timeout or metadata-byte ceiling.
|
|
40
44
|
*
|
|
41
45
|
* @evidenceExclude contracts/performance.md#reuse-equivalent-work This adapter supplies the generation's proof to its cache owner rather than retaining or sharing a completed check itself.
|
|
42
46
|
*
|
|
@@ -48,17 +52,32 @@ export function runNativeCheckWithObservations(
|
|
|
48
52
|
/** Actual argv verb; legacy direct callers already represent a check. */
|
|
49
53
|
command: string = "check",
|
|
50
54
|
): TtscBuildResult {
|
|
51
|
-
|
|
55
|
+
const emitting =
|
|
56
|
+
command === "build" && plugin.capabilities?.emitObservations === true;
|
|
57
|
+
if (
|
|
58
|
+
!emitting &&
|
|
59
|
+
(command !== "check" || plugin.capabilities?.checkObservations !== true)
|
|
60
|
+
)
|
|
52
61
|
return run([]);
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
let directory: string;
|
|
64
|
+
let ownership: fs.Stats;
|
|
65
|
+
try {
|
|
66
|
+
directory = createCanonicalTempDirectory("ttsc-check-observations-");
|
|
67
|
+
ownership = fs.lstatSync(directory);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (emitting) return { ...run([]), observationsComplete: false };
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
56
72
|
const file = path.join(directory, "observations.json");
|
|
57
73
|
let completed: TtscBuildResult | undefined;
|
|
58
74
|
let failed = false;
|
|
59
75
|
let failure: unknown;
|
|
60
76
|
try {
|
|
61
|
-
completed = run([
|
|
77
|
+
completed = run([
|
|
78
|
+
(emitting ? "--emit-observations-json=" : "--check-observations-json=") +
|
|
79
|
+
file,
|
|
80
|
+
]);
|
|
62
81
|
if (completed.processCompletedNormally !== true)
|
|
63
82
|
return { ...completed, observationsComplete: false };
|
|
64
83
|
let text: string;
|
|
@@ -68,6 +87,7 @@ export function runNativeCheckWithObservations(
|
|
|
68
87
|
throw new Error("check observation artifact is not an ordinary file");
|
|
69
88
|
text = fs.readFileSync(file, "utf8");
|
|
70
89
|
} catch (error) {
|
|
90
|
+
if (emitting) return { ...completed, observationsComplete: false };
|
|
71
91
|
if (
|
|
72
92
|
completed.status !== 0 &&
|
|
73
93
|
(error as NodeJS.ErrnoException).code === "ENOENT"
|
|
@@ -80,6 +100,7 @@ export function runNativeCheckWithObservations(
|
|
|
80
100
|
try {
|
|
81
101
|
return { ...completed, ...parseObservations(JSON.parse(text)) };
|
|
82
102
|
} catch (error) {
|
|
103
|
+
if (emitting) return { ...completed, observationsComplete: false };
|
|
83
104
|
throw new Error("ttsc: invalid check observation metadata", {
|
|
84
105
|
cause: new AggregateError([completed, error]),
|
|
85
106
|
});
|
|
@@ -108,6 +129,8 @@ export function runNativeCheckWithObservations(
|
|
|
108
129
|
}
|
|
109
130
|
}
|
|
110
131
|
if (errors.length !== 0) {
|
|
132
|
+
if (emitting && completed !== undefined && !failed)
|
|
133
|
+
return { ...completed, observationsComplete: false };
|
|
111
134
|
const primary = failed ? failure : completed;
|
|
112
135
|
throw new AggregateError(
|
|
113
136
|
[primary, ...errors],
|
package/src/flags/FLAG_SCHEMA.ts
CHANGED
|
@@ -352,6 +352,13 @@ export const FLAG_SCHEMA: readonly FlagSpec[] = [
|
|
|
352
352
|
// -------------------------------------------------------------------------
|
|
353
353
|
// ttsx-specific options.
|
|
354
354
|
// -------------------------------------------------------------------------
|
|
355
|
+
{
|
|
356
|
+
name: "--no-cache",
|
|
357
|
+
kind: "boolean",
|
|
358
|
+
subcommands: ["ttsx"],
|
|
359
|
+
consumedBy: ["launcher"],
|
|
360
|
+
description: "Disable persistent runtime project emit reuse.",
|
|
361
|
+
},
|
|
355
362
|
{
|
|
356
363
|
name: "--require",
|
|
357
364
|
aliases: ["-r"],
|
|
@@ -120,6 +120,7 @@ export function parseTtsxCLI(argv: readonly string[]) {
|
|
|
120
120
|
checkers: getNumber(result, "--checkers"),
|
|
121
121
|
cwd: getString(result, "--cwd"),
|
|
122
122
|
entry,
|
|
123
|
+
noCache: getBoolean(result, "--no-cache") === true,
|
|
123
124
|
noPlugins: getBoolean(result, "--no-plugins") === true,
|
|
124
125
|
passthrough: postEntryArgs,
|
|
125
126
|
preload,
|
|
@@ -65,6 +65,9 @@ export function prepareExecution(
|
|
|
65
65
|
|
|
66
66
|
/** Internal cache key for more than one checked entry in this process. */
|
|
67
67
|
runtimeCacheKey?: string;
|
|
68
|
+
|
|
69
|
+
/** False bypasses persistent project emits while keeping normal execution. */
|
|
70
|
+
runtimeCache?: boolean;
|
|
68
71
|
} = {},
|
|
69
72
|
): {
|
|
70
73
|
/** Claimed runtime generation whose cleanup ownership transfers to the caller. */
|
|
@@ -383,6 +386,15 @@ function createProjectContext(
|
|
|
383
386
|
runtimeCacheKey,
|
|
384
387
|
processDir,
|
|
385
388
|
pluginCacheDir: explicitCacheDir === undefined ? undefined : cacheDir,
|
|
389
|
+
runtimeBuildCacheDir:
|
|
390
|
+
options.runtimeCache === false ||
|
|
391
|
+
env.TTSX_DISABLE_CACHE === "1" ||
|
|
392
|
+
env.TTSC_PLUGIN_DESCRIPTOR_LOAD === "1"
|
|
393
|
+
? undefined
|
|
394
|
+
: path.join(
|
|
395
|
+
cacheRoot,
|
|
396
|
+
SourceBuildCacheLayout.RUNTIME_BUILD_CACHE_DIRNAME,
|
|
397
|
+
),
|
|
386
398
|
orphanCacheDir: path.join(
|
|
387
399
|
cacheRoot,
|
|
388
400
|
SourceBuildCacheLayout.ORPHAN_CACHE_DIRNAME,
|
|
@@ -527,6 +539,7 @@ function buildProject(
|
|
|
527
539
|
emit: true,
|
|
528
540
|
env: options.env,
|
|
529
541
|
cacheDir: context.pluginCacheDir,
|
|
542
|
+
runtimeCacheDir: context.runtimeBuildCacheDir,
|
|
530
543
|
outDir: context.emitDir,
|
|
531
544
|
// Every output this build writes stays in ttsx's private directory: a
|
|
532
545
|
// declared `declarationDir`, `tsBuildInfoFile`, or `outFile`, and any
|
|
@@ -110,6 +110,7 @@ async function run(
|
|
|
110
110
|
cacheDir: resolveCacheDir(cwd, parsed.cacheDir),
|
|
111
111
|
checkers: parsed.checkers,
|
|
112
112
|
cwd,
|
|
113
|
+
env: parsed.noCache ? { TTSX_DISABLE_CACHE: "1" } : undefined,
|
|
113
114
|
passthrough: parsed.tsgoFlags,
|
|
114
115
|
// `--no-plugins` builds the entry's owning project with plugin
|
|
115
116
|
// discovery and loading disabled. ttsc's own config loaders use it
|
|
@@ -121,6 +122,7 @@ async function run(
|
|
|
121
122
|
// tsconfig deliberately does not satisfy.
|
|
122
123
|
plugins: parsed.noPlugins ? false : undefined,
|
|
123
124
|
project: parsed.project,
|
|
125
|
+
runtimeCache: !parsed.noCache,
|
|
124
126
|
singleThreaded: parsed.singleThreaded,
|
|
125
127
|
});
|
|
126
128
|
await settleSignals();
|
|
@@ -159,6 +161,7 @@ function printHelp(): void {
|
|
|
159
161
|
" -P, --project <file> Use an explicit tsconfig.json",
|
|
160
162
|
" --cwd <dir> Resolve entry/project relative to this directory",
|
|
161
163
|
" --cache-dir <dir> Override the runner and source-plugin cache root",
|
|
164
|
+
" --no-cache Disable persistent runtime project emit reuse",
|
|
162
165
|
" --binary <path> Use an explicit tsgo binary",
|
|
163
166
|
" --no-plugins Build the project without ttsc plugins",
|
|
164
167
|
" -r, --require <module> Preload a module before the entrypoint",
|
|
@@ -244,6 +247,7 @@ async function runJavaScriptEntry(
|
|
|
244
247
|
];
|
|
245
248
|
const env: NodeJS.ProcessEnv = {
|
|
246
249
|
...process.env,
|
|
250
|
+
...(parsed.noCache ? { TTSX_DISABLE_CACHE: "1" } : {}),
|
|
247
251
|
// ttsc's own helpers run with what the user passed (#1740).
|
|
248
252
|
...TtsxNodeOptions.give(
|
|
249
253
|
process.env,
|
|
@@ -329,6 +333,7 @@ async function runPreparedEntry(
|
|
|
329
333
|
];
|
|
330
334
|
const runtimeEnv: NodeJS.ProcessEnv = {
|
|
331
335
|
...process.env,
|
|
336
|
+
...(parsed.noCache ? { TTSX_DISABLE_CACHE: "1" } : {}),
|
|
332
337
|
// ttsc's own helpers run with what the user passed (#1740).
|
|
333
338
|
...TtsxNodeOptions.give(
|
|
334
339
|
process.env,
|