Skip to content

Commit

Permalink
Merge pull request #5533 from alphagov/umd-extend-object
Browse files Browse the repository at this point in the history
Fix UMD files overriding existing global
  • Loading branch information
romaricpascal authored Dec 17, 2024
2 parents 0afb279 + 7022a8a commit 6a0fd3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ You do not need `/index` at the end of each import path if you’re using Dart S

This change was introduced in [pull request #5518: Deprecate `govuk/all.scss` and only reference `govuk/index.scss` internally](https://github.com/alphagov/govuk-frontend/pull/5518).

### Fixes

We've made fixes to GOV.UK Frontend in the following pull requests:

- [#5533: Fix UMD files overriding existing global](https://github.com/alphagov/govuk-frontend/pull/5533)

## v5.7.1 (Fix release)

To install this version with npm, run `npm install [email protected]`. You can also find more information about [how to stay up to date](https://frontend.design-system.service.gov.uk/staying-up-to-date/#updating-to-the-latest-version) in our documentation.
Expand Down
7 changes: 6 additions & 1 deletion packages/govuk-frontend/rollup.publish.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export default defineConfig(({ i: input }) => ({
preserveModules: false,

// Export via `window.GOVUKFrontend.${exportName}`
name: 'GOVUKFrontend'
name: 'GOVUKFrontend',

// Loading multiple files will add their export to the same
// `GOVUKFrontend` object rather than re-creating a new `GOVUKFrontend`
// for each and wiping the components previously loaded
extend: true
}
],

Expand Down
8 changes: 7 additions & 1 deletion packages/govuk-frontend/tasks/build/package.unit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('packages/govuk-frontend/dist/', () => {

// Look for AMD module definition for 'GOVUKFrontend'
expect(contents).toContain(
"(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GOVUKFrontend = {}));"
"(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GOVUKFrontend = global.GOVUKFrontend || {}));"
)

// Look for bundled components with CommonJS named exports
Expand Down Expand Up @@ -355,6 +355,12 @@ describe('packages/govuk-frontend/dist/', () => {
)

expect(moduleTextESM).toContain(`export { ${componentClassName} }`)

// Look for AMD module definition for 'GOVUKFrontend'
expect(moduleTextUMD).toContain(
"(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GOVUKFrontend = global.GOVUKFrontend || {}));"
)

expect(moduleTextUMD).toContain(
`exports.${componentClassName} = ${componentClassName};`
)
Expand Down

0 comments on commit 6a0fd3f

Please sign in to comment.