-
Notifications
You must be signed in to change notification settings - Fork 327
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
Rename exported JavaScript modules to include component name #2426
Conversation
I'm not sure I understand what is going on in the first commit... would you mind expanding a bit on why you're making the change and what it means? 😅 |
13f9bf4
to
46d25f9
Compare
46d25f9
to
43e7b6f
Compare
@lfdebrux I'll try to explain it more here, let me know if it's any more helpful! If not, happy to jump on a call to chat about it. The current gulp task as it is on As far as I can tell, there's no easy way of doing this with the current set-up as gulp streams mean you don't get that concept of 'this is the thing that's currently being processed'. I might be wrong about that, welcome to other suggestions! So in order to get more "control" over knowing what file is currently being processed, I've introduced a |
Ah, I get it now, thank you! |
43e7b6f
to
3e3025b
Compare
3e3025b
to
1e581b8
Compare
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'd be nice to have tests to cover at least some of this, but no idea how to make that happen…
Maybe we could add a test to after-build-package.test.js
that looks at the component JS and asserts something about the exported name?
1e581b8
to
096a322
Compare
aae913d
to
751f06e
Compare
751f06e
to
a4f70fb
Compare
a4f70fb
to
36d1183
Compare
36d1183
to
fa40056
Compare
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.
Looks good to me, just one suggestion re how we import the componentNameToJavaScriptModuleName
method.
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.
Looks good to me.
Have manually run the build:dist
and build:package
tasks and the output looks like what I'd expect – although it looks like using the dist
version of the JS the modules are not attached to GOVUKFrontend, but I guess that's expected? It doesn't appear to be a change from the existing behaviour, anyway.
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.
@vanitabarrett Looks great! Just a few tiny comments.
4f85f47
to
e5f09bc
Compare
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.
@vanitabarrett Looks good!
Thanks for your reviews @EoinShaughnessy and @36degrees ! I'm going to hold off merging this for a bit as I've asked @alex-ju to test this change in the GOV.UK Publishing Components to double check it works as expected. |
Test alphagov/govuk-frontend#2426 ,a prerelease using `yarn add alphagov/govuk-frontend#00603a9b`
Many thanks for the work on this, Vanita! 🙌 |
Changes the existing JS compile gulp task to use `glob` and iterate over each file using `forEach`.
Add a new function to our helper-functions.js that converts a component name to the Javascript module name. This means we can use the function elsewhere, such as tests, without duplicating the logic. It also makes sense to put together with the function that generates the macro names, as the two are linked
Adds the module name (e.g: Accordion) to the UMD export name. For example: GOVUKFrontend becomes GOVUKFrontend.Accordion If the file is all.js (which pulls in all component JS), fall back to the original naming ("GOVUKFrontend") otherwise the modules are nested underneath an `all`, e.g: GOVUKFrontend.all.initAll()
e5f09bc
to
ad45adf
Compare
Closes #1836
What
Change the
window
global and UMD export name for component JavaScript to include the component name, for example:GOVUKFrontend.CharacterCount
.The way this PR currently stands, this new naming applies only to component JavaScript files - not to
all.js
,common.js
or any vendor/polyfills. Becauseall.js
already exports multiple modules, we can keep the original naming ofGOVUKFrontend
and modules will already be automatically nested underneath, e.g:window.GOVUKFrontend.initAll()
. If the new naming system was also applied toall.js
, you would end up having to callwindow.GOVUKFrontend.All.initAll()
.This means that if a user imports a specific component JavaScript (e.g: character-count) and then
all.js
-all.js
will overwrite any existing modules attached towindow.GOVUKFrontend
. This feels like an unlikely scenario, but I'm not sure I know enough about how users are importing our JavaScript to know if applying this change only to component JavaScript is likely to cause problems - welcome any thoughts/insights on this.Why
When importing individual scripts, each one was attached to
window.GOVUKFrontend
. This meant that if you imported (for example) the accordion and then imported the button JavaScript, one overwrote the other so that only the button JavaScript would be attached towindow.GOVUKFrontend
.Breaking Changes
Again - I welcome any thoughts/insights on this as I'm not 100% confident I know enough about how users are using our JavaScript to account for all changes that might need to be made
If a user is importing all our JavaScript, I don't think they'll need to make any changes.
If a user is importing individual component JavaScript, then they will need to switch any calls to
window.GOVUKFrontend
to be towindow.GOVUKFrontend.[ComponentName]