fix: avoid leaking @types/node into client code#1531
fix: avoid leaking @types/node into client code#1531aleclarson wants to merge 1 commit intowxt-dev:mainfrom
@types/node into client code#1531Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
I can retarget this to #1085 if you prefer. LMK! |
I think that would be better as @aklinker1 should be merging 0.20.0 very soon as he rebased everything from main into it and we've been testing it |
|
0.20.0 is released and out so make sure to rebase your changes on main! |
54b8603 to
a6969b0
Compare
|
Rebased ✅ |
You can definitely avoid it. The key is to use multiple
This is off the top of my noggin, so could be missing a detail. I assume there isn't a demo with this setup already? |
|
I would love to get this merged. Let me know what the next step is. |
|
Sorry, been busy and it's too easy to just go down the list of recent notifications and forget about these older ones. But I'm catching up! You are definitely right about using multiple TSConfig files. Nuxt supports projects using one tsconfig file or multiple by generating 4 different tsconfig files in the
I'd like to support both approaches as well. WXT generates the first one today, but we could generate the other 3. So I think the full solution here is, in addition to the changes already in this PR, update the I'd recommend looking at a real nuxt project if you've never seen their setup before. A basic starter will have them: pnpm create nuxt@latest <project-name>
pnpm nuxt prepare
ls .nuxt | grep tsconfigThe new tsconfig file generation can come in a separate PR - I need to re-review your changes here since it's been a while, but we'll get this merged soon! But it's past midnight here and I have some early meetings in the morning... So I'll re-review it tomorrow after work |

Overview
The
defineWxtPluginfunction is referenced by the generated.wxt/types/imports.d.tsmodule, which is used by client code. Therefore, we need to avoid importing fromwxt/src/types.ts, as it depends on Node.js-specific packages (likevite). This inadvertently introduces Node.js globals into the extension's client environment, which is undesirable (e.g. it breaks the return type ofsetTimeout).Edit 1
Updated other "offending" imports. Split out the option-related types (into
option-types.ts) and the client-related types (intoclient-types.ts).Manual Testing
Without this change, you should see
setTimeoutreturn aNodeJS.Timeoutobject.After this change,
setTimeoutwill return a number as expected.Related Issue
#1459