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

WIP Renamed node-bindings and added a dedicated entry point for wasm #9768

Closed
wants to merge 4 commits into from

Conversation

alshdavid
Copy link
Contributor

↪️ Pull Request

  • Moved node-bindings to parcel_napi
    • Put existing code under src/parcel_v2
    • Will remove parcel_v2 or migrate code into new context as we progress
  • Created parcel_wasm package to be an entry point for wasm consumers
  • Moved wasm code from node-bindings into parcel_wasm

💻 Examples

🚨 Test instructions

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@alshdavid alshdavid force-pushed the alsh/add-plugin-crates branch 2 times, most recently from 6b9a47c to 0d32a6e Compare June 4, 2024 08:56
@alshdavid alshdavid force-pushed the alsh/dedicated-wasm-entry branch 2 times, most recently from c33bae7 to b0b01b5 Compare June 4, 2024 09:00
build.rs for napi

build.rs for napi

build.rs for napi

dylib

Reverted changes to napi package

Update napi

wasm build
@devongovett
Copy link
Member

Why? Isn't parcel_wasm mostly a duplicate of the napi bindings? There's only a few differences that were covered by conditional compilation before.

}

// We don't currently call functions from multiple threads, but we'll need to change this when we do.
unsafe impl Send for FunctionRef {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need this if you don't call it from multiple threads?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'm just moving existing code and not making changes to the sources

#[napi(constructor)]
pub fn new(project_root: String, options: JsResolverOptions, env: Env) -> Result<Self> {
let fs = {
let fsjs = options.fs.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

you can just fail here ; options.fs.unwrap_or(Err...)?


use crate::function_ref::FunctionRef;

pub struct FileSystemWasm {
Copy link
Contributor

Choose a reason for hiding this comment

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

let mut res = self.resolver.resolve_with_options(
&options.filename,
Path::new(&options.parent),
match options.specifier_type.as_ref() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, assign these to variables so that we have names

))
}
},
if let Some(conditions) = options.package_conditions {
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

mode: u8,
resolver: parcel_resolver::Resolver<'static, FileSystemWasm>,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

you could break up a lot of these functions

Copy link
Contributor

@yamadapc yamadapc left a comment

Choose a reason for hiding this comment

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

I don't understand why we're duplicating all this code

Base automatically changed from alsh/add-plugin-crates to v2 June 5, 2024 04:24
@alshdavid alshdavid changed the title Renamed node-bindings and added a dedicated entry point for wasm WIP Renamed node-bindings and added a dedicated entry point for wasm Jun 5, 2024
@alshdavid
Copy link
Contributor Author

alshdavid commented Jun 5, 2024

Why? Isn't parcel_wasm mostly a duplicate of the napi bindings? There's only a few differences that were covered by conditional compilation before.

I'm thinking of abstracting those peices out on their own and share them between parcel_nodejs and parcel_wasm (which function as entry points for those targets).

For instance, the Resolver implementation can be moved into parcel_plugin_resolver/napi_bindings/parcel-v2 and gated via crate features wasm or nodejs.

This would avoid duplication, allowing the Resolver code to remain largely unchanged whist splitting the wasm and nodejs entrypoints up.

In the end state the binding layer will be significantly lighter so this will be replaced

@devongovett
Copy link
Member

But why do we even need separate entry points for them in the first place if they are both using napi?

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.

None yet

3 participants