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

[UI Framework] Spawn compileCss as a child process to prevent a node-sass fatal error from killing the watch process #13222

Merged
merged 6 commits into from
Aug 1, 2017

Conversation

cjcenizal
Copy link
Contributor

No description provided.

@cjcenizal cjcenizal added Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v6.0.0-rc1 v7.0.0 labels Jul 31, 2017
@cjcenizal cjcenizal requested a review from tylersmalley July 31, 2017 17:13
package.json Outdated
@@ -63,7 +63,8 @@
"mocha": "echo 'use `node scripts/mocha`' && false",
"sterilize": "grunt sterilize",
"uiFramework:start": "grunt uiFramework:start",
"uiFramework:build": "grunt uiFramework:build"
"uiFramework:build": "grunt uiFramework:build",
"uiFramework:compileCss": "grunt uiFramework:compileCss"
Copy link
Contributor

Choose a reason for hiding this comment

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

Expanding on our conversation here. When would someone need to manually compile the CSS? I can understand creating a grunt task for it, but not sure it warrants an aliased npm task.

@cjcenizal
Copy link
Contributor Author

@tylersmalley I've addressed your feedback. Can you take another look?

grunt.file.write('ui_framework/dist/ui_framework.css.map', result.map);
}
});
return new Promise(resolve => {
Copy link
Contributor

@tylersmalley tylersmalley Jul 31, 2017

Choose a reason for hiding this comment

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

We should use Bluebird.promisify instead of wrapping here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you show me what you mean?

Copy link
Contributor

@tylersmalley tylersmalley Aug 1, 2017

Choose a reason for hiding this comment

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

Thinking something like this:

  import { promisify } from 'bluebird';
  const renderSass = promisify(sass.render);

  function uiFrameworkCompile() {
    const from = 'ui_framework/components/index.scss';
    const to = 'ui_framework/dist/ui_framework.css';

    return renderSass({
      file: from
    }).then(result => {
      postcss([postcssConfig])
        .process(result.css, { from, to })
        .then(result => {
          grunt.file.write(to, result.css);

          if (result.map) {
            grunt.file.write(`${to}.map`, result.map);
          }
        });
    }).catch(error => {
      grunt.log.error(error);
    });
  }

const debouncedCompile = debounce(() => {
// Compile the SCSS in a separate process because node-sass throws a fatal error if it fails
// to compile.
grunt.util.spawn({
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted to use a promise here you could as well, but I feel the callback is fine if you want to leave it.

const spawn = promisify(grunt.util.spawn);

...

spawn({
  cmd: isPlatformWindows ? '.\\node_modules\\.bin\\grunt.cmd' : './node_modules/.bin/grunt',
  args: [ 'uiFramework:compileCss' ]
}).then(grunt.log.writeln).catch(e => grunt.log.error(e.stdout));

Copy link
Contributor

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

One minor request to use promisify.

@cjcenizal
Copy link
Contributor Author

@tylersmalley When I implemented your change, the output in the terminal lost some of its color, and the "bell" also didn't ring when there was an error:

image

Here's how it looked before:

image

Any suggestions on what's going on here and how we can get this behavior back?

@cjcenizal cjcenizal force-pushed the bug/ui-framework-build-error branch from e9e665c to ea7e67e Compare August 1, 2017 20:00

return new Promise(resolve => {
sass.render({
file: 'ui_framework/components/index.scss'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use src here

@cjcenizal
Copy link
Contributor Author

Good catch! Fixed. Thanks.

Copy link
Contributor

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

LGTM - not sure why promisify is dropping the colors and bell. Got the same results with Node 8's util.promisify. This works fine.

@cjcenizal cjcenizal merged commit 08719cd into elastic:master Aug 1, 2017
@cjcenizal cjcenizal deleted the bug/ui-framework-build-error branch August 1, 2017 21:11
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Aug 1, 2017
…sass fatal error from killing the watch process (elastic#13222)

* Spawn compileCss as a child process to prevent a node-sass fatal error from killing the watch process.
* Document tasks.
cjcenizal added a commit that referenced this pull request Aug 1, 2017
…sass fatal error from killing the watch process (#13222) (#13271)

* Spawn compileCss as a child process to prevent a node-sass fatal error from killing the watch process.
* Document tasks.
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Aug 11, 2017
…sass fatal error from killing the watch process (elastic#13222)

* Spawn compileCss as a child process to prevent a node-sass fatal error from killing the watch process.
* Document tasks.
cjcenizal added a commit that referenced this pull request Aug 11, 2017
…sass fatal error from killing the watch process (#13222) (#13476)

* Spawn compileCss as a child process to prevent a node-sass fatal error from killing the watch process.
* Document tasks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v6.1.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants