Skip to content
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
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

24 changes: 14 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v7

- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version: 18.x

- name: Prepare
id: preparation
run: |
export PWD=$(pwd);
echo "::set-output name=PROJ_ROOT::$PWD";
echo "PROJ_ROOT=$GITHUB_WORKSPACE" >> "$GITHUB_OUTPUT"

- name: Set up Docker
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1

- name: Install
run: npm install
run: npm ci

- name: Install wabt
env:
PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }}
run: |
cd $PROJ_ROOT;
cd "$PROJ_ROOT";
cd ../;
if [[ "$RUNNER_OS" == "Linux" ]]; then
export WABT_OS="ubuntu";
Expand All @@ -44,17 +48,17 @@ jobs:
if [[ "$RUNNER_OS" == "Windows" ]]; then
export WABT_OS="windows";
fi
curl -sL https://github.com/WebAssembly/wabt/releases/download/${WABT_VERSION}/wabt-${WABT_VERSION}-${WABT_OS}.tar.gz -O
curl -fsSL "https://github.com/WebAssembly/wabt/releases/download/${WABT_VERSION}/wabt-${WABT_VERSION}-${WABT_OS}.tar.gz" -O
# check if package downloaded
ls -la
tar xvf wabt-${WABT_VERSION}-${WABT_OS}.tar.gz
tar xvf "wabt-${WABT_VERSION}-${WABT_OS}.tar.gz"
# check if wabt binaries installed
ls -la ./wabt-${WABT_VERSION}/bin/
ls -la "./wabt-${WABT_VERSION}/bin/"
- name: Compile to Wasm & Test Wasm
env:
PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }}
run: |
cd $PROJ_ROOT;
cd "$PROJ_ROOT";
rm lib/lexer.wasm;
npm run build-wasm;
npm run build;
Expand All @@ -64,5 +68,5 @@ jobs:
env:
PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }}
run: |
cd $PROJ_ROOT;
cd "$PROJ_ROOT";
npm run bench;
14 changes: 5 additions & 9 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand All @@ -16,13 +13,12 @@ jobs:

strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [18.x, 20.x, 22.x, 24.x, 26.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v7
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Where the `__export(require("external"))` statement is explicitly detected as a

### Environment Support

Node.js 10+, and [all browsers with Web Assembly support](https://caniuse.com/#feat=wasm).
Node.js 18+, and [all browsers with Web Assembly support](https://caniuse.com/#feat=wasm).

### JS Grammar Support

Expand Down
21 changes: 11 additions & 10 deletions bench/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const files = fs.readdirSync('test/samples')
};
});

Promise.resolve().then(async () => {
{
/** @param {string} code */
function timeRun (code) {
const start = process.hrtime.bigint();
const parsed = parse(code);
Expand All @@ -32,7 +33,7 @@ Promise.resolve().then(async () => {
{
const start = process.hrtime.bigint();
var { parse } = await import('../lexer.js');
console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
console.log(`> ${c.bold().green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
}

doRun();
Expand All @@ -43,7 +44,7 @@ Promise.resolve().then(async () => {
const start = process.hrtime.bigint();
var { parse, init } = await import('../dist/lexer.mjs');
await init();
console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
console.log(`> ${c.bold().green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`);
}

doRun();
Expand All @@ -57,22 +58,22 @@ Promise.resolve().then(async () => {
totalSize += size;
total += timeRun(code);
});
console.log(c.bold.cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold.green(total + 'ms')}`);
console.log(c.bold().cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold().green(total + 'ms')}`);
gc();
}

console.log(`\nWarm Runs (average of ${n} runs)`);
files.forEach(({ file, code, size }) => {
console.log(c.bold.cyan(`${file} (${Math.round(size / 1e3)} KiB)`));
console.log(c.bold().cyan(`${file} (${Math.round(size / 1e3)} KiB)`));

let total = 0;
for (let i = 0; i < n; i++) {
total += timeRun(code);
gc();
}

console.log(`> ${c.bold.green((total / n) + 'ms')}`);
console.log(`> ${c.bold().green((total / n) + 'ms')}`);
});

console.log(`\nWarm Runs, All Samples (average of ${n} runs)`);
Expand All @@ -83,8 +84,8 @@ Promise.resolve().then(async () => {
total += timeRun(code);
});
}
console.log(c.bold.cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold.green((total / n) + 'ms')}`);
console.log(c.bold().cyan(`test/samples/*.js (${Math.round(totalSize / 1e3)} KiB)`));
console.log(`> ${c.bold().green((total / n) + 'ms')}`);
}
}
});
}
20 changes: 13 additions & 7 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const terser = require('terser');
const fs = require('node:fs');

const MINIFY = true;
const babel = require('@babel/core');
const terser = require('terser');

try { fs.mkdirSync('./dist'); }
catch (e) {}
Expand All @@ -12,14 +12,20 @@ const pjson = JSON.parse(fs.readFileSync('./package.json').toString());

const jsSourceProcessed = jsSource.replace('WASM_BINARY', wasmBuffer.toString('base64'));

const minified = MINIFY && terser.minify(jsSourceProcessed, {
const minified = terser.minify_sync(jsSourceProcessed, {
module: true,
output: {
preamble: `/* cjs-module-lexer ${pjson.version} */`
}
});

if (minified.error)
throw minified.error;
fs.writeFileSync('./dist/lexer.mjs', minified.code);

const cjsSource = babel.transformSync(minified.code, {
babelrc: false,
configFile: false,
plugins: [['@babel/plugin-transform-modules-commonjs', { strict: true }]]
}).code;
const cjsMinified = terser.minify_sync(cjsSource);

fs.writeFileSync('./dist/lexer.mjs', minified ? minified.code : jsSourceProcessed);
fs.writeFileSync('./dist/lexer.js', cjsMinified.code);
Loading
Loading