Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrate to bun + refactor #335

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const OFF = 0;
const WARN = 1;
const ERROR = 2;

/** @type {import('eslint/lib/shared/types').ConfigData & { parserOptions: import('@typescript-eslint/types').ParserOptions }} */
module.exports = {
root: true,
reportUnusedDisableDirectives: true,
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./test/tsconfig.json'],
project: ['tsconfig.json', 'tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
extends: [
Expand All @@ -16,10 +18,23 @@ module.exports = {
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:unicorn/recommended',
'prettier',
],
plugins: ['prettier'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': ERROR,
'import/prefer-default-export': OFF,
'no-restricted-syntax': OFF,
'no-void': OFF,
'prettier/prettier': WARN,
'unicorn/filename-case': OFF,
'unicorn/no-abusive-eslint-disable': WARN,
'unicorn/no-null': OFF,
'unicorn/prefer-module': WARN,
'unicorn/prefer-node-protocol': OFF, // incompatible with older node versions
'unicorn/prefer-string-replace-all': OFF, // incompatible with older node versions
'unicorn/prefer-top-level-await': WARN,
'unicorn/prevent-abbreviations': OFF,
},
};
44 changes: 23 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@ name: ci
on:
push:
branches: [master]
paths-ignore: ['**.md']
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: oven-sh/setup-bun@v1
with:
node-version: 18
- run: npm install --global pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm run build
- run: pnpm run test
- name: Report coverage
if: ${{ github.repository_owner == 'maxmilton' }}
run: |
curl -Lo ./cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.json coverage/lcov.info
./cc-test-reporter upload-coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
bun-version: latest
- run: bun install
- run: bun run build
- run: bun run test
# FIXME: Enable coverage reporting once bun test supports it; https://github.com/oven-sh/bun/issues/2311
# - name: Report coverage
# if: ${{ github.repository_owner == 'maxmilton' }}
# run: |
# curl -Lo ./cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
# chmod +x ./cc-test-reporter
# ./cc-test-reporter format-coverage -t lcov -o coverage/codeclimate.json coverage/lcov.info
# ./cc-test-reporter upload-coverage
# env:
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: oven-sh/setup-bun@v1
with:
node-version: 18
- run: npm install --global pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm run build
- run: pnpm run lint
bun-version: latest
- run: bun install
- run: bun run build
- run: bun run lint
4 changes: 3 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- uses: github/codeql-action/init@v2
with:
languages: javascript
queries: security-extended,security-and-quality
queries: security-and-quality
- uses: github/codeql-action/autobuild@v2
- uses: github/codeql-action/analyze@v2
with:
category: '/language:javascript'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*-lock.json*
*-lock.yaml
*.lock
*.log
*.tsbuildinfo
/coverage/
dist
node_modules
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"arrowParens": "always",
"endOfLine": "lf",
"singleQuote": true,
"trailingComma": "all",
"plugins": ["prettier-plugin-pkg"],
"overrides": [
{
"files": ["*.spec.ts", "*.test.ts"],
"options": {
"printWidth": 100
}
}
]
}
6 changes: 1 addition & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"rohit-gohri.format-code-action"
]
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
39 changes: 0 additions & 39 deletions .vscode/launch.json

This file was deleted.

29 changes: 22 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{
"editor.codeActionsOnSave": [
"source.sortImports",
"source.fixAll.format",
"source.fixAll.eslint"
],
"editor.codeActionsOnSave": {
"source.fixAll": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": false,
"eslint.lintTask.options": "--ignore-path .gitignore",
"git.branchProtection": ["master"],
"js/ts.implicitProjectConfig.checkJs": true
"js/ts.implicitProjectConfig.checkJs": true,
"prettier.ignorePath": ".gitignore",
"typescript.tsdk": "node_modules/typescript/lib",
"[javascript]": {
"editor.codeActionsOnSave": {
"source.sortImports": true,
"source.fixAll": true
}
},
"[typescript]": {
"editor.codeActionsOnSave": {
"source.sortImports": true,
"source.fixAll": true
}
}
}
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ Tools to minify [template literal strings](https://developer.mozilla.org/en-US/d
npm install --save-dev esbuild-minify-templates
```

or

```sh
yarn add -D esbuild-minify-templates
```

## Usage

Add the two esbuild plugins to your build options and set the [write option](https://esbuild.github.io/api/#write) to false.
Expand Down
38 changes: 38 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable no-console */

import esbuild from 'esbuild';
import pkg from './package.json' assert { type: 'json' };

const external = Object.keys(pkg.dependencies);

// Node CJS bundle
const out1 = await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
platform: 'node',
target: ['node12'],
external,
bundle: true,
sourcemap: true,
minify: true,
metafile: true && process.stdout.isTTY,
logLevel: 'debug',
});

// Node ESM bundle
const out2 = await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.mjs',
platform: 'node',
format: 'esm',
target: ['node16'],
external,
bundle: true,
sourcemap: true,
minify: true,
metafile: true && process.stdout.isTTY,
logLevel: 'debug',
});

if (out1.metafile) console.log(await esbuild.analyzeMetafile(out1.metafile));
if (out2.metafile) console.log(await esbuild.analyzeMetafile(out2.metafile));
Binary file added bun.lockb
Binary file not shown.
33 changes: 15 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,45 @@
"node": ">= 12"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "pnpm run prebuild && tsc",
"dev": "tsc --watch --preserveWatchOutput",
"lint": "pnpm run lint:js && pnpm run lint:ts",
"build": "bun build.ts",
"lint": "bun run lint:js && bun run lint:ts",
"lint:js": "eslint --ignore-path .gitignore --ext .ts,.js,.mjs,.cjs .",
"lint:ts": "tsc --noEmit",
"postbuild": "tsc --emitDeclarationOnly -p tsconfig.dts.json",
"prebuild": "rm -rf dist",
"test": "c8 --all --include=src --reporter=text --reporter=lcovonly uvu -r tsm test '\\.test\\.ts$'"
"test": "bun test"
},
"peerDependencies": {
"esbuild": "^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0"
"esbuild": ">=0.13.0 <1.0.0"
},
"dependencies": {
"@ampproject/remapping": "^2.2.0",
"@ampproject/remapping": "^2.2.1",
"astray": "^1.1.1",
"magic-string": "^0.30.0",
"meriyah": "^4.3.0"
"meriyah": "^4.3.7"
},
"devDependencies": {
"@types/estree": "1.0.1",
"@types/node": "18.16.16",
"@types/node": "20.2.5",
"@typescript-eslint/eslint-plugin": "5.59.8",
"@typescript-eslint/parser": "5.59.8",
"c8": "7.14.0",
"bun-types": "0.6.7",
"esbuild": "0.17.19",
"eslint": "8.42.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "17.0.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-unicorn": "47.0.0",
"prettier": "2.8.8",
"tsm": "2.3.0",
"typescript": "4.9.5",
"uvu": "0.5.6"
},
"prettier": {
"arrowParens": "always",
"endOfLine": "lf",
"singleQuote": true,
"trailingComma": "all"
"prettier-plugin-pkg": "0.17.1",
"typescript": "5.1.3"
}
}