Skip to content

Use CommonJS JSON loader#4

Merged
hazzuk merged 1 commit intomainfrom
json-loader-patch
Apr 9, 2025
Merged

Use CommonJS JSON loader#4
hazzuk merged 1 commit intomainfrom
json-loader-patch

Conversation

@hazzuk
Copy link
Copy Markdown
Member

@hazzuk hazzuk commented Apr 9, 2025

OpenAsar#111

  • helps include the project in the asar bundle

- Node natively supports loading JSON via `require()` since 2011, which is a cleaner and easier way to load JSON:

https://nodejs.org/en/blog/release/v0.5.2

- Node's `require()` safely performs regular JSON decode whenever it detects a ".json" file extension, which is what our "detectable.json" filename is using.

- The `createRequire()` API is only necessary because arRPC is not a CommonJS project. Using `createRequire()` is a completely normal, supported interoperability feature of Node, and is documented here:

https://nodejs.org/api/module.html#modulecreaterequirefilename

- This change was done to help downstream projects based on CommonJS or ASAR bundles. Without this change, arRPC will not work in certain downstream apps (depending on their bundling methods).
@hazzuk hazzuk added the arrpc pr Unmerged pull request from arrpc label Apr 9, 2025
@hazzuk hazzuk merged commit d55c8d5 into main Apr 9, 2025
@hazzuk hazzuk deleted the json-loader-patch branch April 9, 2025 10:31
hazzuk added a commit that referenced this pull request Apr 10, 2025
This reimplements the original arRPC PR 133 from pendo324. But with changes from 109 (#3), 111 (#4) and 123 (#5) also included.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrpc pr Unmerged pull request from arrpc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants