Skip to content

refactor(core): expose core.locale as LocaleProxy#3820

Merged
ST-DDT merged 9 commits into
nextfrom
refactor/locale-proxy-in-core
Apr 22, 2026
Merged

refactor(core): expose core.locale as LocaleProxy#3820
ST-DDT merged 9 commits into
nextfrom
refactor/locale-proxy-in-core

Conversation

@ST-DDT
Copy link
Copy Markdown
Member

@ST-DDT ST-DDT commented Apr 19, 2026

Alternative to #3189 and #3819


  • Expose the locale data as LocaleProxy in FakerCore.
  • New raw attribute to get access to the raw LocaleDefinitions (to avoid issues with locale data existence checks)

@ST-DDT ST-DDT added this to the v10.x milestone Apr 19, 2026
@ST-DDT ST-DDT self-assigned this Apr 19, 2026
@ST-DDT ST-DDT requested a review from a team as a code owner April 19, 2026 17:27
@ST-DDT ST-DDT added p: 2-high Fix main branch s: needs decision Needs team/maintainer decision c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs labels Apr 19, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 19, 2026

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit 7d34d0d
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/69e6a7bcccc8ec0009dd92b7
😎 Deploy Preview https://deploy-preview-3820.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 19, 2026

I marked this as P2, because it needs to be decided on prior to the next release.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.84%. Comparing base (c53c1fe) to head (7d34d0d).
⚠️ Report is 4 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3820      +/-   ##
==========================================
- Coverage   98.90%   98.84%   -0.07%     
==========================================
  Files         897      898       +1     
  Lines        3103     3113      +10     
  Branches      556      559       +3     
==========================================
+ Hits         3069     3077       +8     
- Misses         30       32       +2     
  Partials        4        4              
Files with missing lines Coverage Δ
src/core.ts 100.00% <100.00%> (ø)
src/faker.ts 100.00% <100.00%> (ø)
src/internal/locale-proxy.ts 100.00% <100.00%> (ø)
src/modules/helpers/eval.ts 95.65% <100.00%> (ø)
src/modules/person/index.ts 94.02% <100.00%> (ø)

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Apr 19, 2026

Benefits of this over #3189:

  • No duplidated keys
  • Implicit locale data checks

Benefits of #3189 over this:

  • Does not use Proxy
  • Slightly less RAM usage

@ST-DDT ST-DDT requested review from a team and Copilot April 19, 2026 17:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors locale handling so FakerCore exposes locale data as a LocaleProxy, and adds a raw escape hatch to access underlying LocaleDefinition data without proxy behavior.

Changes:

  • Change FakerCore.locale to be a LocaleProxy and wrap locales via createLocaleProxy() in createFakerCore().
  • Add raw (and an internal tag) to LocaleProxy, and allow createLocaleProxy() to accept an existing LocaleProxy.
  • Update modules/tests to use definitions.raw where non-throwing access to locale definitions is needed.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/internal/locale-proxy.spec.ts Adds a test for passing a LocaleProxy into createLocaleProxy().
src/modules/person/index.ts Switches last-name pattern lookup to use raw definitions.
src/modules/helpers/eval.ts Updates fakeEval default entrypoints to use raw definitions.
src/internal/locale-proxy.ts Extends LocaleProxy with raw + tag and updates proxy creation logic.
src/faker.ts Removes stored definitions field; exposes definitions/rawDefinitions via getters.
src/core.ts Makes FakerCore.locale a LocaleProxy and ensures core construction proxies locales.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/faker.ts
Comment thread src/internal/locale-proxy.ts
Comment thread src/internal/locale-proxy.ts
Comment thread test/internal/locale-proxy.spec.ts
Comment thread src/internal/locale-proxy.ts
Shinigami92
Shinigami92 previously approved these changes Apr 20, 2026
@ST-DDT ST-DDT removed the s: needs decision Needs team/maintainer decision label Apr 20, 2026
@ST-DDT ST-DDT changed the title refactor(core): expose locale as LocaleProxy refactor(core): expose core.locale as LocaleProxy Apr 20, 2026
Comment thread src/internal/locale-proxy.ts
Comment thread src/internal/locale-proxy.ts
Comment thread src/internal/locale-proxy.ts
Comment thread src/internal/locale-proxy.ts
Comment thread src/core.ts
@ST-DDT ST-DDT added this pull request to the merge queue Apr 22, 2026
Merged via the queue into next with commit a7825a7 Apr 22, 2026
23 checks passed
@ST-DDT ST-DDT deleted the refactor/locale-proxy-in-core branch April 22, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: refactor PR that affects the runtime behavior, but doesn't add new features or fixes bugs p: 2-high Fix main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants