-
Notifications
You must be signed in to change notification settings - Fork 185
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
build: allow use by TypeScript projects with bundler
/node16
config
#2084
build: allow use by TypeScript projects with bundler
/node16
config
#2084
Conversation
Before this change: ``` $ cd packages/dev-tools $ pnpm tsc --declaration src/router.tsx:12:14 - error TS2742: The inferred type of 'router' cannot be named without a reference to '.pnpm/@remix-run+router@1.6.0/node_modules/@remix-run/router'. This is likely not portable. A type annotation is necessary. 12 export const router = createMemoryRouter( ~~~~~~ Found 1 error in src/router.tsx:12 ```
Without this change, error on tsup: ``` Error: namespace must have a "ModuleBlock" body. > 1 | declare module "prettier-plugin-solidity"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
🦋 Changeset detectedLatest commit: 257e2f9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -1 +1 @@ | |||
declare module "prettier-plugin-solidity"; | |||
declare module "prettier-plugin-solidity" {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tsup's internal dts generation process doesn't support the original syntax, so I've changed it to a format that both tsc and tsup accept. There is no change in meaning in this context. Without this, the following error occurs on tsup:
Error: namespace must have a "ModuleBlock" body.
> 1 | declare module "prettier-plugin-solidity";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
💯 🎉 |
Thank you! CI looks happy, so I'm gonna merge this. Is there anything CI-wise we should wire up to ensure we can keep this level of compatibility? |
Good point. We should ensure CI covers all supported user environments to avoid accidentally breaking compatibility, so I should add a test for non- |
This pull request enables MUD users with
moduleResolution
set tobundler
ornode16
in theirtsconfig.json
to passtsc
by generating.d.ts
files during the build. After this change, users withbundler
/node16
config can use MUD packages without being affected by MUD's internal TypeScript setup, as they won't need to use the.ts
files of MUD packages.Problem
Currently,
moduleResolution: node10
is the only supported option for using MUD packages, which is not ideal for most users. For example, here is the config I'd like to use:However, this configuration results in the following error (similar errors also occur in
client/
):This error occurs because, under the
moduleResolution: bundler
setting, tsc refers to thepackage.json
exports
field of the MUD package to find the.js
file but fails to find the corresponding.d.ts
file.This issue can also be confirmed using the
@arethetypeswrong/cli
tool:Solution
To resolve this, this PR enables the generation of
.d.ts
files during the build. MUD packages use tsup for TypeScript builds, and simply settingdts: true
intsup.config.ts
suffices..ts
files cannot replace.d.ts
files in libraries. Using.ts
files as type declarations forces users to align theirtsconfig.json
with that of the libraries.The targeted packages are under
./packages/
, except for:With this change, the previously mentioned errors are resolved, and the project works without issues. In projects configured with
bundler
ornode16
, tsc no longer asks for the installation of libraries like@types/prettier
and@types/react-dom
. Additionally,tsc --noEmit
time decreased from 13 seconds to 4 seconds undertemplates/vanilla/packages/client
on my mac, as tsc does not need to process MUD's.ts
files.@arethetypeswrong/cli
outputs results like this for the packages:(MUD packages are pure ESM and are not expected to be used from CJS.)
This change does not impact existing users with
node10
, as their tsc does not refer to theexports
fields in MUD packages, and the built.js
files within MUD packages, used by their bundlers, remain unchanged.The downside is an increase in build time. However, it is not significant, as tsup generates
.js
and.d.ts
files in parallel. Here is a comparison on my mac between the main branch and this branch using a build command that disables all cache:git clean -d -f -x -q && pnpm install && time pnpm build --force
.Main branch (dts disabled):
This branch (dts enabled):