@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.
Files changed (49) hide show
  1. package/README.md +11 -0
  2. package/lib/bun-register.d.cts +1 -0
  3. package/lib/bun-register.d.mts +1 -0
  4. package/lib/bun-register.d.ts +1 -0
  5. package/lib/bun-register.js.map +1 -1
  6. package/lib/bun-register.mjs.map +1 -1
  7. package/lib/bun.d.cts +1 -0
  8. package/lib/bun.d.mts +1 -0
  9. package/lib/bun.d.ts +1 -0
  10. package/lib/core/bun/BunRegistrationState.d.cts +6 -3
  11. package/lib/core/bun/BunRegistrationState.d.mts +6 -3
  12. package/lib/core/bun/BunRegistrationState.d.ts +6 -3
  13. package/lib/core/bun/TtscBunLoaderOptions.d.cts +68 -0
  14. package/lib/core/bun/TtscBunLoaderOptions.d.mts +68 -0
  15. package/lib/core/bun/TtscBunLoaderOptions.d.ts +68 -0
  16. package/lib/core/bun/TtscBunOptions.d.cts +2 -2
  17. package/lib/core/bun/TtscBunOptions.d.mts +2 -2
  18. package/lib/core/bun/TtscBunOptions.d.ts +2 -2
  19. package/lib/core/bun/bun.d.cts +28 -14
  20. package/lib/core/bun/bun.d.mts +28 -14
  21. package/lib/core/bun/bun.d.ts +28 -14
  22. package/lib/core/bun/bun.js +51 -18
  23. package/lib/core/bun/bun.js.map +1 -1
  24. package/lib/core/bun/bun.mjs +51 -18
  25. package/lib/core/bun/bun.mjs.map +1 -1
  26. package/lib/core/bun/createBunFilter.d.cts +42 -0
  27. package/lib/core/bun/createBunFilter.d.mts +42 -0
  28. package/lib/core/bun/createBunFilter.d.ts +42 -0
  29. package/lib/core/bun/createBunFilter.js +67 -0
  30. package/lib/core/bun/createBunFilter.js.map +1 -0
  31. package/lib/core/bun/createBunFilter.mjs +65 -0
  32. package/lib/core/bun/createBunFilter.mjs.map +1 -0
  33. package/lib/core/bun/register.d.cts +16 -7
  34. package/lib/core/bun/register.d.mts +16 -7
  35. package/lib/core/bun/register.d.ts +16 -7
  36. package/lib/core/bun/register.js +18 -5
  37. package/lib/core/bun/register.js.map +1 -1
  38. package/lib/core/bun/register.mjs +18 -5
  39. package/lib/core/bun/register.mjs.map +1 -1
  40. package/package.json +3 -3
  41. package/src/bun-register.ts +1 -0
  42. package/src/bun.ts +1 -0
  43. package/src/core/bun/BunRegistrationState.ts +6 -3
  44. package/src/core/bun/TtscBunLoaderOptions.ts +69 -0
  45. package/src/core/bun/TtscBunOptions.ts +3 -3
  46. package/src/core/bun/bun.ts +57 -21
  47. package/src/core/bun/createBunFilter.ts +64 -0
  48. package/src/core/bun/ensureRegistered.ts +2 -2
  49. package/src/core/bun/register.ts +22 -9
@@ -1,4 +1,4 @@
1
- import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions.mjs";
1
+ import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions.mjs";
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.mjs";
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, or when a different option value is supplied after
24
- * the first load. The import-time registration of the entry stays silent off
25
- * Bun so the module is harmless to import from Node (tests, tooling).
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. Before first
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.mjs";
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; a locked call additionally pays deep-comparison cost even when
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.mjs";
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?: TtscUnpluginOptions): void;
65
+ export declare function register(options?: TtscBunLoaderOptions): void;
@@ -1,4 +1,4 @@
1
- import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
1
+ import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
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";
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, or when a different option value is supplied after
24
- * the first load. The import-time registration of the entry stays silent off
25
- * Bun so the module is harmless to import from Node (tests, tooling).
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. Before first
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";
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; a locked call additionally pays deep-comparison cost even when
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";
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?: TtscUnpluginOptions): void;
65
+ export declare function register(options?: TtscBunLoaderOptions): void;
@@ -2,6 +2,7 @@
2
2
 
3
3
  var node_util = require('node:util');
4
4
  var bunRuntime = require('./bunRuntime.js');
5
+ var createBunFilter = require('./createBunFilter.js');
5
6
  var ensureRegistered = require('./ensureRegistered.js');
6
7
  var registrationState = require('./registrationState.js');
7
8
 
@@ -25,12 +26,20 @@ var registrationState = require('./registrationState.js');
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, or when a different option value is supplied after
30
- * the first load. The import-time registration of the entry stays silent off
31
- * Bun so the module is harmless to import from Node (tests, tooling).
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. Before first
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 @@ var registrationState = require('./registrationState.js');
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; a locked call additionally pays deep-comparison cost even when
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
@@ -68,6 +78,9 @@ function register(options) {
68
78
  }
69
79
  const state = registrationState.registrationState(runtime);
70
80
  const snapshot = snapshotOptions(options);
81
+ // Report an invalid filter to the call that supplied it, not to the first
82
+ // module load that happens to resolve the options.
83
+ createBunFilter.createBunFilter(snapshot?.filter);
71
84
  if (state.optionsLocked) {
72
85
  if (node_util.isDeepStrictEqual(snapshot, state.lockedOptions)) {
73
86
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","sources":["../../../src/core/bun/register.ts"],"sourcesContent":[null],"names":["bunRuntime","registrationState","isDeepStrictEqual","ensureRegistered"],"mappings":";;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDG;AACG,SAAU,QAAQ,CAAC,OAA6B,EAAA;AACpD,IAAA,MAAM,OAAO,GAAGA,qBAAU,EAAE;AAC5B,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,wEAAwE;AACxE,YAAA,6CAA6C,CAChD;IACH;AACA,IAAA,MAAM,KAAK,GAAGC,mCAAiB,CAAC,OAAO,CAAC;AACxC,IAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC;AACzC,IAAA,IAAI,KAAK,CAAC,aAAa,EAAE;QACvB,IAAIC,2BAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;YACpD;QACF;QACA,MAAM,IAAI,KAAK,CACb,qEAAqE;YACnE,mEAAmE;AACnE,YAAA,sDAAsD,CACzD;IACH;AACA,IAAA,KAAK,CAAC,aAAa,GAAG,QAAQ;AAC9B,IAAAC,iCAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;AAClC;AAEA;AACA,SAAS,eAAe,CACtB,OAAwC,EAAA;IAExC,IAAI,OAAO,KAAK,SAAS;AAAE,QAAA,OAAO,SAAS;AAC3C,IAAA,IAAI;AACF,QAAA,OAAO,eAAe,CAAC,OAAO,CAAC;IACjC;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,SAAS,CACjB,+EAA+E,EAC/E,EAAE,KAAK,EAAE,CACV;IACH;AACF;;;;"}
1
+ {"version":3,"file":"register.js","sources":["../../../src/core/bun/register.ts"],"sourcesContent":[null],"names":["bunRuntime","registrationState","createBunFilter","isDeepStrictEqual","ensureRegistered"],"mappings":";;;;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DG;AACG,SAAU,QAAQ,CAAC,OAA8B,EAAA;AACrD,IAAA,MAAM,OAAO,GAAGA,qBAAU,EAAE;AAC5B,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,wEAAwE;AACxE,YAAA,6CAA6C,CAChD;IACH;AACA,IAAA,MAAM,KAAK,GAAGC,mCAAiB,CAAC,OAAO,CAAC;AACxC,IAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC;;;AAGzC,IAAAC,+BAAe,CAAC,QAAQ,EAAE,MAAM,CAAC;AACjC,IAAA,IAAI,KAAK,CAAC,aAAa,EAAE;QACvB,IAAIC,2BAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;YACpD;QACF;QACA,MAAM,IAAI,KAAK,CACb,qEAAqE;YACnE,mEAAmE;AACnE,YAAA,sDAAsD,CACzD;IACH;AACA,IAAA,KAAK,CAAC,aAAa,GAAG,QAAQ;AAC9B,IAAAC,iCAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;AAClC;AAEA;AACA,SAAS,eAAe,CACtB,OAAyC,EAAA;IAEzC,IAAI,OAAO,KAAK,SAAS;AAAE,QAAA,OAAO,SAAS;AAC3C,IAAA,IAAI;AACF,QAAA,OAAO,eAAe,CAAC,OAAO,CAAC;IACjC;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,SAAS,CACjB,+EAA+E,EAC/E,EAAE,KAAK,EAAE,CACV;IACH;AACF;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { isDeepStrictEqual } from 'node:util';
2
2
  import { bunRuntime } from './bunRuntime.mjs';
3
+ import { createBunFilter } from './createBunFilter.mjs';
3
4
  import { ensureRegistered } from './ensureRegistered.mjs';
4
5
  import { registrationState } from './registrationState.mjs';
5
6
 
@@ -23,12 +24,20 @@ import { registrationState } from './registrationState.mjs';
23
24
  * are idempotent; a different value throws rather than pretending a resolved
24
25
  * loader changed configuration.
25
26
  *
27
+ * The `filter` option selects the project modules ttsc transforms and is
28
+ * described by `TtscBunLoaderOptions`. It is an ordinary option for snapshots,
29
+ * so a later call with an equal filter is idempotent. The first TypeScript
30
+ * module outside `node_modules` locks the snapshot whether or not the filter
31
+ * selects it.
32
+ *
26
33
  * @throws When called explicitly off the Bun runtime, when options are not
27
- * structured-cloneable, or when a different option value is supplied after
28
- * the first load. The import-time registration of the entry stays silent off
29
- * Bun so the module is harmless to import from Node (tests, tooling).
34
+ * structured-cloneable, when `filter` holds a value that is not a RegExp, or
35
+ * when a different option value is supplied after the first load. The
36
+ * import-time registration of the entry stays silent off Bun so the module is
37
+ * harmless to import from Node (tests, tooling).
30
38
  * @evidence contracts/common.md#principled-implementation
31
- * Structured cloning captures option values before installation. Before first
39
+ * Structured cloning captures option values before installation, including
40
+ * each filter pattern with its match position reset. Before first
32
41
  * load the pending snapshot is replaceable; afterward deep equality permits
33
42
  * only idempotent calls, matching the immutable runtime module session.
34
43
  * @evidence contracts/common.md#clear-and-simple-design
@@ -44,7 +53,8 @@ import { registrationState } from './registrationState.mjs';
44
53
  * Performs no filesystem, path or process operation of its own.
45
54
  * @evidence contracts/performance.md#efficient-algorithms
46
55
  * structuredClone follows the supplied option graph and allocates its detached
47
- * snapshot; a locked call additionally pays deep-comparison cost even when
56
+ * snapshot; filter validation copies its P patterns once and discards them.
57
+ * A locked call additionally pays deep-comparison cost even when
48
58
  * idempotent. First installation delegates plugin construction/setup to
49
59
  * ensureRegistered and the host. Fixed entry-point branches do not erase these costs.
50
60
  * @evidence contracts/performance.md#reuse-equivalent-work
@@ -66,6 +76,9 @@ function register(options) {
66
76
  }
67
77
  const state = registrationState(runtime);
68
78
  const snapshot = snapshotOptions(options);
79
+ // Report an invalid filter to the call that supplied it, not to the first
80
+ // module load that happens to resolve the options.
81
+ createBunFilter(snapshot?.filter);
69
82
  if (state.optionsLocked) {
70
83
  if (isDeepStrictEqual(snapshot, state.lockedOptions)) {
71
84
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"register.mjs","sources":["../../../src/core/bun/register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDG;AACG,SAAU,QAAQ,CAAC,OAA6B,EAAA;AACpD,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE;AAC5B,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,wEAAwE;AACxE,YAAA,6CAA6C,CAChD;IACH;AACA,IAAA,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC;AACxC,IAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC;AACzC,IAAA,IAAI,KAAK,CAAC,aAAa,EAAE;QACvB,IAAI,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;YACpD;QACF;QACA,MAAM,IAAI,KAAK,CACb,qEAAqE;YACnE,mEAAmE;AACnE,YAAA,sDAAsD,CACzD;IACH;AACA,IAAA,KAAK,CAAC,aAAa,GAAG,QAAQ;AAC9B,IAAA,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;AAClC;AAEA;AACA,SAAS,eAAe,CACtB,OAAwC,EAAA;IAExC,IAAI,OAAO,KAAK,SAAS;AAAE,QAAA,OAAO,SAAS;AAC3C,IAAA,IAAI;AACF,QAAA,OAAO,eAAe,CAAC,OAAO,CAAC;IACjC;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,SAAS,CACjB,+EAA+E,EAC/E,EAAE,KAAK,EAAE,CACV;IACH;AACF;;;;"}
1
+ {"version":3,"file":"register.mjs","sources":["../../../src/core/bun/register.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DG;AACG,SAAU,QAAQ,CAAC,OAA8B,EAAA;AACrD,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE;AAC5B,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CACb,6DAA6D;YAC3D,wEAAwE;AACxE,YAAA,6CAA6C,CAChD;IACH;AACA,IAAA,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC;AACxC,IAAA,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC;;;AAGzC,IAAA,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC;AACjC,IAAA,IAAI,KAAK,CAAC,aAAa,EAAE;QACvB,IAAI,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;YACpD;QACF;QACA,MAAM,IAAI,KAAK,CACb,qEAAqE;YACnE,mEAAmE;AACnE,YAAA,sDAAsD,CACzD;IACH;AACA,IAAA,KAAK,CAAC,aAAa,GAAG,QAAQ;AAC9B,IAAA,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC;AAClC;AAEA;AACA,SAAS,eAAe,CACtB,OAAyC,EAAA;IAEzC,IAAI,OAAO,KAAK,SAAS;AAAE,QAAA,OAAO,SAAS;AAC3C,IAAA,IAAI;AACF,QAAA,OAAO,eAAe,CAAC,OAAO,CAAC;IACjC;IAAE,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,SAAS,CACjB,+EAA+E,EAC/E,EAAE,KAAK,EAAE,CACV;IACH;AACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttsc/unplugin",
3
- "version": "0.37.1",
3
+ "version": "0.38.0",
4
4
  "description": "Bundler adapters for ttsc plugins.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",
@@ -202,7 +202,7 @@
202
202
  "fsevents": "^2.3.3"
203
203
  },
204
204
  "peerDependencies": {
205
- "ttsc": "^0.37.1"
205
+ "ttsc": "^0.38.0"
206
206
  },
207
207
  "devDependencies": {
208
208
  "@wrtnlabs/evidence": "^0.5.1",
@@ -218,7 +218,7 @@
218
218
  "typescript": "^7.0.2",
219
219
  "vite": "^7.3.5",
220
220
  "vite8": "npm:vite@^8.3.4",
221
- "ttsc": "0.37.1"
221
+ "ttsc": "0.38.0"
222
222
  },
223
223
  "repository": {
224
224
  "type": "git",
@@ -3,6 +3,7 @@ import { ensureRegistered } from "./core/bun/ensureRegistered";
3
3
  import { registrationState } from "./core/bun/registrationState";
4
4
 
5
5
  export { register, register as default } from "./core/bun/register";
6
+ export type { TtscBunLoaderOptions } from "./core/bun/TtscBunLoaderOptions";
6
7
 
7
8
  // Auto-register on import so a `bunfig.toml` `preload` entry — which only
8
9
  // imports the module — takes effect. The side effect lives in this entry, not
package/src/bun.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 { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
1
+ import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
2
2
 
3
3
  /**
4
4
  * The single runtime loader's registration and option lifecycle for one Bun
@@ -9,6 +9,9 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
9
9
  * for this state's runtime session. Host-owned memory files are passed over
10
10
  * before locking options.
11
11
  *
12
+ * The `filter` option is part of the snapshot, so a project module the filter
13
+ * skips still locks the options when it is the first one loaded.
14
+ *
12
15
  * @evidence contracts/common.md#principled-implementation
13
16
  * Pending and locked snapshots distinguish pre-load replacement from the
14
17
  * immutable module-loading session; registered separately tracks installation.
@@ -39,10 +42,10 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
39
42
  */
40
43
  export interface BunRegistrationState {
41
44
  /** Options the next lock takes, detached from the caller's object. */
42
- activeOptions: TtscUnpluginOptions | undefined;
45
+ activeOptions: TtscBunLoaderOptions | undefined;
43
46
 
44
47
  /** Options the loader resolved with, once `optionsLocked` holds. */
45
- lockedOptions: TtscUnpluginOptions | undefined;
48
+ lockedOptions: TtscBunLoaderOptions | undefined;
46
49
 
47
50
  /** Whether a load has started, which fixes `lockedOptions` for good. */
48
51
  optionsLocked: boolean;
@@ -0,0 +1,69 @@
1
+ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
2
+
3
+ /**
4
+ * Options of the Bun loader: the shared adapter options plus `filter`, which
5
+ * chooses the modules to transform.
6
+ *
7
+ * `Bun.plugin()` and a `bunfig.toml` preload have no include or exclude rules
8
+ * of their own, so the loader takes that choice itself. The shared options stay
9
+ * free of a member the other adapters would ignore.
10
+ *
11
+ * @evidence contracts/common.md#principled-implementation
12
+ * Bun's own `onLoad` selects modules with a RegExp, so one pattern
13
+ * or a list of alternatives expresses the choice, and patterns only narrow
14
+ * the modules the loader already includes.
15
+ * @evidence contracts/common.md#clear-and-simple-design
16
+ * The member sits on the adapter that honors it, and the shared options
17
+ * type is unchanged, so no other adapter accepts and ignores a filter.
18
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts
19
+ * The member selects modules by path pattern for every consumer. It names
20
+ * no fixture or consumer and compensates for no defect.
21
+ * @evidence contracts/common.md#meaningful-documentation
22
+ * The member comment states, each as its own paragraph, the skipped-module
23
+ * behavior, the empty-list meaning and narrowing, the matched path spelling,
24
+ * the case policy and flag behavior, and the option-lock effect, and shows
25
+ * one example.
26
+ * @evidence contracts/portability.md#os-neutral-implementation
27
+ * Patterns are tested against a separator-normalized spelling,
28
+ * which is matching syntax and not filesystem identity.
29
+ * The type learns no platform capability and sets no case policy.
30
+ * @evidenceExclude contracts/performance.md#efficient-algorithms
31
+ * The interface declares a shape and performs no computation.
32
+ * @evidenceExclude contracts/performance.md#reuse-equivalent-work
33
+ * The interface declares a shape and has no work to reuse.
34
+ * @evidenceExclude contracts/performance.md#bound-retention-and-release-resources
35
+ * The interface declares a shape and holds no handle or state.
36
+ */
37
+ export interface TtscBunLoaderOptions extends TtscUnpluginOptions {
38
+ /**
39
+ * Restricts ttsc to the modules whose absolute path matches a pattern.
40
+ *
41
+ * A module that no pattern matches is skipped: Bun loads it as it would
42
+ * without ttsc, so no ttsc plugin runs on it.
43
+ *
44
+ * Omitting the member or passing an empty array applies no restriction. A
45
+ * pattern only narrows what ttsc already transforms: `node_modules`,
46
+ * declaration files and entries supplied through `Bun.build({ files })` stay
47
+ * with Bun whether or not a pattern matches them.
48
+ *
49
+ * A pattern is tested against the absolute path, such as
50
+ * `/home/me/app/src/validators/email.ts`, and not against an import
51
+ * specifier. The path is tested with each `\` written as `/`, so a pattern
52
+ * written with `/` behaves the same on every OS. A Windows path starts with
53
+ * its drive, as in `C:/app/src/validators/email.ts`, so match part of the
54
+ * path and do not anchor on a leading `/`.
55
+ *
56
+ * Matching is case-sensitive, so add the `i` flag on a case-insensitive
57
+ * filesystem. The `g` and `y` flags are safe to use, since no state carries
58
+ * from one module to the next.
59
+ *
60
+ * Under `register`, the first TypeScript module outside `node_modules` that
61
+ * loads locks the options, `filter` included, even if no pattern matches that
62
+ * module. A later call with different options throws.
63
+ *
64
+ * @example
65
+ * // Transform the modules in src/validators and the *.schema.ts files.
66
+ * register({ filter: [/\/src\/validators\//, /\.schema\.ts$/] });
67
+ */
68
+ filter?: RegExp | readonly RegExp[];
69
+ }
@@ -1,4 +1,4 @@
1
- import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
1
+ import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
2
2
 
3
3
  /**
4
4
  * Options accepted by `bun`, either resolved eagerly or supplied through a
@@ -37,5 +37,5 @@ import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
37
37
  * this union acquires no resource or historical state itself.
38
38
  */
39
39
  export type TtscBunOptions =
40
- | TtscUnpluginOptions
41
- | (() => TtscUnpluginOptions | undefined);
40
+ | TtscBunLoaderOptions
41
+ | (() => TtscBunLoaderOptions | undefined);
@@ -1,7 +1,6 @@
1
1
  import fs from "node:fs/promises";
2
2
 
3
3
  import { isTransformTarget } from "../isTransformTarget";
4
- import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
5
4
  import { resolveOptions } from "../options/resolveOptions";
6
5
  import { bunTypeScriptTransformSourcePattern } from "../source/bunTypeScriptTransformSourcePattern";
7
6
  import { typescriptTransformBunLoader } from "../source/typescriptTransformBunLoader";
@@ -13,12 +12,14 @@ import { inlineSourceMap } from "../transform/utils/inlineSourceMap";
13
12
  import type { BunLikeBuild } from "./BunLikeBuild";
14
13
  import type { BunLikePlugin } from "./BunLikePlugin";
15
14
  import type { BunLoader } from "./BunLoader";
15
+ import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
16
16
  import type { TtscBunOptions } from "./TtscBunOptions";
17
+ import { createBunFilter } from "./createBunFilter";
17
18
 
18
19
  /** Resolve {@link TtscBunOptions} to a plain options object (or `undefined`). */
19
20
  function resolveBunOptions(
20
21
  options?: TtscBunOptions,
21
- ): TtscUnpluginOptions | undefined {
22
+ ): TtscBunLoaderOptions | undefined {
22
23
  return typeof options === "function" ? options() : options;
23
24
  }
24
25
 
@@ -45,32 +46,46 @@ function resolveBunOptions(
45
46
  * session, like Bun's own module cache; restart the process after changing
46
47
  * compiler inputs.
47
48
  *
49
+ * The `filter` option narrows the project modules the plugin transforms. A
50
+ * module it does not select is left to Bun like an excluded file, so
51
+ * `Bun.build` gets `undefined` and the runtime gets the original source and
52
+ * loader. The options, and with them the filter, are resolved by the first
53
+ * TypeScript module outside `node_modules`, so that module locks the runtime
54
+ * options whether or not the filter selects it.
55
+ *
48
56
  * @evidence contracts/common.md#principled-implementation
49
57
  * Host hook presence distinguishes a runtime session from bundler builds.
50
- * Disk inputs enter the shared project transform; in-memory bundler entries
51
- * remain Bun-owned, and runtime responses always retain the TypeScript parser.
58
+ * Disk inputs the filter selects enter the shared project transform;
59
+ * in-memory bundler entries and unselected modules remain Bun-owned, and
60
+ * runtime responses always retain the TypeScript parser.
52
61
  * @evidence contracts/common.md#clear-and-simple-design
53
62
  * Setup owns hooks and one cache; source inclusion, option normalization,
54
- * compilation and source-map encoding remain delegated to their shared owners.
63
+ * filter compilation, transformation and source-map encoding remain delegated
64
+ * to their shared owners.
55
65
  * @evidence contracts/common.md#prohibited-implementation-shortcuts
56
- * The runtime's original-source response implements Bun's required nonempty
57
- * onLoad response. Hook absence and files ownership are real host differences,
58
- * not overlapping-loader patches or special treatment of fixture paths.
66
+ * The runtime's original-source response implements Bun's required object
67
+ * onLoad response for every module left to Bun. Hook absence and files
68
+ * ownership are real host differences, not overlapping-loader patches or
69
+ * special treatment of fixture paths.
59
70
  * @evidence contracts/common.md#meaningful-documentation
60
71
  * Native paragraphs explain bundler/runtime responses, in-memory ownership,
61
- * parser selection and process-session limits, following documentation guidance.
72
+ * filter selection, parser selection and process-session limits, following
73
+ * documentation guidance.
62
74
  * @evidence contracts/portability.md#os-neutral-implementation
63
75
  * Node reads native delivered paths. Bun's in-memory key comparison separately
64
76
  * models separator/drive-letter normalization on Windows while preserving
65
77
  * component case and relative spelling rather than treating keys as disk paths.
66
78
  * @evidence contracts/performance.md#efficient-algorithms
67
79
  * A Set indexes F in-memory keys once at setup; a delivery performs a path-length
68
- * lookup and reads S source bytes only for its disk input. First included
69
- * loads also normalize the option overlay. Delegated transform work includes
70
- * cache identity/validation, input/directory/byte proofs, misses' native compile
71
- * and source-map encoding; source-file length alone does not bound it.
80
+ * lookup and reads S source bytes only for its disk input. A module the
81
+ * filter skips costs one predicate call and a source read at runtime, and no
82
+ * transform. First project loads also normalize the option overlay.
83
+ * Delegated transform work includes cache identity/validation,
84
+ * input/directory/byte proofs, misses' native compile and source-map encoding;
85
+ * source-file length alone does not bound it.
72
86
  * @evidence contracts/performance.md#reuse-equivalent-work
73
- * The first included transformable load resolves options once. One cache shares a validated
87
+ * The first project TypeScript load resolves options and compiles the filter
88
+ * once, and every later load reuses both. One cache shares a validated
74
89
  * project generation across deliveries; bundler start/end boundaries reset
75
90
  * delivery proof, while a runtime retains its immutable module-load session.
76
91
  * Coherent local output with unavailable observation shares first deliveries
@@ -79,8 +94,8 @@ function resolveBunOptions(
79
94
  * Setup snapshots the in-memory key population; changing host files/options
80
95
  * is not authorized merely by an unchanged path or previously quiet callback.
81
96
  * @evidence contracts/performance.md#bound-retention-and-release-resources
82
- * Setup owns the F-key matcher, resolved options and project cache. Bundler
83
- * end withdraws cached generations; it does not promise cancellation of an
97
+ * Setup owns the F-key matcher, resolved options, compiled filter and project cache.
98
+ * Bundler end withdraws cached generations; it does not promise cancellation of an
84
99
  * already running native compile, and the host still owns setup closures.
85
100
  * Runtime retention is intended for the process session because this branch
86
101
  * has no teardown hook. Key/option/project bytes have no fixed package-wide cap.
@@ -92,10 +107,24 @@ export function bun(options?: TtscBunOptions): BunLikePlugin {
92
107
  // Resolve options lazily on the first transformable TypeScript load.
93
108
  // Runtime registration may replace its pending configuration at any time
94
109
  // before then; the provider form must observe that last update without
95
- // installing a second shadowing loader.
96
- let resolved: ReturnType<typeof resolveOptions> | undefined;
97
- const getOptions = () =>
98
- (resolved ??= resolveOptions(resolveBunOptions(options)));
110
+ // installing a second shadowing loader. The filter belongs to those
111
+ // options, so it is compiled in the same step and never read earlier.
112
+ let session:
113
+ | {
114
+ options: ReturnType<typeof resolveOptions>;
115
+ accepts: ((file: string) => boolean) | undefined;
116
+ }
117
+ | undefined;
118
+ const getSession = () => {
119
+ if (session === undefined) {
120
+ const supplied = resolveBunOptions(options);
121
+ session = {
122
+ options: resolveOptions(supplied),
123
+ accepts: createBunFilter(supplied?.filter),
124
+ };
125
+ }
126
+ return session;
127
+ };
99
128
  const cache = createTtscTransformCache();
100
129
  const runtime = build.onStart === undefined;
101
130
  const ownsInMemoryFile = createBunInMemoryFileMatcher(build);
@@ -125,7 +154,14 @@ export function bun(options?: TtscBunOptions): BunLikePlugin {
125
154
  };
126
155
  }
127
156
  const loader = bunLoaderFor(args.path);
128
- const transformOptions = getOptions();
157
+ const { options: transformOptions, accepts } = getSession();
158
+ if (accepts !== undefined && !accepts(args.path)) {
159
+ if (!runtime) return undefined;
160
+ return {
161
+ contents: await fs.readFile(args.path, "utf8"),
162
+ loader: bunLoaderFor(args.path),
163
+ };
164
+ }
129
165
  const source = await fs.readFile(args.path, "utf8");
130
166
  // Bun has no dependency subscription API or reusable build result
131
167
  // cache. Builds are one-shot; runtime registration owns one immutable
@@ -0,0 +1,64 @@
1
+ import { normalizePath } from "../transform/filesystem/normalizePath";
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
+ export function createBunFilter(
45
+ filter: RegExp | readonly RegExp[] | undefined,
46
+ ): ((path: string) => boolean) | undefined {
47
+ if (filter === undefined) return undefined;
48
+ const supplied: unknown[] = [filter].flat();
49
+ if (supplied.length === 0) return undefined;
50
+ const patterns = supplied.map((pattern) => {
51
+ if (!(pattern instanceof RegExp))
52
+ throw new TypeError(
53
+ "@ttsc/unplugin filter must be a RegExp or an array of RegExp.",
54
+ );
55
+ return new RegExp(pattern);
56
+ });
57
+ return (path) => {
58
+ const spelling = normalizePath(path);
59
+ return patterns.some((pattern) => {
60
+ pattern.lastIndex = 0;
61
+ return pattern.test(spelling);
62
+ });
63
+ };
64
+ }
@@ -1,6 +1,6 @@
1
- import type { TtscUnpluginOptions } from "../options/TtscUnpluginOptions";
2
1
  import type { BunRegistrationState } from "./BunRegistrationState";
3
2
  import type { BunRuntimeGlobal } from "./BunRuntimeGlobal";
3
+ import type { TtscBunLoaderOptions } from "./TtscBunLoaderOptions";
4
4
  import { bun } from "./bun";
5
5
 
6
6
  /**
@@ -60,7 +60,7 @@ export function ensureRegistered(
60
60
  /** Lock and return the detached option snapshot at first load-handler entry. */
61
61
  function lockOptions(
62
62
  state: BunRegistrationState,
63
- ): TtscUnpluginOptions | undefined {
63
+ ): TtscBunLoaderOptions | undefined {
64
64
  if (!state.optionsLocked) {
65
65
  state.lockedOptions = state.activeOptions;
66
66
  state.optionsLocked = true;