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

feat: create methods to manage runtimes #74

Merged
merged 4 commits into from
Jan 26, 2023
Merged

Conversation

Angelmmiguel
Copy link
Contributor

This PR includes several refactors and new features to manage language runtimes. In general, this PR prepares the code for the complete feature. The main changes applied to this PR are:

  • Create a new set of utilities for fetching data. It uses reqwest in async mode. For the validation side, it receives a Checksum instance to validate against the content.
  • Refactor the Data struct that was used for language runtimes to install transient files in a .wws directory. Now, we also need to download and store runtime files such as wasm modules, polyfills and templates. For this reason, I moved the .wws folder management into a global Store struct. I also fixed the routes to work on Windows too.
  • Create a "manager" set of utilities to initialize runtimes, install and download associated files. It uses the aforementioned Store struct to create the files in the correct location.
  • Merge all repository / runtime metadata structs into a common runtimes/metadata.rs file. This way is less confusing to understand the scope of those structs.
  • Unfortunately, I run into lifetimes issues with Serde and the Repository -> Runtime -> RemoteFile struct. In the end, I opted for making all owned types and revisit it in the future 😞
  • Add a filename field to the RemoteFile struct.

Usage experience

println!("🗺  Fetching index!");
let repo = Repository::from_remote_file(
    "https://raw.githubusercontent.com/Angelmmiguel/wws-index-test/main/index.toml",
).await.unwrap();

let runtime = repo.runtimes.first().unwrap()

println!("🗺  Installing  runtime...");
println!("{}", runtime);
install_runtime("wlr", runtime).await.unwrap();

And then, you can inspect the .wws folder:

~/W/o/wws ❯❯❯ tree .wws
.wws
├── runtimes
│   ├── rust
│   └── wlr
│       └── ruby
│           └── 3.2.0+20230118-8aec06d
│               ├── poly.rb
│               ├── ruby.wasm
│               └── template.txt
└── workers
    └── js
        └── 961b7b706f36e745dc7c3306a2a41214ddac3ad41a38fa8da6a2460058235420
            └── index.js

It closes #66

@Angelmmiguel Angelmmiguel added this to the v1.0.0 milestone Jan 25, 2023
@Angelmmiguel Angelmmiguel requested a review from a team January 25, 2023 12:52
@Angelmmiguel Angelmmiguel self-assigned this Jan 25, 2023
@Angelmmiguel
Copy link
Contributor Author

Added a new commit to prepare the metadata to be serialized. This required to update TOML to v0.6.0 to avoid an issue regarding serialization of values and tables (see toml-rs/toml-rs#142).

On this version, toml removed the support for from_slice, so I had to use the from_str method instead (see v0.6.0 changelog).

The reason why I'm adding it here is to prepare the metadata to be serialized on #67

@Angelmmiguel
Copy link
Contributor Author

Added a new commit to fix the location of the .wws folder. It was using the current path instead of the project path. For example, if we run the following command:

wws ./examples/js-basic

Before this commit, the .wws would be located in ./.wws. However, the correct path for this folder is the project one: ./examples/js-basic/.wws. The last commit fixes that behavior.

Copy link
Contributor

@ereslibre ereslibre left a comment

Choose a reason for hiding this comment

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

LGTM, minor comments

src/config.rs Outdated Show resolved Hide resolved
src/runtimes/metadata.rs Outdated Show resolved Hide resolved
@Angelmmiguel Angelmmiguel merged commit c1b1408 into main Jan 26, 2023
@Angelmmiguel Angelmmiguel deleted the 66-runtime-manager branch May 8, 2023 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a struct to manage runtime metadata files
3 participants