-
Notifications
You must be signed in to change notification settings - Fork 333
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
Respond to Rollup warning for i18n.mjs #2829
Comments
Maybe using a named export would make the warning disappear, as it seems to complain about the export being a default one. If that's the case, that might be a cheap, quick fix for the warning 😄 |
I'd prefer named exports too as it can also avoid compatibility problems with bundlers/compilers having to support a "synthetic default". Likely why Rollup is logging the issue Two questions:
Before import Accordion from './components/accordion/accordion.mjs'
export { Accordion } After import { Accordion } from './components/accordion/accordion.mjs'
export { Accordion } Subtle difference, but the “After” version will also let IDEs keep track of when things get renamed |
Won’t moving to the second version be a breaking change if people are already importing single ESM components? |
@romaricpascal For compatibility reasons perhaps we keep the default export (alongside the named one)? But, do we actually support importing components directly like these examples? Require/Import via filename default exportThis is the current (working) approach to require/import components directly // CommonJS modules
const Button = require('govuk-frontend/govuk/components/button/button')
// ECMAScript modules
import Button from 'govuk-frontend/govuk-esm/components/button/button.mjs'
// Both via dynamic import
const { default: Button } = await import('govuk-frontend/govuk-esm/components/button/button.mjs') Require/Import via filename named exportThis is the suggested Rollup approach but it's possible to support an // CommonJS modules
const { Button } = require('govuk-frontend/govuk/components/button/button')
// ECMAScript modules
import { Button } from 'govuk-frontend/govuk-esm/components/button/button.mjs'
// Both via dynamic import
const { Button } = await import('govuk-frontend/govuk-esm/components/button/button.mjs') Advantages: Linting and "IntelliSense" style tools will know when components get replaced, moved or renamed. Editors and IDEs with "refactor" functionality can rename all references when an import changes Require/Import via
|
If we want to avoid breaking "via filename named export" here's the compatibility suggestion: Single default export only (current) function Accordion ($module, config) {} // Not exported
export default Accordion Both named and default export (suggested) export function Accordion ($module, config) {} // Exported
export default Accordion It's not really recommended (ESLint import plugin has a rule for |
Cheers for the thorough description 😄 On my side, I'd be happy to move towards named for everything, but that's a decision that'll need a wider discussion I think. If we go for it though, having both named and not named while we wait for our next breaking release doesn't sounds like too bad a compromise. That's a neat idea 🙌🏻 |
Thanks @romaricpascal, there's one other potential issue as we use UMD bundles I can't see the "interop" Questions
What does
|
Cheers for demistifying If I understood correctly what it does, wouldn't the situation only be problematic if someone was trying to directly import a CommonJS component from an ES module as such: // Note that they're importing from `govuk` folder, not `govuk-esm`
import {Accordion} from 'govuk-frontend/govuk/components/accordion/accordion.js' The other scenarios for importing, like In that case, shouldn't we not worry about it too much and guide them to import from the Finally, to get back to the original issue, I'm wondering if we couldn't take it in two steps:
|
No problem @romaricpascal 😊 Yeah require/import Older bundlers/resolvers will stick with Using ./govuk/all.js for Like your example, if we went ahead and shipped named exports (alongside default exports) we could see some problems with older tooling that didn't understand You might have seen this with other libraries that haven't got it quite right: const example = require('oops').default
import { default as example } from 'oops' We'll have to consider how UMD bundles affect this too |
Given how much effort we've put into the localisation work, I think we should aim to make it public at some point so that it can be re-used in downstream components. However, that doesn't have to be something we do right now, especially if we want to give ourselves the opportunity to make changes to its API without having to treat them as breaking changes. Maybe this is something to discuss as a team? At the very least I'd like to check in with @querkmachine and see how it would feel about making it public now. |
I don't think there's anything stopping I18n from being public. It's been built around the needs of our existing components and is definitely not the most fully-featured i18n script around (no genders, contextual grammar, etc.), so external users may run into the limitations of it harder than we have, but it does work (🤞). |
We prefer named exports over default exports to avoid compatibility issues with transpiler "synthetic default" as discussed in: #2829 See our [coding standards for JavaScript](/docs/contributing/coding-standards/js.md)
We prefer named exports over default exports to avoid compatibility issues with transpiler "synthetic default" as discussed in: #2829 See our [coding standards for JavaScript](/docs/contributing/coding-standards/js.md)
We prefer named exports over default exports to avoid compatibility issues with transpiler "synthetic default" as discussed in: #2829 See our [coding standards for JavaScript](/docs/contributing/coding-standards/js.md)
What
This notice, which we think is coming from Rollup, currently appears in the test output:
Understand whether there are implications for consumers of GOV.UK Frontend and whether we need to make any changes.
If we don't need to make any changes, see if there's a way to silence the warning.
Why
src/govuk/i18n.mjs
is a new file which has not yet been included in a release of GOV.UK Frontend.We want to make sure that the way that we've written
i18n.mjs
will not impact consumers of GOV.UK Frontend once the next release has gone out.Who needs to work on this
Developers
Who needs to review this
Developers
Done when
The text was updated successfully, but these errors were encountered: