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

refactor(tauri): support for building without environmental variables #850

Merged
merged 69 commits into from
Feb 9, 2021

Conversation

chippers
Copy link
Member

@chippers chippers commented Jul 18, 2020

Both embedded-server and no-server fully work. Heres a checklist ill keep updated i guess:

  • Compressed embedded assets (brotli gzip)
  • no-server
  • embedded-server
  • Pass test suite
  • Create additional tests for changed/new code (not really sure what to add for config testing)
  • TAURI_INLINED_ASSETS support
  • TAURI_CONFIG support
  • Refactor AppConfig -> AppContext to prevent repetition. (i.e. &application.config.config -> &application.ctx.config)
  • handle public paths as in webpack instead of iteratively removing parents from assets

This is the replacement for #830. That PR was more about seeing if it was possible, this PR is about actually removing core environmental build variables from tauri.

This branch/pull request should be tracking changes from dev to prevent having a massive conflict at the end. This touches a few "core" files like runner.rs and has some tentacles in otherwise not related code due to moving tauri-api::config into tauri-config so conflicts are definitely going to happen.

As of the first commit, it can build a no-server application that has been run with tauri dev or tauri build to generate the index.tauri.html.
image

As a high level overview of additional changes planned in this branch:

  1. All tests need to be updated
  2. Support for embedded-server. (and every existing way of using tauri)
  3. Handle additional env vars like TAURI_CONFIG and TAURI_INLINED_ASSETS which are currently ignored

See comments on #830 for a more specific overview if needed

* only no-sever has been tried
* test suite has not been updated to pass tests
* TAURI_CONFIG and TAURI_INLINED_ASSETS currently does nothing
Idk why I thought it would have created a circular dependency.
I must have experimented with something a bit different.

Signed-off-by: Chip Reed <chip@chip.sh>
Because asset embedding had to be slightly reworked, I moved the
equivalent of `tauri_includedir_codegen` into the proc-macro.  I also
embedded the `tauri_includedir` equivalent into `tauri-api/src/assets.rs`.
I felt since the codegen was removed, the other didn't make sense as separate
either.

Signed-off-by: Chip Reed <chip@chip.sh>
@chippers
Copy link
Member Author

the last commit added support for embedded-server,
image

Because of some necessary changes to codegen, I lifted the code from the tauri_includedir_codegen repo into tauri-macros/src/include_dir.rs along with the rework. Since the frontend to that dependency also didn't make much sense, I moved tauri_includedir::Files into tauri-api/src/assets.rs as Assets. This commit doesn't add support for gzip since it was not used anyways. It keeps the structure support for it however, and just needs to be actually implemented in the match in include_dir.rs. I left a few TODO comments that should be handled by the time this PR would be ready

Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
config read helper was too general to be useful both inside the proc
macro and outside of it. better off without it, since it was added
during this feature

Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
@chippers
Copy link
Member Author

Off the top of my head, some todos:

  • replacement for the get() testing in tauri-api/src/config.rs
  • finish gzip support in tauri-macros/src/include_dir.rs
  • support TAURI_CONFIG environmental variable to override any actual config with the content sent in that env var
  • make sure TAURI_INLINED_ASSETS actually works, since the code was ported
  • probably add some tests around the AppConfig and some more tests wherever the config or environmental variable was previously used

phf is now imported and used from `tauri-api`

Signed-off-by: Chip Reed <chip@chip.sh>
@chippers
Copy link
Member Author

I've left the bundler and cli completely untouched, only touching tauri, tauri-api, and (new) tauri-macros. There's still a few places env vars are used in the latter, such as endpoint assets handling and runner splashscreens.

note for myself:

let env_var = envmnt::get_or("TAURI_DIR", "../dist");

Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
they are hard to see errors in when they are disabled on windows,
but you are developing on windows

Signed-off-by: Chip Reed <chip@chip.sh>
Signed-off-by: Chip Reed <chip@chip.sh>
this slipped through the cracks because CI doesn't enable the cli
feature.

Signed-off-by: Chip Reed <chip@chip.sh>
@lucasfernog
Copy link
Member

We should wait for WRY to land on dev before fixing the conflict issues here.

@lucasfernog lucasfernog marked this pull request as ready for review February 8, 2021 16:31
@lucasfernog
Copy link
Member

We'll need to archive tauri-includedir since this change kills it :P

@lucasfernog lucasfernog changed the title experimental support for building without environmental variables refactor(tauri): support for building without environmental variables Feb 9, 2021
Copy link
Sponsor Member

@nothingismagick nothingismagick left a comment

Choose a reason for hiding this comment

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

This is flipping awesome, but please don't change the TS style and watch out for overly expressive changelog stuff.

.changes/config-refactor.md Outdated Show resolved Hide resolved
api/src/fs.ts Outdated Show resolved Hide resolved
@lucasfernog
Copy link
Member

My bad 😂

@lucasfernog lucasfernog merged commit e02c941 into dev Feb 9, 2021
@lucasfernog lucasfernog deleted the feat/no_build_env branch February 9, 2021 18:22
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