mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 17:16:16 +08:00
ci: start devServer before test running to avoid tests timeout (#11297)
This commit is contained in:
+56
-49
@@ -1,3 +1,4 @@
|
||||
import type { Package } from '@affine-tools/utils/workspace';
|
||||
import webpack, { type Compiler, type Configuration } from 'webpack';
|
||||
import WebpackDevServer from 'webpack-dev-server';
|
||||
import { merge } from 'webpack-merge';
|
||||
@@ -21,6 +22,55 @@ function getChannel() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getConfig(pkg: Package, dev: boolean) {
|
||||
let config = createWebpackConfig(pkg, {
|
||||
mode: dev ? 'development' : 'production',
|
||||
channel: getChannel(),
|
||||
});
|
||||
|
||||
let configOverride: Configuration | undefined;
|
||||
const overrideConfigPath = pkg.join('webpack.config.ts');
|
||||
|
||||
if (overrideConfigPath.isFile()) {
|
||||
const override = await import(overrideConfigPath.toFileUrl().toString());
|
||||
configOverride = override.config ?? override.default;
|
||||
}
|
||||
|
||||
if (configOverride) {
|
||||
config = merge(config, configOverride);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export async function start(
|
||||
compiler: Compiler,
|
||||
config: Configuration['devServer']
|
||||
): Promise<WebpackDevServer> {
|
||||
const devServer = new WebpackDevServer(config, compiler);
|
||||
|
||||
await devServer.start();
|
||||
|
||||
return devServer;
|
||||
}
|
||||
|
||||
export async function build(compiler: Compiler) {
|
||||
compiler.run((error, stats) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
if (stats) {
|
||||
if (stats.hasErrors()) {
|
||||
console.error(stats.toString('errors-only'));
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(stats.toString('minimal'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export class BundleCommand extends PackageCommand {
|
||||
static override paths = [['bundle'], ['webpack'], ['pack'], ['bun']];
|
||||
|
||||
@@ -35,60 +85,17 @@ export class BundleCommand extends PackageCommand {
|
||||
async execute() {
|
||||
this.logger.info(`Packing package ${this.package}...`);
|
||||
|
||||
const config = await this.getConfig();
|
||||
const config = await getConfig(
|
||||
this.workspace.getPackage(this.package),
|
||||
this.dev
|
||||
);
|
||||
|
||||
const compiler = webpack(config);
|
||||
|
||||
if (this.dev) {
|
||||
await this.start(compiler, config.devServer);
|
||||
await start(compiler, config.devServer);
|
||||
} else {
|
||||
await this.build(compiler);
|
||||
await build(compiler);
|
||||
}
|
||||
}
|
||||
|
||||
async getConfig() {
|
||||
let config = createWebpackConfig(this.workspace.getPackage(this.package), {
|
||||
mode: this.dev ? 'development' : 'production',
|
||||
channel: getChannel(),
|
||||
});
|
||||
|
||||
let configOverride: Configuration | undefined;
|
||||
const overrideConfigPath = this.workspace
|
||||
.getPackage(this.package)
|
||||
.join('webpack.config.ts');
|
||||
|
||||
if (overrideConfigPath.isFile()) {
|
||||
const override = await import(overrideConfigPath.toFileUrl().toString());
|
||||
configOverride = override.config ?? override.default;
|
||||
}
|
||||
|
||||
if (configOverride) {
|
||||
config = merge(config, configOverride);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
async start(compiler: Compiler, config: Configuration['devServer']) {
|
||||
const devServer = new WebpackDevServer(config, compiler);
|
||||
|
||||
await devServer.start();
|
||||
}
|
||||
|
||||
async build(compiler: Compiler) {
|
||||
compiler.run((error, stats) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
if (stats) {
|
||||
if (stats.hasErrors()) {
|
||||
console.error(stats.toString('errors-only'));
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(stats.toString('minimal'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user