diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f33f40..fe2b637 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,6 +47,16 @@ jobs: shared-key: conformance cache-all-crates: true save-if: ${{ github.ref == 'refs/heads/main' }} + - name: Install the component-test tools at the pinned revision + # Owns the rev derivation, the rev-keyed tools cache, the + # install, and the pins gate; the justfile's _ct-tools + # recognizes the stamped install and does not repeat it. + uses: polymorph-components/polymorph-test/actions/setup@76c094576076284c1a7d0ea1b7bb724e9e7384a5 + with: + tools: component-test-cli + js-locks: | + conformance/driver-ct/jco/pnpm-lock.yaml + js/componentize/wpt/parity/pnpm-lock.yaml - uses: pnpm/action-setup@v4 with: version: 10.34.5 @@ -116,21 +126,11 @@ jobs: # the same aggregate; this re-runs it through component-test's # composite action for the job summary and finding annotations, # with the prebuilt CLI so aggregation semantics cannot skew from - # the pin. `uses:` cannot interpolate, so the ref is a literal - # rev; the guard keeps it on the Cargo.lock pin. - - name: Check the aggregate action ref matches the pin - if: always() - run: | - rev=$(grep -m1 -A2 '^name = "component-test-sdk"' Cargo.lock | grep -oE '[0-9a-f]{40}' | head -1) - test -n "$rev" - if grep -E 'polymorph-test/actions/aggregate@[0-9a-f]{40}' .github/workflows/ci.yml | grep -qv "@$rev"; then - echo "aggregate action ref skew: not at the Cargo.lock rev $rev" >&2 - exit 1 - fi - + # the pin. The action's cargo-lock input polices the `uses:` ref + # against the pin. - name: Publish the conformance matrix if: always() && hashFiles('conformance/driver-ct/results/*.jsonl') != '' - uses: polymorph-components/polymorph-test/actions/aggregate@824d100349dc7804c9bf1723d9b1ba0ed40fa940 + uses: polymorph-components/polymorph-test/actions/aggregate@76c094576076284c1a7d0ea1b7bb724e9e7384a5 with: lock: conformance/guest-ct/tests.lock manifest: conformance/driver-ct/targets.toml @@ -141,6 +141,7 @@ jobs: jco-browser=conformance/driver-ct/results/jco-browser.jsonl summary-title: Conformance matrix cli: target/ct-tools/bin/component-test + cargo-lock: Cargo.lock - name: Upload conformance matrix if: always() diff --git a/Cargo.lock b/Cargo.lock index 7b3d19d..3f5db0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,7 +180,7 @@ dependencies = [ [[package]] name = "component-test-core" version = "0.1.0" -source = "git+https://github.com/polymorph-components/polymorph-test?rev=824d100349dc7804c9bf1723d9b1ba0ed40fa940#824d100349dc7804c9bf1723d9b1ba0ed40fa940" +source = "git+https://github.com/polymorph-components/polymorph-test?rev=76c094576076284c1a7d0ea1b7bb724e9e7384a5#76c094576076284c1a7d0ea1b7bb724e9e7384a5" dependencies = [ "arcstr", "serde", @@ -189,7 +189,7 @@ dependencies = [ [[package]] name = "component-test-formats" version = "0.1.0" -source = "git+https://github.com/polymorph-components/polymorph-test?rev=824d100349dc7804c9bf1723d9b1ba0ed40fa940#824d100349dc7804c9bf1723d9b1ba0ed40fa940" +source = "git+https://github.com/polymorph-components/polymorph-test?rev=76c094576076284c1a7d0ea1b7bb724e9e7384a5#76c094576076284c1a7d0ea1b7bb724e9e7384a5" dependencies = [ "anyhow", "component-test-core", @@ -204,7 +204,7 @@ dependencies = [ [[package]] name = "component-test-results" version = "0.1.0" -source = "git+https://github.com/polymorph-components/polymorph-test?rev=824d100349dc7804c9bf1723d9b1ba0ed40fa940#824d100349dc7804c9bf1723d9b1ba0ed40fa940" +source = "git+https://github.com/polymorph-components/polymorph-test?rev=76c094576076284c1a7d0ea1b7bb724e9e7384a5#76c094576076284c1a7d0ea1b7bb724e9e7384a5" dependencies = [ "anyhow", "component-test-core", @@ -215,7 +215,7 @@ dependencies = [ [[package]] name = "component-test-runner" version = "0.1.0" -source = "git+https://github.com/polymorph-components/polymorph-test?rev=824d100349dc7804c9bf1723d9b1ba0ed40fa940#824d100349dc7804c9bf1723d9b1ba0ed40fa940" +source = "git+https://github.com/polymorph-components/polymorph-test?rev=76c094576076284c1a7d0ea1b7bb724e9e7384a5#76c094576076284c1a7d0ea1b7bb724e9e7384a5" dependencies = [ "anyhow", "component-test-core", @@ -231,7 +231,7 @@ dependencies = [ [[package]] name = "component-test-sdk" version = "0.1.0" -source = "git+https://github.com/polymorph-components/polymorph-test?rev=824d100349dc7804c9bf1723d9b1ba0ed40fa940#824d100349dc7804c9bf1723d9b1ba0ed40fa940" +source = "git+https://github.com/polymorph-components/polymorph-test?rev=76c094576076284c1a7d0ea1b7bb724e9e7384a5#76c094576076284c1a7d0ea1b7bb724e9e7384a5" dependencies = [ "component-test-core", "component-test-sdk-macro", @@ -243,7 +243,7 @@ dependencies = [ [[package]] name = "component-test-sdk-macro" version = "0.1.0" -source = "git+https://github.com/polymorph-components/polymorph-test?rev=824d100349dc7804c9bf1723d9b1ba0ed40fa940#824d100349dc7804c9bf1723d9b1ba0ed40fa940" +source = "git+https://github.com/polymorph-components/polymorph-test?rev=76c094576076284c1a7d0ea1b7bb724e9e7384a5#76c094576076284c1a7d0ea1b7bb724e9e7384a5" dependencies = [ "component-test-core", "proc-macro2", @@ -1814,7 +1814,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.3.4", + "getrandom 0.4.3", "once_cell", "rustix", "windows-sys 0.61.2", diff --git a/Cargo.toml b/Cargo.toml index 6073d99..276bbdb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,8 +30,8 @@ default-members = [ # `cargo update component-test-sdk component-test-runner` and # `pnpm --dir conformance/driver-ct/jco install`; the _ct-tools pins # gate and the CI ref guard fail on skew. -component-test-sdk = { git = "https://github.com/polymorph-components/polymorph-test", rev = "824d100349dc7804c9bf1723d9b1ba0ed40fa940" } -component-test-runner = { git = "https://github.com/polymorph-components/polymorph-test", rev = "824d100349dc7804c9bf1723d9b1ba0ed40fa940" } +component-test-sdk = { git = "https://github.com/polymorph-components/polymorph-test", rev = "76c094576076284c1a7d0ea1b7bb724e9e7384a5" } +component-test-runner = { git = "https://github.com/polymorph-components/polymorph-test", rev = "76c094576076284c1a7d0ea1b7bb724e9e7384a5" } anyhow = "1" bytes = "1" futures = "0.3" diff --git a/conformance/driver-ct/jco/harness.mjs b/conformance/driver-ct/jco/harness.mjs index 7412c6e..c4363e6 100644 --- a/conformance/driver-ct/jco/harness.mjs +++ b/conformance/driver-ct/jco/harness.mjs @@ -20,6 +20,10 @@ import { envelope, inventoryLookup, runCases } from "@polymorph/component-test-js/harness"; import { Context } from "@polymorph/component-test-js/context"; +import { + bindImports as bindCoreImports, + envInterface, +} from "@polymorph/component-test-js/imports"; // The single-attempt wall bound per case, matching the wasmtime leg's // --case-timeout: a wedged case is reported (limit-exceeded provenance), @@ -30,45 +34,19 @@ import { Context } from "@polymorph/component-test-js/context"; const CASE_TIMEOUT_MS = 60_000; /** - * The suite's import object, both key spellings (the generated code - * mixes versioned and unversioned): the SUT host, the test-context - * provider (upstream's), the config environment, and the wasi shims. + * The suite's import object over the upstream builder: the SUT host, + * the test-context provider, the config environment, and the wasi + * shims. */ export function bindImports({ connections, env, cli, clocks, io }) { - const imports = {}; - const bind = (name, impl) => { - imports[name] = impl; - const versioned = name.startsWith("wasi:") ? `${name}@0.2.0` : `${name}@0.1.0`; - imports[versioned] = impl; - }; - bind("polymorph:websocket/connections", connections); - bind("polymorph:test/test-context", { Context }); - bind("wasi:cli/environment", envInterface(env)); - bind("wasi:cli/exit", cli.exit); - bind("wasi:cli/stdin", cli.stdin); - bind("wasi:cli/stdout", cli.stdout); - bind("wasi:cli/stderr", cli.stderr); - bind("wasi:cli/terminal-input", cli.terminalInput); - bind("wasi:cli/terminal-output", cli.terminalOutput); - bind("wasi:cli/terminal-stdin", cli.terminalStdin); - bind("wasi:cli/terminal-stdout", cli.terminalStdout); - bind("wasi:cli/terminal-stderr", cli.terminalStderr); - bind("wasi:clocks/monotonic-clock", clocks.monotonicClock); - bind("wasi:clocks/wall-clock", clocks.wallClock); - bind("wasi:io/error", io.error); - bind("wasi:io/poll", io.poll); - bind("wasi:io/streams", io.streams); - return imports; + return bindCoreImports({ + wasi: { cli, clocks, io }, + env, + sut: { "polymorph:websocket/connections": connections }, + }); } -/** One environment interface for both legs (explicit > shim-internal). */ -export function envInterface(vars) { - return { - getEnvironment: () => vars, - getArguments: () => [], - initialCwd: () => undefined, - }; -} +export { envInterface }; /** * Run the whole suite through the upstream case loop. `newInstance()` diff --git a/conformance/driver-ct/jco/package.json b/conformance/driver-ct/jco/package.json index dc35718..9c19e05 100644 --- a/conformance/driver-ct/jco/package.json +++ b/conformance/driver-ct/jco/package.json @@ -6,14 +6,14 @@ "description": "jco legs (Node + headless browser) for the component-test conformance suite: transpile the suite, bind the browser-first host and the test-context shim, emit component-test results JSONL.", "packageManager": "pnpm@10.34.5", "scripts": { - "transpile": "node ../../../scripts/jco-transpile.mjs transpile ../../../target/wasm32-wasip2/release/conformance_guest_ct.wasm --name conformance-guest-ct -I async -o generated", + "transpile": "component-test-jco-transpile transpile ../../../target/wasm32-wasip2/release/conformance_guest_ct.wasm --name conformance-guest-ct -I async -o generated", "run:node": "node --experimental-wasm-jspi run-node.mjs", "run:browser": "node run-browser.mjs" }, "devDependencies": { "@bytecodealliance/jco-transpile": "https://github.com/lann/jco/releases/download/jco-transpile-0.6.2-fa6990d/bytecodealliance-jco-transpile-0.6.2.tgz", "@bytecodealliance/preview2-shim": "^0.17.2", - "@polymorph/component-test-js": "github:polymorph-components/polymorph-test#824d100349dc7804c9bf1723d9b1ba0ed40fa940", + "@polymorph/component-test-js": "github:polymorph-components/polymorph-test#76c094576076284c1a7d0ea1b7bb724e9e7384a5", "playwright-core": "^1.61.1" }, "engines": { diff --git a/conformance/driver-ct/jco/pnpm-lock.yaml b/conformance/driver-ct/jco/pnpm-lock.yaml index e1d5ea1..f748f28 100644 --- a/conformance/driver-ct/jco/pnpm-lock.yaml +++ b/conformance/driver-ct/jco/pnpm-lock.yaml @@ -15,8 +15,8 @@ importers: specifier: ^0.17.2 version: 0.17.9 '@polymorph/component-test-js': - specifier: github:polymorph-components/polymorph-test#824d100349dc7804c9bf1723d9b1ba0ed40fa940 - version: https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/824d100349dc7804c9bf1723d9b1ba0ed40fa940 + specifier: github:polymorph-components/polymorph-test#76c094576076284c1a7d0ea1b7bb724e9e7384a5 + version: https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5 playwright-core: specifier: ^1.61.1 version: 1.62.1 @@ -182,9 +182,10 @@ packages: cpu: [x64] os: [win32] - '@polymorph/component-test-js@https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/824d100349dc7804c9bf1723d9b1ba0ed40fa940': - resolution: {gitHosted: true, integrity: sha512-KD9z6BjwVHAt5uxWfLeBqMNWALREu1NluYXJz1ucRhkab+OplvHvg1Flh+5Afo8U4EWUtqXE5JzKm2wWPL06tA==, tarball: https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/824d100349dc7804c9bf1723d9b1ba0ed40fa940} + '@polymorph/component-test-js@https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5': + resolution: {gitHosted: true, integrity: sha512-e1ojI6hXZB3RQBrQdxob0BNg0+S3sVAKAOykKs9iqfy3qXVWFsQa+nXJ+px1bXXGB7TBSauJygWin9ANtNZAHw==, tarball: https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5} version: 0.2.0 + hasBin: true '@tybys/wasm-util@0.10.3': resolution: {integrity: sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==} @@ -311,7 +312,7 @@ snapshots: '@oxc-minify/binding-win32-x64-msvc@0.136.0': optional: true - '@polymorph/component-test-js@https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/824d100349dc7804c9bf1723d9b1ba0ed40fa940': {} + '@polymorph/component-test-js@https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5': {} '@tybys/wasm-util@0.10.3': dependencies: diff --git a/conformance/driver-ct/jco/run-browser.mjs b/conformance/driver-ct/jco/run-browser.mjs index 4f82638..2b549c3 100644 --- a/conformance/driver-ct/jco/run-browser.mjs +++ b/conformance/driver-ct/jco/run-browser.mjs @@ -40,6 +40,7 @@ const IMPORT_MAP = JSON.stringify({ imports: { "@polymorph/component-test-js/harness": "/ct/harness.mjs", "@polymorph/component-test-js/context": "/ct/context.js", + "@polymorph/component-test-js/imports": "/ct/imports.mjs", }, }); diff --git a/conformance/driver-ct/justfile b/conformance/driver-ct/justfile index e1492e5..f9b13d3 100644 --- a/conformance/driver-ct/justfile +++ b/conformance/driver-ct/justfile @@ -39,14 +39,18 @@ build-driver: _ct-tools: #!/usr/bin/env bash set -euo pipefail - block="$(grep -m1 -A2 '^name = "component-test-sdk"' '{{root}}/Cargo.lock')" - rev="$(grep -oE '[0-9a-f]{40}' <<< "$block" | head -1)" - url="$(grep -oE 'git\+[^?"]+' <<< "$block" | head -1 | cut -c5-)" - { [ -n "$rev" ] && [ -n "$url" ]; } || { echo "no component-test git source in Cargo.lock" >&2; exit 1; } - cargo install --locked --git "$url" --rev "$rev" \ - component-test-cli --root '{{root}}/target/ct-tools' - '{{ct_cli}}' pins --cargo-lock '{{root}}/Cargo.lock' \ - --js-lock jco/pnpm-lock.yaml --expect "$rev" > /dev/null + cd '{{root}}' + src=$(grep -m1 -A2 '^name = "component-test-sdk"' Cargo.lock | grep '^source = "git+') + url=$(printf '%s' "$src" | sed -E 's/^source = "git\+([^?]+)\?.*/\1/') + rev=$(printf '%s' "$src" | grep -oE '[0-9a-f]{40}' | head -n1) + if [ ! -x target/ct-tools/bin/component-test ] || [ "$(cat target/ct-tools/.rev 2>/dev/null)" != "$rev" ]; then + cargo install --locked --root target/ct-tools --git "$url" --rev "$rev" component-test-cli + printf '%s' "$rev" > target/ct-tools/.rev + fi + target/ct-tools/bin/component-test pins --cargo-lock Cargo.lock \ + --js-lock conformance/driver-ct/jco/pnpm-lock.yaml \ + --js-lock js/componentize/wpt/parity/pnpm-lock.yaml \ + --expect "$rev" > /dev/null build-echod: cargo build --manifest-path {{root}}/Cargo.toml -p conformance-echod diff --git a/js/componentize/wpt/parity/package.json b/js/componentize/wpt/parity/package.json index bb3398a..e86cb79 100644 --- a/js/componentize/wpt/parity/package.json +++ b/js/componentize/wpt/parity/package.json @@ -6,9 +6,9 @@ "description": "WPT parity gate: the vendored WebSocket suites run directly against the platform's WebSocket (baseline) and through the componentized shim transpiled by jco against websocket-jco (round trip); compare.mjs holds the round trip to the baseline's pass set.", "packageManager": "pnpm@10.34.5", "scripts": { - "transpile": "node ../../../../scripts/jco-transpile.mjs transpile ../build/parity-runner.component.wasm --name parity-runner --async-mode jspi --map 'polymorph:websocket/*@0.1.0=../../../../jco/websocket.js#*' --map 'wpt:parity/reporter@0.1.0=../../reporter.js#reporter' -o generated", - "transpile:web": "node ../../../../scripts/jco-transpile.mjs transpile ../build/parity-runner.component.wasm --name parity-runner --async-mode jspi --map 'polymorph:websocket/*@0.1.0=../../../../jco/websocket.js#*' --map 'wpt:parity/reporter@0.1.0=../../reporter.js#reporter' --map 'wasi:cli/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/cli.js#*' --map 'wasi:clocks/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/clocks.js#*' --map 'wasi:filesystem/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/filesystem.js#*' --map 'wasi:io/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/io.js#*' --map 'wasi:random/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/random.js#*' --map 'wasi:sockets/*=../sockets-stub.mjs#*' -o generated-web", - "transpile:smoke": "node ../../../../scripts/jco-transpile.mjs transpile ../build/smoke.component.wasm --name smoke --async-mode jspi --map 'polymorph:websocket/*@0.1.0=../../../../jco/websocket.js#*' --map 'wpt:parity/reporter@0.1.0=../../reporter.js#reporter' -o generated-smoke", + "transpile": "component-test-jco-transpile transpile ../build/parity-runner.component.wasm --name parity-runner --async-mode jspi --map 'polymorph:websocket/*@0.1.0=../../../../jco/websocket.js#*' --map 'wpt:parity/reporter@0.1.0=../../reporter.js#reporter' -o generated", + "transpile:web": "component-test-jco-transpile transpile ../build/parity-runner.component.wasm --name parity-runner --async-mode jspi --map 'polymorph:websocket/*@0.1.0=../../../../jco/websocket.js#*' --map 'wpt:parity/reporter@0.1.0=../../reporter.js#reporter' --map 'wasi:cli/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/cli.js#*' --map 'wasi:clocks/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/clocks.js#*' --map 'wasi:filesystem/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/filesystem.js#*' --map 'wasi:io/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/io.js#*' --map 'wasi:random/*=../node_modules/@bytecodealliance/preview2-shim/dist/browser/random.js#*' --map 'wasi:sockets/*=../sockets-stub.mjs#*' -o generated-web", + "transpile:smoke": "component-test-jco-transpile transpile ../build/smoke.component.wasm --name smoke --async-mode jspi --map 'polymorph:websocket/*@0.1.0=../../../../jco/websocket.js#*' --map 'wpt:parity/reporter@0.1.0=../../reporter.js#reporter' -o generated-smoke", "baseline": "node baseline.mjs", "roundtrip": "node --experimental-wasm-jspi roundtrip.mjs", "compare": "node compare.mjs" @@ -19,6 +19,7 @@ "devDependencies": { "@bytecodealliance/jco-transpile": "https://github.com/lann/jco/releases/download/jco-transpile-0.6.2-fa6990d/bytecodealliance-jco-transpile-0.6.2.tgz", "@bytecodealliance/preview2-shim": "^0.19.0", + "@polymorph/component-test-js": "github:polymorph-components/polymorph-test#76c094576076284c1a7d0ea1b7bb724e9e7384a5", "playwright-core": "^1.61.1" } } diff --git a/js/componentize/wpt/parity/pnpm-lock.yaml b/js/componentize/wpt/parity/pnpm-lock.yaml index 28cfb4a..aab3f37 100644 --- a/js/componentize/wpt/parity/pnpm-lock.yaml +++ b/js/componentize/wpt/parity/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@bytecodealliance/preview2-shim': specifier: ^0.19.0 version: 0.19.0 + '@polymorph/component-test-js': + specifier: github:polymorph-components/polymorph-test#76c094576076284c1a7d0ea1b7bb724e9e7384a5 + version: https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5 playwright-core: specifier: ^1.61.1 version: 1.62.1 @@ -176,6 +179,11 @@ packages: cpu: [x64] os: [win32] + '@polymorph/component-test-js@https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5': + resolution: {gitHosted: true, integrity: sha512-e1ojI6hXZB3RQBrQdxob0BNg0+S3sVAKAOykKs9iqfy3qXVWFsQa+nXJ+px1bXXGB7TBSauJygWin9ANtNZAHw==, tarball: https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5} + version: 0.2.0 + hasBin: true + '@tybys/wasm-util@0.10.3': resolution: {integrity: sha512-F3fo1MYrRJYL3zER0OUOmkutjr1Vp23m7OsSgp7nq4SP6OqX6C/56XFIPAl5bt3zaBRjmW7SGz3u/6LwFpYcOg==} @@ -299,6 +307,8 @@ snapshots: '@oxc-minify/binding-win32-x64-msvc@0.136.0': optional: true + '@polymorph/component-test-js@https://codeload.github.com/polymorph-components/polymorph-test/tar.gz/76c094576076284c1a7d0ea1b7bb724e9e7384a5': {} + '@tybys/wasm-util@0.10.3': dependencies: tslib: 2.8.1 diff --git a/justfile b/justfile index 50fc0bf..bfb0e88 100644 --- a/justfile +++ b/justfile @@ -60,7 +60,6 @@ check-js: node --check conformance/driver-ct/jco/run-browser.mjs node --check conformance/server/echod.mjs node --check scripts/chrome.mjs - node --check scripts/jco-transpile.mjs node --check examples/jco-demo/run.mjs @echo "js: ok" diff --git a/scripts/jco-transpile.mjs b/scripts/jco-transpile.mjs deleted file mode 100644 index 5253417..0000000 --- a/scripts/jco-transpile.mjs +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env node -// Thin CLI over @bytecodealliance/jco-transpile, covering the two jco -// commands this repository uses: `transpile` (component to ES module) and -// `types` (host-side type definitions for a WIT world). jco-transpile is -// the transpilation half of jco, published without the componentization -// toolchain (componentize-js, weval) that the full jco CLI drags in and -// nothing here runs. -// -// The library is resolved from the invoking package's node_modules — each -// package tree pins its own toolchain version — so this script must be run -// with the package directory as the working directory, which is how every -// package.json script invokes it. -// -// The option spellings match the jco CLI's, and the library applies the -// same defaults the CLI did (name derivation, the wasi-shim map entries, -// output-path prefixing), so the generated trees are bit-identical to -// `jco transpile` / `jco types` output for these invocations. - -import { createRequire } from "node:module"; -import { join } from "node:path"; -import { pathToFileURL } from "node:url"; -import { parseArgs } from "node:util"; - -const require = createRequire(join(process.cwd(), "package.json")); -const { transpile, generateHostTypes, writeFiles } = await import( - pathToFileURL(require.resolve("@bytecodealliance/jco-transpile")).href -); - -const [command, path, ...rest] = process.argv.slice(2); -const { values } = parseArgs({ - args: rest, - options: { - name: { type: "string" }, - "async-mode": { type: "string" }, - instantiation: { type: "string", short: "I" }, - map: { type: "string", multiple: true }, - "world-name": { type: "string" }, - "out-dir": { type: "string", short: "o" }, - // `types` only: WIT `@unstable` gates to enable, like `jco types - // --feature` (repeatable). - feature: { type: "string", multiple: true }, - }, -}); - -switch (command) { - case "transpile": { - const map = Object.fromEntries( - (values.map ?? []).map((entry) => { - const eq = entry.indexOf("="); - if (eq === -1) { - throw new Error(`--map entry has no '=': ${entry}`); - } - return [entry.slice(0, eq), entry.slice(eq + 1)]; - }), - ); - const { files } = await transpile(path, { - name: values.name, - asyncMode: values["async-mode"], - instantiation: values.instantiation, - map, - outDir: values["out-dir"], - }); - await writeFiles(files); - break; - } - case "types": { - const files = await generateHostTypes(path, { - worldName: values["world-name"], - asyncMode: values["async-mode"], - outDir: values["out-dir"], - features: values.feature, - }); - await writeFiles(files); - break; - } - default: - throw new Error(`unknown command: ${command} (expected transpile or types)`); -}