-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Try to generalize build transforms #16317
Conversation
const packages = new Set; | ||
function createEntryTransform( mappingFunc ) { | ||
// Track any already built files to avoid duplication. | ||
const fileSet = new Set; |
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.
The second commit in this branch introduces this generic way to avoid duplicate built files, but I'm not sure it's the right solution.
It doesn't avoid repeating expensive operations in the mappingFunc
, which I imagine was the original intention for tracking changed packages. (cc @aduth)
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.
Hm, yeah, I see what you mean. Maybe we can pass fileSet
as the second argument in the mapping function to allow the callback to determine whether to defer to a cached value?
Or if we really want to follow Array#map
signature, as the third argument, and likely as an array and not a set (documentation).
// Only operate once per package, assuming entries are common. | ||
const packageName = getPackageName( file ); | ||
if ( packages.has( packageName ) ) { | ||
if ( isString( mapped ) && ! fileSet.has( mapped ) ) { |
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.
Could we just normalize this value to an array and skip directly to the forEach
below?
|
||
// Build all root level stylesheets for the package. | ||
const packageName = getPackageName( file ); | ||
const rootScssFiles = await glob( path.resolve( PACKAGES_DIR, packageName, 'src/*.scss' ) ); |
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.
The capitalization of this as an acronym should be rootSCSSFiles
.
That said, I don't think we need a variable here, just return await ...
const packages = new Set; | ||
function createEntryTransform( mappingFunc ) { | ||
// Track any already built files to avoid duplication. | ||
const fileSet = new Set; |
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.
Hm, yeah, I see what you mean. Maybe we can pass fileSet
as the second argument in the mapping function to allow the callback to determine whether to defer to a cached value?
Or if we really want to follow Array#map
signature, as the third argument, and likely as an array and not a set (documentation).
Closing this for now—happy for it to be picked up by someone else, but not seeing much value on working on it more. |
Description
As mentioned in #16150 (comment), the solution for handling block.json files when
npm run dev
is running introduces some code duplication. This PR tries to reduce that duplicationHow has this been tested?
Test that
npm run build
andnpm run dev
continue to work.Types of changes
Refactor (non-breaking change which adds functionality)
Checklist: