@rsbuild/core 1.2.0-beta.0 → 1.2.0-beta.1

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.
@@ -4417,14 +4417,14 @@
4417
4417
  return a.start - b.start;
4418
4418
  }
4419
4419
  },
4420
- 6233: (module, __unused_webpack_exports, __nccwpck_require__) => {
4420
+ 9096: (module, __unused_webpack_exports, __nccwpck_require__) => {
4421
4421
  "use strict";
4422
- const middleware = __nccwpck_require__(319);
4423
- const getFilenameFromUrl = __nccwpck_require__(8369);
4424
- const setupHooks = __nccwpck_require__(3414);
4425
- const setupWriteToDisk = __nccwpck_require__(5986);
4426
- const setupOutputFileSystem = __nccwpck_require__(7009);
4427
- const ready = __nccwpck_require__(3195);
4422
+ const middleware = __nccwpck_require__(242);
4423
+ const getFilenameFromUrl = __nccwpck_require__(2039);
4424
+ const setupHooks = __nccwpck_require__(1618);
4425
+ const setupWriteToDisk = __nccwpck_require__(8764);
4426
+ const setupOutputFileSystem = __nccwpck_require__(5921);
4427
+ const ready = __nccwpck_require__(6247);
4428
4428
  const noop = () => {};
4429
4429
  function wdm(compiler, options = {}) {
4430
4430
  const context = {
@@ -4479,14 +4479,14 @@
4479
4479
  }
4480
4480
  module.exports = wdm;
4481
4481
  },
4482
- 319: (module, __unused_webpack_exports, __nccwpck_require__) => {
4482
+ 242: (module, __unused_webpack_exports, __nccwpck_require__) => {
4483
4483
  "use strict";
4484
4484
  const mrmime = __nccwpck_require__(802);
4485
4485
  const onFinishedStream = __nccwpck_require__(8772);
4486
- const getFilenameFromUrl = __nccwpck_require__(8369);
4487
- const ready = __nccwpck_require__(3195);
4488
- const parseTokenList = __nccwpck_require__(6753);
4489
- const memorize = __nccwpck_require__(1526);
4486
+ const getFilenameFromUrl = __nccwpck_require__(2039);
4487
+ const ready = __nccwpck_require__(6247);
4488
+ const parseTokenList = __nccwpck_require__(6653);
4489
+ const memorize = __nccwpck_require__(4544);
4490
4490
  async function getEtag(stat) {
4491
4491
  const mtime = stat.mtime.getTime().toString(16);
4492
4492
  const size = stat.size.toString(16);
@@ -4578,7 +4578,7 @@
4578
4578
  return;
4579
4579
  }
4580
4580
  function sendError(status, options) {
4581
- const escapeHtml = __nccwpck_require__(5730);
4581
+ const escapeHtml = __nccwpck_require__(643);
4582
4582
  const content = statuses[status] || String(status);
4583
4583
  const document = Buffer.from(
4584
4584
  `<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Error</title>\n</head>\n<body>\n<pre>${escapeHtml(content)}</pre>\n</body>\n</html>`,
@@ -4883,7 +4883,7 @@
4883
4883
  }
4884
4884
  module.exports = wrapper;
4885
4885
  },
4886
- 5730: (module) => {
4886
+ 643: (module) => {
4887
4887
  "use strict";
4888
4888
  const matchHtmlRegExp = /["'&<>]/;
4889
4889
  function escapeHtml(string) {
@@ -4928,13 +4928,13 @@
4928
4928
  }
4929
4929
  module.exports = escapeHtml;
4930
4930
  },
4931
- 8369: (module, __unused_webpack_exports, __nccwpck_require__) => {
4931
+ 2039: (module, __unused_webpack_exports, __nccwpck_require__) => {
4932
4932
  "use strict";
4933
4933
  const path = __nccwpck_require__(1017);
4934
4934
  const { parse } = __nccwpck_require__(7310);
4935
4935
  const querystring = __nccwpck_require__(3477);
4936
- const getPaths = __nccwpck_require__(9904);
4937
- const memorize = __nccwpck_require__(1526);
4936
+ const getPaths = __nccwpck_require__(1197);
4937
+ const memorize = __nccwpck_require__(4544);
4938
4938
  const memoizedParse = memorize(parse, undefined, (value) => {
4939
4939
  if (value.pathname) {
4940
4940
  value.pathname = decode(value.pathname);
@@ -5017,7 +5017,7 @@
5017
5017
  }
5018
5018
  module.exports = getFilenameFromUrl;
5019
5019
  },
5020
- 9904: (module) => {
5020
+ 1197: (module) => {
5021
5021
  "use strict";
5022
5022
  function getPaths(context) {
5023
5023
  const { stats, options } = context;
@@ -5038,7 +5038,7 @@
5038
5038
  }
5039
5039
  module.exports = getPaths;
5040
5040
  },
5041
- 1526: (module) => {
5041
+ 4544: (module) => {
5042
5042
  "use strict";
5043
5043
  const cacheStore = new WeakMap();
5044
5044
  function memorize(fn, { cache = new Map() } = {}, callback) {
@@ -5060,7 +5060,7 @@
5060
5060
  }
5061
5061
  module.exports = memorize;
5062
5062
  },
5063
- 6753: (module) => {
5063
+ 6653: (module) => {
5064
5064
  "use strict";
5065
5065
  function parseTokenList(str) {
5066
5066
  let end = 0;
@@ -5093,7 +5093,7 @@
5093
5093
  }
5094
5094
  module.exports = parseTokenList;
5095
5095
  },
5096
- 3195: (module) => {
5096
+ 6247: (module) => {
5097
5097
  "use strict";
5098
5098
  function ready(context, callback, req) {
5099
5099
  if (context.state) {
@@ -5108,7 +5108,7 @@
5108
5108
  }
5109
5109
  module.exports = ready;
5110
5110
  },
5111
- 3414: (module) => {
5111
+ 1618: (module) => {
5112
5112
  "use strict";
5113
5113
  function setupHooks(context) {
5114
5114
  function invalid() {
@@ -5140,7 +5140,7 @@
5140
5140
  }
5141
5141
  module.exports = setupHooks;
5142
5142
  },
5143
- 7009: (module, __unused_webpack_exports, __nccwpck_require__) => {
5143
+ 5921: (module, __unused_webpack_exports, __nccwpck_require__) => {
5144
5144
  "use strict";
5145
5145
  const memfs = __nccwpck_require__(5953);
5146
5146
  function setupOutputFileSystem(context) {
@@ -5167,7 +5167,7 @@
5167
5167
  }
5168
5168
  module.exports = setupOutputFileSystem;
5169
5169
  },
5170
- 5986: (module, __unused_webpack_exports, __nccwpck_require__) => {
5170
+ 8764: (module, __unused_webpack_exports, __nccwpck_require__) => {
5171
5171
  "use strict";
5172
5172
  const fs = __nccwpck_require__(7147);
5173
5173
  const path = __nccwpck_require__(1017);
@@ -6153,6 +6153,6 @@
6153
6153
  }
6154
6154
  if (typeof __nccwpck_require__ !== "undefined")
6155
6155
  __nccwpck_require__.ab = __dirname + "/";
6156
- var __webpack_exports__ = __nccwpck_require__(6233);
6156
+ var __webpack_exports__ = __nccwpck_require__(9096);
6157
6157
  module.exports = __webpack_exports__;
6158
6158
  })();
@@ -1,16 +1,16 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 596: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- const loader = __nccwpck_require__(17);
4
+ 256: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ const loader = __nccwpck_require__(213);
6
6
  module.exports = loader.default;
7
7
  },
8
- 17: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
+ 213: (__unused_webpack_module, exports, __nccwpck_require__) => {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports["default"] = void 0;
11
- var _path = _interopRequireDefault(__nccwpck_require__(822));
12
- var _utils = __nccwpck_require__(995);
13
- var _options = _interopRequireDefault(__nccwpck_require__(189));
11
+ var _path = _interopRequireDefault(__nccwpck_require__(17));
12
+ var _utils = __nccwpck_require__(595);
13
+ var _options = _interopRequireDefault(__nccwpck_require__(209));
14
14
  function _interopRequireDefault(obj) {
15
15
  return obj && obj.__esModule ? obj : { default: obj };
16
16
  }
@@ -104,7 +104,7 @@
104
104
  };
105
105
  var _default = (exports["default"] = loader);
106
106
  },
107
- 692: (module) => {
107
+ 423: (module) => {
108
108
  function isEqualLocals(a, b, isNamedExport) {
109
109
  if ((!a && b) || (a && !b)) {
110
110
  return false;
@@ -130,7 +130,7 @@
130
130
  }
131
131
  module.exports = isEqualLocals;
132
132
  },
133
- 995: (__unused_webpack_module, exports, __nccwpck_require__) => {
133
+ 595: (__unused_webpack_module, exports, __nccwpck_require__) => {
134
134
  Object.defineProperty(exports, "__esModule", { value: true });
135
135
  exports.getExportLazyStyleCode = getExportLazyStyleCode;
136
136
  exports.getExportStyleCode = getExportStyleCode;
@@ -150,8 +150,8 @@
150
150
  exports.getStyleTagTransformFnCode = getStyleTagTransformFnCode;
151
151
  exports.getdomAPI = getdomAPI;
152
152
  exports.stringifyRequest = stringifyRequest;
153
- var _path = _interopRequireDefault(__nccwpck_require__(822));
154
- var _isEqualLocals = _interopRequireDefault(__nccwpck_require__(692));
153
+ var _path = _interopRequireDefault(__nccwpck_require__(17));
154
+ var _isEqualLocals = _interopRequireDefault(__nccwpck_require__(423));
155
155
  function _interopRequireDefault(obj) {
156
156
  return obj && obj.__esModule ? obj : { default: obj };
157
157
  }
@@ -391,10 +391,10 @@
391
391
  : `var setAttributes = require(${modulePath});`;
392
392
  }
393
393
  },
394
- 822: (module) => {
394
+ 17: (module) => {
395
395
  module.exports = require("path");
396
396
  },
397
- 189: (module) => {
397
+ 209: (module) => {
398
398
  module.exports = JSON.parse(
399
399
  '{"title":"Style Loader options","type":"object","properties":{"injectType":{"description":"Allows to setup how styles will be injected into DOM.","link":"https://github.com/webpack-contrib/style-loader#injecttype","enum":["styleTag","singletonStyleTag","autoStyleTag","lazyStyleTag","lazySingletonStyleTag","lazyAutoStyleTag","linkTag"]},"attributes":{"description":"Adds custom attributes to tag.","link":"https://github.com/webpack-contrib/style-loader#attributes","type":"object"},"insert":{"description":"Inserts `<style>`/`<link>` at the given position.","link":"https://github.com/webpack-contrib/style-loader#insert","anyOf":[{"type":"string"},{"instanceof":"Function"}]},"base":{"description":"Sets module ID base for DLLPlugin.","link":"https://github.com/webpack-contrib/style-loader#base","type":"number"},"esModule":{"description":"Use the ES modules syntax.","link":"https://github.com/webpack-contrib/css-loader#esmodule","type":"boolean"},"styleTagTransform":{"description":"Transform tag and css when insert \'style\' tag into the DOM","link":"https://github.com/webpack-contrib/style-loader#styleTagTransform","anyOf":[{"type":"string"},{"instanceof":"Function"}]}},"additionalProperties":false}',
400
400
  );
@@ -422,6 +422,6 @@
422
422
  }
423
423
  if (typeof __nccwpck_require__ !== "undefined")
424
424
  __nccwpck_require__.ab = __dirname + "/";
425
- var __webpack_exports__ = __nccwpck_require__(596);
425
+ var __webpack_exports__ = __nccwpck_require__(256);
426
426
  module.exports = __webpack_exports__;
427
427
  })();
package/dist/index.cjs CHANGED
@@ -507,12 +507,15 @@ var __webpack_exports__ = {};
507
507
  });
508
508
  });
509
509
  }
510
- async function emptyDir(dir) {
511
- if (await pathExists(dir)) try {
512
- for (let file of (await external_node_fs_default().promises.readdir(dir)))await external_node_fs_default().promises.rm(external_node_path_default().resolve(dir, file), {
513
- recursive: !0,
514
- force: !0
510
+ async function emptyDir(dir, keep = [], checkExists = !0) {
511
+ if (!checkExists || await pathExists(dir)) try {
512
+ let entries = await external_node_fs_default().promises.readdir(dir, {
513
+ withFileTypes: !0
515
514
  });
515
+ await Promise.all(entries.map(async (entry)=>{
516
+ let fullPath = external_node_path_default().resolve(dir, entry.name);
517
+ !keep.some((reg)=>reg.test(fullPath)) && (entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await external_node_fs_default().promises.rmdir(fullPath)) : await external_node_fs_default().promises.unlink(fullPath));
518
+ }));
516
519
  } catch (err) {
517
520
  rslog_index_js_namespaceObject.logger.debug(`Failed to empty dir: ${dir}`), rslog_index_js_namespaceObject.logger.debug(err);
518
521
  }
@@ -1700,7 +1703,7 @@ var __webpack_exports__ = {};
1700
1703
  async function createContext(options, userConfig, bundlerType) {
1701
1704
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_namespaceObject.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
1702
1705
  return {
1703
- version: "1.2.0-beta.0",
1706
+ version: "1.2.0-beta.1",
1704
1707
  rootPath,
1705
1708
  distPath: '',
1706
1709
  cachePath,
@@ -1976,18 +1979,39 @@ var __webpack_exports__ = {};
1976
1979
  }), addTrailingSep = (dir)=>dir.endsWith(external_node_path_namespaceObject.sep) ? dir : dir + external_node_path_namespaceObject.sep, isStrictSubdir = (parent, child)=>{
1977
1980
  let parentDir = addTrailingSep(parent), childDir = addTrailingSep(child);
1978
1981
  return parentDir !== childDir && childDir.startsWith(parentDir);
1982
+ }, normalizeCleanDistPath = (userOptions)=>{
1983
+ let defaultOptions = {
1984
+ enable: 'auto'
1985
+ };
1986
+ return 'boolean' == typeof userOptions || 'auto' === userOptions ? {
1987
+ ...defaultOptions,
1988
+ enable: userOptions
1989
+ } : {
1990
+ ...defaultOptions,
1991
+ ...userOptions
1992
+ };
1979
1993
  }, pluginCleanOutput = ()=>({
1980
1994
  name: 'rsbuild:clean-output',
1981
1995
  setup (api) {
1982
- let getRsbuildCleanPath = ()=>{
1983
- let { rootPath, distPath } = api.context, config = api.getNormalizedConfig(), cleanPath = (0, external_node_path_namespaceObject.join)(distPath, RSBUILD_OUTPUTS_PATH), { cleanDistPath } = config.output;
1984
- if (!0 === cleanDistPath || 'auto' === cleanDistPath && isStrictSubdir(rootPath, cleanPath)) return cleanPath;
1985
- }, getCleanPath = (environment)=>{
1986
- let { rootPath } = api.context, { config, distPath } = environment, { cleanDistPath } = config.output;
1987
- if ('auto' !== cleanDistPath || (cleanDistPath = isStrictSubdir(rootPath, distPath)) || (rslog_index_js_namespaceObject.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), rslog_index_js_namespaceObject.logger.warn(`Please set ${index_js_default().yellow('`output.cleanDistPath`')} config manually.`), rslog_index_js_namespaceObject.logger.warn(`Current root path: ${index_js_default().dim(rootPath)}`), rslog_index_js_namespaceObject.logger.warn(`Current dist path: ${index_js_default().dim(distPath)}`)), cleanDistPath) return distPath;
1996
+ let getRsbuildOutputPath = ()=>{
1997
+ let { rootPath, distPath } = api.context, config = api.getNormalizedConfig(), targetPath = (0, external_node_path_namespaceObject.join)(distPath, RSBUILD_OUTPUTS_PATH), { enable } = normalizeCleanDistPath(config.output.cleanDistPath);
1998
+ if (!0 === enable || 'auto' === enable && isStrictSubdir(rootPath, targetPath)) return {
1999
+ path: targetPath
2000
+ };
2001
+ }, getPathInfo = (environment)=>{
2002
+ let { rootPath } = api.context, { config, distPath } = environment, { enable, keep } = normalizeCleanDistPath(config.output.cleanDistPath);
2003
+ return 'auto' === enable ? isStrictSubdir(rootPath, distPath) ? {
2004
+ path: distPath,
2005
+ keep
2006
+ } : (rslog_index_js_namespaceObject.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), rslog_index_js_namespaceObject.logger.warn(`Please set ${index_js_default().yellow('`output.cleanDistPath`')} config manually.`), rslog_index_js_namespaceObject.logger.warn(`Current root path: ${index_js_default().dim(rootPath)}`), void rslog_index_js_namespaceObject.logger.warn(`Current dist path: ${index_js_default().dim(distPath)}`)) : !0 === enable ? {
2007
+ path: distPath,
2008
+ keep
2009
+ } : void 0;
1988
2010
  }, cleanAll = async (params)=>{
1989
- let cleanPaths = Object.values(params.environments).reduce((total, curr)=>(total.find((t)=>t.distPath === curr.distPath) || total.push(curr), total), []).map((e)=>getCleanPath(e)).concat(getRsbuildCleanPath()).filter((p)=>!!p);
1990
- await Promise.all(dedupeNestedPaths(cleanPaths).map((p)=>emptyDir(p)));
2011
+ for (let pathInfo of [
2012
+ ...Object.values(params.environments).reduce((result, curr)=>(result.find((item)=>item.distPath === curr.distPath) || result.push(curr), result), []).map(getPathInfo),
2013
+ getRsbuildOutputPath()
2014
+ ].filter((pathInfo)=>!!pathInfo))await emptyDir(pathInfo.path, pathInfo.keep);
1991
2015
  };
1992
2016
  api.onBeforeBuild(async ({ isFirstCompile, environments })=>{
1993
2017
  isFirstCompile && await cleanAll({
@@ -6057,7 +6081,7 @@ throw new Error('Failed to load Node.js addon: "${name}"\\n' + error);
6057
6081
  handler: (chain, { target, environment })=>{
6058
6082
  if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environment.name)) return;
6059
6083
  let rule = chain.module.rule(id);
6060
- descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer);
6084
+ descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer), descriptor.issuer && rule.issuer(descriptor.issuer), descriptor.with && rule.with(descriptor.with);
6061
6085
  let loaderName = descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs', loaderPath = (0, external_node_path_namespaceObject.join)(LOADER_PATH, loaderName);
6062
6086
  rule.use(id).loader(loaderPath).options({
6063
6087
  id,
@@ -6551,12 +6575,12 @@ ${section.body}` : section.body).join("\n\n"));
6551
6575
  }
6552
6576
  }(), process.title = 'rsbuild-node';
6553
6577
  let { npm_execpath } = process.env;
6554
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.0-beta.0\n`);
6578
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), rslog_index_js_namespaceObject.logger.greet(` Rsbuild v1.2.0-beta.1\n`);
6555
6579
  }();
6556
6580
  try {
6557
6581
  !function() {
6558
6582
  let cli = cac_dist('rsbuild');
6559
- cli.help(), cli.version("1.2.0-beta.0"), applyCommonOptions(cli);
6583
+ cli.help(), cli.version("1.2.0-beta.1"), applyCommonOptions(cli);
6560
6584
  let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
6561
6585
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
6562
6586
  try {
@@ -6607,7 +6631,7 @@ ${section.body}` : section.body).join("\n\n"));
6607
6631
  rslog_index_js_namespaceObject.logger.error('Failed to start Rsbuild CLI.'), rslog_index_js_namespaceObject.logger.error(err);
6608
6632
  }
6609
6633
  }
6610
- let src_rslib_entry_version = "1.2.0-beta.0";
6634
+ let src_rslib_entry_version = "1.2.0-beta.1";
6611
6635
  })();
6612
6636
  var __webpack_export_target__ = exports;
6613
6637
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
package/dist/index.js CHANGED
@@ -419,12 +419,15 @@ async function fileExistsByCompilation({ inputFileSystem }, filePath) {
419
419
  });
420
420
  });
421
421
  }
422
- async function emptyDir(dir) {
423
- if (await pathExists(dir)) try {
424
- for (let file of (await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.readdir(dir)))await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.rm(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.resolve(dir, file), {
425
- recursive: !0,
426
- force: !0
422
+ async function emptyDir(dir, keep = [], checkExists = !0) {
423
+ if (!checkExists || await pathExists(dir)) try {
424
+ let entries = await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.readdir(dir, {
425
+ withFileTypes: !0
427
426
  });
427
+ await Promise.all(entries.map(async (entry)=>{
428
+ let fullPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.resolve(dir, entry.name);
429
+ !keep.some((reg)=>reg.test(fullPath)) && (entry.isDirectory() ? (await emptyDir(fullPath, keep, !1), keep.length || await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.rmdir(fullPath)) : await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__.default.promises.unlink(fullPath));
430
+ }));
428
431
  } catch (err) {
429
432
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(`Failed to empty dir: ${dir}`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.debug(err);
430
433
  }
@@ -1608,7 +1611,7 @@ async function updateEnvironmentContext(context, configs) {
1608
1611
  async function createContext(options, userConfig, bundlerType) {
1609
1612
  let { cwd } = options, rootPath = userConfig.root ? getAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0;
1610
1613
  return {
1611
- version: "1.2.0-beta.0",
1614
+ version: "1.2.0-beta.1",
1612
1615
  rootPath,
1613
1616
  distPath: '',
1614
1617
  cachePath,
@@ -1883,18 +1886,39 @@ let pluginCache = ()=>({
1883
1886
  }), addTrailingSep = (dir)=>dir.endsWith(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep) ? dir : dir + __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.sep, isStrictSubdir = (parent, child)=>{
1884
1887
  let parentDir = addTrailingSep(parent), childDir = addTrailingSep(child);
1885
1888
  return parentDir !== childDir && childDir.startsWith(parentDir);
1889
+ }, normalizeCleanDistPath = (userOptions)=>{
1890
+ let defaultOptions = {
1891
+ enable: 'auto'
1892
+ };
1893
+ return 'boolean' == typeof userOptions || 'auto' === userOptions ? {
1894
+ ...defaultOptions,
1895
+ enable: userOptions
1896
+ } : {
1897
+ ...defaultOptions,
1898
+ ...userOptions
1899
+ };
1886
1900
  }, pluginCleanOutput = ()=>({
1887
1901
  name: 'rsbuild:clean-output',
1888
1902
  setup (api) {
1889
- let getRsbuildCleanPath = ()=>{
1890
- let { rootPath, distPath } = api.context, config = api.getNormalizedConfig(), cleanPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, RSBUILD_OUTPUTS_PATH), { cleanDistPath } = config.output;
1891
- if (!0 === cleanDistPath || 'auto' === cleanDistPath && isStrictSubdir(rootPath, cleanPath)) return cleanPath;
1892
- }, getCleanPath = (environment)=>{
1893
- let { rootPath } = api.context, { config, distPath } = environment, { cleanDistPath } = config.output;
1894
- if ('auto' !== cleanDistPath || (cleanDistPath = isStrictSubdir(rootPath, distPath)) || (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Please set ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('`output.cleanDistPath`')} config manually.`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current root path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(rootPath)}`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current dist path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(distPath)}`)), cleanDistPath) return distPath;
1903
+ let getRsbuildOutputPath = ()=>{
1904
+ let { rootPath, distPath } = api.context, config = api.getNormalizedConfig(), targetPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(distPath, RSBUILD_OUTPUTS_PATH), { enable } = normalizeCleanDistPath(config.output.cleanDistPath);
1905
+ if (!0 === enable || 'auto' === enable && isStrictSubdir(rootPath, targetPath)) return {
1906
+ path: targetPath
1907
+ };
1908
+ }, getPathInfo = (environment)=>{
1909
+ let { rootPath } = api.context, { config, distPath } = environment, { enable, keep } = normalizeCleanDistPath(config.output.cleanDistPath);
1910
+ return 'auto' === enable ? isStrictSubdir(rootPath, distPath) ? {
1911
+ path: distPath,
1912
+ keep
1913
+ } : (__WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn('The dist path is not a subdir of root path, Rsbuild will not empty it.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Please set ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.yellow('`output.cleanDistPath`')} config manually.`), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current root path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(rootPath)}`), void __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.warn(`Current dist path: ${__WEBPACK_EXTERNAL_MODULE__compiled_picocolors_index_js_ea7a20e9__.default.dim(distPath)}`)) : !0 === enable ? {
1914
+ path: distPath,
1915
+ keep
1916
+ } : void 0;
1895
1917
  }, cleanAll = async (params)=>{
1896
- let cleanPaths = Object.values(params.environments).reduce((total, curr)=>(total.find((t)=>t.distPath === curr.distPath) || total.push(curr), total), []).map((e)=>getCleanPath(e)).concat(getRsbuildCleanPath()).filter((p)=>!!p);
1897
- await Promise.all(dedupeNestedPaths(cleanPaths).map((p)=>emptyDir(p)));
1918
+ for (let pathInfo of [
1919
+ ...Object.values(params.environments).reduce((result, curr)=>(result.find((item)=>item.distPath === curr.distPath) || result.push(curr), result), []).map(getPathInfo),
1920
+ getRsbuildOutputPath()
1921
+ ].filter((pathInfo)=>!!pathInfo))await emptyDir(pathInfo.path, pathInfo.keep);
1898
1922
  };
1899
1923
  api.onBeforeBuild(async ({ isFirstCompile, environments })=>{
1900
1924
  isFirstCompile && await cleanAll({
@@ -5946,7 +5970,7 @@ async function createRsbuild(options = {}) {
5946
5970
  handler: (chain, { target, environment })=>{
5947
5971
  if (descriptor.targets && !descriptor.targets.includes(target) || descriptor.environments && !descriptor.environments.includes(environment.name)) return;
5948
5972
  let rule = chain.module.rule(id);
5949
- descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer);
5973
+ descriptor.test && rule.test(descriptor.test), descriptor.resourceQuery && rule.resourceQuery(descriptor.resourceQuery), descriptor.layer && rule.layer(descriptor.layer), descriptor.issuerLayer && rule.issuerLayer(descriptor.issuerLayer), descriptor.issuer && rule.issuer(descriptor.issuer), descriptor.with && rule.with(descriptor.with);
5950
5974
  let loaderName = descriptor.raw ? 'transformRawLoader.mjs' : 'transformLoader.mjs', loaderPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(LOADER_PATH, loaderName);
5951
5975
  rule.use(id).loader(loaderPath).options({
5952
5976
  id,
@@ -6439,12 +6463,12 @@ async function runCLI() {
6439
6463
  }
6440
6464
  }(), process.title = 'rsbuild-node';
6441
6465
  let { npm_execpath } = process.env;
6442
- (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.0-beta.0\n`);
6466
+ (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) && console.log(), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.greet(` Rsbuild v1.2.0-beta.1\n`);
6443
6467
  }();
6444
6468
  try {
6445
6469
  !function() {
6446
6470
  let cli = cac_dist('rsbuild');
6447
- cli.help(), cli.version("1.2.0-beta.0"), applyCommonOptions(cli);
6471
+ cli.help(), cli.version("1.2.0-beta.1"), applyCommonOptions(cli);
6448
6472
  let devCommand = cli.command('dev', 'starting the dev server'), buildCommand = cli.command('build', 'build the app for production'), previewCommand = cli.command('preview', 'preview the production build locally'), inspectCommand = cli.command('inspect', 'inspect the Rspack and Rsbuild configs');
6449
6473
  applyServerOptions(devCommand), applyServerOptions(previewCommand), devCommand.action(async (options)=>{
6450
6474
  try {
@@ -6495,6 +6519,6 @@ async function runCLI() {
6495
6519
  __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error('Failed to start Rsbuild CLI.'), __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger.error(err);
6496
6520
  }
6497
6521
  }
6498
- let src_version = "1.2.0-beta.0";
6522
+ let src_version = "1.2.0-beta.1";
6499
6523
  var __webpack_exports__logger = __WEBPACK_EXTERNAL_MODULE__compiled_rslog_index_js_c302f6e3__.logger, __webpack_exports__rspack = __WEBPACK_EXTERNAL_MODULE__rspack_core_e0096ff7__.rspack;
6500
6524
  export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defineConfig, ensureAssetPrefix, config_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, runCLI, src_version as version, __webpack_exports__logger as logger, __webpack_exports__rspack as rspack };
@@ -10,4 +10,4 @@ export declare const findExists: (files: string[]) => string | false;
10
10
  export declare function pathExists(path: string): Promise<boolean>;
11
11
  export declare function isFileExists(file: string): Promise<boolean>;
12
12
  export declare function fileExistsByCompilation({ inputFileSystem }: Rspack.Compilation, filePath: string): Promise<boolean>;
13
- export declare function emptyDir(dir: string): Promise<void>;
13
+ export declare function emptyDir(dir: string, keep?: RegExp[], checkExists?: boolean): Promise<void>;
@@ -15,5 +15,6 @@ export { logger } from './logger';
15
15
  export { mergeRsbuildConfig } from './mergeConfig';
16
16
  export { ensureAssetPrefix } from './helpers';
17
17
  export { PLUGIN_SWC_NAME, PLUGIN_CSS_NAME } from './constants';
18
- export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, CacheGroup, CacheGroups, Charset, ClientConfig, CliShortcut, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InternalContext, LegalComments, ManifestData, ManifestConfig, ManifestObjectConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigFn, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterEnvironmentCompileFn, OnBeforeEnvironmentCompileFn, OnCloseBuildFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PreloadIncludeType, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProxyConfig, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildProviderHelpers, RsbuildTarget, RspackChain, RspackRule, StartDevServerOptions, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, TransformContext, TransformDescriptor, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
18
+ export type { AppIcon, AppIconItem, AliasStrategy, Build, BuildOptions, BundlerPluginInstance, CacheGroup, CacheGroups, Charset, ClientConfig, CliShortcut, CleanDistPath, CleanDistPathObject, ConfigChain, ConfigChainWithContext, ConsoleType, CreateCompiler, CreateRsbuildOptions, CrossOrigin, CSSLoaderOptions, CSSModules, CSSModulesLocalsConvention, DataUriLimit, Decorators, DevConfig, DistPathConfig, EnvironmentContext, EnvironmentConfig, FilenameConfig, HistoryApiFallbackContext, HistoryApiFallbackOptions, HtmlConfig, HtmlRspackPlugin, HtmlBasicTag, HtmlFallback, HtmlTagHandler, HtmlTagDescriptor, HtmlTagContext, InspectConfigOptions, InspectConfigResult, InlineChunkConfig, InlineChunkTest, InlineChunkTestFunction, InternalContext, LegalComments, ManifestData, ManifestConfig, ManifestObjectConfig, MetaAttrs, MetaOptions, Minify, ModifyBundlerChainFn, ModifyBundlerChainUtils, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyEnvironmentConfigUtils, ModifyHTMLTagsContext, ModifyHTMLTagsFn, ModifyRsbuildConfigUtils, ModifyRspackConfigFn, ModifyRspackConfigUtils, ModifyRsbuildConfigFn, ModifyWebpackChainFn, ModifyWebpackChainUtils, ModifyWebpackConfigFn, ModifyWebpackConfigUtils, ModuleFederationConfig, MergedEnvironmentConfig, NormalizedConfig, NormalizedDevConfig, NormalizedEnvironmentConfig, NormalizedHtmlConfig, NormalizedModuleFederationConfig, NormalizedOutputConfig, NormalizedPerformanceConfig, NormalizedSecurityConfig, NormalizedServerConfig, NormalizedSourceConfig, NormalizedToolsConfig, OnAfterEnvironmentCompileFn, OnBeforeEnvironmentCompileFn, OnCloseBuildFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn, OutputConfig, OutputStructure, PreloadIncludeType, PerformanceConfig, PluginManager, Polyfill, PostCSSLoaderOptions, PostCSSOptions, PostCSSPlugin, PreviewOptions, PreconnectOption, ProxyConfig, ProxyOptions, PrintUrls, PublicDir, PublicDirOptions, ProgressBarConfig, RequestHandler, ResolvedCreateRsbuildOptions, RsbuildConfig, RsbuildContext, RsbuildEntry, RsbuildEntryDescription, RsbuildInstance, RsbuildMode, RsbuildPlugin, RsbuildPluginAPI, RsbuildPlugins, RsbuildProvider, RsbuildProviderHelpers, RsbuildTarget, RspackChain, RspackRule, StartDevServerOptions, SriOptions, SriAlgorithm, ScriptInject, ScriptLoading, SecurityConfig, SourceMap, SetupMiddlewaresFn, SetupMiddlewaresServer, ServerConfig, SourceConfig, SplitChunks, StyleLoaderOptions, TransformContext, TransformDescriptor, ToolsConfig, TransformFn, TransformHandler, TransformImport, WatchFiles, } from './types';
19
19
  export type { ChainIdentifier } from './configChain';
20
+ export type { RsbuildDevServer } from './server/devServer';
@@ -737,6 +737,20 @@ export type ManifestObjectConfig = {
737
737
  filter?: (file: FileDescriptor) => boolean;
738
738
  };
739
739
  export type ManifestConfig = string | boolean | ManifestObjectConfig;
740
+ export type CleanDistPathObject = {
741
+ /**
742
+ * Whether to clean up all files under the output directory before the build starts.
743
+ * @default 'auto'
744
+ */
745
+ enable?: boolean | 'auto';
746
+ /**
747
+ * Specify the files to keep in the output directory.
748
+ * If the file's absolute path matches the regular expression in `keep`, the file will not be removed.
749
+ * @default undefined
750
+ */
751
+ keep?: RegExp[];
752
+ };
753
+ export type CleanDistPath = boolean | 'auto' | CleanDistPathObject;
740
754
  export interface OutputConfig {
741
755
  /**
742
756
  * Specify build target to run in specified environment.
@@ -792,10 +806,10 @@ export interface OutputConfig {
792
806
  */
793
807
  legalComments?: LegalComments;
794
808
  /**
795
- * Whether to clean all files in the dist path before starting compilation.
809
+ * Whether to clean up all files under the output directory before the build starts.
796
810
  * @default 'auto'
797
811
  */
798
- cleanDistPath?: boolean | 'auto';
812
+ cleanDistPath?: CleanDistPath;
799
813
  /**
800
814
  * Allow to custom CSS Modules options.
801
815
  */
@@ -882,6 +896,7 @@ export interface NormalizedOutputConfig extends OutputConfig {
882
896
  js?: Rspack.Configuration['devtool'];
883
897
  css: boolean;
884
898
  };
899
+ cleanDistPath: CleanDistPath;
885
900
  filenameHash: boolean | string;
886
901
  assetPrefix: string;
887
902
  dataUriLimit: number | NormalizedDataUriLimit;
@@ -229,6 +229,17 @@ export type TransformDescriptor = {
229
229
  * @see https://rspack.dev/config/module#ruleissuerlayer
230
230
  */
231
231
  issuerLayer?: string;
232
+ /**
233
+ * Matches all modules that match this resource, and will match against Resource
234
+ * (the absolute path without query and fragment) of the module that issued the current module.
235
+ * @see https://rspack.dev/config/module#ruleissuer
236
+ */
237
+ issuer?: Rspack.RuleSetCondition;
238
+ /**
239
+ * `with` can be used in conjunction with [import attributes](https://github.com/tc39/proposal-import-attributes).
240
+ * @see https://rspack.dev/config/module#rulewith
241
+ */
242
+ with?: Record<string, Rspack.RuleSetCondition>;
232
243
  };
233
244
  export type TransformFn = (descriptor: TransformDescriptor, handler: TransformHandler) => void;
234
245
  export type ProcessAssetsStage = 'additional' | 'pre-process' | 'derived' | 'additions' | 'none' | 'optimize' | 'optimize-count' | 'optimize-compatibility' | 'optimize-size' | 'dev-tooling' | 'optimize-inline' | 'summarize' | 'optimize-hash' | 'optimize-transfer' | 'analyse' | 'report';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.2.0-beta.0",
3
+ "version": "1.2.0-beta.1",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -49,10 +49,10 @@
49
49
  "@rspack/core": "1.2.0-beta.0",
50
50
  "@rspack/lite-tapable": "~1.0.1",
51
51
  "@swc/helpers": "^0.5.15",
52
- "core-js": "~3.39.0"
52
+ "core-js": "~3.40.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@rslib/core": "0.3.0",
55
+ "@rslib/core": "0.3.1",
56
56
  "@types/connect": "3.4.38",
57
57
  "@types/node": "^22.10.5",
58
58
  "@types/on-finished": "2.3.4",
@@ -76,7 +76,7 @@
76
76
  "on-finished": "2.4.1",
77
77
  "open": "^8.4.0",
78
78
  "picocolors": "^1.1.1",
79
- "postcss": "^8.4.49",
79
+ "postcss": "^8.5.1",
80
80
  "postcss-load-config": "6.0.1",
81
81
  "postcss-loader": "8.1.1",
82
82
  "prebundle": "1.2.5",
@@ -88,7 +88,7 @@
88
88
  "sirv": "^3.0.0",
89
89
  "style-loader": "3.3.4",
90
90
  "tinyglobby": "^0.2.10",
91
- "typescript": "^5.7.2",
91
+ "typescript": "^5.7.3",
92
92
  "webpack": "^5.97.1",
93
93
  "webpack-bundle-analyzer": "^4.10.2",
94
94
  "webpack-merge": "6.0.1",