diff --git a/dist/CypressCTRspackPlugin.d.ts b/dist/CypressCTRspackPlugin.d.ts index 986bb0c..608f8dc 100644 --- a/dist/CypressCTRspackPlugin.d.ts +++ b/dist/CypressCTRspackPlugin.d.ts @@ -4,7 +4,6 @@ export interface CypressCTRspackPluginOptions { projectRoot: string; supportFile: string | false; devServerEvents: EventEmitter; - rspack: Function; indexHtmlFile: string; } export type CypressCTContextOptions = Omit; diff --git a/dist/CypressCTRspackPlugin.js b/dist/CypressCTRspackPlugin.js index ef93bd3..14914f9 100644 --- a/dist/CypressCTRspackPlugin.js +++ b/dist/CypressCTRspackPlugin.js @@ -79,7 +79,11 @@ class CypressCTRspackPlugin { */ this.addCompilationHooks = (compilation) => { this.compilation = compilation; - const loader = this.compilation.compiler.rspack.NormalModule.getCompilationHooks(compilation).loader; + // still use legacy `webpack` here since in version 0.x.x does not have rspack + const compiler = ('rspack' in this.compilation.compiler + ? this.compilation.compiler.rspack + : this.compilation.compiler.webpack); + const loader = compiler.NormalModule.getCompilationHooks(compilation).loader; loader.tap('CypressCTPlugin', this.addLoaderContext); }; this.files = options.files; diff --git a/dist/devServer.d.ts b/dist/devServer.d.ts index 5cc4f81..10906f1 100644 --- a/dist/devServer.d.ts +++ b/dist/devServer.d.ts @@ -1,7 +1,6 @@ import type { EventEmitter } from 'events'; import type { RspackDevServer } from '@rspack/dev-server'; import type { Configuration } from '@rspack/core'; -import { SourceRelativeRspackResult } from './helpers/sourceRelativeRspackModules'; export type Frameworks = Extract['framework']; @@ -13,7 +12,7 @@ type FrameworkConfig = { projectConfig: Cypress.AngularDevServerProjectConfig; }; }; -export type ConfigHandler = Partial | (() => Partial | Promise>); +type ConfigHandler = Partial | (() => Partial | Promise>); export type DevServerConfig = { specs: Cypress.Spec[]; cypressConfig: Cypress.PluginConfigOptions; @@ -36,9 +35,4 @@ export declare namespace devServer { compiler: any; }>; } -export type PresetHandlerResult = { - frameworkConfig: Configuration; - sourceRspackModulesResult: SourceRelativeRspackResult; -}; -export declare function isThirdPartyDefinition(framework: string): boolean; -export default devServer; +export {}; diff --git a/dist/devServer.js b/dist/devServer.js index edc6227..dd78d2b 100644 --- a/dist/devServer.js +++ b/dist/devServer.js @@ -1,9 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.devServer = devServer; -exports.isThirdPartyDefinition = isThirdPartyDefinition; const tslib_1 = require("tslib"); -/// const debug_1 = tslib_1.__importDefault(require("debug")); const createRspackDevServer_1 = require("./createRspackDevServer"); const sourceRelativeRspackModules_1 = require("./helpers/sourceRelativeRspackModules"); @@ -97,4 +95,3 @@ devServer.create = async function (devServerConfig) { }); return { server, compiler }; }; -exports.default = devServer; diff --git a/dist/helpers/sourceRelativeRspackModules.d.ts b/dist/helpers/sourceRelativeRspackModules.d.ts index 67d608a..cc7a8fc 100644 --- a/dist/helpers/sourceRelativeRspackModules.d.ts +++ b/dist/helpers/sourceRelativeRspackModules.d.ts @@ -29,7 +29,6 @@ export interface SourceRelativeRspackResult { rspack: SourcedRspack; rspackDevServer: SourcedRspackDevServer; } -export declare const cypressRspackPath: (config: DevServerConfig) => string; export declare function sourceFramework(config: DevServerConfig): SourcedDependency | null; export declare function sourceRspack(config: DevServerConfig, framework: SourcedDependency | null): SourcedRspack; export declare function sourceRspackDevServer(config: DevServerConfig, framework?: SourcedDependency | null): SourcedRspackDevServer; diff --git a/dist/helpers/sourceRelativeRspackModules.js b/dist/helpers/sourceRelativeRspackModules.js index 42d4226..254d944 100644 --- a/dist/helpers/sourceRelativeRspackModules.js +++ b/dist/helpers/sourceRelativeRspackModules.js @@ -1,6 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.cypressRspackPath = void 0; exports.sourceFramework = sourceFramework; exports.sourceRspack = sourceRspack; exports.sourceRspackDevServer = sourceRspackDevServer; @@ -13,12 +12,6 @@ const debug_1 = tslib_1.__importDefault(require("debug")); const debug = (0, debug_1.default)('cypress-rspack-dev-server:sourceRelativeRspackModules'); const originalModuleLoad = module_1.default._load; const originalModuleResolveFilename = module_1.default._resolveFilename; -const cypressRspackPath = (config) => { - return require.resolve('@cypress/rspack-batteries-included-preprocessor', { - paths: [config.cypressConfig.cypressBinaryRoot], - }); -}; -exports.cypressRspackPath = cypressRspackPath; const frameworkRspackMapper = { 'create-react-app': 'react-scripts', 'vue-cli': '@vue/cli-service', @@ -68,22 +61,9 @@ function sourceRspack(config, framework) { const searchRoot = (_a = framework === null || framework === void 0 ? void 0 : framework.importPath) !== null && _a !== void 0 ? _a : config.cypressConfig.projectRoot; debug('Rspack: Attempting to source rspack from %s', searchRoot); const rspack = {}; - let rspackJsonPath; - try { - rspackJsonPath = require.resolve('@rspack/core/package.json', { - paths: [searchRoot], - }); - } - catch (e) { - if (e.code !== 'MODULE_NOT_FOUND') { - debug('Rspack: Failed to source rspack - %s', e); - throw e; - } - debug('rspack: Falling back to bundled version'); - rspackJsonPath = require.resolve('@rspack/core/package.json', { - paths: [(0, exports.cypressRspackPath)(config)], - }); - } + const rspackJsonPath = require.resolve('@rspack/core/package.json', { + paths: [searchRoot], + }); rspack.importPath = path_1.default.dirname(rspackJsonPath); rspack.packageJson = require(rspackJsonPath); rspack.module = require(rspack.importPath).rspack; diff --git a/dist/makeDefaultRspackConfig.js b/dist/makeDefaultRspackConfig.js index 744cebb..f4fe304 100644 --- a/dist/makeDefaultRspackConfig.js +++ b/dist/makeDefaultRspackConfig.js @@ -17,9 +17,7 @@ function makeCypressRspackConfig(config) { // rspack does not recognize the sideEffects flag in the package.json and thus files are not unintentionally // dropped during testing in production mode. sideEffects: false, - splitChunks: { - chunks: 'all', - }, + splitChunks: { chunks: 'all' }, }; const publicPath = path_1.default.sep === posixSeparator ? path_1.default.join(devServerPublicPathRoute, posixSeparator) @@ -44,7 +42,6 @@ function makeCypressRspackConfig(config) { projectRoot, devServerEvents, supportFile, - rspack, indexHtmlFile, }), ], diff --git a/dist/makeRspackConfig.js b/dist/makeRspackConfig.js index 53cc838..a81286c 100644 --- a/dist/makeRspackConfig.js +++ b/dist/makeRspackConfig.js @@ -30,8 +30,7 @@ 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('raw' in plugin ? plugin.raw({ options: { output: {} } }).name : plugin.constructor.name)); + rspackConfig.plugins = rspackConfig.plugins.filter((plugin) => plugin && !removeList.includes(plugin.constructor.name)); } delete rspackConfig.entry; delete rspackConfig.output; diff --git a/src/CypressCTRspackPlugin.ts b/src/CypressCTRspackPlugin.ts index 83535be..f3bb221 100644 --- a/src/CypressCTRspackPlugin.ts +++ b/src/CypressCTRspackPlugin.ts @@ -18,7 +18,6 @@ export interface CypressCTRspackPluginOptions { projectRoot: string supportFile: string | false devServerEvents: EventEmitter - rspack: Function indexHtmlFile: string } @@ -138,8 +137,14 @@ export class CypressCTRspackPlugin { private addCompilationHooks = (compilation: RspackCompilation) => { this.compilation = compilation - const loader = - this.compilation.compiler.rspack.NormalModule.getCompilationHooks(compilation).loader + // still use legacy `webpack` here since in version 0.x.x does not have rspack + const compiler = ( + 'rspack' in this.compilation.compiler + ? this.compilation.compiler.rspack + : (this.compilation.compiler as Compiler).webpack + ) as Compiler['webpack'] + + const loader = compiler.NormalModule.getCompilationHooks(compilation).loader loader.tap('CypressCTPlugin', this.addLoaderContext) } diff --git a/src/devServer.ts b/src/devServer.ts index 5219dfd..0238312 100644 --- a/src/devServer.ts +++ b/src/devServer.ts @@ -1,4 +1,3 @@ -/// import debugLib from 'debug' import type { EventEmitter } from 'events' import type { RspackDevServer } from '@rspack/dev-server' @@ -28,7 +27,7 @@ type FrameworkConfig = } } -export type ConfigHandler = +type ConfigHandler = | Partial | (() => Partial | Promise>) @@ -90,7 +89,7 @@ export function devServer( }) } -export type PresetHandlerResult = { +type PresetHandlerResult = { frameworkConfig: Configuration sourceRspackModulesResult: SourceRelativeRspackResult } @@ -103,7 +102,7 @@ const thirdPartyDefinitionPrefixes = { globalPrefix: 'cypress-ct-', } -export function isThirdPartyDefinition(framework: string) { +function isThirdPartyDefinition(framework: string) { return ( framework.startsWith(thirdPartyDefinitionPrefixes.globalPrefix) || thirdPartyDefinitionPrefixes.namespacedPrefixRe.test(framework) @@ -170,5 +169,3 @@ devServer.create = async function (devServerConfig: DevServerConfig) { return { server, compiler } } - -export default devServer diff --git a/src/helpers/sourceRelativeRspackModules.ts b/src/helpers/sourceRelativeRspackModules.ts index 0627255..ca0d6e6 100644 --- a/src/helpers/sourceRelativeRspackModules.ts +++ b/src/helpers/sourceRelativeRspackModules.ts @@ -46,12 +46,6 @@ export interface SourceRelativeRspackResult { const originalModuleLoad = (Module as ModuleClass)._load const originalModuleResolveFilename = (Module as ModuleClass)._resolveFilename -export const cypressRspackPath = (config: DevServerConfig) => { - return require.resolve('@cypress/rspack-batteries-included-preprocessor', { - paths: [config.cypressConfig.cypressBinaryRoot], - }) -} - type FrameworkRspackMapper = { [Property in Frameworks]: string | undefined } const frameworkRspackMapper: FrameworkRspackMapper = { @@ -121,24 +115,9 @@ export function sourceRspack( const rspack = {} as SourcedRspack - let rspackJsonPath: string - - try { - rspackJsonPath = require.resolve('@rspack/core/package.json', { - paths: [searchRoot], - }) - } catch (e) { - if ((e as { code?: string }).code !== 'MODULE_NOT_FOUND') { - debug('Rspack: Failed to source rspack - %s', e) - throw e - } - - debug('rspack: Falling back to bundled version') - - rspackJsonPath = require.resolve('@rspack/core/package.json', { - paths: [cypressRspackPath(config)], - }) - } + const rspackJsonPath: string = require.resolve('@rspack/core/package.json', { + paths: [searchRoot], + }) rspack.importPath = path.dirname(rspackJsonPath) rspack.packageJson = require(rspackJsonPath) diff --git a/src/makeDefaultRspackConfig.ts b/src/makeDefaultRspackConfig.ts index 5ca3fcd..ebff0c8 100644 --- a/src/makeDefaultRspackConfig.ts +++ b/src/makeDefaultRspackConfig.ts @@ -35,9 +35,7 @@ export function makeCypressRspackConfig(config: CreateFinalRspackConfig): Config // rspack does not recognize the sideEffects flag in the package.json and thus files are not unintentionally // dropped during testing in production mode. sideEffects: false, - splitChunks: { - chunks: 'all', - }, + splitChunks: { chunks: 'all' }, } const publicPath = @@ -65,7 +63,6 @@ export function makeCypressRspackConfig(config: CreateFinalRspackConfig): Config projectRoot, devServerEvents, supportFile, - rspack, indexHtmlFile, }), ], diff --git a/src/makeRspackConfig.ts b/src/makeRspackConfig.ts index d5a7231..e8b7c8c 100644 --- a/src/makeRspackConfig.ts +++ b/src/makeRspackConfig.ts @@ -34,11 +34,7 @@ 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( - 'raw' in plugin ? plugin.raw({ options: { output: {} } }).name : plugin.constructor.name, - ), + (plugin) => plugin && !removeList.includes(plugin.constructor.name), ) }