@bleedingdev/modern-js-builder 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20

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 (62) hide show
  1. package/dist/cjs/createBuilder.js +15 -6
  2. package/dist/cjs/index.js +6 -2
  3. package/dist/cjs/plugins/environmentDefaults.js +7 -8
  4. package/dist/cjs/plugins/manifest.js +1 -1
  5. package/dist/cjs/plugins/rscConfig.js +1 -4
  6. package/dist/cjs/shared/parseCommonConfig.js +19 -4
  7. package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +68 -0
  8. package/dist/cjs/shared/tsgo.js +274 -0
  9. package/dist/esm/createBuilder.mjs +16 -7
  10. package/dist/esm/index.mjs +1 -0
  11. package/dist/esm/plugins/environmentDefaults.mjs +7 -8
  12. package/dist/esm/plugins/manifest.mjs +1 -1
  13. package/dist/esm/plugins/rscConfig.mjs +1 -4
  14. package/dist/esm/shared/parseCommonConfig.mjs +20 -5
  15. package/dist/esm/shared/rsc/rscClientBrowserFallback.mjs +20 -0
  16. package/dist/esm/shared/tsgo.mjs +219 -0
  17. package/dist/esm-node/createBuilder.mjs +16 -7
  18. package/dist/esm-node/index.mjs +1 -0
  19. package/dist/esm-node/plugins/environmentDefaults.mjs +7 -8
  20. package/dist/esm-node/plugins/manifest.mjs +1 -1
  21. package/dist/esm-node/plugins/rscConfig.mjs +1 -4
  22. package/dist/esm-node/shared/parseCommonConfig.mjs +20 -5
  23. package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
  24. package/dist/esm-node/shared/tsgo.mjs +220 -0
  25. package/dist/types/css-minimizer/LICENSE +20 -0
  26. package/dist/types/css-minimizer/index.d.ts +154 -0
  27. package/dist/types/index.d.ts +1 -0
  28. package/dist/types/sass/LICENSE +21 -0
  29. package/dist/types/sass/index.d.ts +36 -0
  30. package/dist/types/sass/loader.d.ts +957 -0
  31. package/dist/types/shared/rsc/rscClientBrowserFallback.d.ts +2 -0
  32. package/dist/types/shared/tsgo.d.ts +27 -0
  33. package/dist/types/types.d.ts +6 -3
  34. package/package.json +13 -11
  35. package/dist/cjs/shared/rsc/rscDisabledClientBrowserRuntime.js +0 -69
  36. package/dist/cjs/shared/rsc/rscDisabledClientEdgeRuntime.js +0 -61
  37. package/dist/cjs/shared/rsc/rscDisabledClientNodeRuntime.js +0 -65
  38. package/dist/cjs/shared/rsc/rscDisabledRuntime.js +0 -140
  39. package/dist/cjs/shared/rsc/rscDisabledRuntimeError.js +0 -42
  40. package/dist/cjs/shared/rsc/rscDisabledServerEdgeRuntime.js +0 -93
  41. package/dist/cjs/shared/rsc/rscDisabledServerNodeRuntime.js +0 -101
  42. package/dist/esm/shared/rsc/rscDisabledClientBrowserRuntime.mjs +0 -10
  43. package/dist/esm/shared/rsc/rscDisabledClientEdgeRuntime.mjs +0 -8
  44. package/dist/esm/shared/rsc/rscDisabledClientNodeRuntime.mjs +0 -9
  45. package/dist/esm/shared/rsc/rscDisabledRuntime.mjs +0 -92
  46. package/dist/esm/shared/rsc/rscDisabledRuntimeError.mjs +0 -4
  47. package/dist/esm/shared/rsc/rscDisabledServerEdgeRuntime.mjs +0 -16
  48. package/dist/esm/shared/rsc/rscDisabledServerNodeRuntime.mjs +0 -18
  49. package/dist/esm-node/shared/rsc/rscDisabledClientBrowserRuntime.mjs +0 -11
  50. package/dist/esm-node/shared/rsc/rscDisabledClientEdgeRuntime.mjs +0 -9
  51. package/dist/esm-node/shared/rsc/rscDisabledClientNodeRuntime.mjs +0 -10
  52. package/dist/esm-node/shared/rsc/rscDisabledRuntime.mjs +0 -97
  53. package/dist/esm-node/shared/rsc/rscDisabledRuntimeError.mjs +0 -5
  54. package/dist/esm-node/shared/rsc/rscDisabledServerEdgeRuntime.mjs +0 -17
  55. package/dist/esm-node/shared/rsc/rscDisabledServerNodeRuntime.mjs +0 -19
  56. package/dist/types/shared/rsc/rscDisabledClientBrowserRuntime.d.ts +0 -9
  57. package/dist/types/shared/rsc/rscDisabledClientEdgeRuntime.d.ts +0 -7
  58. package/dist/types/shared/rsc/rscDisabledClientNodeRuntime.d.ts +0 -8
  59. package/dist/types/shared/rsc/rscDisabledRuntime.d.ts +0 -2
  60. package/dist/types/shared/rsc/rscDisabledRuntimeError.d.ts +0 -1
  61. package/dist/types/shared/rsc/rscDisabledServerEdgeRuntime.d.ts +0 -15
  62. package/dist/types/shared/rsc/rscDisabledServerNodeRuntime.d.ts +0 -17
@@ -34,7 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
34
34
  const core_namespaceObject = require("@rsbuild/core");
35
35
  const rscConfig_js_namespaceObject = require("./plugins/rscConfig.js");
36
36
  const parseCommonConfig_js_namespaceObject = require("./shared/parseCommonConfig.js");
37
- const rscDisabledRuntime_js_namespaceObject = require("./shared/rsc/rscDisabledRuntime.js");
37
+ const rscClientBrowserFallback_js_namespaceObject = require("./shared/rsc/rscClientBrowserFallback.js");
38
38
  async function parseConfig(builderConfig, options) {
39
39
  builderConfig.performance ??= {};
40
40
  builderConfig.performance.buildCache ??= true;
@@ -62,10 +62,7 @@ async function parseConfig(builderConfig, options) {
62
62
  const rscEnvironments = 'object' == typeof rscConfig ? rscConfig.environments : void 0;
63
63
  const rscPlugins = await (0, rscConfig_js_namespaceObject.getRscPlugins)(enableRsc, options.internalDirectory, rscEnvironments);
64
64
  rsbuildPlugins.push(...rscPlugins);
65
- } else rsbuildConfig.plugins = [
66
- ...rsbuildConfig.plugins ?? [],
67
- (0, rscDisabledRuntime_js_namespaceObject.rscDisabledRuntimePlugin)()
68
- ];
65
+ } else rsbuildPlugins.push((0, rscClientBrowserFallback_js_namespaceObject.rscClientBrowserFallbackPlugin)());
69
66
  return {
70
67
  rsbuildConfig,
71
68
  rsbuildPlugins
@@ -83,7 +80,19 @@ async function createRspackBuilder(options) {
83
80
  ];
84
81
  const rsbuild = await (0, core_namespaceObject.createRsbuild)({
85
82
  cwd,
86
- rsbuildConfig
83
+ rsbuildConfig: (0, core_namespaceObject.mergeRsbuildConfig)({
84
+ tools: {
85
+ rspack: {
86
+ module: {
87
+ parser: {
88
+ javascript: {
89
+ createRequire: true
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }, rsbuildConfig)
87
96
  });
88
97
  return {
89
98
  ...rsbuild
package/dist/cjs/index.js CHANGED
@@ -35,10 +35,12 @@ __webpack_require__.d(__webpack_exports__, {
35
35
  createBuilder: ()=>external_createBuilder_js_namespaceObject.createRspackBuilder,
36
36
  isHtmlDisabled: ()=>utils_js_namespaceObject.isHtmlDisabled,
37
37
  logger: ()=>core_namespaceObject.logger,
38
- parseRspackConfig: ()=>external_createBuilder_js_namespaceObject.parseConfig
38
+ parseRspackConfig: ()=>external_createBuilder_js_namespaceObject.parseConfig,
39
+ refreshTsgoCheckerConfig: ()=>tsgo_js_namespaceObject.refreshTsgoCheckerConfig
39
40
  });
40
41
  const external_createBuilder_js_namespaceObject = require("./createBuilder.js");
41
42
  const core_namespaceObject = require("@rsbuild/core");
43
+ const tsgo_js_namespaceObject = require("./shared/tsgo.js");
42
44
  const utils_js_namespaceObject = require("./shared/utils.js");
43
45
  exports.RUNTIME_CHUNK_NAME = __webpack_exports__.RUNTIME_CHUNK_NAME;
44
46
  exports.RUNTIME_CHUNK_REGEX = __webpack_exports__.RUNTIME_CHUNK_REGEX;
@@ -48,6 +50,7 @@ exports.createBuilder = __webpack_exports__.createBuilder;
48
50
  exports.isHtmlDisabled = __webpack_exports__.isHtmlDisabled;
49
51
  exports.logger = __webpack_exports__.logger;
50
52
  exports.parseRspackConfig = __webpack_exports__.parseRspackConfig;
53
+ exports.refreshTsgoCheckerConfig = __webpack_exports__.refreshTsgoCheckerConfig;
51
54
  for(var __rspack_i in __webpack_exports__)if (-1 === [
52
55
  "RUNTIME_CHUNK_NAME",
53
56
  "RUNTIME_CHUNK_REGEX",
@@ -56,7 +59,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
56
59
  "createBuilder",
57
60
  "isHtmlDisabled",
58
61
  "logger",
59
- "parseRspackConfig"
62
+ "parseRspackConfig",
63
+ "refreshTsgoCheckerConfig"
60
64
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
61
65
  Object.defineProperty(exports, '__esModule', {
62
66
  value: true
@@ -88,14 +88,13 @@ const pluginEnvironmentDefaults = (distPath = {})=>({
88
88
  });
89
89
  api.modifyBundlerChain(async (chain, { environment })=>{
90
90
  const isServiceWorker = environment.name === utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME;
91
- if (isServiceWorker && true === chain.output.get('module')) chain.output.library({
92
- ...chain.output.get('library') || {},
93
- type: 'module'
94
- });
95
- else if (isServiceWorker) chain.output.library({
96
- ...chain.output.get('library') || {},
97
- type: 'commonjs2'
98
- });
91
+ if (isServiceWorker) {
92
+ const library = chain.output.get('library');
93
+ chain.output.library({
94
+ ...'object' == typeof library && !Array.isArray(library) ? library : {},
95
+ type: true === chain.output.get('module') ? 'module' : 'commonjs2'
96
+ });
97
+ }
99
98
  });
100
99
  }
101
100
  });
@@ -40,7 +40,7 @@ const pluginManifest = ()=>({
40
40
  chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
41
41
  {
42
42
  fileName: 'web' === target ? 'asset-manifest.json' : `asset-manifest-${target}.json`,
43
- publicPath,
43
+ publicPath: 'string' == typeof publicPath ? publicPath : void 0,
44
44
  generate: manifest_js_namespaceObject.generateManifest
45
45
  }
46
46
  ]);
@@ -46,9 +46,7 @@ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_na
46
46
  const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
47
47
  const SERVER_LOADER_ENTRY_PATTERN = /[/\\](?:server-loader-combined|route-server-loaders)\.js$/;
48
48
  const RENDER_RSC_SOURCE_PATTERN = /render[/\\].*[/\\]server[/\\]rsc/;
49
- const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(?:Worker)?\.mjs$/;
50
- const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
51
- const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
49
+ const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(?:\.edge)?\.mjs$/;
52
50
  const RSC_COMMON_LAYER = 'rsc-common';
53
51
  const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
54
52
  const ROUTE_DATA_FILE_PATTERN = /[/\\]routes[/\\](?:.*[/\\])?(?:layout|page|\$)\.(?:loader|data)\.[tj]sx?(?:\?.*)?$/;
@@ -73,7 +71,6 @@ function pluginRscConfig() {
73
71
  api.modifyBundlerChain({
74
72
  handler: (chain, { isServer })=>{
75
73
  if (isServer) {
76
- chain.resolve.alias.set(`${RENDER_RSC_RUNTIME}$`, RENDER_RSC_WORKER_RUNTIME);
77
74
  let emptyModulePath;
78
75
  try {
79
76
  emptyModulePath = require.resolve('../shared/rsc/rscEmptyModule');
@@ -43,6 +43,7 @@ const globalVars_js_namespaceObject = require("../plugins/globalVars.js");
43
43
  const htmlMinify_js_namespaceObject = require("../plugins/htmlMinify.js");
44
44
  const runtimeChunk_js_namespaceObject = require("../plugins/runtimeChunk.js");
45
45
  const external_devServer_js_namespaceObject = require("./devServer.js");
46
+ const external_tsgo_js_namespaceObject = require("./tsgo.js");
46
47
  const external_utils_js_namespaceObject = require("./utils.js");
47
48
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
48
49
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
@@ -168,7 +169,7 @@ async function parseCommonConfig(builderConfig, options) {
168
169
  if (!disableTsChecker) {
169
170
  const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
170
171
  rsbuildPlugins.push(pluginTypeCheck({
171
- tsCheckerOptions: tsChecker
172
+ tsCheckerOptions: (0, external_tsgo_js_namespaceObject.withTsgoDefaults)(tsChecker, options?.cwd ?? process.cwd())
172
173
  }));
173
174
  }
174
175
  if (convertToRem) {
@@ -184,9 +185,23 @@ async function parseCommonConfig(builderConfig, options) {
184
185
  const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
185
186
  rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
186
187
  }
187
- rsbuildPlugins.push((0, plugin_react_namespaceObject.pluginReact)(options?.disableReactCompiler || void 0 === reactCompiler ? {} : {
188
- reactCompiler
189
- }));
188
+ rsbuildPlugins.push((0, plugin_react_namespaceObject.pluginReact)());
189
+ if (!options?.disableReactCompiler && void 0 !== reactCompiler) rsbuildPlugins.push({
190
+ name: 'builder:react-compiler',
191
+ setup (api) {
192
+ api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>'web' === config.output.target && name !== external_utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME ? mergeEnvironmentConfig({
193
+ tools: {
194
+ swc: {
195
+ jsc: {
196
+ transform: {
197
+ reactCompiler
198
+ }
199
+ }
200
+ }
201
+ }
202
+ }, config) : config);
203
+ }
204
+ });
190
205
  if (!disableSvgr) {
191
206
  const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
192
207
  rsbuildPlugins.push(pluginSvgr({
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
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");
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.r = (exports1)=>{
29
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
+ value: 'Module'
31
+ });
32
+ Object.defineProperty(exports1, '__esModule', {
33
+ value: true
34
+ });
35
+ };
36
+ })();
37
+ var __webpack_exports__ = {};
38
+ __webpack_require__.r(__webpack_exports__);
39
+ __webpack_require__.d(__webpack_exports__, {
40
+ rscClientBrowserFallbackPlugin: ()=>rscClientBrowserFallbackPlugin
41
+ });
42
+ const external_path_namespaceObject = require("path");
43
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
44
+ function rscClientBrowserFallbackPlugin() {
45
+ return {
46
+ name: 'builder:rsc-client-browser-fallback',
47
+ setup (api) {
48
+ let emptyModulePath;
49
+ try {
50
+ emptyModulePath = require.resolve('./rscEmptyModule');
51
+ } catch {
52
+ emptyModulePath = external_path_default().resolve(__dirname, 'rscEmptyModule');
53
+ }
54
+ api.modifyRspackConfig((config)=>{
55
+ config.resolve ??= {};
56
+ config.resolve.fallback ??= {};
57
+ config.resolve.fallback['react-server-dom-rspack/client.browser'] = emptyModulePath;
58
+ });
59
+ }
60
+ };
61
+ }
62
+ exports.rscClientBrowserFallbackPlugin = __webpack_exports__.rscClientBrowserFallbackPlugin;
63
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
64
+ "rscClientBrowserFallbackPlugin"
65
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
66
+ Object.defineProperty(exports, '__esModule', {
67
+ value: true
68
+ });
@@ -0,0 +1,274 @@
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__.n = (module)=>{
8
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
9
+ __webpack_require__.d(getter, {
10
+ a: getter
11
+ });
12
+ return getter;
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.d = (exports1, getters, values)=>{
17
+ var define = (defs, kind)=>{
18
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ [kind]: defs[key]
21
+ });
22
+ };
23
+ define(getters, "get");
24
+ define(values, "value");
25
+ };
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
29
+ })();
30
+ (()=>{
31
+ __webpack_require__.r = (exports1)=>{
32
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
33
+ value: 'Module'
34
+ });
35
+ Object.defineProperty(exports1, '__esModule', {
36
+ value: true
37
+ });
38
+ };
39
+ })();
40
+ var __webpack_exports__ = {};
41
+ __webpack_require__.r(__webpack_exports__);
42
+ __webpack_require__.d(__webpack_exports__, {
43
+ refreshTsgoCheckerConfig: ()=>refreshTsgoCheckerConfig,
44
+ withTsgoDefaults: ()=>withTsgoDefaults
45
+ });
46
+ const external_node_crypto_namespaceObject = require("node:crypto");
47
+ const external_node_fs_namespaceObject = require("node:fs");
48
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
49
+ const external_node_module_namespaceObject = require("node:module");
50
+ const external_node_path_namespaceObject = require("node:path");
51
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
52
+ const utils_namespaceObject = require("@modern-js/utils");
53
+ const builderRequire = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
54
+ const STABLE_TSGO_PACKAGE = "typescript/package.json";
55
+ const NATIVE_PREVIEW_TSGO_PACKAGE = "@typescript/native-preview/package.json";
56
+ const TSGO_CHECKER_DIR = external_node_path_default().join('.modern-js', 'tsgo');
57
+ const tryResolve = (request, rootPath)=>{
58
+ try {
59
+ return builderRequire.resolve(request, {
60
+ paths: [
61
+ rootPath
62
+ ]
63
+ });
64
+ } catch {
65
+ return;
66
+ }
67
+ };
68
+ const readPackageMajorVersion = (packageJsonPath)=>{
69
+ try {
70
+ const packageJson = JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf8'));
71
+ const major = Number.parseInt(String(packageJson.version).split('.')[0], 10);
72
+ return Number.isFinite(major) ? major : void 0;
73
+ } catch {
74
+ return;
75
+ }
76
+ };
77
+ const resolveTsgoPackagePath = (rootPath)=>{
78
+ const stableTypeScriptPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath);
79
+ if (stableTypeScriptPath && (readPackageMajorVersion(stableTypeScriptPath) ?? 0) >= 7) return stableTypeScriptPath;
80
+ const previewFromProject = tryResolve(NATIVE_PREVIEW_TSGO_PACKAGE, rootPath);
81
+ if (previewFromProject) return previewFromProject;
82
+ try {
83
+ return builderRequire.resolve(NATIVE_PREVIEW_TSGO_PACKAGE);
84
+ } catch {
85
+ return;
86
+ }
87
+ };
88
+ const toPosixPath = (input)=>input.replaceAll(external_node_path_default().sep, '/');
89
+ const asTsConfigPath = (request)=>{
90
+ if (external_node_path_default().extname(request)) return [
91
+ request
92
+ ];
93
+ return [
94
+ request,
95
+ `${request}.json`
96
+ ];
97
+ };
98
+ const resolveExtends = (request, configDirectory)=>{
99
+ const configRequire = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(configDirectory, 'tsconfig.json'));
100
+ for (const candidate of asTsConfigPath(request)){
101
+ if (candidate.startsWith('.') || external_node_path_default().isAbsolute(candidate)) {
102
+ const resolved = external_node_path_default().resolve(configDirectory, candidate);
103
+ if (external_node_fs_default().existsSync(resolved)) return resolved;
104
+ continue;
105
+ }
106
+ try {
107
+ return configRequire.resolve(candidate);
108
+ } catch {}
109
+ }
110
+ };
111
+ const PATH_COMPILER_OPTIONS = [
112
+ 'rootDir',
113
+ 'outDir',
114
+ 'declarationDir'
115
+ ];
116
+ const absolutiseConfigPaths = (compilerOptions, configDirectory)=>{
117
+ if (!compilerOptions) return {};
118
+ const resolved = {
119
+ ...compilerOptions
120
+ };
121
+ for (const option of PATH_COMPILER_OPTIONS){
122
+ const value = resolved[option];
123
+ if ('string' == typeof value && !external_node_path_default().isAbsolute(value)) resolved[option] = external_node_path_default().resolve(configDirectory, value);
124
+ }
125
+ return resolved;
126
+ };
127
+ const readTsConfig = (configFile, visited = new Set())=>{
128
+ if (visited.has(configFile) || !external_node_fs_default().existsSync(configFile)) return {};
129
+ visited.add(configFile);
130
+ const config = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(configFile, 'utf8'));
131
+ const configDirectory = external_node_path_default().dirname(configFile);
132
+ const extendsList = Array.isArray(config.extends) ? config.extends : config.extends ? [
133
+ config.extends
134
+ ] : [];
135
+ const baseConfig = extendsList.reduce((merged, request)=>{
136
+ const resolved = resolveExtends(request, configDirectory);
137
+ if (!resolved) return merged;
138
+ const parentConfig = readTsConfig(resolved, visited);
139
+ return {
140
+ ...merged,
141
+ compilerOptions: {
142
+ ...merged.compilerOptions ?? {},
143
+ ...parentConfig.compilerOptions ?? {}
144
+ }
145
+ };
146
+ }, {});
147
+ return {
148
+ ...baseConfig,
149
+ compilerOptions: {
150
+ ...baseConfig.compilerOptions ?? {},
151
+ ...absolutiseConfigPaths(config.compilerOptions, configDirectory)
152
+ }
153
+ };
154
+ };
155
+ const readProjectReferences = (configFile)=>{
156
+ if (!external_node_fs_default().existsSync(configFile)) return [];
157
+ const config = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(configFile, 'utf8'));
158
+ if (!Array.isArray(config.references)) return [];
159
+ const configDirectory = external_node_path_default().dirname(configFile);
160
+ return config.references.filter((reference)=>'string' == typeof reference?.path).map((reference)=>({
161
+ ...reference,
162
+ path: toPosixPath(external_node_path_default().resolve(configDirectory, reference.path))
163
+ }));
164
+ };
165
+ const toRelativeConfigPath = (fromDirectory, target)=>{
166
+ const relative = toPosixPath(external_node_path_default().relative(fromDirectory, target));
167
+ if (relative.startsWith('.')) return relative;
168
+ return `./${relative}`;
169
+ };
170
+ const writeFileIfChanged = (file, content)=>{
171
+ if (external_node_fs_default().existsSync(file) && external_node_fs_default().readFileSync(file, 'utf8') === content) return;
172
+ external_node_fs_default().writeFileSync(file, content);
173
+ };
174
+ const defaultTsgoCheckerConfigFile = (configFile)=>{
175
+ const hash = (0, external_node_crypto_namespaceObject.createHash)('sha1').update(configFile).digest('hex').slice(0, 10);
176
+ return external_node_path_default().join(external_node_path_default().dirname(configFile), TSGO_CHECKER_DIR, `tsconfig.${hash}.json`);
177
+ };
178
+ const createTsgoCheckerConfig = (configFile, checkerConfigFile = defaultTsgoCheckerConfigFile(configFile))=>{
179
+ const configDirectory = external_node_path_default().dirname(configFile);
180
+ const checkerConfigDirectory = external_node_path_default().dirname(checkerConfigFile);
181
+ const tsConfig = readTsConfig(configFile);
182
+ const compilerOptions = {
183
+ baseUrl: null
184
+ };
185
+ const declaredRootDir = tsConfig.compilerOptions?.rootDir;
186
+ if ('string' == typeof declaredRootDir) compilerOptions.rootDir = toPosixPath(declaredRootDir);
187
+ else if (tsConfig.compilerOptions?.composite === true) compilerOptions.rootDir = toPosixPath(configDirectory);
188
+ const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
189
+ if ([
190
+ 'node',
191
+ 'node10'
192
+ ].includes(moduleResolution)) compilerOptions.moduleResolution = null;
193
+ const references = readProjectReferences(configFile);
194
+ const checkerConfig = {
195
+ extends: toRelativeConfigPath(checkerConfigDirectory, configFile),
196
+ compilerOptions,
197
+ ...references.length > 0 ? {
198
+ references
199
+ } : {}
200
+ };
201
+ external_node_fs_default().mkdirSync(checkerConfigDirectory, {
202
+ recursive: true
203
+ });
204
+ writeFileIfChanged(checkerConfigFile, `${JSON.stringify(checkerConfig, null, 2)}\n`);
205
+ return checkerConfigFile;
206
+ };
207
+ const refreshTsgoCheckerConfig = (checkerConfigFile)=>{
208
+ const checkerConfigDirectory = external_node_path_default().dirname(checkerConfigFile);
209
+ if ('tsgo' !== external_node_path_default().basename(checkerConfigDirectory) || '.modern-js' !== external_node_path_default().basename(external_node_path_default().dirname(checkerConfigDirectory)) || !external_node_fs_default().existsSync(checkerConfigFile)) return;
210
+ let checkerConfig;
211
+ try {
212
+ checkerConfig = utils_namespaceObject.json5.parse(external_node_fs_default().readFileSync(checkerConfigFile, 'utf8'));
213
+ } catch {
214
+ return;
215
+ }
216
+ if ('string' != typeof checkerConfig.extends) return;
217
+ const projectConfigFile = external_node_path_default().resolve(checkerConfigDirectory, checkerConfig.extends);
218
+ if (external_node_fs_default().existsSync(projectConfigFile)) try {
219
+ createTsgoCheckerConfig(projectConfigFile, checkerConfigFile);
220
+ } catch {}
221
+ return projectConfigFile;
222
+ };
223
+ const normalizeTsgoConfig = (config, rootPath)=>{
224
+ const { typescript } = config;
225
+ if (typescript?.tsgo === false) return config;
226
+ const compilerOptions = {
227
+ ...typescript?.configOverwrite?.compilerOptions ?? {},
228
+ baseUrl: null
229
+ };
230
+ if ([
231
+ 'node',
232
+ 'node10'
233
+ ].includes(String(compilerOptions.moduleResolution).toLowerCase())) compilerOptions.moduleResolution = null;
234
+ config.typescript = {
235
+ ...typescript,
236
+ configOverwrite: {
237
+ ...typescript?.configOverwrite ?? {},
238
+ compilerOptions
239
+ }
240
+ };
241
+ if (typescript?.configFile) config.typescript.configFile = createTsgoCheckerConfig(external_node_path_default().resolve(rootPath, typescript.configFile));
242
+ return config;
243
+ };
244
+ const withTsgoDefaults = (userOptions, rootPath)=>{
245
+ const tsgoPath = resolveTsgoPackagePath(rootPath);
246
+ const userChain = userOptions ? Array.isArray(userOptions) ? userOptions : [
247
+ userOptions
248
+ ] : [];
249
+ return [
250
+ {
251
+ typescript: tsgoPath ? {
252
+ tsgo: true,
253
+ typescriptPath: tsgoPath
254
+ } : {
255
+ tsgo: true
256
+ }
257
+ },
258
+ ...userChain,
259
+ (config)=>{
260
+ const { typescript } = config;
261
+ if (typescript?.tsgo === false && typescript.typescriptPath === tsgoPath) typescript.typescriptPath = tryResolve("typescript", rootPath);
262
+ return normalizeTsgoConfig(config, rootPath);
263
+ }
264
+ ];
265
+ };
266
+ exports.refreshTsgoCheckerConfig = __webpack_exports__.refreshTsgoCheckerConfig;
267
+ exports.withTsgoDefaults = __webpack_exports__.withTsgoDefaults;
268
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
269
+ "refreshTsgoCheckerConfig",
270
+ "withTsgoDefaults"
271
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
272
+ Object.defineProperty(exports, '__esModule', {
273
+ value: true
274
+ });
@@ -1,7 +1,7 @@
1
- import { createRsbuild } from "@rsbuild/core";
1
+ import { createRsbuild, mergeRsbuildConfig } from "@rsbuild/core";
2
2
  import { getRscPlugins } from "./plugins/rscConfig.mjs";
3
3
  import { parseCommonConfig } from "./shared/parseCommonConfig.mjs";
4
- import { rscDisabledRuntimePlugin } from "./shared/rsc/rscDisabledRuntime.mjs";
4
+ import { rscClientBrowserFallbackPlugin } from "./shared/rsc/rscClientBrowserFallback.mjs";
5
5
  async function parseConfig(builderConfig, options) {
6
6
  builderConfig.performance ??= {};
7
7
  builderConfig.performance.buildCache ??= true;
@@ -29,10 +29,7 @@ async function parseConfig(builderConfig, options) {
29
29
  const rscEnvironments = 'object' == typeof rscConfig ? rscConfig.environments : void 0;
30
30
  const rscPlugins = await getRscPlugins(enableRsc, options.internalDirectory, rscEnvironments);
31
31
  rsbuildPlugins.push(...rscPlugins);
32
- } else rsbuildConfig.plugins = [
33
- ...rsbuildConfig.plugins ?? [],
34
- rscDisabledRuntimePlugin()
35
- ];
32
+ } else rsbuildPlugins.push(rscClientBrowserFallbackPlugin());
36
33
  return {
37
34
  rsbuildConfig,
38
35
  rsbuildPlugins
@@ -50,7 +47,19 @@ async function createRspackBuilder(options) {
50
47
  ];
51
48
  const rsbuild = await createRsbuild({
52
49
  cwd,
53
- rsbuildConfig
50
+ rsbuildConfig: mergeRsbuildConfig({
51
+ tools: {
52
+ rspack: {
53
+ module: {
54
+ parser: {
55
+ javascript: {
56
+ createRequire: true
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }, rsbuildConfig)
54
63
  });
55
64
  return {
56
65
  ...rsbuild
@@ -1,3 +1,4 @@
1
1
  export { createRspackBuilder as createBuilder, parseConfig as parseRspackConfig } from "./createBuilder.mjs";
2
2
  export { logger } from "@rsbuild/core";
3
+ export { refreshTsgoCheckerConfig } from "./shared/tsgo.mjs";
3
4
  export { RUNTIME_CHUNK_NAME, RUNTIME_CHUNK_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME, castArray, isHtmlDisabled } from "./shared/utils.mjs";
@@ -56,14 +56,13 @@ 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 && true === chain.output.get('module')) chain.output.library({
60
- ...chain.output.get('library') || {},
61
- type: 'module'
62
- });
63
- else if (isServiceWorker) chain.output.library({
64
- ...chain.output.get('library') || {},
65
- type: 'commonjs2'
66
- });
59
+ if (isServiceWorker) {
60
+ const library = chain.output.get('library');
61
+ chain.output.library({
62
+ ...'object' == typeof library && !Array.isArray(library) ? library : {},
63
+ type: true === chain.output.get('module') ? 'module' : 'commonjs2'
64
+ });
65
+ }
67
66
  });
68
67
  }
69
68
  });
@@ -8,7 +8,7 @@ const pluginManifest = ()=>({
8
8
  chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [
9
9
  {
10
10
  fileName: 'web' === target ? 'asset-manifest.json' : `asset-manifest-${target}.json`,
11
- publicPath,
11
+ publicPath: 'string' == typeof publicPath ? publicPath : void 0,
12
12
  generate: generateManifest
13
13
  }
14
14
  ]);
@@ -2,9 +2,7 @@ import path from "path";
2
2
  const ASYNC_STORAGE_PATTERN = /universal[/\\]async_storage/;
3
3
  const SERVER_LOADER_ENTRY_PATTERN = /[/\\](?:server-loader-combined|route-server-loaders)\.js$/;
4
4
  const RENDER_RSC_SOURCE_PATTERN = /render[/\\].*[/\\]server[/\\]rsc/;
5
- const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(?:Worker)?\.mjs$/;
6
- const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
7
- const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
5
+ const RENDER_RSC_RSLIB_ENTRY_PATTERN = /render[/\\]dist[/\\]esm[/\\]rsc(?:\.edge)?\.mjs$/;
8
6
  const RSC_COMMON_LAYER = 'rsc-common';
9
7
  const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
10
8
  const ROUTE_DATA_FILE_PATTERN = /[/\\]routes[/\\](?:.*[/\\])?(?:layout|page|\$)\.(?:loader|data)\.[tj]sx?(?:\?.*)?$/;
@@ -29,7 +27,6 @@ function pluginRscConfig() {
29
27
  api.modifyBundlerChain({
30
28
  handler: (chain, { isServer })=>{
31
29
  if (isServer) {
32
- chain.resolve.alias.set(`${RENDER_RSC_RUNTIME}$`, RENDER_RSC_WORKER_RUNTIME);
33
30
  let emptyModulePath;
34
31
  try {
35
32
  emptyModulePath = require.resolve('../shared/rsc/rscEmptyModule');
@@ -10,7 +10,8 @@ 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 { NODE_MODULES_REGEX } from "./utils.mjs";
13
+ import { withTsgoDefaults } from "./tsgo.mjs";
14
+ import { NODE_MODULES_REGEX, SERVICE_WORKER_ENVIRONMENT_NAME } from "./utils.mjs";
14
15
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
15
16
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
16
17
  const DEFAULT_CSS_MINIFIER_OPTIONS = {
@@ -135,7 +136,7 @@ async function parseCommonConfig(builderConfig, options) {
135
136
  if (!disableTsChecker) {
136
137
  const { pluginTypeCheck } = await import("@rsbuild/plugin-type-check");
137
138
  rsbuildPlugins.push(pluginTypeCheck({
138
- tsCheckerOptions: tsChecker
139
+ tsCheckerOptions: withTsgoDefaults(tsChecker, options?.cwd ?? process.cwd())
139
140
  }));
140
141
  }
141
142
  if (convertToRem) {
@@ -151,9 +152,23 @@ async function parseCommonConfig(builderConfig, options) {
151
152
  const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
152
153
  rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
153
154
  }
154
- rsbuildPlugins.push(pluginReact(options?.disableReactCompiler || void 0 === reactCompiler ? {} : {
155
- reactCompiler
156
- }));
155
+ rsbuildPlugins.push(pluginReact());
156
+ if (!options?.disableReactCompiler && void 0 !== reactCompiler) rsbuildPlugins.push({
157
+ name: 'builder:react-compiler',
158
+ setup (api) {
159
+ api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>'web' === config.output.target && name !== SERVICE_WORKER_ENVIRONMENT_NAME ? mergeEnvironmentConfig({
160
+ tools: {
161
+ swc: {
162
+ jsc: {
163
+ transform: {
164
+ reactCompiler
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }, config) : config);
170
+ }
171
+ });
157
172
  if (!disableSvgr) {
158
173
  const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
159
174
  rsbuildPlugins.push(pluginSvgr({