Skip to content

Commit cd39502

Browse files
committed
fix: update copy script to include snarkjs
1 parent a3c4618 commit cd39502

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

packages/auth-server/project.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@
2222
"executor": "nx:run-commands",
2323
"options": {
2424
"cwd": "packages/auth-server",
25-
"commands": [
26-
{
27-
"command": "pnpm run copy:snarkjs && pnpm nuxt generate"
28-
}
29-
]
25+
"commands": [{ "command": "pnpm nuxt generate" }]
26+
},
27+
"inputs": ["default", "{projectRoot}/scripts/copy-snarkjs.mjs"],
28+
"outputs": ["{projectRoot}/dist"],
29+
"dependsOn": ["copy-snarkjs"]
30+
},
31+
"copy-snarkjs": {
32+
"executor": "nx:run-commands",
33+
"options": {
34+
"cwd": "packages/auth-server",
35+
"command": "pnpm run copy:snarkjs"
3036
}
3137
},
3238
"build:local": {
@@ -35,7 +41,7 @@
3541
"cwd": "packages/auth-server",
3642
"command": "pnpm nuxt generate --envName local"
3743
},
38-
"dependsOn": ["^build"]
44+
"dependsOn": ["copy-snarkjs", "^build"]
3945
},
4046
"preview": {
4147
"executor": "nx:run-commands",

packages/auth-server/scripts/copy-snarkjs.mjs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,30 @@ import { dirname, join, resolve } from "node:path";
55
import { fileURLToPath } from "node:url";
66

77
function main() {
8-
// Resolve the path to snarkjs browser bundle
9-
// Resolve snarkjs package base
8+
// Resolve the path to snarkjs browser bundle.
9+
// We cannot rely on snarkjs/package.json because it is not exported.
1010
let baseDir;
1111
try {
12-
// Prefer import.meta.resolve for pure ESM; fallback to createRequire for older Node versions
13-
let pkgJsonPath;
14-
if (typeof import.meta.resolve === "function") {
15-
const resolvedUrl = import.meta.resolve("snarkjs/package.json");
16-
pkgJsonPath = fileURLToPath(resolvedUrl);
17-
} else {
18-
const require = createRequire(import.meta.url);
19-
pkgJsonPath = require.resolve("snarkjs/package.json");
12+
const require = createRequire(import.meta.url);
13+
const mainEntry = require.resolve("snarkjs"); // e.g. node_modules/snarkjs/dist/main.cjs
14+
// ascend until we reach the package root (folder named 'snarkjs')
15+
let curr = dirname(mainEntry);
16+
while (curr && curr !== "/" && curr.includes("snarkjs")) {
17+
if (curr.endsWith("snarkjs")) {
18+
baseDir = curr;
19+
break;
20+
}
21+
curr = dirname(curr);
22+
}
23+
if (!baseDir) {
24+
// fallback: one directory up from dist
25+
baseDir = dirname(dirname(mainEntry));
2026
}
21-
baseDir = dirname(pkgJsonPath);
2227
} catch (e) {
2328
console.warn("[copy-snarkjs] snarkjs not installed yet; skipping copy", e);
2429
return; // don't fail install, maybe another step will install it
2530
}
26-
const candidateRelPaths = ["dist/web/snarkjs.min.js", "dist/snarkjs.min.js", "build/snarkjs.min.js"];
31+
const candidateRelPaths = ["dist/web/snarkjs.min.js", "dist/snarkjs.min.js", "build/snarkjs.min.js", "snarkjs.min.js"];
2732
let src;
2833
for (const rel of candidateRelPaths) {
2934
const cand = join(baseDir, rel);

0 commit comments

Comments
 (0)