Skip to content

Commit

Permalink
Add support for Deno, Bun (#53)
Browse files Browse the repository at this point in the history
Also:

* Improve typescript typings
* Update format/lint
* Fix circular dependency
* Replace `yargs` with `minimist`
* Replace `mocha` with `vitest`
* Configure GitHub Actions
  • Loading branch information
daohoangson authored Sep 15, 2023
1 parent b052276 commit 3ba4318
Show file tree
Hide file tree
Showing 19 changed files with 1,415 additions and 692 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/demo_parser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: demo/parser

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
bun:
runs-on: ubuntu-latest
defaults:
run:
working-directory: demo/parser

steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
submodules: recursive
- name: Setup Bun
uses: oven-sh/setup-bun@a1800f471a0bc25cddac36bb13e6f436ddf341d7 # v1
- run: bun install

- run: npm run bun:build
- run: ./bin/cli --debug -- hanoi

- run: npm run bun:run -- --debug -- hanoi

deno:
runs-on: ubuntu-latest
defaults:
run:
working-directory: demo/parser

steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
submodules: recursive
- name: Setup Deno
uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2

- run: npm run deno:compile
- run: ./bin/cli --debug -- hanoi

- run: npm run deno:run -- --debug -- hanoi

node:
runs-on: ubuntu-latest
defaults:
run:
working-directory: demo/parser

strategy:
matrix:
node-version:
# TODO: re-enable v16, v18 when OOM is fixed
# - 16.x
# - 18.x
- 20.x

steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
with:
submodules: recursive
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
cache: npm
cache-dependency-path: ./demo/parser/package-lock.json
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
- run: npm test

- run: npm run build:bin
- run: node bin/cli.js --debug -- hanoi
8 changes: 4 additions & 4 deletions demo/parser/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module.exports = {
parser: "@typescript-eslint/parser",
extends: [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"prettier",
],
parserOptions: {
ecmaVersion: 2021,
sourceType: "module"
}
sourceType: "module",
},
};
2 changes: 2 additions & 0 deletions demo/parser/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/bin/cli
/bin/cli.js
/node_modules
1 change: 1 addition & 0 deletions demo/parser/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO
15 changes: 0 additions & 15 deletions demo/parser/api/now-build.sh

This file was deleted.

14 changes: 14 additions & 0 deletions demo/parser/api/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-check

import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";

/** @type {import("rollup").RollupOptions} */
export default {
input: "api/vercel.ts",
plugins: [json(), typescript()],
output: {
file: "api/index.js",
format: "cjs",
},
};
File renamed without changes.
35 changes: 8 additions & 27 deletions demo/parser/bin/cli.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,15 @@
#!npx ts-node
import process from "node:process";
import readline from "node:readline";
import minimist from "minimist";

import readline from "readline";
import yargs from "yargs";

import Parser from "../src/parser";
import Parser from "../src/parser.ts";

async function main() {
const argv = await yargs
.help()
.option("debug", {
boolean: true,
description: "Run with debug output",
})
.option("json", {
boolean: true,
description: "Json decode input before parsing",
})
.alias("h", "help").argv;

const { debug, json } = argv;
const parser = new Parser({ debug });

const parseInput = (input) => {
if (json) {
const decoded = JSON.parse(input);
if (decoded && typeof decoded.input === "string") {
input = decoded.input;
}
}
const argv = minimist(process.argv.slice(2));
const { debug } = argv;
const parser = new Parser({ debug: debug === true });

const parseInput = (input: string) => {
process.stdout.write(
JSON.stringify({ input, output: parser.parse(input) }) + "\n"
);
Expand Down
14 changes: 14 additions & 0 deletions demo/parser/bin/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-check

import json from "@rollup/plugin-json";
import typescript from "@rollup/plugin-typescript";

/** @type {import("rollup").RollupOptions} */
export default {
input: "bin/cli.ts",
plugins: [json(), typescript()],
output: {
file: "bin/cli.js",
format: "cjs",
},
};
Loading

1 comment on commit 3ba4318

@vercel
Copy link

@vercel vercel bot commented on 3ba4318 Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dvhcvn – ./

dvhcvn-daohoangson.vercel.app
dvhcvn.vercel.app
dvhcvn-git-master-daohoangson.vercel.app

Please sign in to comment.