Skip to content

Commit

Permalink
Merge pull request #40 from decs/bc2f608
Browse files Browse the repository at this point in the history
Fix Vite support
  • Loading branch information
decs authored Mar 1, 2024
2 parents bc2f608 + 6c178f0 commit 38339e2
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 328 deletions.
15 changes: 15 additions & 0 deletions .changeset/hip-trains-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@typeschema/class-validator": patch
"@typeschema/deepkit": patch
"@typeschema/typebox": patch
"@typeschema/valibot": patch
"@typeschema/effect": patch
"@typeschema/io-ts": patch
"@typeschema/json": patch
"@typeschema/main": patch
"@typeschema/yup": patch
"@typeschema/zod": patch
"@typeschema/ow": patch
---

Fix Vite support
1 change: 1 addition & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ runs:
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
shell: bash
11 changes: 6 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: ci
name: CI

on:
pull_request:
push:
branches:
- main

env:
TURBO_TOKEN: ${{secrets.TURBO_TOKEN}}
TURBO_TEAM: ${{vars.TURBO_TEAM}}

jobs:
gen:
Expand Down Expand Up @@ -61,7 +62,7 @@ jobs:
run: pnpm test:e2e
release:
name: Release packages
if: github.event_name == 'push'
if: github.event_name == 'push' && github.ref_name == 'main'
runs-on: ubuntu-latest
needs: [gen, lint, test, test-e2e]
steps:
Expand Down
4 changes: 2 additions & 2 deletions examples/bundlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"private": true,
"type": "module",
"scripts": {
"test": "pnpm test:bun && pnpm test:esbuild && pnpm test:parcel && pnpm test:rollup && pnpm test:swc && pnpm test:vite && pnpm test:webpack",
"test": "pnpm test:bun && pnpm test:esbuild && pnpm test:rollup && pnpm test:swc && pnpm test:vite && pnpm test:webpack",
"test:bun": "bun build src/main.ts --outdir=bun_dist && node bun_dist/main.js",
"test:esbuild": "esbuild src/main.ts --bundle --outdir=esbuild_dist && node esbuild_dist/main.js",
"test:parcel": "parcel build src/main.ts --dist-dir=parcel_dist --no-cache && node parcel_dist/main.js",
"//test:parcel": "parcel build src/main.ts --dist-dir=parcel_dist --no-cache && node parcel_dist/main.js",
"test:rollup": "rollup --config && node rollup_dist/main.js",
"test:swc": "swc src/main.ts --out-dir=swc_dist && node swc_dist/src/main.js",
"test:vite": "vite build --outDir=vite_dist",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
Expand Down
11 changes: 2 additions & 9 deletions packages/class-validator/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core';
import {memoize} from '@typeschema/core';

const importValidationModule = memoize(async () => {
try {
const moduleName = 'class-validator';
const {validate} = (await import(
/* webpackIgnore: true */ moduleName
)) as typeof import('class-validator');
return {validate};
} catch (error) {
throw error;
}
const {validate} = await import('class-validator');
return {validate};
});

export const validationAdapter: ValidationAdapter<
Expand Down
11 changes: 2 additions & 9 deletions packages/deepkit/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core';
import {memoize} from '@typeschema/core';

const importValidationModule = memoize(async () => {
try {
const moduleName = '@deepkit/type';
const {validate} = (await import(
/* webpackIgnore: true */ moduleName
)) as typeof import('@deepkit/type');
return {validate};
} catch (error) {
throw error;
}
const {validate} = await import('@deepkit/type');
return {validate};
});

export const validationAdapter: ValidationAdapter<
Expand Down
33 changes: 14 additions & 19 deletions packages/effect/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@ import type {ValidationAdapter} from '@typeschema/core';

import {memoize} from '@typeschema/core';

const importValidationModule = memoize(async () => {
try {
const eitherModuleName = 'effect/Either';
const {isRight} = (await import(
/* webpackIgnore: true */ eitherModuleName
)) as typeof import('effect/Either');
const schemaModuleName = '@effect/schema/Schema';
const {parseEither} = (await import(
/* webpackIgnore: true */ schemaModuleName
)) as typeof import('@effect/schema/Schema');
const formatterModuleName = '@effect/schema/TreeFormatter';
const {formatError} = (await import(
/* webpackIgnore: true */ formatterModuleName
)) as typeof import('@effect/schema/TreeFormatter');
return {formatError, isRight, parseEither};
} catch (error) {
throw error;
}
const importValidationEitherModule = memoize(async () => {
const {isRight} = await import('effect/Either');
return {isRight};
});
const importValidationSchemaModule = memoize(async () => {
const {parseEither} = await import('@effect/schema/Schema');
return {parseEither};
});
const importValidationTreeFormatterModule = memoize(async () => {
const {formatError} = await import('@effect/schema/TreeFormatter');
return {formatError};
});

export const validationAdapter: ValidationAdapter<
AdapterResolver
> = async schema => {
const {parseEither, isRight, formatError} = await importValidationModule();
const {isRight} = await importValidationEitherModule();
const {parseEither} = await importValidationSchemaModule();
const {formatError} = await importValidationTreeFormatterModule();
const parseSchema = parseEither(schema);
return async data => {
const result = parseSchema(data);
Expand Down
11 changes: 2 additions & 9 deletions packages/io-ts/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core';
import {memoize} from '@typeschema/core';

const importValidationModule = memoize(async () => {
try {
const moduleName = 'fp-ts/Either';
const {isRight} = (await import(
/* webpackIgnore: true */ moduleName
)) as typeof import('fp-ts/Either');
return {isRight};
} catch (error) {
throw error;
}
const {isRight} = await import('fp-ts/Either');
return {isRight};
});

export const validationAdapter: ValidationAdapter<
Expand Down
2 changes: 1 addition & 1 deletion packages/json/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions packages/json/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core';
import {memoize} from '@typeschema/core';

const importValidationModule = memoize(async () => {
try {
const moduleName = 'ajv';
const {default: Ajv} = (await import(
/* webpackIgnore: true */ moduleName
)) as typeof import('ajv');
return new Ajv();
} catch (error) {
throw error;
}
const {default: Ajv} = await import('ajv');
return new Ajv();
});

export const validationAdapter: ValidationAdapter<
Expand Down
44 changes: 8 additions & 36 deletions packages/main/src/serialization.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 38339e2

Please sign in to comment.