-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: add ParagonWebpackPlugin
to support design tokens
#546
feat: add ParagonWebpackPlugin
to support design tokens
#546
Conversation
Thanks for the pull request, @dcoa! What's next?Please work through the following steps to get your changes ready for engineering review: 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. 🔘 Let us know that your PR is ready for review:Who will review my changes?This repository is currently maintained by Where can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:
When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
86312c3
to
9c1a27b
Compare
Hey @dcoa, thank you for this contribution! Please let us know when the changes are ready for review. |
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.
@dcoa Thank you for re-opening and improving this PR! Left a few suggestions
@@ -0,0 +1,373 @@ | |||
const { sources } = require('webpack'); |
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.
[proposal]: This file is quite large. I suggest dividing it into several files and creating a folder with utilities. I think it would be a good idea to follow this structure:
./utils
htmlUtils.js
- getDescendantByTag
- findScriptInsertionPoint
- findStylesheetInsertionPoint
scriptUtils.js
- minifyScript
- insertScriptContentsIntoDocument
stylesheetUtils.js
- insertStylesheetsIntoDocument
assetUtils.js
- findCoreCssAsset
- findThemeVariantCssAssets
- getCssAssetsFromCompilation
scriptContentUtils.js
- addToScriptContents
- generateScriptContents
urlUtils.js
- handleVersionSubstitution
- getParagonStylesheetUrls
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 agree and I did, not the same order but let me know what you think :)
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.
Thank you! This looks great 💯
afc31ac
to
29f0831
Compare
config/data/paragonUtils.js
Outdated
if (!fs.existsSync(pathToPackageJson)) { | ||
return undefined; | ||
} | ||
return JSON.parse(fs.readFileSync(pathToPackageJson)).version; |
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.
should we add the second argument to use utf8?
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 is optional, however, after reading some posts about it I think it's a good suggestion. 👍
const { | ||
core: themeCore, | ||
variants: themeVariants, | ||
defaults, | ||
} = paragonConfig?.themeUrls || {}; | ||
|
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.
should we validate if the values exist before use them?, I mean just to avoid future errors, something like if !themeCore || !themeVariants return undefined.
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.
It's not necessary because we are using destructuring if any of them is not defined that will return undefined by default.
config/data/paragonUtils.js
Outdated
const themeVariantResults = {}; | ||
validThemeVariantPaths.forEach(([themeVariant, value]) => { | ||
themeVariantResults[themeVariant] = { | ||
filePath: path.resolve(dir, 'node_modules', npmPackageName, 'dist', value.paths.minified), | ||
entryName: isBrandOverride ? `brand.theme.variants.${themeVariant}` : `paragon.theme.variants.${themeVariant}`, | ||
outputChunkName: isBrandOverride ? `brand-theme-variants-${themeVariant}` : `paragon-theme-variants-${themeVariant}`, | ||
}; | ||
}); |
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 think we could use .reduce instead of filtering and iterate this, it might be more efficient but I think this is an easier way to read the code.
Should we worry about efficiency?
config/data/paragonUtils.js
Outdated
if (!paragonThemeCss) { | ||
return cacheGroups; | ||
} | ||
cacheGroups[paragonThemeCss.core.outputChunkName] = { |
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.
We could remove the line 107 and just define the constant from here, right?
9c54792
to
dd5647e
Compare
@dcoa We've got a green build here and it's been a while since the last update. So I'm assuming that the changes are ready for engineering review. Let me know if that's not the case. |
Hi @itsjeyd yes, it is ready for review and has been tested alongside other design tokens PRs here openedx/frontend-app-discussions#726 |
Thanks for confirming @dcoa. @brian-smith-tcril @adamstankiewicz Would you be able to have a look at this PR? |
2733312
to
347e820
Compare
@dcoa in https://openedx.slack.com/archives/C071U9E4VNV/p1715966767660459?thread_ts=1715940913.033459&cid=C071U9E4VNV I mentioned
When I wrote that I wasn't thinking about landing this PR as a non breaking change. Since the plan now is to land this as a non breaking change I think that fully justifies keeping the I would still like to make the move to the |
Thanks @brian-smith-tcril. Only thing I'd add regarding the brand package scope ( |
05b69a2
to
7c65744
Compare
7c65744
to
182100f
Compare
* 1. ``envConfig.PARAGON_THEME_URLS`` (JS based) | ||
* 3. ``process.env.PARAGON_THEME_URLS`` (JSON based) |
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 feel like having PARAGON_THEME_URLS
work in an env.config.js
file but not an env.config.jsx
file is more confusing than just saying PARAGON_THEME_URLS
must be set as an environment variable.
I'd love to hear what others think about this!
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.
To be clear - this file cannot import or use env.config
with any file extension, and we must use process.env
to get this value. The env.config file is runtime configuration and is expected to import runtime files that will require transpilation (i.e., jsx/tsx) and depend on their own runtime dependencies. That code can't meaningfully pollute the build-time configuration, and having multiple files named env.config with different extensions would be seriously confusing for folks.
At a later date we may decide to create a new type of build-only configuration file, but we're just not there at the moment. For now, we just need to use process.env either via command line environment variables or the .env
files, and it'll come in as a string we need to JSON.parse
.
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.
Furthermore, worse, would be for build-time code and build-time dependencies to find their way into env.config... that would mean build-time code gets bundled with the app for a browser environment which is a huge no-no and would definitely break.
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.
+1. Agreed, we should only be relying on process.env.PARAGON_THEME_URLS
at this point, with JSON.parse
for the build-time vs. runtime configuration that @davidjoy is alluding to above (across both this frontend-build PR and within frontend-platform).
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.
On the runtime side for frontend-platform's use, by all means copy PARAGON_THEME_URLS into env.config and format it nicely as an actual object instead of a string. But for now it does need to be duplicated, unfortunately, because the two types of config can't mingle.
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 gave a couple of thumbs up above, but better to be explicit: I agree that for now, process.env.PARAGON_THEME_URLS
should be what is used, and only that.
I also like the idea of eventually having a separate build-only config file, thus doing away with any potential for confusion or breakage. (While at the same time finally removing support for the .env files, hopefully.)
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 also like the idea of eventually having a separate build-only config file, thus doing away with any potential for confusion or breakage. (While at the same time finally removing support for the .env files, hopefully.)
💯
That lines up perfectly with the feelings expressed in the slack thread.
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.
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 Great job! I also closed the original POC implementation's PR.
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.
Thank you so much for this! I know a long review process full of in-depth discussions around architectural decisions isn't always the most fun when trying to land a PR, but this came out great!
LGTM!
ParagonWebpackPlugin
to support design tokens
@dcoa 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
🎉 This PR is included in version 14.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 15.0.0-alpha.15 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I had a comment here about using |
Description:
This PR updates the original one #365 closer to the master branch and adds some extra tests.
Please read the original PR for additional context.
Changes
env.config.js
that can set the variables. (let me know if my reasoning is correct)@edx/paragon
to@openedx/paragon
and add compatibility for either@edx/brand
or@openedx/brand
Finally, I would like to split this PR in 2 one for the main implementation and another one for the example app (due to this one adds frontend-platform and paragon)