@rsbuild/core 0.3.6 → 0.3.8

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.
Files changed (51) hide show
  1. package/compiled/on-finished/index.d.ts +13 -0
  2. package/compiled/on-finished/index.js +14 -0
  3. package/compiled/on-finished/license +23 -0
  4. package/compiled/on-finished/package.json +1 -0
  5. package/dist/cli/commands.js +7 -6
  6. package/dist/cli/config.d.ts +4 -2
  7. package/dist/cli/config.js +12 -10
  8. package/dist/cli/prepare.js +1 -1
  9. package/dist/index.js +1 -1
  10. package/dist/loadEnv.js +9 -4
  11. package/dist/plugins/asset.js +3 -3
  12. package/dist/plugins/basic.js +2 -2
  13. package/dist/plugins/cache.js +9 -9
  14. package/dist/plugins/fileSize.js +7 -7
  15. package/dist/plugins/html.js +4 -4
  16. package/dist/plugins/inlineChunk.js +2 -2
  17. package/dist/plugins/nodeAddons.js +3 -3
  18. package/dist/plugins/server.js +2 -2
  19. package/dist/plugins/splitChunks.js +2 -2
  20. package/dist/plugins/startUrl.js +5 -5
  21. package/dist/plugins/wasm.js +2 -2
  22. package/dist/provider/config.js +5 -11
  23. package/dist/provider/core/createContext.js +4 -4
  24. package/dist/provider/core/inspectConfig.js +3 -3
  25. package/dist/provider/core/rspackConfig.d.ts +2 -1
  26. package/dist/provider/core/rspackConfig.js +8 -5
  27. package/dist/provider/htmlPluginUtil.d.ts +1 -1
  28. package/dist/provider/htmlPluginUtil.js +7 -13
  29. package/dist/provider/index.d.ts +1 -0
  30. package/dist/provider/index.js +3 -0
  31. package/dist/provider/plugins/css.js +9 -5
  32. package/dist/provider/plugins/output.js +3 -3
  33. package/dist/provider/plugins/resolve.js +3 -7
  34. package/dist/provider/plugins/rspackProfile.d.ts +1 -1
  35. package/dist/provider/plugins/rspackProfile.js +7 -7
  36. package/dist/provider/plugins/swc.js +3 -3
  37. package/dist/provider/shared.js +2 -2
  38. package/dist/rspack/HtmlAppIconPlugin.js +5 -5
  39. package/dist/rspack/InlineChunkHtmlPlugin.js +2 -2
  40. package/dist/rspack/preload/helpers/determineAsValue.js +11 -27
  41. package/dist/server/compilerDevMiddleware.d.ts +2 -2
  42. package/dist/server/getDevMiddlewares.js +9 -5
  43. package/dist/server/httpServer.js +2 -2
  44. package/dist/server/middlewares.d.ts +2 -0
  45. package/dist/server/middlewares.js +55 -11
  46. package/dist/server/prodServer.d.ts +1 -1
  47. package/dist/server/prodServer.js +5 -2
  48. package/dist/server/restart.js +2 -2
  49. package/dist/server/socketServer.d.ts +2 -2
  50. package/package.json +3 -3
  51. package/types.d.ts +24 -0
@@ -30,13 +30,14 @@ var middlewares_exports = {};
30
30
  __export(middlewares_exports, {
31
31
  faviconFallbackMiddleware: () => faviconFallbackMiddleware,
32
32
  getHtmlFallbackMiddleware: () => getHtmlFallbackMiddleware,
33
+ getRequestLoggerMiddleware: () => getRequestLoggerMiddleware,
33
34
  notFoundMiddleware: () => notFoundMiddleware
34
35
  });
35
36
  module.exports = __toCommonJS(middlewares_exports);
36
37
  var import_shared = require("@rsbuild/shared");
37
- var import_url = require("url");
38
- var import_path = __toESM(require("path"));
39
- var import_fs = __toESM(require("fs"));
38
+ var import_node_url = require("node:url");
39
+ var import_node_path = __toESM(require("node:path"));
40
+ var import_node_fs = __toESM(require("node:fs"));
40
41
  const faviconFallbackMiddleware = (req, res, next) => {
41
42
  if (req.url === "/favicon.ico") {
42
43
  res.statusCode = 204;
@@ -45,6 +46,42 @@ const faviconFallbackMiddleware = (req, res, next) => {
45
46
  next();
46
47
  }
47
48
  };
49
+ const getStatusCodeColor = (status) => {
50
+ if (status >= 500) {
51
+ return import_shared.color.red;
52
+ }
53
+ if (status >= 400) {
54
+ return import_shared.color.yellow;
55
+ }
56
+ if (status >= 300) {
57
+ return import_shared.color.cyan;
58
+ }
59
+ if (status >= 200) {
60
+ return import_shared.color.green;
61
+ }
62
+ return (res) => res;
63
+ };
64
+ const getRequestLoggerMiddleware = async () => {
65
+ const { default: onFinished } = await Promise.resolve().then(() => __toESM(require("../../compiled/on-finished")));
66
+ return (req, res, next) => {
67
+ const _startAt = process.hrtime();
68
+ const logRequest = () => {
69
+ const method = req.method;
70
+ const url = req.originalUrl || req.url;
71
+ const status = Number(res.statusCode);
72
+ const statusColor = getStatusCodeColor(status);
73
+ const endAt = process.hrtime();
74
+ const totalTime = (endAt[0] - _startAt[0]) * 1e3 + (endAt[1] - _startAt[1]) * 1e-6;
75
+ (0, import_shared.debug)(
76
+ `${statusColor(status)} ${method} ${import_shared.color.gray(url)} ${import_shared.color.gray(
77
+ `${totalTime.toFixed(3)} ms`
78
+ )}`
79
+ );
80
+ };
81
+ onFinished(res, logRequest);
82
+ next();
83
+ };
84
+ };
48
85
  const notFoundMiddleware = (_req, res, _next) => {
49
86
  res.statusCode = 404;
50
87
  res.end();
@@ -63,20 +100,26 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
63
100
  const { url } = req;
64
101
  let pathname = url;
65
102
  try {
66
- pathname = (0, import_url.parse)(url, false, true).pathname;
103
+ pathname = (0, import_node_url.parse)(url, false, true).pathname;
67
104
  } catch (err) {
68
105
  import_shared.logger.error(
69
106
  new Error(`Invalid URL: ${import_shared.color.yellow(url)}`, { cause: err })
70
107
  );
71
108
  return next();
72
109
  }
73
- let outputFileSystem = import_fs.default;
110
+ let outputFileSystem = import_node_fs.default;
74
111
  if (res.locals.webpack) {
75
112
  const { devMiddleware } = res.locals.webpack;
76
113
  outputFileSystem = devMiddleware.outputFileSystem;
77
114
  }
78
- const rewrite = (newUrl) => {
79
- (0, import_shared.debug)?.(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
115
+ const rewrite = (newUrl, isFallback = false) => {
116
+ if (isFallback && (0, import_shared.isDebug)()) {
117
+ (0, import_shared.debug)(
118
+ `${req.method} ${import_shared.color.gray(
119
+ `${req.url} ${import_shared.color.yellow("fallback")} to ${newUrl}`
120
+ )}`
121
+ );
122
+ }
80
123
  req.url = newUrl;
81
124
  if (callback) {
82
125
  return callback(req, res, (...args) => {
@@ -87,7 +130,7 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
87
130
  };
88
131
  if (pathname.endsWith("/")) {
89
132
  const newUrl = `${pathname}index.html`;
90
- const filePath = import_path.default.join(distPath, pathname, "index.html");
133
+ const filePath = import_node_path.default.join(distPath, pathname, "index.html");
91
134
  if (outputFileSystem.existsSync(filePath)) {
92
135
  return rewrite(newUrl);
93
136
  }
@@ -96,14 +139,14 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
96
139
  !pathname.endsWith(".html")
97
140
  ) {
98
141
  const newUrl = `${pathname}.html`;
99
- const filePath = import_path.default.join(distPath, `${pathname}.html`);
142
+ const filePath = import_node_path.default.join(distPath, `${pathname}.html`);
100
143
  if (outputFileSystem.existsSync(filePath)) {
101
144
  return rewrite(newUrl);
102
145
  }
103
146
  }
104
147
  if (htmlFallback === "index") {
105
- if (outputFileSystem.existsSync(import_path.default.join(distPath, "index.html"))) {
106
- return rewrite("/index.html");
148
+ if (outputFileSystem.existsSync(import_node_path.default.join(distPath, "index.html"))) {
149
+ return rewrite("/index.html", true);
107
150
  }
108
151
  }
109
152
  next();
@@ -113,5 +156,6 @@ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
113
156
  0 && (module.exports = {
114
157
  faviconFallbackMiddleware,
115
158
  getHtmlFallbackMiddleware,
159
+ getRequestLoggerMiddleware,
116
160
  notFoundMiddleware
117
161
  });
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { Server } from 'http';
2
+ import type { Server } from 'node:http';
3
3
  import connect from '@rsbuild/shared/connect';
4
4
  import { type ServerConfig, type RsbuildConfig, type StartServerResult, type PreviewServerOptions } from '@rsbuild/shared';
5
5
  import type { InternalContext } from '../types';
@@ -38,7 +38,7 @@ __export(prodServer_exports, {
38
38
  });
39
39
  module.exports = __toCommonJS(prodServer_exports);
40
40
  var import_connect = __toESM(require("@rsbuild/shared/connect"));
41
- var import_path = require("path");
41
+ var import_node_path = require("node:path");
42
42
  var import_sirv = __toESM(require("../../compiled/sirv"));
43
43
  var import_shared = require("@rsbuild/shared");
44
44
  var import_helper = require("./helper");
@@ -58,6 +58,9 @@ class RsbuildProdServer {
58
58
  }
59
59
  async applyDefaultMiddlewares() {
60
60
  const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
61
+ if ((0, import_shared.isDebug)()) {
62
+ this.middlewares.use(await (0, import_middlewares.getRequestLoggerMiddleware)());
63
+ }
61
64
  if (compress) {
62
65
  const { default: compression } = await Promise.resolve().then(() => __toESM(require("../../compiled/http-compression")));
63
66
  this.middlewares.use((req, res, next) => {
@@ -100,7 +103,7 @@ class RsbuildProdServer {
100
103
  serverConfig: { htmlFallback },
101
104
  pwd
102
105
  } = this.options;
103
- const assetMiddleware = (0, import_sirv.default)((0, import_path.join)(pwd, path), {
106
+ const assetMiddleware = (0, import_sirv.default)((0, import_node_path.join)(pwd, path), {
104
107
  etag: true,
105
108
  dev: true,
106
109
  ignores: ["favicon.ico"],
@@ -32,7 +32,7 @@ __export(restart_exports, {
32
32
  restartDevServer: () => restartDevServer
33
33
  });
34
34
  module.exports = __toCommonJS(restart_exports);
35
- var import_path = __toESM(require("path"));
35
+ var import_node_path = __toESM(require("node:path"));
36
36
  var import_shared = require("@rsbuild/shared");
37
37
  var import_commands = require("../cli/commands");
38
38
  let cleaners = [];
@@ -46,7 +46,7 @@ const clearConsole = () => {
46
46
  };
47
47
  const restartDevServer = async ({ filePath }) => {
48
48
  clearConsole();
49
- const filename = import_path.default.basename(filePath);
49
+ const filename = import_node_path.default.basename(filePath);
50
50
  import_shared.logger.info(`Restart because ${import_shared.color.yellow(filename)} is changed.
51
51
  `);
52
52
  for (const cleaner of cleaners) {
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import type { IncomingMessage } from 'http';
4
- import type { Socket } from 'net';
3
+ import type { IncomingMessage } from 'node:http';
4
+ import type { Socket } from 'node:net';
5
5
  import ws from '../../compiled/ws';
6
6
  import { type Stats, type DevMiddlewaresConfig } from '@rsbuild/shared';
7
7
  export declare class SocketServer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -52,12 +52,12 @@
52
52
  "types.d.ts"
53
53
  ],
54
54
  "dependencies": {
55
- "@rspack/core": "0.5.0",
55
+ "@rspack/core": "0.5.2",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.32.2",
58
58
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
59
59
  "postcss": "^8.4.33",
60
- "@rsbuild/shared": "0.3.6"
60
+ "@rsbuild/shared": "0.3.8"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",
package/types.d.ts CHANGED
@@ -17,6 +17,14 @@ declare module '*.jpeg' {
17
17
  const src: string;
18
18
  export default src;
19
19
  }
20
+ declare module '*.pjpeg' {
21
+ const src: string;
22
+ export default src;
23
+ }
24
+ declare module '*.pjp' {
25
+ const src: string;
26
+ export default src;
27
+ }
20
28
  declare module '*.png' {
21
29
  const src: string;
22
30
  export default src;
@@ -41,10 +49,18 @@ declare module '*.avif' {
41
49
  const src: string;
42
50
  export default src;
43
51
  }
52
+ declare module '*.tif' {
53
+ const src: string;
54
+ export default src;
55
+ }
44
56
  declare module '*.tiff' {
45
57
  const src: string;
46
58
  export default src;
47
59
  }
60
+ declare module '*.jfif' {
61
+ const src: string;
62
+ export default src;
63
+ }
48
64
 
49
65
  /**
50
66
  * Font assets
@@ -109,6 +125,14 @@ declare module '*.mov' {
109
125
  const src: string;
110
126
  export default src;
111
127
  }
128
+ declare module '*.m4a' {
129
+ const src: string;
130
+ export default src;
131
+ }
132
+ declare module '*.opus' {
133
+ const src: string;
134
+ export default src;
135
+ }
112
136
 
113
137
  /**
114
138
  * Configuration files