-
-
Notifications
You must be signed in to change notification settings - Fork 980
refactor!: experimental v10 #3513
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
Draft
Shinigami92
wants to merge
2
commits into
test-cjs-require
Choose a base branch
from
experimental-v10
base: test-cjs-require
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,28 +67,20 @@ | |
"type": "module", | ||
"exports": { | ||
".": { | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
}, | ||
"default": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"./locale/*": { | ||
"require": { | ||
"types": "./dist/locale/*.d.cts", | ||
"default": "./dist/locale/*.cjs" | ||
}, | ||
"default": { | ||
"types": "./dist/locale/*.d.ts", | ||
"default": "./dist/locale/*.js" | ||
} | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "dist/index.cjs", | ||
"main": "dist/index.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: I could NOT remove this line, because otherwise the |
||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"typesVersions": { | ||
|
@@ -126,7 +118,7 @@ | |
"eslint-plugin-prettier": "5.2.6", | ||
"eslint-plugin-unicorn": "58.0.0", | ||
"jiti": "2.4.2", | ||
"npm-run-all2": "7.0.2", | ||
"npm-run-all2": "8.0.1", | ||
"prettier": "3.5.3", | ||
"prettier-plugin-organize-imports": "4.1.0", | ||
"prettier-plugin-packagejson": "2.5.10", | ||
|
@@ -146,8 +138,8 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"engines": { | ||
"node": ">=18.0.0", | ||
"npm": ">=9.0.0" | ||
"node": ">=20.19.0", | ||
"npm": ">=10.0.0" | ||
}, | ||
"pnpm": { | ||
"ignoredBuiltDependencies": [ | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll put this question in a file comment. That way we can resolve the discussion at the end and do not have trillions of comments to scroll through.
How does removing the CJS entries benefit the Faker project directly? All of the changes presented are infrastructural related. I fail to see why we would deny a good amount of our users the ability to continue using our library when there is no compelling reason to exclude them.
From what I can see, the only apparent benefit is a reduction in build size (and consequently download size) since we would no longer have to build both ESM and CJS versions. While reducing the package size is certainly a goal for Faker I want to support for environmental reasons, achieving that at the cost of backward compatibility does not seem like the best approach to me.
Instead, I'd like to revisit my solution from discussion #3103. By transitioning from a monolithic project structure to a package-based one, we could potentially reduce the download size to even less than half of its current size, since users would only install the modules they actually need. I recognize that this approach would be challenging to implement, but it would certainly be more inclusive than discarding parts of our community entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is literally exactly what the benefit is.
As far as I can tell, with the new
require(esm)
support by NodeJS, we do not have any downsides anymore, and NodeJS 18 is EOL as well already.However, as I'm still open to refactor the project later to a mono-repo with separated packages, this would be a huge task and potentially also based on how we design the new package structure, a breaking change for the users.
And as
cjs
is an actively dying thing, we would focus power into something that would die sooner or later anyways. So why doing it in the first place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which versions of Node support require(esm)? Has it been backported to any LTS versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I posted a link in the PR's description. According to this, it looks like that it was backported.
Beside this, even our CI test using Node v20 is running green. And we have a test for checking a require from dist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tested this out with https://www.npmjs.com/package/node-fetch which went ESM-only in node-fetch@3
With this sample code which works in node-fetch@2
If you update to node-fetch@3 using Node 20.16.0 for example you get
If you update to Node 20.19.0 the error now shows
Updating the code to
works.
So basically we would need to ensure that CJS users both:
.default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, we can document this in the release notes / changelog, or if we have a migration guide for v10 in that.
Incorrect, faker does not have a default export. So this isn't even required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that in the documentation. Under these circumstances, I'll take back my previous concerns.
A new concern that arises would be the stability level of 1.2. While no breaking changes are anticipates, they might still happen. That's just something I'm thinking about.
I assume that we would also enforce these requirements by correctly adjusting the
engines
field in ourpackage.json
. The changes you listed on top where intended for enhancing the DX/UX further than the bare requirements, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, you are correct about the
engines
field!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think if we do this for v10 then it will definitely make sense to increase the minimum required versions in the engines field to match the versions that support this new syntax for importing ESM modules from CJS projects.
I believe the "engines" field is only advisory though. So even if you specify minimum v20.19.0 you can still install the library if you are using say v20.9.0.
So we should make sure our upgrading guide is clear on what version has supported and any error messages you might get if you are using an older Node version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.npmjs.com/cli/v11/configuring-npm/package-json#engines
So it will already show a warning