@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 { BindingBuiltinPluginName, BindingBundlerImpl, BindingHookResolveIdExtraArgs, BindingRenderedChunk, BindingTransformHookExtraArgs, BindingWatcherEvent, MinifyOptions as MinifyOptions$1, ParserOptions, PreRenderedChunk, TransformOptions } from "./binding-DOpOtI1J.mjs";
1
+ import { BindingBuiltinPluginName, BindingBundlerImpl, BindingHookResolveIdExtraArgs, BindingMagicString, BindingRenderedChunk, BindingTransformHookExtraArgs, BindingWatcherEvent, MinifyOptions as MinifyOptions$1, ParserOptions, PreRenderedChunk, TransformOptions } from "./binding-BkaKdpud.mjs";
2
2
  import { Program } from "@oxc-project/types";
3
3
  import { TopLevelFilterExpression } from "@rolldown/pluginutils";
4
4
 
@@ -253,6 +253,37 @@ interface OutputOptions {
253
253
  minify?: boolean | "dce-only" | MinifyOptions;
254
254
  name?: string;
255
255
  globals?: Record<string, string> | GlobalsFunction;
256
+ /**
257
+ * Maps external module IDs to paths.
258
+ *
259
+ * Allows customizing the path used when importing external dependencies.
260
+ * This is particularly useful for loading dependencies from CDNs or custom locations.
261
+ *
262
+ * - Object form: Maps module IDs to their replacement paths
263
+ * - Function form: Takes a module ID and returns its replacement path
264
+ *
265
+ * @example
266
+ * ```js
267
+ * {
268
+ * paths: {
269
+ * 'd3': 'https://cdn.jsdelivr.net/npm/d3@7'
270
+ * }
271
+ * }
272
+ * ```
273
+ *
274
+ * @example
275
+ * ```js
276
+ * {
277
+ * paths: (id) => {
278
+ * if (id.startsWith('lodash')) {
279
+ * return `https://cdn.jsdelivr.net/npm/${id}`
280
+ * }
281
+ * return id
282
+ * }
283
+ * }
284
+ * ```
285
+ */
286
+ paths?: Record<string, string> | ((id: string) => string);
256
287
  generatedCode?: Partial<GeneratedCodeOptions>;
257
288
  externalLiveBindings?: boolean;
258
289
  inlineDynamicImports?: boolean;
@@ -314,7 +345,7 @@ interface OutputOptions {
314
345
  * By default, each group will also include captured modules' dependencies. This reduces the chance of generating circular chunks.
315
346
  *
316
347
  * If you want to disable this behavior, it's recommended to both set
317
- * - `preserveEntrySignatures: false`
348
+ * - `preserveEntrySignatures: false | 'allow-extension'`
318
349
  * - `strictExecutionOrder: true`
319
350
  *
320
351
  * to avoid generating invalid chunks.
@@ -612,6 +643,7 @@ interface NormalizedInputOptions {
612
643
  }
613
644
  //#endregion
614
645
  //#region src/options/normalized-output-options.d.ts
646
+ type PathsFunction = (id: string) => string;
615
647
  type InternalModuleFormat = "es" | "cjs" | "iife" | "umd";
616
648
  interface NormalizedOutputOptions {
617
649
  name: string | undefined;
@@ -635,6 +667,7 @@ interface NormalizedOutputOptions {
635
667
  esModule: boolean | "if-default-prop";
636
668
  extend: boolean;
637
669
  globals: Record<string, string> | GlobalsFunction;
670
+ paths: Record<string, string> | PathsFunction | undefined;
638
671
  hashCharacters: "base64" | "base36" | "hex";
639
672
  sourcemapDebugIds: boolean;
640
673
  sourcemapIgnoreList: boolean | SourcemapIgnoreListOption | StringOrRegExp | undefined;
@@ -952,7 +985,9 @@ interface ResolveIdExtraOptions {
952
985
  }
953
986
  type ResolveIdResult = string | NullValue | false | PartialResolvedId;
954
987
  type LoadResult = NullValue | string | SourceDescription;
955
- type TransformResult = NullValue | string | Partial<SourceDescription>;
988
+ type TransformResult = NullValue | string | Omit<SourceDescription, "code"> & {
989
+ code?: string | BindingMagicString;
990
+ };
956
991
  type RenderedChunkMeta = {
957
992
  chunks: Record<string, RenderedChunk>;
958
993
  };
@@ -970,6 +1005,7 @@ interface FunctionPluginHooks {
970
1005
  [DEFINED_HOOK_NAMES.load]: (this: PluginContext, id: string) => MaybePromise<LoadResult>;
971
1006
  [DEFINED_HOOK_NAMES.transform]: (this: TransformPluginContext, code: string, id: string, meta: BindingTransformHookExtraArgs & {
972
1007
  moduleType: ModuleType;
1008
+ magicString?: BindingMagicString;
973
1009
  }) => TransformResult;
974
1010
  [DEFINED_HOOK_NAMES.moduleParsed]: (this: PluginContext, moduleInfo: ModuleInfo) => void;
975
1011
  [DEFINED_HOOK_NAMES.buildEnd]: (this: PluginContext, err?: Error) => void;
@@ -1238,6 +1274,17 @@ interface InputOptions {
1238
1274
  onwarn?: (warning: RollupLog, defaultHandler: (warning: RollupLogWithString | (() => RollupLogWithString)) => void) => void;
1239
1275
  moduleTypes?: ModuleTypes;
1240
1276
  experimental?: {
1277
+ /**
1278
+ * Lets modules be executed in the order they are declared.
1279
+ *
1280
+ * - Type: `boolean`
1281
+ * - Default: `false`
1282
+ *
1283
+ * This is done by injecting runtime helpers to ensure that modules are executed in the order they are imported. External modules won't be affected.
1284
+ *
1285
+ * > [!WARNING]
1286
+ * > Enabling this option may negatively increase bundle size. It is recommended to use this option only when absolutely necessary.
1287
+ */
1241
1288
  strictExecutionOrder?: boolean;
1242
1289
  disableLiveBindings?: boolean;
1243
1290
  viteMode?: boolean;
@@ -1326,6 +1373,16 @@ interface InputOptions {
1326
1373
  */
1327
1374
  incrementalBuild?: boolean;
1328
1375
  transformHiresSourcemap?: boolean | "boundary";
1376
+ /**
1377
+ * Use native Rust implementation of MagicString for source map generation.
1378
+ *
1379
+ * - Type: `boolean`
1380
+ * - Default: `false`
1381
+ *
1382
+ * When enabled, rolldown will use a native Rust implementation of MagicString
1383
+ * for better performance during source map generation.
1384
+ */
1385
+ nativeMagicString?: boolean;
1329
1386
  };
1330
1387
  /**
1331
1388
  * Replace global variables or [property accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) with the provided values.
@@ -134,10 +134,9 @@ function exclude(expr) {
134
134
  * @returns a `And` FilterExpression
135
135
  */
136
136
  function queries(queryFilter) {
137
- let arr = Object.entries(queryFilter).map(([key, value]) => {
137
+ return and(...Object.entries(queryFilter).map(([key, value]) => {
138
138
  return new Query(key, value);
139
- });
140
- return and(...arr);
139
+ }));
141
140
  }
142
141
 
143
142
  //#endregion
@@ -1,4 +1,4 @@
1
- import { rolldown } from "./src-DnNenssl.mjs";
1
+ import { rolldown } from "./src-Dqrw8WuH.mjs";
2
2
  import path from "node:path";
3
3
  import { readdir } from "node:fs/promises";
4
4
  import { pathToFileURL } from "node:url";
@@ -66,8 +66,7 @@ async function findConfigFileNameInCwd() {
66
66
  throw new Error("No `rolldown.config` configuration file found.");
67
67
  }
68
68
  async function loadTsConfig(configFile) {
69
- const isEsm = isFilePathESM(configFile);
70
- const file = await bundleTsConfig(configFile, isEsm);
69
+ const file = await bundleTsConfig(configFile, isFilePathESM(configFile));
71
70
  try {
72
71
  return (await import(pathToFileURL(file).href)).default;
73
72
  } finally {
@@ -104,10 +103,8 @@ async function loadConfig(configPath) {
104
103
  const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
105
104
  try {
106
105
  if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import(pathToFileURL(configPath).href)).default;
107
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
108
- const rawConfigPath = path.resolve(configPath);
109
- return await loadTsConfig(rawConfigPath);
110
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
106
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(path.resolve(configPath));
107
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
111
108
  } catch (err) {
112
109
  throw new Error("Error happened while loading config.", { cause: err });
113
110
  }
@@ -416,11 +416,10 @@ ${indent}`);
416
416
  return causedPrefix + message + "\n" + stack + causedError;
417
417
  }
418
418
  formatArgs(args, opts) {
419
- const _args = args.map((arg) => {
419
+ return formatWithOptions(opts, ...args.map((arg) => {
420
420
  if (arg && typeof arg.stack === "string") return this.formatError(arg, opts);
421
421
  return arg;
422
- });
423
- return formatWithOptions(opts, ..._args);
422
+ }));
424
423
  }
425
424
  formatDate(date, opts) {
426
425
  return opts.date ? date.toLocaleTimeString() : "";
@@ -442,11 +441,10 @@ ${indent}`);
442
441
  ]);
443
442
  }
444
443
  log(logObj, ctx) {
445
- const line = this.formatLogObj(logObj, {
444
+ return writeStream(this.formatLogObj(logObj, {
446
445
  columns: ctx.options.stdout.columns || 0,
447
446
  ...ctx.options.formatOptions
448
- });
449
- return writeStream(line + "\n", logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
447
+ }) + "\n", logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
450
448
  }
451
449
  };
452
450
 
@@ -646,8 +644,7 @@ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta
646
644
  return i()[s$1] ?? r[s$1];
647
645
  },
648
646
  has(e, s$1) {
649
- const E = i();
650
- return s$1 in E || s$1 in r;
647
+ return s$1 in i() || s$1 in r;
651
648
  },
652
649
  set(e, s$1, E) {
653
650
  const B = i(true);
@@ -944,7 +941,7 @@ function createConsola(options = {}) {
944
941
  defaults: { level },
945
942
  stdout: process.stdout,
946
943
  stderr: process.stderr,
947
- prompt: (...args) => import("./prompt-R6XhwkxA.mjs").then((m) => m.prompt(...args)),
944
+ prompt: (...args) => import("./prompt-B4e-jZUR.mjs").then((m) => m.prompt(...args)),
948
945
  reporters: options.reporters || [options.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
949
946
  ...options
950
947
  });
@@ -186,7 +186,7 @@ function augmentCodeLocation(properties, pos, source, id) {
186
186
  }
187
187
 
188
188
  //#endregion
189
- //#region ../../node_modules/.pnpm/oxc-parser@0.93.0/node_modules/oxc-parser/src-js/wrap.js
189
+ //#region ../../node_modules/.pnpm/oxc-parser@0.94.0/node_modules/oxc-parser/src-js/wrap.js
190
190
  function wrap$1(result) {
191
191
  let program, module, comments, errors;
192
192
  return {
@@ -39,28 +39,26 @@ function requireSrc() {
39
39
  save: `${ESC}7`,
40
40
  restore: `${ESC}8`
41
41
  };
42
- const scroll = {
43
- up: (count = 1) => `${CSI}S`.repeat(count),
44
- down: (count = 1) => `${CSI}T`.repeat(count)
45
- };
46
- const erase = {
47
- screen: `${CSI}2J`,
48
- up: (count = 1) => `${CSI}1J`.repeat(count),
49
- down: (count = 1) => `${CSI}J`.repeat(count),
50
- line: `${CSI}2K`,
51
- lineEnd: `${CSI}K`,
52
- lineStart: `${CSI}1K`,
53
- lines(count) {
54
- let clear = "";
55
- for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
56
- if (count) clear += cursor.left;
57
- return clear;
58
- }
59
- };
60
42
  src = {
61
43
  cursor,
62
- scroll,
63
- erase,
44
+ scroll: {
45
+ up: (count = 1) => `${CSI}S`.repeat(count),
46
+ down: (count = 1) => `${CSI}T`.repeat(count)
47
+ },
48
+ erase: {
49
+ screen: `${CSI}2J`,
50
+ up: (count = 1) => `${CSI}1J`.repeat(count),
51
+ down: (count = 1) => `${CSI}J`.repeat(count),
52
+ line: `${CSI}2K`,
53
+ lineEnd: `${CSI}K`,
54
+ lineStart: `${CSI}1K`,
55
+ lines(count) {
56
+ let clear = "";
57
+ for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
58
+ if (count) clear += cursor.left;
59
+ return clear;
60
+ }
61
+ },
64
62
  beep
65
63
  };
66
64
  return src;
@@ -1,7 +1,7 @@
1
- import { augmentCodeLocation, error, logCycleLoading, logDuplicateJsxConfig, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst } from "./parse-ast-index-CTl_R-Xm.mjs";
2
- import { and, arraify, code, exclude, id, include, moduleType, noop, or, unimplemented, unreachable, unsupported } from "./dist-CHTC3-kR.mjs";
1
+ import { augmentCodeLocation, error, logCycleLoading, logDuplicateJsxConfig, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst } from "./parse-ast-index-Gktxd-oi.mjs";
2
+ import { and, arraify, code, exclude, id, include, moduleType, noop, or, unimplemented, unreachable, unsupported } from "./dist-CU0dSkK2.mjs";
3
3
  import { Worker, isMainThread } from "node:worker_threads";
4
- import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingChunkModuleOrderBy, BindingJsx, BindingLogLevel, BindingPluginOrder, BindingPropertyReadSideEffects, BindingPropertyWriteSideEffects, BindingWatcher, ParallelJsPluginRegistry, initTraceSubscriber, shutdownAsyncRuntime, startAsyncRuntime } from "../rolldown-binding.wasi.cjs";
4
+ import { BindingAttachDebugInfo, BindingBundler, BindingCallableBuiltinPlugin, BindingChunkModuleOrderBy, BindingJsx, BindingLogLevel, BindingMagicString, BindingMagicString as BindingMagicString$1, BindingPluginOrder, BindingPropertyReadSideEffects, BindingPropertyWriteSideEffects, BindingWatcher, ParallelJsPluginRegistry, initTraceSubscriber, shutdownAsyncRuntime, startAsyncRuntime } from "../rolldown-binding.wasi.cjs";
5
5
  import path from "node:path";
6
6
  import fsp from "node:fs/promises";
7
7
  import os from "node:os";
@@ -243,7 +243,7 @@ if (isMainThread) {
243
243
 
244
244
  //#endregion
245
245
  //#region package.json
246
- var version = "1.0.0-beta.41";
246
+ var version = "1.0.0-beta.43";
247
247
  var description$1 = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
248
248
 
249
249
  //#endregion
@@ -701,7 +701,7 @@ var ansis_default = import_ansis.default;
701
701
  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;
702
702
 
703
703
  //#endregion
704
- //#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.2/node_modules/valibot/dist/index.js
704
+ //#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.3/node_modules/valibot/dist/index.js
705
705
  var store;
706
706
  /* @__NO_SIDE_EFFECTS__ */
707
707
  function getGlobalConfig(config2) {
@@ -2015,7 +2015,8 @@ const InputOptionsSchema = strictObject({
2015
2015
  chunkImportMap: optional(union([boolean(), object({
2016
2016
  baseUrl: optional(string()),
2017
2017
  fileName: optional(string())
2018
- })]))
2018
+ })])),
2019
+ nativeMagicString: optional(boolean())
2019
2020
  })),
2020
2021
  define: pipe(optional(record(string(), string())), description("Define global variables")),
2021
2022
  inject: optional(record(string(), union([string(), tuple([string(), string()])]))),
@@ -2082,6 +2083,7 @@ const ChunkFileNamesSchema = union([string(), pipe(function_(), args(tuple([cust
2082
2083
  const AssetFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
2083
2084
  const SanitizeFileNameSchema = union([boolean(), pipe(function_(), args(tuple([string()])), returns(string()))]);
2084
2085
  const GlobalsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
2086
+ const PathsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
2085
2087
  const AdvancedChunksSchema = strictObject({
2086
2088
  includeDependenciesRecursively: optional(boolean()),
2087
2089
  minSize: optional(number()),
@@ -2156,6 +2158,7 @@ const OutputOptionsSchema = strictObject({
2156
2158
  ])), description("Minify the bundled file")),
2157
2159
  name: pipe(optional(string()), description("Name for UMD / IIFE format outputs")),
2158
2160
  globals: pipe(optional(union([record(string(), string()), GlobalsFunctionSchema])), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2161
+ paths: pipe(optional(union([record(string(), string()), PathsFunctionSchema])), description("Maps external module IDs to paths")),
2159
2162
  generatedCode: pipe(optional(partial(GeneratedCodeOptionsSchema)), description("Generated code options")),
2160
2163
  externalLiveBindings: pipe(optional(boolean()), description("external live bindings")),
2161
2164
  inlineDynamicImports: pipe(optional(boolean()), description("Inline dynamic imports")),
@@ -2208,6 +2211,7 @@ const OutputCliOptionsSchema = omit(strictObject({
2208
2211
  const CliOptionsSchema = strictObject({
2209
2212
  config: pipe(optional(union([string(), boolean()])), description("Path to the config file (default: `rolldown.config.js`)")),
2210
2213
  help: pipe(optional(boolean()), description("Show help")),
2214
+ environment: pipe(optional(union([string(), array(string())])), description("Pass additional settings to the config file via process.ENV.")),
2211
2215
  version: pipe(optional(boolean()), description("Show version number")),
2212
2216
  watch: pipe(optional(boolean()), description("Watch files in bundle and rebuild on changes")),
2213
2217
  ...InputCliOptionsSchema.entries,
@@ -2275,12 +2279,23 @@ function bindingifySourcemap$1(map) {
2275
2279
 
2276
2280
  //#endregion
2277
2281
  //#region src/utils/error.ts
2278
- function normalizeErrors(rawErrors) {
2279
- const errors = rawErrors.map((e$2) => e$2 instanceof Error ? e$2 : Object.assign(/* @__PURE__ */ new Error(), {
2280
- kind: e$2.kind,
2281
- message: e$2.message,
2282
+ function unwrapBindingResult(container) {
2283
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
2284
+ return container;
2285
+ }
2286
+ function normalizeBindingResult(container) {
2287
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
2288
+ return container;
2289
+ }
2290
+ function normalizeBindingError(e$2) {
2291
+ return e$2.type === "JsError" ? e$2.field0 : Object.assign(/* @__PURE__ */ new Error(), {
2292
+ kind: e$2.field0.kind,
2293
+ message: e$2.field0.message,
2282
2294
  stack: void 0
2283
- }));
2295
+ });
2296
+ }
2297
+ function aggregateBindingErrorsIntoJsError(rawErrors) {
2298
+ const errors = rawErrors.map(normalizeBindingError);
2284
2299
  let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
2285
2300
  for (let i$1 = 0; i$1 < errors.length; i$1++) {
2286
2301
  summary += "\n";
@@ -2596,7 +2611,7 @@ var PluginContextImpl = class extends MinimalPluginContextImpl {
2596
2611
  this.data.updateModuleOption(id$1, rawOptions);
2597
2612
  let loadPromise = this.data.loadModulePromiseMap.get(id$1);
2598
2613
  if (!loadPromise) {
2599
- loadPromise = this.context.load(id$1, options.moduleSideEffects ?? void 0).catch(() => {
2614
+ loadPromise = this.context.load(id$1, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
2600
2615
  this.data.loadModulePromiseMap.delete(id$1);
2601
2616
  });
2602
2617
  this.data.loadModulePromiseMap.set(id$1, loadPromise);
@@ -2698,6 +2713,9 @@ var TransformPluginContextImpl = class extends PluginContextImpl {
2698
2713
  addWatchFile(id$1) {
2699
2714
  this.inner.addWatchFile(id$1);
2700
2715
  }
2716
+ sendMagicString(s$1) {
2717
+ this.inner.sendMagicString(s$1);
2718
+ }
2701
2719
  };
2702
2720
 
2703
2721
  //#endregion
@@ -2719,7 +2737,7 @@ function bindingifyBuildEnd(args$1) {
2719
2737
  const { handler, meta } = normalizeHook(hook);
2720
2738
  return {
2721
2739
  plugin: async (ctx, err) => {
2722
- 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);
2740
+ 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);
2723
2741
  },
2724
2742
  meta: bindingifyPluginHookMeta(meta)
2725
2743
  };
@@ -2777,7 +2795,8 @@ function bindingifyResolveDynamicImport(args$1) {
2777
2795
  if (typeof ret === "string") return { id: ret };
2778
2796
  const result = {
2779
2797
  id: ret.id,
2780
- external: ret.external
2798
+ external: ret.external,
2799
+ packageJsonPath: ret.packageJsonPath
2781
2800
  };
2782
2801
  if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
2783
2802
  args$1.pluginContextData.updateModuleOption(ret.id, {
@@ -2796,7 +2815,29 @@ function bindingifyTransform(args$1) {
2796
2815
  const { handler, meta, options } = normalizeHook(hook);
2797
2816
  return {
2798
2817
  plugin: async (ctx, code$1, id$1, meta$1) => {
2799
- 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);
2818
+ Object.defineProperties(meta$1, {
2819
+ magicString: { get() {
2820
+ return new BindingMagicString(code$1);
2821
+ } },
2822
+ ast: { get() {
2823
+ let lang = "js";
2824
+ switch (meta$1.moduleType) {
2825
+ case "js":
2826
+ case "jsx":
2827
+ case "ts":
2828
+ case "tsx":
2829
+ lang = meta$1.moduleType;
2830
+ break;
2831
+ default: break;
2832
+ }
2833
+ return parseAst(code$1, {
2834
+ astType: meta$1.moduleType.includes("ts") ? "ts" : "js",
2835
+ lang
2836
+ });
2837
+ } }
2838
+ });
2839
+ 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);
2840
+ const ret = await handler.call(transformCtx, code$1, id$1, meta$1);
2800
2841
  if (ret == null) return;
2801
2842
  if (typeof ret === "string") return { code: ret };
2802
2843
  let moduleOption = args$1.pluginContextData.updateModuleOption(id$1, {
@@ -2804,9 +2845,18 @@ function bindingifyTransform(args$1) {
2804
2845
  moduleSideEffects: ret.moduleSideEffects ?? null,
2805
2846
  invalidate: false
2806
2847
  });
2848
+ let normalizedCode = void 0;
2849
+ let map = ret.map;
2850
+ if (typeof ret.code === "string") normalizedCode = ret.code;
2851
+ else if (ret.code instanceof BindingMagicString) {
2852
+ let magicString = ret.code;
2853
+ normalizedCode = magicString.toString();
2854
+ let fallbackSourcemap = ctx.sendMagicString(magicString);
2855
+ if (fallbackSourcemap != void 0) map = fallbackSourcemap;
2856
+ }
2807
2857
  return {
2808
- code: ret.code,
2809
- map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id$1, code$1, ret.map)),
2858
+ code: normalizedCode,
2859
+ map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id$1, code$1, map)),
2810
2860
  moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
2811
2861
  moduleType: ret.moduleType
2812
2862
  };
@@ -3019,14 +3069,9 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
3019
3069
  });
3020
3070
  }
3021
3071
  function transformToRollupOutput(output, changed) {
3022
- handleOutputErrors(output);
3023
3072
  const { chunks, assets } = output;
3024
3073
  return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
3025
3074
  }
3026
- function handleOutputErrors(output) {
3027
- const rawErrors = output.errors;
3028
- if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
3029
- }
3030
3075
  function transformToOutputBundle(context, output, changed) {
3031
3076
  const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
3032
3077
  return new Proxy(bundle, {
@@ -3132,7 +3177,7 @@ function bindingifyRenderError(args$1) {
3132
3177
  const { handler, meta } = normalizeHook(hook);
3133
3178
  return {
3134
3179
  plugin: async (ctx, err) => {
3135
- 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));
3180
+ 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));
3136
3181
  },
3137
3182
  meta: bindingifyPluginHookMeta(meta)
3138
3183
  };
@@ -3148,7 +3193,7 @@ function bindingifyGenerateBundle(args$1) {
3148
3193
  deleted: /* @__PURE__ */ new Set()
3149
3194
  };
3150
3195
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3151
- const output = transformToOutputBundle(context, bundle, changed);
3196
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
3152
3197
  await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output, isWrite);
3153
3198
  return collectChangedBundle(changed, output);
3154
3199
  },
@@ -3166,7 +3211,7 @@ function bindingifyWriteBundle(args$1) {
3166
3211
  deleted: /* @__PURE__ */ new Set()
3167
3212
  };
3168
3213
  const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3169
- const output = transformToOutputBundle(context, bundle, changed);
3214
+ const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
3170
3215
  await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output);
3171
3216
  return collectChangedBundle(changed, output);
3172
3217
  },
@@ -3353,7 +3398,7 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
3353
3398
  const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args$1);
3354
3399
  const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args$1);
3355
3400
  let hookUsage = extractHookUsage(plugin).inner();
3356
- const result = {
3401
+ return wrapHandlers({
3357
3402
  name: plugin.name,
3358
3403
  buildStart,
3359
3404
  buildStartMeta,
@@ -3400,8 +3445,7 @@ function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, nor
3400
3445
  closeWatcher,
3401
3446
  closeWatcherMeta,
3402
3447
  hookUsage
3403
- };
3404
- return wrapHandlers(result);
3448
+ });
3405
3449
  }
3406
3450
  function wrapHandlers(plugin) {
3407
3451
  for (const hookName of [
@@ -3540,6 +3584,9 @@ var NormalizedOutputOptionsImpl = class {
3540
3584
  get globals() {
3541
3585
  return this.inner.globals || this.outputOptions.globals;
3542
3586
  }
3587
+ get paths() {
3588
+ return this.outputOptions.paths;
3589
+ }
3543
3590
  get hashCharacters() {
3544
3591
  return this.inner.hashCharacters;
3545
3592
  }
@@ -3794,7 +3841,8 @@ function bindingifyExperimental(experimental) {
3794
3841
  chunkModulesOrder,
3795
3842
  chunkImportMap: experimental?.chunkImportMap,
3796
3843
  onDemandWrapping: experimental?.onDemandWrapping,
3797
- incrementalBuild: experimental?.incrementalBuild
3844
+ incrementalBuild: experimental?.incrementalBuild,
3845
+ nativeMagicString: experimental?.nativeMagicString
3798
3846
  };
3799
3847
  }
3800
3848
  function bindingifyResolve(resolve) {
@@ -3983,7 +4031,7 @@ var ChunkingContextImpl = class {
3983
4031
  //#endregion
3984
4032
  //#region src/utils/bindingify-output-options.ts
3985
4033
  function bindingifyOutputOptions(outputOptions) {
3986
- const { dir, format, 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;
4034
+ const { dir, format, 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;
3987
4035
  const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
3988
4036
  return {
3989
4037
  dir,
@@ -4002,6 +4050,7 @@ function bindingifyOutputOptions(outputOptions) {
4002
4050
  outro: bindingifyAddon(outro),
4003
4051
  extend: outputOptions.extend,
4004
4052
  globals,
4053
+ paths,
4005
4054
  generatedCode,
4006
4055
  esModule,
4007
4056
  name,
@@ -4160,12 +4209,10 @@ async function createBundlerOptions(inputOptions, outputOptions, watchMode) {
4160
4209
  let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
4161
4210
  const parallelPluginInitResult = await initializeParallelPlugins(plugins);
4162
4211
  try {
4163
- const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
4164
- const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
4165
4212
  return {
4166
4213
  bundlerOptions: {
4167
- inputOptions: bindingInputOptions,
4168
- outputOptions: bindingOutputOptions,
4214
+ inputOptions: bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode),
4215
+ outputOptions: bindingifyOutputOptions(outputOptions),
4169
4216
  parallelPluginsRegistry: parallelPluginInitResult?.registry
4170
4217
  },
4171
4218
  inputOptions,
@@ -4213,20 +4260,17 @@ var RolldownBuild = class RolldownBuild {
4213
4260
  }
4214
4261
  async scan() {
4215
4262
  const { impl } = await this.#getBundlerWithStopWorker({});
4216
- const output = await impl.scan();
4217
- return handleOutputErrors(output);
4263
+ unwrapBindingResult(await impl.scan());
4218
4264
  }
4219
4265
  async generate(outputOptions = {}) {
4220
4266
  validateOption("output", outputOptions);
4221
4267
  const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
4222
- const output = await impl.generate();
4223
- return transformToRollupOutput(output);
4268
+ return transformToRollupOutput(unwrapBindingResult(await impl.generate()));
4224
4269
  }
4225
4270
  async write(outputOptions = {}) {
4226
4271
  validateOption("output", outputOptions);
4227
4272
  const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
4228
- const output = await impl.write();
4229
- return transformToRollupOutput(output);
4273
+ return transformToRollupOutput(unwrapBindingResult(await impl.write()));
4230
4274
  }
4231
4275
  async close() {
4232
4276
  if (this.#bundlerImpl) {
@@ -4248,8 +4292,7 @@ var RolldownBuild = class RolldownBuild {
4248
4292
  //#region src/api/rolldown/index.ts
4249
4293
  const rolldown = async (input) => {
4250
4294
  validateOption("input", input);
4251
- const inputOptions = await PluginDriver.callOptionsHook(input);
4252
- return new RolldownBuild(inputOptions);
4295
+ return new RolldownBuild(await PluginDriver.callOptionsHook(input));
4253
4296
  };
4254
4297
 
4255
4298
  //#endregion
@@ -4317,7 +4360,7 @@ var WatcherEmitter = class {
4317
4360
  const data = event.bundleErrorData();
4318
4361
  await listener({
4319
4362
  code: "ERROR",
4320
- error: normalizeErrors(data.error),
4363
+ error: aggregateBindingErrorsIntoJsError(data.error),
4321
4364
  result: data.result
4322
4365
  });
4323
4366
  break;
@@ -4373,12 +4416,10 @@ var Watcher = class {
4373
4416
  async function createWatcher(emitter, input) {
4374
4417
  const options = arraify(input);
4375
4418
  const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
4376
- const inputOptions = await PluginDriver.callOptionsHook(option, true);
4377
- return createBundlerOptions(inputOptions, output, true);
4419
+ return createBundlerOptions(await PluginDriver.callOptionsHook(option, true), output, true);
4378
4420
  })).flat());
4379
4421
  const notifyOptions = getValidNotifyOption(bundlerOptions);
4380
- const bindingWatcher = new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
4381
- new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers)).start();
4422
+ new Watcher(emitter, new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions), bundlerOptions.map((option) => option.stopWorkers)).start();
4382
4423
  }
4383
4424
  function getValidNotifyOption(bundlerOptions) {
4384
4425
  let result;
@@ -4410,4 +4451,4 @@ function defineConfig(config) {
4410
4451
  const VERSION = version;
4411
4452
 
4412
4453
  //#endregion
4413
- export { BuiltinPlugin, PluginContextData, PluginDriver, RolldownBuild, VERSION, ansis_default, bindingifyPlugin, build, createBundlerOptions, defineConfig, description$1 as description, getCliSchemaInfo, getInputCliKeys, getOutputCliKeys, makeBuiltinPluginCallable, normalizedStringOrRegex, onExit, rolldown, validateCliOptions, version, watch };
4454
+ export { BindingMagicString$1 as BindingMagicString, BuiltinPlugin, PluginContextData, PluginDriver, RolldownBuild, VERSION, ansis_default, bindingifyPlugin, build, createBundlerOptions, defineConfig, description$1 as description, getCliSchemaInfo, getInputCliKeys, getOutputCliKeys, makeBuiltinPluginCallable, normalizeBindingResult, normalizedStringOrRegex, onExit, rolldown, validateCliOptions, version, watch };