From 2a866cf696005d77341a717a6815ecdc7ae68d1d Mon Sep 17 00:00:00 2001 From: Tmk Date: Sat, 27 Jan 2024 10:48:00 +0800 Subject: [PATCH] ci: add build & lint:type check --- .github/workflows/ci.yml | 6 ++++++ .gitignore | 1 + apps/ai-assistant/src/background/router/index.ts | 8 +++----- apps/ai-assistant/src/content-scripts/app.tsx | 10 +++++----- examples/react/package.json | 1 - examples/solid/package.json | 1 - examples/svelte/package.json | 1 - examples/vue/package.json | 1 - packages/messaging/e2e/context.ts | 2 +- packages/messaging/modern.config.ts | 1 + packages/messaging/tsconfig.json | 2 +- packages/modernjs-plugin/src/plugins/hmr-cors.ts | 1 + packages/storage/e2e/context.ts | 2 +- packages/storage/modern.config.ts | 1 + packages/storage/tsconfig.json | 2 +- packages/test-utils/bin/tsconfig.json | 1 + packages/test-utils/bin/webx-launch.mjs | 15 +++++++++++---- packages/test-utils/tsconfig.json | 4 ++-- turbo.json | 4 ++-- 19 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 278950c4..8347df25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,5 +35,11 @@ jobs: pnpm i --frozen-lockfile pnpm playwright install + - name: Build + run: pnpm build + + - name: Lint + run: pnpm lint:type + - name: Test run: pnpm test diff --git a/.gitignore b/.gitignore index c21fc33e..d4428bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ node_modules dist +output .turbo diff --git a/apps/ai-assistant/src/background/router/index.ts b/apps/ai-assistant/src/background/router/index.ts index 65f5d584..e91a3e88 100644 --- a/apps/ai-assistant/src/background/router/index.ts +++ b/apps/ai-assistant/src/background/router/index.ts @@ -1,5 +1,5 @@ import { GoogleGenerativeAI } from '@google/generative-ai'; -import { on } from '@webx-kit/messaging/background'; +import { setStreamHandler } from '@webx-kit/messaging/background'; import { apiKeyAtom } from '@/hooks/atoms/config'; import { atom, getDefaultStore } from 'jotai'; @@ -12,17 +12,15 @@ const genAIAtom = atom(async (get) => { store.sub(genAIAtom, () => {}); -on(async (message, subscriber) => { +setStreamHandler(async (message, subscriber) => { const { data } = message; - // @ts-expect-error - if (data && typeof data === 'object' && data.type === 'stream') { + if (data && typeof data === 'object' && 'prompt' in data && typeof data.prompt === 'string') { const genAI = await store.get(genAIAtom); if (!genAI) return subscriber.error('GenAI is not initialized'); const result = await genAI.getGenerativeModel({ model: 'gemini-pro' }).generateContentStream({ contents: [ { role: 'user', - // @ts-expect-error parts: [{ text: data.prompt }], }, ], diff --git a/apps/ai-assistant/src/content-scripts/app.tsx b/apps/ai-assistant/src/content-scripts/app.tsx index 76c4692e..14e3bdb4 100644 --- a/apps/ai-assistant/src/content-scripts/app.tsx +++ b/apps/ai-assistant/src/content-scripts/app.tsx @@ -8,7 +8,7 @@ import { isSelectionValid, rangeToReference, } from '@webx-kit/runtime/content-scripts'; -import { stream } from '@webx-kit/messaging/content-script'; +import { client } from '@webx-kit/messaging/content-script'; import clsx from 'clsx'; import { Provider } from './features/provider'; import './global.less'; @@ -81,8 +81,8 @@ export const App = () => { setContent(''); setIsLoading(true); - stream( - { type: 'stream', prompt: 'Translate the following text to Chinese:\n' + text }, + client.stream( + { prompt: 'Translate the following text to Chinese:\n' + text }, { next: (token) => setContent((prev) => prev + token), error: () => setIsLoading(false), @@ -98,8 +98,8 @@ export const App = () => { setContent(''); setIsLoading(true); - stream( - { type: 'stream', prompt: 'Summarize the following text to Chinese:\n' + text }, + client.stream( + { prompt: 'Summarize the following text to Chinese:\n' + text }, { next: (token) => setContent((prev) => prev + token), error: () => setIsLoading(false), diff --git a/examples/react/package.json b/examples/react/package.json index 87e1d4a1..d58b678c 100644 --- a/examples/react/package.json +++ b/examples/react/package.json @@ -4,7 +4,6 @@ "scripts": { "dev": "modern dev", "build": "modern build", - "pretest": "modern build", "test": "playwright test", "lint:type": "tsc --noEmit" }, diff --git a/examples/solid/package.json b/examples/solid/package.json index b4097f3d..eef30961 100644 --- a/examples/solid/package.json +++ b/examples/solid/package.json @@ -4,7 +4,6 @@ "scripts": { "dev": "modern dev", "build": "modern build", - "pretest": "modern build", "test": "playwright test", "lint:type": "tsc --noEmit" }, diff --git a/examples/svelte/package.json b/examples/svelte/package.json index a8ed4612..ec9f4863 100644 --- a/examples/svelte/package.json +++ b/examples/svelte/package.json @@ -4,7 +4,6 @@ "scripts": { "dev": "modern dev", "build": "modern build", - "pretest": "modern build", "test": "playwright test", "lint:type": "tsc --noEmit" }, diff --git a/examples/vue/package.json b/examples/vue/package.json index eee86af7..2fcafd90 100644 --- a/examples/vue/package.json +++ b/examples/vue/package.json @@ -4,7 +4,6 @@ "scripts": { "dev": "modern dev", "build": "modern build", - "pretest": "modern build", "test": "playwright test", "lint:type": "tsc --noEmit" }, diff --git a/packages/messaging/e2e/context.ts b/packages/messaging/e2e/context.ts index af736905..dd4bf970 100644 --- a/packages/messaging/e2e/context.ts +++ b/packages/messaging/e2e/context.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import { createWebxTest } from '@webx-kit/test-utils/playwright'; export const test = createWebxTest({ - extensionPath: path.resolve(__dirname, '../dist'), + extensionPath: path.resolve(__dirname, '../output'), }); export const { expect } = test; diff --git a/packages/messaging/modern.config.ts b/packages/messaging/modern.config.ts index 3ed86b64..70a774ad 100644 --- a/packages/messaging/modern.config.ts +++ b/packages/messaging/modern.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ entriesDir: './demo/pages', }, output: { + distPath: { root: './output' }, overrideBrowserslist: ['last 2 Chrome versions'], }, }); diff --git a/packages/messaging/tsconfig.json b/packages/messaging/tsconfig.json index df4c9a34..90526c4d 100644 --- a/packages/messaging/tsconfig.json +++ b/packages/messaging/tsconfig.json @@ -18,5 +18,5 @@ "@/*": ["./src/*"] } }, - "exclude": ["dist"] + "exclude": ["dist", "output"] } diff --git a/packages/modernjs-plugin/src/plugins/hmr-cors.ts b/packages/modernjs-plugin/src/plugins/hmr-cors.ts index 3afcf02f..df9ae781 100644 --- a/packages/modernjs-plugin/src/plugins/hmr-cors.ts +++ b/packages/modernjs-plugin/src/plugins/hmr-cors.ts @@ -30,6 +30,7 @@ export const hmrCorsPlugin = (): RsbuildPlugin => { tools: { devServer: { before: [ + // @ts-ignore (req, res, next) => { if (req.method?.toUpperCase() !== 'OPTIONS') return next(); res.writeHead(200, { diff --git a/packages/storage/e2e/context.ts b/packages/storage/e2e/context.ts index af736905..dd4bf970 100644 --- a/packages/storage/e2e/context.ts +++ b/packages/storage/e2e/context.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import { createWebxTest } from '@webx-kit/test-utils/playwright'; export const test = createWebxTest({ - extensionPath: path.resolve(__dirname, '../dist'), + extensionPath: path.resolve(__dirname, '../output'), }); export const { expect } = test; diff --git a/packages/storage/modern.config.ts b/packages/storage/modern.config.ts index 8496c2b5..9ec828ce 100644 --- a/packages/storage/modern.config.ts +++ b/packages/storage/modern.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ entriesDir: './demo/pages', }, output: { + distPath: { root: './output' }, overrideBrowserslist: ['last 2 Chrome versions'], }, }); diff --git a/packages/storage/tsconfig.json b/packages/storage/tsconfig.json index fc9e594e..0b4a506a 100644 --- a/packages/storage/tsconfig.json +++ b/packages/storage/tsconfig.json @@ -18,5 +18,5 @@ "@/*": ["./src/*"] } }, - "exclude": ["dist"] + "exclude": ["dist", "output"] } diff --git a/packages/test-utils/bin/tsconfig.json b/packages/test-utils/bin/tsconfig.json index efaa8b3b..31c5af65 100644 --- a/packages/test-utils/bin/tsconfig.json +++ b/packages/test-utils/bin/tsconfig.json @@ -3,6 +3,7 @@ "compilerOptions": { "target": "ES2020", "module": "ES2020", + "allowJs": true, "noEmit": true } } diff --git a/packages/test-utils/bin/webx-launch.mjs b/packages/test-utils/bin/webx-launch.mjs index 71a18f4b..bbd54573 100755 --- a/packages/test-utils/bin/webx-launch.mjs +++ b/packages/test-utils/bin/webx-launch.mjs @@ -8,13 +8,20 @@ import { chalk, fs, findMonorepoRoot } from '@modern-js/utils'; import commander from '@modern-js/utils/commander'; import { chromium } from '@playwright/test'; -commander.program.option('--path ', 'extension path', 'dist').option('--no-pin', 'pin extension to toolbar'); +commander.program.option('--path [path]', 'extension path').option('--no-pin', 'pin extension to toolbar'); const opts = commander.program.parse(process.argv).opts(); -const extensionPath = path.resolve(opts.path); -if (!fs.existsSync(extensionPath)) throw new Error(`\`${extensionPath}\` does not exist`); -if (!fs.statSync(extensionPath).isDirectory()) throw new Error(`\`${extensionPath}\` is not a directory`); +let extensionPath; + +if (opts.path) { + extensionPath = path.resolve(opts.path); +} else { + extensionPath = fs.existsSync(path.resolve('output/manifest.json')) ? path.resolve('output') : path.resolve('dist'); +} + +if (!fs.existsSync(path.resolve(extensionPath, 'manifest.json'))) + throw new Error(`\`${path.join(extensionPath, 'manifest.json')}\` does not exist`); const dirname = path.dirname(fileURLToPath(import.meta.url)); const monorepoRoot = findMonorepoRoot(dirname); diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json index 34dfa1a5..25957d89 100644 --- a/packages/test-utils/tsconfig.json +++ b/packages/test-utils/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2015", "lib": ["DOM", "ESNext"], - "allowJs": true, + "allowJs": false, "module": "commonjs", "strict": true, "esModuleInterop": true, @@ -14,7 +14,7 @@ "resolveJsonModule": true, "moduleResolution": "node", "baseUrl": "./", - "noEmit": true + "noEmit": true, }, "exclude": ["dist"] } diff --git a/turbo.json b/turbo.json index 9737d7f4..9ec81219 100644 --- a/turbo.json +++ b/turbo.json @@ -10,10 +10,10 @@ "outputs": [] }, "pretest": { - "outputs": ["dist"] + "outputs": ["output"] }, "test": { - "dependsOn": ["pretest", "^test"] + "dependsOn": ["build", "pretest", "^test"] } } }