-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Build: Change package build step to async flow #8093
Conversation
bin/packages/build.js
Outdated
return Promise.all( [ | ||
...files.map( ( file ) => buildFile( file, true ) ), | ||
buildPackageStyleIfApplicable(), | ||
] ).then( () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be replaced with await
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be replaced with
await
?
Yep, updated in rebased 9feaf4a.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
bin/packages/build.js
Outdated
.forEach( buildPackage ); | ||
process.stdout.write( '\n' ); | ||
|
||
Promise.all( [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be:
Promise.all( getPackages().map( buildPackage ) )...
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be:
Promise.all( getPackages().map( buildPackage ) )...?
Updated in rebased 9feaf4a.
@@ -89,7 +89,6 @@ | |||
"concurrently": "3.5.0", | |||
"core-js": "2.5.7", | |||
"cross-env": "3.2.4", | |||
"deasync": "0.1.13", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
This one needs rebase and some adjustments after changes introduced in #8187 for RTL support for CSS. |
c9b776b
to
9feaf4a
Compare
I've finally brought this back up to date. Unfortunately it still doesn't seem to have much of an overall impact. |
Feel free to merge when Travis is happy. It was already reviewed :)
@noisysocks has PR opened which adds caching, maybe it will have an impact together. |
I have two of my own remaining reservations:
|
Ah, I guess I should have read those links more closely, as it answers my question quite concretely 😅
|
See: http://api.postcss.org/LazyResult.html#css >This is why this method is only for debug purpose, you should always use LazyResult#then.
Effectively unchanged, since stringification of the LazyResult object is aliased to the css property. See: http://api.postcss.org/LazyResult.html#toString
I'm fine in the initial approach to have unbounded parallelization. This can be revisited if it's shown to be problematic. |
There's a few issues here impacting (a) sourcemaps, (b) I've proposed a revert at #13195 I have an in-progress branch with some partial fixes at I'll leave a few follow-up comments here for more specific problems. |
buildPaths.jsFiles.forEach( buildJsFile ); | ||
buildPaths.scssPackagePaths.forEach( buildPackageScss ); | ||
return Promise.all( [ | ||
...buildPaths.jsFiles.map( buildJsFile ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong in thinking that by the previous implementation using forEach
, these were arrays, when in fact they're of type Set
. Thus, rebuilds fail with an error:
[1] /Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/bin/packages/build.js:100
[1] ...buildPaths.jsFiles.map( buildJsFile ),
[1] ^
[1]
[1] TypeError: buildPaths.jsFiles.map(...) is not a function or its return value is not iterable
[1] at buildFiles (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/bin/packages/build.js:100:25)
[1] at Object.<anonymous> (/Users/andrew/Documents/Code/vvv/www/editor/htdocs/wp-content/plugins/gutenberg/bin/packages/build.js:234:2)
[1] at Module._compile (internal/modules/cjs/loader.js:689:30)
[1] at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
[1] at Module.load (internal/modules/cjs/loader.js:599:32)
[1] at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
[1] at Function.Module._load (internal/modules/cjs/loader.js:530:3)
[1] at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
[1] at startup (internal/bootstrap/node.js:282:19)
[1] at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Two alternatives are:
- Don't track them as a
Set
, rather as an array and guarantee uniqueness before pushing to array. - Convert
Set
to array at this line before the map, i.e....[ ...buildPaths.jsFiles ].map( buildJsFile ),
fs.writeFileSync( destPath, transformed.code + '\n//# sourceMappingURL=' + path.basename( destPath ) + '.map' ); | ||
await mkdirp( path.dirname( destPath ) ); | ||
const transformed = await transformFile( file, babelOptions ); | ||
writeFile( destPath + '.map', JSON.stringify( transformed.map ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are asynchronous tasks and should have await
, preferably in parallel as await Promise.all
between writing the map file and the original source.
const transformed = babel.transformFileSync( file, babelOptions ); | ||
fs.writeFileSync( destPath + '.map', JSON.stringify( transformed.map ) ); | ||
fs.writeFileSync( destPath, transformed.code + '\n//# sourceMappingURL=' + path.basename( destPath ) + '.map' ); | ||
await mkdirp( path.dirname( destPath ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm seeing varied results in attributing this to be a cause, but I was seeing some improvement by switching this back to its synchronous form.
Possibly related: https://github.com/substack/node-mkdirp/issues/154
Viable substitute module: https://www.npmjs.com/package/make-dir
I had a similar attempt at this over christmas (didn't realise this PR existed). I also didn't see any real improvement in build times, so didn't bother tidying things up: It'll be worth keeping an eye on node 10's promise based filesystem apis. They're currently marked as experimental, hopefully in a not too distant future version they'll become stable: |
* Build: Change package build step to async flow * Build: Trigger LazyResult#then for postcss.process See: http://api.postcss.org/LazyResult.html#css >This is why this method is only for debug purpose, you should always use LazyResult#then. * Build: Consistently use css property for stringified result Effectively unchanged, since stringification of the LazyResult object is aliased to the css property. See: http://api.postcss.org/LazyResult.html#toString
* Build: Change package build step to async flow * Build: Trigger LazyResult#then for postcss.process See: http://api.postcss.org/LazyResult.html#css >This is why this method is only for debug purpose, you should always use LazyResult#then. * Build: Consistently use css property for stringified result Effectively unchanged, since stringification of the LazyResult object is aliased to the css property. See: http://api.postcss.org/LazyResult.html#toString
This pull request seeks to adapt the package build script to perform builds in parallel, rather than in sequence. In practice, this unfortunately does not appear to make a significant difference, reducing the build time for me from about 12s to 10s. It seems that the style build takes a significant part of the time of package build.
Noting also that this is not a total conversion.
getPackages
should be made to be asynchronous, but is touched by other scripts as well. As such, it was decided to be left as a separate task.Testing instructions:
There should be no regressions in the build of packages.