@rsbuild/core 0.4.12 → 0.4.14

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.
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(commands_exports);
24
24
  var import_node_path = require("node:path");
25
25
  var import_node_fs = require("node:fs");
26
26
  var import_shared = require("@rsbuild/shared");
27
- var import_commander = require("@rsbuild/shared/commander");
27
+ var import_commander = require("../../compiled/commander");
28
28
  var import_init = require("./init");
29
29
  const applyCommonOptions = (command) => {
30
30
  command.option(
@@ -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.12");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.4.14");
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.12"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.4.14"}`}
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.12";
41
+ const version = "0.4.14";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_CSS_NAME,
@@ -34,6 +34,24 @@ __export(asset_exports, {
34
34
  module.exports = __toCommonJS(asset_exports);
35
35
  var import_node_path = __toESM(require("node:path"));
36
36
  var import_shared = require("@rsbuild/shared");
37
+ const chainStaticAssetRule = ({
38
+ rule,
39
+ maxSize,
40
+ filename,
41
+ assetType
42
+ }) => {
43
+ rule.oneOf(`${assetType}-asset-url`).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", {
44
+ filename
45
+ });
46
+ rule.oneOf(`${assetType}-asset-inline`).type("asset/inline").resourceQuery(/inline/);
47
+ rule.oneOf(`${assetType}-asset`).type("asset").parser({
48
+ dataUrlCondition: {
49
+ maxSize
50
+ }
51
+ }).set("generator", {
52
+ filename
53
+ });
54
+ };
37
55
  function getRegExpForExts(exts) {
38
56
  const matcher = exts.map((ext) => ext.trim()).map((ext) => ext.startsWith(".") ? ext.slice(1) : ext).join("|");
39
57
  return new RegExp(
@@ -50,9 +68,10 @@ const pluginAsset = () => ({
50
68
  const regExp = getRegExpForExts(exts);
51
69
  const distDir = (0, import_shared.getDistPath)(config, assetType);
52
70
  const filename = (0, import_shared.getFilename)(config, assetType, isProd);
53
- const maxSize = config.output.dataUriLimit[assetType];
71
+ const { dataUriLimit } = config.output;
72
+ const maxSize = typeof dataUriLimit === "number" ? dataUriLimit : dataUriLimit[assetType];
54
73
  const rule = chain.module.rule(assetType).test(regExp);
55
- (0, import_shared.chainStaticAssetRule)({
74
+ chainStaticAssetRule({
56
75
  rule,
57
76
  maxSize,
58
77
  filename: import_node_path.default.posix.join(distDir, filename),
@@ -73,19 +73,19 @@ const coloringAssetName = (assetName) => {
73
73
  }
74
74
  return import_shared2.color.magenta(assetName);
75
75
  };
76
- async function printFileSizes(config, stats, distPath) {
76
+ async function printFileSizes(config, stats, rootPath) {
77
77
  if (config.detail === false && config.total === false) {
78
78
  return;
79
79
  }
80
80
  const { default: gzipSize } = await Promise.resolve().then(() => __toESM(require("@rsbuild/shared/gzip-size")));
81
- const formatAsset = (asset) => {
81
+ const formatAsset = (asset, distPath, distFolder) => {
82
82
  const fileName = asset.name.split("?")[0];
83
83
  const contents = import_shared.fse.readFileSync(import_node_path.default.join(distPath, fileName));
84
84
  const size = contents.length;
85
85
  const gzippedSize = gzipSize.sync(contents);
86
86
  return {
87
87
  size,
88
- 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)),
89
89
  name: import_node_path.default.basename(fileName),
90
90
  gzippedSize,
91
91
  sizeLabel: calcFileSize(size),
@@ -94,6 +94,10 @@ async function printFileSizes(config, stats, distPath) {
94
94
  };
95
95
  const multiStats = "stats" in stats ? stats.stats : [stats];
96
96
  const assets = multiStats.map((stats2) => {
97
+ const distPath = stats2.compilation.outputOptions.path;
98
+ if (!distPath) {
99
+ return [];
100
+ }
97
101
  const origin = stats2.toJson({
98
102
  all: false,
99
103
  assets: true,
@@ -107,7 +111,10 @@ async function printFileSizes(config, stats, distPath) {
107
111
  const filteredAssets = origin.assets.filter(
108
112
  (asset) => filterAsset(asset.name)
109
113
  );
110
- 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
+ );
111
118
  }).reduce((single, all) => all.concat(single), []);
112
119
  if (assets.length === 0) {
113
120
  return;
@@ -173,7 +180,7 @@ const pluginFileSize = () => ({
173
180
  await printFileSizes(
174
181
  printFileSizeConfig,
175
182
  stats,
176
- api.context.distPath
183
+ api.context.rootPath
177
184
  );
178
185
  } catch (err) {
179
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
+ if ((0, import_shared.isMultiCompiler)(compiler)) {
54
+ compiler.hooks.done.tap("rsbuild:done", onDone);
55
+ } else {
56
+ compiler.hooks.done.tapPromise("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 = {
@@ -71,7 +71,7 @@ async function createCompiler({
71
71
  if ((0, import_shared.isProd)()) {
72
72
  compiler.hooks.run.tap("rsbuild:run", logRspackVersion);
73
73
  }
74
- compiler.hooks.done.tap("rsbuild:done", async (stats) => {
74
+ const done = async (stats) => {
75
75
  const obj = stats.toJson({
76
76
  all: false,
77
77
  timings: true
@@ -108,7 +108,12 @@ async function createCompiler({
108
108
  }
109
109
  isCompiling = false;
110
110
  isFirstCompile = false;
111
- });
111
+ };
112
+ if ((0, import_shared.isMultiCompiler)(compiler)) {
113
+ compiler.hooks.done.tap("rsbuild:done", done);
114
+ } else {
115
+ compiler.hooks.done.tapPromise("rsbuild:done", done);
116
+ }
112
117
  await context.hooks.onAfterCreateCompiler.call({ compiler });
113
118
  (0, import_shared.debug)("create compiler done");
114
119
  return compiler;
@@ -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.12",
47
+ version: "0.4.14",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
@@ -49,7 +49,7 @@ const getDevMiddleware = (multiCompiler) => (options) => {
49
49
  }
50
50
  (0, import_shared.setupServerHooks)(compiler, callbacks);
51
51
  };
52
- if (multiCompiler.compilers) {
52
+ if ((0, import_shared.isMultiCompiler)(multiCompiler)) {
53
53
  multiCompiler.compilers.forEach(setupCompiler);
54
54
  } else {
55
55
  setupCompiler(multiCompiler);
@@ -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
+ });
@@ -78,9 +78,7 @@ async function getServerAPIs(options, createDevMiddleware, {
78
78
  customCompiler
79
79
  );
80
80
  const { CompilerDevMiddleware } = await Promise.resolve().then(() => __toESM(require("./compilerDevMiddleware")));
81
- const publicPaths = compiler.compilers ? compiler.compilers.map(
82
- import_shared.getPublicPathFromCompiler
83
- ) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
81
+ const publicPaths = (0, import_shared.isMultiCompiler)(compiler) ? compiler.compilers.map(import_shared.getPublicPathFromCompiler) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
84
82
  const compilerDevMiddleware = new CompilerDevMiddleware({
85
83
  dev: devServerConfig,
86
84
  publicPaths,
@@ -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.12",
3
+ "version": "0.4.14",
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.12"
60
+ "@rsbuild/shared": "0.4.14"
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 +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"}