jiren 3.7.0 → 3.8.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/components/client-bun.ts +12 -0
- package/components/index.ts +1 -1
- package/components/native.ts +35 -4
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JirenClient as NativeJirenClient } from "./client";
|
|
2
|
+
import { JirenClient as FetchJirenClient } from "./client-node-fetch";
|
|
3
|
+
import { isNativeAvailable } from "./native";
|
|
4
|
+
|
|
5
|
+
const forceFallback = process.env.JIREN_FORCE_FETCH_FALLBACK === "1";
|
|
6
|
+
const isWindows = process.platform === "win32";
|
|
7
|
+
|
|
8
|
+
export const JirenClient = (
|
|
9
|
+
!forceFallback && !isWindows && isNativeAvailable
|
|
10
|
+
? NativeJirenClient
|
|
11
|
+
: FetchJirenClient
|
|
12
|
+
) as unknown as typeof NativeJirenClient;
|
package/components/index.ts
CHANGED
package/components/native.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { dlopen, FFIType, suffix } from "bun:ffi";
|
|
2
|
+
import fs from "fs";
|
|
2
3
|
import { join } from "path";
|
|
3
4
|
|
|
4
|
-
const platform = process.platform;
|
|
5
|
-
const arch = process.arch;
|
|
6
|
-
|
|
7
5
|
// Reverted to flat structure
|
|
8
6
|
const libPath = join(import.meta.dir, `../lib/libhttpclient.${suffix}`);
|
|
9
7
|
|
|
@@ -383,4 +381,37 @@ export const ffiDef = {
|
|
|
383
381
|
},
|
|
384
382
|
} as const;
|
|
385
383
|
|
|
386
|
-
|
|
384
|
+
let nativeLib: ReturnType<typeof dlopen> | null = null;
|
|
385
|
+
let nativeLoadError: Error | null = null;
|
|
386
|
+
|
|
387
|
+
try {
|
|
388
|
+
if (!fs.existsSync(libPath)) {
|
|
389
|
+
nativeLoadError = new Error(`Native library not found at: ${libPath}`);
|
|
390
|
+
} else {
|
|
391
|
+
nativeLib = dlopen(libPath, ffiDef);
|
|
392
|
+
}
|
|
393
|
+
} catch (error) {
|
|
394
|
+
nativeLoadError =
|
|
395
|
+
error instanceof Error ? error : new Error("Unknown native load error");
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export const isNativeAvailable = nativeLib !== null;
|
|
399
|
+
export const nativeLibraryPath = libPath;
|
|
400
|
+
export const nativeAvailabilityError = nativeLoadError;
|
|
401
|
+
|
|
402
|
+
function unavailableSymbol(symbol: string) {
|
|
403
|
+
return () => {
|
|
404
|
+
const reason = nativeLoadError?.message || "Native runtime unavailable";
|
|
405
|
+
throw new Error(
|
|
406
|
+
`[Jiren] Native symbol "${symbol}" is unavailable. ${reason}`,
|
|
407
|
+
);
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const unavailableSymbols = new Proxy({} as Record<string, any>, {
|
|
412
|
+
get(_target, symbol) {
|
|
413
|
+
return unavailableSymbol(String(symbol));
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
export const lib = (nativeLib ?? { symbols: unavailableSymbols }) as any;
|