Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed Aug 24, 2024
1 parent b4cd9a8 commit 47a1e83
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"./dist/wasm"
],
"scripts": {
"build:wasm": "cd ./src/wasm && rimraf pkg && wasm-pack build --target web --release && cd ../.. && node patch.js x25519_wasm",
"build:node": "rimraf dist && rollup -c && rsync -a ./src/wasm ./dist --exclude=target --exclude=pkg",
"build:wasm": "cd ./src/wasm && rimraf pkg && wasm-pack build --target web --release && cd ../.. && node patch.wasm.mjs",
"build:node": "rimraf dist && rollup -c && rsync -a ./src/wasm ./dist --exclude=target --exclude=pkg && node patch.node.mjs",
"build": "npm run build:wasm && npm run build:node",
"test": "node ./dist/test/node/index.test.mjs",
"prepare": "npm run build:node"
Expand Down Expand Up @@ -63,6 +63,6 @@
"deno"
],
"peerDependencies": {
"@hazae41/memory.wasm": "^1.0.8"
"@hazae41/memory.wasm": "^1.0.9"
}
}
}
9 changes: 9 additions & 0 deletions patch.node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from "fs"

const slashes = "/..".repeat(process.env.npm_package_name.split("/").length)

const original = fs.readFileSync("./dist/wasm/Cargo.toml", "utf8")

const replaced = original.replaceAll("../../node_modules", `../..${slashes}`)

fs.writeFileSync("./dist/wasm/Cargo.toml", replaced)
5 changes: 4 additions & 1 deletion patch.js → patch.wasm.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { readFileSync, rmSync, writeFileSync } from "fs";

const [name] = process.argv.slice(2)
const cargo = readFileSync(`./src/wasm/Cargo.toml`, "utf8")
const packp = cargo.split("\n\n").find(p => p.startsWith("[package]"))
const namel = packp.split("\n").find(l => l.startsWith("name = "))
const name = namel.split(" = ")[1].replaceAll('"', "").trim()

const wasm = readFileSync(`./src/wasm/pkg/${name}_bg.wasm`)

Expand Down

0 comments on commit 47a1e83

Please sign in to comment.