@rsbuild/core 0.5.5 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,7 +39,7 @@ const applyServerOptions = (command) => {
39
39
  command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
40
40
  };
41
41
  function runCli() {
42
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.5.5");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.5.7");
43
43
  const devCommand = import_commander.program.command("dev");
44
44
  const buildCommand = import_commander.program.command("build");
45
45
  const previewCommand = import_commander.program.command("preview");
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.5.5"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.5.7"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
@@ -64,19 +64,18 @@ function _construct(Parent, args, Class) {
64
64
  }
65
65
  return _construct.apply(null, arguments);
66
66
  }
67
- function _defineProperties(target, props) {
68
- for(var i = 0; i < props.length; i++){
69
- var descriptor = props[i];
70
- descriptor.enumerable = descriptor.enumerable || false;
71
- descriptor.configurable = true;
72
- if ("value" in descriptor) descriptor.writable = true;
73
- Object.defineProperty(target, descriptor.key, descriptor);
67
+ function _define_property(obj, key, value) {
68
+ if (key in obj) {
69
+ Object.defineProperty(obj, key, {
70
+ value: value,
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true
74
+ });
75
+ } else {
76
+ obj[key] = value;
74
77
  }
75
- }
76
- function _create_class(Constructor, protoProps, staticProps) {
77
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
78
- if (staticProps) _defineProperties(Constructor, staticProps);
79
- return Constructor;
78
+ return obj;
80
79
  }
81
80
  function _get_prototype_of(o) {
82
81
  _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
@@ -447,7 +446,7 @@ function linkedText(root, selector, text) {
447
446
  var frag = text.slice(curIndex);
448
447
  el.appendChild(document.createTextNode(frag));
449
448
  }
450
- var overlayTemplate = '\n<style>\n.root {\n position: fixed;\n z-index: 9999;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n margin: 0;\n background: rgba(0, 0, 0, 0.66);\n cursor: pointer;\n}\n\n.container {\n font-family: Menlo, Consolas, monospace;\n line-height: 1.6;\n width: 800px;\n max-width: 85%;\n color: #d8d8d8;\n margin: 32px auto;\n padding: 32px 40px 42px;\n position: relative;\n background: #181818;\n border-radius: 24px;\n box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);\n overflow: hidden;\n direction: ltr;\n text-align: left;\n box-sizing: border-box;\n cursor: default;\n}\n\n.title {\n margin: 0 0 20px;\n padding-bottom: 12px;\n font-size: 17px;\n font-weight: 600;\n color: #fc5e5e;\n border-bottom: 2px solid rgba(252, 94, 94, 0.7);\n}\n\n.content {\n margin: 0;\n font-size: 14px;\n font-family: inherit;\n overflow-x: scroll;\n scrollbar-width: none;\n color: #b8b8b8;\n}\n.content::-webkit-scrollbar {\n display: none;\n}\n\n.file-link {\n cursor: pointer;\n color: #27caca;\n text-decoration: underline;\n\n &:hover {\n opacity: 0.8;\n }\n &:active {\n opacity: 0.6;\n }\n}\n\n.close {\n position: absolute;\n top: 27px;\n right: 32px;\n width: 32px;\n height: 32px;\n cursor: pointer;\n}\n.close:hover {\n opacity: 0.8;\n}\n.close:active {\n opacity: 0.6;\n}\n.close:before,\n.close:after {\n position: absolute;\n left: 16px;\n top: 8px;\n content: \' \';\n height: 18px;\n width: 2px;\n border-radius: 4px;\n background-color: #b8b8b8;\n}\n.close:before {\n transform: rotate(45deg);\n}\n.close:after {\n transform: rotate(-45deg);\n}\n</style>\n\n<div class="root">\n <div class="container">\n <div class="close"></div>\n <p class="title">Compilation failed</p>\n <pre class="content"></pre>\n </div>\n</div>\n';
449
+ var overlayTemplate = '\n<style>\n.root {\n position: fixed;\n z-index: 9999;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n overflow-y: scroll;\n margin: 0;\n background: rgba(0, 0, 0, 0.66);\n cursor: pointer;\n}\n.container {\n font-family: Menlo, Consolas, monospace;\n line-height: 1.6;\n width: 800px;\n max-width: 85%;\n color: #d8d8d8;\n margin: 32px auto;\n padding: 32px 40px;\n position: relative;\n background: #181818;\n border-radius: 24px;\n box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22);\n overflow: hidden;\n direction: ltr;\n text-align: left;\n box-sizing: border-box;\n cursor: default;\n}\n.title {\n margin: 0 0 20px;\n padding-bottom: 12px;\n font-size: 17px;\n font-weight: 600;\n color: #fc5e5e;\n border-bottom: 2px solid rgba(252,94,94,.66);\n}\n.content {\n margin: 0;\n font-size: 14px;\n font-family: inherit;\n overflow-x: scroll;\n scrollbar-width: none;\n color: #b8b8b8;\n}\n.content::-webkit-scrollbar {\n display: none;\n}\n.file-link {\n cursor: pointer;\n color: #27caca;\n text-decoration: underline;\n &:hover {\n opacity: 0.8;\n }\n &:active {\n opacity: 0.6;\n }\n}\n.close {\n position: absolute;\n top: 27px;\n right: 32px;\n width: 32px;\n height: 32px;\n cursor: pointer;\n}\n.close:hover {\n opacity: 0.8;\n}\n.close:active {\n opacity: 0.6;\n}\n.close:before,\n.close:after {\n position: absolute;\n left: 16px;\n top: 8px;\n content: \' \';\n height: 18px;\n width: 2px;\n border-radius: 4px;\n background-color: #b8b8b8;\n}\n.close:before {\n transform: rotate(45deg);\n}\n.close:after {\n transform: rotate(-45deg);\n}\n.footer {\n font-size: 12px;\n color: #7e6a92;\n margin-top: 20px;\n padding-top: 12px;\n border-top: 2px solid rgba(126,106,146,.6);\n}\n.footer p {\n margin: 4px 0 0;\n}\n.footer span {\n color: #a88dc3;\n}\n</style>\n\n<div class="root">\n <div class="container">\n <div class="close"></div>\n <p class="title">Compilation failed</p>\n <pre class="content"></pre>\n <footer class="footer">\n <p><span>Fix error</span>, click outside, or press Esc to close the overlay.</p>\n <p>Disable overlay by setting Rsbuild\'s <span>dev.client.overlay</span> config to false.<p>\n </footer>\n </div>\n</div>\n';
451
450
  var _globalThis_HTMLElement = globalThis.HTMLElement, HTMLElement = _globalThis_HTMLElement === void 0 ? function HTMLElement() {
452
451
  "use strict";
453
452
  _class_call_check(this, HTMLElement);
@@ -459,9 +458,31 @@ var ErrorOverlay = /*#__PURE__*/ function(HTMLElement) {
459
458
  function ErrorOverlay(message) {
460
459
  _class_call_check(this, ErrorOverlay);
461
460
  var _this;
461
+ var _root_querySelector;
462
462
  _this = _super.call(this);
463
+ _define_property(_assert_this_initialized(_this), "close", function() {
464
+ var remove = function() {
465
+ var _this_parentNode;
466
+ return (_this_parentNode = _this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.removeChild(_assert_this_initialized(_this));
467
+ };
468
+ if (_this.animate) {
469
+ _this.animate([
470
+ {
471
+ opacity: 1
472
+ },
473
+ {
474
+ opacity: 0
475
+ }
476
+ ], {
477
+ duration: 300,
478
+ easing: "ease-out"
479
+ }).addEventListener("finish", remove);
480
+ } else {
481
+ remove();
482
+ }
483
+ });
463
484
  if (!_this.attachShadow) {
464
- console.warn("The current browser version does not support displaying rsbuild overlay");
485
+ console.warn("[Rsbuild] Current browser version does not support displaying error overlay");
465
486
  return _possible_constructor_return(_this);
466
487
  }
467
488
  var root = _this.attachShadow({
@@ -469,26 +490,20 @@ var ErrorOverlay = /*#__PURE__*/ function(HTMLElement) {
469
490
  });
470
491
  root.innerHTML = overlayTemplate;
471
492
  linkedText(root, ".content", stripAnsi(message.join("/n")).trim());
472
- root.querySelector(".close").addEventListener("click", function() {
473
- _this.close();
474
- });
475
- _this.addEventListener("click", function() {
476
- _this.close();
477
- });
493
+ (_root_querySelector = root.querySelector(".close")) === null || _root_querySelector === void 0 ? void 0 : _root_querySelector.addEventListener("click", _this.close);
494
+ _this.addEventListener("click", _this.close);
478
495
  root.querySelector(".container").addEventListener("click", function(e) {
479
496
  e.stopPropagation();
480
497
  });
498
+ var onEscKeydown = function(e) {
499
+ if (e.key === "Escape" || e.code === "Escape") {
500
+ _this.close();
501
+ }
502
+ document.removeEventListener("keydown", onEscKeydown);
503
+ };
504
+ document.addEventListener("keydown", onEscKeydown);
481
505
  return _this;
482
506
  }
483
- _create_class(ErrorOverlay, [
484
- {
485
- key: "close",
486
- value: function close() {
487
- var _this_parentNode;
488
- (_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.removeChild(this);
489
- }
490
- }
491
- ]);
492
507
  return ErrorOverlay;
493
508
  }(_wrap_native_super(HTMLElement));
494
509
  var overlayId = "rsbuild-error-overlay";
@@ -498,7 +513,7 @@ if (customElements && !customElements.get(overlayId)) {
498
513
  var documentAvailable = typeof document !== "undefined";
499
514
  function createOverlay(err) {
500
515
  if (!documentAvailable) {
501
- console.info("Failed to display Rsbuild overlay since document is not available, considering turning off the `dev.client.overlay` option.");
516
+ console.info("[Rsbuild] Failed to display error overlay as document is not available, you can disable the `dev.client.overlay` option.");
502
517
  return;
503
518
  }
504
519
  clearOverlay();
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_config = require("./config");
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  var import_mergeConfig = require("./mergeConfig");
40
40
  var import_constants = require("./constants");
41
- const version = "0.5.5";
41
+ const version = "0.5.7";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_CSS_NAME,
@@ -44,7 +44,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
44
44
  const context = {
45
45
  entry: (0, import_entry.getEntryObject)(config, "web"),
46
46
  targets: config.output?.targets || [],
47
- version: "0.5.5",
47
+ version: "0.5.7",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
@@ -22,6 +22,7 @@ __export(initPlugins_exports, {
22
22
  getPluginAPI: () => getPluginAPI
23
23
  });
24
24
  module.exports = __toCommonJS(initPlugins_exports);
25
+ var import_node_path = require("node:path");
25
26
  var import_shared = require("@rsbuild/shared");
26
27
  var import_createContext = require("./createContext");
27
28
  function getHTMLPathByEntry(entryName, config) {
@@ -29,6 +30,23 @@ function getHTMLPathByEntry(entryName, config) {
29
30
  const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
30
31
  return (0, import_shared.removeLeadingSlash)(`${htmlPath}/${filename}`);
31
32
  }
33
+ function applyTransformPlugin(chain, transformer) {
34
+ const name = "RsbuildTransformPlugin";
35
+ if (chain.plugins.get(name)) {
36
+ return;
37
+ }
38
+ class RsbuildTransformPlugin {
39
+ apply(compiler) {
40
+ compiler.__rsbuildTransformer = transformer;
41
+ compiler.hooks.thisCompilation.tap(name, (compilation) => {
42
+ compilation.hooks.childCompiler.tap(name, (childCompiler) => {
43
+ childCompiler.__rsbuildTransformer = transformer;
44
+ });
45
+ });
46
+ }
47
+ }
48
+ chain.plugin(name).use(RsbuildTransformPlugin);
49
+ }
32
50
  function getPluginAPI({
33
51
  context,
34
52
  pluginManager
@@ -63,11 +81,38 @@ function getPluginAPI({
63
81
  {}
64
82
  );
65
83
  };
84
+ const exposed = [];
85
+ const expose = (id, api) => {
86
+ exposed.push({ id, api });
87
+ };
88
+ const useExposed = (id) => {
89
+ const matched = exposed.find((item) => item.id === id);
90
+ if (matched) {
91
+ return matched.api;
92
+ }
93
+ };
94
+ let transformId = 0;
95
+ const transformer = {};
96
+ const transform = (descriptor, handler) => {
97
+ const id = `rsbuild-transform-${transformId++}`;
98
+ transformer[id] = handler;
99
+ hooks.modifyBundlerChain.tap((chain) => {
100
+ const rule = chain.module.rule(id);
101
+ if (descriptor.test) {
102
+ rule.test(descriptor.test);
103
+ }
104
+ rule.use(id).loader((0, import_node_path.join)(__dirname, "../rspack/transformLoader")).options({ id });
105
+ applyTransformPlugin(chain, transformer);
106
+ });
107
+ };
66
108
  (0, import_shared.onExitProcess)(() => {
67
109
  hooks.onExit.call();
68
110
  });
69
111
  return {
70
112
  context: publicContext,
113
+ expose,
114
+ transform,
115
+ useExposed,
71
116
  getHTMLPaths,
72
117
  getRsbuildConfig,
73
118
  getNormalizedConfig,
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from '@rspack/core';
2
+ import type { RspackSourceMap } from '@rsbuild/shared';
3
+ export default function transform(this: LoaderContext<{
4
+ id: string;
5
+ }>, source: string, map?: string | RspackSourceMap): Promise<void>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var transformLoader_exports = {};
20
+ __export(transformLoader_exports, {
21
+ default: () => transform
22
+ });
23
+ module.exports = __toCommonJS(transformLoader_exports);
24
+ async function transform(source, map) {
25
+ const callback = this.async();
26
+ const bypass = () => callback(null, source, map);
27
+ const transformId = this.getOptions().id;
28
+ if (!transformId) {
29
+ return bypass();
30
+ }
31
+ const transform2 = this._compiler?.__rsbuildTransformer?.[transformId];
32
+ if (!transform2) {
33
+ return bypass();
34
+ }
35
+ const result = await transform2({
36
+ code: source,
37
+ resource: this.resource,
38
+ resourcePath: this.resourcePath,
39
+ resourceQuery: this.resourceQuery,
40
+ addDependency: this.addDependency
41
+ });
42
+ if (result === null || result === void 0) {
43
+ return bypass();
44
+ }
45
+ if (typeof result === "string") {
46
+ return callback(null, result, map);
47
+ }
48
+ const useMap = map !== void 0 && map !== null;
49
+ const finalMap = result.map ?? map;
50
+ callback(null, result.code, useMap ? finalMap : void 0);
51
+ }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,10 @@
1
- import type { RsbuildConfig, RsbuildPlugin, RsbuildPlugins, RsbuildContext, NormalizedConfig, RsbuildPluginAPI } from '@rsbuild/shared';
1
+ import type { RsbuildConfig, RsbuildPlugin, RsbuildPlugins, RsbuildContext, NormalizedConfig, RsbuildPluginAPI, TransformHandler } from '@rsbuild/shared';
2
2
  import type { Hooks } from './initHooks';
3
+ declare module '@rspack/core' {
4
+ interface Compiler {
5
+ __rsbuildTransformer?: Record<string, TransformHandler>;
6
+ }
7
+ }
3
8
  export type { RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI };
4
9
  /** The inner context. */
5
10
  export type InternalContext = RsbuildContext & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -52,12 +52,12 @@
52
52
  "types.d.ts"
53
53
  ],
54
54
  "dependencies": {
55
- "@rspack/core": "0.5.9-canary-8778e17-20240328104834",
55
+ "@rspack/core": "0.5.9-canary-8778e17-20240403045016",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.36.0",
58
58
  "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
59
59
  "postcss": "^8.4.38",
60
- "@rsbuild/shared": "0.5.5"
60
+ "@rsbuild/shared": "0.5.7"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",