Skip to content

Commit 9a2fc86

Browse files
committed
feat: make library self-contained with pre-built binaries for Vercel
- Remove swisseph-v2 from direct dependencies (moved to optional) - Add platform-specific prebuilt binaries: - darwin-arm64 for macOS M1/M2/M3 - linux-x64 for Vercel/Linux servers - Implement native-loader.ts for platform detection and binary loading - Add fallback support for development with swisseph-v2 - Export platform utilities (getPlatformInfo, hasPrebuilds) - Update README with Vercel deployment section - Bump version to 0.2.0 This update enables Vercel deployment without native compilation. Closes: native module loading issues on serverless platforms
1 parent a6633f6 commit 9a2fc86

22 files changed

Lines changed: 581 additions & 93 deletions

README.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
Swiss Ephemeris library for Vedic astrology calculations with pre-built native binaries.
44

5+
**✅ Vercel Compatible** - Works in serverless environments without native compilation.
6+
57
## Features
68

79
- 🌟 **Vedic Astrology Focus** - Calculate all 9 Vedic planets (Navagraha)
810
- 🚀 **Pre-built Binaries** - No native compilation required
11+
- ☁️ **Vercel Ready** - Works in serverless environments out of the box
912
- 📦 **Pre-compiled Distribution** - Ready-to-use dist files included
10-
- 🌍 **Cross-Platform** - Works on macOS, Linux, and Windows
13+
- 🌍 **Cross-Platform** - Works on macOS (Intel & ARM), Linux, and Windows
1114
- 📦 **Simple API** - Clean, TypeScript-first interface
1215
-**Fast** - Native Swiss Ephemeris performance
1316

@@ -572,26 +575,66 @@ const moon = calculateSinglePlanet(1, date);
572575
| Linux | ARM64 ||
573576
| Windows | x64 ||
574577

578+
## Vercel Deployment
579+
580+
This library is designed to work seamlessly on Vercel's serverless environment:
581+
582+
-**No native compilation** - Pre-built binaries for linux-x64 included
583+
-**Zero configuration** - Works out of the box
584+
-**Optimized for serverless** - Fast cold starts with minimal bundle impact
585+
586+
### Usage in Next.js API Routes
587+
588+
```typescript
589+
// app/api/calculate/route.ts
590+
import { calculatePlanets, calculateLagna } from '@af/sweph';
591+
592+
export async function GET() {
593+
const planets = calculatePlanets(new Date());
594+
return Response.json({ planets });
595+
}
596+
```
597+
598+
### Debug Platform Info
599+
600+
```typescript
601+
import { getPlatformInfo, hasPrebuilds } from '@af/sweph';
602+
603+
// Check platform detection
604+
console.log(getPlatformInfo());
605+
// { platform: 'linux', arch: 'x64', key: 'linux-x64', isSupported: true, ... }
606+
607+
console.log('Has prebuilds:', hasPrebuilds());
608+
// true
609+
```
610+
575611
## Troubleshooting
576612

577613
### Common Issues
578614

579615
1. **"Failed to load Swiss Ephemeris native module"**
580-
- Ensure `swisseph-v2` is installed: `npm install swisseph-v2`
616+
- Ensure package version is >= 0.2.0 for Vercel compatibility
581617
- Check that prebuilt binaries are available for your platform
618+
- For development: `pnpm add swisseph-v2` (optional fallback)
582619

583-
2. **"Ephemeris files not found"**
620+
2. **Vercel deployment fails with "Cannot find module swisseph.node"**
621+
- Upgrade to `@af/sweph@0.2.0` or later
622+
- Clear Vercel build cache and redeploy
623+
- Verify prebuilds/linux-x64/swisseph.node exists in node_modules
624+
625+
3. **"Ephemeris files not found"**
584626
- Ensure `ephe/` directory exists with `.se1` files
585627
- Or set custom path: `setEphemerisPath('/path/to/ephe')`
586628

587-
3. **Incorrect times**
629+
4. **Incorrect times**
588630
- Verify timezone offset is correct (e.g., 5.5 for IST, -5 for EST)
589631
- Ensure input dates are in local time
590632

591-
4. **Null rise/set times**
633+
5. **Null rise/set times**
592634
- Normal for polar regions during certain seasons
593635
- Moon may not rise/set on some days near equator
594636

637+
595638
## Contributing
596639

597640
1. Fork the repository

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { calculateLagna, calculateHouses, } from './houses';
1010
export { calculateSunTimes, calculateSolarNoon, calculateSunPath, } from './sun';
1111
export { calculateMoonData, calculateMoonPhase, calculateNextMoonPhases, } from './moon';
1212
export { getAyanamsa, setEphemerisPath, getJulianDay, dateToJulian, julianToDate, getNativeModule, } from './utils';
13+
export { getPlatformInfo, hasPrebuilds, getSupportedPlatforms, } from './native-loader';
1314
export { PLANETS, AYANAMSA, HOUSE_SYSTEMS, RASHIS, NAKSHATRAS, VEDIC_PLANET_ORDER, } from './constants';
1415
export { createSwephCalculator, createPlanetaryCalculator, createSwephAdapter, createNodeAdapter, initializeSweph, registerAdapter, calculateKundaliPageData, type PlanetaryCalculationProvider, type SwephAdapter, type SunTimesResult, type MoonTimesResult, type LegacyPlanet, type LegacyLagnaInfo, } from './legacy';
1516
//# sourceMappingURL=index.d.ts.map

dist/index.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.

dist/index.js

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

dist/index.js.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.

dist/legacy.js

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

dist/legacy.js.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.

dist/native-loader.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Load the Swiss Ephemeris native module from pre-built binaries
3+
* Falls back to swisseph-v2 if prebuilds are not available
4+
*
5+
* @returns Swiss Ephemeris native module instance
6+
* @throws Error if no compatible native module can be loaded
7+
*/
8+
export declare function loadNativeBinary(): any;
9+
/**
10+
* Get information about the current platform
11+
* Useful for debugging deployment issues
12+
*/
13+
export declare function getPlatformInfo(): {
14+
platform: string;
15+
arch: string;
16+
key: string;
17+
isSupported: boolean;
18+
prebuildPaths: string[];
19+
};
20+
/**
21+
* Check if prebuilds are available for the current platform
22+
*/
23+
export declare function hasPrebuilds(): boolean;
24+
/**
25+
* Get the list of supported platforms
26+
*/
27+
export declare function getSupportedPlatforms(): readonly string[];
28+
//# sourceMappingURL=native-loader.d.ts.map

dist/native-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.

0 commit comments

Comments
 (0)