summaryrefslogtreecommitdiffhomepage
path: root/nix/scripts/canonicalize-node-modules.ts
diff options
context:
space:
mode:
authorAlbert O'Shea <[email protected]>2025-11-24 15:54:29 +1100
committerGitHub <[email protected]>2025-11-23 22:54:29 -0600
commita3a239967f170423e91382bfdaf1058755befbb8 (patch)
tree322961f56a32fe8d164fdebc43c3a326c3fa421e /nix/scripts/canonicalize-node-modules.ts
parentb4fd4bb25757250b1bcd4da9e6398011ed07e2f3 (diff)
downloadopencode-a3a239967f170423e91382bfdaf1058755befbb8.tar.gz
opencode-a3a239967f170423e91382bfdaf1058755befbb8.zip
nix: bundle js dist with bun and patch tree-sitter wasm paths (#4644)
Co-authored-by: Aiden Cline <[email protected]> Co-authored-by: Github Action <[email protected]>
Diffstat (limited to 'nix/scripts/canonicalize-node-modules.ts')
-rw-r--r--nix/scripts/canonicalize-node-modules.ts31
1 files changed, 24 insertions, 7 deletions
diff --git a/nix/scripts/canonicalize-node-modules.ts b/nix/scripts/canonicalize-node-modules.ts
index bb004f3c5..828a18fbc 100644
--- a/nix/scripts/canonicalize-node-modules.ts
+++ b/nix/scripts/canonicalize-node-modules.ts
@@ -24,15 +24,13 @@ for (const entry of directories) {
if (!info.isDirectory()) {
continue
}
- const marker = entry.lastIndexOf("@")
- if (marker <= 0) {
+ const parsed = parseEntry(entry)
+ if (!parsed) {
continue
}
- const slug = entry.slice(0, marker).replace(/\+/g, "/")
- const version = entry.slice(marker + 1)
- const list = versions.get(slug) ?? []
- list.push({ dir: full, version, label: entry })
- versions.set(slug, list)
+ const list = versions.get(parsed.name) ?? []
+ list.push({ dir: full, version: parsed.version, label: entry })
+ versions.set(parsed.name, list)
}
const semverModule = (await import(join(bunRoot, "node_modules/semver"))) as
@@ -79,6 +77,12 @@ for (const [slug, entry] of Array.from(selections.entries()).sort((a, b) => a[0]
await mkdir(parent, { recursive: true })
const linkPath = join(parent, leaf)
const desired = join(entry.dir, "node_modules", slug)
+ const exists = await lstat(desired)
+ .then(info => info.isDirectory())
+ .catch(() => false)
+ if (!exists) {
+ continue
+ }
const relativeTarget = relative(parent, desired)
const resolved = relativeTarget.length === 0 ? "." : relativeTarget
await rm(linkPath, { recursive: true, force: true })
@@ -94,3 +98,16 @@ for (const line of rewrites.slice(0, 20)) {
if (rewrites.length > 20) {
console.log(" ...")
}
+
+function parseEntry(label: string) {
+ const marker = label.startsWith("@") ? label.indexOf("@", 1) : label.indexOf("@")
+ if (marker <= 0) {
+ return null
+ }
+ const name = label.slice(0, marker).replace(/\+/g, "/")
+ const version = label.slice(marker + 1)
+ if (!name || !version) {
+ return null
+ }
+ return { name, version }
+}