Skip to content

Commit a4149ea

Browse files
committed
fix
1 parent 5b8e80f commit a4149ea

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

src/esbuild.mjs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,43 +110,52 @@ async function main() {
110110
console.warn(`[${name}] sqlite source not found at: ${sqliteSource}`)
111111
}
112112

113-
// Copy bindings package (required by sqlite3)
114-
// Find bindings package dynamically to avoid hardcoding version
115-
let bindingsSource = null
116-
try {
117-
const require = createRequire(import.meta.url)
118-
const bindingsModulePath = require.resolve("bindings/package.json")
119-
bindingsSource = path.dirname(bindingsModulePath)
120-
} catch (err) {
121-
// Fallback: try to find it in pnpm structure by searching for bindings directories
122-
const pnpmDir = path.join(srcDir, "../node_modules/.pnpm")
123-
if (fs.existsSync(pnpmDir)) {
124-
const entries = fs.readdirSync(pnpmDir)
125-
for (const entry of entries) {
126-
if (entry.startsWith("bindings@")) {
127-
const bindingsPath = path.join(pnpmDir, entry, "node_modules/bindings")
128-
if (fs.existsSync(bindingsPath)) {
129-
bindingsSource = bindingsPath
130-
break
113+
// Helper function to find and copy a package
114+
const copyPackage = (packageName) => {
115+
let packageSource = null
116+
try {
117+
const require = createRequire(import.meta.url)
118+
const packagePath = require.resolve(`${packageName}/package.json`)
119+
packageSource = path.dirname(packagePath)
120+
} catch (err) {
121+
// Fallback: try to find it in pnpm structure
122+
const pnpmDir = path.join(srcDir, "../node_modules/.pnpm")
123+
if (fs.existsSync(pnpmDir)) {
124+
const entries = fs.readdirSync(pnpmDir)
125+
for (const entry of entries) {
126+
if (entry.startsWith(`${packageName}@`)) {
127+
const packagePath = path.join(pnpmDir, entry, "node_modules", packageName)
128+
if (fs.existsSync(packagePath)) {
129+
packageSource = packagePath
130+
break
131+
}
131132
}
132133
}
133134
}
134135
}
135-
}
136-
137-
const bindingsDest = path.join(distDir, "node_modules/bindings")
138136

139-
if (bindingsSource && fs.existsSync(bindingsSource)) {
140-
try {
141-
fs.cpSync(bindingsSource, bindingsDest, { recursive: true })
142-
console.log(`[${name}] Copied bindings package to dist/node_modules/bindings`)
143-
} catch (err) {
144-
console.error(`[${name}] Failed to copy bindings package:`, err)
137+
if (packageSource && fs.existsSync(packageSource)) {
138+
const packageDest = path.join(distDir, "node_modules", packageName)
139+
try {
140+
fs.cpSync(packageSource, packageDest, { recursive: true })
141+
console.log(`[${name}] Copied ${packageName} package to dist/node_modules/${packageName}`)
142+
return true
143+
} catch (err) {
144+
console.error(`[${name}] Failed to copy ${packageName} package:`, err)
145+
return false
146+
}
147+
} else {
148+
console.warn(`[${name}] ${packageName} source not found`)
149+
return false
145150
}
146-
} else {
147-
console.warn(`[${name}] bindings source not found`)
148151
}
149152

153+
// Copy bindings package (required by sqlite3)
154+
copyPackage("bindings")
155+
156+
// Copy file-uri-to-path (required by bindings)
157+
copyPackage("file-uri-to-path")
158+
150159
// Copy JSDOM xhr-sync-worker.js to fix runtime resolution
151160
const jsdomWorkerDest = path.join(distDir, "xhr-sync-worker.js")
152161

0 commit comments

Comments
 (0)