@rsbuild/core 1.7.0-beta.1 → 1.7.0-beta.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.
- package/dist/131.js +103 -82
- package/dist/client/hmr.js +1 -1
- package/dist/client/overlay.js +1 -1
- package/dist/index.cjs +105 -85
- package/dist-types/client/hmr.d.ts +1 -9
- package/dist-types/constants.d.ts +1 -0
- package/dist-types/helpers/index.d.ts +1 -0
- package/dist-types/server/browserLogs.d.ts +4 -2
- package/dist-types/server/devServer.d.ts +2 -1
- package/dist-types/types/context.d.ts +1 -1
- package/package.json +1 -1
package/dist/131.js
CHANGED
|
@@ -1182,7 +1182,7 @@ let supportsColor = {
|
|
|
1182
1182
|
'builder',
|
|
1183
1183
|
'*'
|
|
1184
1184
|
].some((key)=>values.includes(key));
|
|
1185
|
-
};
|
|
1185
|
+
}, isVerbose = ()=>'verbose' === src_logger.level;
|
|
1186
1186
|
function getTime() {
|
|
1187
1187
|
let now = new Date(), hours = String(now.getHours()).padStart(2, '0'), minutes = String(now.getMinutes()).padStart(2, '0'), seconds = String(now.getSeconds()).padStart(2, '0');
|
|
1188
1188
|
return `${hours}:${minutes}:${seconds}`;
|
|
@@ -2580,7 +2580,7 @@ function formatModuleTrace(stats, errorFile, level) {
|
|
|
2580
2580
|
moduleNames[0] !== formatted && moduleNames.unshift(formatted);
|
|
2581
2581
|
}
|
|
2582
2582
|
let trace = moduleNames.slice().reverse();
|
|
2583
|
-
return trace.length > 4 &&
|
|
2583
|
+
return trace.length > 4 && !isVerbose() && (trace = [
|
|
2584
2584
|
...trace.slice(0, 2),
|
|
2585
2585
|
`… (${trace.length - 2 - 2} hidden)`,
|
|
2586
2586
|
...trace.slice(trace.length - 2)
|
|
@@ -2636,8 +2636,8 @@ function formatStatsError(stats, root, level = 'error') {
|
|
|
2636
2636
|
}
|
|
2637
2637
|
let prefix = root + external_node_path_.sep;
|
|
2638
2638
|
return (fileName.startsWith(prefix) && (fileName = fileName.replace(prefix, `.${external_node_path_.sep}`)), /:\d+:\d+/.test(fileName)) ? `File: ${color.cyan(fileName)}\n` : stats.loc ? `File: ${color.cyan(`${fileName}:${stats.loc}`)}\n` : `File: ${color.cyan(`${fileName}:1:1`)}\n`;
|
|
2639
|
-
})(fileName, stats, root)}${stats.message}`, verbose =
|
|
2640
|
-
if (verbose && (stats.details && (message += `\nDetails: ${stats.details}\n`), stats.stack && (message += `\n${stats.stack}`)), 'error' === level ||
|
|
2639
|
+
})(fileName, stats, root)}${stats.message}`, verbose = isVerbose();
|
|
2640
|
+
if (verbose && (stats.details && (message += `\nDetails: ${stats.details}\n`), stats.stack && (message += `\n${stats.stack}`)), 'error' === level || isVerbose()) {
|
|
2641
2641
|
let moduleTrace = formatModuleTrace(stats, fileName, level);
|
|
2642
2642
|
moduleTrace && (message += moduleTrace);
|
|
2643
2643
|
}
|
|
@@ -2726,7 +2726,7 @@ function getStatsOptions(compiler, action) {
|
|
|
2726
2726
|
errors: !0,
|
|
2727
2727
|
warnings: !0,
|
|
2728
2728
|
moduleTrace: !0,
|
|
2729
|
-
errorStack:
|
|
2729
|
+
errorStack: isVerbose()
|
|
2730
2730
|
};
|
|
2731
2731
|
if ('dev' === action && (defaultOptions = {
|
|
2732
2732
|
...defaultOptions,
|
|
@@ -2764,7 +2764,7 @@ function formatStats(stats, hasErrors, root) {
|
|
|
2764
2764
|
}
|
|
2765
2765
|
return {};
|
|
2766
2766
|
}
|
|
2767
|
-
let removeLoaderChainDelimiter = (moduleId)=>
|
|
2767
|
+
let removeLoaderChainDelimiter = (moduleId)=>isVerbose() ? moduleId : moduleId.split('!=!')[0];
|
|
2768
2768
|
function _define_property(obj, key, value) {
|
|
2769
2769
|
return key in obj ? Object.defineProperty(obj, key, {
|
|
2770
2770
|
value: value,
|
|
@@ -3609,7 +3609,7 @@ function createPublicContext(context) {
|
|
|
3609
3609
|
async function createContext(options, userConfig) {
|
|
3610
3610
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
|
|
3611
3611
|
return {
|
|
3612
|
-
version: "1.7.0-beta.
|
|
3612
|
+
version: "1.7.0-beta.2",
|
|
3613
3613
|
rootPath,
|
|
3614
3614
|
distPath: '',
|
|
3615
3615
|
cachePath,
|
|
@@ -6057,16 +6057,15 @@ function applyHMREntry({ config, compiler, token, resolvedHost, resolvedPort })
|
|
|
6057
6057
|
'<port>' === clientConfig.port && (clientConfig.port = resolvedPort);
|
|
6058
6058
|
let hmrEntry = `import { init } from '${toPosixPath((0, external_node_path_.join)(CLIENT_PATH, 'hmr.js'))}';
|
|
6059
6059
|
${config.dev.client.overlay ? `import '${toPosixPath((0, external_node_path_.join)(CLIENT_PATH, 'overlay.js'))}';` : ''}
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
});
|
|
6060
|
+
init(
|
|
6061
|
+
'${token}',
|
|
6062
|
+
${JSON.stringify(clientConfig)},
|
|
6063
|
+
${JSON.stringify(resolvedHost)},
|
|
6064
|
+
${resolvedPort},
|
|
6065
|
+
${config.dev.liveReload},
|
|
6066
|
+
${!!config.dev.browserLogs},
|
|
6067
|
+
${JSON.stringify(config.dev.client.logLevel)}
|
|
6068
|
+
)
|
|
6070
6069
|
`;
|
|
6071
6070
|
new compiler.webpack.EntryPlugin(compiler.context, createVirtualModule(hmrEntry), {
|
|
6072
6071
|
name: void 0
|
|
@@ -6225,33 +6224,32 @@ function parseNode(line) {
|
|
|
6225
6224
|
column: parts[4] ? +parts[4] : null
|
|
6226
6225
|
} : null;
|
|
6227
6226
|
}
|
|
6228
|
-
let isValidMethodName = (methodName)=>'<unknown>' !== methodName && !/[\\/]/.test(methodName)
|
|
6229
|
-
function getOriginalPosition(rawSourceMap, line, column) {
|
|
6230
|
-
let { TraceMap, originalPositionFor } = requireCompiledPackage('@jridgewell/trace-mapping');
|
|
6231
|
-
return originalPositionFor(new TraceMap(rawSourceMap), {
|
|
6232
|
-
line,
|
|
6233
|
-
column
|
|
6234
|
-
});
|
|
6235
|
-
}
|
|
6236
|
-
let parseFrame = async (frame, fs, context)=>{
|
|
6227
|
+
let isValidMethodName = (methodName)=>'<unknown>' !== methodName && !/[\\/]/.test(methodName), parseFrame = async (frame, fs, context, cachedTraceMap)=>{
|
|
6237
6228
|
let { file, column, lineNumber } = frame, sourceMapInfo = await getFileFromUrl(`${file}.map`, fs, context);
|
|
6238
6229
|
if (!sourceMapInfo || 'errorCode' in sourceMapInfo) return;
|
|
6239
|
-
let
|
|
6230
|
+
let { TraceMap, originalPositionFor } = requireCompiledPackage('@jridgewell/trace-mapping'), sourceMapPath = sourceMapInfo.filename;
|
|
6240
6231
|
try {
|
|
6241
|
-
let
|
|
6242
|
-
if (
|
|
6243
|
-
|
|
6244
|
-
|
|
6232
|
+
let tracer = cachedTraceMap.get(sourceMapPath);
|
|
6233
|
+
if (!tracer) {
|
|
6234
|
+
let readFile = external_node_util_promisify(fs.readFile), sourceMap = await readFile(sourceMapPath);
|
|
6235
|
+
if (!sourceMap) return;
|
|
6236
|
+
tracer = new TraceMap(sourceMap.toString()), cachedTraceMap.set(sourceMapPath, tracer);
|
|
6237
|
+
}
|
|
6238
|
+
let originalPosition = originalPositionFor(tracer, {
|
|
6239
|
+
line: lineNumber ?? 0,
|
|
6240
|
+
column: column ?? 0
|
|
6241
|
+
});
|
|
6242
|
+
return {
|
|
6243
|
+
sourceMapPath,
|
|
6244
|
+
originalPosition
|
|
6245
6245
|
};
|
|
6246
6246
|
} catch (error) {
|
|
6247
6247
|
error instanceof Error && src_logger.debug(`failed to map source map position: ${error.message}`);
|
|
6248
6248
|
}
|
|
6249
|
-
}, resolveOriginalLocation = async (
|
|
6250
|
-
let
|
|
6251
|
-
if (!parsed.length) return;
|
|
6252
|
-
let frame = parsed.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
6249
|
+
}, resolveOriginalLocation = async (stackFrames, fs, context, cachedTraceMap)=>{
|
|
6250
|
+
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
6253
6251
|
if (!frame) return;
|
|
6254
|
-
let parsedFrame = await parseFrame(frame, fs, context);
|
|
6252
|
+
let parsedFrame = await parseFrame(frame, fs, context, cachedTraceMap);
|
|
6255
6253
|
if (!parsedFrame) return;
|
|
6256
6254
|
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
6257
6255
|
return {
|
|
@@ -6259,40 +6257,41 @@ let parseFrame = async (frame, fs, context)=>{
|
|
|
6259
6257
|
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
6260
6258
|
};
|
|
6261
6259
|
}, formatOriginalLocation = (sourceMapPath, originalMapping, context)=>{
|
|
6262
|
-
let
|
|
6260
|
+
let { source, line, column } = originalMapping;
|
|
6263
6261
|
if (!source) return;
|
|
6264
|
-
let result = (
|
|
6262
|
+
let result = ((source, sourceMapPath, context)=>{
|
|
6263
|
+
if (source.startsWith('webpack/runtime/')) return source;
|
|
6264
|
+
let absoluteSourcePath = external_node_path_.default.isAbsolute(source) ? source : external_node_path_.default.join(external_node_path_.default.dirname(sourceMapPath), source);
|
|
6265
|
+
return external_node_path_.default.relative(context.rootPath, absoluteSourcePath);
|
|
6266
|
+
})(source, sourceMapPath, context);
|
|
6265
6267
|
return null !== line && (result += null === column ? `:${line}` : `:${line}:${column}`), result;
|
|
6266
6268
|
}, formatFrameLocation = (frame)=>{
|
|
6267
6269
|
let { file, lineNumber, column } = frame;
|
|
6268
6270
|
if (file) return null !== lineNumber ? null !== column ? `${file}:${lineNumber}:${column}` : `${file}:${lineNumber}` : file;
|
|
6269
|
-
}, formatFullStack = async (
|
|
6270
|
-
let parsed = stack_trace_parser_esm_parse(stack);
|
|
6271
|
-
if (!parsed.length) return;
|
|
6271
|
+
}, formatFullStack = async (stackFrames, context, fs, cachedTraceMap)=>{
|
|
6272
6272
|
let result = '';
|
|
6273
|
-
for (let frame of
|
|
6274
|
-
let parsedFrame = await parseFrame(frame, fs, context), { methodName } = frame, parts = [];
|
|
6275
|
-
|
|
6273
|
+
for (let frame of stackFrames){
|
|
6274
|
+
let parsedFrame = await parseFrame(frame, fs, context, cachedTraceMap), { methodName } = frame, parts = [];
|
|
6275
|
+
isValidMethodName(methodName) && parts.push(methodName);
|
|
6276
|
+
let parsed = !1;
|
|
6277
|
+
if (parsedFrame) {
|
|
6276
6278
|
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
frameString && parts.push(frameString);
|
|
6281
|
-
}
|
|
6282
|
-
} else {
|
|
6279
|
+
originalLocation && (parts.push(originalLocation), parsed = !0);
|
|
6280
|
+
}
|
|
6281
|
+
if (!parsed && isVerbose()) {
|
|
6283
6282
|
let frameString = formatFrameLocation(frame);
|
|
6284
6283
|
frameString && parts.push(frameString);
|
|
6285
6284
|
}
|
|
6286
6285
|
parts[0] && (result += `\n at ${parts[0]}`), parts[1] && (result += ` (${parts[1]})`);
|
|
6287
6286
|
}
|
|
6288
6287
|
return result;
|
|
6289
|
-
}, formatBrowserErrorLog = async (message, context, fs, stackTrace)=>{
|
|
6288
|
+
}, formatBrowserErrorLog = async (message, context, fs, stackTrace, stackFrames, cachedTraceMap)=>{
|
|
6290
6289
|
var log;
|
|
6291
|
-
let log1 =
|
|
6292
|
-
if (
|
|
6290
|
+
let log1 = color.red(message);
|
|
6291
|
+
if (stackFrames?.length) switch(stackTrace){
|
|
6293
6292
|
case 'summary':
|
|
6294
6293
|
{
|
|
6295
|
-
let resolved = await resolveOriginalLocation(
|
|
6294
|
+
let resolved = await resolveOriginalLocation(stackFrames, fs, context, cachedTraceMap);
|
|
6296
6295
|
if (!resolved) break;
|
|
6297
6296
|
let { frame, location } = resolved, { methodName } = frame, suffix = '';
|
|
6298
6297
|
isValidMethodName(methodName) && (suffix += ` at ${methodName}`), location && (suffix += ` (${location})`), log1 += suffix ? color.dim(suffix) : '';
|
|
@@ -6300,7 +6299,7 @@ let parseFrame = async (frame, fs, context)=>{
|
|
|
6300
6299
|
}
|
|
6301
6300
|
case 'full':
|
|
6302
6301
|
{
|
|
6303
|
-
let fullStack = await formatFullStack(
|
|
6302
|
+
let fullStack = await formatFullStack(stackFrames, context, fs, cachedTraceMap);
|
|
6304
6303
|
fullStack && (log1 += fullStack);
|
|
6305
6304
|
}
|
|
6306
6305
|
}
|
|
@@ -6347,9 +6346,9 @@ function ansiHTML(text) {
|
|
|
6347
6346
|
return ansiCodes.length > 0 && (ret += Array(ansiCodes.length + 1).join('</span>')), ret;
|
|
6348
6347
|
}
|
|
6349
6348
|
function convertLinksInHtml(text, root) {
|
|
6350
|
-
let PATH_RE = /(?:\.\.?[/\\]|(file:\/\/\/)?[a-zA-Z]:\\|(file:\/\/)?\/|[A-Za-z0-9._-]+[/\\])[^\s:]*:\d+:\d+/g, URL_RE = /(https?:\/\/(?:[\w-]+\.)+[a-z0-9](?:[\w-.~:/?#[\]@!$&'*+,;=])*)/gi, NODE_INTERNAL_RE = /node:internal[/\\]/, FILE_URI_WINDOWS_RE = /^file:\/\/\/([A-Za-z]:)/, FILE_URI_UNIX_RE = /^file:\/\//;
|
|
6349
|
+
let PATH_RE = /(?:\.\.?[/\\]|(file:\/\/\/)?[a-zA-Z]:\\|(file:\/\/)?\/|[A-Za-z0-9._-]+[/\\])[^\s:]*:\d+:\d+/g, URL_RE = /(https?:\/\/(?:[\w-]+\.)+[a-z0-9](?:[\w-.~:/?#[\]@!$&'*+,;=])*)/gi, NODE_INTERNAL_RE = /node:internal[/\\]/, RSPACK_RUNTIME_RE = /webpack\/runtime\//, FILE_URI_WINDOWS_RE = /^file:\/\/\/([A-Za-z]:)/, FILE_URI_UNIX_RE = /^file:\/\//;
|
|
6351
6350
|
return text.split('\n').map((line)=>{
|
|
6352
|
-
if (NODE_INTERNAL_RE.test(line)) return line;
|
|
6351
|
+
if (NODE_INTERNAL_RE.test(line) || RSPACK_RUNTIME_RE.test(line)) return line;
|
|
6353
6352
|
let replacedLine = line.replace(PATH_RE, (file)=>{
|
|
6354
6353
|
let hasClosingSpan = (file = ((file)=>{
|
|
6355
6354
|
if (!file.startsWith('file://')) return file;
|
|
@@ -6459,18 +6458,21 @@ class SocketServer {
|
|
|
6459
6458
|
socket.isAlive = !0;
|
|
6460
6459
|
}), socket.on('message', async (data)=>{
|
|
6461
6460
|
try {
|
|
6462
|
-
let
|
|
6461
|
+
let payload = JSON.parse('string' == typeof data ? data : data.toString()), { context } = this, config = context.normalizedConfig;
|
|
6463
6462
|
if (!config) return;
|
|
6464
6463
|
let { browserLogs, client } = config.dev;
|
|
6465
|
-
if ('client-error' ===
|
|
6466
|
-
let stackTrace = isObject(browserLogs) && browserLogs.stackTrace || DEFAULT_STACK_TRACE, log = await formatBrowserErrorLog(message, context,
|
|
6467
|
-
this.reportedBrowserLogs.has(log) || (this.reportedBrowserLogs.add(log), src_logger.error(log)), 'object' == typeof client.overlay && client.overlay.runtime
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6464
|
+
if ('client-error' === payload.type && 'rspack' === context.bundlerType && !context.buildState.hasErrors && browserLogs) {
|
|
6465
|
+
let stackTrace = isObject(browserLogs) && browserLogs.stackTrace || DEFAULT_STACK_TRACE, outputFs = this.getOutputFileSystem(), stackFrames = payload.stack ? stack_trace_parser_esm_parse(payload.stack) : null, cachedTraceMap = new Map(), log = await formatBrowserErrorLog(payload.message, context, outputFs, stackTrace, stackFrames, cachedTraceMap);
|
|
6466
|
+
if (this.reportedBrowserLogs.has(log) || (this.reportedBrowserLogs.add(log), src_logger.error(`${color.cyan('[browser]')} ${log}`)), 'object' == typeof client.overlay && client.overlay.runtime) {
|
|
6467
|
+
let resolvedLog = 'full' === stackTrace ? log : await formatBrowserErrorLog(payload.message, context, outputFs, 'full', stackFrames, cachedTraceMap);
|
|
6468
|
+
this.sockWrite({
|
|
6469
|
+
type: 'resolved-client-error',
|
|
6470
|
+
data: {
|
|
6471
|
+
id: payload.id,
|
|
6472
|
+
message: convertLinksInHtml(ansiHTML(escapeHtml(resolvedLog)), void 0)
|
|
6473
|
+
}
|
|
6474
|
+
}, token);
|
|
6475
|
+
}
|
|
6474
6476
|
}
|
|
6475
6477
|
} catch {}
|
|
6476
6478
|
});
|
|
@@ -7286,7 +7288,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
7286
7288
|
root
|
|
7287
7289
|
}), (devMiddlewares = ((options)=>{
|
|
7288
7290
|
let middlewares = [], { buildManager } = options;
|
|
7289
|
-
|
|
7291
|
+
isVerbose() && middlewares.push(getRequestLoggerMiddleware());
|
|
7290
7292
|
let { before, after } = ((config, devServerAPI)=>{
|
|
7291
7293
|
let setupMiddlewares = config.dev.setupMiddlewares || [], serverOptions = pick(devServerAPI, [
|
|
7292
7294
|
'sockWrite',
|
|
@@ -7423,7 +7425,7 @@ async function devServer_createDevServer(options, createCompiler, config, { comp
|
|
|
7423
7425
|
let filePath = external_node_path_.default.join(distPath, 'index.html');
|
|
7424
7426
|
if (await middlewares_isFileExists(filePath, buildManager.outputFileSystem)) {
|
|
7425
7427
|
let newUrl = '/index.html';
|
|
7426
|
-
|
|
7428
|
+
isVerbose() && src_logger.debug(` ${req.method} ${req.url} ${color.yellow('fallback to')} ${newUrl}`), req.url = newUrl, buildManager.assetsMiddleware(req, res, (...args)=>{
|
|
7427
7429
|
next(...args);
|
|
7428
7430
|
});
|
|
7429
7431
|
return;
|
|
@@ -7535,7 +7537,7 @@ class RsbuildProdServer {
|
|
|
7535
7537
|
}
|
|
7536
7538
|
async applyDefaultMiddlewares() {
|
|
7537
7539
|
let { headers, proxy, historyApiFallback, compress, base, cors } = this.options.serverConfig;
|
|
7538
|
-
if (
|
|
7540
|
+
if (isVerbose() && this.middlewares.use(getRequestLoggerMiddleware()), cors) {
|
|
7539
7541
|
let corsMiddleware = requireCompiledPackage('cors');
|
|
7540
7542
|
this.middlewares.use(corsMiddleware('boolean' == typeof cors ? {} : cors));
|
|
7541
7543
|
}
|
|
@@ -8188,16 +8190,35 @@ function applyDefaultPlugins(pluginManager, context) {
|
|
|
8188
8190
|
],
|
|
8189
8191
|
raw: !0
|
|
8190
8192
|
}, ({ code, emitFile, resourcePath })=>{
|
|
8191
|
-
let name,
|
|
8192
|
-
if (null ===
|
|
8193
|
-
|
|
8193
|
+
let name, filename = (name = resourcePath && external_node_path_.default.parse(resourcePath).name) ? `${name}.node` : null;
|
|
8194
|
+
if (null === filename) throw Error(`${color.dim('[rsbuild:node-addons]')} Failed to load Node.js addon: ${color.yellow(resourcePath)}`);
|
|
8195
|
+
emitFile(filename, code);
|
|
8196
|
+
let config = api.getNormalizedConfig(), handleErrorSnippet = `throw new Error('Failed to load Node.js addon: "${filename}"', {
|
|
8197
|
+
cause: error,
|
|
8198
|
+
});`;
|
|
8199
|
+
return config.output.module ? `
|
|
8200
|
+
import path from "node:path";
|
|
8201
|
+
import { createRequire } from "node:module";
|
|
8202
|
+
import { fileURLToPath } from "node:url";
|
|
8203
|
+
|
|
8204
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8205
|
+
const __dirname = path.dirname(__filename);
|
|
8206
|
+
const require = createRequire(import.meta.url);
|
|
8207
|
+
|
|
8208
|
+
let native;
|
|
8194
8209
|
try {
|
|
8195
|
-
|
|
8196
|
-
process.dlopen(module, path.join(__dirname, "${name1}"));
|
|
8210
|
+
native = require(path.join(__dirname, "${filename}"));
|
|
8197
8211
|
} catch (error) {
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8212
|
+
${handleErrorSnippet}
|
|
8213
|
+
}
|
|
8214
|
+
|
|
8215
|
+
export default native;
|
|
8216
|
+
` : `
|
|
8217
|
+
try {
|
|
8218
|
+
const path = __non_webpack_require__("node:path");
|
|
8219
|
+
module.exports = __non_webpack_require__(path.join(__dirname, "${filename}"));
|
|
8220
|
+
} catch (error) {
|
|
8221
|
+
${handleErrorSnippet}
|
|
8201
8222
|
}
|
|
8202
8223
|
`;
|
|
8203
8224
|
});
|
|
@@ -9053,7 +9074,7 @@ async function loadConfig_loadConfig({ cwd = process.cwd(), path, envMode, meta,
|
|
|
9053
9074
|
if (customConfig) {
|
|
9054
9075
|
let customConfigPath = (0, external_node_path_.isAbsolute)(customConfig) ? customConfig : (0, external_node_path_.join)(root, customConfig);
|
|
9055
9076
|
if (node_fs.existsSync(customConfigPath)) return customConfigPath;
|
|
9056
|
-
|
|
9077
|
+
throw Error(`${color.dim('[rsbuild:loadConfig]')} Cannot find config file: ${color.dim(customConfigPath)}`);
|
|
9057
9078
|
}
|
|
9058
9079
|
for (let file of [
|
|
9059
9080
|
'rsbuild.config.mjs',
|
|
@@ -9222,7 +9243,7 @@ let applyServerOptions = (command)=>{
|
|
|
9222
9243
|
};
|
|
9223
9244
|
function setupCommands() {
|
|
9224
9245
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
9225
|
-
cli.version("1.7.0-beta.
|
|
9246
|
+
cli.version("1.7.0-beta.2"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
|
|
9226
9247
|
default: 'auto'
|
|
9227
9248
|
}).option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
|
|
9228
9249
|
type: [
|
|
@@ -9291,7 +9312,7 @@ function initNodeEnv() {
|
|
|
9291
9312
|
}
|
|
9292
9313
|
function showGreeting() {
|
|
9293
9314
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
9294
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.7.0-beta.
|
|
9315
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.7.0-beta.2\n`);
|
|
9295
9316
|
}
|
|
9296
9317
|
function setupLogLevel() {
|
|
9297
9318
|
let logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
@@ -9312,5 +9333,5 @@ function runCLI() {
|
|
|
9312
9333
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err);
|
|
9313
9334
|
}
|
|
9314
9335
|
}
|
|
9315
|
-
let src_version = "1.7.0-beta.
|
|
9336
|
+
let src_version = "1.7.0-beta.2";
|
|
9316
9337
|
export { PLUGIN_CSS_NAME, PLUGIN_SWC_NAME, createRsbuild, defaultAllowedOrigins, defineConfig, ensureAssetPrefix, external_node_util_promisify, loadConfig_loadConfig as loadConfig, loadEnv, mergeRsbuildConfig, node_fs, node_os, node_process, rspack_rspack as rspack, runCLI, src_logger as logger, src_version as version };
|
package/dist/client/hmr.js
CHANGED
|
@@ -5,7 +5,7 @@ const registerOverlay = (createFn, clearFn)=>{
|
|
|
5
5
|
createOverlay = createFn;
|
|
6
6
|
clearOverlay = clearFn;
|
|
7
7
|
};
|
|
8
|
-
function init(
|
|
8
|
+
function init(token, config, serverHost, serverPort, liveReload, browserLogs, logLevel) {
|
|
9
9
|
logger.level = logLevel;
|
|
10
10
|
const queuedMessages = [];
|
|
11
11
|
const clientErrors = [];
|
package/dist/client/overlay.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1290,7 +1290,7 @@ for(var __rspack_i in (()=>{
|
|
|
1290
1290
|
'builder',
|
|
1291
1291
|
'*'
|
|
1292
1292
|
].some((key)=>values.includes(key));
|
|
1293
|
-
};
|
|
1293
|
+
}, isVerbose = ()=>'verbose' === src_logger.level;
|
|
1294
1294
|
function getTime() {
|
|
1295
1295
|
let now = new Date(), hours = String(now.getHours()).padStart(2, '0'), minutes = String(now.getMinutes()).padStart(2, '0'), seconds = String(now.getSeconds()).padStart(2, '0');
|
|
1296
1296
|
return `${hours}:${minutes}:${seconds}`;
|
|
@@ -2688,7 +2688,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2688
2688
|
moduleNames[0] !== formatted && moduleNames.unshift(formatted);
|
|
2689
2689
|
}
|
|
2690
2690
|
let trace = moduleNames.slice().reverse();
|
|
2691
|
-
return trace.length > 4 &&
|
|
2691
|
+
return trace.length > 4 && !isVerbose() && (trace = [
|
|
2692
2692
|
...trace.slice(0, 2),
|
|
2693
2693
|
`… (${trace.length - 2 - 2} hidden)`,
|
|
2694
2694
|
...trace.slice(trace.length - 2)
|
|
@@ -2744,8 +2744,8 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2744
2744
|
}
|
|
2745
2745
|
let prefix = root + external_node_path_.sep;
|
|
2746
2746
|
return (fileName.startsWith(prefix) && (fileName = fileName.replace(prefix, `.${external_node_path_.sep}`)), /:\d+:\d+/.test(fileName)) ? `File: ${color.cyan(fileName)}\n` : stats.loc ? `File: ${color.cyan(`${fileName}:${stats.loc}`)}\n` : `File: ${color.cyan(`${fileName}:1:1`)}\n`;
|
|
2747
|
-
})(fileName, stats, root)}${stats.message}`, verbose =
|
|
2748
|
-
if (verbose && (stats.details && (message += `\nDetails: ${stats.details}\n`), stats.stack && (message += `\n${stats.stack}`)), 'error' === level ||
|
|
2747
|
+
})(fileName, stats, root)}${stats.message}`, verbose = isVerbose();
|
|
2748
|
+
if (verbose && (stats.details && (message += `\nDetails: ${stats.details}\n`), stats.stack && (message += `\n${stats.stack}`)), 'error' === level || isVerbose()) {
|
|
2749
2749
|
let moduleTrace = formatModuleTrace(stats, fileName, level);
|
|
2750
2750
|
moduleTrace && (message += moduleTrace);
|
|
2751
2751
|
}
|
|
@@ -2834,7 +2834,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2834
2834
|
errors: !0,
|
|
2835
2835
|
warnings: !0,
|
|
2836
2836
|
moduleTrace: !0,
|
|
2837
|
-
errorStack:
|
|
2837
|
+
errorStack: isVerbose()
|
|
2838
2838
|
};
|
|
2839
2839
|
if ('dev' === action && (defaultOptions = {
|
|
2840
2840
|
...defaultOptions,
|
|
@@ -2872,7 +2872,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
2872
2872
|
}
|
|
2873
2873
|
return {};
|
|
2874
2874
|
}
|
|
2875
|
-
let removeLoaderChainDelimiter = (moduleId)=>
|
|
2875
|
+
let removeLoaderChainDelimiter = (moduleId)=>isVerbose() ? moduleId : moduleId.split('!=!')[0];
|
|
2876
2876
|
var external_node_fs_ = __webpack_require__("node:fs"), external_node_fs_default = __webpack_require__.n(external_node_fs_);
|
|
2877
2877
|
function _define_property(obj, key, value) {
|
|
2878
2878
|
return key in obj ? Object.defineProperty(obj, key, {
|
|
@@ -3742,7 +3742,7 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
3742
3742
|
async function createContext(options, userConfig) {
|
|
3743
3743
|
let { cwd } = options, rootPath = userConfig.root ? ensureAbsolutePath(cwd, userConfig.root) : cwd, rsbuildConfig = await withDefaultConfig(rootPath, userConfig), cachePath = (0, external_node_path_.join)(rootPath, 'node_modules', '.cache'), specifiedEnvironments = options.environment && options.environment.length > 0 ? options.environment : void 0, bundlerType = userConfig.provider ? 'webpack' : 'rspack';
|
|
3744
3744
|
return {
|
|
3745
|
-
version: "1.7.0-beta.
|
|
3745
|
+
version: "1.7.0-beta.2",
|
|
3746
3746
|
rootPath,
|
|
3747
3747
|
distPath: '',
|
|
3748
3748
|
cachePath,
|
|
@@ -6179,16 +6179,15 @@ ${section.body}` : section.body).join("\n\n"));
|
|
|
6179
6179
|
'<port>' === clientConfig.port && (clientConfig.port = resolvedPort);
|
|
6180
6180
|
let hmrEntry = `import { init } from '${toPosixPath((0, external_node_path_.join)(CLIENT_PATH, 'hmr.js'))}';
|
|
6181
6181
|
${config.dev.client.overlay ? `import '${toPosixPath((0, external_node_path_.join)(CLIENT_PATH, 'overlay.js'))}';` : ''}
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
});
|
|
6182
|
+
init(
|
|
6183
|
+
'${token}',
|
|
6184
|
+
${JSON.stringify(clientConfig)},
|
|
6185
|
+
${JSON.stringify(resolvedHost)},
|
|
6186
|
+
${resolvedPort},
|
|
6187
|
+
${config.dev.liveReload},
|
|
6188
|
+
${!!config.dev.browserLogs},
|
|
6189
|
+
${JSON.stringify(config.dev.client.logLevel)}
|
|
6190
|
+
)
|
|
6192
6191
|
`;
|
|
6193
6192
|
new compiler.webpack.EntryPlugin(compiler.context, createVirtualModule(hmrEntry), {
|
|
6194
6193
|
name: void 0
|
|
@@ -6347,33 +6346,32 @@ init({
|
|
|
6347
6346
|
column: parts[4] ? +parts[4] : null
|
|
6348
6347
|
} : null;
|
|
6349
6348
|
}
|
|
6350
|
-
let isValidMethodName = (methodName)=>'<unknown>' !== methodName && !/[\\/]/.test(methodName)
|
|
6351
|
-
function getOriginalPosition(rawSourceMap, line, column) {
|
|
6352
|
-
let { TraceMap, originalPositionFor } = requireCompiledPackage('@jridgewell/trace-mapping');
|
|
6353
|
-
return originalPositionFor(new TraceMap(rawSourceMap), {
|
|
6354
|
-
line,
|
|
6355
|
-
column
|
|
6356
|
-
});
|
|
6357
|
-
}
|
|
6358
|
-
let parseFrame = async (frame, fs, context)=>{
|
|
6349
|
+
let isValidMethodName = (methodName)=>'<unknown>' !== methodName && !/[\\/]/.test(methodName), parseFrame = async (frame, fs, context, cachedTraceMap)=>{
|
|
6359
6350
|
let { file, column, lineNumber } = frame, sourceMapInfo = await getFileFromUrl(`${file}.map`, fs, context);
|
|
6360
6351
|
if (!sourceMapInfo || 'errorCode' in sourceMapInfo) return;
|
|
6361
|
-
let
|
|
6352
|
+
let { TraceMap, originalPositionFor } = requireCompiledPackage('@jridgewell/trace-mapping'), sourceMapPath = sourceMapInfo.filename;
|
|
6362
6353
|
try {
|
|
6363
|
-
let
|
|
6364
|
-
if (
|
|
6365
|
-
|
|
6366
|
-
|
|
6354
|
+
let tracer = cachedTraceMap.get(sourceMapPath);
|
|
6355
|
+
if (!tracer) {
|
|
6356
|
+
let readFile = (0, external_node_util_.promisify)(fs.readFile), sourceMap = await readFile(sourceMapPath);
|
|
6357
|
+
if (!sourceMap) return;
|
|
6358
|
+
tracer = new TraceMap(sourceMap.toString()), cachedTraceMap.set(sourceMapPath, tracer);
|
|
6359
|
+
}
|
|
6360
|
+
let originalPosition = originalPositionFor(tracer, {
|
|
6361
|
+
line: lineNumber ?? 0,
|
|
6362
|
+
column: column ?? 0
|
|
6363
|
+
});
|
|
6364
|
+
return {
|
|
6365
|
+
sourceMapPath,
|
|
6366
|
+
originalPosition
|
|
6367
6367
|
};
|
|
6368
6368
|
} catch (error) {
|
|
6369
6369
|
error instanceof Error && src_logger.debug(`failed to map source map position: ${error.message}`);
|
|
6370
6370
|
}
|
|
6371
|
-
}, resolveOriginalLocation = async (
|
|
6372
|
-
let
|
|
6373
|
-
if (!parsed.length) return;
|
|
6374
|
-
let frame = parsed.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
6371
|
+
}, resolveOriginalLocation = async (stackFrames, fs, context, cachedTraceMap)=>{
|
|
6372
|
+
let frame = stackFrames.find((frame)=>null !== frame.file && null !== frame.column && null !== frame.lineNumber && SCRIPT_REGEX.test(frame.file));
|
|
6375
6373
|
if (!frame) return;
|
|
6376
|
-
let parsedFrame = await parseFrame(frame, fs, context);
|
|
6374
|
+
let parsedFrame = await parseFrame(frame, fs, context, cachedTraceMap);
|
|
6377
6375
|
if (!parsedFrame) return;
|
|
6378
6376
|
let { sourceMapPath, originalPosition } = parsedFrame;
|
|
6379
6377
|
return {
|
|
@@ -6381,41 +6379,41 @@ init({
|
|
|
6381
6379
|
location: formatOriginalLocation(sourceMapPath, originalPosition, context)
|
|
6382
6380
|
};
|
|
6383
6381
|
}, formatOriginalLocation = (sourceMapPath, originalMapping, context)=>{
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6382
|
+
let { source, line, column } = originalMapping;
|
|
6383
|
+
if (!source) return;
|
|
6384
|
+
let result = ((source, sourceMapPath, context)=>{
|
|
6385
|
+
if (source.startsWith('webpack/runtime/')) return source;
|
|
6386
|
+
let absoluteSourcePath = external_node_path_default().isAbsolute(source) ? source : external_node_path_default().join(external_node_path_default().dirname(sourceMapPath), source);
|
|
6387
|
+
return external_node_path_default().relative(context.rootPath, absoluteSourcePath);
|
|
6388
|
+
})(source, sourceMapPath, context);
|
|
6388
6389
|
return null !== line && (result += null === column ? `:${line}` : `:${line}:${column}`), result;
|
|
6389
6390
|
}, formatFrameLocation = (frame)=>{
|
|
6390
6391
|
let { file, lineNumber, column } = frame;
|
|
6391
6392
|
if (file) return null !== lineNumber ? null !== column ? `${file}:${lineNumber}:${column}` : `${file}:${lineNumber}` : file;
|
|
6392
|
-
}, formatFullStack = async (
|
|
6393
|
-
let parsed = stack_trace_parser_esm_parse(stack);
|
|
6394
|
-
if (!parsed.length) return;
|
|
6393
|
+
}, formatFullStack = async (stackFrames, context, fs, cachedTraceMap)=>{
|
|
6395
6394
|
let result = '';
|
|
6396
|
-
for (let frame of
|
|
6397
|
-
let parsedFrame = await parseFrame(frame, fs, context), { methodName } = frame, parts = [];
|
|
6398
|
-
|
|
6395
|
+
for (let frame of stackFrames){
|
|
6396
|
+
let parsedFrame = await parseFrame(frame, fs, context, cachedTraceMap), { methodName } = frame, parts = [];
|
|
6397
|
+
isValidMethodName(methodName) && parts.push(methodName);
|
|
6398
|
+
let parsed = !1;
|
|
6399
|
+
if (parsedFrame) {
|
|
6399
6400
|
let { sourceMapPath, originalPosition } = parsedFrame, originalLocation = formatOriginalLocation(sourceMapPath, originalPosition, context);
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
frameString && parts.push(frameString);
|
|
6404
|
-
}
|
|
6405
|
-
} else {
|
|
6401
|
+
originalLocation && (parts.push(originalLocation), parsed = !0);
|
|
6402
|
+
}
|
|
6403
|
+
if (!parsed && isVerbose()) {
|
|
6406
6404
|
let frameString = formatFrameLocation(frame);
|
|
6407
6405
|
frameString && parts.push(frameString);
|
|
6408
6406
|
}
|
|
6409
6407
|
parts[0] && (result += `\n at ${parts[0]}`), parts[1] && (result += ` (${parts[1]})`);
|
|
6410
6408
|
}
|
|
6411
6409
|
return result;
|
|
6412
|
-
}, formatBrowserErrorLog = async (message, context, fs, stackTrace)=>{
|
|
6410
|
+
}, formatBrowserErrorLog = async (message, context, fs, stackTrace, stackFrames, cachedTraceMap)=>{
|
|
6413
6411
|
var log;
|
|
6414
|
-
let log1 =
|
|
6415
|
-
if (
|
|
6412
|
+
let log1 = color.red(message);
|
|
6413
|
+
if (stackFrames?.length) switch(stackTrace){
|
|
6416
6414
|
case 'summary':
|
|
6417
6415
|
{
|
|
6418
|
-
let resolved = await resolveOriginalLocation(
|
|
6416
|
+
let resolved = await resolveOriginalLocation(stackFrames, fs, context, cachedTraceMap);
|
|
6419
6417
|
if (!resolved) break;
|
|
6420
6418
|
let { frame, location } = resolved, { methodName } = frame, suffix = '';
|
|
6421
6419
|
isValidMethodName(methodName) && (suffix += ` at ${methodName}`), location && (suffix += ` (${location})`), log1 += suffix ? color.dim(suffix) : '';
|
|
@@ -6423,7 +6421,7 @@ init({
|
|
|
6423
6421
|
}
|
|
6424
6422
|
case 'full':
|
|
6425
6423
|
{
|
|
6426
|
-
let fullStack = await formatFullStack(
|
|
6424
|
+
let fullStack = await formatFullStack(stackFrames, context, fs, cachedTraceMap);
|
|
6427
6425
|
fullStack && (log1 += fullStack);
|
|
6428
6426
|
}
|
|
6429
6427
|
}
|
|
@@ -6470,9 +6468,9 @@ init({
|
|
|
6470
6468
|
return ansiCodes.length > 0 && (ret += Array(ansiCodes.length + 1).join('</span>')), ret;
|
|
6471
6469
|
}
|
|
6472
6470
|
function convertLinksInHtml(text, root) {
|
|
6473
|
-
let PATH_RE = /(?:\.\.?[/\\]|(file:\/\/\/)?[a-zA-Z]:\\|(file:\/\/)?\/|[A-Za-z0-9._-]+[/\\])[^\s:]*:\d+:\d+/g, URL_RE = /(https?:\/\/(?:[\w-]+\.)+[a-z0-9](?:[\w-.~:/?#[\]@!$&'*+,;=])*)/gi, NODE_INTERNAL_RE = /node:internal[/\\]/, FILE_URI_WINDOWS_RE = /^file:\/\/\/([A-Za-z]:)/, FILE_URI_UNIX_RE = /^file:\/\//;
|
|
6471
|
+
let PATH_RE = /(?:\.\.?[/\\]|(file:\/\/\/)?[a-zA-Z]:\\|(file:\/\/)?\/|[A-Za-z0-9._-]+[/\\])[^\s:]*:\d+:\d+/g, URL_RE = /(https?:\/\/(?:[\w-]+\.)+[a-z0-9](?:[\w-.~:/?#[\]@!$&'*+,;=])*)/gi, NODE_INTERNAL_RE = /node:internal[/\\]/, RSPACK_RUNTIME_RE = /webpack\/runtime\//, FILE_URI_WINDOWS_RE = /^file:\/\/\/([A-Za-z]:)/, FILE_URI_UNIX_RE = /^file:\/\//;
|
|
6474
6472
|
return text.split('\n').map((line)=>{
|
|
6475
|
-
if (NODE_INTERNAL_RE.test(line)) return line;
|
|
6473
|
+
if (NODE_INTERNAL_RE.test(line) || RSPACK_RUNTIME_RE.test(line)) return line;
|
|
6476
6474
|
let replacedLine = line.replace(PATH_RE, (file)=>{
|
|
6477
6475
|
let hasClosingSpan = (file = ((file)=>{
|
|
6478
6476
|
if (!file.startsWith('file://')) return file;
|
|
@@ -6585,19 +6583,22 @@ init({
|
|
|
6585
6583
|
socket.isAlive = !0;
|
|
6586
6584
|
}), socket.on('message', async (data)=>{
|
|
6587
6585
|
try {
|
|
6588
|
-
let
|
|
6586
|
+
let payload = JSON.parse('string' == typeof data ? data : data.toString()), { context } = this, config = context.normalizedConfig;
|
|
6589
6587
|
if (!config) return;
|
|
6590
6588
|
let { browserLogs, client } = config.dev;
|
|
6591
|
-
if ('client-error' ===
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6589
|
+
if ('client-error' === payload.type && 'rspack' === context.bundlerType && !context.buildState.hasErrors && browserLogs) {
|
|
6590
|
+
let stackTrace = isObject(browserLogs) && browserLogs.stackTrace || DEFAULT_STACK_TRACE, outputFs = this.getOutputFileSystem(), stackFrames = payload.stack ? stack_trace_parser_esm_parse(payload.stack) : null, cachedTraceMap = new Map(), log = await formatBrowserErrorLog(payload.message, context, outputFs, stackTrace, stackFrames, cachedTraceMap);
|
|
6591
|
+
if (this.reportedBrowserLogs.has(log) || (this.reportedBrowserLogs.add(log), src_logger.error(`${color.cyan('[browser]')} ${log}`)), 'object' == typeof client.overlay && client.overlay.runtime) {
|
|
6592
|
+
var error;
|
|
6593
|
+
let resolvedLog = 'full' === stackTrace ? log : await formatBrowserErrorLog(payload.message, context, outputFs, 'full', stackFrames, cachedTraceMap);
|
|
6594
|
+
this.sockWrite({
|
|
6595
|
+
type: 'resolved-client-error',
|
|
6596
|
+
data: {
|
|
6597
|
+
id: payload.id,
|
|
6598
|
+
message: (error = resolvedLog, convertLinksInHtml(ansiHTML(escapeHtml(error)), void 0))
|
|
6599
|
+
}
|
|
6600
|
+
}, token);
|
|
6601
|
+
}
|
|
6601
6602
|
}
|
|
6602
6603
|
} catch {}
|
|
6603
6604
|
});
|
|
@@ -7418,7 +7419,7 @@ init({
|
|
|
7418
7419
|
root
|
|
7419
7420
|
}), (devMiddlewares = ((options)=>{
|
|
7420
7421
|
let middlewares = [], { buildManager } = options;
|
|
7421
|
-
|
|
7422
|
+
isVerbose() && middlewares.push(getRequestLoggerMiddleware());
|
|
7422
7423
|
let { before, after } = ((config, devServerAPI)=>{
|
|
7423
7424
|
let setupMiddlewares = config.dev.setupMiddlewares || [], serverOptions = pick(devServerAPI, [
|
|
7424
7425
|
'sockWrite',
|
|
@@ -7555,7 +7556,7 @@ init({
|
|
|
7555
7556
|
let filePath = external_node_path_default().join(distPath, 'index.html');
|
|
7556
7557
|
if (await middlewares_isFileExists(filePath, buildManager.outputFileSystem)) {
|
|
7557
7558
|
let newUrl = '/index.html';
|
|
7558
|
-
|
|
7559
|
+
isVerbose() && src_logger.debug(` ${req.method} ${req.url} ${color.yellow('fallback to')} ${newUrl}`), req.url = newUrl, buildManager.assetsMiddleware(req, res, (...args)=>{
|
|
7559
7560
|
next(...args);
|
|
7560
7561
|
});
|
|
7561
7562
|
return;
|
|
@@ -7667,7 +7668,7 @@ init({
|
|
|
7667
7668
|
}
|
|
7668
7669
|
async applyDefaultMiddlewares() {
|
|
7669
7670
|
let { headers, proxy, historyApiFallback, compress, base, cors } = this.options.serverConfig;
|
|
7670
|
-
if (
|
|
7671
|
+
if (isVerbose() && this.middlewares.use(getRequestLoggerMiddleware()), cors) {
|
|
7671
7672
|
let corsMiddleware = requireCompiledPackage('cors');
|
|
7672
7673
|
this.middlewares.use(corsMiddleware('boolean' == typeof cors ? {} : cors));
|
|
7673
7674
|
}
|
|
@@ -8322,16 +8323,35 @@ init({
|
|
|
8322
8323
|
raw: !0
|
|
8323
8324
|
}, ({ code, emitFile, resourcePath })=>{
|
|
8324
8325
|
var resourcePath1;
|
|
8325
|
-
let name,
|
|
8326
|
-
if (null ===
|
|
8327
|
-
|
|
8326
|
+
let name, filename = (name = (resourcePath1 = resourcePath) && external_node_path_default().parse(resourcePath1).name) ? `${name}.node` : null;
|
|
8327
|
+
if (null === filename) throw Error(`${color.dim('[rsbuild:node-addons]')} Failed to load Node.js addon: ${color.yellow(resourcePath)}`);
|
|
8328
|
+
emitFile(filename, code);
|
|
8329
|
+
let config = api.getNormalizedConfig(), handleErrorSnippet = `throw new Error('Failed to load Node.js addon: "${filename}"', {
|
|
8330
|
+
cause: error,
|
|
8331
|
+
});`;
|
|
8332
|
+
return config.output.module ? `
|
|
8333
|
+
import path from "node:path";
|
|
8334
|
+
import { createRequire } from "node:module";
|
|
8335
|
+
import { fileURLToPath } from "node:url";
|
|
8336
|
+
|
|
8337
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8338
|
+
const __dirname = path.dirname(__filename);
|
|
8339
|
+
const require = createRequire(import.meta.url);
|
|
8340
|
+
|
|
8341
|
+
let native;
|
|
8328
8342
|
try {
|
|
8329
|
-
|
|
8330
|
-
process.dlopen(module, path.join(__dirname, "${name1}"));
|
|
8343
|
+
native = require(path.join(__dirname, "${filename}"));
|
|
8331
8344
|
} catch (error) {
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
8345
|
+
${handleErrorSnippet}
|
|
8346
|
+
}
|
|
8347
|
+
|
|
8348
|
+
export default native;
|
|
8349
|
+
` : `
|
|
8350
|
+
try {
|
|
8351
|
+
const path = __non_webpack_require__("node:path");
|
|
8352
|
+
module.exports = __non_webpack_require__(path.join(__dirname, "${filename}"));
|
|
8353
|
+
} catch (error) {
|
|
8354
|
+
${handleErrorSnippet}
|
|
8335
8355
|
}
|
|
8336
8356
|
`;
|
|
8337
8357
|
});
|
|
@@ -9187,7 +9207,7 @@ try {
|
|
|
9187
9207
|
if (customConfig) {
|
|
9188
9208
|
let customConfigPath = (0, external_node_path_.isAbsolute)(customConfig) ? customConfig : (0, external_node_path_.join)(root, customConfig);
|
|
9189
9209
|
if (external_node_fs_default().existsSync(customConfigPath)) return customConfigPath;
|
|
9190
|
-
|
|
9210
|
+
throw Error(`${color.dim('[rsbuild:loadConfig]')} Cannot find config file: ${color.dim(customConfigPath)}`);
|
|
9191
9211
|
}
|
|
9192
9212
|
for (let file of [
|
|
9193
9213
|
'rsbuild.config.mjs',
|
|
@@ -9356,7 +9376,7 @@ try {
|
|
|
9356
9376
|
};
|
|
9357
9377
|
function setupCommands() {
|
|
9358
9378
|
let cli = ((name = "")=>new CAC(name))('rsbuild');
|
|
9359
|
-
cli.version("1.7.0-beta.
|
|
9379
|
+
cli.version("1.7.0-beta.2"), cli.option('--base <base>', 'Set the base path of the server').option('-c, --config <config>', 'Set the configuration file (relative or absolute path)').option('--config-loader <loader>', 'Set the config file loader (auto | jiti | native)', {
|
|
9360
9380
|
default: 'auto'
|
|
9361
9381
|
}).option('--env-dir <dir>', 'Set the directory for loading `.env` files').option('--env-mode <mode>', 'Set the env mode to load the `.env.[mode]` file').option('--environment <name>', 'Set the environment name(s) to build', {
|
|
9362
9382
|
type: [
|
|
@@ -9425,7 +9445,7 @@ try {
|
|
|
9425
9445
|
}
|
|
9426
9446
|
function showGreeting() {
|
|
9427
9447
|
let { npm_execpath, npm_lifecycle_event, NODE_RUN_SCRIPT_NAME } = process.env, isBun = npm_execpath?.includes('.bun');
|
|
9428
|
-
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.7.0-beta.
|
|
9448
|
+
src_logger.greet(`${'npx' === npm_lifecycle_event || isBun || NODE_RUN_SCRIPT_NAME ? '\n' : ''}Rsbuild v1.7.0-beta.2\n`);
|
|
9429
9449
|
}
|
|
9430
9450
|
function setupLogLevel() {
|
|
9431
9451
|
let logLevelIndex = process.argv.findIndex((item)=>'--log-level' === item || '--logLevel' === item);
|
|
@@ -9446,7 +9466,7 @@ try {
|
|
|
9446
9466
|
src_logger.error('Failed to start Rsbuild CLI.'), src_logger.error(err);
|
|
9447
9467
|
}
|
|
9448
9468
|
}
|
|
9449
|
-
let src_version = "1.7.0-beta.
|
|
9469
|
+
let src_version = "1.7.0-beta.2";
|
|
9450
9470
|
})(), exports.PLUGIN_CSS_NAME = __webpack_exports__.PLUGIN_CSS_NAME, exports.PLUGIN_SWC_NAME = __webpack_exports__.PLUGIN_SWC_NAME, exports.createRsbuild = __webpack_exports__.createRsbuild, exports.defaultAllowedOrigins = __webpack_exports__.defaultAllowedOrigins, exports.defineConfig = __webpack_exports__.defineConfig, exports.ensureAssetPrefix = __webpack_exports__.ensureAssetPrefix, exports.loadConfig = __webpack_exports__.loadConfig, exports.loadEnv = __webpack_exports__.loadEnv, exports.logger = __webpack_exports__.logger, exports.mergeRsbuildConfig = __webpack_exports__.mergeRsbuildConfig, exports.rspack = __webpack_exports__.rspack, exports.runCLI = __webpack_exports__.runCLI, exports.version = __webpack_exports__.version, __webpack_exports__)-1 === [
|
|
9451
9471
|
"PLUGIN_CSS_NAME",
|
|
9452
9472
|
"PLUGIN_SWC_NAME",
|
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import type { LogLevel, NormalizedClientConfig } from '../types';
|
|
2
2
|
export declare const registerOverlay: (createFn: (title: string, content: string) => void, clearFn: () => void) => void;
|
|
3
|
-
export declare function init(
|
|
4
|
-
token: string;
|
|
5
|
-
config: NormalizedClientConfig;
|
|
6
|
-
serverHost: string;
|
|
7
|
-
serverPort: number;
|
|
8
|
-
liveReload: boolean;
|
|
9
|
-
browserLogs: boolean;
|
|
10
|
-
logLevel: LogLevel;
|
|
11
|
-
}): void;
|
|
3
|
+
export declare function init(token: string, config: NormalizedClientConfig, serverHost: string, serverPort: number, liveReload: boolean, browserLogs: boolean, logLevel: LogLevel): void;
|
|
@@ -49,3 +49,4 @@ export declare const IMAGE_EXTENSIONS: string[];
|
|
|
49
49
|
export declare const VIDEO_EXTENSIONS: string[];
|
|
50
50
|
export declare const AUDIO_EXTENSIONS: string[];
|
|
51
51
|
export declare const LAZY_COMPILATION_IDENTIFIER = "lazy-compilation-proxy";
|
|
52
|
+
export declare const BROWSER_LOG_PREFIX = "[browser]";
|
|
@@ -26,3 +26,4 @@ export declare const prettyTime: (seconds: number) => string;
|
|
|
26
26
|
*/
|
|
27
27
|
export declare const isTTY: (type?: "stdin" | "stdout") => boolean;
|
|
28
28
|
export declare function hash(data: string): Promise<string>;
|
|
29
|
+
export declare const isRspackRuntimeModule: (identifier: string) => boolean;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { StackFrame } from 'stacktrace-parser';
|
|
2
|
+
import type { TraceMap } from '../../compiled/@jridgewell/trace-mapping';
|
|
1
3
|
import type { BrowserLogsStackTrace, InternalContext, Rspack } from '../types';
|
|
2
|
-
|
|
4
|
+
export type CachedTraceMap = Map<string, TraceMap>;
|
|
3
5
|
/**
|
|
4
6
|
* Formats error messages received from the browser into a log string with
|
|
5
7
|
* source location information.
|
|
6
8
|
*/
|
|
7
|
-
export declare const formatBrowserErrorLog: (message:
|
|
9
|
+
export declare const formatBrowserErrorLog: (message: string, context: InternalContext, fs: Rspack.OutputFileSystem, stackTrace: BrowserLogsStackTrace, stackFrames: StackFrame[] | null, cachedTraceMap: CachedTraceMap) => Promise<string>;
|
|
@@ -38,7 +38,8 @@ export type RsbuildDevServer = {
|
|
|
38
38
|
environments: EnvironmentAPI;
|
|
39
39
|
/**
|
|
40
40
|
* The resolved port.
|
|
41
|
-
* By default, Rsbuild server listens on port `3000` and automatically increments
|
|
41
|
+
* By default, Rsbuild server listens on port `3000` and automatically increments
|
|
42
|
+
* the port number if the port is occupied.
|
|
42
43
|
*/
|
|
43
44
|
port: number;
|
|
44
45
|
/**
|
|
@@ -37,7 +37,7 @@ export type RsbuildContext = {
|
|
|
37
37
|
devServer?: {
|
|
38
38
|
/** The hostname the server is running on. */
|
|
39
39
|
hostname: string;
|
|
40
|
-
/** The port number the server is listening on. */
|
|
40
|
+
/** The actual port number the server is listening on. */
|
|
41
41
|
port: number;
|
|
42
42
|
/** Whether the server is using HTTPS protocol. */
|
|
43
43
|
https: boolean;
|