diff --git a/buildtools/wasm/Dockerfile b/buildtools/wasm/Dockerfile index 7c7f7ce..d0e3db3 100644 --- a/buildtools/wasm/Dockerfile +++ b/buildtools/wasm/Dockerfile @@ -6,11 +6,10 @@ RUN corepack enable COPY buildtools/wasm/package.json buildtools/wasm/pnpm-lock.yaml ./ RUN pnpm install --frozen-lockfile +COPY buildtools/wasm/*.mjs ./ COPY buildtools/wasm/*.ts ./ COPY buildtools/wasm/tsconfig.json ./ RUN pnpm run build -COPY buildtools/wasm/patch.txt ./ -RUN patch -p0 < patch.txt FROM ghcr.io/webassembly/wasi-sdk:wasi-sdk-21 diff --git a/buildtools/wasm/hoist-imports.mjs b/buildtools/wasm/hoist-imports.mjs new file mode 100644 index 0000000..74a2cf1 --- /dev/null +++ b/buildtools/wasm/hoist-imports.mjs @@ -0,0 +1,31 @@ +import readline from "node:readline"; + +async function run() { + const lines = readline.createInterface({ + input: process.stdin, + terminal: false, + }); + + const imports = []; + const others = []; + + for await (const line of lines) { + if ( + line.startsWith("import ") && + (line.endsWith(' "std";') || line.endsWith(' "os";')) + ) { + imports.push(line); + } else { + others.push(line); + } + } + + for (const line of imports) { + console.log(line); + } + for (const line of others) { + console.log(line); + } +} + +await run(); diff --git a/buildtools/wasm/package.json b/buildtools/wasm/package.json index 5554f8e..49e5cc6 100644 --- a/buildtools/wasm/package.json +++ b/buildtools/wasm/package.json @@ -4,7 +4,7 @@ "description": "", "type": "module", "scripts": { - "build": "esbuild --external:std --bundle protoc-gen-connect-es.ts --format=esm --outfile=dist/protoc-gen-connect-es.js" + "build": "esbuild --external:std --bundle protoc-gen-connect-es.ts --format=esm | node hoist-imports.mjs > dist/protoc-gen-connect-es.js" }, "keywords": [], "author": "", diff --git a/buildtools/wasm/patch.txt b/buildtools/wasm/patch.txt deleted file mode 100644 index 028c88b..0000000 --- a/buildtools/wasm/patch.txt +++ /dev/null @@ -1,19 +0,0 @@ ---- dist/protoc-gen-connect-es.js 2024-01-11 15:13:36.598651612 +0900 -+++ dist/protoc-gen-connect-es-new.js 2024-01-11 15:14:08.146189312 +0900 -@@ -1,3 +1,6 @@ -+// run-quickjs.ts -+import { exit, err as stderr, in as stdin, out as stdout } from "std"; -+ - var __create = Object.create; - var __defProp = Object.defineProperty; - var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -@@ -168771,9 +168774,6 @@ - generateDts - }); - --// run-quickjs.ts --import { exit, err as stderr, in as stdin, out as stdout } from "std"; -- - // error.ts - var PluginOptionError2 = class extends Error { - constructor(option, reason) {