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

Install elm-json using elm-tooling #480

Merged
merged 12 commits into from
Jan 4, 2021
Merged

Conversation

lydell
Copy link
Collaborator

@lydell lydell commented Dec 18, 2020

This PR uses elm-tooling to install elm-json instead of the elm-json npm package.

Look at this size improvement:

Version Size
0.19.1-revision3 19 MB
0.19.1-revision4 18 MB
master 17 MB
This PR 2 MB

Size was measured by running du -sh node_modules after installing node-test-runner (and nothing else) on MacOS.

The elm-json binary itself around 2 MB on MacOS.

The huge space drop comes from not depending on binwrap anymore. It has some pretty have dependencies.

Benefits of using elm-tooling:

  • Faster installs. Fewer npm dependencies to install. elm-test users often use elm-test as well – once both use elm-tooling there won’t be a double elm-json download on each npm install. And if the user uses elm-tooling to install elm and elm-format as well, all three tools are downloaded in parallel. Similar PR for elm-review.
  • Less disk space wasted: Less dependencies in node_modules, and no copy of elm-json in every project.
  • Security. elm-tooling uses sha256 to verify that it downloads what it expects.

The only noticeable difference is when the elm-json executable is transferred from the Internet to the user’s machine.

  • Previously, it happened during npm install. Unless you use ignore-scripts – then it happened the first time elm-json was executed. Now, it happens right before elm-json is about to be executed. Unless the user already downloaded elm-json to ~/.elm/elm-tooling/ before.

  • Given that node-test-runner executes both elm and elm-json, which both can make network requests, I think it’s fine to also execute elm-tooling’s getExectuable function which also can make network requests. node-test-runner continues to work offline once all needed things exist on the user’s machine.

  • binwrap uses the request module, while elm-tooling uses curl if available, otherwise wget and finally Node.js’ https module. If the user used request’s environment variables for proxies, that should probably just work since curl seems to use the same environment variables. But there might be some little difference. Either way, both curl and wget also support config files that lets the user alter how they work as needed, which is a good thing.

  • Previously, the elm-json binary was downloaded to ./node_modules/elm-json/unpacked-bin/. Now it’s downloaded to ~/.elm/elm-tooling/elm-json/0.2.8/. Elm and elm-json write to ~/.elm too, so it should be fine. (elm-tooling supports ELM_HOME and Windows.)

The plan now is to:

  • Try to transfer elm-tooling to the @elm-tooling org so I don’t become a single point of failure.
  • Release elm-tooling 1.0.0. It works on Linux, macOS and Windows, has 100% test coverage, has been tested by a couple of people on Discord (Dillon Kearns even put it in his elm-pages-starter template) and I haven’t found any improvements to make in a month.
  • Merge this PR and the one for elm-review.
  • Announce elm-tooling in Slack and Discourse. So far I haven’t talked much about it, waiting for these two PRs to be made.

@harrysarson harrysarson added the status: waiting for review Pull request needs a review label Dec 20, 2020
@harrysarson harrysarson self-assigned this Dec 20, 2020
@harrysarson
Copy link
Collaborator

I might not get to my laptop to look at this before Christmas so bare with me. I have already gone from skeptical to keen though so nice work 👍

@lydell
Copy link
Collaborator Author

lydell commented Dec 20, 2020

No worries! No rush to do anything before Christmas. Or this year. We’ll get back to it in 2021! 🎅

Copy link
Collaborator

@harrysarson harrysarson left a comment

Choose a reason for hiding this comment

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

Looks good, raised a couple of points for discussion:

.github/workflows/test.yml Show resolved Hide resolved
.github/workflows/test.yml Show resolved Hide resolved
lib/RunTests.js Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
lib/elm-test.js Show resolved Hide resolved
lib/Solve.js Outdated Show resolved Hide resolved
lib/RunTests.js Outdated Show resolved Hide resolved
@harrysarson harrysarson added status: waiting for author Review comments need addressing. and removed status: waiting for review Pull request needs a review labels Jan 2, 2021
@harrysarson harrysarson added status: waiting for review Pull request needs a review and removed status: waiting for author Review comments need addressing. labels Jan 3, 2021
@harrysarson harrysarson added status: waiting for author Review comments need addressing. and removed status: waiting for review Pull request needs a review labels Jan 4, 2021
@harrysarson harrysarson merged commit 84a504a into rtfeldman:master Jan 4, 2021
@lydell lydell deleted the elm-tooling branch January 4, 2021 21:30
harrysarson pushed a commit that referenced this pull request Jan 22, 2021
Before:

```
❯ ../bin/elm-test
-- UNFINISHED DEFINITION - /Users/lydell/forks/node-test-runner/example-application/tests/TestsPassing.elm

I got stuck while parsing the `x` definition:

3| x
    ^
I was expecting to see an argument or an equals sign next.

Here is a valid definition (with a type annotation) for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!

Compiling >
`elm make` failed with exit code 1.
```

After:

```
❯ ../bin/elm-test
-- UNFINISHED DEFINITION - /Users/lydell/forks/node-test-runner/example-application/tests/TestsPassing.elm

I got stuck while parsing the `x` definition:

3| x
    ^
I was expecting to see an argument or an equals sign next.

Here is a valid definition (with a type annotation) for reference:

    greet : String -> String
    greet name =
      "Hello " ++ name ++ "!"

The top line (called a "type annotation") is optional. You can leave it off if
you want. As you get more comfortable with Elm and as your project grows, it
becomes more and more valuable to add them though! They work great as
compiler-verified documentation, and they often improve error messages!


`elm make` failed with exit code 1.
```

Notice the `Compile >` line near the bottom in the “Before” output. That’s not supposed to be there.

I fixed this by reverting the change here: #480 (comment)

This is pretty tricky. I’ll try to explain.

So we print this `Thing > Other thing > Last thing` progress line, where each segment appears over time. For this reason, the terminal cursor never moves to the next line, so we can overwrite the line over and over. Once done, we move to the next line so the test output can print below the (finished) progress line.

But what happens if there’s an error? We don’t want to end up with something like:

```
Thing > Other thingError: Can’t do this and that for:
more lines of error
Maybe try this and that?
```

So we want to move to the next line when printing an error as well. `progressLogger.logLine('')` worked for this case most of the time: It would reprint `Thing > Other` (which technically was unnecessary but couldn’t be seen) and then moved to the new line. Another thing I noticed while writing this: The empty string would actually result in `This > Other > ` (an unwanted trailing `>` separator).

But the thing is that we can’t actually know that the cursor is still on the cursor line. Why? Because `elm make` might have printed to stderr (in case of compilation errors in the user’s code). We don’t know if it has either – we can’t capture its stderr because then we would lose colors.

So a solution that works in both cases is to _not_ reprint the progress line and instead only move to the next line. (That results in an extra blank line for the compiler errors but I don’t think it matters.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Review comments need addressing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants