@rsbuild/core 1.0.4 → 1.0.6

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,16 +1,16 @@
1
1
  (() => {
2
2
  "use strict";
3
3
  var __webpack_modules__ = {
4
- 967: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
- const loader = __nccwpck_require__(205);
4
+ 639: (module, __unused_webpack_exports, __nccwpck_require__) => {
5
+ const loader = __nccwpck_require__(325);
6
6
  module.exports = loader.default;
7
7
  },
8
- 205: (__unused_webpack_module, exports, __nccwpck_require__) => {
8
+ 325: (__unused_webpack_module, exports, __nccwpck_require__) => {
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports["default"] = void 0;
11
11
  var _path = _interopRequireDefault(__nccwpck_require__(17));
12
- var _utils = __nccwpck_require__(220);
13
- var _options = _interopRequireDefault(__nccwpck_require__(434));
12
+ var _utils = __nccwpck_require__(439);
13
+ var _options = _interopRequireDefault(__nccwpck_require__(946));
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
- 894: (module) => {
107
+ 3: (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
- 220: (__unused_webpack_module, exports, __nccwpck_require__) => {
133
+ 439: (__unused_webpack_module, exports, __nccwpck_require__) => {
134
134
  Object.defineProperty(exports, "__esModule", { value: true });
135
135
  exports.getExportLazyStyleCode = getExportLazyStyleCode;
136
136
  exports.getExportStyleCode = getExportStyleCode;
@@ -151,7 +151,7 @@
151
151
  exports.getdomAPI = getdomAPI;
152
152
  exports.stringifyRequest = stringifyRequest;
153
153
  var _path = _interopRequireDefault(__nccwpck_require__(17));
154
- var _isEqualLocals = _interopRequireDefault(__nccwpck_require__(894));
154
+ var _isEqualLocals = _interopRequireDefault(__nccwpck_require__(3));
155
155
  function _interopRequireDefault(obj) {
156
156
  return obj && obj.__esModule ? obj : { default: obj };
157
157
  }
@@ -394,7 +394,7 @@
394
394
  17: (module) => {
395
395
  module.exports = require("path");
396
396
  },
397
- 434: (module) => {
397
+ 946: (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__(967);
425
+ var __webpack_exports__ = __nccwpck_require__(639);
426
426
  module.exports = __webpack_exports__;
427
427
  })();
@@ -158,8 +158,7 @@ var { HTMLElement = class {
158
158
  var ErrorOverlay = class extends HTMLElement {
159
159
  constructor(message) {
160
160
  var _root_querySelector;
161
- super();
162
- _define_property(this, "close", () => {
161
+ super(), _define_property(this, "close", () => {
163
162
  const remove = () => {
164
163
  var _this_parentNode;
165
164
  return (_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.removeChild(this);
package/dist/index.cjs CHANGED
@@ -2304,7 +2304,7 @@ async function createContext(options, userConfig, bundlerType) {
2304
2304
  const rsbuildConfig = await withDefaultConfig(rootPath, userConfig);
2305
2305
  const cachePath = (0, import_node_path9.join)(rootPath, "node_modules", ".cache");
2306
2306
  return {
2307
- version: "1.0.4",
2307
+ version: "1.0.6",
2308
2308
  rootPath,
2309
2309
  distPath: "",
2310
2310
  cachePath,
@@ -4408,6 +4408,143 @@ var init_httpServer = __esm({
4408
4408
  }
4409
4409
  });
4410
4410
 
4411
+ // src/server/open.ts
4412
+ async function openBrowser(url2) {
4413
+ const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
4414
+ if (shouldTryOpenChromeWithAppleScript) {
4415
+ try {
4416
+ const targetBrowser = await getTargetBrowser();
4417
+ if (targetBrowser) {
4418
+ await execAsync(
4419
+ `osascript openChrome.applescript "${encodeURI(
4420
+ url2
4421
+ )}" "${targetBrowser}"`,
4422
+ {
4423
+ cwd: STATIC_PATH
4424
+ }
4425
+ );
4426
+ return true;
4427
+ }
4428
+ import_rslog.logger.debug("Failed to find the target browser.");
4429
+ } catch (err) {
4430
+ import_rslog.logger.debug("Failed to open start URL with apple script.");
4431
+ import_rslog.logger.debug(err);
4432
+ }
4433
+ }
4434
+ try {
4435
+ const { default: open2 } = await import("../compiled/open/index.js");
4436
+ await open2(url2);
4437
+ return true;
4438
+ } catch (err) {
4439
+ import_rslog.logger.error("Failed to open start URL.");
4440
+ import_rslog.logger.error(err);
4441
+ return false;
4442
+ }
4443
+ }
4444
+ function resolveUrl(str, base) {
4445
+ if (canParse(str)) {
4446
+ return str;
4447
+ }
4448
+ try {
4449
+ const url2 = new URL(str, base);
4450
+ return url2.href;
4451
+ } catch (e) {
4452
+ throw new Error(
4453
+ "[rsbuild:open]: Invalid input: not a valid URL or pathname"
4454
+ );
4455
+ }
4456
+ }
4457
+ async function open({
4458
+ https,
4459
+ port,
4460
+ routes,
4461
+ config,
4462
+ clearCache
4463
+ }) {
4464
+ const { targets, before } = normalizeOpenConfig(config);
4465
+ const isCodesandbox = process.env.CSB === "true";
4466
+ if (isCodesandbox) {
4467
+ return;
4468
+ }
4469
+ if (clearCache) {
4470
+ clearOpenedURLs();
4471
+ }
4472
+ const urls = [];
4473
+ const protocol = https ? "https" : "http";
4474
+ const baseUrl = `${protocol}://localhost:${port}`;
4475
+ if (!targets.length) {
4476
+ if (routes.length) {
4477
+ urls.push(`${baseUrl}${routes[0].pathname}`);
4478
+ }
4479
+ } else {
4480
+ urls.push(
4481
+ ...targets.map(
4482
+ (target) => resolveUrl(replacePortPlaceholder(target, port), baseUrl)
4483
+ )
4484
+ );
4485
+ }
4486
+ if (before) {
4487
+ await before();
4488
+ }
4489
+ for (const url2 of urls) {
4490
+ if (!openedURLs.includes(url2)) {
4491
+ openBrowser(url2);
4492
+ openedURLs.push(url2);
4493
+ }
4494
+ }
4495
+ }
4496
+ var import_node_child_process, import_node_util, execAsync, supportedChromiumBrowsers, getTargetBrowser, openedURLs, clearOpenedURLs, replacePortPlaceholder, normalizeOpenConfig;
4497
+ var init_open = __esm({
4498
+ "src/server/open.ts"() {
4499
+ "use strict";
4500
+ import_node_child_process = require("child_process");
4501
+ import_node_util = require("util");
4502
+ init_constants();
4503
+ init_helpers();
4504
+ init_logger();
4505
+ execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
4506
+ supportedChromiumBrowsers = [
4507
+ "Google Chrome Canary",
4508
+ "Google Chrome Dev",
4509
+ "Google Chrome Beta",
4510
+ "Google Chrome",
4511
+ "Microsoft Edge",
4512
+ "Brave Browser",
4513
+ "Vivaldi",
4514
+ "Chromium"
4515
+ ];
4516
+ getTargetBrowser = async () => {
4517
+ let targetBrowser = process.env.BROWSER;
4518
+ if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
4519
+ const { stdout: ps } = await execAsync("ps cax");
4520
+ targetBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b));
4521
+ }
4522
+ return targetBrowser;
4523
+ };
4524
+ openedURLs = [];
4525
+ clearOpenedURLs = () => {
4526
+ openedURLs = [];
4527
+ };
4528
+ replacePortPlaceholder = (url2, port) => url2.replace(/<port>/g, String(port));
4529
+ normalizeOpenConfig = (config) => {
4530
+ const { open: open2 } = config.server;
4531
+ if (typeof open2 === "boolean") {
4532
+ return { targets: [] };
4533
+ }
4534
+ if (typeof open2 === "string") {
4535
+ return { targets: [open2] };
4536
+ }
4537
+ if (Array.isArray(open2)) {
4538
+ return { targets: open2 };
4539
+ }
4540
+ return {
4541
+ targets: open2.target ? castArray(open2.target) : [],
4542
+ before: open2.before
4543
+ };
4544
+ };
4545
+ }
4546
+ });
4547
+
4411
4548
  // src/server/watchFiles.ts
4412
4549
  async function setupWatchFiles(options) {
4413
4550
  const { dev, server, compileMiddlewareAPI } = options;
@@ -5080,7 +5217,16 @@ async function createDevServer(options, createCompiler2, config, {
5080
5217
  await options.context.hooks.onCloseDevServer.call();
5081
5218
  await Promise.all([devMiddlewares.close(), fileWatcher?.close()]);
5082
5219
  },
5083
- printUrls
5220
+ printUrls,
5221
+ open: async () => {
5222
+ return open({
5223
+ https,
5224
+ port,
5225
+ routes,
5226
+ config,
5227
+ clearCache: true
5228
+ });
5229
+ }
5084
5230
  };
5085
5231
  import_rslog.logger.debug("create dev server done");
5086
5232
  return devServerAPI;
@@ -5098,6 +5244,7 @@ var init_devServer = __esm({
5098
5244
  init_helper();
5099
5245
  init_httpServer();
5100
5246
  init_middlewares();
5247
+ init_open();
5101
5248
  init_restart();
5102
5249
  init_watchFiles();
5103
5250
  formatDevConfig = (config, port) => {
@@ -5734,8 +5881,7 @@ var init_css = __esm({
5734
5881
  ...cssModules,
5735
5882
  localIdentName
5736
5883
  },
5737
- sourceMap: config.output.sourceMap.css,
5738
- _skipReuseAST: config.tools.lightningcssLoader !== false
5884
+ sourceMap: config.output.sourceMap.css
5739
5885
  };
5740
5886
  const mergedCssLoaderOptions = reduceConfigs({
5741
5887
  initial: defaultOptions2,
@@ -5770,157 +5916,6 @@ var init_css = __esm({
5770
5916
  }
5771
5917
  });
5772
5918
 
5773
- // src/plugins/open.ts
5774
- var open_exports = {};
5775
- __export(open_exports, {
5776
- openBrowser: () => openBrowser,
5777
- pluginOpen: () => pluginOpen,
5778
- replacePortPlaceholder: () => replacePortPlaceholder,
5779
- resolveUrl: () => resolveUrl
5780
- });
5781
- async function openBrowser(url2) {
5782
- const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
5783
- if (shouldTryOpenChromeWithAppleScript) {
5784
- try {
5785
- const targetBrowser = await getTargetBrowser();
5786
- if (targetBrowser) {
5787
- await execAsync(
5788
- `osascript openChrome.applescript "${encodeURI(
5789
- url2
5790
- )}" "${targetBrowser}"`,
5791
- {
5792
- cwd: STATIC_PATH
5793
- }
5794
- );
5795
- return true;
5796
- }
5797
- import_rslog.logger.debug("Failed to find the target browser.");
5798
- } catch (err) {
5799
- import_rslog.logger.debug("Failed to open start URL with apple script.");
5800
- import_rslog.logger.debug(err);
5801
- }
5802
- }
5803
- try {
5804
- const { default: open } = await import("../compiled/open/index.js");
5805
- await open(url2);
5806
- return true;
5807
- } catch (err) {
5808
- import_rslog.logger.error("Failed to open start URL.");
5809
- import_rslog.logger.error(err);
5810
- return false;
5811
- }
5812
- }
5813
- function resolveUrl(str, base) {
5814
- if (canParse(str)) {
5815
- return str;
5816
- }
5817
- try {
5818
- const url2 = new URL(str, base);
5819
- return url2.href;
5820
- } catch (e) {
5821
- throw new Error(
5822
- "[rsbuild:open]: Invalid input: not a valid URL or pathname"
5823
- );
5824
- }
5825
- }
5826
- function pluginOpen() {
5827
- return {
5828
- name: "rsbuild:open",
5829
- setup(api) {
5830
- const onStartServer = async (params) => {
5831
- const { port, routes } = params;
5832
- const config = api.getNormalizedConfig();
5833
- const { https } = api.context.devServer || {};
5834
- const { targets, before } = normalizeOpenConfig(config);
5835
- const isCodesandbox = process.env.CSB === "true";
5836
- const shouldOpen = targets !== void 0 && !isCodesandbox;
5837
- if (!shouldOpen) {
5838
- return;
5839
- }
5840
- const urls = [];
5841
- const protocol = https ? "https" : "http";
5842
- const baseUrl = `${protocol}://localhost:${port}`;
5843
- if (!targets.length) {
5844
- if (routes.length) {
5845
- urls.push(`${baseUrl}${routes[0].pathname}`);
5846
- }
5847
- } else {
5848
- urls.push(
5849
- ...targets.map(
5850
- (target) => resolveUrl(replacePortPlaceholder(target, port), baseUrl)
5851
- )
5852
- );
5853
- }
5854
- const openUrls = () => {
5855
- for (const url2 of urls) {
5856
- if (!openedURLs.includes(url2)) {
5857
- openBrowser(url2);
5858
- openedURLs.push(url2);
5859
- }
5860
- }
5861
- };
5862
- if (before) {
5863
- await before();
5864
- }
5865
- openUrls();
5866
- };
5867
- api.onAfterStartDevServer(onStartServer);
5868
- api.onAfterStartProdServer(onStartServer);
5869
- }
5870
- };
5871
- }
5872
- var import_node_child_process, import_node_util, execAsync, supportedChromiumBrowsers, getTargetBrowser, replacePortPlaceholder, openedURLs, normalizeOpenConfig;
5873
- var init_open = __esm({
5874
- "src/plugins/open.ts"() {
5875
- "use strict";
5876
- import_node_child_process = require("child_process");
5877
- import_node_util = require("util");
5878
- init_constants();
5879
- init_helpers();
5880
- init_logger();
5881
- execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
5882
- supportedChromiumBrowsers = [
5883
- "Google Chrome Canary",
5884
- "Google Chrome Dev",
5885
- "Google Chrome Beta",
5886
- "Google Chrome",
5887
- "Microsoft Edge",
5888
- "Brave Browser",
5889
- "Vivaldi",
5890
- "Chromium"
5891
- ];
5892
- getTargetBrowser = async () => {
5893
- let targetBrowser = process.env.BROWSER;
5894
- if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
5895
- const { stdout: ps } = await execAsync("ps cax");
5896
- targetBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b));
5897
- }
5898
- return targetBrowser;
5899
- };
5900
- replacePortPlaceholder = (url2, port) => url2.replace(/<port>/g, String(port));
5901
- openedURLs = [];
5902
- normalizeOpenConfig = (config) => {
5903
- const { open } = config.server;
5904
- if (open === false) {
5905
- return {};
5906
- }
5907
- if (open === true) {
5908
- return { targets: [] };
5909
- }
5910
- if (typeof open === "string") {
5911
- return { targets: [open] };
5912
- }
5913
- if (Array.isArray(open)) {
5914
- return { targets: open };
5915
- }
5916
- return {
5917
- targets: open.target ? castArray(open.target) : [],
5918
- before: open.before
5919
- };
5920
- };
5921
- }
5922
- });
5923
-
5924
5919
  // src/plugins/output.ts
5925
5920
  var output_exports = {};
5926
5921
  __export(output_exports, {
@@ -5961,8 +5956,8 @@ var init_output = __esm({
5961
5956
  init_constants();
5962
5957
  init_helpers();
5963
5958
  init_pluginHelper();
5964
- init_css();
5965
5959
  init_open();
5960
+ init_css();
5966
5961
  getJsAsyncPath = (jsPath, isServer, jsAsync) => {
5967
5962
  if (jsAsync !== void 0) {
5968
5963
  return jsAsync;
@@ -6044,7 +6039,10 @@ function applyFullySpecified({
6044
6039
  }) {
6045
6040
  chain.module.rule(CHAIN_ID2.RULE.MJS).test(/\.m?js/).resolve.set("fullySpecified", false);
6046
6041
  }
6047
- function applyExtensions({ chain }) {
6042
+ function applyExtensions({
6043
+ chain,
6044
+ tsconfigPath
6045
+ }) {
6048
6046
  const extensions = [
6049
6047
  // most projects are using TypeScript, resolve .ts(x) files first to reduce resolve time.
6050
6048
  ".ts",
@@ -6055,6 +6053,11 @@ function applyExtensions({ chain }) {
6055
6053
  ".json"
6056
6054
  ];
6057
6055
  chain.resolve.extensions.merge(extensions);
6056
+ if (tsconfigPath) {
6057
+ chain.resolve.extensionAlias.merge({
6058
+ ".js": [".ts", ".tsx", ".js"]
6059
+ });
6060
+ }
6058
6061
  }
6059
6062
  function applyAlias({
6060
6063
  chain,
@@ -6097,7 +6100,7 @@ var init_resolve = __esm({
6097
6100
  order: "pre",
6098
6101
  handler: (chain, { environment, CHAIN_ID: CHAIN_ID2 }) => {
6099
6102
  const { config, tsconfigPath } = environment;
6100
- applyExtensions({ chain });
6103
+ applyExtensions({ chain, tsconfigPath });
6101
6104
  applyAlias({
6102
6105
  chain,
6103
6106
  config,
@@ -7504,9 +7507,6 @@ function getDefaultSwcConfig(browserslist3, cacheRoot) {
7504
7507
  syntax: "typescript",
7505
7508
  decorators: true
7506
7509
  },
7507
- // Avoid the webpack magic comment to be removed
7508
- // https://github.com/swc-project/swc/issues/6403
7509
- preserveAllComments: true,
7510
7510
  experimental: {
7511
7511
  cacheRoot
7512
7512
  }
@@ -8602,9 +8602,23 @@ var init_server = __esm({
8602
8602
  import_node_fs9 = __toESM(require("fs"));
8603
8603
  import_node_path33 = require("path");
8604
8604
  init_config();
8605
+ init_open();
8605
8606
  pluginServer = () => ({
8606
8607
  name: "rsbuild:server",
8607
8608
  setup(api) {
8609
+ const onStartServer = async ({ port, routes }) => {
8610
+ const config = api.getNormalizedConfig();
8611
+ if (config.server.open) {
8612
+ open({
8613
+ https: api.context.devServer?.https,
8614
+ port,
8615
+ routes,
8616
+ config
8617
+ });
8618
+ }
8619
+ };
8620
+ api.onAfterStartDevServer(onStartServer);
8621
+ api.onAfterStartProdServer(onStartServer);
8608
8622
  api.onBeforeBuild(async ({ isFirstCompile }) => {
8609
8623
  if (!isFirstCompile) {
8610
8624
  return;
@@ -9423,7 +9437,6 @@ async function applyDefaultPlugins(pluginManager, context) {
9423
9437
  Promise.resolve().then(() => (init_splitChunks(), splitChunks_exports)).then(
9424
9438
  ({ pluginSplitChunks: pluginSplitChunks2 }) => pluginSplitChunks2()
9425
9439
  ),
9426
- Promise.resolve().then(() => (init_open(), open_exports)).then(({ pluginOpen: pluginOpen2 }) => pluginOpen2()),
9427
9440
  Promise.resolve().then(() => (init_inlineChunk(), inlineChunk_exports)).then(
9428
9441
  ({ pluginInlineChunk: pluginInlineChunk2 }) => pluginInlineChunk2()
9429
9442
  ),
@@ -9679,7 +9692,7 @@ var init_init = __esm({
9679
9692
 
9680
9693
  // src/cli/commands.ts
9681
9694
  function runCli() {
9682
- import_commander.program.name("rsbuild").usage("<command> [options]").version("1.0.4");
9695
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("1.0.6");
9683
9696
  const devCommand = import_commander.program.command("dev");
9684
9697
  const buildCommand = import_commander.program.command("build");
9685
9698
  const previewCommand = import_commander.program.command("preview");
@@ -9802,7 +9815,7 @@ function prepareCli() {
9802
9815
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
9803
9816
  console.log();
9804
9817
  }
9805
- import_rslog.logger.greet(` ${`Rsbuild v${"1.0.4"}`}
9818
+ import_rslog.logger.greet(` ${`Rsbuild v${"1.0.6"}`}
9806
9819
  `);
9807
9820
  }
9808
9821
  var init_prepare = __esm({
@@ -9886,7 +9899,7 @@ init_logger();
9886
9899
  init_mergeConfig();
9887
9900
  init_helpers();
9888
9901
  init_constants();
9889
- var version = "1.0.4";
9902
+ var version = "1.0.6";
9890
9903
  // Annotate the CommonJS export names for ESM import in node:
9891
9904
  0 && (module.exports = {
9892
9905
  PLUGIN_CSS_NAME,