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

breaking: string only waku.config.ts #1281

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Mar 2, 2025

This is for v0.22.0.

Previously, waku.config.ts allows to put functions directly. Instead of that, this one is to take strings only.

Here's the patch for 38_cookies examnple:

diff --git a/examples/38_cookies/waku.config.ts b/examples/38_cookies/waku.config.ts
index d64ef237..60a72ce8 100644
--- a/examples/38_cookies/waku.config.ts
+++ b/examples/38_cookies/waku.config.ts
@@ -1,10 +1,10 @@
 import { defineConfig } from 'waku/config';
 
 export default defineConfig({
-  middleware: () => [
-    import('waku/middleware/context'),
-    import('./src/middleware/cookie.js'),
-    import('waku/middleware/dev-server'),
-    import('waku/middleware/handler'),
+  middleware: [
+    'waku/middleware/context',
+    './src/middleware/cookie.js',
+    'waku/middleware/dev-server',
+    'waku/middleware/handler',
   ],
 });

Tasks:

  • DEV
  • PRD
  • --with-cloudflare
  • other deploy plugins
  • docs

Copy link

vercel bot commented Mar 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
waku ⬜️ Ignored (Inspect) Visit Preview Mar 7, 2025 4:18am

Copy link

codesandbox-ci bot commented Mar 2, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 2, 2025

@rmarscher I get a weird error with pnpm -F 07_cloudflare build --with-cloudflare. Can you have a look when you get a chance?

@fengzilong
Copy link

It seems we will lose type checking for middleware in waku config file. Would you consider supporting both Promise<{ default: Middleware }>[] and string[]?

@rmarscher
Copy link
Contributor

@rmarscher I get a weird error with pnpm -F 07_cloudflare build --with-cloudflare. Can you have a look when you get a chance?

It looks like import.meta.env && !import.meta.env.PROD is true during build. The intent is to only set unstable_honoEnhancer during dev mode.

@rmarscher
Copy link
Contributor

I'm curious what is the reason for this change. Does it enable hot reload for middleware code? Or some other use case for the middleware to be imported within the vite context?

@@ -17,6 +17,8 @@ const CONFIG_FILE = 'waku.config.ts'; // XXX only ts extension
export function rscEntriesPlugin(opts: {
basePath: string;
rscBase: string;
middleware: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

I can follow up this PR with type suggestions for the waku supported plugins if you're open to it. It would still allow any string, but suggest the built in ones.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Can you highlight your idea with a few lines of code?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks. I see this doesn't break anything. Not sure how much it helps because it's very unlikely to people to type it. (Besides, this isn't a fix for the regression.)

I don't think we need it at least in this PR.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 4, 2025

The goal of string-based config is to avoid leaking runtime code in the config file. It's cleaner if we could separate them. It relates to hot reload, but it's secondary (not the goal of this PR).

So, in a word, it's a security concern.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 4, 2025

The intent is to only set unstable_honoEnhancer during dev mode.

It's much easier in that case. Let me see.

Hmm, but it's still "build" from the waku perspective. I'll see import.meta.env.PROD issue.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 4, 2025

It still doesn't work. It fails with building.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 6, 2025

Hmm, but it's still "build" from the waku perspective.

It's my misunderstanding. Now, it builds fine with import.meta.PRD condition.

@rmarscher Can you look into how e2e is failing?

@rmarscher
Copy link
Contributor

cd examples/07_cloudflare
pnpm run build
pnpm run start

open http://localhost:8787/

I am getting an error:

TypeError: Cannot read properties of undefined (reading 'find')

It is coming from here:

const htmlHead = !devServer && entriesPrd.dynamicHtmlPaths.find(([pathSpec]) => getPathMapping(pathSpec, ctx.req.url.pathname))?.[1] || "";

entriesPrd.dynamicHtmlPaths must be undefined. I'm not sure what that is about.

Are you seeing the same error?

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 6, 2025

Are you seeing the same error?

Oh, yeah, I didn't notice it when I run it previously. This should be fixable. Thanks.

dai-shi added a commit that referenced this pull request Mar 6, 2025
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.

4 participants