Skip to content

Commit 1e8f16b

Browse files
anandgupta42claude
andcommitted
fix: address code review — existence check, comment fix, better diagnostics
- Add `existsSync` check before copying `node_python_bridge.py` with a clear error message if the file is missing from the dependency - Fix misleading comment that said "no fallback needed" while fallback code existed — now accurately describes the `__require` fallback - Log the nearest `__dirname` match on pattern mismatch to aid debugging Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9d6336f commit 1e8f16b

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cpSync, readFileSync, writeFileSync } from "fs"
1+
import { cpSync, existsSync, readFileSync, writeFileSync } from "fs"
22
import { dirname, join } from "path"
33

44
const dist = join(import.meta.dir, "..", "dist")
@@ -12,6 +12,11 @@ console.log(`Copied altimate_python_packages → dist/`)
1212
// 2. Copy node_python_bridge.py into dist so it lives next to index.js
1313
// node_python_bridge.py is shipped in dbt-integration's dist
1414
const bridgePy = join(dirname(resolved), "node_python_bridge.py")
15+
if (!existsSync(bridgePy)) {
16+
console.error(`ERROR: node_python_bridge.py not found at ${bridgePy}`)
17+
console.error(` Is @altimateai/dbt-integration up to date?`)
18+
process.exit(1)
19+
}
1520
cpSync(bridgePy, join(dist, "node_python_bridge.py"))
1621
console.log(`Copied node_python_bridge.py → dist/`)
1722

@@ -23,12 +28,15 @@ let code = readFileSync(indexPath, "utf8")
2328
const pattern = /var __dirname\s*=\s*"[^"]*python-bridge[^"]*"/
2429
if (pattern.test(code)) {
2530
// import.meta.dirname is supported by Bun and Node >= 20.11.0.
26-
// Node 18 is EOL (April 2025), so no fallback needed.
31+
// Fallback via __require handles older runtimes where import.meta.dirname is unavailable.
2732
const replacement = `var __dirname = typeof import.meta.dirname === "string" ? import.meta.dirname : __require("path").dirname(__require("url").fileURLToPath(import.meta.url))`
2833
code = code.replace(pattern, replacement)
2934
writeFileSync(indexPath, code)
3035
console.log(`Patched __dirname in dist/index.js`)
3136
} else {
37+
const found = code.match(/var __dirname[^;]*/)?.[0] ?? "(not found)"
3238
console.error(`ERROR: could not find python-bridge __dirname to patch — the bundle format may have changed`)
39+
console.error(` Pattern: ${pattern}`)
40+
console.error(` Nearest match: ${found}`)
3341
process.exit(1)
3442
}

0 commit comments

Comments
 (0)