-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (47 loc) · 1.99 KB
/
Copy pathindex.js
File metadata and controls
53 lines (47 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict"
const path = require("path")
const fs = require("fs")
// Try a prebuilt binary first (shipped with published packages),
// then fall back to a locally compiled build.
function loadAddon() {
const platform = process.platform
const arch = process.arch
const prebuilt = path.join(__dirname, "prebuilds", `${platform}-${arch}`, "doltlite.node")
const compiled = path.join(__dirname, "build", "Release", "doltlite.node")
const compiledObjTarget = path.join(__dirname, "build", "Release", "obj.target", "doltlite.node")
const errors = []
for (const candidate of [prebuilt, compiled, compiledObjTarget]) {
if (!fs.existsSync(candidate)) continue
try {
return require(candidate)
} catch (err) {
errors.push(`${candidate}: ${err && err.message ? err.message : err}`)
}
}
throw new Error(
`@dolthub/doltlite: no native binary found for ${platform}-${arch}.\n` +
(errors.length ? `Tried:\n${errors.join("\n")}\n` : "") +
`Run \`npm install\` to build from source, or file an issue at ` +
`https://github.com/dolthub/doltlite-node/issues`
)
}
// Absolute path to the platform's `doltlite` CLI binary, shipped in the
// package's prebuilds/ alongside the .node addon. Used by consumers (e.g.
// opencode) that want to spawn an interactive shell or pipe SQL through
// the doltlite shell. Throws if the binary isn't bundled for this platform.
function binPath() {
const platform = process.platform
const arch = process.arch
const ext = platform === "win32" ? ".exe" : ""
const candidate = path.join(__dirname, "prebuilds", `${platform}-${arch}`, `doltlite${ext}`)
if (!fs.existsSync(candidate)) {
throw new Error(
`@dolthub/doltlite: no doltlite CLI binary bundled for ${platform}-${arch}.\n` +
`Expected at ${candidate}. File an issue at ` +
`https://github.com/dolthub/doltlite-node/issues`
)
}
return candidate
}
const { DatabaseSync, StatementSync } = loadAddon()
module.exports = { DatabaseSync, StatementSync, binPath }