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

Revert to custom export conditions #68

Closed
wants to merge 7 commits into from

Conversation

theseanl
Copy link
Contributor

@theseanl theseanl commented Jan 28, 2024

In #67, I initially achieved its goal via custom condition that points to .ts source files and applied by specifying it in tsconfig and esbuild configs, but a we have made a choice to make import directly point to .ts source files instead.

It turned out that this later decision conflicts with one's ability to locally install a development version of a package to other third-party package and test it. It is not right to make import point to non-js source files, because the behavior of import is dictated by nodejs and is not customizable. Thus, this PR reverts the latest change.

Previously, typescript project references were used to wire imports
between workspace packages. Now this is done by package.json export
conditions. This nodejs feature has already been used to support
consuming packages in both esm and cjs format. We add an artificial
condition "_bundle", and use the respective bundler's export conditions
feature https://esbuild.github.io/api/#conditions and https://www.typescriptlang.org/tsconfig#customConditions
to achieve that IDE and TS compiler resolve any workspace package
imports to their respective Typescript source file, not their build
output .d.ts files.

This has an additional benefit of reducing bundle size of cjs build.
Previously, CJS build operated on ESM build output; They fed
dist/index.js files to esbuild. This changes this so that esbuild
directly operates on Typescript source files even in CJS build. As
esbuild will have more information, it will be able to better tree-shake
unused codes.
also used double quotes for interoparabilities with Windows
Since package.json is re-written before publishing, we are free to point
`import` condition to `.ts` source files. However, CLI tests need to be
able to resolve to `dist/*.js` files, so a custom condition `prebuilt`
pointing to those are kept in every package.json.
@siefkenj
Copy link
Owner

You're talking about running npm link inside the various directories? If npm link is run from inside the dist directory, then this shouldn't be an issue (provided the package.json has been created in that directory). I would prefer a solution of adding the creation of package.json to the build process and having people link directly in the dist folder.

This should come with an explanation in the top-level readme and an npm run link script that automatically calls npm link from inside each dist directory.

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