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

ci: add build & lint:type check #16

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'],
},
});
16 changes: 8 additions & 8 deletions packages/messaging/src/core/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { setTimeout as sleep } from 'node:timers/promises';
import { expect, it, vi } from 'vitest';
import { createMessaging, fromMessagePort } from '../index';

it('should on/off listener', async () => {
it.concurrent('should on/off listener', async () => {
const { port1, port2 } = new MessageChannel();
const listenerFn = vi.fn();

Expand All @@ -17,7 +17,7 @@ it('should on/off listener', async () => {
expect(listenerFn).toBeCalledTimes(1);
});

it('should support request', async () => {
it.concurrent('should support request', async () => {
const { port1, port2 } = new MessageChannel();

const _receiver = createMessaging(fromMessagePort(port1), {
Expand All @@ -36,7 +36,7 @@ it('should support request', async () => {
await expect(sender.request({ name: 'greet', user: 'Tmk' })).rejects.toThrow('Unknown method');
});

it('should support stream', async () => {
it.concurrent('should support stream', async () => {
const { port1, port2 } = new MessageChannel();

const _receiver = createMessaging(fromMessagePort(port1), {
Expand Down Expand Up @@ -84,7 +84,7 @@ it('should support stream', async () => {
).rejects.toThrow('Unknown method');
});

it('should support abort stream', async () => {
it.concurrent('should support abort stream', async () => {
const { port1, port2 } = new MessageChannel();

const cleanupFn = vi.fn();
Expand All @@ -111,7 +111,7 @@ it('should support abort stream', async () => {
new Promise<unknown[]>((resolve, reject) => {
const result: unknown[] = [];
const unsubscribe = sender.stream(
{ name: 'hello', interval: 30 },
{ name: 'hello', interval: 50 },
{
next: (value) => result.push(value),
error: (reason) => reject(reason),
Expand All @@ -121,15 +121,15 @@ it('should support abort stream', async () => {
setTimeout(() => {
unsubscribe();
resolve(result);
}, 80);
}, 123);
})
).resolves.toEqual([0, 1]);
await sleep(10);
expect(cleanupFn).toBeCalled();
expect(completeFn).not.toBeCalled();
});

it('should support relay request', async () => {
it.concurrent('should support relay request', async () => {
const { port1, port2 } = new MessageChannel();
const { port1: port3, port2: port4 } = new MessageChannel();

Expand All @@ -155,7 +155,7 @@ it('should support relay request', async () => {
await expect(sender.request({ name: 'greet', user: 'Tmk' })).rejects.toThrow('Unknown method');
});

it('should support relay stream', async () => {
it.concurrent('should support relay stream', async () => {
const { port1, port2 } = new MessageChannel();
const { port1: port3, port2: port4 } = new MessageChannel();

Expand Down
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"]
}
}
}
Loading