@elliots/unplugin-typical 0.1.6

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.
@@ -0,0 +1,18 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/esbuild.d.ts
4
+
5
+ /**
6
+ * Esbuild plugin
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { build } from 'esbuild'
11
+ * import Typical from '@elliots/unplugin-typical/esbuild'
12
+ *
13
+ * build({ plugins: [Typical()] })
14
+ * ```
15
+ */
16
+ declare const esbuild: typeof Typical.esbuild;
17
+ //#endregion
18
+ export { esbuild as default, esbuild as "module.exports" };
@@ -0,0 +1,24 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/esbuild.ts
4
+ /**
5
+ * This entry file is for esbuild plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Esbuild plugin
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { build } from 'esbuild'
15
+ * import Typical from '@elliots/unplugin-typical/esbuild'
16
+ *
17
+ * build({ plugins: [Typical()] })
18
+ * ```
19
+ */
20
+ const esbuild = Typical.esbuild;
21
+ var esbuild_default = esbuild;
22
+
23
+ //#endregion
24
+ export { esbuild_default as default, esbuild as "module.exports" };
@@ -0,0 +1,20 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/farm.d.ts
4
+
5
+ /**
6
+ * Farm plugin
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // farm.config.ts
11
+ * import Typical from '@elliots/unplugin-typical/farm'
12
+ *
13
+ * export default {
14
+ * plugins: [Typical()],
15
+ * }
16
+ * ```
17
+ */
18
+ declare const farm: typeof Typical.farm;
19
+ //#endregion
20
+ export { farm as default, farm as "module.exports" };
package/dist/farm.mjs ADDED
@@ -0,0 +1,26 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/farm.ts
4
+ /**
5
+ * This entry file is for Farm plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Farm plugin
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // farm.config.ts
15
+ * import Typical from '@elliots/unplugin-typical/farm'
16
+ *
17
+ * export default {
18
+ * plugins: [Typical()],
19
+ * }
20
+ * ```
21
+ */
22
+ const farm = Typical.farm;
23
+ var farm_default = farm;
24
+
25
+ //#endregion
26
+ export { farm_default as default, farm as "module.exports" };
@@ -0,0 +1,34 @@
1
+ import { FilterPattern, UnpluginInstance } from "unplugin";
2
+ import ts from "typescript";
3
+
4
+ //#region ../../dist/src/config.d.ts
5
+ interface TypicalDebugConfig {
6
+ writeIntermediateFiles?: boolean;
7
+ }
8
+ interface TypicalConfig {
9
+ include?: string[];
10
+ exclude?: string[];
11
+ reusableValidators?: boolean;
12
+ validateCasts?: boolean;
13
+ hoistRegex?: boolean;
14
+ debug?: TypicalDebugConfig;
15
+ /**
16
+ * Type patterns to skip validation for (supports wildcards).
17
+ * Use this for types that typia cannot process (e.g., React event types).
18
+ * Example: ["React.*", "Express.Request", "*.Event"]
19
+ */
20
+ ignoreTypes?: string[];
21
+ }
22
+ //#endregion
23
+ //#region src/core/options.d.ts
24
+ interface Options {
25
+ include?: FilterPattern;
26
+ exclude?: FilterPattern;
27
+ enforce?: "pre" | "post" | undefined;
28
+ typical?: Partial<TypicalConfig>;
29
+ }
30
+ //#endregion
31
+ //#region src/index.d.ts
32
+ declare const Typical: UnpluginInstance<Options | undefined, false>;
33
+ //#endregion
34
+ export { Options as n, Typical as t };
@@ -0,0 +1,2 @@
1
+ import { n as Options, t as Typical } from "./index-BI1Rh2MC.mjs";
2
+ export { Options, Typical };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ export { Typical };
@@ -0,0 +1,20 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/rolldown.d.ts
4
+
5
+ /**
6
+ * Rolldown plugin
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // rolldown.config.js
11
+ * import Typical from '@elliots/unplugin-typical/rolldown'
12
+ *
13
+ * export default {
14
+ * plugins: [Typical()],
15
+ * }
16
+ * ```
17
+ */
18
+ declare const rolldown: typeof Typical.rolldown;
19
+ //#endregion
20
+ export { rolldown as default, rolldown as "module.exports" };
@@ -0,0 +1,26 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/rolldown.ts
4
+ /**
5
+ * This entry file is for Rolldown plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Rolldown plugin
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // rolldown.config.js
15
+ * import Typical from '@elliots/unplugin-typical/rolldown'
16
+ *
17
+ * export default {
18
+ * plugins: [Typical()],
19
+ * }
20
+ * ```
21
+ */
22
+ const rolldown = Typical.rolldown;
23
+ var rolldown_default = rolldown;
24
+
25
+ //#endregion
26
+ export { rolldown_default as default, rolldown as "module.exports" };
@@ -0,0 +1,20 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/rollup.d.ts
4
+
5
+ /**
6
+ * Rollup plugin
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // rollup.config.js
11
+ * import Typical from '@elliots/unplugin-typical/rollup'
12
+ *
13
+ * export default {
14
+ * plugins: [Typical()],
15
+ * }
16
+ * ```
17
+ */
18
+ declare const rollup: typeof Typical.rollup;
19
+ //#endregion
20
+ export { rollup as default, rollup as "module.exports" };
@@ -0,0 +1,26 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/rollup.ts
4
+ /**
5
+ * This entry file is for Rollup plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Rollup plugin
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // rollup.config.js
15
+ * import Typical from '@elliots/unplugin-typical/rollup'
16
+ *
17
+ * export default {
18
+ * plugins: [Typical()],
19
+ * }
20
+ * ```
21
+ */
22
+ const rollup = Typical.rollup;
23
+ var rollup_default = rollup;
24
+
25
+ //#endregion
26
+ export { rollup_default as default, rollup as "module.exports" };
@@ -0,0 +1,20 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/rspack.d.ts
4
+
5
+ /**
6
+ * Rspack plugin
7
+ *
8
+ * @example
9
+ * ```js
10
+ * // rspack.config.js
11
+ * import Typical from '@elliots/unplugin-typical/rspack'
12
+ *
13
+ * export default {
14
+ * plugins: [Typical()],
15
+ * }
16
+ * ```
17
+ */
18
+ declare const rspack: typeof Typical.rspack;
19
+ //#endregion
20
+ export { rspack as default, rspack as "module.exports" };
@@ -0,0 +1,26 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/rspack.ts
4
+ /**
5
+ * This entry file is for Rspack plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Rspack plugin
11
+ *
12
+ * @example
13
+ * ```js
14
+ * // rspack.config.js
15
+ * import Typical from '@elliots/unplugin-typical/rspack'
16
+ *
17
+ * export default {
18
+ * plugins: [Typical()],
19
+ * }
20
+ * ```
21
+ */
22
+ const rspack = Typical.rspack;
23
+ var rspack_default = rspack;
24
+
25
+ //#endregion
26
+ export { rspack_default as default, rspack as "module.exports" };
@@ -0,0 +1,112 @@
1
+ import { createUnplugin } from "unplugin";
2
+ import { TypicalTransformer, loadConfig } from "@elliots/typical";
3
+ import ts from "typescript";
4
+ import { dirname, extname, resolve } from "path";
5
+
6
+ //#region src/core/options.ts
7
+ function resolveOptions(options) {
8
+ return {
9
+ include: options.include || [/\.[cm]?[jt]sx?$/],
10
+ exclude: options.exclude || [/node_modules/],
11
+ enforce: "enforce" in options ? options.enforce : "pre",
12
+ typical: options.typical
13
+ };
14
+ }
15
+
16
+ //#endregion
17
+ //#region src/core/transform.ts
18
+ let cachedCompilerOptions;
19
+ const sourceFileCache = /* @__PURE__ */ new Map();
20
+ const TRANSFORM_EXTENSIONS = new Set([
21
+ ".ts",
22
+ ".tsx",
23
+ ".mts",
24
+ ".cts"
25
+ ]);
26
+ /**
27
+ * Transform a TypeScript file with Typical.
28
+ *
29
+ * Creates a program per file that includes the provided source content.
30
+ * This ensures the type checker can resolve types for the incoming code.
31
+ */
32
+ function transformTypia(id, source, config) {
33
+ const ext = extname(id).toLowerCase();
34
+ if (!TRANSFORM_EXTENSIONS.has(ext)) return;
35
+ const { program, sourceFile } = createProgramWithSource(resolve(id), source, getCompilerOptions());
36
+ const result = new TypicalTransformer(config, program).transform(sourceFile, "js");
37
+ if (process.env.DEBUG) console.log("[unplugin-typical] Transform output (first 1000 chars):", result.substring(0, 1e3));
38
+ return result;
39
+ }
40
+ /**
41
+ * Get TypeScript compiler options from tsconfig.json (cached)
42
+ */
43
+ function getCompilerOptions() {
44
+ if (cachedCompilerOptions) return cachedCompilerOptions;
45
+ const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists, "tsconfig.json");
46
+ if (!configPath) {
47
+ cachedCompilerOptions = {
48
+ target: ts.ScriptTarget.ES2020,
49
+ module: ts.ModuleKind.ESNext,
50
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
51
+ esModuleInterop: true,
52
+ strict: true
53
+ };
54
+ return cachedCompilerOptions;
55
+ }
56
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
57
+ if (configFile.error) throw new Error(ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n"));
58
+ cachedCompilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(configPath)).options;
59
+ return cachedCompilerOptions;
60
+ }
61
+ /**
62
+ * Create a TypeScript program with the provided source content.
63
+ * Uses a custom compiler host that:
64
+ * - Returns the provided source for the target file
65
+ * - Caches other source files from disk for reuse
66
+ */
67
+ function createProgramWithSource(id, source, compilerOptions) {
68
+ const sourceFile = ts.createSourceFile(id, source, compilerOptions.target ?? ts.ScriptTarget.ES2020, true);
69
+ const host = ts.createCompilerHost(compilerOptions);
70
+ const originalGetSourceFile = host.getSourceFile.bind(host);
71
+ host.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
72
+ const resolvedFileName = resolve(fileName);
73
+ if (resolvedFileName === id) return sourceFile;
74
+ const cached = sourceFileCache.get(resolvedFileName);
75
+ if (cached) return cached;
76
+ const result = originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
77
+ if (result) sourceFileCache.set(resolvedFileName, result);
78
+ return result;
79
+ };
80
+ const program = ts.createProgram([id], compilerOptions, host);
81
+ if (process.env.DEBUG) console.log("[unplugin-typical] Program source files:", program.getSourceFiles().map((sf) => sf.fileName));
82
+ return {
83
+ program,
84
+ sourceFile: program.getSourceFile(id)
85
+ };
86
+ }
87
+
88
+ //#endregion
89
+ //#region src/index.ts
90
+ const Typical = createUnplugin((rawOptions = {}) => {
91
+ const options = resolveOptions(rawOptions);
92
+ const typicalConfig = {
93
+ ...loadConfig(),
94
+ ...options.typical
95
+ };
96
+ return {
97
+ name: "unplugin-typical",
98
+ enforce: options.enforce,
99
+ transform: {
100
+ filter: { id: {
101
+ include: options.include,
102
+ exclude: options.exclude
103
+ } },
104
+ handler(code, id) {
105
+ return transformTypia(id, code, typicalConfig);
106
+ }
107
+ }
108
+ };
109
+ });
110
+
111
+ //#endregion
112
+ export { Typical as t };
@@ -0,0 +1,20 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/vite.d.ts
4
+
5
+ /**
6
+ * Vite plugin
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // vite.config.ts
11
+ * import Typical from '@elliots/unplugin-typical/vite'
12
+ *
13
+ * export default defineConfig({
14
+ * plugins: [Typical()],
15
+ * })
16
+ * ```
17
+ */
18
+ declare const vite: typeof Typical.vite;
19
+ //#endregion
20
+ export { vite as default, vite as "module.exports" };
package/dist/vite.mjs ADDED
@@ -0,0 +1,26 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/vite.ts
4
+ /**
5
+ * This entry file is for Vite plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Vite plugin
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // vite.config.ts
15
+ * import Typical from '@elliots/unplugin-typical/vite'
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [Typical()],
19
+ * })
20
+ * ```
21
+ */
22
+ const vite = Typical.vite;
23
+ var vite_default = vite;
24
+
25
+ //#endregion
26
+ export { vite_default as default, vite as "module.exports" };
@@ -0,0 +1,20 @@
1
+ import { t as Typical } from "./index-BI1Rh2MC.mjs";
2
+
3
+ //#region src/webpack.d.ts
4
+
5
+ /**
6
+ * Webpack plugin
7
+ *
8
+ * @example
9
+ * ```js
10
+ * // webpack.config.js
11
+ * import Typical from '@elliots/unplugin-typical/webpack'
12
+ *
13
+ * export default {
14
+ * plugins: [Typical()],
15
+ * }
16
+ * ```
17
+ */
18
+ declare const webpack: typeof Typical.webpack;
19
+ //#endregion
20
+ export { webpack as default, webpack as "module.exports" };
@@ -0,0 +1,26 @@
1
+ import { t as Typical } from "./src-DVJWj1px.mjs";
2
+
3
+ //#region src/webpack.ts
4
+ /**
5
+ * This entry file is for webpack plugin.
6
+ *
7
+ * @module
8
+ */
9
+ /**
10
+ * Webpack plugin
11
+ *
12
+ * @example
13
+ * ```js
14
+ * // webpack.config.js
15
+ * import Typical from '@elliots/unplugin-typical/webpack'
16
+ *
17
+ * export default {
18
+ * plugins: [Typical()],
19
+ * }
20
+ * ```
21
+ */
22
+ const webpack = Typical.webpack;
23
+ var webpack_default = webpack;
24
+
25
+ //#endregion
26
+ export { webpack_default as default, webpack as "module.exports" };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@elliots/unplugin-typical",
3
+ "type": "module",
4
+ "version": "0.1.6",
5
+ "description": "Unplugin for typical - runtime safe TypeScript transformer",
6
+ "author": "Elliot Shepherd <elliot@jarofworms.com>",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/elliots/typical#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/elliots/typical.git",
12
+ "directory": "packages/unplugin"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/elliots/typical/issues"
16
+ },
17
+ "keywords": [
18
+ "unplugin",
19
+ "vite",
20
+ "webpack",
21
+ "rspack",
22
+ "rollup",
23
+ "rolldown",
24
+ "esbuild",
25
+ "farm",
26
+ "typescript",
27
+ "runtime",
28
+ "validation",
29
+ "typical"
30
+ ],
31
+ "exports": {
32
+ ".": "./dist/index.mjs",
33
+ "./esbuild": "./dist/esbuild.mjs",
34
+ "./farm": "./dist/farm.mjs",
35
+ "./rolldown": "./dist/rolldown.mjs",
36
+ "./rollup": "./dist/rollup.mjs",
37
+ "./rspack": "./dist/rspack.mjs",
38
+ "./vite": "./dist/vite.mjs",
39
+ "./webpack": "./dist/webpack.mjs",
40
+ "./package.json": "./package.json"
41
+ },
42
+ "main": "./dist/index.mjs",
43
+ "module": "./dist/index.mjs",
44
+ "types": "./dist/index.d.mts",
45
+ "typesVersions": {
46
+ "*": {
47
+ "*": [
48
+ "./dist/*.d.mts",
49
+ "./*"
50
+ ]
51
+ }
52
+ },
53
+ "files": [
54
+ "dist"
55
+ ],
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "dependencies": {
60
+ "@elliots/typical": "0.1.6",
61
+ "unplugin": "^2.3.11"
62
+ },
63
+ "devDependencies": {
64
+ "@types/node": "^22.0.0",
65
+ "tsdown": "^0.18.3"
66
+ },
67
+ "peerDependencies": {
68
+ "typescript": "^5.0.0"
69
+ },
70
+ "scripts": {
71
+ "build": "tsdown",
72
+ "dev": "tsdown --watch",
73
+ "typecheck": "tsc --noEmit"
74
+ }
75
+ }