Skip to content

Commit

Permalink
Merge pull request #1080 from ryoppippi/feature/add-bun-support
Browse files Browse the repository at this point in the history
feat: Add support for 'bun' package manager
  • Loading branch information
samchon committed Jun 9, 2024
2 parents 2ed7574 + 2fc82e2 commit 1adadf9
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 18 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ on:
paths:
- 'src/**'
- 'test/**'
- 'test-esm/**'
- 'package.json'
pull_request:
paths:
- 'src/**'
- 'test/**'
- 'test-esm/**'
- 'package.json'
jobs:
Ubuntu:
Expand All @@ -18,6 +20,9 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: actions/cache@v4
with:
path: ~/.npm
Expand All @@ -27,4 +32,4 @@ jobs:
- run: npm install
- run: npm run build
- run: npm run test
- run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/
packages/typescript-json/src/
package-lock.json
pnpm-lock.yaml
bun.lockb

*.log
*.tgz
13 changes: 12 additions & 1 deletion deploy/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chalk from "chalk";
import cp from "child_process";
import $ from "dax-sh";
import fs from "fs";

import { ReplicaPublisher } from "./internal/ReplicaPublisher";
Expand Down Expand Up @@ -73,7 +74,12 @@ const title = (label: string): void => {
console.log("---------------------------------------------------------");
};

const main = (): void => {
const detectComanndAvailable = async (command: string): Promise<boolean> => {
const path = await $.which(command);
return path !== null;
};

const main = async (): Promise<void> => {
const tag: string | undefined = process.argv[2];
if (tag === undefined) {
console.log("specify tag name like latest or next");
Expand All @@ -93,6 +99,11 @@ const main = (): void => {
: ["npm run build", "npm start"],
);
test(version)("test-esm")(["npm run build", "npm start"]);
/* if bun is available, test with bun */
if (await detectComanndAvailable("bun")) {
test(version)("test")(["bun --bun run build_run", "bun --bun run start"]);
test(version)("test-esm")(["bun --bun run build", "bun --bun run start"]);
}
test(version)("errors")(["npm start"]);
test(version)("benchmark")(["npm run build"]);

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"chalk": "^4.0.0",
"dax-sh": "^0.41.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"rollup": "^4.18.0",
Expand Down
3 changes: 2 additions & 1 deletion src/executable/TypiaSetupWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PluginConfigurator } from "./setup/PluginConfigurator";

export namespace TypiaSetupWizard {
export interface IArguments {
manager: "npm" | "pnpm" | "yarn";
manager: "npm" | "pnpm" | "yarn" | "bun";
project: string | null;
}

Expand Down Expand Up @@ -137,6 +137,7 @@ export namespace TypiaSetupWizard {
[
"npm" as const,
"pnpm" as const,
"bun" as const,
"yarn (berry is not supported)" as "yarn",
],
(value) => value.split(" ")[0] as "yarn",
Expand Down
25 changes: 20 additions & 5 deletions src/executable/setup/PackageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ import path from "path";
import { CommandExecutor } from "./CommandExecutor";
import { FileRetriever } from "./FileRetriever";

const managers = ["npm", "pnpm", "yarn", "bun"] as const;
type Manager = (typeof managers)[number];

const installCmdTable = {
npm: "install",
pnpm: "add",
yarn: "add",
bun: "add",
} as const satisfies Record<Manager, string>;
const devOptionTable = {
npm: "--save-dev",
pnpm: "--save-dev",
yarn: "--dev",
bun: "--dev",
} as const satisfies Record<Manager, string>;

export class PackageManager {
public manager: string = "npm";
public manager: Manager = "npm";
public get file(): string {
return path.join(this.directory, "package.json");
}
Expand Down Expand Up @@ -40,10 +56,9 @@ export class PackageManager {
modulo: string;
version: string;
}): boolean {
const middle: string =
this.manager === "yarn"
? `add${props.dev ? " -D" : ""}`
: `install ${props.dev ? "--save-dev" : "--save"}`;
const cmd = installCmdTable[this.manager];
const option = props.dev ? devOptionTable[this.manager] : "";
const middle: string = `${cmd} ${option}` as const;
CommandExecutor.run(
`${this.manager} ${middle} ${props.modulo}${
props.version ? `@${props.version}` : ""
Expand Down
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"build": "rimraf bin && tsc",
"build_run": "npm run build",
"prepare": "ts-patch install",
"prettier": "prettier ./src/**/*.ts --write",
"setup": "node build/setup.js",
Expand Down
84 changes: 74 additions & 10 deletions website/pages/docs/setup.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Callout, Tabs, Tab } from 'nextra-theme-docs'

## Summary
<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" showLineNumbers copy
npm install typia
Expand All @@ -19,6 +19,12 @@ pnpm typia setup --manager pnpm
# YARN BERRY IS NOT SUPPORTED
yarn add typia
yarn typia setup --manager yarn
```
</Tab>
<Tab>
```bash filename="Terminal" showLineNumbers copy
bun add typia
bun typia setup --manager bun
```
</Tab>
</Tabs>
Expand Down Expand Up @@ -95,7 +101,7 @@ exports.check = check;
</Tabs>

### Setup Wizard
<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
npm install --save typia
Expand All @@ -113,6 +119,12 @@ pnpm typia setup --manager pnpm
# YARN BERRY IS NOT SUPPORTED
yarn add typia
yarn typia setup --manager yarn
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
bun add typia
bun typia setup --manager bun
```
</Tab>
</Tabs>
Expand All @@ -122,7 +134,7 @@ You can turn on transformation mode just by running `npx typia setup` command.
Setup wizard would be executed, and it will do everything for the transformation.

### Manual Setup
<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
npm install --save typia
Expand All @@ -140,6 +152,12 @@ pnpm install --save-dev typescript ts-patch
# YARN BERRY IS NOT SUPPORTED
yarn add typia
yarn add -D typescript ts-patch
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
bun add typia
bun add -d typescript ts-patch
```
</Tab>
</Tabs>
Expand Down Expand Up @@ -179,7 +197,7 @@ As `typia` generates optimal operation code through transformation, it must be c
}
```

<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
npm run prepare
Expand All @@ -194,6 +212,11 @@ pnpm prepare
```bash filename="Terminal" copy showLineNumbers
# YARN BERRY IS NOT SUPPORTED
yarn prepare
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
bun prepare
```
</Tab>
</Tabs>
Expand Down Expand Up @@ -236,7 +259,7 @@ Currently, `unplugin-typia` supports the following bundlers:
- [Vite](https://jsr.io/@ryoppippi/unplugin-typia/doc/vite/~/default)
- [Webpack](https://webpack.js.org/)

<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" showLineNumbers copy
npx jsr add -D @ryoppippi/unplugin-typia
Expand All @@ -257,6 +280,13 @@ pnpm typia setup --manager pnpm
yarn dlx jsr add -D @ryoppippi/unplugin-typia
yarn add typia
yarn typia setup --manager yarn
```
</Tab>
<Tab>
```bash filename="Terminal" showLineNumbers copy
bun add @ryoppippi/unplugin-typia
bun add typia
bun typia setup
```
</Tab>
</Tabs>
Expand Down Expand Up @@ -315,7 +345,7 @@ build({
[`unplugin-typia`](#unplugin-typia) also supports `webpack` as well.
</Callout>

<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
# TYPIA
Expand Down Expand Up @@ -350,6 +380,17 @@ yarn typia setup --manager yarn
# WEBPACK + TS-LOADER
yarn add -D ts-loader
yarn add -D webpack webpack-cli
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
# TYPIA
bun add typia
bun typia setup

# WEBPACK + TS-LOADER
bun add -d ts-loader
bun add -d webpack webpack-cli
```
</Tab>
</Tabs>
Expand Down Expand Up @@ -393,7 +434,7 @@ module.exports = {

From now on, you can build the single JS file just by running the `npx webpack` command. By the way, when removing `devDependencies` for `--production` install, never forget to add the `--ignore-scripts` option to prevent the `prepare` script.

<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
npx webpack
Expand All @@ -411,6 +452,12 @@ pnpm install --production --ignore-scripts
yarn webpack
rm -rf node_modules
yarn install --production --ignore-scripts --immutable
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
bun webpack
bun install --production --ignore-scripts
```
</Tab>
</Tabs>
Expand All @@ -425,7 +472,7 @@ Additionally, if you're using `typia` in the NodeJS project especially for the b


### NX
<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
npm install --save typia
Expand All @@ -445,6 +492,12 @@ yarn add typia
yarn typia setup --manager yarn
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
bun add typia
bun typia setup --manager bun
```
</Tab>
</Tabs>

After install `typia` like above, you have to modify `project.json` on each app like below.
Expand All @@ -470,7 +523,7 @@ After install `typia` like above, you have to modify `project.json` on each app


## Generation
<Tabs items={['npm', 'pnpm', 'yarn']}>
<Tabs items={['npm', 'pnpm', 'yarn', 'bun']}>
<Tab>
```bash filename="Terminal" copy showLineNumbers
# INSTALL TYPIA
Expand Down Expand Up @@ -508,6 +561,17 @@ yarn typia generate \
--input src/templates \
--output src/generated \
--project tsconfig.json
```
</Tab>
<Tab>
```bash filename="Terminal" copy showLineNumbers
# INSTALL TYPIA
bun add typia
bun add -d typescript
bun typia generate \
--input src/templates \
--output src/generated \
--project tsconfig.json
```
</Tab>
</Tabs>
Expand Down Expand Up @@ -566,4 +630,4 @@ export const check = (input: any): input is IMember => {
**Why not support non-standard compilers?**

Non-standard TypeScript compilers are removing every type informations, and skipping type checkings for rapid compilation. By the way, without those type informations, `typia` can't do anything. This is the reason why `typia` doesn't support non-standard TypeScript compilers.
</Callout>
</Callout>

0 comments on commit 1adadf9

Please sign in to comment.