Skip to content

Commit

Permalink
Use elm-solve-deps-wasm instead of elm-json solve (#558)
Browse files Browse the repository at this point in the history
Use a custom dependency solver library instead of the elm-json binary.

This PR introduces a custom dependency solver, extracted from the solver in elm-test-rs, improving the compatibility with other elm-based platforms such as Lamdera.

The core algorithmic part of the solver, called "pubgrub", is rooted in the same logic than used in elm-json but implemented differently in the rust package `pubgrub-rs`.
That core algorithmic logic has been ported into a WebAssembly package called `elm-solve-deps-wasm` dedicated to the constraints of the elm package ecosystem and providing the following `solve_deps` wasm function where the two functions passed as arguments `js_fetch_elm_json` and `js_list_available_versions` are two functions injected via the JS call.

```rust
pub fn solve_deps(
    project_elm_json_str: &str,
    use_test: bool,
    // additional_constraints_str: &HashMap<String, Constraint>,
    additional_constraints_str: JsValue,
    // js_fetch_elm_json(pkg: &str, version: &str) -> String;
    js_fetch_elm_json: js_sys::Function,
    // js_list_available_versions(pkg: &str) -> Vec<String>;
    js_list_available_versions: js_sys::Function,
) -> Result<JsValue, JsValue> {
```

In this PR, the JS overlay implementing those two `js_fetch_elm_json` and `js_list_available_versions` is taken care of in the form of a `DependencyProvider` class providing two functions `solveOffline` and `solveOnline`. In the case of the offline solver, listing of existing versions and discovery of dependencies is exclusively performed from the packages installed inside the elm home. In the case of the online solver, some information may be retrieved from the package server.

```js
// same interface for solveOnline
solveOffline( 
  elmJson /*: string */,
  useTest /*: boolean */,
  extra /*: { [string]: string } */
) /*: string */ { ... }
```

Remark: since requests for the online solver need to perform http requests in a synchronous manner, an approach based on a web worker thread is used, requiring a minimum node version of 12.20.0.
  • Loading branch information
mpizenberg authored Apr 6, 2022
1 parent c609f0b commit fd52f04
Show file tree
Hide file tree
Showing 11 changed files with 862 additions and 753 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"extends": "eslint:recommended",
"env": {
"es6": true,
"es2017": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2022
},
"rules": {
"no-inner-declarations": "off",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [12.x, 14.x, 16.x, 17.x]
node-version: [12.20.0, 12.x, 14.x, 16.x, 17.x]

env:
ELM_HOME: '${{ github.workspace }}/elm-stuff/elm-home'
Expand Down
Loading

0 comments on commit fd52f04

Please sign in to comment.