@systemfsoftware/effect-schema-vite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ryan Lee
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.
@@ -0,0 +1,26 @@
1
+ import { Plugin as Plugin_2 } from 'vite';
2
+
3
+ /**
4
+ * Vite plugin that walks the consumer's `src/` directory, finds every
5
+ * exported Effect `Schema`, and auto-injects `ruleOfSchemas` round-trip
6
+ * property tests for each one.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * // vitest.config.ts
11
+ * import { inlineSchemaTests } from '@systemfsoftware/effect-schema-vite'
12
+ *
13
+ * export default defineConfig({
14
+ * plugins: [inlineSchemaTests()],
15
+ * })
16
+ * ```
17
+ */
18
+ export declare const inlineSchemaTests: (options?: InlineSchemaTestsOptions) => Plugin_2;
19
+
20
+ /** @since 0.1.0 */
21
+ export declare interface InlineSchemaTestsOptions {
22
+ /** Directory to scan for schema files, relative to Vite root. Default: `"src"`. */
23
+ dir?: string;
24
+ }
25
+
26
+ export { }
@@ -0,0 +1,25 @@
1
+ import { Plugin } from "vite";
2
+ //#region src/vite-inline-schema-tests.d.ts
3
+ /** @since 0.1.0 */
4
+ interface InlineSchemaTestsOptions {
5
+ /** Directory to scan for schema files, relative to Vite root. Default: `"src"`. */
6
+ dir?: string;
7
+ }
8
+ /**
9
+ * Vite plugin that walks the consumer's `src/` directory, finds every
10
+ * exported Effect `Schema`, and auto-injects `ruleOfSchemas` round-trip
11
+ * property tests for each one.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // vitest.config.ts
16
+ * import { inlineSchemaTests } from '@systemfsoftware/effect-schema-vite'
17
+ *
18
+ * export default defineConfig({
19
+ * plugins: [inlineSchemaTests()],
20
+ * })
21
+ * ```
22
+ */
23
+ declare const inlineSchemaTests: (options?: InlineSchemaTestsOptions) => Plugin;
24
+ //#endregion
25
+ export { type InlineSchemaTestsOptions, inlineSchemaTests };
@@ -0,0 +1,25 @@
1
+ import { Plugin } from "vite";
2
+ //#region src/vite-inline-schema-tests.d.ts
3
+ /** @since 0.1.0 */
4
+ interface InlineSchemaTestsOptions {
5
+ /** Directory to scan for schema files, relative to Vite root. Default: `"src"`. */
6
+ dir?: string;
7
+ }
8
+ /**
9
+ * Vite plugin that walks the consumer's `src/` directory, finds every
10
+ * exported Effect `Schema`, and auto-injects `ruleOfSchemas` round-trip
11
+ * property tests for each one.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // vitest.config.ts
16
+ * import { inlineSchemaTests } from '@systemfsoftware/effect-schema-vite'
17
+ *
18
+ * export default defineConfig({
19
+ * plugins: [inlineSchemaTests()],
20
+ * })
21
+ * ```
22
+ */
23
+ declare const inlineSchemaTests: (options?: InlineSchemaTestsOptions) => Plugin;
24
+ //#endregion
25
+ export { type InlineSchemaTestsOptions, inlineSchemaTests };
package/dist/index.mjs ADDED
@@ -0,0 +1,151 @@
1
+ import { readFileSync, readdirSync, statSync } from "node:fs";
2
+ import { extname, join, relative, resolve } from "node:path";
3
+ import { parseSync } from "oxc-parser";
4
+ //#region src/vite-inline-schema-tests.ts
5
+ /**
6
+ * Walk a directory and return every exported const whose type annotation
7
+ * or initialiser references Effect Schema APIs.
8
+ */
9
+ function findExportedSchemas(root, dir) {
10
+ const schemas = [];
11
+ function walk(current) {
12
+ let entries;
13
+ try {
14
+ entries = readdirSync(current);
15
+ } catch {
16
+ return;
17
+ }
18
+ for (const entry of entries) {
19
+ const full = join(current, entry);
20
+ let stat;
21
+ try {
22
+ stat = statSync(full);
23
+ } catch {
24
+ continue;
25
+ }
26
+ if (stat.isDirectory()) {
27
+ if (entry === "__tests__" || entry === "node_modules" || entry === ".git") continue;
28
+ walk(full);
29
+ } else if (stat.isFile() && extname(entry) === ".ts" && !entry.endsWith(".test.ts") && !entry.endsWith(".spec.ts")) {
30
+ const names = findExportedSchemaNames(readFileSync(full, "utf-8"));
31
+ for (const name of names) schemas.push({
32
+ name,
33
+ importPath: `./${relative(root, full).replace(/\.ts$/, "")}`
34
+ });
35
+ }
36
+ }
37
+ }
38
+ walk(dir);
39
+ return schemas;
40
+ }
41
+ function findExportedSchemaNames(source) {
42
+ try {
43
+ const result = parseSync("temp.ts", source);
44
+ const names = [];
45
+ for (const node of result.program.body) {
46
+ if (node.type !== "ExportNamedDeclaration") continue;
47
+ const decl = node.declaration;
48
+ if (!decl || decl.type !== "VariableDeclaration") continue;
49
+ for (const declarator of decl.declarations) {
50
+ const id = declarator.id;
51
+ if (id.type !== "Identifier") continue;
52
+ const name = id.name;
53
+ if (name.startsWith("_")) continue;
54
+ let isSchema = false;
55
+ if (id.typeAnnotation?.typeAnnotation) isSchema = typeRefContainsSchema(id.typeAnnotation.typeAnnotation);
56
+ if (!isSchema && declarator.init) isSchema = initRefersToSchema(declarator.init);
57
+ if (isSchema) names.push(name);
58
+ }
59
+ }
60
+ return names;
61
+ } catch {
62
+ return [];
63
+ }
64
+ }
65
+ function typeRefContainsSchema(t) {
66
+ if (!t || typeof t !== "object") return false;
67
+ const node = t;
68
+ if (node.type === "TSTypeReference" && node.typeName) {
69
+ const tn = node.typeName;
70
+ if (tn.type === "Identifier" && typeof tn.name === "string" && tn.name.includes("Schema")) return true;
71
+ if (tn.type === "TSQualifiedName" && typeof tn.name === "string" && tn.name.includes("Schema")) return true;
72
+ }
73
+ if (node.typeParameters) {
74
+ const params = node.typeParameters;
75
+ if (Array.isArray(params.params)) {
76
+ for (const p of params.params) if (typeRefContainsSchema(p)) return true;
77
+ }
78
+ }
79
+ if (node.types && Array.isArray(node.types)) {
80
+ for (const m of node.types) if (typeRefContainsSchema(m)) return true;
81
+ }
82
+ return false;
83
+ }
84
+ function initRefersToSchema(expr) {
85
+ if (!expr || typeof expr !== "object") return false;
86
+ const node = expr;
87
+ if (node.type === "CallExpression" && node.callee) {
88
+ const callee = node.callee;
89
+ if (callee.type === "Identifier" && callee.name === "pipe") {
90
+ const args = node.arguments;
91
+ if (Array.isArray(args)) {
92
+ for (const arg of args) if (initRefersToSchema(arg)) return true;
93
+ }
94
+ return false;
95
+ }
96
+ if (callee.type === "MemberExpression") return memberChainStartsWithS(callee);
97
+ if (callee.type === "Identifier" && callee.name.includes("Schema")) return true;
98
+ }
99
+ if (node.type === "MemberExpression") return memberChainStartsWithS(node);
100
+ return false;
101
+ }
102
+ function memberChainStartsWithS(node) {
103
+ const obj = node.object;
104
+ if (!obj) return false;
105
+ if (obj.type === "Identifier" && obj.name === "S") return true;
106
+ if (obj.type === "Identifier" && typeof obj.name === "string" && obj.name.includes("Schema")) return true;
107
+ if (obj.type === "MemberExpression") return memberChainStartsWithS(obj);
108
+ return false;
109
+ }
110
+ /**
111
+ * Vite plugin that walks the consumer's `src/` directory, finds every
112
+ * exported Effect `Schema`, and auto-injects `ruleOfSchemas` round-trip
113
+ * property tests for each one.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * // vitest.config.ts
118
+ * import { inlineSchemaTests } from '@systemfsoftware/effect-schema-vite'
119
+ *
120
+ * export default defineConfig({
121
+ * plugins: [inlineSchemaTests()],
122
+ * })
123
+ * ```
124
+ */
125
+ const inlineSchemaTests = (options) => {
126
+ let config;
127
+ return {
128
+ name: "@systemfsoftware/inline-schema-tests",
129
+ enforce: "pre",
130
+ configResolved(c) {
131
+ config = c;
132
+ },
133
+ resolveId(id) {
134
+ if (id === "virtual:@systemfsoftware/inline-schema-tests") return "\0virtual:@systemfsoftware/inline-schema-tests";
135
+ },
136
+ load(id) {
137
+ if (id !== "\0virtual:@systemfsoftware/inline-schema-tests") return;
138
+ const srcDir = resolve(config.root, options?.dir ?? "src");
139
+ const schemas = findExportedSchemas(config.root, srcDir);
140
+ if (schemas.length === 0) return "// no schemas found";
141
+ return [
142
+ `import { ruleOfSchemas } from '@systemfsoftware/effect-schema-law'`,
143
+ schemas.map((s) => `import { ${s.name} } from '${s.importPath}'`).join("\n"),
144
+ "",
145
+ schemas.map((s) => `ruleOfSchemas('${s.name}', ${s.name})`).join("\n")
146
+ ].join("\n");
147
+ }
148
+ };
149
+ };
150
+ //#endregion
151
+ export { inlineSchemaTests };
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@systemfsoftware/effect-schema-vite",
3
+ "license": "MIT",
4
+ "version": "0.1.0",
5
+ "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/systemfsoftware/systemfsoftware.git",
9
+ "directory": "packages/effect-schema-vite"
10
+ },
11
+ "homepage": "https://github.com/systemfsoftware/systemfsoftware/tree/main/packages/effect-schema-vite#readme",
12
+ "bugs": "https://github.com/systemfsoftware/systemfsoftware/issues",
13
+ "description": "Vite plugin that auto-discovers Effect Schema exports and injects round-trip property tests via @systemfsoftware/effect-schema-law.",
14
+ "keywords": [
15
+ "effect",
16
+ "effect-ts",
17
+ "schema",
18
+ "vite",
19
+ "vitest",
20
+ "plugin",
21
+ "property-testing",
22
+ "law-testing",
23
+ "typescript"
24
+ ],
25
+ "type": "module",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/effect-schema-vite.d.ts",
29
+ "default": "./dist/index.mjs"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "dependencies": {
37
+ "oxc-parser": "^0.140.0",
38
+ "@oxc-project/types": "^0.140.0"
39
+ },
40
+ "devDependencies": {
41
+ "@microsoft/api-extractor": "^7.58.7",
42
+ "@types/node": "^24",
43
+ "effect": "^3.22.0",
44
+ "rimraf": "^6.1.3",
45
+ "tsdown": "^0.22.9",
46
+ "vite": "^7",
47
+ "vitest": "^4",
48
+ "@systemfsoftware/effect-schema-law": "^0.1.0",
49
+ "@systemfsoftware/oxlint-config": "^0.1.0",
50
+ "@systemfsoftware/tsconfig": "^1.0.0",
51
+ "@systemfsoftware/vitest-config": "^0.1.0"
52
+ },
53
+ "peerDependencies": {
54
+ "@systemfsoftware/effect-schema-law": "*",
55
+ "effect": "*",
56
+ "vite": ">5.0.0",
57
+ "vitest": "*"
58
+ },
59
+ "scripts": {
60
+ "clean": "rimraf dist",
61
+ "build": "tsdown",
62
+ "typecheck": "tsc --noEmit --incremental",
63
+ "test": "vitest run",
64
+ "test:run": "vitest run",
65
+ "api:check": "api-extractor run",
66
+ "api:update": "api-extractor run --local",
67
+ "lint": "oxlint . ${AGENT:+--format=unix --quiet}"
68
+ }
69
+ }