@rolldown/browser 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/cli-setup.mjs +16 -0
  2. package/dist/cli.mjs +1084 -1281
  3. package/dist/config.d.mts +1 -3
  4. package/dist/config.mjs +7 -5
  5. package/dist/constructors-B8gqcrFr.js +61 -0
  6. package/dist/experimental-index.browser.mjs +225 -50
  7. package/dist/experimental-index.d.mts +164 -76
  8. package/dist/experimental-index.mjs +220 -60
  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 +123 -3
  12. package/dist/get-log-filter.d.mts +7 -0
  13. package/dist/get-log-filter.mjs +48 -0
  14. package/dist/index.browser.mjs +242 -2
  15. package/dist/index.d.mts +4 -3
  16. package/dist/index.mjs +54 -5
  17. package/dist/{shared/parse-ast-index-BHaE0ECV.cjs → normalize-string-or-regex-CL-PJZI7.js} +70 -137
  18. package/dist/parallel-plugin-worker.mjs +26 -33
  19. package/dist/parallel-plugin.d.mts +7 -7
  20. package/dist/parse-ast-index.d.mts +5 -6
  21. package/dist/parse-ast-index.mjs +1 -2
  22. package/dist/plugins-index.browser.mjs +39 -0
  23. package/dist/plugins-index.d.mts +30 -0
  24. package/dist/plugins-index.mjs +39 -0
  25. package/dist/rolldown-binding.wasi-browser.js +41 -24
  26. package/dist/rolldown-binding.wasi.cjs +62 -24
  27. package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
  28. package/dist/rolldown-build-BntP6Bjl.js +5063 -0
  29. package/dist/shared/bindingify-input-options-CObJx_Uj.mjs +2236 -0
  30. package/dist/shared/composable-filters-CIxSuZSM.mjs +227 -0
  31. package/dist/shared/constructors-5bt5oBhE.d.mts +28 -0
  32. package/dist/shared/constructors-BTW-c3jX.mjs +61 -0
  33. package/dist/shared/define-config-C-sO_cLw.d.mts +3679 -0
  34. package/dist/shared/define-config-Dlptvz3X.mjs +7 -0
  35. package/dist/shared/{load-config-D7UduHRZ.mjs → load-config-hx3WBhLe.mjs} +23 -33
  36. package/dist/shared/logging-RB67zQ4N.d.mts +50 -0
  37. package/dist/shared/{parse-ast-index-vu376yZ1.mjs → logs-B2CASPcx.mjs} +21 -116
  38. package/dist/shared/normalize-string-or-regex-DIwprzLy.mjs +60 -0
  39. package/dist/shared/parse-ast-index-BQpfNG1v.mjs +98 -0
  40. package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-CYPmuhh-.mjs} +301 -308
  41. package/dist/shared/rolldown-D2E0YTeB.mjs +42 -0
  42. package/dist/shared/rolldown-build-Do6WlRGM.mjs +2371 -0
  43. package/dist/shared/types-CIhJMr1h.d.mts +1300 -0
  44. package/dist/shared/utils-CqMTwlsR.d.mts +22 -0
  45. package/dist/shared/watch-BsneBCNP.mjs +378 -0
  46. package/package.json +33 -38
  47. package/dist/cli.cjs +0 -1748
  48. package/dist/config.cjs +0 -12
  49. package/dist/config.d.cts +0 -11
  50. package/dist/experimental-index.cjs +0 -129
  51. package/dist/experimental-index.d.cts +0 -96
  52. package/dist/filter-index.cjs +0 -53
  53. package/dist/filter-index.d.cts +0 -3
  54. package/dist/index.cjs +0 -9
  55. package/dist/index.d.cts +0 -3
  56. package/dist/parallel-plugin-worker.cjs +0 -33
  57. package/dist/parallel-plugin-worker.d.cts +0 -1
  58. package/dist/parallel-plugin.cjs +0 -8
  59. package/dist/parallel-plugin.d.cts +0 -14
  60. package/dist/parse-ast-index.cjs +0 -4
  61. package/dist/parse-ast-index.d.cts +0 -9
  62. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  63. package/dist/shared/chunk-DSsiIF1Z.mjs +0 -30
  64. package/dist/shared/define-config.d-D4lKXE9V.d.cts +0 -1165
  65. package/dist/shared/define-config.d-Dm9iNdt9.d.mts +0 -1165
  66. package/dist/shared/dist-BMVjvV-v.cjs +0 -249
  67. package/dist/shared/dist-CAn6dxW6.mjs +0 -153
  68. package/dist/shared/load-config-CtKjQ8Mn.cjs +0 -125
  69. package/dist/shared/prompt-GFYxfPw7.mjs +0 -854
  70. package/dist/shared/src-D0nc44MQ.mjs +0 -4691
  71. package/dist/shared/src-s89s870G.cjs +0 -4647
  72. package/dist/src-CeWghjQt.js +0 -4329
  73. /package/dist/{cli.d.cts → cli-setup.d.mts} +0 -0
@@ -0,0 +1,7 @@
1
+ //#region src/utils/define-config.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+
6
+ //#endregion
7
+ export { defineConfig as t };
@@ -1,10 +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-D2E0YTeB.mjs";
3
2
  import path from "node:path";
3
+ import { readdir } from "node:fs/promises";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import { cwd } from "node:process";
6
6
  import fs from "node:fs";
7
- import { readdir } from "node:fs/promises";
8
7
 
9
8
  //#region src/utils/load-config.ts
10
9
  async function bundleTsConfig(configFile, isEsm) {
@@ -15,13 +14,13 @@ async function bundleTsConfig(configFile, isEsm) {
15
14
  input: configFile,
16
15
  platform: "node",
17
16
  resolve: { mainFields: ["main"] },
18
- define: {
17
+ transform: { define: {
19
18
  __dirname: dirnameVarName,
20
19
  __filename: filenameVarName,
21
20
  "import.meta.url": importMetaUrlVarName,
22
21
  "import.meta.dirname": dirnameVarName,
23
22
  "import.meta.filename": filenameVarName
24
- },
23
+ } },
25
24
  treeshake: false,
26
25
  external: [/^[\w@][^:]/],
27
26
  plugins: [{
@@ -29,9 +28,8 @@ async function bundleTsConfig(configFile, isEsm) {
29
28
  transform: {
30
29
  filter: { id: /\.[cm]?[jt]s$/ },
31
30
  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
31
  return {
34
- code: injectValues + code,
32
+ code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
35
33
  map: null
36
34
  };
37
35
  }
@@ -39,15 +37,26 @@ async function bundleTsConfig(configFile, isEsm) {
39
37
  }]
40
38
  });
41
39
  const outputDir = path.dirname(configFile);
42
- const result = await bundle.write({
40
+ const fileName = (await bundle.write({
43
41
  dir: outputDir,
44
42
  format: isEsm ? "esm" : "cjs",
45
43
  sourcemap: "inline",
46
44
  entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
47
- });
48
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
45
+ })).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
49
46
  return path.join(outputDir, fileName);
50
47
  }
48
+ const SUPPORTED_JS_CONFIG_FORMATS = [
49
+ ".js",
50
+ ".mjs",
51
+ ".cjs"
52
+ ];
53
+ const SUPPORTED_TS_CONFIG_FORMATS = [
54
+ ".ts",
55
+ ".mts",
56
+ ".cts"
57
+ ];
58
+ const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
59
+ const DEFAULT_CONFIG_BASE = "rolldown.config";
51
60
  async function findConfigFileNameInCwd() {
52
61
  const filesInWorkingDirectory = new Set(await readdir(cwd()));
53
62
  for (const extension of SUPPORTED_CONFIG_FORMATS) {
@@ -57,8 +66,7 @@ async function findConfigFileNameInCwd() {
57
66
  throw new Error("No `rolldown.config` configuration file found.");
58
67
  }
59
68
  async function loadTsConfig(configFile) {
60
- const isEsm = isFilePathESM(configFile);
61
- const file = await bundleTsConfig(configFile, isEsm);
69
+ const file = await bundleTsConfig(configFile, isFilePathESM(configFile));
62
70
  try {
63
71
  return (await import(pathToFileURL(file).href)).default;
64
72
  } finally {
@@ -95,30 +103,12 @@ async function loadConfig(configPath) {
95
103
  const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
96
104
  try {
97
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;
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}\``);
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}\``);
102
108
  } catch (err) {
103
109
  throw new Error("Error happened while loading config.", { cause: err });
104
110
  }
105
111
  }
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
112
 
123
113
  //#endregion
124
- export { init_load_config, loadConfig };
114
+ 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,12 +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
38
 
45
39
  //#endregion
46
40
  //#region src/log/locate-character/index.js
@@ -59,13 +53,13 @@ function rangeContains(range, index) {
59
53
  function getLocator(source, options = {}) {
60
54
  const { offsetLine = 0, offsetColumn = 0 } = options;
61
55
  let start = 0;
62
- const ranges = source.split("\n").map((line, i$1) => {
56
+ const ranges = source.split("\n").map((line, i) => {
63
57
  const end = start + line.length + 1;
64
58
  /** @type {import('./types').Range} */
65
59
  const range = {
66
60
  start,
67
61
  end,
68
- line: i$1
62
+ line: i
69
63
  };
70
64
  start = end;
71
65
  return range;
@@ -102,14 +96,16 @@ function getLocator(source, options = {}) {
102
96
  function locate(source, search, options) {
103
97
  return getLocator(source, options)(search, options && options.startIndex);
104
98
  }
105
- var init_locate_character = __esm({ "src/log/locate-character/index.js"() {} });
106
99
 
107
100
  //#endregion
108
101
  //#region src/log/logs.ts
109
- function logParseError(message) {
102
+ 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", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION", PARSE_ERROR = "PARSE_ERROR", NO_FS_IN_BROWSER = "NO_FS_IN_BROWSER";
103
+ function logParseError(message, id, pos) {
110
104
  return {
111
105
  code: PARSE_ERROR,
112
- message
106
+ id,
107
+ message,
108
+ pos
113
109
  };
114
110
  }
115
111
  function logInvalidLogPosition(pluginName) {
@@ -136,16 +132,16 @@ function logMultiplyNotifyOption() {
136
132
  message: `Found multiply notify option at watch options, using first one to start notify watcher.`
137
133
  };
138
134
  }
139
- function logPluginError(error$1, plugin, { hook, id } = {}) {
135
+ function logPluginError(error, plugin, { hook, id } = {}) {
140
136
  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;
137
+ const code = error.code;
138
+ if (!error.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error.pluginCode = code;
139
+ error.code = PLUGIN_ERROR;
140
+ error.plugin = plugin;
141
+ if (hook) error.hook = hook;
142
+ if (id) error.id = id;
147
143
  } catch (_) {} finally {
148
- return error$1;
144
+ return error;
149
145
  }
150
146
  }
151
147
  function error(base) {
@@ -182,97 +178,6 @@ function augmentCodeLocation(properties, pos, source, id) {
182
178
  properties.frame = getCodeFrame(source, line, column);
183
179
  }
184
180
  }
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
- //#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
181
 
277
182
  //#endregion
278
- export { augmentCodeLocation, error, init_logs, init_parse_ast_index, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMultiplyNotifyOption, logPluginError, parseAst, parseAstAsync };
183
+ export { logInvalidLogPosition as a, logPluginError as c, logInputHookInOutputPlugin as i, locate as l, error as n, logMultiplyNotifyOption as o, logCycleLoading as r, logParseError as s, augmentCodeLocation as t, getCodeFrame as u };
@@ -0,0 +1,60 @@
1
+ import { c as logPluginError, n as error } from "./logs-B2CASPcx.mjs";
2
+ import { BindingCallableBuiltinPlugin } from "../rolldown-binding.wasi.cjs";
3
+
4
+ //#region src/builtin-plugin/utils.ts
5
+ var BuiltinPlugin = class {
6
+ /** Vite-specific option to control plugin ordering */
7
+ enforce;
8
+ constructor(name, _options) {
9
+ this.name = name;
10
+ this._options = _options;
11
+ }
12
+ };
13
+ function makeBuiltinPluginCallable(plugin) {
14
+ let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
15
+ const wrappedPlugin = plugin;
16
+ for (const key in callablePlugin) wrappedPlugin[key] = async function(...args) {
17
+ try {
18
+ return await callablePlugin[key](...args);
19
+ } catch (e) {
20
+ if (e instanceof Error && !e.stack?.includes("at ")) Error.captureStackTrace(e, wrappedPlugin[key]);
21
+ return error(logPluginError(e, plugin.name, {
22
+ hook: key,
23
+ id: key === "transform" ? args[2] : void 0
24
+ }));
25
+ }
26
+ };
27
+ return wrappedPlugin;
28
+ }
29
+ function bindingifyBuiltInPlugin(plugin) {
30
+ return {
31
+ __name: plugin.name,
32
+ options: plugin._options
33
+ };
34
+ }
35
+ function bindingifyManifestPlugin(plugin, pluginContextData) {
36
+ const { isOutputOptionsForLegacyChunks, ...options } = plugin._options;
37
+ return {
38
+ __name: plugin.name,
39
+ options: {
40
+ ...options,
41
+ isLegacy: isOutputOptionsForLegacyChunks ? (opts) => {
42
+ return isOutputOptionsForLegacyChunks(pluginContextData.getOutputOptions(opts));
43
+ } : void 0
44
+ }
45
+ };
46
+ }
47
+
48
+ //#endregion
49
+ //#region src/utils/normalize-string-or-regex.ts
50
+ function normalizedStringOrRegex(pattern) {
51
+ if (!pattern) return;
52
+ if (!isReadonlyArray(pattern)) return [pattern];
53
+ return pattern;
54
+ }
55
+ function isReadonlyArray(input) {
56
+ return Array.isArray(input);
57
+ }
58
+
59
+ //#endregion
60
+ export { makeBuiltinPluginCallable as a, bindingifyManifestPlugin as i, BuiltinPlugin as n, bindingifyBuiltInPlugin as r, normalizedStringOrRegex as t };
@@ -0,0 +1,98 @@
1
+ import { l as locate, n as error, s as logParseError, t as augmentCodeLocation, u as getCodeFrame } from "./logs-B2CASPcx.mjs";
2
+ import { parse, parseSync } from "../rolldown-binding.wasi.cjs";
3
+
4
+ //#region ../../node_modules/.pnpm/oxc-parser@0.111.0/node_modules/oxc-parser/src-js/wrap.js
5
+ function wrap$1(result) {
6
+ let program, module, comments, errors;
7
+ return {
8
+ get program() {
9
+ if (!program) program = jsonParseAst(result.program);
10
+ return program;
11
+ },
12
+ get module() {
13
+ if (!module) module = result.module;
14
+ return module;
15
+ },
16
+ get comments() {
17
+ if (!comments) comments = result.comments;
18
+ return comments;
19
+ },
20
+ get errors() {
21
+ if (!errors) errors = result.errors;
22
+ return errors;
23
+ }
24
+ };
25
+ }
26
+ function jsonParseAst(programJson) {
27
+ const { node: program, fixes } = JSON.parse(programJson);
28
+ for (const fixPath of fixes) applyFix(program, fixPath);
29
+ return program;
30
+ }
31
+ function applyFix(program, fixPath) {
32
+ let node = program;
33
+ for (const key of fixPath) node = node[key];
34
+ if (node.bigint) node.value = BigInt(node.bigint);
35
+ else try {
36
+ node.value = RegExp(node.regex.pattern, node.regex.flags);
37
+ } catch {}
38
+ }
39
+
40
+ //#endregion
41
+ //#region src/utils/parse.ts
42
+ /**
43
+ * Parse asynchronously.
44
+ *
45
+ * Note: This function can be slower than `parseSync` due to the overhead of spawning a thread.
46
+ */
47
+ async function parse$1(filename, sourceText, options) {
48
+ return wrap$1(await parse(filename, sourceText, options));
49
+ }
50
+ /** Parse synchronously. */
51
+ function parseSync$1(filename, sourceText, options) {
52
+ return wrap$1(parseSync(filename, sourceText, options));
53
+ }
54
+
55
+ //#endregion
56
+ //#region src/parse-ast-index.ts
57
+ function wrap(result, filename, sourceText) {
58
+ if (result.errors.length > 0) return normalizeParseError(filename, sourceText, result.errors);
59
+ return result.program;
60
+ }
61
+ function normalizeParseError(filename, sourceText, errors) {
62
+ let message = `Parse failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
63
+ const pos = errors[0]?.labels?.[0]?.start;
64
+ for (let i = 0; i < errors.length; i++) {
65
+ if (i >= 5) {
66
+ message += "\n...";
67
+ break;
68
+ }
69
+ const e = errors[i];
70
+ message += e.message + "\n" + e.labels.map((label) => {
71
+ const location = locate(sourceText, label.start, { offsetLine: 1 });
72
+ if (!location) return;
73
+ return getCodeFrame(sourceText, location.line, location.column);
74
+ }).filter(Boolean).join("\n");
75
+ }
76
+ const log = logParseError(message, filename, pos);
77
+ if (pos !== void 0 && filename) augmentCodeLocation(log, pos, sourceText, filename);
78
+ return error(log);
79
+ }
80
+ const defaultParserOptions = {
81
+ lang: "js",
82
+ preserveParens: false
83
+ };
84
+ function parseAst(sourceText, options, filename) {
85
+ return wrap(parseSync$1(filename ?? "file.js", sourceText, {
86
+ ...defaultParserOptions,
87
+ ...options
88
+ }), filename, sourceText);
89
+ }
90
+ async function parseAstAsync(sourceText, options, filename) {
91
+ return wrap(await parse$1(filename ?? "file.js", sourceText, {
92
+ ...defaultParserOptions,
93
+ ...options
94
+ }), filename, sourceText);
95
+ }
96
+
97
+ //#endregion
98
+ export { parseSync$1 as i, parseAstAsync as n, parse$1 as r, parseAst as t };