Skip to content

Comments

feat: make require('./foo.json') work as expected even if the json is transformed to JS by a custom plugin#4984

Merged
IWANABETHATGUY merged 1 commit intomainfrom
06-17-fix_3640
Jun 17, 2025
Merged

feat: make require('./foo.json') work as expected even if the json is transformed to JS by a custom plugin#4984
IWANABETHATGUY merged 1 commit intomainfrom
06-17-fix_3640

Conversation

@IWANABETHATGUY
Copy link
Member

@IWANABETHATGUY IWANABETHATGUY commented Jun 17, 2025

  1. Compatible with the Rollup CommonJS plugin;
  2. Note: only works if experimental.viteMode is enabled cc @sapphi-red, this is because our default behavior is aalignedwith esbuild and webpack already (Both of them prefer interop correctness, so do we), I am hesitant to enable it by default.
    Closed [Feature Request]: make require('./foo.json') work as expected even if the json is transformed to JS by a custom plugin #3640

Copy link
Member Author

@netlify
Copy link

netlify bot commented Jun 17, 2025

Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 3802329
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/68511dd05b3c62000859767f
😎 Deploy Preview https://deploy-preview-4984--rolldown-rs.netlify.app
📱 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.

@sapphi-red
Copy link
Member

sapphi-red commented Jun 17, 2025

Just to confirm, is this a temporary solution until "Option 1" in #3640 (module.exports export) is implemented? (As I believe we will support that one in the future)

@IWANABETHATGUY
Copy link
Member Author

IWANABETHATGUY commented Jun 17, 2025

Just to confirm, is this a temporary solution until "Option 1" in #3640 (module.exports export) is implemented? (As I believe we will support that one in the future)

After the pr is landed the option one is no longer needed, we already use a different way to handle require('.json') even if the moduleType is js, although it is a little bit tricky, just like the rollup commonjs plugin. See the test as an example.

@github-actions
Copy link
Contributor

Benchmarks Rust

group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     82.9±2.17ms        ? ?/sec    1.02     84.5±2.38ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     96.1±3.16ms        ? ?/sec    1.00     96.3±2.66ms        ? ?/sec
bundle/bundle@rome_ts                                        1.02    120.7±2.26ms        ? ?/sec    1.00    118.4±2.12ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    135.2±2.60ms        ? ?/sec    1.01    137.1±3.50ms        ? ?/sec
bundle/bundle@threejs                                        1.03     44.2±2.98ms        ? ?/sec    1.00     42.8±0.57ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.01     49.7±0.65ms        ? ?/sec    1.00     49.4±0.58ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01    460.8±6.37ms        ? ?/sec    1.00    457.0±5.70ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.01    535.5±4.79ms        ? ?/sec    1.00    530.2±8.92ms        ? ?/sec
scan/scan@rome_ts                                            1.00     92.1±1.96ms        ? ?/sec    1.03     94.6±2.14ms        ? ?/sec
scan/scan@threejs                                            1.00     32.5±0.48ms        ? ?/sec    1.02     33.2±2.10ms        ? ?/sec
scan/scan@threejs10x                                         1.00    333.4±4.72ms        ? ?/sec    1.01    338.2±5.61ms        ? ?/sec

@IWANABETHATGUY IWANABETHATGUY changed the title fix: 3640 feat: make require('./foo.json') work as expected even if the json is transformed to JS by a custom plugin Jun 17, 2025
@IWANABETHATGUY IWANABETHATGUY marked this pull request as ready for review June 17, 2025 08:04
@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Jun 17, 2025
@IWANABETHATGUY
Copy link
Member Author

I test with #3640 (comment), it works fine when enable viteMode

@IWANABETHATGUY IWANABETHATGUY removed this pull request from the merge queue due to a manual request Jun 17, 2025
@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Jun 17, 2025
@sapphi-red
Copy link
Member

sapphi-red commented Jun 17, 2025

Just to confirm, is this a temporary solution until "Option 1" in #3640 (module.exports export) is implemented? (As I believe we will support that one in the future)

After the pr is landed the option one is no longer needed, we already use a different way to handle require('.json') even if the moduleType is js, although it is a little bit tricky, just like the rollup commonjs plugin. See the test as an example.

Yes, this PR would work for Vite's case. But I think we'll still need to implement Option 1 in the future as it's supported by Node.js. Or do we plan not to support that intentionally?

@IWANABETHATGUY
Copy link
Member Author

IWANABETHATGUY commented Jun 17, 2025

Just to confirm, is this a temporary solution until "Option 1" in #3640 (module.exports export) is implemented? (As I believe we will support that one in the future)

After the pr is landed the option one is no longer needed, we already use a different way to handle require('.json') even if the moduleType is js, although it is a little bit tricky, just like the rollup commonjs plugin. See the test as an example.

Yes, this PR would work for Vite's case. But I think we'll still need to implement Option 1 in the future as it's supported by Node.js. Or do we plan not to support that intentionally?

No, I just mean for this case it is not needed. We could support it.

@IWANABETHATGUY
Copy link
Member Author

You could open another issue to track it if it is necessary.

Merged via the queue into main with commit 13e7afc Jun 17, 2025
29 checks passed
@IWANABETHATGUY IWANABETHATGUY deleted the 06-17-fix_3640 branch June 17, 2025 08:18
github-actions bot pushed a commit that referenced this pull request Jun 17, 2025
## [1.0.0-beta.17] - 2025-06-17

### 🚀 Features

- binding: feat(binding): always use the same `BindingBundler` to create `BindingBundlerImpl` for the same `RolldownBuild` by @hyf0 in [#4985](#4985)
- debug: feat(debug): cache large string by @hyf0 in [#4882](#4882)
- feat: make require('./foo.json') work as expected even if the json is transformed to JS by a custom plugin by @IWANABETHATGUY in [#4984](#4984)
- feat: add diagnostic for multiple entries with UMD/IIFE formats by @shulaoda in [#4954](#4954)

### 🐛 Bug Fixes

- plugin/vite-resolve: fix(plugin/vite-resolve): importing an optional peer dep should throw an runtime error by @sapphi-red in [#4980](#4980)
- fix: upgrade napi, fix wasm url by @sxzz in [#4958](#4958)
- fix: should rewrite hmr related ast after test if `experimental.hmr` is enabled. by @IWANABETHATGUY in [#4972](#4972)

### 💼 Other

- build: provide `"type": "module"` in `package.json` by @iiio2 in [#4974](#4974)

### 🚜 Refactor

- binding: refactor(binding): rename `Bundler` to `BindingBundleImpl` by @hyf0 in [#4983](#4983)
- rolldown: refactor(rolldown): migrate to ESM package by @sxzz in [#4959](#4959)

### 📚 Documentation

- docs: explain how to transpile legacy decorators by @hyf0 in [#4989](#4989)
- code-splitting: docs(code-splitting): make terms bold instead of wrapped with inline code block by @hyf0 in [#4975](#4975)
- docs: improve advanced chunks by @hyf0 in [#4966](#4966)
- docs: refine code splitting guide by @sapphi-red in [#4969](#4969)

### 🧪 Testing

- test: place empty `package.json` to prevent all files to be treated as node mode by @sapphi-red in [#4979](#4979)

### ⚙️ Miscellaneous Tasks

- infra: chore(infra): ensure `pnpm install` for common commands by @hyf0 in [#4987](#4987)
- browser: chore(browser): add `@oxc-project/runtime` by @shulaoda in [#4988](#4988)
- deps: chore(deps): update dependency tsdown to v0.12.8 by @renovate[bot] in [#4977](#4977)
- deps: chore(deps): update npm packages (major) by @renovate[bot] in [#4963](#4963)
- deps: chore(deps): lock file maintenance npm packages by @renovate[bot] in [#4967](#4967)
- deps: chore(deps): lock file maintenance rust crates by @renovate[bot] in [#4965](#4965)
- deps: chore(deps): lock file maintenance npm packages by @renovate[bot] in [#4964](#4964)
- deps: chore(deps): update github-actions by @renovate[bot] in [#4962](#4962)

### ❤️ New Contributors

* @iiio2 made their first contribution in [#4974](#4974)
github-merge-queue bot pushed a commit that referenced this pull request Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: make require('./foo.json') work as expected even if the json is transformed to JS by a custom plugin

3 participants