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.
@@ -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
- const targetPath = join(moduleDir, `../../libroxify_native-${target}.${ext}`);
45
- const targetAltPath = targetAlt
46
- ? join(moduleDir, `../../libroxify_native-${targetAlt}.${ext}`)
47
- : null;
48
- try {
49
- return nativeRequire.resolve(prebuiltPath);
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
- catch {
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
- return nativeRequire.resolve(bundlePath);
54
- }
55
- catch {
56
- try {
57
- return nativeRequire.resolve(targetPath);
58
- }
59
- catch {
60
- if (targetAltPath) {
61
- try {
62
- return nativeRequire.resolve(targetAltPath);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxify",
3
- "version": "1.5.7",
3
+ "version": "1.5.8",
4
4
  "description": "Ultra-lightweight PNG steganography with native Rust acceleration. Encode binary data into PNG images with zstd compression.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",