Skip to content

Commit

Permalink
Merge pull request #60 from ryoppippi/feature/fix-bun-docs
Browse files Browse the repository at this point in the history
Update dependencies and enhance Bun build support
  • Loading branch information
ryoppippi authored Jun 9, 2024
2 parents f0572da + 2a0f88d commit 9966a5a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 43 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/bun-build/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import UnpluginTypia from 'unplugin-typia/bun'

await Bun.build({
entrypoints: ["./index.ts"],
entrypoints: ["./index.ts" ,"./index.build.ts"],
outdir: "./out",
plugins: [
UnpluginTypia()
UnpluginTypia({ cache: false })
]
});
32 changes: 32 additions & 0 deletions examples/bun-build/index.build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This is the example of how to use typia with bun
*/

import typia, { type tags } from "typia"

/** define the schema of the member */
interface IMember {
/**
* email of the member
*/
email: string & tags.Format<"email">;

/**
* id of the member
*/
id: string & tags.Format<"uuid">;

/**
* age of the member
* age should be greater than 19
*/
age: number & tags.ExclusiveMinimum<19> & tags.Maximum<100>;

/**
* pattern of the member
*/
pattern: string & tags.Pattern<"^[a-z]+$">;
}

const random = typia.createRandom<IMember>();
console.log(random())
5 changes: 4 additions & 1 deletion examples/bun-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"type": "module",
"scripts": {
"prepare": "ts-patch install && typia patch",
"test": "bun run ./index.ts",
"test": "run-s test:*",
"test:runtime": "bun run ./index.ts",
"test:build": "npm run build && bun run ./out/*.js",
"build": "bun run ./build.ts"
},
"devDependencies": {
"@types/bun": "latest",
"npm-run-all2": "^6.2.0",
"typia": "^6.0.6"
},
"peerDependencies": {
Expand Down
52 changes: 27 additions & 25 deletions packages/unplugin-typia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,33 @@ Examples:
<details>
<summary>Bun.build</summary><br>

### Example 1: Using for running script
### Example 1: Using for building script

```ts
// build.ts
import UnpluginTypia from 'unplugin-typia/bun';

await Bun.build({
entrypoints: ['./index.ts'],
outdir: './out',
plugins: [
UnpluginTypia({ /* your options */})
]
});
```

For building the script:

```sh
bun run ./build.ts
node ./out/index.js
```

Check the [Plugins – Bundler | Bun Docs](https://bun.sh/docs/bundler/plugins) for more details.

### Example 2: Using for running script

> ⚠️ Note: Experimental feature. Some typia functions does not works because of bun/typia/randexp internal implementation. see the [issse](https://github.com/ryoppippi/unplugin-typia/issues/44)
```ts
// preload.ts
Expand All @@ -138,30 +164,6 @@ bun run ./index.ts

Check the [Plugins – Runtime | Bun Docs](https://bun.sh/docs/runtime/plugins) for more details.

### Example 2: Using for building script

```ts
// build.ts
import UnpluginTypia from 'unplugin-typia/bun';

await Bun.build({
entrypoints: ['./index.ts'],
outdir: './out',
plugins: [
UnpluginTypia({ /* your options */})
]
});
```

For building the script:

```sh
bun run ./build.ts
node ./out/index.js
```

Check the [Plugins – Bundler | Bun Docs](https://bun.sh/docs/bundler/plugins) for more details.

<br></details>

<details>
Expand Down
41 changes: 26 additions & 15 deletions packages/unplugin-typia/src/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,30 @@ if (globalThis.Bun == null) {
/**
* bun plugin
*
* some typia functions does not works because of bun/typia internal implementation. see the [issse](https://github.com/ryoppippi/unplugin-typia/issues/44)
* @experimental
* also check out hte [Bun.build docc](https://bun.sh/docs/bundler)
* @example
* ```ts
* // build.ts
*
* import UnpluginTypia from 'unplugin-typia/bun'
*
* Bun.build({
* entrypoints: ['./index.ts'],
* outdir: './out',
* plugins: [
* UnpluginTypia({ /* your options *\/})
* ]
* })
*
* ```sh
* $ node build.ts
* ```
*
* Check the [Plugins – Bundler | Bun Docs](https://bun.sh/docs/bundler/plugins) for more details.
*
* @example
* @experimental
* some typia functions does not works because of bun/typia/randexp internal implementation. see the [issse](https://github.com/ryoppippi/unplugin-typia/issues/44)
*
* ```ts
* // preload.ts
* import { plugin } from 'bun';
Expand All @@ -36,19 +55,11 @@ if (globalThis.Bun == null) {
* preload = ["./preload.ts"]
* ```
*
* @example
* ```ts
* // build.ts
*
* import UnpluginTypia from 'unplugin-typia/bun'
* ```sh
* $ bun run ./index.ts
* ```
* Check the [Plugins – Runtime | Bun Docs](https://bun.sh/docs/runtime/plugins) for more details.
*
* Bun.build({
* entrypoints: ['./index.ts'],
* outdir: './out',
* plugins: [
* UnpluginTypia({ /* your options *\/})
* ]
* })
*/
function bunTypiaPlugin(
options?: Options,
Expand Down

0 comments on commit 9966a5a

Please sign in to comment.