Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ jobs:
echo "::error::dbt-tools bundle contains hardcoded absolute path in __dirname"
exit 1
fi
# Verify __dirname was patched to runtime resolution
if ! grep -q 'import.meta.dirname' packages/dbt-tools/dist/index.js; then
echo "::error::dbt-tools bundle missing import.meta.dirname patch"
# Verify the bridge script resolves relative to the bundle at runtime
if ! grep -q 'fileURLToPath(import.meta.url)' packages/dbt-tools/dist/index.js; then
echo "::error::dbt-tools bundle does not resolve node_python_bridge.py at runtime"
exit 1
fi
echo "dbt-tools smoke test passed"
Expand Down
82 changes: 18 additions & 64 deletions bun.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/dbt-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test:e2e": "bun test test/e2e/ --timeout 300000"
},
"dependencies": {
"@altimateai/dbt-integration": "^0.2.2"
"@altimateai/dbt-integration": "^0.3.13"
},
"devDependencies": {
"@tsconfig/bun": "catalog:",
Expand Down
29 changes: 11 additions & 18 deletions packages/dbt-tools/script/copy-python.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cpSync, existsSync, readFileSync, writeFileSync } from "fs"
import { cpSync, existsSync, readFileSync } from "fs"
import { dirname, join } from "path"

const dist = join(import.meta.dir, "..", "dist")
Expand All @@ -20,23 +20,16 @@ if (!existsSync(bridgePy)) {
cpSync(bridgePy, join(dist, "node_python_bridge.py"))
console.log(`Copied node_python_bridge.py → dist/`)

// 3. Fix the hardcoded __dirname that bun bakes at compile time.
// Replace it with a runtime resolution so the bridge script is found
// relative to the built index.js, not the CI runner's node_modules.
// 3. dbt-integration resolves node_python_bridge.py at runtime from its own
// location (`fileURLToPath(import.meta.url)`), which in this bundle is dist/,
// where step 2 put the script. Fail the build if the bundle ever carries a
// path baked in at build time instead.
const indexPath = join(dist, "index.js")
let code = readFileSync(indexPath, "utf8")
const pattern = /var __dirname\s*=\s*"[^"]*python-bridge[^"]*"/
if (pattern.test(code)) {
// import.meta.dirname is supported by Bun and Node >= 20.11.0.
// Fallback via __require handles older runtimes where import.meta.dirname is unavailable.
const replacement = `var __dirname = typeof import.meta.dirname === "string" ? import.meta.dirname : __require("path").dirname(__require("url").fileURLToPath(import.meta.url))`
code = code.replace(pattern, replacement)
writeFileSync(indexPath, code)
console.log(`Patched __dirname in dist/index.js`)
} else {
const found = code.match(/var __dirname[^;]*/)?.[0] ?? "(not found)"
console.error(`ERROR: could not find python-bridge __dirname to patch — the bundle format may have changed`)
console.error(` Pattern: ${pattern}`)
console.error(` Nearest match: ${found}`)
const code = readFileSync(indexPath, "utf8")
const baked = /var __dirname\s*=\s*"(?:[A-Za-z]:\\\\|\/)/
if (!code.includes("fileURLToPath(import.meta.url)") || !code.includes(`"node_python_bridge.py"`) || baked.test(code)) {
console.error(`ERROR: dist/index.js does not resolve node_python_bridge.py relative to itself at runtime`)
console.error(` Has the @altimateai/dbt-integration bundle format changed?`)
process.exit(1)
}
console.log(`Verified dist/index.js resolves node_python_bridge.py at runtime`)
5 changes: 4 additions & 1 deletion packages/dbt-tools/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
GraphParser,
SourceParser,
TestParser,
UnitTestParser,
SemanticModelParser,
ExposureParser,
FunctionParser,
DocParser,
Expand Down Expand Up @@ -181,7 +183,6 @@ export async function create(cfg: Config): Promise<DBTProjectIntegrationAdapter>
diag,
defer,
changed,
cloudVariantDetector,
)

const adapter = new DBTProjectIntegrationAdapter(
Expand All @@ -200,11 +201,13 @@ export async function create(cfg: Config): Promise<DBTProjectIntegrationAdapter>
new GraphParser(term),
new SourceParser(term),
new TestParser(term),
new UnitTestParser(term),
new ExposureParser(term),
new FunctionParser(term),
new DocParser(term),
term,
new ModelDepthParser(term, client, config),
new SemanticModelParser(term),
)

await adapter.initialize()
Expand Down
Loading
Loading