Date package: do not bundle moment.js for getSettings only#76865
Date package: do not bundle moment.js for getSettings only#76865
getSettings only#76865Conversation
Made-with: Cursor
Made-with: Cursor # Conflicts: # packages/date/src/index.ts # packages/date/src/test/index.js
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +27 B (0%) Total Size: 7.73 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 19a9467. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23650088976
|
getSettings onlygetSettings only
Description
Consumers of
@wordpress/datethat only need access to the date settings (e.g.getSettings) are currently forced to bundlemomentandmoment-timezone(~300KB), because the entire module is evaluated on import — including top-level moment imports and asetupWPTimezone()call.This PR extracts the settings state into a new
settings.tsmodule with no moment dependency, and exposes it as a package subpath export:This import resolves to a module that only depends on
./types(which usesimport typefrom moment, erased at compile time), so bundlers won't include moment.js.The existing
getSettings()export from the main entry point continues to work unchanged — no deprecation, no breaking changes.Changes
packages/date/src/settings.ts: Contains thesettingsobject and exportsgetCurrentSettings()/setCurrentSettings(). No runtime dependencies on moment.packages/date/src/index.ts: Now imports from./settingsinstead of owning the settings state directly.getSettings()delegates togetCurrentSettings().packages/date/package.json: Added./settingssubpath export pointing to the built settings module (CJS, ESM, and types).getSettings()returns the same value asgetCurrentSettings(). Existing tests migrated to usegetCurrentSettings()directly.How has this been tested?
All existing
@wordpress/dateunit tests pass, including the new zone recovery tests from trunk.npm run test:unit -- --testPathPattern='packages/date/src/test'