@modern-js/builder 2.46.1 → 3.0.0-alpha.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 (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +14 -16
  3. package/compiled/postcss-load-config/index.d.ts +1 -0
  4. package/compiled/postcss-load-config/index.js +14 -0
  5. package/compiled/postcss-load-config/license +20 -0
  6. package/compiled/postcss-load-config/package.json +1 -0
  7. package/dist/createBuilder.d.ts +8 -2
  8. package/dist/createBuilder.js +124 -39
  9. package/dist/index.d.ts +8 -4
  10. package/dist/index.js +18 -7
  11. package/dist/plugins/babel-post.d.ts +5 -0
  12. package/dist/plugins/{asset.js → babel-post.js} +21 -22
  13. package/dist/plugins/devtools.d.ts +4 -0
  14. package/dist/plugins/{devtool.js → devtools.js} +15 -16
  15. package/dist/plugins/emitRouteFile.d.ts +6 -0
  16. package/dist/plugins/{cleanOutput.js → emitRouteFile.js} +34 -16
  17. package/dist/plugins/environmentDefaults.d.ts +3 -0
  18. package/dist/plugins/environmentDefaults.js +99 -0
  19. package/dist/plugins/globalVars.d.ts +3 -0
  20. package/dist/plugins/{moment.js → globalVars.js} +23 -16
  21. package/dist/plugins/htmlMinify.d.ts +2 -0
  22. package/dist/plugins/htmlMinify.js +126 -0
  23. package/dist/plugins/manifest.d.ts +2 -0
  24. package/dist/plugins/{entry.js → manifest.js} +18 -16
  25. package/dist/plugins/postcss.d.ts +6 -0
  26. package/dist/plugins/postcss.js +133 -0
  27. package/dist/plugins/runtimeChunk.d.ts +2 -0
  28. package/dist/plugins/runtimeChunk.js +55 -0
  29. package/dist/rsc/common.d.ts +22 -0
  30. package/dist/rsc/common.js +174 -0
  31. package/dist/rsc/plugins/rsbuild-rsc-plugin.d.ts +7 -0
  32. package/dist/rsc/plugins/rsbuild-rsc-plugin.js +166 -0
  33. package/dist/rsc/plugins/rspack-rsc-client-plugin.d.ts +14 -0
  34. package/dist/rsc/plugins/rspack-rsc-client-plugin.js +233 -0
  35. package/dist/rsc/plugins/rspack-rsc-server-plugin.d.ts +32 -0
  36. package/dist/rsc/plugins/rspack-rsc-server-plugin.js +290 -0
  37. package/dist/rsc/rsc-client-loader.d.ts +7 -0
  38. package/dist/rsc/rsc-client-loader.js +70 -0
  39. package/dist/rsc/rsc-css-loader.d.ts +2 -0
  40. package/dist/{plugins/yaml.js → rsc/rsc-css-loader.js} +11 -17
  41. package/dist/rsc/rsc-server-loader.d.ts +6 -0
  42. package/dist/rsc/rsc-server-loader.js +95 -0
  43. package/dist/rsc/rsc-ssr-loader.d.ts +6 -0
  44. package/dist/rsc/rsc-ssr-loader.js +58 -0
  45. package/dist/shared/devServer.d.ts +6 -0
  46. package/dist/shared/devServer.js +83 -0
  47. package/dist/shared/getCssSupport.d.ts +1 -0
  48. package/dist/shared/getCssSupport.js +113 -0
  49. package/dist/shared/manifest.d.ts +2 -0
  50. package/dist/{plugins/toml.js → shared/manifest.js} +16 -14
  51. package/dist/shared/parseCommonConfig.d.ts +8 -0
  52. package/dist/shared/parseCommonConfig.js +232 -0
  53. package/dist/shared/utils.d.ts +12 -0
  54. package/dist/shared/utils.js +109 -0
  55. package/dist/types.d.ts +283 -0
  56. package/dist/types.js +16 -0
  57. package/package.json +54 -59
  58. package/dist/cli/commands.d.ts +0 -2
  59. package/dist/cli/commands.js +0 -45
  60. package/dist/cli/config.d.ts +0 -14
  61. package/dist/cli/config.js +0 -72
  62. package/dist/cli/index.d.ts +0 -6
  63. package/dist/cli/index.js +0 -51
  64. package/dist/cli/provider.d.ts +0 -2
  65. package/dist/cli/provider.js +0 -73
  66. package/dist/plugins/antd.d.ts +0 -3
  67. package/dist/plugins/antd.js +0 -63
  68. package/dist/plugins/arco.d.ts +0 -2
  69. package/dist/plugins/arco.js +0 -61
  70. package/dist/plugins/asset.d.ts +0 -2
  71. package/dist/plugins/assetsRetry.d.ts +0 -2
  72. package/dist/plugins/assetsRetry.js +0 -64
  73. package/dist/plugins/bundleAnalyzer.d.ts +0 -2
  74. package/dist/plugins/bundleAnalyzer.js +0 -59
  75. package/dist/plugins/cache.d.ts +0 -2
  76. package/dist/plugins/cache.js +0 -129
  77. package/dist/plugins/checkSyntax.d.ts +0 -2
  78. package/dist/plugins/checkSyntax.js +0 -73
  79. package/dist/plugins/cleanOutput.d.ts +0 -2
  80. package/dist/plugins/define.d.ts +0 -2
  81. package/dist/plugins/define.js +0 -68
  82. package/dist/plugins/devtool.d.ts +0 -2
  83. package/dist/plugins/entry.d.ts +0 -2
  84. package/dist/plugins/externals.d.ts +0 -2
  85. package/dist/plugins/externals.js +0 -48
  86. package/dist/plugins/fileSize.d.ts +0 -4
  87. package/dist/plugins/fileSize.js +0 -164
  88. package/dist/plugins/html.d.ts +0 -3
  89. package/dist/plugins/html.js +0 -236
  90. package/dist/plugins/index.d.ts +0 -2
  91. package/dist/plugins/index.js +0 -74
  92. package/dist/plugins/inlineChunk.d.ts +0 -2
  93. package/dist/plugins/inlineChunk.js +0 -82
  94. package/dist/plugins/moment.d.ts +0 -2
  95. package/dist/plugins/networkPerformance.d.ts +0 -2
  96. package/dist/plugins/networkPerformance.js +0 -54
  97. package/dist/plugins/nodeAddons.d.ts +0 -2
  98. package/dist/plugins/nodeAddons.js +0 -73
  99. package/dist/plugins/performance.d.ts +0 -5
  100. package/dist/plugins/performance.js +0 -66
  101. package/dist/plugins/preloadOrPrefetch.d.ts +0 -2
  102. package/dist/plugins/preloadOrPrefetch.js +0 -57
  103. package/dist/plugins/rem.d.ts +0 -2
  104. package/dist/plugins/rem.js +0 -106
  105. package/dist/plugins/sourceBuild.d.ts +0 -15
  106. package/dist/plugins/sourceBuild.js +0 -121
  107. package/dist/plugins/splitChunks.d.ts +0 -4
  108. package/dist/plugins/splitChunks.js +0 -249
  109. package/dist/plugins/startUrl.d.ts +0 -3
  110. package/dist/plugins/startUrl.js +0 -86
  111. package/dist/plugins/svg.d.ts +0 -2
  112. package/dist/plugins/svg.js +0 -89
  113. package/dist/plugins/target.d.ts +0 -2
  114. package/dist/plugins/target.js +0 -73
  115. package/dist/plugins/toml.d.ts +0 -2
  116. package/dist/plugins/tsChecker.d.ts +0 -2
  117. package/dist/plugins/tsChecker.js +0 -109
  118. package/dist/plugins/wasm.d.ts +0 -2
  119. package/dist/plugins/wasm.js +0 -51
  120. package/dist/plugins/yaml.d.ts +0 -2
  121. package/vitest.config.ts +0 -19
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rspack_rsc_server_plugin_exports = {};
20
+ __export(rspack_rsc_server_plugin_exports, {
21
+ RscServerPlugin: () => RscServerPlugin
22
+ });
23
+ module.exports = __toCommonJS(rspack_rsc_server_plugin_exports);
24
+ var import_common = require("../common");
25
+ const resourcePath2Entries = /* @__PURE__ */ new Map();
26
+ class RscServerPlugin {
27
+ isValidModule(module2) {
28
+ return Boolean(module2 === null || module2 === void 0 ? void 0 : module2.resource);
29
+ }
30
+ hasValidEntries(entries) {
31
+ return Boolean(entries && entries.length > 0);
32
+ }
33
+ getEntryNameFromIssuer(issuer) {
34
+ return issuer.resource ? this.entryPath2Name.get(issuer.resource) : void 0;
35
+ }
36
+ createEntryFromIssuer(issuer, entryName) {
37
+ return {
38
+ entryName,
39
+ entryPath: issuer.resource
40
+ };
41
+ }
42
+ buildModuleToEntriesMapping(compilation) {
43
+ this.moduleToEntries.clear();
44
+ for (const [entryName, entryDependency] of compilation.entries.entries()) {
45
+ const entryModule = compilation.moduleGraph.getModule(entryDependency.dependencies[0]);
46
+ if (!entryModule)
47
+ continue;
48
+ this.traverseModulesFromEntry(entryModule, entryName, compilation.moduleGraph, /* @__PURE__ */ new Set());
49
+ }
50
+ }
51
+ traverseModulesFromEntry(module2, entryName, moduleGraph, visited) {
52
+ if (!(module2 === null || module2 === void 0 ? void 0 : module2.resource) || visited.has(module2.resource)) {
53
+ return;
54
+ }
55
+ visited.add(module2.resource);
56
+ if (!this.moduleToEntries.has(module2.resource)) {
57
+ this.moduleToEntries.set(module2.resource, /* @__PURE__ */ new Set());
58
+ }
59
+ this.moduleToEntries.get(module2.resource).add(entryName);
60
+ for (const connection of moduleGraph.getOutgoingConnections(module2)) {
61
+ if (connection.module && "resource" in connection.module) {
62
+ this.traverseModulesFromEntry(connection.module, entryName, moduleGraph, visited);
63
+ }
64
+ }
65
+ }
66
+ findModuleEntries(module2, compilation, resourcePath2Entries2, visited = /* @__PURE__ */ new Set()) {
67
+ if (!this.isValidModule(module2) || visited.has(module2.resource)) {
68
+ return [];
69
+ }
70
+ visited.add(module2.resource);
71
+ const currentEntries = resourcePath2Entries2.get(module2.resource);
72
+ if (this.hasValidEntries(currentEntries)) {
73
+ return currentEntries;
74
+ }
75
+ const entryNames = this.moduleToEntries.get(module2.resource);
76
+ if (entryNames && entryNames.size > 0) {
77
+ const entries = [];
78
+ for (const entryName2 of entryNames) {
79
+ const entryPath = this.getEntryPathByName(entryName2, compilation);
80
+ if (entryPath) {
81
+ entries.push({
82
+ entryName: entryName2,
83
+ entryPath
84
+ });
85
+ }
86
+ }
87
+ return entries;
88
+ }
89
+ const issuer = (0, import_common.findRootIssuer)(compilation.moduleGraph, module2);
90
+ if (!issuer) {
91
+ return [];
92
+ }
93
+ const issuerEntries = this.findModuleEntries(issuer, compilation, resourcePath2Entries2, visited);
94
+ if (issuerEntries.length > 0) {
95
+ return issuerEntries;
96
+ }
97
+ const entryName = this.getEntryNameFromIssuer(issuer);
98
+ if (entryName) {
99
+ return [
100
+ this.createEntryFromIssuer(issuer, entryName)
101
+ ];
102
+ }
103
+ return [];
104
+ }
105
+ getEntryPathByName(entryName, compilation) {
106
+ const entryDependency = compilation.entries.get(entryName);
107
+ if (entryDependency && entryDependency.dependencies.length > 0) {
108
+ const firstDep = entryDependency.dependencies[0];
109
+ if ("request" in firstDep && typeof firstDep.request === "string") {
110
+ return firstDep.request;
111
+ }
112
+ }
113
+ return void 0;
114
+ }
115
+ apply(compiler) {
116
+ const { EntryPlugin, WebpackError, sources: { RawSource } } = compiler.rspack;
117
+ const includeModule = async (compilation, resource, resourceEntryNames, layer) => {
118
+ const entries = Array.from(compilation.entries.entries());
119
+ if (entries.length === 0) {
120
+ compilation.errors.push(new WebpackError(`Could not find an entry in the compilation.`));
121
+ return;
122
+ }
123
+ const includePromises = entries.filter(([entryName]) => resourceEntryNames === null || resourceEntryNames === void 0 ? void 0 : resourceEntryNames.includes(entryName)).map(([entryName]) => {
124
+ const dependency = EntryPlugin.createDependency(resource);
125
+ return new Promise((resolve, reject) => {
126
+ compilation.addInclude(compiler.context, dependency, {
127
+ name: entryName,
128
+ layer
129
+ }, (error, module2) => {
130
+ if (error) {
131
+ compilation.errors.push(error);
132
+ return reject(error);
133
+ }
134
+ if (!module2) {
135
+ const noModuleError = new WebpackError(`Module not added`);
136
+ noModuleError.file = resource;
137
+ compilation.errors.push(noModuleError);
138
+ return reject(noModuleError);
139
+ }
140
+ (0, import_common.setRscBuildInfo)(module2, {
141
+ __entryName: entryName
142
+ });
143
+ compilation.moduleGraph.getExportsInfo(module2).setUsedInUnknownWay(entryName);
144
+ resolve();
145
+ });
146
+ });
147
+ });
148
+ await Promise.all(includePromises);
149
+ };
150
+ let needsAdditionalPass = false;
151
+ compiler.hooks.finishMake.tapPromise(RscServerPlugin.name, async (compilation) => {
152
+ this.buildModuleToEntriesMapping(compilation);
153
+ const processModules = (modules) => {
154
+ let hasChangeReference2 = false;
155
+ for (const module2 of modules) {
156
+ if ("resource" in module2 && (0, import_common.isCssModule)(module2)) {
157
+ this.styles.add(module2.resource);
158
+ }
159
+ const buildInfo = (0, import_common.getRscBuildInfo)(module2);
160
+ if (!buildInfo || !buildInfo.resourcePath) {
161
+ continue;
162
+ }
163
+ if (module2.layer && buildInfo.type === "server") {
164
+ import_common.sharedData.set(buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.resourcePath, buildInfo);
165
+ }
166
+ if (!module2.layer && buildInfo.type === "client") {
167
+ import_common.sharedData.set(buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.resourcePath, buildInfo);
168
+ }
169
+ const currentReference = (buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.type) === "client" ? this.clientReferencesMap.get(buildInfo.resourcePath) : this.serverReferencesMap.get(buildInfo.resourcePath);
170
+ if ((buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.type) === "client" && !currentReference) {
171
+ hasChangeReference2 = true;
172
+ this.clientReferencesMap.set(buildInfo.resourcePath, buildInfo.clientReferences);
173
+ } else if ((buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.type) === "server" && !currentReference) {
174
+ hasChangeReference2 = true;
175
+ this.serverReferencesMap.set(buildInfo.resourcePath, buildInfo.exportNames);
176
+ }
177
+ const entries = this.findModuleEntries(module2, compilation, resourcePath2Entries);
178
+ if (entries.length > 0) {
179
+ resourcePath2Entries.set(module2.resource, entries);
180
+ }
181
+ }
182
+ return hasChangeReference2;
183
+ };
184
+ this.serverManifest = {};
185
+ const clientReferences = [
186
+ ...this.clientReferencesMap.keys()
187
+ ];
188
+ const serverReferences = [
189
+ ...this.serverReferencesMap.keys()
190
+ ];
191
+ const referencesBefore = [
192
+ ...clientReferences,
193
+ ...serverReferences
194
+ ];
195
+ let hasChangeReference = false;
196
+ await Promise.all([
197
+ ...clientReferences.map(async (resource) => {
198
+ try {
199
+ var _resourcePath2Entries_get;
200
+ await includeModule(compilation, resource, ((_resourcePath2Entries_get = resourcePath2Entries.get(resource)) === null || _resourcePath2Entries_get === void 0 ? void 0 : _resourcePath2Entries_get.map((entry) => entry.entryName)) || []);
201
+ } catch (error) {
202
+ console.error(error);
203
+ hasChangeReference = true;
204
+ this.clientReferencesMap.delete(resource);
205
+ }
206
+ }),
207
+ ...serverReferences.map(async (resource) => {
208
+ try {
209
+ var _resourcePath2Entries_get;
210
+ await includeModule(compilation, resource, ((_resourcePath2Entries_get = resourcePath2Entries.get(resource)) === null || _resourcePath2Entries_get === void 0 ? void 0 : _resourcePath2Entries_get.map((entry) => entry.entryName)) || [], import_common.rspackRscLayerName);
211
+ } catch (error) {
212
+ console.error(error);
213
+ hasChangeReference = true;
214
+ this.serverReferencesMap.delete(resource);
215
+ }
216
+ })
217
+ ]);
218
+ hasChangeReference = processModules(compilation.modules);
219
+ const referencesAfter = [
220
+ ...this.clientReferencesMap.keys(),
221
+ ...this.serverReferencesMap.keys()
222
+ ];
223
+ if (referencesBefore.length !== referencesAfter.length || !referencesAfter.every((reference) => referencesBefore.includes(reference)) && hasChangeReference) {
224
+ needsAdditionalPass = true;
225
+ }
226
+ });
227
+ compiler.hooks.done.tap(RscServerPlugin.name, () => {
228
+ import_common.sharedData.set("serverReferencesMap", this.serverReferencesMap);
229
+ import_common.sharedData.set("clientReferencesMap", this.clientReferencesMap);
230
+ import_common.sharedData.set("styles", this.styles);
231
+ });
232
+ compiler.hooks.afterCompile.tap(RscServerPlugin.name, (compilation) => {
233
+ for (const module2 of compilation.modules) {
234
+ var _getRscBuildInfo;
235
+ const resource = module2.nameForCondition();
236
+ if (!resource) {
237
+ continue;
238
+ }
239
+ const moduleId = compilation.chunkGraph.getModuleId(module2);
240
+ if (moduleId === null) {
241
+ continue;
242
+ }
243
+ if (module2.layer !== import_common.rspackRscLayerName && this.clientReferencesMap.has(resource)) {
244
+ const clientReferences = this.clientReferencesMap.get(resource);
245
+ if (clientReferences) {
246
+ for (const clientReference of clientReferences) {
247
+ clientReference.ssrId = moduleId;
248
+ }
249
+ } else {
250
+ compilation.errors.push(new WebpackError(`Could not find client references info in \`clientReferencesMap\` for ${resource}.`));
251
+ }
252
+ } else if (module2.layer === import_common.rspackRscLayerName && ((_getRscBuildInfo = (0, import_common.getRscBuildInfo)(module2)) === null || _getRscBuildInfo === void 0 ? void 0 : _getRscBuildInfo.type) === "server") {
253
+ const serverReferencesModuleInfo = (0, import_common.getRscBuildInfo)(module2);
254
+ if (serverReferencesModuleInfo) {
255
+ serverReferencesModuleInfo.moduleId = moduleId;
256
+ for (const exportName of serverReferencesModuleInfo.exportNames) {
257
+ this.serverManifest[`${moduleId}#${exportName}`] = {
258
+ id: moduleId,
259
+ chunks: [],
260
+ name: exportName
261
+ };
262
+ }
263
+ } else {
264
+ compilation.errors.push(new WebpackError(`Could not find server references module info in \`serverReferencesMap\` for ${resource}.`));
265
+ }
266
+ }
267
+ }
268
+ });
269
+ compiler.hooks.thisCompilation.tap(RscServerPlugin.name, (compilation) => {
270
+ compilation.hooks.needAdditionalPass.tap(RscServerPlugin.name, () => !(needsAdditionalPass = !needsAdditionalPass));
271
+ compilation.hooks.processAssets.tap(RscServerPlugin.name, () => {
272
+ compilation.emitAsset(this.serverManifestFilename, new RawSource(JSON.stringify(this.serverManifest, null, 2), false));
273
+ });
274
+ });
275
+ }
276
+ constructor(options) {
277
+ this.clientReferencesMap = /* @__PURE__ */ new Map();
278
+ this.serverReferencesMap = /* @__PURE__ */ new Map();
279
+ this.serverManifest = {};
280
+ this.entryPath2Name = /* @__PURE__ */ new Map();
281
+ this.moduleToEntries = /* @__PURE__ */ new Map();
282
+ this.styles = /* @__PURE__ */ new Set();
283
+ this.serverManifestFilename = (options === null || options === void 0 ? void 0 : options.serverManifestFilename) || `react-server-manifest.json`;
284
+ this.entryPath2Name = (options === null || options === void 0 ? void 0 : options.entryPath2Name) || /* @__PURE__ */ new Map();
285
+ }
286
+ }
287
+ // Annotate the CommonJS export names for ESM import in node:
288
+ 0 && (module.exports = {
289
+ RscServerPlugin
290
+ });
@@ -0,0 +1,7 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ import { type SourceMap } from './common';
3
+ export type ClientLoaderOptions = {
4
+ callServerImport?: string;
5
+ registerImport?: string;
6
+ };
7
+ export default function rscClientLoader(this: Rspack.LoaderContext<ClientLoaderOptions>, source: string, sourceMap: SourceMap): Promise<void>;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rsc_client_loader_exports = {};
20
+ __export(rsc_client_loader_exports, {
21
+ default: () => rscClientLoader
22
+ });
23
+ module.exports = __toCommonJS(rsc_client_loader_exports);
24
+ var import_common = require("./common");
25
+ async function rscClientLoader(source, sourceMap) {
26
+ this.cacheable(true);
27
+ const callback = this.async();
28
+ const ast = await (0, import_common.parseSource)(source);
29
+ const hasUseServerDirective = await (0, import_common.isServerModule)(ast);
30
+ if (!hasUseServerDirective) {
31
+ callback(null, source, sourceMap);
32
+ return;
33
+ }
34
+ const { callServerImport = `@modern-js/runtime/rsc/client`, registerImport = `@modern-js/runtime/rsc/client` } = this.getOptions();
35
+ const buildInfo = import_common.sharedData.get(this.resourcePath);
36
+ const moduleInfo = buildInfo ? {
37
+ moduleId: buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.moduleId,
38
+ exportNames: buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.exportNames
39
+ } : null;
40
+ if (!moduleInfo) {
41
+ this.emitError(new Error(`Could not find server module info in \`serverReferencesMap\` for ${this.resourcePath}.`));
42
+ callback(null, "");
43
+ return;
44
+ }
45
+ const { moduleId, exportNames } = moduleInfo;
46
+ if (!moduleId) {
47
+ this.emitError(new Error(`Could not find server module ID in \`serverReferencesMap\` for ${this.resourcePath}.`));
48
+ callback(null, "");
49
+ return;
50
+ }
51
+ if (!exportNames) {
52
+ callback(null, "");
53
+ return;
54
+ }
55
+ const importsCode = `
56
+ import { createServerReference } from "${registerImport}";
57
+ import { callServer } from "${callServerImport}";
58
+ `;
59
+ const exportsCode = exportNames.map((item) => {
60
+ const name = item;
61
+ if (name === "default") {
62
+ return `export default createServerReference("${moduleId}", callServer);`;
63
+ } else {
64
+ return `export const ${name} = createServerReference("${moduleId}#${name}", callServer);`;
65
+ }
66
+ }).join("\n");
67
+ callback(null, `${importsCode}
68
+ ${exportsCode}`);
69
+ return;
70
+ }
@@ -0,0 +1,2 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ export default function rscCssLoader(this: Rspack.LoaderContext<unknown>, source: string): string;
@@ -16,21 +16,15 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var yaml_exports = {};
20
- __export(yaml_exports, {
21
- builderPluginYaml: () => builderPluginYaml
22
- });
23
- module.exports = __toCommonJS(yaml_exports);
24
- var import_builder_shared = require("@modern-js/builder-shared");
25
- const builderPluginYaml = () => ({
26
- name: "builder-plugin-yaml",
27
- setup(api) {
28
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
29
- chain.module.rule(CHAIN_ID.RULE.YAML).type("javascript/auto").test(/\.ya?ml$/).use(CHAIN_ID.USE.YAML).loader((0, import_builder_shared.getSharedPkgCompiledPath)("yaml-loader"));
30
- });
31
- }
32
- });
33
- // Annotate the CommonJS export names for ESM import in node:
34
- 0 && (module.exports = {
35
- builderPluginYaml
19
+ var rsc_css_loader_exports = {};
20
+ __export(rsc_css_loader_exports, {
21
+ default: () => rscCssLoader
36
22
  });
23
+ module.exports = __toCommonJS(rsc_css_loader_exports);
24
+ var import_common = require("./common");
25
+ function rscCssLoader(source) {
26
+ this._module && (0, import_common.setRscBuildInfo)(this._module, {
27
+ isCssModule: true
28
+ });
29
+ return source;
30
+ }
@@ -0,0 +1,6 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ export type RscServerLoaderOptions = {
3
+ appDir: string;
4
+ runtimePath?: string;
5
+ };
6
+ export default function rscServerLoader(this: Rspack.LoaderContext<RscServerLoaderOptions>, source: string): Promise<void>;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var rsc_server_loader_exports = {};
30
+ __export(rsc_server_loader_exports, {
31
+ default: () => rscServerLoader
32
+ });
33
+ module.exports = __toCommonJS(rsc_server_loader_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_core = require("@swc/core");
36
+ var import_common = require("./common");
37
+ function extractMetadata(code) {
38
+ const metadataRegex = /\/\* @modern-js-rsc-metadata\n([\s\S]*?)\*\//;
39
+ const match = code.match(metadataRegex);
40
+ if (!match)
41
+ return null;
42
+ try {
43
+ const metadata = JSON.parse(match[1]);
44
+ return metadata;
45
+ } catch (e) {
46
+ console.error("Failed to parse metadata:", e);
47
+ return null;
48
+ }
49
+ }
50
+ async function rscServerLoader(source) {
51
+ this.cacheable(true);
52
+ const callback = this.async();
53
+ const { appDir, runtimePath = "@modern-js/runtime/rsc/server" } = this.getOptions();
54
+ const result = await (0, import_core.transform)(source, {
55
+ filename: this.resourcePath,
56
+ jsc: {
57
+ target: "es2020",
58
+ experimental: {
59
+ cacheRoot: import_path.default.resolve(appDir, "node_modules/.swc"),
60
+ plugins: [
61
+ [
62
+ require.resolve("@modern-js/flight-server-transform-plugin"),
63
+ {
64
+ appDir,
65
+ runtimePath
66
+ }
67
+ ]
68
+ ]
69
+ }
70
+ },
71
+ isModule: true
72
+ });
73
+ const { code, map } = result;
74
+ const metadata = extractMetadata(code);
75
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.directive) && metadata.directive === "client") {
76
+ const { exportNames } = metadata;
77
+ if (exportNames.length > 0) {
78
+ (0, import_common.setRscBuildInfo)(this._module, {
79
+ type: "client",
80
+ resourcePath: this.resourcePath,
81
+ clientReferences: exportNames
82
+ });
83
+ }
84
+ } else if (metadata) {
85
+ const { exportNames } = metadata;
86
+ if (exportNames.length > 0) {
87
+ (0, import_common.setRscBuildInfo)(this._module, {
88
+ type: "server",
89
+ resourcePath: this.resourcePath,
90
+ exportNames: exportNames.map((item) => item.exportName)
91
+ });
92
+ }
93
+ }
94
+ return callback(null, code, map);
95
+ }
@@ -0,0 +1,6 @@
1
+ import type { Rspack } from '@rsbuild/core';
2
+ import { type SourceMap } from './common';
3
+ export type RscSsrLoaderOptions = {
4
+ entryPath2Name: Map<string, string>;
5
+ };
6
+ export default function rscSsrLoader(this: Rspack.LoaderContext<RscSsrLoaderOptions>, source: string, sourceMap: SourceMap): Promise<void>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var rsc_ssr_loader_exports = {};
20
+ __export(rsc_ssr_loader_exports, {
21
+ default: () => rscSsrLoader
22
+ });
23
+ module.exports = __toCommonJS(rsc_ssr_loader_exports);
24
+ var import_common = require("./common");
25
+ async function rscSsrLoader(source, sourceMap) {
26
+ this.cacheable(true);
27
+ const callback = this.async();
28
+ const ast = await (0, import_common.parseSource)(source);
29
+ const hasDeclareServerDirective = await (0, import_common.isServerModule)(ast);
30
+ const resourcePath = this.resourcePath;
31
+ if (!hasDeclareServerDirective) {
32
+ callback(null, source, sourceMap);
33
+ return;
34
+ }
35
+ const exportedNames = await (0, import_common.getExportNames)(ast, true);
36
+ const importsCode = `
37
+ 'use server';
38
+ `;
39
+ const exportsCode = exportedNames.map((name) => {
40
+ if (name === "default") {
41
+ return `export default () => {throw new Error("Server actions must not be called during server-side rendering.")}`;
42
+ } else {
43
+ return `export const ${name} = () => {
44
+ throw new Error("Server actions must not be called during server-side rendering.")
45
+ }`;
46
+ }
47
+ }).join("\n");
48
+ if (exportedNames.length > 0) {
49
+ (0, import_common.setRscBuildInfo)(this._module, {
50
+ type: "server",
51
+ resourcePath,
52
+ exportNames: exportedNames
53
+ });
54
+ }
55
+ callback(null, `${importsCode}
56
+ ${exportsCode}`, sourceMap);
57
+ return;
58
+ }
@@ -0,0 +1,6 @@
1
+ import type { DevConfig, ServerConfig } from '@rsbuild/core';
2
+ import type { BuilderConfig, ToolsDevServerConfig } from '../types';
3
+ export declare const transformToRsbuildServerOptions: (dev: NonNullable<BuilderConfig["dev"]>, devServer: ToolsDevServerConfig, server?: BuilderConfig["server"]) => {
4
+ rsbuildDev: DevConfig;
5
+ rsbuildServer: ServerConfig;
6
+ };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var devServer_exports = {};
20
+ __export(devServer_exports, {
21
+ transformToRsbuildServerOptions: () => transformToRsbuildServerOptions
22
+ });
23
+ module.exports = __toCommonJS(devServer_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_ts_deepmerge = require("ts-deepmerge");
26
+ const defaultDevConfig = {
27
+ writeToDisk: (file) => !file.includes(".hot-update."),
28
+ hmr: true,
29
+ liveReload: true,
30
+ progressBar: true,
31
+ client: {
32
+ path: "/webpack-hmr",
33
+ overlay: false,
34
+ port: "<port>"
35
+ }
36
+ };
37
+ const transformToRsbuildServerOptions = (dev, devServer, server) => {
38
+ const { host, https, startUrl, beforeStartUrl, server: devServerConfig, ...devConfig } = dev;
39
+ var _server_port;
40
+ const port = process.env.PORT ? Number(process.env.PORT) : (_server_port = server === null || server === void 0 ? void 0 : server.port) !== null && _server_port !== void 0 ? _server_port : 8080;
41
+ const rsbuildDev = (0, import_ts_deepmerge.merge)(defaultDevConfig, devConfig);
42
+ delete rsbuildDev.setupMiddlewares;
43
+ const legacyServerConfig = (0, import_utils.applyOptionsChain)({}, devServer, {}, import_ts_deepmerge.merge);
44
+ var _devServerConfig_compress, _devServerConfig_headers, _devServerConfig_historyApiFallback, _devServerConfig_proxy;
45
+ const serverCofig = {
46
+ compress: (_devServerConfig_compress = devServerConfig === null || devServerConfig === void 0 ? void 0 : devServerConfig.compress) !== null && _devServerConfig_compress !== void 0 ? _devServerConfig_compress : legacyServerConfig.compress,
47
+ headers: (_devServerConfig_headers = devServerConfig === null || devServerConfig === void 0 ? void 0 : devServerConfig.headers) !== null && _devServerConfig_headers !== void 0 ? _devServerConfig_headers : legacyServerConfig.headers,
48
+ historyApiFallback: (_devServerConfig_historyApiFallback = devServerConfig === null || devServerConfig === void 0 ? void 0 : devServerConfig.historyApiFallback) !== null && _devServerConfig_historyApiFallback !== void 0 ? _devServerConfig_historyApiFallback : legacyServerConfig.historyApiFallback,
49
+ proxy: (_devServerConfig_proxy = devServerConfig === null || devServerConfig === void 0 ? void 0 : devServerConfig.proxy) !== null && _devServerConfig_proxy !== void 0 ? _devServerConfig_proxy : legacyServerConfig.proxy
50
+ };
51
+ const rsbuildServer = (0, import_utils.isProd)() ? {
52
+ publicDir: false,
53
+ htmlFallback: false,
54
+ printUrls: false
55
+ } : {
56
+ publicDir: false,
57
+ htmlFallback: false,
58
+ printUrls: false,
59
+ compress: serverCofig.compress,
60
+ headers: serverCofig.headers,
61
+ historyApiFallback: serverCofig.historyApiFallback,
62
+ proxy: serverCofig.proxy,
63
+ host,
64
+ port,
65
+ https: https ? https : void 0,
66
+ middlewareMode: true,
67
+ cors: server === null || server === void 0 ? void 0 : server.cors
68
+ };
69
+ if (!(0, import_utils.isProd)() && startUrl) {
70
+ rsbuildServer.open = beforeStartUrl ? {
71
+ target: startUrl === true ? "//localhost:<port>" : startUrl,
72
+ before: beforeStartUrl
73
+ } : startUrl;
74
+ }
75
+ return {
76
+ rsbuildDev,
77
+ rsbuildServer
78
+ };
79
+ };
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ transformToRsbuildServerOptions
83
+ });
@@ -0,0 +1 @@
1
+ export declare function getCssSupport(projectBrowserslist: string[]): Record<"customProperties" | "initial" | "pageBreak" | "fontVariant" | "mediaMinmax", boolean>;