roxify 1.5.8 → 1.5.9

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.
@@ -13,11 +13,24 @@ function getNativeModule() {
13
13
  nativeRequire = require;
14
14
  }
15
15
  else {
16
- // Mode ESM - utiliser import.meta.url
17
- // @ts-ignore - import.meta.url existe en ESM
18
- const __filename = fileURLToPath(import.meta.url);
19
- moduleDir = dirname(__filename);
20
- nativeRequire = createRequire(import.meta.url);
16
+ // Try ESM import.meta.url first (may throw in CJS/bundled contexts), otherwise fallback to CWD
17
+ try {
18
+ // @ts-ignore - import.meta.url exists in proper ESM contexts
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ moduleDir = dirname(__filename);
21
+ nativeRequire = createRequire(import.meta.url);
22
+ }
23
+ catch {
24
+ // Fallback (bundled CJS without __dirname): use current working directory
25
+ moduleDir = process.cwd();
26
+ try {
27
+ // @ts-ignore
28
+ nativeRequire = require;
29
+ }
30
+ catch {
31
+ nativeRequire = createRequire(process.cwd());
32
+ }
33
+ }
21
34
  }
22
35
  function getNativePath() {
23
36
  const platformMap = {
@@ -2,8 +2,22 @@ import { spawn } from 'child_process';
2
2
  import { existsSync } from 'fs';
3
3
  import { dirname, join } from 'path';
4
4
  import { fileURLToPath } from 'url';
5
- const __filename = fileURLToPath(import.meta.url);
6
- const __dirname = dirname(__filename);
5
+ let moduleDir;
6
+ try {
7
+ // CJS bundlers may provide __dirname; prefer it when available
8
+ if (typeof __dirname !== 'undefined') {
9
+ // @ts-ignore
10
+ moduleDir = __dirname;
11
+ }
12
+ else {
13
+ // @ts-ignore - import.meta.url exists in ESM
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ moduleDir = dirname(__filename);
16
+ }
17
+ }
18
+ catch {
19
+ moduleDir = process.cwd();
20
+ }
7
21
  function findRustBinary() {
8
22
  const candidates = [];
9
23
  const binNames = process.platform === 'win32'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roxify",
3
- "version": "1.5.8",
3
+ "version": "1.5.9",
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",