@bleedingdev/modern-js-builder 3.4.0-ultramodern.9 → 3.5.0-ultramodern.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -37,6 +37,7 @@ var __webpack_require__ = {};
|
|
|
37
37
|
var __webpack_exports__ = {};
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
enrichServerOnlyDiagnostics: ()=>enrichServerOnlyDiagnostics,
|
|
40
41
|
getRscPlugins: ()=>getRscPlugins,
|
|
41
42
|
pluginRscConfig: ()=>pluginRscConfig
|
|
42
43
|
});
|
|
@@ -50,6 +51,9 @@ const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
|
|
|
50
51
|
const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
|
|
51
52
|
const RSC_COMMON_LAYER = 'rsc-common';
|
|
52
53
|
const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
|
|
54
|
+
const SERVER_ONLY_MARKER_PATTERN = /(?:^|[/\\])server-only[/\\]index\.js(?:\?|$)/;
|
|
55
|
+
const SERVER_ONLY_MESSAGE_PATTERN = /server-only|server only|only works in a Server Component|cannot be imported (?:directly )?(?:from|into) (?:a )?Client Component/i;
|
|
56
|
+
const SERVER_ONLY_DIAGNOSTIC_PREFIX = '[Modern.js RSC server-only diagnostic context]';
|
|
53
57
|
const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
|
|
54
58
|
const isAsyncStorageExclude = (exclude)=>{
|
|
55
59
|
if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
|
|
@@ -88,6 +92,102 @@ const disableReactCompilerInSwcLoaders = (value, seen = new WeakSet())=>{
|
|
|
88
92
|
}
|
|
89
93
|
for (const item of Object.values(record))disableReactCompilerInSwcLoaders(item, seen);
|
|
90
94
|
};
|
|
95
|
+
const normalizeDiagnosticText = (diagnostic)=>[
|
|
96
|
+
diagnostic.message,
|
|
97
|
+
diagnostic.details,
|
|
98
|
+
diagnostic.file,
|
|
99
|
+
getModulePath(diagnostic.module),
|
|
100
|
+
getModuleIdentifier(diagnostic.module)
|
|
101
|
+
].filter((item)=>Boolean(item)).join('\n');
|
|
102
|
+
const isServerOnlyDiagnostic = (diagnostic)=>{
|
|
103
|
+
const text = normalizeDiagnosticText(diagnostic);
|
|
104
|
+
return SERVER_ONLY_MARKER_PATTERN.test(text) || SERVER_ONLY_MESSAGE_PATTERN.test(text);
|
|
105
|
+
};
|
|
106
|
+
const isEnrichedServerOnlyDiagnostic = (diagnostic)=>diagnostic.message.includes(SERVER_ONLY_DIAGNOSTIC_PREFIX) || diagnostic.details?.includes(SERVER_ONLY_DIAGNOSTIC_PREFIX);
|
|
107
|
+
const getModulePath = (module)=>{
|
|
108
|
+
if (!module) return;
|
|
109
|
+
return module.resource || module.nameForCondition?.() || module.userRequest;
|
|
110
|
+
};
|
|
111
|
+
const getModuleIdentifier = (module)=>{
|
|
112
|
+
if (!module) return;
|
|
113
|
+
return getModulePath(module) || module.readableIdentifier?.() || module.identifier?.() || module.request || module.rawRequest;
|
|
114
|
+
};
|
|
115
|
+
const formatModuleContext = (module)=>{
|
|
116
|
+
const id = getModuleIdentifier(module);
|
|
117
|
+
if (!id) return;
|
|
118
|
+
const layer = module?.layer ? ` [layer: ${module.layer}]` : '';
|
|
119
|
+
return `${id}${layer}`;
|
|
120
|
+
};
|
|
121
|
+
const getIssuerChain = (compilation, module)=>{
|
|
122
|
+
const chain = [];
|
|
123
|
+
const seen = new Set();
|
|
124
|
+
let current = module;
|
|
125
|
+
while(current && !seen.has(current) && chain.length < 8){
|
|
126
|
+
seen.add(current);
|
|
127
|
+
const issuer = compilation.moduleGraph?.getIssuer?.(current);
|
|
128
|
+
const formatted = formatModuleContext(issuer);
|
|
129
|
+
if (!issuer || !formatted) break;
|
|
130
|
+
chain.push(formatted);
|
|
131
|
+
current = issuer;
|
|
132
|
+
}
|
|
133
|
+
return chain;
|
|
134
|
+
};
|
|
135
|
+
const getModuleTraceChain = (diagnostic)=>{
|
|
136
|
+
const trace = diagnostic.moduleTrace || [];
|
|
137
|
+
const chain = [];
|
|
138
|
+
for (const item of trace){
|
|
139
|
+
const formatted = formatModuleContext(item.origin) || item.originName || formatModuleContext(item.module) || item.moduleName;
|
|
140
|
+
if (formatted && !chain.includes(formatted)) chain.push(formatted);
|
|
141
|
+
}
|
|
142
|
+
return chain.slice(0, 8);
|
|
143
|
+
};
|
|
144
|
+
const appendDiagnosticDetails = (diagnostic, lines)=>{
|
|
145
|
+
const context = `${SERVER_ONLY_DIAGNOSTIC_PREFIX}\n${lines.join('\n')}`;
|
|
146
|
+
diagnostic.details = diagnostic.details ? `${diagnostic.details}\n\n${context}` : context;
|
|
147
|
+
};
|
|
148
|
+
const enrichServerOnlyDiagnostics = (compilation, environmentName)=>{
|
|
149
|
+
const diagnostics = [
|
|
150
|
+
...compilation.warnings,
|
|
151
|
+
...compilation.errors
|
|
152
|
+
];
|
|
153
|
+
for (const diagnostic of diagnostics){
|
|
154
|
+
if (!isServerOnlyDiagnostic(diagnostic) || isEnrichedServerOnlyDiagnostic(diagnostic)) continue;
|
|
155
|
+
const lines = [
|
|
156
|
+
`Environment: ${environmentName || compilation.name || 'unknown'}`
|
|
157
|
+
];
|
|
158
|
+
const markerModule = formatModuleContext(diagnostic.module);
|
|
159
|
+
if (markerModule) lines.push(`Matched module: ${markerModule}`);
|
|
160
|
+
const issuerChain = getIssuerChain(compilation, diagnostic.module);
|
|
161
|
+
const moduleTraceChain = getModuleTraceChain(diagnostic);
|
|
162
|
+
const importerChain = issuerChain.length > 0 ? issuerChain : moduleTraceChain;
|
|
163
|
+
if (importerChain.length > 0) lines.push(`Importer chain: ${importerChain.join(' -> ')}`);
|
|
164
|
+
appendDiagnosticDetails(diagnostic, lines);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const applyServerOnlyDiagnosticPlugin = (compiler, environmentName)=>{
|
|
168
|
+
compiler.hooks.thisCompilation.tap('ModernJsServerOnlyDiagnosticContextPlugin', (compilation)=>{
|
|
169
|
+
compilation.hooks.processWarnings.tap('ModernJsServerOnlyDiagnosticContextPlugin', (warnings)=>{
|
|
170
|
+
enrichServerOnlyDiagnostics({
|
|
171
|
+
errors: compilation.errors,
|
|
172
|
+
moduleGraph: compilation.moduleGraph,
|
|
173
|
+
warnings
|
|
174
|
+
}, environmentName || compilation.name || compiler.name);
|
|
175
|
+
return warnings;
|
|
176
|
+
});
|
|
177
|
+
compilation.hooks.afterSeal.tapPromise('ModernJsServerOnlyDiagnosticContextPlugin', async ()=>{
|
|
178
|
+
enrichServerOnlyDiagnostics(compilation, environmentName || compilation.name || compiler.name);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
const applyServerOnlyDiagnosticPlugins = (compiler, environments)=>{
|
|
183
|
+
const compilers = 'compilers' in compiler ? compiler.compilers : [
|
|
184
|
+
compiler
|
|
185
|
+
];
|
|
186
|
+
compilers.forEach((childCompiler, index)=>{
|
|
187
|
+
const environmentName = childCompiler.name || Object.values(environments).find((environment)=>environment.index === index)?.name;
|
|
188
|
+
applyServerOnlyDiagnosticPlugin(childCompiler, environmentName);
|
|
189
|
+
});
|
|
190
|
+
};
|
|
91
191
|
function pluginRscConfig() {
|
|
92
192
|
return {
|
|
93
193
|
name: 'builder:rsc-config',
|
|
@@ -159,6 +259,9 @@ function pluginRscConfig() {
|
|
|
159
259
|
});
|
|
160
260
|
}
|
|
161
261
|
});
|
|
262
|
+
api.onAfterCreateCompiler(({ compiler, environments })=>{
|
|
263
|
+
applyServerOnlyDiagnosticPlugins(compiler, environments);
|
|
264
|
+
});
|
|
162
265
|
api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
|
|
163
266
|
if (!isServer && !isWebWorker) {
|
|
164
267
|
const entries = chain.entryPoints.entries();
|
|
@@ -196,9 +299,11 @@ async function getRscPlugins(enableRsc, internalDirectory, environments) {
|
|
|
196
299
|
}
|
|
197
300
|
return [];
|
|
198
301
|
}
|
|
302
|
+
exports.enrichServerOnlyDiagnostics = __webpack_exports__.enrichServerOnlyDiagnostics;
|
|
199
303
|
exports.getRscPlugins = __webpack_exports__.getRscPlugins;
|
|
200
304
|
exports.pluginRscConfig = __webpack_exports__.pluginRscConfig;
|
|
201
305
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
306
|
+
"enrichServerOnlyDiagnostics",
|
|
202
307
|
"getRscPlugins",
|
|
203
308
|
"pluginRscConfig"
|
|
204
309
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -7,6 +7,9 @@ const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
|
|
|
7
7
|
const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
|
|
8
8
|
const RSC_COMMON_LAYER = 'rsc-common';
|
|
9
9
|
const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
|
|
10
|
+
const SERVER_ONLY_MARKER_PATTERN = /(?:^|[/\\])server-only[/\\]index\.js(?:\?|$)/;
|
|
11
|
+
const SERVER_ONLY_MESSAGE_PATTERN = /server-only|server only|only works in a Server Component|cannot be imported (?:directly )?(?:from|into) (?:a )?Client Component/i;
|
|
12
|
+
const SERVER_ONLY_DIAGNOSTIC_PREFIX = '[Modern.js RSC server-only diagnostic context]';
|
|
10
13
|
const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
|
|
11
14
|
const isAsyncStorageExclude = (exclude)=>{
|
|
12
15
|
if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
|
|
@@ -45,6 +48,102 @@ const disableReactCompilerInSwcLoaders = (value, seen = new WeakSet())=>{
|
|
|
45
48
|
}
|
|
46
49
|
for (const item of Object.values(record))disableReactCompilerInSwcLoaders(item, seen);
|
|
47
50
|
};
|
|
51
|
+
const normalizeDiagnosticText = (diagnostic)=>[
|
|
52
|
+
diagnostic.message,
|
|
53
|
+
diagnostic.details,
|
|
54
|
+
diagnostic.file,
|
|
55
|
+
getModulePath(diagnostic.module),
|
|
56
|
+
getModuleIdentifier(diagnostic.module)
|
|
57
|
+
].filter((item)=>Boolean(item)).join('\n');
|
|
58
|
+
const isServerOnlyDiagnostic = (diagnostic)=>{
|
|
59
|
+
const text = normalizeDiagnosticText(diagnostic);
|
|
60
|
+
return SERVER_ONLY_MARKER_PATTERN.test(text) || SERVER_ONLY_MESSAGE_PATTERN.test(text);
|
|
61
|
+
};
|
|
62
|
+
const isEnrichedServerOnlyDiagnostic = (diagnostic)=>diagnostic.message.includes(SERVER_ONLY_DIAGNOSTIC_PREFIX) || diagnostic.details?.includes(SERVER_ONLY_DIAGNOSTIC_PREFIX);
|
|
63
|
+
const getModulePath = (module)=>{
|
|
64
|
+
if (!module) return;
|
|
65
|
+
return module.resource || module.nameForCondition?.() || module.userRequest;
|
|
66
|
+
};
|
|
67
|
+
const getModuleIdentifier = (module)=>{
|
|
68
|
+
if (!module) return;
|
|
69
|
+
return getModulePath(module) || module.readableIdentifier?.() || module.identifier?.() || module.request || module.rawRequest;
|
|
70
|
+
};
|
|
71
|
+
const formatModuleContext = (module)=>{
|
|
72
|
+
const id = getModuleIdentifier(module);
|
|
73
|
+
if (!id) return;
|
|
74
|
+
const layer = module?.layer ? ` [layer: ${module.layer}]` : '';
|
|
75
|
+
return `${id}${layer}`;
|
|
76
|
+
};
|
|
77
|
+
const getIssuerChain = (compilation, module)=>{
|
|
78
|
+
const chain = [];
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
let current = module;
|
|
81
|
+
while(current && !seen.has(current) && chain.length < 8){
|
|
82
|
+
seen.add(current);
|
|
83
|
+
const issuer = compilation.moduleGraph?.getIssuer?.(current);
|
|
84
|
+
const formatted = formatModuleContext(issuer);
|
|
85
|
+
if (!issuer || !formatted) break;
|
|
86
|
+
chain.push(formatted);
|
|
87
|
+
current = issuer;
|
|
88
|
+
}
|
|
89
|
+
return chain;
|
|
90
|
+
};
|
|
91
|
+
const getModuleTraceChain = (diagnostic)=>{
|
|
92
|
+
const trace = diagnostic.moduleTrace || [];
|
|
93
|
+
const chain = [];
|
|
94
|
+
for (const item of trace){
|
|
95
|
+
const formatted = formatModuleContext(item.origin) || item.originName || formatModuleContext(item.module) || item.moduleName;
|
|
96
|
+
if (formatted && !chain.includes(formatted)) chain.push(formatted);
|
|
97
|
+
}
|
|
98
|
+
return chain.slice(0, 8);
|
|
99
|
+
};
|
|
100
|
+
const appendDiagnosticDetails = (diagnostic, lines)=>{
|
|
101
|
+
const context = `${SERVER_ONLY_DIAGNOSTIC_PREFIX}\n${lines.join('\n')}`;
|
|
102
|
+
diagnostic.details = diagnostic.details ? `${diagnostic.details}\n\n${context}` : context;
|
|
103
|
+
};
|
|
104
|
+
const enrichServerOnlyDiagnostics = (compilation, environmentName)=>{
|
|
105
|
+
const diagnostics = [
|
|
106
|
+
...compilation.warnings,
|
|
107
|
+
...compilation.errors
|
|
108
|
+
];
|
|
109
|
+
for (const diagnostic of diagnostics){
|
|
110
|
+
if (!isServerOnlyDiagnostic(diagnostic) || isEnrichedServerOnlyDiagnostic(diagnostic)) continue;
|
|
111
|
+
const lines = [
|
|
112
|
+
`Environment: ${environmentName || compilation.name || 'unknown'}`
|
|
113
|
+
];
|
|
114
|
+
const markerModule = formatModuleContext(diagnostic.module);
|
|
115
|
+
if (markerModule) lines.push(`Matched module: ${markerModule}`);
|
|
116
|
+
const issuerChain = getIssuerChain(compilation, diagnostic.module);
|
|
117
|
+
const moduleTraceChain = getModuleTraceChain(diagnostic);
|
|
118
|
+
const importerChain = issuerChain.length > 0 ? issuerChain : moduleTraceChain;
|
|
119
|
+
if (importerChain.length > 0) lines.push(`Importer chain: ${importerChain.join(' -> ')}`);
|
|
120
|
+
appendDiagnosticDetails(diagnostic, lines);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const applyServerOnlyDiagnosticPlugin = (compiler, environmentName)=>{
|
|
124
|
+
compiler.hooks.thisCompilation.tap('ModernJsServerOnlyDiagnosticContextPlugin', (compilation)=>{
|
|
125
|
+
compilation.hooks.processWarnings.tap('ModernJsServerOnlyDiagnosticContextPlugin', (warnings)=>{
|
|
126
|
+
enrichServerOnlyDiagnostics({
|
|
127
|
+
errors: compilation.errors,
|
|
128
|
+
moduleGraph: compilation.moduleGraph,
|
|
129
|
+
warnings
|
|
130
|
+
}, environmentName || compilation.name || compiler.name);
|
|
131
|
+
return warnings;
|
|
132
|
+
});
|
|
133
|
+
compilation.hooks.afterSeal.tapPromise('ModernJsServerOnlyDiagnosticContextPlugin', async ()=>{
|
|
134
|
+
enrichServerOnlyDiagnostics(compilation, environmentName || compilation.name || compiler.name);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
const applyServerOnlyDiagnosticPlugins = (compiler, environments)=>{
|
|
139
|
+
const compilers = 'compilers' in compiler ? compiler.compilers : [
|
|
140
|
+
compiler
|
|
141
|
+
];
|
|
142
|
+
compilers.forEach((childCompiler, index)=>{
|
|
143
|
+
const environmentName = childCompiler.name || Object.values(environments).find((environment)=>environment.index === index)?.name;
|
|
144
|
+
applyServerOnlyDiagnosticPlugin(childCompiler, environmentName);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
48
147
|
function pluginRscConfig() {
|
|
49
148
|
return {
|
|
50
149
|
name: 'builder:rsc-config',
|
|
@@ -116,6 +215,9 @@ function pluginRscConfig() {
|
|
|
116
215
|
});
|
|
117
216
|
}
|
|
118
217
|
});
|
|
218
|
+
api.onAfterCreateCompiler(({ compiler, environments })=>{
|
|
219
|
+
applyServerOnlyDiagnosticPlugins(compiler, environments);
|
|
220
|
+
});
|
|
119
221
|
api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
|
|
120
222
|
if (!isServer && !isWebWorker) {
|
|
121
223
|
const entries = chain.entryPoints.entries();
|
|
@@ -153,4 +255,4 @@ async function getRscPlugins(enableRsc, internalDirectory, environments) {
|
|
|
153
255
|
}
|
|
154
256
|
return [];
|
|
155
257
|
}
|
|
156
|
-
export { getRscPlugins, pluginRscConfig };
|
|
258
|
+
export { enrichServerOnlyDiagnostics, getRscPlugins, pluginRscConfig };
|
|
@@ -12,6 +12,9 @@ const RENDER_RSC_RUNTIME = '@modern-js/render/rsc';
|
|
|
12
12
|
const RENDER_RSC_WORKER_RUNTIME = '@modern-js/render/rsc-worker';
|
|
13
13
|
const RSC_COMMON_LAYER = 'rsc-common';
|
|
14
14
|
const ENTRY_NAME_VAR = '__MODERN_JS_ENTRY_NAME';
|
|
15
|
+
const SERVER_ONLY_MARKER_PATTERN = /(?:^|[/\\])server-only[/\\]index\.js(?:\?|$)/;
|
|
16
|
+
const SERVER_ONLY_MESSAGE_PATTERN = /server-only|server only|only works in a Server Component|cannot be imported (?:directly )?(?:from|into) (?:a )?Client Component/i;
|
|
17
|
+
const SERVER_ONLY_DIAGNOSTIC_PREFIX = '[Modern.js RSC server-only diagnostic context]';
|
|
15
18
|
const createVirtualModule = (content)=>`data:text/javascript,${encodeURIComponent(content)}`;
|
|
16
19
|
const isAsyncStorageExclude = (exclude)=>{
|
|
17
20
|
if ('string' == typeof exclude) return ASYNC_STORAGE_PATTERN.test(exclude);
|
|
@@ -50,6 +53,102 @@ const disableReactCompilerInSwcLoaders = (value, seen = new WeakSet())=>{
|
|
|
50
53
|
}
|
|
51
54
|
for (const item of Object.values(record))disableReactCompilerInSwcLoaders(item, seen);
|
|
52
55
|
};
|
|
56
|
+
const normalizeDiagnosticText = (diagnostic)=>[
|
|
57
|
+
diagnostic.message,
|
|
58
|
+
diagnostic.details,
|
|
59
|
+
diagnostic.file,
|
|
60
|
+
getModulePath(diagnostic.module),
|
|
61
|
+
getModuleIdentifier(diagnostic.module)
|
|
62
|
+
].filter((item)=>Boolean(item)).join('\n');
|
|
63
|
+
const isServerOnlyDiagnostic = (diagnostic)=>{
|
|
64
|
+
const text = normalizeDiagnosticText(diagnostic);
|
|
65
|
+
return SERVER_ONLY_MARKER_PATTERN.test(text) || SERVER_ONLY_MESSAGE_PATTERN.test(text);
|
|
66
|
+
};
|
|
67
|
+
const isEnrichedServerOnlyDiagnostic = (diagnostic)=>diagnostic.message.includes(SERVER_ONLY_DIAGNOSTIC_PREFIX) || diagnostic.details?.includes(SERVER_ONLY_DIAGNOSTIC_PREFIX);
|
|
68
|
+
const getModulePath = (module)=>{
|
|
69
|
+
if (!module) return;
|
|
70
|
+
return module.resource || module.nameForCondition?.() || module.userRequest;
|
|
71
|
+
};
|
|
72
|
+
const getModuleIdentifier = (module)=>{
|
|
73
|
+
if (!module) return;
|
|
74
|
+
return getModulePath(module) || module.readableIdentifier?.() || module.identifier?.() || module.request || module.rawRequest;
|
|
75
|
+
};
|
|
76
|
+
const formatModuleContext = (module)=>{
|
|
77
|
+
const id = getModuleIdentifier(module);
|
|
78
|
+
if (!id) return;
|
|
79
|
+
const layer = module?.layer ? ` [layer: ${module.layer}]` : '';
|
|
80
|
+
return `${id}${layer}`;
|
|
81
|
+
};
|
|
82
|
+
const getIssuerChain = (compilation, module)=>{
|
|
83
|
+
const chain = [];
|
|
84
|
+
const seen = new Set();
|
|
85
|
+
let current = module;
|
|
86
|
+
while(current && !seen.has(current) && chain.length < 8){
|
|
87
|
+
seen.add(current);
|
|
88
|
+
const issuer = compilation.moduleGraph?.getIssuer?.(current);
|
|
89
|
+
const formatted = formatModuleContext(issuer);
|
|
90
|
+
if (!issuer || !formatted) break;
|
|
91
|
+
chain.push(formatted);
|
|
92
|
+
current = issuer;
|
|
93
|
+
}
|
|
94
|
+
return chain;
|
|
95
|
+
};
|
|
96
|
+
const getModuleTraceChain = (diagnostic)=>{
|
|
97
|
+
const trace = diagnostic.moduleTrace || [];
|
|
98
|
+
const chain = [];
|
|
99
|
+
for (const item of trace){
|
|
100
|
+
const formatted = formatModuleContext(item.origin) || item.originName || formatModuleContext(item.module) || item.moduleName;
|
|
101
|
+
if (formatted && !chain.includes(formatted)) chain.push(formatted);
|
|
102
|
+
}
|
|
103
|
+
return chain.slice(0, 8);
|
|
104
|
+
};
|
|
105
|
+
const appendDiagnosticDetails = (diagnostic, lines)=>{
|
|
106
|
+
const context = `${SERVER_ONLY_DIAGNOSTIC_PREFIX}\n${lines.join('\n')}`;
|
|
107
|
+
diagnostic.details = diagnostic.details ? `${diagnostic.details}\n\n${context}` : context;
|
|
108
|
+
};
|
|
109
|
+
const enrichServerOnlyDiagnostics = (compilation, environmentName)=>{
|
|
110
|
+
const diagnostics = [
|
|
111
|
+
...compilation.warnings,
|
|
112
|
+
...compilation.errors
|
|
113
|
+
];
|
|
114
|
+
for (const diagnostic of diagnostics){
|
|
115
|
+
if (!isServerOnlyDiagnostic(diagnostic) || isEnrichedServerOnlyDiagnostic(diagnostic)) continue;
|
|
116
|
+
const lines = [
|
|
117
|
+
`Environment: ${environmentName || compilation.name || 'unknown'}`
|
|
118
|
+
];
|
|
119
|
+
const markerModule = formatModuleContext(diagnostic.module);
|
|
120
|
+
if (markerModule) lines.push(`Matched module: ${markerModule}`);
|
|
121
|
+
const issuerChain = getIssuerChain(compilation, diagnostic.module);
|
|
122
|
+
const moduleTraceChain = getModuleTraceChain(diagnostic);
|
|
123
|
+
const importerChain = issuerChain.length > 0 ? issuerChain : moduleTraceChain;
|
|
124
|
+
if (importerChain.length > 0) lines.push(`Importer chain: ${importerChain.join(' -> ')}`);
|
|
125
|
+
appendDiagnosticDetails(diagnostic, lines);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const applyServerOnlyDiagnosticPlugin = (compiler, environmentName)=>{
|
|
129
|
+
compiler.hooks.thisCompilation.tap('ModernJsServerOnlyDiagnosticContextPlugin', (compilation)=>{
|
|
130
|
+
compilation.hooks.processWarnings.tap('ModernJsServerOnlyDiagnosticContextPlugin', (warnings)=>{
|
|
131
|
+
enrichServerOnlyDiagnostics({
|
|
132
|
+
errors: compilation.errors,
|
|
133
|
+
moduleGraph: compilation.moduleGraph,
|
|
134
|
+
warnings
|
|
135
|
+
}, environmentName || compilation.name || compiler.name);
|
|
136
|
+
return warnings;
|
|
137
|
+
});
|
|
138
|
+
compilation.hooks.afterSeal.tapPromise('ModernJsServerOnlyDiagnosticContextPlugin', async ()=>{
|
|
139
|
+
enrichServerOnlyDiagnostics(compilation, environmentName || compilation.name || compiler.name);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
const applyServerOnlyDiagnosticPlugins = (compiler, environments)=>{
|
|
144
|
+
const compilers = 'compilers' in compiler ? compiler.compilers : [
|
|
145
|
+
compiler
|
|
146
|
+
];
|
|
147
|
+
compilers.forEach((childCompiler, index)=>{
|
|
148
|
+
const environmentName = childCompiler.name || Object.values(environments).find((environment)=>environment.index === index)?.name;
|
|
149
|
+
applyServerOnlyDiagnosticPlugin(childCompiler, environmentName);
|
|
150
|
+
});
|
|
151
|
+
};
|
|
53
152
|
function pluginRscConfig() {
|
|
54
153
|
return {
|
|
55
154
|
name: 'builder:rsc-config',
|
|
@@ -121,6 +220,9 @@ function pluginRscConfig() {
|
|
|
121
220
|
});
|
|
122
221
|
}
|
|
123
222
|
});
|
|
223
|
+
api.onAfterCreateCompiler(({ compiler, environments })=>{
|
|
224
|
+
applyServerOnlyDiagnosticPlugins(compiler, environments);
|
|
225
|
+
});
|
|
124
226
|
api.modifyBundlerChain((chain, { isServer, isWebWorker })=>{
|
|
125
227
|
if (!isServer && !isWebWorker) {
|
|
126
228
|
const entries = chain.entryPoints.entries();
|
|
@@ -158,4 +260,4 @@ async function getRscPlugins(enableRsc, internalDirectory, environments) {
|
|
|
158
260
|
}
|
|
159
261
|
return [];
|
|
160
262
|
}
|
|
161
|
-
export { getRscPlugins, pluginRscConfig };
|
|
263
|
+
export { enrichServerOnlyDiagnostics, getRscPlugins, pluginRscConfig };
|
|
@@ -1,4 +1,35 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
type RspackDiagnostic = Error & {
|
|
3
|
+
details?: string;
|
|
4
|
+
file?: string;
|
|
5
|
+
module?: DiagnosticModule | null;
|
|
6
|
+
moduleTrace?: Array<{
|
|
7
|
+
module?: DiagnosticModule | null;
|
|
8
|
+
moduleName?: string;
|
|
9
|
+
origin?: DiagnosticModule | null;
|
|
10
|
+
originName?: string;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
type DiagnosticModule = {
|
|
14
|
+
resource?: string;
|
|
15
|
+
request?: string;
|
|
16
|
+
userRequest?: string;
|
|
17
|
+
rawRequest?: string;
|
|
18
|
+
layer?: string;
|
|
19
|
+
context?: string;
|
|
20
|
+
identifier?: () => string;
|
|
21
|
+
readableIdentifier?: (requestShortener?: unknown) => string;
|
|
22
|
+
nameForCondition?: () => string | undefined;
|
|
23
|
+
};
|
|
24
|
+
type DiagnosticCompilation = {
|
|
25
|
+
errors: RspackDiagnostic[];
|
|
26
|
+
name?: string;
|
|
27
|
+
moduleGraph?: {
|
|
28
|
+
getIssuer?: (module: DiagnosticModule) => DiagnosticModule | null;
|
|
29
|
+
};
|
|
30
|
+
warnings: RspackDiagnostic[];
|
|
31
|
+
};
|
|
32
|
+
export declare const enrichServerOnlyDiagnostics: (compilation: DiagnosticCompilation, environmentName?: string) => void;
|
|
2
33
|
/**
|
|
3
34
|
* Unified plugin for RSC (React Server Components) configuration
|
|
4
35
|
* Handles:
|
|
@@ -25,3 +56,4 @@ export declare function getRscPlugins(enableRsc: boolean, internalDirectory: str
|
|
|
25
56
|
server?: string;
|
|
26
57
|
client?: string;
|
|
27
58
|
}): Promise<RsbuildPlugin[]>;
|
|
59
|
+
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ export type BuilderExtraConfig = {
|
|
|
99
99
|
*/
|
|
100
100
|
devServer?: ToolsDevServerConfig;
|
|
101
101
|
/**
|
|
102
|
-
* Modify the options of [
|
|
102
|
+
* Modify the options of [ts-checker-rspack-plugin](https://github.com/rstackjs/ts-checker-rspack-plugin).
|
|
103
103
|
*/
|
|
104
104
|
tsChecker?: PluginTypeCheckerOptions['tsCheckerOptions'];
|
|
105
105
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bleedingdev/modern-js-builder",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-ultramodern.1",
|
|
4
4
|
"description": "A builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"rsbuild-plugin-rsc": "0.1.1",
|
|
60
60
|
"rspack-manifest-plugin": "5.2.2",
|
|
61
61
|
"ts-deepmerge": "8.0.0",
|
|
62
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.
|
|
62
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@rslib/core": "0.23.0",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"react": "^19.2.7",
|
|
69
69
|
"terser": "^5.48.0",
|
|
70
70
|
"typescript": "^6.0.3",
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
71
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.1",
|
|
72
|
+
"@scripts/rstest-config": "2.66.0"
|
|
73
73
|
},
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public",
|