diff --git a/biome.jsonc b/biome.jsonc index f9bd0cf85e3..1c9c610acd5 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -38,30 +38,16 @@ "useKeyWithClickEvents": "off" }, "complexity": { - "noMultipleSpacesInRegularExpressionLiterals": "off", "noStaticOnlyClass": "off", "noThisInStatic": "off", - "noUselessConstructor": "off", - "noBannedTypes": "off", - "useOptionalChain": "off", - "noUselessEmptyExport": "off", - "noExtraBooleanCast": "off" + "noBannedTypes": "off" }, "correctness": { "noConstructorReturn": "off", - "noSwitchDeclarations": "off", - "noInvalidUseBeforeDeclaration": "off", - "noInnerDeclarations": "off", "noVoidTypeReturn": "off" }, "style": { - "noCommaOperator": "off", - "useExponentiationOperator": "off", - "useShorthandFunctionType": "off", - "noArguments": "off", - "noInferrableTypes": "off", "noParameterAssign": "off", - "useSingleVarDeclarator": "off", "noNonNullAssertion": "off" }, "performance": { @@ -72,16 +58,12 @@ "noGlobalEval": "off" }, "suspicious": { - "noEmptyInterface": "off", - "noGlobalAssign": "off", - "noGlobalIsNan": "off", "noFallthroughSwitchClause": "off", "noConfusingVoidType": "off", "noPrototypeBuiltins": "off", "noImplicitAnyLet": "off", "noAssignInExpressions": "off", "noArrayIndexKey": "off", - "noRedundantUseStrict": "off", "noControlCharactersInRegex": "off", "noExplicitAny": "off" } @@ -106,4 +88,4 @@ "clientKind": "git", "useIgnoreFile": true } -} \ No newline at end of file +} diff --git a/packages/playground/cases/react/worker/src/worker.js b/packages/playground/cases/react/worker/src/worker.js index 01baa84f07d..6c9e60d02e4 100644 --- a/packages/playground/cases/react/worker/src/worker.js +++ b/packages/playground/cases/react/worker/src/worker.js @@ -1,6 +1,6 @@ import Button from "./Button"; -onmessage = e => { +window.onmessage = () => { Button.add(); postMessage(Button.get()); }; diff --git a/packages/rspack-cli/src/commands/build.ts b/packages/rspack-cli/src/commands/build.ts index 6f02d0cc796..f647304fb89 100644 --- a/packages/rspack-cli/src/commands/build.ts +++ b/packages/rspack-cli/src/commands/build.ts @@ -53,7 +53,7 @@ export class BuildCommand implements RspackCommand { logger.error(error); process.exit(2); } - if (stats && stats.hasErrors()) { + if (stats?.hasErrors()) { process.exitCode = 1; } if (!compiler || !stats) { diff --git a/packages/rspack-dev-server/src/ansiHTML.ts b/packages/rspack-dev-server/src/ansiHTML.ts index e7c2c37c2bd..480a0cc50a2 100644 --- a/packages/rspack-dev-server/src/ansiHTML.ts +++ b/packages/rspack-dev-server/src/ansiHTML.ts @@ -62,9 +62,9 @@ const _openTags: Record Option)> = { // color const mode = _colorMode[match[0]]; if (mode === "rgb") { - const r = match[1], - g = match[2], - b = match[3]; + const r = match[1]; + const g = match[2]; + const b = match[3]; match.advance(4); return `color: rgb(${r},${g},${b})`; } @@ -73,9 +73,9 @@ const _openTags: Record Option)> = { // background color const mode = _colorMode[match[0]]; if (mode === "rgb") { - const r = match[1], - g = match[2], - b = match[3]; + const r = match[1]; + const g = match[2]; + const b = match[3]; match.advance(4); return `background-color: rgb(${r},${g},${b})`; } @@ -95,8 +95,8 @@ const _closeTags: Record< 0: ansiCodes => { if (!ansiCodes) return ""; if (!ansiCodes.length) return ""; - let code: Option, - ret = ""; + let code: Option; + let ret = ""; while ((code = ansiCodes.pop())) { const closeTag = _openTagToCloseTag[code]; if (closeTag) { @@ -147,8 +147,8 @@ export default function ansiHTML(text: string) { this.splice(0, count); } }); - let seq, - rep = ""; + let seq; + let rep = ""; while ((seq = match[0])) { match.advance(1); rep += applySeq(seq); @@ -169,8 +169,7 @@ export default function ansiHTML(text: string) { )(ansiCodes); } // If current sequence has been opened, close it. - if (!!~ansiCodes.indexOf(seq)) { - // eslint-disable-line no-extra-boolean-cast + if (ansiCodes.indexOf(seq) !== -1) { ansiCodes.pop(); return ""; } diff --git a/packages/rspack-lite-tapable/src/index.ts b/packages/rspack-lite-tapable/src/index.ts index 2e5fa9dfe66..6c7fbb68a9c 100644 --- a/packages/rspack-lite-tapable/src/index.ts +++ b/packages/rspack-lite-tapable/src/index.ts @@ -441,7 +441,8 @@ export class SyncHook< queried: QueriedHook, ...args: AsArray ): R { - let result, error; + let result; + let error; this.callAsyncStageRange( queried, // @ts-expect-error @@ -514,7 +515,8 @@ export class SyncBailHook< queried: QueriedHook, ...args: AsArray ): R { - let result, error; + let result; + let error; this.callAsyncStageRange( queried, // @ts-expect-error @@ -593,7 +595,8 @@ export class SyncWaterfallHook< queried: QueriedHook[0], AdditionalOptions>, ...args: AsArray ): AsArray[0] { - let result, error; + let result; + let error; this.callAsyncStageRange( queried, // @ts-expect-error diff --git a/packages/rspack-plugin-react-refresh/src/utils/getAdditionalEntries.ts b/packages/rspack-plugin-react-refresh/src/utils/getAdditionalEntries.ts index c5af2b5848e..15ccb327132 100644 --- a/packages/rspack-plugin-react-refresh/src/utils/getAdditionalEntries.ts +++ b/packages/rspack-plugin-react-refresh/src/utils/getAdditionalEntries.ts @@ -13,7 +13,6 @@ export function getAdditionalEntries({ devServer: any; options: NormalizedPluginOptions; }): AdditionalEntries { - /** @type {Record} */ const resourceQuery: Record = {}; if (devServer) { @@ -78,12 +77,8 @@ export function getAdditionalEntries({ undefined, undefined, { - /** - * @param {string} string - * @returns {string} - */ - encodeURIComponent(string) { - return string; + encodeURIComponent(str: string): string { + return str; } } ); @@ -95,8 +90,8 @@ export function getAdditionalEntries({ const overlayEntries = [ // Error overlay runtime - options.overlay && - options.overlay.entry && + options.overlay !== false && + options.overlay?.entry && `${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ""}` ].filter(Boolean) as string[]; diff --git a/packages/rspack-test-tools/etc/api.md b/packages/rspack-test-tools/etc/api.md index 2ef2be6e55b..a255342679d 100644 --- a/packages/rspack-test-tools/etc/api.md +++ b/packages/rspack-test-tools/etc/api.md @@ -1522,7 +1522,6 @@ export class WebpackDiffConfigPlugin { // @public (undocumented) export class WebpackModulePlaceholderPlugin { - constructor(); // (undocumented) apply(compiler: any): void; } diff --git a/packages/rspack-test-tools/src/compiler.ts b/packages/rspack-test-tools/src/compiler.ts index 5e95e9a2755..0fd82523761 100644 --- a/packages/rspack-test-tools/src/compiler.ts +++ b/packages/rspack-test-tools/src/compiler.ts @@ -79,7 +79,7 @@ export class TestCompilerManager }); } - watch(timeout: number = 1000) { + watch(timeout = 1000) { if (!this.compilerInstance) throw new Error("Compiler should be created before watch"); this.compilerInstance!.watch( diff --git a/packages/rspack-test-tools/src/helper/legacy/checkArrayExpectation.js b/packages/rspack-test-tools/src/helper/legacy/checkArrayExpectation.js index dff10c7fe6f..53dde62cbf1 100644 --- a/packages/rspack-test-tools/src/helper/legacy/checkArrayExpectation.js +++ b/packages/rspack-test-tools/src/helper/legacy/checkArrayExpectation.js @@ -94,63 +94,56 @@ module.exports = function checkArrayExpectation( const diff = diffItems(array, expected, kind); if (expected.length < array.length) { - return ( - done( - new Error( - `More ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}` - ) - ), - true + done( + new Error( + `More ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}` + ) ); + + return true; } if (expected.length > array.length) { - return ( - done( - new Error( - `Less ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}` - ) - ), - true + done( + new Error( + `Less ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}` + ) ); + return true; } for (let i = 0; i < array.length; i++) { if (Array.isArray(expected[i])) { for (let j = 0; j < expected[i].length; j++) { if (!check(expected[i][j], array[i])) { - return ( - done( - new Error( - `${upperCaseKind} ${i}: ${explain( - array[i] - )} doesn't match ${explain(expected[i][j])}` - ) - ), - true + done( + new Error( + `${upperCaseKind} ${i}: ${explain( + array[i] + )} doesn't match ${explain(expected[i][j])}` + ) ); + + return true; } } - } else if (!check(expected[i], array[i])) - return ( - done( - new Error( - `${upperCaseKind} ${i}: ${explain( - array[i] - )} doesn't match ${explain(expected[i])}` - ) - ), - true + } else if (!check(expected[i], array[i])) { + done( + new Error( + `${upperCaseKind} ${i}: ${explain( + array[i] + )} doesn't match ${explain(expected[i])}` + ) ); + return true; + } } } else if (array.length > 0) { - return ( - done( - new Error( - `${upperCaseKind}s while compiling:\n\n${array - .map(explain) - .join("\n\n")}` - ) - ), - true + done( + new Error( + `${upperCaseKind}s while compiling:\n\n${array + .map(explain) + .join("\n\n")}` + ) ); + return true; } }; diff --git a/packages/rspack-test-tools/src/helper/legacy/copyDiff.js b/packages/rspack-test-tools/src/helper/legacy/copyDiff.js index da77d376d4d..c26f87f2488 100644 --- a/packages/rspack-test-tools/src/helper/legacy/copyDiff.js +++ b/packages/rspack-test-tools/src/helper/legacy/copyDiff.js @@ -13,7 +13,7 @@ module.exports = function copyDiff(src, dest, initial) { if (directory) { copyDiff(srcFile, destFile, initial); } else { - var content = fs.readFileSync(srcFile); + const content = fs.readFileSync(srcFile); if (/^DELETE\s*$/.test(content.toString("utf-8"))) { fs.unlinkSync(destFile); } else if (/^DELETE_DIRECTORY\s*$/.test(content.toString("utf-8"))) { diff --git a/packages/rspack-test-tools/src/helper/setup-env.ts b/packages/rspack-test-tools/src/helper/setup-env.ts index bf467b73d6e..51ea46cd423 100644 --- a/packages/rspack-test-tools/src/helper/setup-env.ts +++ b/packages/rspack-test-tools/src/helper/setup-env.ts @@ -38,7 +38,7 @@ if (process.env.DEBUG_INFO) { process.stdout.write(`START1 ${name}\n`); try { const promise = fn(); - if (promise && promise.then) { + if (promise?.then) { return promise.then( r => { process.stdout.write(`DONE OK ${name}\n`); diff --git a/packages/rspack-test-tools/src/helper/util/identifier.js b/packages/rspack-test-tools/src/helper/util/identifier.js index 2c7966b4366..7ed0c451e46 100644 --- a/packages/rspack-test-tools/src/helper/util/identifier.js +++ b/packages/rspack-test-tools/src/helper/util/identifier.js @@ -1,9 +1,7 @@ // @ts-nocheck /* - MIT License http://www.opensource.org/licenses/mit-license.php -*/ - -"use strict"; + * MIT License http://www.opensource.org/licenses/mit-license.php + */ const path = require("node:path"); diff --git a/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts b/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts index ad0c7b4ea96..2454e79e81c 100644 --- a/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts +++ b/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts @@ -56,7 +56,6 @@ function createRenderRuntimeModulesFn(Template) { const caches = new WeakMap(); export class WebpackModulePlaceholderPlugin { - constructor() {} apply(compiler) { const { webpack } = compiler; const { diff --git a/packages/rspack-test-tools/src/processor/config.ts b/packages/rspack-test-tools/src/processor/config.ts index a5cf67328c1..c76601026ad 100644 --- a/packages/rspack-test-tools/src/processor/config.ts +++ b/packages/rspack-test-tools/src/processor/config.ts @@ -37,7 +37,7 @@ export class ConfigProcessor< options.output?.path && fs.existsSync(path.join(options.output.path!, `bundle${index}${ext}`)) ) { - if (options.experiments && options.experiments.css) { + if (options.experiments?.css) { const cssOutputPath = path.join( options.output.path!, (typeof options.output?.cssFilename === "string" && diff --git a/packages/rspack-test-tools/src/processor/hook.ts b/packages/rspack-test-tools/src/processor/hook.ts index cdfd62f172e..b25f562f476 100644 --- a/packages/rspack-test-tools/src/processor/hook.ts +++ b/packages/rspack-test-tools/src/processor/hook.ts @@ -78,7 +78,7 @@ const serialize = (val: unknown, indent = 2, formatOverrides = {}) => export class HookCasesContext extends TestContext { protected promises: Promise[] = []; - protected count: number = 0; + protected count = 0; protected snapshots: Record< string | number, Array<[string | Buffer, string]> diff --git a/packages/rspack-test-tools/src/processor/stats.ts b/packages/rspack-test-tools/src/processor/stats.ts index 43997e5032f..b5398057312 100644 --- a/packages/rspack-test-tools/src/processor/stats.ts +++ b/packages/rspack-test-tools/src/processor/stats.ts @@ -1,5 +1,3 @@ -/* eslint-disable no-control-regex */ - import fs from "node:fs"; import path from "node:path"; import type { Compiler, Stats } from "@rspack/core"; @@ -51,8 +49,7 @@ export class StatsProcessor< for (const compiler of compilers) { const ifs = compiler.inputFileSystem; compiler.inputFileSystem = Object.create(ifs); - compiler.inputFileSystem.readFile = () => { - const args = Array.prototype.slice.call(arguments); + compiler.inputFileSystem.readFile = (...args: any[]) => { const callback = args.pop(); ifs.readFile.apply( ifs, @@ -171,7 +168,7 @@ export class StatsProcessor< actual = actual .replace(/\r\n?/g, "\n") // CHANGE: Remove potential line break and "|" caused by long text - .replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n │ )/g, "$1") + .replace(/((ERROR|WARNING)([\s\S](?!╭|├))*?)(\n {2}│ )/g, "$1") // CHANGE: Update the regular expression to replace the 'Rspack' version string .replace(/Rspack [^ )]+(\)?) compiled/g, "Rspack x.x.x$1 compiled") .replace( diff --git a/packages/rspack-test-tools/src/test/tester.ts b/packages/rspack-test-tools/src/test/tester.ts index a471685e042..43a5b539796 100644 --- a/packages/rspack-test-tools/src/test/tester.ts +++ b/packages/rspack-test-tools/src/test/tester.ts @@ -10,8 +10,8 @@ import { TestContext } from "./context"; export class Tester implements ITester { private context: ITestContext; private steps: ITestProcessor[] = []; - step: number = 0; - total: number = 0; + step = 0; + total = 0; constructor(private config: ITesterConfig) { this.context = new TestContext(config); @@ -81,7 +81,7 @@ export class Tester implements ITester { private async runStepMethods( step: ITestProcessor, methods: Array<"before" | "config" | "compiler" | "build" | "after">, - force: boolean = false + force = false ) { for (const i of methods) { if (!force && this.context.hasError()) return; diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-push.js b/packages/rspack-test-tools/tests/errorCases/error-test-push.js index d1f99a21993..8c6028bf8f0 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-push.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-push.js:10:31)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "loc": "1:0-33", diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js index f5fe2b29cad..e61a107167c 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-shift.js @@ -24,7 +24,7 @@ module.exports = { Object { "message": " × Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-shift.js:13:35)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], "warnings": Array [], diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js index 04b01fff7be..9eac3926e4b 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-1.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], "warnings": Array [], diff --git a/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js index c74c2969d73..096c4d2c88f 100644 --- a/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js @@ -20,7 +20,7 @@ module.exports = { Object { "message": " × Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/error-test-splice-2.js:10:39)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "loc": "1:0-33", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js index d40f15eedad..5d81454ecc6 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-push.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-push.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test push\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test push\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-push.js:10:33)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js index 3b3e7a79232..bbca70a6063 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-shift.js @@ -25,7 +25,7 @@ module.exports = { Object { "message": " ⚠ Error: test unshift\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test unshift\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-shift.js:13:37)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js index 2b8755f6f01..38d104a1d0a 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-1.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, ], } diff --git a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js index 24a8d88ba43..f79639ff8aa 100644 --- a/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js +++ b/packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js @@ -21,7 +21,7 @@ module.exports = { Object { "message": " ⚠ Error: test splice\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n │ at xxx\\n", "moduleTrace": Array [], - "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:526:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:546:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", + "stack": "Error: test splice\\n at Object.fn (packages/rspack-test-tools/tests/errorCases/warning-test-splice-2.js:10:41)\\n at next (packages/rspack-lite-tapable/dist/index.js:529:25)\\n at AsyncSeriesHook.callAsyncStageRange (packages/rspack-lite-tapable/dist/index.js:549:9)\\n at AsyncSeriesHook.callAsync (packages/rspack-lite-tapable/dist/index.js:88:21)\\n at packages/rspack/dist/Compiler.js:458:41\\n at packages/rspack/dist/Compiler.js:525:23", }, Object { "message": " ⚠ Module parse warning:\\n ╰─▶ ⚠ Unsupported feature: require.main.require() is not supported by Rspack.\\n ╭────\\n 1 │ require.main.require('./file');\\n · ──────────────────────────────\\n ╰────\\n \\n", diff --git a/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt index 877e86dcea8..209399b7b6b 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web/2.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 7241 +- Update: main.LAST_HASH.hot-update.js, size: 7181 ## Manifest @@ -44,10 +44,8 @@ const noDocument = typeof document === "undefined"; const { forEach } = Array.prototype; function debounce(fn, time) { let timeout = 0; - return function () { - // @ts-ignore + return function (...args) { const self = this; - const args = arguments; const functionCall = function functionCall() { return fn.apply(self, args); }; @@ -76,7 +74,7 @@ function getCurrentScriptUrl(moduleId) { return null; } const splitResult = src.split(/([^//]+)/.js$/); - const filename = splitResult && splitResult[1]; + const filename = splitResult?.[1]; if (!filename) { return [src.replace(".js", ".css")]; } diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index f9f0858f6e1..8858c483609 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -4428,7 +4428,6 @@ export const javascript: JavaScript; // @public (undocumented) class JavascriptModulesPlugin extends RspackBuiltinPlugin { - constructor(); // (undocumented) affectedHooks: "compilation"; // (undocumented) @@ -5144,10 +5143,7 @@ export type LoaderDefinition = LoaderDe }; // @public (undocumented) -export interface LoaderDefinitionFunction { - // (undocumented) - (this: LoaderContext & ContextAdditions, content: string, sourceMap?: string | SourceMap, additionalData?: AdditionalData): string | void | Buffer | Promise; -} +export type LoaderDefinitionFunction = (this: LoaderContext & ContextAdditions, content: string, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => string | void | Buffer | Promise; // @public (undocumented) class LoaderObject { @@ -8543,10 +8539,7 @@ const performance_2: z.ZodUnion<[z.ZodObject<{ }>, z.ZodLiteral]>; // @public (undocumented) -interface PitchLoaderDefinitionFunction { - // (undocumented) - (this: LoaderContext & ContextAdditions, remainingRequest: string, previousRequest: string, data: object): string | void | Buffer | Promise; -} +type PitchLoaderDefinitionFunction = (this: LoaderContext & ContextAdditions, remainingRequest: string, previousRequest: string, data: object) => string | void | Buffer | Promise; // @public (undocumented) type PluginImportConfig = { @@ -8738,8 +8731,7 @@ export type ResolveAlias = z.infer; const resolveAlias: z.ZodRecord, z.ZodString]>, z.ZodArray]>, "many">]>>; // @public (undocumented) -interface ResolveContext { -} +type ResolveContext = {}; // @public (undocumented) type ResolveData = { @@ -12813,7 +12805,6 @@ export const rspackOptions: z.ZodObject<{ // @public (undocumented) class RspackOptionsApply { - constructor(); // (undocumented) process(options: RspackOptionsNormalized, compiler: Compiler): void; } @@ -14197,8 +14188,7 @@ interface TerserMangleOptions { } // @public (undocumented) -interface TerserManglePropertiesOptions { -} +type TerserManglePropertiesOptions = {}; // @public (undocumented) const TIMERS_AGGREGATES_SYMBOL: unique symbol; @@ -14523,7 +14513,6 @@ export const WebpackError: ErrorConstructor; class WebpackError_2 extends Error { // (undocumented) [inspect.custom](): string; - constructor(message?: string); // (undocumented) chunk?: Chunk; // (undocumented) diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index 2a391b86655..29e2c782bb2 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -500,7 +500,7 @@ class Compiler { } purgeInputFileSystem() { - if (this.inputFileSystem && this.inputFileSystem.purge) { + if (this.inputFileSystem?.purge) { this.inputFileSystem.purge(); } } diff --git a/packages/rspack/src/ExecuteModulePlugin.ts b/packages/rspack/src/ExecuteModulePlugin.ts index 177f776952e..2cb5bec64dd 100644 --- a/packages/rspack/src/ExecuteModulePlugin.ts +++ b/packages/rspack/src/ExecuteModulePlugin.ts @@ -4,8 +4,6 @@ import { RuntimeGlobals } from "."; import type { Compiler } from "./Compiler"; export default class ExecuteModulePlugin { - constructor() {} - apply(compiler: Compiler) { compiler.hooks.compilation.tap("executeModule", compilation => { compilation.hooks.executeModule.tap( diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index ee7cc93a09d..184d7dbff6d 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -1,6 +1,5 @@ import type { JsCodegenerationResult, - JsCodegenerationResults, JsCreateData, JsFactoryMeta, JsModule @@ -134,6 +133,4 @@ export class CodeGenerationResult { } } -export class CodeGenerationResults { - constructor(_result: JsCodegenerationResults) {} -} +export class CodeGenerationResults {} diff --git a/packages/rspack/src/MultiCompiler.ts b/packages/rspack/src/MultiCompiler.ts index 7d65894f959..c86edac0ab4 100644 --- a/packages/rspack/src/MultiCompiler.ts +++ b/packages/rspack/src/MultiCompiler.ts @@ -531,7 +531,7 @@ export class MultiCompiler { purgeInputFileSystem() { for (const compiler of this.compilers) { - if (compiler.inputFileSystem && compiler.inputFileSystem.purge) { + if (compiler.inputFileSystem?.purge) { compiler.inputFileSystem.purge(); } } diff --git a/packages/rspack/src/Resolver.ts b/packages/rspack/src/Resolver.ts index 8392d88fcd8..eb527eff5aa 100644 --- a/packages/rspack/src/Resolver.ts +++ b/packages/rspack/src/Resolver.ts @@ -1,7 +1,7 @@ import type * as binding from "@rspack/binding"; import { type Resolve, getRawResolve } from "./config"; -interface ResolveContext {} +type ResolveContext = {}; type ErrorWithDetail = Error & { details?: string }; diff --git a/packages/rspack/src/builtin-loader/lightningcss/index.ts b/packages/rspack/src/builtin-loader/lightningcss/index.ts index 64d9a211d6b..ccfebaa5f2c 100644 --- a/packages/rspack/src/builtin-loader/lightningcss/index.ts +++ b/packages/rspack/src/builtin-loader/lightningcss/index.ts @@ -147,7 +147,7 @@ function parseVersion(version: string) { .split(".") .map(v => Number.parseInt(v, 10)); - if (isNaN(major) || isNaN(minor) || isNaN(patch)) { + if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) { return null; } diff --git a/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts b/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts index d829f0cf4d8..07551a5cb8c 100644 --- a/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts +++ b/packages/rspack/src/builtin-plugin/ExternalsPlugin.ts @@ -38,7 +38,7 @@ function getRawExternalItem(item: ExternalItem | undefined): RawExternalItem { externalType: type }); }) as Promise; - if (promise && promise.then) { + if (promise?.then) { promise.then( result => resolve({ diff --git a/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts b/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts index bb102969a85..74ee1406c59 100644 --- a/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts +++ b/packages/rspack/src/builtin-plugin/JavascriptModulesPlugin.ts @@ -17,10 +17,6 @@ export class JavascriptModulesPlugin extends RspackBuiltinPlugin { name = BuiltinPluginName.JavascriptModulesPlugin; affectedHooks = "compilation" as const; - constructor() { - super(); - } - raw(): BuiltinPlugin { return createBuiltinPlugin(this.name, undefined); } diff --git a/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts b/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts index 7108b73dec5..cf1274ed6e6 100644 --- a/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts +++ b/packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts @@ -215,7 +215,7 @@ export interface TerserMangleOptions { safari10?: boolean; reserved?: string[]; } -export interface TerserManglePropertiesOptions {} +export type TerserManglePropertiesOptions = {}; function isObject(value: any): value is Object { const type = typeof value; diff --git a/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts b/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts index 361056f30e9..06778ebfcf4 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts @@ -17,13 +17,11 @@ function debounce any>( ): DebouncedFunction { let timeout: NodeJS.Timeout | number = 0; - return function () { - // @ts-ignore + return function (this: any, ...args: Parameters[]) { const self = this; - const args = arguments; const functionCall = function functionCall() { - return fn.apply(self, args as unknown as Parameters); + return fn.apply(self, args as Parameters); }; clearTimeout(timeout); @@ -58,7 +56,7 @@ function getCurrentScriptUrl(moduleId: string) { } const splitResult = src.split(/([^\\/]+)\.js$/); - const filename = splitResult && splitResult[1]; + const filename = splitResult?.[1]; if (!filename) { return [src.replace(".js", ".css")]; diff --git a/packages/rspack/src/builtin-plugin/css-extract/index.ts b/packages/rspack/src/builtin-plugin/css-extract/index.ts index ccc7823860c..e23524c7174 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/index.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/index.ts @@ -24,7 +24,7 @@ export interface CssExtractRspackPluginOptions { } export class CssExtractRspackPlugin { - static pluginName: string = "css-extract-rspack-plugin"; + static pluginName = "css-extract-rspack-plugin"; static loader: string = LOADER_PATH; options: CssExtractRspackPluginOptions; diff --git a/packages/rspack/src/builtin-plugin/css-extract/loader.ts b/packages/rspack/src/builtin-plugin/css-extract/loader.ts index a6c1792b8c5..bcd6dd40dcf 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/loader.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/loader.ts @@ -75,10 +75,7 @@ export function hotLoader( const loader: LoaderDefinition = function loader(content) { if ( - this._compiler && - this._compiler.options && - this._compiler.options.experiments && - this._compiler.options.experiments.css && + this._compiler?.options?.experiments?.css && this._module && (this._module.type === "css" || this._module.type === "css/auto" || @@ -91,10 +88,7 @@ const loader: LoaderDefinition = function loader(content) { export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { if ( - this._compiler && - this._compiler.options && - this._compiler.options.experiments && - this._compiler.options.experiments.css && + this._compiler?.options?.experiments?.css && this._module && (this._module.type === "css" || this._module.type === "css/auto" || @@ -182,7 +176,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { } } } else { - locals = exports && exports.locals; + locals = exports?.locals; } if (Array.isArray(exports) && emit) { diff --git a/packages/rspack/src/builtin-plugin/lazy-compilation/backend.ts b/packages/rspack/src/builtin-plugin/lazy-compilation/backend.ts index 54b0f177780..9171136a3a7 100644 --- a/packages/rspack/src/builtin-plugin/lazy-compilation/backend.ts +++ b/packages/rspack/src/builtin-plugin/lazy-compilation/backend.ts @@ -1,9 +1,7 @@ /* - MIT License http://www.opensource.org/licenses/mit-license.php - Author Tobias Koppers @sokra -*/ - -"use strict"; + * MIT License http://www.opensource.org/licenses/mit-license.php + * Author Tobias Koppers @sokra + */ import type { IncomingMessage, diff --git a/packages/rspack/src/config/adapterRuleUse.ts b/packages/rspack/src/config/adapterRuleUse.ts index c5f0ad8f89f..fc838cdd92c 100644 --- a/packages/rspack/src/config/adapterRuleUse.ts +++ b/packages/rspack/src/config/adapterRuleUse.ts @@ -153,29 +153,25 @@ export interface LoaderContext { _module: Module; } -export interface LoaderDefinitionFunction< +export type LoaderDefinitionFunction< OptionsType = {}, ContextAdditions = {} -> { - ( - this: LoaderContext & ContextAdditions, - content: string, - sourceMap?: string | SourceMap, - additionalData?: AdditionalData - ): string | void | Buffer | Promise; -} +> = ( + this: LoaderContext & ContextAdditions, + content: string, + sourceMap?: string | SourceMap, + additionalData?: AdditionalData +) => string | void | Buffer | Promise; -export interface PitchLoaderDefinitionFunction< +export type PitchLoaderDefinitionFunction< OptionsType = {}, ContextAdditions = {} -> { - ( - this: LoaderContext & ContextAdditions, - remainingRequest: string, - previousRequest: string, - data: object - ): string | void | Buffer | Promise; -} +> = ( + this: LoaderContext & ContextAdditions, + remainingRequest: string, + previousRequest: string, + data: object +) => string | void | Buffer | Promise; export type LoaderDefinition< OptionsType = {}, @@ -263,8 +259,8 @@ function createRawModuleRuleUsesImpl( } return uses.map((use, index) => { - let o, - isBuiltin = false; + let o; + let isBuiltin = false; if (use.loader.startsWith(BUILTIN_LOADER_PREFIX)) { o = getBuiltinLoaderOptions(use.loader, use.options, options); o = isNil(o) ? undefined : typeof o === "string" ? o : JSON.stringify(o); diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 1d7568b842f..10d8bccfba6 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -781,8 +781,8 @@ const applyOutputDefaults = ( const conditionallyOptimistic = (v?: boolean, c?: boolean) => (v === undefined && c) || v; - F(environment, "globalThis", () => tp && tp.globalThis); - F(environment, "bigIntLiteral", () => tp && tp.bigIntLiteral); + F(environment, "globalThis", () => tp?.globalThis); + F(environment, "bigIntLiteral", () => tp?.bigIntLiteral); F(environment, "const", () => tp && optimistic(tp.const)); F(environment, "arrowFunction", () => tp && optimistic(tp.arrowFunction)); F(environment, "asyncFunction", () => tp && optimistic(tp.asyncFunction)); @@ -800,13 +800,13 @@ const applyOutputDefaults = ( ); F(environment, "templateLiteral", () => tp && optimistic(tp.templateLiteral)); F(environment, "dynamicImport", () => - conditionallyOptimistic(tp && tp.dynamicImport, output.module) + conditionallyOptimistic(tp?.dynamicImport, output.module) ); F(environment, "dynamicImportInWorker", () => - conditionallyOptimistic(tp && tp.dynamicImportInWorker, output.module) + conditionallyOptimistic(tp?.dynamicImportInWorker, output.module) ); F(environment, "module", () => - conditionallyOptimistic(tp && tp.module, output.module) + conditionallyOptimistic(tp?.module, output.module) ); F(environment, "document", () => tp && optimistic(tp.document)); }; @@ -815,35 +815,25 @@ const applyExternalsPresetsDefaults = ( externalsPresets: ExternalsPresets, { targetProperties }: { targetProperties: any } ) => { - D(externalsPresets, "web", targetProperties && targetProperties.web); - D(externalsPresets, "node", targetProperties && targetProperties.node); - D( - externalsPresets, - "electron", - targetProperties && targetProperties.electron - ); + D(externalsPresets, "web", targetProperties?.web); + D(externalsPresets, "node", targetProperties?.node); + D(externalsPresets, "electron", targetProperties?.electron); D( externalsPresets, "electronMain", - targetProperties && - targetProperties.electron && - targetProperties.electronMain + targetProperties?.electron && targetProperties.electronMain ); D( externalsPresets, "electronPreload", - targetProperties && - targetProperties.electron && - targetProperties.electronPreload + targetProperties?.electron && targetProperties.electronPreload ); D( externalsPresets, "electronRenderer", - targetProperties && - targetProperties.electron && - targetProperties.electronRenderer + targetProperties?.electron && targetProperties.electronRenderer ); - D(externalsPresets, "nwjs", targetProperties && targetProperties.nwjs); + D(externalsPresets, "nwjs", targetProperties?.nwjs); }; const applyLoaderDefaults = ( @@ -874,17 +864,17 @@ const applyNodeDefaults = ( // IGNORE(node.global): The default value of `global` is determined by `futureDefaults` in webpack. F(node, "global", () => { - if (targetProperties && targetProperties.global) return false; + if (targetProperties?.global) return false; return "warn"; }); // IGNORE(node.__dirname): The default value of `__dirname` is determined by `futureDefaults` in webpack. F(node, "__dirname", () => { - if (targetProperties && targetProperties.node) return "eval-only"; + if (targetProperties?.node) return "eval-only"; return "warn-mock"; }); // IGNORE(node.__filename): The default value of `__filename` is determined by `futureDefaults` in webpack. F(node, "__filename", () => { - if (targetProperties && targetProperties.node) return "eval-only"; + if (targetProperties?.node) return "eval-only"; return "warn-mock"; }); }; @@ -1018,7 +1008,7 @@ const getResolveDefaults = ({ const tp = targetProperties; const browserField = - tp && tp.web && (!tp.node || (tp.electron && tp.electronRenderer)); + tp?.web && (!tp.node || (tp.electron && tp.electronRenderer)); const aliasFields = browserField ? ["browser"] : []; const mainFields = browserField ? ["browser", "module", "..."] diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 36cd570002b..451757c702e 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -417,12 +417,12 @@ const keyedNestedConfig = ( value === undefined ? {} : Object.keys(value).reduce( - (obj, key) => ( - (obj[key] = ( - customKeys && key in customKeys ? customKeys[key] : fn - )(value[key])), - obj - ), + (obj, key) => { + obj[key] = (customKeys && key in customKeys ? customKeys[key] : fn)( + value[key] + ); + return obj; + }, {} as Record ); if (customKeys) { diff --git a/packages/rspack/src/lib/AbstractMethodError.ts b/packages/rspack/src/lib/AbstractMethodError.ts index 6daff6398df..31985276188 100644 --- a/packages/rspack/src/lib/AbstractMethodError.ts +++ b/packages/rspack/src/lib/AbstractMethodError.ts @@ -26,8 +26,7 @@ class Message extends Error { this.stack = undefined; Error.captureStackTrace(this); const match = this.stack!.split("\n")[3].match(CURRENT_METHOD_REGEXP); - this.message = - match && match[1] ? createMessage(match[1]) : createMessage(); + this.message = match?.[1] ? createMessage(match[1]) : createMessage(); } } diff --git a/packages/rspack/src/lib/WebpackError.ts b/packages/rspack/src/lib/WebpackError.ts index 2eb79b36991..17be4f641b5 100644 --- a/packages/rspack/src/lib/WebpackError.ts +++ b/packages/rspack/src/lib/WebpackError.ts @@ -23,15 +23,6 @@ export class WebpackError extends Error { details?: string; hideStack?: boolean; - /** - * Creates an instance of WebpackError. - * @param message error message - * @returns - */ - constructor(message?: string) { - super(message); - } - [inspect.custom]() { return this.stack + (this.details ? `\n${this.details}` : ""); } diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index 54372e8d55f..91bf98f2535 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -327,8 +327,7 @@ function getCurrentLoader( index = loaderContext.loaderIndex ) { if ( - loaderContext.loaders && - loaderContext.loaders.length && + loaderContext.loaders?.length && index < loaderContext.loaders.length && index >= 0 && loaderContext.loaders[index] diff --git a/packages/rspack/src/logging/Logger.ts b/packages/rspack/src/logging/Logger.ts index eb72b37d469..16de167fc53 100644 --- a/packages/rspack/src/logging/Logger.ts +++ b/packages/rspack/src/logging/Logger.ts @@ -122,7 +122,7 @@ export class Logger { } timeLog(label: any) { - const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label); + const prev = this[TIMERS_SYMBOL]?.get(label); if (!prev) { throw new Error(`No such label '${label}' for WebpackLogger.timeLog()`); } @@ -131,7 +131,7 @@ export class Logger { } timeEnd(label: any) { - const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label); + const prev = this[TIMERS_SYMBOL]?.get(label); if (!prev) { throw new Error(`No such label '${label}' for WebpackLogger.timeEnd()`); } @@ -141,7 +141,7 @@ export class Logger { } timeAggregate(label: any) { - const prev = this[TIMERS_SYMBOL] && this[TIMERS_SYMBOL].get(label); + const prev = this[TIMERS_SYMBOL]?.get(label); if (!prev) { throw new Error( `No such label '${label}' for WebpackLogger.timeAggregate()` diff --git a/packages/rspack/src/node/NodeWatchFileSystem.ts b/packages/rspack/src/node/NodeWatchFileSystem.ts index 075032e80af..c78273a3f2e 100644 --- a/packages/rspack/src/node/NodeWatchFileSystem.ts +++ b/packages/rspack/src/node/NodeWatchFileSystem.ts @@ -84,7 +84,7 @@ export default class NodeWatchFileSystem implements WatchFileSystem { // pause emitting events (avoids clearing aggregated changes and removals on timeout) this.watcher.pause(); - if (this.inputFileSystem && this.inputFileSystem.purge) { + if (this.inputFileSystem?.purge) { const fs = this.inputFileSystem; for (const item of changes) { fs.purge(item); @@ -125,7 +125,7 @@ export default class NodeWatchFileSystem implements WatchFileSystem { }, getAggregatedRemovals: util.deprecate( () => { - const items = this.watcher && this.watcher.aggregatedRemovals; + const items = this.watcher?.aggregatedRemovals; if (items && this.inputFileSystem && this.inputFileSystem.purge) { const fs = this.inputFileSystem; for (const item of items) { @@ -139,7 +139,7 @@ export default class NodeWatchFileSystem implements WatchFileSystem { ), getAggregatedChanges: util.deprecate( () => { - const items = this.watcher && this.watcher.aggregatedChanges; + const items = this.watcher?.aggregatedChanges; if (items && this.inputFileSystem && this.inputFileSystem.purge) { const fs = this.inputFileSystem; for (const item of items) { @@ -166,9 +166,9 @@ export default class NodeWatchFileSystem implements WatchFileSystem { "DEP_WEBPACK_WATCHER_CONTEXT_TIME_INFO_ENTRIES" ), getInfo: () => { - const removals = this.watcher && this.watcher.aggregatedRemovals; - const changes = this.watcher && this.watcher.aggregatedChanges; - if (this.inputFileSystem && this.inputFileSystem.purge) { + const removals = this.watcher?.aggregatedRemovals; + const changes = this.watcher?.aggregatedChanges; + if (this.inputFileSystem?.purge) { const fs = this.inputFileSystem; if (removals) { for (const item of removals) { diff --git a/packages/rspack/src/rspackOptionsApply.ts b/packages/rspack/src/rspackOptionsApply.ts index a67ae97c71c..5e2041e186f 100644 --- a/packages/rspack/src/rspackOptionsApply.ts +++ b/packages/rspack/src/rspackOptionsApply.ts @@ -74,7 +74,6 @@ import { DefaultStatsPrinterPlugin } from "./stats/DefaultStatsPrinterPlugin"; import { assertNotNill } from "./util/assertNotNil"; export class RspackOptionsApply { - constructor() {} process(options: RspackOptionsNormalized, compiler: Compiler) { assert( options.output.path, diff --git a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts index 18fa30dd812..4dea1a23eb4 100644 --- a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts +++ b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts @@ -193,7 +193,7 @@ const ASSETS_GROUPERS: Record< const groupByAssetInfoFlag = (name: keyof JsStatsAssetInfo) => { groupConfigs.push({ getKeys: asset => { - return asset.info && asset.info[name] ? ["1"] : undefined; + return asset.info?.[name] ? ["1"] : undefined; }, // @ts-expect-error createGroup: (key, children: KnownStatsAsset[]) => { diff --git a/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts b/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts index 6b08089b19c..ef26e249432 100644 --- a/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts +++ b/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts @@ -369,7 +369,7 @@ const SIMPLE_PRINTERS: Record< "module.cached": (cached, { formatFlag, green }) => cached ? green(formatFlag("cached")) : undefined, "module.assets": (assets, { formatFlag, magenta }) => - assets && assets.length + assets?.length ? magenta( formatFlag( `${assets.length} ${plural(assets.length, "asset", "assets")}` diff --git a/packages/rspack/src/util/SizeFormatHelpers.ts b/packages/rspack/src/util/SizeFormatHelpers.ts index b5fbb7b08a5..ee789533a49 100644 --- a/packages/rspack/src/util/SizeFormatHelpers.ts +++ b/packages/rspack/src/util/SizeFormatHelpers.ts @@ -20,7 +20,5 @@ export const formatSize = (size: unknown) => { const abbreviations = ["bytes", "KiB", "MiB", "GiB"]; const index = Math.floor(Math.log(size) / Math.log(1024)); - return `${+(size / Math.pow(1024, index)).toPrecision(3)} ${ - abbreviations[index] - }`; + return `${+(size / 1024 ** index).toPrecision(3)} ${abbreviations[index]}`; }; diff --git a/packages/rspack/src/util/cleverMerge.ts b/packages/rspack/src/util/cleverMerge.ts index 41c1a6dbe3e..57499a75d38 100644 --- a/packages/rspack/src/util/cleverMerge.ts +++ b/packages/rspack/src/util/cleverMerge.ts @@ -11,6 +11,7 @@ type Obj = Record; type Info = Map; +const DYNAMIC_INFO = Symbol("cleverMerge dynamic info"); type FunctionWithDynamicInfo = ((...args: any[]) => any) & { [DYNAMIC_INFO]?: [FunctionWithDynamicInfo, Obj]; }; @@ -52,7 +53,6 @@ const setPropertyCache = new WeakMap< Map> >(); export const DELETE = Symbol("DELETE"); -const DYNAMIC_INFO = Symbol("cleverMerge dynamic info"); /** * Merges two given objects and caches the result to avoid computation if same objects passed as arguments again. @@ -375,7 +375,7 @@ const mergeEntries = ( // second value override everything // = second.base + second.byProperty return secondEntry; - case VALUE_TYPE_UNDEFINED: + case VALUE_TYPE_UNDEFINED: { if (!firstEntry.byProperty) { // = first.base + second.byProperty return { @@ -404,6 +404,7 @@ const mergeEntries = ( byProperty: firstEntry.byProperty, byValues: newByValues }; + } default: { if (!firstEntry.byProperty) { // The simple case diff --git a/packages/rspack/src/util/fs.ts b/packages/rspack/src/util/fs.ts index d9a10457ca2..21170a82799 100644 --- a/packages/rspack/src/util/fs.ts +++ b/packages/rspack/src/util/fs.ts @@ -154,7 +154,7 @@ export function rmrf( } const join = (fs: OutputFileSystem, rootPath: string, filename: string) => { - if (fs && fs.join) { + if (fs?.join) { return fs.join(rootPath, filename); } if (path.posix.isAbsolute(rootPath)) { @@ -169,7 +169,7 @@ const join = (fs: OutputFileSystem, rootPath: string, filename: string) => { }; const dirname = (fs: OutputFileSystem, absPath: string) => { - if (fs && fs.dirname) { + if (fs?.dirname) { return fs.dirname(absPath); } if (path.posix.isAbsolute(absPath)) { diff --git a/packages/rspack/src/util/identifier.ts b/packages/rspack/src/util/identifier.ts index ce536aa2784..6dff06738d5 100644 --- a/packages/rspack/src/util/identifier.ts +++ b/packages/rspack/src/util/identifier.ts @@ -123,9 +123,9 @@ const makeCacheable = ( return fn; }; -const makeCacheableWithContext = (fn: { - (context: string, identifier: string): string; -}) => { +const makeCacheableWithContext = ( + fn: (context: string, identifier: string) => string +) => { const cache: WeakMap< object, Map> diff --git a/packages/rspack/src/util/smartGrouping.ts b/packages/rspack/src/util/smartGrouping.ts index e9bb88d1c45..046270233e1 100644 --- a/packages/rspack/src/util/smartGrouping.ts +++ b/packages/rspack/src/util/smartGrouping.ts @@ -116,23 +116,22 @@ export const smartGrouping = ( if (options === undefined) { const groupConfig = group.config; state.options = options = - (groupConfig.getOptions && - groupConfig.getOptions( - group.name, - Array.from(items, ({ item }) => item) - )) || - false; + groupConfig.getOptions?.( + group.name, + Array.from(items, ({ item }) => item) + ) || false; } - const force = options && options.force; + const force = options !== false && options.force; if (!force) { - if (bestGroupOptions && bestGroupOptions.force) continue; + if (bestGroupOptions !== false && bestGroupOptions?.force) continue; if (used) continue; if (items.size <= 1 || totalSize - items.size <= 1) { continue; } } - const targetGroupCount = (options && options.targetGroupCount) || 4; + const targetGroupCount = + (options !== false && options.targetGroupCount) || 4; const sizeValue = force ? items.size : Math.min( diff --git a/scripts/meta/check_is_workspace_root.js b/scripts/meta/check_is_workspace_root.js index 268667b4b9f..5fc85ee9847 100644 --- a/scripts/meta/check_is_workspace_root.js +++ b/scripts/meta/check_is_workspace_root.js @@ -21,5 +21,3 @@ try { err.cause = oldErr; throw err; } - -export {}; diff --git a/scripts/test/patch-node-env.cjs b/scripts/test/patch-node-env.cjs index 62e632e44c0..0c062a10a08 100644 --- a/scripts/test/patch-node-env.cjs +++ b/scripts/test/patch-node-env.cjs @@ -7,9 +7,6 @@ const NodeEnvironment = require("jest-environment-node"); class CustomEnvironment extends NodeEnvironment { - constructor(config, context) { - super(config, context); - } // Workaround for `Symbol('JEST_STATE_SYMBOL')` async handleTestEvent(event, state) { diff --git a/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js b/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js index 40fb7b5f132..c3f8c591af9 100644 --- a/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js +++ b/tests/plugin-test/css-extract/cases/hmr-locals/expected/main.js @@ -11,10 +11,8 @@ const noDocument = typeof document === "undefined"; const { forEach } = Array.prototype; function debounce(fn, time) { let timeout = 0; - return function () { - // @ts-ignore + return function (...args) { const self = this; - const args = arguments; const functionCall = function functionCall() { return fn.apply(self, args); }; @@ -43,7 +41,7 @@ function getCurrentScriptUrl(moduleId) { return null; } const splitResult = src.split(/([^\\/]+)\.js$/); - const filename = splitResult && splitResult[1]; + const filename = splitResult?.[1]; if (!filename) { return [src.replace(".js", ".css")]; } diff --git a/tests/plugin-test/css-extract/cases/hmr/expected/main.js b/tests/plugin-test/css-extract/cases/hmr/expected/main.js index 8cbc25cb674..0d510072428 100644 --- a/tests/plugin-test/css-extract/cases/hmr/expected/main.js +++ b/tests/plugin-test/css-extract/cases/hmr/expected/main.js @@ -11,10 +11,8 @@ const noDocument = typeof document === "undefined"; const { forEach } = Array.prototype; function debounce(fn, time) { let timeout = 0; - return function () { - // @ts-ignore + return function (...args) { const self = this; - const args = arguments; const functionCall = function functionCall() { return fn.apply(self, args); }; @@ -43,7 +41,7 @@ function getCurrentScriptUrl(moduleId) { return null; } const splitResult = src.split(/([^\\/]+)\.js$/); - const filename = splitResult && splitResult[1]; + const filename = splitResult?.[1]; if (!filename) { return [src.replace(".js", ".css")]; }