@ttsc/unplugin 0.37.1 → 0.38.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/README.md +11 -0
- package/lib/bun-register.d.cts +1 -0
- package/lib/bun-register.d.mts +1 -0
- package/lib/bun-register.d.ts +1 -0
- package/lib/bun-register.js.map +1 -1
- package/lib/bun-register.mjs.map +1 -1
- package/lib/bun.d.cts +1 -0
- package/lib/bun.d.mts +1 -0
- package/lib/bun.d.ts +1 -0
- package/lib/core/bun/BunRegistrationState.d.cts +6 -3
- package/lib/core/bun/BunRegistrationState.d.mts +6 -3
- package/lib/core/bun/BunRegistrationState.d.ts +6 -3
- package/lib/core/bun/TtscBunLoaderOptions.d.cts +68 -0
- package/lib/core/bun/TtscBunLoaderOptions.d.mts +68 -0
- package/lib/core/bun/TtscBunLoaderOptions.d.ts +68 -0
- package/lib/core/bun/TtscBunOptions.d.cts +2 -2
- package/lib/core/bun/TtscBunOptions.d.mts +2 -2
- package/lib/core/bun/TtscBunOptions.d.ts +2 -2
- package/lib/core/bun/bun.d.cts +28 -14
- package/lib/core/bun/bun.d.mts +28 -14
- package/lib/core/bun/bun.d.ts +28 -14
- package/lib/core/bun/bun.js +51 -18
- package/lib/core/bun/bun.js.map +1 -1
- package/lib/core/bun/bun.mjs +51 -18
- package/lib/core/bun/bun.mjs.map +1 -1
- package/lib/core/bun/createBunFilter.d.cts +42 -0
- package/lib/core/bun/createBunFilter.d.mts +42 -0
- package/lib/core/bun/createBunFilter.d.ts +42 -0
- package/lib/core/bun/createBunFilter.js +67 -0
- package/lib/core/bun/createBunFilter.js.map +1 -0
- package/lib/core/bun/createBunFilter.mjs +65 -0
- package/lib/core/bun/createBunFilter.mjs.map +1 -0
- package/lib/core/bun/register.d.cts +16 -7
- package/lib/core/bun/register.d.mts +16 -7
- package/lib/core/bun/register.d.ts +16 -7
- package/lib/core/bun/register.js +18 -5
- package/lib/core/bun/register.js.map +1 -1
- package/lib/core/bun/register.mjs +18 -5
- package/lib/core/bun/register.mjs.map +1 -1
- package/package.json +3 -3
- package/src/bun-register.ts +1 -0
- package/src/bun.ts +1 -0
- package/src/core/bun/BunRegistrationState.ts +6 -3
- package/src/core/bun/TtscBunLoaderOptions.ts +69 -0
- package/src/core/bun/TtscBunOptions.ts +3 -3
- package/src/core/bun/bun.ts +57 -21
- package/src/core/bun/createBunFilter.ts +64 -0
- package/src/core/bun/ensureRegistered.ts +2 -2
- package/src/core/bun/register.ts +22 -9
package/lib/core/bun/bun.js
CHANGED
|
@@ -10,6 +10,7 @@ var createTtscTransformCache = require('../transform/cache/createTtscTransformCa
|
|
|
10
10
|
var resetTtscTransformCache = require('../transform/cache/resetTtscTransformCache.js');
|
|
11
11
|
var transformTtsc = require('../transform/transformTtsc.js');
|
|
12
12
|
var inlineSourceMap = require('../transform/utils/inlineSourceMap.js');
|
|
13
|
+
var createBunFilter = require('./createBunFilter.js');
|
|
13
14
|
|
|
14
15
|
/** Resolve {@link TtscBunOptions} to a plain options object (or `undefined`). */
|
|
15
16
|
function resolveBunOptions(options) {
|
|
@@ -38,32 +39,46 @@ function resolveBunOptions(options) {
|
|
|
38
39
|
* session, like Bun's own module cache; restart the process after changing
|
|
39
40
|
* compiler inputs.
|
|
40
41
|
*
|
|
42
|
+
* The `filter` option narrows the project modules the plugin transforms. A
|
|
43
|
+
* module it does not select is left to Bun like an excluded file, so
|
|
44
|
+
* `Bun.build` gets `undefined` and the runtime gets the original source and
|
|
45
|
+
* loader. The options, and with them the filter, are resolved by the first
|
|
46
|
+
* TypeScript module outside `node_modules`, so that module locks the runtime
|
|
47
|
+
* options whether or not the filter selects it.
|
|
48
|
+
*
|
|
41
49
|
* @evidence contracts/common.md#principled-implementation
|
|
42
50
|
* Host hook presence distinguishes a runtime session from bundler builds.
|
|
43
|
-
* Disk inputs enter the shared project transform;
|
|
44
|
-
*
|
|
51
|
+
* Disk inputs the filter selects enter the shared project transform;
|
|
52
|
+
* in-memory bundler entries and unselected modules remain Bun-owned, and
|
|
53
|
+
* runtime responses always retain the TypeScript parser.
|
|
45
54
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
46
55
|
* Setup owns hooks and one cache; source inclusion, option normalization,
|
|
47
|
-
* compilation and source-map encoding remain delegated
|
|
56
|
+
* filter compilation, transformation and source-map encoding remain delegated
|
|
57
|
+
* to their shared owners.
|
|
48
58
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
49
|
-
* The runtime's original-source response implements Bun's required
|
|
50
|
-
* onLoad response. Hook absence and files
|
|
51
|
-
* not overlapping-loader patches or
|
|
59
|
+
* The runtime's original-source response implements Bun's required object
|
|
60
|
+
* onLoad response for every module left to Bun. Hook absence and files
|
|
61
|
+
* ownership are real host differences, not overlapping-loader patches or
|
|
62
|
+
* special treatment of fixture paths.
|
|
52
63
|
* @evidence contracts/common.md#meaningful-documentation
|
|
53
64
|
* Native paragraphs explain bundler/runtime responses, in-memory ownership,
|
|
54
|
-
* parser selection and process-session limits, following
|
|
65
|
+
* filter selection, parser selection and process-session limits, following
|
|
66
|
+
* documentation guidance.
|
|
55
67
|
* @evidence contracts/portability.md#os-neutral-implementation
|
|
56
68
|
* Node reads native delivered paths. Bun's in-memory key comparison separately
|
|
57
69
|
* models separator/drive-letter normalization on Windows while preserving
|
|
58
70
|
* component case and relative spelling rather than treating keys as disk paths.
|
|
59
71
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
60
72
|
* A Set indexes F in-memory keys once at setup; a delivery performs a path-length
|
|
61
|
-
* lookup and reads S source bytes only for its disk input.
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
73
|
+
* lookup and reads S source bytes only for its disk input. A module the
|
|
74
|
+
* filter skips costs one predicate call and a source read at runtime, and no
|
|
75
|
+
* transform. First project loads also normalize the option overlay.
|
|
76
|
+
* Delegated transform work includes cache identity/validation,
|
|
77
|
+
* input/directory/byte proofs, misses' native compile and source-map encoding;
|
|
78
|
+
* source-file length alone does not bound it.
|
|
65
79
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
66
|
-
* The first
|
|
80
|
+
* The first project TypeScript load resolves options and compiles the filter
|
|
81
|
+
* once, and every later load reuses both. One cache shares a validated
|
|
67
82
|
* project generation across deliveries; bundler start/end boundaries reset
|
|
68
83
|
* delivery proof, while a runtime retains its immutable module-load session.
|
|
69
84
|
* Coherent local output with unavailable observation shares first deliveries
|
|
@@ -72,8 +87,8 @@ function resolveBunOptions(options) {
|
|
|
72
87
|
* Setup snapshots the in-memory key population; changing host files/options
|
|
73
88
|
* is not authorized merely by an unchanged path or previously quiet callback.
|
|
74
89
|
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
75
|
-
* Setup owns the F-key matcher, resolved options and project cache.
|
|
76
|
-
* end withdraws cached generations; it does not promise cancellation of an
|
|
90
|
+
* Setup owns the F-key matcher, resolved options, compiled filter and project cache.
|
|
91
|
+
* Bundler end withdraws cached generations; it does not promise cancellation of an
|
|
77
92
|
* already running native compile, and the host still owns setup closures.
|
|
78
93
|
* Runtime retention is intended for the process session because this branch
|
|
79
94
|
* has no teardown hook. Key/option/project bytes have no fixed package-wide cap.
|
|
@@ -85,9 +100,19 @@ function bun(options) {
|
|
|
85
100
|
// Resolve options lazily on the first transformable TypeScript load.
|
|
86
101
|
// Runtime registration may replace its pending configuration at any time
|
|
87
102
|
// before then; the provider form must observe that last update without
|
|
88
|
-
// installing a second shadowing loader.
|
|
89
|
-
|
|
90
|
-
|
|
103
|
+
// installing a second shadowing loader. The filter belongs to those
|
|
104
|
+
// options, so it is compiled in the same step and never read earlier.
|
|
105
|
+
let session;
|
|
106
|
+
const getSession = () => {
|
|
107
|
+
if (session === undefined) {
|
|
108
|
+
const supplied = resolveBunOptions(options);
|
|
109
|
+
session = {
|
|
110
|
+
options: resolveOptions.resolveOptions(supplied),
|
|
111
|
+
accepts: createBunFilter.createBunFilter(supplied?.filter),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return session;
|
|
115
|
+
};
|
|
91
116
|
const cache = createTtscTransformCache.createTtscTransformCache();
|
|
92
117
|
const runtime = build.onStart === undefined;
|
|
93
118
|
const ownsInMemoryFile = createBunInMemoryFileMatcher(build);
|
|
@@ -116,7 +141,15 @@ function bun(options) {
|
|
|
116
141
|
};
|
|
117
142
|
}
|
|
118
143
|
const loader = bunLoaderFor(args.path);
|
|
119
|
-
const transformOptions =
|
|
144
|
+
const { options: transformOptions, accepts } = getSession();
|
|
145
|
+
if (accepts !== undefined && !accepts(args.path)) {
|
|
146
|
+
if (!runtime)
|
|
147
|
+
return undefined;
|
|
148
|
+
return {
|
|
149
|
+
contents: await fs.readFile(args.path, "utf8"),
|
|
150
|
+
loader: bunLoaderFor(args.path),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
120
153
|
const source = await fs.readFile(args.path, "utf8");
|
|
121
154
|
// Bun has no dependency subscription API or reusable build result
|
|
122
155
|
// cache. Builds are one-shot; runtime registration owns one immutable
|
package/lib/core/bun/bun.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.js","sources":["../../../src/core/bun/bun.ts"],"sourcesContent":[null],"names":["resolveOptions","createTtscTransformCache","beginTtscTransformBuild","resetTtscTransformCache","bunTypeScriptTransformSourcePattern","isTransformTarget","transformTtsc","inlineSourceMap","typescriptTransformBunLoader"],"mappings":"
|
|
1
|
+
{"version":3,"file":"bun.js","sources":["../../../src/core/bun/bun.ts"],"sourcesContent":[null],"names":["resolveOptions","createBunFilter","createTtscTransformCache","beginTtscTransformBuild","resetTtscTransformCache","bunTypeScriptTransformSourcePattern","isTransformTarget","transformTtsc","inlineSourceMap","typescriptTransformBunLoader"],"mappings":";;;;;;;;;;;;;;AAkBA;AACA,SAAS,iBAAiB,CACxB,OAAwB,EAAA;AAExB,IAAA,OAAO,OAAO,OAAO,KAAK,UAAU,GAAG,OAAO,EAAE,GAAG,OAAO;AAC5D;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAC3D,YAAA,CAAC,CACF;QACH,CAAC;KACF;AACH;AAEA;;;;AAIG;AACH,SAAS,YAAY,CAAC,QAAgB,EAAA;AACpC,IAAA,MAAM,MAAM,GAAGC,yDAA4B,CAAC,QAAQ,CAAC;AACrD,IAAA,IAAI,MAAM,KAAK,SAAS,EAAE;AACxB,QAAA,MAAM,IAAI,KAAK,CAAC,6CAA6C,QAAQ,CAAA,CAAE,CAAC;IAC1E;AACA,IAAA,OAAO,MAAM;AACf;AAEA;;;;;;;AAOG;AACH,SAAS,4BAA4B,CACnC,KAAmB,EAAA;AAEnB,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK;IACjC,IAAI,KAAK,KAAK,SAAS;AAAE,QAAA,OAAO,MAAM,KAAK;AAC3C,IAAA,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AACtE,IAAA,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAC3D;AAEA;;;;;;AAMG;AACH,SAAS,kBAAkB,CAAC,IAAY,EAAA;AACtC,IAAA,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;AAAE,QAAA,OAAO,IAAI;AAC7C,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,KAAK,EAAE,GAAG;AAClB,SAAA,OAAO,CACN,YAAY,EACZ,CAAC,MAAM,EAAE,KAAa,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAA,CAAA,CAAG,CACrD;AACL;;;;"}
|
package/lib/core/bun/bun.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { createTtscTransformCache } from '../transform/cache/createTtscTransform
|
|
|
8
8
|
import { resetTtscTransformCache } from '../transform/cache/resetTtscTransformCache.mjs';
|
|
9
9
|
import { transformTtsc } from '../transform/transformTtsc.mjs';
|
|
10
10
|
import { inlineSourceMap } from '../transform/utils/inlineSourceMap.mjs';
|
|
11
|
+
import { createBunFilter } from './createBunFilter.mjs';
|
|
11
12
|
|
|
12
13
|
/** Resolve {@link TtscBunOptions} to a plain options object (or `undefined`). */
|
|
13
14
|
function resolveBunOptions(options) {
|
|
@@ -36,32 +37,46 @@ function resolveBunOptions(options) {
|
|
|
36
37
|
* session, like Bun's own module cache; restart the process after changing
|
|
37
38
|
* compiler inputs.
|
|
38
39
|
*
|
|
40
|
+
* The `filter` option narrows the project modules the plugin transforms. A
|
|
41
|
+
* module it does not select is left to Bun like an excluded file, so
|
|
42
|
+
* `Bun.build` gets `undefined` and the runtime gets the original source and
|
|
43
|
+
* loader. The options, and with them the filter, are resolved by the first
|
|
44
|
+
* TypeScript module outside `node_modules`, so that module locks the runtime
|
|
45
|
+
* options whether or not the filter selects it.
|
|
46
|
+
*
|
|
39
47
|
* @evidence contracts/common.md#principled-implementation
|
|
40
48
|
* Host hook presence distinguishes a runtime session from bundler builds.
|
|
41
|
-
* Disk inputs enter the shared project transform;
|
|
42
|
-
*
|
|
49
|
+
* Disk inputs the filter selects enter the shared project transform;
|
|
50
|
+
* in-memory bundler entries and unselected modules remain Bun-owned, and
|
|
51
|
+
* runtime responses always retain the TypeScript parser.
|
|
43
52
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
44
53
|
* Setup owns hooks and one cache; source inclusion, option normalization,
|
|
45
|
-
* compilation and source-map encoding remain delegated
|
|
54
|
+
* filter compilation, transformation and source-map encoding remain delegated
|
|
55
|
+
* to their shared owners.
|
|
46
56
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
47
|
-
* The runtime's original-source response implements Bun's required
|
|
48
|
-
* onLoad response. Hook absence and files
|
|
49
|
-
* not overlapping-loader patches or
|
|
57
|
+
* The runtime's original-source response implements Bun's required object
|
|
58
|
+
* onLoad response for every module left to Bun. Hook absence and files
|
|
59
|
+
* ownership are real host differences, not overlapping-loader patches or
|
|
60
|
+
* special treatment of fixture paths.
|
|
50
61
|
* @evidence contracts/common.md#meaningful-documentation
|
|
51
62
|
* Native paragraphs explain bundler/runtime responses, in-memory ownership,
|
|
52
|
-
* parser selection and process-session limits, following
|
|
63
|
+
* filter selection, parser selection and process-session limits, following
|
|
64
|
+
* documentation guidance.
|
|
53
65
|
* @evidence contracts/portability.md#os-neutral-implementation
|
|
54
66
|
* Node reads native delivered paths. Bun's in-memory key comparison separately
|
|
55
67
|
* models separator/drive-letter normalization on Windows while preserving
|
|
56
68
|
* component case and relative spelling rather than treating keys as disk paths.
|
|
57
69
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
58
70
|
* A Set indexes F in-memory keys once at setup; a delivery performs a path-length
|
|
59
|
-
* lookup and reads S source bytes only for its disk input.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
71
|
+
* lookup and reads S source bytes only for its disk input. A module the
|
|
72
|
+
* filter skips costs one predicate call and a source read at runtime, and no
|
|
73
|
+
* transform. First project loads also normalize the option overlay.
|
|
74
|
+
* Delegated transform work includes cache identity/validation,
|
|
75
|
+
* input/directory/byte proofs, misses' native compile and source-map encoding;
|
|
76
|
+
* source-file length alone does not bound it.
|
|
63
77
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
64
|
-
* The first
|
|
78
|
+
* The first project TypeScript load resolves options and compiles the filter
|
|
79
|
+
* once, and every later load reuses both. One cache shares a validated
|
|
65
80
|
* project generation across deliveries; bundler start/end boundaries reset
|
|
66
81
|
* delivery proof, while a runtime retains its immutable module-load session.
|
|
67
82
|
* Coherent local output with unavailable observation shares first deliveries
|
|
@@ -70,8 +85,8 @@ function resolveBunOptions(options) {
|
|
|
70
85
|
* Setup snapshots the in-memory key population; changing host files/options
|
|
71
86
|
* is not authorized merely by an unchanged path or previously quiet callback.
|
|
72
87
|
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
73
|
-
* Setup owns the F-key matcher, resolved options and project cache.
|
|
74
|
-
* end withdraws cached generations; it does not promise cancellation of an
|
|
88
|
+
* Setup owns the F-key matcher, resolved options, compiled filter and project cache.
|
|
89
|
+
* Bundler end withdraws cached generations; it does not promise cancellation of an
|
|
75
90
|
* already running native compile, and the host still owns setup closures.
|
|
76
91
|
* Runtime retention is intended for the process session because this branch
|
|
77
92
|
* has no teardown hook. Key/option/project bytes have no fixed package-wide cap.
|
|
@@ -83,9 +98,19 @@ function bun(options) {
|
|
|
83
98
|
// Resolve options lazily on the first transformable TypeScript load.
|
|
84
99
|
// Runtime registration may replace its pending configuration at any time
|
|
85
100
|
// before then; the provider form must observe that last update without
|
|
86
|
-
// installing a second shadowing loader.
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
// installing a second shadowing loader. The filter belongs to those
|
|
102
|
+
// options, so it is compiled in the same step and never read earlier.
|
|
103
|
+
let session;
|
|
104
|
+
const getSession = () => {
|
|
105
|
+
if (session === undefined) {
|
|
106
|
+
const supplied = resolveBunOptions(options);
|
|
107
|
+
session = {
|
|
108
|
+
options: resolveOptions(supplied),
|
|
109
|
+
accepts: createBunFilter(supplied?.filter),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return session;
|
|
113
|
+
};
|
|
89
114
|
const cache = createTtscTransformCache();
|
|
90
115
|
const runtime = build.onStart === undefined;
|
|
91
116
|
const ownsInMemoryFile = createBunInMemoryFileMatcher(build);
|
|
@@ -114,7 +139,15 @@ function bun(options) {
|
|
|
114
139
|
};
|
|
115
140
|
}
|
|
116
141
|
const loader = bunLoaderFor(args.path);
|
|
117
|
-
const transformOptions =
|
|
142
|
+
const { options: transformOptions, accepts } = getSession();
|
|
143
|
+
if (accepts !== undefined && !accepts(args.path)) {
|
|
144
|
+
if (!runtime)
|
|
145
|
+
return undefined;
|
|
146
|
+
return {
|
|
147
|
+
contents: await fs.readFile(args.path, "utf8"),
|
|
148
|
+
loader: bunLoaderFor(args.path),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
118
151
|
const source = await fs.readFile(args.path, "utf8");
|
|
119
152
|
// Bun has no dependency subscription API or reusable build result
|
|
120
153
|
// cache. Builds are one-shot; runtime registration owns one immutable
|
package/lib/core/bun/bun.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun.mjs","sources":["../../../src/core/bun/bun.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bun.mjs","sources":["../../../src/core/bun/bun.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;AAkBA;AACA,SAAS,iBAAiB,CACxB,OAAwB,EAAA;AAExB,IAAA,OAAO,OAAO,OAAO,KAAK,UAAU,GAAG,OAAO,EAAE,GAAG,OAAO;AAC5D;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4EG;AACG,SAAU,GAAG,CAAC,OAAwB,EAAA;IAC1C,OAAO;AACL,QAAA,IAAI,EAAE,eAAe;AACrB,QAAA,KAAK,CAAC,KAAK,EAAA;;;;;;AAMT,YAAA,IAAI,OAKS;YACb,MAAM,UAAU,GAAG,MAAK;AACtB,gBAAA,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,oBAAA,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC;AAC3C,oBAAA,OAAO,GAAG;AACR,wBAAA,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC;AACjC,wBAAA,OAAO,EAAE,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC;qBAC3C;gBACH;AACA,gBAAA,OAAO,OAAO;AAChB,YAAA,CAAC;AACD,YAAA,MAAM,KAAK,GAAG,wBAAwB,EAAE;AACxC,YAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,KAAK,SAAS;AAC3C,YAAA,MAAM,gBAAgB,GAAG,4BAA4B,CAAC,KAAK,CAAC;;;;;;;;YAQ5D,uBAAuB,CAAC,KAAK,CAAC;AAC9B,YAAA,KAAK,CA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AAO,CAAC,QAAQ,KAAK,OAAO;AAAE,QAAA,OAAO,IAAI;AAC7C,IAAA,OAAO;AACJ,SAAA,OAAO,CAAC,KAAK,EAAE,GAAG;AAClB,SAAA,OAAO,CACN,YAAY,EACZ,CAAC,MAAM,EAAE,KAAa,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAA,CAAA,CAAG,CACrD;AACL;;;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the `filter` loader option into one predicate over delivered module
|
|
3
|
+
* paths, or `undefined` when no module is skipped.
|
|
4
|
+
*
|
|
5
|
+
* The predicate tests a copy of each pattern, so a global or sticky pattern
|
|
6
|
+
* carries no match position from one module to the next and the caller's
|
|
7
|
+
* pattern is never changed. It tests the path with `\` written as `/` and
|
|
8
|
+
* leaves the delivered path itself untouched for reading and compiling.
|
|
9
|
+
*
|
|
10
|
+
* @throws TypeError when an entry of `filter` is not a RegExp.
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation
|
|
12
|
+
* `RegExp.prototype.test` on a global or sticky pattern reads and writes
|
|
13
|
+
* `lastIndex`, so a copy reset to zero before each test makes every answer
|
|
14
|
+
* depend on the path alone; `new RegExp(pattern)` keeps source and flags.
|
|
15
|
+
* An empty list names no restriction.
|
|
16
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
17
|
+
* Validation, ownership of the copies and matching concern the same patterns,
|
|
18
|
+
* so one function answers the loader's one question. The loader keeps
|
|
19
|
+
* the decision of what a skipped module returns.
|
|
20
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
21
|
+
* The `lastIndex` reset follows from the language's stateful `test`,
|
|
22
|
+
* not from a consumer; no RegExp prototype or caller pattern is modified.
|
|
23
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
24
|
+
* The comment states pattern ownership, the tested spelling, the `undefined`
|
|
25
|
+
* result and the thrown failure, which the signature does not show.
|
|
26
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
27
|
+
* Only the string under test is converted, with the repository's separator
|
|
28
|
+
* conversion. The native path is never rewritten and no filesystem identity
|
|
29
|
+
* or case policy is implied. A POSIX file name containing a backslash
|
|
30
|
+
* is tested as if the backslash were a separator.
|
|
31
|
+
* @evidence contracts/performance.md#efficient-algorithms
|
|
32
|
+
* Construction copies the P supplied patterns once; a call converts a path
|
|
33
|
+
* of length L once and tests patterns in order until the first match,
|
|
34
|
+
* so its cost is O(L) plus the cost of the patterns the caller wrote.
|
|
35
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
36
|
+
* Keeps no cache of its own; the loader builds the predicate once per session
|
|
37
|
+
* and calls it per module.
|
|
38
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
39
|
+
* The predicate retains only its P pattern copies for as long as the loader
|
|
40
|
+
* holds it, bounded by the supplied list, and acquires no handle or task.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createBunFilter(filter: RegExp | readonly RegExp[] | undefined): ((path: string) => boolean) | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the `filter` loader option into one predicate over delivered module
|
|
3
|
+
* paths, or `undefined` when no module is skipped.
|
|
4
|
+
*
|
|
5
|
+
* The predicate tests a copy of each pattern, so a global or sticky pattern
|
|
6
|
+
* carries no match position from one module to the next and the caller's
|
|
7
|
+
* pattern is never changed. It tests the path with `\` written as `/` and
|
|
8
|
+
* leaves the delivered path itself untouched for reading and compiling.
|
|
9
|
+
*
|
|
10
|
+
* @throws TypeError when an entry of `filter` is not a RegExp.
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation
|
|
12
|
+
* `RegExp.prototype.test` on a global or sticky pattern reads and writes
|
|
13
|
+
* `lastIndex`, so a copy reset to zero before each test makes every answer
|
|
14
|
+
* depend on the path alone; `new RegExp(pattern)` keeps source and flags.
|
|
15
|
+
* An empty list names no restriction.
|
|
16
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
17
|
+
* Validation, ownership of the copies and matching concern the same patterns,
|
|
18
|
+
* so one function answers the loader's one question. The loader keeps
|
|
19
|
+
* the decision of what a skipped module returns.
|
|
20
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
21
|
+
* The `lastIndex` reset follows from the language's stateful `test`,
|
|
22
|
+
* not from a consumer; no RegExp prototype or caller pattern is modified.
|
|
23
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
24
|
+
* The comment states pattern ownership, the tested spelling, the `undefined`
|
|
25
|
+
* result and the thrown failure, which the signature does not show.
|
|
26
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
27
|
+
* Only the string under test is converted, with the repository's separator
|
|
28
|
+
* conversion. The native path is never rewritten and no filesystem identity
|
|
29
|
+
* or case policy is implied. A POSIX file name containing a backslash
|
|
30
|
+
* is tested as if the backslash were a separator.
|
|
31
|
+
* @evidence contracts/performance.md#efficient-algorithms
|
|
32
|
+
* Construction copies the P supplied patterns once; a call converts a path
|
|
33
|
+
* of length L once and tests patterns in order until the first match,
|
|
34
|
+
* so its cost is O(L) plus the cost of the patterns the caller wrote.
|
|
35
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
36
|
+
* Keeps no cache of its own; the loader builds the predicate once per session
|
|
37
|
+
* and calls it per module.
|
|
38
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
39
|
+
* The predicate retains only its P pattern copies for as long as the loader
|
|
40
|
+
* holds it, bounded by the supplied list, and acquires no handle or task.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createBunFilter(filter: RegExp | readonly RegExp[] | undefined): ((path: string) => boolean) | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile the `filter` loader option into one predicate over delivered module
|
|
3
|
+
* paths, or `undefined` when no module is skipped.
|
|
4
|
+
*
|
|
5
|
+
* The predicate tests a copy of each pattern, so a global or sticky pattern
|
|
6
|
+
* carries no match position from one module to the next and the caller's
|
|
7
|
+
* pattern is never changed. It tests the path with `\` written as `/` and
|
|
8
|
+
* leaves the delivered path itself untouched for reading and compiling.
|
|
9
|
+
*
|
|
10
|
+
* @throws TypeError when an entry of `filter` is not a RegExp.
|
|
11
|
+
* @evidence contracts/common.md#principled-implementation
|
|
12
|
+
* `RegExp.prototype.test` on a global or sticky pattern reads and writes
|
|
13
|
+
* `lastIndex`, so a copy reset to zero before each test makes every answer
|
|
14
|
+
* depend on the path alone; `new RegExp(pattern)` keeps source and flags.
|
|
15
|
+
* An empty list names no restriction.
|
|
16
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
17
|
+
* Validation, ownership of the copies and matching concern the same patterns,
|
|
18
|
+
* so one function answers the loader's one question. The loader keeps
|
|
19
|
+
* the decision of what a skipped module returns.
|
|
20
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
21
|
+
* The `lastIndex` reset follows from the language's stateful `test`,
|
|
22
|
+
* not from a consumer; no RegExp prototype or caller pattern is modified.
|
|
23
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
24
|
+
* The comment states pattern ownership, the tested spelling, the `undefined`
|
|
25
|
+
* result and the thrown failure, which the signature does not show.
|
|
26
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
27
|
+
* Only the string under test is converted, with the repository's separator
|
|
28
|
+
* conversion. The native path is never rewritten and no filesystem identity
|
|
29
|
+
* or case policy is implied. A POSIX file name containing a backslash
|
|
30
|
+
* is tested as if the backslash were a separator.
|
|
31
|
+
* @evidence contracts/performance.md#efficient-algorithms
|
|
32
|
+
* Construction copies the P supplied patterns once; a call converts a path
|
|
33
|
+
* of length L once and tests patterns in order until the first match,
|
|
34
|
+
* so its cost is O(L) plus the cost of the patterns the caller wrote.
|
|
35
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
36
|
+
* Keeps no cache of its own; the loader builds the predicate once per session
|
|
37
|
+
* and calls it per module.
|
|
38
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
39
|
+
* The predicate retains only its P pattern copies for as long as the loader
|
|
40
|
+
* holds it, bounded by the supplied list, and acquires no handle or task.
|
|
41
|
+
*/
|
|
42
|
+
export declare function createBunFilter(filter: RegExp | readonly RegExp[] | undefined): ((path: string) => boolean) | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var normalizePath = require('../transform/filesystem/normalizePath.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Compile the `filter` loader option into one predicate over delivered module
|
|
7
|
+
* paths, or `undefined` when no module is skipped.
|
|
8
|
+
*
|
|
9
|
+
* The predicate tests a copy of each pattern, so a global or sticky pattern
|
|
10
|
+
* carries no match position from one module to the next and the caller's
|
|
11
|
+
* pattern is never changed. It tests the path with `\` written as `/` and
|
|
12
|
+
* leaves the delivered path itself untouched for reading and compiling.
|
|
13
|
+
*
|
|
14
|
+
* @throws TypeError when an entry of `filter` is not a RegExp.
|
|
15
|
+
* @evidence contracts/common.md#principled-implementation
|
|
16
|
+
* `RegExp.prototype.test` on a global or sticky pattern reads and writes
|
|
17
|
+
* `lastIndex`, so a copy reset to zero before each test makes every answer
|
|
18
|
+
* depend on the path alone; `new RegExp(pattern)` keeps source and flags.
|
|
19
|
+
* An empty list names no restriction.
|
|
20
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
21
|
+
* Validation, ownership of the copies and matching concern the same patterns,
|
|
22
|
+
* so one function answers the loader's one question. The loader keeps
|
|
23
|
+
* the decision of what a skipped module returns.
|
|
24
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
25
|
+
* The `lastIndex` reset follows from the language's stateful `test`,
|
|
26
|
+
* not from a consumer; no RegExp prototype or caller pattern is modified.
|
|
27
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
28
|
+
* The comment states pattern ownership, the tested spelling, the `undefined`
|
|
29
|
+
* result and the thrown failure, which the signature does not show.
|
|
30
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
31
|
+
* Only the string under test is converted, with the repository's separator
|
|
32
|
+
* conversion. The native path is never rewritten and no filesystem identity
|
|
33
|
+
* or case policy is implied. A POSIX file name containing a backslash
|
|
34
|
+
* is tested as if the backslash were a separator.
|
|
35
|
+
* @evidence contracts/performance.md#efficient-algorithms
|
|
36
|
+
* Construction copies the P supplied patterns once; a call converts a path
|
|
37
|
+
* of length L once and tests patterns in order until the first match,
|
|
38
|
+
* so its cost is O(L) plus the cost of the patterns the caller wrote.
|
|
39
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
40
|
+
* Keeps no cache of its own; the loader builds the predicate once per session
|
|
41
|
+
* and calls it per module.
|
|
42
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
43
|
+
* The predicate retains only its P pattern copies for as long as the loader
|
|
44
|
+
* holds it, bounded by the supplied list, and acquires no handle or task.
|
|
45
|
+
*/
|
|
46
|
+
function createBunFilter(filter) {
|
|
47
|
+
if (filter === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
const supplied = [filter].flat();
|
|
50
|
+
if (supplied.length === 0)
|
|
51
|
+
return undefined;
|
|
52
|
+
const patterns = supplied.map((pattern) => {
|
|
53
|
+
if (!(pattern instanceof RegExp))
|
|
54
|
+
throw new TypeError("@ttsc/unplugin filter must be a RegExp or an array of RegExp.");
|
|
55
|
+
return new RegExp(pattern);
|
|
56
|
+
});
|
|
57
|
+
return (path) => {
|
|
58
|
+
const spelling = normalizePath.normalizePath(path);
|
|
59
|
+
return patterns.some((pattern) => {
|
|
60
|
+
pattern.lastIndex = 0;
|
|
61
|
+
return pattern.test(spelling);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.createBunFilter = createBunFilter;
|
|
67
|
+
//# sourceMappingURL=createBunFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBunFilter.js","sources":["../../../src/core/bun/createBunFilter.ts"],"sourcesContent":[null],"names":["normalizePath"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCG;AACG,SAAU,eAAe,CAC7B,MAA8C,EAAA;IAE9C,IAAI,MAAM,KAAK,SAAS;AAAE,QAAA,OAAO,SAAS;IAC1C,MAAM,QAAQ,GAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;AAC3C,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,SAAS;IAC3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,KAAI;AACxC,QAAA,IAAI,EAAE,OAAO,YAAY,MAAM,CAAC;AAC9B,YAAA,MAAM,IAAI,SAAS,CACjB,+DAA+D,CAChE;AACH,QAAA,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC;AAC5B,IAAA,CAAC,CAAC;IACF,OAAO,CAAC,IAAI,KAAI;AACd,QAAA,MAAM,QAAQ,GAAGA,2BAAa,CAAC,IAAI,CAAC;AACpC,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,KAAI;AAC/B,YAAA,OAAO,CAAC,SAAS,GAAG,CAAC;AACrB,YAAA,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;AAC/B,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { normalizePath } from '../transform/filesystem/normalizePath.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compile the `filter` loader option into one predicate over delivered module
|
|
5
|
+
* paths, or `undefined` when no module is skipped.
|
|
6
|
+
*
|
|
7
|
+
* The predicate tests a copy of each pattern, so a global or sticky pattern
|
|
8
|
+
* carries no match position from one module to the next and the caller's
|
|
9
|
+
* pattern is never changed. It tests the path with `\` written as `/` and
|
|
10
|
+
* leaves the delivered path itself untouched for reading and compiling.
|
|
11
|
+
*
|
|
12
|
+
* @throws TypeError when an entry of `filter` is not a RegExp.
|
|
13
|
+
* @evidence contracts/common.md#principled-implementation
|
|
14
|
+
* `RegExp.prototype.test` on a global or sticky pattern reads and writes
|
|
15
|
+
* `lastIndex`, so a copy reset to zero before each test makes every answer
|
|
16
|
+
* depend on the path alone; `new RegExp(pattern)` keeps source and flags.
|
|
17
|
+
* An empty list names no restriction.
|
|
18
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
19
|
+
* Validation, ownership of the copies and matching concern the same patterns,
|
|
20
|
+
* so one function answers the loader's one question. The loader keeps
|
|
21
|
+
* the decision of what a skipped module returns.
|
|
22
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
23
|
+
* The `lastIndex` reset follows from the language's stateful `test`,
|
|
24
|
+
* not from a consumer; no RegExp prototype or caller pattern is modified.
|
|
25
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
26
|
+
* The comment states pattern ownership, the tested spelling, the `undefined`
|
|
27
|
+
* result and the thrown failure, which the signature does not show.
|
|
28
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
29
|
+
* Only the string under test is converted, with the repository's separator
|
|
30
|
+
* conversion. The native path is never rewritten and no filesystem identity
|
|
31
|
+
* or case policy is implied. A POSIX file name containing a backslash
|
|
32
|
+
* is tested as if the backslash were a separator.
|
|
33
|
+
* @evidence contracts/performance.md#efficient-algorithms
|
|
34
|
+
* Construction copies the P supplied patterns once; a call converts a path
|
|
35
|
+
* of length L once and tests patterns in order until the first match,
|
|
36
|
+
* so its cost is O(L) plus the cost of the patterns the caller wrote.
|
|
37
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
38
|
+
* Keeps no cache of its own; the loader builds the predicate once per session
|
|
39
|
+
* and calls it per module.
|
|
40
|
+
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
41
|
+
* The predicate retains only its P pattern copies for as long as the loader
|
|
42
|
+
* holds it, bounded by the supplied list, and acquires no handle or task.
|
|
43
|
+
*/
|
|
44
|
+
function createBunFilter(filter) {
|
|
45
|
+
if (filter === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
const supplied = [filter].flat();
|
|
48
|
+
if (supplied.length === 0)
|
|
49
|
+
return undefined;
|
|
50
|
+
const patterns = supplied.map((pattern) => {
|
|
51
|
+
if (!(pattern instanceof RegExp))
|
|
52
|
+
throw new TypeError("@ttsc/unplugin filter must be a RegExp or an array of RegExp.");
|
|
53
|
+
return new RegExp(pattern);
|
|
54
|
+
});
|
|
55
|
+
return (path) => {
|
|
56
|
+
const spelling = normalizePath(path);
|
|
57
|
+
return patterns.some((pattern) => {
|
|
58
|
+
pattern.lastIndex = 0;
|
|
59
|
+
return pattern.test(spelling);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { createBunFilter };
|
|
65
|
+
//# sourceMappingURL=createBunFilter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBunFilter.mjs","sources":["../../../src/core/bun/createBunFilter.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCG;AACG,SAAU,eAAe,CAC7B,MAA8C,EAAA;IAE9C,IAAI,MAAM,KAAK,SAAS;AAAE,QAAA,OAAO,SAAS;IAC1C,MAAM,QAAQ,GAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;AAC3C,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,SAAS;IAC3C,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,KAAI;AACxC,QAAA,IAAI,EAAE,OAAO,YAAY,MAAM,CAAC;AAC9B,YAAA,MAAM,IAAI,SAAS,CACjB,+DAA+D,CAChE;AACH,QAAA,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC;AAC5B,IAAA,CAAC,CAAC;IACF,OAAO,CAAC,IAAI,KAAI;AACd,QAAA,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC;AACpC,QAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,KAAI;AAC/B,YAAA,OAAO,CAAC,SAAS,GAAG,CAAC;AACrB,YAAA,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;AAC/B,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC;AACH;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Register the ttsc transform as a Bun **runtime** plugin.
|
|
4
4
|
*
|
|
@@ -19,12 +19,20 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
|
19
19
|
* are idempotent; a different value throws rather than pretending a resolved
|
|
20
20
|
* loader changed configuration.
|
|
21
21
|
*
|
|
22
|
+
* The `filter` option selects the project modules ttsc transforms and is
|
|
23
|
+
* described by `TtscBunLoaderOptions`. It is an ordinary option for snapshots,
|
|
24
|
+
* so a later call with an equal filter is idempotent. The first TypeScript
|
|
25
|
+
* module outside `node_modules` locks the snapshot whether or not the filter
|
|
26
|
+
* selects it.
|
|
27
|
+
*
|
|
22
28
|
* @throws When called explicitly off the Bun runtime, when options are not
|
|
23
|
-
* structured-cloneable,
|
|
24
|
-
*
|
|
25
|
-
*
|
|
29
|
+
* structured-cloneable, when `filter` holds a value that is not a RegExp, or
|
|
30
|
+
* when a different option value is supplied after the first load. The
|
|
31
|
+
* import-time registration of the entry stays silent off Bun so the module is
|
|
32
|
+
* harmless to import from Node (tests, tooling).
|
|
26
33
|
* @evidence contracts/common.md#principled-implementation
|
|
27
|
-
* Structured cloning captures option values before installation
|
|
34
|
+
* Structured cloning captures option values before installation, including
|
|
35
|
+
* each filter pattern with its match position reset. Before first
|
|
28
36
|
* load the pending snapshot is replaceable; afterward deep equality permits
|
|
29
37
|
* only idempotent calls, matching the immutable runtime module session.
|
|
30
38
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
@@ -40,7 +48,8 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
|
40
48
|
* Performs no filesystem, path or process operation of its own.
|
|
41
49
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
42
50
|
* structuredClone follows the supplied option graph and allocates its detached
|
|
43
|
-
* snapshot;
|
|
51
|
+
* snapshot; filter validation copies its P patterns once and discards them.
|
|
52
|
+
* A locked call additionally pays deep-comparison cost even when
|
|
44
53
|
* idempotent. First installation delegates plugin construction/setup to
|
|
45
54
|
* ensureRegistered and the host. Fixed entry-point branches do not erase these costs.
|
|
46
55
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
@@ -53,4 +62,4 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
|
53
62
|
* the loader's setup cache for the runtime session; no teardown or fixed option
|
|
54
63
|
* byte bound is provided here. Rejected snapshot/deep-compare values are local.
|
|
55
64
|
*/
|
|
56
|
-
export declare function register(options?:
|
|
65
|
+
export declare function register(options?: TtscBunLoaderOptions): void;
|