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

feat: esm and cjs exports #426

Closed
wants to merge 3 commits into from
Closed

feat: esm and cjs exports #426

wants to merge 3 commits into from

Conversation

kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Sep 20, 2023

🧰 Changes

Builds on #425 to build exports for both CJS and ESM.

@kanadgupta kanadgupta changed the base branch from main to ts-strict-mode September 20, 2023 17:00
@kanadgupta kanadgupta changed the title Esm and cjs feat: esm and cjs exports Sep 20, 2023
@kanadgupta
Copy link
Member Author

this PR is giving me a surprising amount of grief, which I believe is a tsup bug 😬

  • if the cjsInterop is not included in the tsup config:

    • the CJS types don't match the actual function signature (i.e., TS only types fetchHAR if the require statement is const fetchHAR = require('.').default; when the actual JS code will only run if it's const fetchHAR = require('.').default;. this is correctly getting flagged by attw:

      CleanShot 2023-09-20 at 13 27 30@2x
  • if the cjsInterop: truein the tsup config:

    • attempting to run a CJS file with the package loaded via CJS just... doesn't work at all. it seems to be an issue with how tsup is constructing the module.exports — if I comment out the last line in the CJS dist file, it works properly:

      CleanShot 2023-09-20 at 13 34 44@2x
    • TS appears to be consistent with the typing at least, and attw agrees:

      CleanShot 2023-09-20 at 13 29 53@2x

feels like a frustrating two-steps-forward-two-steps-back dance here, so I'm going to close this out and I might create an issue in tsup at some point.

@kanadgupta kanadgupta closed this Sep 20, 2023
@kanadgupta kanadgupta deleted the esm-and-cjs branch September 20, 2023 18:38
@kanadgupta kanadgupta mentioned this pull request Sep 20, 2023
7 tasks
@kanadgupta kanadgupta restored the esm-and-cjs branch September 21, 2023 20:56
@kanadgupta kanadgupta mentioned this pull request Sep 21, 2023
2 tasks
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.

1 participant