-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[RFC] Next Step for @swc/helpers #7157
Comments
I think this is a good direction overall, and IMHO, a breaking change of |
With this RFC design, the paths of // src/_array_like_to_array.mjs
export { _array_like_to_array as default } from "../esm/_array_like_to_array.js"; // lib/_array_like_to_array.js
module.exports = {
get default() {
return require("../cjs/_array_like_to_array.cjs")._array_like_to_array;
}
} Note: ⭕ old version But, is it worthwhile to do so? I cannot find the reason for upgrading |
It makes sense. Then I think it's fine anyway. |
Compatibility result
Note:
https://gist.github.com/a5e9619b8d797d2736bc08b6d74dae31.git |
Guidelines from webpack
|
**BREAKING CHANGE:** Breaking changes for `@swc/helpers`. A new major version `0.5.0` is required. **Related issue:** - Closes #7157
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the feature
Motivation
Current issues with @swc/helpers:
default export
used in helpersThe use of
default export
incurs theinteropRequireDefault
overhead when transpiling to CJS.We should use named export to avoid it.
Additionally, keeping the exported function name consistent with the filename can reduce conversion complexity and aid in debugging.
CJS and ESM should have different module formats, but this should not be explicitly done in
@swc/core
.We can use a unified import path and rely on the exports field to automatically select the suitable module format for runtime/bundler.
Better Way to introduce
@swc/helpers
1. use named export
This is a simple changes and also the reason for breaking changes.
2. unified import path
To ensure semantic clarity and ease of debugging, we have opted to use
esm
andcjs
path instead ofsrc
andlib
.Taking
_array_like_to_array
as an example, after relocating the module, the directory structure is as follows.There are a few details to note, such as utilizing
.js
as the file extension for esmand declaring
type: module
in thepackage.json
.This prioritizes the use of esm modules and hints the bundler to use them as much as possible.
By adding the
exports
field to thepackage.json
file, we can benefit from conditional exports and use a uniform import path during translation.note: I have chosen the path
_
here to ensure the shortest possible pathway.To ensure compatibility with bundlers/runtimes that do not support conditional exports,
we add the file
./_/_array_like_to_array/package.json
with the following content:Babel plugin or link to the feature description
No response
Additional context
These changes would require introducing breaking changes, meaning that @swc/helpers would need to be updated to version 0.5.0.
I have published a @magic-akari/swc-helpers-experiments package. Compatibility testing is currently in progress and I will update the test results here.
The text was updated successfully, but these errors were encountered: