From 7c3925ab5560295b8fad1ebffe5e7d019045c18c Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 00:54:22 +0300 Subject: [PATCH 01/14] refactor: code --- src/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 20aa298..513829a 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,7 @@ const getTinyGlobby = memoize(() => require("tinyglobby")); /** @typedef {import("webpack").Compilation} Compilation */ /** @typedef {import("webpack").WebpackError} WebpackError */ /** @typedef {import("webpack").Asset} Asset */ +/** @typedef {import("webpack").AssetInfo} AssetInfo */ /** @typedef {import("tinyglobby").GlobOptions} GlobbyOptions */ /** @typedef {ReturnType} WebpackLogger */ /** @typedef {ReturnType} CacheFacade */ @@ -273,7 +274,7 @@ class CopyPlugin { `starting to process a pattern from '${normalizedOriginalFrom}' using '${pattern.context}' context`, ); - let absoluteFrom = path.isAbsolute(normalizedOriginalFrom) + const absoluteFrom = path.isAbsolute(normalizedOriginalFrom) ? normalizedOriginalFrom : path.resolve(pattern.context, normalizedOriginalFrom); @@ -340,7 +341,6 @@ class CopyPlugin { ), "**/*", ); - absoluteFrom = path.join(absoluteFrom, "**/*"); if (typeof globOptions.dot === "undefined") { globOptions.dot = true; @@ -443,8 +443,7 @@ class CopyPlugin { logger.debug(`found '${from}'`); - // `globby`/`fast-glob` return the relative path when the path contains special characters on windows - const absoluteFilename = path.resolve(pattern.context, from); + const absoluteFilename = from; const to = typeof pattern.to === "function" ? await pattern.to({ @@ -469,7 +468,8 @@ class CopyPlugin { if (path.isAbsolute(filename)) { filename = path.relative( - /** @type {string} */ (compiler.options.output.path), + /** @type {string} */ + (compiler.options.output.path), filename, ); } @@ -674,6 +674,7 @@ class CopyPlugin { } } + /** @type {AssetInfo} */ let info = typeof pattern.info === "undefined" ? {} From d3b1bea319de8901766db27d7be58fe91fbd3ad5 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:00:20 +0300 Subject: [PATCH 02/14] refactor: code --- src/index.js | 2 +- types/index.d.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 513829a..a02076b 100644 --- a/src/index.js +++ b/src/index.js @@ -443,7 +443,7 @@ class CopyPlugin { logger.debug(`found '${from}'`); - const absoluteFilename = from; + const absoluteFilename = path.normalize(from); const to = typeof pattern.to === "function" ? await pattern.to({ diff --git a/types/index.d.ts b/types/index.d.ts index a4d56c2..874d0af 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -62,6 +62,7 @@ declare namespace CopyPlugin { Compilation, WebpackError, Asset, + AssetInfo, GlobbyOptions, WebpackLogger, CacheFacade, @@ -94,6 +95,7 @@ type Compiler = import("webpack").Compiler; type Compilation = import("webpack").Compilation; type WebpackError = import("webpack").WebpackError; type Asset = import("webpack").Asset; +type AssetInfo = import("webpack").AssetInfo; type GlobbyOptions = import("tinyglobby").GlobOptions; type WebpackLogger = ReturnType; type CacheFacade = ReturnType; From 68c35c048c36fc39dd711a36e5c801b599f03e09 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:17:01 +0300 Subject: [PATCH 03/14] test: debug --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index a02076b..c12e7f1 100644 --- a/src/index.js +++ b/src/index.js @@ -362,9 +362,10 @@ class CopyPlugin { break; case "glob": default: { - const contextDependencies = path.normalize( - getGlobParent()(absoluteFrom), - ); + const contextDependencies = getGlobParent()(absoluteFrom); + + // eslint-disable-next-line no-console + console.log(contextDependencies); compilation.contextDependencies.add(contextDependencies); From bf5d1c969d57f8a564f8dfd36d22e9458ff4c034 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:20:37 +0300 Subject: [PATCH 04/14] test: debug --- src/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index c12e7f1..eb1078f 100644 --- a/src/index.js +++ b/src/index.js @@ -362,10 +362,9 @@ class CopyPlugin { break; case "glob": default: { - const contextDependencies = getGlobParent()(absoluteFrom); - - // eslint-disable-next-line no-console - console.log(contextDependencies); + const contextDependencies = getGlobParent()(absoluteFrom, { + flipBackslashes: false, + }); compilation.contextDependencies.add(contextDependencies); From 65b86348571206f393d9efa28dea1a1e8d46d9f3 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:25:51 +0300 Subject: [PATCH 05/14] test: debug --- src/index.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index eb1078f..a53c30f 100644 --- a/src/index.js +++ b/src/index.js @@ -336,9 +336,7 @@ class CopyPlugin { pattern.context = absoluteFrom; glob = path.posix.join( - getTinyGlobby().escapePath( - getNormalizePath()(path.resolve(absoluteFrom)), - ), + getTinyGlobby().escapePath(absoluteFrom), "**/*", ); @@ -352,9 +350,7 @@ class CopyPlugin { logger.debug(`added '${absoluteFrom}' as a file dependency`); pattern.context = path.dirname(absoluteFrom); - glob = getTinyGlobby().escapePath( - getNormalizePath()(path.resolve(absoluteFrom)), - ); + glob = getTinyGlobby().escapePath(absoluteFrom); if (typeof globOptions.dot === "undefined") { globOptions.dot = true; @@ -362,9 +358,9 @@ class CopyPlugin { break; case "glob": default: { - const contextDependencies = getGlobParent()(absoluteFrom, { - flipBackslashes: false, - }); + const contextDependencies = path.normalize( + getGlobParent()(absoluteFrom), + ); compilation.contextDependencies.add(contextDependencies); From 2f9d62b86cf9ffe2a690646f5e1c5f6e6d7ce06e Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:31:23 +0300 Subject: [PATCH 06/14] test: debug --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index a53c30f..d32166c 100644 --- a/src/index.js +++ b/src/index.js @@ -336,7 +336,7 @@ class CopyPlugin { pattern.context = absoluteFrom; glob = path.posix.join( - getTinyGlobby().escapePath(absoluteFrom), + getTinyGlobby().escapePath(getNormalizePath()(absoluteFrom)), "**/*", ); @@ -350,7 +350,7 @@ class CopyPlugin { logger.debug(`added '${absoluteFrom}' as a file dependency`); pattern.context = path.dirname(absoluteFrom); - glob = getTinyGlobby().escapePath(absoluteFrom); + glob = getTinyGlobby().escapePath(getNormalizePath()(absoluteFrom)); if (typeof globOptions.dot === "undefined") { globOptions.dot = true; From 1295472affb4d6c91a83ec34626a3aa3134d2643 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:39:00 +0300 Subject: [PATCH 07/14] refactor: code --- src/index.js | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/index.js b/src/index.js index d32166c..16beff0 100644 --- a/src/index.js +++ b/src/index.js @@ -806,16 +806,16 @@ class CopyPlugin { /** * @type {ObjectPattern} */ - const normalizedPattern = + const pattern = typeof item === "string" ? { from: item } : { ...item }; const context = - typeof normalizedPattern.context === "undefined" + typeof pattern.context === "undefined" ? compiler.context - : path.isAbsolute(normalizedPattern.context) - ? normalizedPattern.context - : path.join(compiler.context, normalizedPattern.context); + : path.isAbsolute(pattern.context) + ? pattern.context + : path.join(compiler.context, pattern.context); - normalizedPattern.context = context; + pattern.context = context; /** * @type {Array | undefined} @@ -831,7 +831,7 @@ class CopyPlugin { cache, concurrency, /** @type {ObjectPattern & { context: string }} */ - (normalizedPattern), + (pattern), index, ); } catch (error) { @@ -855,13 +855,13 @@ class CopyPlugin { (result) => result !== undefined, ); - if (typeof normalizedPattern.transformAll !== "undefined") { - if (typeof normalizedPattern.to === "undefined") { + if (typeof pattern.transformAll !== "undefined") { + if (typeof pattern.to === "undefined") { compilation.errors.push( /** @type {WebpackError} */ ( new Error( - `Invalid "pattern.to" for the "pattern.from": "${normalizedPattern.from}" and "pattern.transformAll" function. The "to" option must be specified.`, + `Invalid "pattern.to" for the "pattern.from": "${pattern.from}" and "pattern.transformAll" function. The "to" option must be specified.`, ) ), ); @@ -906,26 +906,25 @@ class CopyPlugin { const cacheItem = cache.getItemCache( `transformAll|${getSerializeJavascript()({ version, - from: normalizedPattern.from, - to: normalizedPattern.to, - transformAll: normalizedPattern.transformAll, + from: pattern.from, + to: pattern.to, + transformAll: pattern.transformAll, })}`, mergedEtag, ); let transformedAsset = await cacheItem.getPromise(); if (!transformedAsset) { - transformedAsset = { filename: normalizedPattern.to }; + transformedAsset = { filename: pattern.to }; try { - transformedAsset.data = - await normalizedPattern.transformAll( - filteredCopiedResult.map((asset) => ({ - data: asset.source.buffer(), - sourceFilename: asset.sourceFilename, - absoluteFilename: asset.absoluteFilename, - })), - ); + transformedAsset.data = await pattern.transformAll( + filteredCopiedResult.map((asset) => ({ + data: asset.source.buffer(), + sourceFilename: asset.sourceFilename, + absoluteFilename: asset.absoluteFilename, + })), + ); } catch (error) { compilation.errors.push( /** @type {WebpackError} */ (error), @@ -935,9 +934,9 @@ class CopyPlugin { } const filename = - typeof normalizedPattern.to === "function" - ? await normalizedPattern.to({ context }) - : normalizedPattern.to; + typeof pattern.to === "function" + ? await pattern.to({ context }) + : pattern.to; if (template.test(filename)) { const contentHash = CopyPlugin.getContentHash( @@ -967,7 +966,7 @@ class CopyPlugin { transformedAsset.source = new RawSource( transformedAsset.data, ); - transformedAsset.force = normalizedPattern.force; + transformedAsset.force = pattern.force; await cacheItem.storePromise(transformedAsset); } @@ -975,7 +974,7 @@ class CopyPlugin { filteredCopiedResult = [transformedAsset]; } - const priority = normalizedPattern.priority || 0; + const priority = pattern.priority || 0; if (!copiedResultMap.has(priority)) { copiedResultMap.set(priority, new Map()); From d4f47188476cb4976e3b73cf658221cfeb3ba80d Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:51:25 +0300 Subject: [PATCH 08/14] test: debug --- src/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 16beff0..fd4cf10 100644 --- a/src/index.js +++ b/src/index.js @@ -229,7 +229,8 @@ class CopyPlugin { const { hashDigest, hashDigestLength, hashFunction, hashSalt } = outputOptions; const hash = compiler.webpack.util.createHash( - /** @type {string} */ (hashFunction), + /** @type {string} */ + (hashFunction), ); if (hashSalt) { @@ -446,9 +447,9 @@ class CopyPlugin { context: pattern.context, absoluteFilename, }) - : path.normalize( - typeof pattern.to !== "undefined" ? pattern.to : "", - ); + : typeof pattern.to !== "undefined" + ? path.normalize(pattern.to) + : ""; const toType = pattern.toType || (template.test(to) @@ -476,6 +477,11 @@ class CopyPlugin { path.relative(compiler.context, absoluteFilename), ); + // eslint-disable-next-line no-console + console.log(sourceFilename); + // eslint-disable-next-line no-console + console.log(path.relative(compiler.context, absoluteFilename)); + // If this came from a glob or dir, add it to the file dependencies if (fromType === "dir" || fromType === "glob") { compilation.fileDependencies.add(absoluteFilename); From 27b56d449a649c89976798c9ee8f302ba71ff77a Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 01:55:27 +0300 Subject: [PATCH 09/14] test: debug --- src/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index fd4cf10..78dccca 100644 --- a/src/index.js +++ b/src/index.js @@ -447,9 +447,9 @@ class CopyPlugin { context: pattern.context, absoluteFilename, }) - : typeof pattern.to !== "undefined" - ? path.normalize(pattern.to) - : ""; + : path.normalize( + typeof pattern.to !== "undefined" ? pattern.to : "", + ); const toType = pattern.toType || (template.test(to) From 0cb6dedf6ec1379c7a513e4f9e70cbc41d522744 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 02:05:51 +0300 Subject: [PATCH 10/14] test: debug --- src/index.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/index.js b/src/index.js index 78dccca..5f7fa68 100644 --- a/src/index.js +++ b/src/index.js @@ -370,9 +370,7 @@ class CopyPlugin { glob = path.isAbsolute(originalFrom) ? originalFrom : path.posix.join( - getTinyGlobby().escapePath( - getNormalizePath()(path.resolve(pattern.context)), - ), + getTinyGlobby().escapePath(getNormalizePath()(pattern.context)), originalFrom, ); } @@ -477,11 +475,6 @@ class CopyPlugin { path.relative(compiler.context, absoluteFilename), ); - // eslint-disable-next-line no-console - console.log(sourceFilename); - // eslint-disable-next-line no-console - console.log(path.relative(compiler.context, absoluteFilename)); - // If this came from a glob or dir, add it to the file dependencies if (fromType === "dir" || fromType === "glob") { compilation.fileDependencies.add(absoluteFilename); @@ -703,9 +696,7 @@ class CopyPlugin { const base = path.basename(sourceFilename); const name = base.slice(0, base.length - ext.length); const data = { - filename: getNormalizePath()( - path.relative(pattern.context, absoluteFilename), - ), + filename: getNormalizePath()(relativeFrom), contentHash, chunk: { name, From e6772c30c92ae967209f899569d7216951af57ea Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 02:18:08 +0300 Subject: [PATCH 11/14] test: debug --- src/index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/index.js b/src/index.js index 5f7fa68..73cfea7 100644 --- a/src/index.js +++ b/src/index.js @@ -252,7 +252,7 @@ class CopyPlugin { * @param {WebpackLogger} logger the logger to use for logging * @param {CacheFacade} cache the cache facade to use for caching * @param {number} concurrency /maximum number of concurrent operations - * @param {ObjectPattern & { context: string }} inputPattern the pattern to process + * @param {ObjectPattern & { context: string }} pattern the pattern to process * @param {number} index the index of the pattern in the patterns array * @returns {Promise | undefined>} processes the pattern and returns an array of copied results */ @@ -263,21 +263,18 @@ class CopyPlugin { logger, cache, concurrency, - inputPattern, + pattern, index, ) { const { RawSource } = compiler.webpack.sources; - const pattern = { ...inputPattern }; - const originalFrom = pattern.from; - const normalizedOriginalFrom = path.normalize(originalFrom); logger.log( - `starting to process a pattern from '${normalizedOriginalFrom}' using '${pattern.context}' context`, + `starting to process a pattern from '${pattern.from}' using '${pattern.context}' context`, ); - const absoluteFrom = path.isAbsolute(normalizedOriginalFrom) - ? normalizedOriginalFrom - : path.resolve(pattern.context, normalizedOriginalFrom); + const absoluteFrom = path.isAbsolute(pattern.from) + ? path.normalize(pattern.from) + : path.resolve(pattern.context, pattern.from); logger.debug(`getting stats for '${absoluteFrom}'...`); @@ -367,11 +364,11 @@ class CopyPlugin { logger.debug(`added '${contextDependencies}' as a context dependency`); - glob = path.isAbsolute(originalFrom) - ? originalFrom + glob = path.isAbsolute(pattern.from) + ? pattern.from : path.posix.join( getTinyGlobby().escapePath(getNormalizePath()(pattern.context)), - originalFrom, + pattern.from, ); } } @@ -394,7 +391,7 @@ class CopyPlugin { if (globEntries.length === 0) { if (pattern.noErrorOnMissing) { logger.log( - `finished to process a pattern from '${normalizedOriginalFrom}' using '${pattern.context}' context to '${pattern.to}'`, + `finished to process a pattern from '${pattern.from}' using '${pattern.context}' context to '${pattern.to}'`, ); return; @@ -736,7 +733,7 @@ class CopyPlugin { if (copiedResult.length === 0) { if (pattern.noErrorOnMissing) { logger.log( - `finished to process a pattern from '${normalizedOriginalFrom}' using '${pattern.context}' context to '${pattern.to}'`, + `finished to process a pattern from '${pattern.from}' using '${pattern.context}' context to '${pattern.to}'`, ); return; @@ -752,7 +749,7 @@ class CopyPlugin { } logger.log( - `finished to process a pattern from '${normalizedOriginalFrom}' using '${pattern.context}' context`, + `finished to process a pattern from '${pattern.from}' using '${pattern.context}' context`, ); return copiedResult; From 4f9ebb38323e4970f498ad78bd5f9f967b6b1155 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 02:21:16 +0300 Subject: [PATCH 12/14] chore: fix lint --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 874d0af..444249c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -31,7 +31,7 @@ declare class CopyPlugin { * @param {WebpackLogger} logger the logger to use for logging * @param {CacheFacade} cache the cache facade to use for caching * @param {number} concurrency /maximum number of concurrent operations - * @param {ObjectPattern & { context: string }} inputPattern the pattern to process + * @param {ObjectPattern & { context: string }} pattern the pattern to process * @param {number} index the index of the pattern in the patterns array * @returns {Promise | undefined>} processes the pattern and returns an array of copied results */ From e90db9e4cba8a9bfc223e27f17df4077921c8872 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 02:46:37 +0300 Subject: [PATCH 13/14] refactor: code --- src/index.js | 59 ++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/src/index.js b/src/index.js index 73cfea7..82c47e1 100644 --- a/src/index.js +++ b/src/index.js @@ -20,7 +20,6 @@ const getTinyGlobby = memoize(() => require("tinyglobby")); /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ /** @typedef {import("webpack").Compiler} Compiler */ /** @typedef {import("webpack").Compilation} Compilation */ -/** @typedef {import("webpack").WebpackError} WebpackError */ /** @typedef {import("webpack").Asset} Asset */ /** @typedef {import("webpack").AssetInfo} AssetInfo */ /** @typedef {import("tinyglobby").GlobOptions} GlobbyOptions */ @@ -383,7 +382,7 @@ class CopyPlugin { try { globEntries = await globby(glob, globOptions); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -397,9 +396,7 @@ class CopyPlugin { return; } - const missingError = new Error(`unable to locate '${glob}' glob`); - - compilation.errors.push(/** @type {WebpackError} */ (missingError)); + compilation.errors.push(new Error(`unable to locate '${glob}' glob`)); return; } @@ -419,7 +416,7 @@ class CopyPlugin { try { isFiltered = await pattern.filter(globEntry); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -431,11 +428,10 @@ class CopyPlugin { } } - const from = globEntry; + const absoluteFilename = path.normalize(globEntry); - logger.debug(`found '${from}'`); + logger.debug(`found '${absoluteFilename}'`); - const absoluteFilename = path.normalize(from); const to = typeof pattern.to === "function" ? await pattern.to({ @@ -455,8 +451,12 @@ class CopyPlugin { logger.log(`'to' option '${to}' determinated as '${toType}'`); - const relativeFrom = path.relative(pattern.context, absoluteFilename); - let filename = toType === "dir" ? path.join(to, relativeFrom) : to; + const relativeFilename = path.relative( + pattern.context, + absoluteFilename, + ); + let filename = + toType === "dir" ? path.join(to, relativeFilename) : to; if (path.isAbsolute(filename)) { filename = path.relative( @@ -466,7 +466,9 @@ class CopyPlugin { ); } - logger.log(`determined that '${from}' should write to '${filename}'`); + logger.log( + `determined that '${absoluteFilename}' should write to '${filename}'`, + ); const sourceFilename = getNormalizePath()( path.relative(compiler.context, absoluteFilename), @@ -489,7 +491,7 @@ class CopyPlugin { null, ); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -514,7 +516,7 @@ class CopyPlugin { cacheEntry.snapshot, ); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -541,7 +543,7 @@ class CopyPlugin { // @ts-expect-error - webpack types are incomplete data = await readFile(inputFileSystem, absoluteFilename); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -561,7 +563,7 @@ class CopyPlugin { absoluteFilename, ); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -576,7 +578,7 @@ class CopyPlugin { snapshot, }); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -693,7 +695,7 @@ class CopyPlugin { const base = path.basename(sourceFilename); const name = base.slice(0, base.length - ext.length); const data = { - filename: getNormalizePath()(relativeFrom), + filename: getNormalizePath()(relativeFilename), contentHash, chunk: { name, @@ -725,7 +727,7 @@ class CopyPlugin { }), ); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -739,12 +741,10 @@ class CopyPlugin { return; } - const missingError = new Error( - `unable to locate '${glob}' glob after filtering paths`, + compilation.errors.push( + new Error(`Unable to locate '${glob}' glob after filtering paths`), ); - compilation.errors.push(/** @type {WebpackError} */ (missingError)); - return; } @@ -829,7 +829,7 @@ class CopyPlugin { index, ); } catch (error) { - compilation.errors.push(/** @type {WebpackError} */ (error)); + compilation.errors.push(/** @type {Error} */ (error)); return; } @@ -852,11 +852,8 @@ class CopyPlugin { if (typeof pattern.transformAll !== "undefined") { if (typeof pattern.to === "undefined") { compilation.errors.push( - /** @type {WebpackError} */ - ( - new Error( - `Invalid "pattern.to" for the "pattern.from": "${pattern.from}" and "pattern.transformAll" function. The "to" option must be specified.`, - ) + new Error( + `Invalid "pattern.to" for the "pattern.from": "${pattern.from}" and "pattern.transformAll" function. The "to" option must be specified.`, ), ); @@ -920,9 +917,7 @@ class CopyPlugin { })), ); } catch (error) { - compilation.errors.push( - /** @type {WebpackError} */ (error), - ); + compilation.errors.push(/** @type {Error} */ (error)); return; } From b28c7f0b6682748536126e392cfa6d384b6ec8e3 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 12 Aug 2025 02:48:59 +0300 Subject: [PATCH 14/14] refactor: code --- types/index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 444249c..06bfa9a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -60,7 +60,6 @@ declare namespace CopyPlugin { Schema, Compiler, Compilation, - WebpackError, Asset, AssetInfo, GlobbyOptions, @@ -93,7 +92,6 @@ declare namespace CopyPlugin { type Schema = import("schema-utils/declarations/validate").Schema; type Compiler = import("webpack").Compiler; type Compilation = import("webpack").Compilation; -type WebpackError = import("webpack").WebpackError; type Asset = import("webpack").Asset; type AssetInfo = import("webpack").AssetInfo; type GlobbyOptions = import("tinyglobby").GlobOptions;