From b65540651db4bd996c1c2c1bcfeb652420167a83 Mon Sep 17 00:00:00 2001 From: xfsnowind Date: Thu, 10 Oct 2024 14:05:17 +0800 Subject: [PATCH] fix: update the code of fetching plugin's name to be compatible of old HtmlRspackPlugin and HtmlWebpackPlugin --- dist/makeRspackConfig.js | 16 +++++++++++++++- src/makeRspackConfig.ts | 17 ++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/dist/makeRspackConfig.js b/dist/makeRspackConfig.js index a81286c..06ca0d7 100644 --- a/dist/makeRspackConfig.js +++ b/dist/makeRspackConfig.js @@ -30,7 +30,21 @@ exports.CYPRESS_RSPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js'); */ function modifyRspackConfigForCypress(rspackConfig) { if (rspackConfig === null || rspackConfig === void 0 ? void 0 : rspackConfig.plugins) { - rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => plugin && !removeList.includes(plugin.constructor.name)); + rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => { + if (plugin) { + let pluginName = ''; + try { + // NOTE: this is to be compatible the old version htmlRspackPlugin, to get its correct name + pluginName = + 'raw' in plugin ? plugin.raw({ options: { output: {} } }).name : plugin.constructor.name; + } + catch (_a) { + pluginName = plugin.constructor.name; + } + return !removeList.includes(pluginName); + } + return false; + }); } delete rspackConfig.entry; delete rspackConfig.output; diff --git a/src/makeRspackConfig.ts b/src/makeRspackConfig.ts index e8b7c8c..af7bebc 100644 --- a/src/makeRspackConfig.ts +++ b/src/makeRspackConfig.ts @@ -33,9 +33,20 @@ export const CYPRESS_RSPACK_ENTRYPOINT = path.resolve(__dirname, 'browser.js') */ function modifyRspackConfigForCypress(rspackConfig: Partial) { if (rspackConfig?.plugins) { - rspackConfig.plugins = rspackConfig.plugins.filter( - (plugin) => plugin && !removeList.includes(plugin.constructor.name), - ) + rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => { + if (plugin) { + let pluginName: string = '' + try { + // NOTE: this is to be compatible the old version htmlRspackPlugin, to get its correct name + pluginName = + 'raw' in plugin ? plugin.raw({ options: { output: {} } }).name : plugin.constructor.name + } catch { + pluginName = plugin.constructor.name + } + return !removeList.includes(pluginName) + } + return false + }) } delete rspackConfig.entry