-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
index: use Node's CommonJS JSON loader #111
base: main
Are you sure you want to change the base?
Conversation
This is ready to merge. Everything works exactly as before. The It's a much cleaner way to load JSON, by relying on Node's native support for it. Especially if we change the project to |
This is just a change to change? I don't see any benefit since the project will never move to commonjs. |
It's a change to help downstream apps that integrate arRPC, so that they don't need to patch that command when they include arRPC in ASAR bundles or something like that. The With the change to use https://github.com/Vencord/Vesktop/blob/main/patches/arrpc%403.4.0.patch And the way that I'm including |
8ccb660
to
8020500
Compare
@CanadaHonk Hi Oliver, I noticed that you're very busy with other projects. However, since this is such a small fix, I'm wondering if we can move ahead with this so that I can then alert the downstream project that they don't need to patch arRPC any longer. :) |
as i pretty much not like node to run in background, i have an idea to run it with bun. ive tried it just work normally. |
@hUwUtao @CanadaHonk Yes, exactly. We need to merge this otherwise arRPC doesn't work when bundled (such as inside ASAR packages). The old code assumes that arRPC is always extracted as regular files on disk. This is not how most apps operate. They bundle things into 1 archive. |
- 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).
8020500
to
ea8e116
Compare
@CanadaHonk Thanks again for discovering the caching issue with |
no, bundling will eventually mess up the dynamic trait of |
@hUwUtao Unfortunately your comment is nonsense. Bundling is not supposed to dynamically update There is no mechanism for dynamically loading Furthermore, arrpc was designed to never dynamically update Now, if there is a scenario where you might NOT be bundling arrpc inside your ASAR and you want to reload a newer |
to "ship" and to "bundle" is 2 different level. i can see that the way we do is pretty orient on embed the whole thing. as for statically bundle it, there is no reason to depend on node require call, as bundler will eventually treat json as js and no parse done, if all was just for stuffing a json in asar package, well smh |
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. UsingcreateRequire()
is a completely normal, supported interoperability feature of Node, and is documented here:https://nodejs.org/api/module.html#modulecreaterequirefilename