roxify 1.5.7 → 1.5.8
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/dist/utils/native.js +53 -24
- package/package.json +1 -1
package/dist/utils/native.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { arch, platform } from 'os';
|
|
2
|
-
import { join, dirname } from 'path';
|
|
2
|
+
import { join, dirname, resolve } from 'path';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
+
import { existsSync } from 'fs';
|
|
5
6
|
function getNativeModule() {
|
|
6
7
|
let moduleDir;
|
|
7
8
|
let nativeRequire;
|
|
@@ -41,36 +42,64 @@ function getNativeModule() {
|
|
|
41
42
|
}
|
|
42
43
|
const prebuiltPath = join(moduleDir, '../../libroxify_native.node');
|
|
43
44
|
const bundlePath = join(moduleDir, '../libroxify_native.node');
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
// compute repo root by walking up from moduleDir (fallback to process.cwd())
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
console.debug('[native] moduleDir', moduleDir);
|
|
48
|
+
let root = moduleDir && moduleDir !== '.' ? moduleDir : process.cwd();
|
|
49
|
+
while (root.length > 1 && !existsSync(resolve(root, 'package.json')) && !existsSync(resolve(root, 'Cargo.toml'))) {
|
|
50
|
+
const parent = resolve(root, '..');
|
|
51
|
+
if (parent === root)
|
|
52
|
+
break;
|
|
53
|
+
root = parent;
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
const localTargetRelease = resolve(root, `target/release/libroxify_native${ext === 'node' ? '.node' : `-${target}.${ext}`}`);
|
|
56
|
+
const localReleaseGeneric = resolve(root, 'target/release/libroxify_native.so');
|
|
57
|
+
const nodeModulesBase = resolve(root, 'node_modules/roxify');
|
|
58
|
+
const nodeModulesTarget = resolve(nodeModulesBase, `libroxify_native-${target}.${ext}`);
|
|
59
|
+
const nodeModulesGeneric = resolve(nodeModulesBase, ext === 'node' ? 'libroxify_native.node' : `libroxify_native.${ext}`);
|
|
60
|
+
const bundleTarget = resolve(moduleDir, `../libroxify_native-${target}.${ext}`);
|
|
61
|
+
const bundleGeneric = resolve(moduleDir, bundlePath);
|
|
62
|
+
const candidates = [
|
|
63
|
+
localTargetRelease,
|
|
64
|
+
localReleaseGeneric,
|
|
65
|
+
nodeModulesTarget,
|
|
66
|
+
nodeModulesGeneric,
|
|
67
|
+
bundleTarget,
|
|
68
|
+
bundleGeneric,
|
|
69
|
+
prebuiltPath,
|
|
70
|
+
];
|
|
71
|
+
// use built-in fs.existsSync (static import to work in ESM and CJS)
|
|
72
|
+
for (const c of candidates) {
|
|
52
73
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
throw new Error(`Native module not found for ${currentPlatform}-${arch()}. ` +
|
|
66
|
-
`Expected: ${prebuiltPath} or ${bundlePath} or ${targetPath} or ${targetAltPath}`);
|
|
74
|
+
if (!existsSync(c))
|
|
75
|
+
continue;
|
|
76
|
+
// If it's a .so (native build) but Node expects .node extension, create a .node symlink
|
|
77
|
+
if (c.endsWith('.so')) {
|
|
78
|
+
const nodeAlias = c.replace(/\.so$/, '.node');
|
|
79
|
+
try {
|
|
80
|
+
if (!existsSync(nodeAlias)) {
|
|
81
|
+
// copy the .so to a .node so Node treats it as a native addon
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
require('fs').copyFileSync(c, nodeAlias);
|
|
67
84
|
}
|
|
85
|
+
// debug
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
console.debug('[native] using node alias', nodeAlias);
|
|
88
|
+
return nodeAlias;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
// fallback to original .so (might fail to load via require)
|
|
92
|
+
return c;
|
|
68
93
|
}
|
|
69
|
-
throw new Error(`Native module not found for ${currentPlatform}-${arch()}. ` +
|
|
70
|
-
`Expected: ${prebuiltPath} or ${bundlePath} or ${targetPath}`);
|
|
71
94
|
}
|
|
95
|
+
// debug
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
console.debug('[native] using path', c);
|
|
98
|
+
return c;
|
|
72
99
|
}
|
|
100
|
+
catch { }
|
|
73
101
|
}
|
|
102
|
+
throw new Error(`Native module not found for ${currentPlatform}-${arch()}. Checked: ${candidates.join(' ')}`);
|
|
74
103
|
}
|
|
75
104
|
return nativeRequire(getNativePath());
|
|
76
105
|
}
|
package/package.json
CHANGED