@rsbuild/core 0.4.11 → 0.4.13

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.
@@ -39,7 +39,7 @@ const applyServerOptions = (command) => {
39
39
  command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
40
40
  };
41
41
  function runCli() {
42
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.4.11");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.4.13");
43
43
  const devCommand = import_commander.program.command("dev");
44
44
  const buildCommand = import_commander.program.command("build");
45
45
  const previewCommand = import_commander.program.command("preview");
@@ -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.4.11"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.4.13"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_config = require("./config");
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  var import_mergeConfig = require("./mergeConfig");
40
40
  var import_constants = require("./constants");
41
- const version = "0.4.11";
41
+ const version = "0.4.13";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_CSS_NAME,
@@ -50,7 +50,8 @@ const pluginAsset = () => ({
50
50
  const regExp = getRegExpForExts(exts);
51
51
  const distDir = (0, import_shared.getDistPath)(config, assetType);
52
52
  const filename = (0, import_shared.getFilename)(config, assetType, isProd);
53
- const maxSize = config.output.dataUriLimit[assetType];
53
+ const { dataUriLimit } = config.output;
54
+ const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
54
55
  const rule = chain.module.rule(assetType).test(regExp);
55
56
  (0, import_shared.chainStaticAssetRule)({
56
57
  rule,
@@ -61,19 +61,31 @@ const calcFileSize = (len) => {
61
61
  const val = len / 1e3;
62
62
  return `${val.toFixed(val < 1 ? 2 : 1)} kB`;
63
63
  };
64
- async function printFileSizes(config, stats, distPath) {
64
+ const coloringAssetName = (assetName) => {
65
+ if (import_shared.JS_REGEX.test(assetName)) {
66
+ return import_shared2.color.cyan(assetName);
67
+ }
68
+ if (import_shared.CSS_REGEX.test(assetName)) {
69
+ return import_shared2.color.yellow(assetName);
70
+ }
71
+ if (import_shared.HTML_REGEX.test(assetName)) {
72
+ return import_shared2.color.green(assetName);
73
+ }
74
+ return import_shared2.color.magenta(assetName);
75
+ };
76
+ async function printFileSizes(config, stats, rootPath) {
65
77
  if (config.detail === false && config.total === false) {
66
78
  return;
67
79
  }
68
80
  const { default: gzipSize } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/gzip-size")));
69
- const formatAsset = (asset) => {
81
+ const formatAsset = (asset, distPath, distFolder) => {
70
82
  const fileName = asset.name.split("?")[0];
71
83
  const contents = import_shared.fse.readFileSync(import_node_path.default.join(distPath, fileName));
72
84
  const size = contents.length;
73
85
  const gzippedSize = gzipSize.sync(contents);
74
86
  return {
75
87
  size,
76
- folder: import_node_path.default.join(import_node_path.default.basename(distPath), import_node_path.default.dirname(fileName)),
88
+ folder: import_node_path.default.join(distFolder, import_node_path.default.dirname(fileName)),
77
89
  name: import_node_path.default.basename(fileName),
78
90
  gzippedSize,
79
91
  sizeLabel: calcFileSize(size),
@@ -82,6 +94,10 @@ async function printFileSizes(config, stats, distPath) {
82
94
  };
83
95
  const multiStats = "stats" in stats ? stats.stats : [stats];
84
96
  const assets = multiStats.map((stats2) => {
97
+ const distPath = stats2.compilation.outputOptions.path;
98
+ if (!distPath) {
99
+ return [];
100
+ }
85
101
  const origin = stats2.toJson({
86
102
  all: false,
87
103
  assets: true,
@@ -95,7 +111,10 @@ async function printFileSizes(config, stats, distPath) {
95
111
  const filteredAssets = origin.assets.filter(
96
112
  (asset) => filterAsset(asset.name)
97
113
  );
98
- return filteredAssets.map(formatAsset);
114
+ const distFolder = distPath.replace(rootPath + import_node_path.default.sep, "");
115
+ return filteredAssets.map(
116
+ (asset) => formatAsset(asset, distPath, distFolder)
117
+ );
99
118
  }).reduce((single, all) => all.concat(single), []);
100
119
  if (assets.length === 0) {
101
120
  return;
@@ -123,7 +142,7 @@ async function printFileSizes(config, stats, distPath) {
123
142
  const rightPadding = " ".repeat(longestLabelLength - sizeLength);
124
143
  sizeLabel += rightPadding;
125
144
  }
126
- let fileNameLabel = import_shared2.color.dim(asset.folder + import_node_path.default.sep) + import_shared2.color.cyan(asset.name);
145
+ let fileNameLabel = import_shared2.color.dim(asset.folder + import_node_path.default.sep) + coloringAssetName(asset.name);
127
146
  if (fileNameLength < longestFileLength) {
128
147
  const rightPadding = " ".repeat(longestFileLength - fileNameLength);
129
148
  fileNameLabel += rightPadding;
@@ -161,7 +180,7 @@ const pluginFileSize = () => ({
161
180
  await printFileSizes(
162
181
  printFileSizeConfig,
163
182
  stats,
164
- api.context.distPath
183
+ api.context.rootPath
165
184
  );
166
185
  } catch (err) {
167
186
  import_shared2.logger.warn("Failed to print file size.");
@@ -22,7 +22,6 @@ __export(nodeAddons_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(nodeAddons_exports);
24
24
  var import_node_path = require("node:path");
25
- var import_shared = require("@rsbuild/shared");
26
25
  const pluginNodeAddons = () => ({
27
26
  name: "rsbuild:node-addons",
28
27
  setup(api) {
@@ -30,35 +29,7 @@ const pluginNodeAddons = () => ({
30
29
  if (!isServer) {
31
30
  return;
32
31
  }
33
- const getDistName = (resourcePath) => {
34
- const pkgJSON = (0, import_shared.findUpSync)({
35
- filename: "package.json",
36
- cwd: (0, import_node_path.dirname)(resourcePath)
37
- });
38
- if (!pkgJSON) {
39
- throw new Error(
40
- `Failed to compile Node.js addons, couldn't find the package.json of ${import_shared.color.yellow(
41
- resourcePath
42
- )}.`
43
- );
44
- }
45
- const getFilename = (resource, pkgName2) => {
46
- const reg = new RegExp(`node_modules/${pkgName2}/(.+)`);
47
- const match = resource.match(reg);
48
- const filename = match?.[1];
49
- if (!filename) {
50
- return "[name].[ext]";
51
- }
52
- return `${filename}`;
53
- };
54
- const { name: pkgName } = import_shared.fse.readJSONSync(pkgJSON);
55
- const config = api.getNormalizedConfig();
56
- const serverPath = (0, import_shared.getDistPath)(config, "server");
57
- return `${serverPath}/${getFilename(resourcePath, pkgName)}`;
58
- };
59
- chain.module.rule(CHAIN_ID.RULE.NODE).test(/\.node$/).use(CHAIN_ID.USE.NODE).loader((0, import_node_path.join)(__dirname, "../../compiled/node-loader")).options({
60
- name: getDistName
61
- });
32
+ chain.module.rule(CHAIN_ID.RULE.NODE).test(/\.node$/).use(CHAIN_ID.USE.NODE).loader((0, import_node_path.join)(__dirname, "../rspack/nodeAddonsLoader"));
62
33
  });
63
34
  }
64
35
  });
@@ -101,7 +101,7 @@ function splitByModule(ctx) {
101
101
  return {
102
102
  ...defaultConfig,
103
103
  minSize: 0,
104
- maxInitialRequests: Infinity,
104
+ maxInitialRequests: Number.POSITIVE_INFINITY,
105
105
  ...override,
106
106
  cacheGroups: {
107
107
  ...defaultConfig.cacheGroups,
@@ -124,7 +124,7 @@ function splitBySize(ctx) {
124
124
  return {
125
125
  ...defaultConfig,
126
126
  minSize: userConfig.minSize ?? 0,
127
- maxSize: userConfig.maxSize ?? Infinity,
127
+ maxSize: userConfig.maxSize ?? Number.POSITIVE_INFINITY,
128
128
  ...override,
129
129
  cacheGroups: {
130
130
  ...defaultConfig.cacheGroups,
@@ -41,9 +41,20 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
41
41
  });
42
42
  bundlerConfigs = rspackConfigs;
43
43
  }
44
+ let isFirstCompile = true;
44
45
  await context.hooks.onBeforeBuild.call({
45
46
  bundlerConfigs
46
47
  });
48
+ const onDone = async (stats) => {
49
+ const p = context.hooks.onAfterBuild.call({ isFirstCompile, stats });
50
+ isFirstCompile = false;
51
+ await p;
52
+ };
53
+ try {
54
+ compiler.hooks.done.tapPromise("rsbuild:done", onDone);
55
+ } catch {
56
+ compiler.hooks.done.tap("rsbuild:done", onDone);
57
+ }
47
58
  if (watch) {
48
59
  compiler.watch({}, (err) => {
49
60
  if (err) {
@@ -52,21 +63,18 @@ const build = async (initOptions, { mode = "production", watch, compiler: custom
52
63
  });
53
64
  return;
54
65
  }
55
- const { stats } = await new Promise(
56
- (resolve, reject) => {
57
- compiler.run((err, stats2) => {
58
- if (err || stats2?.hasErrors()) {
59
- const buildError = err || new Error("Rspack build failed!");
60
- reject(buildError);
61
- } else {
62
- compiler.close(() => {
63
- resolve({ stats: stats2 });
64
- });
65
- }
66
- });
67
- }
68
- );
69
- await context.hooks.onAfterBuild.call({ stats });
66
+ await new Promise((resolve, reject) => {
67
+ compiler.run((err, stats) => {
68
+ if (err || stats?.hasErrors()) {
69
+ const buildError = err || new Error("Rspack build failed!");
70
+ reject(buildError);
71
+ } else {
72
+ compiler.close(() => {
73
+ resolve({ stats });
74
+ });
75
+ }
76
+ });
77
+ });
70
78
  };
71
79
  // Annotate the CommonJS export names for ESM import in node:
72
80
  0 && (module.exports = {
@@ -44,7 +44,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
44
44
  const context = {
45
45
  entry: (0, import_entry.getEntryObject)(config, "web"),
46
46
  targets: config.output?.targets || [],
47
- version: "0.4.11",
47
+ version: "0.4.13",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
@@ -0,0 +1,3 @@
1
+ import type { Rspack } from '@rsbuild/shared';
2
+ export default function (this: Rspack.LoaderContext, source: string): string;
3
+ export declare const raw = true;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var nodeAddonsLoader_exports = {};
30
+ __export(nodeAddonsLoader_exports, {
31
+ default: () => nodeAddonsLoader_default,
32
+ raw: () => raw
33
+ });
34
+ module.exports = __toCommonJS(nodeAddonsLoader_exports);
35
+ var import_node_path = __toESM(require("node:path"));
36
+ const getFilename = (resourcePath) => {
37
+ let basename = "";
38
+ if (resourcePath) {
39
+ const parsed = import_node_path.default.parse(resourcePath);
40
+ if (parsed.dir) {
41
+ basename = parsed.name;
42
+ }
43
+ }
44
+ if (basename) {
45
+ return `${basename}.node`;
46
+ }
47
+ return null;
48
+ };
49
+ function nodeAddonsLoader_default(source) {
50
+ const name = getFilename(this.resourcePath);
51
+ if (name === null) {
52
+ throw new Error(`Failed to load Node.js addon: "${this.resourcePath}"`);
53
+ }
54
+ this.emitFile(name, source);
55
+ return `
56
+ try {
57
+ const path = require("path");
58
+ process.dlopen(module, path.join(__dirname, "${name}"));
59
+ } catch (error) {
60
+ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
61
+ }
62
+ `;
63
+ }
64
+ const raw = true;
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ raw
68
+ });
@@ -149,7 +149,7 @@ const getPort = async ({
149
149
  silent = false
150
150
  }) => {
151
151
  if (typeof port === "string") {
152
- port = parseInt(port, 10);
152
+ port = Number.parseInt(port, 10);
153
153
  }
154
154
  if (strictPort) {
155
155
  tryLimits = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -55,13 +55,13 @@
55
55
  "@rspack/core": "0.5.6",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.32.2",
58
- "html-webpack-plugin": "npm:html-rspack-plugin@5.6.1",
58
+ "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
59
59
  "postcss": "^8.4.33",
60
- "@rsbuild/shared": "0.4.11"
60
+ "@rsbuild/shared": "0.4.13"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",
64
- "typescript": "^5.3.0",
64
+ "typescript": "^5.4.2",
65
65
  "webpack": "^5.89.0"
66
66
  },
67
67
  "engines": {
@@ -1 +0,0 @@
1
- export = any;
@@ -1 +0,0 @@
1
- (()=>{"use strict";var e={950:(e,r,t)=>{const n=t(867);e.exports=n.default;e.exports.raw=n.raw},867:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:true});r["default"]=loader;r.raw=void 0;var n=t(72);var o=_interopRequireDefault(t(349));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function loader(e){const r=this.getOptions(o.default);const t=(0,n.interpolateName)(this,typeof r.name!=="undefined"?r.name:"[contenthash].[ext]",{context:this.rootContext,content:e});this.emitFile(t,e);return`\ntry {\n process.dlopen(module, __dirname + require("path").sep + __webpack_public_path__ + ${JSON.stringify(t)}${typeof r.flags!=="undefined"?`, ${JSON.stringify(r.flags)}`:""});\n} catch (error) {\n throw new Error('node-loader:\\n' + error);\n}\n`}const a=true;r.raw=a},72:e=>{e.exports=require("@rsbuild/shared/loader-utils2")},349:e=>{e.exports=JSON.parse('{"title":"Node Loader options","type":"object","properties":{"name":{"anyOf":[{"type":"string"},{"instanceof":"Function"}]},"flags":{"type":"integer"}},"additionalProperties":false}')}};var r={};function __nccwpck_require__(t){var n=r[t];if(n!==undefined){return n.exports}var o=r[t]={exports:{}};var a=true;try{e[t](o,o.exports,__nccwpck_require__);a=false}finally{if(a)delete r[t]}return o.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var t=__nccwpck_require__(950);module.exports=t})();
@@ -1,20 +0,0 @@
1
- Copyright JS Foundation and other contributors
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- 'Software'), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +0,0 @@
1
- {"name":"node-loader","author":"Tobias Koppers @sokra","version":"2.0.0","funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"license":"MIT","types":"index.d.ts","type":"commonjs"}