@bleedingdev/modern-js-builder 3.2.0-ultramodern.99 → 3.4.0-ultramodern.0

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 (42) hide show
  1. package/dist/cjs/createBuilder.js +13 -7
  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 +9 -5
  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 +13 -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/createBuilder.mjs +4 -2
  24. package/dist/esm/plugins/postcss.mjs +5 -45
  25. package/dist/esm/plugins/rscConfig.mjs +4 -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/createBuilder.mjs +4 -2
  30. package/dist/esm-node/plugins/postcss.mjs +5 -45
  31. package/dist/esm-node/plugins/rscConfig.mjs +4 -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/rscConfig.d.ts +10 -1
  37. package/dist/types/plugins/rsdoctor.d.ts +1 -1
  38. package/dist/types/rsdoctorConfig.d.ts +12 -0
  39. package/dist/types/shared/parseCommonConfig.d.ts +2 -1
  40. package/dist/types/shared/tsgo.d.ts +12 -0
  41. package/dist/types/types.d.ts +27 -14
  42. package/package.json +27 -27
@@ -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
  (()=>{
@@ -24,9 +24,11 @@ async function parseConfig(builderConfig, options) {
24
24
  autoprefixer: builderConfig.tools?.autoprefixer
25
25
  }));
26
26
  }
27
- const enableRsc = builderConfig.server?.rsc ?? false;
27
+ const rscConfig = builderConfig.server?.rsc ?? false;
28
+ const enableRsc = Boolean(rscConfig);
28
29
  if (enableRsc) {
29
- const rscPlugins = await getRscPlugins(enableRsc, options.internalDirectory);
30
+ const rscEnvironments = 'object' == typeof rscConfig ? rscConfig.environments : void 0;
31
+ const rscPlugins = await getRscPlugins(enableRsc, options.internalDirectory, rscEnvironments);
30
32
  rsbuildPlugins.push(...rscPlugins);
31
33
  } else rsbuildPlugins.push(rscClientBrowserFallbackPlugin());
32
34
  const rsdoctorPlugin = pluginRsdoctor(rsdoctorConfig);
@@ -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 };
@@ -93,12 +93,15 @@ function pluginRscConfig() {
93
93
  }
94
94
  };
95
95
  }
96
- async function getRscPlugins(enableRsc, internalDirectory) {
96
+ async function getRscPlugins(enableRsc, internalDirectory, environments) {
97
97
  if (enableRsc) {
98
98
  const routesFileReg = new RegExp(`${internalDirectory.replace(/[/\\]/g, '[/\\\\]')}[/\\\\][^/\\\\]*[/\\\\]routes`);
99
99
  const { pluginRSC } = await import("rsbuild-plugin-rsc");
100
100
  return [
101
101
  pluginRSC({
102
+ ...environments ? {
103
+ environments
104
+ } : {},
102
105
  layers: {
103
106
  ssr: SERVER_LOADER_ENTRY_PATTERN,
104
107
  rsc: [
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 };
@@ -25,9 +25,11 @@ async function parseConfig(builderConfig, options) {
25
25
  autoprefixer: builderConfig.tools?.autoprefixer
26
26
  }));
27
27
  }
28
- const enableRsc = builderConfig.server?.rsc ?? false;
28
+ const rscConfig = builderConfig.server?.rsc ?? false;
29
+ const enableRsc = Boolean(rscConfig);
29
30
  if (enableRsc) {
30
- const rscPlugins = await getRscPlugins(enableRsc, options.internalDirectory);
31
+ const rscEnvironments = 'object' == typeof rscConfig ? rscConfig.environments : void 0;
32
+ const rscPlugins = await getRscPlugins(enableRsc, options.internalDirectory, rscEnvironments);
31
33
  rsbuildPlugins.push(...rscPlugins);
32
34
  } else rsbuildPlugins.push(rscClientBrowserFallbackPlugin());
33
35
  const rsdoctorPlugin = pluginRsdoctor(rsdoctorConfig);
@@ -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 };
@@ -98,12 +98,15 @@ function pluginRscConfig() {
98
98
  }
99
99
  };
100
100
  }
101
- async function getRscPlugins(enableRsc, internalDirectory) {
101
+ async function getRscPlugins(enableRsc, internalDirectory, environments) {
102
102
  if (enableRsc) {
103
103
  const routesFileReg = new RegExp(`${internalDirectory.replace(/[/\\]/g, '[/\\\\]')}[/\\\\][^/\\\\]*[/\\\\]routes`);
104
104
  const { pluginRSC } = await import("rsbuild-plugin-rsc");
105
105
  return [
106
106
  pluginRSC({
107
+ ...environments ? {
108
+ environments
109
+ } : {},
107
110
  layers: {
108
111
  ssr: SERVER_LOADER_ENTRY_PATTERN,
109
112
  rsc: [
@@ -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
  }
@@ -13,6 +13,15 @@ export declare function pluginRscConfig(): RsbuildPlugin;
13
13
  * Get RSC plugins based on configuration
14
14
  * @param enableRsc - Whether RSC is enabled
15
15
  * @param internalDirectory - Internal directory path for route matching
16
+ * @param environments - Optional mapping of the RSC plugin's `server`/`client`
17
+ * environments onto existing Rsbuild environment names. When omitted, the RSC
18
+ * plugin uses its defaults (`'server'` / `'client'`). Frameworks that already
19
+ * declare their own environments can point RSC at them instead of having the
20
+ * plugin create new empty environments (which would otherwise fall back to the
21
+ * default `./src` entry and fail to resolve).
16
22
  * @returns Array of RSC-related plugins
17
23
  */
18
- export declare function getRscPlugins(enableRsc: boolean, internalDirectory: string): Promise<RsbuildPlugin[]>;
24
+ export declare function getRscPlugins(enableRsc: boolean, internalDirectory: string, environments?: {
25
+ server?: string;
26
+ client?: string;
27
+ }): Promise<RsbuildPlugin[]>;
@@ -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 {};