@ttsc/unplugin 0.37.0 → 0.37.2
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/README.md
CHANGED
|
@@ -201,6 +201,17 @@ register({ project: "tsconfig.build.json" });
|
|
|
201
201
|
|
|
202
202
|
Importing the module registers it, so a bare `import "@ttsc/unplugin/bun-register"` is enough when the defaults are right. CommonJS and ESM loads in the same Bun process share that one registration. Calls made before the first transformable TypeScript load use last-call-wins and capture their options by value, which lets an immediate explicit call replace the preload defaults without installing a second loader. Entering the first such load locks the options synchronously for the module-loading session. A later call with the same structural value is idempotent, while a different value throws and requires restarting the Bun process.
|
|
203
203
|
|
|
204
|
+
By default, `ttsc` transforms every TypeScript module that Bun loads, except those in `node_modules`. To transform only some of them, pass `filter`, a `RegExp` or an array of `RegExp`. A module is transformed when any pattern matches its absolute path, and every other module loads as Bun would load it without `ttsc`:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
import register from "@ttsc/unplugin/bun-register";
|
|
208
|
+
|
|
209
|
+
// Transform only the modules in a src/validators directory.
|
|
210
|
+
register({ filter: /\/src\/validators\// });
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`ttsc({ filter })` takes the same option under `Bun.build`. The [bundler guide](https://ttsc.dev/docs/setup/unplugin/#select-modules-with-filter) covers how a path is matched and when `filter` can no longer change.
|
|
214
|
+
|
|
204
215
|
Under `Bun.build`, the adapter yields to the next loader for declarations, `node_modules`, source that `ttsc` leaves unchanged, and entries supplied through `Bun.build({ files })`. In-memory entries remain with Bun because ttsc transforms filesystem-backed project inputs. Bun's runtime `onLoad` contract does not accept an undefined result, so `Bun.plugin()` explicitly passes excluded and unchanged filesystem files through with their original source. Each `Bun.build` opens a delivery pass through `onStart`, then `onEnd` disposes the completed project generation and its filesystem trackers. The runtime API has neither lifecycle hook, so one setup is treated as one immutable module-loading session: restart the Bun process after changing source, tsconfig, or plugin inputs.
|
|
205
216
|
|
|
206
217
|
## Configuration
|
package/lib/bun-register.d.cts
CHANGED
package/lib/bun-register.d.mts
CHANGED
package/lib/bun-register.d.ts
CHANGED
package/lib/bun-register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-register.js","sources":["../src/bun-register.ts"],"sourcesContent":[null],"names":["bunRuntime","ensureRegistered","registrationState"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"bun-register.js","sources":["../src/bun-register.ts"],"sourcesContent":[null],"names":["bunRuntime","ensureRegistered","registrationState"],"mappings":";;;;;;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,OAAO,GAAGA,qBAAU,EAAE;AAC5B,IAAI,OAAO,KAAK,SAAS,EAAE;IACzBC,iCAAgB,CAAC,OAAO,EAAEC,mCAAiB,CAAC,OAAO,CAAC,CAAC;AACvD;;;;;"}
|
package/lib/bun-register.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-register.mjs","sources":["../src/bun-register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"bun-register.mjs","sources":["../src/bun-register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,OAAO,GAAG,UAAU,EAAE;AAC5B,IAAI,OAAO,KAAK,SAAS,EAAE;IACzB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;AACvD"}
|
package/lib/bun.d.cts
CHANGED
|
@@ -2,4 +2,5 @@ export { bun as default } from "./core/bun/bun.cjs";
|
|
|
2
2
|
export type { BunLikeBuild } from "./core/bun/BunLikeBuild.cjs";
|
|
3
3
|
export type { BunLikePlugin } from "./core/bun/BunLikePlugin.cjs";
|
|
4
4
|
export type { BunLoader } from "./core/bun/BunLoader.cjs";
|
|
5
|
+
export type { TtscBunLoaderOptions } from "./core/bun/TtscBunLoaderOptions.cjs";
|
|
5
6
|
export type { TtscBunOptions } from "./core/bun/TtscBunOptions.cjs";
|
package/lib/bun.d.mts
CHANGED
|
@@ -2,4 +2,5 @@ export { bun as default } from "./core/bun/bun.mjs";
|
|
|
2
2
|
export type { BunLikeBuild } from "./core/bun/BunLikeBuild.mjs";
|
|
3
3
|
export type { BunLikePlugin } from "./core/bun/BunLikePlugin.mjs";
|
|
4
4
|
export type { BunLoader } from "./core/bun/BunLoader.mjs";
|
|
5
|
+
export type { TtscBunLoaderOptions } from "./core/bun/TtscBunLoaderOptions.mjs";
|
|
5
6
|
export type { TtscBunOptions } from "./core/bun/TtscBunOptions.mjs";
|
package/lib/bun.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { bun as default } from "./core/bun/bun";
|
|
|
2
2
|
export type { BunLikeBuild } from "./core/bun/BunLikeBuild";
|
|
3
3
|
export type { BunLikePlugin } from "./core/bun/BunLikePlugin";
|
|
4
4
|
export type { BunLoader } from "./core/bun/BunLoader";
|
|
5
|
+
export type { TtscBunLoaderOptions } from "./core/bun/TtscBunLoaderOptions";
|
|
5
6
|
export type { TtscBunOptions } from "./core/bun/TtscBunOptions";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* The single runtime loader's registration and option lifecycle for one Bun
|
|
4
4
|
* runtime, shared by both emitted module conditions of `bun-register`.
|
|
@@ -8,6 +8,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
|
8
8
|
* for this state's runtime session. Host-owned memory files are passed over
|
|
9
9
|
* before locking options.
|
|
10
10
|
*
|
|
11
|
+
* The `filter` option is part of the snapshot, so a project module the filter
|
|
12
|
+
* skips still locks the options when it is the first one loaded.
|
|
13
|
+
*
|
|
11
14
|
* @evidence contracts/common.md#principled-implementation
|
|
12
15
|
* Pending and locked snapshots distinguish pre-load replacement from the
|
|
13
16
|
* immutable module-loading session; registered separately tracks installation.
|
|
@@ -38,9 +41,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
|
38
41
|
*/
|
|
39
42
|
export interface BunRegistrationState {
|
|
40
43
|
/** Options the next lock takes, detached from the caller's object. */
|
|
41
|
-
activeOptions:
|
|
44
|
+
activeOptions: TtscBunLoaderOptions | undefined;
|
|
42
45
|
/** Options the loader resolved with, once `optionsLocked` holds. */
|
|
43
|
-
lockedOptions:
|
|
46
|
+
lockedOptions: TtscBunLoaderOptions | undefined;
|
|
44
47
|
/** Whether a load has started, which fixes `lockedOptions` for good. */
|
|
45
48
|
optionsLocked: boolean;
|
|
46
49
|
/** Installation guard set before the host call and reset on synchronous error. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* The single runtime loader's registration and option lifecycle for one Bun
|
|
4
4
|
* runtime, shared by both emitted module conditions of `bun-register`.
|
|
@@ -8,6 +8,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.mjs";
|
|
|
8
8
|
* for this state's runtime session. Host-owned memory files are passed over
|
|
9
9
|
* before locking options.
|
|
10
10
|
*
|
|
11
|
+
* The `filter` option is part of the snapshot, so a project module the filter
|
|
12
|
+
* skips still locks the options when it is the first one loaded.
|
|
13
|
+
*
|
|
11
14
|
* @evidence contracts/common.md#principled-implementation
|
|
12
15
|
* Pending and locked snapshots distinguish pre-load replacement from the
|
|
13
16
|
* immutable module-loading session; registered separately tracks installation.
|
|
@@ -38,9 +41,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.mjs";
|
|
|
38
41
|
*/
|
|
39
42
|
export interface BunRegistrationState {
|
|
40
43
|
/** Options the next lock takes, detached from the caller's object. */
|
|
41
|
-
activeOptions:
|
|
44
|
+
activeOptions: TtscBunLoaderOptions | undefined;
|
|
42
45
|
/** Options the loader resolved with, once `optionsLocked` holds. */
|
|
43
|
-
lockedOptions:
|
|
46
|
+
lockedOptions: TtscBunLoaderOptions | undefined;
|
|
44
47
|
/** Whether a load has started, which fixes `lockedOptions` for good. */
|
|
45
48
|
optionsLocked: boolean;
|
|
46
49
|
/** Installation guard set before the host call and reset on synchronous error. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
|
|
2
2
|
/**
|
|
3
3
|
* The single runtime loader's registration and option lifecycle for one Bun
|
|
4
4
|
* runtime, shared by both emitted module conditions of `bun-register`.
|
|
@@ -8,6 +8,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
|
|
|
8
8
|
* for this state's runtime session. Host-owned memory files are passed over
|
|
9
9
|
* before locking options.
|
|
10
10
|
*
|
|
11
|
+
* The `filter` option is part of the snapshot, so a project module the filter
|
|
12
|
+
* skips still locks the options when it is the first one loaded.
|
|
13
|
+
*
|
|
11
14
|
* @evidence contracts/common.md#principled-implementation
|
|
12
15
|
* Pending and locked snapshots distinguish pre-load replacement from the
|
|
13
16
|
* immutable module-loading session; registered separately tracks installation.
|
|
@@ -38,9 +41,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
|
|
|
38
41
|
*/
|
|
39
42
|
export interface BunRegistrationState {
|
|
40
43
|
/** Options the next lock takes, detached from the caller's object. */
|
|
41
|
-
activeOptions:
|
|
44
|
+
activeOptions: TtscBunLoaderOptions | undefined;
|
|
42
45
|
/** Options the loader resolved with, once `optionsLocked` holds. */
|
|
43
|
-
lockedOptions:
|
|
46
|
+
lockedOptions: TtscBunLoaderOptions | undefined;
|
|
44
47
|
/** Whether a load has started, which fixes `lockedOptions` for good. */
|
|
45
48
|
optionsLocked: boolean;
|
|
46
49
|
/** Installation guard set before the host call and reset on synchronous error. */
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Options of the Bun loader: the shared adapter options plus `filter`, which
|
|
4
|
+
* chooses the modules to transform.
|
|
5
|
+
*
|
|
6
|
+
* `Bun.plugin()` and a `bunfig.toml` preload have no include or exclude rules
|
|
7
|
+
* of their own, so the loader takes that choice itself. The shared options stay
|
|
8
|
+
* free of a member the other adapters would ignore.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/common.md#principled-implementation
|
|
11
|
+
* Bun's own `onLoad` selects modules with a RegExp, so one pattern
|
|
12
|
+
* or a list of alternatives expresses the choice, and patterns only narrow
|
|
13
|
+
* the modules the loader already includes.
|
|
14
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
15
|
+
* The member sits on the adapter that honors it, and the shared options
|
|
16
|
+
* type is unchanged, so no other adapter accepts and ignores a filter.
|
|
17
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
18
|
+
* The member selects modules by path pattern for every consumer. It names
|
|
19
|
+
* no fixture or consumer and compensates for no defect.
|
|
20
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
21
|
+
* The member comment states, each as its own paragraph, the skipped-module
|
|
22
|
+
* behavior, the empty-list meaning and narrowing, the matched path spelling,
|
|
23
|
+
* the case policy and flag behavior, and the option-lock effect, and shows
|
|
24
|
+
* one example.
|
|
25
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
26
|
+
* Patterns are tested against a separator-normalized spelling,
|
|
27
|
+
* which is matching syntax and not filesystem identity.
|
|
28
|
+
* The type learns no platform capability and sets no case policy.
|
|
29
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
30
|
+
* The interface declares a shape and performs no computation.
|
|
31
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
32
|
+
* The interface declares a shape and has no work to reuse.
|
|
33
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
34
|
+
* The interface declares a shape and holds no handle or state.
|
|
35
|
+
*/
|
|
36
|
+
export interface TtscBunLoaderOptions extends TtscUnpluginOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Restricts ttsc to the modules whose absolute path matches a pattern.
|
|
39
|
+
*
|
|
40
|
+
* A module that no pattern matches is skipped: Bun loads it as it would
|
|
41
|
+
* without ttsc, so no ttsc plugin runs on it.
|
|
42
|
+
*
|
|
43
|
+
* Omitting the member or passing an empty array applies no restriction. A
|
|
44
|
+
* pattern only narrows what ttsc already transforms: `node_modules`,
|
|
45
|
+
* declaration files and entries supplied through `Bun.build({ files })` stay
|
|
46
|
+
* with Bun whether or not a pattern matches them.
|
|
47
|
+
*
|
|
48
|
+
* A pattern is tested against the absolute path, such as
|
|
49
|
+
* `/home/me/app/src/validators/email.ts`, and not against an import
|
|
50
|
+
* specifier. The path is tested with each `\` written as `/`, so a pattern
|
|
51
|
+
* written with `/` behaves the same on every OS. A Windows path starts with
|
|
52
|
+
* its drive, as in `C:/app/src/validators/email.ts`, so match part of the
|
|
53
|
+
* path and do not anchor on a leading `/`.
|
|
54
|
+
*
|
|
55
|
+
* Matching is case-sensitive, so add the `i` flag on a case-insensitive
|
|
56
|
+
* filesystem. The `g` and `y` flags are safe to use, since no state carries
|
|
57
|
+
* from one module to the next.
|
|
58
|
+
*
|
|
59
|
+
* Under `register`, the first TypeScript module outside `node_modules` that
|
|
60
|
+
* loads locks the options, `filter` included, even if no pattern matches that
|
|
61
|
+
* module. A later call with different options throws.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Transform the modules in src/validators and the *.schema.ts files.
|
|
65
|
+
* register({ filter: [/\/src\/validators\//, /\.schema\.ts$/] });
|
|
66
|
+
*/
|
|
67
|
+
filter?: RegExp | readonly RegExp[];
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Options of the Bun loader: the shared adapter options plus `filter`, which
|
|
4
|
+
* chooses the modules to transform.
|
|
5
|
+
*
|
|
6
|
+
* `Bun.plugin()` and a `bunfig.toml` preload have no include or exclude rules
|
|
7
|
+
* of their own, so the loader takes that choice itself. The shared options stay
|
|
8
|
+
* free of a member the other adapters would ignore.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/common.md#principled-implementation
|
|
11
|
+
* Bun's own `onLoad` selects modules with a RegExp, so one pattern
|
|
12
|
+
* or a list of alternatives expresses the choice, and patterns only narrow
|
|
13
|
+
* the modules the loader already includes.
|
|
14
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
15
|
+
* The member sits on the adapter that honors it, and the shared options
|
|
16
|
+
* type is unchanged, so no other adapter accepts and ignores a filter.
|
|
17
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
18
|
+
* The member selects modules by path pattern for every consumer. It names
|
|
19
|
+
* no fixture or consumer and compensates for no defect.
|
|
20
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
21
|
+
* The member comment states, each as its own paragraph, the skipped-module
|
|
22
|
+
* behavior, the empty-list meaning and narrowing, the matched path spelling,
|
|
23
|
+
* the case policy and flag behavior, and the option-lock effect, and shows
|
|
24
|
+
* one example.
|
|
25
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
26
|
+
* Patterns are tested against a separator-normalized spelling,
|
|
27
|
+
* which is matching syntax and not filesystem identity.
|
|
28
|
+
* The type learns no platform capability and sets no case policy.
|
|
29
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
30
|
+
* The interface declares a shape and performs no computation.
|
|
31
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
32
|
+
* The interface declares a shape and has no work to reuse.
|
|
33
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
34
|
+
* The interface declares a shape and holds no handle or state.
|
|
35
|
+
*/
|
|
36
|
+
export interface TtscBunLoaderOptions extends TtscUnpluginOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Restricts ttsc to the modules whose absolute path matches a pattern.
|
|
39
|
+
*
|
|
40
|
+
* A module that no pattern matches is skipped: Bun loads it as it would
|
|
41
|
+
* without ttsc, so no ttsc plugin runs on it.
|
|
42
|
+
*
|
|
43
|
+
* Omitting the member or passing an empty array applies no restriction. A
|
|
44
|
+
* pattern only narrows what ttsc already transforms: `node_modules`,
|
|
45
|
+
* declaration files and entries supplied through `Bun.build({ files })` stay
|
|
46
|
+
* with Bun whether or not a pattern matches them.
|
|
47
|
+
*
|
|
48
|
+
* A pattern is tested against the absolute path, such as
|
|
49
|
+
* `/home/me/app/src/validators/email.ts`, and not against an import
|
|
50
|
+
* specifier. The path is tested with each `\` written as `/`, so a pattern
|
|
51
|
+
* written with `/` behaves the same on every OS. A Windows path starts with
|
|
52
|
+
* its drive, as in `C:/app/src/validators/email.ts`, so match part of the
|
|
53
|
+
* path and do not anchor on a leading `/`.
|
|
54
|
+
*
|
|
55
|
+
* Matching is case-sensitive, so add the `i` flag on a case-insensitive
|
|
56
|
+
* filesystem. The `g` and `y` flags are safe to use, since no state carries
|
|
57
|
+
* from one module to the next.
|
|
58
|
+
*
|
|
59
|
+
* Under `register`, the first TypeScript module outside `node_modules` that
|
|
60
|
+
* loads locks the options, `filter` included, even if no pattern matches that
|
|
61
|
+
* module. A later call with different options throws.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Transform the modules in src/validators and the *.schema.ts files.
|
|
65
|
+
* register({ filter: [/\/src\/validators\//, /\.schema\.ts$/] });
|
|
66
|
+
*/
|
|
67
|
+
filter?: RegExp | readonly RegExp[];
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
|
|
2
|
+
/**
|
|
3
|
+
* Options of the Bun loader: the shared adapter options plus `filter`, which
|
|
4
|
+
* chooses the modules to transform.
|
|
5
|
+
*
|
|
6
|
+
* `Bun.plugin()` and a `bunfig.toml` preload have no include or exclude rules
|
|
7
|
+
* of their own, so the loader takes that choice itself. The shared options stay
|
|
8
|
+
* free of a member the other adapters would ignore.
|
|
9
|
+
*
|
|
10
|
+
* @evidence contracts/common.md#principled-implementation
|
|
11
|
+
* Bun's own `onLoad` selects modules with a RegExp, so one pattern
|
|
12
|
+
* or a list of alternatives expresses the choice, and patterns only narrow
|
|
13
|
+
* the modules the loader already includes.
|
|
14
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
15
|
+
* The member sits on the adapter that honors it, and the shared options
|
|
16
|
+
* type is unchanged, so no other adapter accepts and ignores a filter.
|
|
17
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
18
|
+
* The member selects modules by path pattern for every consumer. It names
|
|
19
|
+
* no fixture or consumer and compensates for no defect.
|
|
20
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
21
|
+
* The member comment states, each as its own paragraph, the skipped-module
|
|
22
|
+
* behavior, the empty-list meaning and narrowing, the matched path spelling,
|
|
23
|
+
* the case policy and flag behavior, and the option-lock effect, and shows
|
|
24
|
+
* one example.
|
|
25
|
+
* @evidence contracts/portability.md#os-neutral-implementation
|
|
26
|
+
* Patterns are tested against a separator-normalized spelling,
|
|
27
|
+
* which is matching syntax and not filesystem identity.
|
|
28
|
+
* The type learns no platform capability and sets no case policy.
|
|
29
|
+
* @evidenceExclude contracts/performance.md#efficient-algorithms
|
|
30
|
+
* The interface declares a shape and performs no computation.
|
|
31
|
+
* @evidenceExclude contracts/performance.md#reuse-equivalent-work
|
|
32
|
+
* The interface declares a shape and has no work to reuse.
|
|
33
|
+
* @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
|
|
34
|
+
* The interface declares a shape and holds no handle or state.
|
|
35
|
+
*/
|
|
36
|
+
export interface TtscBunLoaderOptions extends TtscUnpluginOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Restricts ttsc to the modules whose absolute path matches a pattern.
|
|
39
|
+
*
|
|
40
|
+
* A module that no pattern matches is skipped: Bun loads it as it would
|
|
41
|
+
* without ttsc, so no ttsc plugin runs on it.
|
|
42
|
+
*
|
|
43
|
+
* Omitting the member or passing an empty array applies no restriction. A
|
|
44
|
+
* pattern only narrows what ttsc already transforms: `node_modules`,
|
|
45
|
+
* declaration files and entries supplied through `Bun.build({ files })` stay
|
|
46
|
+
* with Bun whether or not a pattern matches them.
|
|
47
|
+
*
|
|
48
|
+
* A pattern is tested against the absolute path, such as
|
|
49
|
+
* `/home/me/app/src/validators/email.ts`, and not against an import
|
|
50
|
+
* specifier. The path is tested with each `\` written as `/`, so a pattern
|
|
51
|
+
* written with `/` behaves the same on every OS. A Windows path starts with
|
|
52
|
+
* its drive, as in `C:/app/src/validators/email.ts`, so match part of the
|
|
53
|
+
* path and do not anchor on a leading `/`.
|
|
54
|
+
*
|
|
55
|
+
* Matching is case-sensitive, so add the `i` flag on a case-insensitive
|
|
56
|
+
* filesystem. The `g` and `y` flags are safe to use, since no state carries
|
|
57
|
+
* from one module to the next.
|
|
58
|
+
*
|
|
59
|
+
* Under `register`, the first TypeScript module outside `node_modules` that
|
|
60
|
+
* loads locks the options, `filter` included, even if no pattern matches that
|
|
61
|
+
* module. A later call with different options throws.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // Transform the modules in src/validators and the *.schema.ts files.
|
|
65
|
+
* register({ filter: [/\/src\/validators\//, /\.schema\.ts$/] });
|
|
66
|
+
*/
|
|
67
|
+
filter?: RegExp | readonly RegExp[];
|
|
68
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Options accepted by `bun`, either resolved eagerly or supplied through a
|
|
4
4
|
* provider evaluated lazily on the first included transformable `onLoad` call.
|
|
@@ -35,4 +35,4 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.cjs";
|
|
|
35
35
|
* The installed loader/state owners retain provider and snapshot values;
|
|
36
36
|
* this union acquires no resource or historical state itself.
|
|
37
37
|
*/
|
|
38
|
-
export type TtscBunOptions =
|
|
38
|
+
export type TtscBunOptions = TtscBunLoaderOptions | (() => TtscBunLoaderOptions | undefined);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Options accepted by `bun`, either resolved eagerly or supplied through a
|
|
4
4
|
* provider evaluated lazily on the first included transformable `onLoad` call.
|
|
@@ -35,4 +35,4 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.mjs";
|
|
|
35
35
|
* The installed loader/state owners retain provider and snapshot values;
|
|
36
36
|
* this union acquires no resource or historical state itself.
|
|
37
37
|
*/
|
|
38
|
-
export type TtscBunOptions =
|
|
38
|
+
export type TtscBunOptions = TtscBunLoaderOptions | (() => TtscBunLoaderOptions | undefined);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
|
|
2
2
|
/**
|
|
3
3
|
* Options accepted by `bun`, either resolved eagerly or supplied through a
|
|
4
4
|
* provider evaluated lazily on the first included transformable `onLoad` call.
|
|
@@ -35,4 +35,4 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
|
|
|
35
35
|
* The installed loader/state owners retain provider and snapshot values;
|
|
36
36
|
* this union acquires no resource or historical state itself.
|
|
37
37
|
*/
|
|
38
|
-
export type TtscBunOptions =
|
|
38
|
+
export type TtscBunOptions = TtscBunLoaderOptions | (() => TtscBunLoaderOptions | undefined);
|
package/lib/core/bun/bun.d.cts
CHANGED
|
@@ -23,32 +23,46 @@ import type { TtscBunOptions } from "./TtscBunOptions.cjs";
|
|
|
23
23
|
* session, like Bun's own module cache; restart the process after changing
|
|
24
24
|
* compiler inputs.
|
|
25
25
|
*
|
|
26
|
+
* The `filter` option narrows the project modules the plugin transforms. A
|
|
27
|
+
* module it does not select is left to Bun like an excluded file, so
|
|
28
|
+
* `Bun.build` gets `undefined` and the runtime gets the original source and
|
|
29
|
+
* loader. The options, and with them the filter, are resolved by the first
|
|
30
|
+
* TypeScript module outside `node_modules`, so that module locks the runtime
|
|
31
|
+
* options whether or not the filter selects it.
|
|
32
|
+
*
|
|
26
33
|
* @evidence contracts/common.md#principled-implementation
|
|
27
34
|
* Host hook presence distinguishes a runtime session from bundler builds.
|
|
28
|
-
* Disk inputs enter the shared project transform;
|
|
29
|
-
*
|
|
35
|
+
* Disk inputs the filter selects enter the shared project transform;
|
|
36
|
+
* in-memory bundler entries and unselected modules remain Bun-owned, and
|
|
37
|
+
* runtime responses always retain the TypeScript parser.
|
|
30
38
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
31
39
|
* Setup owns hooks and one cache; source inclusion, option normalization,
|
|
32
|
-
* compilation and source-map encoding remain delegated
|
|
40
|
+
* filter compilation, transformation and source-map encoding remain delegated
|
|
41
|
+
* to their shared owners.
|
|
33
42
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
34
|
-
* The runtime's original-source response implements Bun's required
|
|
35
|
-
* onLoad response. Hook absence and files
|
|
36
|
-
* not overlapping-loader patches or
|
|
43
|
+
* The runtime's original-source response implements Bun's required object
|
|
44
|
+
* onLoad response for every module left to Bun. Hook absence and files
|
|
45
|
+
* ownership are real host differences, not overlapping-loader patches or
|
|
46
|
+
* special treatment of fixture paths.
|
|
37
47
|
* @evidence contracts/common.md#meaningful-documentation
|
|
38
48
|
* Native paragraphs explain bundler/runtime responses, in-memory ownership,
|
|
39
|
-
* parser selection and process-session limits, following
|
|
49
|
+
* filter selection, parser selection and process-session limits, following
|
|
50
|
+
* documentation guidance.
|
|
40
51
|
* @evidence contracts/portability.md#os-neutral-implementation
|
|
41
52
|
* Node reads native delivered paths. Bun's in-memory key comparison separately
|
|
42
53
|
* models separator/drive-letter normalization on Windows while preserving
|
|
43
54
|
* component case and relative spelling rather than treating keys as disk paths.
|
|
44
55
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
45
56
|
* A Set indexes F in-memory keys once at setup; a delivery performs a path-length
|
|
46
|
-
* lookup and reads S source bytes only for its disk input.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
57
|
+
* lookup and reads S source bytes only for its disk input. A module the
|
|
58
|
+
* filter skips costs one predicate call and a source read at runtime, and no
|
|
59
|
+
* transform. First project loads also normalize the option overlay.
|
|
60
|
+
* Delegated transform work includes cache identity/validation,
|
|
61
|
+
* input/directory/byte proofs, misses' native compile and source-map encoding;
|
|
62
|
+
* source-file length alone does not bound it.
|
|
50
63
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
51
|
-
* The first
|
|
64
|
+
* The first project TypeScript load resolves options and compiles the filter
|
|
65
|
+
* once, and every later load reuses both. One cache shares a validated
|
|
52
66
|
* project generation across deliveries; bundler start/end boundaries reset
|
|
53
67
|
* delivery proof, while a runtime retains its immutable module-load session.
|
|
54
68
|
* Coherent local output with unavailable observation shares first deliveries
|
|
@@ -57,8 +71,8 @@ import type { TtscBunOptions } from "./TtscBunOptions.cjs";
|
|
|
57
71
|
* Setup snapshots the in-memory key population; changing host files/options
|
|
58
72
|
* is not authorized merely by an unchanged path or previously quiet callback.
|
|
59
73
|
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
60
|
-
* Setup owns the F-key matcher, resolved options and project cache.
|
|
61
|
-
* end withdraws cached generations; it does not promise cancellation of an
|
|
74
|
+
* Setup owns the F-key matcher, resolved options, compiled filter and project cache.
|
|
75
|
+
* Bundler end withdraws cached generations; it does not promise cancellation of an
|
|
62
76
|
* already running native compile, and the host still owns setup closures.
|
|
63
77
|
* Runtime retention is intended for the process session because this branch
|
|
64
78
|
* has no teardown hook. Key/option/project bytes have no fixed package-wide cap.
|
package/lib/core/bun/bun.d.mts
CHANGED
|
@@ -23,32 +23,46 @@ import type { TtscBunOptions } from "./TtscBunOptions.mjs";
|
|
|
23
23
|
* session, like Bun's own module cache; restart the process after changing
|
|
24
24
|
* compiler inputs.
|
|
25
25
|
*
|
|
26
|
+
* The `filter` option narrows the project modules the plugin transforms. A
|
|
27
|
+
* module it does not select is left to Bun like an excluded file, so
|
|
28
|
+
* `Bun.build` gets `undefined` and the runtime gets the original source and
|
|
29
|
+
* loader. The options, and with them the filter, are resolved by the first
|
|
30
|
+
* TypeScript module outside `node_modules`, so that module locks the runtime
|
|
31
|
+
* options whether or not the filter selects it.
|
|
32
|
+
*
|
|
26
33
|
* @evidence contracts/common.md#principled-implementation
|
|
27
34
|
* Host hook presence distinguishes a runtime session from bundler builds.
|
|
28
|
-
* Disk inputs enter the shared project transform;
|
|
29
|
-
*
|
|
35
|
+
* Disk inputs the filter selects enter the shared project transform;
|
|
36
|
+
* in-memory bundler entries and unselected modules remain Bun-owned, and
|
|
37
|
+
* runtime responses always retain the TypeScript parser.
|
|
30
38
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
31
39
|
* Setup owns hooks and one cache; source inclusion, option normalization,
|
|
32
|
-
* compilation and source-map encoding remain delegated
|
|
40
|
+
* filter compilation, transformation and source-map encoding remain delegated
|
|
41
|
+
* to their shared owners.
|
|
33
42
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
34
|
-
* The runtime's original-source response implements Bun's required
|
|
35
|
-
* onLoad response. Hook absence and files
|
|
36
|
-
* not overlapping-loader patches or
|
|
43
|
+
* The runtime's original-source response implements Bun's required object
|
|
44
|
+
* onLoad response for every module left to Bun. Hook absence and files
|
|
45
|
+
* ownership are real host differences, not overlapping-loader patches or
|
|
46
|
+
* special treatment of fixture paths.
|
|
37
47
|
* @evidence contracts/common.md#meaningful-documentation
|
|
38
48
|
* Native paragraphs explain bundler/runtime responses, in-memory ownership,
|
|
39
|
-
* parser selection and process-session limits, following
|
|
49
|
+
* filter selection, parser selection and process-session limits, following
|
|
50
|
+
* documentation guidance.
|
|
40
51
|
* @evidence contracts/portability.md#os-neutral-implementation
|
|
41
52
|
* Node reads native delivered paths. Bun's in-memory key comparison separately
|
|
42
53
|
* models separator/drive-letter normalization on Windows while preserving
|
|
43
54
|
* component case and relative spelling rather than treating keys as disk paths.
|
|
44
55
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
45
56
|
* A Set indexes F in-memory keys once at setup; a delivery performs a path-length
|
|
46
|
-
* lookup and reads S source bytes only for its disk input.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
57
|
+
* lookup and reads S source bytes only for its disk input. A module the
|
|
58
|
+
* filter skips costs one predicate call and a source read at runtime, and no
|
|
59
|
+
* transform. First project loads also normalize the option overlay.
|
|
60
|
+
* Delegated transform work includes cache identity/validation,
|
|
61
|
+
* input/directory/byte proofs, misses' native compile and source-map encoding;
|
|
62
|
+
* source-file length alone does not bound it.
|
|
50
63
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
51
|
-
* The first
|
|
64
|
+
* The first project TypeScript load resolves options and compiles the filter
|
|
65
|
+
* once, and every later load reuses both. One cache shares a validated
|
|
52
66
|
* project generation across deliveries; bundler start/end boundaries reset
|
|
53
67
|
* delivery proof, while a runtime retains its immutable module-load session.
|
|
54
68
|
* Coherent local output with unavailable observation shares first deliveries
|
|
@@ -57,8 +71,8 @@ import type { TtscBunOptions } from "./TtscBunOptions.mjs";
|
|
|
57
71
|
* Setup snapshots the in-memory key population; changing host files/options
|
|
58
72
|
* is not authorized merely by an unchanged path or previously quiet callback.
|
|
59
73
|
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
60
|
-
* Setup owns the F-key matcher, resolved options and project cache.
|
|
61
|
-
* end withdraws cached generations; it does not promise cancellation of an
|
|
74
|
+
* Setup owns the F-key matcher, resolved options, compiled filter and project cache.
|
|
75
|
+
* Bundler end withdraws cached generations; it does not promise cancellation of an
|
|
62
76
|
* already running native compile, and the host still owns setup closures.
|
|
63
77
|
* Runtime retention is intended for the process session because this branch
|
|
64
78
|
* has no teardown hook. Key/option/project bytes have no fixed package-wide cap.
|
package/lib/core/bun/bun.d.ts
CHANGED
|
@@ -23,32 +23,46 @@ import type { TtscBunOptions } from "./TtscBunOptions";
|
|
|
23
23
|
* session, like Bun's own module cache; restart the process after changing
|
|
24
24
|
* compiler inputs.
|
|
25
25
|
*
|
|
26
|
+
* The `filter` option narrows the project modules the plugin transforms. A
|
|
27
|
+
* module it does not select is left to Bun like an excluded file, so
|
|
28
|
+
* `Bun.build` gets `undefined` and the runtime gets the original source and
|
|
29
|
+
* loader. The options, and with them the filter, are resolved by the first
|
|
30
|
+
* TypeScript module outside `node_modules`, so that module locks the runtime
|
|
31
|
+
* options whether or not the filter selects it.
|
|
32
|
+
*
|
|
26
33
|
* @evidence contracts/common.md#principled-implementation
|
|
27
34
|
* Host hook presence distinguishes a runtime session from bundler builds.
|
|
28
|
-
* Disk inputs enter the shared project transform;
|
|
29
|
-
*
|
|
35
|
+
* Disk inputs the filter selects enter the shared project transform;
|
|
36
|
+
* in-memory bundler entries and unselected modules remain Bun-owned, and
|
|
37
|
+
* runtime responses always retain the TypeScript parser.
|
|
30
38
|
* @evidence contracts/common.md#clear-and-simple-design
|
|
31
39
|
* Setup owns hooks and one cache; source inclusion, option normalization,
|
|
32
|
-
* compilation and source-map encoding remain delegated
|
|
40
|
+
* filter compilation, transformation and source-map encoding remain delegated
|
|
41
|
+
* to their shared owners.
|
|
33
42
|
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
34
|
-
* The runtime's original-source response implements Bun's required
|
|
35
|
-
* onLoad response. Hook absence and files
|
|
36
|
-
* not overlapping-loader patches or
|
|
43
|
+
* The runtime's original-source response implements Bun's required object
|
|
44
|
+
* onLoad response for every module left to Bun. Hook absence and files
|
|
45
|
+
* ownership are real host differences, not overlapping-loader patches or
|
|
46
|
+
* special treatment of fixture paths.
|
|
37
47
|
* @evidence contracts/common.md#meaningful-documentation
|
|
38
48
|
* Native paragraphs explain bundler/runtime responses, in-memory ownership,
|
|
39
|
-
* parser selection and process-session limits, following
|
|
49
|
+
* filter selection, parser selection and process-session limits, following
|
|
50
|
+
* documentation guidance.
|
|
40
51
|
* @evidence contracts/portability.md#os-neutral-implementation
|
|
41
52
|
* Node reads native delivered paths. Bun's in-memory key comparison separately
|
|
42
53
|
* models separator/drive-letter normalization on Windows while preserving
|
|
43
54
|
* component case and relative spelling rather than treating keys as disk paths.
|
|
44
55
|
* @evidence contracts/performance.md#efficient-algorithms
|
|
45
56
|
* A Set indexes F in-memory keys once at setup; a delivery performs a path-length
|
|
46
|
-
* lookup and reads S source bytes only for its disk input.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
57
|
+
* lookup and reads S source bytes only for its disk input. A module the
|
|
58
|
+
* filter skips costs one predicate call and a source read at runtime, and no
|
|
59
|
+
* transform. First project loads also normalize the option overlay.
|
|
60
|
+
* Delegated transform work includes cache identity/validation,
|
|
61
|
+
* input/directory/byte proofs, misses' native compile and source-map encoding;
|
|
62
|
+
* source-file length alone does not bound it.
|
|
50
63
|
* @evidence contracts/performance.md#reuse-equivalent-work
|
|
51
|
-
* The first
|
|
64
|
+
* The first project TypeScript load resolves options and compiles the filter
|
|
65
|
+
* once, and every later load reuses both. One cache shares a validated
|
|
52
66
|
* project generation across deliveries; bundler start/end boundaries reset
|
|
53
67
|
* delivery proof, while a runtime retains its immutable module-load session.
|
|
54
68
|
* Coherent local output with unavailable observation shares first deliveries
|
|
@@ -57,8 +71,8 @@ import type { TtscBunOptions } from "./TtscBunOptions";
|
|
|
57
71
|
* Setup snapshots the in-memory key population; changing host files/options
|
|
58
72
|
* is not authorized merely by an unchanged path or previously quiet callback.
|
|
59
73
|
* @evidence contracts/performance.md#bound-retention-and-release-resources
|
|
60
|
-
* Setup owns the F-key matcher, resolved options and project cache.
|
|
61
|
-
* end withdraws cached generations; it does not promise cancellation of an
|
|
74
|
+
* Setup owns the F-key matcher, resolved options, compiled filter and project cache.
|
|
75
|
+
* Bundler end withdraws cached generations; it does not promise cancellation of an
|
|
62
76
|
* already running native compile, and the host still owns setup closures.
|
|
63
77
|
* Runtime retention is intended for the process session because this branch
|
|
64
78
|
* has no teardown hook. Key/option/project bytes have no fixed package-wide cap.
|