rolldown 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 (73) hide show
  1. package/README.md +11 -0
  2. package/dist/cli.mjs +962 -1551
  3. package/dist/config.d.mts +9 -7
  4. package/dist/config.mjs +10 -11
  5. package/dist/experimental-index.d.mts +225 -68
  6. package/dist/experimental-index.mjs +277 -57
  7. package/dist/experimental-runtime-types.d.ts +98 -0
  8. package/dist/filter-index.d.mts +195 -4
  9. package/dist/filter-index.mjs +347 -6
  10. package/dist/get-log-filter.d.mts +3 -0
  11. package/dist/get-log-filter.mjs +68 -0
  12. package/dist/index.d.mts +4 -4
  13. package/dist/index.mjs +54 -6
  14. package/dist/parallel-plugin-worker.mjs +28 -35
  15. package/dist/parallel-plugin.d.mts +6 -8
  16. package/dist/parallel-plugin.mjs +1 -2
  17. package/dist/parse-ast-index.d.mts +27 -4
  18. package/dist/parse-ast-index.mjs +61 -4
  19. package/dist/plugins-index.d.mts +33 -0
  20. package/dist/plugins-index.mjs +41 -0
  21. package/dist/shared/binding-BV_UWDF3.mjs +582 -0
  22. package/dist/shared/binding-Dsq9Azhm.d.mts +1851 -0
  23. package/dist/shared/bindingify-input-options-DoaqRULI.mjs +2170 -0
  24. package/dist/shared/constructors-DfpIbfMG.d.mts +37 -0
  25. package/dist/shared/constructors-DqC7XSXy.mjs +68 -0
  26. package/dist/shared/define-config-CV9D_Qea.d.mts +3781 -0
  27. package/dist/shared/define-config-DJOr6Iwt.mjs +6 -0
  28. package/dist/shared/error-BO4SlZV_.mjs +85 -0
  29. package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
  30. package/dist/shared/{load-config-Dll-92l5.mjs → load-config-ezHg7sBf.mjs} +32 -36
  31. package/dist/shared/logging-C6h4g8dA.d.mts +50 -0
  32. package/dist/shared/logs-D80CXhvg.mjs +180 -0
  33. package/dist/shared/{misc-DGAe2XOW.mjs → misc-DJYbNKZX.mjs} +1 -8
  34. package/dist/shared/normalize-string-or-regex-D7wlw16t.mjs +58 -0
  35. package/dist/shared/parse-nWsWXhOL.mjs +74 -0
  36. package/dist/shared/{prompt-CxjDC0Gn.cjs → prompt-BYQIwEjg.mjs} +301 -310
  37. package/dist/shared/resolve-tsconfig-C3OzszY-.mjs +113 -0
  38. package/dist/shared/rolldown-BOb3gBhW.mjs +40 -0
  39. package/dist/shared/rolldown-build-yQC7KN8K.mjs +3319 -0
  40. package/dist/shared/transform-B5D1aA1B.d.mts +149 -0
  41. package/dist/shared/watch-CzsahzPN.mjs +374 -0
  42. package/dist/utils-index.d.mts +376 -0
  43. package/dist/utils-index.mjs +2416 -0
  44. package/package.json +93 -99
  45. package/dist/cli.cjs +0 -1748
  46. package/dist/cli.d.cts +0 -1
  47. package/dist/config.cjs +0 -12
  48. package/dist/config.d.cts +0 -12
  49. package/dist/experimental-index.cjs +0 -132
  50. package/dist/experimental-index.d.cts +0 -96
  51. package/dist/filter-index.cjs +0 -105
  52. package/dist/filter-index.d.cts +0 -5
  53. package/dist/index.cjs +0 -9
  54. package/dist/index.d.cts +0 -4
  55. package/dist/parallel-plugin-worker.cjs +0 -33
  56. package/dist/parallel-plugin-worker.d.cts +0 -1
  57. package/dist/parallel-plugin.cjs +0 -8
  58. package/dist/parallel-plugin.d.cts +0 -15
  59. package/dist/parse-ast-index.cjs +0 -4
  60. package/dist/parse-ast-index.d.cts +0 -9
  61. package/dist/shared/binding.d-Dz3qQrbl.d.mts +0 -1682
  62. package/dist/shared/binding.d-QXzDcVmm.d.cts +0 -1682
  63. package/dist/shared/chunk--iN_1bjD.mjs +0 -33
  64. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  65. package/dist/shared/define-config.d-CUcDq_vm.d.cts +0 -1080
  66. package/dist/shared/define-config.d-qV1PzX_C.d.mts +0 -1080
  67. package/dist/shared/load-config-Bx9W9x2a.cjs +0 -125
  68. package/dist/shared/misc-BKp5iIef.cjs +0 -67
  69. package/dist/shared/parse-ast-index-0m6JgGc9.mjs +0 -655
  70. package/dist/shared/parse-ast-index-Cn_efzjO.cjs +0 -697
  71. package/dist/shared/prompt-uGrwvyp0.mjs +0 -854
  72. package/dist/shared/src-B4EklR3U.mjs +0 -4704
  73. package/dist/shared/src-BzFe16tX.cjs +0 -4654
@@ -0,0 +1,6 @@
1
+ //#region src/utils/define-config.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+ //#endregion
6
+ export { defineConfig as t };
@@ -0,0 +1,85 @@
1
+ import { t as require_binding } from "./binding-BV_UWDF3.mjs";
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
+ require_binding();
17
+ function unwrapBindingResult(container) {
18
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) throw aggregateBindingErrorsIntoJsError(container.errors);
19
+ return container;
20
+ }
21
+ function normalizeBindingResult(container) {
22
+ if (typeof container === "object" && container !== null && "isBindingErrors" in container && container.isBindingErrors) return aggregateBindingErrorsIntoJsError(container.errors);
23
+ return container;
24
+ }
25
+ function normalizeBindingError(e) {
26
+ return e.type === "JsError" ? e.field0 : Object.assign(/* @__PURE__ */ new Error(), {
27
+ code: e.field0.kind,
28
+ kind: e.field0.kind,
29
+ message: e.field0.message,
30
+ id: e.field0.id,
31
+ exporter: e.field0.exporter,
32
+ loc: e.field0.loc,
33
+ pos: e.field0.pos,
34
+ stack: void 0
35
+ });
36
+ }
37
+ function aggregateBindingErrorsIntoJsError(rawErrors) {
38
+ const errors = rawErrors.map(normalizeBindingError);
39
+ let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
40
+ for (let i = 0; i < errors.length; i++) {
41
+ summary += "\n";
42
+ if (i >= 5) {
43
+ summary += "...";
44
+ break;
45
+ }
46
+ summary += getErrorMessage(errors[i]);
47
+ }
48
+ const wrapper = new Error(summary);
49
+ Object.defineProperty(wrapper, "errors", {
50
+ configurable: true,
51
+ enumerable: true,
52
+ get: () => errors,
53
+ set: (value) => Object.defineProperty(wrapper, "errors", {
54
+ configurable: true,
55
+ enumerable: true,
56
+ value
57
+ })
58
+ });
59
+ return wrapper;
60
+ }
61
+ function getErrorMessage(e) {
62
+ if (Object.hasOwn(e, "kind")) return e.message;
63
+ let s = "";
64
+ if (e.plugin) s += `[plugin ${e.plugin}]`;
65
+ const id = e.id ?? e.loc?.file;
66
+ if (id) {
67
+ s += " " + id;
68
+ if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
69
+ }
70
+ if (s) s += "\n";
71
+ const message = `${e.name ?? "Error"}: ${e.message}`;
72
+ s += message;
73
+ if (e.frame) s = joinNewLine(s, e.frame);
74
+ if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
75
+ if (e.cause) {
76
+ s = joinNewLine(s, "Caused by:");
77
+ s = joinNewLine(s, getErrorMessage(e.cause).split("\n").map((line) => " " + line).join("\n"));
78
+ }
79
+ return s;
80
+ }
81
+ function joinNewLine(s1, s2) {
82
+ return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
83
+ }
84
+ //#endregion
85
+ 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--iN_1bjD.mjs";
2
- import { init_rolldown, rolldown } from "./src-B4EklR3U.mjs";
1
+ import { t as rolldown } from "./rolldown-BOb3gBhW.mjs";
3
2
  import fs from "node:fs";
4
3
  import path from "node:path";
5
- import { pathToFileURL } from "node:url";
6
- import { cwd } from "node:process";
7
4
  import { readdir } from "node:fs/promises";
8
-
5
+ import { cwd } from "node:process";
6
+ import { pathToFileURL } from "node:url";
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 };
@@ -0,0 +1,180 @@
1
+ //#region src/utils/code-frame.ts
2
+ function spaces(index) {
3
+ let result = "";
4
+ while (index--) result += " ";
5
+ return result;
6
+ }
7
+ function tabsToSpaces(value) {
8
+ return value.replace(/^\t+/, (match) => match.split(" ").join(" "));
9
+ }
10
+ const LINE_TRUNCATE_LENGTH = 120;
11
+ const MIN_CHARACTERS_SHOWN_AFTER_LOCATION = 10;
12
+ const ELLIPSIS = "...";
13
+ function getCodeFrame(source, line, column) {
14
+ let lines = source.split("\n");
15
+ if (line > lines.length) return "";
16
+ const maxLineLength = Math.max(tabsToSpaces(lines[line - 1].slice(0, column)).length + MIN_CHARACTERS_SHOWN_AFTER_LOCATION + 3, LINE_TRUNCATE_LENGTH);
17
+ const frameStart = Math.max(0, line - 3);
18
+ let frameEnd = Math.min(line + 2, lines.length);
19
+ lines = lines.slice(frameStart, frameEnd);
20
+ while (!/\S/.test(lines[lines.length - 1])) {
21
+ lines.pop();
22
+ frameEnd -= 1;
23
+ }
24
+ const digits = String(frameEnd).length;
25
+ return lines.map((sourceLine, index) => {
26
+ const isErrorLine = frameStart + index + 1 === line;
27
+ let lineNumber = String(index + frameStart + 1);
28
+ while (lineNumber.length < digits) lineNumber = ` ${lineNumber}`;
29
+ let displayedLine = tabsToSpaces(sourceLine);
30
+ if (displayedLine.length > maxLineLength) displayedLine = `${displayedLine.slice(0, maxLineLength - 3)}${ELLIPSIS}`;
31
+ if (isErrorLine) {
32
+ const indicator = spaces(digits + 2 + tabsToSpaces(sourceLine.slice(0, column)).length) + "^";
33
+ return `${lineNumber}: ${displayedLine}\n${indicator}`;
34
+ }
35
+ return `${lineNumber}: ${displayedLine}`;
36
+ }).join("\n");
37
+ }
38
+ //#endregion
39
+ //#region src/log/locate-character/index.js
40
+ /** @typedef {import('./types').Location} Location */
41
+ /**
42
+ * @param {import('./types').Range} range
43
+ * @param {number} index
44
+ */
45
+ function rangeContains(range, index) {
46
+ return range.start <= index && index < range.end;
47
+ }
48
+ /**
49
+ * @param {string} source
50
+ * @param {import('./types').Options} [options]
51
+ */
52
+ function getLocator(source, options = {}) {
53
+ const { offsetLine = 0, offsetColumn = 0 } = options;
54
+ let start = 0;
55
+ const ranges = source.split("\n").map((line, i) => {
56
+ const end = start + line.length + 1;
57
+ /** @type {import('./types').Range} */
58
+ const range = {
59
+ start,
60
+ end,
61
+ line: i
62
+ };
63
+ start = end;
64
+ return range;
65
+ });
66
+ let i = 0;
67
+ /**
68
+ * @param {string | number} search
69
+ * @param {number} [index]
70
+ * @returns {Location | undefined}
71
+ */
72
+ function locator(search, index) {
73
+ if (typeof search === "string") search = source.indexOf(search, index ?? 0);
74
+ if (search === -1) return void 0;
75
+ let range = ranges[i];
76
+ const d = search >= range.end ? 1 : -1;
77
+ while (range) {
78
+ if (rangeContains(range, search)) return {
79
+ line: offsetLine + range.line,
80
+ column: offsetColumn + search - range.start,
81
+ character: search
82
+ };
83
+ i += d;
84
+ range = ranges[i];
85
+ }
86
+ }
87
+ return locator;
88
+ }
89
+ /**
90
+ * @param {string} source
91
+ * @param {string | number} search
92
+ * @param {import('./types').Options} [options]
93
+ * @returns {Location | undefined}
94
+ */
95
+ function locate(source, search, options) {
96
+ return getLocator(source, options)(search, options && options.startIndex);
97
+ }
98
+ //#endregion
99
+ //#region src/log/logs.ts
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) {
102
+ return {
103
+ code: PARSE_ERROR,
104
+ id,
105
+ message,
106
+ pos
107
+ };
108
+ }
109
+ function logInvalidLogPosition(pluginName) {
110
+ return {
111
+ code: INVALID_LOG_POSITION,
112
+ message: `Plugin "${pluginName}" tried to add a file position to a log or warning. This is only supported in the "transform" hook at the moment and will be ignored.`
113
+ };
114
+ }
115
+ function logInputHookInOutputPlugin(pluginName, hookName) {
116
+ return {
117
+ code: INPUT_HOOK_IN_OUTPUT_PLUGIN,
118
+ message: `The "${hookName}" hook used by the output plugin ${pluginName} 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.`
119
+ };
120
+ }
121
+ function logCycleLoading(pluginName, moduleId) {
122
+ return {
123
+ code: CYCLE_LOADING,
124
+ message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
125
+ };
126
+ }
127
+ function logMultipleWatcherOption() {
128
+ return {
129
+ code: MULTIPLE_WATCHER_OPTION,
130
+ message: `Found multiple watcher options at watch options, using first one to start watcher.`
131
+ };
132
+ }
133
+ function logPluginError(error, plugin, { hook, id } = {}) {
134
+ try {
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;
141
+ } catch (_) {} finally {
142
+ return error;
143
+ }
144
+ }
145
+ function error(base) {
146
+ if (!(base instanceof Error)) {
147
+ base = Object.assign(new Error(base.message), base);
148
+ Object.defineProperty(base, "name", {
149
+ value: "RolldownError",
150
+ writable: true
151
+ });
152
+ }
153
+ throw base;
154
+ }
155
+ function augmentCodeLocation(properties, pos, source, id) {
156
+ if (typeof pos === "object") {
157
+ const { line, column } = pos;
158
+ properties.loc = {
159
+ column,
160
+ file: id,
161
+ line
162
+ };
163
+ } else {
164
+ properties.pos = pos;
165
+ const location = locate(source, pos, { offsetLine: 1 });
166
+ if (!location) return;
167
+ const { line, column } = location;
168
+ properties.loc = {
169
+ column,
170
+ file: id,
171
+ line
172
+ };
173
+ }
174
+ if (properties.frame === void 0) {
175
+ const { line, column } = properties.loc;
176
+ properties.frame = getCodeFrame(source, line, column);
177
+ }
178
+ }
179
+ //#endregion
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 };
@@ -1,12 +1,7 @@
1
- import { __esm } from "./chunk--iN_1bjD.mjs";
2
-
3
1
  //#region src/utils/misc.ts
4
2
  function arraify(value) {
5
3
  return Array.isArray(value) ? value : [value];
6
4
  }
7
- function isNullish(value) {
8
- return value === null || value === void 0;
9
- }
10
5
  function isPromiseLike(value) {
11
6
  return value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
12
7
  }
@@ -22,7 +17,5 @@ function unsupported(info) {
22
17
  throw new Error(`UNSUPPORTED: ${info}`);
23
18
  }
24
19
  function noop(..._args) {}
25
- var init_misc = __esm({ "src/utils/misc.ts"() {} });
26
-
27
20
  //#endregion
28
- export { arraify, init_misc, isNullish, isPromiseLike, noop, unimplemented, unreachable, unsupported };
21
+ export { unreachable as a, unimplemented as i, isPromiseLike as n, unsupported as o, noop as r, arraify as t };
@@ -0,0 +1,58 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-BV_UWDF3.mjs";
2
+ import { c as logPluginError, n as error } from "./logs-D80CXhvg.mjs";
3
+ //#region src/builtin-plugin/utils.ts
4
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
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 import_binding.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
+ //#endregion
48
+ //#region src/utils/normalize-string-or-regex.ts
49
+ function normalizedStringOrRegex(pattern) {
50
+ if (!pattern) return;
51
+ if (!isReadonlyArray(pattern)) return [pattern];
52
+ return pattern;
53
+ }
54
+ function isReadonlyArray(input) {
55
+ return Array.isArray(input);
56
+ }
57
+ //#endregion
58
+ export { makeBuiltinPluginCallable as a, bindingifyManifestPlugin as i, BuiltinPlugin as n, bindingifyBuiltInPlugin as r, normalizedStringOrRegex as t };
@@ -0,0 +1,74 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-BV_UWDF3.mjs";
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
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
40
+ /**
41
+ * Parse JS/TS source asynchronously on a separate thread.
42
+ *
43
+ * Note that not all of the workload can happen on a separate thread.
44
+ * Parsing on Rust side does happen in a separate thread, but deserialization of the AST to JS objects
45
+ * has to happen on current thread. This synchronous deserialization work typically outweighs
46
+ * the asynchronous parsing by a factor of between 3 and 20.
47
+ *
48
+ * i.e. the majority of the workload cannot be parallelized by using this method.
49
+ *
50
+ * Generally {@linkcode parseSync} is preferable to use as it does not have the overhead of spawning a thread.
51
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads.
52
+ *
53
+ * @category Utilities
54
+ */
55
+ async function parse(filename, sourceText, options) {
56
+ return wrap(await (0, import_binding.parse)(filename, sourceText, options));
57
+ }
58
+ /**
59
+ * Parse JS/TS source synchronously on current thread.
60
+ *
61
+ * This is generally preferable over {@linkcode parse} (async) as it does not have the overhead
62
+ * of spawning a thread, and the majority of the workload cannot be parallelized anyway
63
+ * (see {@linkcode parse} documentation for details).
64
+ *
65
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads
66
+ * with {@linkcode parseSync} rather than using {@linkcode parse}.
67
+ *
68
+ * @category Utilities
69
+ */
70
+ function parseSync(filename, sourceText, options) {
71
+ return wrap((0, import_binding.parseSync)(filename, sourceText, options));
72
+ }
73
+ //#endregion
74
+ export { parseSync as n, parse as t };