Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/export-base-server.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a minor, but honestly, I’m not sure it’s necessary. What’s your use case?

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack-dev-server": patch
---

Export the documented `BaseServer` extension class and accept its constructors in the public `webSocketServer.type` declaration.
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function loadWebpackPeer() {

/**
* @typedef {object} WebSocketServerConfiguration
* @property {("ws" | string | (() => WebSocketServerConfiguration))=} type type
* @property {("ws" | string | typeof import("./servers/BaseServer.js").default)=} type type
* @property {Record<string, EXPECTED_ANY>=} options options
*/

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"default": "./lib/Server.js"
},
"./client/*": "./client/*",
"./lib/servers/BaseServer.js": {
"types": "./types/lib/servers/BaseServer.d.ts",
"import": "./lib/servers/BaseServer.js",
"require": "./dist/servers/BaseServer.js",
"default": "./lib/servers/BaseServer.js"
},
"./package.json": "./package.json"
},
"main": "./dist/Server.js",
Expand Down
15 changes: 8 additions & 7 deletions scripts/finalize-cjs-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import { fileURLToPath } from "node:url";
// files in `dist/` as CommonJS regardless of the package's root
// `"type": "module"`.
// 2. Babel emits the loader as `exports.default`. Append the `module.exports`
// unwrap so `require("webpack-dev-server")` returns the `Server` class
// directly (parity with the pre-ESM `module.exports = Server`), while
// `.default` keeps pointing at it for interop.
// unwrap so the public Server and BaseServer entrypoints return their
// classes directly, while `.default` keeps pointing at them for interop.

const CJS_DIR = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
Expand All @@ -27,7 +26,9 @@ await writeFile(
`${JSON.stringify({ type: "commonjs" }, null, 2)}\n`,
);

await appendFile(
path.join(CJS_DIR, "Server.js"),
"module.exports = exports.default;\nmodule.exports.default = exports.default;\n",
);
for (const entry of ["Server.js", "servers/BaseServer.js"]) {
await appendFile(
path.join(CJS_DIR, entry),
"module.exports = exports.default;\nmodule.exports.default = exports.default;\n",
);
}
4 changes: 3 additions & 1 deletion types/lib/Server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export type WebSocketServerConfiguration = {
/**
* type
*/
type?: ("ws" | string | (() => WebSocketServerConfiguration)) | undefined;
type?:
| ("ws" | string | typeof import("./servers/BaseServer.js").default)
| undefined;
/**
* options
*/
Expand Down