From 32742995033c14eca814741a4c4420b593f8b9e1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Dec 2023 01:02:57 +0100 Subject: [PATCH 1/5] import order to ensure best matches on autocomplete --- package.json | 6 +++--- tsconfig.json | 6 +++--- vite.config.ts | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 244ab6b..cd16c6d 100644 --- a/package.json +++ b/package.json @@ -135,15 +135,15 @@ "vuepress": "^2.0.0-rc.0" }, "imports": { - "#root/*": "./*", - "#src/*": "./src/*", "#components/*": "./src/components/*", "#pages/*": "./src/pages/*", "#assets/*": "./src/assets/*", "#layouts/*": "./src/layouts/*", "#stores/*": "./src/stores/*", + "#src/*": "./src/*", "#plugins/*": "./renderer/plugins/*", "#context/*": "./renderer/context/*", - "#types/*": "./types/*" + "#types/*": "./types/*", + "#root/*": "./*" } } diff --git a/tsconfig.json b/tsconfig.json index 3e28b4c..719a6f4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,16 +11,16 @@ "esModuleInterop": true, "resolveJsonModule": true, "paths": { - "#root/*": ["./*"], - "#src/*": ["./src/*"], "#components/*": ["./src/components/*"], "#pages/*": ["./src/pages/*"], "#assets/*": ["./src/assets/*"], "#layouts/*": ["./src/layouts/*"], "#stores/*": ["./src/stores/*"], + "#src/*": ["./src/*"], "#plugins/*": ["./renderer/plugins/*"], "#context/*": ["./renderer/context/*"], - "#types/*": ["./types/*"] + "#types/*": ["./types/*"], + "#root/*": ["./*"] } }, "ts-node": { diff --git a/vite.config.ts b/vite.config.ts index 029f2f0..34f13b2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -28,16 +28,16 @@ const config: UserConfig = { ssr: { noExternal: ['vuetify'] }, resolve: { alias: { - '#root': __dirname, - '#src': path.join(__dirname, '/src'), '#components': path.join(__dirname, '/src/components'), '#pages': path.join(__dirname, '/src/pages'), '#assets': path.join(__dirname, '/src/assets'), '#layouts': path.join(__dirname, '/src/layouts'), '#stores': path.join(__dirname, '/src/stores'), + '#src': path.join(__dirname, '/src'), '#plugins': path.join(__dirname, '/renderer/plugins'), '#context': path.join(__dirname, '/renderer/context'), '#types': path.join(__dirname, '/types'), + '#root': __dirname, }, }, } From 3d28141447ec8b2131d1ecd2d65ad50fcd96ad9a Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Dec 2023 01:04:10 +0100 Subject: [PATCH 2/5] SBComp type --- types/SBComp.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 types/SBComp.ts diff --git a/types/SBComp.ts b/types/SBComp.ts new file mode 100644 index 0000000..5e44279 --- /dev/null +++ b/types/SBComp.ts @@ -0,0 +1,4 @@ +import { ConcreteComponent } from 'vue' + +// Storybook Component Type +export type SBComp = Omit, 'props'> From eaf361c31d4744e2bcca3cbb6f87be06931f8c34 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Dec 2023 01:06:30 +0100 Subject: [PATCH 3/5] fix all stories using SBComp --- src/stories/ExampleButton.stories.ts | 5 +++-- src/stories/ExampleHeader.stories.ts | 5 +++-- src/stories/ExamplePage.stories.ts | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/stories/ExampleButton.stories.ts b/src/stories/ExampleButton.stories.ts index 05a6057..527a6ea 100644 --- a/src/stories/ExampleButton.stories.ts +++ b/src/stories/ExampleButton.stories.ts @@ -1,3 +1,5 @@ +import { SBComp } from '#types/SBComp' + import ExampleButton from './ExampleButton.vue' import type { Meta, StoryObj } from '@storybook/vue3' @@ -5,8 +7,7 @@ import type { Meta, StoryObj } from '@storybook/vue3' // More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction const meta = { title: 'Example/Button', - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - component: ExampleButton, + component: ExampleButton as SBComp, // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs tags: ['autodocs'], argTypes: { diff --git a/src/stories/ExampleHeader.stories.ts b/src/stories/ExampleHeader.stories.ts index 4a323b4..3caaf3a 100644 --- a/src/stories/ExampleHeader.stories.ts +++ b/src/stories/ExampleHeader.stories.ts @@ -1,3 +1,5 @@ +import { SBComp } from '#types/SBComp' + import ExampleHeader from './ExampleHeader.vue' import type { Meta, StoryObj } from '@storybook/vue3' @@ -8,8 +10,7 @@ const meta = { * to learn how to generate automatic titles */ title: 'Example/Header', - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - component: ExampleHeader, + component: ExampleHeader as SBComp, // eslint-disable-next-line @typescript-eslint/no-explicit-any render: (args: any) => ({ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment diff --git a/src/stories/ExamplePage.stories.ts b/src/stories/ExamplePage.stories.ts index cc50eb3..0fa903e 100644 --- a/src/stories/ExamplePage.stories.ts +++ b/src/stories/ExamplePage.stories.ts @@ -1,13 +1,14 @@ import { within, userEvent } from '@storybook/testing-library' +import { SBComp } from '#types/SBComp' + import ExamplePage from './ExamplePage.vue' import type { Meta, StoryObj } from '@storybook/vue3' const meta = { title: 'Example/Page', - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - component: ExamplePage, + component: ExamplePage as SBComp, render: () => ({ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment components: { ExamplePage }, From 347e4b659956d8c77c4c1a2a35bd8ca391c75716 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Dec 2023 01:15:54 +0100 Subject: [PATCH 4/5] fix promise type problem, include emoji --- server/index.ts | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/server/index.ts b/server/index.ts index 715bcec..d819eb3 100644 --- a/server/index.ts +++ b/server/index.ts @@ -52,27 +52,28 @@ async function startServer() { // Vike middleware. It should always be our last middleware (because it's a // catch-all middleware superseding any middleware placed after it). - // eslint-disable-next-line @typescript-eslint/no-misused-promises - app.get('*', async (req, res, next) => { - const pageContextInit = { - urlOriginal: req.originalUrl, - } - const pageContext = await renderPage(pageContextInit) - const { httpResponse } = pageContext - if (!httpResponse) { - return next() - } else { - const { body, statusCode, headers, earlyHints } = httpResponse - if (res.writeEarlyHints) res.writeEarlyHints({ link: earlyHints.map((e) => e.earlyHintLink) }) - headers.forEach(([name, value]) => res.setHeader(name, value)) - res.status(statusCode) - // For HTTP streams use httpResponse.pipe() instead, see https://vike.dev/stream - res.send(body) - } + app.get('*', (req, res, next) => { + void (async (req, res, next) => { + const pageContextInit = { + urlOriginal: req.originalUrl, + } + const pageContext = await renderPage(pageContextInit) + const { httpResponse } = pageContext + if (!httpResponse) { + next() + } else { + const { body, statusCode, headers, earlyHints } = httpResponse + if (res.writeEarlyHints) res.writeEarlyHints({ link: earlyHints.map((e) => e.earlyHintLink) }) + headers.forEach(([name, value]) => res.setHeader(name, value)) + res.status(statusCode) + // For HTTP streams use httpResponse.pipe() instead, see https://vike.dev/stream + res.send(body) + } + })(req, res, next) }) const port = process.env.PORT || 3000 app.listen(port) // eslint-disable-next-line no-console - console.log(`Server running at http://localhost:${port}`) + console.log(`🚀 Server running at http://localhost:${port}`) } From c431b621ec4a1d00dac4bb52f83976beae69ca66 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 14 Dec 2023 01:18:29 +0100 Subject: [PATCH 5/5] lint fixes --- server/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/index.ts b/server/index.ts index d819eb3..55b323e 100644 --- a/server/index.ts +++ b/server/index.ts @@ -63,7 +63,8 @@ async function startServer() { next() } else { const { body, statusCode, headers, earlyHints } = httpResponse - if (res.writeEarlyHints) res.writeEarlyHints({ link: earlyHints.map((e) => e.earlyHintLink) }) + if (res.writeEarlyHints) + res.writeEarlyHints({ link: earlyHints.map((e) => e.earlyHintLink) }) headers.forEach(([name, value]) => res.setHeader(name, value)) res.status(statusCode) // For HTTP streams use httpResponse.pipe() instead, see https://vike.dev/stream