Skip to content

fix(node): fix type errors #1642

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

Merged
merged 5 commits into from
Jul 16, 2024
Merged

Conversation

hi-ogawa
Copy link
Collaborator

Description

This PR renames rust side struct to match js naming BindingJsonSourcemap to workaround napi's inconsistent dts emit. I also added build-types-check to verify type check passes for its package types exports (similar to how vite does).

I'm not sure changing rust side naming is ideal. Another workaround is to prevent napi renaming by napi_derive::napi(object, js_name = "BindingJSONSourcemap")). I don't think I can figure the fix on napi side, so I thought it's worth suggesting a quick fix here. Please let me know what you think. Thanks!

hi-ogawa added 3 commits July 16, 2024 15:33

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Copy link

netlify bot commented Jul 16, 2024

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 56aa161
🔍 Latest deploy log https://app.netlify.com/sites/rolldown-rs/deploys/66964938703730000875520d

@@ -113,7 +113,7 @@ function __napi_rs_initialize_modules(__napiInstance) {
__napiInstance.exports['__napi_register__BindingRenderedModule_struct_79']?.()
__napiInstance.exports['__napi_register__AliasItem_struct_80']?.()
__napiInstance.exports['__napi_register__BindingSourcemap_struct_81']?.()
__napiInstance.exports['__napi_register__BindingJSONSourcemap_struct_82']?.()
__napiInstance.exports['__napi_register__BindingJsonSourcemap_struct_82']?.()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have a question about wasi output. It looks like there are two similar looking code here under packages/rolldown/src and also at the package root packages/rolldown.

When I build locally just build and just build wasi, the ones in packages/rolldown/src updated but package/rolldown hasn't changed. Could I be missing some local setup?

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused too. You could just leave it there for now.

Copy link
Member

Choose a reason for hiding this comment

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

Is this only for type check on dist? Does the situation that compiled dts is wrong happen a lot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does the situation that compiled dts is wrong happen a lot?

I don't think it usually happens since if it's emitted by tsc or rollup dts, then they are supposed to be correct. (actually I'm not sure why current build-types script's tsc is not able to spot typo like xxxJSON and xxxJson).

As in the comment, I mostly copied the one from https://github.com/vitejs/vite/blob/main/packages/vite/tsconfig.check.json, but it might be overkill to do the same on rolldown.

@IWANABETHATGUY
Copy link
Member

The pull request probably not enough to fix all issues, I pull your branch and link to local, there are still 17 type errors exists:

../../../rolldown/packages/rolldown/dist/types/utils/asset-source.d.ts:1:36 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import { BindingAssetSource } from '../binding';
                                     ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/options/normalized-input-options.d.ts:1:104 - error TS2307: Cannot find module '../rollup' or its corresponding type declarations.

1 import type { LogLevelOption, RollupLog, NormalizedInputOptions as RollupNormalizedInputOptions } from '../rollup';
                                                                                                         ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/types/sourcemap.d.ts:1:34 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import { BindingSourcemap } from '../binding';
                                   ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/plugin-context-data.d.ts:1:38 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import { BindingPluginContext } from '../binding';
                                       ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/plugin-context.d.ts:1:51 - error TS2307: Cannot find module '../rollup' or its corresponding type declarations.

1 import type { RollupError, LoggingFunction } from '../rollup';
                                                    ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/plugin-context.d.ts:2:43 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

2 import type { BindingPluginContext } from '../binding';
                                            ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/transfrom-plugin-context.d.ts:1:74 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import type { BindingPluginContext, BindingTransformPluginContext } from '../binding';
                                                                           ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/transfrom-plugin-context.d.ts:2:34 - error TS2307: Cannot find module '../rollup' or its corresponding type declarations.

2 import type { RollupError } from '../rollup';
                                   ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/options/output-options.d.ts:1:36 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import type { RenderedChunk } from '../binding';
                                     ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/options/normalized-output-options.d.ts:1:78 - error TS2307: Cannot find module '../rollup' or its corresponding type declarations.

1 import type { SourcemapIgnoreListOption, SourcemapPathTransformOption } from '../rollup';
                                                                               ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/options/normalized-output-options.d.ts:4:36 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

4 import type { RenderedChunk } from '../binding';
                                     ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/log/logger.d.ts:1:63 - error TS2307: Cannot find module '../rollup' or its corresponding type declarations.

1 import type { LoggingFunction, LogHandler, RollupError } from '../rollup';
                                                                ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/builtin-plugin.d.ts:1:64 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import { BindingBuiltinPlugin, BindingBuiltinPluginName } from '../binding';
                                                                 ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/index.d.ts:1:70 - error TS2307: Cannot find module '../binding' or its corresponding type declarations.

1 import type { BindingHookResolveIdExtraOptions, RenderedChunk } from '../binding';
                                                                       ~~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/plugin/index.d.ts:11:32 - error TS2307: Cannot find module '../rollup' or its corresponding type declarations.

11 import type { RollupLog } from '../rollup';
                                  ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/index.d.ts:15:42 - error TS2307: Cannot find module './binding' or its corresponding type declarations.

15 import { RenderedChunk, transform } from './binding';
                                            ~~~~~~~~~~~

../../../rolldown/packages/rolldown/dist/types/index.d.ts:25:62 - error TS2307: Cannot find module './rollup' or its corresponding type declarations.

25 export type { RollupError, RollupLog, LoggingFunction } from './rollup';
                                                                ~~~~~~~~~~


Found 17 errors.

⋊> ~/D/r/i/r/rolldown-typescript-error on main ⨯                                                                                                                                                        17:34:22

@underfin
Copy link
Contributor

underfin commented Jul 16, 2024

Is this only for type check on dist? Does the situation that compiled dts is wrong happen a lot?

I'm retest at vite build at my local, not found issue, i'm worry for me... But i think it should be fixed and type check for dist.

Here has some complex for bundling d.ts, let us waiting some days to fix it.

@IWANABETHATGUY
Copy link
Member

Maybe it is related to microsoft/TypeScript#5112

@IWANABETHATGUY
Copy link
Member

This simple patch seems worked,

diff --git a/packages/rolldown/package.json b/packages/rolldown/package.json
index b80d329b..551a63b2 100644
--- a/packages/rolldown/package.json
+++ b/packages/rolldown/package.json
@@ -58,6 +58,7 @@
     "bak_build-node": "unbuild",
     "build-node": "node ../../node_modules/npm-rolldown/bin/cli.js -c ./rolldown.config.mjs",
     "build-types": "tsc -p ./tsconfig.dts.json",
+    "post:build-types": "cp src/*.d.ts ./dist/types/",
     "build-native:debug": "run-s build-binding build-types build-node",
     "build-native:release": "run-s build-binding:release build-types build-node",
     "build-wasi:debug": "run-s build-binding:wasi build-node",

@underfin
Copy link
Contributor

@IWANABETHATGUY Could you push it and merge the pr. I think it's ok for me.

@hyf0
Copy link
Member

hyf0 commented Jul 16, 2024

This simple patch seems worked,

diff --git a/packages/rolldown/package.json b/packages/rolldown/package.json
index b80d329b..551a63b2 100644
--- a/packages/rolldown/package.json
+++ b/packages/rolldown/package.json
@@ -58,6 +58,7 @@
     "bak_build-node": "unbuild",
     "build-node": "node ../../node_modules/npm-rolldown/bin/cli.js -c ./rolldown.config.mjs",
     "build-types": "tsc -p ./tsconfig.dts.json",
+    "post:build-types": "cp src/*.d.ts ./dist/types/",
     "build-native:debug": "run-s build-binding build-types build-node",
     "build-native:release": "run-s build-binding:release build-types build-node",
     "build-wasi:debug": "run-s build-binding:wasi build-node",

Better add to rolldown.config.mjs.

@hyf0
Copy link
Member

hyf0 commented Jul 16, 2024

CI failed.

@IWANABETHATGUY
Copy link
Member

IWANABETHATGUY commented Jul 16, 2024

@IWANABETHATGUY Could you push it and merge the pr. I think it's ok for me.

This simple patch seems worked,

diff --git a/packages/rolldown/package.json b/packages/rolldown/package.json
index b80d329b..551a63b2 100644
--- a/packages/rolldown/package.json
+++ b/packages/rolldown/package.json
@@ -58,6 +58,7 @@
     "bak_build-node": "unbuild",
     "build-node": "node ../../node_modules/npm-rolldown/bin/cli.js -c ./rolldown.config.mjs",
     "build-types": "tsc -p ./tsconfig.dts.json",
+    "post:build-types": "cp src/*.d.ts ./dist/types/",
     "build-native:debug": "run-s build-binding build-types build-node",
     "build-native:release": "run-s build-binding:release build-types build-node",
     "build-wasi:debug": "run-s build-binding:wasi build-node",

Better add to rolldown.config.mjs.

Moving the copy operation to rolldown.config.mjs require each time run pnpm build-types must following a build-node?

@hi-ogawa
Copy link
Collaborator Author

Moving the copy operation to rolldown.config.mjs require each time run pnpm build-types must following a build-node?

When running just build locally, I have dist/types/binding.d.ts there, so I thought this is handled already? I ran these commands:

rm -rf packages/rolldown/dist
just build
ls packages/rolldown/dist/types/binding.d.ts 

hi-ogawa added 2 commits July 16, 2024 19:15

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@IWANABETHATGUY
Copy link
Member

Moving the copy operation to rolldown.config.mjs require each time run pnpm build-types must following a build-node?

When running just build locally, I have dist/types/binding.d.ts there, so I thought this is handled already? I ran these commands:

rm -rf packages/rolldown/dist
just build
ls packages/rolldown/dist/types/binding.d.ts 

Then ignore me, just fix the CI, it is good to merge.

@IWANABETHATGUY IWANABETHATGUY enabled auto-merge July 16, 2024 10:19
@IWANABETHATGUY IWANABETHATGUY added this pull request to the merge queue Jul 16, 2024
Merged via the queue into rolldown:main with commit f6a8d51 Jul 16, 2024
22 checks passed
@hi-ogawa hi-ogawa deleted the fix-rolldown-dts branch July 26, 2024 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rolldown npm package's dts has type errors
4 participants