Skip to content
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

Fix requires of external CommonJS SWC helpers #8693

Merged
merged 1 commit into from
Dec 14, 2022
Merged

Fix requires of external CommonJS SWC helpers #8693

merged 1 commit into from
Dec 14, 2022

Conversation

devongovett
Copy link
Member

Fixes a regression introduced by #8555. Reproduction

The root cause was that due to library mode rewriting SWC helpers for CJS libraries, the dep had a placeholder: https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/js/core/src/dependency_collector.rs#L124-L125

Then, when we build our dep map, we use the placeholder rather than the original specifier + "esm":

dep.meta.placeholder ??
dep.specifier +
(dep.specifierType === 'esm' ? dep.specifierType : ''),

But when looking up the dep, we would still append "esm", leading no dep to be found and therefore no symbols replaced later on:

let specifierType = '';
if (kind === 'Import' || kind === 'Export') {
specifierType = 'esm';
}
let dep = deps.get(source + specifierType);

To fix this, I've changed the way this works so we don't append "esm" but instead use a placeholder for CJS deps on the rust side. This fixes the original issue where CJS and ESM imports for the same specifier wouldn't work, without needing additional metadata. To get that to work, I had to add specifiers for external modules to the dev packager so we remap from the placeholder to the original specifier when requiring them.

@parcel-benchmark
Copy link

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.97s -33.00ms
Cached 422.00ms -42.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 108.00ms -218.00ms 🚀
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 109.00ms -219.00ms 🚀
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 108.00ms -221.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 326.00ms +219.00ms ⚠️
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 327.00ms +220.00ms ⚠️
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 326.00ms +218.00ms ⚠️

React HackerNews ✅

Timings

Description Time Difference
Cold 12.42s -47.00ms
Cached 530.00ms +1.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 2.21m -429.00ms
Cached 2.65s +17.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Three.js ✅

Timings

Description Time Difference
Cold 8.92s -30.00ms
Cached 325.00ms +2.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

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.

2 participants