@lynx-js/rspeedy 0.8.7 → 0.9.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.
Files changed (163) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/bin/rspeedy.js +2 -2
  3. package/dist/cli/main.js +414 -0
  4. package/dist/cli/start.js +171 -0
  5. package/dist/index.d.ts +2971 -0
  6. package/dist/index.js +39556 -0
  7. package/dist/register/hooks.js +552 -0
  8. package/dist/register/index.js +22 -0
  9. package/dist/src_cli_build_ts.js +47 -0
  10. package/dist/src_cli_commands_ts.js +60 -0
  11. package/dist/src_cli_dev_ts.js +87 -0
  12. package/dist/src_cli_exit_ts.js +111 -0
  13. package/dist/src_cli_inspect_ts.js +42 -0
  14. package/dist/src_cli_preview_ts.js +49 -0
  15. package/dist/src_config_loadConfig_ts-src_create-rspeedy_ts.js +39311 -0
  16. package/dist/src_plugins_api_plugin_ts.js +32 -0
  17. package/dist/src_plugins_chunkLoading_plugin_ts.js +35 -0
  18. package/dist/src_plugins_dev_plugin_ts.js +141 -0
  19. package/dist/src_plugins_index_ts.js +60 -0
  20. package/dist/src_plugins_inspect_plugin_ts.js +48 -0
  21. package/dist/src_plugins_minify_plugin_ts.js +85 -0
  22. package/dist/src_plugins_optimization_plugin_ts.js +25 -0
  23. package/dist/src_plugins_output_plugin_ts.js +46 -0
  24. package/dist/src_plugins_resolve_plugin_ts.js +21 -0
  25. package/dist/src_plugins_rsdoctor_plugin_ts.js +59 -0
  26. package/dist/src_plugins_sourcemap_plugin_ts.js +99 -0
  27. package/dist/src_plugins_stats_plugin_ts.js +26 -0
  28. package/dist/src_plugins_swc_plugin_ts.js +36 -0
  29. package/dist/src_plugins_target_plugin_ts.js +45 -0
  30. package/dist/src_version_ts.js +18 -0
  31. package/dist/vendors-node_modules_pnpm_chokidar_4_0_3_node_modules_chokidar_esm_index_js.js +1435 -0
  32. package/dist/vendors-node_modules_pnpm_chokidar_4_0_3_node_modules_chokidar_esm_index_js.js.LICENSE.txt +1 -0
  33. package/dist/vendors-node_modules_pnpm_commander_13_1_0_node_modules_commander_esm_mjs.js +1761 -0
  34. package/dist/vendors-node_modules_pnpm_ipaddr_js_2_2_0_node_modules_ipaddr_js_lib_ipaddr_js.js +1067 -0
  35. package/dist/vendors-node_modules_pnpm_javascript-stringify_2_1_0_node_modules_javascript-stringify_dist_i-b558be.js +416 -0
  36. package/package.json +36 -23
  37. package/LICENSE +0 -202
  38. package/lib/api.d.ts +0 -46
  39. package/lib/api.js +0 -2
  40. package/lib/cli/build.d.ts +0 -4
  41. package/lib/cli/build.js +0 -32
  42. package/lib/cli/commands.d.ts +0 -5
  43. package/lib/cli/commands.js +0 -45
  44. package/lib/cli/dev.d.ts +0 -4
  45. package/lib/cli/dev.js +0 -75
  46. package/lib/cli/exit.d.ts +0 -1
  47. package/lib/cli/exit.js +0 -51
  48. package/lib/cli/inspect.d.ts +0 -8
  49. package/lib/cli/inspect.js +0 -30
  50. package/lib/cli/main.d.ts +0 -1
  51. package/lib/cli/main.js +0 -39
  52. package/lib/cli/preview.d.ts +0 -4
  53. package/lib/cli/preview.js +0 -31
  54. package/lib/cli/start.d.ts +0 -6
  55. package/lib/cli/start.js +0 -88
  56. package/lib/config/defaults.d.ts +0 -2
  57. package/lib/config/defaults.js +0 -32
  58. package/lib/config/defineConfig.d.ts +0 -22
  59. package/lib/config/defineConfig.js +0 -24
  60. package/lib/config/dev/client.d.ts +0 -15
  61. package/lib/config/dev/client.js +0 -2
  62. package/lib/config/dev/index.d.ts +0 -173
  63. package/lib/config/dev/index.js +0 -2
  64. package/lib/config/index.d.ts +0 -172
  65. package/lib/config/index.js +0 -2
  66. package/lib/config/loadConfig.d.ts +0 -50
  67. package/lib/config/loadConfig.js +0 -98
  68. package/lib/config/mergeRspeedyConfig.d.ts +0 -36
  69. package/lib/config/mergeRspeedyConfig.js +0 -42
  70. package/lib/config/output/css-modules.d.ts +0 -84
  71. package/lib/config/output/css-modules.js +0 -2
  72. package/lib/config/output/dist-path.d.ts +0 -19
  73. package/lib/config/output/dist-path.js +0 -2
  74. package/lib/config/output/filename.d.ts +0 -167
  75. package/lib/config/output/filename.js +0 -2
  76. package/lib/config/output/index.d.ts +0 -324
  77. package/lib/config/output/index.js +0 -2
  78. package/lib/config/output/minify.d.ts +0 -80
  79. package/lib/config/output/minify.js +0 -2
  80. package/lib/config/output/source-map.d.ts +0 -68
  81. package/lib/config/output/source-map.js +0 -2
  82. package/lib/config/performance/chunk-split.d.ts +0 -192
  83. package/lib/config/performance/chunk-split.js +0 -2
  84. package/lib/config/performance/index.d.ts +0 -165
  85. package/lib/config/performance/index.js +0 -2
  86. package/lib/config/rsbuild/entry.d.ts +0 -3
  87. package/lib/config/rsbuild/entry.js +0 -31
  88. package/lib/config/rsbuild/index.d.ts +0 -4
  89. package/lib/config/rsbuild/index.js +0 -75
  90. package/lib/config/server/index.d.ts +0 -91
  91. package/lib/config/server/index.js +0 -2
  92. package/lib/config/source/decorators.d.ts +0 -43
  93. package/lib/config/source/decorators.js +0 -2
  94. package/lib/config/source/entry.d.ts +0 -84
  95. package/lib/config/source/entry.js +0 -2
  96. package/lib/config/source/index.d.ts +0 -474
  97. package/lib/config/source/index.js +0 -2
  98. package/lib/config/source/transformImport.d.ts +0 -106
  99. package/lib/config/source/transformImport.js +0 -2
  100. package/lib/config/tools/css-extract.d.ts +0 -72
  101. package/lib/config/tools/css-extract.js +0 -2
  102. package/lib/config/tools/css-loader.d.ts +0 -130
  103. package/lib/config/tools/css-loader.js +0 -2
  104. package/lib/config/tools/index.d.ts +0 -170
  105. package/lib/config/tools/index.js +0 -2
  106. package/lib/config/validate.d.ts +0 -4
  107. package/lib/config/validate.js +0 -28877
  108. package/lib/create-rspeedy.d.ts +0 -52
  109. package/lib/create-rspeedy.js +0 -49
  110. package/lib/debug.d.ts +0 -3
  111. package/lib/debug.js +0 -25
  112. package/lib/index.d.ts +0 -46
  113. package/lib/index.js +0 -11
  114. package/lib/plugins/api.plugin.d.ts +0 -3
  115. package/lib/plugins/api.plugin.js +0 -25
  116. package/lib/plugins/chunkLoading.plugin.d.ts +0 -2
  117. package/lib/plugins/chunkLoading.plugin.js +0 -43
  118. package/lib/plugins/dev.plugin.d.ts +0 -5
  119. package/lib/plugins/dev.plugin.js +0 -137
  120. package/lib/plugins/index.d.ts +0 -3
  121. package/lib/plugins/index.js +0 -49
  122. package/lib/plugins/inspect.plugin.d.ts +0 -4
  123. package/lib/plugins/inspect.plugin.js +0 -39
  124. package/lib/plugins/minify.plugin.d.ts +0 -3
  125. package/lib/plugins/minify.plugin.js +0 -89
  126. package/lib/plugins/optimization.plugin.d.ts +0 -2
  127. package/lib/plugins/optimization.plugin.js +0 -31
  128. package/lib/plugins/output.plugin.d.ts +0 -3
  129. package/lib/plugins/output.plugin.js +0 -34
  130. package/lib/plugins/resolve.plugin.d.ts +0 -2
  131. package/lib/plugins/resolve.plugin.js +0 -38
  132. package/lib/plugins/rsdoctor.plugin.d.ts +0 -3
  133. package/lib/plugins/rsdoctor.plugin.js +0 -48
  134. package/lib/plugins/sourcemap.plugin.d.ts +0 -2
  135. package/lib/plugins/sourcemap.plugin.js +0 -86
  136. package/lib/plugins/stats.plugin.d.ts +0 -2
  137. package/lib/plugins/stats.plugin.js +0 -20
  138. package/lib/plugins/swc.plugin.d.ts +0 -2
  139. package/lib/plugins/swc.plugin.js +0 -21
  140. package/lib/plugins/target.plugin.d.ts +0 -2
  141. package/lib/plugins/target.plugin.js +0 -22
  142. package/lib/utils/getESVersionTarget.d.ts +0 -1
  143. package/lib/utils/getESVersionTarget.js +0 -7
  144. package/lib/utils/is-ci.d.ts +0 -1
  145. package/lib/utils/is-ci.js +0 -7
  146. package/lib/utils/is-lynx.d.ts +0 -2
  147. package/lib/utils/is-lynx.js +0 -6
  148. package/lib/utils/is-web.d.ts +0 -2
  149. package/lib/utils/is-web.js +0 -6
  150. package/lib/version.d.ts +0 -4
  151. package/lib/version.js +0 -15
  152. package/lib/webpack/CompilationIdPlugin.d.ts +0 -4
  153. package/lib/webpack/CompilationIdPlugin.js +0 -20
  154. package/lib/webpack/EvalSourceMapDevToolPlugin.d.ts +0 -9
  155. package/lib/webpack/EvalSourceMapDevToolPlugin.js +0 -15
  156. package/lib/webpack/ProvidePlugin.d.ts +0 -9
  157. package/lib/webpack/ProvidePlugin.js +0 -15
  158. package/lib/webpack/SourceMapDevToolPlugin.d.ts +0 -9
  159. package/lib/webpack/SourceMapDevToolPlugin.js +0 -15
  160. package/register/data.d.ts +0 -9
  161. package/register/hooks.js +0 -146
  162. package/register/index.js +0 -47
  163. /package/{register → dist/register}/index.d.ts +0 -0
@@ -0,0 +1,87 @@
1
+ export const __webpack_ids__ = [
2
+ 'src_cli_dev_ts'
3
+ ];
4
+ export const __webpack_modules__ = {
5
+ "./src/cli/dev.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
+ __webpack_require__.r(__webpack_exports__);
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ dev: ()=>dev
9
+ });
10
+ var node_path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:path");
11
+ var _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("@rsbuild/core");
12
+ var picocolors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
13
+ var picocolors__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/ __webpack_require__.n(picocolors__WEBPACK_IMPORTED_MODULE_5__);
14
+ var _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/config/loadConfig.ts");
15
+ var _create_rspeedy_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/create-rspeedy.ts");
16
+ var _exit_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/cli/exit.ts");
17
+ async function dev(cwd, devOptions) {
18
+ let onBeforeRestart = [];
19
+ try {
20
+ const configPath = (0, _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_2__.Mk)(cwd, devOptions.config);
21
+ const { content: rspeedyConfig } = await (0, _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_2__.ME)({
22
+ cwd,
23
+ configPath
24
+ });
25
+ if (devOptions.base) {
26
+ rspeedyConfig.server ??= {};
27
+ rspeedyConfig.server.base = devOptions.base;
28
+ }
29
+ const watchedFiles = [
30
+ configPath
31
+ ];
32
+ if (Array.isArray(rspeedyConfig.dev?.watchFiles)) watchedFiles.push(...rspeedyConfig.dev.watchFiles.filter((item)=>'reload-server' === item.type).flatMap((item)=>item.paths));
33
+ else if (rspeedyConfig.dev?.watchFiles?.type === 'reload-server') {
34
+ const { paths } = rspeedyConfig.dev.watchFiles;
35
+ watchedFiles.push(...Array.isArray(paths) ? paths : [
36
+ paths
37
+ ]);
38
+ }
39
+ await watchFiles(watchedFiles.map((filePath)=>node_path__WEBPACK_IMPORTED_MODULE_0__["default"].isAbsolute(filePath) ? filePath : node_path__WEBPACK_IMPORTED_MODULE_0__["default"].join(cwd, filePath)), async (filename)=>{
40
+ _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__.logger.info(`Restart because ${picocolors__WEBPACK_IMPORTED_MODULE_5___default().yellow(filename)} is changed.\n`);
41
+ const cleanup = onBeforeRestart.map((f)=>f());
42
+ onBeforeRestart = [];
43
+ await Promise.all(cleanup);
44
+ await dev.call(this, cwd, devOptions);
45
+ });
46
+ const options = {
47
+ cwd,
48
+ rspeedyConfig
49
+ };
50
+ if (devOptions.envMode) options.loadEnv = {
51
+ mode: devOptions.envMode
52
+ };
53
+ if (devOptions.environment) options.environment = devOptions.environment;
54
+ const rspeedy = await (0, _create_rspeedy_js__WEBPACK_IMPORTED_MODULE_3__.S)(options);
55
+ const server = await rspeedy.createDevServer();
56
+ const { server: { close } } = await server.listen();
57
+ onBeforeRestart.push(close);
58
+ } catch (error) {
59
+ _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__.logger.error(error);
60
+ (0, _exit_js__WEBPACK_IMPORTED_MODULE_4__.exit)(1);
61
+ }
62
+ }
63
+ async function watchFiles(files, callback) {
64
+ const chokidar = await __webpack_require__.e("vendors-node_modules_pnpm_chokidar_4_0_3_node_modules_chokidar_esm_index_js").then(__webpack_require__.bind(__webpack_require__, "../../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js"));
65
+ const watcher = chokidar.default.watch(files, {
66
+ ignoreInitial: true,
67
+ ignorePermissionErrors: true
68
+ });
69
+ const cb = debounce((event, filePath)=>{
70
+ const startTime = Date.now();
71
+ watcher.close().then(()=>callback(filePath, startTime, event));
72
+ }, 300);
73
+ watcher.once('add', cb.bind(null, 'add'));
74
+ watcher.once('change', cb.bind(null, 'change'));
75
+ watcher.once('unlink', cb.bind(null, 'unlink'));
76
+ }
77
+ function debounce(func, wait) {
78
+ let timeoutId = null;
79
+ return (...args)=>{
80
+ if (null !== timeoutId) clearTimeout(timeoutId);
81
+ timeoutId = setTimeout(()=>{
82
+ func(...args);
83
+ }, wait);
84
+ };
85
+ }
86
+ }
87
+ };
@@ -0,0 +1,111 @@
1
+ export const __webpack_ids__ = [
2
+ 'src_cli_exit_ts'
3
+ ];
4
+ export const __webpack_modules__ = {
5
+ "./src/cli/exit.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
+ __webpack_require__.d(__webpack_exports__, {
7
+ exit: ()=>exit_exit
8
+ });
9
+ var core_ = __webpack_require__("@rsbuild/core");
10
+ var external_node_process_ = __webpack_require__("node:process");
11
+ const asyncCallbacks = new Set();
12
+ const callbacks = new Set();
13
+ let isCalled = false;
14
+ let isRegistered = false;
15
+ async function exit(shouldManuallyExit, isSynchronous, signal) {
16
+ if (isCalled) return;
17
+ isCalled = true;
18
+ if (asyncCallbacks.size > 0 && isSynchronous) console.error("SYNCHRONOUS TERMINATION NOTICE: When explicitly exiting the process via process.exit or via a parent process, asynchronous tasks in your exitHooks will not run. Either remove these tasks, use gracefulExit() instead of process.exit(), or ensure your parent process sends a SIGINT to the process running this code.");
19
+ const exitCode = 128 + signal;
20
+ const done = (force = false)=>{
21
+ if (true === force || true === shouldManuallyExit) external_node_process_["default"].exit(exitCode);
22
+ };
23
+ for (const callback of callbacks)callback(exitCode);
24
+ if (isSynchronous) return void done();
25
+ const promises = [];
26
+ let forceAfter = 0;
27
+ for (const [callback, wait] of asyncCallbacks){
28
+ forceAfter = Math.max(forceAfter, wait);
29
+ promises.push(Promise.resolve(callback(exitCode)));
30
+ }
31
+ const asyncTimer = setTimeout(()=>{
32
+ done(true);
33
+ }, forceAfter);
34
+ await Promise.all(promises);
35
+ clearTimeout(asyncTimer);
36
+ done();
37
+ }
38
+ function addHook(options) {
39
+ const { onExit, wait, isSynchronous } = options;
40
+ const asyncCallbackConfig = [
41
+ onExit,
42
+ wait
43
+ ];
44
+ if (isSynchronous) callbacks.add(onExit);
45
+ else asyncCallbacks.add(asyncCallbackConfig);
46
+ if (!isRegistered) {
47
+ isRegistered = true;
48
+ external_node_process_["default"].once('beforeExit', exit.bind(void 0, true, false, -128));
49
+ external_node_process_["default"].once('SIGINT', exit.bind(void 0, true, false, 2));
50
+ external_node_process_["default"].once('SIGTERM', exit.bind(void 0, true, false, 15));
51
+ external_node_process_["default"].once('exit', exit.bind(void 0, false, true, 0));
52
+ external_node_process_["default"].on('message', (message)=>{
53
+ if ('shutdown' === message) exit(true, true, -128);
54
+ });
55
+ }
56
+ return ()=>{
57
+ if (isSynchronous) callbacks.delete(onExit);
58
+ else asyncCallbacks.delete(asyncCallbackConfig);
59
+ };
60
+ }
61
+ function asyncExitHook(onExit, options = {}) {
62
+ if ('function' != typeof onExit) throw new TypeError('onExit must be a function');
63
+ if (!('number' == typeof options.wait && options.wait > 0)) throw new TypeError('wait must be set to a positive numeric value');
64
+ return addHook({
65
+ onExit,
66
+ wait: options.wait,
67
+ isSynchronous: false
68
+ });
69
+ }
70
+ function gracefulExit(signal = 0) {
71
+ exit(true, false, -128 + signal);
72
+ }
73
+ var picocolors = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
74
+ var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
75
+ var debug = __webpack_require__("./src/debug.ts");
76
+ const start = Date.now();
77
+ const exitPromises = [];
78
+ const unsubscribe = asyncExitHook(exit_onExit, {
79
+ wait: 1000
80
+ });
81
+ process.on('unhandledRejection', async (reason)=>{
82
+ core_.logger.error('Unhandled Rejection with reason:', reason instanceof Error ? reason : new Error(JSON.stringify(reason)));
83
+ unsubscribe();
84
+ await exit_onExit(1);
85
+ process.exit(1);
86
+ });
87
+ let interrupted = false;
88
+ process.on('SIGINT', ()=>{
89
+ if (interrupted) {
90
+ core_.logger.info("Force exiting Rspeedy.");
91
+ return process.exit(130);
92
+ }
93
+ interrupted = true;
94
+ core_.logger.info(`Gracefully shutting down. Please wait... (Press ${picocolors_default().cyan('Ctrl+C')} again to force exit)`);
95
+ exit_exit(130);
96
+ });
97
+ let previousSignal = null;
98
+ const exit_exit = (signal = 0)=>{
99
+ if (null !== previousSignal) (0, debug.fF)(`graceful exit called multiple times, current: ${signal}, previous: ${previousSignal}`);
100
+ previousSignal = signal;
101
+ (0, debug.fF)(`graceful exit process with signal: ${signal}`);
102
+ gracefulExit(signal);
103
+ };
104
+ async function exit_onExit(signal) {
105
+ const duration = Date.now() - start;
106
+ (0, debug.fF)(`exit hook fired with signal: ${signal}, duration: ${duration}`);
107
+ (0, debug.fF)(`awaiting exit promises(length: ${exitPromises.length})...`);
108
+ await Promise.allSettled(exitPromises);
109
+ }
110
+ }
111
+ };
@@ -0,0 +1,42 @@
1
+ export const __webpack_ids__ = [
2
+ 'src_cli_inspect_ts'
3
+ ];
4
+ export const __webpack_modules__ = {
5
+ "./src/cli/inspect.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
+ __webpack_require__.r(__webpack_exports__);
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ inspect: ()=>inspect
9
+ });
10
+ var _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("@rsbuild/core");
11
+ var _exit_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/cli/exit.ts");
12
+ var _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/config/loadConfig.ts");
13
+ var _create_rspeedy_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/create-rspeedy.ts");
14
+ async function inspect(cwd, inspectOptions) {
15
+ try {
16
+ const { content: rspeedyConfig } = await (0, _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_2__.ME)({
17
+ cwd,
18
+ configPath: inspectOptions.config
19
+ });
20
+ const rspeedy = await (0, _create_rspeedy_js__WEBPACK_IMPORTED_MODULE_3__.S)({
21
+ cwd,
22
+ rspeedyConfig,
23
+ ...inspectOptions.envMode ? {
24
+ loadEnv: {
25
+ mode: inspectOptions.envMode
26
+ }
27
+ } : {}
28
+ });
29
+ await rspeedy.inspectConfig({
30
+ mode: inspectOptions.mode ?? process.env['NODE_ENV'] ?? 'development',
31
+ verbose: inspectOptions.verbose ?? false,
32
+ outputPath: inspectOptions.output,
33
+ writeToDisk: true
34
+ });
35
+ return (0, _exit_js__WEBPACK_IMPORTED_MODULE_1__.exit)();
36
+ } catch (error) {
37
+ _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__.logger.error(error);
38
+ _rsbuild_core__WEBPACK_IMPORTED_MODULE_0__.logger.error();
39
+ }
40
+ }
41
+ }
42
+ };
@@ -0,0 +1,49 @@
1
+ export const __webpack_ids__ = [
2
+ 'src_cli_preview_ts'
3
+ ];
4
+ export const __webpack_modules__ = {
5
+ "./src/cli/preview.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
6
+ __webpack_require__.r(__webpack_exports__);
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ preview: ()=>preview
9
+ });
10
+ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("node:fs");
11
+ var _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("@rsbuild/core");
12
+ var picocolors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("../../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
13
+ var picocolors__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/ __webpack_require__.n(picocolors__WEBPACK_IMPORTED_MODULE_5__);
14
+ var _exit_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/cli/exit.ts");
15
+ var _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./src/config/loadConfig.ts");
16
+ var _create_rspeedy_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./src/create-rspeedy.ts");
17
+ async function preview(cwd, previewOptions) {
18
+ try {
19
+ const configPath = (0, _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_3__.Mk)(cwd, previewOptions.config);
20
+ const { content: rspeedyConfig } = await (0, _config_loadConfig_js__WEBPACK_IMPORTED_MODULE_3__.ME)({
21
+ cwd,
22
+ configPath
23
+ });
24
+ if (previewOptions.base) {
25
+ rspeedyConfig.server ??= {};
26
+ rspeedyConfig.server.base = previewOptions.base;
27
+ }
28
+ const rspeedy = await (0, _create_rspeedy_js__WEBPACK_IMPORTED_MODULE_4__.S)({
29
+ cwd,
30
+ rspeedyConfig,
31
+ ...previewOptions.envMode ? {
32
+ loadEnv: {
33
+ mode: previewOptions.envMode
34
+ }
35
+ } : {}
36
+ });
37
+ await rspeedy.initConfigs();
38
+ const { distPath } = rspeedy.context;
39
+ if (!node_fs__WEBPACK_IMPORTED_MODULE_0__["default"].existsSync(distPath)) throw new Error(`The output directory ${picocolors__WEBPACK_IMPORTED_MODULE_5___default().yellow(distPath)} does not exist, please build the project before previewing.`);
40
+ await rspeedy.preview();
41
+ } catch (error) {
42
+ _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__.logger.error('Failed to start preview server.');
43
+ _rsbuild_core__WEBPACK_IMPORTED_MODULE_1__.logger.error(error);
44
+ (0, _exit_js__WEBPACK_IMPORTED_MODULE_2__.exit)(1);
45
+ return;
46
+ }
47
+ }
48
+ }
49
+ };