From d76d322154b32d3834cea9ab23679648051af099 Mon Sep 17 00:00:00 2001 From: Eric Rodrigues Pires Date: Sun, 30 Nov 2025 22:15:46 -0300 Subject: [PATCH] Add release workflows for @duper-js/node and @duper-js/wasm --- ...elease-uniffi.yaml => release-dotnet.yaml} | 19 ++- .github/workflows/release-lsp.yaml | 6 +- .github/workflows/release-node.yaml | 159 ++++++++++++++++++ .github/workflows/release-wasm.yaml | 83 +++++++++ .github/workflows/website.yaml | 4 +- duper-js-node/README.md | 54 ++++++ duper-js-node/lib/index.ts | 4 +- duper-js-node/package.json | 6 +- duper-js-node/tsconfig.json | 1 - duper-js-node/wasi-worker-browser.mjs | 32 ---- duper-js-wasm/package.json | 2 + duper-js-wasm/src/index.ts | 2 +- 12 files changed, 324 insertions(+), 48 deletions(-) rename .github/workflows/{release-uniffi.yaml => release-dotnet.yaml} (91%) create mode 100644 .github/workflows/release-node.yaml create mode 100644 .github/workflows/release-wasm.yaml create mode 100644 duper-js-node/README.md delete mode 100644 duper-js-node/wasi-worker-browser.mjs diff --git a/.github/workflows/release-uniffi.yaml b/.github/workflows/release-dotnet.yaml similarity index 91% rename from .github/workflows/release-uniffi.yaml rename to .github/workflows/release-dotnet.yaml index 6698262..307b61c 100644 --- a/.github/workflows/release-uniffi.yaml +++ b/.github/workflows/release-dotnet.yaml @@ -1,4 +1,4 @@ -name: "[Release] Build UniFFI packages" +name: "[Release] Build .NET package" on: workflow_dispatch: @@ -36,7 +36,7 @@ jobs: # - runner: ubuntu-24.04 # target: aarch64-pc-windows-msvc # os: windows - - runner: macos-15-intel + - runner: macos-15-intel # TO-DO: Change to macos-15 target: x86_64-apple-darwin os: macos - runner: macos-15 @@ -49,7 +49,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: true - - name: Fetch MSRV and target + - name: Fetch MSRV and add target run: | rustup toolchain install ${RUST_VERSION} rustup override set ${RUST_VERSION} @@ -112,10 +112,12 @@ jobs: name: dist-${{ matrix.target }} path: dist - dotnet: + release: name: Release .NET package runs-on: ubuntu-24.04 environment: nuget + permissions: + id-token: write needs: build steps: - name: Checkout repository @@ -166,7 +168,14 @@ jobs: run: | dotnet build dotnet pack + - name: Login to NuGet + uses: NuGet/login@d22cc5f58ff5b88bf9bd452535b4335137e24544 # v1 + id: login + with: + user: ${{ vars.NUGET_USER }} - name: Publish to NuGet working-directory: duper_uniffi/dotnet run: | - dotnet nuget push bin/Release/*.nupkg --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json + dotnet nuget push bin/Release/*.nupkg --api-key ${NUGET_API_KEY} --source https://api.nuget.org/v3/index.json + env: + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} \ No newline at end of file diff --git a/.github/workflows/release-lsp.yaml b/.github/workflows/release-lsp.yaml index 22c74ab..4178635 100644 --- a/.github/workflows/release-lsp.yaml +++ b/.github/workflows/release-lsp.yaml @@ -38,11 +38,11 @@ jobs: target: x86_64-pc-windows-msvc vscode-target: win32-x64 os: windows - - runner: windows-11-arm + - runner: windows-11-arm # TO-DO: Change to windows-latest target: aarch64-pc-windows-msvc vscode-target: win32-arm64 os: windows - - runner: macos-15-intel + - runner: macos-15-intel # TO-DO: Change to macos-15 target: x86_64-apple-darwin vscode-target: darwin-x64 os: macos @@ -57,7 +57,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: persist-credentials: true - - name: Fetch MSRV and target + - name: Fetch MSRV and add target run: | rustup toolchain install ${RUST_VERSION} rustup override set ${RUST_VERSION} diff --git a/.github/workflows/release-node.yaml b/.github/workflows/release-node.yaml new file mode 100644 index 0000000..5492cbc --- /dev/null +++ b/.github/workflows/release-node.yaml @@ -0,0 +1,159 @@ +name: "[Release] Build @duper-js/node package" + +on: + workflow_dispatch: + +permissions: + contents: read + +env: + RUST_VERSION: "1.91.1" + CARGO_INCREMENTAL: "0" + CARGO_PROFILE_TEST_DEBUG: "0" + NODE_VERSION: "20" + +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-24.04 + target: x86_64-unknown-linux-gnu + os: linux + - runner: ubuntu-24.04 + target: aarch64-unknown-linux-gnu + os: linux + - runner: ubuntu-24.04 + target: x86_64-unknown-linux-musl + os: linux + - runner: ubuntu-24.04 + target: aarch64-unknown-linux-musl + os: linux + - runner: windows-latest + target: x86_64-pc-windows-msvc + os: windows + - runner: windows-latest + target: aarch64-pc-windows-msvc + os: windows + - runner: macos-15 + target: x86_64-apple-darwin + os: macos + - runner: macos-15 + target: aarch64-apple-darwin + os: macos + name: Build and package (${{ matrix.target }}) + runs-on: ${{ matrix.runner }} + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: true + - name: Fetch MSRV and add target + run: | + rustup toolchain install ${RUST_VERSION} + rustup override set ${RUST_VERSION} + rustup target add ${{ matrix.target }} + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1 + - name: Install Zig + if: matrix.runner == 'ubuntu-24.04' + uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # v2.0.5 + with: + version: latest + - name: Install cargo-zigbuild (Linux) + if: matrix.runner == 'ubuntu-24.04' + uses: taiki-e/install-action@a24ba45235ed716ff76646268742990dc9458860 # v2.62.42 + with: + tool: cargo-zigbuild + - name: Install lld (macOS) + if: matrix.os == 'macos' + run: | + brew install lld + - name: Install lld (Windows) + if: matrix.os == 'windows' + run: | + choco install llvm + - name: Setup Node + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: ${{ env.NODE_VERSION }} + - name: Install dependencies + working-directory: duper-js-node + run: | + npm install + - name: Build with cargo-zigbuild (Linux) + if: matrix.runner == 'ubuntu-24.04' + working-directory: duper-js-node + run: | + npm run build:release -- --cross-compile --target ${{ matrix.target }} + - name: Build with cargo (macOS / Windows) + if: matrix.runner != 'ubuntu-24.04' + working-directory: duper-js-node + run: | + npm run build:release -- --target ${{ matrix.target }} + - name: Bundle + working-directory: duper-js-node + run: | + npm run bundle + - name: Upload artifacts + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: dist-${{ matrix.target }} + path: duper-js-node/dist + + release: + name: Release @duper-js/node + runs-on: ubuntu-24.04 + needs: build + permissions: + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: true + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-x86_64-unknown-linux-gnu + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-aarch64-unknown-linux-gnu + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-x86_64-unknown-linux-musl + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-aarch64-unknown-linux-musl + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-x86_64-pc-windows-msvc + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-aarch64-pc-windows-msvc + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-x86_64-apple-darwin + path: duper-js-node/dist + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-aarch64-apple-darwin + path: duper-js-node/dist + - run: | + ls -al ./duper-js-node/dist + + - name: Setup Node + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: ${{ env.NODE_VERSION }} + registry-url: 'https://registry.npmjs.org' + - name: Publish to NPM + working-directory: duper-js-node + run: | + npm publish --access public diff --git a/.github/workflows/release-wasm.yaml b/.github/workflows/release-wasm.yaml new file mode 100644 index 0000000..720af08 --- /dev/null +++ b/.github/workflows/release-wasm.yaml @@ -0,0 +1,83 @@ +name: "[Release] Build @duper-js/wasm package" + +on: + workflow_dispatch: + +permissions: + contents: read + +env: + RUST_VERSION: "1.91.1" + CARGO_INCREMENTAL: "0" + CARGO_PROFILE_TEST_DEBUG: "0" + NODE_VERSION: "20" + BINARYEN_VERSION: "124" + WASM_BINDGEN_VERSION: "0.2.100" + +jobs: + build: + name: Build and package + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: true + - name: Fetch MSRV and add target + run: | + rustup toolchain install ${RUST_VERSION} + rustup override set ${RUST_VERSION} + rustup target add wasm32-unknown-unknown + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1 + - name: Install wasm-bindgen + uses: taiki-e/install-action@a24ba45235ed716ff76646268742990dc9458860 # v2.62.42 + with: + tool: wasm-bindgen@${{ env.WASM_BINDGEN_VERSION }} + - name: Install wasm-opt + run: | + curl -L https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz -o binaryen.tar.gz + tar -xzf binaryen.tar.gz + mv binaryen-version_${BINARYEN_VERSION} binaryen + - name: Setup Node + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: ${{ env.NODE_VERSION }} + - name: Install dependencies and build + working-directory: duper-js-wasm + run: | + npm install + npm run build:release + - name: Upload artifacts + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: dist-duper-js-wasm + path: duper-js-wasm/dist + + release: + name: Release @duper-js/wasm + runs-on: ubuntu-24.04 + needs: build + permissions: + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: true + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: dist-x86_64-unknown-linux-gnu + path: duper-js-wasm/dist + - run: | + ls -al ./duper-js-wasm/dist + + - name: Setup Node + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 + with: + node-version: ${{ env.NODE_VERSION }} + registry-url: 'https://registry.npmjs.org' + - name: Publish to NPM + working-directory: duper-js-wasm + run: | + npm publish --access public diff --git a/.github/workflows/website.yaml b/.github/workflows/website.yaml index 2ddcb82..b8cffd6 100644 --- a/.github/workflows/website.yaml +++ b/.github/workflows/website.yaml @@ -15,6 +15,8 @@ concurrency: env: RUST_VERSION: "1.91.1" + CARGO_INCREMENTAL: "0" + CARGO_PROFILE_TEST_DEBUG: "0" NODE_VERSION: "24" BINARYEN_VERSION: "124" WASM_BINDGEN_VERSION: "0.2.100" @@ -32,7 +34,7 @@ jobs: uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 with: node-version: ${{ env.NODE_VERSION }} - - name: Fetch Rust and install target + - name: Fetch Rust and add target run: | rustup toolchain install ${RUST_VERSION}-x86_64-unknown-linux-gnu rustup override set ${RUST_VERSION}-x86_64-unknown-linux-gnu diff --git a/duper-js-node/README.md b/duper-js-node/README.md new file mode 100644 index 0000000..0d7b06f --- /dev/null +++ b/duper-js-node/README.md @@ -0,0 +1,54 @@ +

+ The Duper logo, with a confident spectacled mole wearing a flailing blue cape.
+

+

@duper-js/wasm

+ +

+ PyPI version + GitHub license +

+ +Duper support for Node.JS. + +[Check out the official website for Duper.](https://duper.dev.br) + +## Installation + +```bash +npm install --save @duper-js/node +``` + +## Examples + +```typescript +import { parse, stringify } from "@duper-js/node"; + +const duper_data = ` +APIResponse({ + status: 200, + headers: { + content_type: "application/duper", + cache_control: "max-age=3600", + }, + body: { + users: [ + User({ + id: Uuid("7039311b-02d2-4849-a6de-900d4dbe9acb"), + name: "Alice", + email: Email("alice@example.com"), + roles: ["admin", "user"], + metadata: { + last_login: Instant('2024-01-15T10:30:00Z'), + ip: IPV4("173.255.230.79"), + }, + }), + ], + }, +}) +`; + +const obj = parse(duper_data); + +console.log(stringify, { stripIdentifiers: false }); +console.log(JSON.stringify(obj)); +``` diff --git a/duper-js-node/lib/index.ts b/duper-js-node/lib/index.ts index 8d0bf0d..edb6788 100644 --- a/duper-js-node/lib/index.ts +++ b/duper-js-node/lib/index.ts @@ -1,10 +1,8 @@ +/** biome-ignore-all lint/suspicious/noExplicitAny: Serialization/Deserialization involves a lot of `any` */ import duperNapi from "./napi"; const duperSymbol: unique symbol = Symbol(); -const SERDE_JSON_ARBITRARY_PRECISION_NUMBER = - "$serde_json::private::Number" as const; - /** * A valid Duper value. */ diff --git a/duper-js-node/package.json b/duper-js-node/package.json index 6aa1758..59900b9 100644 --- a/duper-js-node/package.json +++ b/duper-js-node/package.json @@ -1,6 +1,6 @@ { "name": "@duper-js/node", - "version": "0.1.0", + "version": "0.0.1", "description": "Node.JS bindings for Duper, the format that's super!", "keywords": [ "Duper", @@ -32,9 +32,11 @@ "aarch64-apple-darwin", "aarch64-pc-windows-msvc", "aarch64-unknown-linux-gnu", + "aarch64-unknown-linux-musl", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", - "x86_64-unknown-linux-gnu" + "x86_64-unknown-linux-gnu", + "x86_64-unknown-linux-musl" ] }, "engines": { diff --git a/duper-js-node/tsconfig.json b/duper-js-node/tsconfig.json index cc00d15..746e890 100644 --- a/duper-js-node/tsconfig.json +++ b/duper-js-node/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "types": ["node", "@types/jest"], "target": "ESNext", "module": "CommonJS", "moduleResolution": "node", diff --git a/duper-js-node/wasi-worker-browser.mjs b/duper-js-node/wasi-worker-browser.mjs deleted file mode 100644 index 8b1b172..0000000 --- a/duper-js-node/wasi-worker-browser.mjs +++ /dev/null @@ -1,32 +0,0 @@ -import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime' - -const handler = new MessageHandler({ - onLoad({ wasmModule, wasmMemory }) { - const wasi = new WASI({ - print: function () { - // eslint-disable-next-line no-console - console.log.apply(console, arguments) - }, - printErr: function() { - // eslint-disable-next-line no-console - console.error.apply(console, arguments) - }, - }) - return instantiateNapiModuleSync(wasmModule, { - childThread: true, - wasi, - overwriteImports(importObject) { - importObject.env = { - ...importObject.env, - ...importObject.napi, - ...importObject.emnapi, - memory: wasmMemory, - } - }, - }) - }, -}) - -globalThis.onmessage = function (e) { - handler.handle(e) -} diff --git a/duper-js-wasm/package.json b/duper-js-wasm/package.json index bd07a41..b8f988e 100644 --- a/duper-js-wasm/package.json +++ b/duper-js-wasm/package.json @@ -32,11 +32,13 @@ }, "scripts": { "bindgen": "uniffi-bindgen-react-native build web", + "bindgen:release": "uniffi-bindgen-react-native build web --release", "optimize": "wasm-opt -Os ./src/generated/wasm-bindgen/index_bg.wasm -o ./src/generated/wasm-bindgen/index_bg.wasm", "clean": "rm -rf dist", "bundle": "node esbuild.mjs && tsc && cp -r ./src/generated/wasm-bindgen ./dist/wasm-bindgen", "build": "npm run clean && npm run bindgen && npm run optimize && npm run bundle", "build:ci": "npm run clean && npm run bindgen && npm run bundle", + "build:release": "npm run clean && npm run bindgen:release && npm run optimize && npm run bundle", "test": "vitest run" }, "devDependencies": { diff --git a/duper-js-wasm/src/index.ts b/duper-js-wasm/src/index.ts index f1b57df..44d5b8c 100644 --- a/duper-js-wasm/src/index.ts +++ b/duper-js-wasm/src/index.ts @@ -637,7 +637,7 @@ function toFfi( return toFfi(value.toJSON(), true); } else if (typeof value !== "function" && typeof value !== "symbol") { const array = Object.entries(value).map(([key, val]) => - duperFfi.DuperObjectEntry.new({ key, value: toFfi(val) }), + duperFfi.DuperObjectEntry.new({ key, value: toFfi(val as any) }), ); return duperFfi.DuperValue.Object.new({ identifier: undefined, -- 2.51.2