@elliots/bun-plugin-typical 0.2.3 → 0.2.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elliot Shepherd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.mts CHANGED
@@ -1,130 +1,58 @@
1
+ import { TypicalConfig } from "@elliots/typical";
1
2
  import { BunPlugin } from "bun";
2
3
 
3
- //#region ../../dist/src/config.d.ts
4
- interface TypicalDebugConfig {
5
- writeIntermediateFiles?: boolean;
6
- }
7
- /**
8
- * Configuration options for source map generation.
9
- */
10
- interface TypicalSourceMapConfig {
11
- /**
12
- * Generate source maps. Default: true
13
- */
14
- enabled?: boolean;
15
- /**
16
- * Include original source content in the map. Default: true
17
- */
18
- includeContent?: boolean;
19
- /**
20
- * Use inline source maps (data URL) instead of external files. Default: false
21
- */
22
- inline?: boolean;
23
- }
24
- interface TypicalConfig {
25
- include?: string[];
26
- exclude?: string[];
27
- /**
28
- * Controls whether validators are hoisted to module scope for reuse.
29
- * - 'auto' (default): Hoist only validators used more than once
30
- * - 'never': Never hoist, always generate inline validators
31
- * - 'always': Always hoist validators, even if only used once
32
- */
33
- reusableValidators?: 'auto' | 'never' | 'always';
34
- validateCasts?: boolean;
35
- hoistRegex?: boolean;
36
- debug?: TypicalDebugConfig;
37
- /**
38
- * Type patterns to skip validation for (supports wildcards).
39
- * Use this for types that typia cannot process (e.g., React event types).
40
- * Example: ["React.*", "Express.Request", "*.Event"]
41
- */
42
- ignoreTypes?: string[];
43
- /**
44
- * Validate function parameters and return types at runtime.
45
- * When enabled, typed function parameters get runtime validation calls injected.
46
- * Default: true
47
- */
48
- validateFunctions?: boolean;
4
+ //#region src/core/options.d.ts
5
+ interface Options {
49
6
  /**
50
- * Transform JSON.parse<T>() calls to validate and filter the parsed result
51
- * to only include properties defined in type T.
52
- * Default: true
7
+ * Bun plugin target.
8
+ * @default 'bun'
53
9
  */
54
- transformJSONParse?: boolean;
10
+ target?: "bun" | "browser" | "node";
55
11
  /**
56
- * Transform JSON.stringify<T>() calls to only stringify properties defined
57
- * in type T, preventing accidental data leaks.
58
- * Default: true
12
+ * Patterns to include for transformation.
13
+ * If empty, all TypeScript files are included.
59
14
  */
60
- transformJSONStringify?: boolean;
15
+ include?: (string | RegExp)[];
61
16
  /**
62
- * Source map generation settings.
63
- * Controls whether and how source maps are generated for transformed code.
17
+ * Patterns to exclude from transformation.
64
18
  */
65
- sourceMap?: TypicalSourceMapConfig;
19
+ exclude?: (string | RegExp)[];
66
20
  /**
67
- * Maximum number of helper functions (_io0, _io1, etc.) that can be generated
68
- * for a single type before erroring. Complex DOM types or library types can
69
- * generate hundreds of functions which indicates a type that should be excluded.
70
- * Set to 0 to disable the limit.
71
- * Default: 50
21
+ * Typical configuration overrides.
72
22
  */
73
- maxGeneratedFunctions?: number;
74
- }
75
- //#endregion
76
- //#region src/core/options.d.ts
77
- type FilterPattern = string | RegExp | (string | RegExp)[];
78
- interface Options {
79
- /**
80
- * Files to include. Defaults to all .ts/.tsx/.mts/.cts files.
81
- */
82
- include?: FilterPattern;
83
- /**
84
- * Files to exclude. Defaults to node_modules.
85
- */
86
- exclude?: FilterPattern;
87
- /**
88
- * Bun target environment.
89
- * @default 'bun'
90
- */
91
- target?: "bun" | "browser" | "node";
92
- /**
93
- * Typical configuration overrides.
94
- */
95
23
  typical?: Partial<TypicalConfig>;
96
24
  }
97
25
  //#endregion
98
26
  //#region src/core/transform.d.ts
99
27
  /**
100
- * Close the shared transformer and release resources.
101
- */
28
+ * Close the shared transformer and release resources.
29
+ */
102
30
  declare function closeTransformer(): Promise<void>;
103
31
  //#endregion
104
32
  //#region src/index.d.ts
105
33
  /**
106
- * Create a Bun plugin for Typical transformation.
107
- *
108
- * @example
109
- * ```ts
110
- * // For Bun.build()
111
- * import typicalPlugin from '@elliots/bun-plugin-typical'
112
- *
113
- * await Bun.build({
114
- * entrypoints: ['./src/index.ts'],
115
- * outdir: './dist',
116
- * plugins: [typicalPlugin()],
117
- * })
118
- * ```
119
- *
120
- * @example
121
- * ```ts
122
- * // For runtime (bunfig.toml preload)
123
- * import typicalPlugin from '@elliots/bun-plugin-typical'
124
- *
125
- * Bun.plugin(typicalPlugin())
126
- * ```
127
- */
34
+ * Create a Bun plugin for Typical transformation.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * // For Bun.build()
39
+ * import typicalPlugin from '@elliots/bun-plugin-typical'
40
+ *
41
+ * await Bun.build({
42
+ * entrypoints: ['./src/index.ts'],
43
+ * outdir: './dist',
44
+ * plugins: [typicalPlugin()],
45
+ * })
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * // For runtime (bunfig.toml preload)
51
+ * import typicalPlugin from '@elliots/bun-plugin-typical'
52
+ *
53
+ * Bun.plugin(typicalPlugin())
54
+ * ```
55
+ */
128
56
  declare function typicalPlugin(rawOptions?: Options): BunPlugin;
129
57
  //#endregion
130
58
  export { type Options, closeTransformer, typicalPlugin as default, typicalPlugin };
package/dist/index.mjs CHANGED
@@ -1,3 +1,123 @@
1
- import { n as typicalPlugin, r as closeTransformer, t as src_default } from "./src-CBBPzozy.mjs";
1
+ import { TypicalTransformer, buildTimer, loadConfig, validateConfig } from "@elliots/typical";
2
+ import { extname, resolve } from "path";
2
3
 
4
+ //#region src/core/options.ts
5
+ /**
6
+ * Resolve plugin options with defaults.
7
+ */
8
+ function resolveOptions(options = {}) {
9
+ return {
10
+ target: options.target ?? "bun",
11
+ include: options.include ?? [],
12
+ exclude: options.exclude ?? [/node_modules/],
13
+ typical: options.typical ?? {}
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ //#region src/core/transform.ts
19
+ const TRANSFORM_EXTENSIONS = new Set([
20
+ ".ts",
21
+ ".tsx",
22
+ ".mts",
23
+ ".cts"
24
+ ]);
25
+ const LOADER_MAP = {
26
+ ".ts": "ts",
27
+ ".mts": "ts",
28
+ ".cts": "ts",
29
+ ".tsx": "tsx"
30
+ };
31
+ let sharedTransformer = null;
32
+ /**
33
+ * Transform a TypeScript file with Typical.
34
+ *
35
+ * Returns TypeScript code with validation injected.
36
+ * Bun handles the final transpilation to JavaScript.
37
+ */
38
+ async function transformFile(filePath, config) {
39
+ buildTimer.start("total-transform");
40
+ const ext = extname(filePath).toLowerCase();
41
+ if (!TRANSFORM_EXTENSIONS.has(ext)) {
42
+ buildTimer.end("total-transform");
43
+ return;
44
+ }
45
+ const resolvedPath = resolve(filePath);
46
+ buildTimer.start("create-transformer");
47
+ if (!sharedTransformer) sharedTransformer = new TypicalTransformer(validateConfig(config));
48
+ buildTimer.end("create-transformer");
49
+ buildTimer.start("transform");
50
+ const result = await sharedTransformer.transform(resolvedPath, "ts");
51
+ buildTimer.end("transform");
52
+ buildTimer.end("total-transform");
53
+ if (process.env.DEBUG) console.log(`[bun-plugin-typical] Transformed: ${filePath}`);
54
+ return {
55
+ code: result.code,
56
+ loader: LOADER_MAP[ext] ?? "ts"
57
+ };
58
+ }
59
+ /**
60
+ * Close the shared transformer and release resources.
61
+ */
62
+ async function closeTransformer() {
63
+ if (sharedTransformer) {
64
+ await sharedTransformer.close();
65
+ sharedTransformer = null;
66
+ }
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/index.ts
71
+ const TS_FILTER = /\.(ts|tsx|mts|cts)$/;
72
+ /**
73
+ * Create a Bun plugin for Typical transformation.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * // For Bun.build()
78
+ * import typicalPlugin from '@elliots/bun-plugin-typical'
79
+ *
80
+ * await Bun.build({
81
+ * entrypoints: ['./src/index.ts'],
82
+ * outdir: './dist',
83
+ * plugins: [typicalPlugin()],
84
+ * })
85
+ * ```
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * // For runtime (bunfig.toml preload)
90
+ * import typicalPlugin from '@elliots/bun-plugin-typical'
91
+ *
92
+ * Bun.plugin(typicalPlugin())
93
+ * ```
94
+ */
95
+ function typicalPlugin(rawOptions = {}) {
96
+ const options = resolveOptions(rawOptions);
97
+ const typicalConfig = {
98
+ ...loadConfig(),
99
+ ...options.typical
100
+ };
101
+ return {
102
+ name: "bun-plugin-typical",
103
+ target: options.target,
104
+ setup(build) {
105
+ buildTimer.reset();
106
+ build.onLoad({ filter: TS_FILTER }, async (args) => {
107
+ if (options.exclude.some((pattern) => typeof pattern === "string" ? args.path.includes(pattern) : pattern.test(args.path))) return;
108
+ if (options.include.length > 0 && !options.include.some((pattern) => typeof pattern === "string" ? args.path.includes(pattern) : pattern.test(args.path))) return;
109
+ const result = await transformFile(args.path, typicalConfig);
110
+ if (!result) return;
111
+ if (process.env.DEBUG) buildTimer.report("[bun-plugin-typical]");
112
+ return {
113
+ contents: result.code,
114
+ loader: result.loader
115
+ };
116
+ });
117
+ }
118
+ };
119
+ }
120
+ var src_default = typicalPlugin;
121
+
122
+ //#endregion
3
123
  export { closeTransformer, src_default as default, typicalPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliots/bun-plugin-typical",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Bun plugin for typical - runtime safe TypeScript transformer",
5
5
  "keywords": [
6
6
  "bun",
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@elliots/typical": "0.2.3"
39
+ "@elliots/typical": "0.2.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/bun": "^1.0.0",
@@ -1 +0,0 @@
1
- export { };
package/dist/preload.mjs DELETED
@@ -1,34 +0,0 @@
1
- import { n as typicalPlugin } from "./src-CBBPzozy.mjs";
2
-
3
- //#region src/preload.ts
4
- /**
5
- * Convenience module for preloading the Typical plugin.
6
- *
7
- * @example
8
- * ```toml
9
- * # bunfig.toml
10
- * preload = ["./preload.ts"]
11
- * ```
12
- *
13
- * @example
14
- * ```ts
15
- * // preload.ts
16
- * import '@elliots/bun-plugin-typical/preload'
17
- * ```
18
- *
19
- * Or with custom options:
20
- * ```ts
21
- * // preload.ts
22
- * import { typicalPlugin } from '@elliots/bun-plugin-typical'
23
- *
24
- * Bun.plugin(typicalPlugin({
25
- * typical: {
26
- * reusableValidators: true,
27
- * }
28
- * }))
29
- * ```
30
- */
31
- Bun.plugin(typicalPlugin());
32
-
33
- //#endregion
34
- export { };
@@ -1,125 +0,0 @@
1
- import { TypicalTransformer, buildTimer, loadConfig, validateConfig } from "@elliots/typical";
2
- import { extname, resolve } from "path";
3
-
4
- //#region src/core/options.ts
5
- function normalizePattern(pattern) {
6
- if (!pattern) return [];
7
- if (Array.isArray(pattern)) return pattern;
8
- return [pattern];
9
- }
10
- function resolveOptions(options) {
11
- return {
12
- include: normalizePattern(options.include),
13
- exclude: options.exclude ? normalizePattern(options.exclude) : [/node_modules/],
14
- target: options.target ?? "bun",
15
- typical: options.typical
16
- };
17
- }
18
-
19
- //#endregion
20
- //#region src/core/transform.ts
21
- const TRANSFORM_EXTENSIONS = new Set([
22
- ".ts",
23
- ".tsx",
24
- ".mts",
25
- ".cts"
26
- ]);
27
- const LOADER_MAP = {
28
- ".ts": "ts",
29
- ".mts": "ts",
30
- ".cts": "ts",
31
- ".tsx": "tsx"
32
- };
33
- let sharedTransformer = null;
34
- /**
35
- * Transform a TypeScript file with Typical.
36
- *
37
- * Returns TypeScript code with validation injected.
38
- * Bun handles the final transpilation to JavaScript.
39
- */
40
- async function transformFile(filePath, config) {
41
- buildTimer.start("total-transform");
42
- const ext = extname(filePath).toLowerCase();
43
- if (!TRANSFORM_EXTENSIONS.has(ext)) {
44
- buildTimer.end("total-transform");
45
- return;
46
- }
47
- const resolvedPath = resolve(filePath);
48
- buildTimer.start("create-transformer");
49
- if (!sharedTransformer) sharedTransformer = new TypicalTransformer(validateConfig(config));
50
- buildTimer.end("create-transformer");
51
- buildTimer.start("transform");
52
- const result = await sharedTransformer.transform(resolvedPath, "ts");
53
- buildTimer.end("transform");
54
- buildTimer.end("total-transform");
55
- if (process.env.DEBUG) console.log(`[bun-plugin-typical] Transformed: ${filePath}`);
56
- return {
57
- code: result.code,
58
- loader: LOADER_MAP[ext] ?? "ts"
59
- };
60
- }
61
- /**
62
- * Close the shared transformer and release resources.
63
- */
64
- async function closeTransformer() {
65
- if (sharedTransformer) {
66
- await sharedTransformer.close();
67
- sharedTransformer = null;
68
- }
69
- }
70
-
71
- //#endregion
72
- //#region src/index.ts
73
- const TS_FILTER = /\.(ts|tsx|mts|cts)$/;
74
- /**
75
- * Create a Bun plugin for Typical transformation.
76
- *
77
- * @example
78
- * ```ts
79
- * // For Bun.build()
80
- * import typicalPlugin from '@elliots/bun-plugin-typical'
81
- *
82
- * await Bun.build({
83
- * entrypoints: ['./src/index.ts'],
84
- * outdir: './dist',
85
- * plugins: [typicalPlugin()],
86
- * })
87
- * ```
88
- *
89
- * @example
90
- * ```ts
91
- * // For runtime (bunfig.toml preload)
92
- * import typicalPlugin from '@elliots/bun-plugin-typical'
93
- *
94
- * Bun.plugin(typicalPlugin())
95
- * ```
96
- */
97
- function typicalPlugin(rawOptions = {}) {
98
- const options = resolveOptions(rawOptions);
99
- const typicalConfig = {
100
- ...loadConfig(),
101
- ...options.typical
102
- };
103
- return {
104
- name: "bun-plugin-typical",
105
- target: options.target,
106
- setup(build) {
107
- buildTimer.reset();
108
- build.onLoad({ filter: TS_FILTER }, async (args) => {
109
- if (options.exclude.some((pattern) => typeof pattern === "string" ? args.path.includes(pattern) : pattern.test(args.path))) return;
110
- if (options.include.length > 0 && !options.include.some((pattern) => typeof pattern === "string" ? args.path.includes(pattern) : pattern.test(args.path))) return;
111
- const result = await transformFile(args.path, typicalConfig);
112
- if (!result) return;
113
- if (process.env.DEBUG) buildTimer.report("[bun-plugin-typical]");
114
- return {
115
- contents: result.code,
116
- loader: result.loader
117
- };
118
- });
119
- }
120
- };
121
- }
122
- var src_default = typicalPlugin;
123
-
124
- //#endregion
125
- export { typicalPlugin as n, closeTransformer as r, src_default as t };