@bleedingdev/modern-js-builder 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121

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 (41) hide show
  1. package/dist/cjs/createBuilder.js +9 -5
  2. package/dist/cjs/index.js +9 -5
  3. package/dist/cjs/plugins/devtools.js +12 -8
  4. package/dist/cjs/plugins/emitRouteFile.js +9 -5
  5. package/dist/cjs/plugins/environmentDefaults.js +14 -6
  6. package/dist/cjs/plugins/globalVars.js +9 -5
  7. package/dist/cjs/plugins/htmlMinify.js +9 -5
  8. package/dist/cjs/plugins/manifest.js +9 -5
  9. package/dist/cjs/plugins/postcss.js +16 -49
  10. package/dist/cjs/plugins/rscConfig.js +15 -6
  11. package/dist/cjs/plugins/rsdoctor.js +12 -8
  12. package/dist/cjs/plugins/runtimeChunk.js +9 -5
  13. package/dist/cjs/rsdoctorConfig.js +18 -0
  14. package/dist/cjs/shared/devServer.js +9 -5
  15. package/dist/cjs/shared/getCssSupport.js +9 -5
  16. package/dist/cjs/shared/manifest.js +12 -8
  17. package/dist/cjs/shared/parseCommonConfig.js +23 -11
  18. package/dist/cjs/shared/rsc/rsc-server-entry-loader.js +12 -8
  19. package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +9 -5
  20. package/dist/cjs/shared/rsc/rscEmptyModule.js +12 -8
  21. package/dist/cjs/shared/tsgo.js +76 -0
  22. package/dist/cjs/shared/utils.js +9 -5
  23. package/dist/esm/plugins/environmentDefaults.mjs +5 -1
  24. package/dist/esm/plugins/postcss.mjs +5 -45
  25. package/dist/esm/plugins/rscConfig.mjs +6 -1
  26. package/dist/esm/rsdoctorConfig.mjs +0 -0
  27. package/dist/esm/shared/parseCommonConfig.mjs +14 -6
  28. package/dist/esm/shared/tsgo.mjs +35 -0
  29. package/dist/esm-node/plugins/environmentDefaults.mjs +5 -1
  30. package/dist/esm-node/plugins/postcss.mjs +5 -45
  31. package/dist/esm-node/plugins/rscConfig.mjs +6 -1
  32. package/dist/esm-node/rsdoctorConfig.mjs +1 -0
  33. package/dist/esm-node/shared/parseCommonConfig.mjs +14 -6
  34. package/dist/esm-node/shared/tsgo.mjs +36 -0
  35. package/dist/types/plugins/postcss.d.ts +1 -0
  36. package/dist/types/plugins/rsdoctor.d.ts +1 -1
  37. package/dist/types/rsdoctorConfig.d.ts +12 -0
  38. package/dist/types/shared/parseCommonConfig.d.ts +2 -1
  39. package/dist/types/shared/tsgo.d.ts +12 -0
  40. package/dist/types/types.d.ts +2 -13
  41. package/package.json +27 -28
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -23,10 +27,10 @@ var __webpack_require__ = {};
23
27
  })();
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- default: ()=>__rspack_default_export
28
- });
29
30
  const __rspack_default_export = {};
31
+ __webpack_require__.d(__webpack_exports__, {}, {
32
+ default: __rspack_default_export
33
+ });
30
34
  exports["default"] = __webpack_exports__["default"];
31
35
  for(var __rspack_i in __webpack_exports__)if (-1 === [
32
36
  "default"
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
+ return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
+ }();
5
+ var __webpack_require__ = {};
6
+ (()=>{
7
+ __webpack_require__.d = (exports1, getters, values)=>{
8
+ var define = (defs, kind)=>{
9
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
10
+ enumerable: true,
11
+ [kind]: defs[key]
12
+ });
13
+ };
14
+ define(getters, "get");
15
+ define(values, "value");
16
+ };
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
20
+ })();
21
+ (()=>{
22
+ __webpack_require__.r = (exports1)=>{
23
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
24
+ value: 'Module'
25
+ });
26
+ Object.defineProperty(exports1, '__esModule', {
27
+ value: true
28
+ });
29
+ };
30
+ })();
31
+ var __webpack_exports__ = {};
32
+ __webpack_require__.r(__webpack_exports__);
33
+ __webpack_require__.d(__webpack_exports__, {
34
+ withTsgoDefaults: ()=>withTsgoDefaults
35
+ });
36
+ const external_node_module_namespaceObject = require("node:module");
37
+ const builderRequire = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
38
+ const TSGO_PACKAGE = "@typescript/native-preview/package.json";
39
+ const tryResolve = (request, rootPath)=>{
40
+ try {
41
+ return builderRequire.resolve(request, {
42
+ paths: [
43
+ rootPath
44
+ ]
45
+ });
46
+ } catch {
47
+ return;
48
+ }
49
+ };
50
+ const withTsgoDefaults = (userOptions, rootPath)=>{
51
+ const tsgoPath = tryResolve(TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(TSGO_PACKAGE);
52
+ const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
53
+ userOptions
54
+ ] : [];
55
+ return [
56
+ {
57
+ typescript: {
58
+ tsgo: true,
59
+ typescriptPath: tsgoPath
60
+ }
61
+ },
62
+ ...userChain,
63
+ (config)=>{
64
+ const { typescript } = config;
65
+ if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
66
+ return config;
67
+ }
68
+ ];
69
+ };
70
+ exports.withTsgoDefaults = __webpack_exports__.withTsgoDefaults;
71
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
72
+ "withTsgoDefaults"
73
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
74
+ Object.defineProperty(exports, '__esModule', {
75
+ value: true
76
+ });
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -56,7 +56,11 @@ const pluginEnvironmentDefaults = (distPath = {})=>({
56
56
  });
57
57
  api.modifyBundlerChain(async (chain, { environment })=>{
58
58
  const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
59
- if (isServiceWorker) chain.output.library({
59
+ if (isServiceWorker && true === chain.output.get('module')) chain.output.library({
60
+ ...chain.output.get('library') || {},
61
+ type: 'module'
62
+ });
63
+ else if (isServiceWorker) chain.output.library({
60
64
  ...chain.output.get('library') || {},
61
65
  type: 'commonjs2'
62
66
  });
@@ -6,14 +6,6 @@ import { logger } from "@rsbuild/core";
6
6
  import { getCssSupport } from "../shared/getCssSupport.mjs";
7
7
  const builderRequire = createRequire(import.meta.url);
8
8
  const createRootRequire = (rootPath)=>createRequire(pathToFileURL(node_path.join(rootPath, 'package.json')).href);
9
- const loadByResolver = (resolveWith, name)=>{
10
- try {
11
- return resolveWith(name);
12
- } catch (error) {
13
- const resolved = resolveWith.resolve(name);
14
- return resolveWith(resolved);
15
- }
16
- };
17
9
  const loadPostcssPlugin = (name, appRootPath)=>{
18
10
  const resolvers = [
19
11
  builderRequire,
@@ -22,34 +14,13 @@ const loadPostcssPlugin = (name, appRootPath)=>{
22
14
  ];
23
15
  let firstError = null;
24
16
  for (const resolveWith of resolvers)try {
25
- return loadByResolver(resolveWith, name);
17
+ return resolveWith(name);
26
18
  } catch (error) {
27
19
  firstError ??= error;
28
20
  }
29
21
  throw firstError;
30
22
  };
31
23
  const importPostcssPlugin = (name, appRootPath)=>Promise.resolve(loadPostcssPlugin(name, appRootPath));
32
- const clonePostCSSConfig = (config)=>({
33
- ...config,
34
- plugins: config.plugins ? [
35
- ...config.plugins
36
- ] : void 0
37
- });
38
- const postcssLoadConfig = builderRequire('postcss-load-config');
39
- const userPostcssrcCache = new Map();
40
- const loadUserPostcssrc = async (root)=>{
41
- const cached = userPostcssrcCache.get(root);
42
- if (cached) return clonePostCSSConfig(await cached);
43
- const promise = postcssLoadConfig({}, root).catch((err)=>{
44
- if (err?.message?.includes('No PostCSS Config found')) return {};
45
- throw err;
46
- });
47
- userPostcssrcCache.set(root, promise);
48
- return promise.then((config)=>{
49
- userPostcssrcCache.set(root, config);
50
- return clonePostCSSConfig(config);
51
- });
52
- };
53
24
  const pluginPostcss = (options = {})=>({
54
25
  name: 'builder:postcss-plugins',
55
26
  pre: [
@@ -85,7 +56,6 @@ const pluginPostcss = (options = {})=>({
85
56
  overrideBrowserslist: config.output.overrideBrowserslist
86
57
  }, autoprefixer)))
87
58
  ]).then((results)=>results.filter(Boolean));
88
- const userOptions = await loadUserPostcssrc(api.context.rootPath);
89
59
  return mergeEnvironmentConfig({
90
60
  tools: {
91
61
  postcss: (opts)=>{
@@ -93,23 +63,13 @@ const pluginPostcss = (options = {})=>({
93
63
  logger.warn('unexpected function type postcssOptions, the default postcss plugins will not be applied.');
94
64
  return opts;
95
65
  }
96
- const existingOptions = opts.postcssOptions ?? {};
97
- const mergedOptions = {
98
- ...userOptions,
99
- ...existingOptions
100
- };
101
- const userPlugins = userOptions.plugins ?? [];
102
- const existingPlugins = existingOptions.plugins ?? [];
103
- mergedOptions.plugins = [
104
- ...userPlugins,
105
- ...existingPlugins,
106
- ...plugins
107
- ];
108
- opts.postcssOptions = mergedOptions;
66
+ opts.postcssOptions ??= {};
67
+ opts.postcssOptions.plugins ??= [];
68
+ opts.postcssOptions.plugins.push(...plugins);
109
69
  }
110
70
  }
111
71
  }, config);
112
72
  });
113
73
  }
114
74
  });
115
- export { pluginPostcss };
75
+ export { loadPostcssPlugin, pluginPostcss };
@@ -1,5 +1,8 @@
1
1
  import path from "path";
2
2
  const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
3
+ const SERVER_LOADER_ENTRY_PATTERN = /[/\\](?:server-loader-combined|route-server-loaders)\.js$/;
4
+ const RENDER_RSC_SOURCE_PATTERN = /render[/\\].*[/\\]server[/\\]rsc/;
5
+ const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc\.mjs$/;
3
6
  const RSC_COMMON_LAYER = 'rsc-common';
4
7
  const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
5
8
  const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
@@ -97,8 +100,10 @@ async function getRscPlugins(enableRsc, internalDirectory) {
97
100
  return [
98
101
  pluginRSC({
99
102
  layers: {
103
+ ssr: SERVER_LOADER_ENTRY_PATTERN,
100
104
  rsc: [
101
- /render[/\\].*[/\\]server[/\\]rsc/,
105
+ RENDER_RSC_SOURCE_PATTERN,
106
+ RENDER_RSC_RSLIB_ENTRY_PATTERN,
102
107
  /AppProxy/,
103
108
  routesFileReg
104
109
  ]
File without changes
@@ -10,6 +10,7 @@ import { pluginGlobalVars } from "../plugins/globalVars.mjs";
10
10
  import { pluginHtmlMinifierTerser } from "../plugins/htmlMinify.mjs";
11
11
  import { pluginRuntimeChunk } from "../plugins/runtimeChunk.mjs";
12
12
  import { transformToRsbuildServerOptions } from "./devServer.mjs";
13
+ import { withTsgoDefaults } from "./tsgo.mjs";
13
14
  import { NODE_MODULES_REGEX } from "./utils.mjs";
14
15
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
15
16
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
@@ -76,17 +77,24 @@ async function parseCommonConfig(builderConfig, options) {
76
77
  html.appIcon = appIcon;
77
78
  extraConfig.tools ??= {};
78
79
  if (false !== htmlPlugin) extraConfig.tools.htmlPlugin = (config)=>{
80
+ const defaultTemplateParameters = {
81
+ title: config.title,
82
+ meta: void 0,
83
+ mountId: html.mountId
84
+ };
79
85
  if ('function' == typeof config.templateParameters) {
80
86
  const originFn = config.templateParameters;
81
- config.templateParameters = (...args)=>{
82
- const res = originFn(...args);
87
+ config.templateParameters = async (...args)=>{
88
+ const res = await originFn(...args);
83
89
  return {
84
- title: config.title,
85
- meta: void 0,
90
+ ...defaultTemplateParameters,
86
91
  ...res
87
92
  };
88
93
  };
89
- }
94
+ } else config.templateParameters = {
95
+ ...defaultTemplateParameters,
96
+ ...config.templateParameters
97
+ };
90
98
  };
91
99
  if (!dev.lazyCompilation) dev.lazyCompilation = false;
92
100
  const { rsbuildDev, rsbuildServer } = transformToRsbuildServerOptions(dev || {}, devServer || {}, server || {});
@@ -116,7 +124,7 @@ async function parseCommonConfig(builderConfig, options) {
116
124
  if (!disableTsChecker) {
117
125
  const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
118
126
  rsbuildPlugins.push(pluginTypeCheck({
119
- tsCheckerOptions: tsChecker
127
+ tsCheckerOptions: withTsgoDefaults(tsChecker, options?.cwd ?? process.cwd())
120
128
  }));
121
129
  }
122
130
  if (convertToRem) {
@@ -0,0 +1,35 @@
1
+ import { createRequire } from "node:module";
2
+ const builderRequire = createRequire(import.meta.url);
3
+ const TSGO_PACKAGE = "@typescript/native-preview/package.json";
4
+ const tryResolve = (request, rootPath)=>{
5
+ try {
6
+ return builderRequire.resolve(request, {
7
+ paths: [
8
+ rootPath
9
+ ]
10
+ });
11
+ } catch {
12
+ return;
13
+ }
14
+ };
15
+ const withTsgoDefaults = (userOptions, rootPath)=>{
16
+ const tsgoPath = tryResolve(TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(TSGO_PACKAGE);
17
+ const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
18
+ userOptions
19
+ ] : [];
20
+ return [
21
+ {
22
+ typescript: {
23
+ tsgo: true,
24
+ typescriptPath: tsgoPath
25
+ }
26
+ },
27
+ ...userChain,
28
+ (config)=>{
29
+ const { typescript } = config;
30
+ if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
31
+ return config;
32
+ }
33
+ ];
34
+ };
35
+ export { withTsgoDefaults };
@@ -57,7 +57,11 @@ const pluginEnvironmentDefaults = (distPath = {})=>({
57
57
  });
58
58
  api.modifyBundlerChain(async (chain, { environment })=>{
59
59
  const isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
60
- if (isServiceWorker) chain.output.library({
60
+ if (isServiceWorker && true === chain.output.get('module')) chain.output.library({
61
+ ...chain.output.get('library') || {},
62
+ type: 'module'
63
+ });
64
+ else if (isServiceWorker) chain.output.library({
61
65
  ...chain.output.get('library') || {},
62
66
  type: 'commonjs2'
63
67
  });
@@ -7,14 +7,6 @@ import { logger } from "@rsbuild/core";
7
7
  import { getCssSupport } from "../shared/getCssSupport.mjs";
8
8
  const builderRequire = createRequire(import.meta.url);
9
9
  const createRootRequire = (rootPath)=>createRequire(pathToFileURL(node_path.join(rootPath, 'package.json')).href);
10
- const loadByResolver = (resolveWith, name)=>{
11
- try {
12
- return resolveWith(name);
13
- } catch (error) {
14
- const resolved = resolveWith.resolve(name);
15
- return resolveWith(resolved);
16
- }
17
- };
18
10
  const loadPostcssPlugin = (name, appRootPath)=>{
19
11
  const resolvers = [
20
12
  builderRequire,
@@ -23,34 +15,13 @@ const loadPostcssPlugin = (name, appRootPath)=>{
23
15
  ];
24
16
  let firstError = null;
25
17
  for (const resolveWith of resolvers)try {
26
- return loadByResolver(resolveWith, name);
18
+ return resolveWith(name);
27
19
  } catch (error) {
28
20
  firstError ??= error;
29
21
  }
30
22
  throw firstError;
31
23
  };
32
24
  const importPostcssPlugin = (name, appRootPath)=>Promise.resolve(loadPostcssPlugin(name, appRootPath));
33
- const clonePostCSSConfig = (config)=>({
34
- ...config,
35
- plugins: config.plugins ? [
36
- ...config.plugins
37
- ] : void 0
38
- });
39
- const postcssLoadConfig = builderRequire('postcss-load-config');
40
- const userPostcssrcCache = new Map();
41
- const loadUserPostcssrc = async (root)=>{
42
- const cached = userPostcssrcCache.get(root);
43
- if (cached) return clonePostCSSConfig(await cached);
44
- const promise = postcssLoadConfig({}, root).catch((err)=>{
45
- if (err?.message?.includes('No PostCSS Config found')) return {};
46
- throw err;
47
- });
48
- userPostcssrcCache.set(root, promise);
49
- return promise.then((config)=>{
50
- userPostcssrcCache.set(root, config);
51
- return clonePostCSSConfig(config);
52
- });
53
- };
54
25
  const pluginPostcss = (options = {})=>({
55
26
  name: 'builder:postcss-plugins',
56
27
  pre: [
@@ -86,7 +57,6 @@ const pluginPostcss = (options = {})=>({
86
57
  overrideBrowserslist: config.output.overrideBrowserslist
87
58
  }, autoprefixer)))
88
59
  ]).then((results)=>results.filter(Boolean));
89
- const userOptions = await loadUserPostcssrc(api.context.rootPath);
90
60
  return mergeEnvironmentConfig({
91
61
  tools: {
92
62
  postcss: (opts)=>{
@@ -94,23 +64,13 @@ const pluginPostcss = (options = {})=>({
94
64
  logger.warn('unexpected function type postcssOptions, the default postcss plugins will not be applied.');
95
65
  return opts;
96
66
  }
97
- const existingOptions = opts.postcssOptions ?? {};
98
- const mergedOptions = {
99
- ...userOptions,
100
- ...existingOptions
101
- };
102
- const userPlugins = userOptions.plugins ?? [];
103
- const existingPlugins = existingOptions.plugins ?? [];
104
- mergedOptions.plugins = [
105
- ...userPlugins,
106
- ...existingPlugins,
107
- ...plugins
108
- ];
109
- opts.postcssOptions = mergedOptions;
67
+ opts.postcssOptions ??= {};
68
+ opts.postcssOptions.plugins ??= [];
69
+ opts.postcssOptions.plugins.push(...plugins);
110
70
  }
111
71
  }
112
72
  }, config);
113
73
  });
114
74
  }
115
75
  });
116
- export { pluginPostcss };
76
+ export { loadPostcssPlugin, pluginPostcss };
@@ -5,6 +5,9 @@ import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
5
5
  import { dirname as __rspack_dirname } from "node:path";
6
6
  var rscConfig_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
7
7
  const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
8
+ const SERVER_LOADER_ENTRY_PATTERN = /[/\\](?:server-loader-combined|route-server-loaders)\.js$/;
9
+ const RENDER_RSC_SOURCE_PATTERN = /render[/\\].*[/\\]server[/\\]rsc/;
10
+ const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc\.mjs$/;
8
11
  const RSC_COMMON_LAYER = 'rsc-common';
9
12
  const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
10
13
  const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
@@ -102,8 +105,10 @@ async function getRscPlugins(enableRsc, internalDirectory) {
102
105
  return [
103
106
  pluginRSC({
104
107
  layers: {
108
+ ssr: SERVER_LOADER_ENTRY_PATTERN,
105
109
  rsc: [
106
- /render[/\\].*[/\\]server[/\\]rsc/,
110
+ RENDER_RSC_SOURCE_PATTERN,
111
+ RENDER_RSC_RSLIB_ENTRY_PATTERN,
107
112
  /AppProxy/,
108
113
  routesFileReg
109
114
  ]
@@ -0,0 +1 @@
1
+ import "node:module";
@@ -11,6 +11,7 @@ import { pluginGlobalVars } from "../plugins/globalVars.mjs";
11
11
  import { pluginHtmlMinifierTerser } from "../plugins/htmlMinify.mjs";
12
12
  import { pluginRuntimeChunk } from "../plugins/runtimeChunk.mjs";
13
13
  import { transformToRsbuildServerOptions } from "./devServer.mjs";
14
+ import { withTsgoDefaults } from "./tsgo.mjs";
14
15
  import { NODE_MODULES_REGEX } from "./utils.mjs";
15
16
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
16
17
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
@@ -77,17 +78,24 @@ async function parseCommonConfig(builderConfig, options) {
77
78
  html.appIcon = appIcon;
78
79
  extraConfig.tools ??= {};
79
80
  if (false !== htmlPlugin) extraConfig.tools.htmlPlugin = (config)=>{
81
+ const defaultTemplateParameters = {
82
+ title: config.title,
83
+ meta: void 0,
84
+ mountId: html.mountId
85
+ };
80
86
  if ('function' == typeof config.templateParameters) {
81
87
  const originFn = config.templateParameters;
82
- config.templateParameters = (...args)=>{
83
- const res = originFn(...args);
88
+ config.templateParameters = async (...args)=>{
89
+ const res = await originFn(...args);
84
90
  return {
85
- title: config.title,
86
- meta: void 0,
91
+ ...defaultTemplateParameters,
87
92
  ...res
88
93
  };
89
94
  };
90
- }
95
+ } else config.templateParameters = {
96
+ ...defaultTemplateParameters,
97
+ ...config.templateParameters
98
+ };
91
99
  };
92
100
  if (!dev.lazyCompilation) dev.lazyCompilation = false;
93
101
  const { rsbuildDev, rsbuildServer } = transformToRsbuildServerOptions(dev || {}, devServer || {}, server || {});
@@ -117,7 +125,7 @@ async function parseCommonConfig(builderConfig, options) {
117
125
  if (!disableTsChecker) {
118
126
  const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
119
127
  rsbuildPlugins.push(pluginTypeCheck({
120
- tsCheckerOptions: tsChecker
128
+ tsCheckerOptions: withTsgoDefaults(tsChecker, options?.cwd ?? process.cwd())
121
129
  }));
122
130
  }
123
131
  if (convertToRem) {
@@ -0,0 +1,36 @@
1
+ import "node:module";
2
+ import { createRequire } from "node:module";
3
+ const builderRequire = createRequire(import.meta.url);
4
+ const TSGO_PACKAGE = "@typescript/native-preview/package.json";
5
+ const tryResolve = (request, rootPath)=>{
6
+ try {
7
+ return builderRequire.resolve(request, {
8
+ paths: [
9
+ rootPath
10
+ ]
11
+ });
12
+ } catch {
13
+ return;
14
+ }
15
+ };
16
+ const withTsgoDefaults = (userOptions, rootPath)=>{
17
+ const tsgoPath = tryResolve(TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(TSGO_PACKAGE);
18
+ const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
19
+ userOptions
20
+ ] : [];
21
+ return [
22
+ {
23
+ typescript: {
24
+ tsgo: true,
25
+ typescriptPath: tsgoPath
26
+ }
27
+ },
28
+ ...userChain,
29
+ (config)=>{
30
+ const { typescript } = config;
31
+ if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
32
+ return config;
33
+ }
34
+ ];
35
+ };
36
+ export { withTsgoDefaults };
@@ -1,5 +1,6 @@
1
1
  import { type RsbuildPlugin } from '@rsbuild/core';
2
2
  import type { ToolsAutoprefixerConfig } from '../types';
3
+ export declare const loadPostcssPlugin: (name: string, appRootPath: string) => any;
3
4
  export interface PluginPostcssOptions {
4
5
  autoprefixer?: ToolsAutoprefixerConfig;
5
6
  }
@@ -1,3 +1,3 @@
1
1
  import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { RsdoctorUserConfig } from '../types';
2
+ import type { RsdoctorUserConfig } from '../rsdoctorConfig';
3
3
  export declare const pluginRsdoctor: (config: RsdoctorUserConfig | undefined) => RsbuildPlugin | null;
@@ -0,0 +1,12 @@
1
+ export type RsdoctorUserConfig = boolean | {
2
+ /**
3
+ * Force enable / disable Rsdoctor.
4
+ * When `performance.rsdoctor` is not configured, Rsdoctor is disabled.
5
+ */
6
+ enabled?: boolean;
7
+ /**
8
+ * Disable Rsdoctor client server and ensure build process exits after report generation.
9
+ * @default true
10
+ */
11
+ disableClientServer?: boolean;
12
+ };
@@ -1,5 +1,6 @@
1
1
  import { type RsbuildConfig, type RsbuildPlugin } from '@rsbuild/core';
2
- import type { BuilderConfig, CreateBuilderCommonOptions, RsdoctorUserConfig } from '../types';
2
+ import type { RsdoctorUserConfig } from '../rsdoctorConfig';
3
+ import type { BuilderConfig, CreateBuilderCommonOptions } from '../types';
3
4
  /** Determine if a file path is a CSS module when disableCssModuleExtension is enabled. */
4
5
  export declare const isLooseCssModules: (path: string) => boolean;
5
6
  export declare function parseCommonConfig(builderConfig: BuilderConfig, options?: CreateBuilderCommonOptions): Promise<{
@@ -0,0 +1,12 @@
1
+ import type { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
2
+ type TsCheckerChain = NonNullable<PluginTypeCheckerOptions['tsCheckerOptions']>;
3
+ type TsCheckerFn = Extract<TsCheckerChain, (config: never) => unknown>;
4
+ export type TsCheckerOptions = Parameters<TsCheckerFn>[0];
5
+ /**
6
+ * Type checking runs on TypeScript Go (`tsgo`) by default. The checker
7
+ * prefers the project's own `@typescript/native-preview` and falls back to
8
+ * the copy bundled with the builder, so it works without an extra install.
9
+ * Set `tools.tsChecker.typescript.tsgo: false` to use the classic checker.
10
+ */
11
+ export declare const withTsgoDefaults: (userOptions: TsCheckerChain | undefined, rootPath: string) => TsCheckerChain;
12
+ export {};
@@ -10,6 +10,8 @@ import type { PluginSourceBuildOptions } from '@rsbuild/plugin-source-build';
10
10
  import type { SvgDefaultExport } from '@rsbuild/plugin-svgr';
11
11
  import type { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
12
12
  import type { Options as AutoprefixerOptions } from 'autoprefixer';
13
+ import type { RsdoctorUserConfig } from './rsdoctorConfig';
14
+ export type { RsdoctorUserConfig } from './rsdoctorConfig';
13
15
  export type CacheGroup = Rspack.OptimizationSplitChunksCacheGroup;
14
16
  export type Stats = Omit<Rspack.Stats, '#private' | 'hash' | 'startTime' | 'endTime'>;
15
17
  export type RspackConfig = Rspack.Configuration;
@@ -79,18 +81,6 @@ export type ToolsDevServerConfig = ConfigChain<{
79
81
  watch?: boolean;
80
82
  }>;
81
83
  export type ToolsAutoprefixerConfig = ConfigChain<AutoprefixerOptions>;
82
- export type RsdoctorUserConfig = boolean | {
83
- /**
84
- * Force enable / disable Rsdoctor.
85
- * By default, Modern.js enables Rsdoctor in production builds.
86
- */
87
- enabled?: boolean;
88
- /**
89
- * Disable Rsdoctor client server and ensure build process exits after report generation.
90
- * @default true
91
- */
92
- disableClientServer?: boolean;
93
- };
94
84
  export type BuilderExtraConfig = {
95
85
  tools?: {
96
86
  /**
@@ -284,4 +274,3 @@ export type BuilderConfig = {
284
274
  [key: string]: EnvironmentConfig;
285
275
  };
286
276
  } & BuilderExtraConfig;
287
- export {};