@rsbuild/core 0.2.14 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,7 +83,7 @@ async function init({
83
83
  }
84
84
  }
85
85
  function runCli() {
86
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.2.14");
86
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.2.15");
87
87
  import_commander.program.command("dev").option("--open [url]", "open the page in browser on startup").option(
88
88
  "--port <port>",
89
89
  "specify a port number for Rsbuild Server to listen"
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.2.14"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.2.15"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -31,39 +31,15 @@ const pluginEntry = () => ({
31
31
  const { preEntry } = config.source;
32
32
  const injectCoreJsEntry = config.output.polyfill === "entry" && !isServer && !isServiceWorker;
33
33
  Object.keys(entry).forEach((entryName) => {
34
- const entryImport = [];
35
- let entryDescription = null;
36
- const appendEntry = (item) => {
37
- if (typeof item === "string") {
38
- entryImport.push(item);
39
- return;
40
- }
41
- if (item.import) {
42
- entryImport.push(...(0, import_shared.castArray)(item.import));
43
- }
44
- if (entryDescription) {
45
- Object.assign(entryDescription, item);
46
- } else {
47
- entryDescription = item;
48
- }
34
+ const entryPoint = chain.entry(entryName);
35
+ const addEntry = (item) => {
36
+ entryPoint.add(item);
49
37
  };
50
- preEntry.forEach(appendEntry);
38
+ preEntry.forEach(addEntry);
51
39
  if (injectCoreJsEntry) {
52
- appendEntry((0, import_shared.createVirtualModule)('import "core-js";'));
40
+ addEntry((0, import_shared.createVirtualModule)('import "core-js";'));
53
41
  }
54
- (0, import_shared.castArray)(entry[entryName]).forEach(appendEntry);
55
- chain.entryPoints.set(entryName, {
56
- // @ts-expect-error EntryDescription type mismatch
57
- values() {
58
- if (entryDescription) {
59
- return {
60
- ...entryDescription,
61
- import: entryImport
62
- };
63
- }
64
- return entryImport;
65
- }
66
- });
42
+ (0, import_shared.castArray)(entry[entryName]).forEach(addEntry);
67
43
  });
68
44
  });
69
45
  api.onBeforeCreateCompiler(({ bundlerConfigs }) => {
@@ -59,7 +59,7 @@ function createContextByConfig(options, bundlerType, config = {}) {
59
59
  const context = {
60
60
  entry: config.source?.entry || getDefaultEntry(rootPath),
61
61
  targets: config.output?.targets || [],
62
- version: "0.2.14",
62
+ version: "0.2.15",
63
63
  rootPath,
64
64
  distPath,
65
65
  cachePath,
@@ -125,7 +125,7 @@ async function generateRspackConfig({
125
125
  HotModuleReplacementPlugin
126
126
  }
127
127
  });
128
- let rspackConfig = chain.toConfig();
128
+ let rspackConfig = (0, import_shared.chainToConfig)(chain);
129
129
  rspackConfig = await modifyRspackConfig(
130
130
  context,
131
131
  rspackConfig,
@@ -135,14 +135,21 @@ async function startDevServer(options, createDevMiddleware, {
135
135
  (0, import_shared.debug)("create dev server done");
136
136
  const protocol = https ? "https" : "http";
137
137
  let urls = (0, import_shared.getAddressUrls)(protocol, port, host);
138
- if (printURLs && devServerConfig.printUrls !== false) {
138
+ if (printURLs) {
139
139
  if ((0, import_shared.isFunction)(printURLs)) {
140
140
  urls = printURLs(urls);
141
141
  if (!Array.isArray(urls)) {
142
142
  throw new Error("Please return an array in the `printURLs` function.");
143
143
  }
144
144
  }
145
- (0, import_helper.printServerURLs)(urls, defaultRoutes, logger);
145
+ (0, import_helper.printServerURLs)({
146
+ urls,
147
+ port,
148
+ routes: defaultRoutes,
149
+ logger,
150
+ protocol,
151
+ printUrls: devServerConfig.printUrls
152
+ });
146
153
  }
147
154
  const compileMiddlewareAPI = await serverAPIs.startCompile();
148
155
  const devMiddlewares = await serverAPIs.getMiddlewares({
@@ -1,10 +1,17 @@
1
1
  /// <reference types="node" />
2
- import type { Logger, Routes, DevConfig, RsbuildEntry, RsbuildConfig, OutputStructure } from '@rsbuild/shared';
2
+ import type { Logger, Routes, DevConfig, PrintUrls, RsbuildEntry, RsbuildConfig, OutputStructure } from '@rsbuild/shared';
3
3
  export declare const formatRoutes: (entry: RsbuildEntry, prefix: string | undefined, outputStructure: OutputStructure | undefined) => Routes;
4
- export declare function printServerURLs(urls: Array<{
5
- url: string;
6
- label: string;
7
- }>, routes: Routes, logger?: Logger): void;
4
+ export declare function printServerURLs({ urls, port, routes, protocol, printUrls, logger, }: {
5
+ urls: Array<{
6
+ url: string;
7
+ label: string;
8
+ }>;
9
+ port: number;
10
+ routes: Routes;
11
+ logger?: Logger;
12
+ protocol: string;
13
+ printUrls?: PrintUrls;
14
+ }): void;
8
15
  /**
9
16
  * hmr socket connect path
10
17
  */
@@ -54,7 +61,7 @@ export declare const getDevOptions: ({ rsbuildConfig, getPortSilently, }: {
54
61
  historyApiFallback?: boolean | import("@rsbuild/shared").HistoryApiFallbackOptions | undefined;
55
62
  proxy?: import("@rsbuild/shared").ProxyOptions | undefined;
56
63
  strictPort?: boolean | undefined;
57
- printUrls?: boolean | undefined;
64
+ printUrls?: PrintUrls | undefined;
58
65
  };
59
66
  port: number;
60
67
  host: string;
@@ -34,7 +34,25 @@ const formatRoutes = (entry, prefix, outputStructure) => {
34
34
  (name === "index" && outputStructure !== "nested" ? "" : name)
35
35
  })).sort((a) => a.name === "index" ? -1 : 1);
36
36
  };
37
- function printServerURLs(urls, routes, logger = import_shared.logger) {
37
+ function printServerURLs({
38
+ urls,
39
+ port,
40
+ routes,
41
+ protocol,
42
+ printUrls,
43
+ logger = import_shared.logger
44
+ }) {
45
+ if (printUrls === false) {
46
+ return;
47
+ }
48
+ if ((0, import_shared.isFunction)(printUrls)) {
49
+ printUrls({
50
+ urls: urls.map((item) => item.url),
51
+ port,
52
+ protocol
53
+ });
54
+ return;
55
+ }
38
56
  let message = "";
39
57
  if (routes.length === 1) {
40
58
  message = urls.map(
@@ -153,13 +153,15 @@ async function startProdServer(context, rsbuildConfig, { printURLs = true, getPo
153
153
  port,
154
154
  routes
155
155
  });
156
- const urls = (0, import_shared.getAddressUrls)(https ? "https" : "http", port);
157
- if (printURLs && serverConfig.printUrls !== false) {
158
- (0, import_helper.printServerURLs)(
159
- (0, import_shared.isFunction)(printURLs) ? printURLs(urls) : urls,
160
- routes
161
- );
162
- }
156
+ const protocol = https ? "https" : "http";
157
+ const urls = (0, import_shared.getAddressUrls)(protocol, port);
158
+ (0, import_helper.printServerURLs)({
159
+ urls: (0, import_shared.isFunction)(printURLs) ? printURLs(urls) : urls,
160
+ port,
161
+ routes,
162
+ protocol,
163
+ printUrls: serverConfig.printUrls
164
+ });
163
165
  const onClose = () => {
164
166
  server.close();
165
167
  httpServer.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Unleash the power of Rspack with the out-of-the-box build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -60,7 +60,7 @@
60
60
  "core-js": "~3.32.2",
61
61
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
62
62
  "postcss": "8.4.31",
63
- "@rsbuild/shared": "0.2.14"
63
+ "@rsbuild/shared": "0.2.15"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@types/node": "16.x",