feat: make library self-contained with pre-built binaries for Vercel#7
Conversation
- 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
Summary of ChangesHello @astro-fusion, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the library's deployability and ease of use, particularly for serverless platforms like Vercel. By embedding pre-built native binaries and implementing a robust native module loading mechanism, it removes the common hurdle of native compilation during deployment. This change makes the library more self-contained and developer-friendly, ensuring a smoother experience across various operating systems and deployment targets. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a significant improvement, making the library self-contained and Vercel-friendly by including pre-built native binaries. The new native loader is well-designed with a robust fallback mechanism, and the documentation updates are clear and helpful for users deploying on serverless platforms. I've provided a few suggestions to improve the build script's debuggability, clarify a troubleshooting step in the README, and refactor a minor redundancy in the path resolution logic. Overall, this is an excellent update that greatly enhances the library's usability.
| 2. **Vercel deployment fails with "Cannot find module swisseph.node"** | ||
| - Upgrade to `@af/sweph@0.2.0` or later | ||
| - Clear Vercel build cache and redeploy | ||
| - Verify prebuilds/linux-x64/swisseph.node exists in node_modules |
There was a problem hiding this comment.
To make troubleshooting easier for users, it would be helpful to provide the full, unambiguous path to the binary within the node_modules directory.
| - Verify prebuilds/linux-x64/swisseph.node exists in node_modules | |
| - Verify `node_modules/@af/sweph/prebuilds/linux-x64/swisseph.node` exists. |
| apt-get install -y -qq python3 make g++ > /dev/null 2>&1 && \ | ||
| echo '🔧 Building native module...' && \ | ||
| npm install --ignore-scripts > /dev/null 2>&1 && \ |
There was a problem hiding this comment.
Redirecting the output of apt-get and npm install to /dev/null can hide important warnings or errors, making it difficult to debug build failures inside the Docker container. It's better to allow this output to be displayed for better visibility into the build process.
| apt-get install -y -qq python3 make g++ > /dev/null 2>&1 && \ | |
| echo '🔧 Building native module...' && \ | |
| npm install --ignore-scripts > /dev/null 2>&1 && \ | |
| apt-get install -y -qq python3 make g++ && \ | |
| echo '🔧 Building native module...' && \ | |
| npm install --ignore-scripts && \ |
| // Standard prebuild location (when running from dist/) | ||
| paths.push(path.join(__dirname, '..', 'prebuilds', platformKey, 'swisseph.node')); | ||
|
|
||
| // When running from src/ during development | ||
| paths.push(path.resolve(__dirname, '..', 'prebuilds', platformKey, 'swisseph.node')); |
There was a problem hiding this comment.
The first two paths in getPrebuildPaths are redundant, as both path.join(__dirname, '..', ...) and path.resolve(__dirname, '..', ...) will point to the same location. You can simplify this by keeping only the path.resolve version, which is slightly more robust, and updating the comment.
| // Standard prebuild location (when running from dist/) | |
| paths.push(path.join(__dirname, '..', 'prebuilds', platformKey, 'swisseph.node')); | |
| // When running from src/ during development | |
| paths.push(path.resolve(__dirname, '..', 'prebuilds', platformKey, 'swisseph.node')); | |
| // This path resolves correctly whether running from `dist/` or `src/` | |
| paths.push(path.resolve(__dirname, '..', 'prebuilds', platformKey, 'swisseph.node')); |
- Update pnpm-lock.yaml to match package.json (fixes CI) - Scripts: Improve build-linux-prebuild.sh debuggability (logging) - Loader: Simplify path resolution in native-loader.ts - Docs: Clarify Vercel troubleshooting path in README.md
This update enables Vercel deployment without native compilation. Closes: native module loading issues on serverless platforms