@rsbuild/core 2.2.8 → 2.2.10

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 (45) hide show
  1. package/compiled/css-loader/index.js +2 -2
  2. package/compiled/html-rspack-plugin/htmlLoader.js +8 -17
  3. package/compiled/html-rspack-plugin/index.d.ts +8 -4
  4. package/compiled/html-rspack-plugin/index.js +61 -69
  5. package/compiled/html-rspack-plugin/package.json +1 -1
  6. package/compiled/postcss-loader/index.js +6 -6
  7. package/compiled/ws/index.d.ts +445 -0
  8. package/compiled/ws/license +21 -0
  9. package/compiled/ws/package.json +1 -0
  10. package/dist/1.js +84 -0
  11. package/dist/chokidar.js +1 -1
  12. package/dist/client/hmr.js +1 -1
  13. package/dist/client/overlay.js +1 -1
  14. package/dist/cssUrlLoader.mjs +4 -3
  15. package/dist/helpers/cachedImport.d.ts +2 -0
  16. package/dist/helpers/path.d.ts +9 -0
  17. package/dist/http-proxy-middleware.js +4 -4
  18. package/dist/ignoreCssLoader.mjs +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +2 -1
  21. package/dist/launch-editor-middleware.js +1 -1
  22. package/dist/{626.js → m.js} +162 -286
  23. package/dist/manifest-plugin.js +1 -1
  24. package/dist/memfs.js +1 -1
  25. package/dist/open.js +2 -2
  26. package/dist/r.js +7 -0
  27. package/dist/remapping.js +8 -3
  28. package/dist/rslib-runtime.js +1 -1
  29. package/dist/server/assets-middleware/setupWriteToDisk.d.ts +16 -1
  30. package/dist/server/browserLogs.d.ts +5 -2
  31. package/dist/server/helper.d.ts +2 -2
  32. package/dist/server/runner/asModule.d.ts +1 -1
  33. package/dist/server/runner/basic.d.ts +5 -4
  34. package/dist/server/runner/type.d.ts +1 -1
  35. package/dist/server/socketServer.d.ts +1 -1
  36. package/dist/sirv.js +1 -1
  37. package/dist/tinyglobby.js +1 -1
  38. package/dist/trace-mapping.js +236 -22
  39. package/dist/transformLoader.mjs +3 -2
  40. package/dist/types/config.d.ts +13 -1
  41. package/dist/ws.js +2 -2
  42. package/package.json +7 -7
  43. /package/dist/{252.js → c.js} +0 -0
  44. /package/dist/client/{307~0.js → f~0.js} +0 -0
  45. /package/dist/{626.js.LICENSE.txt → m.js.LICENSE.txt} +0 -0
@@ -1,23 +1,46 @@
1
+ import { definePropertyGetters, makeNamespaceObject } from "./rslib-runtime.js";
2
+ var trace_mapping_namespaceObject = {};
3
+ makeNamespaceObject(trace_mapping_namespaceObject), definePropertyGetters(trace_mapping_namespaceObject, {
4
+ AnyMap: ()=>FlattenMap,
5
+ FlattenMap: ()=>FlattenMap,
6
+ GREATEST_LOWER_BOUND: ()=>GREATEST_LOWER_BOUND,
7
+ LEAST_UPPER_BOUND: ()=>LEAST_UPPER_BOUND,
8
+ TraceMap: ()=>TraceMap,
9
+ allGeneratedPositionsFor: ()=>allGeneratedPositionsFor,
10
+ decodedMap: ()=>decodedMap,
11
+ decodedMappings: ()=>decodedMappings,
12
+ eachMapping: ()=>eachMapping,
13
+ encodedMap: ()=>encodedMap,
14
+ encodedMappings: ()=>encodedMappings,
15
+ generatedPositionFor: ()=>generatedPositionFor,
16
+ isIgnored: ()=>isIgnored,
17
+ originalPositionFor: ()=>originalPositionFor,
18
+ presortedDecodedMap: ()=>presortedDecodedMap,
19
+ sourceContentFor: ()=>sourceContentFor,
20
+ traceSegment: ()=>traceSegment
21
+ });
1
22
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
2
23
  for(let i = 0; i < chars.length; i++){
3
24
  let c = chars.charCodeAt(i);
4
25
  intToChar[i] = c, charToInt[c] = i;
5
26
  }
6
- function decodeInteger(reader, relative) {
27
+ function decodeInteger(reader) {
7
28
  let value = 0, shift = 0, integer = 0;
8
29
  do value |= (31 & (integer = charToInt[reader.next()])) << shift, shift += 5;
9
30
  while (32 & integer);
10
- let shouldNegate = 1 & value;
11
- return value >>>= 1, shouldNegate && (value = -2147483648 | -value), relative + value;
31
+ return value;
12
32
  }
13
- function encodeInteger(builder, num, relative) {
14
- let delta = num - relative;
15
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
33
+ function decodeSign(num) {
34
+ return 1 & num ? -2147483648 | -(num >>> 1) : num >>> 1;
35
+ }
36
+ function encodeInteger(builder, num) {
16
37
  do {
17
- let clamped = 31 & delta;
18
- (delta >>>= 5) > 0 && (clamped |= 32), builder.write(intToChar[clamped]);
19
- }while (delta > 0);
20
- return num;
38
+ let clamped = 31 & num;
39
+ (num >>>= 5) > 0 && (clamped |= 32), builder.write(intToChar[clamped]);
40
+ }while (num > 0);
41
+ }
42
+ function encodeSign(num) {
43
+ return num < 0 ? -num << 1 | 1 : num << 1;
21
44
  }
22
45
  function hasMoreVlq(reader, max) {
23
46
  return !(reader.pos >= max) && 44 !== reader.peek();
@@ -63,13 +86,13 @@ function decode(mappings) {
63
86
  let semi = reader.indexOf(";"), line = [], sorted = !0, lastCol = 0;
64
87
  for(genColumn = 0; reader.pos < semi;){
65
88
  let seg;
66
- (genColumn = decodeInteger(reader, genColumn)) < lastCol && (sorted = !1), lastCol = genColumn, hasMoreVlq(reader, semi) ? (sourcesIndex = decodeInteger(reader, sourcesIndex), sourceLine = decodeInteger(reader, sourceLine), sourceColumn = decodeInteger(reader, sourceColumn), seg = hasMoreVlq(reader, semi) ? [
89
+ (genColumn += decodeSign(decodeInteger(reader))) < lastCol && (sorted = !1), lastCol = genColumn, hasMoreVlq(reader, semi) ? (sourcesIndex += decodeSign(decodeInteger(reader)), sourceLine += decodeSign(decodeInteger(reader)), sourceColumn += decodeSign(decodeInteger(reader)), hasMoreVlq(reader, semi) ? (namesIndex += decodeSign(decodeInteger(reader)), seg = [
67
90
  genColumn,
68
91
  sourcesIndex,
69
92
  sourceLine,
70
93
  sourceColumn,
71
- namesIndex = decodeInteger(reader, namesIndex)
72
- ] : [
94
+ namesIndex
95
+ ]) : seg = [
73
96
  genColumn,
74
97
  sourcesIndex,
75
98
  sourceLine,
@@ -88,7 +111,7 @@ function sort(line) {
88
111
  function sortComparator(a, b) {
89
112
  return a[0] - b[0];
90
113
  }
91
- function sourcemap_codec_encode(decoded) {
114
+ function encode(decoded) {
92
115
  let writer = new StringWriter(), sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
93
116
  for(let i = 0; i < decoded.length; i++){
94
117
  let line = decoded[i];
@@ -96,7 +119,7 @@ function sourcemap_codec_encode(decoded) {
96
119
  let genColumn = 0;
97
120
  for(let j = 0; j < line.length; j++){
98
121
  let segment = line[j];
99
- j > 0 && writer.write(44), genColumn = encodeInteger(writer, segment[0], genColumn), 1 !== segment.length && (sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex), sourceLine = encodeInteger(writer, segment[2], sourceLine), sourceColumn = encodeInteger(writer, segment[3], sourceColumn), 4 !== segment.length && (namesIndex = encodeInteger(writer, segment[4], namesIndex)));
122
+ j > 0 && writer.write(44), encodeInteger(writer, encodeSign(segment[0] - genColumn)), genColumn = segment[0], 1 !== segment.length && (encodeInteger(writer, encodeSign(segment[1] - sourcesIndex)), encodeInteger(writer, encodeSign(segment[2] - sourceLine)), encodeInteger(writer, encodeSign(segment[3] - sourceColumn)), sourcesIndex = segment[1], sourceLine = segment[2], sourceColumn = segment[3], 4 !== segment.length && (encodeInteger(writer, encodeSign(segment[4] - namesIndex)), namesIndex = segment[4]));
100
123
  }
101
124
  }
102
125
  return writer.flush();
@@ -248,6 +271,30 @@ function sortSegments(line, owned) {
248
271
  function trace_mapping_sortComparator(a, b) {
249
272
  return a[0] - b[0];
250
273
  }
274
+ function buildBySources(decoded, memos) {
275
+ let sources = memos.map(()=>[]);
276
+ for(let i = 0; i < decoded.length; i++){
277
+ let line = decoded[i];
278
+ for(let j = 0; j < line.length; j++){
279
+ let seg = line[j];
280
+ if (1 === seg.length) continue;
281
+ let sourceIndex2 = seg[1], sourceLine = seg[2], sourceColumn = seg[3], source = sources[sourceIndex2];
282
+ (source[sourceLine] || (source[sourceLine] = [])).push([
283
+ sourceColumn,
284
+ i,
285
+ seg[0]
286
+ ]);
287
+ }
288
+ }
289
+ for(let i = 0; i < sources.length; i++){
290
+ let source = sources[i];
291
+ for(let j = 0; j < source.length; j++){
292
+ let line = source[j];
293
+ line && line.sort(trace_mapping_sortComparator);
294
+ }
295
+ }
296
+ return sources;
297
+ }
251
298
  var found = !1;
252
299
  function binarySearch(haystack, needle, low, high) {
253
300
  for(; low <= high;){
@@ -283,7 +330,75 @@ function memoizedBinarySearch(haystack, needle, state, key) {
283
330
  function parse(map) {
284
331
  return "string" == typeof map ? JSON.parse(map) : map;
285
332
  }
286
- var TraceMap = class {
333
+ var FlattenMap = function(map, mapUrl) {
334
+ let parsed = parse(map);
335
+ if (!("sections" in parsed)) return new TraceMap(parsed, mapUrl);
336
+ let mappings = [], sources = [], sourcesContent = [], names = [], ignoreList = [];
337
+ return recurse(parsed, mapUrl, mappings, sources, sourcesContent, names, ignoreList, 0, 0, 1 / 0, 1 / 0), presortedDecodedMap({
338
+ version: 3,
339
+ file: parsed.file,
340
+ names,
341
+ sources,
342
+ sourcesContent,
343
+ mappings,
344
+ ignoreList
345
+ });
346
+ };
347
+ function recurse(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
348
+ let { sections } = input;
349
+ for(let i = 0; i < sections.length; i++){
350
+ let { map, offset } = sections[i], sl = stopLine, sc = stopColumn;
351
+ if (i + 1 < sections.length) {
352
+ let nextOffset = sections[i + 1].offset;
353
+ (sl = Math.min(stopLine, lineOffset + nextOffset.line)) === stopLine ? sc = Math.min(stopColumn, columnOffset + nextOffset.column) : sl < stopLine && (sc = columnOffset + nextOffset.column);
354
+ }
355
+ addSection(map, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset + offset.line, columnOffset + offset.column, sl, sc);
356
+ }
357
+ }
358
+ function addSection(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
359
+ let parsed = parse(input);
360
+ if ("sections" in parsed) return recurse(...arguments);
361
+ let map = new TraceMap(parsed, mapUrl), sourcesOffset = sources.length, namesOffset = names.length, decoded = decodedMappings(map), { resolvedSources, sourcesContent: contents, ignoreList: ignores } = map;
362
+ if (append(sources, resolvedSources), append(names, map.names), contents) append(sourcesContent, contents);
363
+ else for(let i = 0; i < resolvedSources.length; i++)sourcesContent.push(null);
364
+ if (ignores) for(let i = 0; i < ignores.length; i++)ignoreList.push(ignores[i] + sourcesOffset);
365
+ for(let i = 0; i < decoded.length; i++){
366
+ let lineI = lineOffset + i;
367
+ if (lineI > stopLine) return;
368
+ let out = getLine(mappings, lineI), cOffset = 0 === i ? columnOffset : 0, line = decoded[i];
369
+ for(let j = 0; j < line.length; j++){
370
+ let seg = line[j], column = cOffset + seg[0];
371
+ if (lineI === stopLine && column >= stopColumn) return;
372
+ if (1 === seg.length) {
373
+ out.push([
374
+ column
375
+ ]);
376
+ continue;
377
+ }
378
+ let sourcesIndex = sourcesOffset + seg[1], sourceLine = seg[2], sourceColumn = seg[3];
379
+ out.push(4 === seg.length ? [
380
+ column,
381
+ sourcesIndex,
382
+ sourceLine,
383
+ sourceColumn
384
+ ] : [
385
+ column,
386
+ sourcesIndex,
387
+ sourceLine,
388
+ sourceColumn,
389
+ namesOffset + seg[4]
390
+ ]);
391
+ }
392
+ }
393
+ }
394
+ function append(arr, other) {
395
+ for(let i = 0; i < other.length; i++)arr.push(other[i]);
396
+ }
397
+ function getLine(arr, index) {
398
+ for(let i = arr.length; i <= index; i++)arr[i] = [];
399
+ return arr[index];
400
+ }
401
+ var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)", COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)", LEAST_UPPER_BOUND = -1, GREATEST_LOWER_BOUND = 1, TraceMap = class {
287
402
  constructor(map, mapUrl){
288
403
  let isString = "string" == typeof map;
289
404
  if (!isString && map._decodedMemo) return map;
@@ -299,28 +414,95 @@ var TraceMap = class {
299
414
  this._decodedMemo = memoizedState(), this._bySources = void 0, this._bySourceMemos = void 0;
300
415
  }
301
416
  };
417
+ function encodedMappings(map) {
418
+ var _b;
419
+ return null != (_b = map._encoded) ? _b : map._encoded = encode(map._decoded);
420
+ }
302
421
  function decodedMappings(map) {
303
422
  return map._decoded || (map._decoded = decode(map._encoded));
304
423
  }
305
424
  function traceSegment(map, line, column) {
306
425
  let decoded = decodedMappings(map);
307
426
  if (line >= decoded.length) return null;
308
- let segments = decoded[line], index = traceSegmentInternal(segments, map._decodedMemo, line, column, 1);
427
+ let segments = decoded[line], index = traceSegmentInternal(segments, map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
309
428
  return -1 === index ? null : segments[index];
310
429
  }
311
430
  function originalPositionFor(map, needle) {
312
431
  let { line, column, bias } = needle;
313
- if (--line < 0) throw Error("`line` must be greater than 0 (lines start at line 1)");
314
- if (column < 0) throw Error("`column` must be greater than or equal to 0 (columns start at column 0)");
432
+ if (--line < 0) throw Error(LINE_GTR_ZERO);
433
+ if (column < 0) throw Error(COL_GTR_EQ_ZERO);
315
434
  let decoded = decodedMappings(map);
316
435
  if (line >= decoded.length) return OMapping(null, null, null, null);
317
- let segments = decoded[line], index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || 1);
436
+ let segments = decoded[line], index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
318
437
  if (-1 === index) return OMapping(null, null, null, null);
319
438
  let segment = segments[index];
320
439
  if (1 === segment.length) return OMapping(null, null, null, null);
321
440
  let { names, resolvedSources } = map;
322
441
  return OMapping(resolvedSources[segment[1]], segment[2] + 1, segment[3], 5 === segment.length ? names[segment[4]] : null);
323
442
  }
443
+ function generatedPositionFor(map, needle) {
444
+ let { source, line, column, bias } = needle;
445
+ return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, !1);
446
+ }
447
+ function allGeneratedPositionsFor(map, needle) {
448
+ let { source, line, column, bias } = needle;
449
+ return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, !0);
450
+ }
451
+ function eachMapping(map, cb) {
452
+ let decoded = decodedMappings(map), { names, resolvedSources } = map;
453
+ for(let i = 0; i < decoded.length; i++){
454
+ let line = decoded[i];
455
+ for(let j = 0; j < line.length; j++){
456
+ let seg = line[j], generatedLine = i + 1, generatedColumn = seg[0], source = null, originalLine = null, originalColumn = null, name = null;
457
+ 1 !== seg.length && (source = resolvedSources[seg[1]], originalLine = seg[2] + 1, originalColumn = seg[3]), 5 === seg.length && (name = names[seg[4]]), cb({
458
+ generatedLine,
459
+ generatedColumn,
460
+ source,
461
+ originalLine,
462
+ originalColumn,
463
+ name
464
+ });
465
+ }
466
+ }
467
+ }
468
+ function sourceIndex(map, source) {
469
+ let { sources, resolvedSources } = map, index = sources.indexOf(source);
470
+ return -1 === index && (index = resolvedSources.indexOf(source)), index;
471
+ }
472
+ function sourceContentFor(map, source) {
473
+ let { sourcesContent } = map;
474
+ if (null == sourcesContent) return null;
475
+ let index = sourceIndex(map, source);
476
+ return -1 === index ? null : sourcesContent[index];
477
+ }
478
+ function isIgnored(map, source) {
479
+ let { ignoreList } = map;
480
+ if (null == ignoreList) return !1;
481
+ let index = sourceIndex(map, source);
482
+ return -1 !== index && ignoreList.includes(index);
483
+ }
484
+ function presortedDecodedMap(map, mapUrl) {
485
+ let tracer = new TraceMap(clone(map, []), mapUrl);
486
+ return tracer._decoded = map.mappings, tracer;
487
+ }
488
+ function decodedMap(map) {
489
+ return clone(map, decodedMappings(map));
490
+ }
491
+ function encodedMap(map) {
492
+ return clone(map, encodedMappings(map));
493
+ }
494
+ function clone(map, mappings) {
495
+ return {
496
+ version: map.version,
497
+ file: map.file,
498
+ names: map.names,
499
+ sourceRoot: map.sourceRoot,
500
+ sources: map.sources,
501
+ sourcesContent: map.sourcesContent,
502
+ mappings,
503
+ ignoreList: map.ignoreList || map.x_google_ignoreList
504
+ };
505
+ }
324
506
  function OMapping(source, line, column, name) {
325
507
  return {
326
508
  source,
@@ -329,8 +511,40 @@ function OMapping(source, line, column, name) {
329
511
  name
330
512
  };
331
513
  }
514
+ function GMapping(line, column) {
515
+ return {
516
+ line,
517
+ column
518
+ };
519
+ }
332
520
  function traceSegmentInternal(segments, memo, line, column, bias) {
333
521
  let index = memoizedBinarySearch(segments, column, memo, line);
334
- return (found ? index = (-1 === bias ? upperBound : lowerBound)(segments, column, index) : -1 === bias && index++, -1 === index || index === segments.length) ? -1 : index;
522
+ return (found ? index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index) : bias === LEAST_UPPER_BOUND && index++, -1 === index || index === segments.length) ? -1 : index;
523
+ }
524
+ function sliceGeneratedPositions(segments, memo, line, column, bias) {
525
+ let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
526
+ if (!found && bias === LEAST_UPPER_BOUND && min++, -1 === min || min === segments.length) return [];
527
+ let matchedColumn = found ? column : segments[min][0];
528
+ found || (min = lowerBound(segments, matchedColumn, min));
529
+ let max = upperBound(segments, matchedColumn, min), result = [];
530
+ for(; min <= max; min++){
531
+ let segment = segments[min];
532
+ result.push(GMapping(segment[1] + 1, segment[2]));
533
+ }
534
+ return result;
535
+ }
536
+ function generatedPosition(map, source, line, column, bias, all) {
537
+ if (--line < 0) throw Error(LINE_GTR_ZERO);
538
+ if (column < 0) throw Error(COL_GTR_EQ_ZERO);
539
+ let { sources, resolvedSources } = map, sourceIndex2 = sources.indexOf(source);
540
+ if (-1 === sourceIndex2 && (sourceIndex2 = resolvedSources.indexOf(source)), -1 === sourceIndex2) return all ? [] : GMapping(null, null);
541
+ let bySourceMemos = map._bySourceMemos || (map._bySourceMemos = sources.map(memoizedState)), segments = (map._bySources || (map._bySources = buildBySources(decodedMappings(map), bySourceMemos)))[sourceIndex2][line];
542
+ if (null == segments) return all ? [] : GMapping(null, null);
543
+ let memo = bySourceMemos[sourceIndex2];
544
+ if (all) return sliceGeneratedPositions(segments, memo, line, column, bias);
545
+ let index = traceSegmentInternal(segments, memo, line, column, bias);
546
+ if (-1 === index) return GMapping(null, null);
547
+ let segment = segments[index];
548
+ return GMapping(segment[1] + 1, segment[2]);
335
549
  }
336
- export { TraceMap, decodedMappings, originalPositionFor, sourcemap_codec_encode, traceSegment };
550
+ export { TraceMap, decodedMappings, encode, traceSegment, trace_mapping_namespaceObject };
@@ -1,5 +1,6 @@
1
- let mergeSourceMap = async (originalSourceMap, generatedSourceMap)=>{
2
- let { default: remapping } = await import("./remapping.js");
1
+ import { cachedImport } from "./r.js";
2
+ let getRemapping = cachedImport(()=>import("./remapping.js").then((m)=>m.remapping_namespaceObject)), mergeSourceMap = async (originalSourceMap, generatedSourceMap)=>{
3
+ let { default: remapping } = await getRemapping();
3
4
  return remapping([
4
5
  generatedSourceMap,
5
6
  originalSourceMap
@@ -1429,7 +1429,19 @@ export type NormalizedHtmlConfig = HtmlConfig & {
1429
1429
  export type ProgressBarConfig = {
1430
1430
  id?: string;
1431
1431
  };
1432
- export type RequestHandler = Connect.NextHandleFunction;
1432
+ export interface RsbuildServerResponse extends ServerResponse {
1433
+ /**
1434
+ * Flush buffered gzip data without ending the response.
1435
+ * May be absent when compression is disabled or the middleware has not run.
1436
+ */ flush?: () => void;
1437
+ }
1438
+ export type RequestHandler = (req: Connect.IncomingMessage, res: RsbuildServerResponse, next: Connect.NextFunction) => unknown;
1439
+ export interface RsbuildMiddlewares extends Connect.Server {
1440
+ use(fn: RequestHandler): this;
1441
+ use(fn: Connect.ServerHandle): this;
1442
+ use(route: string, fn: RequestHandler): this;
1443
+ use(route: string, fn: Connect.ServerHandle): this;
1444
+ }
1433
1445
  export type EnvironmentAPI = Record<string, {
1434
1446
  /**
1435
1447
  * Get stats info about current environment.