From 3e46dd2c1e66d66155da301023d9d78cf948dee8 Mon Sep 17 00:00:00 2001 From: pshu Date: Tue, 25 Nov 2025 15:19:21 +0800 Subject: [PATCH 1/2] chore: fix prettier script align style with rspack --- .github/renovate.json5 | 8 +- .github/workflows/release.yml | 5 +- .prettierignore | 5 + .prettierrc.js | 21 ++++ .vscode/extensions.json | 12 +- .vscode/settings.json | 32 ++--- README.md | 18 +-- client-src/index.js | 66 +++++----- client-src/utils/ansiHTML.ts | 116 +++++++++--------- package.json | 7 +- .../multi-compiler-two-configurations/one.js | 2 +- .../worker-config-dev-server-false/index.js | 2 +- .../public/worker-bundle.js | 17 ++- .../webpack.config.js | 14 +-- .../worker-config-dev-server-false/worker.js | 2 +- tests/fixtures/worker-config/index.js | 2 +- .../fixtures/worker-config/webpack.config.js | 18 +-- tests/fixtures/worker-config/worker.js | 2 +- tests/tsconfig.json | 16 +-- tsconfig.build.json | 10 +- tsconfig.client.json | 24 ++-- tsconfig.json | 46 +++---- 22 files changed, 231 insertions(+), 214 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc.js diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 5017ff0..4196e31 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,6 +1,6 @@ { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": ["config:base", "schedule:monthly", "group:allNonMajor"], - "rangeStrategy": "bump", - "packageRules": [{ "depTypeList": ["peerDependencies"], "enabled": false }] + $schema: "https://docs.renovatebot.com/renovate-schema.json", + extends: ["config:base", "schedule:monthly", "group:allNonMajor"], + rangeStrategy: "bump", + packageRules: [{ depTypeList: ["peerDependencies"], enabled: false }] } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37d5acc..e536ab8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,3 @@ - name: Release Full on: @@ -29,7 +28,7 @@ on: - latest - beta - alpha - + dry_run: type: boolean description: "DryRun release" @@ -72,7 +71,7 @@ jobs: - name: Run Test run: pnpm run test - + - name: Try release to npm run: pnpm run release env: diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..b704893 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +dist +node_modules +client +*.tsbuildinfo +pnpm-lock.yaml diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..fb8951d --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,21 @@ +module.exports = { + useTabs: true, + tabWidth: 2, + trailingComma: "none", + arrowParens: "avoid", + overrides: [ + { + files: "*.json", + options: { + parser: "json", + useTabs: false, + }, + }, + { + files: "*.ts", + options: { + parser: "typescript", + }, + }, + ], +}; diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 593120a..ed91718 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,8 @@ { - "recommendations": [ - "streetsidesoftware.code-spell-checker", - "tamasfe.even-better-toml", - "rust-lang.rust-analyzer", - "fabiospampinato.vscode-debug-launcher" - ] + "recommendations": [ + "streetsidesoftware.code-spell-checker", + "tamasfe.even-better-toml", + "rust-lang.rust-analyzer", + "fabiospampinato.vscode-debug-launcher" + ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c3dfeb..58f2f56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,18 +1,18 @@ { - "search.useIgnoreFiles": true, - "[json]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[typescript]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[javascript]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[javascriptreact]": { - "editor.defaultFormatter": "biomejs.biome" - }, - "[css]": { - "editor.defaultFormatter": "biomejs.biome" - } + "search.useIgnoreFiles": true, + "[json]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[typescript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascript]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[javascriptreact]": { + "editor.defaultFormatter": "biomejs.biome" + }, + "[css]": { + "editor.defaultFormatter": "biomejs.biome" + } } diff --git a/README.md b/README.md index 5577bdc..86b2788 100644 --- a/README.md +++ b/README.md @@ -75,11 +75,11 @@ While starting the development server, you can specify the configuration by the ```js // rspack.config.mjs export default { - // ... - devServer: { - // the configuration of the development server - port: 8080, - }, + // ... + devServer: { + // the configuration of the development server + port: 8080 + } }; ``` @@ -96,15 +96,15 @@ import rspackConfig from "./rspack.config.mjs"; const compiler = rspack(rspackConfig); const devServerOptions = { - ...rspackConfig.devServer, - // override - port: 8888, + ...rspackConfig.devServer, + // override + port: 8888 }; const server = new RspackDevServer(devServerOptions, compiler); server.startCallback(() => { - console.log("Successfully started server on http://localhost:8888"); + console.log("Successfully started server on http://localhost:8888"); }); ``` diff --git a/client-src/index.js b/client-src/index.js index 89362b0..e76f6a3 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -7,12 +7,12 @@ import hotEmitter from "@rspack/core/hot/emitter.js"; import webpackHotLog from "@rspack/core/hot/log.js"; import { createOverlay, - formatProblem, + formatProblem } from "webpack-dev-server/client/overlay.js"; import socket from "webpack-dev-server/client/socket.js"; import { defineProgressElement, - isProgressSupported, + isProgressSupported } from "webpack-dev-server/client/progress.js"; import { log, setLogLevel } from "webpack-dev-server/client/utils/log.js"; import sendMessage from "webpack-dev-server/client/utils/sendMessage.js"; @@ -45,19 +45,19 @@ import sendMessage from "webpack-dev-server/client/utils/sendMessage.js"; /** * @param {boolean | { warnings?: boolean | string; errors?: boolean | string; runtimeErrors?: boolean | string; }} overlayOptions */ -const decodeOverlayOptions = (overlayOptions) => { +const decodeOverlayOptions = overlayOptions => { if (typeof overlayOptions === "object") { - ["warnings", "errors", "runtimeErrors"].forEach((property) => { + ["warnings", "errors", "runtimeErrors"].forEach(property => { if (typeof overlayOptions[property] === "string") { const overlayFilterFunctionString = decodeURIComponent( - overlayOptions[property], + overlayOptions[property] ); // eslint-disable-next-line no-new-func overlayOptions[property] = new Function( "message", `var callback = ${overlayFilterFunctionString} - return callback(message)`, + return callback(message)` ); } }); @@ -68,7 +68,7 @@ const decodeOverlayOptions = (overlayOptions) => { * @param {string} resourceQuery * @returns {{ [key: string]: string | boolean }} */ -const parseURL = (resourceQuery) => { +const parseURL = resourceQuery => { /** @type {{ [key: string]: string }} */ let result = {}; @@ -111,7 +111,7 @@ const parseURL = (resourceQuery) => { const status = { isUnloading: false, // eslint-disable-next-line camelcase - currentHash: __webpack_hash__, + currentHash: __webpack_hash__ }; /** @@ -128,7 +128,7 @@ const getCurrentScriptSource = () => { const scriptElements = document.scripts || []; const scriptElementsWithSrc = Array.prototype.filter.call( scriptElements, - (element) => element.getAttribute("src"), + element => element.getAttribute("src") ); if (scriptElementsWithSrc.length > 0) { @@ -148,7 +148,7 @@ const enabledFeatures = { "Hot Module Replacement": false, "Live Reloading": false, Progress: false, - Overlay: false, + Overlay: false }; /** @type {Options} */ @@ -156,7 +156,7 @@ const options = { hot: false, liveReload: false, progress: false, - overlay: false, + overlay: false }; if (parsedResourceQuery.hot === "true") { @@ -187,7 +187,7 @@ if (parsedResourceQuery.overlay) { errors: true, warnings: true, runtimeErrors: true, - ...options.overlay, + ...options.overlay }; decodeOverlayOptions(options.overlay); @@ -206,10 +206,10 @@ if (typeof parsedResourceQuery.reconnect !== "undefined") { /** * @param {string} level */ -const setAllLogLevel = (level) => { +const setAllLogLevel = level => { // This is needed because the HMR logger operate separately from dev server logger webpackHotLog.setLogLevel( - level === "verbose" || level === "log" ? "info" : level, + level === "verbose" || level === "log" ? "info" : level ); setLogLevel(level); }; @@ -218,7 +218,7 @@ if (options.logging) { setAllLogLevel(options.logging); } -const logEnabledFeatures = (features) => { +const logEnabledFeatures = features => { const listEnabledFeatures = Object.keys(features); if (!features || listEnabledFeatures.length === 0) { return; @@ -249,12 +249,12 @@ const overlay = typeof options.overlay === "object" ? { trustedTypesPolicyName: options.overlay.trustedTypesPolicyName, - catchRuntimeError: options.overlay.runtimeErrors, + catchRuntimeError: options.overlay.runtimeErrors } : { trustedTypesPolicyName: false, - catchRuntimeError: options.overlay, - }, + catchRuntimeError: options.overlay + } ) : { send: () => {} }; @@ -326,9 +326,9 @@ const reloadApp = ({ hot, liveReload }, currentStatus) => { const ansiRegex = new RegExp( [ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", - "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", + "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))" ].join("|"), - "g", + "g" ); /** @@ -340,7 +340,7 @@ const ansiRegex = new RegExp( * @param {string} string * @return {string} */ -const stripAnsi = (string) => { +const stripAnsi = string => { if (typeof string !== "string") { throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``); } @@ -419,7 +419,7 @@ const onSocketMessage = { log.info( `${data.pluginName ? `[${data.pluginName}] ` : ""}${data.percent}% - ${ data.msg - }.`, + }.` ); } @@ -463,7 +463,7 @@ const onSocketMessage = { log.info( `${ file ? `"${file}"` : "Content" - } from static directory was changed. Reloading...`, + } from static directory was changed. Reloading...` ); self.location.reload(); @@ -475,7 +475,7 @@ const onSocketMessage = { warnings(warnings, params) { log.warn("Warnings while compiling."); - const printableWarnings = warnings.map((error) => { + const printableWarnings = warnings.map(error => { const { header, body } = formatProblem("warning", error); return `${header}\n${stripAnsi(body)}`; @@ -502,7 +502,7 @@ const onSocketMessage = { overlay.send({ type: "BUILD_ERROR", level: "warning", - messages: warnings, + messages: warnings }); } } @@ -519,7 +519,7 @@ const onSocketMessage = { errors(errors) { log.error("Errors while compiling. Reload prevented."); - const printableErrors = errors.map((error) => { + const printableErrors = errors.map(error => { const { header, body } = formatProblem("error", error); return `${header}\n${stripAnsi(body)}`; @@ -546,7 +546,7 @@ const onSocketMessage = { overlay.send({ type: "BUILD_ERROR", level: "error", - messages: errors, + messages: errors }); } } @@ -565,14 +565,14 @@ const onSocketMessage = { } sendMessage("Close"); - }, + } }; /** * @param {{ protocol?: string, auth?: string, hostname?: string, port?: string, pathname?: string, search?: string, hash?: string, slashes?: boolean }} objURL * @returns {string} */ -const formatURL = (objURL) => { +const formatURL = objURL => { let protocol = objURL.protocol || ""; if (protocol && protocol.substr(-1) !== ":") { @@ -631,7 +631,7 @@ const formatURL = (objURL) => { * @param {string} match * @returns {string} */ - (match) => encodeURIComponent(match), + match => encodeURIComponent(match) ); search = search.replace("#", "%23"); @@ -642,7 +642,7 @@ const formatURL = (objURL) => { * @param {URL & { fromCurrentScript?: boolean }} parsedURL * @returns {string} */ -const createSocketURL = (parsedURL) => { +const createSocketURL = parsedURL => { let { hostname } = parsedURL; // Node.js module parses it as `::` @@ -673,7 +673,7 @@ const createSocketURL = (parsedURL) => { socketURLProtocol = socketURLProtocol.replace( /^(?:http|.+-extension|file)/i, - "ws", + "ws" ); let socketURLAuth = ""; @@ -726,7 +726,7 @@ const createSocketURL = (parsedURL) => { hostname: socketURLHostname, port: socketURLPort, pathname: socketURLPathname, - slashes: true, + slashes: true }); }; diff --git a/client-src/utils/ansiHTML.ts b/client-src/utils/ansiHTML.ts index 0da9ff2..52094c0 100644 --- a/client-src/utils/ansiHTML.ts +++ b/client-src/utils/ansiHTML.ts @@ -34,7 +34,7 @@ const _defColors: Record> = { magenta: "ff00ff", cyan: "00ffee", lightgrey: "f0f0f0", - darkgrey: "888", + darkgrey: "888" }; const _styles: Record = { 30: "black", @@ -44,11 +44,11 @@ const _styles: Record = { 34: "blue", 35: "magenta", 36: "cyan", - 37: "lightgrey", + 37: "lightgrey" }; const _colorMode: Record = { - 2: "rgb", + 2: "rgb" }; const _openTags: Record Option)> = { @@ -79,20 +79,20 @@ const _openTags: Record Option)> = { match.advance(4); return `background-color: rgb(${r},${g},${b})`; } - }, + } }; const _openTagToCloseTag: Record = { 3: "23", 4: "24", - 9: "29", + 9: "29" }; const _closeTags: Record< string, string | ((ansiCodes: Option>) => string) > = { - 0: (ansiCodes) => { + 0: ansiCodes => { if (!ansiCodes) return ""; if (!ansiCodes.length) return ""; let code: Option; @@ -109,7 +109,7 @@ const _closeTags: Record< }, 23: "", // reset italic 24: "", // reset underscore - 29: "", // reset delete + 29: "" // reset delete }; for (const n of [21, 22, 27, 28, 39, 49]) { @@ -140,60 +140,56 @@ export default function ansiHTML(text: string) { const ansiCodes: string[] = []; // Replace with markup. //@ts-ignore TS1487 error - let ret = text.replace( - /\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, - (m) => { - const match = m.match(/(;?\d+)/g)?.map(normalizeSeq) as unknown as Match; - Object.defineProperty(match, "advance", { - value: function (count: number) { - this.splice(0, count); - }, - }); - let rep = ""; - let seq: string; - while ((seq = match[0])) { - match.advance(1); - rep += applySeq(seq); + let ret = text.replace(/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g, m => { + const match = m.match(/(;?\d+)/g)?.map(normalizeSeq) as unknown as Match; + Object.defineProperty(match, "advance", { + value: function (count: number) { + this.splice(0, count); } - return rep; - - function applySeq(seq: string) { - let other = _openTags[seq]; - if ( - other && - (other = - typeof other === "function" ? (other(match) as string) : other) - ) { - // If reset signal is encountered, we have to reset everything. - let ret = ""; - if (seq === "0") { - ret += ( - _closeTags[seq] as (ansiCodes: Option>) => string - )(ansiCodes); - } - // If current sequence has been opened, close it. - if (ansiCodes.indexOf(seq) !== -1) { - ansiCodes.pop(); - return ""; - } - // Open tag. - ansiCodes.push(seq); - return ret + (other[0] === "<" ? other : ``); - } + }); + let rep = ""; + let seq: string; + while ((seq = match[0])) { + match.advance(1); + rep += applySeq(seq); + } + return rep; - const ct = _closeTags[seq]; - if (typeof ct === "function") { - return ct(ansiCodes); + function applySeq(seq: string) { + let other = _openTags[seq]; + if ( + other && + (other = typeof other === "function" ? (other(match) as string) : other) + ) { + // If reset signal is encountered, we have to reset everything. + let ret = ""; + if (seq === "0") { + ret += ( + _closeTags[seq] as (ansiCodes: Option>) => string + )(ansiCodes); } - if (ct) { - // Pop sequence + // If current sequence has been opened, close it. + if (ansiCodes.indexOf(seq) !== -1) { ansiCodes.pop(); - return ct; + return ""; } - return ""; + // Open tag. + ansiCodes.push(seq); + return ret + (other[0] === "<" ? other : ``); + } + + const ct = _closeTags[seq]; + if (typeof ct === "function") { + return ct(ansiCodes); } - }, - ); + if (ct) { + // Pop sequence + ansiCodes.pop(); + return ct; + } + return ""; + } + }); // Make sure tags are closed. const l = ansiCodes.length; @@ -225,10 +221,10 @@ ansiHTML.setColors = (colors: typeof _defColors) => { if ( !Array.isArray(hex) || hex.length === 0 || - hex.some((h) => typeof h !== "string") + hex.some(h => typeof h !== "string") ) { throw new Error( - `The value of \`${key}\` property must be an Array and each item could only be a hex string, e.g.: FF0000`, + `The value of \`${key}\` property must be an Array and each item could only be a hex string, e.g.: FF0000` ); } const defHexColor = _defColors[key]; @@ -243,7 +239,7 @@ ansiHTML.setColors = (colors: typeof _defColors) => { hex = hex.slice(0, 2); } else if (typeof hex !== "string") { throw new Error( - `The value of \`${key}\` property must be a hex string, e.g.: FF0000`, + `The value of \`${key}\` property must be a hex string, e.g.: FF0000` ); } _finalColors[key] = hex; @@ -266,10 +262,10 @@ ansiHTML.tags = {} as AnsiHtmlTags; if (Object.defineProperty) { Object.defineProperty(ansiHTML.tags, "open", { - get: () => _openTags, + get: () => _openTags }); Object.defineProperty(ansiHTML.tags, "close", { - get: () => _closeTags, + get: () => _closeTags }); } else { ansiHTML.tags.open = _openTags; diff --git a/package.json b/package.json index bf72ec0..206cfb3 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dev": "tsc -b -w", "lint": "biome check .", "lint:write": "biome check . --write", - "format": "node ./node_modules/prettier/bin/prettier.cjs \"packages/**/src/**/*.{ts,tsx,js}\" \"crates/rspack_plugin_runtime/**/*.{ts,js}\" \"x.mjs\" --check", + "format": "prettier --write .", "test:install": "cross-env ./node_modules/.bin/puppeteer browsers install chrome", "test": "pnpm run test:install && pnpm run build && cross-env NO_COLOR=1 node --expose-gc --max-old-space-size=8192 --experimental-vm-modules ./node_modules/jest-cli/bin/jest --colors", "release": "node ./scripts/release.mjs" @@ -37,10 +37,7 @@ "biome check --write --no-errors-on-unmatched" ] }, - "files": [ - "dist", - "client" - ], + "files": ["dist", "client"], "engines": { "node": ">= 18.12.0" }, diff --git a/tests/fixtures/multi-compiler-two-configurations/one.js b/tests/fixtures/multi-compiler-two-configurations/one.js index 0f5ee7b..5765483 100644 --- a/tests/fixtures/multi-compiler-two-configurations/one.js +++ b/tests/fixtures/multi-compiler-two-configurations/one.js @@ -2,4 +2,4 @@ console.log("one"); // comment -// comment \ No newline at end of file +// comment diff --git a/tests/fixtures/worker-config-dev-server-false/index.js b/tests/fixtures/worker-config-dev-server-false/index.js index f78ab4a..a3ca188 100644 --- a/tests/fixtures/worker-config-dev-server-false/index.js +++ b/tests/fixtures/worker-config-dev-server-false/index.js @@ -1,6 +1,6 @@ const myWorker = new Worker("./worker-bundle.js"); -myWorker.onmessage = (event) => { +myWorker.onmessage = event => { console.log(`Worker said: ${event.data}`); }; diff --git a/tests/fixtures/worker-config-dev-server-false/public/worker-bundle.js b/tests/fixtures/worker-config-dev-server-false/public/worker-bundle.js index a39e1a9..8c804e8 100644 --- a/tests/fixtures/worker-config-dev-server-false/public/worker-bundle.js +++ b/tests/fixtures/worker-config-dev-server-false/public/worker-bundle.js @@ -1,13 +1,12 @@ -(() => { // webpackBootstrap +(() => { + // webpackBootstrap -/*!*******************!*\ + /*!*******************!*\ !*** ./worker.js ***! \*******************/ -postMessage("I'm working before postMessage"); + postMessage("I'm working before postMessage"); -onmessage = (event) => { - postMessage(`Message sent: ${event.data}`); -}; - -})() -; \ No newline at end of file + onmessage = event => { + postMessage(`Message sent: ${event.data}`); + }; +})(); diff --git a/tests/fixtures/worker-config-dev-server-false/webpack.config.js b/tests/fixtures/worker-config-dev-server-false/webpack.config.js index 960f599..21cd4c3 100644 --- a/tests/fixtures/worker-config-dev-server-false/webpack.config.js +++ b/tests/fixtures/worker-config-dev-server-false/webpack.config.js @@ -12,13 +12,13 @@ module.exports = [ context: __dirname, stats: "none", output: { - path: path.resolve(__dirname, "./dist/"), + path: path.resolve(__dirname, "./dist/") }, infrastructureLogging: { level: "info", stream: { - write: () => {}, - }, + write: () => {} + } }, plugins: [new HTMLGeneratorPlugin()], experiments: { @@ -39,13 +39,13 @@ module.exports = [ stats: "none", output: { path: path.resolve(__dirname, "public"), - filename: "worker-bundle.js", + filename: "worker-bundle.js" }, infrastructureLogging: { level: "info", stream: { - write: () => {}, - }, + write: () => {} + } }, devServer: false, experiments: { @@ -55,5 +55,5 @@ module.exports = [ } } } - }, + } ]; diff --git a/tests/fixtures/worker-config-dev-server-false/worker.js b/tests/fixtures/worker-config-dev-server-false/worker.js index ae6802f..9c632d7 100644 --- a/tests/fixtures/worker-config-dev-server-false/worker.js +++ b/tests/fixtures/worker-config-dev-server-false/worker.js @@ -1,5 +1,5 @@ postMessage("I'm working before postMessage"); -onmessage = (event) => { +onmessage = event => { postMessage(`Message sent: ${event.data}`); }; diff --git a/tests/fixtures/worker-config/index.js b/tests/fixtures/worker-config/index.js index 0008271..3963f91 100644 --- a/tests/fixtures/worker-config/index.js +++ b/tests/fixtures/worker-config/index.js @@ -1,6 +1,6 @@ const myWorker = new Worker("./worker.js"); -myWorker.onmessage = (event) => { +myWorker.onmessage = event => { console.log(`Worker said: ${event.data}`); }; diff --git a/tests/fixtures/worker-config/webpack.config.js b/tests/fixtures/worker-config/webpack.config.js index 7377b8f..d6ca350 100644 --- a/tests/fixtures/worker-config/webpack.config.js +++ b/tests/fixtures/worker-config/webpack.config.js @@ -11,15 +11,15 @@ module.exports = [ context: __dirname, stats: "none", output: { - path: "/", + path: "/" }, infrastructureLogging: { level: "info", stream: { - write: () => {}, - }, + write: () => {} + } }, - plugins: [new HTMLGeneratorPlugin()], + plugins: [new HTMLGeneratorPlugin()] }, { name: "worker", @@ -31,13 +31,13 @@ module.exports = [ stats: "none", output: { path: "/", - filename: "worker.js", + filename: "worker.js" }, infrastructureLogging: { level: "info", stream: { - write: () => {}, - }, - }, - }, + write: () => {} + } + } + } ]; diff --git a/tests/fixtures/worker-config/worker.js b/tests/fixtures/worker-config/worker.js index ae6802f..9c632d7 100644 --- a/tests/fixtures/worker-config/worker.js +++ b/tests/fixtures/worker-config/worker.js @@ -1,5 +1,5 @@ postMessage("I'm working before postMessage"); -onmessage = (event) => { +onmessage = event => { postMessage(`Message sent: ${event.data}`); }; diff --git a/tests/tsconfig.json b/tests/tsconfig.json index c4e73fb..09037e0 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -1,10 +1,10 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "allowJs": true, - "checkJs": false, - "rootDir": "../" - }, - "include": ["../src", "../tests", "../client-src"], - "references": [] + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "rootDir": "../" + }, + "include": ["../src", "../tests", "../client-src"], + "references": [] } diff --git a/tsconfig.build.json b/tsconfig.build.json index 73db71e..7973b10 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,7 +1,7 @@ { - "extends": "./tsconfig.json", - "compilerOptions": { - "sourceMap": false, - "declarationMap": false - } + "extends": "./tsconfig.json", + "compilerOptions": { + "sourceMap": false, + "declarationMap": false + } } diff --git a/tsconfig.client.json b/tsconfig.client.json index 54d2e8b..48a2109 100644 --- a/tsconfig.client.json +++ b/tsconfig.client.json @@ -1,14 +1,14 @@ { - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "ES2020", - "target": "ES5", - "outDir": "client", - "rootDir": "client-src", - "composite": false, - "sourceMap": false, - "declarationMap": false, - "declaration": false - }, - "include": ["client-src"] + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ES2020", + "target": "ES5", + "outDir": "client", + "rootDir": "client-src", + "composite": false, + "sourceMap": false, + "declarationMap": false, + "declaration": false + }, + "include": ["client-src"] } diff --git a/tsconfig.json b/tsconfig.json index 0568d2f..e0e61d1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,25 @@ { - "compilerOptions": { - "module": "NodeNext", - "moduleResolution": "NodeNext", - "target": "ES2021", - "esModuleInterop": true, - "declaration": true, - "isolatedModules": true, - "sourceMap": true, - "declarationMap": true, - "composite": true, - "forceConsistentCasingInFileNames": true, - "allowJs": true, - "checkJs": true, - "strict": true, - "skipLibCheck": true, - "noUnusedLocals": true, - "outDir": "dist", - "rootDir": "src" - }, - "ts-node": { - "transpileOnly": true - }, - "include": ["src"] + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "ES2021", + "esModuleInterop": true, + "declaration": true, + "isolatedModules": true, + "sourceMap": true, + "declarationMap": true, + "composite": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "checkJs": true, + "strict": true, + "skipLibCheck": true, + "noUnusedLocals": true, + "outDir": "dist", + "rootDir": "src" + }, + "ts-node": { + "transpileOnly": true + }, + "include": ["src"] } From 9afe09da8e136617fd9f93cf035b310ad8f82082 Mon Sep 17 00:00:00 2001 From: pshu Date: Tue, 25 Nov 2025 17:09:04 +0800 Subject: [PATCH 2/2] feat: inject __rspack_dev_server_uri__ define after dev server initialization --- package.json | 2 +- pnpm-lock.yaml | 179 ++++++++++++++++++++++++------------------------- src/server.ts | 20 +++++- 3 files changed, 109 insertions(+), 92 deletions(-) diff --git a/package.json b/package.json index ee3f7f1..2fe5e4f 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@biomejs/biome": "^1.8.3", "@jest/reporters": "29.7.0", "@jest/test-sequencer": "^29.7.0", - "@rspack/core": "npm:@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256", + "@rspack/core": "1.6.4", "@rspack/plugin-react-refresh": "1.0.0", "@types/express": "4.17.21", "@types/jest": "29.5.12", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a6c665..73ee8f4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,8 +37,8 @@ importers: specifier: ^29.7.0 version: 29.7.0 '@rspack/core': - specifier: npm:@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256 - version: '@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256' + specifier: 1.6.4 + version: 1.6.4 '@rspack/plugin-react-refresh': specifier: 1.0.0 version: 1.0.0(react-refresh@0.14.0) @@ -62,7 +62,7 @@ importers: version: 7.0.3 css-loader: specifier: ^7.1.2 - version: 7.1.2(@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256)(webpack@5.94.0) + version: 7.1.2(@rspack/core@1.6.4)(webpack@5.94.0) execa: specifier: 9.3.0 version: 9.3.0 @@ -501,96 +501,95 @@ packages: '@leichtgewicht/ip-codec@2.0.5': resolution: {integrity: sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==} - '@module-federation/error-codes@0.15.0': - resolution: {integrity: sha512-CFJSF+XKwTcy0PFZ2l/fSUpR4z247+Uwzp1sXVkdIfJ/ATsnqf0Q01f51qqSEA6MYdQi6FKos9FIcu3dCpQNdg==} + '@module-federation/error-codes@0.21.4': + resolution: {integrity: sha512-ClpL5MereWNXh+EgDjz7w4RrC1JlisQTvXDa1gLxpviHafzNDfdViVmuhi9xXVuj+EYo8KU70Y999KHhk9424Q==} - '@module-federation/runtime-core@0.15.0': - resolution: {integrity: sha512-RYzI61fRDrhyhaEOXH3AgIGlHiot0wPFXu7F43cr+ZnTi+VlSYWLdlZ4NBuT9uV6JSmH54/c+tEZm5SXgKR2sQ==} + '@module-federation/runtime-core@0.21.4': + resolution: {integrity: sha512-SGpmoOLGNxZofpTOk6Lxb2ewaoz5wMi93AFYuuJB04HTVcngEK+baNeUZ2D/xewrqNIJoMY6f5maUjVfIIBPUA==} - '@module-federation/runtime-tools@0.15.0': - resolution: {integrity: sha512-kzFn3ObUeBp5vaEtN1WMxhTYBuYEErxugu1RzFUERD21X3BZ+b4cWwdFJuBDlsmVjctIg/QSOoZoPXRKAO0foA==} + '@module-federation/runtime-tools@0.21.4': + resolution: {integrity: sha512-RzFKaL0DIjSmkn76KZRfzfB6dD07cvID84950jlNQgdyoQFUGkqD80L6rIpVCJTY/R7LzR3aQjHnoqmq4JPo3w==} - '@module-federation/runtime@0.15.0': - resolution: {integrity: sha512-dTPsCNum9Bhu3yPOcrPYq0YnM9eCMMMNB1wuiqf1+sFbQlNApF0vfZxooqz3ln0/MpgE0jerVvFsLVGfqvC9Ug==} + '@module-federation/runtime@0.21.4': + resolution: {integrity: sha512-wgvGqryurVEvkicufJmTG0ZehynCeNLklv8kIk5BLIsWYSddZAE+xe4xov1kgH5fIJQAoQNkRauFFjVNlHoAkA==} - '@module-federation/sdk@0.15.0': - resolution: {integrity: sha512-PWiYbGcJrKUD6JZiEPihrXhV3bgXdll4bV7rU+opV7tHaun+Z0CdcawjZ82Xnpb8MCPGmqHwa1MPFeUs66zksw==} + '@module-federation/sdk@0.21.4': + resolution: {integrity: sha512-tzvhOh/oAfX++6zCDDxuvioHY4Jurf8vcfoCbKFxusjmyKr32GPbwFDazUP+OPhYCc3dvaa9oWU6X/qpUBLfJw==} - '@module-federation/webpack-bundler-runtime@0.15.0': - resolution: {integrity: sha512-i+3wu2Ljh2TmuUpsnjwZVupOVqV50jP0ndA8PSP4gwMKlgdGeaZ4VH5KkHAXGr2eiYUxYLMrJXz1+eILJqeGDg==} + '@module-federation/webpack-bundler-runtime@0.21.4': + resolution: {integrity: sha512-dusmR3uPnQh9u9ChQo3M+GLOuGFthfvnh7WitF/a1eoeTfRmXqnMFsXtZCUK+f/uXf+64874Zj/bhAgbBcVHZA==} - '@napi-rs/wasm-runtime@0.2.12': - resolution: {integrity: sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ==} + '@napi-rs/wasm-runtime@1.0.7': + resolution: {integrity: sha512-SeDnOO0Tk7Okiq6DbXmmBODgOAb9dp9gjlphokTUxmt8U3liIP1ZsozBahH69j/RJv+Rfs6IwUKHTgQYJ/HBAw==} '@puppeteer/browsers@2.4.0': resolution: {integrity: sha512-x8J1csfIygOwf6D6qUAZ0ASk3z63zPb7wkNeHRerCMh82qWKUrOgkuP005AJC8lDL6/evtXETGEJVcwykKT4/g==} engines: {node: '>=18'} hasBin: true - '@rspack-canary/binding-darwin-arm64@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-x8CAVBOeunQBftEwOOHJSVRTUXlfK9jQCaJS7inNE47G7SaVFtFAOGw6DBTTUplmX8eJ+QapVBaPVg95gYELQg==} + '@rspack/binding-darwin-arm64@1.6.4': + resolution: {integrity: sha512-qD2C5xwdY2qKEXTZiPJQx1L1kELapOc0AaZDqcAyzXs30d1qTKpx6PdyW3HN+gueKovyWZwMMYfz6RxcMCnaDQ==} cpu: [arm64] os: [darwin] - '@rspack-canary/binding-darwin-x64@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-kZsoki8s+6s1KGp7qhjLeqfI1toolqfhXCfNGV5V2Gyw8bFCUpwcfXvfoR4DFgVdqhLj6Fd10BBbfbM6kNILtw==} + '@rspack/binding-darwin-x64@1.6.4': + resolution: {integrity: sha512-IHceyLDxeubqIrGz4gUqJavnygTij4vtDDE2Fkgobz7hkTJwGtD5mxBKbVNRqGvhrasVw0h9rEjR7tdbDSiUhQ==} cpu: [x64] os: [darwin] - '@rspack-canary/binding-linux-arm64-gnu@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-fn88EEKfJrC94e4Zi57prT53NSPey+hTe6ZI9mFlm9pkGXgWAvMdzxy/sc061ct88yn0oezfFEzuNHtby0HeuA==} + '@rspack/binding-linux-arm64-gnu@1.6.4': + resolution: {integrity: sha512-Ldpoz2wWnBaL2+XKLIOyCZMkAkd4pk/L24EVgma3SpRtwgenLEr10bQupvwGAK5OLkjayslOTZmRiAv0FH5o/w==} cpu: [arm64] os: [linux] - '@rspack-canary/binding-linux-arm64-musl@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-0285DQ2fRf3cZlGKVRA8Ab4Y9t6bhPZnJPxo3oDrKddxNPOLVzrXBAZDlb4uwHFIcQd11OrgecNvNcCKI0zL9Q==} + '@rspack/binding-linux-arm64-musl@1.6.4': + resolution: {integrity: sha512-3fLMSDK5yMjKmx7iFbYG3P3A0xNdtmNu09v5P6hzq65tkJ3dflIt3p8DvtOTURtuSgQZV2A1LDd9hpIXdnigqA==} cpu: [arm64] os: [linux] - '@rspack-canary/binding-linux-x64-gnu@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-Ls8Yhe2ZS79OxDaK3bn2i2QF6nZKCRxpAy6XB7lbD0dDG2JW9/ON+iKpltwinTtwIO2d7K2qKJwubDzqTYnQIA==} + '@rspack/binding-linux-x64-gnu@1.6.4': + resolution: {integrity: sha512-5YzXUKLnaiqND05CDgkKE0WNRtC1ulkVncYs78xPikonzZmgVXa8eRaTPOZC6ZjpLR0eTsg+MSesLUsPUu27hA==} cpu: [x64] os: [linux] - '@rspack-canary/binding-linux-x64-musl@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-svXr4ryHICO9F7K5+muG3r5ErjnceiyhgBjbP0pVg2uftATuJBeBLsoB4FDrTtM4TWI78leB9VNmQyKF3FsSVg==} + '@rspack/binding-linux-x64-musl@1.6.4': + resolution: {integrity: sha512-KcSFla8a9bXG1mmV5oQ1R5h/dSXfd41/qHOsNuLqho2UCX8CVh4dezUA153dj7p1S4yOhTy6VZZi6C1szweE9A==} cpu: [x64] os: [linux] - '@rspack-canary/binding-wasm32-wasi@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-quXMvknMtfnsblnocDNDYK/HNmUQq22CYjqQSRKiUFnIxTbTwsXu1vGs/186PXTQUQZctFNSJnoKbRSt3SN1TQ==} + '@rspack/binding-wasm32-wasi@1.6.4': + resolution: {integrity: sha512-mfFJbDJkRy5I1iW3m0JlWbc0X8pjVd+GRUz5nhbccwEhSQOc27ao3evf7XPU4aaDxud1B3UEqYiRcRmtm1BrjA==} cpu: [wasm32] - '@rspack-canary/binding-win32-arm64-msvc@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-SI0WhzKK2gjvBBBQFCX3RSNLw/UWo7MKyqKir/bFfxiv/DksIPEbXB2IZ8bjd6vtYTcg3ZprCqcuJdnLARvQ/A==} + '@rspack/binding-win32-arm64-msvc@1.6.4': + resolution: {integrity: sha512-QtIqxsfeTSS1lwfaPGrPFfJ9ir/3aWZv5t3iAgYj/CNUA8MTKWt4vQKcco7NRIGK4ZLMI+dgJBFtvd/lUDMQsw==} cpu: [arm64] os: [win32] - '@rspack-canary/binding-win32-ia32-msvc@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-Zci5Oo3A+Go5O2QIXBzypwokEtBTyQaoLvqppCl4olcD/a63+vGiKCh/GWYBxLIcYiqFyLWJyEG1IgeRwYJGDg==} + '@rspack/binding-win32-ia32-msvc@1.6.4': + resolution: {integrity: sha512-HXEWGDllgh0jFwjGhkGcLqb0dzXbc/rA8vQr2JcSdC41p1DTzLgO215jWdKSIvzCzhyPh3VeQkXk76hjFB2cLQ==} cpu: [ia32] os: [win32] - '@rspack-canary/binding-win32-x64-msvc@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-FPrOiNyfoLJRfOn/7NeHO2Be7451+dVbJwFIYYLjWgGtZZBvWKY3/EQDlm/YDkSo1wzMKfu8XLee8jjHKhYF5A==} + '@rspack/binding-win32-x64-msvc@1.6.4': + resolution: {integrity: sha512-MAO5rOnGYoeuT2LPn/P7JVJCi3d78XoXgOq3tkGh6qXhvhkjsBRtYluWCzACXQpXfFHEWYd7uT5yHoZgxiVuoA==} cpu: [x64] os: [win32] - '@rspack-canary/binding@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-cwJ5WjPmQQ+quuA4wYkIPTAEOt7VeRZP7x2sgxJDjLRyooC1OJtS00XFqNWjLAerrE0jskFWFKV4rgIeKymw8Q==} + '@rspack/binding@1.6.4': + resolution: {integrity: sha512-vUxc/zUdsCuyysOvP4CTdIYxsZPb2jIXST5vrLABiTPIaHpXZ0hVdgKif2XPJwJeuCVS6w25xvyPN0mBCU0MvQ==} - '@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256': - resolution: {integrity: sha512-ge9y0DyVi8IW3AkKKlS8BeFy9Xq1Sbftt632RIM/7ExVwuBTZg/w5y9Uf1RbiWpWfNjMZnnxZSOFI3VXmF6UOQ==} - engines: {node: '>=16.0.0'} + '@rspack/core@1.6.4': + resolution: {integrity: sha512-5F1+MQD8rfbFbUHnaiZe4jqOu9pnSb+PliqQvi0lj+uvpMpcS3sJDIs/mz6P1u87lfkfBXChIT4zSLAzeOgMWw==} + engines: {node: '>=18.12.0'} peerDependencies: '@swc/helpers': '>=0.5.1' peerDependenciesMeta: '@swc/helpers': optional: true - '@rspack/lite-tapable@1.0.1': - resolution: {integrity: sha512-VynGOEsVw2s8TAlLf/uESfrgfrq2+rcXB1muPJYBWbsm1Oa6r5qVQhjA5ggM6z/coYPrsVMgovl3Ff7Q7OCp1w==} - engines: {node: '>=16.0.0'} + '@rspack/lite-tapable@1.1.0': + resolution: {integrity: sha512-E2B0JhYFmVAwdDiG14+DW0Di4Ze4Jg10Pc4/lILUrd5DRCaklduz2OvJ5HYQ6G+hd+WTzqQb3QnDNfK4yvAFYw==} '@rspack/plugin-react-refresh@1.0.0': resolution: {integrity: sha512-WvXkLewW5G0Mlo5H1b251yDh5FFiH4NDAbYlFpvFjcuXX2AchZRf9zdw57BDE/ADyWsJgA8kixN/zZWBTN3iYA==} @@ -3387,32 +3386,32 @@ snapshots: '@leichtgewicht/ip-codec@2.0.5': {} - '@module-federation/error-codes@0.15.0': {} + '@module-federation/error-codes@0.21.4': {} - '@module-federation/runtime-core@0.15.0': + '@module-federation/runtime-core@0.21.4': dependencies: - '@module-federation/error-codes': 0.15.0 - '@module-federation/sdk': 0.15.0 + '@module-federation/error-codes': 0.21.4 + '@module-federation/sdk': 0.21.4 - '@module-federation/runtime-tools@0.15.0': + '@module-federation/runtime-tools@0.21.4': dependencies: - '@module-federation/runtime': 0.15.0 - '@module-federation/webpack-bundler-runtime': 0.15.0 + '@module-federation/runtime': 0.21.4 + '@module-federation/webpack-bundler-runtime': 0.21.4 - '@module-federation/runtime@0.15.0': + '@module-federation/runtime@0.21.4': dependencies: - '@module-federation/error-codes': 0.15.0 - '@module-federation/runtime-core': 0.15.0 - '@module-federation/sdk': 0.15.0 + '@module-federation/error-codes': 0.21.4 + '@module-federation/runtime-core': 0.21.4 + '@module-federation/sdk': 0.21.4 - '@module-federation/sdk@0.15.0': {} + '@module-federation/sdk@0.21.4': {} - '@module-federation/webpack-bundler-runtime@0.15.0': + '@module-federation/webpack-bundler-runtime@0.21.4': dependencies: - '@module-federation/runtime': 0.15.0 - '@module-federation/sdk': 0.15.0 + '@module-federation/runtime': 0.21.4 + '@module-federation/sdk': 0.21.4 - '@napi-rs/wasm-runtime@0.2.12': + '@napi-rs/wasm-runtime@1.0.7': dependencies: '@emnapi/core': 1.6.0 '@emnapi/runtime': 1.6.0 @@ -3432,58 +3431,58 @@ snapshots: transitivePeerDependencies: - supports-color - '@rspack-canary/binding-darwin-arm64@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-darwin-arm64@1.6.4': optional: true - '@rspack-canary/binding-darwin-x64@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-darwin-x64@1.6.4': optional: true - '@rspack-canary/binding-linux-arm64-gnu@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-linux-arm64-gnu@1.6.4': optional: true - '@rspack-canary/binding-linux-arm64-musl@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-linux-arm64-musl@1.6.4': optional: true - '@rspack-canary/binding-linux-x64-gnu@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-linux-x64-gnu@1.6.4': optional: true - '@rspack-canary/binding-linux-x64-musl@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-linux-x64-musl@1.6.4': optional: true - '@rspack-canary/binding-wasm32-wasi@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-wasm32-wasi@1.6.4': dependencies: - '@napi-rs/wasm-runtime': 0.2.12 + '@napi-rs/wasm-runtime': 1.0.7 optional: true - '@rspack-canary/binding-win32-arm64-msvc@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-win32-arm64-msvc@1.6.4': optional: true - '@rspack-canary/binding-win32-ia32-msvc@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-win32-ia32-msvc@1.6.4': optional: true - '@rspack-canary/binding-win32-x64-msvc@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding-win32-x64-msvc@1.6.4': optional: true - '@rspack-canary/binding@1.4.3-canary-98b815e4-20250703091256': + '@rspack/binding@1.6.4': optionalDependencies: - '@rspack/binding-darwin-arm64': '@rspack-canary/binding-darwin-arm64@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-darwin-x64': '@rspack-canary/binding-darwin-x64@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-linux-arm64-gnu': '@rspack-canary/binding-linux-arm64-gnu@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-linux-arm64-musl': '@rspack-canary/binding-linux-arm64-musl@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-linux-x64-gnu': '@rspack-canary/binding-linux-x64-gnu@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-linux-x64-musl': '@rspack-canary/binding-linux-x64-musl@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-wasm32-wasi': '@rspack-canary/binding-wasm32-wasi@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-win32-arm64-msvc': '@rspack-canary/binding-win32-arm64-msvc@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-win32-ia32-msvc': '@rspack-canary/binding-win32-ia32-msvc@1.4.3-canary-98b815e4-20250703091256' - '@rspack/binding-win32-x64-msvc': '@rspack-canary/binding-win32-x64-msvc@1.4.3-canary-98b815e4-20250703091256' + '@rspack/binding-darwin-arm64': 1.6.4 + '@rspack/binding-darwin-x64': 1.6.4 + '@rspack/binding-linux-arm64-gnu': 1.6.4 + '@rspack/binding-linux-arm64-musl': 1.6.4 + '@rspack/binding-linux-x64-gnu': 1.6.4 + '@rspack/binding-linux-x64-musl': 1.6.4 + '@rspack/binding-wasm32-wasi': 1.6.4 + '@rspack/binding-win32-arm64-msvc': 1.6.4 + '@rspack/binding-win32-ia32-msvc': 1.6.4 + '@rspack/binding-win32-x64-msvc': 1.6.4 - '@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256': + '@rspack/core@1.6.4': dependencies: - '@module-federation/runtime-tools': 0.15.0 - '@rspack/binding': '@rspack-canary/binding@1.4.3-canary-98b815e4-20250703091256' - '@rspack/lite-tapable': 1.0.1 + '@module-federation/runtime-tools': 0.21.4 + '@rspack/binding': 1.6.4 + '@rspack/lite-tapable': 1.1.0 - '@rspack/lite-tapable@1.0.1': {} + '@rspack/lite-tapable@1.1.0': {} '@rspack/plugin-react-refresh@1.0.0(react-refresh@0.14.0)': dependencies: @@ -4135,7 +4134,7 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 - css-loader@7.1.2(@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256)(webpack@5.94.0): + css-loader@7.1.2(@rspack/core@1.6.4)(webpack@5.94.0): dependencies: icss-utils: 5.1.0(postcss@8.4.47) postcss: 8.4.47 @@ -4146,7 +4145,7 @@ snapshots: postcss-value-parser: 4.2.0 semver: 7.6.3 optionalDependencies: - '@rspack/core': '@rspack-canary/core@1.4.3-canary-98b815e4-20250703091256' + '@rspack/core': 1.6.4 webpack: 5.94.0 cssesc@3.0.0: {} diff --git a/src/server.ts b/src/server.ts index e033b86..5cfc511 100644 --- a/src/server.ts +++ b/src/server.ts @@ -9,7 +9,7 @@ */ import type { Server } from "node:http"; import type { Socket } from "node:net"; -import { type Compiler, MultiCompiler } from "@rspack/core"; +import { type Compiler, DefinePlugin, MultiCompiler } from "@rspack/core"; import type { FSWatcher } from "chokidar"; import WebpackDevServer from "webpack-dev-server"; // @ts-ignore 'package.json' is not under 'rootDir' @@ -79,6 +79,8 @@ export class RspackDevServer extends WebpackDevServer { ? this.compiler.compilers : [this.compiler]; + const compilerForDev = compilers[0]; + for (const compiler of compilers) { const mode = compiler.options.mode || process.env.NODE_ENV; if (this.options.hot) { @@ -100,6 +102,22 @@ export class RspackDevServer extends WebpackDevServer { // @ts-expect-error await super.initialize(); + + // now we have the exact URI + this.defineDevServerUri(compilerForDev); + } + + defineDevServerUri(compiler: Compiler) { + new DefinePlugin({ + __rspack_dev_server_uri: JSON.stringify(this.getDevServerUri()) + }).apply(compiler); + } + + getDevServerUri() { + const protocol = this.options.server.type; + const hostname = this.options.host || "127.0.0.1"; + const port = this.options.port; + return `${protocol}://${hostname}:${port}`; } getClientEntry(): string {