@toolkit-cli/toolkode-native-darwin-x64 1.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +52 -0
- package/package.json +7 -0
- package/toolkode-core.darwin-x64.node +0 -0
package/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @toolkit-cli/toolkode-native — platform dispatcher.
|
|
5
|
+
*
|
|
6
|
+
* Resolves the correct per-platform napi binary at runtime. End users get
|
|
7
|
+
* `@toolkit-cli/toolkode-native-<os>-<arch>` pulled in via this package's
|
|
8
|
+
* optionalDependencies during `npm install`. Dev mode (post `napi build`)
|
|
9
|
+
* falls back to a locally-built `.node` file sitting next to this file. If
|
|
10
|
+
* nothing loads, callers get graceful-degradation stubs so the TUI keeps
|
|
11
|
+
* working.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const { platform, arch } = process
|
|
15
|
+
const target = `${platform}-${arch}`
|
|
16
|
+
|
|
17
|
+
function tryRequire(id) {
|
|
18
|
+
try {
|
|
19
|
+
return require(id)
|
|
20
|
+
} catch (_) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function load() {
|
|
26
|
+
// 1. Per-platform npm package (shipped by CI via optionalDependencies)
|
|
27
|
+
const pkgMod = tryRequire(`@toolkit-cli/toolkode-native-${target}`)
|
|
28
|
+
if (pkgMod) return pkgMod
|
|
29
|
+
|
|
30
|
+
// 2. Locally built .node next to this file (dev mode after `napi build`)
|
|
31
|
+
// napi-rs emits names like `toolkode-core.darwin-arm64.node` or
|
|
32
|
+
// just `toolkode-core.node` depending on the flags used.
|
|
33
|
+
const localCandidates = [
|
|
34
|
+
`./toolkode-core.${target}.node`,
|
|
35
|
+
"./toolkode-core.node",
|
|
36
|
+
]
|
|
37
|
+
for (const candidate of localCandidates) {
|
|
38
|
+
const mod = tryRequire(candidate)
|
|
39
|
+
if (mod) return mod
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 3. Graceful fallback. Callers should check `Native.isAvailable()` and
|
|
43
|
+
// degrade to a friendly error path (the TUI does this already).
|
|
44
|
+
return {
|
|
45
|
+
ping: () => "toolkode-core::pong (fallback)",
|
|
46
|
+
version: () => "0.0.0-fallback",
|
|
47
|
+
foresight_analyze: null,
|
|
48
|
+
foresight_pattern_count: null,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = load()
|
package/package.json
ADDED
|
Binary file
|