Skip to content

Yew CLI development PR#1419

Closed
philip-peterson wants to merge 89 commits into
yewstack:masterfrom
cramt:yew-cli
Closed

Yew CLI development PR#1419
philip-peterson wants to merge 89 commits into
yewstack:masterfrom
cramt:yew-cli

Conversation

@philip-peterson
Copy link
Copy Markdown
Contributor

Description

This is a PR for tracking the development of Yew CLI

@philip-peterson philip-peterson marked this pull request as draft July 19, 2020 02:32
Comment thread cli/.idea/misc.xml Outdated
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think editor setup shouldn't be commited to the repo. Would you mind adding this to the .gitignore?

Comment thread cli/Cargo.toml Outdated
rayon = "1.3.1"
lazy_static = "1.4.0"
log = "0.4.11"
clap = "2.33.1" No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think these can be a little less specific (I know IntelliJ tends to fill in with the most specific possible) because of how semantic versioning works. e.g.

Suggested change
clap = "2.33.1"
clap = "2.33"

Comment thread cli/src/main.rs Outdated

use log::{error, info, warn};

// Usages:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These would be better as doc comments attached to the main function.

/// content ...
fn main() { ... }

Comment thread cli/src/main.rs Outdated
.about("compiles a Yew application")
.arg(
Arg::with_name("run")
.help("Start a webserver for the built project and open it in a browser window")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
.help("Start a webserver for the built project and open it in a browser window")
.help("Start a web server for the built project and open it in a browser window")

Comment thread cli/src/main.rs Outdated
.short("r")
)
.arg(
Arg::with_name("release")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this could be better handled by taking everything after -- and passing it to cargo (like how cargo allows you to pass arguments to rustc, e.g. cargo test -- --nocapture where --nocapture is passed to rustc).

@philip-peterson
Copy link
Copy Markdown
Contributor Author

@teymour-aldridge All valid comments. It should be noted though, this is a draft PR and still very WIP so we probably won’t really be ready for a review for a number of iterations. :-)

@teymour-aldridge
Copy link
Copy Markdown
Contributor

@philip-peterson I realise that :P – I'm just making one or two suggestions here for future development before the work is done rather than afterwards (to minimise wasted effort).
Give me a shout if there's anything you'd like any help on (I'll do my best to try and assist!)

@philip-peterson
Copy link
Copy Markdown
Contributor Author

Fair enough! It is helpful feedback to have, will give another shout when things are farther along. Thanks for the initial feedback 🙏

@siku2 siku2 linked an issue Jul 19, 2020 that may be closed by this pull request
@siku2
Copy link
Copy Markdown
Member

siku2 commented Aug 24, 2020

How far along are we with this? I'm seeing some rather surprising things in here like yew-config. Looks promising, but what's the goal there?

Now that we have #1504 for the internal maintenance tasks we no longer need this to take care of them.
I think that's a good thing because this has shaped more into a tool for developers than maintainers and having it be both at the same time comes at a cost for both parties.

The CLI stands completely on its own now so I would like to give it its own repository in the yewstack organisation.
The reason for this is that the CLI isn't directly coupled with the library and should probably have an independent release cycle. It also allows it to make better use of various GitHub features which could get quite messy if it was part of the monorepo.

What do you think, @jstarry?

@philip-peterson
Copy link
Copy Markdown
Contributor Author

The goal of yew-config was to solve the following problem: we want users to be able to run all the examples at once, and that means compiling them and starting a web server for each. However we can’t specify whether each example is wasm-bindgen or wasm-pack on a per-example basis, as that would require a flag for each example, negating the convenience of starting all examples at one time. (We can currently only specify the build scheme for all projects across the board, however, some examples use wasm-pack and others don’t.) Because of this, we really wanted a per-project config standard so that each project could specify whether it wants wasm-pack or not, as well as maybe some settings like route structures for SSG/SSR down the line.

Yew-config allows the user to specify a configuration on each project, using normal Rust typing mechanisms instead of ad-hoc unspecified dynamic config files a la Webpack. The configs will be read by the yew-cli tool before starting up the web servers for the examples. I do think it’s a tad unrelated and can be merged as its own PR first, but it’s still a requirement for that feature of yew-cli.

@siku2
Copy link
Copy Markdown
Member

siku2 commented Aug 25, 2020

I love that it's possible to run all examples at once but I don't think that's something we were really missing :)

I also really like the idea of having a config for Yew projects but to be brutally honest I don't like the idea of having the configuration in the actual Rust code which even adds an additional dependency to the project. I'm willing to change my mind on this if you can point me to a project that uses this approach successfully but right now I'm very much in favour of a simple yew.toml file.

Why are we distinguishing between wasm-bindgen and wasm-pack? wasm-pack build is just a shortcut for cargo build -> wasm-bindgen -> wasm-opt (the main benefit being that it can automatically download these things).
There's no need to switch between the two because they are basically the same thing.

I think yew-cli should behave like a fork of wasm-pack but geared towards applications instead of libraries. Most of the functionality we need is already in wasm-pack, we just need to add things like the dev server.

@philip-peterson
Copy link
Copy Markdown
Contributor Author

philip-peterson commented Aug 26, 2020

Wasm-pack requires that there be a function annotation #[wasm_bindgen(start)] on some function and might also require a wasm-bindgen dependency in Cargo -- see the differences between examples/minimal and examples/minimal_wp. It would be nice if we could eliminate one of the schemes.

As for yew-config, that's pretty disappointing to hear .. I would prefer not to be the person to introduce yet another untyped, schema-less config to the web development ecosystem. Would sooner vote to just remove the ability to run all examples at once. I really think we'll need yew-config at some point soon, especially if we want to run the yew-router examples which each have their own independent lists of routes that correspond to the index.html. We can kick the can down the road for now by not including it but I expect it will come up eventually.

@siku2
Copy link
Copy Markdown
Member

siku2 commented Aug 26, 2020

Wasm-pack requires that there be a function annotation #[wasm_bindgen(start)] on some function and might also require a wasm-bindgen dependency in Cargo -- see the differences between examples/minimal and examples/minimal_wp.

There are a few differences I didn't mention because they are mostly surface-level and only exist because wasm-pack is designed for libraries.
wasm-pack doesn't technically need a function with the #[wasm_bindgen(start)] annotation, it just doesn't generate an entry point because it uses cargo build --lib to generate the WASM binary (it also requires the crate to be cdylib for this reason).
If wasm-pack ran cargo build instead, these differences would disappear.
Anyway, all I was trying to say is that they fundamentally do the same thing only that wasm-pack operates at a higher level and is designed for libraries which isn't what we need for Yew apps.


It would be nice if we could eliminate one of the schemes.

Yes, I absolutely agree. wasm-pack was never really meant to be used for Yew projects but it's flexible enough to make it work.
I believe we should only use wasm-bindgen in the end.
wasm-pack already has a lot of the functionality we want (automatic downloads, wasm-opt, testing) which is why I'm suggesting we basically copy it but rip out all the parts that apply to libraries and make it work for applications.

@philip-peterson
Copy link
Copy Markdown
Contributor Author

I'm a bit skeptical of that plan, wouldn't it be better to have wasm-pack own support for this? wasm-pack looks like a pretty large surface area to maintain, and I'm not really sure what we would gain from forking it.

@siku2
Copy link
Copy Markdown
Member

siku2 commented Aug 27, 2020

I'm a bit skeptical of that plan, wouldn't it be better to have wasm-pack own support for this?

That would make some sense, but I doubt the maintainers of wasm-pack want to add this functionality. My understanding of wasm-pack's scope is that it's meant to integrate Rust into the Javascript ecosystem and everything it does is to accommodate that goal.
In order for wasm-pack to really work for us it would need things like a wasm-pack start command and the option to build binary targets instead of libraries. Both of those don't really make sense for a tool designed to publish Rust WASM libraries to NPM.

wasm-pack looks like a pretty large surface area to maintain, and I'm not really sure what we would gain from forking it.

Well, what's the alternative then? If we use wasm-bindgen-cli directly we'll just end up re-implementing a lot of things we could've taken from wasm-pack.
I agree that wasm-pack isn't exactly tiny but it has a lot of features I wouldn't want to miss out on.

@philip-peterson
Copy link
Copy Markdown
Contributor Author

philip-peterson commented Aug 27, 2020

They would probably rather support the feature than have us fork their library and split the ecosystem. We should at least ask IMO. But, also I would posit that we don’t exactly need to have this — we already invoke wasm-pack with success, it’s just not ideal because of the annotation and cargo dependency. MVP for yew-cli at least doesn’t require a wasm-pack fork for now.

@siku2
Copy link
Copy Markdown
Member

siku2 commented Aug 27, 2020

I wouldn't really call it "splitting the ecosystem" if the tools serve two distinct purposes but I admit that it doesn't hurt to ask first.

MVP for yew-cli at least doesn’t require a wasm-pack fork for now.

Just to make this clear: I'm not advocating for creating a fork of wasm-pack to be used by yew-cli. I'm saying yew-cli should be the fork of wasm-pack.

Anyway, I think it's fine to have yew-cli call out to wasm-pack for the test command for now but I would rather we didn't use it for the build command because then we'd either have to drop support for raw wasm-bindgen or have it conform to the standards set by wasm-pack otherwise we would end up splitting the ecosystem.

@philip-peterson
Copy link
Copy Markdown
Contributor Author

I’m confused. Why would supporting wasm-pack require dropping support for wasm-bindgen? We already support both.

@jstarry
Copy link
Copy Markdown
Member

jstarry commented Sep 20, 2020

I’m confused. Why would supporting wasm-pack require dropping support for wasm-bindgen? > We already support both.

@philip-peterson Because examples that are setup as binaries (rather than libraries) and use wasm-bindgen cannot be built with wasm-pack build because it only builds libraries.

Personally, I think that trunk is the way forward here. Of course there could be room for an alternative tool to trunk and it could even be called yew-cli if it's intended to be Yew specific.

I do agree with @siku2 that this PR is not the right place for that exploration. I would prefer if this was moved to a separate non-yewstack repo (like many other yew libraries) and developed independently. In the future, I expect some of the independent libraries will become first class members of the yew monorepo. The best the Yew maintainers can do is help the community discover and collaborate on these libraries while they are still in their infancy.

I'm going to close this PR due to this being the wrong place for this type of exploration. Please feel free to open a PR that would add links to a new yew-cli repo and we can add channels in the Yew Discord if needed

@jstarry jstarry closed this Sep 20, 2020
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.

5 participants