Skip to content

Commit

Permalink
chore: move hot next function from runner to runner factory (#6140)
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder authored Apr 8, 2024
1 parent 5b6844e commit 10b9605
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 51 deletions.
55 changes: 50 additions & 5 deletions packages/rspack-test-tools/src/runner/hot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { StatsCompilation } from "@rspack/core";
import checkArrayExpectation from "../helper/legacy/checkArrayExpectation";
import {
ECompilerType,
ITestEnv,
Expand All @@ -18,21 +20,64 @@ export class HotRunnerFactory<
const compiler = this.context.getCompiler(this.name);
const testConfig = this.context.getTestConfig();
const stats = compiler.getStats();
const source = this.context.getSource();
const dist = this.context.getDist();
const hotUpdateContext = this.context.getValue(
this.name,
"hotUpdateContext"
) as { updateIndex: number };

const next = (
callback: (error: Error | null, stats?: StatsCompilation) => void
) => {
hotUpdateContext.updateIndex++;
compiler
.build()
.then(stats => {
if (!stats)
return callback(new Error("Should generate stats during build"));
const jsonStats = stats.toJson({
// errorDetails: true
});
if (
checkArrayExpectation(
source,
jsonStats,
"error",
"errors" + hotUpdateContext.updateIndex,
"Error",
callback
)
) {
return;
}
if (
checkArrayExpectation(
source,
jsonStats,
"warning",
"warnings" + hotUpdateContext.updateIndex,
"Warning",
callback
)
) {
return;
}
callback(null, jsonStats as StatsCompilation);
})
.catch(callback);
};

return new HotRunner({
env,
stats: stats!,
name: this.name,
runInNewContext: false,
testConfig,
source: this.context.getSource(),
dist: this.context.getDist(),
compilerOptions,
compiler,
hotUpdateContext
source,
dist,
next,
compilerOptions
});
}
}
51 changes: 5 additions & 46 deletions packages/rspack-test-tools/src/runner/runner/hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import createHotDocument from "../../helper/legacy/createHotDocument";
import urlToRelativePath from "../../helper/legacy/urlToRelativePath";
import createFakeWorker from "../../helper/legacy/createFakeWorker";
import EventSource from "../../helper/legacy/EventSourceForNode";
import { ECompilerType, ITestCompilerManager } from "../../type";
import { ECompilerType } from "../../type";
import { BasicRunner } from "./basic";
import {
IBasicModuleScope,
Expand All @@ -13,14 +13,12 @@ import {
import fs from "fs";
import path from "path";
import { StatsCompilation } from "@rspack/core";
import checkArrayExpectation from "../../helper/legacy/checkArrayExpectation";

interface IHotRunnerOptionsr<T extends ECompilerType = ECompilerType.Rspack>
extends IBasicRunnerOptions<T> {
hotUpdateContext: {
updateIndex: number;
};
compiler: ITestCompilerManager<T>;
next: (
callback: (error: Error | null, stats?: StatsCompilation) => void
) => void;
}

export class HotRunner<
Expand Down Expand Up @@ -109,46 +107,7 @@ export class HotRunner<
moduleScope["Worker"] = this.globalContext!["Worker"];
moduleScope["EventSource"] = this.globalContext!["EventSource"];
moduleScope["STATS"] = moduleScope.__STATS__;
moduleScope["NEXT"] = (
callback: (error: Error | null, stats?: StatsCompilation) => void
) => {
this._options.hotUpdateContext.updateIndex++;
this._options.compiler
.build()
.then(stats => {
if (!stats)
return callback(new Error("Should generate stats during build"));
const jsonStats = stats.toJson({
// errorDetails: true
});
if (
checkArrayExpectation(
this._options.source,
jsonStats,
"error",
"errors" + this._options.hotUpdateContext.updateIndex,
"Error",
callback
)
) {
return;
}
if (
checkArrayExpectation(
this._options.source,
jsonStats,
"warning",
"warnings" + this._options.hotUpdateContext.updateIndex,
"Warning",
callback
)
) {
return;
}
callback(null, jsonStats as StatsCompilation);
})
.catch(callback);
};
moduleScope["NEXT"] = this._options.next;
return moduleScope;
}

Expand Down

2 comments on commit 10b9605

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs, self-hosted, Linux, ci ❌ failure
_selftest, ubuntu-latest ✅ success
nx, ubuntu-latest ✅ success
rspress, ubuntu-latest ✅ success
rsbuild, ubuntu-latest ❌ failure
compat, ubuntu-latest ✅ success
examples, ubuntu-latest ❌ failure

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-04-08 c0307c4) Current Change
10000_development-mode + exec 2.63 s ± 31 ms 2.64 s ± 31 ms +0.41 %
10000_development-mode_hmr + exec 666 ms ± 3 ms 669 ms ± 5 ms +0.46 %
10000_production-mode + exec 2.69 s ± 48 ms 2.69 s ± 22 ms +0.06 %
arco-pro_development-mode + exec 2.51 s ± 105 ms 2.51 s ± 78 ms -0.10 %
arco-pro_development-mode_hmr + exec 443 ms ± 3.2 ms 442 ms ± 2.4 ms -0.25 %
arco-pro_development-mode_hmr_intercept-plugin + exec 454 ms ± 0.91 ms 453 ms ± 1.7 ms -0.23 %
arco-pro_development-mode_intercept-plugin + exec 3.28 s ± 96 ms 3.27 s ± 69 ms -0.16 %
arco-pro_production-mode + exec 3.93 s ± 108 ms 3.93 s ± 96 ms +0.13 %
arco-pro_production-mode_intercept-plugin + exec 4.73 s ± 58 ms 4.7 s ± 74 ms -0.57 %
threejs_development-mode_10x + exec 2 s ± 15 ms 1.99 s ± 28 ms -0.43 %
threejs_development-mode_10x_hmr + exec 722 ms ± 21 ms 728 ms ± 24 ms +0.87 %
threejs_production-mode_10x + exec 5.27 s ± 26 ms 5.26 s ± 39 ms -0.10 %

Please sign in to comment.