diff --git a/.changeset/hip-trains-shake.md b/.changeset/hip-trains-shake.md new file mode 100644 index 0000000..42277e2 --- /dev/null +++ b/.changeset/hip-trains-shake.md @@ -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 diff --git a/.github/actions/setup/action.yaml b/.github/actions/setup/action.yaml index 87927ec..68c5423 100644 --- a/.github/actions/setup/action.yaml +++ b/.github/actions/setup/action.yaml @@ -10,6 +10,7 @@ runs: uses: actions/setup-node@v3 with: node-version: 20 + cache: 'pnpm' - name: Install dependencies run: pnpm install shell: bash diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ab09930..e05a335 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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: @@ -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: diff --git a/examples/bundlers/package.json b/examples/bundlers/package.json index 2b81feb..0ae4b79 100644 --- a/examples/bundlers/package.json +++ b/examples/bundlers/package.json @@ -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", diff --git a/package.json b/package.json index b96bc44..7aabf9b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/class-validator/src/validation.ts b/packages/class-validator/src/validation.ts index 23cae2f..76366d6 100644 --- a/packages/class-validator/src/validation.ts +++ b/packages/class-validator/src/validation.ts @@ -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< diff --git a/packages/deepkit/src/validation.ts b/packages/deepkit/src/validation.ts index 682fe63..36dfdb9 100644 --- a/packages/deepkit/src/validation.ts +++ b/packages/deepkit/src/validation.ts @@ -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< diff --git a/packages/effect/src/validation.ts b/packages/effect/src/validation.ts index 932d6cc..616e946 100644 --- a/packages/effect/src/validation.ts +++ b/packages/effect/src/validation.ts @@ -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); diff --git a/packages/io-ts/src/validation.ts b/packages/io-ts/src/validation.ts index 3982f31..69221ba 100644 --- a/packages/io-ts/src/validation.ts +++ b/packages/io-ts/src/validation.ts @@ -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< diff --git a/packages/json/README.md b/packages/json/README.md index 4680c4e..fe589ba 100644 --- a/packages/json/README.md +++ b/packages/json/README.md @@ -39,7 +39,7 @@ const appRouter = t.router({ Use it directly or through [`@typeschema/main`](https://github.com/decs/typeschema/tree/main/packages/main) ## Dependencies -- [`ajv`](https://www.npmjs.com/package/ajv): Required for validation (`^8.12.0`) +- [`ajv`](https://www.npmjs.com/package/ajv): Required for validation and serialization (`^8.12.0`) - [`json-schema-to-ts`](https://www.npmjs.com/package/json-schema-to-ts): Required for inference (`^3.0.0`) ## API diff --git a/packages/json/src/validation.ts b/packages/json/src/validation.ts index 4a66004..f5995db 100644 --- a/packages/json/src/validation.ts +++ b/packages/json/src/validation.ts @@ -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< diff --git a/packages/main/src/serialization.ts b/packages/main/src/serialization.ts index d15e987..6bb6191 100644 --- a/packages/main/src/serialization.ts +++ b/packages/main/src/serialization.ts @@ -13,51 +13,23 @@ import {memoize, unsupportedAdapter} from '@typeschema/core'; import {select} from './selector'; const importJsonSerializationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/json'; - const {serializationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/json'); - return serializationAdapter; - } catch (error) { - throw error; - } + const {serializationAdapter} = await import('@typeschema/json'); + return serializationAdapter; }); const importValibotSerializationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/valibot'; - const {serializationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/valibot'); - return serializationAdapter; - } catch (error) { - throw error; - } + const {serializationAdapter} = await import('@typeschema/valibot'); + return serializationAdapter; }); const importYupSerializationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/yup'; - const {serializationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/yup'); - return serializationAdapter; - } catch (error) { - throw error; - } + const {serializationAdapter} = await import('@typeschema/yup'); + return serializationAdapter; }); const importZodSerializationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/zod'; - const {serializationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/zod'); - return serializationAdapter; - } catch (error) { - throw error; - } + const {serializationAdapter} = await import('@typeschema/zod'); + return serializationAdapter; }); export const serializationAdapter: SerializationAdapter = select({ diff --git a/packages/main/src/validation.ts b/packages/main/src/validation.ts index 43ea9b9..9b3179c 100644 --- a/packages/main/src/validation.ts +++ b/packages/main/src/validation.ts @@ -13,183 +13,78 @@ import {memoize, unsupportedAdapter} from '@typeschema/core'; import {select} from './selector'; const importArktypeValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/arktype'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/arktype'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/arktype'); + return validationAdapter; }); const importClassValidatorValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/class-validator'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/class-validator'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/class-validator'); + return validationAdapter; }); const importDeepkitValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/deepkit'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/deepkit'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/deepkit'); + return validationAdapter; }); const importEffectValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/effect'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/effect'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/effect'); + return validationAdapter; }); const importFunctionValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/function'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/function'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/function'); + return validationAdapter; }); const importIoTsValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/io-ts'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/io-ts'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/io-ts'); + return validationAdapter; }); const importJoiValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/joi'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/joi'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/joi'); + return validationAdapter; }); const importJsonValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/json'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/json'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/json'); + return validationAdapter; }); const importOwValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/ow'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/ow'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/ow'); + return validationAdapter; }); const importRuntypesValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/runtypes'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/runtypes'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/runtypes'); + return validationAdapter; }); const importSuperstructValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/superstruct'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/superstruct'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/superstruct'); + return validationAdapter; }); const importTypeboxValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/typebox'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/typebox'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/typebox'); + return validationAdapter; }); const importValibotValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/valibot'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/valibot'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/valibot'); + return validationAdapter; }); const importYupValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/yup'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/yup'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/yup'); + return validationAdapter; }); const importZodValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/zod'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/zod'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/zod'); + return validationAdapter; }); export const validationAdapter: ValidationAdapter = select({ diff --git a/packages/ow/src/validation.ts b/packages/ow/src/validation.ts index e4a604e..66afc3b 100644 --- a/packages/ow/src/validation.ts +++ b/packages/ow/src/validation.ts @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importValidationModule = memoize(async () => { - try { - const moduleName = 'ow'; - const {default: ow, ArgumentError} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('ow'); - return {ArgumentError, ow}; - } catch (error) { - throw error; - } + const {default: ow, ArgumentError} = await import('ow'); + return {ArgumentError, ow}; }); export const validationAdapter: ValidationAdapter< diff --git a/packages/typebox/src/validation.ts b/packages/typebox/src/validation.ts index c02d192..0e87d1b 100644 --- a/packages/typebox/src/validation.ts +++ b/packages/typebox/src/validation.ts @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importValidationModule = memoize(async () => { - try { - const moduleName = '@sinclair/typebox/compiler'; - const {TypeCompiler} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@sinclair/typebox/compiler'); - return {TypeCompiler}; - } catch (error) { - throw error; - } + const {TypeCompiler} = await import('@sinclair/typebox/compiler'); + return {TypeCompiler}; }); export const validationAdapter: ValidationAdapter< diff --git a/packages/valibot/src/serialization.ts b/packages/valibot/src/serialization.ts index 7b46276..e7443bb 100644 --- a/packages/valibot/src/serialization.ts +++ b/packages/valibot/src/serialization.ts @@ -4,15 +4,8 @@ import type {SerializationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importSerializationModule = memoize(async () => { - try { - const moduleName = '@gcornut/valibot-json-schema'; - const {toJSONSchema} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@gcornut/valibot-json-schema'); - return {toJSONSchema}; - } catch (error) { - throw error; - } + const {toJSONSchema} = await import('@gcornut/valibot-json-schema'); + return {toJSONSchema}; }); export const serializationAdapter: SerializationAdapter< diff --git a/packages/valibot/src/validation.ts b/packages/valibot/src/validation.ts index f363382..4ce07aa 100644 --- a/packages/valibot/src/validation.ts +++ b/packages/valibot/src/validation.ts @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importValidationModule = memoize(async () => { - try { - const moduleName = 'valibot'; - const {safeParseAsync} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('valibot'); - return {safeParseAsync}; - } catch (error) { - throw error; - } + const {safeParseAsync} = await import('valibot'); + return {safeParseAsync}; }); export const validationAdapter: ValidationAdapter< diff --git a/packages/yup/src/serialization.ts b/packages/yup/src/serialization.ts index 55a5fd0..d7983a4 100644 --- a/packages/yup/src/serialization.ts +++ b/packages/yup/src/serialization.ts @@ -4,15 +4,8 @@ import type {SerializationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importSerializationModule = memoize(async () => { - try { - const moduleName = '@sodaru/yup-to-json-schema'; - const {convertSchema} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@sodaru/yup-to-json-schema'); - return {convertSchema}; - } catch (error) { - throw error; - } + const {convertSchema} = await import('@sodaru/yup-to-json-schema'); + return {convertSchema}; }); export const serializationAdapter: SerializationAdapter< diff --git a/packages/yup/src/validation.ts b/packages/yup/src/validation.ts index 0b5591c..3c15d9d 100644 --- a/packages/yup/src/validation.ts +++ b/packages/yup/src/validation.ts @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importValidationModule = memoize(async () => { - try { - const moduleName = 'yup'; - const {ValidationError} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('yup'); - return {ValidationError}; - } catch (error) { - throw error; - } + const {ValidationError} = await import('yup'); + return {ValidationError}; }); export const validationAdapter: ValidationAdapter< diff --git a/packages/zod/src/serialization.ts b/packages/zod/src/serialization.ts index 41ed724..595f2df 100644 --- a/packages/zod/src/serialization.ts +++ b/packages/zod/src/serialization.ts @@ -4,15 +4,8 @@ import type {SerializationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importSerializationModule = memoize(async () => { - try { - const moduleName = 'zod-to-json-schema'; - const {zodToJsonSchema} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('zod-to-json-schema'); - return {zodToJsonSchema}; - } catch (error) { - throw error; - } + const {zodToJsonSchema} = await import('zod-to-json-schema'); + return {zodToJsonSchema}; }); export const serializationAdapter: SerializationAdapter< diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f55040..7312547 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,6 +35,9 @@ importers: '@typescript-eslint/parser': specifier: ^6.19.0 version: 6.21.0(eslint@8.56.0)(typescript@5.3.3) + esbuild: + specifier: ^0.20.0 + version: 0.20.0 eslint: specifier: ^8.56.0 version: 8.56.0 @@ -106,7 +109,7 @@ importers: dependencies: '@typeschema/main': specifier: workspace:* - version: file:packages/main(@typeschema/zod@0.13.1) + version: file:packages/main(@typeschema/zod@0.13.2) '@typeschema/zod': specifier: workspace:* version: file:packages/zod(zod@3.22.4) @@ -172,7 +175,7 @@ importers: dependencies: '@typeschema/main': specifier: workspace:* - version: file:packages/main(@typeschema/zod@0.13.1) + version: file:packages/main(@typeschema/zod@0.13.2) valibot: specifier: ^0.27.1 version: 0.27.1 @@ -184,7 +187,7 @@ importers: dependencies: '@typeschema/main': specifier: workspace:* - version: file:packages/main(@typeschema/zod@0.13.1) + version: file:packages/main(@typeschema/zod@0.13.2) '@typeschema/zod': specifier: workspace:* version: file:packages/zod(zod@3.22.4) @@ -11858,7 +11861,7 @@ packages: '@typeschema/zod': link:packages/zod dev: false - file:packages/main(@typeschema/zod@0.13.1): + file:packages/main(@typeschema/zod@0.13.2): resolution: {directory: packages/main, type: directory} id: file:packages/main name: '@typeschema/main' diff --git a/tsup.config.ts b/tsup.config.ts index c12ed64..757dea2 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,8 +1,31 @@ +import type {Plugin} from 'esbuild'; + +import fs from 'node:fs'; + import {defineConfig} from 'tsup'; +const dynamicImportsPlugin: Plugin = { + name: 'dynamicImports', + setup(build) { + build.onLoad({filter: /\.ts$/}, async args => ({ + contents: fs.readFileSync(args.path, 'utf-8').replace( + /([ \t]*)const (\w+|{.+}) = await import\((.*)\);\s*return ([^;]+);/g, + `$1try { +$1 const $2 = await import(/* webpackIgnore: true */ $3); +$1 return $4; +$1} catch (error) { +$1 throw error; +$1}`, + ), + loader: 'ts', + })); + }, +}; + export default defineConfig({ clean: true, dts: true, entry: ['src/index.ts'], + esbuildPlugins: [dynamicImportsPlugin], format: ['esm', 'cjs'], }); diff --git a/turbo/generators/templates/create-adapter/src/validation.ts.hbs b/turbo/generators/templates/create-adapter/src/validation.ts.hbs index 79b8be2..8487a19 100644 --- a/turbo/generators/templates/create-adapter/src/validation.ts.hbs +++ b/turbo/generators/templates/create-adapter/src/validation.ts.hbs @@ -4,15 +4,8 @@ import type {ValidationAdapter} from '@typeschema/core'; import {memoize} from '@typeschema/core'; const importValidationModule = memoize(async () => { - try { - const moduleName = '$FixMe'; - const {$FixMe} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('$FixMe'); - return {$FixMe}; - } catch (error) { - throw error; - } + const {$FixMe} = await import('$FixMe'); + return {$FixMe}; }); export const validationAdapter: ValidationAdapter< diff --git a/turbo/generators/templates/main/src/serialization.ts.hbs b/turbo/generators/templates/main/src/serialization.ts.hbs index 7abfb4c..109e369 100644 --- a/turbo/generators/templates/main/src/serialization.ts.hbs +++ b/turbo/generators/templates/main/src/serialization.ts.hbs @@ -11,15 +11,8 @@ import {select} from './selector'; {{#each adapters}} {{#if hasModule.serialization}} const import{{pascalCase name}}SerializationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/{{name}}'; - const {serializationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/{{name}}'); - return serializationAdapter; - } catch (error) { - throw error; - } + const {serializationAdapter} = await import('@typeschema/{{name}}'); + return serializationAdapter; }); {{/if}} diff --git a/turbo/generators/templates/main/src/validation.ts.hbs b/turbo/generators/templates/main/src/validation.ts.hbs index ed91361..f403784 100644 --- a/turbo/generators/templates/main/src/validation.ts.hbs +++ b/turbo/generators/templates/main/src/validation.ts.hbs @@ -11,15 +11,8 @@ import {select} from './selector'; {{#each adapters}} {{#if hasModule.validation}} const import{{pascalCase name}}ValidationAdapter = memoize(async () => { - try { - const moduleName = '@typeschema/{{name}}'; - const {validationAdapter} = (await import( - /* webpackIgnore: true */ moduleName - )) as typeof import('@typeschema/{{name}}'); - return validationAdapter; - } catch (error) { - throw error; - } + const {validationAdapter} = await import('@typeschema/{{name}}'); + return validationAdapter; }); {{/if}}