@bleedingdev/modern-js-builder 3.9.0-ultramodern.9 → 3.9.3-ultramodern.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.
@@ -88,14 +88,15 @@ 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
+ ...'string' == typeof library || Array.isArray(library) ? {
95
+ name: library
96
+ } : library,
97
+ type: true === chain.output.get('module') ? 'module' : 'commonjs2'
98
+ });
99
+ }
99
100
  });
100
101
  }
101
102
  });
@@ -40,7 +40,9 @@ 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
+ ...'string' == typeof publicPath ? {
44
+ publicPath
45
+ } : {},
44
46
  generate: manifest_js_namespaceObject.generateManifest
45
47
  }
46
48
  ]);
@@ -46,19 +46,26 @@ 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?(?:\?.*)?$/;
55
53
  const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
54
+ const resolveRscEnvironments = (environments)=>{
55
+ const resolved = {
56
+ server: environments?.server ?? 'server',
57
+ client: environments?.client ?? 'client'
58
+ };
59
+ for (const [role, name] of Object.entries(resolved))if ('string' != typeof name || !name.trim()) throw new TypeError(`RSC ${role} environment must have a nonempty name`);
60
+ return resolved;
61
+ };
56
62
  const isAsyncStorageExclude = (exclude)=>{
57
63
  if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
58
64
  if (exclude instanceof RegExp) return exclude.test('universal/async_storage') || exclude.test('universal\\async_storage');
59
65
  return false;
60
66
  };
61
- function pluginRscConfig() {
67
+ function pluginRscConfig(environments, rscLayerMatchers = []) {
68
+ const serverEnvironment = resolveRscEnvironments(environments).server;
62
69
  return {
63
70
  name: 'builder:rsc-config',
64
71
  setup (api) {
@@ -71,9 +78,8 @@ function pluginRscConfig() {
71
78
  return layersCache;
72
79
  };
73
80
  api.modifyBundlerChain({
74
- handler: (chain, { isServer })=>{
75
- if (isServer) {
76
- chain.resolve.alias.set(`${RENDER_RSC_RUNTIME}$`, RENDER_RSC_WORKER_RUNTIME);
81
+ handler: (chain, { isServer, environment })=>{
82
+ if (isServer || environment.name === serverEnvironment) {
77
83
  let emptyModulePath;
78
84
  try {
79
85
  emptyModulePath = require.resolve('../shared/rsc/rscEmptyModule');
@@ -96,9 +102,25 @@ function pluginRscConfig() {
96
102
  order: 'pre'
97
103
  });
98
104
  api.modifyRspackConfig(async (config, utils)=>{
99
- const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === 'server';
105
+ const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === serverEnvironment;
100
106
  if (!isServer) return;
101
107
  const Layers = await getLayers();
108
+ if (utils.environment?.name !== serverEnvironment && rscLayerMatchers.length > 0) {
109
+ config.module ??= {};
110
+ config.module.rules ??= [];
111
+ config.module.rules.push({
112
+ test: rscLayerMatchers,
113
+ layer: Layers.rsc
114
+ }, {
115
+ issuerLayer: Layers.rsc,
116
+ resolve: {
117
+ conditionNames: [
118
+ 'react-server',
119
+ '...'
120
+ ]
121
+ }
122
+ });
123
+ }
102
124
  if (config.entry) {
103
125
  const entries = config.entry;
104
126
  const newEntries = {};
@@ -135,8 +157,8 @@ function pluginRscConfig() {
135
157
  });
136
158
  }
137
159
  });
138
- api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
139
- if (!isServer && !isWebWorker) {
160
+ api.modifyBundlerChain((chain, { isServer, isWebWorker, environment })=>{
161
+ if (!isServer && !isWebWorker && environment.name !== serverEnvironment) {
140
162
  const entries = chain.entryPoints.entries();
141
163
  if (entries && 'object' == typeof entries) for (const entryName of Object.keys(entries)){
142
164
  const entryPoint = chain.entry(entryName);
@@ -150,13 +172,12 @@ function pluginRscConfig() {
150
172
  }
151
173
  async function getRscPlugins(enableRsc, internalDirectory, environments) {
152
174
  if (enableRsc) {
175
+ const rscEnvironments = resolveRscEnvironments(environments);
153
176
  const rscLayerMatchers = createRscLayerMatchers(internalDirectory);
154
177
  const { pluginRSC } = await import("rsbuild-plugin-rsc");
155
178
  return [
156
179
  pluginRSC({
157
- ...environments ? {
158
- environments
159
- } : {},
180
+ environments: rscEnvironments,
160
181
  layers: {
161
182
  ssr: SERVER_LOADER_ENTRY_PATTERN,
162
183
  rsc: [
@@ -167,7 +188,7 @@ async function getRscPlugins(enableRsc, internalDirectory, environments) {
167
188
  ]
168
189
  }
169
190
  }),
170
- pluginRscConfig()
191
+ pluginRscConfig(rscEnvironments, rscLayerMatchers)
171
192
  ];
172
193
  }
173
194
  return [];
@@ -34,7 +34,6 @@ __webpack_require__.d(__webpack_exports__, {
34
34
  const core_namespaceObject = require("@rsbuild/core");
35
35
  const plugin_css_minimizer_namespaceObject = require("@rsbuild/plugin-css-minimizer");
36
36
  const plugin_less_namespaceObject = require("@rsbuild/plugin-less");
37
- const plugin_react_namespaceObject = require("@rsbuild/plugin-react");
38
37
  const plugin_sass_namespaceObject = require("@rsbuild/plugin-sass");
39
38
  const devtools_js_namespaceObject = require("../plugins/devtools.js");
40
39
  const emitRouteFile_js_namespaceObject = require("../plugins/emitRouteFile.js");
@@ -43,6 +42,7 @@ const globalVars_js_namespaceObject = require("../plugins/globalVars.js");
43
42
  const htmlMinify_js_namespaceObject = require("../plugins/htmlMinify.js");
44
43
  const runtimeChunk_js_namespaceObject = require("../plugins/runtimeChunk.js");
45
44
  const external_devServer_js_namespaceObject = require("./devServer.js");
45
+ const external_pluginOptions_js_namespaceObject = require("./pluginOptions.js");
46
46
  const external_tsgo_js_namespaceObject = require("./tsgo.js");
47
47
  const external_utils_js_namespaceObject = require("./utils.js");
48
48
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
@@ -70,7 +70,7 @@ function removeUndefinedKey(obj) {
70
70
  }
71
71
  async function parseCommonConfig(builderConfig, options) {
72
72
  const frameworkConfigPath = options?.frameworkConfigPath;
73
- const { plugins: [...plugins] = [], splitChunks, performance: { ...performanceConfig } = {}, output: { module = false, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetManifest, sourceMap, convertToRem, polyfill, dataUriLimit = 10000, distPath = {}, ...outputConfig } = {}, html: { outputStructure, appIcon, ...htmlConfig } = {}, source: { alias, globalVars, transformImport, reactCompiler, ...sourceConfig } = {}, dev = {}, server = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, htmlPlugin, autoprefixer, ...toolsConfig } = {}, environments = {}, resolve = {} } = builderConfig;
73
+ const { plugins: [...plugins] = [], splitChunks, performance: { ...performanceConfig } = {}, output: { module = false, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetManifest, sourceMap, convertToRem, polyfill, dataUriLimit = 10000, distPath = {}, ...outputConfig } = {}, html: { outputStructure, appIcon, ...htmlConfig } = {}, source: { alias, globalVars, transformImport, reactCompiler, ...sourceConfig } = {}, dev = {}, server = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, svgr, htmlPlugin, autoprefixer, ...toolsConfig } = {}, environments = {}, resolve = {} } = builderConfig;
74
74
  let combinedAlias;
75
75
  if (alias || resolve.alias) combinedAlias = [].concat(alias ?? []).concat(resolve.alias ?? []);
76
76
  const rsbuildConfig = {
@@ -153,12 +153,8 @@ async function parseCommonConfig(builderConfig, options) {
153
153
  sourceMap
154
154
  }),
155
155
  (0, emitRouteFile_js_namespaceObject.pluginEmitRouteFile)(),
156
- (0, plugin_sass_namespaceObject.pluginSass)({
157
- sassLoaderOptions: sass
158
- }),
159
- (0, plugin_less_namespaceObject.pluginLess)({
160
- lessLoaderOptions: less
161
- }),
156
+ (0, plugin_sass_namespaceObject.pluginSass)((0, external_pluginOptions_js_namespaceObject.normalizeSassOptions)(sass)),
157
+ (0, plugin_less_namespaceObject.pluginLess)((0, external_pluginOptions_js_namespaceObject.normalizeLessOptions)(less)),
162
158
  (0, environmentDefaults_js_namespaceObject.pluginEnvironmentDefaults)(distPath),
163
159
  (0, htmlMinify_js_namespaceObject.pluginHtmlMinifierTerser)()
164
160
  ];
@@ -185,19 +181,44 @@ async function parseCommonConfig(builderConfig, options) {
185
181
  const { pluginSourceBuild } = await import("@rsbuild/plugin-source-build");
186
182
  rsbuildPlugins.push(pluginSourceBuild(true === sourceBuild ? {} : sourceBuild));
187
183
  }
188
- rsbuildPlugins.push((0, plugin_react_namespaceObject.pluginReact)(options?.disableReactCompiler || void 0 === reactCompiler ? {} : {
189
- reactCompiler
190
- }));
191
- if (!disableSvgr) {
192
- const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
193
- rsbuildPlugins.push(pluginSvgr({
194
- mixedImport: true,
195
- parallel: true,
196
- svgrOptions: {
197
- exportType: 'component' === svgDefaultExport ? 'default' : 'named'
198
- }
199
- }));
200
- }
184
+ rsbuildPlugins.push({
185
+ name: 'rsbuild:react',
186
+ async setup (api) {
187
+ const { pluginReact } = await import("@rsbuild/plugin-react");
188
+ return pluginReact().setup(api);
189
+ }
190
+ });
191
+ if (!options?.disableReactCompiler && void 0 !== reactCompiler) rsbuildPlugins.push({
192
+ name: 'builder:react-compiler',
193
+ setup (api) {
194
+ api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>'web' === config.output.target && name !== external_utils_js_namespaceObject.SERVICE_WORKER_ENVIRONMENT_NAME ? mergeEnvironmentConfig({
195
+ tools: {
196
+ swc: {
197
+ jsc: {
198
+ transform: {
199
+ reactCompiler
200
+ }
201
+ }
202
+ }
203
+ }
204
+ }, config) : config);
205
+ }
206
+ });
207
+ const svgrOptions = (0, external_pluginOptions_js_namespaceObject.resolveSvgrOptions)({
208
+ svgr,
209
+ disableSvgr,
210
+ svgDefaultExport
211
+ });
212
+ if (false !== svgrOptions) rsbuildPlugins.push({
213
+ name: 'rsbuild:svgr',
214
+ pre: [
215
+ 'rsbuild:react'
216
+ ],
217
+ async setup (api) {
218
+ const { pluginSvgr } = await import("@rsbuild/plugin-svgr");
219
+ await pluginSvgr(svgrOptions).setup(api);
220
+ }
221
+ });
201
222
  if (assetsRetry) {
202
223
  const { pluginAssetsRetry } = await import("@rsbuild/plugin-assets-retry");
203
224
  rsbuildPlugins.push(pluginAssetsRetry(assetsRetry));
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
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");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ normalizeLessOptions: ()=>normalizeLessOptions,
32
+ normalizeSassOptions: ()=>normalizeSassOptions,
33
+ resetPluginOptionsWarnings: ()=>resetPluginOptionsWarnings,
34
+ resolveSvgrOptions: ()=>resolveSvgrOptions
35
+ });
36
+ const utils_namespaceObject = require("@modern-js/utils");
37
+ const LESS_PLUGIN_KEYS = [
38
+ 'lessLoaderOptions',
39
+ 'include',
40
+ 'exclude',
41
+ 'parallel'
42
+ ];
43
+ const SASS_PLUGIN_KEYS = [
44
+ 'sassLoaderOptions',
45
+ 'include',
46
+ 'exclude',
47
+ 'rewriteUrls'
48
+ ];
49
+ const warned = new Set();
50
+ const resetPluginOptionsWarnings = ()=>{
51
+ warned.clear();
52
+ };
53
+ const warnOnceInDev = (key, message)=>{
54
+ if (!(0, utils_namespaceObject.isDevCommand)() || warned.has(key)) return;
55
+ warned.add(key);
56
+ utils_namespaceObject.logger.warn(message);
57
+ };
58
+ const isPlainObject = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
59
+ const isPluginLevelOptions = (value, pluginKeys)=>isPlainObject(value) && pluginKeys.some((key)=>key in value);
60
+ const isEmptyObject = (value)=>isPlainObject(value) && 0 === Object.keys(value).length;
61
+ const warnIgnoredKeys = (name, value, pluginKeys, loaderOptionsKey)=>{
62
+ const pluginLevel = Object.keys(value).filter((key)=>pluginKeys.includes(key));
63
+ const ignored = Object.keys(value).filter((key)=>!pluginKeys.includes(key));
64
+ if (0 === ignored.length) return;
65
+ warnOnceInDev(`${name}:mixed`, `\`${name}\` contains plugin-level options (${pluginLevel.join(', ')}) together with other keys (${ignored.join(', ')}). The whole object is passed to the plugin, so the other keys are ignored. Move loader options under \`${loaderOptionsKey}\`.`);
66
+ };
67
+ const normalizeLessOptions = (less)=>{
68
+ if (isPluginLevelOptions(less, LESS_PLUGIN_KEYS)) {
69
+ warnIgnoredKeys('tools.less', less, LESS_PLUGIN_KEYS, 'lessLoaderOptions');
70
+ return less;
71
+ }
72
+ if (void 0 !== less && !isEmptyObject(less)) warnOnceInDev('tools.less', "`tools.less` now accepts the full options of @rsbuild/plugin-less. Passing less-loader options directly is deprecated and will stop working in the next major version. Move them under `lessLoaderOptions`:\n before: tools: { less: { lessOptions: { javascriptEnabled: true } } }\n after: tools: { less: { lessLoaderOptions: { lessOptions: { javascriptEnabled: true } } } }");
73
+ return {
74
+ lessLoaderOptions: less
75
+ };
76
+ };
77
+ const normalizeSassOptions = (sass)=>{
78
+ if (isPluginLevelOptions(sass, SASS_PLUGIN_KEYS)) {
79
+ warnIgnoredKeys('tools.sass', sass, SASS_PLUGIN_KEYS, 'sassLoaderOptions');
80
+ return sass;
81
+ }
82
+ if (void 0 !== sass && !isEmptyObject(sass)) warnOnceInDev('tools.sass', "`tools.sass` now accepts the full options of @rsbuild/plugin-sass. Passing sass-loader options directly is deprecated and will stop working in the next major version. Move them under `sassLoaderOptions`:\n before: tools: { sass: { sassOptions: { quietDeps: true } } }\n after: tools: { sass: { sassLoaderOptions: { sassOptions: { quietDeps: true } } } }");
83
+ return {
84
+ sassLoaderOptions: sass
85
+ };
86
+ };
87
+ const mergeSvgrOptions = (target, source)=>{
88
+ const svgrOptions = source.svgrOptions ? {
89
+ ...target.svgrOptions,
90
+ ...source.svgrOptions
91
+ } : target.svgrOptions;
92
+ return Object.assign(target, source, {
93
+ svgrOptions
94
+ });
95
+ };
96
+ const resolveSvgrOptions = ({ svgr, disableSvgr, svgDefaultExport })=>{
97
+ if (void 0 !== disableSvgr) warnOnceInDev('output.disableSvgr', disableSvgr ? '`output.disableSvgr` is deprecated and will be removed in the next major version. Use `tools: { svgr: false }` instead.' : '`output.disableSvgr` is deprecated and will be removed in the next major version. SVGR is enabled by default, so `output.disableSvgr: false` can be removed (or use `tools: { svgr: {} }` to keep it explicit).');
98
+ if (void 0 !== svgDefaultExport) warnOnceInDev('output.svgDefaultExport', "`output.svgDefaultExport` is deprecated and will be removed in the next major version. Use `tools.svgr.svgrOptions.exportType` instead:\n before: output: { svgDefaultExport: 'component' }\n after: tools: { svgr: { svgrOptions: { exportType: 'default' } } }\n ('url' maps to exportType: 'named')");
99
+ if (false === svgr) return false;
100
+ if (void 0 === svgr && disableSvgr) return false;
101
+ const defaults = {
102
+ mixedImport: true,
103
+ parallel: true,
104
+ svgrOptions: {
105
+ exportType: 'component' === svgDefaultExport ? 'default' : 'named'
106
+ }
107
+ };
108
+ return (0, utils_namespaceObject.applyOptionsChain)(defaults, svgr, void 0, mergeSvgrOptions);
109
+ };
110
+ exports.normalizeLessOptions = __webpack_exports__.normalizeLessOptions;
111
+ exports.normalizeSassOptions = __webpack_exports__.normalizeSassOptions;
112
+ exports.resetPluginOptionsWarnings = __webpack_exports__.resetPluginOptionsWarnings;
113
+ exports.resolveSvgrOptions = __webpack_exports__.resolveSvgrOptions;
114
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
115
+ "normalizeLessOptions",
116
+ "normalizeSassOptions",
117
+ "resetPluginOptionsWarnings",
118
+ "resolveSvgrOptions"
119
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
120
+ Object.defineProperty(exports, '__esModule', {
121
+ value: true
122
+ });
@@ -52,7 +52,6 @@ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_no
52
52
  const utils_namespaceObject = require("@modern-js/utils");
53
53
  const builderRequire = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
54
54
  const STABLE_TSGO_PACKAGE = "typescript/package.json";
55
- const NATIVE_PREVIEW_TSGO_PACKAGE = "@typescript/native-preview/package.json";
56
55
  const TSGO_CHECKER_DIR = external_node_path_default().join('.modern-js', 'tsgo');
57
56
  const tryResolve = (request, rootPath)=>{
58
57
  try {
@@ -65,25 +64,11 @@ const tryResolve = (request, rootPath)=>{
65
64
  return;
66
65
  }
67
66
  };
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
67
  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
- }
68
+ const packageJsonPath = tryResolve(STABLE_TSGO_PACKAGE, rootPath) ?? builderRequire.resolve(STABLE_TSGO_PACKAGE);
69
+ const packageJson = JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf8'));
70
+ if ("typescript" !== packageJson.name || '7.0.2' !== packageJson.version) throw new Error(`The native type checker requires typescript@7.0.2; found ${String(packageJson.name)}@${String(packageJson.version)} at ${packageJsonPath}.`);
71
+ return packageJsonPath;
87
72
  };
88
73
  const toPosixPath = (input)=>input.replaceAll(external_node_path_default().sep, '/');
89
74
  const asTsConfigPath = (request)=>{
@@ -184,7 +169,7 @@ const createTsgoCheckerConfig = (configFile, checkerConfigFile = defaultTsgoChec
184
169
  };
185
170
  const declaredRootDir = tsConfig.compilerOptions?.rootDir;
186
171
  if ('string' == typeof declaredRootDir) compilerOptions.rootDir = toPosixPath(declaredRootDir);
187
- else if (tsConfig.compilerOptions?.composite === true) compilerOptions.rootDir = toPosixPath(configDirectory);
172
+ else compilerOptions.rootDir = toPosixPath(configDirectory);
188
173
  const moduleResolution = String(tsConfig.compilerOptions?.moduleResolution).toLowerCase();
189
174
  if ([
190
175
  'node',
@@ -248,19 +233,13 @@ const withTsgoDefaults = (userOptions, rootPath)=>{
248
233
  ] : [];
249
234
  return [
250
235
  {
251
- typescript: tsgoPath ? {
236
+ typescript: {
252
237
  tsgo: true,
253
238
  typescriptPath: tsgoPath
254
- } : {
255
- tsgo: true
256
239
  }
257
240
  },
258
241
  ...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
- }
242
+ (config)=>normalizeTsgoConfig(config, rootPath)
264
243
  ];
265
244
  };
266
245
  exports.refreshTsgoCheckerConfig = __webpack_exports__.refreshTsgoCheckerConfig;
@@ -56,14 +56,15 @@ 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
+ ...'string' == typeof library || Array.isArray(library) ? {
63
+ name: library
64
+ } : library,
65
+ type: true === chain.output.get('module') ? 'module' : 'commonjs2'
66
+ });
67
+ }
67
68
  });
68
69
  }
69
70
  });
@@ -8,7 +8,9 @@ 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
+ ...'string' == typeof publicPath ? {
12
+ publicPath
13
+ } : {},
12
14
  generate: generateManifest
13
15
  }
14
16
  ]);
@@ -2,19 +2,26 @@ 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?(?:\?.*)?$/;
11
9
  const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
10
+ const resolveRscEnvironments = (environments)=>{
11
+ const resolved = {
12
+ server: environments?.server ?? 'server',
13
+ client: environments?.client ?? 'client'
14
+ };
15
+ for (const [role, name] of Object.entries(resolved))if ('string' != typeof name || !name.trim()) throw new TypeError(`RSC ${role} environment must have a nonempty name`);
16
+ return resolved;
17
+ };
12
18
  const isAsyncStorageExclude = (exclude)=>{
13
19
  if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
14
20
  if (exclude instanceof RegExp) return exclude.test('universal/async_storage') || exclude.test('universal\\async_storage');
15
21
  return false;
16
22
  };
17
- function pluginRscConfig() {
23
+ function pluginRscConfig(environments, rscLayerMatchers = []) {
24
+ const serverEnvironment = resolveRscEnvironments(environments).server;
18
25
  return {
19
26
  name: 'builder:rsc-config',
20
27
  setup (api) {
@@ -27,9 +34,8 @@ function pluginRscConfig() {
27
34
  return layersCache;
28
35
  };
29
36
  api.modifyBundlerChain({
30
- handler: (chain, { isServer })=>{
31
- if (isServer) {
32
- chain.resolve.alias.set(`${RENDER_RSC_RUNTIME}$`, RENDER_RSC_WORKER_RUNTIME);
37
+ handler: (chain, { isServer, environment })=>{
38
+ if (isServer || environment.name === serverEnvironment) {
33
39
  let emptyModulePath;
34
40
  try {
35
41
  emptyModulePath = require.resolve('../shared/rsc/rscEmptyModule');
@@ -52,9 +58,25 @@ function pluginRscConfig() {
52
58
  order: 'pre'
53
59
  });
54
60
  api.modifyRspackConfig(async (config, utils)=>{
55
- const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === 'server';
61
+ const isServer = 'node' === config.target || 'node' === utils.target || utils.environment?.name === serverEnvironment;
56
62
  if (!isServer) return;
57
63
  const Layers = await getLayers();
64
+ if (utils.environment?.name !== serverEnvironment && rscLayerMatchers.length > 0) {
65
+ config.module ??= {};
66
+ config.module.rules ??= [];
67
+ config.module.rules.push({
68
+ test: rscLayerMatchers,
69
+ layer: Layers.rsc
70
+ }, {
71
+ issuerLayer: Layers.rsc,
72
+ resolve: {
73
+ conditionNames: [
74
+ 'react-server',
75
+ '...'
76
+ ]
77
+ }
78
+ });
79
+ }
58
80
  if (config.entry) {
59
81
  const entries = config.entry;
60
82
  const newEntries = {};
@@ -91,8 +113,8 @@ function pluginRscConfig() {
91
113
  });
92
114
  }
93
115
  });
94
- api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
95
- if (!isServer && !isWebWorker) {
116
+ api.modifyBundlerChain((chain, { isServer, isWebWorker, environment })=>{
117
+ if (!isServer && !isWebWorker && environment.name !== serverEnvironment) {
96
118
  const entries = chain.entryPoints.entries();
97
119
  if (entries && 'object' == typeof entries) for (const entryName of Object.keys(entries)){
98
120
  const entryPoint = chain.entry(entryName);
@@ -106,13 +128,12 @@ function pluginRscConfig() {
106
128
  }
107
129
  async function getRscPlugins(enableRsc, internalDirectory, environments) {
108
130
  if (enableRsc) {
131
+ const rscEnvironments = resolveRscEnvironments(environments);
109
132
  const rscLayerMatchers = createRscLayerMatchers(internalDirectory);
110
133
  const { pluginRSC } = await import("rsbuild-plugin-rsc");
111
134
  return [
112
135
  pluginRSC({
113
- ...environments ? {
114
- environments
115
- } : {},
136
+ environments: rscEnvironments,
116
137
  layers: {
117
138
  ssr: SERVER_LOADER_ENTRY_PATTERN,
118
139
  rsc: [
@@ -123,7 +144,7 @@ async function getRscPlugins(enableRsc, internalDirectory, environments) {
123
144
  ]
124
145
  }
125
146
  }),
126
- pluginRscConfig()
147
+ pluginRscConfig(rscEnvironments, rscLayerMatchers)
127
148
  ];
128
149
  }
129
150
  return [];