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

Split core functionality from CLI #14

Merged
merged 13 commits into from
Jun 8, 2018

Conversation

kachkaev
Copy link
Contributor

@kachkaev 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.

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 https://github.com/rtfeldman/node-elm-compiler/issues/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
Copy link
Owner

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

@kachkaev kachkaev force-pushed the split-cli-from-index branch from 3414b82 to deeb2c4 Compare May 8, 2018 13:07
@kachkaev kachkaev force-pushed the split-cli-from-index branch from deeb2c4 to d7ff3b5 Compare May 8, 2018 13:08
@kachkaev
Copy link
Contributor Author

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 [WIP] Split core functionality from CLI Split core functionality from CLI May 8, 2018
@kachkaev kachkaev force-pushed the split-cli-from-index branch from 1f67b47 to 7a8879c Compare May 8, 2018 13:34
@kachkaev
Copy link
Contributor Author

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
Copy link
Contributor Author

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",
Copy link
Contributor Author

@kachkaev kachkaev May 15, 2018

Choose a reason for hiding this comment

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

&& 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",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

&& 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.`);
Copy link
Contributor Author

@kachkaev kachkaev May 15, 2018

Choose a reason for hiding this comment

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

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

src/index.js Outdated
await Promise.all([
close(elmCompileStdoutFd).catch(() => {}),
close(elmCompileStderrFd).catch(() => {}),
]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

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
Copy link
Contributor Author

kachkaev commented May 21, 2018

ping @jfairbank 🏓 🙂

@jfairbank
Copy link
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.

@kachkaev
Copy link
Contributor Author

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
@jfairbank
Copy link
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!

@jfairbank
Copy link
Owner

v2.3.0 is now out!

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.

2 participants