Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to rspack #16

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions __snapshots__/makeRspackConfig.spec.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
exports[
'makeRspackConfig ignores userland rspack `output.publicPath` and `devServer.overlay` with rspack-dev-server v4 1'
] = {
output: {
publicPath: '/test-public-path/',
filename: '[name].js',
},
devServer: {
magicHtml: true,
client: {
progress: false,
overlay: false,
},
},
optimization: {
emitOnErrors: true,
sideEffects: false,
splitChunks: {
chunks: 'all',
},
},
devtool: 'inline-source-map',
mode: 'development',
plugins: ['HtmlWebpackPlugin', 'CypressCTWebpackPlugin'],
}

exports[
'makeWebpackConfig ignores userland rspack `output.publicPath` and `devServer.overlay` with rspack-dev-server v3 1'
] = {
output: {
publicPath: '/test-public-path/',
filename: '[name].js',
},
devServer: {
progress: true,
overlay: false,
},
optimization: {
noEmitOnErrors: false,
sideEffects: false,
splitChunks: {
chunks: 'all',
},
},
devtool: 'inline-source-map',
mode: 'development',
plugins: ['HtmlWebpackPlugin', 'CypressCTWebpackPlugin'],
}
50 changes: 0 additions & 50 deletions __snapshots__/makeWebpackConfig.spec.ts.js

This file was deleted.

2 changes: 1 addition & 1 deletion dist/createRspackDevServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ async function createRspackDevServer(config) {
server,
compiler: rspackCompiler,
};
throw new Error(`Unsupported webpackDevServer version ${rspackDevServerMajorVersion}`);
throw new Error(`Unsupported rspackDevServer version ${rspackDevServerMajorVersion}`);
}
exports.createRspackDevServer = createRspackDevServer;
6 changes: 3 additions & 3 deletions dist/devServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export type DevServerConfig = {
specs: Cypress.Spec[];
cypressConfig: Cypress.PluginConfigOptions;
devServerEvents: NodeJS.EventEmitter;
onConfigNotFound?: (devServer: 'webpack', cwd: string, lookedIn: string[]) => void;
onConfigNotFound?: (devServer: 'rspack', cwd: string, lookedIn: string[]) => void;
rspackConfig?: ConfigHandler;
} & FrameworkConfig;
/**
* import { devServer } from '@cypress/rspack-dev-server'
* import { RspackDevServer } from '@rspack/dev-server'
*
* Creates & returns a WebpackDevServer for serving files related
* Creates & returns a RspackDevServer for serving files related
* to Cypress Component Testing
*
* @param config
Expand Down
4 changes: 2 additions & 2 deletions dist/devServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const debug_1 = tslib_1.__importDefault(require("debug"));
const sourceRelativeRspackModules_1 = require("./helpers/sourceRelativeRspackModules");
const debug = (0, debug_1.default)('cypress:rspack-dev-server:devServer');
/**
* import { devServer } from '@cypress/rspack-dev-server'
* import { RspackDevServer } from '@rspack/dev-server'
*
* Creates & returns a WebpackDevServer for serving files related
* Creates & returns a RspackDevServer for serving files related
* to Cypress Component Testing
*
* @param config
Expand Down
2 changes: 1 addition & 1 deletion dist/helpers/sourceRelativeRspackModules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface SourceRelativeRspackResult {
rspack: SourcedRspack;
rspackDevServer: SourcedRspackDevServer;
}
export declare const cypressWebpackPath: (config: DevServerConfig) => string;
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;
Expand Down
42 changes: 19 additions & 23 deletions dist/helpers/sourceRelativeRspackModules.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.restoreLoadHook = exports.getMajorVersion = exports.sourceDefaultRspackDependencies = exports.sourceRspackDevServer = exports.sourceRspack = exports.sourceFramework = exports.cypressWebpackPath = void 0;
exports.restoreLoadHook = exports.getMajorVersion = exports.sourceDefaultRspackDependencies = exports.sourceRspackDevServer = exports.sourceRspack = exports.sourceFramework = exports.cypressRspackPath = void 0;
const tslib_1 = require("tslib");
const module_1 = tslib_1.__importDefault(require("module"));
const path_1 = tslib_1.__importDefault(require("path"));
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 cypressWebpackPath = (config) => {
const cypressRspackPath = (config) => {
return require.resolve('@cypress/rspack-batteries-included-preprocessor', {
paths: [config.cypressConfig.cypressBinaryRoot],
});
};
exports.cypressWebpackPath = cypressWebpackPath;
const frameworkWebpackMapper = {
exports.cypressRspackPath = cypressRspackPath;
const frameworkRspackMapper = {
'create-react-app': 'react-scripts',
'vue-cli': '@vue/cli-service',
nuxt: '@nuxt/rspack',
Expand All @@ -32,14 +32,14 @@ function sourceFramework(config) {
debug('Framework: No framework provided');
return null;
}
const sourceOfWebpack = frameworkWebpackMapper[config.framework];
if (!sourceOfWebpack) {
const sourceOfRspack = frameworkRspackMapper[config.framework];
if (!sourceOfRspack) {
debug('Not a higher-order framework so rspack dependencies should be resolvable from projectRoot');
return null;
}
const framework = {};
try {
const frameworkJsonPath = require.resolve(`${sourceOfWebpack}/package.json`, {
const frameworkJsonPath = require.resolve(`${sourceOfRspack}/package.json`, {
paths: [config.cypressConfig.projectRoot],
});
const frameworkPathRoot = path_1.default.dirname(frameworkJsonPath);
Expand Down Expand Up @@ -78,16 +78,16 @@ function sourceRspack(config, framework) {
}
debug('rspack: Falling back to bundled version');
rspackJsonPath = require.resolve('@rspack/core/package.json', {
paths: [(0, exports.cypressWebpackPath)(config)],
paths: [(0, exports.cypressRspackPath)(config)],
});
}
rspack.importPath = path_1.default.dirname(rspackJsonPath);
rspack.packageJson = require(rspackJsonPath);
rspack.module = require(rspack.importPath).rspack;
rspack.majorVersion = getMajorVersion(rspack.packageJson, [0]);
debug('Webpack: Successfully sourced rspack - %o', rspack);
debug('Rspack: Successfully sourced rspack - %o', rspack);
module_1.default._load = function (request, parent, isMain) {
if (request === 'webpack' || request.startsWith('rspack/')) {
if (request === 'rspack' || request.startsWith('rspack/')) {
const resolvePath = require.resolve(request, {
paths: [rspack.importPath],
});
Expand All @@ -97,11 +97,11 @@ function sourceRspack(config, framework) {
return originalModuleLoad(request, parent, isMain);
};
module_1.default._resolveFilename = function (request, parent, isMain, options) {
if (request === 'webpack' || (request.startsWith('rspack/') && !(options === null || options === void 0 ? void 0 : options.paths))) {
if (request === 'rspack' || (request.startsWith('rspack/') && !(options === null || options === void 0 ? void 0 : options.paths))) {
const resolveFilename = originalModuleResolveFilename(request, parent, isMain, {
paths: [rspack.importPath],
});
debug('Webpack: Module._resolveFilename resolveFilename - %s', resolveFilename);
debug('Rspack: Module._resolveFilename resolveFilename - %s', resolveFilename);
return resolveFilename;
}
return originalModuleResolveFilename(request, parent, isMain, options);
Expand All @@ -114,7 +114,7 @@ exports.sourceRspack = sourceRspack;
function sourceRspackDevServer(config, framework) {
var _a;
const searchRoot = (_a = framework === null || framework === void 0 ? void 0 : framework.importPath) !== null && _a !== void 0 ? _a : config.cypressConfig.projectRoot;
debug('WebpackDevServer: Attempting to source rspack-dev-server from %s', searchRoot);
debug('RspackDevServer: Attempting to source rspack-dev-server from %s', searchRoot);
const rspackDevServer = {};
let rspackDevServerJsonPath;
try {
Expand All @@ -127,7 +127,7 @@ function sourceRspackDevServer(config, framework) {
debug('RspackDevServer: Failed to source @rspack/dev-server - %s', e);
throw e;
}
debug('WebpackDevServer: Falling back to bundled version');
debug('RspackDevServer: Falling back to bundled version');
rspackDevServerJsonPath = require.resolve('@rspack/dev-server/package.json', {
paths: [__dirname],
});
Expand All @@ -136,27 +136,23 @@ function sourceRspackDevServer(config, framework) {
rspackDevServer.packageJson = require(rspackDevServerJsonPath);
rspackDevServer.module = require(rspackDevServer.importPath).RspackDevServer;
rspackDevServer.majorVersion = getMajorVersion(rspackDevServer.packageJson, [0]);
debug('WebpackDevServer: Successfully sourced rspack-dev-server - %o', rspackDevServer);
debug('RspackDevServer: Successfully sourced rspack-dev-server - %o', rspackDevServer);
return rspackDevServer;
}
exports.sourceRspackDevServer = sourceRspackDevServer;
// Most frameworks follow a similar path for sourcing rspack dependencies so this is a utility to handle all the sourcing.
function sourceDefaultRspackDependencies(config) {
const framework = sourceFramework(config);
const webpack = sourceRspack(config, framework);
const webpackDevServer = sourceRspackDevServer(config, framework);
return {
framework,
rspack: webpack,
rspackDevServer: webpackDevServer,
};
const rspack = sourceRspack(config, framework);
const rspackDevServer = sourceRspackDevServer(config, framework);
return { framework, rspack, rspackDevServer };
}
exports.sourceDefaultRspackDependencies = sourceDefaultRspackDependencies;
function getMajorVersion(json, acceptedVersions) {
const major = Number(json.version.split('.')[0]);
if (!acceptedVersions.includes(major)) {
throw new Error(`Unexpected major version of ${json.name}. ` +
`Cypress webpack-dev-server works with ${json.name} versions ${acceptedVersions.join(', ')} - saw ${json.version}`);
`Cypress-rspack-dev-server works with ${json.name} versions ${acceptedVersions.join(', ')} - saw ${json.version}`);
}
return Number(major);
}
Expand Down
6 changes: 3 additions & 3 deletions dist/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const debug = (0, debug_1.default)('cypress:rspack-dev-server:rspack');
*/
const makeImport = (file, filename, chunkName, projectRoot) => {
// If we want to rename the chunks, we can use this
const magicComments = chunkName ? `/* webpackChunkName: "${chunkName}" */` : '';
const magicComments = chunkName ? `/* rspackChunkName: "${chunkName}" */` : '';
return `"${filename}": {
shouldLoad: () => decodeURI(document.location.pathname).includes("${file.absolute}"),
load: () => import(${magicComments} "${file.absolute}"),
Expand All @@ -32,7 +32,7 @@ const makeImport = (file, filename, chunkName, projectRoot) => {
* "App.spec.js": {
* shouldLoad: () => document.location.pathname.includes('cypress/component/App.spec.js'),
* load: () => {
* return import("/Users/projects/my-app/cypress/component/App.spec.js" \/* webpackChunkName: "spec-0" *\/)
* return import("/Users/projects/my-app/cypress/component/App.spec.js" \/* rspackChunkName: "spec-0" *\/)
* },
* chunkName: "spec-0"
* }
Expand Down Expand Up @@ -80,7 +80,7 @@ function loader() {
absolute: ${supportFileAbsolutePath},
relative: ${supportFileRelativePath},
relativeUrl: "/__cypress/src/cypress-support-file.js",
load: () => import(/* webpackChunkName: "cypress-support-file" */ ${supportFileAbsolutePath}),
load: () => import(/* rspackChunkName: "cypress-support-file" */ ${supportFileAbsolutePath}),
}
scriptLoaders.unshift(supportFile)
}
Expand Down
26 changes: 23 additions & 3 deletions dist/makeRspackConfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ export declare function makeRspackConfig(config: CreateFinalRspackConfig): Promi
asyncChunks?: boolean | undefined;
wasmLoading?: string | false | undefined;
filename?: string | undefined;
library?: {
type: string;
amdContainer?: string | undefined;
auxiliaryComment?: string | {
amd?: string | undefined;
commonjs?: string | undefined;
commonjs2?: string | undefined;
root?: string | undefined;
} | undefined;
export?: string | string[] | undefined;
name?: string | string[] | {
amd?: string | undefined;
commonjs?: string | undefined;
root?: string | string[] | undefined;
} | undefined;
umdNamedDefine?: boolean | undefined;
} | undefined;
}> | undefined;
output?: {
path?: string | undefined;
Expand All @@ -40,6 +57,7 @@ export declare function makeRspackConfig(config: CreateFinalRspackConfig): Promi
root?: string | string[] | undefined;
} | {
type: string;
amdContainer?: string | undefined;
auxiliaryComment?: string | {
amd?: string | undefined;
commonjs?: string | undefined;
Expand All @@ -57,6 +75,7 @@ export declare function makeRspackConfig(config: CreateFinalRspackConfig): Promi
libraryExport?: string | string[] | undefined;
libraryTarget?: string | undefined;
umdNamedDefine?: boolean | undefined;
amdContainer?: string | undefined;
auxiliaryComment?: string | {
amd?: string | undefined;
commonjs?: string | undefined;
Expand Down Expand Up @@ -111,20 +130,20 @@ export declare function makeRspackConfig(config: CreateFinalRspackConfig): Promi
context?: string | undefined;
dependencyType?: string | undefined;
request?: string | undefined;
}, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "jsonp" | "import" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs" | "commonjs2" | "commonjs-module" | "commonjs-static" | "amd" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
}, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
context?: string | undefined;
dependencyType?: string | undefined;
request?: string | undefined;
}, ...args_1: unknown[]) => Promise<string | boolean | string[] | Record<string, string | string[]>>) | (string | RegExp | Record<string, string | boolean | string[] | Record<string, string | string[]>> | ((args_0: {
context?: string | undefined;
dependencyType?: string | undefined;
request?: string | undefined;
}, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "jsonp" | "import" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs" | "commonjs2" | "commonjs-module" | "commonjs-static" | "amd" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
}, args_1: (args_0: Error | undefined, args_1: string | boolean | string[] | Record<string, string | string[]> | undefined, args_2: "module" | "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined, ...args_3: unknown[]) => void, ...args_2: unknown[]) => unknown) | ((args_0: {
context?: string | undefined;
dependencyType?: string | undefined;
request?: string | undefined;
}, ...args_1: unknown[]) => Promise<string | boolean | string[] | Record<string, string | string[]>>))[] | undefined;
externalsType?: "module" | "promise" | "jsonp" | "import" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs" | "commonjs2" | "commonjs-module" | "commonjs-static" | "amd" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined;
externalsType?: "module" | "promise" | "jsonp" | "import" | "amd" | "commonjs" | "commonjs2" | "var" | "assign" | "this" | "window" | "self" | "global" | "commonjs-module" | "commonjs-static" | "amd-require" | "umd" | "umd2" | "system" | "script" | "node-commonjs" | undefined;
externalsPresets?: {
node?: boolean | undefined;
web?: boolean | undefined;
Expand Down Expand Up @@ -189,6 +208,7 @@ export declare function makeRspackConfig(config: CreateFinalRspackConfig): Promi
logging?: boolean | "none" | "verbose" | "error" | "warn" | "info" | "log" | undefined;
loggingDebug?: string | boolean | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean) | (string | RegExp | ((args_0: string, ...args_1: unknown[]) => boolean))[] | undefined;
loggingTrace?: boolean | undefined;
runtimeModules?: boolean | undefined;
} | undefined;
snapshot?: {
module?: {
Expand Down
Loading
Loading