Skip to content

Commit

Permalink
feat(dev-server): export package version (#7305)
Browse files Browse the repository at this point in the history
* chore: add type

* chore: lint

* chore: add comment

---------

Co-authored-by: SoonIter <sooniter@gmail.com>
  • Loading branch information
leimonio and SoonIter authored Aug 5, 2024
1 parent f44c966 commit 9347ecc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/rspack-dev-server/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export class RspackDevServer extends WebpackDevServer {
// (undocumented)
staticWatchers: FSWatcher[];
// (undocumented)
static version: string;
// (undocumented)
webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { type Compiler, MultiCompiler } from "@rspack/core";
import type { FSWatcher } from "chokidar";
import rdm from "webpack-dev-middleware";
import WebpackDevServer from "webpack-dev-server";
// @ts-ignore 'package.json' is not under 'rootDir'
import { version } from "../package.json";

import type { DevServer, ResolvedDevServer } from "./config";
import { applyDevServerPatch } from "./patch";
Expand All @@ -35,7 +37,10 @@ export class RspackDevServer extends WebpackDevServer {
// TODO: remove @ts-ignore here
/** @ts-ignore */
public compiler: Compiler | MultiCompiler;
webSocketServer: WebpackDevServer.WebSocketServerImplementation | undefined;
public webSocketServer:
| WebpackDevServer.WebSocketServerImplementation
| undefined;
static version: string = version;

constructor(options: DevServer, compiler: Compiler | MultiCompiler) {
super(options, compiler as any);
Expand Down
11 changes: 5 additions & 6 deletions packages/rspack-dev-server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"include": [
"src"
],
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
"rootDir": "src",
"resolveJsonModule": true
},
"include": ["src"]
}
4 changes: 2 additions & 2 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13340,7 +13340,7 @@ export interface RspackPluginInstance {
}

// @public (undocumented)
export const rspackVersion: any;
export const rspackVersion: string;

// @public
type Rule = RegExp | string;
Expand Down Expand Up @@ -14727,7 +14727,7 @@ export const util: {
};

// @public (undocumented)
export const version: any;
export const version: string;

// @public (undocumented)
interface Wasm {
Expand Down
13 changes: 11 additions & 2 deletions packages/rspack/src/exports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const { version: rspackVersion, webpackVersion } = require("../package.json");
export { rspackVersion, webpackVersion as version };
import {
version as _version,
webpackVersion as _webpackVersion
// @ts-ignore 'package.json' is not under 'rootDir'
} from "../package.json";

// this is a hack to be compatible with plugin which detect webpack's version
const rspackVersion = _version as string;
const version = _webpackVersion as string;

export { rspackVersion, version };

export type {
Asset,
Expand Down
9 changes: 2 additions & 7 deletions packages/rspack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
"json-parse-even-better-errors": [
"../compiled/json-parse-even-better-errors"
],
"webpack-sources": [
"../compiled/webpack-sources"
]
"webpack-sources": ["../compiled/webpack-sources"]
}
},
"include": ["src", "src/**/*.json"],
"exclude": [
"src/config/schema.check.js",
"src/container/default.runtime.js"
],
"exclude": ["src/config/schema.check.js", "src/container/default.runtime.js"],
"ts-node": {
"transpileOnly": true
},
Expand Down

2 comments on commit 9347ecc

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-08-05 b616f98) Current Change
10000_development-mode + exec 2.32 s ± 33 ms 2.32 s ± 29 ms -0.13 %
10000_development-mode_hmr + exec 703 ms ± 9.4 ms 702 ms ± 15 ms -0.20 %
10000_production-mode + exec 2.86 s ± 27 ms 2.85 s ± 27 ms -0.14 %
arco-pro_development-mode + exec 1.91 s ± 71 ms 1.9 s ± 72 ms -0.66 %
arco-pro_development-mode_hmr + exec 433 ms ± 3.7 ms 434 ms ± 2.9 ms +0.17 %
arco-pro_production-mode + exec 3.46 s ± 69 ms 3.44 s ± 92 ms -0.58 %
threejs_development-mode_10x + exec 1.7 s ± 20 ms 1.69 s ± 24 ms -0.63 %
threejs_development-mode_10x_hmr + exec 811 ms ± 8.4 ms 808 ms ± 14 ms -0.44 %
threejs_production-mode_10x + exec 5.52 s ± 28 ms 5.5 s ± 20 ms -0.38 %

Please sign in to comment.