roxify 1.5.6 → 1.5.7

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,54 +1,77 @@
1
- import { createRequire } from 'module';
2
1
  import { arch, platform } from 'os';
3
- import { dirname, join } from 'path';
2
+ import { join, dirname } from 'path';
3
+ import { createRequire } from 'module';
4
4
  import { fileURLToPath } from 'url';
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
7
- const require = createRequire(import.meta.url);
8
- function getNativePath() {
9
- const platformMap = {
10
- linux: 'x86_64-unknown-linux-gnu',
11
- darwin: arch() === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin',
12
- win32: 'x86_64-pc-windows-gnu',
13
- };
14
- const platformAltMap = {
15
- win32: 'x86_64-pc-windows-msvc',
16
- };
17
- const extMap = {
18
- linux: 'so',
19
- darwin: 'dylib',
20
- win32: 'node',
21
- };
22
- const currentPlatform = platform();
23
- const target = platformMap[currentPlatform];
24
- const targetAlt = platformAltMap[currentPlatform];
25
- const ext = extMap[currentPlatform];
26
- if (!target || !ext) {
27
- throw new Error(`Unsupported platform: ${currentPlatform}`);
5
+ function getNativeModule() {
6
+ let moduleDir;
7
+ let nativeRequire;
8
+ if (typeof __dirname !== 'undefined') {
9
+ // Mode CJS - variables globales disponibles
10
+ moduleDir = __dirname;
11
+ // @ts-ignore
12
+ nativeRequire = require;
28
13
  }
29
- const prebuiltPath = join(__dirname, '../../libroxify_native.node');
30
- const targetPath = join(__dirname, `../../libroxify_native-${target}.${ext}`);
31
- const targetAltPath = targetAlt ? join(__dirname, `../../libroxify_native-${targetAlt}.${ext}`) : null;
32
- try {
33
- return require.resolve(prebuiltPath);
14
+ else {
15
+ // Mode ESM - utiliser import.meta.url
16
+ // @ts-ignore - import.meta.url existe en ESM
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ moduleDir = dirname(__filename);
19
+ nativeRequire = createRequire(import.meta.url);
34
20
  }
35
- catch {
21
+ function getNativePath() {
22
+ const platformMap = {
23
+ linux: 'x86_64-unknown-linux-gnu',
24
+ darwin: arch() === 'arm64' ? 'aarch64-apple-darwin' : 'x86_64-apple-darwin',
25
+ win32: 'x86_64-pc-windows-gnu',
26
+ };
27
+ const platformAltMap = {
28
+ win32: 'x86_64-pc-windows-msvc',
29
+ };
30
+ const extMap = {
31
+ linux: 'so',
32
+ darwin: 'dylib',
33
+ win32: 'node',
34
+ };
35
+ const currentPlatform = platform();
36
+ const target = platformMap[currentPlatform];
37
+ const targetAlt = platformAltMap[currentPlatform];
38
+ const ext = extMap[currentPlatform];
39
+ if (!target || !ext) {
40
+ throw new Error(`Unsupported platform: ${currentPlatform}`);
41
+ }
42
+ const prebuiltPath = join(moduleDir, '../../libroxify_native.node');
43
+ 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;
36
48
  try {
37
- return require.resolve(targetPath);
49
+ return nativeRequire.resolve(prebuiltPath);
38
50
  }
39
51
  catch {
40
- if (targetAltPath) {
52
+ try {
53
+ return nativeRequire.resolve(bundlePath);
54
+ }
55
+ catch {
41
56
  try {
42
- return require.resolve(targetAltPath);
57
+ return nativeRequire.resolve(targetPath);
43
58
  }
44
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}`);
67
+ }
68
+ }
45
69
  throw new Error(`Native module not found for ${currentPlatform}-${arch()}. ` +
46
- `Expected: ${prebuiltPath} or ${targetPath} or ${targetAltPath}`);
70
+ `Expected: ${prebuiltPath} or ${bundlePath} or ${targetPath}`);
47
71
  }
48
72
  }
49
- throw new Error(`Native module not found for ${currentPlatform}-${arch()}. ` +
50
- `Expected: ${prebuiltPath} or ${targetPath}`);
51
73
  }
52
74
  }
75
+ return nativeRequire(getNativePath());
53
76
  }
54
- export const native = require(getNativePath());
77
+ export const native = getNativeModule();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxify",
3
- "version": "1.5.6",
3
+ "version": "1.5.7",
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",