summaryrefslogtreecommitdiffhomepage
path: root/nix/scripts
diff options
context:
space:
mode:
authorGraham Bennett <[email protected]>2025-12-29 21:15:42 +0000
committerGitHub <[email protected]>2025-12-29 15:15:42 -0600
commit923d114ffab6b8dba8c77e10f07cfc5d0bbca2e4 (patch)
tree77e0dfb7a2a7b2f8063d12048dc199603191caf6 /nix/scripts
parentb157fd10a70531a9eba9ae0790f1a3aa448f4fe3 (diff)
downloadopencode-923d114ffab6b8dba8c77e10f07cfc5d0bbca2e4.tar.gz
opencode-923d114ffab6b8dba8c77e10f07cfc5d0bbca2e4.zip
Support different Nix store path prefixes (#6367)
Diffstat (limited to 'nix/scripts')
-rw-r--r--nix/scripts/patch-wasm.ts7
1 files changed, 4 insertions, 3 deletions
diff --git a/nix/scripts/patch-wasm.ts b/nix/scripts/patch-wasm.ts
index 99f8a40e9..75d6a73d9 100644
--- a/nix/scripts/patch-wasm.ts
+++ b/nix/scripts/patch-wasm.ts
@@ -31,9 +31,10 @@ for (const [name, wasmPath] of byName) {
next = next.replaceAll("tree-sitter.wasm", mainWasm).replaceAll("web-tree-sitter/tree-sitter.wasm", mainWasm)
// Collapse any relative prefixes before absolute store paths (e.g., "../../../..//nix/store/...")
+const nixStorePrefix = process.env.NIX_STORE || "/nix/store";
next = next.replace(/(\.\/)+/g, "./")
-next = next.replace(/(\.\.\/)+\/?(\/nix\/store[^"']+)/g, "/$2")
-next = next.replace(/(["'])\/{2,}(\/nix\/store[^"']+)(["'])/g, "$1/$2$3")
-next = next.replace(/(["'])\/\/(nix\/store[^"']+)(["'])/g, "$1/$2$3")
+next = next.replace(new RegExp(`(\\.\\.\\/)+\\/{1,2}(${nixStorePrefix.replace(/^\//, '').replace(/\//g, "\\/")}[^"']+)`, 'g'), '/$2')
+next = next.replace(new RegExp(`(["'])\\/{2,}(\\/${nixStorePrefix.replace(/\//g, "\\/")}[^"']+)(["'])`, 'g'), '$1$2$3')
+next = next.replace(new RegExp(`(["'])\\/\\/(${nixStorePrefix.replace(/\//g, "\\/")}[^"']+)(["'])`, 'g'), '$1$2$3')
if (next !== content) fs.writeFileSync(file, next)