Skip to content

Commit

Permalink
Add support for webpack #24
Browse files Browse the repository at this point in the history
  • Loading branch information
decs committed Oct 13, 2023
1 parent 3d33f69 commit 8fa8b33
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 16 deletions.
42 changes: 36 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,46 @@ jobs:
working-directory: ./sample
run: yarn build

bundle_with_nextjs:
needs: build
name: Test bundling with Next.js (webpack)
runs-on: ubuntu-latest
steps:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Create a Next.js project
run: yarn create next-app sample --ts --eslint --tailwind --src-dir --app --import-alias="@/*"
- name: Download package
uses: actions/download-artifact@v3
with:
name: package.tgz
- name: Add package
working-directory: ./sample
run: yarn add $(ls ../decs-typeschema-*.tgz) zod
- name: Use package
working-directory: ./sample
run: |
echo "
import {validate} from '@decs/typeschema';
import {z} from 'zod';
export default function Page() {
validate(z.string(), "hello").then(console.log);
}
" > src/app/page.tsx
- name: Bundle project
working-directory: ./sample
run: yarn build

check_for_version_upgrade:
name: Check for version upgrade
if: |
github.event_name == 'push' ||
github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login
runs-on: ubuntu-latest
needs:
- bundle_with_vite
needs: [bundle_with_vite, bundle_with_nextjs]
outputs:
from_version: ${{steps.check.outputs.from_version}}
to_version: ${{steps.check.outputs.to_version}}
Expand All @@ -89,8 +121,7 @@ jobs:
publish_to_deno:
name: Publish to Deno
runs-on: ubuntu-latest
needs:
- check_for_version_upgrade
needs: check_for_version_upgrade
if: |
needs.check_for_version_upgrade.outputs.is_upgraded_version == 'true' &&
(
Expand Down Expand Up @@ -142,8 +173,7 @@ jobs:
publish_to_npm:
name: Publish to NPM
runs-on: ubuntu-latest
needs:
- check_for_version_upgrade
needs: check_for_version_upgrade
if: |
needs.check_for_version_upgrade.outputs.is_upgraded_version == 'true' &&
(
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface AjvResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {default: Ajv} = await import('ajv');
const {default: Ajv} = await import(/* webpackIgnore: true */ 'ajv');
return new Ajv();
});

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/deepkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface DeepkitResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {validate} = await import('@deepkit/type');
const {validate} = await import(/* webpackIgnore: true */ '@deepkit/type');
return {validate};
});

Expand Down
12 changes: 9 additions & 3 deletions src/adapters/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ export interface EffectResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {isRight} = await import('@effect/data/Either');
const {isSchema, parseEither} = await import('@effect/schema/Schema');
const {formatErrors} = await import('@effect/schema/TreeFormatter');
const {isRight} = await import(
/* webpackIgnore: true */ '@effect/data/Either'
);
const {isSchema, parseEither} = await import(
/* webpackIgnore: true */ '@effect/schema/Schema'
);
const {formatErrors} = await import(
/* webpackIgnore: true */ '@effect/schema/TreeFormatter'
);
return {formatErrors, isRight, isSchema, parseEither};
});

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/io-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface IoTsResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {isRight} = await import('fp-ts/Either');
const {isRight} = await import(/* webpackIgnore: true */ 'fp-ts/Either');
return {isRight};
});

Expand Down
4 changes: 3 additions & 1 deletion src/adapters/ow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export interface OwResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {default: ow, ArgumentError} = await import('ow');
const {default: ow, ArgumentError} = await import(
/* webpackIgnore: true */ 'ow'
);
return {ArgumentError, ow};
});

Expand Down
4 changes: 3 additions & 1 deletion src/adapters/typebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export interface TypeBoxResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {TypeCompiler} = await import('@sinclair/typebox/compiler');
const {TypeCompiler} = await import(
/* webpackIgnore: true */ '@sinclair/typebox/compiler'
);
return {TypeCompiler};
});

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ValibotResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {safeParseAsync} = await import('valibot');
const {safeParseAsync} = await import(/* webpackIgnore: true */ 'valibot');
return {safeParseAsync};
});

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/yup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface YupResolver extends Resolver {
}

export const fetchModule = /* @__PURE__ */ memoize(async () => {
const {ValidationError} = await import('yup');
const {ValidationError} = await import(/* webpackIgnore: true */ 'yup');
return {ValidationError};
});

Expand Down

0 comments on commit 8fa8b33

Please sign in to comment.