@modern-js/uni-builder 2.64.1 → 2.64.2

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.
@@ -0,0 +1,240 @@
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
+ findModuleEntries(module2, compilation, resourcePath2Entries2, visited = /* @__PURE__ */ new Set()) {
28
+ if (!(module2 === null || module2 === void 0 ? void 0 : module2.resource) || visited.has(module2.resource)) {
29
+ return [];
30
+ }
31
+ visited.add(module2.resource);
32
+ const currentEntries = resourcePath2Entries2.get(module2.resource);
33
+ if (currentEntries && (currentEntries === null || currentEntries === void 0 ? void 0 : currentEntries.length) > 0) {
34
+ return currentEntries;
35
+ }
36
+ const issuer = (0, import_common.findRootIssuer)(compilation.moduleGraph, module2);
37
+ if (!issuer) {
38
+ return [];
39
+ }
40
+ const issuerEntries = this.findModuleEntries(issuer, compilation, resourcePath2Entries2, visited);
41
+ if (issuerEntries.length > 0) {
42
+ return issuerEntries;
43
+ }
44
+ if (issuer.resource) {
45
+ const entryName = this.entryPath2Name.get(issuer.resource);
46
+ if (entryName) {
47
+ return [
48
+ {
49
+ entryName,
50
+ entryPath: issuer.resource
51
+ }
52
+ ];
53
+ }
54
+ }
55
+ return [];
56
+ }
57
+ apply(compiler) {
58
+ const {
59
+ EntryPlugin,
60
+ WebpackError,
61
+ // dependencies: { NullDependency },
62
+ // util: {
63
+ // runtime: { getEntryRuntime },
64
+ // },
65
+ sources: { RawSource }
66
+ } = compiler.webpack;
67
+ const includeModule = async (compilation, resource, resourceEntryNames, layer) => {
68
+ const entries = Array.from(compilation.entries.entries());
69
+ if (entries.length === 0) {
70
+ compilation.errors.push(new WebpackError(`Could not find an entry in the compilation.`));
71
+ return;
72
+ }
73
+ const includePromises = entries.filter(([entryName]) => resourceEntryNames === null || resourceEntryNames === void 0 ? void 0 : resourceEntryNames.includes(entryName)).map(([entryName]) => {
74
+ const dependency = EntryPlugin.createDependency(resource, {
75
+ name: resource
76
+ });
77
+ return new Promise((resolve, reject) => {
78
+ compilation.addInclude(compiler.context, dependency, {
79
+ name: entryName,
80
+ layer
81
+ }, (error, module2) => {
82
+ if (error) {
83
+ compilation.errors.push(error);
84
+ return reject(error);
85
+ }
86
+ if (!module2) {
87
+ const noModuleError = new WebpackError(`Module not added`);
88
+ noModuleError.file = resource;
89
+ compilation.errors.push(noModuleError);
90
+ return reject(noModuleError);
91
+ }
92
+ (0, import_common.setRscBuildInfo)(module2, {
93
+ __entryName: entryName
94
+ });
95
+ compilation.moduleGraph.getExportsInfo(module2).setUsedInUnknownWay(entryName);
96
+ resolve();
97
+ });
98
+ });
99
+ });
100
+ await Promise.all(includePromises);
101
+ };
102
+ let needsAdditionalPass = false;
103
+ compiler.hooks.finishMake.tapPromise(RscServerPlugin.name, async (compilation) => {
104
+ const processModules = (modules) => {
105
+ let hasChangeReference2 = false;
106
+ for (const module2 of modules) {
107
+ if ("resource" in module2 && (0, import_common.isCssModule)(module2)) {
108
+ this.styles.add(module2.resource);
109
+ }
110
+ const buildInfo = (0, import_common.getRscBuildInfo)(module2);
111
+ if (!buildInfo || !buildInfo.resourcePath) {
112
+ continue;
113
+ }
114
+ if (module2.layer && buildInfo.type === "server") {
115
+ import_common.sharedData.set(buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.resourcePath, buildInfo);
116
+ }
117
+ if (!module2.layer && buildInfo.type === "client") {
118
+ import_common.sharedData.set(buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.resourcePath, buildInfo);
119
+ }
120
+ const currentReference = (buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.type) === "client" ? this.clientReferencesMap.get(buildInfo.resourcePath) : this.serverReferencesMap.get(buildInfo.resourcePath);
121
+ if ((buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.type) === "client" && !currentReference) {
122
+ hasChangeReference2 = true;
123
+ this.clientReferencesMap.set(buildInfo.resourcePath, buildInfo.clientReferences);
124
+ } else if ((buildInfo === null || buildInfo === void 0 ? void 0 : buildInfo.type) === "server" && !currentReference) {
125
+ hasChangeReference2 = true;
126
+ this.serverReferencesMap.set(buildInfo.resourcePath, buildInfo.exportNames);
127
+ }
128
+ const entries = this.findModuleEntries(module2, compilation, resourcePath2Entries);
129
+ if (entries.length > 0) {
130
+ resourcePath2Entries.set(module2.resource, entries);
131
+ }
132
+ }
133
+ return hasChangeReference2;
134
+ };
135
+ this.serverManifest = {};
136
+ const clientReferences = [
137
+ ...this.clientReferencesMap.keys()
138
+ ];
139
+ const serverReferences = [
140
+ ...this.serverReferencesMap.keys()
141
+ ];
142
+ const referencesBefore = [
143
+ ...clientReferences,
144
+ ...serverReferences
145
+ ];
146
+ let hasChangeReference = false;
147
+ await Promise.all([
148
+ ...clientReferences.map(async (resource) => {
149
+ try {
150
+ var _resourcePath2Entries_get;
151
+ await includeModule(compilation, resource, ((_resourcePath2Entries_get = resourcePath2Entries.get(resource)) === null || _resourcePath2Entries_get === void 0 ? void 0 : _resourcePath2Entries_get.map((entry) => entry.entryName)) || []);
152
+ } catch (error) {
153
+ console.error(error);
154
+ hasChangeReference = true;
155
+ this.clientReferencesMap.delete(resource);
156
+ }
157
+ }),
158
+ ...serverReferences.map(async (resource) => {
159
+ try {
160
+ var _resourcePath2Entries_get;
161
+ await includeModule(compilation, resource, ((_resourcePath2Entries_get = resourcePath2Entries.get(resource)) === null || _resourcePath2Entries_get === void 0 ? void 0 : _resourcePath2Entries_get.map((entry) => entry.entryName)) || [], import_common.webpackRscLayerName);
162
+ } catch (error) {
163
+ console.error(error);
164
+ hasChangeReference = true;
165
+ this.serverReferencesMap.delete(resource);
166
+ }
167
+ })
168
+ ]);
169
+ hasChangeReference = processModules(compilation.modules);
170
+ const referencesAfter = [
171
+ ...this.clientReferencesMap.keys(),
172
+ ...this.serverReferencesMap.keys()
173
+ ];
174
+ if (referencesBefore.length !== referencesAfter.length || !referencesAfter.every((reference) => referencesBefore.includes(reference)) && hasChangeReference) {
175
+ needsAdditionalPass = true;
176
+ }
177
+ });
178
+ compiler.hooks.done.tap(RscServerPlugin.name, () => {
179
+ import_common.sharedData.set("serverReferencesMap", this.serverReferencesMap);
180
+ import_common.sharedData.set("clientReferencesMap", this.clientReferencesMap);
181
+ import_common.sharedData.set("styles", this.styles);
182
+ });
183
+ compiler.hooks.afterCompile.tap(RscServerPlugin.name, (compilation) => {
184
+ for (const module2 of compilation.modules) {
185
+ var _getRscBuildInfo;
186
+ const resource = module2.nameForCondition();
187
+ if (!resource) {
188
+ continue;
189
+ }
190
+ const moduleId = compilation.chunkGraph.getModuleId(module2);
191
+ if (moduleId === null) {
192
+ continue;
193
+ }
194
+ if (module2.layer !== import_common.webpackRscLayerName && this.clientReferencesMap.has(resource)) {
195
+ const clientReferences = this.clientReferencesMap.get(resource);
196
+ if (clientReferences) {
197
+ for (const clientReference of clientReferences) {
198
+ clientReference.ssrId = moduleId;
199
+ }
200
+ } else {
201
+ compilation.errors.push(new WebpackError(`Could not find client references info in \`clientReferencesMap\` for ${resource}.`));
202
+ }
203
+ } else if (module2.layer === import_common.webpackRscLayerName && ((_getRscBuildInfo = (0, import_common.getRscBuildInfo)(module2)) === null || _getRscBuildInfo === void 0 ? void 0 : _getRscBuildInfo.type) === "server") {
204
+ const serverReferencesModuleInfo = (0, import_common.getRscBuildInfo)(module2);
205
+ if (serverReferencesModuleInfo) {
206
+ serverReferencesModuleInfo.moduleId = moduleId;
207
+ for (const exportName of serverReferencesModuleInfo.exportNames) {
208
+ this.serverManifest[`${moduleId}#${exportName}`] = {
209
+ id: moduleId,
210
+ chunks: [],
211
+ name: exportName
212
+ };
213
+ }
214
+ } else {
215
+ compilation.errors.push(new WebpackError(`Could not find server references module info in \`serverReferencesMap\` for ${resource}.`));
216
+ }
217
+ }
218
+ }
219
+ });
220
+ compiler.hooks.thisCompilation.tap(RscServerPlugin.name, (compilation, { normalModuleFactory }) => {
221
+ compilation.hooks.needAdditionalPass.tap(RscServerPlugin.name, () => !(needsAdditionalPass = !needsAdditionalPass));
222
+ compilation.hooks.processAssets.tap(RscServerPlugin.name, () => {
223
+ compilation.emitAsset(this.serverManifestFilename, new RawSource(JSON.stringify(this.serverManifest, null, 2), false));
224
+ });
225
+ });
226
+ }
227
+ constructor(options) {
228
+ this.clientReferencesMap = /* @__PURE__ */ new Map();
229
+ this.serverReferencesMap = /* @__PURE__ */ new Map();
230
+ this.serverManifest = {};
231
+ this.entryPath2Name = /* @__PURE__ */ new Map();
232
+ this.styles = /* @__PURE__ */ new Set();
233
+ this.serverManifestFilename = (options === null || options === void 0 ? void 0 : options.serverManifestFilename) || `react-server-manifest.json`;
234
+ this.entryPath2Name = (options === null || options === void 0 ? void 0 : options.entryPath2Name) || /* @__PURE__ */ new Map();
235
+ }
236
+ }
237
+ // Annotate the CommonJS export names for ESM import in node:
238
+ 0 && (module.exports = {
239
+ RscServerPlugin
240
+ });
@@ -0,0 +1,7 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ import { type SourceMap } from './common';
3
+ export type ClientLoaderOptions = {
4
+ callServerImport?: string;
5
+ registerImport?: string;
6
+ };
7
+ export default function rscClientLoader(this: 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 { LoaderContext } from 'webpack';
2
+ export default function rscCssLoader(this: LoaderContext<unknown>, source: string): string;
@@ -0,0 +1,30 @@
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_css_loader_exports = {};
20
+ __export(rsc_css_loader_exports, {
21
+ default: () => rscCssLoader
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 { LoaderContext } from 'webpack';
2
+ export type RscServerLoaderOptions = {
3
+ appDir: string;
4
+ runtimePath?: string;
5
+ };
6
+ export default function rscServerLoader(this: LoaderContext<RscServerLoaderOptions>, source: string): Promise<void>;
@@ -0,0 +1,94 @@
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
+ });
72
+ const { code, map } = result;
73
+ const metadata = extractMetadata(code);
74
+ if ((metadata === null || metadata === void 0 ? void 0 : metadata.directive) && metadata.directive === "client") {
75
+ const { exportNames } = metadata;
76
+ if (exportNames.length > 0) {
77
+ (0, import_common.setRscBuildInfo)(this._module, {
78
+ type: "client",
79
+ resourcePath: this.resourcePath,
80
+ clientReferences: exportNames
81
+ });
82
+ }
83
+ } else if (metadata) {
84
+ const { exportNames } = metadata;
85
+ if (exportNames.length > 0) {
86
+ (0, import_common.setRscBuildInfo)(this._module, {
87
+ type: "server",
88
+ resourcePath: this.resourcePath,
89
+ exportNames: exportNames.map((item) => item.exportName)
90
+ });
91
+ }
92
+ }
93
+ return callback(null, code, map);
94
+ }
@@ -0,0 +1,6 @@
1
+ import type { LoaderContext } from 'webpack';
2
+ import { type SourceMap } from './common';
3
+ export type RscSsrLoaderOptions = {
4
+ entryPath2Name: Map<string, string>;
5
+ };
6
+ export default function rscSsrLoader(this: LoaderContext<RscSsrLoaderOptions>, source: string, sourceMap: SourceMap): Promise<void>;
@@ -0,0 +1,59 @@
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 { entryPath2Name } = this.getOptions();
29
+ const ast = await (0, import_common.parseSource)(source);
30
+ const hasDeclareServerDirective = await (0, import_common.isServerModule)(ast);
31
+ const resourcePath = this.resourcePath;
32
+ if (!hasDeclareServerDirective) {
33
+ callback(null, source, sourceMap);
34
+ return;
35
+ }
36
+ const exportedNames = await (0, import_common.getExportNames)(ast, true);
37
+ const importsCode = `
38
+ 'use server';
39
+ `;
40
+ const exportsCode = exportedNames.map((name) => {
41
+ if (name === "default") {
42
+ return `export default () => {throw new Error("Server actions must not be called during server-side rendering.")}`;
43
+ } else {
44
+ return `export const ${name} = () => {
45
+ throw new Error("Server actions must not be called during server-side rendering.")
46
+ }`;
47
+ }
48
+ }).join("\n");
49
+ if (exportedNames.length > 0) {
50
+ (0, import_common.setRscBuildInfo)(this._module, {
51
+ type: "server",
52
+ resourcePath,
53
+ exportNames: exportedNames
54
+ });
55
+ }
56
+ callback(null, `${importsCode}
57
+ ${exportsCode}`, sourceMap);
58
+ return;
59
+ }
package/dist/types.d.ts CHANGED
@@ -17,6 +17,7 @@ import type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
17
17
  import type TerserPlugin from 'terser-webpack-plugin';
18
18
  import type { PluginTsLoaderOptions } from './webpack/plugins/tsLoader';
19
19
  type ArrayOrNot<T> = T | T[];
20
+ export type CacheGroup = Rspack.OptimizationSplitChunksCacheGroup;
20
21
  export type Stats = Omit<Rspack.Stats, '#private' | 'hash' | 'startTime' | 'endTime'>;
21
22
  export type RspackConfig = Rspack.Configuration;
22
23
  export type MultiStats = Rspack.MultiStats;
@@ -38,9 +39,13 @@ export type CreateBuilderCommonOptions = {
38
39
  frameworkConfigPath?: string;
39
40
  /** The root path of current project. */
40
41
  cwd: string;
42
+ rscClientRuntimePath?: string;
43
+ rscServerRuntimePath?: string;
41
44
  };
42
45
  export type BundlerType = 'rspack' | 'webpack';
43
46
  export type CreateUniBuilderOptions = {
47
+ rscClientRuntimePath?: string;
48
+ rscServerRuntimePath?: string;
44
49
  bundlerType: BundlerType;
45
50
  config: UniBuilderConfig;
46
51
  } & Partial<CreateBuilderCommonOptions>;
@@ -373,6 +378,9 @@ export type UniBuilderConfig = {
373
378
  polyfill?: Polyfill | 'ua';
374
379
  distPath?: DistPath;
375
380
  };
381
+ server?: {
382
+ rsc?: boolean;
383
+ };
376
384
  performance?: RsbuildConfig['performance'];
377
385
  security?: Omit<SecurityConfig, 'sri'>;
378
386
  tools?: Omit<ToolsConfig, 'htmlPlugin'>;
@@ -36,12 +36,13 @@ var import_core = require("@rsbuild/core");
36
36
  var import_compatLegacyPlugin = require("../shared/compatLegacyPlugin");
37
37
  var import_parseCommonConfig = require("../shared/parseCommonConfig");
38
38
  var import_postcss = require("../shared/plugins/postcss");
39
+ var import_rsbuild_rsc_plugin = require("../shared/rsc/plugins/rsbuild-rsc-plugin");
39
40
  var import_utils = require("../shared/utils");
40
41
  var import_babel = require("./plugins/babel");
41
42
  var import_moduleScopes = require("./plugins/moduleScopes");
42
43
  var import_react = require("./plugins/react");
43
44
  async function parseConfig(uniBuilderConfig, options) {
44
- var _uniBuilderConfig_tools, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2, _uniBuilderConfig_source;
45
+ var _uniBuilderConfig_tools, _uniBuilderConfig_server, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2, _uniBuilderConfig_source;
45
46
  const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
46
47
  rsbuildPlugins.push((0, import_postcss.pluginPostcss)({
47
48
  autoprefixer: (_uniBuilderConfig_tools = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools === void 0 ? void 0 : _uniBuilderConfig_tools.autoprefixer
@@ -96,6 +97,17 @@ async function parseConfig(uniBuilderConfig, options) {
96
97
  }));
97
98
  }
98
99
  rsbuildPlugins.push((0, import_react.pluginReact)());
100
+ var _uniBuilderConfig_server_rsc;
101
+ const enableRsc = (_uniBuilderConfig_server_rsc = (_uniBuilderConfig_server = uniBuilderConfig.server) === null || _uniBuilderConfig_server === void 0 ? void 0 : _uniBuilderConfig_server.rsc) !== null && _uniBuilderConfig_server_rsc !== void 0 ? _uniBuilderConfig_server_rsc : false;
102
+ if (enableRsc) {
103
+ const { rscClientRuntimePath, rscServerRuntimePath } = options;
104
+ rsbuildPlugins.push((0, import_rsbuild_rsc_plugin.rsbuildRscPlugin)({
105
+ appDir: options.cwd,
106
+ isRspack: false,
107
+ rscClientRuntimePath,
108
+ rscServerRuntimePath
109
+ }));
110
+ }
99
111
  if ((_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.tsLoader) {
100
112
  const { pluginTsLoader } = await Promise.resolve().then(() => __toESM(require("./plugins/tsLoader")));
101
113
  rsbuildPlugins.push(pluginTsLoader(uniBuilderConfig.tools.tsLoader, uniBuilderConfig.tools.babel));