Skip to content

Commit

Permalink
Revert "fix(typing): fix partial ts-expect-error in packages/rspack (#…
Browse files Browse the repository at this point in the history
…5909)"

This reverts commit f3dc1fd.
  • Loading branch information
Boshen committed Mar 14, 2024
1 parent 3c7a0d7 commit a394aa7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
10 changes: 6 additions & 4 deletions packages/rspack/src/Compilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface Asset {
}
export interface LogEntry {
type: string;
args?: any[];
args: any[];
time?: number;
trace?: string[];
}
Expand Down Expand Up @@ -662,7 +662,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
);
}
}
let trace: string[] | undefined;
let trace: string[];
switch (type) {
case LogType.warn:
case LogType.error:
Expand All @@ -675,12 +675,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
const logEntry: LogEntry = {
time: Date.now(),
type,
// @ts-expect-error
args,
// @ts-expect-error
trace
};
if (this.hooks.log.call(name, logEntry) === undefined) {
if (logEntry.type === LogType.profileEnd) {
if (typeof console.profileEnd === "function" && logEntry.args) {
if (typeof console.profileEnd === "function") {
console.profileEnd(`[${name}] ${logEntry.args[0]}`);
}
}
Expand All @@ -693,7 +695,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
}
logEntries.push(logEntry);
if (logEntry.type === LogType.profile) {
if (typeof console.profile === "function" && logEntry.args) {
if (typeof console.profile === "function") {
console.profile(`[${name}] ${logEntry.args[0]}`);
}
}
Expand Down
29 changes: 17 additions & 12 deletions packages/rspack/src/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import fs from "fs";
import * as tapable from "tapable";
import * as liteTapable from "./lite-tapable";
import { Callback, SyncBailHook, SyncHook } from "tapable";
import { WatchOptions } from "./config";
import type { WatchOptions } from "watchpack";
import {
EntryNormalized,
OutputNormalized,
Expand Down Expand Up @@ -53,7 +53,8 @@ class Compiler {
#instance?: binding.Rspack;

webpack = rspack;
compilation!: Compilation;
// @ts-expect-error
compilation: Compilation;
// TODO: remove this after remove rebuild on the rust side.
first: boolean = true;
builtinPlugins: binding.BuiltinPlugin[];
Expand All @@ -68,9 +69,11 @@ class Compiler {
inputFileSystem: any;
outputFileSystem: typeof import("fs");
ruleSet: RuleSetCompiler;
watchFileSystem!: WatchFileSystem;
// @ts-expect-error
watchFileSystem: WatchFileSystem;
intermediateFileSystem: any;
watchMode?: boolean;
// @ts-expect-error
watchMode: boolean;
context: string;
modifiedFiles?: ReadonlySet<string>;
cache: Cache;
Expand All @@ -94,7 +97,7 @@ class Compiler {
contextModuleFactory: tapable.SyncHook<ContextModuleFactory>;
initialize: tapable.SyncHook<[]>;
shouldEmit: tapable.SyncBailHook<[Compilation], boolean>;
infrastructureLog: tapable.SyncBailHook<[string, string, any[]?], true>;
infrastructureLog: tapable.SyncBailHook<[string, string, any[]], true>;
beforeRun: tapable.AsyncSeriesHook<[Compiler]>;
run: tapable.AsyncSeriesHook<[Compiler]>;
emit: tapable.AsyncSeriesHook<[Compilation]>;
Expand Down Expand Up @@ -450,6 +453,7 @@ class Compiler {
}
} else {
if (
// @ts-expect-error
this.hooks.infrastructureLog.call(name, type, args) === undefined
) {
if (this.infrastructureLogger !== undefined) {
Expand All @@ -461,7 +465,8 @@ class Compiler {
(childName): any => {
if (typeof name === "function") {
if (typeof childName === "function") {
return this.getInfrastructureLogger(() => {
// @ts-expect-error
return this.getInfrastructureLogger(_ => {
if (typeof name === "function") {
name = name();
if (!name) {
Expand Down Expand Up @@ -914,7 +919,8 @@ class Compiler {
const startTime = Date.now();
this.running = true;
const doRun = () => {
const finalCallback = (err: Error | null, stats?: Stats) => {
// @ts-expect-error
const finalCallback = (err, stats?) => {
this.idle = true;
this.cache.beginIdle();
this.idle = true;
Expand All @@ -925,7 +931,7 @@ class Compiler {
if (callback) {
callback(err, stats);
}
stats && this.hooks.afterDone.call(stats);
this.hooks.afterDone.call(stats);
};
this.hooks.beforeRun.callAsync(this, err => {
if (err) {
Expand Down Expand Up @@ -1050,15 +1056,14 @@ class Compiler {
});
}

watch(
watchOptions: WatchOptions,
handler: (error?: Error, stats?: Stats) => void
): Watching | void {
watch(watchOptions: WatchOptions, handler: Callback<Error, Stats>): Watching {
if (this.running) {
// @ts-expect-error
return handler(new ConcurrentCompilationError());
}
this.running = true;
this.watchMode = true;
// @ts-expect-error
this.watching = new Watching(this, watchOptions, handler);
return this.watching;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/MultiCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ export class MultiCompiler {
},
(compiler, watching, _done) => {
if (compiler.watching !== watching) return;
if (!watching?.running) watching?.invalidate();
if (!watching.running) watching.invalidate();
},
handler
);
Expand Down
1 change: 0 additions & 1 deletion packages/rspack/src/config/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ const watchOptions = z.strictObject({
.array()
.or(z.instanceof(RegExp))
.or(z.string())
.or(z.function(z.tuple([z.string()])).returns(z.boolean()))
.optional(),
poll: z.number().or(z.boolean()).optional(),
stdin: z.boolean().optional()
Expand Down
3 changes: 1 addition & 2 deletions packages/rspack/src/node/NodeWatchFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
*/

import util from "util";
import Watchpack from "watchpack";
import { WatchOptions } from "../config";
import Watchpack, { WatchOptions } from "watchpack";
import { FileSystemInfoEntry, Watcher, WatchFileSystem } from "../util/fs";

export default class NodeWatchFileSystem implements WatchFileSystem {
Expand Down

2 comments on commit a394aa7

@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-03-14 769ca8e) Current Change
10000_development-mode + exec 1.74 s ± 19 ms 1.78 s ± 13 ms +2.50 %
10000_development-mode_hmr + exec 723 ms ± 9.4 ms 719 ms ± 7.5 ms -0.57 %
10000_production-mode + exec 2.67 s ± 27 ms 2.66 s ± 28 ms -0.03 %
arco-pro_development-mode + exec 3.04 s ± 20 ms 3.02 s ± 58 ms -0.50 %
arco-pro_development-mode_hmr + exec 510 ms ± 2.8 ms 512 ms ± 4.2 ms +0.32 %
arco-pro_development-mode_hmr_intercept-plugin + exec 524 ms ± 16 ms 525 ms ± 3.6 ms +0.06 %
arco-pro_development-mode_intercept-plugin + exec 3.32 s ± 104 ms 3.27 s ± 42 ms -1.46 %
arco-pro_production-mode + exec 4.64 s ± 40 ms 4.69 s ± 96 ms +1.01 %
arco-pro_production-mode_intercept-plugin + exec 4.89 s ± 44 ms 5.03 s ± 71 ms +2.66 %
threejs_development-mode_10x + exec 1.82 s ± 33 ms 1.81 s ± 26 ms -0.72 %
threejs_development-mode_10x_hmr + exec 728 ms ± 6 ms 728 ms ± 7 ms -0.02 %
threejs_production-mode_10x + exec 5.8 s ± 64 ms 5.78 s ± 39 ms -0.38 %

@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 ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
compat ✅ success
examples ✅ success

Please sign in to comment.