@rolldown/browser 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.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 (82) hide show
  1. package/dist/cli.mjs +961 -1551
  2. package/dist/config.d.mts +9 -6
  3. package/dist/config.mjs +9 -11
  4. package/dist/constructors-DsfxKD6A.js +68 -0
  5. package/dist/error-BeZaDkS8.js +157 -0
  6. package/dist/experimental-index.browser.mjs +278 -44
  7. package/dist/experimental-index.d.mts +228 -68
  8. package/dist/experimental-index.mjs +274 -55
  9. package/dist/experimental-runtime-types.d.ts +98 -0
  10. package/dist/filter-index.d.mts +104 -2
  11. package/dist/filter-index.mjs +144 -5
  12. package/dist/get-log-filter.d.mts +3 -0
  13. package/dist/get-log-filter.mjs +68 -0
  14. package/dist/index.browser.mjs +238 -3
  15. package/dist/index.d.mts +4 -3
  16. package/dist/index.mjs +53 -6
  17. package/dist/{shared/parse-ast-index-BHaE0ECV.cjs → normalize-string-or-regex-TtAGUp42.js} +74 -147
  18. package/dist/parallel-plugin-worker.mjs +27 -35
  19. package/dist/parallel-plugin.d.mts +7 -7
  20. package/dist/parallel-plugin.mjs +1 -2
  21. package/dist/parse-ast-index.d.mts +28 -5
  22. package/dist/parse-ast-index.mjs +60 -4
  23. package/dist/plugins-index.browser.mjs +40 -0
  24. package/dist/plugins-index.d.mts +33 -0
  25. package/dist/plugins-index.mjs +40 -0
  26. package/dist/resolve-tsconfig-DThkUPSZ.js +112 -0
  27. package/dist/rolldown-binding.wasi-browser.js +46 -24
  28. package/dist/rolldown-binding.wasi.cjs +67 -24
  29. package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
  30. package/dist/rolldown-build-Chx5S-TB.js +5349 -0
  31. package/dist/shared/bindingify-input-options-Czbczr8Z.mjs +2168 -0
  32. package/dist/shared/composable-filters-B2ByPP8y.mjs +224 -0
  33. package/dist/shared/constructors-BVnf_fH1.d.mts +37 -0
  34. package/dist/shared/constructors-CemeNi29.mjs +68 -0
  35. package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
  36. package/dist/shared/define-config-i6TWE2hm.d.mts +3855 -0
  37. package/dist/shared/error-CQ6njWsV.mjs +86 -0
  38. package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
  39. package/dist/shared/{load-config-D7UduHRZ.mjs → load-config-CxvL5JxT.mjs} +32 -36
  40. package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
  41. package/dist/shared/{parse-ast-index-vu376yZ1.mjs → logs-D80CXhvg.mjs} +25 -123
  42. package/dist/shared/normalize-string-or-regex-CF3Uz6aU.mjs +57 -0
  43. package/dist/shared/parse-CRhjbrcT.mjs +73 -0
  44. package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-BYQIwEjg.mjs} +301 -310
  45. package/dist/shared/resolve-tsconfig-Cwoo4h_o.mjs +112 -0
  46. package/dist/shared/rolldown-C3wFxOwq.mjs +40 -0
  47. package/dist/shared/rolldown-build-ChZOz6BP.mjs +3318 -0
  48. package/dist/shared/transform-DEgNAQOQ.d.mts +149 -0
  49. package/dist/shared/types-Cx3HYorz.d.mts +1302 -0
  50. package/dist/shared/utils-6wxe_LMG.d.mts +22 -0
  51. package/dist/shared/watch-C1jC1oFT.mjs +373 -0
  52. package/dist/utils-index.browser.mjs +2414 -0
  53. package/dist/utils-index.d.mts +374 -0
  54. package/dist/utils-index.mjs +2415 -0
  55. package/package.json +33 -38
  56. package/dist/cli.cjs +0 -1748
  57. package/dist/cli.d.cts +0 -1
  58. package/dist/config.cjs +0 -12
  59. package/dist/config.d.cts +0 -11
  60. package/dist/experimental-index.cjs +0 -129
  61. package/dist/experimental-index.d.cts +0 -96
  62. package/dist/filter-index.cjs +0 -53
  63. package/dist/filter-index.d.cts +0 -3
  64. package/dist/index.cjs +0 -9
  65. package/dist/index.d.cts +0 -3
  66. package/dist/parallel-plugin-worker.cjs +0 -33
  67. package/dist/parallel-plugin-worker.d.cts +0 -1
  68. package/dist/parallel-plugin.cjs +0 -8
  69. package/dist/parallel-plugin.d.cts +0 -14
  70. package/dist/parse-ast-index.cjs +0 -4
  71. package/dist/parse-ast-index.d.cts +0 -9
  72. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  73. package/dist/shared/chunk-DSsiIF1Z.mjs +0 -30
  74. package/dist/shared/define-config.d-D4lKXE9V.d.cts +0 -1165
  75. package/dist/shared/define-config.d-Dm9iNdt9.d.mts +0 -1165
  76. package/dist/shared/dist-BMVjvV-v.cjs +0 -249
  77. package/dist/shared/dist-CAn6dxW6.mjs +0 -153
  78. package/dist/shared/load-config-CtKjQ8Mn.cjs +0 -125
  79. package/dist/shared/prompt-GFYxfPw7.mjs +0 -854
  80. package/dist/shared/src-D0nc44MQ.mjs +0 -4691
  81. package/dist/shared/src-s89s870G.cjs +0 -4647
  82. package/dist/src-CeWghjQt.js +0 -4329
@@ -0,0 +1,86 @@
1
+ import "../rolldown-binding.wasi.cjs";
2
+ //#region src/types/sourcemap.ts
3
+ function bindingifySourcemap(map) {
4
+ if (map == null) return;
5
+ return { inner: typeof map === "string" ? map : {
6
+ file: map.file ?? void 0,
7
+ mappings: map.mappings,
8
+ sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
9
+ sources: map.sources?.map((s) => s ?? void 0),
10
+ sourcesContent: map.sourcesContent?.map((s) => s ?? void 0),
11
+ names: map.names,
12
+ x_google_ignoreList: map.x_google_ignoreList,
13
+ debugId: "debugId" in map ? map.debugId : void 0
14
+ } };
15
+ }
16
+ //#endregion
17
+ //#region src/utils/error.ts
18
+ function unwrapBindingResult(container) {
19
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
20
+ return container;
21
+ }
22
+ function normalizeBindingResult(container) {
23
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
24
+ return container;
25
+ }
26
+ function normalizeBindingError(e) {
27
+ return e.type === "JsError" ? e.field0 : Object.assign(/* @__PURE__ */ new Error(), {
28
+ code: e.field0.kind,
29
+ kind: e.field0.kind,
30
+ message: e.field0.message,
31
+ id: e.field0.id,
32
+ exporter: e.field0.exporter,
33
+ loc: e.field0.loc,
34
+ pos: e.field0.pos,
35
+ stack: void 0
36
+ });
37
+ }
38
+ function aggregateBindingErrorsIntoJsError(rawErrors) {
39
+ const errors = rawErrors.map(normalizeBindingError);
40
+ let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
41
+ for (let i = 0; i < errors.length; i++) {
42
+ summary += "\n";
43
+ if (i >= 5) {
44
+ summary += "...";
45
+ break;
46
+ }
47
+ summary += getErrorMessage(errors[i]);
48
+ }
49
+ const wrapper = new Error(summary);
50
+ Object.defineProperty(wrapper, "errors", {
51
+ configurable: true,
52
+ enumerable: true,
53
+ get: () => errors,
54
+ set: (value) => Object.defineProperty(wrapper, "errors", {
55
+ configurable: true,
56
+ enumerable: true,
57
+ value
58
+ })
59
+ });
60
+ return wrapper;
61
+ }
62
+ function getErrorMessage(e) {
63
+ if (Object.hasOwn(e, "kind")) return e.message;
64
+ let s = "";
65
+ if (e.plugin) s += `[plugin ${e.plugin}]`;
66
+ const id = e.id ?? e.loc?.file;
67
+ if (id) {
68
+ s += " " + id;
69
+ if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
70
+ }
71
+ if (s) s += "\n";
72
+ const message = `${e.name ?? "Error"}: ${e.message}`;
73
+ s += message;
74
+ if (e.frame) s = joinNewLine(s, e.frame);
75
+ if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
76
+ if (e.cause) {
77
+ s = joinNewLine(s, "Caused by:");
78
+ s = joinNewLine(s, getErrorMessage(e.cause).split("\n").map((line) => " " + line).join("\n"));
79
+ }
80
+ return s;
81
+ }
82
+ function joinNewLine(s1, s2) {
83
+ return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
84
+ }
85
+ //#endregion
86
+ export { bindingifySourcemap as a, unwrapBindingResult as i, normalizeBindingError as n, normalizeBindingResult as r, aggregateBindingErrorsIntoJsError as t };
@@ -0,0 +1,35 @@
1
+ import { a as RolldownLog } from "./logging-C6h4g8dA.mjs";
2
+
3
+ //#region src/get-log-filter.d.ts
4
+ /**
5
+ * @param filters A list of log filters to apply
6
+ * @returns A function that tests whether a log should be output
7
+ *
8
+ * @category Config
9
+ */
10
+ type GetLogFilter = (filters: string[]) => (log: RolldownLog) => boolean;
11
+ /**
12
+ * A helper function to generate log filters using the same syntax as the CLI.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { defineConfig } from 'rolldown';
17
+ * import { getLogFilter } from 'rolldown/getLogFilter';
18
+ *
19
+ * const logFilter = getLogFilter(['code:FOO', 'code:BAR']);
20
+ *
21
+ * export default defineConfig({
22
+ * input: 'main.js',
23
+ * onLog(level, log, handler) {
24
+ * if (logFilter(log)) {
25
+ * handler(level, log);
26
+ * }
27
+ * }
28
+ * });
29
+ * ```
30
+ *
31
+ * @category Config
32
+ */
33
+ declare const getLogFilter: GetLogFilter;
34
+ //#endregion
35
+ export { getLogFilter as n, GetLogFilter as t };
@@ -1,11 +1,9 @@
1
- import { __esm } from "./chunk-DSsiIF1Z.mjs";
2
- import { init_rolldown, rolldown } from "./src-D0nc44MQ.mjs";
1
+ import { t as rolldown } from "./rolldown-C3wFxOwq.mjs";
3
2
  import path from "node:path";
4
- import { pathToFileURL } from "node:url";
3
+ import { readdir } from "node:fs/promises";
5
4
  import { cwd } from "node:process";
5
+ import { pathToFileURL } from "node:url";
6
6
  import fs from "node:fs";
7
- import { readdir } from "node:fs/promises";
8
-
9
7
  //#region src/utils/load-config.ts
10
8
  async function bundleTsConfig(configFile, isEsm) {
11
9
  const dirnameVarName = "injected_original_dirname";
@@ -15,13 +13,13 @@ async function bundleTsConfig(configFile, isEsm) {
15
13
  input: configFile,
16
14
  platform: "node",
17
15
  resolve: { mainFields: ["main"] },
18
- define: {
16
+ transform: { define: {
19
17
  __dirname: dirnameVarName,
20
18
  __filename: filenameVarName,
21
19
  "import.meta.url": importMetaUrlVarName,
22
20
  "import.meta.dirname": dirnameVarName,
23
21
  "import.meta.filename": filenameVarName
24
- },
22
+ } },
25
23
  treeshake: false,
26
24
  external: [/^[\w@][^:]/],
27
25
  plugins: [{
@@ -29,9 +27,8 @@ async function bundleTsConfig(configFile, isEsm) {
29
27
  transform: {
30
28
  filter: { id: /\.[cm]?[jt]s$/ },
31
29
  async handler(code, id) {
32
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
33
30
  return {
34
- code: injectValues + code,
31
+ code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
35
32
  map: null
36
33
  };
37
34
  }
@@ -39,15 +36,26 @@ async function bundleTsConfig(configFile, isEsm) {
39
36
  }]
40
37
  });
41
38
  const outputDir = path.dirname(configFile);
42
- const result = await bundle.write({
39
+ const fileName = (await bundle.write({
43
40
  dir: outputDir,
44
41
  format: isEsm ? "esm" : "cjs",
45
42
  sourcemap: "inline",
46
43
  entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
47
- });
48
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
44
+ })).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
49
45
  return path.join(outputDir, fileName);
50
46
  }
47
+ const SUPPORTED_JS_CONFIG_FORMATS = [
48
+ ".js",
49
+ ".mjs",
50
+ ".cjs"
51
+ ];
52
+ const SUPPORTED_TS_CONFIG_FORMATS = [
53
+ ".ts",
54
+ ".mts",
55
+ ".cts"
56
+ ];
57
+ const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
58
+ const DEFAULT_CONFIG_BASE = "rolldown.config";
51
59
  async function findConfigFileNameInCwd() {
52
60
  const filesInWorkingDirectory = new Set(await readdir(cwd()));
53
61
  for (const extension of SUPPORTED_CONFIG_FORMATS) {
@@ -57,8 +65,7 @@ async function findConfigFileNameInCwd() {
57
65
  throw new Error("No `rolldown.config` configuration file found.");
58
66
  }
59
67
  async function loadTsConfig(configFile) {
60
- const isEsm = isFilePathESM(configFile);
61
- const file = await bundleTsConfig(configFile, isEsm);
68
+ const file = await bundleTsConfig(configFile, isFilePathESM(configFile));
62
69
  try {
63
70
  return (await import(pathToFileURL(file).href)).default;
64
71
  } finally {
@@ -91,34 +98,23 @@ function tryStatSync(file) {
91
98
  return fs.statSync(file, { throwIfNoEntry: false });
92
99
  } catch {}
93
100
  }
101
+ /**
102
+ * Load config from a file in a way that Rolldown does.
103
+ *
104
+ * @param configPath The path to the config file. If empty, it will look for `rolldown.config` with supported extensions in the current working directory.
105
+ * @returns The loaded config export
106
+ *
107
+ * @category Config
108
+ */
94
109
  async function loadConfig(configPath) {
95
110
  const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
96
111
  try {
97
112
  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;
98
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
99
- const rawConfigPath = path.resolve(configPath);
100
- return await loadTsConfig(rawConfigPath);
101
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
113
+ else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(path.resolve(configPath));
114
+ else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
102
115
  } catch (err) {
103
116
  throw new Error("Error happened while loading config.", { cause: err });
104
117
  }
105
118
  }
106
- var SUPPORTED_JS_CONFIG_FORMATS, SUPPORTED_TS_CONFIG_FORMATS, SUPPORTED_CONFIG_FORMATS, DEFAULT_CONFIG_BASE;
107
- var init_load_config = __esm({ "src/utils/load-config.ts"() {
108
- init_rolldown();
109
- SUPPORTED_JS_CONFIG_FORMATS = [
110
- ".js",
111
- ".mjs",
112
- ".cjs"
113
- ];
114
- SUPPORTED_TS_CONFIG_FORMATS = [
115
- ".ts",
116
- ".mts",
117
- ".cts"
118
- ];
119
- SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
120
- DEFAULT_CONFIG_BASE = "rolldown.config";
121
- } });
122
-
123
119
  //#endregion
124
- export { init_load_config, loadConfig };
120
+ export { loadConfig as t };
@@ -0,0 +1,50 @@
1
+ //#region src/log/logging.d.ts
2
+ /** @inline */
3
+ type LogLevel = "info" | "debug" | "warn";
4
+ /** @inline */
5
+ type LogLevelOption = LogLevel | "silent";
6
+ /** @inline */
7
+ type LogLevelWithError = LogLevel | "error";
8
+ interface RolldownLog {
9
+ binding?: string;
10
+ cause?: unknown;
11
+ /**
12
+ * The log code for this log object.
13
+ * @example 'PLUGIN_ERROR'
14
+ */
15
+ code?: string;
16
+ exporter?: string;
17
+ frame?: string;
18
+ hook?: string;
19
+ id?: string;
20
+ ids?: string[];
21
+ loc?: {
22
+ column: number;
23
+ file?: string;
24
+ line: number;
25
+ };
26
+ /**
27
+ * The message for this log object.
28
+ * @example 'The "transform" hook used by the output plugin "rolldown-plugin-foo" is a build time hook and will not be run for that plugin. Either this plugin cannot be used as an output plugin, or it should have an option to configure it as an output plugin.'
29
+ */
30
+ message: string;
31
+ meta?: any;
32
+ names?: string[];
33
+ plugin?: string;
34
+ pluginCode?: unknown;
35
+ pos?: number;
36
+ reexporter?: string;
37
+ stack?: string;
38
+ url?: string;
39
+ }
40
+ /** @inline */
41
+ type RolldownLogWithString = RolldownLog | string;
42
+ /** @category Plugin APIs */
43
+ interface RolldownError extends RolldownLog {
44
+ name?: string;
45
+ stack?: string;
46
+ watchFiles?: string[];
47
+ }
48
+ type LogOrStringHandler = (level: LogLevelWithError, log: RolldownLogWithString) => void;
49
+ //#endregion
50
+ export { RolldownLog as a, RolldownError as i, LogLevelOption as n, RolldownLogWithString as o, LogOrStringHandler as r, LogLevel as t };
@@ -1,6 +1,3 @@
1
- import { __esm } from "./chunk-DSsiIF1Z.mjs";
2
- import { parseAsync, parseSync } from "../rolldown-binding.wasi.cjs";
3
-
4
1
  //#region src/utils/code-frame.ts
5
2
  function spaces(index) {
6
3
  let result = "";
@@ -10,10 +7,13 @@ function spaces(index) {
10
7
  function tabsToSpaces(value) {
11
8
  return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
12
9
  }
10
+ const LINE_TRUNCATE_LENGTH = 120;
11
+ const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
12
+ const ELLIPSIS = "...";
13
13
  function getCodeFrame(source, line, column) {
14
14
  let lines = source.split("\n");
15
15
  if (line > lines.length) return "";
16
- const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + ELLIPSIS.length, LINE_TRUNCATE_LENGTH);
16
+ const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + 3, LINE_TRUNCATE_LENGTH);
17
17
  const frameStart = Math.max(0, line - 3);
18
18
  let frameEnd = Math.min(line + 2, lines.length);
19
19
  lines = lines.slice(frameStart, frameEnd);
@@ -27,7 +27,7 @@ function getCodeFrame(source, line, column) {
27
27
  let lineNumber = String(index + frameStart + 1);
28
28
  while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
29
29
  let displayedLine = tabsToSpaces(sourceLine);
30
- if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - ELLIPSIS.length)}${ELLIPSIS}`;
30
+ if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - 3)}${ELLIPSIS}`;
31
31
  if (isErrorLine) {
32
32
  const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
33
33
  return `${lineNumber}: ${displayedLine}\n${indicator}`;
@@ -35,13 +35,6 @@ function getCodeFrame(source, line, column) {
35
35
  return `${lineNumber}: ${displayedLine}`;
36
36
  }).join("\n");
37
37
  }
38
- var LINE_TRUNCATE_LENGTH, MIN_CHARACTERS_SHOWN_AFTER_LOCATION, ELLIPSIS;
39
- var init_code_frame = __esm({ "src/utils/code-frame.ts"() {
40
- LINE_TRUNCATE_LENGTH = 120;
41
- MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
42
- ELLIPSIS = "...";
43
- } });
44
-
45
38
  //#endregion
46
39
  //#region src/log/locate-character/index.js
47
40
  /** @typedef {import('./types').Location} Location */
@@ -59,13 +52,13 @@ function rangeContains(range, index) {
59
52
  function getLocator(source, options = {}) {
60
53
  const { offsetLine = 0, offsetColumn = 0 } = options;
61
54
  let start = 0;
62
- const ranges = source.split("\n").map((line, i$1) => {
55
+ const ranges = source.split("\n").map((line, i) => {
63
56
  const end = start + line.length + 1;
64
57
  /** @type {import('./types').Range} */
65
58
  const range = {
66
59
  start,
67
60
  end,
68
- line: i$1
61
+ line: i
69
62
  };
70
63
  start = end;
71
64
  return range;
@@ -102,14 +95,15 @@ function getLocator(source, options = {}) {
102
95
  function locate(source, search, options) {
103
96
  return getLocator(source, options)(search, options && options.startIndex);
104
97
  }
105
- var init_locate_character = __esm({ "src/log/locate-character/index.js"() {} });
106
-
107
98
  //#endregion
108
99
  //#region src/log/logs.ts
109
- function logParseError(message) {
100
+ const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLE_WATCHER_OPTION = "MULTIPLE_WATCHER_OPTION", PARSE_ERROR = "PARSE_ERROR";
101
+ function logParseError(message, id, pos) {
110
102
  return {
111
103
  code: PARSE_ERROR,
112
- message
104
+ id,
105
+ message,
106
+ pos
113
107
  };
114
108
  }
115
109
  function logInvalidLogPosition(pluginName) {
@@ -130,29 +124,29 @@ function logCycleLoading(pluginName, moduleId) {
130
124
  message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
131
125
  };
132
126
  }
133
- function logMultiplyNotifyOption() {
127
+ function logMultipleWatcherOption() {
134
128
  return {
135
- code: MULTIPLY_NOTIFY_OPTION,
136
- message: `Found multiply notify option at watch options, using first one to start notify watcher.`
129
+ code: MULTIPLE_WATCHER_OPTION,
130
+ message: `Found multiple watcher options at watch options, using first one to start watcher.`
137
131
  };
138
132
  }
139
- function logPluginError(error$1, plugin, { hook, id } = {}) {
133
+ function logPluginError(error, plugin, { hook, id } = {}) {
140
134
  try {
141
- const code = error$1.code;
142
- if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
143
- error$1.code = PLUGIN_ERROR;
144
- error$1.plugin = plugin;
145
- if (hook) error$1.hook = hook;
146
- if (id) error$1.id = id;
135
+ const code = error.code;
136
+ if (!error.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error.pluginCode = code;
137
+ error.code = PLUGIN_ERROR;
138
+ error.plugin = plugin;
139
+ if (hook) error.hook = hook;
140
+ if (id) error.id = id;
147
141
  } catch (_) {} finally {
148
- return error$1;
142
+ return error;
149
143
  }
150
144
  }
151
145
  function error(base) {
152
146
  if (!(base instanceof Error)) {
153
147
  base = Object.assign(new Error(base.message), base);
154
148
  Object.defineProperty(base, "name", {
155
- value: "RollupError",
149
+ value: "RolldownError",
156
150
  writable: true
157
151
  });
158
152
  }
@@ -182,97 +176,5 @@ function augmentCodeLocation(properties, pos, source, id) {
182
176
  properties.frame = getCodeFrame(source, line, column);
183
177
  }
184
178
  }
185
- var INVALID_LOG_POSITION, PLUGIN_ERROR, INPUT_HOOK_IN_OUTPUT_PLUGIN, CYCLE_LOADING, MULTIPLY_NOTIFY_OPTION, PARSE_ERROR;
186
- var init_logs = __esm({ "src/log/logs.ts"() {
187
- init_code_frame();
188
- init_locate_character();
189
- INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", PARSE_ERROR = "PARSE_ERROR";
190
- } });
191
-
192
179
  //#endregion
193
- //#region ../../node_modules/.pnpm/oxc-parser@0.72.0/node_modules/oxc-parser/wrap.mjs
194
- function wrap$1(result) {
195
- let program, module, comments, errors;
196
- return {
197
- get program() {
198
- if (!program) program = jsonParseAst(result.program);
199
- return program;
200
- },
201
- get module() {
202
- if (!module) module = result.module;
203
- return module;
204
- },
205
- get comments() {
206
- if (!comments) comments = result.comments;
207
- return comments;
208
- },
209
- get errors() {
210
- if (!errors) errors = result.errors;
211
- return errors;
212
- }
213
- };
214
- }
215
- function jsonParseAst(programJson) {
216
- const { node: program, fixes } = JSON.parse(programJson);
217
- for (const fixPath of fixes) applyFix(program, fixPath);
218
- return program;
219
- }
220
- function applyFix(program, fixPath) {
221
- let node = program;
222
- for (const key of fixPath) node = node[key];
223
- if (node.bigint) node.value = BigInt(node.bigint);
224
- else try {
225
- node.value = RegExp(node.regex.pattern, node.regex.flags);
226
- } catch (_err) {}
227
- }
228
- var init_wrap = __esm({ "../../node_modules/.pnpm/oxc-parser@0.72.0/node_modules/oxc-parser/wrap.mjs"() {} });
229
-
230
- //#endregion
231
- //#region src/parse-ast-index.ts
232
- function wrap(result, sourceText) {
233
- result = wrap$1(result);
234
- if (result.errors.length > 0) return normalizeParseError(sourceText, result.errors);
235
- return result.program;
236
- }
237
- function normalizeParseError(sourceText, errors) {
238
- let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
239
- for (let i = 0; i < errors.length; i++) {
240
- if (i >= 5) {
241
- message += "\n...";
242
- break;
243
- }
244
- const e = errors[i];
245
- message += e.message + "\n" + e.labels.map((label) => {
246
- const location = locate(sourceText, label.start, { offsetLine: 1 });
247
- if (!location) return;
248
- return getCodeFrame(sourceText, location.line, location.column);
249
- }).filter(Boolean).join("\n");
250
- }
251
- return error(logParseError(message));
252
- }
253
- function parseAst(sourceText, options, filename) {
254
- return wrap(parseSync(filename ?? "file.js", sourceText, {
255
- ...defaultParserOptions,
256
- ...options
257
- }), sourceText);
258
- }
259
- async function parseAstAsync(sourceText, options, filename) {
260
- return wrap(await parseAsync(filename ?? "file.js", sourceText, {
261
- ...defaultParserOptions,
262
- ...options
263
- }), sourceText);
264
- }
265
- var defaultParserOptions;
266
- var init_parse_ast_index = __esm({ "src/parse-ast-index.ts"() {
267
- init_locate_character();
268
- init_logs();
269
- init_code_frame();
270
- init_wrap();
271
- defaultParserOptions = {
272
- lang: "js",
273
- preserveParens: false
274
- };
275
- } });
276
-
277
- //#endregion
278
- export { augmentCodeLocation, error, init_logs, init_parse_ast_index, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst, parseAstAsync };
180
+ export { logInvalidLogPosition as a, logPluginError as c, logInputHookInOutputPlugin as i, locate as l, error as n, logMultipleWatcherOption as o, logCycleLoading as r, logParseError as s, augmentCodeLocation as t, getCodeFrame as u };
@@ -0,0 +1,57 @@
1
+ import { c as logPluginError, n as error } from "./logs-D80CXhvg.mjs";
2
+ import { BindingCallableBuiltinPlugin } from "../rolldown-binding.wasi.cjs";
3
+ //#region src/builtin-plugin/utils.ts
4
+ var BuiltinPlugin = class {
5
+ /** Vite-specific option to control plugin ordering */
6
+ enforce;
7
+ constructor(name, _options) {
8
+ this.name = name;
9
+ this._options = _options;
10
+ }
11
+ };
12
+ function makeBuiltinPluginCallable(plugin) {
13
+ let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
14
+ const wrappedPlugin = plugin;
15
+ for (const key in callablePlugin) wrappedPlugin[key] = async function(...args) {
16
+ try {
17
+ return await callablePlugin[key](...args);
18
+ } catch (e) {
19
+ if (e instanceof Error && !e.stack?.includes("at ")) Error.captureStackTrace(e, wrappedPlugin[key]);
20
+ return error(logPluginError(e, plugin.name, {
21
+ hook: key,
22
+ id: key === "transform" ? args[2] : void 0
23
+ }));
24
+ }
25
+ };
26
+ return wrappedPlugin;
27
+ }
28
+ function bindingifyBuiltInPlugin(plugin) {
29
+ return {
30
+ __name: plugin.name,
31
+ options: plugin._options
32
+ };
33
+ }
34
+ function bindingifyManifestPlugin(plugin, pluginContextData) {
35
+ const { isOutputOptionsForLegacyChunks, ...options } = plugin._options;
36
+ return {
37
+ __name: plugin.name,
38
+ options: {
39
+ ...options,
40
+ isLegacy: isOutputOptionsForLegacyChunks ? (opts) => {
41
+ return isOutputOptionsForLegacyChunks(pluginContextData.getOutputOptions(opts));
42
+ } : void 0
43
+ }
44
+ };
45
+ }
46
+ //#endregion
47
+ //#region src/utils/normalize-string-or-regex.ts
48
+ function normalizedStringOrRegex(pattern) {
49
+ if (!pattern) return;
50
+ if (!isReadonlyArray(pattern)) return [pattern];
51
+ return pattern;
52
+ }
53
+ function isReadonlyArray(input) {
54
+ return Array.isArray(input);
55
+ }
56
+ //#endregion
57
+ export { makeBuiltinPluginCallable as a, bindingifyManifestPlugin as i, BuiltinPlugin as n, bindingifyBuiltInPlugin as r, normalizedStringOrRegex as t };
@@ -0,0 +1,73 @@
1
+ import { parse, parseSync } from "../rolldown-binding.wasi.cjs";
2
+ //#region ../../node_modules/.pnpm/oxc-parser@0.120.0/node_modules/oxc-parser/src-js/wrap.js
3
+ function wrap(result) {
4
+ let program, module, comments, errors;
5
+ return {
6
+ get program() {
7
+ if (!program) program = jsonParseAst(result.program);
8
+ return program;
9
+ },
10
+ get module() {
11
+ if (!module) module = result.module;
12
+ return module;
13
+ },
14
+ get comments() {
15
+ if (!comments) comments = result.comments;
16
+ return comments;
17
+ },
18
+ get errors() {
19
+ if (!errors) errors = result.errors;
20
+ return errors;
21
+ }
22
+ };
23
+ }
24
+ function jsonParseAst(programJson) {
25
+ const { node: program, fixes } = JSON.parse(programJson);
26
+ for (const fixPath of fixes) applyFix(program, fixPath);
27
+ return program;
28
+ }
29
+ function applyFix(program, fixPath) {
30
+ let node = program;
31
+ for (const key of fixPath) node = node[key];
32
+ if (node.bigint) node.value = BigInt(node.bigint);
33
+ else try {
34
+ node.value = RegExp(node.regex.pattern, node.regex.flags);
35
+ } catch {}
36
+ }
37
+ //#endregion
38
+ //#region src/utils/parse.ts
39
+ /**
40
+ * Parse JS/TS source asynchronously on a separate thread.
41
+ *
42
+ * Note that not all of the workload can happen on a separate thread.
43
+ * Parsing on Rust side does happen in a separate thread, but deserialization of the AST to JS objects
44
+ * has to happen on current thread. This synchronous deserialization work typically outweighs
45
+ * the asynchronous parsing by a factor of between 3 and 20.
46
+ *
47
+ * i.e. the majority of the workload cannot be parallelized by using this method.
48
+ *
49
+ * Generally {@linkcode parseSync} is preferable to use as it does not have the overhead of spawning a thread.
50
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads.
51
+ *
52
+ * @category Utilities
53
+ */
54
+ async function parse$1(filename, sourceText, options) {
55
+ return wrap(await parse(filename, sourceText, options));
56
+ }
57
+ /**
58
+ * Parse JS/TS source synchronously on current thread.
59
+ *
60
+ * This is generally preferable over {@linkcode parse} (async) as it does not have the overhead
61
+ * of spawning a thread, and the majority of the workload cannot be parallelized anyway
62
+ * (see {@linkcode parse} documentation for details).
63
+ *
64
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads
65
+ * with {@linkcode parseSync} rather than using {@linkcode parse}.
66
+ *
67
+ * @category Utilities
68
+ */
69
+ function parseSync$1(filename, sourceText, options) {
70
+ return wrap(parseSync(filename, sourceText, options));
71
+ }
72
+ //#endregion
73
+ export { parseSync$1 as n, parse$1 as t };