@ttsc/unplugin 0.36.2 → 0.36.4
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/api.js +5 -2
- package/lib/api.js.map +1 -1
- package/lib/api.mjs +1 -1
- package/lib/core/bridge/TtscProjectRecord.d.cts +7 -0
- package/lib/core/bridge/TtscProjectRecord.d.mts +7 -0
- package/lib/core/bridge/TtscProjectRecord.d.ts +7 -0
- package/lib/core/bridge/projectRecordArgumentsMatch.d.cts +8 -5
- package/lib/core/bridge/projectRecordArgumentsMatch.d.mts +8 -5
- package/lib/core/bridge/projectRecordArgumentsMatch.d.ts +8 -5
- package/lib/core/bridge/projectRecordArgumentsMatch.js +15 -8
- package/lib/core/bridge/projectRecordArgumentsMatch.js.map +1 -1
- package/lib/core/bridge/projectRecordArgumentsMatch.mjs +15 -8
- package/lib/core/bridge/projectRecordArgumentsMatch.mjs.map +1 -1
- package/lib/core/bridge/readProjectRecordFile.js +8 -1
- package/lib/core/bridge/readProjectRecordFile.js.map +1 -1
- package/lib/core/bridge/readProjectRecordFile.mjs +8 -1
- package/lib/core/bridge/readProjectRecordFile.mjs.map +1 -1
- package/lib/core/index.js +5 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -1
- package/lib/core/next/next.js +2 -2
- package/lib/core/next/next.js.map +1 -1
- package/lib/core/next/next.mjs +1 -1
- package/lib/core/rollup/rollupDeliveryOptions.js +2 -2
- package/lib/core/rollup/rollupDeliveryOptions.js.map +1 -1
- package/lib/core/rollup/rollupDeliveryOptions.mjs +1 -1
- package/lib/core/transform/cache/selectCachedGenerationAction.d.cts +12 -4
- package/lib/core/transform/cache/selectCachedGenerationAction.d.mts +12 -4
- package/lib/core/transform/cache/selectCachedGenerationAction.d.ts +12 -4
- package/lib/core/transform/cache/selectCachedGenerationAction.js +16 -9
- package/lib/core/transform/cache/selectCachedGenerationAction.js.map +1 -1
- package/lib/core/transform/cache/selectCachedGenerationAction.mjs +16 -9
- package/lib/core/transform/cache/selectCachedGenerationAction.mjs.map +1 -1
- package/lib/core/transform/generation/captureTransformGeneration.js +8 -2
- package/lib/core/transform/generation/captureTransformGeneration.js.map +1 -1
- package/lib/core/transform/generation/captureTransformGeneration.mjs +8 -2
- package/lib/core/transform/generation/captureTransformGeneration.mjs.map +1 -1
- package/lib/core/transform/session/claimSharedCompile.d.cts +12 -1
- package/lib/core/transform/session/claimSharedCompile.d.mts +12 -1
- package/lib/core/transform/session/claimSharedCompile.d.ts +12 -1
- package/lib/core/transform/session/claimSharedCompile.js +22 -4
- package/lib/core/transform/session/claimSharedCompile.js.map +1 -1
- package/lib/core/transform/session/claimSharedCompile.mjs +22 -4
- package/lib/core/transform/session/claimSharedCompile.mjs.map +1 -1
- package/lib/core/transform/transformTtsc.js +3 -2
- package/lib/core/transform/transformTtsc.js.map +1 -1
- package/lib/core/transform/transformTtsc.mjs +2 -1
- package/lib/core/transform/transformTtsc.mjs.map +1 -1
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.d.cts +1 -17
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.d.mts +1 -17
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.d.ts +1 -17
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.js +7 -53
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.js.map +1 -1
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.mjs +1 -54
- package/lib/core/transform/tsconfig/resolveCompilerEnvironment.mjs.map +1 -1
- package/lib/core/transform/validation/captureUniversalHostInputValidation.d.cts +10 -2
- package/lib/core/transform/validation/captureUniversalHostInputValidation.d.mts +10 -2
- package/lib/core/transform/validation/captureUniversalHostInputValidation.d.ts +10 -2
- package/lib/core/transform/validation/captureUniversalHostInputValidation.js +19 -2
- package/lib/core/transform/validation/captureUniversalHostInputValidation.js.map +1 -1
- package/lib/core/transform/validation/captureUniversalHostInputValidation.mjs +19 -2
- package/lib/core/transform/validation/captureUniversalHostInputValidation.mjs.map +1 -1
- package/lib/core/transform/validation/environmentInputMismatch.d.cts +23 -0
- package/lib/core/transform/validation/environmentInputMismatch.d.mts +23 -0
- package/lib/core/transform/validation/environmentInputMismatch.d.ts +23 -0
- package/lib/core/transform/validation/environmentInputMismatch.js +46 -0
- package/lib/core/transform/validation/environmentInputMismatch.js.map +1 -0
- package/lib/core/transform/validation/environmentInputMismatch.mjs +44 -0
- package/lib/core/transform/validation/environmentInputMismatch.mjs.map +1 -0
- package/lib/core/transform/validation/isEnvironmentInputs.d.cts +15 -0
- package/lib/core/transform/validation/isEnvironmentInputs.d.mts +15 -0
- package/lib/core/transform/validation/isEnvironmentInputs.d.ts +15 -0
- package/lib/core/transform/validation/isEnvironmentInputs.js +26 -0
- package/lib/core/transform/validation/isEnvironmentInputs.js.map +1 -0
- package/lib/core/transform/validation/isEnvironmentInputs.mjs +24 -0
- package/lib/core/transform/validation/isEnvironmentInputs.mjs.map +1 -0
- package/lib/core/transform/watch/TtscTransformHooks.d.cts +6 -4
- package/lib/core/transform/watch/TtscTransformHooks.d.mts +6 -4
- package/lib/core/transform/watch/TtscTransformHooks.d.ts +6 -4
- package/lib/core/transform/watch/handWatchInputs.d.cts +3 -1
- package/lib/core/transform/watch/handWatchInputs.d.mts +3 -1
- package/lib/core/transform/watch/handWatchInputs.d.ts +3 -1
- package/lib/core/transform/watch/handWatchInputs.js +7 -2
- package/lib/core/transform/watch/handWatchInputs.js.map +1 -1
- package/lib/core/transform/watch/handWatchInputs.mjs +7 -2
- package/lib/core/transform/watch/handWatchInputs.mjs.map +1 -1
- package/lib/core/transform/watch/notifyFailedGenerationInputs.js +3 -1
- package/lib/core/transform/watch/notifyFailedGenerationInputs.js.map +1 -1
- package/lib/core/transform/watch/notifyFailedGenerationInputs.mjs +3 -1
- package/lib/core/transform/watch/notifyFailedGenerationInputs.mjs.map +1 -1
- package/lib/core/transform/watch/notifyProjectRecord.js +4 -0
- package/lib/core/transform/watch/notifyProjectRecord.js.map +1 -1
- package/lib/core/transform/watch/notifyProjectRecord.mjs +4 -0
- package/lib/core/transform/watch/notifyProjectRecord.mjs.map +1 -1
- package/lib/core/transform/watch/notifyWatchInputs.js +3 -1
- package/lib/core/transform/watch/notifyWatchInputs.js.map +1 -1
- package/lib/core/transform/watch/notifyWatchInputs.mjs +3 -1
- package/lib/core/transform/watch/notifyWatchInputs.mjs.map +1 -1
- package/lib/core/turbopack/turbopack.js +2 -2
- package/lib/core/turbopack/turbopack.js.map +1 -1
- package/lib/core/turbopack/turbopack.mjs +1 -1
- package/lib/core/unplugin.js +3 -3
- package/lib/core/unplugin.js.map +1 -1
- package/lib/core/unplugin.mjs +1 -1
- package/package.json +3 -3
- package/src/core/bridge/TtscProjectRecord.ts +8 -0
- package/src/core/bridge/projectRecordArgumentsMatch.ts +19 -7
- package/src/core/bridge/readProjectRecordFile.ts +8 -1
- package/src/core/transform/cache/selectCachedGenerationAction.ts +19 -4
- package/src/core/transform/generation/captureTransformGeneration.ts +8 -1
- package/src/core/transform/session/claimSharedCompile.ts +35 -5
- package/src/core/transform/transformTtsc.ts +1 -0
- package/src/core/transform/tsconfig/resolveCompilerEnvironment.ts +1 -61
- package/src/core/transform/validation/captureUniversalHostInputValidation.ts +21 -1
- package/src/core/transform/validation/environmentInputMismatch.ts +43 -0
- package/src/core/transform/validation/isEnvironmentInputs.ts +28 -0
- package/src/core/transform/watch/TtscTransformHooks.ts +6 -3
- package/src/core/transform/watch/handWatchInputs.ts +5 -1
- package/src/core/transform/watch/notifyFailedGenerationInputs.ts +3 -0
- package/src/core/transform/watch/notifyProjectRecord.ts +5 -0
- package/src/core/transform/watch/notifyWatchInputs.ts +8 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { envelopeDerivation } from "../envelope/envelopeDerivation";
|
|
2
2
|
import { isVolatileFile } from "../envelope/isVolatileFile";
|
|
3
3
|
import type { TtscGenerationProof } from "../validation/TtscGenerationProof";
|
|
4
|
+
import { environmentInputMismatch } from "../validation/environmentInputMismatch";
|
|
4
5
|
import { matchesCachedSource } from "../validation/matchesCachedSource";
|
|
5
6
|
import type { TtscCachedProjectTransform } from "./TtscCachedProjectTransform";
|
|
6
7
|
import type { TtscTransformCache } from "./TtscTransformCache";
|
|
@@ -12,11 +13,14 @@ import { evictGeneration } from "./evictGeneration";
|
|
|
12
13
|
* The caller owns awaiting, Promise-ownership checks and required native
|
|
13
14
|
* notification settling. A volatile or mismatching generation is evicted by
|
|
14
15
|
* identity; if eviction exposed a sibling replacement, the caller retries it.
|
|
15
|
-
* Otherwise the caller must capture a new generation. A
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Otherwise the caller must capture a new generation. A generation whose
|
|
17
|
+
* plugins read an environment variable that `environment`, the delivery's
|
|
18
|
+
* compiler environment snapshot, no longer gives the recorded value is
|
|
19
|
+
* mismatching on every path, the pass-shared first delivery included: no file
|
|
20
|
+
* proof can stand in for it. A serving decision does not perform output
|
|
21
|
+
* selection or host notification, which remain with delivery.
|
|
18
22
|
*
|
|
19
|
-
* @evidence contracts/common.md#principled-implementation The actual generation's volatility and recorded source proof decide serving; identity-guarded eviction then distinguishes a sibling's current replacement from an empty capture slot.
|
|
23
|
+
* @evidence contracts/common.md#principled-implementation The actual generation's volatility, recorded environment reads and recorded source proof decide serving; identity-guarded eviction then distinguishes a sibling's current replacement from an empty capture slot.
|
|
20
24
|
* @evidence contracts/common.md#clear-and-simple-design One synchronous operation selects serve/retry/capture and owns mismatch eviction, while its production caller owns awaiting, notification settling, native capture and output delivery.
|
|
21
25
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts Decisions inspect the supplied actual generation and validators without fabricating a producer result, capability or success; no injectable compiler callback or test-only branch is introduced.
|
|
22
26
|
* @evidence contracts/common.md#meaningful-documentation Native prose states the caller's awaited-Promise and settled-notification responsibilities and separates the decision from producer and delivery effects.
|
|
@@ -43,11 +47,22 @@ export function selectCachedGenerationAction(props: {
|
|
|
43
47
|
generation: Promise<TtscCachedProjectTransform>;
|
|
44
48
|
key: string;
|
|
45
49
|
source: string;
|
|
50
|
+
/**
|
|
51
|
+
* The delivery's compiler environment snapshot, the one a recompile would run
|
|
52
|
+
* under, against which recorded environment reads are compared.
|
|
53
|
+
*/
|
|
54
|
+
environment: NodeJS.ProcessEnv;
|
|
46
55
|
/** False only for speculative source reads before an actual module delivery. */
|
|
47
56
|
reportDivergence?: boolean;
|
|
48
57
|
proof?: TtscGenerationProof.Transaction;
|
|
49
58
|
}): "serve" | "retry" | "capture" {
|
|
50
59
|
if (
|
|
60
|
+
environmentInputMismatch(
|
|
61
|
+
props.cached.result.type === "exception"
|
|
62
|
+
? undefined
|
|
63
|
+
: props.cached.result.environmentInputs,
|
|
64
|
+
props.environment,
|
|
65
|
+
) === undefined &&
|
|
51
66
|
!isVolatileFile(envelopeDerivation(props.cached), {
|
|
52
67
|
file: props.file,
|
|
53
68
|
projectRoot: props.cached.projectRoot,
|
|
@@ -367,7 +367,11 @@ export async function captureTransformGeneration(props: {
|
|
|
367
367
|
props.session,
|
|
368
368
|
sharedCompileIdentity({ ...props, projectRoot }),
|
|
369
369
|
state,
|
|
370
|
-
{
|
|
370
|
+
{
|
|
371
|
+
adopt: true,
|
|
372
|
+
environment: compilerEnvironment,
|
|
373
|
+
rejectedPublication: props.rejected,
|
|
374
|
+
},
|
|
371
375
|
)
|
|
372
376
|
: undefined;
|
|
373
377
|
if (claim?.kind === "compile") {
|
|
@@ -799,9 +803,12 @@ export async function captureTransformGeneration(props: {
|
|
|
799
803
|
const graphFailures = compilerGraphInputProofFailures(cached);
|
|
800
804
|
mergeGenerationProofFailures(failures, graphFailures);
|
|
801
805
|
mergeGenerationProofFailures(failures, externalInputSnapshot.failures);
|
|
806
|
+
// Recorded environment reads must hold under the environment this worker
|
|
807
|
+
// compiles under; a publication recorded under another value is refuted.
|
|
802
808
|
const universalInputCapture = captureUniversalHostInputValidation(
|
|
803
809
|
cached,
|
|
804
810
|
props.currentFile,
|
|
811
|
+
compilerEnvironment,
|
|
805
812
|
);
|
|
806
813
|
restrictNotificationCoverageToProvenInputs(
|
|
807
814
|
hostInputTracker,
|
|
@@ -3,6 +3,8 @@ import fs from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
5
|
import { isZombieProcess } from "../utils/isZombieProcess";
|
|
6
|
+
import { environmentInputMismatch } from "../validation/environmentInputMismatch";
|
|
7
|
+
import { isEnvironmentInputs } from "../validation/isEnvironmentInputs";
|
|
6
8
|
import type { TtscSharedCompileClaim } from "./TtscSharedCompileClaim";
|
|
7
9
|
import type { TtscSharedCompilePublication } from "./TtscSharedCompilePublication";
|
|
8
10
|
|
|
@@ -66,6 +68,12 @@ const KEPT_STORE_BYTES = 256 * 1024 * 1024;
|
|
|
66
68
|
* for independent adoption proof. The digest is computed from the already read
|
|
67
69
|
* UTF-8 publication, without another filesystem query.
|
|
68
70
|
*
|
|
71
|
+
* Neither key names the environment variables the plugins read: only the
|
|
72
|
+
* compile discovers them. A publication is therefore adoptable only while each
|
|
73
|
+
* variable its envelope recorded has the recorded value, or stays unset, in the
|
|
74
|
+
* adopter's `environment`. An ineligible publication is treated like a rejected
|
|
75
|
+
* one: the worker takes the lock and its compile replaces it.
|
|
76
|
+
*
|
|
69
77
|
* Its place in the adapter's invalidation model, and the units beside it, are
|
|
70
78
|
* mapped in the maintainer page
|
|
71
79
|
* `website/src/content/docs/development/reference/unplugin-invalidation.mdx`.
|
|
@@ -74,6 +82,8 @@ const KEPT_STORE_BYTES = 256 * 1024 * 1024;
|
|
|
74
82
|
* @param identity Caller-provided hex configuration digest used in store names.
|
|
75
83
|
* @param state Caller-provided hex project-state digest used in store names.
|
|
76
84
|
* @param options.adopt Whether an existing publication may be adopted.
|
|
85
|
+
* @param options.environment The adopter's compiler environment, which every
|
|
86
|
+
* recorded environment read of an adopted publication must still match.
|
|
77
87
|
* @param options.rejectedPublication Digest of the exact previously refuted
|
|
78
88
|
* payload; a replacement still requires the caller's full proof.
|
|
79
89
|
* @evidence contracts/common.md#principled-implementation
|
|
@@ -142,7 +152,13 @@ export async function claimSharedCompile(
|
|
|
142
152
|
store: string,
|
|
143
153
|
identity: string,
|
|
144
154
|
state: string,
|
|
145
|
-
options:
|
|
155
|
+
options:
|
|
156
|
+
| { adopt: false }
|
|
157
|
+
| {
|
|
158
|
+
adopt: true;
|
|
159
|
+
environment: NodeJS.ProcessEnv;
|
|
160
|
+
rejectedPublication?: string;
|
|
161
|
+
},
|
|
146
162
|
): Promise<TtscSharedCompileClaim | undefined> {
|
|
147
163
|
const name = `${identity}-${state}`;
|
|
148
164
|
const publication = path.join(store, `${name}.json`);
|
|
@@ -154,7 +170,13 @@ export async function claimSharedCompile(
|
|
|
154
170
|
const published = await readPublication(publication);
|
|
155
171
|
if (
|
|
156
172
|
published !== undefined &&
|
|
157
|
-
published.fingerprint !== options.rejectedPublication
|
|
173
|
+
published.fingerprint !== options.rejectedPublication &&
|
|
174
|
+
environmentInputMismatch(
|
|
175
|
+
published.value.result.type === "exception"
|
|
176
|
+
? undefined
|
|
177
|
+
: published.value.result.environmentInputs,
|
|
178
|
+
options.environment,
|
|
179
|
+
) === undefined
|
|
158
180
|
) {
|
|
159
181
|
await markUsed(publication);
|
|
160
182
|
return {
|
|
@@ -173,7 +195,13 @@ export async function claimSharedCompile(
|
|
|
173
195
|
const published = await readPublication(publication);
|
|
174
196
|
if (
|
|
175
197
|
published !== undefined &&
|
|
176
|
-
published.fingerprint !== options.rejectedPublication
|
|
198
|
+
published.fingerprint !== options.rejectedPublication &&
|
|
199
|
+
environmentInputMismatch(
|
|
200
|
+
published.value.result.type === "exception"
|
|
201
|
+
? undefined
|
|
202
|
+
: published.value.result.environmentInputs,
|
|
203
|
+
options.environment,
|
|
204
|
+
) === undefined
|
|
177
205
|
) {
|
|
178
206
|
claim.release();
|
|
179
207
|
await markUsed(publication);
|
|
@@ -496,7 +524,7 @@ function isPublicationRecord(value: unknown): value is Record<string, unknown> {
|
|
|
496
524
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
497
525
|
}
|
|
498
526
|
|
|
499
|
-
/** Check
|
|
527
|
+
/** Check consumed envelope fields, including the complete environment witness. */
|
|
500
528
|
function isPublicationResult(value: unknown): boolean {
|
|
501
529
|
if (
|
|
502
530
|
!isPublicationRecord(value) ||
|
|
@@ -504,7 +532,9 @@ function isPublicationResult(value: unknown): boolean {
|
|
|
504
532
|
!isPublicationRecord(value.typescript) ||
|
|
505
533
|
!Object.values(value.typescript).every(
|
|
506
534
|
(source) => typeof source === "string",
|
|
507
|
-
)
|
|
535
|
+
) ||
|
|
536
|
+
(value.environmentInputs !== undefined &&
|
|
537
|
+
!isEnvironmentInputs(value.environmentInputs))
|
|
508
538
|
)
|
|
509
539
|
return false;
|
|
510
540
|
// Neither an explicit incomplete observer nor failed per-input authority can
|
|
@@ -1,61 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Capture one invocation's environment and explicit content-mapper permission.
|
|
3
|
-
*
|
|
4
|
-
* Omission preserves inherited arguments. An explicit boolean appends its
|
|
5
|
-
* upstream assignment after inherited arguments, keeping their order and cwd.
|
|
6
|
-
* Invalid transport fails instead of discarding inherited choices.
|
|
7
|
-
*
|
|
8
|
-
* @evidence contracts/common.md#principled-implementation A detached environment and ordered JSON argv preserve inherited choices; an explicit boolean assignment has final precedence.
|
|
9
|
-
* @evidence contracts/common.md#clear-and-simple-design Capture happens before cache selection; scratch routing derives a child copy afterward.
|
|
10
|
-
* @evidence contracts/common.md#prohibited-implementation-shortcuts No process global or compiler behavior is replaced.
|
|
11
|
-
* @evidence contracts/common.md#meaningful-documentation Native prose documents omission, precedence, cwd and invalid transport.
|
|
12
|
-
* @evidence contracts/portability.md#os-neutral-implementation Windows environment names follow their native case-insensitive rule; POSIX names remain exact. JSON preserves argv without shell syntax.
|
|
13
|
-
* @evidence contracts/performance.md#efficient-algorithms Copying visits environment keys; Windows normalization scans them once, and an explicit permission parses and serializes argument bytes once.
|
|
14
|
-
* @evidenceExclude contracts/performance.md#reuse-equivalent-work Every invocation observes current inherited values; cache owners compare its snapshot.
|
|
15
|
-
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The detached result transfers to its caller and acquires no handle or history.
|
|
16
|
-
*/
|
|
17
|
-
export function resolveCompilerEnvironment(
|
|
18
|
-
runExternalCode?: boolean,
|
|
19
|
-
inherited: NodeJS.ProcessEnv = process.env,
|
|
20
|
-
): NodeJS.ProcessEnv {
|
|
21
|
-
const env = { ...inherited };
|
|
22
|
-
if (process.platform === "win32") {
|
|
23
|
-
const selected = new Map<
|
|
24
|
-
string,
|
|
25
|
-
{ key: string; value: string | undefined }
|
|
26
|
-
>();
|
|
27
|
-
for (const key of Object.keys(env)) {
|
|
28
|
-
const name = key.toUpperCase();
|
|
29
|
-
if (name === "TTSC_TSGO_ARGS" || name === "TTSC_TSGO_ARGS_CWD") {
|
|
30
|
-
const prior = selected.get(name);
|
|
31
|
-
if (prior === undefined || key < prior.key)
|
|
32
|
-
selected.set(name, { key, value: env[key] });
|
|
33
|
-
delete env[key];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
for (const [name, value] of selected) env[name] = value.value;
|
|
37
|
-
}
|
|
38
|
-
// Own absent channels too: a later process.env edit must not become a new
|
|
39
|
-
// inherited argument between this cache lookup and the compiler spawn.
|
|
40
|
-
env.TTSC_TSGO_ARGS = env.TTSC_TSGO_ARGS;
|
|
41
|
-
env.TTSC_TSGO_ARGS_CWD = env.TTSC_TSGO_ARGS_CWD;
|
|
42
|
-
if (runExternalCode === undefined) return env;
|
|
43
|
-
if (typeof runExternalCode !== "boolean")
|
|
44
|
-
throw new TypeError("@ttsc/unplugin: runExternalCode must be a boolean");
|
|
45
|
-
// Go's environment transport trims Unicode White_Space, which excludes BOM.
|
|
46
|
-
const raw = env.TTSC_TSGO_ARGS?.replace(
|
|
47
|
-
/^\p{White_Space}+|\p{White_Space}+$/gu,
|
|
48
|
-
"",
|
|
49
|
-
);
|
|
50
|
-
const args: unknown = raw === undefined || raw === "" ? [] : JSON.parse(raw);
|
|
51
|
-
if (!Array.isArray(args) || args.some((value) => typeof value !== "string"))
|
|
52
|
-
throw new TypeError(
|
|
53
|
-
"@ttsc/unplugin: TTSC_TSGO_ARGS must be a JSON string array",
|
|
54
|
-
);
|
|
55
|
-
env.TTSC_TSGO_ARGS = JSON.stringify([
|
|
56
|
-
...args,
|
|
57
|
-
"--runExternalCode",
|
|
58
|
-
String(runExternalCode),
|
|
59
|
-
]);
|
|
60
|
-
return env;
|
|
61
|
-
}
|
|
1
|
+
export { resolveCompilerEnvironment } from "ttsc";
|
|
@@ -21,6 +21,7 @@ import { pluginSourceHolds } from "../inputs/pluginSourceHolds";
|
|
|
21
21
|
import { usesPreparedPluginBuildEnvironments } from "../inputs/preparePluginBuildEnvironments";
|
|
22
22
|
import { sameHostInputRealpath } from "../inputs/sameHostInputRealpath";
|
|
23
23
|
import type { TtscHostInputValidation } from "./TtscHostInputValidation";
|
|
24
|
+
import { environmentInputMismatch } from "./environmentInputMismatch";
|
|
24
25
|
import { matchesRecordedInput } from "./matchesRecordedInput";
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -36,7 +37,13 @@ import { matchesRecordedInput } from "./matchesRecordedInput";
|
|
|
36
37
|
* callers retain the original native observation API; result identity records
|
|
37
38
|
* async execution ownership even when preparation fails.
|
|
38
39
|
*
|
|
39
|
-
*
|
|
40
|
+
* Recorded environment reads are universal inputs too. Each must still have its
|
|
41
|
+
* recorded value, or stay unset, in `environment`, the compiler environment the
|
|
42
|
+
* generation is admitted under; an adopted publication recorded under another
|
|
43
|
+
* value fails here like a changed host input. They need no manifest entry:
|
|
44
|
+
* delivery compares them against its own snapshot.
|
|
45
|
+
*
|
|
46
|
+
* @evidence contracts/common.md#principled-implementation Evaluation-time content and physical-target witnesses and recorded environment values must agree with the generation snapshot before reuse; explicit producer observation unavailability remains distinct from changed, contradictory or unexplained missing proof, and every input is checked before classifying the attempt.
|
|
40
47
|
* @evidence contracts/common.md#clear-and-simple-design One admission operation builds the manifest; per-entry, grouped or exact-native absence and tree validators own its subsequent checks.
|
|
41
48
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts A missing publication witness declines narrow reuse instead of certifying an input from a convenient newer read.
|
|
42
49
|
* @evidence contracts/common.md#meaningful-documentation Native prose explains failed admission and successful generation attachment; inline comments justify readable-state, blocker and tree distinctions.
|
|
@@ -48,6 +55,8 @@ import { matchesRecordedInput } from "./matchesRecordedInput";
|
|
|
48
55
|
export function captureUniversalHostInputValidation(
|
|
49
56
|
cached: TtscCachedProjectTransform,
|
|
50
57
|
currentFile: string,
|
|
58
|
+
/** Compiler environment the generation is admitted under. */
|
|
59
|
+
environment: NodeJS.ProcessEnv,
|
|
51
60
|
): {
|
|
52
61
|
/** Classified reasons why universal input authority could not be admitted. */
|
|
53
62
|
failures: TtscGenerationProofFailures;
|
|
@@ -81,6 +90,17 @@ export function captureUniversalHostInputValidation(
|
|
|
81
90
|
detail: "observer-incomplete",
|
|
82
91
|
});
|
|
83
92
|
}
|
|
93
|
+
const environmentChanged = environmentInputMismatch(
|
|
94
|
+
result.type === "exception" ? undefined : result.environmentInputs,
|
|
95
|
+
environment,
|
|
96
|
+
);
|
|
97
|
+
if (environmentChanged !== undefined) {
|
|
98
|
+
recordGenerationProofFailure(failures, {
|
|
99
|
+
domain: "host",
|
|
100
|
+
kind: "environment-changed",
|
|
101
|
+
detail: environmentChanged,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
84
104
|
for (const [input, reason] of Object.entries(proofFailures ?? {})) {
|
|
85
105
|
recordGenerationProofFailure(failures, {
|
|
86
106
|
domain: "host",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name the first recorded environment read that no longer has its recorded
|
|
3
|
+
* value, or stays unset, in `environment`; `undefined` when every read holds.
|
|
4
|
+
*
|
|
5
|
+
* Native plugins record each variable they read through `ctx.Env` in the
|
|
6
|
+
* envelope's `environmentInputs`, which generations, publications and project
|
|
7
|
+
* records carry. Output is reusable only under an environment that would make
|
|
8
|
+
* every such read return what it returned, so callers compare against the
|
|
9
|
+
* compiler environment snapshot (`resolveCompilerEnvironment`) a recompile
|
|
10
|
+
* would run under. A cache key cannot carry these names: only the compile
|
|
11
|
+
* discovers them. An absent record, from an exception or from plugins that read
|
|
12
|
+
* no variable, always holds.
|
|
13
|
+
*
|
|
14
|
+
* @evidence contracts/common.md#principled-implementation Equality of each recorded value or absence with the supplied snapshot is exactly the condition under which the plugin's reads would repeat; unrecorded variables are not inputs and are ignored.
|
|
15
|
+
* @evidence contracts/common.md#clear-and-simple-design One predicate over the recorded map serves cached delivery, capture admission, shared-store adoption and persistent project records.
|
|
16
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts No variable list, prefix or consumer name is special-cased; the recorded names alone decide what is compared.
|
|
17
|
+
* @evidence contracts/common.md#meaningful-documentation Native paragraphs state the returned name, the comparison environment, why a key cannot replace this proof and the empty case.
|
|
18
|
+
* @evidence contracts/portability.md#os-neutral-implementation Windows variable names compare case-insensitively against the snapshot, choosing the lexically first spelling as ttsc's sidecar environment does; other platforms compare names exactly.
|
|
19
|
+
* @evidence contracts/performance.md#efficient-algorithms One lookup per recorded name; on Windows each lookup scans the snapshot's names, O(recorded × environment) with both small.
|
|
20
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work The predicate decides reuse for its caller and retains no verdict.
|
|
21
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources Entry and Windows key arrays are call-local; no environment, verdict or native handle is retained.
|
|
22
|
+
*/
|
|
23
|
+
export function environmentInputMismatch(
|
|
24
|
+
recorded: Readonly<Record<string, string | null>> | undefined,
|
|
25
|
+
environment: NodeJS.ProcessEnv,
|
|
26
|
+
): string | undefined {
|
|
27
|
+
for (const [name, value] of Object.entries(recorded ?? {})) {
|
|
28
|
+
let current: string | undefined;
|
|
29
|
+
if (process.platform === "win32") {
|
|
30
|
+
const identity = name.toUpperCase();
|
|
31
|
+
let selected: string | undefined;
|
|
32
|
+
for (const key of Object.keys(environment))
|
|
33
|
+
if (
|
|
34
|
+
key.toUpperCase() === identity &&
|
|
35
|
+
(selected === undefined || key < selected)
|
|
36
|
+
)
|
|
37
|
+
selected = key;
|
|
38
|
+
current = selected === undefined ? undefined : environment[selected];
|
|
39
|
+
} else if (Object.hasOwn(environment, name)) current = environment[name];
|
|
40
|
+
if ((current ?? null) !== value) return name;
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate a persisted plugin environment-read map before it can authorize
|
|
3
|
+
* reuse. Optional-field omission belongs to the reader; a present field must
|
|
4
|
+
* contain nonempty names and string values or null for recorded absence.
|
|
5
|
+
*
|
|
6
|
+
* @evidence contracts/common.md#principled-implementation The complete dictionary must satisfy the native envelope's name/value contract before equality can prove its reads. Arrays and primitive whole fields cannot become an empty dependency set.
|
|
7
|
+
* @evidence contracts/common.md#clear-and-simple-design Shared-publication and project-record readers use one predicate for their common environment witness while retaining ownership of their surrounding schemas.
|
|
8
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts Invalid records are rejected whole without dropping entries, coercing values or reconstructing an earlier observation from the current environment.
|
|
9
|
+
* @evidence contracts/common.md#meaningful-documentation Native prose distinguishes reader-owned omission from a present dictionary and explains null absence.
|
|
10
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation This checks decoded JSON names and values without reading native environment state or normalizing platform aliases.
|
|
11
|
+
* @evidence contracts/performance.md#efficient-algorithms Object.entries visits own dictionary entries once; the temporary array grows with the number of recorded reads, and no value bytes are copied or hashed.
|
|
12
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work Each reader validates its newly decoded record; this predicate retains no prior schema verdict.
|
|
13
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources The call borrows its value and retains no state, handle or history.
|
|
14
|
+
*/
|
|
15
|
+
export function isEnvironmentInputs(
|
|
16
|
+
value: unknown,
|
|
17
|
+
): value is Record<string, string | null> {
|
|
18
|
+
return (
|
|
19
|
+
typeof value === "object" &&
|
|
20
|
+
value !== null &&
|
|
21
|
+
!Array.isArray(value) &&
|
|
22
|
+
Object.entries(value).every(
|
|
23
|
+
([name, recorded]) =>
|
|
24
|
+
name.length !== 0 &&
|
|
25
|
+
(recorded === null || typeof recorded === "string"),
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -61,7 +61,9 @@ export interface TtscTransformHooks {
|
|
|
61
61
|
* once per delivered module and does not call `addWatchFile` for that module.
|
|
62
62
|
* `failed` marks a recovery batch: a failed compiler can omit inputs from its
|
|
63
63
|
* previous successful result, so replacing hosts should retain those
|
|
64
|
-
* spellings until the next successful delivery.
|
|
64
|
+
* spellings until the next successful delivery. The third argument carries
|
|
65
|
+
* the generation's environment reads for hosts that include non-file inputs
|
|
66
|
+
* in their persistent keys.
|
|
65
67
|
*/
|
|
66
68
|
addWatchFiles?: TtscAddWatchFiles;
|
|
67
69
|
|
|
@@ -163,9 +165,9 @@ export type TtscAddWatchFile = (
|
|
|
163
165
|
) => void;
|
|
164
166
|
|
|
165
167
|
/**
|
|
166
|
-
* Receive a readonly input batch
|
|
168
|
+
* Receive a readonly input batch and its recorded environment reads.
|
|
167
169
|
*
|
|
168
|
-
* @evidence contracts/common.md#principled-implementation The batch and optional failure flag express replacement versus recovery delivery
|
|
170
|
+
* @evidence contracts/common.md#principled-implementation The batch and optional failure flag express replacement versus recovery delivery; optional environment reads retain non-file inputs for persistent keys.
|
|
169
171
|
* @evidence contracts/common.md#clear-and-simple-design A single named function signature preserves the optional flag and original function-property assignability.
|
|
170
172
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts Recovery is an explicit host contract rather than successful evidence manufactured for a failed compile.
|
|
171
173
|
* @evidence contracts/common.md#meaningful-documentation Native prose and the owning member explain readonly batching and failed retention; separated tags follow documentation guidance.
|
|
@@ -183,6 +185,7 @@ export type TtscAddWatchFile = (
|
|
|
183
185
|
export type TtscAddWatchFiles = (
|
|
184
186
|
inputs: readonly TtscWatchInput[],
|
|
185
187
|
failed?: boolean,
|
|
188
|
+
environmentInputs?: Readonly<Record<string, string | null>>,
|
|
186
189
|
) => void;
|
|
187
190
|
|
|
188
191
|
/**
|
|
@@ -25,6 +25,8 @@ import type { TtscWatchInput } from "./TtscWatchInput";
|
|
|
25
25
|
* @param hooks The host's hooks; nothing is handed when it takes no inputs.
|
|
26
26
|
* @param inputs The inputs in the order they were derived.
|
|
27
27
|
* @param failed Whether they are a failed generation's, for a batching host.
|
|
28
|
+
* @param environmentInputs Generation-time environment reads for a batching
|
|
29
|
+
* host's persistent key, including recorded absences.
|
|
28
30
|
* @evidence contracts/common.md#principled-implementation Exact registration spellings are deduplicated with membership preferred over ordinary evidence and evidence over a recovery-only path; equal-ranked entries retain the first observation.
|
|
29
31
|
* @evidence contracts/common.md#clear-and-simple-design One precedence pass feeds either the batch callback or individual callbacks, leaving evidence derivation and bundler policy with their owners.
|
|
30
32
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts Contract-defined precedence keeps the strongest available input meaning without inventing facts, and batch preference follows the supported callback contract.
|
|
@@ -38,6 +40,7 @@ export function handWatchInputs(
|
|
|
38
40
|
hooks: TtscTransformHooks | undefined,
|
|
39
41
|
inputs: readonly TtscWatchInput[],
|
|
40
42
|
failed?: boolean,
|
|
43
|
+
environmentInputs?: Readonly<Record<string, string | null>>,
|
|
41
44
|
): void {
|
|
42
45
|
const addWatchFile = hooks?.addWatchFile;
|
|
43
46
|
const addWatchFiles = hooks?.addWatchFiles;
|
|
@@ -51,7 +54,8 @@ export function handWatchInputs(
|
|
|
51
54
|
}
|
|
52
55
|
const distinct = [...chosen.values()];
|
|
53
56
|
if (addWatchFiles !== undefined) {
|
|
54
|
-
addWatchFiles(distinct, failed);
|
|
57
|
+
if (environmentInputs === undefined) addWatchFiles(distinct, failed);
|
|
58
|
+
else addWatchFiles(distinct, failed, environmentInputs);
|
|
55
59
|
return;
|
|
56
60
|
}
|
|
57
61
|
for (const input of distinct) addWatchFile!(input.file, input.evidence);
|
|
@@ -226,11 +226,16 @@ function recordOf(
|
|
|
226
226
|
inputs: readonly TtscWatchInput[],
|
|
227
227
|
): TtscProjectRecord {
|
|
228
228
|
const dependencies = cached.externalDependencyInputs ?? [];
|
|
229
|
+
const environmentInputs =
|
|
230
|
+
cached.result.type === "exception"
|
|
231
|
+
? undefined
|
|
232
|
+
: cached.result.environmentInputs;
|
|
229
233
|
const record: TtscProjectRecord = {
|
|
230
234
|
...(cached.compilerArguments === undefined
|
|
231
235
|
? {}
|
|
232
236
|
: { compilerArguments: cached.compilerArguments }),
|
|
233
237
|
...(dependencies.length === 0 ? {} : { dependencies }),
|
|
238
|
+
...(environmentInputs === undefined ? {} : { environmentInputs }),
|
|
234
239
|
inputs: {},
|
|
235
240
|
membership:
|
|
236
241
|
cached.projectDirectories === undefined
|
|
@@ -98,5 +98,12 @@ export function notifyWatchInputs(
|
|
|
98
98
|
file: spell(input.file),
|
|
99
99
|
})))
|
|
100
100
|
inputs.push(entryToAppend);
|
|
101
|
-
handWatchInputs(
|
|
101
|
+
handWatchInputs(
|
|
102
|
+
hooks,
|
|
103
|
+
inputs,
|
|
104
|
+
undefined,
|
|
105
|
+
cached.result.type === "exception"
|
|
106
|
+
? undefined
|
|
107
|
+
: cached.result.environmentInputs,
|
|
108
|
+
);
|
|
102
109
|
}
|