@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/src/core/bun/register.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
|
|
4
4
|
import { bunRuntime } from "./bunRuntime";
|
|
5
|
+
import { createBunFilter } from "./createBunFilter";
|
|
5
6
|
import { ensureRegistered } from "./ensureRegistered";
|
|
6
7
|
import { registrationState } from "./registrationState";
|
|
7
8
|
|
|
@@ -25,12 +26,20 @@ import { registrationState } from "./registrationState";
|
|
|
25
26
|
* are idempotent; a different value throws rather than pretending a resolved
|
|
26
27
|
* loader changed configuration.
|
|
27
28
|
*
|
|
29
|
+
* The `filter` option selects the project modules ttsc transforms and is
|
|
30
|
+
* described by `TtscBunLoaderOptions`. It is an ordinary option for snapshots,
|
|
31
|
+
* so a later call with an equal filter is idempotent. The first TypeScript
|
|
32
|
+
* module outside `node_modules` locks the snapshot whether or not the filter
|
|
33
|
+
* selects it.
|
|
34
|
+
*
|
|
28
35
|
* @throws When called explicitly off the Bun runtime, when options are not
|
|
29
|
-
* structured-cloneable,
|
|
30
|
-
*
|
|
31
|
-
*
|
|
36
|
+
* structured-cloneable, when `filter` holds a value that is not a RegExp, or
|
|
37
|
+
* when a different option value is supplied after the first load. The
|
|
38
|
+
* import-time registration of the entry stays silent off Bun so the module is
|
|
39
|
+
* harmless to import from Node (tests, tooling).
|
|
32
40
|
* @evidence contracts/common.md#principled-implementation
|
|
33
|
-
* Structured cloning captures option values before installation
|
|
41
|
+
* Structured cloning captures option values before installation, including
|
|
42
|
+
* each filter pattern with its match position reset. Before first
|
|
34
43
|
* load the pending snapshot is replaceable; afterward deep equality permits
|
|
35
44
|
* only idempotent calls, matching the immutable runtime module session.
|
|
36
45
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
@@ -46,7 +55,8 @@ import { registrationState } from "./registrationState";
|
|
|
46
55
|
* Performs no filesystem, path or process operation of its own.
|
|
47
56
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
48
57
|
* structuredClone follows the supplied option graph and allocates its detached
|
|
49
|
-
* snapshot;
|
|
58
|
+
* snapshot; filter validation copies its P patterns once and discards them.
|
|
59
|
+
* A locked call additionally pays deep-comparison cost even when
|
|
50
60
|
* idempotent. First installation delegates plugin construction/setup to
|
|
51
61
|
* ensureRegistered and the host. Fixed entry-point branches do not erase these costs.
|
|
52
62
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
@@ -59,7 +69,7 @@ import { registrationState } from "./registrationState";
|
|
|
59
69
|
* the loader's setup cache for the runtime session; no teardown or fixed option
|
|
60
70
|
* byte bound is provided here. Rejected snapshot/deep-compare values are local.
|
|
61
71
|
*/
|
|
62
|
-
export function register(options?:
|
|
72
|
+
export function register(options?: TtscBunLoaderOptions): void {
|
|
63
73
|
const runtime = bunRuntime();
|
|
64
74
|
if (runtime === undefined) {
|
|
65
75
|
throw new Error(
|
|
@@ -70,6 +80,9 @@ export function register(options?: TtscUnpluginOptions): void {
|
|
|
70
80
|
}
|
|
71
81
|
const state = registrationState(runtime);
|
|
72
82
|
const snapshot = snapshotOptions(options);
|
|
83
|
+
// Report an invalid filter to the call that supplied it, not to the first
|
|
84
|
+
// module load that happens to resolve the options.
|
|
85
|
+
createBunFilter(snapshot?.filter);
|
|
73
86
|
if (state.optionsLocked) {
|
|
74
87
|
if (isDeepStrictEqual(snapshot, state.lockedOptions)) {
|
|
75
88
|
return;
|
|
@@ -86,8 +99,8 @@ export function register(options?: TtscUnpluginOptions): void {
|
|
|
86
99
|
|
|
87
100
|
/** Detach JSON-shaped options from mutations made after `register` returns. */
|
|
88
101
|
function snapshotOptions(
|
|
89
|
-
options:
|
|
90
|
-
):
|
|
102
|
+
options: TtscBunLoaderOptions | undefined,
|
|
103
|
+
): TtscBunLoaderOptions | undefined {
|
|
91
104
|
if (options === undefined) return undefined;
|
|
92
105
|
try {
|
|
93
106
|
return structuredClone(options);
|