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

Add QuickJS support #1735

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add QuickJS support #1735

wants to merge 2 commits into from

Conversation

yne
Copy link

@yne yne commented Jun 16, 2024

This Add QuickJS support to Asciidoctor.js

You can run the only quickjs test with:

# qjs must be in your $PATH
npm run test:quickjs --prefix packages/core

QuickJS can also compile asciidoctor.js into a native binary (like a WASM+runtime) so we could release asciidoctor.js as standalone binary for windows/mac/linux.

Here is a basic CLI frontend (asciidoctor.mjs):

import * as std from 'std';
import Asciidoctor from "asciidoctor-quickjs.js";

const _ = scriptArgs.shift();
const USAGE = `USAGE: ${_} [OPTIONS] [FILE|-]
EXAMPLE: ${_} --safe=0 --doctype=\\"article\\" <<< include::partial.adoc[]`
const die = (msg) => console.log(msg) + std.exit(1);
const [file = ""] = scriptArgs.filter(arg => !arg.startsWith('-'));
const options = Object.fromEntries(scriptArgs.filter(arg => arg.startsWith('-'))
    .map(arg => arg.split('=')).map(([k, ...v]) => [k.replace(/^-+/, ''), std.parseExtJSON(v.join('=') || '1')]));
if (options.help) die(USAGE);
std.err.puts(`converting ${file ? "file:" + file : 'stdin'} options:${JSON.stringify(options)}\n`);
const body = file ? std.loadFile(file) : std.in.readAsString();
if (!body) die(USAGE);
try {
    console.log(Asciidoctor().convert(body, options));
} catch (e) {
    console.log(e)
}

which we can be compile/strip/pack with

qjsc -o asciidoctor_bin -flto asciidoctor.mjs && strip asciidoctor_bin && upx -9 asciidoctor_bin

To get a 746,5 KiB binary:

@yne
Copy link
Author

yne commented Jul 4, 2024

@ggrossetie In addition to the quickjs tests, also added a compile step for Linux and MacOS that build asciidoctor as standalone binaries.

Possible improvement:

  • compile qjs and run qjs tests on windows and build an asciidoctor.exe
  • add more quickjs tests
  • test the generated binaries via CLI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants