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

Split core functionality from CLI #14

Merged
merged 13 commits into from Jun 8, 2018

Conversation

Projects
None yet
2 participants
@kachkaev
Contributor

kachkaev commented Apr 28, 2018

👋

I recently needed to use run-elm via require() rather than by spawning a sub-process and came up with a refactoring that involved splitting core functionality from CLI. At the moment this change is included into a fork called @kachkaev/run-elm, but I hope to deprecate that package once we update run-elm.

I have marked this PR as work-in-progress because it includes commits from #13, has some fork-specific commits and also lacks usage instructions for require() in README. The tests have been done though, all works!

One thing that bugs me is that I'm using compileSync instead of compile (they both replace compileToString and save one cycle of file write/read). The reason is in rtfeldman/node-elm-compiler#68 (async version calls process.exit() on error, so it can't be used when we require('run-elm')).

WDYT @jfairbank? I'm happy to rebase and refactor after merging #13 and getting your general approval.

@jfairbank

This comment has been minimized.

Show comment
Hide comment
@jfairbank

jfairbank May 8, 2018

Owner

This seems like a good change to make. I'll wait for you to rebase before I review. Thanks!

Owner

jfairbank commented May 8, 2018

This seems like a good change to make. I'll wait for you to rebase before I review. Thanks!

kachkaev added some commits Apr 26, 2018

@kachkaev

This comment has been minimized.

Show comment
Hide comment
@kachkaev

kachkaev May 8, 2018

Contributor

Despite that all tests pass, I'm still not sure this PR is worth merging as is. The issue that I see is that we're calling node-elm-compiler synchronously, because otherwise we'll get early exit due to rtfeldman/node-elm-compiler#68. Therefore, the main Node.js thread will get blocked and performance will suffer (this only applies when Node API is used). There is no regression in CLI use, just a non-optimality in the new execution mode.

What are your thoughts on this @jfairbank? How is the PR in general?

Contributor

kachkaev commented May 8, 2018

Despite that all tests pass, I'm still not sure this PR is worth merging as is. The issue that I see is that we're calling node-elm-compiler synchronously, because otherwise we'll get early exit due to rtfeldman/node-elm-compiler#68. Therefore, the main Node.js thread will get blocked and performance will suffer (this only applies when Node API is used). There is no regression in CLI use, just a non-optimality in the new execution mode.

What are your thoughts on this @jfairbank? How is the PR in general?

@kachkaev kachkaev changed the title from [WIP] Split core functionality from CLI to Split core functionality from CLI May 8, 2018

kachkaev added some commits May 8, 2018

@kachkaev

This comment has been minimized.

Show comment
Hide comment
@kachkaev

kachkaev May 14, 2018

Contributor

I also noticed today that Elm's Debug.log is being incorrectly reported in the API mode. Will add a fix to this soon, please don't merge.

Contributor

kachkaev commented May 14, 2018

I also noticed today that Elm's Debug.log is being incorrectly reported in the API mode. Will add a fix to this soon, please don't merge.

kachkaev added some commits May 14, 2018

@kachkaev

This comment has been minimized.

Show comment
Hide comment
@kachkaev

kachkaev May 15, 2018

Contributor

I also managed to fix a few things so that they work on Windows:
https://ci.appveyor.com/project/kachkaev/run-elm/build/27

Things to note:

  • stderr / stdout never contain \r (even when it's Windows) to make sure there are no unwanted parsing issues in the downstream projects. If someone asks for a nice-looking output for cmd, we can look into adding a CLI option for that.

  • I had to rename Aux.elm into Helper.elm in one of the tests, because you can't use AUX for file names on Windows 😱 This was giving a pretty strange exception.

@jfairbank feel free to integrate AppVeyor to the repo just as I did in my fork.

One last thing I'd like to look into is to make a call to elm compiler async despite rtfeldman/node-elm-compiler#68.

Contributor

kachkaev commented May 15, 2018

I also managed to fix a few things so that they work on Windows:
https://ci.appveyor.com/project/kachkaev/run-elm/build/27

Things to note:

  • stderr / stdout never contain \r (even when it's Windows) to make sure there are no unwanted parsing issues in the downstream projects. If someone asks for a nice-looking output for cmd, we can look into adding a CLI option for that.

  • I had to rename Aux.elm into Helper.elm in one of the tests, because you can't use AUX for file names on Windows 😱 This was giving a pretty strange exception.

@jfairbank feel free to integrate AppVeyor to the repo just as I did in my fork.

One last thing I'd like to look into is to make a call to elm compiler async despite rtfeldman/node-elm-compiler#68.

},
"scripts": {
"test:clean": "cd test/integration && git clean -d -f -X",
"clean:test": "git clean -d -f -X test/integration",

This comment has been minimized.

@kachkaev

kachkaev May 15, 2018

Contributor

&& are not allowed in npm scripts on Windows; also renamed test:clean into clean:test for a better clarity

@kachkaev

kachkaev May 15, 2018

Contributor

&& are not allowed in npm scripts on Windows; also renamed test:clean into clean:test for a better clarity

"lint": "eslint src test --ignore-pattern elm-stuff",
"prebuild": "rimraf lib",
"build": "babel src --out-dir lib",
"postbuild": "cpx \"src/*.elm.template\" lib",

This comment has been minimized.

@kachkaev

kachkaev May 15, 2018

Contributor

&& are not allowed in npm scripts on Windows, so I had to split command into three

@kachkaev

kachkaev May 15, 2018

Contributor

&& are not allowed in npm scripts on Windows, so I had to split command into three

@@ -70,10 +37,10 @@ import sh from 'shelljs';
// ensure --output-name is specified adequately
if (!outputName.match(/^[a-z_]\w*$/)) {
throw new Error(`Provided --output-name \`${outputName}\` is not a valid constant or function name in elm.`);
throw new Error(`Provided output name \`${outputName}\` is not a valid constant or function name in elm.`);

This comment has been minimized.

@kachkaev

kachkaev May 15, 2018

Contributor

not using --output-name to avoid confusion in non-CLI usage. Same applies to other args

@kachkaev

kachkaev May 15, 2018

Contributor

not using --output-name to avoid confusion in non-CLI usage. Same applies to other args

Show outdated Hide outdated src/index.js
await Promise.all([
close(elmCompileStdoutFd).catch(() => {}),
close(elmCompileStderrFd).catch(() => {}),
]);

This comment has been minimized.

@kachkaev

kachkaev May 15, 2018

Contributor

Had to do this to support Windows, otherwise the files were left unclosed and could not be deleted

@kachkaev

kachkaev May 15, 2018

Contributor

Had to do this to support Windows, otherwise the files were left unclosed and could not be deleted

kachkaev referenced this pull request in rtfeldman/node-elm-compiler May 15, 2018

@kachkaev

This comment has been minimized.

Show comment
Hide comment
@kachkaev

kachkaev May 15, 2018

Contributor

The PR should be ready for your review @jfairbank 🎉 Calls to elm-compile are async now and both Travis and AppVeyor#28 (Windows) pass!

Contributor

kachkaev commented May 15, 2018

The PR should be ready for your review @jfairbank 🎉 Calls to elm-compile are async now and both Travis and AppVeyor#28 (Windows) pass!

@kachkaev

This comment has been minimized.

Show comment
Hide comment
@kachkaev

kachkaev May 21, 2018

Contributor

ping @jfairbank 🏓 🙂

Contributor

kachkaev commented May 21, 2018

ping @jfairbank 🏓 🙂

@jfairbank

This comment has been minimized.

Show comment
Hide comment
@jfairbank

jfairbank May 23, 2018

Owner

Hey, @kachkaev. I've been at a conference this week and am traveling the rest of the week, so I won't be able to check this PR more thoroughly until next week. Sorry for the delay, but I didn't want to keep you in the dark at least.

Owner

jfairbank commented May 23, 2018

Hey, @kachkaev. I've been at a conference this week and am traveling the rest of the week, so I won't be able to check this PR more thoroughly until next week. Sorry for the delay, but I didn't want to keep you in the dark at least.

@kachkaev

This comment has been minimized.

Show comment
Hide comment
@kachkaev

kachkaev Jun 7, 2018

Contributor

@jfairbank when about could you have a look at this? No rush, just curious.

Contributor

kachkaev commented Jun 7, 2018

@jfairbank when about could you have a look at this? No rush, just curious.

@jfairbank jfairbank merged commit 8fa0acc into jfairbank:master Jun 8, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jfairbank

This comment has been minimized.

Show comment
Hide comment
@jfairbank

jfairbank Jun 8, 2018

Owner

Sorry again; I've just been super busy with other priorities. I finally looked this over, and it seems reasonable. I'll get a release out later tonight. Thanks!

Owner

jfairbank commented Jun 8, 2018

Sorry again; I've just been super busy with other priorities. I finally looked this over, and it seems reasonable. I'll get a release out later tonight. Thanks!

@jfairbank

This comment has been minimized.

Show comment
Hide comment
@jfairbank

jfairbank Jun 8, 2018

Owner

v2.3.0 is now out!

Owner

jfairbank commented Jun 8, 2018

v2.3.0 is now out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment