Add opt-in core bundle with on-demand localization - #410
Open
Alex Vallone (amv146) wants to merge 1 commit into
Open
Add opt-in core bundle with on-demand localization#410Alex Vallone (amv146) wants to merge 1 commit into
Alex Vallone (amv146) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change adds a smaller, opt-in package entrypoint that excludes non-English localization templates from the initial bundle.
The existing
@microsoft/powerquery-parserentrypoint remains unchanged and continues to load every supported locale synchronously. Consumers can migrate independently without a breaking change.Changes
@microsoft/powerquery-parser/core.en-US.en-USfor unregistered locales.LocalizationUtils.registerLocalizationTemplates(locale, templates).@microsoft/powerquery-parser/locales/fr-FR@microsoft/powerquery-parser/locales/de-DE@microsoft/powerquery-parser/locales/allfor consumers requiring every locale.TemplatesByLocaleregistry and direct-map mutation behavior.Bundle impact
Measured using a minified Webpack production bundle:
fr-FRUsing core reduces the initial parser payload by approximately 54.8 KB gzip.
Why
createPackageEntrypoints.jsis necessaryTypeScript currently emits the new core module at:
Without a package
exportsmap, Node resolves:to a
core.jsfile at the package root. The build script creates that thin proxy and its declaration file. It also creates stablelocales/<locale>JavaScript and declaration entrypoints from the generated localization JSON files, allowing consumers to use namedtemplatesimports without maintaining a source wrapper for every locale.A package
exportsmap would normally provide these aliases without generated proxy files. It is not used here because definingexportsrestricts package access to explicitly exported paths. This package has historically allowed arbitrary deep imports underlib/powerquery-parser, and testing confirmed that introducingexportswould block existing consumers of those paths.Removing the script
The preferred long-term solution is a major-version release that:
package.json#exports../coredirectly to./lib/powerquery-parser/core.js.{ templates }API is required.Once arbitrary deep-import compatibility is no longer required,
createPackageEntrypoints.js, the generated package-root proxies, and their.gitignoreentries can be removed.Migration guide
No migration is required for existing consumers:
This continues to include and support every locale.
English-only consumers
Replace root imports with the core entrypoint:
No other changes are required. Locale values without a registered translation fall back to
en-US.Consumers requiring one locale
Import the core parser, load the required locale, and register it before parsing:
Existing settings continue to select the locale normally:
Lazy-loading a locale
Applications can place translations in separate chunks:
Registration must finish before constructing localized lexer or parser errors.
Consumers requiring every locale
Alternatively, continue using the existing package root.
Transitive dependencies
If another dependency imports
@microsoft/powerquery-parser, changing only application imports may retain the full bundle. Applications can alias the root import to core in their bundler:The application must then register every non-English locale it uses.
Compatibility
Templatesexports remain available.TemplatesByLocalemutations continue to work.Validation