Skip to content

Commit 4b793c6

Browse files
committed
feat(v0.3.0): Add WASM support & fix webpack bundling issues
## Changes: - Add WebAssembly (WASM) support for browser environments - Refactor native-loader to use dynamic require (module.createRequire) - Create independent browser-loader for WASM module loading - Lazy-load loaders in utils.ts to prevent webpack bundling - Add build:check script to verify no static requires in output - Add build:wasm script for WASM compilation - Update tests to call initializeSweph() in beforeAll hook ## Breaking Changes: - initializeSweph() must now be awaited before using calculation functions ## Verification: - All 34 tests pass - build:check confirms no static swisseph-v2 requires - Webpack can no longer detect native module imports at build time
1 parent bea6159 commit 4b793c6

22 files changed

Lines changed: 1191 additions & 389 deletions

dist/browser-loader.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Browser/WASM Loader for @af/sweph
3+
*
4+
* This module is COMPLETELY INDEPENDENT from native-loader.ts.
5+
* It handles loading the WebAssembly module for browser environments.
6+
*
7+
* The package.json "browser" field aliases native-loader to this file
8+
* when bundling for browser targets.
9+
*/
10+
/**
11+
* Load and initialize the WASM module
12+
* This is the browser equivalent of loadNativeBinary from native-loader.ts
13+
*/
14+
export declare function loadNativeBinary(options?: {
15+
wasmUrl?: string;
16+
}): Promise<any>;
17+
/**
18+
* Get native module instance (throws if not loaded)
19+
* Browser equivalent of getNativeModuleSync
20+
*/
21+
export declare function getNativeModuleSync(): any;
22+
/**
23+
* Platform info for browser (always returns browser info)
24+
*/
25+
export declare function getPlatformInfo(): {
26+
platform: string;
27+
arch: string;
28+
key: string;
29+
isSupported: boolean;
30+
prebuildPaths: string[];
31+
};
32+
/**
33+
* Check if WASM is available (always true in supported browsers)
34+
*/
35+
export declare function hasPrebuilds(): boolean;
36+
/**
37+
* Get supported platforms for browser
38+
*/
39+
export declare function getSupportedPlatforms(): readonly string[];
40+
//# sourceMappingURL=browser-loader.d.ts.map

dist/browser-loader.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser-loader.js

Lines changed: 265 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/browser-loader.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/native-loader.d.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
* Load the Swiss Ephemeris native module from pre-built binaries
33
* Falls back to swisseph-v2 if prebuilds are not available
44
*
5-
* @returns Swiss Ephemeris native module instance
5+
* Uses dynamic requires to prevent webpack bundling of native modules.
6+
*
7+
* @returns Promise resolving to Swiss Ephemeris native module instance
68
* @throws Error if no compatible native module can be loaded
79
*/
8-
export declare function loadNativeBinary(): any;
10+
export declare function loadNativeBinary(_options?: any): Promise<any>;
11+
/**
12+
* Synchronous version for backward compatibility
13+
* Will throw if module hasn't been loaded yet via async loadNativeBinary
14+
*/
15+
export declare function getNativeModuleSync(): any;
916
/**
1017
* Get information about the current platform
1118
* Useful for debugging deployment issues

dist/native-loader.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)