From 1005ec6934dfd3240d78e61b4672240ef8e8e8c3 Mon Sep 17 00:00:00 2001 From: snowingfox <1503401882@qq.com> Date: Fri, 1 Sep 2023 13:12:37 +0800 Subject: [PATCH] chore: remove unused vars & prefer const & remove default generic value --- crates/node_binding/tests/binding.spec.ts | 4 +- .../cases/hooks/asset-emitted/index.test.ts | 4 +- packages/rspack-cli/src/commands/build.ts | 2 +- packages/rspack-cli/src/commands/preview.ts | 2 +- packages/rspack-cli/src/rspack-cli.ts | 6 +- packages/rspack-cli/src/utils/loadConfig.ts | 1 - packages/rspack-cli/src/utils/options.ts | 4 +- .../rspack-cli/src/utils/readPackageUp.ts | 2 +- .../tests/build/config/config.test.ts | 15 ++--- .../tests/serve/basic/serve-basic.test.ts | 2 +- packages/rspack-dev-server/src/middleware.ts | 2 +- packages/rspack-dev-server/src/server.ts | 2 +- packages/rspack/src/Compilation.ts | 26 ++++---- packages/rspack/src/Compiler.ts | 2 +- packages/rspack/src/MultiCompiler.ts | 16 ++--- packages/rspack/src/MultiStats.ts | 1 - packages/rspack/src/builtin-plugin/index.ts | 5 +- packages/rspack/src/config/adapterRuleUse.ts | 2 - packages/rspack/src/config/defaults.ts | 5 +- packages/rspack/src/config/normalization.ts | 1 - .../src/config/zod/optimization/index.ts | 1 - packages/rspack/src/loader-runner/index.ts | 60 +++++++++---------- .../src/stats/DefaultStatsFactoryPlugin.ts | 5 +- .../rspack/src/util/bindingVersionCheck.ts | 4 +- packages/rspack/src/util/createHash.ts | 4 +- packages/rspack/src/util/index.ts | 1 - packages/rspack/src/util/smartGrouping.ts | 2 +- 27 files changed, 77 insertions(+), 104 deletions(-) diff --git a/crates/node_binding/tests/binding.spec.ts b/crates/node_binding/tests/binding.spec.ts index a094f9bb1db..4bb497d295a 100644 --- a/crates/node_binding/tests/binding.spec.ts +++ b/crates/node_binding/tests/binding.spec.ts @@ -1,8 +1,6 @@ -import assert from 'assert' import path from 'path' -import log from 'why-is-node-running' import binding from '..' -import { RawOptions } from '../binding.d' +import { RawOptions } from '../binding' describe('binding', () => { it('work', async () => { diff --git a/packages/playground/cases/hooks/asset-emitted/index.test.ts b/packages/playground/cases/hooks/asset-emitted/index.test.ts index c1a064d80a5..f6e00ba87c8 100644 --- a/packages/playground/cases/hooks/asset-emitted/index.test.ts +++ b/packages/playground/cases/hooks/asset-emitted/index.test.ts @@ -5,7 +5,7 @@ test("asset emitted hook should only emit modified assets", async ({ fileAction, rspack }) => { - let assets: string[] = []; + const assets: string[] = []; rspack.compiler.hooks.assetEmitted.tap("test", function (name) { if (name.includes(".hot-update.")) { return; @@ -55,7 +55,7 @@ test("asset emitted should not emit removed assets", async ({ rspack, fileAction }) => { - let assets: string[] = []; + const assets: string[] = []; rspack.compiler.hooks.assetEmitted.tap("test", function (name) { if (name.includes(".hot-update.")) { return; diff --git a/packages/rspack-cli/src/commands/build.ts b/packages/rspack-cli/src/commands/build.ts index bc9a0496a36..6f6eee15c12 100644 --- a/packages/rspack-cli/src/commands/build.ts +++ b/packages/rspack-cli/src/commands/build.ts @@ -82,7 +82,7 @@ export class BuildCommand implements RspackCommand { } }; - let rspackOptions = { ...options, argv: { ...options } }; + const rspackOptions = { ...options, argv: { ...options } }; const errorHandler = (err, Stats) => { callback(err, Stats); diff --git a/packages/rspack-cli/src/commands/preview.ts b/packages/rspack-cli/src/commands/preview.ts index b377bb85897..1b40a23dba2 100644 --- a/packages/rspack-cli/src/commands/preview.ts +++ b/packages/rspack-cli/src/commands/preview.ts @@ -40,7 +40,7 @@ export class PreviewCommand implements RspackCommand { const devServerOptions = config.devServer as DevServer; - let compiler = rspack({ entry: {} }); + const compiler = rspack({ entry: {} }); if (!compiler) return; try { const server = new RspackDevServer(devServerOptions, compiler); diff --git a/packages/rspack-cli/src/rspack-cli.ts b/packages/rspack-cli/src/rspack-cli.ts index 19672e81a73..4ba10a0fdb4 100644 --- a/packages/rspack-cli/src/rspack-cli.ts +++ b/packages/rspack-cli/src/rspack-cli.ts @@ -14,11 +14,11 @@ import { PreviewCommand } from "./commands/preview"; import { RspackOptions, MultiCompiler, - Compiler, rspack, MultiRspackOptions, Stats, - MultiStats + MultiStats, + Compiler } from "@rspack/core"; import { normalizeEnv } from "./utils/options"; import { loadRspackConfig } from "./utils/loadConfig"; @@ -31,7 +31,7 @@ type Command = "serve" | "build"; const defaultEntry = "src/index"; export class RspackCLI { colors: RspackCLIColors; - program: yargs.Argv<{}>; + program: yargs.Argv; constructor() { this.colors = this.createColors(); this.program = yargs(); diff --git a/packages/rspack-cli/src/utils/loadConfig.ts b/packages/rspack-cli/src/utils/loadConfig.ts index 3eca4201036..b579a8f3371 100644 --- a/packages/rspack-cli/src/utils/loadConfig.ts +++ b/packages/rspack-cli/src/utils/loadConfig.ts @@ -5,7 +5,6 @@ import { RspackOptions, MultiRspackOptions } from "@rspack/core"; import findConfig from "./findConfig"; import rechoir from "rechoir"; import interpret from "interpret"; -import { pathToFileURL } from "url"; import isEsmFile from "./isEsmFile"; import isTsFile from "./isTsFile"; import crossImport from "./crossImport"; diff --git a/packages/rspack-cli/src/utils/options.ts b/packages/rspack-cli/src/utils/options.ts index 149c34a53df..99aed302cef 100644 --- a/packages/rspack-cli/src/utils/options.ts +++ b/packages/rspack-cli/src/utils/options.ts @@ -1,5 +1,5 @@ import yargs from "yargs"; -export const commonOptions = (yargs: yargs.Argv<{}>) => { +export const commonOptions = (yargs: yargs.Argv) => { return yargs.options({ config: { g: true, @@ -40,7 +40,7 @@ export const commonOptions = (yargs: yargs.Argv<{}>) => { }); }; -export const previewOptions = (yargs: yargs.Argv<{}>) => { +export const previewOptions = (yargs: yargs.Argv) => { return yargs .positional("dir", { type: "string", diff --git a/packages/rspack-cli/src/utils/readPackageUp.ts b/packages/rspack-cli/src/utils/readPackageUp.ts index e82d307525b..ebb88e5581d 100644 --- a/packages/rspack-cli/src/utils/readPackageUp.ts +++ b/packages/rspack-cli/src/utils/readPackageUp.ts @@ -6,7 +6,7 @@ const readPackageUp = (cwd = process.cwd()): { type?: "module" } | null => { let packageJsonPath = path.join(currentDir, "package.json"); while (!fs.existsSync(packageJsonPath)) { - let parentDir = path.dirname(currentDir); + const parentDir = path.dirname(currentDir); if (parentDir === currentDir) { return null; } diff --git a/packages/rspack-cli/tests/build/config/config.test.ts b/packages/rspack-cli/tests/build/config/config.test.ts index 2eb5ed509d4..c7a1e74bf8a 100644 --- a/packages/rspack-cli/tests/build/config/config.test.ts +++ b/packages/rspack-cli/tests/build/config/config.test.ts @@ -1,7 +1,6 @@ import { run } from "../../utils/test-utils"; -import { writeFileSync, mkdirSync, unlinkSync } from "fs"; -import { rm, readFile } from "fs/promises"; -import { join, resolve } from "path"; +import { readFile } from "fs/promises"; +import { resolve } from "path"; describe("rspack cli", () => { describe("should config not found", () => { @@ -129,13 +128,9 @@ describe("rspack cli", () => { describe("should load moonrepo config", () => { const cwd = resolve(__dirname, "./moonrepo"); it("should load moonrepo config.ts file", async () => { - const { exitCode, stderr, stdout } = await run( - cwd, - ["-c", "rspack.config.ts"], - { - nodeOptions: ["--experimental-loader=ts-node/esm"] - } - ); + const { exitCode, stdout } = await run(cwd, ["-c", "rspack.config.ts"], { + nodeOptions: ["--experimental-loader=ts-node/esm"] + }); expect(stdout).toBeTruthy(); expect(exitCode).toBe(0); expect( diff --git a/packages/rspack-cli/tests/serve/basic/serve-basic.test.ts b/packages/rspack-cli/tests/serve/basic/serve-basic.test.ts index a265e054d4e..dce7a1d13a2 100644 --- a/packages/rspack-cli/tests/serve/basic/serve-basic.test.ts +++ b/packages/rspack-cli/tests/serve/basic/serve-basic.test.ts @@ -2,7 +2,7 @@ import { normalizeStderr, runWatch } from "../../utils/test-utils"; describe("basic serve usage", () => { it.skip("should work", async () => { - const { stderr, stdout } = await runWatch(__dirname, ["serve"]); + const { stderr } = await runWatch(__dirname, ["serve"]); // @todo current server implementation is too buggy to test expect(normalizeStderr(stderr)).toBeTruthy; diff --git a/packages/rspack-dev-server/src/middleware.ts b/packages/rspack-dev-server/src/middleware.ts index f695a4189d4..0052070cfc5 100644 --- a/packages/rspack-dev-server/src/middleware.ts +++ b/packages/rspack-dev-server/src/middleware.ts @@ -32,7 +32,7 @@ export function getRspackMemoryAssets( const filename = path.startsWith(publicPath) ? path.slice(publicPath.length) : path.slice(1); - let buffer = + const buffer = compiler.getAsset(filename) ?? (() => { const { index } = rdm.context.options; diff --git a/packages/rspack-dev-server/src/server.ts b/packages/rspack-dev-server/src/server.ts index aa6472ba57e..d7ac0f40278 100644 --- a/packages/rspack-dev-server/src/server.ts +++ b/packages/rspack-dev-server/src/server.ts @@ -445,7 +445,7 @@ export class RspackDevServer extends WebpackDevServer { compilers.forEach(compiler => { if (compiler.options.experiments.lazyCompilation) { middlewares.push({ - middleware: (req, res, next) => { + middleware: (req, res) => { if (req.url.indexOf("/lazy-compilation-web/") > -1) { const path = req.url.replace("/lazy-compilation-web/", ""); if (fs.existsSync(path)) { diff --git a/packages/rspack/src/Compilation.ts b/packages/rspack/src/Compilation.ts index 05ded25b76d..12b7fd787e5 100644 --- a/packages/rspack/src/Compilation.ts +++ b/packages/rspack/src/Compilation.ts @@ -121,7 +121,7 @@ export class Compilation { this.name = undefined; this.startTime = undefined; this.endTime = undefined; - let processAssetsHooks = createFakeProcessAssetsHook(this); + const processAssetsHooks = createFakeProcessAssetsHook(this); this.hooks = { processAssets: processAssetsHooks, // TODO: webpack 6 deprecate, keep it just for compatibility @@ -178,7 +178,7 @@ export class Compilation { return this.__internal__getAssetSource(property); } }, - set: (target, p, newValue, receiver) => { + set: (target, p, newValue) => { if (typeof p === "string") { this.__internal__setAssetSource(p, newValue); return true; @@ -437,12 +437,12 @@ export class Compilation { } get errors() { - let inner = this.#inner; + const inner = this.#inner; return { push: (...errs: (Error | JsStatsError)[]) => { // compatible for javascript array for (let i = 0; i < errs.length; i++) { - let error = errs[i]; + const error = errs[i]; this.#inner.pushDiagnostic( "error", isJsStatsError(error) ? error.title : error.name, @@ -452,7 +452,7 @@ export class Compilation { }, [Symbol.iterator]() { // TODO: this is obviously a bad design, optimize this after finishing angular prototype - let errors = inner.getStats().getErrors(); + const errors = inner.getStats().getErrors(); let index = 0; return { next() { @@ -470,14 +470,14 @@ export class Compilation { } get warnings() { - let inner = this.#inner; + const inner = this.#inner; return { // compatible for javascript array push: (...warns: (Error | JsStatsError)[]) => { // TODO: find a way to make JsStatsError be actual errors warns = this.hooks.processWarnings.call(warns as any); for (let i = 0; i < warns.length; i++) { - let warn = warns[i]; + const warn = warns[i]; this.#inner.pushDiagnostic( "warning", isJsStatsError(warn) ? warn.title : warn.name, @@ -487,7 +487,7 @@ export class Compilation { }, [Symbol.iterator]() { // TODO: this is obviously a bad design, optimize this after finishing angular prototype - let warnings = inner.getStats().getWarnings(); + const warnings = inner.getStats().getWarnings(); let index = 0; return { next() { @@ -656,7 +656,7 @@ export class Compilation { // FIXME: This is not aligned with Webpack. get chunks() { - var stats = this.getStats().toJson({ + const stats = this.getStats().toJson({ all: false, chunks: true, chunkModules: true, @@ -683,13 +683,13 @@ export class Compilation { * @internal */ __internal__getAssociatedModules(chunk: JsStatsChunk): any[] | undefined { - let modules = this.__internal__getModules(); - let moduleMap: Map = new Map(); - for (let module of modules) { + const modules = this.__internal__getModules(); + const moduleMap: Map = new Map(); + for (const module of modules) { moduleMap.set(module.moduleIdentifier, module); } return chunk.modules?.flatMap(chunkModule => { - let jsModule = this.__internal__findJsModule( + const jsModule = this.__internal__findJsModule( chunkModule.issuer ?? chunkModule.identifier, moduleMap ); diff --git a/packages/rspack/src/Compiler.ts b/packages/rspack/src/Compiler.ts index a78ee38d827..490290e6b2b 100644 --- a/packages/rspack/src/Compiler.ts +++ b/packages/rspack/src/Compiler.ts @@ -24,7 +24,7 @@ import { Stats } from "./Stats"; import { Compilation, CompilationParams } from "./Compilation"; import { ContextModuleFactory } from "./ContextModuleFactory"; import ResolverFactory from "./ResolverFactory"; -import { getRawOptions } from "./config/adapter"; +import { getRawOptions } from "./config"; import { LoaderContext, LoaderResult } from "./config/adapterRuleUse"; import ConcurrentCompilationError from "./error/ConcurrentCompilationError"; import { createThreadsafeNodeFSFromRaw } from "./fileSystem"; diff --git a/packages/rspack/src/MultiCompiler.ts b/packages/rspack/src/MultiCompiler.ts index c4368fac2cb..fe4a3c9878f 100644 --- a/packages/rspack/src/MultiCompiler.ts +++ b/packages/rspack/src/MultiCompiler.ts @@ -8,21 +8,16 @@ * https://github.com/webpack/webpack/blob/main/LICENSE */ -import { - Compilation, - Compiler, - RspackOptions, - RspackOptionsNormalized, - Stats -} from "."; +import { Compiler, RspackOptions, Stats } from "."; import ResolverFactory from "./ResolverFactory"; import { WatchFileSystem } from "./util/fs"; import Watching from "./Watching"; -import tapable, { +import { AsyncSeriesHook, Callback, MultiHook, - SyncHook + SyncHook, + SyncBailHook } from "tapable"; import MultiStats from "./MultiStats"; import asyncLib from "neo-async"; @@ -30,9 +25,6 @@ import ArrayQueue from "./util/ArrayQueue"; import ConcurrentCompilationError from "./error/ConcurrentCompilationError"; import MultiWatching from "./MultiWatching"; import { WatchOptions } from "./config"; -import { IFs } from "memfs"; -import assert from "assert"; -import { isNil } from "./util"; type Any = any; diff --git a/packages/rspack/src/MultiStats.ts b/packages/rspack/src/MultiStats.ts index 434341e925f..2386b8533af 100644 --- a/packages/rspack/src/MultiStats.ts +++ b/packages/rspack/src/MultiStats.ts @@ -9,7 +9,6 @@ */ import { KnownCreateStatsOptionsContext } from "."; -import { SnapshotOptions } from "./config"; import { StatsCompilation } from "./stats/statsFactoryUtils"; import { Stats } from "./Stats"; import { indent } from "./util"; diff --git a/packages/rspack/src/builtin-plugin/index.ts b/packages/rspack/src/builtin-plugin/index.ts index 5ae292563bf..bcaf8ae11fa 100644 --- a/packages/rspack/src/builtin-plugin/index.ts +++ b/packages/rspack/src/builtin-plugin/index.ts @@ -21,7 +21,7 @@ import { RawBuiltins, RawCssModulesConfig } from "@rspack/binding"; -import { termlink, deprecatedWarn } from "../util"; +import { deprecatedWarn } from "../util"; import { Compiler, RspackOptionsNormalized } from ".."; import { HtmlPluginOptions, @@ -35,8 +35,7 @@ import { CopyPlugin, BannerPlugin, SwcJsMinimizerPlugin, - SwcCssMinimizerPlugin, - RspackBuiltinPlugin + SwcCssMinimizerPlugin } from "."; import { loadConfig } from "browserslist"; import path from "path"; diff --git a/packages/rspack/src/config/adapterRuleUse.ts b/packages/rspack/src/config/adapterRuleUse.ts index a7297eee0c7..7ca4a9f5883 100644 --- a/packages/rspack/src/config/adapterRuleUse.ts +++ b/packages/rspack/src/config/adapterRuleUse.ts @@ -4,7 +4,6 @@ import type { RawModuleRuleUse, RawOptions } from "@rspack/binding"; -import assert from "assert"; import { ResolveRequest } from "enhanced-resolve"; import { Compiler } from "../Compiler"; @@ -13,7 +12,6 @@ import Hash from "../util/hash"; import { Mode, Resolve, - RuleSetUse, RuleSetUseItem, RuleSetLoaderWithOptions } from "./types"; diff --git a/packages/rspack/src/config/defaults.ts b/packages/rspack/src/config/defaults.ts index 5d4dae12115..b37b0939508 100644 --- a/packages/rspack/src/config/defaults.ts +++ b/packages/rspack/src/config/defaults.ts @@ -13,7 +13,6 @@ import fs from "fs"; import path from "path"; import { isNil } from "../util"; import { cleverMerge } from "../util/cleverMerge"; -import { deprecated_resolveBuiltins } from "../builtin-plugin"; import { getDefaultTarget, getTargetProperties, @@ -22,8 +21,6 @@ import { import type { AvailableTarget, Context, - Entry, - EntryDescription, EntryDescriptionNormalized, EntryNormalized, ExperimentsNormalized, @@ -653,7 +650,7 @@ const applyNodeDefaults = ( const applyOptimizationDefaults = ( optimization: Optimization, - { production, development }: { production: boolean; development: boolean } + { production }: { production: boolean; development: boolean } ) => { D(optimization, "removeAvailableModules", true); D(optimization, "removeEmptyChunks", true); diff --git a/packages/rspack/src/config/normalization.ts b/packages/rspack/src/config/normalization.ts index 49f7dc6d93d..670bbbd7fa4 100644 --- a/packages/rspack/src/config/normalization.ts +++ b/packages/rspack/src/config/normalization.ts @@ -13,7 +13,6 @@ import type { EntryStatic, EntryStaticNormalized, LibraryOptions, - OptimizationRuntimeChunk, OptimizationRuntimeChunkNormalized, RspackOptions, RspackOptionsNormalized diff --git a/packages/rspack/src/config/zod/optimization/index.ts b/packages/rspack/src/config/zod/optimization/index.ts index 21bf01e733a..80a0e463026 100644 --- a/packages/rspack/src/config/zod/optimization/index.ts +++ b/packages/rspack/src/config/zod/optimization/index.ts @@ -1,5 +1,4 @@ import { z } from "zod"; -import { Compiler } from "../../../Compiler"; import { splitChunks } from "./split-chunks"; const rspackPluginInstance = z.any(); diff --git a/packages/rspack/src/loader-runner/index.ts b/packages/rspack/src/loader-runner/index.ts index 5b89d04d72f..4ac7b76f18b 100644 --- a/packages/rspack/src/loader-runner/index.ts +++ b/packages/rspack/src/loader-runner/index.ts @@ -45,7 +45,7 @@ export function parsePathQueryFragment(str: string): { query: string; fragment: string; } { - let match = PATH_QUERY_FRAGMENT_REGEXP.exec(str); + const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str); return { path: match?.[1].replace(/\0(.)/g, "$1") || "", query: match?.[2] ? match[2].replace(/\0(.)/g, "$1") : "", @@ -55,12 +55,12 @@ export function parsePathQueryFragment(str: string): { function dirname(path: string) { if (path === "/") return "/"; - var i = path.lastIndexOf("/"); - var j = path.lastIndexOf("\\"); - var i2 = path.indexOf("/"); - var j2 = path.indexOf("\\"); - var idx = i > j ? i : j; - var idx2 = i > j ? i2 : j2; + const i = path.lastIndexOf("/"); + const j = path.lastIndexOf("\\"); + const i2 = path.indexOf("/"); + const j2 = path.indexOf("\\"); + const idx = i > j ? i : j; + const idx2 = i > j ? i2 : j2; if (idx < 0) return path; if (idx === idx2) return path.slice(0, idx + 1); return path.slice(0, idx); @@ -95,7 +95,7 @@ function createLoaderObject(loader: any, compiler: Compiler): LoaderObject { }, set: function (value) { if (typeof value === "string") { - let splittedRequest = parsePathQueryFragment(value); + const splittedRequest = parsePathQueryFragment(value); obj.path = splittedRequest.path; obj.query = splittedRequest.query; obj.fragment = splittedRequest.fragment; @@ -179,11 +179,11 @@ export async function runLoader( // execution state let cacheable = true; - let fileDependencies: string[] = rawContext.fileDependencies.slice(); - let contextDependencies: string[] = rawContext.contextDependencies.slice(); - let missingDependencies: string[] = rawContext.missingDependencies.slice(); - let buildDependencies: string[] = rawContext.buildDependencies.slice(); - let assetFilenames = rawContext.assetFilenames.slice(); + const fileDependencies: string[] = rawContext.fileDependencies.slice(); + const contextDependencies: string[] = rawContext.contextDependencies.slice(); + const missingDependencies: string[] = rawContext.missingDependencies.slice(); + const buildDependencies: string[] = rawContext.buildDependencies.slice(); + const assetFilenames = rawContext.assetFilenames.slice(); const loaders = rawContext.currentLoader .split("$") @@ -237,7 +237,7 @@ export async function runLoader( ); }, set: function (value) { - var splittedResource = value && parsePathQueryFragment(value); + const splittedResource = value && parsePathQueryFragment(value); loaderContext.resourcePath = splittedResource ? splittedResource.path : undefined; @@ -303,7 +303,7 @@ export async function runLoader( Object.defineProperty(loaderContext, "query", { enumerable: true, get: function () { - var entry = loaderContext.loaders[loaderContext.loaderIndex]; + const entry = loaderContext.loaders[loaderContext.loaderIndex]; return entry.options && typeof entry.options === "object" ? entry.options : entry.query; @@ -504,7 +504,7 @@ export async function runLoader( loaderContext._compiler = compiler; loaderContext._compilation = compiler.compilation; loaderContext.getOptions = function (schema) { - let loader = getCurrentLoader(loaderContext); + const loader = getCurrentLoader(loaderContext); let options = loader?.options; if (options === null || options === undefined) { @@ -598,7 +598,7 @@ export async function runLoader( } function utf8BufferToString(buf: Buffer) { - var str = buf.toString("utf-8"); + const str = buf.toString("utf-8"); if (str.charCodeAt(0) === 0xfeff) { return str.slice(1); } else { @@ -618,10 +618,10 @@ function runSyncOrAsync( args: any[], callback: Function ) { - var isSync = true; - var isDone = false; - var isError = false; // internal error - var reportedError = false; + let isSync = true; + let isDone = false; + let isError = false; // internal error + let reportedError = false; // @ts-expect-error loader-runner leverages `arguments` to achieve the same functionality. context.async = function async() { if (isDone) { @@ -631,7 +631,7 @@ function runSyncOrAsync( isSync = false; return innerCallback; }; - var innerCallback = (context.callback = function () { + const innerCallback = (context.callback = function () { if (isDone) { if (reportedError) return; // ignore throw new Error("callback(): The callback was already called."); @@ -646,7 +646,7 @@ function runSyncOrAsync( } }); try { - var result = (function LOADER_EXECUTION() { + const result = (function LOADER_EXECUTION() { return fn.apply(context, args); })(); if (isSync) { @@ -690,7 +690,7 @@ function iteratePitchingLoaders( if (loaderContext.loaderIndex >= loaderContext.loaders.length) return callback(null, args); - var currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex]; + const currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex]; // iterate if (currentLoaderObject.pitchExecuted) { @@ -704,7 +704,7 @@ function iteratePitchingLoaders( loaderContext.cacheable(false); return callback(err); } - var fn = currentLoaderObject.pitch; + const fn = currentLoaderObject.pitch; currentLoaderObject.pitchExecuted = true; if (!fn) return iteratePitchingLoaders(loaderContext, args, callback); @@ -719,11 +719,11 @@ function iteratePitchingLoaders( ], function (err: Error) { if (err) return callback(err); - var args = Array.prototype.slice.call(arguments, 1); + const args = Array.prototype.slice.call(arguments, 1); // Determine whether to continue the pitching process based on // argument values (as opposed to argument presence) in order // to support synchronous and asynchronous usages. - var hasArg = args.some(function (value) { + const hasArg = args.some(function (value) { return value !== undefined; }); // If a loader pitched successfully, @@ -749,7 +749,7 @@ function iterateNormalLoaders( // JS loaders ends if (loaderContext.loaderIndex < 0) return callback(null, args); - var currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex]; + const currentLoaderObject = loaderContext.loaders[loaderContext.loaderIndex]; // iterate if (currentLoaderObject.normalExecuted) { @@ -763,7 +763,7 @@ function iterateNormalLoaders( return callback(err); } - var fn = currentLoaderObject.normal; + const fn = currentLoaderObject.normal; currentLoaderObject.normalExecuted = true; if (!fn) { return iterateNormalLoaders(loaderContext, args, callback); @@ -774,7 +774,7 @@ function iterateNormalLoaders( runSyncOrAsync(fn, loaderContext, args, function (err: Error) { if (err) return callback(err); - var args = Array.prototype.slice.call(arguments, 1); + const args = Array.prototype.slice.call(arguments, 1); iterateNormalLoaders(loaderContext, args, callback); }); }); diff --git a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts index 450ef201190..9b2062c62a4 100644 --- a/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts +++ b/packages/rspack/src/stats/DefaultStatsFactoryPlugin.ts @@ -216,11 +216,8 @@ const MODULES_GROUPERS = ( }; const { groupModulesByCacheStatus, - groupModulesByLayer, groupModulesByAttributes, - groupModulesByType, - groupModulesByPath, - groupModulesByExtension + groupModulesByType } = options; if (groupModulesByAttributes) { groupByFlag("errors", "modules with errors"); diff --git a/packages/rspack/src/util/bindingVersionCheck.ts b/packages/rspack/src/util/bindingVersionCheck.ts index c07c939c41d..d59f43752a2 100644 --- a/packages/rspack/src/util/bindingVersionCheck.ts +++ b/packages/rspack/src/util/bindingVersionCheck.ts @@ -61,7 +61,7 @@ const getAddonPlatformArchAbi = function () { let binding = ""; binding += platform; - let abi = NodePlatformArchToAbi[platform][arch]; + const abi = NodePlatformArchToAbi[platform][arch]; if (abi === undefined) return new Error(`unsupported cpu arch: ${arch}`); binding += "-" + arch; @@ -92,7 +92,7 @@ export const checkVersion = () => { return result; } - let platformArchAbi = getAddonPlatformArchAbi(); + const platformArchAbi = getAddonPlatformArchAbi(); if (platformArchAbi instanceof Error) { return (result = platformArchAbi); } diff --git a/packages/rspack/src/util/createHash.ts b/packages/rspack/src/util/createHash.ts index 3a7e9224966..2480cbfe67c 100644 --- a/packages/rspack/src/util/createHash.ts +++ b/packages/rspack/src/util/createHash.ts @@ -124,7 +124,9 @@ class DebugHash extends Hash { * @returns {string|Buffer} digest */ digest(encoding) { - return "debug-digest-" + Buffer.from(this.string).toString("hex"); + return ( + "debug-digest-" + Buffer.from(this.string).toString(encoding || "hex") + ); } } diff --git a/packages/rspack/src/util/index.ts b/packages/rspack/src/util/index.ts index 520c0b046d2..346ec580e18 100644 --- a/packages/rspack/src/util/index.ts +++ b/packages/rspack/src/util/index.ts @@ -1,7 +1,6 @@ import type { JsAssetInfo, JsStatsError } from "@rspack/binding"; import { AssetInfo } from "../Compilation"; import terminalLink from "terminal-link"; -import * as util from "util"; export function mapValues( record: Record, diff --git a/packages/rspack/src/util/smartGrouping.ts b/packages/rspack/src/util/smartGrouping.ts index ac3972f07d8..7bf7a757fd4 100644 --- a/packages/rspack/src/util/smartGrouping.ts +++ b/packages/rspack/src/util/smartGrouping.ts @@ -133,7 +133,7 @@ export const smartGrouping = ( } } const targetGroupCount = (options && options.targetGroupCount) || 4; - let sizeValue = force + const sizeValue = force ? items.size : Math.min( items.size,