From 75fab872dc8d55dcb10bdece19005d5d750e223d Mon Sep 17 00:00:00 2001 From: "gaoyuan.1226" Date: Tue, 12 Nov 2024 11:47:34 +0800 Subject: [PATCH] fix: ci --- .github/workflows/nodejs.yml | 2 +- src/index.js | 12 ++++++------ src/middleware.js | 14 ++++++++++---- src/utils/getFilenameFromUrl.js | 4 +++- test/middleware.test.js | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 6857e8c..fb94bc8 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -42,7 +42,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - cache: 'pnpm' + cache: "pnpm" - name: Install dependencies run: pnpm install diff --git a/src/index.js b/src/index.js index f3d65e1..b9d85cd 100644 --- a/src/index.js +++ b/src/index.js @@ -218,17 +218,17 @@ function wdm(compiler, options = {}) { if ( Array.isArray(/** @type {MultiCompiler} */ (context.compiler).compilers) ) { - const compiler = /** @type {MultiCompiler} */ (context.compiler); - const watchOptions = compiler.compilers.map( + const multiCompiler = /** @type {MultiCompiler} */ (context.compiler); + const watchOptions = multiCompiler.compilers.map( (childCompiler) => childCompiler.options.watchOptions || {}, ); - context.watching = compiler.watch(watchOptions, errorHandler); + context.watching = multiCompiler.watch(watchOptions, errorHandler); } else { - const compiler = /** @type {Compiler} */ (context.compiler); - const watchOptions = compiler.options.watchOptions || {}; + const singleCompiler = /** @type {Compiler} */ (context.compiler); + const watchOptions = singleCompiler.options.watchOptions || {}; - context.watching = compiler.watch(watchOptions, errorHandler); + context.watching = singleCompiler.watch(watchOptions, errorHandler); } } diff --git a/src/middleware.js b/src/middleware.js index a1217d5..32a1fb5 100644 --- a/src/middleware.js +++ b/src/middleware.js @@ -103,7 +103,7 @@ function parseHttpDate(date) { const timestamp = date && Date.parse(date); // istanbul ignore next: guard against date.js Date.parse patching - return typeof timestamp === "number" ? timestamp : NaN; + return typeof timestamp === "number" ? timestamp : Number.NaN; } const CACHE_CONTROL_NO_CACHE_REGEXP = /(?:^|,)\s*?no-cache\s*?(?:,|$)/; @@ -252,6 +252,7 @@ function wrapper(context) { } // Send basic response + // eslint-disable-next-line no-param-reassign res.statusCode = status; res.setHeader("Content-Type", "text/html; charset=utf-8"); res.setHeader("Content-Security-Policy", "default-src 'none'"); @@ -305,12 +306,12 @@ function wrapper(context) { // A recipient MUST ignore the If-Unmodified-Since header field if the // received field-value is not a valid HTTP-date. - if (!isNaN(unmodifiedSince)) { + if (!Number.isNaN(unmodifiedSince)) { const lastModified = parseHttpDate( /** @type {string} */ (res.getHeader("Last-Modified")), ); - return isNaN(lastModified) || lastModified > unmodifiedSince; + return Number.isNaN(lastModified) || lastModified > unmodifiedSince; } } @@ -546,6 +547,7 @@ function wrapper(context) { // For Koa if (res.statusCode === 404) { + // eslint-disable-next-line no-param-reassign res.statusCode = 200; } @@ -558,6 +560,7 @@ function wrapper(context) { (res.getHeader("Last-Modified")), }) ) { + // eslint-disable-next-line no-param-reassign res.statusCode = 304; // Remove content header fields @@ -597,7 +600,8 @@ function wrapper(context) { }); return; - } else if (parsedRanges === -2) { + } + if (parsedRanges === -2) { context.logger.error( "A malformed 'Range' header was provided. A regular response will be sent for this request.", ); @@ -609,6 +613,7 @@ function wrapper(context) { if (parsedRanges !== -2 && parsedRanges.length === 1) { // Content-Range + // eslint-disable-next-line no-param-reassign res.statusCode = 206; res.setHeader( "Content-Range", @@ -648,6 +653,7 @@ function wrapper(context) { if (req.method === "HEAD") { // For Koa if (res.statusCode === 404) { + // eslint-disable-next-line no-param-reassign res.statusCode = 200; } diff --git a/src/utils/getFilenameFromUrl.js b/src/utils/getFilenameFromUrl.js index 67852ee..ff489fc 100644 --- a/src/utils/getFilenameFromUrl.js +++ b/src/utils/getFilenameFromUrl.js @@ -125,7 +125,8 @@ function getFilenameFromUrl(context, url, extra = {}) { foundFilename = filename; break; - } else if ( + } + if ( extra.stats.isDirectory() && (typeof options.index === "undefined" || options.index) ) { @@ -138,6 +139,7 @@ function getFilenameFromUrl(context, url, extra = {}) { filename = path.join(filename, indexValue); try { + // eslint-disable-next-line no-param-reassign extra.stats = /** @type {import("fs").statSync} */ (context.outputFileSystem.statSync)(filename); diff --git a/test/middleware.test.js b/test/middleware.test.js index a86098a..c2eb3d3 100644 --- a/test/middleware.test.js +++ b/test/middleware.test.js @@ -1664,7 +1664,7 @@ describe.each([ undefined, { setupMiddlewares: (middlewares) => { - middlewares.unshift((req, res, next) => { + middlewares.unshift((_req, res, next) => { // Express API if (res.set) { res.set(