Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

fix: skip transforming CommonJS files #2

Merged
merged 17 commits into from
May 17, 2022
Merged

Conversation

privatenumber
Copy link
Member

@privatenumber privatenumber commented May 13, 2022

Problem

  • Node.js is unable to detect whether a .ts file is commonjs/module, and assumes all .ts files are module. This fails when there are TS files that expect to be executed in a CJS context (eg. using __dirname/__filename).

  • This loader should not transform .cts files to ESM because it's technically a CJS file (with import/export syntax support). It should be able to access __filename, and therefore, must be delegated to the cjs-loader.

closes privatenumber/tsx#2

Changes

  • Added package type detection, allowing TS files to be skipped if the package type is commonjs, letting cjs-loader handle transforming TS files in commonjs contexts.
  • Updates core-utils to transform dynamic imports to interop with modules that have __esModule.

@privatenumber privatenumber marked this pull request as ready for review May 13, 2022 04:28
@privatenumber privatenumber changed the title fix: ignore ts in cjs contexts fix: skip transforming CommonJS files May 17, 2022
@privatenumber privatenumber merged commit cbb32c5 into develop May 17, 2022
@privatenumber privatenumber deleted the handle-cjs-package branch May 17, 2022 16:29
@privatenumber
Copy link
Member Author

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support named imports for JSON
1 participant