Skip to content

feat: transform core modules to standalone module functions#3857

Open
ST-DDT wants to merge 4 commits into
nextfrom
feat/standalone/core-modules
Open

feat: transform core modules to standalone module functions#3857
ST-DDT wants to merge 4 commits into
nextfrom
feat/standalone/core-modules

Conversation

@ST-DDT
Copy link
Copy Markdown
Member

@ST-DDT ST-DDT commented May 23, 2026

Split from #3748


Transforms the core modules to standalone module functions.

These core modules are interdependent and thus cannot be transformed on their own.

  • DatatypeModule
  • HelpersModule
  • NumberModule
  • StringModule

Most of the conversion steps are done automatically, but some changes have been done manually.

Please note that I renamed some util files to _, to distinguish files that export an API SMF from those that don't.

This PR can be reviewed more easily using two ways

1. Compare automated steps vs PR

#checkout PR
git reset HEAD~1 --hard
pnpm tsx scripts/temp-tranform-once.ts 
pnpm tsx scripts/generate-module-tree.ts
mv src/modules/helpers/eval.ts src/modules/helpers/_eval.ts
mv src/modules/helpers/luhn-check.ts src/modules/helpers/_luhn-check.ts 
git add .
git diff origin/feat/standalone/core-modules
#There will be quite a bit of delta
#Mostly from functions being moved to separate/different files

2. Verify no diff in modules to #3748 and look at the manual transform commits

#checkout PR
git diff origin/feat/standalone-module-functions -- src/modules/<ModuleName>
#No Diff expected

Check the individual module transform commits:


Please do not merge any PRs changing anything in the modules after this PR until all modules are transformed.

@ST-DDT ST-DDT added this to the v10.x milestone May 23, 2026
@ST-DDT ST-DDT self-assigned this May 23, 2026
@ST-DDT ST-DDT requested a review from a team as a code owner May 23, 2026 15:17
@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent m: datatype Something is referring to the datatype module m: helpers Something is referring to the helpers module m: string Something is referring to the string module m: number Something is referring to the number module labels May 23, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 23, 2026

Deploy Preview for fakerjs ready!

Name Link
🔨 Latest commit 4668dfe
🔍 Latest deploy log https://app.netlify.com/projects/fakerjs/deploys/6a215929063c420008981f9b
😎 Deploy Preview https://deploy-preview-3857.fakerjs.dev
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@ST-DDT ST-DDT requested a review from a team May 23, 2026 15:17
@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

❌ Patch coverage is 97.59863% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.89%. Comparing base (03a1682) to head (4668dfe).

Files with missing lines Patch % Lines
src/modules/helpers/from-reg-exp.ts 94.11% 5 Missing and 2 partials ⚠️
src/modules/helpers/replace-credit-card-symbols.ts 88.00% 6 Missing ⚠️
src/modules/helpers/weighted-array-element.ts 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #3857      +/-   ##
==========================================
- Coverage   98.92%   98.89%   -0.03%     
==========================================
  Files         910      947      +37     
  Lines        3161     3262     +101     
  Branches      581      588       +7     
==========================================
+ Hits         3127     3226      +99     
- Misses         30       32       +2     
  Partials        4        4              
Files with missing lines Coverage Δ
src/modules/datatype/boolean.ts 100.00% <100.00%> (ø)
src/modules/datatype/index.ts 100.00% <100.00%> (ø)
src/modules/helpers/_eval.ts 95.65% <ø> (ø)
src/modules/helpers/_luhn-check.ts 100.00% <ø> (ø)
src/modules/helpers/array-element.ts 100.00% <100.00%> (ø)
src/modules/helpers/array-elements.ts 100.00% <100.00%> (ø)
src/modules/helpers/enum-value.ts 100.00% <100.00%> (ø)
src/modules/helpers/index.ts 100.00% <100.00%> (+4.72%) ⬆️
src/modules/helpers/maybe.ts 100.00% <100.00%> (ø)
src/modules/helpers/multiple.ts 100.00% <100.00%> (ø)
... and 35 more

... and 1 file 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.

@Shinigami92
Copy link
Copy Markdown
Member

discussable arguable opinionated feedback

this feels quite messy
the problem I have with it, is that you mentally need to know the entire faker structure in your head instead of exploring it by e.g. namespace or one import

this is right now just internal code, I would never like to ship something like this for customers
customers should be able to use e.g. import { datatypeBoolean, helpersArrayElement } from '@faker-js/faker' and so on

maybe we can have something like this also internally (and still don't 🦆-up 🌲-🫨)

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Jun 5, 2026

Just for clarification:

Would you like for us to use qualified method names from the start?
E.g. export function helpersArrayElement
Instead of the rename during import (if the name collides).
Or something else?

This is kind of relevant for the later public API: Will we only export from root or also export via the module paths e.g. @faker-js/faker/module/helpers? Or will we adapt our own naming scheme such as fakeArrayElement similar to useRouter?

@Shinigami92
Copy link
Copy Markdown
Member

Shinigami92 commented Jun 5, 2026

Just for clarification:

Would you like for us to use qualified method names from the start? E.g. export function helpersArrayElement Instead of the rename during import (if the name collides). Or something else?

Partly that was my thought regarding yes, but I did not fully thought that through yet.
My greater problem is more that we e.g. could use internally imports like:

// instead of
import { arrayElement as helpersArrayElement } from './array-element';
import { arrayElements as helpersArrayElements } from './array-elements';
import { enumValue as helpersEnumValue } from './enum-value';

// something like
import { arrayElement as helpersArrayElement, arrayElements as helpersArrayElements, enumValue as helpersEnumValue } from '../helpers';

but ../helpers is equals ./index and this is the file we are just in... so I understand that problem

thinking further...

maybe we move the module class into a separate file, so we can import from index... 🦆 might not work either, because we would need to import the module class in index to pass further to top again 🤔 ...

best what we could try to achieve would be something like:

import * as helpers from './?whatever?';
import * as helpers from './?whatever?';
import * as string from '../string';

export class SimpleHelpersModule extends SimpleModuleBase {
  slugify(string: string = ''): string {
    return helpers.slugify(this.faker.fakerCore, string);
  }

  // string.alphanumeric

I know that what I start to propose here might need fundamental movements of files, and this is why I raising this right now (I'm sorry 🥲)

I can also later (not in company-working-hours try to thinker with claude about this, maybe it has some enlightening ideas)

Edit:
I'm raising this right now, because I think this is how we maintainers, contributors and even AIs will need to live and work in the future codebase of Faker. This is such a fundamental shaping. And I did not delivered the solution yet, just uncovered the "problem" (mental load).

@ST-DDT
Copy link
Copy Markdown
Member Author

ST-DDT commented Jun 5, 2026

IMO moving the module to a separate file (and not including it in the index) would work for me too.

Maybe prepare a proposal so that we can talk about it later. Though I dont have time this weekend.

Note: I ammended my previous comment. Not sure whether you have seen it.

@Shinigami92
Copy link
Copy Markdown
Member

IMO moving the module to a separate file (and not including it in the index) would work for me too.

👍

Maybe prepare a proposal so that we can talk about it later. Though I dont have time this weekend.

🤝 I will also hide myself this weekend deeply into Gothic 1 Remake 😇

Note: I ammended my previous comment. Not sure whether you have seen it.

THX! I have NOT seen it 👍

It is kinda a sibling topic, because this is then how we structure the external API
I would be fine maybe even ship and allow both: { arrayElements } from @faker-js/faker/module/helpers AND { helpersArrayElements } from @faker-js/faker

But maybe we should outsource this discussion to a separate place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: feature Request for new feature m: datatype Something is referring to the datatype module m: helpers Something is referring to the helpers module m: number Something is referring to the number module m: string Something is referring to the string module p: 1-normal Nothing urgent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants