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

Refactor the build scripts #11787

Merged
merged 5 commits into from
Dec 6, 2017
Merged

Refactor the build scripts #11787

merged 5 commits into from
Dec 6, 2017

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Dec 6, 2017

This might be a bit hard to review since a few things moved around.
The code that produces the bundles is exactly the same (just split into a few methods).

This mostly changes the code that copies folders and shims:

  • We no longer process.exit() all over the place, and instead use the normal try/catch flow.
  • We intentionally crash on uncaught Promise rejections.
  • The old code was convoluted because it tried to create an npm package folder lazily for every bundle. The new code just creates them at the end (so we don't need to check if one exists).
  • Another reason the old code was convoluted is due to all the checks if folders exist before creating them. I just changed our asyncCopyTo function to do that automatically.
  • I'm no longer creating npm packages in a temp folder, and instead I'm doing it in place. This is easier to read and understand. We're also now doing one pack/unpack cycle per package (instead of per bundle).

Note I mostly rewrote the folder moving file from scratch.
I found it easier than refactoring the old one.

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

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

Nice tidy-ups. LGTM

syncReactNative,
syncReactNativeRT,
syncReactNativeCS,
} = require('./sync').syncReactDom;
const Packaging = require('./packaging');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also deconstruct this object rather than using Packaging?

@gaearon
Copy link
Collaborator Author

gaearon commented Dec 6, 2017

I wanted to keep Modules and Packages the way they are so it's obvious these aren't local functions. I think this helps understand the structure a little bit better.

I'll do the same for Sync instead to be consistent.

@gaearon gaearon merged commit f72043a into facebook:master Dec 6, 2017
@gaearon gaearon deleted the rewrite-build branch December 6, 2017 20:11
Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

I just skimmed this really, but it looks good.

if (error.code) {
console.error(
`\x1b[31m-- ${error.code}${error.plugin ? ` (${error.plugin})` : ''} --`
console.log(`${chalk.bgRed.black(' OH NOES! ')} ${logKey}\n`);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: console.error ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's a further console.error too so I guess it doesn't matter? The diff makes it look like I replaced one with the other, but I just added an additional one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be honest I'm not even sure what the difference on Node is 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the only difference is that one outputs to stderr and the other to stdout. I don't think it actually matters in this case. 😁

return;
}
console.error(
`\x1b[31m-- ${error.code}${error.plugin ? ` (${error.plugin})` : ''} --`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use chalk.red() ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy paste of existing code, didn't look into how it works.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. Should be identical to chalk.red('string')

}
return asyncMkDirP(path.dirname(to)).then(
() =>
new Promise((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible follow-up: We could remove this new Promise boilerplate here and below using Promise.denodeify

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

Successfully merging this pull request may close these issues.

4 participants