@rsbuild/webpack 1.6.0-beta.1 → 1.6.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.
@@ -1,8 +1,10 @@
1
- export const __webpack_id__ = "0";
2
- export const __webpack_ids__ = [
3
- "0"
4
- ];
5
- export const __webpack_modules__ = {
1
+ import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
2
+ import { __webpack_require__ } from "./rslib-runtime.js";
3
+ import picocolors from "picocolors";
4
+ import webpack from "webpack";
5
+ import { Console } from "node:console";
6
+ import { logger } from "./index.js";
7
+ __webpack_require__.add({
6
8
  "../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js": function(module) {
7
9
  let ansiEscapes = module.exports;
8
10
  module.exports.default = ansiEscapes;
@@ -81,7 +83,7 @@ export const __webpack_modules__ = {
81
83
  };
82
84
  Object.defineProperty(module, 'exports', {
83
85
  enumerable: !0,
84
- get: function() {
86
+ get: function assembleStyles() {
85
87
  let codes = new Map(), styles = {
86
88
  modifier: {
87
89
  reset: [
@@ -412,6 +414,9 @@ export const __webpack_modules__ = {
412
414
  value: labels
413
415
  });
414
416
  }
417
+ function comparativeDistance(x, y) {
418
+ return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
419
+ }
415
420
  convert.rgb.hsl = function(rgb) {
416
421
  let h, r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255, min = Math.min(r, g, b), max = Math.max(r, g, b), delta = max - min;
417
422
  max === min ? h = 0 : r === max ? h = (g - b) / delta : g === max ? h = 2 + (b - r) / delta : b === max && (h = 4 + (r - g) / delta), (h = Math.min(60 * h, 360)) < 0 && (h += 360);
@@ -450,7 +455,7 @@ export const __webpack_modules__ = {
450
455
  if (reversed) return reversed;
451
456
  let currentClosestDistance = 1 / 0;
452
457
  for (let keyword of Object.keys(cssKeywords)){
453
- let value = cssKeywords[keyword], distance = (rgb[0] - value[0]) ** 2 + (rgb[1] - value[1]) ** 2 + (rgb[2] - value[2]) ** 2;
458
+ let distance = comparativeDistance(rgb, cssKeywords[keyword]);
454
459
  distance < currentClosestDistance && (currentClosestDistance = distance, currentClosestKeyword = keyword);
455
460
  }
456
461
  return currentClosestKeyword;
@@ -814,6 +819,24 @@ export const __webpack_modules__ = {
814
819
  },
815
820
  "../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
816
821
  let conversions = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js"), route = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js"), convert = {};
822
+ function wrapRaw(fn) {
823
+ let wrappedFn = function(...args) {
824
+ let arg0 = args[0];
825
+ return null == arg0 ? arg0 : (arg0.length > 1 && (args = arg0), fn(args));
826
+ };
827
+ return 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn;
828
+ }
829
+ function wrapRounded(fn) {
830
+ let wrappedFn = function(...args) {
831
+ let arg0 = args[0];
832
+ if (null == arg0) return arg0;
833
+ arg0.length > 1 && (args = arg0);
834
+ let result = fn(args);
835
+ if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
836
+ return result;
837
+ };
838
+ return 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn;
839
+ }
817
840
  Object.keys(conversions).forEach((fromModel)=>{
818
841
  convert[fromModel] = {}, Object.defineProperty(convert[fromModel], 'channels', {
819
842
  value: conversions[fromModel].channels
@@ -822,58 +845,52 @@ export const __webpack_modules__ = {
822
845
  });
823
846
  let routes = route(fromModel);
824
847
  Object.keys(routes).forEach((toModel)=>{
825
- let wrappedFn, wrappedFn1, fn = routes[toModel];
826
- convert[fromModel][toModel] = (wrappedFn = function(...args) {
827
- let arg0 = args[0];
828
- if (null == arg0) return arg0;
829
- arg0.length > 1 && (args = arg0);
830
- let result = fn(args);
831
- if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
832
- return result;
833
- }, 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn), convert[fromModel][toModel].raw = (wrappedFn1 = function(...args) {
834
- let arg0 = args[0];
835
- return null == arg0 ? arg0 : (arg0.length > 1 && (args = arg0), fn(args));
836
- }, 'conversion' in fn && (wrappedFn1.conversion = fn.conversion), wrappedFn1);
848
+ let fn = routes[toModel];
849
+ convert[fromModel][toModel] = wrapRounded(fn), convert[fromModel][toModel].raw = wrapRaw(fn);
837
850
  });
838
851
  }), module.exports = convert;
839
852
  },
840
853
  "../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js": function(module, __unused_webpack_exports, __webpack_require__) {
841
854
  let conversions = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js");
842
- module.exports = function(fromModel) {
843
- let graph = function(fromModel) {
844
- let graph = function() {
845
- let graph = {}, models = Object.keys(conversions);
846
- for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
847
- distance: -1,
848
- parent: null
849
- };
850
- return graph;
851
- }(), queue = [
852
- fromModel
853
- ];
854
- for(graph[fromModel].distance = 0; queue.length;){
855
- let current = queue.pop(), adjacents = Object.keys(conversions[current]);
856
- for(let len = adjacents.length, i = 0; i < len; i++){
857
- let adjacent = adjacents[i], node = graph[adjacent];
858
- -1 === node.distance && (node.distance = graph[current].distance + 1, node.parent = current, queue.unshift(adjacent));
859
- }
855
+ function buildGraph() {
856
+ let graph = {}, models = Object.keys(conversions);
857
+ for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
858
+ distance: -1,
859
+ parent: null
860
+ };
861
+ return graph;
862
+ }
863
+ function deriveBFS(fromModel) {
864
+ let graph = buildGraph(), queue = [
865
+ fromModel
866
+ ];
867
+ for(graph[fromModel].distance = 0; queue.length;){
868
+ let current = queue.pop(), adjacents = Object.keys(conversions[current]);
869
+ for(let len = adjacents.length, i = 0; i < len; i++){
870
+ let adjacent = adjacents[i], node = graph[adjacent];
871
+ -1 === node.distance && (node.distance = graph[current].distance + 1, node.parent = current, queue.unshift(adjacent));
860
872
  }
861
- return graph;
862
- }(fromModel), conversion = {}, models = Object.keys(graph);
873
+ }
874
+ return graph;
875
+ }
876
+ function link(from, to) {
877
+ return function(args) {
878
+ return to(from(args));
879
+ };
880
+ }
881
+ function wrapConversion(toModel, graph) {
882
+ let path = [
883
+ graph[toModel].parent,
884
+ toModel
885
+ ], fn = conversions[graph[toModel].parent][toModel], cur = graph[toModel].parent;
886
+ for(; graph[cur].parent;)path.unshift(graph[cur].parent), fn = link(conversions[graph[cur].parent][cur], fn), cur = graph[cur].parent;
887
+ return fn.conversion = path, fn;
888
+ }
889
+ module.exports = function(fromModel) {
890
+ let graph = deriveBFS(fromModel), conversion = {}, models = Object.keys(graph);
863
891
  for(let len = models.length, i = 0; i < len; i++){
864
892
  let toModel = models[i];
865
- null !== graph[toModel].parent && (conversion[toModel] = function(toModel, graph) {
866
- let path = [
867
- graph[toModel].parent,
868
- toModel
869
- ], fn = conversions[graph[toModel].parent][toModel], cur = graph[toModel].parent;
870
- for(; graph[cur].parent;)path.unshift(graph[cur].parent), fn = function(from, to) {
871
- return function(args) {
872
- return to(from(args));
873
- };
874
- }(conversions[graph[cur].parent][cur], fn), cur = graph[cur].parent;
875
- return fn.conversion = path, fn;
876
- }(toModel, graph));
893
+ null !== graph[toModel].parent && (conversion[toModel] = wrapConversion(toModel, graph));
877
894
  }
878
895
  return conversion;
879
896
  };
@@ -1736,5 +1753,202 @@ export const __webpack_modules__ = {
1736
1753
  "../../../node_modules/.pnpm/strip-ansi@6.0.1/node_modules/strip-ansi/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
1737
1754
  let ansiRegex = __webpack_require__("../../../node_modules/.pnpm/ansi-regex@5.0.1/node_modules/ansi-regex/index.js");
1738
1755
  module.exports = (string)=>'string' == typeof string ? string.replace(ansiRegex(), '') : string;
1756
+ },
1757
+ stream: function(module) {
1758
+ module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
1759
+ }
1760
+ });
1761
+ let clamp = (x, min, max)=>Math.min(max, Math.max(min, x)), cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js");
1762
+ var cli_truncate_default = __webpack_require__.n(cli_truncate);
1763
+ let defaultOption = {
1764
+ total: 100,
1765
+ current: 0,
1766
+ color: 'green',
1767
+ bgColor: 'gray',
1768
+ char: '━',
1769
+ width: 25,
1770
+ buildIcon: '◯',
1771
+ errorIcon: '✖',
1772
+ errorInfo: 'compile failed',
1773
+ message: '',
1774
+ done: !1,
1775
+ spaceWidth: 1,
1776
+ messageWidth: 25,
1777
+ messageColor: 'gray',
1778
+ id: '',
1779
+ maxIdLen: 16,
1780
+ hasErrors: !1
1781
+ }, ansi_escapes = __webpack_require__("../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js");
1782
+ var ansi_escapes_default = __webpack_require__.n(ansi_escapes);
1783
+ let build = __webpack_require__("../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js");
1784
+ var build_default = __webpack_require__.n(build);
1785
+ let colorList = [
1786
+ 'green',
1787
+ 'cyan',
1788
+ 'yellow',
1789
+ 'blue',
1790
+ 'magenta'
1791
+ ], bus = new class {
1792
+ states = [];
1793
+ log;
1794
+ restore;
1795
+ prevOutput;
1796
+ destroyed = !1;
1797
+ constructor(){
1798
+ var stream;
1799
+ let previousLineCount, previousOutput, render;
1800
+ this.prevOutput = '', this.log = (stream = process.stdout, previousLineCount = 0, previousOutput = '', (render = (str)=>{
1801
+ let output = `${str}\n`;
1802
+ output !== previousOutput && (previousOutput = output, stream.write(ansi_escapes_default().eraseLines(previousLineCount) + output), previousLineCount = output.split('\n').length);
1803
+ }).clear = ()=>{
1804
+ stream.write(ansi_escapes_default().eraseLines(previousLineCount)), previousOutput = '', previousLineCount = 0;
1805
+ }, render.done = ()=>{
1806
+ previousOutput = '', previousLineCount = 0;
1807
+ }, render), console.Console = Console, this.restore = build_default()((type, data)=>{
1808
+ this.writeToStd(type, data);
1809
+ });
1810
+ }
1811
+ update(state) {
1812
+ let index = this.states.findIndex((i)=>i.id === state.id);
1813
+ -1 === index ? this.states.push(state) : this.states[index] = state;
1814
+ }
1815
+ writeToStd(type = 'stdout', data) {
1816
+ this.log.clear(), data && ('stdout' === type ? process.stdout.write(data) : 'stderr' === type && process.stderr.write(data)), this.log(this.prevOutput);
1817
+ }
1818
+ render() {
1819
+ let maxIdLen = Math.max(...this.states.map((i)=>i.id?.length ?? 0)) + 2, { columns = 70 } = process.stdout;
1820
+ this.prevOutput = this.states.map((i, k)=>{
1821
+ let bar = ((option)=>{
1822
+ var id;
1823
+ let left, right, mergedOptions = {
1824
+ ...defaultOption,
1825
+ ...option
1826
+ }, { total, done, buildIcon, errorIcon, errorInfo, width, current, color, bgColor, char, message, messageWidth, spaceWidth, messageColor, maxIdLen, hasErrors } = mergedOptions, space = ' '.repeat(spaceWidth), percent = clamp(Math.floor(current / total * 100), 0, 100), barColor = picocolors[color], backgroundColor = picocolors[bgColor], doneColor = hasErrors ? picocolors.red : barColor, idColor = done ? doneColor : barColor, id1 = mergedOptions.id ? idColor((left = Math.floor((maxIdLen - (id = mergedOptions.id).length) / 2), right = maxIdLen - left - id.length, ' '.repeat(left) + id + ' '.repeat(right))) : '', { columns: terminalWidth = 70 } = process.stdout;
1827
+ if (done) {
1828
+ if (hasErrors) {
1829
+ let message = picocolors.bold(doneColor(errorInfo));
1830
+ return terminalWidth >= 40 ? [
1831
+ idColor(errorIcon),
1832
+ id1,
1833
+ doneColor(`${space}${message}`)
1834
+ ].join('') : [
1835
+ id1,
1836
+ doneColor(`${message}`)
1837
+ ].join('');
1838
+ }
1839
+ return '';
1840
+ }
1841
+ let msgStr = picocolors[messageColor](cli_truncate_default()(message, messageWidth, {
1842
+ position: 'start'
1843
+ })), left1 = clamp(Math.floor(percent * width / 100), 0, width), right1 = clamp(width - left1, 0, width), barStr = `${barColor(char.repeat(left1))}${backgroundColor(char.repeat(right1))}`, percentStr = `${percent.toString().padStart(3)}%`;
1844
+ return terminalWidth >= 70 ? [
1845
+ idColor(buildIcon),
1846
+ id1,
1847
+ space,
1848
+ barStr,
1849
+ space,
1850
+ percentStr,
1851
+ space,
1852
+ msgStr
1853
+ ].join('') : terminalWidth >= 40 ? [
1854
+ idColor(buildIcon),
1855
+ id1,
1856
+ space,
1857
+ barStr,
1858
+ space,
1859
+ percentStr
1860
+ ].join('') : [
1861
+ idColor(buildIcon),
1862
+ id1,
1863
+ space,
1864
+ percentStr
1865
+ ].join('');
1866
+ })({
1867
+ maxIdLen,
1868
+ color: i.color ?? colorList[k % colorList.length],
1869
+ ...i
1870
+ });
1871
+ return bar ? cli_truncate_default()(bar, columns, {
1872
+ position: 'end'
1873
+ }) : null;
1874
+ }).filter((item)=>null !== item).join('\n'), this.writeToStd();
1875
+ }
1876
+ destroy() {
1877
+ this.destroyed || this.restore(), this.destroyed = !0;
1878
+ }
1879
+ clear() {
1880
+ this.log.clear(), this.log.done();
1881
+ }
1882
+ }();
1883
+ function createNonTTYLogger() {
1884
+ let prevPercentage = 0;
1885
+ return {
1886
+ log: ({ id, done, current, hasErrors, compileTime })=>{
1887
+ let suffix = picocolors.gray(`(${id})`);
1888
+ if (done) {
1889
+ if (100 === prevPercentage) return;
1890
+ prevPercentage = 100, hasErrors ? logger.error(`built failed in ${compileTime} ${suffix}`) : logger.ready(`built in ${compileTime} ${suffix}`);
1891
+ } else current - prevPercentage > 10 && (prevPercentage = current, logger.info(`build progress: ${current.toFixed(0)}% ${suffix}`));
1892
+ }
1893
+ };
1894
+ }
1895
+ class ProgressPlugin extends webpack.ProgressPlugin {
1896
+ name = 'ProgressPlugin';
1897
+ id;
1898
+ hasCompileErrors = !1;
1899
+ compileTime = null;
1900
+ prettyTime;
1901
+ constructor(options){
1902
+ let prevPercentage, { id = 'Rsbuild' } = options, nonTTYLogger = createNonTTYLogger(), friendlyPercentage = (prevPercentage = 0, (percentage)=>{
1903
+ if (0 === percentage || 1 === percentage) return prevPercentage = 0, percentage;
1904
+ if (percentage <= prevPercentage) {
1905
+ let step = 0;
1906
+ return prevPercentage < 0.3 ? step = 0.001 : prevPercentage < 0.6 ? step = 0.002 : prevPercentage < 0.8 ? step = 0.004 : prevPercentage < 0.99 && (step = 0.002), prevPercentage += step;
1907
+ }
1908
+ return prevPercentage = percentage, percentage;
1909
+ });
1910
+ super({
1911
+ activeModules: !1,
1912
+ entries: !0,
1913
+ modules: !0,
1914
+ modulesCount: 5000,
1915
+ profile: !1,
1916
+ dependencies: !0,
1917
+ dependenciesCount: 10000,
1918
+ percentBy: null,
1919
+ handler: (originalPercentage, message)=>{
1920
+ let percentage = friendlyPercentage(originalPercentage), done = 1 === percentage;
1921
+ process.stdout.isTTY ? (bus.update({
1922
+ id,
1923
+ current: 100 * percentage,
1924
+ message,
1925
+ done,
1926
+ hasErrors: this.hasCompileErrors
1927
+ }), bus.render()) : nonTTYLogger.log({
1928
+ id,
1929
+ done,
1930
+ current: 100 * percentage,
1931
+ hasErrors: this.hasCompileErrors,
1932
+ compileTime: this.compileTime
1933
+ });
1934
+ }
1935
+ }), this.id = id, this.prettyTime = options.prettyTime;
1936
+ }
1937
+ apply(compiler) {
1938
+ super.apply(compiler);
1939
+ let startTime = null;
1940
+ compiler.hooks.compile.tap(this.name, ()=>{
1941
+ this.compileTime = null, startTime = process.hrtime();
1942
+ }), compiler.hooks.done.tap(this.name, (stat)=>{
1943
+ if (startTime) {
1944
+ this.hasCompileErrors = stat.hasErrors();
1945
+ let hrtime = process.hrtime(startTime), seconds = hrtime[0] + hrtime[1] / 1e9;
1946
+ if (this.compileTime = this.prettyTime(seconds), startTime = null, !this.hasCompileErrors) {
1947
+ let suffix = this.id ? picocolors.gray(` (${this.id})`) : '';
1948
+ logger.ready(`built in ${this.compileTime} ${suffix}`);
1949
+ }
1950
+ }
1951
+ });
1739
1952
  }
1740
- };
1953
+ }
1954
+ export { ProgressPlugin };
package/dist/1~0.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
1
2
  exports.ids = [
2
3
  "0"
3
4
  ], exports.modules = {
@@ -82,7 +83,7 @@ exports.ids = [
82
83
  };
83
84
  Object.defineProperty(module, 'exports', {
84
85
  enumerable: !0,
85
- get: function() {
86
+ get: function assembleStyles() {
86
87
  let codes = new Map(), styles = {
87
88
  modifier: {
88
89
  reset: [
@@ -415,6 +416,9 @@ exports.ids = [
415
416
  value: labels
416
417
  });
417
418
  }
419
+ function comparativeDistance(x, y) {
420
+ return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
421
+ }
418
422
  convert.rgb.hsl = function(rgb) {
419
423
  let h, r = rgb[0] / 255, g = rgb[1] / 255, b = rgb[2] / 255, min = Math.min(r, g, b), max = Math.max(r, g, b), delta = max - min;
420
424
  max === min ? h = 0 : r === max ? h = (g - b) / delta : g === max ? h = 2 + (b - r) / delta : b === max && (h = 4 + (r - g) / delta), (h = Math.min(60 * h, 360)) < 0 && (h += 360);
@@ -453,7 +457,7 @@ exports.ids = [
453
457
  if (reversed) return reversed;
454
458
  let currentClosestDistance = 1 / 0;
455
459
  for (let keyword of Object.keys(cssKeywords)){
456
- let value = cssKeywords[keyword], distance = (rgb[0] - value[0]) ** 2 + (rgb[1] - value[1]) ** 2 + (rgb[2] - value[2]) ** 2;
460
+ let distance = comparativeDistance(rgb, cssKeywords[keyword]);
457
461
  distance < currentClosestDistance && (currentClosestDistance = distance, currentClosestKeyword = keyword);
458
462
  }
459
463
  return currentClosestKeyword;
@@ -817,6 +821,24 @@ exports.ids = [
817
821
  },
818
822
  "../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
819
823
  let conversions = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js"), route = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js"), convert = {};
824
+ function wrapRaw(fn) {
825
+ let wrappedFn = function(...args) {
826
+ let arg0 = args[0];
827
+ return null == arg0 ? arg0 : (arg0.length > 1 && (args = arg0), fn(args));
828
+ };
829
+ return 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn;
830
+ }
831
+ function wrapRounded(fn) {
832
+ let wrappedFn = function(...args) {
833
+ let arg0 = args[0];
834
+ if (null == arg0) return arg0;
835
+ arg0.length > 1 && (args = arg0);
836
+ let result = fn(args);
837
+ if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
838
+ return result;
839
+ };
840
+ return 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn;
841
+ }
820
842
  Object.keys(conversions).forEach((fromModel)=>{
821
843
  convert[fromModel] = {}, Object.defineProperty(convert[fromModel], 'channels', {
822
844
  value: conversions[fromModel].channels
@@ -825,58 +847,52 @@ exports.ids = [
825
847
  });
826
848
  let routes = route(fromModel);
827
849
  Object.keys(routes).forEach((toModel)=>{
828
- let wrappedFn, wrappedFn1, fn = routes[toModel];
829
- convert[fromModel][toModel] = (wrappedFn = function(...args) {
830
- let arg0 = args[0];
831
- if (null == arg0) return arg0;
832
- arg0.length > 1 && (args = arg0);
833
- let result = fn(args);
834
- if ('object' == typeof result) for(let len = result.length, i = 0; i < len; i++)result[i] = Math.round(result[i]);
835
- return result;
836
- }, 'conversion' in fn && (wrappedFn.conversion = fn.conversion), wrappedFn), convert[fromModel][toModel].raw = (wrappedFn1 = function(...args) {
837
- let arg0 = args[0];
838
- return null == arg0 ? arg0 : (arg0.length > 1 && (args = arg0), fn(args));
839
- }, 'conversion' in fn && (wrappedFn1.conversion = fn.conversion), wrappedFn1);
850
+ let fn = routes[toModel];
851
+ convert[fromModel][toModel] = wrapRounded(fn), convert[fromModel][toModel].raw = wrapRaw(fn);
840
852
  });
841
853
  }), module.exports = convert;
842
854
  },
843
855
  "../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js": function(module, __unused_webpack_exports, __webpack_require__) {
844
856
  let conversions = __webpack_require__("../../../node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js");
845
- module.exports = function(fromModel) {
846
- let graph = function(fromModel) {
847
- let graph = function() {
848
- let graph = {}, models = Object.keys(conversions);
849
- for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
850
- distance: -1,
851
- parent: null
852
- };
853
- return graph;
854
- }(), queue = [
855
- fromModel
856
- ];
857
- for(graph[fromModel].distance = 0; queue.length;){
858
- let current = queue.pop(), adjacents = Object.keys(conversions[current]);
859
- for(let len = adjacents.length, i = 0; i < len; i++){
860
- let adjacent = adjacents[i], node = graph[adjacent];
861
- -1 === node.distance && (node.distance = graph[current].distance + 1, node.parent = current, queue.unshift(adjacent));
862
- }
857
+ function buildGraph() {
858
+ let graph = {}, models = Object.keys(conversions);
859
+ for(let len = models.length, i = 0; i < len; i++)graph[models[i]] = {
860
+ distance: -1,
861
+ parent: null
862
+ };
863
+ return graph;
864
+ }
865
+ function deriveBFS(fromModel) {
866
+ let graph = buildGraph(), queue = [
867
+ fromModel
868
+ ];
869
+ for(graph[fromModel].distance = 0; queue.length;){
870
+ let current = queue.pop(), adjacents = Object.keys(conversions[current]);
871
+ for(let len = adjacents.length, i = 0; i < len; i++){
872
+ let adjacent = adjacents[i], node = graph[adjacent];
873
+ -1 === node.distance && (node.distance = graph[current].distance + 1, node.parent = current, queue.unshift(adjacent));
863
874
  }
864
- return graph;
865
- }(fromModel), conversion = {}, models = Object.keys(graph);
875
+ }
876
+ return graph;
877
+ }
878
+ function link(from, to) {
879
+ return function(args) {
880
+ return to(from(args));
881
+ };
882
+ }
883
+ function wrapConversion(toModel, graph) {
884
+ let path = [
885
+ graph[toModel].parent,
886
+ toModel
887
+ ], fn = conversions[graph[toModel].parent][toModel], cur = graph[toModel].parent;
888
+ for(; graph[cur].parent;)path.unshift(graph[cur].parent), fn = link(conversions[graph[cur].parent][cur], fn), cur = graph[cur].parent;
889
+ return fn.conversion = path, fn;
890
+ }
891
+ module.exports = function(fromModel) {
892
+ let graph = deriveBFS(fromModel), conversion = {}, models = Object.keys(graph);
866
893
  for(let len = models.length, i = 0; i < len; i++){
867
894
  let toModel = models[i];
868
- null !== graph[toModel].parent && (conversion[toModel] = function(toModel, graph) {
869
- let path = [
870
- graph[toModel].parent,
871
- toModel
872
- ], fn = conversions[graph[toModel].parent][toModel], cur = graph[toModel].parent;
873
- for(; graph[cur].parent;)path.unshift(graph[cur].parent), fn = function(from, to) {
874
- return function(args) {
875
- return to(from(args));
876
- };
877
- }(conversions[graph[cur].parent][cur], fn), cur = graph[cur].parent;
878
- return fn.conversion = path, fn;
879
- }(toModel, graph));
895
+ null !== graph[toModel].parent && (conversion[toModel] = wrapConversion(toModel, graph));
880
896
  }
881
897
  return conversion;
882
898
  };
package/dist/1~363.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
2
3
  exports.ids = [
3
4
  "363"
4
5
  ], exports.modules = {
@@ -6,7 +7,7 @@ exports.ids = [
6
7
  __webpack_require__.d(__webpack_exports__, {
7
8
  ProgressPlugin: ()=>ProgressPlugin
8
9
  });
9
- var core_ = __webpack_require__("@rsbuild/core"), external_picocolors_ = __webpack_require__("picocolors"), external_picocolors_default = __webpack_require__.n(external_picocolors_), external_webpack_ = __webpack_require__("webpack?2a1e"), external_webpack_default = __webpack_require__.n(external_webpack_), cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js"), cli_truncate_default = __webpack_require__.n(cli_truncate);
10
+ var core_ = __webpack_require__("@rsbuild/core"), external_picocolors_ = __webpack_require__("picocolors"), external_picocolors_default = __webpack_require__.n(external_picocolors_), external_webpack_ = __webpack_require__("webpack"), external_webpack_default = __webpack_require__.n(external_webpack_), cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js"), cli_truncate_default = __webpack_require__.n(cli_truncate);
10
11
  let clamp = (x, min, max)=>Math.min(max, Math.max(min, x)), defaultOption = {
11
12
  total: 100,
12
13
  current: 0,
@@ -126,6 +127,18 @@ exports.ids = [
126
127
  this.log.clear(), this.log.done();
127
128
  }
128
129
  }();
130
+ function createNonTTYLogger() {
131
+ let prevPercentage = 0;
132
+ return {
133
+ log: ({ id, done, current, hasErrors, compileTime })=>{
134
+ let suffix = external_picocolors_default().gray(`(${id})`);
135
+ if (done) {
136
+ if (100 === prevPercentage) return;
137
+ prevPercentage = 100, hasErrors ? core_.logger.error(`built failed in ${compileTime} ${suffix}`) : core_.logger.ready(`built in ${compileTime} ${suffix}`);
138
+ } else current - prevPercentage > 10 && (prevPercentage = current, core_.logger.info(`build progress: ${current.toFixed(0)}% ${suffix}`));
139
+ }
140
+ };
141
+ }
129
142
  class ProgressPlugin extends external_webpack_default().ProgressPlugin {
130
143
  name = 'ProgressPlugin';
131
144
  id;
@@ -133,18 +146,7 @@ exports.ids = [
133
146
  compileTime = null;
134
147
  prettyTime;
135
148
  constructor(options){
136
- const { id = 'Rsbuild' } = options, nonTTYLogger = function() {
137
- let prevPercentage = 0;
138
- return {
139
- log: ({ id, done, current, hasErrors, compileTime })=>{
140
- let suffix = external_picocolors_default().gray(`(${id})`);
141
- if (done) {
142
- if (100 === prevPercentage) return;
143
- prevPercentage = 100, hasErrors ? core_.logger.error(`built failed in ${compileTime} ${suffix}`) : core_.logger.ready(`built in ${compileTime} ${suffix}`);
144
- } else current - prevPercentage > 10 && (prevPercentage = current, core_.logger.info(`build progress: ${current.toFixed(0)}% ${suffix}`));
145
- }
146
- };
147
- }(), friendlyPercentage = (()=>{
149
+ const { id = 'Rsbuild' } = options, nonTTYLogger = createNonTTYLogger(), friendlyPercentage = (()=>{
148
150
  let prevPercentage = 0;
149
151
  return (percentage)=>{
150
152
  if (0 === percentage || 1 === percentage) return prevPercentage = 0, percentage;
package/dist/index.cjs CHANGED
@@ -13,33 +13,8 @@ var __webpack_modules__ = {
13
13
  stream: function(module) {
14
14
  module.exports = require("stream");
15
15
  },
16
- "webpack?2a1e": function(module) {
16
+ webpack: function(module) {
17
17
  module.exports = require("webpack");
18
- },
19
- "copy-webpack-plugin": function(module) {
20
- module.exports = import("copy-webpack-plugin").then(function(module) {
21
- return module;
22
- });
23
- },
24
- "html-webpack-plugin": function(module) {
25
- module.exports = import("html-webpack-plugin").then(function(module) {
26
- return module;
27
- });
28
- },
29
- "mini-css-extract-plugin": function(module) {
30
- module.exports = import("mini-css-extract-plugin").then(function(module) {
31
- return module;
32
- });
33
- },
34
- "tsconfig-paths-webpack-plugin": function(module) {
35
- module.exports = import("tsconfig-paths-webpack-plugin").then(function(module) {
36
- return module;
37
- });
38
- },
39
- "webpack?5a4d": function(module) {
40
- module.exports = import("webpack").then(function(module) {
41
- return module;
42
- });
43
18
  }
44
19
  }, __webpack_module_cache__ = {};
45
20
  function __webpack_require__(moduleId) {
@@ -120,10 +95,10 @@ for(var __webpack_i__ in (()=>{
120
95
  mergeFn: utils.mergeConfig
121
96
  })), core_.logger.debug('modify webpack config done'), modifiedConfig;
122
97
  }
123
- async function getChainUtils(target, environment, helpers) {
124
- let { default: webpack } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "webpack?5a4d"));
98
+ async function getChainUtils(target, environment, environments, helpers) {
99
+ let { default: webpack } = await import("webpack");
125
100
  return {
126
- ...helpers.getChainUtils(target, environment),
101
+ ...helpers.getChainUtils(target, environment, environments),
127
102
  name: ({
128
103
  web: 'client',
129
104
  node: 'server',
@@ -134,7 +109,7 @@ for(var __webpack_i__ in (()=>{
134
109
  };
135
110
  }
136
111
  async function generateWebpackConfig({ target, context, environment, helpers }) {
137
- let chainUtils = await getChainUtils(target, context.environments[environment], helpers), { default: webpack } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "webpack?5a4d")), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
112
+ let chainUtils = await getChainUtils(target, context.environments[environment], context.environments, helpers), { default: webpack } = await import("webpack"), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
138
113
  ...chainUtils,
139
114
  bundler: {
140
115
  BannerPlugin,
@@ -186,7 +161,7 @@ for(var __webpack_i__ in (()=>{
186
161
  bundlerConfigs: webpackConfigs,
187
162
  environments: context.environments
188
163
  });
189
- let { default: webpack } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "webpack?5a4d")), compiler = webpack(1 === webpackConfigs.length ? webpackConfigs[0] : webpackConfigs);
164
+ let { default: webpack } = await import("webpack"), compiler = webpack(1 === webpackConfigs.length ? webpackConfigs[0] : webpackConfigs);
190
165
  return compiler.hooks.run.tap(HOOK_NAME, ()=>{
191
166
  context.buildState.status = 'building';
192
167
  }), compiler.hooks.watchRun.tap(HOOK_NAME, ()=>{
@@ -249,7 +224,7 @@ for(var __webpack_i__ in (()=>{
249
224
  }, external_node_fs_namespaceObject = require("node:fs");
250
225
  var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
251
226
  async function applyTsConfigPathsPlugin({ chain, CHAIN_ID, mainFields, extensions, configFile }) {
252
- let { TsconfigPathsPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "tsconfig-paths-webpack-plugin"));
227
+ let { TsconfigPathsPlugin } = await import("tsconfig-paths-webpack-plugin");
253
228
  chain.resolve.plugin(CHAIN_ID.RESOLVE_PLUGIN.TS_CONFIG_PATHS).use(TsconfigPathsPlugin, [
254
229
  {
255
230
  configFile,
@@ -258,10 +233,13 @@ for(var __webpack_i__ in (()=>{
258
233
  }
259
234
  ]);
260
235
  }
236
+ function isWebTarget(target) {
237
+ return castArray(target).includes('web') || target.includes('web-worker');
238
+ }
261
239
  let webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers })=>{
262
- let helpers1, { default: cssExtractPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "mini-css-extract-plugin"));
240
+ let helpers1, { default: cssExtractPlugin } = await import("mini-css-extract-plugin");
263
241
  if (helpers.setCssExtractPlugin(cssExtractPlugin), helpers.setHTMLPlugin) {
264
- let { default: htmlPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "html-webpack-plugin"));
242
+ let { default: htmlPlugin } = await import("html-webpack-plugin");
265
243
  helpers.setHTMLPlugin(htmlPlugin);
266
244
  }
267
245
  let createCompiler = async ()=>(await createCompiler_createCompiler({
@@ -275,13 +253,13 @@ for(var __webpack_i__ in (()=>{
275
253
  name: 'rsbuild-webpack:adaptor',
276
254
  setup (api) {
277
255
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target })=>{
278
- var chain1, target1, target2;
256
+ var chain1, target1;
279
257
  let mainFields, { config, tsconfigPath } = environment, aliasStrategy = config.source.aliasStrategy ?? config.resolve.aliasStrategy;
280
258
  tsconfigPath && 'prefer-tsconfig' === aliasStrategy && await applyTsConfigPathsPlugin({
281
259
  chain,
282
260
  CHAIN_ID,
283
261
  configFile: tsconfigPath,
284
- mainFields: (chain1 = chain, target1 = target, (mainFields = chain1.resolve.mainFields.values()).length ? mainFields : castArray(target2 = target1).includes('web') || target2.includes('web-worker') ? [
262
+ mainFields: (chain1 = chain, target1 = target, (mainFields = chain1.resolve.mainFields.values()).length ? mainFields : isWebTarget(target1) ? [
285
263
  'browser',
286
264
  'module',
287
265
  'main'
@@ -307,7 +285,7 @@ for(var __webpack_i__ in (()=>{
307
285
  }
308
286
  let { copy } = config.output;
309
287
  if (copy) {
310
- let { default: CopyPlugin } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "copy-webpack-plugin")), options = Array.isArray(copy) ? {
288
+ let { default: CopyPlugin } = await import("copy-webpack-plugin"), options = Array.isArray(copy) ? {
311
289
  patterns: copy
312
290
  } : copy;
313
291
  chain.plugin(CHAIN_ID.PLUGIN.COPY).use(CopyPlugin, [
package/dist/index.js CHANGED
@@ -1,61 +1,12 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__ from "@rsbuild/core";
1
+ import { logger } from "@rsbuild/core";
2
2
  import MultiStats from "webpack/lib/MultiStats.js";
3
3
  import { reduceConfigsWithContext } from "reduce-configs";
4
4
  import node_fs from "node:fs";
5
- var installedChunks, installChunk, __webpack_modules__ = {
6
- "@rsbuild/core": function(module) {
7
- module.exports = __WEBPACK_EXTERNAL_MODULE__rsbuild_core_1b356efc__;
8
- }
9
- }, __webpack_module_cache__ = {};
10
- function __webpack_require__(moduleId) {
11
- var cachedModule = __webpack_module_cache__[moduleId];
12
- if (void 0 !== cachedModule) return cachedModule.exports;
13
- var module = __webpack_module_cache__[moduleId] = {
14
- id: moduleId,
15
- loaded: !1,
16
- exports: {}
17
- };
18
- return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.loaded = !0, module.exports;
19
- }
20
- __webpack_require__.m = __webpack_modules__, __webpack_require__.n = (module)=>{
21
- var getter = module && module.__esModule ? ()=>module.default : ()=>module;
22
- return __webpack_require__.d(getter, {
23
- a: getter
24
- }), getter;
25
- }, __webpack_require__.d = (exports, definition)=>{
26
- for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
27
- enumerable: !0,
28
- get: definition[key]
29
- });
30
- }, __webpack_require__.f = {}, __webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>(__webpack_require__.f[key](chunkId, promises), promises), [])), __webpack_require__.u = (chunkId)=>"0~" + chunkId + ".js", __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.nmd = (module)=>(module.paths = [], module.children || (module.children = []), module), installedChunks = {
31
- 410: 0
32
- }, installChunk = (data)=>{
33
- var moduleId, chunkId, __webpack_ids__ = data.__webpack_ids__, __webpack_modules__ = data.__webpack_modules__, __webpack_runtime__ = data.__webpack_runtime__, i = 0;
34
- for(moduleId in __webpack_modules__)__webpack_require__.o(__webpack_modules__, moduleId) && (__webpack_require__.m[moduleId] = __webpack_modules__[moduleId]);
35
- for(__webpack_runtime__ && __webpack_runtime__(__webpack_require__); i < __webpack_ids__.length; i++)chunkId = __webpack_ids__[i], __webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId] && installedChunks[chunkId][0](), installedChunks[__webpack_ids__[i]] = 0;
36
- }, __webpack_require__.f.j = function(chunkId, promises) {
37
- var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
38
- if (0 !== installedChunkData) if (installedChunkData) promises.push(installedChunkData[1]);
39
- else {
40
- var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, (e)=>{
41
- throw 0 !== installedChunks[chunkId] && (installedChunks[chunkId] = void 0), e;
42
- }), promise = Promise.race([
43
- promise,
44
- new Promise((resolve)=>{
45
- installedChunkData = installedChunks[chunkId] = [
46
- resolve
47
- ];
48
- })
49
- ]);
50
- promises.push(installedChunkData[1] = promise);
51
- }
52
- };
53
- var core_ = __webpack_require__("@rsbuild/core");
54
5
  let castArray = (arr)=>void 0 === arr ? [] : Array.isArray(arr) ? arr : [
55
6
  arr
56
7
  ];
57
8
  async function modifyWebpackChain(context, utils, chain) {
58
- core_.logger.debug('modify webpack chain');
9
+ logger.debug('modify webpack chain');
59
10
  let [modifiedChain] = await context.hooks.modifyWebpackChain.callChain({
60
11
  environment: utils.environment.name,
61
12
  args: [
@@ -64,10 +15,10 @@ async function modifyWebpackChain(context, utils, chain) {
64
15
  ]
65
16
  });
66
17
  if (utils.environment.config.tools?.webpackChain) for (let item of castArray(utils.environment.config.tools.webpackChain))item(modifiedChain, utils);
67
- return core_.logger.debug('modify webpack chain done'), modifiedChain;
18
+ return logger.debug('modify webpack chain done'), modifiedChain;
68
19
  }
69
20
  async function modifyWebpackConfig(context, webpackConfig, utils) {
70
- core_.logger.debug('modify webpack config');
21
+ logger.debug('modify webpack config');
71
22
  let [modifiedConfig] = await context.hooks.modifyWebpackConfig.callChain({
72
23
  environment: utils.environment.name,
73
24
  args: [
@@ -80,12 +31,12 @@ async function modifyWebpackConfig(context, webpackConfig, utils) {
80
31
  config: utils.environment.config.tools.webpack,
81
32
  ctx: utils,
82
33
  mergeFn: utils.mergeConfig
83
- })), core_.logger.debug('modify webpack config done'), modifiedConfig;
34
+ })), logger.debug('modify webpack config done'), modifiedConfig;
84
35
  }
85
- async function getChainUtils(target, environment, helpers) {
36
+ async function getChainUtils(target, environment, environments, helpers) {
86
37
  let { default: webpack } = await import("webpack");
87
38
  return {
88
- ...helpers.getChainUtils(target, environment),
39
+ ...helpers.getChainUtils(target, environment, environments),
89
40
  name: ({
90
41
  web: 'client',
91
42
  node: 'server',
@@ -96,7 +47,7 @@ async function getChainUtils(target, environment, helpers) {
96
47
  };
97
48
  }
98
49
  async function generateWebpackConfig({ target, context, environment, helpers }) {
99
- let chainUtils = await getChainUtils(target, context.environments[environment], helpers), { default: webpack } = await import("webpack"), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
50
+ let chainUtils = await getChainUtils(target, context.environments[environment], context.environments, helpers), { default: webpack } = await import("webpack"), { BannerPlugin, DefinePlugin, IgnorePlugin, ProvidePlugin, SourceMapDevToolPlugin, HotModuleReplacementPlugin } = webpack, bundlerChain = await helpers.modifyBundlerChain(context, {
100
51
  ...chainUtils,
101
52
  bundler: {
102
53
  BannerPlugin,
@@ -119,7 +70,7 @@ async function initConfigs({ context, pluginManager, rsbuildOptions, helpers })
119
70
  environment,
120
71
  helpers
121
72
  })));
122
- if ('verbose' === core_.logger.level) {
73
+ if ('verbose' === logger.level) {
123
74
  let inspect = async ()=>{
124
75
  await helpers.inspectConfig({
125
76
  context,
@@ -142,7 +93,7 @@ async function initConfigs({ context, pluginManager, rsbuildOptions, helpers })
142
93
  };
143
94
  }
144
95
  async function createCompiler_createCompiler(options) {
145
- core_.logger.debug('creating compiler');
96
+ logger.debug('creating compiler');
146
97
  let HOOK_NAME = 'rsbuild:compiler', { helpers, context } = options, { webpackConfigs } = await initConfigs(options);
147
98
  await context.hooks.onBeforeCreateCompiler.callBatch({
148
99
  bundlerConfigs: webpackConfigs,
@@ -159,7 +110,7 @@ async function createCompiler_createCompiler(options) {
159
110
  let stats = helpers.getRsbuildStats(statsInstance, compiler, context.action), hasErrors = statsInstance.hasErrors();
160
111
  context.buildState.stats = stats, context.buildState.status = 'done', context.buildState.hasErrors = hasErrors, context.socketServer?.onBuildDone();
161
112
  let { message, level } = helpers.formatStats(stats, hasErrors);
162
- 'error' === level ? core_.logger.error(message) : 'warning' === level && core_.logger.warn(message);
113
+ 'error' === level ? logger.error(message) : 'warning' === level && logger.warn(message);
163
114
  }), 'dev' === context.action && helpers.registerDevHook({
164
115
  compiler,
165
116
  context,
@@ -168,7 +119,7 @@ async function createCompiler_createCompiler(options) {
168
119
  }), await context.hooks.onAfterCreateCompiler.callBatch({
169
120
  compiler,
170
121
  environments: context.environments
171
- }), core_.logger.debug('compiler created'), {
122
+ }), logger.debug('compiler created'), {
172
123
  compiler,
173
124
  webpackConfigs
174
125
  };
@@ -187,7 +138,7 @@ let build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
187
138
  isWatch: !!watch,
188
139
  MultiStatsCtor: MultiStats
189
140
  }), watch) return compiler.watch({}, (err)=>{
190
- err && core_.logger.error(err);
141
+ err && logger.error(err);
191
142
  }), {
192
143
  close: ()=>new Promise((resolve)=>{
193
144
  compiler.close(()=>{
@@ -198,7 +149,7 @@ let build = async (initOptions, { watch, compiler: customCompiler } = {})=>{
198
149
  let { stats } = await new Promise((resolve, reject)=>{
199
150
  compiler.run((err, stats)=>{
200
151
  err ? reject(err) : context.buildState.hasErrors ? reject(Error('webpack build failed.')) : compiler.close((closeErr)=>{
201
- closeErr && core_.logger.error(closeErr), resolve({
152
+ closeErr && logger.error(closeErr), resolve({
202
153
  stats
203
154
  });
204
155
  });
@@ -219,6 +170,9 @@ async function applyTsConfigPathsPlugin({ chain, CHAIN_ID, mainFields, extension
219
170
  }
220
171
  ]);
221
172
  }
173
+ function isWebTarget(target) {
174
+ return castArray(target).includes('web') || target.includes('web-worker');
175
+ }
222
176
  let webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers })=>{
223
177
  let { default: cssExtractPlugin } = await import("mini-css-extract-plugin");
224
178
  if (helpers.setCssExtractPlugin(cssExtractPlugin), helpers.setHTMLPlugin) {
@@ -236,30 +190,26 @@ let webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers }
236
190
  name: 'rsbuild-webpack:adaptor',
237
191
  setup (api) {
238
192
  api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target })=>{
239
- let { config, tsconfigPath } = environment, aliasStrategy = config.source.aliasStrategy ?? config.resolve.aliasStrategy;
193
+ let mainFields, { config, tsconfigPath } = environment, aliasStrategy = config.source.aliasStrategy ?? config.resolve.aliasStrategy;
240
194
  tsconfigPath && 'prefer-tsconfig' === aliasStrategy && await applyTsConfigPathsPlugin({
241
195
  chain,
242
196
  CHAIN_ID,
243
197
  configFile: tsconfigPath,
244
- mainFields: ((chain, target)=>{
245
- let mainFields = chain.resolve.mainFields.values();
246
- return mainFields.length ? mainFields : castArray(target).includes('web') || target.includes('web-worker') ? [
247
- 'browser',
248
- 'module',
249
- 'main'
250
- ] : [
251
- 'module',
252
- 'main'
253
- ];
254
- })(chain, target),
198
+ mainFields: (mainFields = chain.resolve.mainFields.values()).length ? mainFields : isWebTarget(target) ? [
199
+ 'browser',
200
+ 'module',
201
+ 'main'
202
+ ] : [
203
+ 'module',
204
+ 'main'
205
+ ],
255
206
  extensions: chain.resolve.extensions.values()
256
207
  });
257
208
  let { progressBar } = config.dev;
258
209
  if (progressBar) {
259
- let { ProgressPlugin } = await Promise.all([
260
- __webpack_require__.e("0"),
261
- __webpack_require__.e("502")
262
- ]).then(__webpack_require__.bind(__webpack_require__, "./src/progress/ProgressPlugin.ts"));
210
+ let { ProgressPlugin } = await import("./0~24.js").then((mod)=>({
211
+ ProgressPlugin: mod.ProgressPlugin
212
+ }));
263
213
  chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [
264
214
  {
265
215
  id: environment.name,
@@ -341,4 +291,4 @@ let webpackProvider = async ({ context, pluginManager, rsbuildOptions, helpers }
341
291
  }
342
292
  };
343
293
  };
344
- export { webpackProvider };
294
+ export { logger, webpackProvider };
@@ -0,0 +1,25 @@
1
+ var __webpack_modules__ = {}, __webpack_module_cache__ = {};
2
+ function __webpack_require__(moduleId) {
3
+ var cachedModule = __webpack_module_cache__[moduleId];
4
+ if (void 0 !== cachedModule) return cachedModule.exports;
5
+ var module = __webpack_module_cache__[moduleId] = {
6
+ id: moduleId,
7
+ loaded: !1,
8
+ exports: {}
9
+ };
10
+ return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.loaded = !0, module.exports;
11
+ }
12
+ __webpack_require__.m = __webpack_modules__, __webpack_require__.add = function registerModules(modules) {
13
+ Object.assign(__webpack_require__.m, modules);
14
+ }, __webpack_require__.n = (module)=>{
15
+ var getter = module && module.__esModule ? ()=>module.default : ()=>module;
16
+ return __webpack_require__.d(getter, {
17
+ a: getter
18
+ }), getter;
19
+ }, __webpack_require__.d = (exports, definition)=>{
20
+ for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
21
+ enumerable: !0,
22
+ get: definition[key]
23
+ });
24
+ }, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.nmd = (module)=>(module.paths = [], module.children || (module.children = []), module);
25
+ export { __webpack_require__ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/webpack",
3
- "version": "1.6.0-beta.1",
3
+ "version": "1.6.1",
4
4
  "homepage": "https://rsbuild.rs",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,14 +32,14 @@
32
32
  "webpack": "^5.102.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@rslib/core": "0.15.1",
36
- "@types/node": "^22.18.12",
35
+ "@rslib/core": "0.17.1",
36
+ "@types/node": "^24.9.2",
37
37
  "ansi-escapes": "4.3.2",
38
38
  "cli-truncate": "2.1.0",
39
39
  "patch-console": "1.0.0",
40
40
  "typescript": "^5.9.3",
41
41
  "@scripts/test-helper": "1.0.1",
42
- "@rsbuild/core": "1.6.0-beta.1"
42
+ "@rsbuild/core": "1.6.4"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "@rsbuild/core": "^1.3.21"
package/dist/0~502.js DELETED
@@ -1,204 +0,0 @@
1
- import picocolors from "picocolors";
2
- import webpack from "webpack";
3
- import { Console } from "node:console";
4
- import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
5
- export const __webpack_id__ = "502";
6
- export const __webpack_ids__ = [
7
- "502"
8
- ];
9
- export const __webpack_modules__ = {
10
- "./src/progress/ProgressPlugin.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
11
- __webpack_require__.d(__webpack_exports__, {
12
- ProgressPlugin: ()=>ProgressPlugin
13
- });
14
- var core_ = __webpack_require__("@rsbuild/core"), cli_truncate = __webpack_require__("../../../node_modules/.pnpm/cli-truncate@2.1.0/node_modules/cli-truncate/index.js"), cli_truncate_default = __webpack_require__.n(cli_truncate);
15
- let clamp = (x, min, max)=>Math.min(max, Math.max(min, x)), defaultOption = {
16
- total: 100,
17
- current: 0,
18
- color: 'green',
19
- bgColor: 'gray',
20
- char: '━',
21
- width: 25,
22
- buildIcon: '◯',
23
- errorIcon: '✖',
24
- errorInfo: 'compile failed',
25
- message: '',
26
- done: !1,
27
- spaceWidth: 1,
28
- messageWidth: 25,
29
- messageColor: 'gray',
30
- id: '',
31
- maxIdLen: 16,
32
- hasErrors: !1
33
- };
34
- var build = __webpack_require__("../../../node_modules/.pnpm/patch-console@1.0.0/node_modules/patch-console/build/index.js"), build_default = __webpack_require__.n(build), ansi_escapes = __webpack_require__("../../../node_modules/.pnpm/ansi-escapes@4.3.2/node_modules/ansi-escapes/index.js"), ansi_escapes_default = __webpack_require__.n(ansi_escapes);
35
- let colorList = [
36
- 'green',
37
- 'cyan',
38
- 'yellow',
39
- 'blue',
40
- 'magenta'
41
- ], bus = new class {
42
- states = [];
43
- log;
44
- restore;
45
- prevOutput;
46
- destroyed = !1;
47
- constructor(){
48
- var stream;
49
- let previousLineCount, previousOutput, render;
50
- this.prevOutput = '', this.log = (stream = process.stdout, previousLineCount = 0, previousOutput = '', (render = (str)=>{
51
- let output = `${str}\n`;
52
- output !== previousOutput && (previousOutput = output, stream.write(ansi_escapes_default().eraseLines(previousLineCount) + output), previousLineCount = output.split('\n').length);
53
- }).clear = ()=>{
54
- stream.write(ansi_escapes_default().eraseLines(previousLineCount)), previousOutput = '', previousLineCount = 0;
55
- }, render.done = ()=>{
56
- previousOutput = '', previousLineCount = 0;
57
- }, render), console.Console = Console, this.restore = build_default()((type, data)=>{
58
- this.writeToStd(type, data);
59
- });
60
- }
61
- update(state) {
62
- let index = this.states.findIndex((i)=>i.id === state.id);
63
- -1 === index ? this.states.push(state) : this.states[index] = state;
64
- }
65
- writeToStd(type = 'stdout', data) {
66
- this.log.clear(), data && ('stdout' === type ? process.stdout.write(data) : 'stderr' === type && process.stderr.write(data)), this.log(this.prevOutput);
67
- }
68
- render() {
69
- let maxIdLen = Math.max(...this.states.map((i)=>i.id?.length ?? 0)) + 2, { columns = 70 } = process.stdout;
70
- this.prevOutput = this.states.map((i, k)=>{
71
- let bar = ((option)=>{
72
- var id;
73
- let left, right, mergedOptions = {
74
- ...defaultOption,
75
- ...option
76
- }, { total, done, buildIcon, errorIcon, errorInfo, width, current, color, bgColor, char, message, messageWidth, spaceWidth, messageColor, maxIdLen, hasErrors } = mergedOptions, space = ' '.repeat(spaceWidth), percent = clamp(Math.floor(current / total * 100), 0, 100), barColor = picocolors[color], backgroundColor = picocolors[bgColor], doneColor = hasErrors ? picocolors.red : barColor, idColor = done ? doneColor : barColor, id1 = mergedOptions.id ? idColor((left = Math.floor((maxIdLen - (id = mergedOptions.id).length) / 2), right = maxIdLen - left - id.length, ' '.repeat(left) + id + ' '.repeat(right))) : '', { columns: terminalWidth = 70 } = process.stdout;
77
- if (done) {
78
- if (hasErrors) {
79
- let message = picocolors.bold(doneColor(errorInfo));
80
- return terminalWidth >= 40 ? [
81
- idColor(errorIcon),
82
- id1,
83
- doneColor(`${space}${message}`)
84
- ].join('') : [
85
- id1,
86
- doneColor(`${message}`)
87
- ].join('');
88
- }
89
- return '';
90
- }
91
- let msgStr = picocolors[messageColor](cli_truncate_default()(message, messageWidth, {
92
- position: 'start'
93
- })), left1 = clamp(Math.floor(percent * width / 100), 0, width), right1 = clamp(width - left1, 0, width), barStr = `${barColor(char.repeat(left1))}${backgroundColor(char.repeat(right1))}`, percentStr = `${percent.toString().padStart(3)}%`;
94
- return terminalWidth >= 70 ? [
95
- idColor(buildIcon),
96
- id1,
97
- space,
98
- barStr,
99
- space,
100
- percentStr,
101
- space,
102
- msgStr
103
- ].join('') : terminalWidth >= 40 ? [
104
- idColor(buildIcon),
105
- id1,
106
- space,
107
- barStr,
108
- space,
109
- percentStr
110
- ].join('') : [
111
- idColor(buildIcon),
112
- id1,
113
- space,
114
- percentStr
115
- ].join('');
116
- })({
117
- maxIdLen,
118
- color: i.color ?? colorList[k % colorList.length],
119
- ...i
120
- });
121
- return bar ? cli_truncate_default()(bar, columns, {
122
- position: 'end'
123
- }) : null;
124
- }).filter((item)=>null !== item).join('\n'), this.writeToStd();
125
- }
126
- destroy() {
127
- this.destroyed || this.restore(), this.destroyed = !0;
128
- }
129
- clear() {
130
- this.log.clear(), this.log.done();
131
- }
132
- }();
133
- class ProgressPlugin extends webpack.ProgressPlugin {
134
- name = 'ProgressPlugin';
135
- id;
136
- hasCompileErrors = !1;
137
- compileTime = null;
138
- prettyTime;
139
- constructor(options){
140
- let prevPercentage, prevPercentage1, { id = 'Rsbuild' } = options, nonTTYLogger = (prevPercentage = 0, {
141
- log: ({ id, done, current, hasErrors, compileTime })=>{
142
- let suffix = picocolors.gray(`(${id})`);
143
- if (done) {
144
- if (100 === prevPercentage) return;
145
- prevPercentage = 100, hasErrors ? core_.logger.error(`built failed in ${compileTime} ${suffix}`) : core_.logger.ready(`built in ${compileTime} ${suffix}`);
146
- } else current - prevPercentage > 10 && (prevPercentage = current, core_.logger.info(`build progress: ${current.toFixed(0)}% ${suffix}`));
147
- }
148
- }), friendlyPercentage = (prevPercentage1 = 0, (percentage)=>{
149
- if (0 === percentage || 1 === percentage) return prevPercentage1 = 0, percentage;
150
- if (percentage <= prevPercentage1) {
151
- let step = 0;
152
- return prevPercentage1 < 0.3 ? step = 0.001 : prevPercentage1 < 0.6 ? step = 0.002 : prevPercentage1 < 0.8 ? step = 0.004 : prevPercentage1 < 0.99 && (step = 0.002), prevPercentage1 += step;
153
- }
154
- return prevPercentage1 = percentage, percentage;
155
- });
156
- super({
157
- activeModules: !1,
158
- entries: !0,
159
- modules: !0,
160
- modulesCount: 5000,
161
- profile: !1,
162
- dependencies: !0,
163
- dependenciesCount: 10000,
164
- percentBy: null,
165
- handler: (originalPercentage, message)=>{
166
- let percentage = friendlyPercentage(originalPercentage), done = 1 === percentage;
167
- process.stdout.isTTY ? (bus.update({
168
- id,
169
- current: 100 * percentage,
170
- message,
171
- done,
172
- hasErrors: this.hasCompileErrors
173
- }), bus.render()) : nonTTYLogger.log({
174
- id,
175
- done,
176
- current: 100 * percentage,
177
- hasErrors: this.hasCompileErrors,
178
- compileTime: this.compileTime
179
- });
180
- }
181
- }), this.id = id, this.prettyTime = options.prettyTime;
182
- }
183
- apply(compiler) {
184
- super.apply(compiler);
185
- let startTime = null;
186
- compiler.hooks.compile.tap(this.name, ()=>{
187
- this.compileTime = null, startTime = process.hrtime();
188
- }), compiler.hooks.done.tap(this.name, (stat)=>{
189
- if (startTime) {
190
- this.hasCompileErrors = stat.hasErrors();
191
- let hrtime = process.hrtime(startTime), seconds = hrtime[0] + hrtime[1] / 1e9;
192
- if (this.compileTime = this.prettyTime(seconds), startTime = null, !this.hasCompileErrors) {
193
- let suffix = this.id ? picocolors.gray(` (${this.id})`) : '';
194
- core_.logger.ready(`built in ${this.compileTime} ${suffix}`);
195
- }
196
- }
197
- });
198
- }
199
- }
200
- },
201
- stream: function(module) {
202
- module.exports = __WEBPACK_EXTERNAL_MODULE_stream__;
203
- }
204
- };