@ttsc/metro 0.30.4 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -6
- package/lib/core/SnapshotReadOperations.d.ts +119 -0
- package/lib/core/SnapshotReadOperations.js +3 -0
- package/lib/core/SnapshotReadOperations.js.map +1 -0
- package/lib/core/SnapshotReadOperations.mjs +2 -0
- package/lib/core/SnapshotReadOperations.mjs.map +1 -0
- package/lib/core/TtscMetroOptions.d.ts +119 -0
- package/lib/core/TtscMetroOptions.js +3 -0
- package/lib/core/TtscMetroOptions.js.map +1 -0
- package/lib/core/TtscMetroOptions.mjs +2 -0
- package/lib/core/TtscMetroOptions.mjs.map +1 -0
- package/lib/core/TtscMetroProjectView.d.ts +64 -0
- package/lib/core/TtscMetroProjectView.js +3 -0
- package/lib/core/TtscMetroProjectView.js.map +1 -0
- package/lib/core/TtscMetroProjectView.mjs +2 -0
- package/lib/core/TtscMetroProjectView.mjs.map +1 -0
- package/lib/core/UpstreamTransformer.d.ts +127 -0
- package/lib/core/UpstreamTransformer.js +3 -0
- package/lib/core/UpstreamTransformer.js.map +1 -0
- package/lib/core/UpstreamTransformer.mjs +2 -0
- package/lib/core/UpstreamTransformer.mjs.map +1 -0
- package/lib/core/fingerprint.d.ts +442 -97
- package/lib/core/fingerprint.js +838 -83
- package/lib/core/fingerprint.js.map +1 -1
- package/lib/core/fingerprint.mjs +839 -84
- package/lib/core/fingerprint.mjs.map +1 -1
- package/lib/core/options.d.ts +81 -58
- package/lib/core/options.js +81 -4
- package/lib/core/options.js.map +1 -1
- package/lib/core/options.mjs +81 -4
- package/lib/core/options.mjs.map +1 -1
- package/lib/core/remapAstLocations.d.ts +76 -0
- package/lib/core/remapAstLocations.js +205 -0
- package/lib/core/remapAstLocations.js.map +1 -0
- package/lib/core/remapAstLocations.mjs +203 -0
- package/lib/core/remapAstLocations.mjs.map +1 -0
- package/lib/core/upstream.d.ts +97 -27
- package/lib/core/upstream.js +109 -8
- package/lib/core/upstream.js.map +1 -1
- package/lib/core/upstream.mjs +109 -9
- package/lib/core/upstream.mjs.map +1 -1
- package/lib/index.d.ts +50 -2
- package/lib/index.js +88 -24
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +89 -25
- package/lib/index.mjs.map +1 -1
- package/lib/transformer.d.ts +183 -6
- package/lib/transformer.js +209 -14
- package/lib/transformer.js.map +1 -1
- package/lib/transformer.mjs +211 -16
- package/lib/transformer.mjs.map +1 -1
- package/package.json +7 -18
- package/src/core/SnapshotReadOperations.ts +121 -0
- package/src/core/TtscMetroOptions.ts +127 -0
- package/src/core/TtscMetroProjectView.ts +74 -0
- package/src/core/UpstreamTransformer.ts +126 -0
- package/src/core/fingerprint.ts +987 -109
- package/src/core/options.ts +85 -62
- package/src/core/remapAstLocations.ts +219 -0
- package/src/core/upstream.ts +110 -26
- package/src/index.ts +99 -28
- package/src/transformer.ts +214 -17
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TtscWatchInput,
|
|
3
|
+
readProjectMembershipPolicy,
|
|
4
|
+
} from "@ttsc/unplugin/api";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One project, and the membership policy that describes it.
|
|
8
|
+
*
|
|
9
|
+
* The recorder's question is whether the project walk already covers an input,
|
|
10
|
+
* so it needs both the walk's roots and the policy that walk used, and it is
|
|
11
|
+
* wrong exactly when those two describe different projects. Passing them
|
|
12
|
+
* separately made that mismatch expressible — the policy for one project
|
|
13
|
+
* alongside the root of another — and passing the policy alone made it
|
|
14
|
+
* expressible in a quieter way still, since a recorder that resolved its own
|
|
15
|
+
* could describe a different program than the walk hashed. Both halves travel
|
|
16
|
+
* together so neither can be supplied without the other (samchon/ttsc#1316).
|
|
17
|
+
*
|
|
18
|
+
* @evidence contracts/common.md#principled-implementation
|
|
19
|
+
* A readonly structural interface carries the selected config, discovery
|
|
20
|
+
* observations, membership policy and walk roots as one view.
|
|
21
|
+
* resolveProjectView supplies that coherent view to the recorder instead of
|
|
22
|
+
* independently resolving its parts.
|
|
23
|
+
*
|
|
24
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
25
|
+
* The view groups config, policy, roots and discovery observations so a
|
|
26
|
+
* recorder receives one selected project rather than independently chosen
|
|
27
|
+
* pieces. Readonly members prevent replacement through this interface.
|
|
28
|
+
*
|
|
29
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
30
|
+
* The type does not structurally prohibit an inconsistent manually
|
|
31
|
+
* constructed value; it introduces no executable branches, consumer
|
|
32
|
+
* exceptions or foreign mutation.
|
|
33
|
+
*
|
|
34
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
35
|
+
* The native JSDoc explains each readonly field, one selected project and
|
|
36
|
+
* the reason policy and roots travel together. Checked against the
|
|
37
|
+
* documentation skill: separate paragraphs state the contract and why its
|
|
38
|
+
* nonobvious boundary matters; field comments retain their own useful
|
|
39
|
+
* facts.
|
|
40
|
+
*
|
|
41
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
42
|
+
* Declares a shape only; it holds no state, handle or buffer.
|
|
43
|
+
*
|
|
44
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
45
|
+
* Declares a shape only; there is no loop or processing in it.
|
|
46
|
+
*
|
|
47
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
48
|
+
* Declares a shape only; it computes nothing to share.
|
|
49
|
+
*
|
|
50
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation
|
|
51
|
+
* Carries absolute paths chosen by the project resolver; it compares or normalizes none.
|
|
52
|
+
*/
|
|
53
|
+
export interface TtscMetroProjectView {
|
|
54
|
+
/** The base directory both fingerprint sides agree on. */
|
|
55
|
+
readonly base: string;
|
|
56
|
+
|
|
57
|
+
/** Config candidates observed while selecting this transform's project. */
|
|
58
|
+
readonly discoveryInputs: readonly TtscWatchInput[];
|
|
59
|
+
|
|
60
|
+
/** The caller's explicit `project`, if any. */
|
|
61
|
+
readonly explicitProject: string | undefined;
|
|
62
|
+
|
|
63
|
+
/** The membership policy resolved for that project. */
|
|
64
|
+
readonly policy: ReturnType<typeof readProjectMembershipPolicy>;
|
|
65
|
+
|
|
66
|
+
/** The policy used by the routed static walk. */
|
|
67
|
+
readonly walkPolicy: ReturnType<typeof readProjectMembershipPolicy>;
|
|
68
|
+
|
|
69
|
+
/** Lexical roots whose fingerprint uses this project's policy. */
|
|
70
|
+
readonly roots: readonly string[];
|
|
71
|
+
|
|
72
|
+
/** The exact config selected for this project. */
|
|
73
|
+
readonly tsconfig: string;
|
|
74
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The subset of the Metro Babel-transformer contract this adapter relies on.
|
|
3
|
+
*
|
|
4
|
+
* Metro loads the module named by `transformer.babelTransformerPath` and calls
|
|
5
|
+
* its `transform` once per file, expecting a Babel AST back. `getCacheKey` is
|
|
6
|
+
* an optional export Metro folds into its transform-cache key; Metro invokes it
|
|
7
|
+
* with arguments (e.g. `{ projectRoot, enableBabelRCLookup }`), so it is typed
|
|
8
|
+
* variadic.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/common.md#principled-implementation
|
|
11
|
+
* This structural interface describes Metro's Babel-transformer extension:
|
|
12
|
+
* one transform operation and an optional variadic cache key. It does not
|
|
13
|
+
* implement Babel, install peers or alter their exports. Concrete modules
|
|
14
|
+
* supply the callbacks through normal Node loading.
|
|
15
|
+
*
|
|
16
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
17
|
+
* This peer-independent interface exposes only the transform and cache-key
|
|
18
|
+
* callbacks the adapter invokes, avoiding a dependency on Metro's full API.
|
|
19
|
+
*
|
|
20
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
21
|
+
* The representation follows the documented consumer contract; its fields do
|
|
22
|
+
* not introduce fixture-selected variants.
|
|
23
|
+
*
|
|
24
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
25
|
+
* The native JSDoc explains the awaited AST result and optional cache-key
|
|
26
|
+
* callback including forwarded arguments. Checked against the documentation
|
|
27
|
+
* skill: separate paragraphs state the contract and why its nonobvious
|
|
28
|
+
* boundary matters; field comments retain their own useful facts.
|
|
29
|
+
*
|
|
30
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
31
|
+
* Declares a shape only; it holds no state, handle or buffer.
|
|
32
|
+
*
|
|
33
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
34
|
+
* Declares a shape only; there is no loop or processing in it.
|
|
35
|
+
*
|
|
36
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
37
|
+
* Declares a shape only; it computes nothing to share.
|
|
38
|
+
*
|
|
39
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation
|
|
40
|
+
* Describes the callbacks of a Babel transformer; it names no path or process.
|
|
41
|
+
*/
|
|
42
|
+
export interface UpstreamTransformer {
|
|
43
|
+
/**
|
|
44
|
+
* Parse the supplied source and return the Babel AST Metro consumes.
|
|
45
|
+
*
|
|
46
|
+
* The adapter preserves Metro's filename, options and additional parameters;
|
|
47
|
+
* only `src` may hold successfully transformed TypeScript. The returned AST
|
|
48
|
+
* may have its locations remapped by the adapter before Metro receives it.
|
|
49
|
+
*
|
|
50
|
+
* @evidence contracts/common.md#principled-implementation
|
|
51
|
+
* This method signature represents the upstream transformer that Metro
|
|
52
|
+
* selected.
|
|
53
|
+
*
|
|
54
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
55
|
+
* One parameter record preserves Metro's extensible delivery shape and
|
|
56
|
+
* the result exposes only the AST this adapter needs.
|
|
57
|
+
*
|
|
58
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
59
|
+
* It accepts the original Metro parameter record, with src replaced only by
|
|
60
|
+
* the owning adapter after a successful compiler pass; the type declares no
|
|
61
|
+
* implementation or test-specific branch.
|
|
62
|
+
*
|
|
63
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
64
|
+
* The native JSDoc explains source, filename, extra Metro parameters and
|
|
65
|
+
* the awaited Babel AST result. Checked against the documentation skill:
|
|
66
|
+
* separate paragraphs state the contract and why its nonobvious boundary
|
|
67
|
+
* matters; field comments retain their own useful facts.
|
|
68
|
+
*
|
|
69
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
70
|
+
* Declares a shape only; it holds no state, handle or buffer.
|
|
71
|
+
*
|
|
72
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
73
|
+
* Declares a shape only; there is no loop or processing in it.
|
|
74
|
+
*
|
|
75
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
76
|
+
* Declares a shape only; it computes nothing to share.
|
|
77
|
+
*
|
|
78
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation
|
|
79
|
+
* The filename is Metro's own string, passed through to Babel unchanged.
|
|
80
|
+
*/
|
|
81
|
+
transform(params: {
|
|
82
|
+
src: string;
|
|
83
|
+
filename: string;
|
|
84
|
+
options: Record<string, unknown>;
|
|
85
|
+
[key: string]: unknown;
|
|
86
|
+
}): Promise<{ ast: object }>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Optional upstream contribution to Metro's static transformer key.
|
|
90
|
+
*
|
|
91
|
+
* Metro's arguments are forwarded unchanged. Absence contributes no upstream
|
|
92
|
+
* key; the adapter treats a throwing key as nonfatal and disables reuse,
|
|
93
|
+
* while transformer loading failures still fail actual transformation.
|
|
94
|
+
*
|
|
95
|
+
* @evidence contracts/common.md#principled-implementation
|
|
96
|
+
* The optional callback follows Metro's upstream transformer contract.
|
|
97
|
+
* Arguments are variadic because Metro supplies its own key options; absence
|
|
98
|
+
* is handled by the adapter.
|
|
99
|
+
*
|
|
100
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
101
|
+
* An optional variadic callback expresses the one upstream contribution
|
|
102
|
+
* without adapter-specific copies of Metro's cache-key options.
|
|
103
|
+
*
|
|
104
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
105
|
+
* This signature executes nothing and never replaces a foreign callback.
|
|
106
|
+
*
|
|
107
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
108
|
+
* The native JSDoc explains optional absence, forwarded Metro arguments and
|
|
109
|
+
* the upstream key contribution. Checked against the documentation skill:
|
|
110
|
+
* separate paragraphs state the contract and why its nonobvious boundary
|
|
111
|
+
* matters; field comments retain their own useful facts.
|
|
112
|
+
*
|
|
113
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
114
|
+
* Declares a shape only; it holds no state, handle or buffer.
|
|
115
|
+
*
|
|
116
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
117
|
+
* Declares a shape only; there is no loop or processing in it.
|
|
118
|
+
*
|
|
119
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
120
|
+
* Declares a shape only; it computes nothing to share.
|
|
121
|
+
*
|
|
122
|
+
* @evidenceExclude contracts/portability.md#os-neutral-implementation
|
|
123
|
+
* Metro's arguments are forwarded unchanged; no path is interpreted here.
|
|
124
|
+
*/
|
|
125
|
+
getCacheKey?: (...args: unknown[]) => string;
|
|
126
|
+
}
|