@rolldown/browser 1.0.0-beta.41 → 1.0.0-beta.43

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.
@@ -1,4 +1,4 @@
1
- import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingChunkModuleOrderBy, BindingJsx, BindingLogLevel, BindingPluginOrder, BindingPropertyReadSideEffects, BindingPropertyWriteSideEffects, BindingWatcher, parseSync, shutdownAsyncRuntime, startAsyncRuntime } from "./rolldown-binding.wasi-browser.js";
1
+ import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingChunkModuleOrderBy, BindingJsx, BindingLogLevel, BindingMagicString, BindingMagicString as BindingMagicString$1, BindingPluginOrder, BindingPropertyReadSideEffects, BindingPropertyWriteSideEffects, BindingWatcher, parseSync, shutdownAsyncRuntime, startAsyncRuntime } from "./rolldown-binding.wasi-browser.js";
2
2
 
3
3
  //#region rolldown:runtime
4
4
  var __create = Object.create;
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
 
28
28
  //#endregion
29
29
  //#region package.json
30
- var version = "1.0.0-beta.41";
30
+ var version = "1.0.0-beta.43";
31
31
 
32
32
  //#endregion
33
33
  //#region src/utils/code-frame.ts
@@ -397,10 +397,7 @@ let _lazyMatch = () => {
397
397
  throw new Error("Invalid rule");
398
398
  }), P = "abcdefghijklmnopqrstuvwxyz", ir = (r$1) => {
399
399
  let e$2 = "";
400
- for (; r$1 > 0;) {
401
- const n$2 = (r$1 - 1) % 26;
402
- e$2 = P[n$2] + e$2, r$1 = Math.floor((r$1 - 1) / 26);
403
- }
400
+ for (; r$1 > 0;) e$2 = P[(r$1 - 1) % 26] + e$2, r$1 = Math.floor((r$1 - 1) / 26);
404
401
  return e$2;
405
402
  }, O$1 = (r$1) => {
406
403
  let e$2 = 0;
@@ -414,45 +411,45 @@ let _lazyMatch = () => {
414
411
  }, or$1 = (r$1, e$2, n$2) => S(r$1, e$2).map((a$2) => String(a$2).padStart(n$2, "0")), R = (r$1, e$2) => S(O$1(r$1), O$1(e$2)).map(ir), p$1 = (r$1) => r$1, z = (r$1) => ur((e$2) => rr(e$2, r$1, { memoization: false }).join("")), ur = (r$1) => {
415
412
  const e$2 = {};
416
413
  return (n$2) => e$2[n$2] ?? (e$2[n$2] = r$1(n$2));
417
- }, sr = i$1(/^\*\*\/\*$/, ".*"), cr = i$1(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r$1, e$2, n$2) => `.*${e$2 ? "" : "(?:^|/)"}${n$2.replaceAll(".", "\\.")}`), lr = i$1(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r$1, e$2, n$2, a$2) => `.*${e$2 ? "" : "(?:^|/)"}${n$2.replaceAll(".", "\\.")}(?:${a$2.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i$1(/\\./, p$1), pr = i$1(/[$.*+?^(){}[\]\|]/, (r$1) => `\\${r$1}`), vr = i$1(/./, p$1), hr = i$1(/^(?:!!)*!(.*)$/, (r$1, e$2) => `(?!^${L(e$2)}$).*?`), dr = i$1(/^(!!)+/, ""), fr = l$1([hr, dr]), xr = i$1(/\/(\*\*\/)+/, "(?:/.+/|/)"), gr = i$1(/^(\*\*\/)+/, "(?:^|.*/)"), mr = i$1(/\/(\*\*)$/, "(?:/.*|$)"), _r = i$1(/\*\*/, ".*"), j = l$1([
418
- xr,
419
- gr,
420
- mr,
421
- _r
422
- ]), Sr = i$1(/\*\/(?!\*\*\/)/, "[^/]*/"), yr = i$1(/\*/, "[^/]*"), N = l$1([Sr, yr]), k = i$1("?", "[^/]"), $r = i$1("[", p$1), wr = i$1("]", p$1), Ar = i$1(/[!^]/, "^/"), br = i$1(/[a-z]-[a-z]|[0-9]-[0-9]/i, p$1), Cr = i$1(/[$.*+?^(){}[\|]/, (r$1) => `\\${r$1}`), Mr = i$1(/[^\]]/, p$1), Er = l$1([
414
+ }, sr = i$1(/^\*\*\/\*$/, ".*"), cr = i$1(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r$1, e$2, n$2) => `.*${e$2 ? "" : "(?:^|/)"}${n$2.replaceAll(".", "\\.")}`), lr = i$1(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r$1, e$2, n$2, a$2) => `.*${e$2 ? "" : "(?:^|/)"}${n$2.replaceAll(".", "\\.")}(?:${a$2.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i$1(/\\./, p$1), pr = i$1(/[$.*+?^(){}[\]\|]/, (r$1) => `\\${r$1}`), vr = i$1(/./, p$1), fr = l$1([i$1(/^(?:!!)*!(.*)$/, (r$1, e$2) => `(?!^${L(e$2)}$).*?`), i$1(/^(!!)+/, "")]), j = l$1([
415
+ i$1(/\/(\*\*\/)+/, "(?:/.+/|/)"),
416
+ i$1(/^(\*\*\/)+/, "(?:^|.*/)"),
417
+ i$1(/\/(\*\*)$/, "(?:/.*|$)"),
418
+ i$1(/\*\*/, ".*")
419
+ ]), N = l$1([i$1(/\*\/(?!\*\*\/)/, "[^/]*/"), i$1(/\*/, "[^/]*")]), k = i$1("?", "[^/]"), $r = i$1("[", p$1), wr = i$1("]", p$1), Ar = i$1(/[!^]/, "^/"), br = i$1(/[a-z]-[a-z]|[0-9]-[0-9]/i, p$1), Er = l$1([
423
420
  y,
424
- Cr,
421
+ i$1(/[$.*+?^(){}[\|]/, (r$1) => `\\${r$1}`),
425
422
  br,
426
- Mr
423
+ i$1(/[^\]]/, p$1)
427
424
  ]), B = x([
428
425
  $r,
429
426
  tr(Ar),
430
427
  f$1(Er),
431
428
  wr
432
- ]), Pr = i$1("{", "(?:"), Or$1 = i$1("}", ")"), Rr = i$1(/(\d+)\.\.(\d+)/, (r$1, e$2, n$2) => or$1(+e$2, +n$2, Math.min(e$2.length, n$2.length)).join("|")), zr = i$1(/([a-z]+)\.\.([a-z]+)/, (r$1, e$2, n$2) => R(e$2, n$2).join("|")), jr = i$1(/([A-Z]+)\.\.([A-Z]+)/, (r$1, e$2, n$2) => R(e$2.toLowerCase(), n$2.toLowerCase()).join("|").toUpperCase()), Nr = l$1([
433
- Rr,
434
- zr,
435
- jr
436
- ]), I = x([
429
+ ]), Pr = i$1("{", "(?:"), Or$1 = i$1("}", ")"), I = x([
437
430
  Pr,
438
- Nr,
431
+ l$1([
432
+ i$1(/(\d+)\.\.(\d+)/, (r$1, e$2, n$2) => or$1(+e$2, +n$2, Math.min(e$2.length, n$2.length)).join("|")),
433
+ i$1(/([a-z]+)\.\.([a-z]+)/, (r$1, e$2, n$2) => R(e$2, n$2).join("|")),
434
+ i$1(/([A-Z]+)\.\.([A-Z]+)/, (r$1, e$2, n$2) => R(e$2.toLowerCase(), n$2.toLowerCase()).join("|").toUpperCase())
435
+ ]),
439
436
  Or$1
440
- ]), kr = i$1("{", "(?:"), Br = i$1("}", ")"), Ir = i$1(",", "|"), Fr = i$1(/[$.*+?^(){[\]\|]/, (r$1) => `\\${r$1}`), Lr = i$1(/[^}]/, p$1), Zr = E(() => F), Dr = l$1([
441
- j,
442
- N,
443
- k,
444
- B,
445
- I,
446
- Zr,
447
- y,
448
- Fr,
449
- Ir,
450
- Lr
451
- ]), F = x([
437
+ ]), kr = i$1("{", "(?:"), Br = i$1("}", ")"), Ir = i$1(",", "|"), Fr = i$1(/[$.*+?^(){[\]\|]/, (r$1) => `\\${r$1}`), Lr = i$1(/[^}]/, p$1), F = x([
452
438
  kr,
453
- f$1(Dr),
439
+ f$1(l$1([
440
+ j,
441
+ N,
442
+ k,
443
+ B,
444
+ I,
445
+ E(() => F),
446
+ y,
447
+ Fr,
448
+ Ir,
449
+ Lr
450
+ ])),
454
451
  Br
455
- ]), Vr = f$1(l$1([
452
+ ]), L = z(f$1(l$1([
456
453
  sr,
457
454
  cr,
458
455
  lr,
@@ -466,13 +463,13 @@ let _lazyMatch = () => {
466
463
  y,
467
464
  pr,
468
465
  vr
469
- ])), L = z(Vr), Tr = i$1(/\\./, p$1), qr = i$1(/./, p$1), Hr = i$1(/\*\*\*+/, "*"), Jr = i$1(/([^/{[(!])\*\*/, (r$1, e$2) => `${e$2}*`), Qr = i$1(/(^|.)\*\*(?=[^*/)\]}])/, (r$1, e$2) => `${e$2}*`), Kr = f$1(l$1([
466
+ ]))), Tr = i$1(/\\./, p$1), qr = i$1(/./, p$1), Yr = z(f$1(l$1([
470
467
  Tr,
471
- Hr,
472
- Jr,
473
- Qr,
468
+ i$1(/\*\*\*+/, "*"),
469
+ i$1(/([^/{[(!])\*\*/, (r$1, e$2) => `${e$2}*`),
470
+ i$1(/(^|.)\*\*(?=[^*/)\]}])/, (r$1, e$2) => `${e$2}*`),
474
471
  qr
475
- ])), Yr = z(Kr), $ = (r$1, e$2) => {
472
+ ]))), $ = (r$1, e$2) => {
476
473
  const n$2 = Array.isArray(r$1) ? r$1 : [r$1];
477
474
  if (!n$2.length) return false;
478
475
  const a$2 = n$2.map($.compile), t$3 = n$2.every((s$1) => /(\/(?:\*\*)?|\[\/\])$/.test(s$1)), o$1 = e$2.replace(/[\\\/]+/g, "/").replace(/\/$/, t$3 ? "/" : "");
@@ -1146,7 +1143,7 @@ var ansis_default = import_ansis.default;
1146
1143
  const { Ansis, fg, bg, rgb, bgRgb, hex, bgHex, reset, inverse, hidden, visible, bold, dim, italic, underline, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = import_ansis.default;
1147
1144
 
1148
1145
  //#endregion
1149
- //#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.2/node_modules/valibot/dist/index.js
1146
+ //#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.3/node_modules/valibot/dist/index.js
1150
1147
  var store;
1151
1148
  /* @__NO_SIDE_EFFECTS__ */
1152
1149
  function getGlobalConfig(config2) {
@@ -2371,7 +2368,8 @@ const InputOptionsSchema = strictObject({
2371
2368
  chunkImportMap: optional(union([boolean(), object({
2372
2369
  baseUrl: optional(string()),
2373
2370
  fileName: optional(string())
2374
- })]))
2371
+ })])),
2372
+ nativeMagicString: optional(boolean())
2375
2373
  })),
2376
2374
  define: pipe(optional(record(string(), string())), description("Define global variables")),
2377
2375
  inject: optional(record(string(), union([string(), tuple([string(), string()])]))),
@@ -2438,6 +2436,7 @@ const ChunkFileNamesSchema = union([string(), pipe(function_(), args(tuple([cust
2438
2436
  const AssetFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
2439
2437
  const SanitizeFileNameSchema = union([boolean(), pipe(function_(), args(tuple([string()])), returns(string()))]);
2440
2438
  const GlobalsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
2439
+ const PathsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
2441
2440
  const AdvancedChunksSchema = strictObject({
2442
2441
  includeDependenciesRecursively: optional(boolean()),
2443
2442
  minSize: optional(number()),
@@ -2512,6 +2511,7 @@ const OutputOptionsSchema = strictObject({
2512
2511
  ])), description("Minify the bundled file")),
2513
2512
  name: pipe(optional(string()), description("Name for UMD / IIFE format outputs")),
2514
2513
  globals: pipe(optional(union([record(string(), string()), GlobalsFunctionSchema])), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2514
+ paths: pipe(optional(union([record(string(), string()), PathsFunctionSchema])), description("Maps external module IDs to paths")),
2515
2515
  generatedCode: pipe(optional(partial(GeneratedCodeOptionsSchema)), description("Generated code options")),
2516
2516
  externalLiveBindings: pipe(optional(boolean()), description("external live bindings")),
2517
2517
  inlineDynamicImports: pipe(optional(boolean()), description("Inline dynamic imports")),
@@ -2564,6 +2564,7 @@ const OutputCliOptionsSchema = omit(strictObject({
2564
2564
  const CliOptionsSchema = strictObject({
2565
2565
  config: pipe(optional(union([string(), boolean()])), description("Path to the config file (default: `rolldown.config.js`)")),
2566
2566
  help: pipe(optional(boolean()), description("Show help")),
2567
+ environment: pipe(optional(union([string(), array(string())])), description("Pass additional settings to the config file via process.ENV.")),
2567
2568
  version: pipe(optional(boolean()), description("Show version number")),
2568
2569
  watch: pipe(optional(boolean()), description("Watch files in bundle and rebuild on changes")),
2569
2570
  ...InputCliOptionsSchema.entries,
@@ -2598,6 +2599,77 @@ function validateOption(key, options) {
2598
2599
  }
2599
2600
  }
2600
2601
 
2602
+ //#endregion
2603
+ //#region ../../node_modules/.pnpm/oxc-parser@0.94.0/node_modules/oxc-parser/src-js/wrap.js
2604
+ function wrap$1(result) {
2605
+ let program, module$1, comments, errors;
2606
+ return {
2607
+ get program() {
2608
+ if (!program) program = jsonParseAst(result.program);
2609
+ return program;
2610
+ },
2611
+ get module() {
2612
+ if (!module$1) module$1 = result.module;
2613
+ return module$1;
2614
+ },
2615
+ get comments() {
2616
+ if (!comments) comments = result.comments;
2617
+ return comments;
2618
+ },
2619
+ get errors() {
2620
+ if (!errors) errors = result.errors;
2621
+ return errors;
2622
+ }
2623
+ };
2624
+ }
2625
+ function jsonParseAst(programJson) {
2626
+ const { node: program, fixes } = JSON.parse(programJson);
2627
+ for (const fixPath of fixes) applyFix(program, fixPath);
2628
+ return program;
2629
+ }
2630
+ function applyFix(program, fixPath) {
2631
+ let node = program;
2632
+ for (const key of fixPath) node = node[key];
2633
+ if (node.bigint) node.value = BigInt(node.bigint);
2634
+ else try {
2635
+ node.value = RegExp(node.regex.pattern, node.regex.flags);
2636
+ } catch (_err) {}
2637
+ }
2638
+
2639
+ //#endregion
2640
+ //#region src/parse-ast-index.ts
2641
+ function wrap(result, sourceText) {
2642
+ result = wrap$1(result);
2643
+ if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
2644
+ return result.program;
2645
+ }
2646
+ function normalizeParseError(sourceText, errors) {
2647
+ let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
2648
+ for (let i$1 = 0; i$1 < errors.length; i$1++) {
2649
+ if (i$1 >= 5) {
2650
+ message += "\n...";
2651
+ break;
2652
+ }
2653
+ const e$2 = errors[i$1];
2654
+ message += e$2.message + "\n" + e$2.labels.map((label) => {
2655
+ const location = locate(sourceText, label.start, { offsetLine: 1 });
2656
+ if (!location) return;
2657
+ return getCodeFrame(sourceText, location.line, location.column);
2658
+ }).filter(Boolean).join("\n");
2659
+ }
2660
+ return error(logParseError(message));
2661
+ }
2662
+ const defaultParserOptions = {
2663
+ lang: "js",
2664
+ preserveParens: false
2665
+ };
2666
+ function parseAst(sourceText, options, filename) {
2667
+ return wrap(parseSync(filename ?? "file.js", sourceText, {
2668
+ ...defaultParserOptions,
2669
+ ...options
2670
+ }), sourceText);
2671
+ }
2672
+
2601
2673
  //#endregion
2602
2674
  //#region src/types/sourcemap.ts
2603
2675
  function bindingifySourcemap$1(map) {
@@ -2616,12 +2688,23 @@ function bindingifySourcemap$1(map) {
2616
2688
 
2617
2689
  //#endregion
2618
2690
  //#region src/utils/error.ts
2619
- function normalizeErrors(rawErrors) {
2620
- const errors = rawErrors.map((e$2) => e$2 instanceof Error ? e$2 : Object.assign(/* @__PURE__ */ new Error(), {
2621
- kind: e$2.kind,
2622
- message: e$2.message,
2691
+ function unwrapBindingResult(container) {
2692
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
2693
+ return container;
2694
+ }
2695
+ function normalizeBindingResult(container) {
2696
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
2697
+ return container;
2698
+ }
2699
+ function normalizeBindingError(e$2) {
2700
+ return e$2.type === "JsError" ? e$2.field0 : Object.assign(/* @__PURE__ */ new Error(), {
2701
+ kind: e$2.field0.kind,
2702
+ message: e$2.field0.message,
2623
2703
  stack: void 0
2624
- }));
2704
+ });
2705
+ }
2706
+ function aggregateBindingErrorsIntoJsError(rawErrors) {
2707
+ const errors = rawErrors.map(normalizeBindingError);
2625
2708
  let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
2626
2709
  for (let i$1 = 0; i$1 < errors.length; i$1++) {
2627
2710
  summary += "\n";
@@ -2967,77 +3050,6 @@ function bindingPluginOrder(order) {
2967
3050
  }
2968
3051
  }
2969
3052
 
2970
- //#endregion
2971
- //#region ../../node_modules/.pnpm/oxc-parser@0.93.0/node_modules/oxc-parser/src-js/wrap.js
2972
- function wrap$1(result) {
2973
- let program, module$1, comments, errors;
2974
- return {
2975
- get program() {
2976
- if (!program) program = jsonParseAst(result.program);
2977
- return program;
2978
- },
2979
- get module() {
2980
- if (!module$1) module$1 = result.module;
2981
- return module$1;
2982
- },
2983
- get comments() {
2984
- if (!comments) comments = result.comments;
2985
- return comments;
2986
- },
2987
- get errors() {
2988
- if (!errors) errors = result.errors;
2989
- return errors;
2990
- }
2991
- };
2992
- }
2993
- function jsonParseAst(programJson) {
2994
- const { node: program, fixes } = JSON.parse(programJson);
2995
- for (const fixPath of fixes) applyFix(program, fixPath);
2996
- return program;
2997
- }
2998
- function applyFix(program, fixPath) {
2999
- let node = program;
3000
- for (const key of fixPath) node = node[key];
3001
- if (node.bigint) node.value = BigInt(node.bigint);
3002
- else try {
3003
- node.value = RegExp(node.regex.pattern, node.regex.flags);
3004
- } catch (_err) {}
3005
- }
3006
-
3007
- //#endregion
3008
- //#region src/parse-ast-index.ts
3009
- function wrap(result, sourceText) {
3010
- result = wrap$1(result);
3011
- if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
3012
- return result.program;
3013
- }
3014
- function normalizeParseError(sourceText, errors) {
3015
- let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
3016
- for (let i$1 = 0; i$1 < errors.length; i$1++) {
3017
- if (i$1 >= 5) {
3018
- message += "\n...";
3019
- break;
3020
- }
3021
- const e$2 = errors[i$1];
3022
- message += e$2.message + "\n" + e$2.labels.map((label) => {
3023
- const location = locate(sourceText, label.start, { offsetLine: 1 });
3024
- if (!location) return;
3025
- return getCodeFrame(sourceText, location.line, location.column);
3026
- }).filter(Boolean).join("\n");
3027
- }
3028
- return error(logParseError(message));
3029
- }
3030
- const defaultParserOptions = {
3031
- lang: "js",
3032
- preserveParens: false
3033
- };
3034
- function parseAst(sourceText, options, filename) {
3035
- return wrap(parseSync(filename ?? "file.js", sourceText, {
3036
- ...defaultParserOptions,
3037
- ...options
3038
- }), sourceText);
3039
- }
3040
-
3041
3053
  //#endregion
3042
3054
  //#region src/utils/asset-source.ts
3043
3055
  function transformAssetSource(bindingAssetSource$1) {
@@ -3097,7 +3109,7 @@ var PluginContextImpl = class extends MinimalPluginContextImpl {
3097
3109
  this.data.updateModuleOption(id$1, rawOptions);
3098
3110
  let loadPromise = this.data.loadModulePromiseMap.get(id$1);
3099
3111
  if (!loadPromise) {
3100
- loadPromise = this.context.load(id$1, options.moduleSideEffects ?? void 0).catch(() => {
3112
+ loadPromise = this.context.load(id$1, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
3101
3113
  this.data.loadModulePromiseMap.delete(id$1);
3102
3114
  });
3103
3115
  this.data.loadModulePromiseMap.set(id$1, loadPromise);
@@ -3199,6 +3211,9 @@ var TransformPluginContextImpl = class extends PluginContextImpl {
3199
3211
  addWatchFile(id$1) {
3200
3212
  this.inner.addWatchFile(id$1);
3201
3213
  }
3214
+ sendMagicString(s$1) {
3215
+ this.inner.sendMagicString(s$1);
3216
+ }
3202
3217
  };
3203
3218
 
3204
3219
  //#endregion
@@ -3220,7 +3235,7 @@ function bindingifyBuildEnd(args$1) {
3220
3235
  const { handler, meta } = normalizeHook(hook);
3221
3236
  return {
3222
3237
  plugin: async (ctx, err) => {
3223
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), err ? normalizeErrors(err) : void 0);
3238
+ await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
3224
3239
  },
3225
3240
  meta: bindingifyPluginHookMeta(meta)
3226
3241
  };
@@ -3278,7 +3293,8 @@ function bindingifyResolveDynamicImport(args$1) {
3278
3293
  if (typeof ret === "string") return { id: ret };
3279
3294
  const result = {
3280
3295
  id: ret.id,
3281
- external: ret.external
3296
+ external: ret.external,
3297
+ packageJsonPath: ret.packageJsonPath
3282
3298
  };
3283
3299
  if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
3284
3300
  args$1.pluginContextData.updateModuleOption(ret.id, {
@@ -3297,7 +3313,29 @@ function bindingifyTransform(args$1) {
3297
3313
  const { handler, meta, options } = normalizeHook(hook);
3298
3314
  return {
3299
3315
  plugin: async (ctx, code$1, id$1, meta$1) => {
3300
- const ret = await handler.call(new TransformPluginContextImpl(args$1.outputOptions, ctx.inner(), args$1.plugin, args$1.pluginContextData, ctx, id$1, code$1, args$1.onLog, args$1.logLevel, args$1.watchMode), code$1, id$1, meta$1);
3316
+ Object.defineProperties(meta$1, {
3317
+ magicString: { get() {
3318
+ return new BindingMagicString(code$1);
3319
+ } },
3320
+ ast: { get() {
3321
+ let lang = "js";
3322
+ switch (meta$1.moduleType) {
3323
+ case "js":
3324
+ case "jsx":
3325
+ case "ts":
3326
+ case "tsx":
3327
+ lang = meta$1.moduleType;
3328
+ break;
3329
+ default: break;
3330
+ }
3331
+ return parseAst(code$1, {
3332
+ astType: meta$1.moduleType.includes("ts") ? "ts" : "js",
3333
+ lang
3334
+ });
3335
+ } }
3336
+ });
3337
+ const transformCtx = new TransformPluginContextImpl(args$1.outputOptions, ctx.inner(), args$1.plugin, args$1.pluginContextData, ctx, id$1, code$1, args$1.onLog, args$1.logLevel, args$1.watchMode);
3338
+ const ret = await handler.call(transformCtx, code$1, id$1, meta$1);
3301
3339
  if (ret == null) return;
3302
3340
  if (typeof ret === "string") return { code: ret };
3303
3341
  let moduleOption = args$1.pluginContextData.updateModuleOption(id$1, {
@@ -3305,9 +3343,18 @@ function bindingifyTransform(args$1) {
3305
3343
  moduleSideEffects: ret.moduleSideEffects ?? null,
3306
3344
  invalidate: false
3307
3345
  });
3346
+ let normalizedCode = void 0;
3347
+ let map = ret.map;
3348
+ if (typeof ret.code === "string") normalizedCode = ret.code;
3349
+ else if (ret.code instanceof BindingMagicString) {
3350
+ let magicString = ret.code;
3351
+ normalizedCode = magicString.toString();
3352
+ let fallbackSourcemap = ctx.sendMagicString(magicString);
3353
+ if (fallbackSourcemap != void 0) map = fallbackSourcemap;
3354
+ }
3308
3355
  return {
3309
- code: ret.code,
3310
- map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id$1, code$1, ret.map)),
3356
+ code: normalizedCode,
3357
+ map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id$1, code$1, map)),
3311
3358
  moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
3312
3359
  moduleType: ret.moduleType
3313
3360
  };
@@ -3520,14 +3567,9 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
3520
3567
  });
3521
3568
  }
3522
3569
  function transformToRollupOutput(output, changed) {
3523
- handleOutputErrors(output);
3524
3570
  const { chunks, assets } = output;
3525
3571
  return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
3526
3572
  }
3527
- function handleOutputErrors(output) {
3528
- const rawErrors = output.errors;
3529
- if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
3530
- }
3531
3573
  function transformToOutputBundle(context, output, changed) {
3532
3574
  const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
3533
3575
  return new Proxy(bundle, {
@@ -3633,7 +3675,7 @@ function bindingifyRenderError(args$1) {
3633
3675
  const { handler, meta } = normalizeHook(hook);
3634
3676
  return {
3635
3677
  plugin: async (ctx, err) => {
3636
- handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), normalizeErrors(err));
3678
+ handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), aggregateBindingErrorsIntoJsError(err));
3637
3679
  },
3638
3680
  meta: bindingifyPluginHookMeta(meta)
3639
3681
  };
@@ -3649,7 +3691,7 @@ function bindingifyGenerateBundle(args$1) {
3649
3691
  deleted: /* @__PURE__ */ new Set()
3650
3692
  };
3651
3693
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3652
- const output = transformToOutputBundle(context, bundle, changed);
3694
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
3653
3695
  await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output, isWrite);
3654
3696
  return collectChangedBundle(changed, output);
3655
3697
  },
@@ -3667,7 +3709,7 @@ function bindingifyWriteBundle(args$1) {
3667
3709
  deleted: /* @__PURE__ */ new Set()
3668
3710
  };
3669
3711
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3670
- const output = transformToOutputBundle(context, bundle, changed);
3712
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
3671
3713
  await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output);
3672
3714
  return collectChangedBundle(changed, output);
3673
3715
  },
@@ -3854,7 +3896,7 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
3854
3896
  const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args$1);
3855
3897
  const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args$1);
3856
3898
  let hookUsage = extractHookUsage(plugin).inner();
3857
- const result = {
3899
+ return wrapHandlers({
3858
3900
  name: plugin.name,
3859
3901
  buildStart,
3860
3902
  buildStartMeta,
@@ -3901,8 +3943,7 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
3901
3943
  closeWatcher,
3902
3944
  closeWatcherMeta,
3903
3945
  hookUsage
3904
- };
3905
- return wrapHandlers(result);
3946
+ });
3906
3947
  }
3907
3948
  function wrapHandlers(plugin) {
3908
3949
  for (const hookName of [
@@ -4041,6 +4082,9 @@ var NormalizedOutputOptionsImpl = class {
4041
4082
  get globals() {
4042
4083
  return this.inner.globals || this.outputOptions.globals;
4043
4084
  }
4085
+ get paths() {
4086
+ return this.outputOptions.paths;
4087
+ }
4044
4088
  get hashCharacters() {
4045
4089
  return this.inner.hashCharacters;
4046
4090
  }
@@ -4295,7 +4339,8 @@ function bindingifyExperimental(experimental) {
4295
4339
  chunkModulesOrder,
4296
4340
  chunkImportMap: experimental?.chunkImportMap,
4297
4341
  onDemandWrapping: experimental?.onDemandWrapping,
4298
- incrementalBuild: experimental?.incrementalBuild
4342
+ incrementalBuild: experimental?.incrementalBuild,
4343
+ nativeMagicString: experimental?.nativeMagicString
4299
4344
  };
4300
4345
  }
4301
4346
  function bindingifyResolve(resolve$1) {
@@ -4484,7 +4529,7 @@ var ChunkingContextImpl = class {
4484
4529
  //#endregion
4485
4530
  //#region src/utils/bindingify-output-options.ts
4486
4531
  function bindingifyOutputOptions(outputOptions) {
4487
- const { dir, format: format$1, exports, hashCharacters, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, generatedCode, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks, topLevelVar } = outputOptions;
4532
+ const { dir, format: format$1, exports, hashCharacters, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, paths, generatedCode, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks, topLevelVar } = outputOptions;
4488
4533
  const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
4489
4534
  return {
4490
4535
  dir,
@@ -4503,6 +4548,7 @@ function bindingifyOutputOptions(outputOptions) {
4503
4548
  outro: bindingifyAddon(outro),
4504
4549
  extend: outputOptions.extend,
4505
4550
  globals,
4551
+ paths,
4506
4552
  generatedCode,
4507
4553
  esModule,
4508
4554
  name,
@@ -4599,12 +4645,10 @@ async function createBundlerOptions(inputOptions, outputOptions, watchMode) {
4599
4645
  let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
4600
4646
  const parallelPluginInitResult = void 0;
4601
4647
  try {
4602
- const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
4603
- const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
4604
4648
  return {
4605
4649
  bundlerOptions: {
4606
- inputOptions: bindingInputOptions,
4607
- outputOptions: bindingOutputOptions,
4650
+ inputOptions: bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode),
4651
+ outputOptions: bindingifyOutputOptions(outputOptions),
4608
4652
  parallelPluginsRegistry: parallelPluginInitResult?.registry
4609
4653
  },
4610
4654
  inputOptions,
@@ -4652,20 +4696,17 @@ var RolldownBuild = class RolldownBuild {
4652
4696
  }
4653
4697
  async scan() {
4654
4698
  const { impl } = await this.#getBundlerWithStopWorker({});
4655
- const output = await impl.scan();
4656
- return handleOutputErrors(output);
4699
+ unwrapBindingResult(await impl.scan());
4657
4700
  }
4658
4701
  async generate(outputOptions = {}) {
4659
4702
  validateOption("output", outputOptions);
4660
4703
  const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
4661
- const output = await impl.generate();
4662
- return transformToRollupOutput(output);
4704
+ return transformToRollupOutput(unwrapBindingResult(await impl.generate()));
4663
4705
  }
4664
4706
  async write(outputOptions = {}) {
4665
4707
  validateOption("output", outputOptions);
4666
4708
  const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
4667
- const output = await impl.write();
4668
- return transformToRollupOutput(output);
4709
+ return transformToRollupOutput(unwrapBindingResult(await impl.write()));
4669
4710
  }
4670
4711
  async close() {
4671
4712
  if (this.#bundlerImpl) {
@@ -4687,8 +4728,7 @@ var RolldownBuild = class RolldownBuild {
4687
4728
  //#region src/api/rolldown/index.ts
4688
4729
  const rolldown = async (input) => {
4689
4730
  validateOption("input", input);
4690
- const inputOptions = await PluginDriver.callOptionsHook(input);
4691
- return new RolldownBuild(inputOptions);
4731
+ return new RolldownBuild(await PluginDriver.callOptionsHook(input));
4692
4732
  };
4693
4733
 
4694
4734
  //#endregion
@@ -4756,7 +4796,7 @@ var WatcherEmitter = class {
4756
4796
  const data = event.bundleErrorData();
4757
4797
  await listener({
4758
4798
  code: "ERROR",
4759
- error: normalizeErrors(data.error),
4799
+ error: aggregateBindingErrorsIntoJsError(data.error),
4760
4800
  result: data.result
4761
4801
  });
4762
4802
  break;
@@ -4812,12 +4852,10 @@ var Watcher = class {
4812
4852
  async function createWatcher(emitter, input) {
4813
4853
  const options = arraify(input);
4814
4854
  const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
4815
- const inputOptions = await PluginDriver.callOptionsHook(option, true);
4816
- return createBundlerOptions(inputOptions, output, true);
4855
+ return createBundlerOptions(await PluginDriver.callOptionsHook(option, true), output, true);
4817
4856
  })).flat());
4818
4857
  const notifyOptions = getValidNotifyOption(bundlerOptions);
4819
- const bindingWatcher = new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
4820
- new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers)).start();
4858
+ new Watcher(emitter, new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions), bundlerOptions.map((option) => option.stopWorkers)).start();
4821
4859
  }
4822
4860
  function getValidNotifyOption(bundlerOptions) {
4823
4861
  let result;
@@ -4849,4 +4887,4 @@ function defineConfig(config) {
4849
4887
  const VERSION = version;
4850
4888
 
4851
4889
  //#endregion
4852
- export { BuiltinPlugin, PluginDriver, RolldownBuild, VERSION, build, createBundlerOptions, defineConfig, makeBuiltinPluginCallable, normalizedStringOrRegex, rolldown, watch };
4890
+ export { BindingMagicString$1 as BindingMagicString, BuiltinPlugin, PluginDriver, RolldownBuild, VERSION, build, createBundlerOptions, defineConfig, makeBuiltinPluginCallable, normalizeBindingResult, normalizedStringOrRegex, rolldown, watch };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolldown/browser",
3
- "version": "1.0.0-beta.41",
3
+ "version": "1.0.0-beta.43",
4
4
  "description": "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.",
5
5
  "homepage": "https://rolldown.rs/",
6
6
  "type": "module",