@modern-js/builder 3.0.0-alpha.0 → 3.0.0-alpha.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.
Files changed (136) hide show
  1. package/dist/cjs/createBuilder.js +96 -0
  2. package/dist/cjs/index.js +59 -0
  3. package/dist/cjs/plugins/devtools.js +47 -0
  4. package/dist/cjs/plugins/emitRouteFile.js +75 -0
  5. package/dist/cjs/plugins/environmentDefaults.js +100 -0
  6. package/dist/cjs/plugins/globalVars.js +55 -0
  7. package/dist/cjs/plugins/htmlMinify.js +115 -0
  8. package/dist/cjs/plugins/manifest.js +52 -0
  9. package/dist/cjs/plugins/postcss.js +118 -0
  10. package/dist/cjs/plugins/runtimeChunk.js +54 -0
  11. package/dist/cjs/rsc/common.js +157 -0
  12. package/dist/cjs/rsc/plugins/rsbuild-rsc-plugin.js +169 -0
  13. package/dist/cjs/rsc/plugins/rspack-rsc-client-plugin.js +187 -0
  14. package/dist/cjs/rsc/plugins/rspack-rsc-server-plugin.js +245 -0
  15. package/dist/cjs/rsc/rsc-client-loader.js +71 -0
  16. package/dist/cjs/rsc/rsc-css-loader.js +42 -0
  17. package/dist/cjs/rsc/rsc-server-loader.js +102 -0
  18. package/dist/cjs/rsc/rsc-ssr-loader.js +60 -0
  19. package/dist/cjs/shared/devServer.js +87 -0
  20. package/dist/cjs/shared/getCssSupport.js +121 -0
  21. package/dist/cjs/shared/manifest.js +46 -0
  22. package/dist/cjs/shared/parseCommonConfig.js +209 -0
  23. package/dist/cjs/shared/rsc/rscClientBrowserFallback.js +64 -0
  24. package/dist/cjs/shared/rsc/rscEmptyModule.js +36 -0
  25. package/dist/cjs/shared/utils.js +115 -0
  26. package/dist/cjs/types.js +18 -0
  27. package/dist/compiled/postcss-load-config/index.d.ts +1 -0
  28. package/dist/compiled/postcss-load-config/index.js +608 -0
  29. package/dist/compiled/postcss-load-config/index.js.LICENSE.txt +13 -0
  30. package/dist/compiled/postcss-load-config/license +20 -0
  31. package/dist/compiled/postcss-load-config/package.json +1 -0
  32. package/dist/esm/createBuilder.mjs +59 -0
  33. package/dist/esm/index.mjs +4 -0
  34. package/dist/esm/plugins/devtools.mjs +13 -0
  35. package/dist/esm/plugins/emitRouteFile.mjs +28 -0
  36. package/dist/esm/plugins/environmentDefaults.mjs +66 -0
  37. package/dist/esm/plugins/globalVars.mjs +21 -0
  38. package/dist/esm/plugins/htmlMinify.mjs +81 -0
  39. package/dist/esm/plugins/manifest.mjs +18 -0
  40. package/dist/esm/plugins/postcss.mjs +81 -0
  41. package/dist/esm/plugins/runtimeChunk.mjs +20 -0
  42. package/dist/esm/rsc/common.mjs +87 -0
  43. package/dist/esm/rsc/plugins/rsbuild-rsc-plugin.mjs +124 -0
  44. package/dist/esm/rsc/plugins/rspack-rsc-client-plugin.mjs +143 -0
  45. package/dist/esm/rsc/plugins/rspack-rsc-server-plugin.mjs +211 -0
  46. package/dist/esm/rsc/rsc-client-loader.mjs +37 -0
  47. package/dist/esm/rsc/rsc-css-loader.mjs +8 -0
  48. package/dist/esm/rsc/rsc-server-loader.mjs +58 -0
  49. package/dist/esm/rsc/rsc-ssr-loader.mjs +26 -0
  50. package/dist/esm/shared/devServer.mjs +53 -0
  51. package/dist/esm/shared/getCssSupport.mjs +77 -0
  52. package/dist/esm/shared/manifest.mjs +12 -0
  53. package/dist/esm/shared/parseCommonConfig.mjs +172 -0
  54. package/dist/esm/shared/rsc/rscClientBrowserFallback.mjs +20 -0
  55. package/dist/esm/shared/rsc/rscEmptyModule.mjs +2 -0
  56. package/dist/esm/shared/utils.mjs +53 -0
  57. package/dist/esm/types.mjs +0 -0
  58. package/dist/esm-node/createBuilder.mjs +61 -0
  59. package/dist/esm-node/index.mjs +6 -0
  60. package/dist/esm-node/plugins/devtools.mjs +15 -0
  61. package/dist/esm-node/plugins/emitRouteFile.mjs +30 -0
  62. package/dist/esm-node/plugins/environmentDefaults.mjs +68 -0
  63. package/dist/esm-node/plugins/globalVars.mjs +23 -0
  64. package/dist/esm-node/plugins/htmlMinify.mjs +83 -0
  65. package/dist/esm-node/plugins/manifest.mjs +20 -0
  66. package/dist/esm-node/plugins/postcss.mjs +83 -0
  67. package/dist/esm-node/plugins/runtimeChunk.mjs +22 -0
  68. package/dist/esm-node/rsc/common.mjs +89 -0
  69. package/dist/esm-node/rsc/plugins/rsbuild-rsc-plugin.mjs +126 -0
  70. package/dist/esm-node/rsc/plugins/rspack-rsc-client-plugin.mjs +145 -0
  71. package/dist/esm-node/rsc/plugins/rspack-rsc-server-plugin.mjs +213 -0
  72. package/dist/esm-node/rsc/rsc-client-loader.mjs +39 -0
  73. package/dist/esm-node/rsc/rsc-css-loader.mjs +10 -0
  74. package/dist/esm-node/rsc/rsc-server-loader.mjs +60 -0
  75. package/dist/esm-node/rsc/rsc-ssr-loader.mjs +28 -0
  76. package/dist/esm-node/shared/devServer.mjs +55 -0
  77. package/dist/esm-node/shared/getCssSupport.mjs +79 -0
  78. package/dist/esm-node/shared/manifest.mjs +14 -0
  79. package/dist/esm-node/shared/parseCommonConfig.mjs +174 -0
  80. package/dist/esm-node/shared/rsc/rscClientBrowserFallback.mjs +25 -0
  81. package/dist/esm-node/shared/rsc/rscEmptyModule.mjs +4 -0
  82. package/dist/esm-node/shared/utils.mjs +55 -0
  83. package/dist/esm-node/types.mjs +2 -0
  84. package/dist/types/shared/rsc/rscClientBrowserFallback.d.ts +2 -0
  85. package/dist/types/shared/rsc/rscEmptyModule.d.ts +2 -0
  86. package/dist/{types.d.ts → types/types.d.ts} +2 -16
  87. package/package.json +36 -31
  88. package/dist/createBuilder.js +0 -153
  89. package/dist/index.js +0 -45
  90. package/dist/plugins/babel-post.d.ts +0 -5
  91. package/dist/plugins/babel-post.js +0 -57
  92. package/dist/plugins/devtools.js +0 -42
  93. package/dist/plugins/emitRouteFile.js +0 -70
  94. package/dist/plugins/environmentDefaults.js +0 -99
  95. package/dist/plugins/globalVars.js +0 -50
  96. package/dist/plugins/htmlMinify.js +0 -126
  97. package/dist/plugins/manifest.js +0 -54
  98. package/dist/plugins/postcss.js +0 -133
  99. package/dist/plugins/runtimeChunk.js +0 -55
  100. package/dist/rsc/common.js +0 -174
  101. package/dist/rsc/plugins/rsbuild-rsc-plugin.js +0 -166
  102. package/dist/rsc/plugins/rspack-rsc-client-plugin.js +0 -233
  103. package/dist/rsc/plugins/rspack-rsc-server-plugin.js +0 -290
  104. package/dist/rsc/rsc-client-loader.js +0 -70
  105. package/dist/rsc/rsc-css-loader.js +0 -30
  106. package/dist/rsc/rsc-server-loader.js +0 -95
  107. package/dist/rsc/rsc-ssr-loader.js +0 -58
  108. package/dist/shared/devServer.js +0 -83
  109. package/dist/shared/getCssSupport.js +0 -113
  110. package/dist/shared/manifest.js +0 -38
  111. package/dist/shared/parseCommonConfig.js +0 -232
  112. package/dist/shared/utils.js +0 -109
  113. package/dist/types.js +0 -16
  114. /package/dist/{createBuilder.d.ts → types/createBuilder.d.ts} +0 -0
  115. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  116. /package/dist/{plugins → types/plugins}/devtools.d.ts +0 -0
  117. /package/dist/{plugins → types/plugins}/emitRouteFile.d.ts +0 -0
  118. /package/dist/{plugins → types/plugins}/environmentDefaults.d.ts +0 -0
  119. /package/dist/{plugins → types/plugins}/globalVars.d.ts +0 -0
  120. /package/dist/{plugins → types/plugins}/htmlMinify.d.ts +0 -0
  121. /package/dist/{plugins → types/plugins}/manifest.d.ts +0 -0
  122. /package/dist/{plugins → types/plugins}/postcss.d.ts +0 -0
  123. /package/dist/{plugins → types/plugins}/runtimeChunk.d.ts +0 -0
  124. /package/dist/{rsc → types/rsc}/common.d.ts +0 -0
  125. /package/dist/{rsc → types/rsc}/plugins/rsbuild-rsc-plugin.d.ts +0 -0
  126. /package/dist/{rsc → types/rsc}/plugins/rspack-rsc-client-plugin.d.ts +0 -0
  127. /package/dist/{rsc → types/rsc}/plugins/rspack-rsc-server-plugin.d.ts +0 -0
  128. /package/dist/{rsc → types/rsc}/rsc-client-loader.d.ts +0 -0
  129. /package/dist/{rsc → types/rsc}/rsc-css-loader.d.ts +0 -0
  130. /package/dist/{rsc → types/rsc}/rsc-server-loader.d.ts +0 -0
  131. /package/dist/{rsc → types/rsc}/rsc-ssr-loader.d.ts +0 -0
  132. /package/dist/{shared → types/shared}/devServer.d.ts +0 -0
  133. /package/dist/{shared → types/shared}/getCssSupport.d.ts +0 -0
  134. /package/dist/{shared → types/shared}/manifest.d.ts +0 -0
  135. /package/dist/{shared → types/shared}/parseCommonConfig.d.ts +0 -0
  136. /package/dist/{shared → types/shared}/utils.d.ts +0 -0
@@ -1,233 +0,0 @@
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 rspack_rsc_client_plugin_exports = {};
30
- __export(rspack_rsc_client_plugin_exports, {
31
- RspackRscClientPlugin: () => RspackRscClientPlugin
32
- });
33
- module.exports = __toCommonJS(rspack_rsc_client_plugin_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_common = require("../common");
36
- const hasExtension = (filePath) => {
37
- return import_path.default.extname(filePath) !== "";
38
- };
39
- class RspackRscClientPlugin {
40
- apply(compiler) {
41
- const { EntryPlugin, RuntimeGlobals, RuntimeModule, WebpackError, sources: { RawSource } } = compiler.rspack;
42
- const ssrManifest = {
43
- moduleMap: {},
44
- moduleLoading: null,
45
- styles: []
46
- };
47
- const getEntryModule = (compilation) => {
48
- const entryModules = [];
49
- for (const [, entryValue] of compilation.entries.entries()) {
50
- const entryDependency = entryValue.dependencies[0];
51
- if (!entryDependency) {
52
- compilation.errors.push(new WebpackError(`Could not find an entry dependency.`));
53
- continue;
54
- }
55
- const resolvedModule = compilation.moduleGraph.getModule(entryDependency);
56
- if (resolvedModule) {
57
- entryModules.push(resolvedModule);
58
- }
59
- }
60
- if (entryModules.length === 0) {
61
- compilation.errors.push(new WebpackError(`Could not find any entries in the compilation.`));
62
- return [];
63
- }
64
- return entryModules;
65
- };
66
- const addClientReferencesChunks = (compilation, callback) => {
67
- const promises = [];
68
- [
69
- ...this.clientReferencesMap.keys()
70
- ].forEach((resourcePath) => {
71
- const entries = compilation.entries.entries();
72
- for (const [entryName, entry] of entries) {
73
- const runtimeName = entry.options.runtime || entryName;
74
- if (hasExtension(entryName)) {
75
- continue;
76
- }
77
- const dependency = EntryPlugin.createDependency(resourcePath);
78
- promises.push(new Promise((resolve, reject) => {
79
- compilation.addInclude(compiler.context, dependency, {
80
- name: entryName
81
- }, (error, module2) => {
82
- if (error) {
83
- reject(error);
84
- } else {
85
- compilation.moduleGraph.getExportsInfo(module2).setUsedInUnknownWay(runtimeName);
86
- this.dependencies.push(dependency);
87
- resolve(void 0);
88
- }
89
- });
90
- }));
91
- }
92
- });
93
- if (this.styles && this.styles.size > 0) {
94
- for (const style of this.styles) {
95
- const dependency = EntryPlugin.createDependency(style);
96
- promises.push(new Promise((resolve, reject) => {
97
- compilation.addInclude(compiler.context, dependency, {
98
- name: void 0
99
- }, (error, module2) => {
100
- if (error) {
101
- reject(error);
102
- } else {
103
- compilation.moduleGraph.getExportsInfo(module2).setUsedInUnknownWay(void 0);
104
- this.dependencies.push(dependency);
105
- resolve(void 0);
106
- }
107
- });
108
- }));
109
- }
110
- }
111
- Promise.all(promises).then(() => callback(null)).catch((error) => callback(error));
112
- };
113
- compiler.hooks.finishMake.tapAsync(RspackRscClientPlugin.name, (compilation, callback) => {
114
- const entryModules = getEntryModule(compilation);
115
- for (const entryModule of entryModules) {
116
- if (entryModule) {
117
- addClientReferencesChunks(compilation, callback);
118
- }
119
- }
120
- });
121
- compiler.hooks.compilation.tap(RspackRscClientPlugin.name, (compilation) => {
122
- class EntryNameRuntimeModule extends RuntimeModule {
123
- generate() {
124
- return `window.__MODERN_JS_ENTRY_NAME="${this.entryName}";`;
125
- }
126
- constructor(entryName) {
127
- super("entry-name", 10);
128
- this.entryName = entryName;
129
- }
130
- }
131
- compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.ensureChunk).tap(RspackRscClientPlugin.name, (chunk) => {
132
- Array.from(compilation.entrypoints.entries()).forEach(([entryName, entrypoint]) => {
133
- if (entrypoint.chunks.includes(chunk)) {
134
- compilation.addRuntimeModule(chunk, new EntryNameRuntimeModule(entryName));
135
- }
136
- });
137
- });
138
- });
139
- compiler.hooks.thisCompilation.tap(RspackRscClientPlugin.name, (compilation) => {
140
- this.styles = import_common.sharedData.get("styles");
141
- this.clientReferencesMap = import_common.sharedData.get("clientReferencesMap");
142
- compilation.hooks.additionalTreeRuntimeRequirements.tap(RspackRscClientPlugin.name, (_chunk, runtimeRequirements) => {
143
- runtimeRequirements.add(RuntimeGlobals.ensureChunkHandlers);
144
- runtimeRequirements.add(RuntimeGlobals.ensureChunk);
145
- runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);
146
- });
147
- compilation.hooks.processAssets.tap(RspackRscClientPlugin.name, () => {
148
- const clientManifest = {};
149
- const { chunkGraph, moduleGraph } = compilation;
150
- for (const dependency of this.dependencies) {
151
- const module2 = moduleGraph.getModule(dependency);
152
- if (!module2) {
153
- continue;
154
- }
155
- const resourcePath = module2.nameForCondition();
156
- const clientReferences = resourcePath ? this.clientReferencesMap.get(resourcePath) : void 0;
157
- if (clientReferences) {
158
- const moduleId = chunkGraph.getModuleId(module2);
159
- const ssrModuleMetaData = {};
160
- for (const { id, exportName, ssrId } of clientReferences) {
161
- const clientExportName = exportName;
162
- const ssrExportName = exportName;
163
- const chunksSet = /* @__PURE__ */ new Set();
164
- for (const chunk of chunkGraph.getModuleChunksIterable(module2)) {
165
- chunksSet.add(chunk);
166
- }
167
- for (const connection of moduleGraph.getOutgoingConnections(module2)) {
168
- for (const chunk of chunkGraph.getModuleChunksIterable(connection.module)) {
169
- chunksSet.add(chunk);
170
- }
171
- }
172
- const chunks = [];
173
- const styles = [];
174
- for (const chunk of chunksSet) {
175
- if (chunk.id) {
176
- for (const file of chunk.files) {
177
- if (file.endsWith(".js")) {
178
- chunks.push(chunk.id, file);
179
- }
180
- }
181
- }
182
- }
183
- clientManifest[id] = {
184
- id: moduleId,
185
- name: clientExportName,
186
- chunks,
187
- styles
188
- };
189
- if (ssrId) {
190
- ssrModuleMetaData[clientExportName] = {
191
- id: ssrId,
192
- name: ssrExportName,
193
- chunks: []
194
- };
195
- }
196
- }
197
- ssrManifest.moduleMap[moduleId] = ssrModuleMetaData;
198
- }
199
- }
200
- compilation.emitAsset(this.clientManifestFilename, new RawSource(JSON.stringify(clientManifest, null, 2), false));
201
- const { crossOriginLoading, publicPath = `` } = compilation.outputOptions;
202
- var _compilation_hash;
203
- ssrManifest.moduleLoading = {
204
- // https://github.com/webpack/webpack/blob/87660921808566ef3b8796f8df61bd79fc026108/lib/runtime/PublicPathRuntimeModule.js#L30-L32
205
- prefix: compilation.getPath(publicPath, {
206
- hash: (_compilation_hash = compilation.hash) !== null && _compilation_hash !== void 0 ? _compilation_hash : `XXXX`
207
- }),
208
- crossOrigin: crossOriginLoading ? crossOriginLoading === `use-credentials` ? crossOriginLoading : `` : void 0
209
- };
210
- if (this.styles && this.styles.size > 0) {
211
- const assets = compilation.getAssets();
212
- const cssAsset = assets.find((asset) => {
213
- return asset.name.endsWith(".css");
214
- });
215
- if (cssAsset) {
216
- ssrManifest.styles.push(cssAsset.name);
217
- }
218
- }
219
- compilation.emitAsset(this.ssrManifestFilename, new RawSource(JSON.stringify(ssrManifest, null, 2), false));
220
- });
221
- });
222
- }
223
- constructor(options) {
224
- this.clientReferencesMap = /* @__PURE__ */ new Map();
225
- this.dependencies = [];
226
- this.clientManifestFilename = (options === null || options === void 0 ? void 0 : options.clientManifestFilename) || `react-client-manifest.json`;
227
- this.ssrManifestFilename = (options === null || options === void 0 ? void 0 : options.ssrManifestFilename) || `react-ssr-manifest.json`;
228
- }
229
- }
230
- // Annotate the CommonJS export names for ESM import in node:
231
- 0 && (module.exports = {
232
- RspackRscClientPlugin
233
- });
@@ -1,290 +0,0 @@
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
- });
@@ -1,70 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
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
- }