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

Treat re-exports of '*' from empty files as ESM #9079

Merged
merged 2 commits into from
Jun 8, 2023
Merged

Conversation

lettertwo
Copy link
Member

@lettertwo lettertwo commented Jun 7, 2023

↪️ Pull Request

Background

Many packages written in e.g., TypeScript are built for publishing to NPM by stripping types from the source files. This can lead to situations where ‘types-only’ files are stripped of all of their type definitions, leaving completely empty files behind. If there are imports from these ‘types-only’ files that are not also stripped (e.g., they re-export * from the module without the type keyword), then the resulting package ships with a dependency on a completely empty file.

Current Behavior

This is a conundrum for Parcel, as it’s not clear what to do about the empty file when resolving. The current behavior is to treat these files as ‘dynamic CJS’ (to account for scenarios where module.exports might be modified outside of the module itself).

The Problem

However, this is suboptimal for what is probably the most common case (as described in the first paragraph); ideally Parcel would treat these empty files as ESM with empty exports, and thus avoid the deopt to dynamic resolution altogether.

Suggested Change

The compromise solution here is to treat these empty files as ESM only if the asset is known to have no side effects (e.g., the package defines sideEffects: false), and keep the 'dynamic CJS' behavior as the fallback.

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@lettertwo lettertwo changed the title Re export all empty Treat re-exports of '*' from empty files as ESM Jun 7, 2023
@lettertwo lettertwo requested a review from mischnic June 7, 2023 19:37
Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be ok

@lettertwo lettertwo merged commit 4db35cd into v2 Jun 8, 2023
14 of 16 checks passed
@lettertwo lettertwo deleted the re-export-all-empty branch June 8, 2023 19:32
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.

None yet

3 participants