Skip to content

Commit da04c8e

Browse files
suryaiyer95claude
andcommitted
fix: drop Node 18 fallback — path is not in scope before __dirname in bundle
GLM-5 review correctly identified that `path` is defined AFTER `__dirname` in the bundled output, so the `path.dirname(fileURLToPath(...))` fallback would throw `ReferenceError` on Node < 20.11.0. Since Node 18 is EOL (April 2025), use `import.meta.dirname` unconditionally. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2cc41eb commit da04c8e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/dbt-tools/script/copy-python.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const indexPath = join(dist, "index.js")
2222
let code = readFileSync(indexPath, "utf8")
2323
const pattern = /var __dirname\s*=\s*"[^"]*python-bridge[^"]*"/
2424
if (pattern.test(code)) {
25-
// Fallback for Node < 20.11.0 where import.meta.dirname is unavailable.
26-
// The bundle already imports fileURLToPath from "url", so path + url are in scope.
27-
const replacement = `var __dirname = typeof import.meta.dirname === "string" ? import.meta.dirname : path.dirname(fileURLToPath(import.meta.url))`
25+
// import.meta.dirname is supported by Bun and Node >= 20.11.0.
26+
// Node 18 is EOL (April 2025), so no fallback needed.
27+
const replacement = `var __dirname = import.meta.dirname`
2828
code = code.replace(pattern, replacement)
2929
writeFileSync(indexPath, code)
3030
console.log(`Patched __dirname in dist/index.js`)

0 commit comments

Comments
 (0)