Skip to content

Commit

Permalink
ci: add build & lint:type check
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx committed Jan 27, 2024
1 parent 0f22f92 commit 2a866cf
Show file tree
Hide file tree
Showing 19 changed files with 38 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

node_modules
dist
output

.turbo
8 changes: 3 additions & 5 deletions apps/ai-assistant/src/background/router/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 }],
},
],
Expand Down
10 changes: 5 additions & 5 deletions apps/ai-assistant/src/content-scripts/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
1 change: 0 additions & 1 deletion examples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"scripts": {
"dev": "modern dev",
"build": "modern build",
"pretest": "modern build",
"test": "playwright test",
"lint:type": "tsc --noEmit"
},
Expand Down
1 change: 0 additions & 1 deletion examples/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"scripts": {
"dev": "modern dev",
"build": "modern build",
"pretest": "modern build",
"test": "playwright test",
"lint:type": "tsc --noEmit"
},
Expand Down
1 change: 0 additions & 1 deletion examples/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"scripts": {
"dev": "modern dev",
"build": "modern build",
"pretest": "modern build",
"test": "playwright test",
"lint:type": "tsc --noEmit"
},
Expand Down
1 change: 0 additions & 1 deletion examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"scripts": {
"dev": "modern dev",
"build": "modern build",
"pretest": "modern build",
"test": "playwright test",
"lint:type": "tsc --noEmit"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/e2e/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions packages/messaging/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
entriesDir: './demo/pages',
},
output: {
distPath: { root: './output' },
overrideBrowserslist: ['last 2 Chrome versions'],
},
});
2 changes: 1 addition & 1 deletion packages/messaging/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"@/*": ["./src/*"]
}
},
"exclude": ["dist"]
"exclude": ["dist", "output"]
}
1 change: 1 addition & 0 deletions packages/modernjs-plugin/src/plugins/hmr-cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/e2e/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions packages/storage/modern.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineConfig({
entriesDir: './demo/pages',
},
output: {
distPath: { root: './output' },
overrideBrowserslist: ['last 2 Chrome versions'],
},
});
2 changes: 1 addition & 1 deletion packages/storage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"@/*": ["./src/*"]
}
},
"exclude": ["dist"]
"exclude": ["dist", "output"]
}
1 change: 1 addition & 0 deletions packages/test-utils/bin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"target": "ES2020",
"module": "ES2020",
"allowJs": true,
"noEmit": true
}
}
15 changes: 11 additions & 4 deletions packages/test-utils/bin/webx-launch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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);
Expand Down
4 changes: 2 additions & 2 deletions packages/test-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ES2015",
"lib": ["DOM", "ESNext"],
"allowJs": true,
"allowJs": false,
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
Expand All @@ -14,7 +14,7 @@
"resolveJsonModule": true,
"moduleResolution": "node",
"baseUrl": "./",
"noEmit": true
"noEmit": true,
},
"exclude": ["dist"]
}
4 changes: 2 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"outputs": []
},
"pretest": {
"outputs": ["dist"]
"outputs": ["output"]
},
"test": {
"dependsOn": ["pretest", "^test"]
"dependsOn": ["build", "pretest", "^test"]
}
}
}

0 comments on commit 2a866cf

Please sign in to comment.