Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Print npm stderr if npm install fails #288

Merged
merged 3 commits into from
Apr 2, 2018
Merged

Print npm stderr if npm install fails #288

merged 3 commits into from
Apr 2, 2018

Conversation

eliangcs
Copy link
Member

@eliangcs eliangcs commented Mar 30, 2018

Fixes #82 and zapier/zapier#16579.

Our current code in zapier build assumes if npm install returns 0, everything is good. But npm install may fail without returning a non-zero exit code. For example, try npm install when the name in package.json has a space character. In this case, npm prints the error to stderr, but exits with 0 as if it was successful.

So what we should do instead, is to check further if APP_DIR/node_modules/zapier-platform-core exists to make sure npm install is really successful before moving on to the next step.

With this PR, now if you zapier build an app with a space in thier name in package.json, we'll show the stderr from npm:

$ zapier build
Building project.

  Copying project to temp directory ⠃ done!
  Installing project dependencies ⠆

Error! Could not install dependencies properly. Error log:
npm WARN Invalid name: "my app"
npm WARN zapier-d1da7977 No description
npm WARN zapier-d1da7977 No repository field.
npm WARN zapier-d1da7977 No README data
npm WARN zapier-d1da7977 No license field.


(Use --debug flag and run this command again to get more details.)

@eliangcs eliangcs requested review from FokkeZB and xavdid March 30, 2018 10:45
Copy link
Contributor

@FokkeZB FokkeZB left a comment

Choose a reason for hiding this comment

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

Awesome approach! Perhaps add a test?

@@ -66,7 +68,7 @@ const runCommand = (command, args, options) => {
if (code !== 0) {
reject(new Error(stderr));
}
resolve(stdout);
resolve({ stdout, stderr });
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume you've checked we're not expecting this to resolve with only stdout anywhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was supposed to. Thanks for the reminder! Fixed in a218ba4.

if (global.argOpts.debug) {
console.log(colors.green(stdout));
process.stdout.write(colors.green(str));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change from console.log to process.stdout?

Copy link
Member Author

@eliangcs eliangcs Mar 30, 2018

Choose a reason for hiding this comment

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

console.log appends a newline on every call, but the stdout from the external command already has newlines. We don't want to print a newline every time we get a piece of text from stdout.

@eliangcs
Copy link
Member Author

@FokkeZB thanks for reviewing. I wouldn't worry about adding a test for now though. To test it, we need to test the build() function in the utils/build module, which requires quite an amount of effort as there's no test like that at the moment. Doesn't seem worthwhile for a UX/DX enhancement.

Copy link
Contributor

@xavdid xavdid left a comment

Choose a reason for hiding this comment

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

I'm pretty sure the fs.exists needs to change. I like the stderr/stdout change.

To take it a step further (out of scope for this PR), we could move this to shelljs, which will handle windows compatibility and simplify this code greatly (I'm all for using other people's tested code over rolling our own).

'node_modules',
constants.PLATFORM_PACKAGE
);
if (!fs.exists(corePath)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

fs.exists is both asynchronous and deprecated (docs). I believe this needs to be fs.existsSync or one of the other methods mentioned in that doc link

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch! Fixed in 5fb57c1.

@eliangcs eliangcs merged commit de36531 into master Apr 2, 2018
@eliangcs eliangcs deleted the print-npm-stderr branch April 2, 2018 03:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants