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: deno support #1613

Merged
merged 7 commits into from
Feb 2, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,34 @@ jobs:

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

strategy:
max-parallel: 3
matrix:
deno-version:
- 2.1.9

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4

- name: Set up Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}

- name: Install
run: npm ci

- name: lint
run: deno run lint

- name: test build
run: deno task test:build

- name: test
run: deno task test
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,50 @@ jobs:
push: true
fetch: true
pull: '--rebase --autostash'
build-deno:
name: "Deno ${{ matrix.deno-version }}"

runs-on: ubuntu-latest

strategy:
max-parallel: 1
matrix:
deno-version:
- 2.1.9

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4

- name: Use Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}

- name: Install
run: npm ci

- name: Lint
run: deno run lint

- name: Test build
run: deno task test:build

- name: Test
run: deno task test

- name: generate benchmarks with deno
run: ./start.sh DENO

- name: push
uses: EndBug/add-and-commit@v9
## prevents forked repos from comitting results in PRs
if: github.repository == 'moltar/typescript-runtime-type-benchmarks'
with:
author_name: ${{ env.GIT_COMMIT_AUTHOR_NAME }}
author_email: ${{ env.GIT_COMMIT_AUTHOR_EMAIL }}
message: 'feat: ${{ matrix.deno-version }} adds auto-generated benchmarks and bar graph'
push: true
fetch: true
pull: '--rebase --autostash'
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ const res = isMyDataValid(data)
* Use `curl -fsSl https://bun.sh/install | bash -s "bun-v1.0.x"` to switch to a specific bun version
* `curl -fsSl https://bun.sh/install | bash -s "bun-v1.1.43"` - switch to bun 1.1.43

#### Deno

* Use `deno upgrade x.x.x` to switch to a specific Deno version
* `deno upgrade stable` - switch to Deno x.x.x

## Adding new runtime version

### Node.js runtime
Expand All @@ -162,6 +167,11 @@ const res = isMyDataValid(data)
* update bun version matrix in `.github/workflows/pr.yml` and `.github/workflows/release.yml`
* update `BUN_VERSIONS` in `docs/dist/app.tsx` and run `npm run docs:build`

### Deno runtime

* update Deno version matrix in `.github/workflows/pr.yml` and `.github/workflows/release.yml`
* update `DENO_VERSIONS` in `docs/dist/app.tsx` and run `npm run docs:build`

## Test cases

* **Safe Parsing**
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/helpers/graph.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeFileSync } from 'fs';
import { writeFileSync } from 'node:fs';
import { optimize } from 'svgo';
import { parse, View } from 'vega';
import { compile } from 'vega-lite';
Expand Down
30 changes: 27 additions & 3 deletions benchmarks/helpers/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import { add, complete, cycle, suite } from 'benny';
import { readFileSync, writeFileSync, existsSync, unlinkSync } from 'fs';
import { join } from 'path';
import { readFileSync, writeFileSync, existsSync, unlinkSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { writePreviewGraph } from './graph';
import { getRegisteredBenchmarks } from './register';
import type { BenchmarkCase, BenchmarkResult } from './types';

const DOCS_DIR = join(__dirname, '../../docs');
/**
* A getDirname that works in CJS and ESM, since this file is directly shared
* across both kinds of projects.
* @TODO We can remove this once we've migrated all consumers to ESM.
*
* @see https://stackoverflow.com/a/79251101/13503626
*/
function pathFromStack() {
const { stack } = new Error();
if (!stack) {
throw new Error('Could not get stack');
}
const lines = stack.split('\n');
for (const line of lines) {
if (line.includes(' (/') || line.includes(' (file://')) {
// assumes UNIX-like paths
const location = line.split(' (')[1].replace('file://', '');
const filepath = location.split(':')[0];
const dirpath = dirname(filepath);
return { dirpath, filepath };
}
}
throw new Error('Could not get dirname');
}
const DOCS_DIR = join(pathFromStack().dirpath, '../../docs');
const RUNTIME = process.env.RUNTIME || 'node';
const RUNTIME_VERSION = process.env.RUNTIME_VERSION || process.version;
const RUNTIME_FOR_PREVIEW = 'node';
Expand Down
11 changes: 11 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"unstable": [
// https://docs.deno.com/runtime/reference/cli/unstable_flags/#--unstable-sloppy-imports: needed because Deno can only read ESM modules but project lacks file extension in imports (.ts)
"sloppy-imports",
// https://docs.deno.com/runtime/reference/cli/unstable_flags/#--unstable-detect-cjs: needed as some of the packages are CJS but masquerade as ESM
"detect-cjs"
],
"compilerOptions": {
"experimentalDecorators": true
}
}
Loading