Skip to content

Commit

Permalink
Merge pull request #1225 from DarkGL/bun-support
Browse files Browse the repository at this point in the history
Bun support and linting configuration refactor
  • Loading branch information
hoeck authored Sep 14, 2024
2 parents 03bf304 + 9437ed5 commit 6826b79
Show file tree
Hide file tree
Showing 27 changed files with 548 additions and 136 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ docs/dist
cases/spectypes/build
cases/ts-runtime-checks/build
cases/typia/build
cases/deepkit/build
cases/deepkit/build
jest.config.js
27 changes: 25 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
{
"extends": "./node_modules/gts/",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"project": "./tsconfig.json",
"sourceType": "module"
},
"rules": {
"node/no-unpublished-import": "off"
"node/no-unpublished-import": "off",
"@typescript-eslint/consistent-type-imports": [
"error",
{
"prefer": "type-imports",
"fixStyle": "separate-type-imports"
}
],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/no-import-type-side-effects": "error"
},
"env": {
"jest": true
}
},
"overrides": [
{
"files": ["docs/**/*.tsx"],
"parserOptions": {
"project": "./tsconfig.docs.json"
}
}
]
}
29 changes: 29 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,32 @@ jobs:

- name: test
run: npm test
build-bun:
needs: build
runs-on: ubuntu-latest

strategy:
max-parallel: 3
matrix:
bun-version:
- 1.1.27

steps:
- uses: actions/checkout@v4

- name: Set up Bun ${{ matrix.bun-version }}
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ matrix.bun-version }}

- name: install
run: bun install

- name: lint
run: bun run lint

- name: test build
run: bun run test:build

- name: test
run: bun test
54 changes: 52 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- "*.ts"
- package.json
- package-lock.json
- bun.lockb

jobs:
build:
Expand Down Expand Up @@ -67,8 +68,8 @@ jobs:
- name: npm test
run: npm t

- name: generate benchmarks
run: ./start.sh
- name: generate benchmarks with node
run: ./start.sh NODE

## FIX: https://github.com/github-actions-x/commit/issues/16
- name: Expose git commit data
Expand All @@ -85,3 +86,52 @@ jobs:
rebase: 'true'
name: ${{ env.GIT_COMMIT_AUTHOR_NAME }} ## FIX: https://github.com/github-actions-x/commit/issues/16
email: ${{ env.GIT_COMMIT_AUTHOR_EMAIL }} ## FIX: https://github.com/github-actions-x/commit/issues/16
build-bun:
name: "Bun ${{ matrix.bun-version }}"

runs-on: ubuntu-latest

strategy:
max-parallel: 1
matrix:
bun-version:
- 1.1.27

steps:
- uses: actions/checkout@v4

- name: Use Bun ${{ matrix.bun-version }}
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ matrix.bun-version }}

- name: Install
run: bun install

- name: Lint
run: bun run lint

- name: Test build
run: bun run test:build

- name: Test
run: bun run test

- name: generate benchmarks with bun
run: ./start.sh BUN

## FIX: https://github.com/github-actions-x/commit/issues/16
- name: Expose git commit data
uses: rlespinasse/git-commit-data-action@v1 ## https://github.com/rlespinasse/git-commit-data-action

- name: push
uses: github-actions-x/[email protected]
## prevents forked repos from comitting results in PRs
if: github.repository == 'moltar/typescript-runtime-type-benchmarks'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
push-branch: master
commit-message: 'feat: ${{ matrix.bun-version }} adds auto-generated benchmarks and bar graph'
rebase: 'true'
name: ${{ env.GIT_COMMIT_AUTHOR_NAME }} ## FIX: https://github.com/github-actions-x/commit/issues/16
email: ${{ env.GIT_COMMIT_AUTHOR_EMAIL }} ## FIX: https://github.com/github-actions-x/commit/issues/16
67 changes: 60 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# Created by https://www.gitignore.io/api/node
# Edit at https://www.gitignore.io/?templates=node
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

### Node ###
# Logs
Expand All @@ -10,6 +9,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -49,6 +49,9 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

Expand All @@ -58,6 +61,15 @@ typings/
# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

Expand All @@ -67,25 +79,44 @@ typings/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# next.js build output
# Next.js build output
.next
out

# nuxt.js build output
# Nuxt.js build / generate output
.nuxt
dist

# react / gatsby
public/

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

Expand All @@ -95,7 +126,29 @@ public/
# DynamoDB Local files
.dynamodb/

# End of https://www.gitignore.io/api/node
# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

### Node Patch ###
# Serverless Webpack directories
.webpack/

# Optional stylelint cache

# SvelteKit build / generate output
.svelte-kit

# End of https://www.toptal.com/developers/gitignore/api/node

# sourcemaps
docs/dist/app.js.map
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/assertLoose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AssertLoose extends Benchmark<Fn> {
this.fn(validateData);
}

test() {
test(describe: jest.Describe, expect: jest.Expect, test: jest.It) {
describe(this.moduleName, () => {
test('should validate the data', () => {
expect(this.fn(validateData)).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/assertStrict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AssertStrict extends Benchmark<Fn> {
this.fn(validateData);
}

test() {
test(describe: jest.Describe, expect: jest.Expect, test: jest.It) {
describe(this.moduleName, () => {
test('should validate the data', () => {
expect(this.fn(validateData)).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/helpers/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { writeFileSync } from 'fs';
import { optimize } from 'svgo';
import { parse, View } from 'vega';
import { compile } from 'vega-lite';
import { availableBenchmarks, AvailableBenchmarksIds } from './register';
import { BenchmarkResult } from './types';
import { availableBenchmarks, type AvailableBenchmarksIds } from './register';
import type { BenchmarkResult } from './types';

interface PreviewGraphParams {
values: BenchmarkResult[];
Expand Down
25 changes: 16 additions & 9 deletions benchmarks/helpers/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { readFileSync, writeFileSync, existsSync, unlinkSync } from 'fs';
import { join } from 'path';
import { writePreviewGraph } from './graph';
import { getRegisteredBenchmarks } from './register';
import { BenchmarkCase, BenchmarkResult } from './types';
import type { BenchmarkCase, BenchmarkResult } from './types';

const DOCS_DIR = join(__dirname, '../../docs');
const NODE_VERSION = process.env.NODE_VERSION || process.version;
const RUNTIME = process.env.RUNTIME || 'node';
const RUNTIME_VERSION = process.env.RUNTIME_VERSION || process.version;
const RUNTIME_FOR_PREVIEW = 'node';
const NODE_VERSION_FOR_PREVIEW = 20;

/**
Expand All @@ -28,7 +30,8 @@ export async function runAllBenchmarks() {
name,
ops,
margin,
nodeVersion: NODE_VERSION,
runtime: RUNTIME,
runtimeVersion: RUNTIME_VERSION,
});
});
}
Expand All @@ -54,7 +57,10 @@ export function deleteResults() {
export async function createPreviewGraph() {
const majorVersion = getNodeMajorVersion();

if (majorVersion === NODE_VERSION_FOR_PREVIEW) {
if (
majorVersion === NODE_VERSION_FOR_PREVIEW &&
RUNTIME_FOR_PREVIEW === 'node'
) {
const allResults: BenchmarkResult[] = JSON.parse(
readFileSync(resultsJsonFilename()).toString()
).results;
Expand Down Expand Up @@ -96,9 +102,10 @@ function appendResults(results: BenchmarkResult[]) {
const getKey = ({
benchmark,
name,
nodeVersion,
runtime,
runtimeVersion,
}: BenchmarkResult): string => {
return JSON.stringify({ benchmark, name, nodeVersion });
return JSON.stringify({ benchmark, name, runtime, runtimeVersion });
};
const existingResultsIndex = new Set(existingResults.map(r => getKey(r)));

Expand All @@ -124,7 +131,7 @@ function appendResults(results: BenchmarkResult[]) {
function resultsJsonFilename() {
const majorVersion = getNodeMajorVersion();

return join(DOCS_DIR, 'results', `node-${majorVersion}.json`);
return join(DOCS_DIR, 'results', `${RUNTIME}-${majorVersion}.json`);
}

function previewSvgFilename() {
Expand All @@ -134,13 +141,13 @@ function previewSvgFilename() {
function getNodeMajorVersion() {
let majorVersion = 0;

majorVersion = parseInt(NODE_VERSION);
majorVersion = parseInt(RUNTIME_VERSION);

if (!isNaN(majorVersion)) {
return majorVersion;
}

majorVersion = parseInt(NODE_VERSION.slice(1));
majorVersion = parseInt(RUNTIME_VERSION.slice(1));

if (!isNaN(majorVersion)) {
return majorVersion;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/helpers/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AssertLoose } from '../assertLoose';
import { AssertStrict } from '../assertStrict';
import { ParseSafe } from '../parseSafe';
import { ParseStrict } from '../parseStrict';
import { BenchmarkCase } from './types';
import type { BenchmarkCase } from './types';

/**
* Map of all benchmarks.
Expand Down
Loading

0 comments on commit 6826b79

Please sign in to comment.