@ttsc/unplugin 0.28.3 → 0.28.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.
Files changed (46) hide show
  1. package/README.md +70 -8
  2. package/lib/api.js +3 -0
  3. package/lib/api.js.map +1 -1
  4. package/lib/api.mjs +1 -0
  5. package/lib/api.mjs.map +1 -1
  6. package/lib/core/index.d.cts +17 -6
  7. package/lib/core/index.d.mts +17 -6
  8. package/lib/core/index.d.ts +17 -6
  9. package/lib/core/index.js +117 -21
  10. package/lib/core/index.js.map +1 -1
  11. package/lib/core/index.mjs +115 -21
  12. package/lib/core/index.mjs.map +1 -1
  13. package/lib/core/transform.d.cts +93 -25
  14. package/lib/core/transform.d.mts +93 -25
  15. package/lib/core/transform.d.ts +93 -25
  16. package/lib/core/transform.js +803 -121
  17. package/lib/core/transform.js.map +1 -1
  18. package/lib/core/transform.mjs +804 -122
  19. package/lib/core/transform.mjs.map +1 -1
  20. package/lib/core/tsconfigPaths.d.cts +61 -0
  21. package/lib/core/tsconfigPaths.d.mts +61 -0
  22. package/lib/core/tsconfigPaths.d.ts +61 -0
  23. package/lib/core/tsconfigPaths.js +190 -7
  24. package/lib/core/tsconfigPaths.js.map +1 -1
  25. package/lib/core/tsconfigPaths.mjs +188 -8
  26. package/lib/core/tsconfigPaths.mjs.map +1 -1
  27. package/lib/next.d.cts +27 -10
  28. package/lib/next.d.mts +27 -10
  29. package/lib/next.d.ts +27 -10
  30. package/lib/next.js +229 -8
  31. package/lib/next.js.map +1 -1
  32. package/lib/next.mjs +229 -8
  33. package/lib/next.mjs.map +1 -1
  34. package/lib/turbopack.d.cts +5 -4
  35. package/lib/turbopack.d.mts +5 -4
  36. package/lib/turbopack.d.ts +5 -4
  37. package/lib/turbopack.js +13 -7
  38. package/lib/turbopack.js.map +1 -1
  39. package/lib/turbopack.mjs +14 -8
  40. package/lib/turbopack.mjs.map +1 -1
  41. package/package.json +3 -3
  42. package/src/core/index.ts +122 -21
  43. package/src/core/transform.ts +1073 -132
  44. package/src/core/tsconfigPaths.ts +254 -8
  45. package/src/next.ts +262 -10
  46. package/src/turbopack.ts +13 -9
@@ -3,6 +3,7 @@ import type { ITtscCompilerTransformation } from "ttsc";
3
3
  import { type FilesystemPathIdentityContext, type FilesystemPathIdentityOperations } from "ttsc/path-identity";
4
4
  import type { TransformResult } from "unplugin";
5
5
  import type { ResolvedTtscUnpluginOptions } from "./options";
6
+ import { type ITtscProjectMembershipPolicy } from "./tsconfigPaths";
6
7
  /**
7
8
  * The normalised transform result type that this module produces.
8
9
  *
@@ -11,22 +12,31 @@ import type { ResolvedTtscUnpluginOptions } from "./options";
11
12
  * `undefined`.
12
13
  */
13
14
  export type TtscTransformResult = Exclude<TransformResult, string | null | undefined>;
14
- /**
15
- * Normalised alias entry used when building the `paths` overlay for the
16
- * generated tsconfig. Derived from either a Vite array alias or a webpack/
17
- * Rspack object alias.
18
- */
19
- export interface TtscTransformAlias {
20
- /** The alias key (module specifier prefix). */
21
- find: string;
22
- /** Absolute or cwd-relative path that the alias points to. */
23
- replacement: string;
24
- }
25
- /** One directory's cheap project-membership identity at generation time. */
15
+ /** One directory's project-membership identity at generation time. */
26
16
  interface TtscProjectDirectorySnapshot {
27
17
  /** Absolute directory spelling used by the project walk. */
28
18
  path: string;
29
- /** Metadata signature that changes when its immediate membership changes. */
19
+ /**
20
+ * Whether this directory's subtree can hold a program input.
21
+ *
22
+ * A directory that cannot is still walked and still watched, so a source
23
+ * appearing in it later is noticed, but it takes no part in the membership
24
+ * comparison. That is what lets a bundler create its output directory and
25
+ * fill it without voiding a generation no compiler input touched, for any
26
+ * output directory rather than for fifteen names (samchon/ttsc#1307).
27
+ */
28
+ relevant: boolean;
29
+ /**
30
+ * Digest of the entries the walk itself considers: every immediate child the
31
+ * ignore list does not drop, with its kind.
32
+ *
33
+ * Deliberately not the directory's own metadata. A directory's stamp moves
34
+ * whenever _any_ entry is added or removed, including the ones the walk
35
+ * exists to ignore, so a bundler emitting into `dist/` — or merely creating
36
+ * that directory for the first time — moved the project root's stamp and
37
+ * voided a generation that no compiler input had touched. The ignore list
38
+ * only protects the generation if the membership proof honours it too.
39
+ */
30
40
  signature: string;
31
41
  }
32
42
  /** Generation-scoped directory watchers used to detect membership changes. */
@@ -117,6 +127,28 @@ export interface TtscCachedProjectTransform {
117
127
  * transform.
118
128
  */
119
129
  inputHashes: Record<string, string>;
130
+ /**
131
+ * What the resolved configuration admitted into this generation's program.
132
+ *
133
+ * Recorded per generation rather than read per validation because it is a
134
+ * property of the configuration the compile ran under, so a later delivery
135
+ * must judge membership by the same rule the compile did. A tsconfig edit
136
+ * that changes the rule also changes a declared input, which replaces the
137
+ * generation and its policy together.
138
+ */
139
+ membershipPolicy: ITtscProjectMembershipPolicy;
140
+ /**
141
+ * Files already reported as absent from the program, and the pass that
142
+ * reporting belongs to, so the notice is one per file per pass rather than
143
+ * one per delivery.
144
+ */
145
+ missingOutputReported?: Set<string>;
146
+ missingOutputEpoch?: number;
147
+ /**
148
+ * The project config this generation compiled, so a module the program does
149
+ * not contain can be told which program that was.
150
+ */
151
+ tsconfig: string;
120
152
  /**
121
153
  * Metadata signature of each {@link inputHashes} entry whose hash was proven
122
154
  * against an unracing read of the file on disk, in a tick the observed
@@ -179,10 +211,35 @@ export interface TtscCachedProjectTransform {
179
211
  projectRoot: string;
180
212
  /** Raw compiler output returned by {@link TtscCompiler.transform}. */
181
213
  result: ITtscCompilerTransformation;
214
+ /**
215
+ * The delivery epoch this generation is currently settled against, or
216
+ * `undefined` for a generation no epoch has proven.
217
+ *
218
+ * Set when the generation is compiled, and again whenever a later epoch's
219
+ * first delivery proves the whole generation still matches the filesystem.
220
+ * While it equals the cache's current epoch, each module's first delivery is
221
+ * settled by the supplied source alone, exactly as it was when every pass
222
+ * compiled its own generation (samchon/ttsc#1300).
223
+ */
224
+ deliveryEpoch?: number;
225
+ /**
226
+ * Whether this generation's non-error diagnostics have been surfaced at all,
227
+ * and the epoch they were last surfaced in.
228
+ *
229
+ * The diagnostics describe one compile of one program, so they belong to the
230
+ * generation rather than to a delivery; a pass that reuses a retained
231
+ * generation still surfaces them once, because a build's warnings are part of
232
+ * what that build reports (samchon/ttsc#1304). The two fields are separate so
233
+ * a persistent host, whose epoch is `undefined`, still reports the first
234
+ * time.
235
+ */
236
+ diagnosticsReported?: boolean;
237
+ diagnosticsEpoch?: number;
182
238
  /**
183
239
  * Files already delivered from this generation, keyed by filesystem identity.
184
- * Build-scoped caches use this to skip persistent validation only for a
185
- * module's first delivery inside the current build.
240
+ * A cache with a delivery epoch uses this to skip persistent validation only
241
+ * for a module's first delivery inside the current pass; the set is cleared
242
+ * whenever a new epoch's gate re-proves the generation.
186
243
  */
187
244
  servedFiles?: Set<string>;
188
245
  /**
@@ -251,20 +308,31 @@ export declare function normalizeHostInputName(name: string, caseSensitive: bool
251
308
  /** Create an empty persistent transform cache with isolated filesystem reads. */
252
309
  export declare function createTtscTransformCache(operations?: Partial<TtscTransformFilesystemOperations>): TtscTransformCache;
253
310
  /**
254
- * Start a host build, clearing its prior generation and enabling constant-time
255
- * first delivery for modules compiled during this build.
311
+ * Open a new delivery pass, enabling constant-time first delivery for every
312
+ * module this pass asks for.
313
+ *
314
+ * This deliberately retains the cached generation. The pass boundary is a
315
+ * statement about _deliveries_ — each module is requested at most once inside
316
+ * it — not about whether the compiled program is still correct, which the
317
+ * generation's own recorded snapshot answers and which
318
+ * {@link matchesCachedSource} proves once at the pass's first delivery. Clearing
319
+ * here instead made a host whose `buildStart` repeats recompile the whole
320
+ * project on every rebuild even when no compiler input had changed
321
+ * (samchon/ttsc#1300). Use {@link resetTtscTransformCache} to actually discard a
322
+ * generation and its watchers.
256
323
  *
257
- * Hosts without a guaranteed build-start callback use persistent validation
258
- * unless they have another immutable lifecycle. Bun runtime setup, for example,
324
+ * Hosts without a guaranteed pass boundary use persistent validation unless
325
+ * they have another immutable lifecycle. Bun runtime setup, for example,
259
326
  * defines one process-scoped module-loading session.
260
327
  */
261
328
  export declare function beginTtscTransformBuild(cache: TtscTransformCache): void;
262
329
  /**
263
- * Clear a cache and return it to persistent validation mode.
330
+ * Discard every generation, dispose its watchers, and return the cache to
331
+ * persistent validation mode.
264
332
  *
265
- * This is distinct from {@link beginTtscTransformBuild}: hosts such as Vite's
266
- * development server may invoke `buildStart` only once for a process that spans
267
- * many edits, so that callback cannot authorize build-scoped shortcuts.
333
+ * This is the unconditional lifecycle boundary, and it is distinct from
334
+ * {@link beginTtscTransformBuild}: a pass ending is not a reason to throw a
335
+ * proven compile away, while a session ending is.
268
336
  */
269
337
  export declare function resetTtscTransformCache(cache: TtscTransformCache): void;
270
338
  /**
@@ -402,7 +470,7 @@ export declare function createTransformResult(source: string, code: string): Tts
402
470
  * slash path. Exported so hosts without a per-build boundary (`@ttsc/metro`)
403
471
  * can fold the identical input universe into their own cache fingerprints.
404
472
  */
405
- export declare function collectProjectInputHashes(projectRoot: string, identities?: FilesystemPathIdentityContext, filesystem?: TtscTransformFilesystemOperations): Record<string, string>;
473
+ export declare function collectProjectInputHashes(projectRoot: string, identities?: FilesystemPathIdentityContext, filesystem?: TtscTransformFilesystemOperations, policy?: ITtscProjectMembershipPolicy): Record<string, string>;
406
474
  /**
407
475
  * Report whether an absolute `file` belongs to the project walk universe of
408
476
  * `root`: it lies under `root`, every component exists without traversing a
@@ -412,7 +480,7 @@ export declare function collectProjectInputHashes(projectRoot: string, identitie
412
480
  * Missing paths and files reached through symlinks or Windows junctions are
413
481
  * out-of-walk inputs that only the reference graph can prove relevant.
414
482
  */
415
- export declare function isProjectWalkPath(root: string, file: string, _identities?: FilesystemPathIdentityContext, filesystem?: TtscTransformFilesystemOperations): boolean;
483
+ export declare function isProjectWalkPath(root: string, file: string, _identities?: FilesystemPathIdentityContext, filesystem?: TtscTransformFilesystemOperations, policy?: ITtscProjectMembershipPolicy): boolean;
416
484
  /**
417
485
  * Hash a list of absolute out-of-walk input paths: content SHA-256 for a
418
486
  * readable file, a stable directory-kind digest for a directory candidate, and