Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.2.4 createRequire to allow copy loader from esbuild to work in SEA #48

Merged
merged 7 commits into from
Oct 8, 2024

Conversation

jackyzha0
Copy link
Member

@jackyzha0 jackyzha0 commented Oct 8, 2024

The JS Bindings that NAPI-RS produces use raw require calls for local files.

With esbuild, this is normally fine as you can use the copy loader to just move the .node addon to the right place but SEAs dont allow requiring from the fs: nodejs.org/docs/latest-v20.x/api/single-executable-applications.html#requireid-in-the-injected-main-script-is-not-file-based

They recommend using createRequire instead

This change should allow native addons created by NAPI-RS to be used in SEAs

@jackyzha0 jackyzha0 changed the title [draft] test alternative require to allow copy loader from esbuild to work in SEA 3.2.4 createRequire to allow copy loader from esbuild to work in SEA Oct 8, 2024
Copy link
Member

@masad-frost masad-frost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to list ruspty as external to the esbuild bundle now?

@@ -6,6 +6,8 @@

const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
const { createRequire } = require('node:module')
require = createRequire(__filename)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not const require make it local?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 the node docs recommend it like this, i assume theres some static analysis things at work here

@jackyzha0
Copy link
Member Author

Do we have to list ruspty as external to the esbuild bundle now?

no it should still bundle ok

@jackyzha0 jackyzha0 merged commit 40b2568 into main Oct 8, 2024
4 checks passed
@jackyzha0 jackyzha0 deleted the jackyzha0/change-to-require branch October 8, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants