Skip to content

Commit

Permalink
Using bun (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail authored Jul 7, 2024
1 parent d6b59be commit 09285f3
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 3,347 deletions.
14 changes: 0 additions & 14 deletions .github/dependabot.yml

This file was deleted.

57 changes: 29 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@ jobs:
unitTest:
runs-on: ubuntu-latest
steps:
- name: Get yarn cache dir
id: yarnCache
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
node-version: 18.x
bun-version: latest
- name: Get bun cache dir
id: bunCache
run: echo "dir=$(bun pm cache)" >> $GITHUB_OUTPUT
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-yarn
cache-name: cache-bun
with:
path: ${{ steps.yarnCache.outputs.dir }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.bunCache.outputs.dir }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/bun.lockb') }}
- name: Install dependencies
run: yarn install
run: bun install
- name: Testing
run: |
yarn lint
yarn test
bun run lint
bun run test
- name: Coveralls
uses: coverallsapp/github-action@v2
continue-on-error: true
with:
github-token: ${{ secrets.github_token }}
- name: Benchmark
run: yarn vitest bench --run
run: bunx vitest bench --run --outputJson bench.json
- name: Benchmark processing
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "# Performance benchmark" >> bench.txt
echo ${{ github.event.pull_request.head.sha }} >> bench.txt
echo '```' >> bench.txt
yarn tsx tools/benchmark.processor.ts >> bench.txt
bun run tools/benchmark.processor.ts >> bench.txt
echo '```' >> bench.txt
- name: Store results
if: ${{ github.event_name == 'pull_request' }}
Expand Down Expand Up @@ -109,43 +109,44 @@ jobs:
- 5.15.0
- latest
steps:
- name: Get yarn cache dir
id: yarnCache
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
node-version: 18.x
bun-version: latest
- name: Get bun cache dir
id: bunCache
run: echo "dir=$(bun pm cache)" >> $GITHUB_OUTPUT
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-yarn
cache-name: cache-bun
with:
path: ${{ steps.yarnCache.outputs.dir }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.bunCache.outputs.dir }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/bun.lockb') }}
- name: Install dependencies
run: yarn install
run: bun install
- name: Build
run: yarn build
run: bun run build
- name: Test
env:
MUI_VERSION: ${{ matrix.mui-version }}
run: |
bun link
cat >integration-test/package.json <<EOF
{
"name": "integration-test",
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"merge-sx": "link:./..",
"merge-sx": "link:merge-sx",
"@mui/material": "${MUI_VERSION}",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
EOF
cat integration-test/package.json
yarn install --cwd=integration-test
yarn intTest
bun --cwd=integration-test install
bun run intTest
7 changes: 6 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ jobs:
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: yarn install
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- run: npm publish --tag ${{ inputs.tag }}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_KEY}}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Version 3

### v3.0.0

- There are no breaking changes, but the distribution build process has changed:
- ESM is built using [bun](https://bun.sh/);
- DTS is built using [bun plugin Isolated Declarations](https://github.com/ryoppippi/bun-plugin-isolated-decl)
that runs [oxc transformer](https://www.npmjs.com/package/oxc-transform) under the hood;
- CJS is built using [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html)
and minified using [uglify-js](https://www.npmjs.com/package/uglify-js).

## Version 2

### v2.0.3
Expand Down
Binary file added bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[test]
coverage = true # always enable coverage
coverageReporter = ["text", "lcov"]
16 changes: 3 additions & 13 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@ import jsPlugin from "@eslint/js";
import tsPlugin from "typescript-eslint";
import prettierOverrides from "eslint-config-prettier";
import prettierRules from "eslint-plugin-prettier/recommended";
import unicornPlugin from "eslint-plugin-unicorn";
import importPlugin from "eslint-plugin-import";

export default [
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
plugins: {
unicorn: unicornPlugin,
import: importPlugin,
},
languageOptions: { globals: globals.browser },
plugins: { import: importPlugin },
settings: {
// "import-x" plugin installed as "import", in order to suppress the warning from the typescript resolver
// @link https://github.com/import-js/eslint-import-resolver-typescript/issues/293
"import-x/resolver": { typescript: true, node: true },
"import-x/resolver": { typescript: true },
},
},
jsPlugin.configs.recommended,
Expand All @@ -33,7 +24,6 @@ export default [
// Things to turn on globally
{
rules: {
"unicorn/prefer-node-protocol": "error",
"import/named": "error",
"import/export": "error",
"import/no-duplicates": "warn",
Expand Down
2 changes: 1 addition & 1 deletion integration-test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package.json
yarn.lock
bun.lockb
2 changes: 1 addition & 1 deletion integration-test/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SxProps, Theme } from "@mui/system";
import { mergeSx } from "merge-sx";
import { describe, test, expect } from "vitest";
import { describe, test, expect } from "bun:test";

describe("Integration", () => {
test("mergeSx() operates SxProps", () => {
Expand Down
37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "merge-sx",
"version": "2.0.3",
"version": "3.0.0-beta.2",
"description": "Combines multiple SxProps for Material UI components.",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down Expand Up @@ -34,37 +34,38 @@
},
"license": "MIT",
"scripts": {
"build": "tsup && attw --pack",
"build:cjs": "tsc -p tsconfig.cjs.json && uglifyjs dist/index.js -c -m -o dist/index.cjs",
"build": "bun run build:cjs && bun run tools/build.ts && cp dist/index.d.ts dist/index.d.cts && attw --pack",
"lint": "eslint",
"test": "tsc -p tsconfig.unit.json && vitest run src --coverage",
"intTest": "tsc -p integration-test/tsconfig.json && vitest run -r integration-test",
"test": "tsc --noEmit && bun test src",
"intTest": "tsc -p integration-test/tsconfig.json && bun test integration-test",
"mdfix": "prettier *.md --write",
"postversion": "git push && git push --tags",
"prepublishOnly": "yarn lint && yarn test && yarn build"
"prepublishOnly": "bun run lint && bun run test && bun run build"
},
"peerDependencies": {
"@mui/material": "^5.1.0"
"@mui/material": "^5.15.17"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.0",
"@mui/system": "^5.15.0",
"@tsconfig/node18": "^18.2.2",
"@types/node": "^20.10.4",
"@vitest/coverage-istanbul": "^1.6.0",
"@arethetypeswrong/cli": "^0.15.3",
"@emotion/styled": "^11.11.5",
"@mui/system": "^5.16.0",
"@tsconfig/bun": "^1.0.7",
"@tsconfig/node18": "^18.2.4",
"@types/bun": "latest",
"bun-plugin-isolated-decl": "^0.1.1",
"eslint": "^9.6.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "https://registry.npmjs.org/eslint-plugin-import-x/-/eslint-plugin-import-x-0.5.2.tgz",
"eslint-plugin-import": "npm:eslint-plugin-import-x@^0.5.3",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-unicorn": "^54.0.0",
"globals": "^15.3.0",
"globals": "^15.8.0",
"oxc-transform": "^0.17.0",
"prettier": "3.3.2",
"react": "^18.3.1",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.3.3",
"typescript": "^5.5.3",
"typescript-eslint": "^8.0.0-alpha.39",
"vitest": "^1.6.0"
"uglify-js": "^3.18.0"
},
"resolutions": {
"**/@typescript-eslint/utils": "=8.0.0-alpha.39"
Expand Down
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SxProps, Theme } from "@mui/system";
import { mergeSx } from "./index";
import { describe, it, expect } from "vitest";
import { describe, it, expect } from "bun:test";

describe("mergeSx()", () => {
describe("simple cases", () => {
Expand Down
2 changes: 1 addition & 1 deletion tools/benchmark.bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SxProps, Theme } from "@mui/system";
import type { SxProps, Theme } from "@mui/system";
import { mergeSx } from "../src";
import { bench, describe } from "vitest";

Expand Down
5 changes: 1 addition & 4 deletions tools/benchmark.processor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { readFileSync } from "node:fs";

const text = readFileSync("bench.json", "utf-8");
const json = JSON.parse(text);
const json = await Bun.file("bench.json", { type: "application/json" }).json();
const data = json.files[0].groups[0];
const suite = data.fullName.split(">")[1].trim();

Expand Down
14 changes: 14 additions & 0 deletions tools/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import isolatedDecl from "bun-plugin-isolated-decl";

await Bun.build({
entrypoints: ["src/index.ts"],
outdir: "dist",
/** @link https://github.com/oven-sh/bun/issues/159 */
format: "esm",
splitting: false,
sourcemap: "none",
minify: true,
plugins: [isolatedDecl()],
target: "browser",
external: ["*"],
});
11 changes: 11 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"moduleResolution": "node",
"target": "ES6",
"removeComments": true
},
"include": ["src/index.ts"]
}
11 changes: 3 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"strict": true,
"target": "ES6",
"module": "ES2022",
"moduleResolution": "Bundler",
"skipLibCheck": true
}
"extends": "@tsconfig/bun/tsconfig.json",
"compilerOptions": {},
"include": ["src"]
}
7 changes: 0 additions & 7 deletions tsconfig.unit.json

This file was deleted.

12 changes: 0 additions & 12 deletions tsup.config.ts

This file was deleted.

16 changes: 0 additions & 16 deletions vitest.config.ts

This file was deleted.

Loading

0 comments on commit 09285f3

Please sign in to comment.