rolldown 1.0.0-beta.2-commit.2666b23 → 1.0.0-beta.20

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 (236) hide show
  1. package/bin/cli.mjs +2 -0
  2. package/dist/{cjs/cli.cjs → cli.cjs} +630 -603
  3. package/dist/cli.d.cts +1 -0
  4. package/dist/cli.d.mts +1 -0
  5. package/dist/{esm/cli.mjs → cli.mjs} +605 -575
  6. package/dist/config.cjs +12 -0
  7. package/dist/config.d.cts +10 -0
  8. package/dist/config.d.mts +10 -0
  9. package/dist/config.mjs +10 -0
  10. package/dist/experimental-index.cjs +107 -0
  11. package/dist/experimental-index.d.cts +63 -0
  12. package/dist/experimental-index.d.mts +63 -0
  13. package/dist/experimental-index.mjs +82 -0
  14. package/dist/experimental-runtime-types.d.ts +52 -0
  15. package/dist/filter-index.cjs +105 -0
  16. package/dist/filter-index.d.cts +4 -0
  17. package/dist/filter-index.d.mts +4 -0
  18. package/dist/filter-index.mjs +44 -0
  19. package/dist/index.cjs +9 -0
  20. package/dist/index.d.cts +3 -0
  21. package/dist/index.d.mts +3 -0
  22. package/dist/index.mjs +5 -0
  23. package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +6 -14
  24. package/dist/parallel-plugin-worker.d.cts +1 -0
  25. package/dist/parallel-plugin-worker.d.mts +1 -0
  26. package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -12
  27. package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
  28. package/dist/parallel-plugin.d.cts +14 -0
  29. package/dist/parallel-plugin.d.mts +14 -0
  30. package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
  31. package/dist/parse-ast-index.cjs +4 -0
  32. package/dist/parse-ast-index.d.cts +9 -0
  33. package/dist/parse-ast-index.d.mts +9 -0
  34. package/dist/parse-ast-index.mjs +3 -0
  35. package/dist/shared/binding-5O9lFYtz.d.mts +1215 -0
  36. package/dist/shared/binding-BvKFOCZr.d.cts +1215 -0
  37. package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
  38. package/dist/shared/define-config-BOD4oRSZ.d.cts +1204 -0
  39. package/dist/shared/define-config-DdVYel_V.d.mts +1204 -0
  40. package/dist/shared/load-config-B_hPIyxu.mjs +119 -0
  41. package/dist/shared/load-config-BdY850xq.cjs +125 -0
  42. package/dist/shared/misc-BKp5iIef.cjs +67 -0
  43. package/dist/shared/misc-BN0nse6C.mjs +25 -0
  44. package/dist/shared/parse-ast-index-CVVmsBjK.cjs +738 -0
  45. package/dist/shared/parse-ast-index-DW8kbzjr.mjs +616 -0
  46. package/dist/shared/{prompt-Nfm4Xz36.mjs → prompt-C5jz26Zn.mjs} +247 -246
  47. package/dist/shared/{prompt-B7tq3GL9.cjs → prompt-QNI93ne7.cjs} +250 -250
  48. package/dist/shared/src-CZ0tgOug.cjs +4851 -0
  49. package/dist/shared/src-DHXNdTPA.mjs +4647 -0
  50. package/package.json +63 -67
  51. package/bin/cli.js +0 -2
  52. package/dist/cjs/experimental-index.cjs +0 -79
  53. package/dist/cjs/index.cjs +0 -8
  54. package/dist/cjs/parse-ast-index.cjs +0 -57
  55. package/dist/esm/experimental-index.mjs +0 -56
  56. package/dist/esm/index.mjs +0 -4
  57. package/dist/esm/parse-ast-index.mjs +0 -55
  58. package/dist/shared/binding-l7VLSKnB.mjs +0 -610
  59. package/dist/shared/binding-orkvONpS.cjs +0 -661
  60. package/dist/shared/src-BC6S-BmL.cjs +0 -2828
  61. package/dist/shared/src-mupmacNC.mjs +0 -2647
  62. package/dist/types/api/build.d.ts +0 -18
  63. package/dist/types/api/build.js +0 -22
  64. package/dist/types/api/experimental.d.ts +0 -7
  65. package/dist/types/api/experimental.js +0 -13
  66. package/dist/types/api/rolldown/index.d.ts +0 -3
  67. package/dist/types/api/rolldown/index.js +0 -7
  68. package/dist/types/api/rolldown/rolldown-build.d.ts +0 -12
  69. package/dist/types/api/rolldown/rolldown-build.js +0 -43
  70. package/dist/types/api/watch/index.d.ts +0 -3
  71. package/dist/types/api/watch/index.js +0 -8
  72. package/dist/types/api/watch/watch-emitter.d.ts +0 -31
  73. package/dist/types/api/watch/watch-emitter.js +0 -69
  74. package/dist/types/api/watch/watcher.d.ts +0 -13
  75. package/dist/types/api/watch/watcher.js +0 -66
  76. package/dist/types/binding.d.ts +0 -1327
  77. package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
  78. package/dist/types/builtin-plugin/alias-plugin.js +0 -4
  79. package/dist/types/builtin-plugin/constructors.d.ts +0 -20
  80. package/dist/types/builtin-plugin/constructors.js +0 -68
  81. package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
  82. package/dist/types/builtin-plugin/replace-plugin.js +0 -29
  83. package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
  84. package/dist/types/builtin-plugin/transform-plugin.js +0 -16
  85. package/dist/types/builtin-plugin/utils.d.ts +0 -8
  86. package/dist/types/builtin-plugin/utils.js +0 -19
  87. package/dist/types/cli/arguments/alias.d.ts +0 -16
  88. package/dist/types/cli/arguments/alias.js +0 -63
  89. package/dist/types/cli/arguments/index.d.ts +0 -15
  90. package/dist/types/cli/arguments/index.js +0 -127
  91. package/dist/types/cli/arguments/normalize.d.ts +0 -12
  92. package/dist/types/cli/arguments/normalize.js +0 -48
  93. package/dist/types/cli/arguments/utils.d.ts +0 -8
  94. package/dist/types/cli/arguments/utils.js +0 -67
  95. package/dist/types/cli/colors.d.ts +0 -11
  96. package/dist/types/cli/colors.js +0 -17
  97. package/dist/types/cli/commands/bundle.d.ts +0 -3
  98. package/dist/types/cli/commands/bundle.js +0 -203
  99. package/dist/types/cli/commands/help.d.ts +0 -1
  100. package/dist/types/cli/commands/help.js +0 -88
  101. package/dist/types/cli/index.d.ts +0 -1
  102. package/dist/types/cli/index.js +0 -27
  103. package/dist/types/cli/load-config.d.ts +0 -3
  104. package/dist/types/cli/load-config.js +0 -95
  105. package/dist/types/cli/logger.d.ts +0 -5
  106. package/dist/types/cli/logger.js +0 -35
  107. package/dist/types/constants/plugin-context.d.ts +0 -7
  108. package/dist/types/constants/plugin-context.js +0 -7
  109. package/dist/types/constants/plugin.d.ts +0 -45
  110. package/dist/types/constants/plugin.js +0 -69
  111. package/dist/types/experimental-index.d.ts +0 -9
  112. package/dist/types/experimental-index.js +0 -9
  113. package/dist/types/index.d.ts +0 -28
  114. package/dist/types/index.js +0 -7
  115. package/dist/types/log/logHandler.d.ts +0 -4
  116. package/dist/types/log/logHandler.js +0 -25
  117. package/dist/types/log/logger.d.ts +0 -6
  118. package/dist/types/log/logger.js +0 -107
  119. package/dist/types/log/logging.d.ts +0 -11
  120. package/dist/types/log/logging.js +0 -11
  121. package/dist/types/log/logs.d.ts +0 -18
  122. package/dist/types/log/logs.js +0 -86
  123. package/dist/types/options/input-options.d.ts +0 -170
  124. package/dist/types/options/input-options.js +0 -1
  125. package/dist/types/options/normalized-input-options.d.ts +0 -18
  126. package/dist/types/options/normalized-input-options.js +0 -21
  127. package/dist/types/options/normalized-output-options.d.ts +0 -67
  128. package/dist/types/options/normalized-output-options.js +0 -99
  129. package/dist/types/options/output-options.d.ts +0 -86
  130. package/dist/types/options/output-options.js +0 -1
  131. package/dist/types/options/watch-options.d.ts +0 -5
  132. package/dist/types/options/watch-options.js +0 -1
  133. package/dist/types/parallel-plugin-worker.d.ts +0 -1
  134. package/dist/types/parallel-plugin-worker.js +0 -31
  135. package/dist/types/parallel-plugin.d.ts +0 -1
  136. package/dist/types/parallel-plugin.js +0 -1
  137. package/dist/types/parse-ast-index.d.ts +0 -4
  138. package/dist/types/parse-ast-index.js +0 -73
  139. package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
  140. package/dist/types/plugin/bindingify-build-hooks.js +0 -213
  141. package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
  142. package/dist/types/plugin/bindingify-hook-filter.js +0 -39
  143. package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
  144. package/dist/types/plugin/bindingify-output-hooks.js +0 -189
  145. package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
  146. package/dist/types/plugin/bindingify-plugin-hook-meta.js +0 -19
  147. package/dist/types/plugin/bindingify-plugin.d.ts +0 -15
  148. package/dist/types/plugin/bindingify-plugin.js +0 -124
  149. package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
  150. package/dist/types/plugin/bindingify-watch-hooks.js +0 -29
  151. package/dist/types/plugin/hook-filter.d.ts +0 -48
  152. package/dist/types/plugin/hook-filter.js +0 -1
  153. package/dist/types/plugin/index.d.ts +0 -126
  154. package/dist/types/plugin/index.js +0 -1
  155. package/dist/types/plugin/minimal-plugin-context.d.ts +0 -15
  156. package/dist/types/plugin/minimal-plugin-context.js +0 -25
  157. package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
  158. package/dist/types/plugin/parallel-plugin-implementation.js +0 -3
  159. package/dist/types/plugin/parallel-plugin.d.ts +0 -9
  160. package/dist/types/plugin/parallel-plugin.js +0 -6
  161. package/dist/types/plugin/plugin-context-data.d.ts +0 -16
  162. package/dist/types/plugin/plugin-context-data.js +0 -55
  163. package/dist/types/plugin/plugin-context.d.ts +0 -52
  164. package/dist/types/plugin/plugin-context.js +0 -108
  165. package/dist/types/plugin/plugin-driver.d.ts +0 -8
  166. package/dist/types/plugin/plugin-driver.js +0 -88
  167. package/dist/types/plugin/transform-plugin-context.d.ts +0 -17
  168. package/dist/types/plugin/transform-plugin-context.js +0 -37
  169. package/dist/types/types/assert.d.ts +0 -13
  170. package/dist/types/types/assert.js +0 -1
  171. package/dist/types/types/config-export.d.ts +0 -5
  172. package/dist/types/types/config-export.js +0 -1
  173. package/dist/types/types/misc.d.ts +0 -40
  174. package/dist/types/types/misc.js +0 -1
  175. package/dist/types/types/module-info.d.ts +0 -15
  176. package/dist/types/types/module-info.js +0 -1
  177. package/dist/types/types/module-side-effects.d.ts +0 -10
  178. package/dist/types/types/module-side-effects.js +0 -1
  179. package/dist/types/types/output-bundle.d.ts +0 -4
  180. package/dist/types/types/output-bundle.js +0 -1
  181. package/dist/types/types/rolldown-options.d.ts +0 -5
  182. package/dist/types/types/rolldown-options.js +0 -1
  183. package/dist/types/types/rolldown-output.d.ts +0 -63
  184. package/dist/types/types/rolldown-output.js +0 -1
  185. package/dist/types/types/schema.d.ts +0 -33
  186. package/dist/types/types/schema.js +0 -1
  187. package/dist/types/types/sourcemap.d.ts +0 -13
  188. package/dist/types/types/sourcemap.js +0 -16
  189. package/dist/types/types/utils.d.ts +0 -13
  190. package/dist/types/types/utils.js +0 -1
  191. package/dist/types/utils/asset-source.d.ts +0 -4
  192. package/dist/types/utils/asset-source.js +0 -8
  193. package/dist/types/utils/async-flatten.d.ts +0 -1
  194. package/dist/types/utils/async-flatten.js +0 -7
  195. package/dist/types/utils/bindingify-input-options.d.ts +0 -7
  196. package/dist/types/utils/bindingify-input-options.js +0 -225
  197. package/dist/types/utils/bindingify-output-options.d.ts +0 -3
  198. package/dist/types/utils/bindingify-output-options.js +0 -92
  199. package/dist/types/utils/code-frame.d.ts +0 -1
  200. package/dist/types/utils/code-frame.js +0 -46
  201. package/dist/types/utils/compose-js-plugins.d.ts +0 -2
  202. package/dist/types/utils/compose-js-plugins.js +0 -400
  203. package/dist/types/utils/create-bundler-option.d.ts +0 -11
  204. package/dist/types/utils/create-bundler-option.js +0 -53
  205. package/dist/types/utils/create-bundler.d.ts +0 -8
  206. package/dist/types/utils/create-bundler.js +0 -15
  207. package/dist/types/utils/define-config.d.ts +0 -5
  208. package/dist/types/utils/define-config.js +0 -3
  209. package/dist/types/utils/error.d.ts +0 -2
  210. package/dist/types/utils/error.js +0 -65
  211. package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
  212. package/dist/types/utils/initialize-parallel-plugins.js +0 -54
  213. package/dist/types/utils/misc.d.ts +0 -6
  214. package/dist/types/utils/misc.js +0 -22
  215. package/dist/types/utils/normalize-hook.d.ts +0 -7
  216. package/dist/types/utils/normalize-hook.js +0 -21
  217. package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
  218. package/dist/types/utils/normalize-plugin-option.js +0 -35
  219. package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
  220. package/dist/types/utils/normalize-string-or-regex.js +0 -14
  221. package/dist/types/utils/plugin/index.d.ts +0 -2
  222. package/dist/types/utils/plugin/index.js +0 -7
  223. package/dist/types/utils/transform-module-info.d.ts +0 -4
  224. package/dist/types/utils/transform-module-info.js +0 -19
  225. package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
  226. package/dist/types/utils/transform-rendered-chunk.js +0 -43
  227. package/dist/types/utils/transform-rendered-module.d.ts +0 -3
  228. package/dist/types/utils/transform-rendered-module.js +0 -10
  229. package/dist/types/utils/transform-side-effects.d.ts +0 -3
  230. package/dist/types/utils/transform-side-effects.js +0 -16
  231. package/dist/types/utils/transform-sourcemap.d.ts +0 -3
  232. package/dist/types/utils/transform-sourcemap.js +0 -29
  233. package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
  234. package/dist/types/utils/transform-to-rollup-output.js +0 -165
  235. package/dist/types/utils/validator.d.ts +0 -7
  236. package/dist/types/utils/validator.js +0 -275
@@ -1,2647 +0,0 @@
1
- import { augmentCodeLocation, colors, error, import_binding, logCycleLoading, logInputHookInOutputPlugin, logInvalidLogPosition, logMinifyWarning, logMultiplyNotifyOption, logPluginError } from "./binding-l7VLSKnB.mjs";
2
- import path from "node:path";
3
- import { Buffer } from "node:buffer";
4
- import { Worker } from "node:worker_threads";
5
- import { availableParallelism } from "node:os";
6
- import * as v from "valibot";
7
- import { toJsonSchema } from "@valibot/to-json-schema";
8
-
9
- //#region src/utils/define-config.ts
10
- function defineConfig(config) {
11
- return config;
12
- }
13
-
14
- //#endregion
15
- //#region src/utils/misc.ts
16
- function arraify(value) {
17
- return Array.isArray(value) ? value : [value];
18
- }
19
- function isNullish(value) {
20
- return value === null || value === undefined;
21
- }
22
- function unimplemented(info) {
23
- if (info) throw new Error(`unimplemented: ${info}`);
24
- throw new Error("unimplemented");
25
- }
26
- function unreachable(info) {
27
- if (info) throw new Error(`unreachable: ${info}`);
28
- throw new Error("unreachable");
29
- }
30
- function unsupported(info) {
31
- throw new Error(`UNSUPPORTED: ${info}`);
32
- }
33
- function noop(..._args) {}
34
-
35
- //#endregion
36
- //#region src/log/logging.ts
37
- const LOG_LEVEL_SILENT = "silent";
38
- const LOG_LEVEL_ERROR = "error";
39
- const LOG_LEVEL_WARN = "warn";
40
- const LOG_LEVEL_INFO = "info";
41
- const LOG_LEVEL_DEBUG = "debug";
42
- const logLevelPriority = {
43
- [LOG_LEVEL_DEBUG]: 0,
44
- [LOG_LEVEL_INFO]: 1,
45
- [LOG_LEVEL_WARN]: 2,
46
- [LOG_LEVEL_SILENT]: 3
47
- };
48
-
49
- //#endregion
50
- //#region src/log/logHandler.ts
51
- const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
52
- function getLogHandler(level, code, logger, pluginName, logLevel) {
53
- if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
54
- return (log, pos) => {
55
- if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
56
- log = normalizeLog(log);
57
- if (log.code && !log.pluginCode) log.pluginCode = log.code;
58
- log.code = code;
59
- log.plugin = pluginName;
60
- logger(level, log);
61
- };
62
- }
63
-
64
- //#endregion
65
- //#region src/utils/normalize-hook.ts
66
- function normalizeHook(hook) {
67
- if (typeof hook === "function" || typeof hook === "string") return {
68
- handler: hook,
69
- options: {},
70
- meta: {}
71
- };
72
- if (typeof hook === "object" && hook !== null) {
73
- const { handler, order,...options } = hook;
74
- return {
75
- handler,
76
- options,
77
- meta: { order }
78
- };
79
- }
80
- unreachable("Invalid hook type");
81
- }
82
-
83
- //#endregion
84
- //#region src/log/logger.ts
85
- function getLogger(plugins, onLog, logLevel) {
86
- const minimalPriority = logLevelPriority[logLevel];
87
- const logger = (level, log, skipped = new Set()) => {
88
- const logPriority = logLevelPriority[level];
89
- if (logPriority < minimalPriority) return;
90
- for (const plugin of getSortedPlugins("onLog", plugins)) {
91
- if (skipped.has(plugin)) continue;
92
- const { onLog: pluginOnLog } = plugin;
93
- if (pluginOnLog) {
94
- const getLogHandler$1 = (level$1) => {
95
- if (logLevelPriority[level$1] < minimalPriority) return () => {};
96
- return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
97
- };
98
- const handler = "handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
99
- if (handler.call({
100
- debug: getLogHandler$1(LOG_LEVEL_DEBUG),
101
- error: (log$1) => error(normalizeLog(log$1)),
102
- info: getLogHandler$1(LOG_LEVEL_INFO),
103
- meta: {
104
- rollupVersion: "4.23.0",
105
- rolldownVersion: VERSION,
106
- watchMode: false
107
- },
108
- warn: getLogHandler$1(LOG_LEVEL_WARN),
109
- pluginName: plugin.name || "unknown"
110
- }, level, log) === false) return;
111
- }
112
- }
113
- onLog(level, log);
114
- };
115
- return logger;
116
- }
117
- const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
118
- const { onwarn, onLog } = config;
119
- const defaultOnLog = getDefaultOnLog(printLog, onwarn);
120
- if (onLog) {
121
- const minimalPriority = logLevelPriority[logLevel];
122
- return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
123
- if (level$1 === LOG_LEVEL_ERROR) return error(normalizeLog(handledLog));
124
- if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog));
125
- });
126
- }
127
- return defaultOnLog;
128
- };
129
- const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
130
- if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
131
- else printLog(level, log);
132
- } : printLog;
133
- const addLogToString = (log) => {
134
- Object.defineProperty(log, "toString", {
135
- value: () => getExtendedLogMessage(log),
136
- writable: true
137
- });
138
- return log;
139
- };
140
- const defaultPrintLog = (level, log) => {
141
- const message = getExtendedLogMessage(log);
142
- switch (level) {
143
- case LOG_LEVEL_WARN: return console.warn(message);
144
- case LOG_LEVEL_DEBUG: return console.debug(message);
145
- default: return console.info(message);
146
- }
147
- };
148
- const getExtendedLogMessage = (log) => {
149
- let prefix = "";
150
- if (log.plugin) prefix += `(${log.plugin} plugin) `;
151
- if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
152
- return prefix + log.message;
153
- };
154
- function relativeId(id) {
155
- if (!path.isAbsolute(id)) return id;
156
- return path.relative(path.resolve(), id);
157
- }
158
-
159
- //#endregion
160
- //#region src/builtin-plugin/utils.ts
161
- function makeBuiltinPluginCallable(plugin) {
162
- let callablePlugin = new import_binding.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
163
- const wrappedPlugin = plugin;
164
- for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
165
- return callablePlugin[key](...args);
166
- };
167
- return wrappedPlugin;
168
- }
169
- function bindingifyBuiltInPlugin(plugin) {
170
- return {
171
- __name: plugin.name,
172
- options: plugin._options
173
- };
174
- }
175
-
176
- //#endregion
177
- //#region src/builtin-plugin/constructors.ts
178
- var BuiltinPlugin = class {
179
- constructor(name, _options) {
180
- this.name = name;
181
- this._options = _options;
182
- this.name = name;
183
- this._options = _options;
184
- }
185
- };
186
- function modulePreloadPolyfillPlugin(config) {
187
- return new BuiltinPlugin("builtin:module-preload-polyfill", config);
188
- }
189
- function dynamicImportVarsPlugin() {
190
- return new BuiltinPlugin("builtin:dynamic-import-vars");
191
- }
192
- function importGlobPlugin(config) {
193
- return new BuiltinPlugin("builtin:import-glob", config);
194
- }
195
- function manifestPlugin(config) {
196
- return new BuiltinPlugin("builtin:manifest", config);
197
- }
198
- function wasmHelperPlugin() {
199
- return new BuiltinPlugin("builtin:wasm-helper");
200
- }
201
- function wasmFallbackPlugin() {
202
- return new BuiltinPlugin("builtin:wasm-fallback");
203
- }
204
- function loadFallbackPlugin() {
205
- return new BuiltinPlugin("builtin:load-fallback");
206
- }
207
- function jsonPlugin(config) {
208
- return new BuiltinPlugin("builtin:json", config);
209
- }
210
- function buildImportAnalysisPlugin(config) {
211
- return new BuiltinPlugin("builtin:build-import-analysis", config);
212
- }
213
- function viteResolvePlugin(config) {
214
- const builtinPlugin = new BuiltinPlugin("builtin:vite-resolve", {
215
- ...config,
216
- runtime: process.versions.deno ? "deno" : process.versions.bun ? "bun" : "node"
217
- });
218
- return makeBuiltinPluginCallable(builtinPlugin);
219
- }
220
- function moduleFederationPlugin(config) {
221
- return new BuiltinPlugin("builtin:module-federation", {
222
- ...config,
223
- remotes: config.remotes && Object.entries(config.remotes).map(([name, remote]) => {
224
- if (typeof remote === "string") {
225
- const [entryGlobalName] = remote.split("@");
226
- const entry = remote.replace(entryGlobalName + "@", "");
227
- return {
228
- entry,
229
- name
230
- };
231
- }
232
- return {
233
- ...remote,
234
- name: remote.name ?? name
235
- };
236
- })
237
- });
238
- }
239
-
240
- //#endregion
241
- //#region src/utils/async-flatten.ts
242
- async function asyncFlatten(array) {
243
- do
244
- array = (await Promise.all(array)).flat(Infinity);
245
- while (array.some((v$1) => v$1?.then));
246
- return array;
247
- }
248
-
249
- //#endregion
250
- //#region src/constants/plugin.ts
251
- const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
252
- "options",
253
- "buildStart",
254
- "resolveId",
255
- "load",
256
- "transform",
257
- "moduleParsed",
258
- "buildEnd",
259
- "onLog",
260
- "resolveDynamicImport",
261
- "closeBundle",
262
- "closeWatcher",
263
- "watchChange"
264
- ];
265
- const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
266
- "augmentChunkHash",
267
- "outputOptions",
268
- "renderChunk",
269
- "renderStart",
270
- "renderError",
271
- "writeBundle",
272
- "generateBundle"
273
- ];
274
- const ENUMERATED_PLUGIN_HOOK_NAMES = [
275
- ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
276
- ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
277
- "footer",
278
- "banner",
279
- "intro",
280
- "outro"
281
- ];
282
- const DEFINED_HOOK_NAMES = {
283
- [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
284
- [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
285
- [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
286
- [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
287
- [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
288
- [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
289
- [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
290
- [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
291
- [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
292
- [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
293
- [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
294
- [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
295
- [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
296
- [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
297
- [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
298
- [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
299
- [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
300
- [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
301
- [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
302
- [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
303
- [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
304
- [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
305
- [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
306
- };
307
-
308
- //#endregion
309
- //#region src/utils/normalize-plugin-option.ts
310
- const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
311
- function checkOutputPluginOption(plugins, onLog) {
312
- for (const plugin of plugins) for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) if (hook in plugin) {
313
- delete plugin[hook];
314
- onLog(LOG_LEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook));
315
- }
316
- return plugins;
317
- }
318
- function normalizePlugins(plugins, anonymousPrefix) {
319
- for (const [index, plugin] of plugins.entries()) {
320
- if ("_parallel" in plugin) continue;
321
- if (plugin instanceof BuiltinPlugin) continue;
322
- if (!plugin.name) plugin.name = `${anonymousPrefix}${index + 1}`;
323
- }
324
- return plugins;
325
- }
326
- const ANONYMOUS_PLUGIN_PREFIX = "at position ";
327
- const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = "at output position ";
328
-
329
- //#endregion
330
- //#region src/plugin/plugin-driver.ts
331
- var PluginDriver = class {
332
- static async callOptionsHook(inputOptions) {
333
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
334
- const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
335
- const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel);
336
- for (const plugin of plugins) {
337
- const name = plugin.name || "unknown";
338
- const options = plugin.options;
339
- if (options) {
340
- const { handler } = normalizeHook(options);
341
- const result = await handler.call({
342
- debug: getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", logger, name, logLevel),
343
- error: (e) => error(logPluginError(normalizeLog(e), name, { hook: "onLog" })),
344
- info: getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", logger, name, logLevel),
345
- meta: {
346
- rollupVersion: "4.23.0",
347
- rolldownVersion: VERSION,
348
- watchMode: false
349
- },
350
- warn: getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", logger, name, logLevel),
351
- pluginName: name
352
- }, inputOptions);
353
- if (result) inputOptions = result;
354
- }
355
- }
356
- return inputOptions;
357
- }
358
- static callOutputOptionsHook(rawPlugins, outputOptions) {
359
- const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins));
360
- for (const plugin of sortedPlugins) {
361
- const options = plugin.outputOptions;
362
- if (options) {
363
- const { handler } = normalizeHook(options);
364
- const result = handler.call(null, outputOptions);
365
- if (result) outputOptions = result;
366
- }
367
- }
368
- return outputOptions;
369
- }
370
- };
371
- function getObjectPlugins(plugins) {
372
- return plugins.filter((plugin) => {
373
- if (!plugin) return undefined;
374
- if ("_parallel" in plugin) return undefined;
375
- if (plugin instanceof BuiltinPlugin) return undefined;
376
- return plugin;
377
- });
378
- }
379
- function getSortedPlugins(hookName, plugins) {
380
- const pre = [];
381
- const normal = [];
382
- const post = [];
383
- for (const plugin of plugins) {
384
- const hook = plugin[hookName];
385
- if (hook) {
386
- if (typeof hook === "object") {
387
- if (hook.order === "pre") {
388
- pre.push(plugin);
389
- continue;
390
- }
391
- if (hook.order === "post") {
392
- post.push(plugin);
393
- continue;
394
- }
395
- }
396
- normal.push(plugin);
397
- }
398
- }
399
- return [
400
- ...pre,
401
- ...normal,
402
- ...post
403
- ];
404
- }
405
-
406
- //#endregion
407
- //#region src/utils/asset-source.ts
408
- function transformAssetSource(bindingAssetSource$1) {
409
- return bindingAssetSource$1.inner;
410
- }
411
- function bindingAssetSource(source) {
412
- return { inner: source };
413
- }
414
-
415
- //#endregion
416
- //#region src/types/sourcemap.ts
417
- function bindingifySourcemap$1(map) {
418
- if (map == null) return;
419
- return { inner: typeof map === "string" ? map : {
420
- file: map.file ?? undefined,
421
- mappings: map.mappings,
422
- sourceRoot: map.sourceRoot,
423
- sources: map.sources?.map((s) => s ?? undefined),
424
- sourcesContent: map.sourcesContent?.map((s) => s ?? undefined),
425
- names: map.names
426
- } };
427
- }
428
-
429
- //#endregion
430
- //#region src/utils/error.ts
431
- function normalizeErrors(rawErrors) {
432
- const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
433
- kind: e.kind,
434
- message: e.message,
435
- stack: undefined
436
- }));
437
- let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
438
- for (let i = 0; i < errors.length; i++) {
439
- if (i >= 5) {
440
- summary += "\n...";
441
- break;
442
- }
443
- summary += getErrorMessage(errors[i]) + "\n";
444
- }
445
- const wrapper = new Error(summary);
446
- Object.defineProperty(wrapper, "errors", {
447
- configurable: true,
448
- enumerable: true,
449
- get: () => errors,
450
- set: (value) => Object.defineProperty(wrapper, "errors", {
451
- configurable: true,
452
- enumerable: true,
453
- value
454
- })
455
- });
456
- return wrapper;
457
- }
458
- function getErrorMessage(e) {
459
- let s = "";
460
- if (e.plugin) s += `[plugin ${e.plugin}]`;
461
- const id = e.id ?? e.loc?.file;
462
- if (id) {
463
- s += " " + id;
464
- if (e.loc) s += `:${e.loc.line}:${e.loc.column}`;
465
- }
466
- if (s) s += "\n";
467
- const message = `${e.name ?? "Error"}: ${e.message}`;
468
- s += message;
469
- if (e.frame) s = joinNewLine(s, e.frame);
470
- if (e.stack) s = joinNewLine(s, e.stack.replace(message, ""));
471
- return s;
472
- }
473
- function joinNewLine(s1, s2) {
474
- return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
475
- }
476
-
477
- //#endregion
478
- //#region src/utils/transform-rendered-module.ts
479
- function transformToRenderedModule(bindingRenderedModule) {
480
- return {
481
- get code() {
482
- return bindingRenderedModule.code;
483
- },
484
- get renderedLength() {
485
- return bindingRenderedModule.code?.length || 0;
486
- }
487
- };
488
- }
489
-
490
- //#endregion
491
- //#region src/utils/transform-rendered-chunk.ts
492
- function transformRenderedChunk(chunk) {
493
- return {
494
- get name() {
495
- return chunk.name;
496
- },
497
- get isEntry() {
498
- return chunk.isEntry;
499
- },
500
- get isDynamicEntry() {
501
- return chunk.isDynamicEntry;
502
- },
503
- get facadeModuleId() {
504
- return chunk.facadeModuleId;
505
- },
506
- get moduleIds() {
507
- return chunk.moduleIds;
508
- },
509
- get exports() {
510
- return chunk.exports;
511
- },
512
- get fileName() {
513
- return chunk.fileName;
514
- },
515
- get imports() {
516
- return chunk.imports;
517
- },
518
- get dynamicImports() {
519
- return chunk.dynamicImports;
520
- },
521
- get modules() {
522
- return transformChunkModules(chunk.modules);
523
- }
524
- };
525
- }
526
- function transformChunkModules(modules) {
527
- const result = {};
528
- for (const [id, index] of Object.entries(modules.idToIndex)) {
529
- let mod = modules.value[index];
530
- result[id] = transformToRenderedModule(mod);
531
- }
532
- return result;
533
- }
534
-
535
- //#endregion
536
- //#region src/utils/transform-to-rollup-output.ts
537
- function transformToRollupSourceMap(map) {
538
- const parsed = JSON.parse(map);
539
- const obj = {
540
- ...parsed,
541
- toString() {
542
- return JSON.stringify(obj);
543
- },
544
- toUrl() {
545
- return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
546
- }
547
- };
548
- return obj;
549
- }
550
- function transformToRollupOutputChunk(bindingChunk, changed) {
551
- const chunk = {
552
- type: "chunk",
553
- get code() {
554
- return bindingChunk.code;
555
- },
556
- fileName: bindingChunk.fileName,
557
- name: bindingChunk.name,
558
- get modules() {
559
- return transformChunkModules(bindingChunk.modules);
560
- },
561
- get imports() {
562
- return bindingChunk.imports;
563
- },
564
- get dynamicImports() {
565
- return bindingChunk.dynamicImports;
566
- },
567
- exports: bindingChunk.exports,
568
- isEntry: bindingChunk.isEntry,
569
- facadeModuleId: bindingChunk.facadeModuleId || null,
570
- isDynamicEntry: bindingChunk.isDynamicEntry,
571
- get moduleIds() {
572
- return bindingChunk.moduleIds;
573
- },
574
- get map() {
575
- return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
576
- },
577
- sourcemapFileName: bindingChunk.sourcemapFileName || null,
578
- preliminaryFileName: bindingChunk.preliminaryFileName
579
- };
580
- const cache = {};
581
- return new Proxy(chunk, {
582
- get(target, p) {
583
- if (p in cache) return cache[p];
584
- return target[p];
585
- },
586
- set(target, p, newValue) {
587
- cache[p] = newValue;
588
- changed?.updated.add(bindingChunk.fileName);
589
- return true;
590
- }
591
- });
592
- }
593
- function transformToRollupOutputAsset(bindingAsset, changed) {
594
- const asset = {
595
- type: "asset",
596
- fileName: bindingAsset.fileName,
597
- originalFileName: bindingAsset.originalFileName || null,
598
- originalFileNames: bindingAsset.originalFileNames,
599
- get source() {
600
- return transformAssetSource(bindingAsset.source);
601
- },
602
- name: bindingAsset.name ?? undefined,
603
- names: bindingAsset.names
604
- };
605
- const cache = {};
606
- return new Proxy(asset, {
607
- get(target, p) {
608
- if (p in cache) return cache[p];
609
- return target[p];
610
- },
611
- set(target, p, newValue) {
612
- cache[p] = newValue;
613
- changed?.updated.add(bindingAsset.fileName);
614
- return true;
615
- }
616
- });
617
- }
618
- function transformToRollupOutput(output, changed) {
619
- handleOutputErrors(output);
620
- const { chunks, assets } = output;
621
- return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
622
- }
623
- function handleOutputErrors(output) {
624
- const rawErrors = output.errors;
625
- if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
626
- }
627
- function transformToOutputBundle(output, changed) {
628
- const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
629
- return new Proxy(bundle, { deleteProperty(target, property) {
630
- if (typeof property === "string") changed.deleted.add(property);
631
- return true;
632
- } });
633
- }
634
- function collectChangedBundle(changed, bundle) {
635
- const assets = [];
636
- const chunks = [];
637
- for (const key in bundle) {
638
- if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
639
- const item = bundle[key];
640
- if (item.type === "asset") assets.push({
641
- filename: item.fileName,
642
- originalFileNames: item.originalFileNames,
643
- source: bindingAssetSource(item.source),
644
- names: item.names
645
- });
646
- else chunks.push({
647
- code: item.code,
648
- filename: item.fileName,
649
- name: item.name,
650
- isEntry: item.isEntry,
651
- exports: item.exports,
652
- modules: {},
653
- imports: item.imports,
654
- dynamicImports: item.dynamicImports,
655
- facadeModuleId: item.facadeModuleId || undefined,
656
- isDynamicEntry: item.isDynamicEntry,
657
- moduleIds: item.moduleIds,
658
- map: bindingifySourcemap$1(item.map),
659
- sourcemapFilename: item.sourcemapFileName || undefined,
660
- preliminaryFilename: item.preliminaryFileName
661
- });
662
- }
663
- return {
664
- assets,
665
- chunks,
666
- deleted: Array.from(changed.deleted)
667
- };
668
- }
669
-
670
- //#endregion
671
- //#region src/utils/transform-sourcemap.ts
672
- function isEmptySourcemapFiled(array) {
673
- if (!array) return true;
674
- if (array.length === 0 || !array[0]) return true;
675
- return false;
676
- }
677
- function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
678
- if (!rawMap) return;
679
- let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
680
- if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
681
- if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
682
- return map;
683
- }
684
-
685
- //#endregion
686
- //#region src/utils/transform-module-info.ts
687
- function transformModuleInfo(info, option) {
688
- return {
689
- get ast() {
690
- return unsupported("ModuleInfo#ast");
691
- },
692
- get code() {
693
- return info.code;
694
- },
695
- id: info.id,
696
- importers: info.importers,
697
- dynamicImporters: info.dynamicImporters,
698
- importedIds: info.importedIds,
699
- dynamicallyImportedIds: info.dynamicallyImportedIds,
700
- exports: info.exports,
701
- isEntry: info.isEntry,
702
- ...option
703
- };
704
- }
705
-
706
- //#endregion
707
- //#region src/plugin/minimal-plugin-context.ts
708
- var MinimalPluginContext = class {
709
- info;
710
- warn;
711
- debug;
712
- meta;
713
- constructor(onLog, logLevel, pluginName) {
714
- this.pluginName = pluginName;
715
- this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
716
- this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
717
- this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
718
- this.meta = {
719
- rollupVersion: "4.23.0",
720
- rolldownVersion: VERSION,
721
- watchMode: false
722
- };
723
- }
724
- error(e) {
725
- return error(logPluginError(normalizeLog(e), this.pluginName));
726
- }
727
- };
728
-
729
- //#endregion
730
- //#region src/utils/transform-side-effects.ts
731
- function bindingifySideEffects(sideEffects) {
732
- switch (sideEffects) {
733
- case true: return import_binding.BindingHookSideEffects.True;
734
- case false: return import_binding.BindingHookSideEffects.False;
735
- case "no-treeshake": return import_binding.BindingHookSideEffects.NoTreeshake;
736
- case null:
737
- case undefined: return undefined;
738
- default: throw new Error(`Unexpected side effects: ${sideEffects}`);
739
- }
740
- }
741
-
742
- //#endregion
743
- //#region src/plugin/plugin-context.ts
744
- var PluginContext = class extends MinimalPluginContext {
745
- constructor(context, plugin, data, onLog, logLevel, currentLoadingModule) {
746
- super(onLog, logLevel, plugin.name);
747
- this.context = context;
748
- this.data = data;
749
- this.onLog = onLog;
750
- this.currentLoadingModule = currentLoadingModule;
751
- }
752
- async load(options) {
753
- const id = options.id;
754
- if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
755
- const moduleInfo = this.data.getModuleInfo(id, this.context);
756
- if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
757
- const rawOptions = {
758
- meta: options.meta || {},
759
- moduleSideEffects: options.moduleSideEffects || null
760
- };
761
- this.data.updateModuleOption(id, rawOptions);
762
- async function createLoadModulePromise(context, data) {
763
- const loadPromise = data.loadModulePromiseMap.get(id);
764
- if (loadPromise) return loadPromise;
765
- let resolveFn;
766
- const promise = new Promise((resolve, _) => {
767
- resolveFn = resolve;
768
- });
769
- data.loadModulePromiseMap.set(id, promise);
770
- try {
771
- await context.load(id, bindingifySideEffects(options.moduleSideEffects), resolveFn);
772
- } finally {
773
- data.loadModulePromiseMap.delete(id);
774
- }
775
- return promise;
776
- }
777
- await createLoadModulePromise(this.context, this.data);
778
- return this.data.getModuleInfo(id, this.context);
779
- }
780
- async resolve(source, importer, options) {
781
- let receipt = undefined;
782
- if (options != null) receipt = this.data.saveResolveOptions(options);
783
- const res = await this.context.resolve(source, importer, {
784
- custom: receipt,
785
- skipSelf: options?.skipSelf
786
- });
787
- if (receipt != null) this.data.removeSavedResolveOptions(receipt);
788
- if (res == null) return null;
789
- const info = this.data.getModuleOption(res.id) || {};
790
- return {
791
- ...res,
792
- ...info
793
- };
794
- }
795
- emitFile(file) {
796
- if (file.type === "prebuilt-chunk") return unimplemented("PluginContext.emitFile with type prebuilt-chunk");
797
- if (file.type === "chunk") return this.context.emitChunk(file);
798
- return this.context.emitFile({
799
- ...file,
800
- originalFileName: file.originalFileName || undefined,
801
- source: bindingAssetSource(file.source)
802
- });
803
- }
804
- getFileName(referenceId) {
805
- return this.context.getFileName(referenceId);
806
- }
807
- getModuleInfo(id) {
808
- return this.data.getModuleInfo(id, this.context);
809
- }
810
- getModuleIds() {
811
- return this.data.getModuleIds(this.context);
812
- }
813
- addWatchFile(id) {
814
- this.context.addWatchFile(id);
815
- }
816
- /**
817
- * @deprecated This rollup API won't be supported by rolldown. Using this API will cause runtime error.
818
- */
819
- parse(_input, _options) {
820
- unsupported("`PluginContext#parse` is not supported by rolldown.");
821
- }
822
- };
823
-
824
- //#endregion
825
- //#region src/plugin/transform-plugin-context.ts
826
- var TransformPluginContext = class extends PluginContext {
827
- constructor(context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption) {
828
- super(context, plugin, data, onLog, LogLevelOption, moduleId);
829
- this.inner = inner;
830
- this.moduleId = moduleId;
831
- this.moduleSource = moduleSource;
832
- const getLogHandler$1 = (handler) => (log, pos) => {
833
- log = normalizeLog(log);
834
- if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
835
- log.id = moduleId;
836
- log.hook = "transform";
837
- handler(log);
838
- };
839
- this.debug = getLogHandler$1(this.debug);
840
- this.warn = getLogHandler$1(this.warn);
841
- this.info = getLogHandler$1(this.info);
842
- }
843
- error(e, pos) {
844
- if (typeof e === "string") e = { message: e };
845
- if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
846
- e.id = this.moduleId;
847
- e.hook = "transform";
848
- return error(logPluginError(normalizeLog(e), this.pluginName));
849
- }
850
- getCombinedSourcemap() {
851
- return JSON.parse(this.inner.getCombinedSourcemap());
852
- }
853
- };
854
-
855
- //#endregion
856
- //#region src/plugin/bindingify-plugin-hook-meta.ts
857
- function bindingifyPluginHookMeta(options) {
858
- return { order: bindingPluginOrder(options.order) };
859
- }
860
- function bindingPluginOrder(order) {
861
- switch (order) {
862
- case "post": return import_binding.BindingPluginOrder.Post;
863
- case "pre": return import_binding.BindingPluginOrder.Pre;
864
- case null:
865
- case undefined: return undefined;
866
- default: throw new Error(`Unknown plugin order: ${order}`);
867
- }
868
- }
869
-
870
- //#endregion
871
- //#region src/constants/plugin-context.ts
872
- const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol("plugin-context-resolve-caller");
873
-
874
- //#endregion
875
- //#region src/plugin/bindingify-hook-filter.ts
876
- function bindingifyStringFilter(matcher) {
877
- if (typeof matcher === "string" || matcher instanceof RegExp) return { include: [matcher] };
878
- if (Array.isArray(matcher)) return { include: matcher };
879
- return {
880
- include: matcher.include ? arraify(matcher.include) : undefined,
881
- exclude: matcher.exclude ? arraify(matcher.exclude) : undefined
882
- };
883
- }
884
- function bindingifyResolveIdFilter(filterOption) {
885
- return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
886
- }
887
- function bindingifyLoadFilter(filterOption) {
888
- return filterOption?.id ? bindingifyStringFilter(filterOption.id) : undefined;
889
- }
890
- function bindingifyTransformFilter(filterOption) {
891
- if (!filterOption) return undefined;
892
- const { id, code, moduleType } = filterOption;
893
- let moduleTypeRet;
894
- if (moduleType) if (Array.isArray(moduleType)) moduleTypeRet = moduleType;
895
- else moduleTypeRet = moduleType.include;
896
- return {
897
- id: id ? bindingifyStringFilter(id) : undefined,
898
- code: code ? bindingifyStringFilter(code) : undefined,
899
- moduleType: moduleTypeRet
900
- };
901
- }
902
-
903
- //#endregion
904
- //#region src/options/normalized-input-options.ts
905
- var NormalizedInputOptionsImpl = class {
906
- inner;
907
- constructor(inner, onLog) {
908
- this.onLog = onLog;
909
- this.inner = inner;
910
- }
911
- get shimMissingExports() {
912
- return this.inner.shimMissingExports;
913
- }
914
- get input() {
915
- return this.inner.input;
916
- }
917
- get cwd() {
918
- return this.inner.cwd ?? undefined;
919
- }
920
- get platform() {
921
- return this.inner.platform;
922
- }
923
- };
924
-
925
- //#endregion
926
- //#region src/plugin/bindingify-build-hooks.ts
927
- function bindingifyBuildStart(args) {
928
- const hook = args.plugin.buildStart;
929
- if (!hook) return {};
930
- const { handler, meta } = normalizeHook(hook);
931
- return {
932
- plugin: async (ctx, opts) => {
933
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedInputOptionsImpl(opts, args.onLog));
934
- },
935
- meta: bindingifyPluginHookMeta(meta)
936
- };
937
- }
938
- function bindingifyBuildEnd(args) {
939
- const hook = args.plugin.buildEnd;
940
- if (!hook) return {};
941
- const { handler, meta } = normalizeHook(hook);
942
- return {
943
- plugin: async (ctx, err) => {
944
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
945
- },
946
- meta: bindingifyPluginHookMeta(meta)
947
- };
948
- }
949
- function bindingifyResolveId(args) {
950
- const hook = args.plugin.resolveId;
951
- if (!hook) return {};
952
- const { handler, meta, options } = normalizeHook(hook);
953
- return {
954
- plugin: async (ctx, specifier, importer, extraOptions) => {
955
- const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : undefined;
956
- const newExtraOptions = {
957
- ...extraOptions,
958
- custom: contextResolveOptions?.custom,
959
- [SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]: contextResolveOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF]
960
- };
961
- const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? undefined, newExtraOptions);
962
- if (ret == null) return;
963
- if (ret === false) return {
964
- id: specifier,
965
- external: true
966
- };
967
- if (typeof ret === "string") return { id: ret };
968
- args.pluginContextData.updateModuleOption(ret.id, {
969
- meta: ret.meta || {},
970
- moduleSideEffects: ret.moduleSideEffects || null
971
- });
972
- return {
973
- id: ret.id,
974
- external: ret.external,
975
- sideEffects: bindingifySideEffects(ret.moduleSideEffects)
976
- };
977
- },
978
- meta: bindingifyPluginHookMeta(meta),
979
- filter: bindingifyResolveIdFilter(options.filter)
980
- };
981
- }
982
- function bindingifyResolveDynamicImport(args) {
983
- const hook = args.plugin.resolveDynamicImport;
984
- if (!hook) return {};
985
- const { handler, meta } = normalizeHook(hook);
986
- return {
987
- plugin: async (ctx, specifier, importer) => {
988
- const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), specifier, importer ?? undefined);
989
- if (ret == null) return;
990
- if (ret === false) return {
991
- id: specifier,
992
- external: true
993
- };
994
- if (typeof ret === "string") return { id: ret };
995
- const result = {
996
- id: ret.id,
997
- external: ret.external
998
- };
999
- if (ret.moduleSideEffects !== null) result.sideEffects = bindingifySideEffects(ret.moduleSideEffects);
1000
- args.pluginContextData.updateModuleOption(ret.id, {
1001
- meta: ret.meta || {},
1002
- moduleSideEffects: ret.moduleSideEffects || null
1003
- });
1004
- return result;
1005
- },
1006
- meta: bindingifyPluginHookMeta(meta)
1007
- };
1008
- }
1009
- function bindingifyTransform(args) {
1010
- const hook = args.plugin.transform;
1011
- if (!hook) return {};
1012
- const { handler, meta, options } = normalizeHook(hook);
1013
- return {
1014
- plugin: async (ctx, code, id, meta$1) => {
1015
- const ret = await handler.call(new TransformPluginContext(ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel), code, id, meta$1);
1016
- if (ret == null) return undefined;
1017
- if (typeof ret === "string") return { code: ret };
1018
- args.pluginContextData.updateModuleOption(id, {
1019
- meta: ret.meta || {},
1020
- moduleSideEffects: ret.moduleSideEffects || null
1021
- });
1022
- return {
1023
- code: ret.code,
1024
- map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id, code, ret.map)),
1025
- sideEffects: bindingifySideEffects(ret.moduleSideEffects),
1026
- moduleType: ret.moduleType
1027
- };
1028
- },
1029
- meta: bindingifyPluginHookMeta(meta),
1030
- filter: bindingifyTransformFilter(options.filter)
1031
- };
1032
- }
1033
- function bindingifyLoad(args) {
1034
- const hook = args.plugin.load;
1035
- if (!hook) return {};
1036
- const { handler, meta, options } = normalizeHook(hook);
1037
- return {
1038
- plugin: async (ctx, id) => {
1039
- const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, id), id);
1040
- if (ret == null) return;
1041
- if (typeof ret === "string") return { code: ret };
1042
- args.pluginContextData.updateModuleOption(id, {
1043
- meta: ret.meta || {},
1044
- moduleSideEffects: ret.moduleSideEffects || null
1045
- });
1046
- let map = preProcessSourceMap(ret, id);
1047
- return {
1048
- code: ret.code,
1049
- map: bindingifySourcemap$1(map),
1050
- moduleType: ret.moduleType,
1051
- sideEffects: bindingifySideEffects(ret.moduleSideEffects)
1052
- };
1053
- },
1054
- meta: bindingifyPluginHookMeta(meta),
1055
- filter: bindingifyLoadFilter(options.filter)
1056
- };
1057
- }
1058
- function preProcessSourceMap(ret, id) {
1059
- if (!ret.map) return;
1060
- let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
1061
- if (!isEmptySourcemapFiled(map.sources)) {
1062
- const directory = path.dirname(id) || ".";
1063
- const sourceRoot = map.sourceRoot || ".";
1064
- map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
1065
- }
1066
- return map;
1067
- }
1068
- function bindingifyModuleParsed(args) {
1069
- const hook = args.plugin.moduleParsed;
1070
- if (!hook) return {};
1071
- const { handler, meta } = normalizeHook(hook);
1072
- return {
1073
- plugin: async (ctx, moduleInfo) => {
1074
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
1075
- },
1076
- meta: bindingifyPluginHookMeta(meta)
1077
- };
1078
- }
1079
-
1080
- //#endregion
1081
- //#region src/options/normalized-output-options.ts
1082
- function mapFunctionOption(option, name) {
1083
- return typeof option === "undefined" ? () => {
1084
- unsupported(`You should not take \`NormalizedOutputOptions#${name}\` and call it directly`);
1085
- } : option;
1086
- }
1087
- var NormalizedOutputOptionsImpl = class {
1088
- inner;
1089
- constructor(inner) {
1090
- this.inner = inner;
1091
- }
1092
- get dir() {
1093
- return this.inner.dir ?? undefined;
1094
- }
1095
- get entryFileNames() {
1096
- return mapFunctionOption(this.inner.entryFilenames, "entryFileNames");
1097
- }
1098
- get chunkFileNames() {
1099
- return mapFunctionOption(this.inner.chunkFilenames, "chunkFileNames");
1100
- }
1101
- get assetFileNames() {
1102
- return this.inner.assetFilenames;
1103
- }
1104
- get format() {
1105
- return this.inner.format;
1106
- }
1107
- get exports() {
1108
- return this.inner.exports;
1109
- }
1110
- get sourcemap() {
1111
- return this.inner.sourcemap;
1112
- }
1113
- get cssEntryFileNames() {
1114
- return mapFunctionOption(this.inner.cssEntryFilenames, "cssEntryFileNames");
1115
- }
1116
- get cssChunkFileNames() {
1117
- return mapFunctionOption(this.inner.cssChunkFilenames, "cssChunkFileNames");
1118
- }
1119
- get shimMissingExports() {
1120
- return this.inner.shimMissingExports;
1121
- }
1122
- get name() {
1123
- return this.inner.name ?? undefined;
1124
- }
1125
- get file() {
1126
- return this.inner.file ?? undefined;
1127
- }
1128
- get inlineDynamicImports() {
1129
- return this.inner.inlineDynamicImports;
1130
- }
1131
- get externalLiveBindings() {
1132
- return this.inner.externalLiveBindings;
1133
- }
1134
- get banner() {
1135
- return mapFunctionOption(this.inner.banner, "banner") ?? undefined;
1136
- }
1137
- get footer() {
1138
- return mapFunctionOption(this.inner.footer, "footer") ?? undefined;
1139
- }
1140
- get intro() {
1141
- return mapFunctionOption(this.inner.intro, "intro") ?? undefined;
1142
- }
1143
- get outro() {
1144
- return mapFunctionOption(this.inner.outro, "outro") ?? undefined;
1145
- }
1146
- get esModule() {
1147
- return this.inner.esModule;
1148
- }
1149
- get extend() {
1150
- return this.inner.extend;
1151
- }
1152
- get globals() {
1153
- return mapFunctionOption(this.inner.globals, "globals");
1154
- }
1155
- get hashCharacters() {
1156
- return this.inner.hashCharacters;
1157
- }
1158
- get sourcemapDebugIds() {
1159
- return this.inner.sourcemapDebugIds;
1160
- }
1161
- get sourcemapIgnoreList() {
1162
- return mapFunctionOption(void 0, "sourcemapIgnoreList");
1163
- }
1164
- get sourcemapPathTransform() {
1165
- return mapFunctionOption(void 0, "sourcemapPathTransform");
1166
- }
1167
- get minify() {
1168
- return this.inner.minify;
1169
- }
1170
- get comments() {
1171
- return this.inner.comments;
1172
- }
1173
- get polyfillRequire() {
1174
- return this.inner.polyfillRequire;
1175
- }
1176
- };
1177
-
1178
- //#endregion
1179
- //#region src/plugin/bindingify-output-hooks.ts
1180
- function bindingifyRenderStart(args) {
1181
- const hook = args.plugin.renderStart;
1182
- if (!hook) return {};
1183
- const { handler, meta } = normalizeHook(hook);
1184
- return {
1185
- plugin: async (ctx, opts) => {
1186
- handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), new NormalizedInputOptionsImpl(opts, args.onLog));
1187
- },
1188
- meta: bindingifyPluginHookMeta(meta)
1189
- };
1190
- }
1191
- function bindingifyRenderChunk(args) {
1192
- const hook = args.plugin.renderChunk;
1193
- if (!hook) return {};
1194
- const { handler, meta } = normalizeHook(hook);
1195
- return {
1196
- plugin: async (ctx, code, chunk, opts) => {
1197
- const ret = await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), code, transformRenderedChunk(chunk), new NormalizedOutputOptionsImpl(opts));
1198
- if (ret == null) return;
1199
- if (typeof ret === "string") return { code: ret };
1200
- if (!ret.map) return { code: ret.code };
1201
- return {
1202
- code: ret.code,
1203
- map: bindingifySourcemap$1(ret.map)
1204
- };
1205
- },
1206
- meta: bindingifyPluginHookMeta(meta)
1207
- };
1208
- }
1209
- function bindingifyAugmentChunkHash(args) {
1210
- const hook = args.plugin.augmentChunkHash;
1211
- if (!hook) return {};
1212
- const { handler, meta } = normalizeHook(hook);
1213
- return {
1214
- plugin: async (ctx, chunk) => {
1215
- return await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1216
- },
1217
- meta: bindingifyPluginHookMeta(meta)
1218
- };
1219
- }
1220
- function bindingifyRenderError(args) {
1221
- const hook = args.plugin.renderError;
1222
- if (!hook) return {};
1223
- const { handler, meta } = normalizeHook(hook);
1224
- return {
1225
- plugin: async (ctx, err) => {
1226
- handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
1227
- },
1228
- meta: bindingifyPluginHookMeta(meta)
1229
- };
1230
- }
1231
- function bindingifyGenerateBundle(args) {
1232
- const hook = args.plugin.generateBundle;
1233
- if (!hook) return {};
1234
- const { handler, meta } = normalizeHook(hook);
1235
- return {
1236
- plugin: async (ctx, bundle, isWrite, opts) => {
1237
- const changed = {
1238
- updated: new Set(),
1239
- deleted: new Set()
1240
- };
1241
- const output = transformToOutputBundle(bundle, changed);
1242
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output, isWrite);
1243
- return collectChangedBundle(changed, output);
1244
- },
1245
- meta: bindingifyPluginHookMeta(meta)
1246
- };
1247
- }
1248
- function bindingifyWriteBundle(args) {
1249
- const hook = args.plugin.writeBundle;
1250
- if (!hook) return {};
1251
- const { handler, meta } = normalizeHook(hook);
1252
- return {
1253
- plugin: async (ctx, bundle, opts) => {
1254
- const changed = {
1255
- updated: new Set(),
1256
- deleted: new Set()
1257
- };
1258
- const output = transformToOutputBundle(bundle, changed);
1259
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new NormalizedOutputOptionsImpl(opts), output);
1260
- return collectChangedBundle(changed, output);
1261
- },
1262
- meta: bindingifyPluginHookMeta(meta)
1263
- };
1264
- }
1265
- function bindingifyCloseBundle(args) {
1266
- const hook = args.plugin.closeBundle;
1267
- if (!hook) return {};
1268
- const { handler, meta } = normalizeHook(hook);
1269
- return {
1270
- plugin: async (ctx) => {
1271
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
1272
- },
1273
- meta: bindingifyPluginHookMeta(meta)
1274
- };
1275
- }
1276
- function bindingifyBanner(args) {
1277
- const hook = args.plugin.banner;
1278
- if (!hook) return {};
1279
- const { handler, meta } = normalizeHook(hook);
1280
- return {
1281
- plugin: async (ctx, chunk) => {
1282
- if (typeof handler === "string") return handler;
1283
- return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1284
- },
1285
- meta: bindingifyPluginHookMeta(meta)
1286
- };
1287
- }
1288
- function bindingifyFooter(args) {
1289
- const hook = args.plugin.footer;
1290
- if (!hook) return {};
1291
- const { handler, meta } = normalizeHook(hook);
1292
- return {
1293
- plugin: async (ctx, chunk) => {
1294
- if (typeof handler === "string") return handler;
1295
- return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1296
- },
1297
- meta: bindingifyPluginHookMeta(meta)
1298
- };
1299
- }
1300
- function bindingifyIntro(args) {
1301
- const hook = args.plugin.intro;
1302
- if (!hook) return {};
1303
- const { handler, meta } = normalizeHook(hook);
1304
- return {
1305
- plugin: async (ctx, chunk) => {
1306
- if (typeof handler === "string") return handler;
1307
- return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1308
- },
1309
- meta: bindingifyPluginHookMeta(meta)
1310
- };
1311
- }
1312
- function bindingifyOutro(args) {
1313
- const hook = args.plugin.outro;
1314
- if (!hook) return {};
1315
- const { handler, meta } = normalizeHook(hook);
1316
- return {
1317
- plugin: async (ctx, chunk) => {
1318
- if (typeof handler === "string") return handler;
1319
- return handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), transformRenderedChunk(chunk));
1320
- },
1321
- meta: bindingifyPluginHookMeta(meta)
1322
- };
1323
- }
1324
-
1325
- //#endregion
1326
- //#region src/plugin/bindingify-watch-hooks.ts
1327
- function bindingifyWatchChange(args) {
1328
- const hook = args.plugin.watchChange;
1329
- if (!hook) return {};
1330
- const { handler, meta } = normalizeHook(hook);
1331
- return {
1332
- plugin: async (ctx, id, event) => {
1333
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), id, { event });
1334
- },
1335
- meta: bindingifyPluginHookMeta(meta)
1336
- };
1337
- }
1338
- function bindingifyCloseWatcher(args) {
1339
- const hook = args.plugin.closeWatcher;
1340
- if (!hook) return {};
1341
- const { handler, meta } = normalizeHook(hook);
1342
- return {
1343
- plugin: async (ctx) => {
1344
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel));
1345
- },
1346
- meta: bindingifyPluginHookMeta(meta)
1347
- };
1348
- }
1349
-
1350
- //#endregion
1351
- //#region src/plugin/bindingify-plugin.ts
1352
- function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, onLog, logLevel) {
1353
- const args = {
1354
- plugin,
1355
- options,
1356
- outputOptions,
1357
- pluginContextData,
1358
- onLog,
1359
- logLevel
1360
- };
1361
- const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
1362
- const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
1363
- const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
1364
- const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
1365
- const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
1366
- const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
1367
- const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
1368
- const { plugin: renderChunk, meta: renderChunkMeta } = bindingifyRenderChunk(args);
1369
- const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
1370
- const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
1371
- const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
1372
- const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
1373
- const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
1374
- const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
1375
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
1376
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
1377
- const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
1378
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
1379
- const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
1380
- const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
1381
- const result = {
1382
- name: plugin.name,
1383
- buildStart,
1384
- buildStartMeta,
1385
- resolveId,
1386
- resolveIdMeta,
1387
- resolveIdFilter,
1388
- resolveDynamicImport,
1389
- resolveDynamicImportMeta,
1390
- buildEnd,
1391
- buildEndMeta,
1392
- transform,
1393
- transformMeta,
1394
- transformFilter,
1395
- moduleParsed,
1396
- moduleParsedMeta,
1397
- load,
1398
- loadMeta,
1399
- loadFilter,
1400
- renderChunk,
1401
- renderChunkMeta,
1402
- augmentChunkHash,
1403
- augmentChunkHashMeta,
1404
- renderStart,
1405
- renderStartMeta,
1406
- renderError,
1407
- renderErrorMeta,
1408
- generateBundle,
1409
- generateBundleMeta,
1410
- writeBundle,
1411
- writeBundleMeta,
1412
- closeBundle,
1413
- closeBundleMeta,
1414
- banner,
1415
- bannerMeta,
1416
- footer,
1417
- footerMeta,
1418
- intro,
1419
- introMeta,
1420
- outro,
1421
- outroMeta,
1422
- watchChange,
1423
- watchChangeMeta,
1424
- closeWatcher,
1425
- closeWatcherMeta
1426
- };
1427
- return wrapHandlers(result);
1428
- }
1429
- function wrapHandlers(plugin) {
1430
- for (const hookName of [
1431
- "buildStart",
1432
- "resolveId",
1433
- "resolveDynamicImport",
1434
- "buildEnd",
1435
- "transform",
1436
- "moduleParsed",
1437
- "load",
1438
- "renderChunk",
1439
- "augmentChunkHash",
1440
- "renderStart",
1441
- "renderError",
1442
- "generateBundle",
1443
- "writeBundle",
1444
- "closeBundle",
1445
- "banner",
1446
- "footer",
1447
- "intro",
1448
- "outro",
1449
- "watchChange",
1450
- "closeWatcher"
1451
- ]) {
1452
- const handler = plugin[hookName];
1453
- if (handler) plugin[hookName] = async (...args) => {
1454
- try {
1455
- return await handler(...args);
1456
- } catch (e) {
1457
- return error(logPluginError(e, plugin.name, {
1458
- hook: hookName,
1459
- id: hookName === "transform" ? args[2] : undefined
1460
- }));
1461
- }
1462
- };
1463
- }
1464
- return plugin;
1465
- }
1466
-
1467
- //#endregion
1468
- //#region src/plugin/plugin-context-data.ts
1469
- var PluginContextData = class {
1470
- moduleOptionMap = new Map();
1471
- resolveOptionsMap = new Map();
1472
- loadModulePromiseMap = new Map();
1473
- updateModuleOption(id, option) {
1474
- const existing = this.moduleOptionMap.get(id);
1475
- if (existing) {
1476
- if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
1477
- if (option.meta != null) Object.assign(existing.meta, option.meta);
1478
- } else this.moduleOptionMap.set(id, option);
1479
- }
1480
- getModuleOption(id) {
1481
- const option = this.moduleOptionMap.get(id);
1482
- if (!option) {
1483
- const raw = {
1484
- moduleSideEffects: null,
1485
- meta: {}
1486
- };
1487
- this.moduleOptionMap.set(id, raw);
1488
- return raw;
1489
- }
1490
- return option;
1491
- }
1492
- getModuleInfo(id, context) {
1493
- const bindingInfo = context.getModuleInfo(id);
1494
- if (bindingInfo) {
1495
- const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
1496
- return info;
1497
- }
1498
- return null;
1499
- }
1500
- getModuleIds(context) {
1501
- const moduleIds = context.getModuleIds();
1502
- return moduleIds.values();
1503
- }
1504
- saveResolveOptions(options) {
1505
- const index = this.resolveOptionsMap.size;
1506
- this.resolveOptionsMap.set(index, options);
1507
- return index;
1508
- }
1509
- getSavedResolveOptions(receipt) {
1510
- return this.resolveOptionsMap.get(receipt);
1511
- }
1512
- removeSavedResolveOptions(receipt) {
1513
- this.resolveOptionsMap.delete(receipt);
1514
- }
1515
- };
1516
-
1517
- //#endregion
1518
- //#region src/utils/normalize-string-or-regex.ts
1519
- function normalizedStringOrRegex(pattern) {
1520
- if (!pattern) return undefined;
1521
- if (!Array.isArray(pattern)) pattern = [pattern];
1522
- return pattern;
1523
- }
1524
-
1525
- //#endregion
1526
- //#region src/utils/bindingify-input-options.ts
1527
- function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
1528
- const pluginContextData = new PluginContextData();
1529
- const plugins = rawPlugins.map((plugin) => {
1530
- if ("_parallel" in plugin) return undefined;
1531
- if (plugin instanceof BuiltinPlugin) return bindingifyBuiltInPlugin(plugin);
1532
- return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, onLog, logLevel);
1533
- });
1534
- return {
1535
- input: bindingifyInput(inputOptions.input),
1536
- plugins,
1537
- cwd: inputOptions.cwd ?? process.cwd(),
1538
- external: bindingifyExternal(inputOptions.external),
1539
- resolve: bindingifyResolve(inputOptions.resolve),
1540
- platform: inputOptions.platform,
1541
- shimMissingExports: inputOptions.shimMissingExports,
1542
- logLevel: bindingifyLogLevel(logLevel),
1543
- onLog,
1544
- treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
1545
- moduleTypes: inputOptions.moduleTypes,
1546
- define: inputOptions.define ? Object.entries(inputOptions.define) : undefined,
1547
- inject: bindingifyInject(inputOptions.inject),
1548
- experimental: {
1549
- strictExecutionOrder: inputOptions.experimental?.strictExecutionOrder,
1550
- disableLiveBindings: inputOptions.experimental?.disableLiveBindings,
1551
- viteMode: inputOptions.experimental?.viteMode,
1552
- resolveNewUrlToAsset: inputOptions.experimental?.resolveNewUrlToAsset
1553
- },
1554
- profilerNames: inputOptions?.profilerNames,
1555
- jsx: bindingifyJsx(inputOptions.jsx),
1556
- watch: bindingifyWatch(inputOptions.watch),
1557
- dropLabels: inputOptions.dropLabels,
1558
- keepNames: inputOptions.keepNames,
1559
- checks: inputOptions.checks
1560
- };
1561
- }
1562
- function bindingifyExternal(external) {
1563
- if (external) {
1564
- if (typeof external === "function") return (id, importer, isResolved) => {
1565
- if (id.startsWith("\0")) return false;
1566
- return external(id, importer, isResolved) ?? false;
1567
- };
1568
- const externalArr = arraify(external);
1569
- return (id, _importer, _isResolved) => {
1570
- return externalArr.some((pat) => {
1571
- if (pat instanceof RegExp) return pat.test(id);
1572
- return id === pat;
1573
- });
1574
- };
1575
- }
1576
- }
1577
- function bindingifyResolve(resolve) {
1578
- if (resolve) {
1579
- const { alias, extensionAlias,...rest } = resolve;
1580
- return {
1581
- alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
1582
- find: name,
1583
- replacements: arraify(replacement)
1584
- })) : undefined,
1585
- extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
1586
- target: name,
1587
- replacements: value
1588
- })) : undefined,
1589
- ...rest
1590
- };
1591
- }
1592
- }
1593
- function bindingifyInject(inject) {
1594
- if (inject) return Object.entries(inject).map(([alias, item]) => {
1595
- if (Array.isArray(item)) {
1596
- if (item[1] === "*") return {
1597
- tagNamespace: true,
1598
- alias,
1599
- from: item[0]
1600
- };
1601
- return {
1602
- tagNamed: true,
1603
- alias,
1604
- from: item[0],
1605
- imported: item[1]
1606
- };
1607
- } else return {
1608
- tagNamed: true,
1609
- imported: "default",
1610
- alias,
1611
- from: item
1612
- };
1613
- });
1614
- }
1615
- function bindingifyLogLevel(logLevel) {
1616
- switch (logLevel) {
1617
- case "silent": return import_binding.BindingLogLevel.Silent;
1618
- case "debug": return import_binding.BindingLogLevel.Debug;
1619
- case "warn": return import_binding.BindingLogLevel.Warn;
1620
- case "info": return import_binding.BindingLogLevel.Info;
1621
- default: throw new Error(`Unexpected log level: ${logLevel}`);
1622
- }
1623
- }
1624
- function bindingifyInput(input) {
1625
- if (input === undefined) return [];
1626
- if (typeof input === "string") return [{ import: input }];
1627
- if (Array.isArray(input)) return input.map((src) => ({ import: src }));
1628
- return Object.entries(input).map((value) => {
1629
- return {
1630
- name: value[0],
1631
- import: value[1]
1632
- };
1633
- });
1634
- }
1635
- function bindingifyJsx(input) {
1636
- if (input === false) return { type: "Disable" };
1637
- if (input) {
1638
- if (input.mode === "preserve") return { type: "Preserve" };
1639
- const mode = input.mode ?? "automatic";
1640
- return {
1641
- type: "Enable",
1642
- field0: {
1643
- runtime: mode,
1644
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : undefined,
1645
- pragma: input.factory,
1646
- pragmaFrag: input.fragment,
1647
- development: input.development,
1648
- refresh: input.refresh
1649
- }
1650
- };
1651
- }
1652
- }
1653
- function bindingifyWatch(watch$1) {
1654
- if (watch$1) {
1655
- let value = {
1656
- skipWrite: watch$1.skipWrite,
1657
- include: normalizedStringOrRegex(watch$1.include),
1658
- exclude: normalizedStringOrRegex(watch$1.exclude)
1659
- };
1660
- if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
1661
- return value;
1662
- }
1663
- }
1664
- function bindingifyTreeshakeOptions(config) {
1665
- if (config === false) return undefined;
1666
- if (config === true || config === undefined) return {
1667
- moduleSideEffects: true,
1668
- annotations: true
1669
- };
1670
- let normalizedConfig = { moduleSideEffects: true };
1671
- if (config.moduleSideEffects === undefined) normalizedConfig.moduleSideEffects = true;
1672
- else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
1673
- external: true,
1674
- sideEffects: false
1675
- }, {
1676
- external: false,
1677
- sideEffects: true
1678
- }];
1679
- else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
1680
- normalizedConfig.annotations = config.annotations ?? true;
1681
- return normalizedConfig;
1682
- }
1683
-
1684
- //#endregion
1685
- //#region src/utils/bindingify-output-options.ts
1686
- function bindingifyOutputOptions(outputOptions) {
1687
- const { dir, format, exports, hashCharacters, sourcemap, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file } = outputOptions;
1688
- return {
1689
- dir,
1690
- file: file == null ? undefined : file,
1691
- format: bindingifyFormat(format),
1692
- exports,
1693
- hashCharacters,
1694
- sourcemap: bindingifySourcemap(sourcemap),
1695
- sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
1696
- sourcemapPathTransform,
1697
- banner: bindingifyAddon(banner),
1698
- footer: bindingifyAddon(footer),
1699
- intro: bindingifyAddon(intro),
1700
- outro: bindingifyAddon(outro),
1701
- extend: outputOptions.extend,
1702
- globals,
1703
- esModule,
1704
- name,
1705
- assetFileNames,
1706
- entryFileNames,
1707
- chunkFileNames,
1708
- cssEntryFileNames,
1709
- cssChunkFileNames,
1710
- plugins: [],
1711
- minify: outputOptions.minify,
1712
- externalLiveBindings: outputOptions.externalLiveBindings,
1713
- inlineDynamicImports: outputOptions.inlineDynamicImports,
1714
- advancedChunks: outputOptions.advancedChunks,
1715
- polyfillRequire: outputOptions.polyfillRequire,
1716
- target: outputOptions.target
1717
- };
1718
- }
1719
- function bindingifyAddon(configAddon) {
1720
- return async (chunk) => {
1721
- if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
1722
- return configAddon || "";
1723
- };
1724
- }
1725
- function bindingifyFormat(format) {
1726
- switch (format) {
1727
- case undefined:
1728
- case "es":
1729
- case "esm":
1730
- case "module": return "es";
1731
- case "cjs":
1732
- case "commonjs": return "cjs";
1733
- case "iife": return "iife";
1734
- case "umd": return "umd";
1735
- case "experimental-app": return "app";
1736
- default: unimplemented(`output.format: ${format}`);
1737
- }
1738
- }
1739
- function bindingifySourcemap(sourcemap) {
1740
- switch (sourcemap) {
1741
- case true: return "file";
1742
- case "inline": return "inline";
1743
- case false:
1744
- case undefined: return undefined;
1745
- case "hidden": return "hidden";
1746
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
1747
- }
1748
- }
1749
- function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
1750
- return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
1751
- }
1752
-
1753
- //#endregion
1754
- //#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-K26VP6CL.js
1755
- function u$1(t$1, n, a) {
1756
- let o = (r) => t$1(r, ...n);
1757
- return a === void 0 ? o : Object.assign(o, {
1758
- lazy: a,
1759
- lazyArgs: n
1760
- });
1761
- }
1762
-
1763
- //#endregion
1764
- //#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-RAAYCPUM.js
1765
- function u(r, n, a) {
1766
- let o = r.length - n.length;
1767
- if (o === 0) return r(...n);
1768
- if (o === 1) return u$1(r, n, a);
1769
- throw new Error("Wrong number of arguments");
1770
- }
1771
-
1772
- //#endregion
1773
- //#region ../../node_modules/.pnpm/remeda@2.19.1/node_modules/remeda/dist/chunk-NMJS7ULY.js
1774
- function t(...n) {
1775
- return u(Object.keys, n);
1776
- }
1777
-
1778
- //#endregion
1779
- //#region src/utils/plugin/index.ts
1780
- const isPluginHookName = function() {
1781
- const PLUGIN_HOOK_NAMES_SET = new Set(ENUMERATED_PLUGIN_HOOK_NAMES);
1782
- return function isPluginHookName$1(hookName) {
1783
- return PLUGIN_HOOK_NAMES_SET.has(hookName);
1784
- };
1785
- }();
1786
-
1787
- //#endregion
1788
- //#region src/utils/compose-js-plugins.ts
1789
- const unsupportedHookName = [
1790
- "augmentChunkHash",
1791
- "generateBundle",
1792
- "moduleParsed",
1793
- "onLog",
1794
- "options",
1795
- "outputOptions",
1796
- "renderError",
1797
- "renderStart",
1798
- "resolveDynamicImport",
1799
- "writeBundle"
1800
- ];
1801
- const unsupportedHooks = new Set(unsupportedHookName);
1802
- function isUnsupportedHooks(hookName) {
1803
- return unsupportedHooks.has(hookName);
1804
- }
1805
- function createComposedPlugin(plugins) {
1806
- const names = [];
1807
- const batchedHooks = {};
1808
- plugins.forEach((plugin, index) => {
1809
- const pluginName = plugin.name || `Anonymous(index: ${index})`;
1810
- names.push(pluginName);
1811
- t(plugin).forEach((pluginProp) => {
1812
- if (isUnsupportedHooks(pluginProp)) throw new Error(`Failed to compose js plugins. Plugin ${pluginName} has an unsupported hook: ${pluginProp}`);
1813
- if (!isPluginHookName(pluginProp)) return;
1814
- switch (pluginProp) {
1815
- case "buildStart": {
1816
- const handlers = batchedHooks.buildStart ?? [];
1817
- batchedHooks.buildStart = handlers;
1818
- if (plugin.buildStart) handlers.push([plugin.buildStart, plugin]);
1819
- break;
1820
- }
1821
- case "load": {
1822
- const handlers = batchedHooks.load ?? [];
1823
- batchedHooks.load = handlers;
1824
- if (plugin.load) handlers.push([plugin.load, plugin]);
1825
- break;
1826
- }
1827
- case "transform": {
1828
- const handlers = batchedHooks.transform ?? [];
1829
- batchedHooks.transform = handlers;
1830
- if (plugin.transform) handlers.push([plugin.transform, plugin]);
1831
- break;
1832
- }
1833
- case "resolveId": {
1834
- const handlers = batchedHooks.resolveId ?? [];
1835
- batchedHooks.resolveId = handlers;
1836
- if (plugin.resolveId) handlers.push([plugin.resolveId, plugin]);
1837
- break;
1838
- }
1839
- case "buildEnd": {
1840
- const handlers = batchedHooks.buildEnd ?? [];
1841
- batchedHooks.buildEnd = handlers;
1842
- if (plugin.buildEnd) handlers.push([plugin.buildEnd, plugin]);
1843
- break;
1844
- }
1845
- case "renderChunk": {
1846
- const handlers = batchedHooks.renderChunk ?? [];
1847
- batchedHooks.renderChunk = handlers;
1848
- if (plugin.renderChunk) handlers.push([plugin.renderChunk, plugin]);
1849
- break;
1850
- }
1851
- case "banner":
1852
- case "footer":
1853
- case "intro":
1854
- case "outro": {
1855
- const hook = plugin[pluginProp];
1856
- if (hook) (batchedHooks[pluginProp] ??= []).push([hook, plugin]);
1857
- break;
1858
- }
1859
- case "closeBundle": {
1860
- const handlers = batchedHooks.closeBundle ?? [];
1861
- batchedHooks.closeBundle = handlers;
1862
- if (plugin.closeBundle) handlers.push([plugin.closeBundle, plugin]);
1863
- break;
1864
- }
1865
- case "watchChange": {
1866
- const handlers = batchedHooks.watchChange ?? [];
1867
- batchedHooks.watchChange = handlers;
1868
- if (plugin.watchChange) handlers.push([plugin.watchChange, plugin]);
1869
- break;
1870
- }
1871
- case "closeWatcher": {
1872
- const handlers = batchedHooks.closeWatcher ?? [];
1873
- batchedHooks.closeWatcher = handlers;
1874
- if (plugin.closeWatcher) handlers.push([plugin.closeWatcher, plugin]);
1875
- break;
1876
- }
1877
- default: {}
1878
- }
1879
- });
1880
- });
1881
- const composed = { name: `Composed(${names.join(", ")})` };
1882
- const createFixedPluginResolveFnMap = new Map();
1883
- function applyFixedPluginResolveFn(ctx, plugin) {
1884
- const createFixedPluginResolveFn = createFixedPluginResolveFnMap.get(plugin);
1885
- if (createFixedPluginResolveFn) ctx.resolve = createFixedPluginResolveFn(ctx, ctx.resolve.bind(ctx));
1886
- return ctx;
1887
- }
1888
- if (batchedHooks.resolveId) {
1889
- const batchedHandlers = batchedHooks.resolveId;
1890
- const handlerSymbols = batchedHandlers.map(([_handler, plugin]) => Symbol(plugin.name ?? `Anonymous`));
1891
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
1892
- const [_handler, plugin] = batchedHandlers[handlerIdx];
1893
- const handlerSymbol = handlerSymbols[handlerIdx];
1894
- const createFixedPluginResolveFn = (ctx, resolve) => {
1895
- return (source, importer, rawContextResolveOptions) => {
1896
- const contextResolveOptions = rawContextResolveOptions ?? {};
1897
- if (contextResolveOptions.skipSelf) {
1898
- contextResolveOptions[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF] = handlerSymbol;
1899
- contextResolveOptions.skipSelf = false;
1900
- }
1901
- return resolve(source, importer, contextResolveOptions);
1902
- };
1903
- };
1904
- createFixedPluginResolveFnMap.set(plugin, createFixedPluginResolveFn);
1905
- }
1906
- composed.resolveId = async function(source, importer, rawHookResolveIdOptions) {
1907
- const hookResolveIdOptions = rawHookResolveIdOptions;
1908
- const symbolForCallerThatSkipSelf = hookResolveIdOptions?.[SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF];
1909
- for (let handlerIdx = 0; handlerIdx < batchedHandlers.length; handlerIdx++) {
1910
- const [handler, plugin] = batchedHandlers[handlerIdx];
1911
- const handlerSymbol = handlerSymbols[handlerIdx];
1912
- if (symbolForCallerThatSkipSelf === handlerSymbol) continue;
1913
- const { handler: handlerFn } = normalizeHook(handler);
1914
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), source, importer, rawHookResolveIdOptions);
1915
- if (!isNullish(result)) return result;
1916
- }
1917
- };
1918
- }
1919
- t(batchedHooks).forEach((hookName) => {
1920
- switch (hookName) {
1921
- case "resolveId": break;
1922
- case "buildStart": {
1923
- if (batchedHooks.buildStart) {
1924
- const batchedHandlers = batchedHooks.buildStart;
1925
- composed.buildStart = async function(options) {
1926
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
1927
- const { handler: handlerFn } = normalizeHook(handler);
1928
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), options);
1929
- }));
1930
- };
1931
- }
1932
- break;
1933
- }
1934
- case "load": {
1935
- if (batchedHooks.load) {
1936
- const batchedHandlers = batchedHooks.load;
1937
- composed.load = async function(id) {
1938
- for (const [handler, plugin] of batchedHandlers) {
1939
- const { handler: handlerFn } = normalizeHook(handler);
1940
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), id);
1941
- if (!isNullish(result)) return result;
1942
- }
1943
- };
1944
- }
1945
- break;
1946
- }
1947
- case "transform": {
1948
- if (batchedHooks.transform) {
1949
- const batchedHandlers = batchedHooks.transform;
1950
- composed.transform = async function(initialCode, id, moduleType) {
1951
- let code = initialCode;
1952
- let moduleSideEffects = undefined;
1953
- function updateOutput(newCode, newModuleSideEffects) {
1954
- code = newCode;
1955
- moduleSideEffects = newModuleSideEffects ?? undefined;
1956
- }
1957
- for (const [handler, plugin] of batchedHandlers) {
1958
- const { handler: handlerFn } = normalizeHook(handler);
1959
- this.getCombinedSourcemap = () => {
1960
- throw new Error(`The getCombinedSourcemap is not implement in transform hook at composedJsPlugins`);
1961
- };
1962
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, id, moduleType);
1963
- if (!isNullish(result)) {
1964
- if (typeof result === "string") updateOutput(result);
1965
- else if (result.code) updateOutput(result.code, result.moduleSideEffects);
1966
- }
1967
- }
1968
- return {
1969
- code,
1970
- moduleSideEffects
1971
- };
1972
- };
1973
- }
1974
- break;
1975
- }
1976
- case "buildEnd": {
1977
- if (batchedHooks.buildEnd) {
1978
- const batchedHandlers = batchedHooks.buildEnd;
1979
- composed.buildEnd = async function(err) {
1980
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
1981
- const { handler: handlerFn } = normalizeHook(handler);
1982
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), err);
1983
- }));
1984
- };
1985
- }
1986
- break;
1987
- }
1988
- case "renderChunk": {
1989
- if (batchedHooks.renderChunk) {
1990
- const batchedHandlers = batchedHooks.renderChunk;
1991
- composed.renderChunk = async function(code, chunk, options) {
1992
- for (const [handler, plugin] of batchedHandlers) {
1993
- const { handler: handlerFn } = normalizeHook(handler);
1994
- const result = await handlerFn.call(applyFixedPluginResolveFn(this, plugin), code, chunk, options);
1995
- if (!isNullish(result)) return result;
1996
- }
1997
- };
1998
- }
1999
- break;
2000
- }
2001
- case "banner":
2002
- case "footer":
2003
- case "intro":
2004
- case "outro": {
2005
- const hooks = batchedHooks[hookName];
2006
- if (hooks?.length) composed[hookName] = async function(chunk) {
2007
- const ret = [];
2008
- for (const [hook, plugin] of hooks) {
2009
- const { handler } = normalizeHook(hook);
2010
- ret.push(typeof handler === "string" ? handler : await handler.call(applyFixedPluginResolveFn(this, plugin), chunk));
2011
- }
2012
- return ret.join("\n");
2013
- };
2014
- break;
2015
- }
2016
- case "closeBundle": {
2017
- if (batchedHooks.closeBundle) {
2018
- const batchedHandlers = batchedHooks.closeBundle;
2019
- composed.closeBundle = async function() {
2020
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2021
- const { handler: handlerFn } = normalizeHook(handler);
2022
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
2023
- }));
2024
- };
2025
- }
2026
- break;
2027
- }
2028
- case "watchChange": {
2029
- if (batchedHooks.watchChange) {
2030
- const batchedHandlers = batchedHooks.watchChange;
2031
- composed.watchChange = async function(id, event) {
2032
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2033
- const { handler: handlerFn } = normalizeHook(handler);
2034
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin), id, event);
2035
- }));
2036
- };
2037
- }
2038
- break;
2039
- }
2040
- case "closeWatcher": {
2041
- if (batchedHooks.closeWatcher) {
2042
- const batchedHandlers = batchedHooks.closeWatcher;
2043
- composed.closeWatcher = async function() {
2044
- await Promise.all(batchedHandlers.map(([handler, plugin]) => {
2045
- const { handler: handlerFn } = normalizeHook(handler);
2046
- return handlerFn.call(applyFixedPluginResolveFn(this, plugin));
2047
- }));
2048
- };
2049
- }
2050
- break;
2051
- }
2052
- default: {}
2053
- }
2054
- });
2055
- return composed;
2056
- }
2057
- function isComposablePlugin(plugin) {
2058
- if (plugin instanceof BuiltinPlugin) return false;
2059
- if ("_parallel" in plugin) return false;
2060
- const hasNotComposablePattern = t(plugin).some((hookName) => {
2061
- if (!isPluginHookName(hookName)) return false;
2062
- const OK_TO_COMPOSE = false;
2063
- if (isUnsupportedHooks(hookName)) return !OK_TO_COMPOSE;
2064
- if (plugin[hookName]) {
2065
- const { meta } = normalizeHook(plugin[hookName]);
2066
- if (meta.order === "pre" || meta.order === "post") return !OK_TO_COMPOSE;
2067
- }
2068
- return OK_TO_COMPOSE;
2069
- });
2070
- if (hasNotComposablePattern) return false;
2071
- return true;
2072
- }
2073
- function composeJsPlugins(plugins) {
2074
- const newPlugins = [];
2075
- const toBeComposed = [];
2076
- plugins.forEach((plugin) => {
2077
- if (isComposablePlugin(plugin)) toBeComposed.push(plugin);
2078
- else {
2079
- if (toBeComposed.length > 0) {
2080
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
2081
- else newPlugins.push(toBeComposed[0]);
2082
- toBeComposed.length = 0;
2083
- }
2084
- newPlugins.push(plugin);
2085
- }
2086
- });
2087
- if (toBeComposed.length > 0) {
2088
- if (toBeComposed.length > 1) newPlugins.push(createComposedPlugin(toBeComposed));
2089
- else newPlugins.push(toBeComposed[0]);
2090
- toBeComposed.length = 0;
2091
- }
2092
- return newPlugins;
2093
- }
2094
-
2095
- //#endregion
2096
- //#region src/utils/initialize-parallel-plugins.ts
2097
- async function initializeParallelPlugins(plugins) {
2098
- const pluginInfos = [];
2099
- for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
2100
- const { fileUrl, options } = plugin._parallel;
2101
- pluginInfos.push({
2102
- index,
2103
- fileUrl,
2104
- options
2105
- });
2106
- }
2107
- if (pluginInfos.length <= 0) return undefined;
2108
- const count = Math.min(availableParallelism(), 8);
2109
- const parallelJsPluginRegistry = new import_binding.ParallelJsPluginRegistry(count);
2110
- const registryId = parallelJsPluginRegistry.id;
2111
- const workers = await initializeWorkers(registryId, count, pluginInfos);
2112
- const stopWorkers = async () => {
2113
- await Promise.all(workers.map((worker) => worker.terminate()));
2114
- };
2115
- return {
2116
- registry: parallelJsPluginRegistry,
2117
- stopWorkers
2118
- };
2119
- }
2120
- function initializeWorkers(registryId, count, pluginInfos) {
2121
- return Promise.all(Array.from({ length: count }, (_, i) => initializeWorker(registryId, pluginInfos, i)));
2122
- }
2123
- async function initializeWorker(registryId, pluginInfos, threadNumber) {
2124
- const urlString = import.meta.resolve("#parallel-plugin-worker");
2125
- const workerData$1 = {
2126
- registryId,
2127
- pluginInfos,
2128
- threadNumber
2129
- };
2130
- let worker;
2131
- try {
2132
- worker = new Worker(new URL(urlString), { workerData: workerData$1 });
2133
- worker.unref();
2134
- await new Promise((resolve, reject) => {
2135
- worker.once("message", async (message) => {
2136
- if (message.type === "error") reject(message.error);
2137
- else resolve();
2138
- });
2139
- });
2140
- return worker;
2141
- } catch (e) {
2142
- worker?.terminate();
2143
- throw e;
2144
- }
2145
- }
2146
-
2147
- //#endregion
2148
- //#region src/utils/validator.ts
2149
- const StringOrRegExpSchema = v.union([v.string(), v.instance(RegExp)]);
2150
- const LogLevelSchema = v.union([
2151
- v.literal("debug"),
2152
- v.literal("info"),
2153
- v.literal("warn")
2154
- ]);
2155
- const LogLevelOptionSchema = v.union([LogLevelSchema, v.literal("silent")]);
2156
- const LogLevelWithErrorSchema = v.union([LogLevelSchema, v.literal("error")]);
2157
- const RollupLogSchema = v.any();
2158
- const RollupLogWithStringSchema = v.union([RollupLogSchema, v.string()]);
2159
- const InputOptionSchema = v.union([
2160
- v.string(),
2161
- v.array(v.string()),
2162
- v.record(v.string(), v.string())
2163
- ]);
2164
- const ExternalSchema = v.union([
2165
- StringOrRegExpSchema,
2166
- v.array(StringOrRegExpSchema),
2167
- v.pipe(v.function(), v.args(v.tuple([
2168
- v.string(),
2169
- v.optional(v.string()),
2170
- v.boolean()
2171
- ])), v.returns(v.nullish(v.boolean())))
2172
- ]);
2173
- const ModuleTypesSchema = v.record(v.string(), v.union([
2174
- v.literal("base64"),
2175
- v.literal("binary"),
2176
- v.literal("css"),
2177
- v.literal("dataurl"),
2178
- v.literal("empty"),
2179
- v.literal("js"),
2180
- v.literal("json"),
2181
- v.literal("jsx"),
2182
- v.literal("text"),
2183
- v.literal("ts"),
2184
- v.literal("tsx")
2185
- ]));
2186
- const JsxOptionsSchema = v.strictObject({
2187
- development: v.pipe(v.optional(v.boolean()), v.description("Development specific information")),
2188
- factory: v.pipe(v.optional(v.string()), v.description("Jsx element transformation")),
2189
- fragment: v.pipe(v.optional(v.string()), v.description("Jsx fragment transformation")),
2190
- importSource: v.pipe(v.optional(v.string()), v.description("Import the factory of element and fragment if mode is classic")),
2191
- jsxImportSource: v.pipe(v.optional(v.string()), v.description("Import the factory of element and fragment if mode is automatic")),
2192
- mode: v.pipe(v.optional(v.union([v.literal("classic"), v.literal("automatic")])), v.description("Jsx transformation mode")),
2193
- refresh: v.pipe(v.optional(v.boolean()), v.description("React refresh transformation"))
2194
- });
2195
- const WatchOptionsSchema = v.strictObject({
2196
- chokidar: v.optional(v.any()),
2197
- exclude: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
2198
- include: v.optional(v.union([StringOrRegExpSchema, v.array(StringOrRegExpSchema)])),
2199
- notify: v.pipe(v.optional(v.strictObject({
2200
- compareContents: v.optional(v.boolean()),
2201
- pollInterval: v.optional(v.number())
2202
- })), v.description("Notify options")),
2203
- skipWrite: v.pipe(v.optional(v.boolean()), v.description("Skip the bundle.write() step"))
2204
- });
2205
- const ChecksOptionsSchema = v.strictObject({ circularDependency: v.pipe(v.optional(v.boolean()), v.description("Wether to emit warnings when detecting circular dependencies")) });
2206
- const ResolveOptionsSchema = v.strictObject({
2207
- alias: v.optional(v.record(v.string(), v.union([v.string(), v.array(v.string())]))),
2208
- aliasFields: v.optional(v.array(v.array(v.string()))),
2209
- conditionNames: v.optional(v.array(v.string())),
2210
- extensionAlias: v.optional(v.record(v.string(), v.array(v.string()))),
2211
- exportsFields: v.optional(v.array(v.array(v.string()))),
2212
- extensions: v.optional(v.array(v.string())),
2213
- mainFields: v.optional(v.array(v.string())),
2214
- mainFiles: v.optional(v.array(v.string())),
2215
- modules: v.optional(v.array(v.string())),
2216
- symlinks: v.optional(v.boolean()),
2217
- tsconfigFilename: v.optional(v.string())
2218
- });
2219
- const TreeshakingOptionsSchema = v.union([v.boolean(), v.looseObject({ annotations: v.optional(v.boolean()) })]);
2220
- const OnLogSchema = v.pipe(v.function(), v.args(v.tuple([
2221
- LogLevelSchema,
2222
- RollupLogSchema,
2223
- v.pipe(v.function(), v.args(v.tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
2224
- ])));
2225
- const OnwarnSchema = v.pipe(v.function(), v.args(v.tuple([RollupLogSchema, v.pipe(v.function(), v.args(v.tuple([v.union([RollupLogWithStringSchema, v.pipe(v.function(), v.returns(RollupLogWithStringSchema))])])))])));
2226
- const InputOptionsSchema = v.strictObject({
2227
- input: v.optional(InputOptionSchema),
2228
- plugins: v.optional(v.custom(() => true)),
2229
- external: v.optional(ExternalSchema),
2230
- resolve: v.optional(ResolveOptionsSchema),
2231
- cwd: v.pipe(v.optional(v.string()), v.description("Current working directory")),
2232
- platform: v.pipe(v.optional(v.union([
2233
- v.literal("browser"),
2234
- v.literal("neutral"),
2235
- v.literal("node")
2236
- ])), v.description(`Platform for which the code should be generated (node, ${colors.underline("browser")}, neutral)`)),
2237
- shimMissingExports: v.pipe(v.optional(v.boolean()), v.description("Create shim variables for missing exports")),
2238
- treeshake: v.optional(TreeshakingOptionsSchema),
2239
- logLevel: v.pipe(v.optional(LogLevelOptionSchema), v.description(`Log level (${colors.dim("silent")}, ${colors.underline(colors.gray("info"))}, debug, ${colors.yellow("warn")})`)),
2240
- onLog: v.optional(OnLogSchema),
2241
- onwarn: v.optional(OnwarnSchema),
2242
- moduleTypes: v.pipe(v.optional(ModuleTypesSchema), v.description("Module types for customized extensions")),
2243
- experimental: v.optional(v.strictObject({
2244
- disableLiveBindings: v.optional(v.boolean()),
2245
- enableComposingJsPlugins: v.optional(v.boolean()),
2246
- resolveNewUrlToAsset: v.optional(v.boolean()),
2247
- strictExecutionOrder: v.optional(v.boolean())
2248
- })),
2249
- define: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Define global variables")),
2250
- inject: v.optional(v.record(v.string(), v.union([v.string(), v.tuple([v.string(), v.string()])]))),
2251
- profilerNames: v.optional(v.boolean()),
2252
- jsx: v.optional(JsxOptionsSchema),
2253
- watch: v.optional(v.union([WatchOptionsSchema, v.literal(false)])),
2254
- dropLabels: v.pipe(v.optional(v.array(v.string())), v.description("Remove labeled statements with these label names")),
2255
- checks: v.optional(ChecksOptionsSchema)
2256
- });
2257
- const InputCliOverrideSchema = v.strictObject({
2258
- external: v.pipe(v.optional(v.array(v.string())), v.description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
2259
- inject: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Inject import statements on demand")),
2260
- treeshake: v.pipe(v.optional(v.boolean(), true), v.description("enable treeshaking"))
2261
- });
2262
- const InputCliOptionsSchema = v.omit(v.strictObject({
2263
- ...InputOptionsSchema.entries,
2264
- ...InputCliOverrideSchema.entries
2265
- }), [
2266
- "input",
2267
- "plugins",
2268
- "onwarn",
2269
- "onLog",
2270
- "resolve",
2271
- "experimental",
2272
- "profilerNames",
2273
- "watch"
2274
- ]);
2275
- var ESTarget = function(ESTarget$1) {
2276
- ESTarget$1["ES6"] = "es6";
2277
- ESTarget$1["ES2015"] = "es2015";
2278
- ESTarget$1["ES2016"] = "es2016";
2279
- ESTarget$1["ES2017"] = "es2017";
2280
- ESTarget$1["ES2018"] = "es2018";
2281
- ESTarget$1["ES2019"] = "es2019";
2282
- ESTarget$1["ES2020"] = "es2020";
2283
- ESTarget$1["ES2021"] = "es2021";
2284
- ESTarget$1["ES2022"] = "es2022";
2285
- ESTarget$1["ES2023"] = "es2023";
2286
- ESTarget$1["ES2024"] = "es2024";
2287
- ESTarget$1["ESNext"] = "esnext";
2288
- return ESTarget$1;
2289
- }(ESTarget || {});
2290
- const ModuleFormatSchema = v.union([
2291
- v.literal("es"),
2292
- v.literal("cjs"),
2293
- v.literal("esm"),
2294
- v.literal("module"),
2295
- v.literal("commonjs"),
2296
- v.literal("iife"),
2297
- v.literal("umd")
2298
- ]);
2299
- const AddonFunctionSchema = v.pipe(v.function(), v.args(v.tuple([v.custom(() => true)])), v.returnsAsync(v.unionAsync([v.string(), v.pipeAsync(v.promise(), v.awaitAsync(), v.string())])));
2300
- const ChunkFileNamesSchema = v.union([v.string(), v.pipe(v.function(), v.args(v.tuple([v.custom(() => true)])), v.returns(v.string()))]);
2301
- const GlobalsFunctionSchema = v.pipe(v.function(), v.args(v.tuple([v.string()])), v.returns(v.string()));
2302
- const AdvancedChunksSchema = v.strictObject({
2303
- minSize: v.optional(v.number()),
2304
- maxSize: v.optional(v.number()),
2305
- minModuleSize: v.optional(v.number()),
2306
- maxModuleSize: v.optional(v.number()),
2307
- minShareCount: v.optional(v.number()),
2308
- groups: v.optional(v.array(v.strictObject({
2309
- name: v.string(),
2310
- test: v.optional(v.union([v.string(), v.instance(RegExp)])),
2311
- priority: v.optional(v.number()),
2312
- minSize: v.optional(v.number()),
2313
- minShareCount: v.optional(v.number()),
2314
- maxSize: v.optional(v.number()),
2315
- minModuleSize: v.optional(v.number()),
2316
- maxModuleSize: v.optional(v.number())
2317
- })))
2318
- });
2319
- const OutputOptionsSchema = v.strictObject({
2320
- dir: v.pipe(v.optional(v.string()), v.description("Output directory, defaults to `dist` if `file` is not set")),
2321
- file: v.pipe(v.optional(v.string()), v.description("Single output file")),
2322
- exports: v.pipe(v.optional(v.union([
2323
- v.literal("auto"),
2324
- v.literal("named"),
2325
- v.literal("default"),
2326
- v.literal("none")
2327
- ])), v.description(`Specify a export mode (${colors.underline("auto")}, named, default, none)`)),
2328
- hashCharacters: v.pipe(v.optional(v.union([
2329
- v.literal("base64"),
2330
- v.literal("base36"),
2331
- v.literal("hex")
2332
- ])), v.description("Use the specified character set for file hashes")),
2333
- format: v.pipe(v.optional(ModuleFormatSchema), v.description(`Output format of the generated bundle (supports ${colors.underline("esm")}, cjs, and iife)`)),
2334
- sourcemap: v.pipe(v.optional(v.union([
2335
- v.boolean(),
2336
- v.literal("inline"),
2337
- v.literal("hidden")
2338
- ])), v.description(`Generate sourcemap (\`-s inline\` for inline, or ${colors.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`)),
2339
- sourcemapIgnoreList: v.optional(v.union([v.boolean(), v.custom(() => true)])),
2340
- sourcemapPathTransform: v.optional(v.custom(() => true)),
2341
- banner: v.optional(v.union([v.string(), AddonFunctionSchema])),
2342
- footer: v.optional(v.union([v.string(), AddonFunctionSchema])),
2343
- intro: v.optional(v.union([v.string(), AddonFunctionSchema])),
2344
- outro: v.optional(v.union([v.string(), AddonFunctionSchema])),
2345
- extend: v.pipe(v.optional(v.boolean()), v.description("Extend global variable defined by name in IIFE / UMD formats")),
2346
- esModule: v.optional(v.union([v.boolean(), v.literal("if-default-prop")])),
2347
- assetFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for asset files")),
2348
- entryFileNames: v.optional(ChunkFileNamesSchema),
2349
- chunkFileNames: v.optional(ChunkFileNamesSchema),
2350
- cssEntryFileNames: v.optional(ChunkFileNamesSchema),
2351
- cssChunkFileNames: v.optional(ChunkFileNamesSchema),
2352
- minify: v.pipe(v.optional(v.boolean()), v.description("Minify the bundled file")),
2353
- name: v.pipe(v.optional(v.string()), v.description("Name for UMD / IIFE format outputs")),
2354
- globals: v.pipe(v.optional(v.union([v.record(v.string(), v.string()), GlobalsFunctionSchema])), v.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2355
- externalLiveBindings: v.pipe(v.optional(v.boolean(), true), v.description("external live bindings")),
2356
- inlineDynamicImports: v.pipe(v.optional(v.boolean(), false), v.description("Inline dynamic imports")),
2357
- advancedChunks: v.optional(AdvancedChunksSchema),
2358
- comments: v.pipe(v.optional(v.union([v.literal("none"), v.literal("preserve-legal")])), v.description("Control comments in the output")),
2359
- target: v.pipe(v.optional(v.enum(ESTarget)), v.description("The JavaScript target environment"))
2360
- });
2361
- const getAddonDescription = (placement, wrapper) => {
2362
- return `Code to insert the ${colors.bold(placement)} of the bundled file (${colors.bold(wrapper)} the wrapper function)`;
2363
- };
2364
- const OutputCliOverrideSchema = v.strictObject({
2365
- entryFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted entry chunks")),
2366
- chunkFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted secondary chunks")),
2367
- cssEntryFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted css entry chunks")),
2368
- cssChunkFileNames: v.pipe(v.optional(v.string()), v.description("Name pattern for emitted css secondary chunks")),
2369
- banner: v.pipe(v.optional(v.string()), v.description(getAddonDescription("top", "outside"))),
2370
- footer: v.pipe(v.optional(v.string()), v.description(getAddonDescription("bottom", "outside"))),
2371
- intro: v.pipe(v.optional(v.string()), v.description(getAddonDescription("top", "inside"))),
2372
- outro: v.pipe(v.optional(v.string()), v.description(getAddonDescription("bottom", "inside"))),
2373
- esModule: v.pipe(v.optional(v.boolean()), v.description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
2374
- globals: v.pipe(v.optional(v.record(v.string(), v.string())), v.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2375
- advancedChunks: v.pipe(v.optional(v.strictObject({
2376
- minSize: v.pipe(v.optional(v.number()), v.description("Minimum size of the chunk")),
2377
- minShareCount: v.pipe(v.optional(v.number()), v.description("Minimum share count of the chunk"))
2378
- })), v.description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)"))
2379
- });
2380
- const OutputCliOptionsSchema = v.omit(v.strictObject({
2381
- ...OutputOptionsSchema.entries,
2382
- ...OutputCliOverrideSchema.entries
2383
- }), ["sourcemapIgnoreList", "sourcemapPathTransform"]);
2384
- const CliOptionsSchema = v.strictObject({
2385
- config: v.pipe(v.optional(v.union([v.string(), v.boolean()])), v.description("Path to the config file (default: `rolldown.config.js`)")),
2386
- help: v.pipe(v.optional(v.boolean()), v.description("Show help")),
2387
- version: v.pipe(v.optional(v.boolean()), v.description("Show version number")),
2388
- watch: v.pipe(v.optional(v.boolean()), v.description("Watch files in bundle and rebuild on changes")),
2389
- ...InputCliOptionsSchema.entries,
2390
- ...OutputCliOptionsSchema.entries
2391
- });
2392
- function validateTreeShakingOptions(options) {
2393
- v.parse(TreeshakingOptionsSchema, options);
2394
- }
2395
- function validateCliOptions(options) {
2396
- let parsed = v.safeParse(CliOptionsSchema, options);
2397
- return [parsed.output, parsed.issues?.map((issue) => issue.path?.join(", ")).filter((v$1) => v$1 !== undefined)];
2398
- }
2399
- function getInputCliKeys() {
2400
- return v.keyof(InputCliOptionsSchema).options;
2401
- }
2402
- function getOutputCliKeys() {
2403
- return v.keyof(OutputCliOptionsSchema).options;
2404
- }
2405
- function getJsonSchema() {
2406
- return toJsonSchema(CliOptionsSchema);
2407
- }
2408
-
2409
- //#endregion
2410
- //#region src/utils/create-bundler-option.ts
2411
- async function createBundlerOptions(inputOptions, outputOptions) {
2412
- if (inputOptions.treeshake !== undefined) validateTreeShakingOptions(inputOptions.treeshake);
2413
- const inputPlugins = await normalizePluginOption(inputOptions.plugins);
2414
- const outputPlugins = await normalizePluginOption(outputOptions.plugins);
2415
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
2416
- const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel);
2417
- outputOptions = PluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions);
2418
- if (outputOptions.minify === true) onLog(LOG_LEVEL_WARN, logMinifyWarning());
2419
- let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(await normalizePluginOption(outputOptions.plugins), ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
2420
- if (inputOptions.experimental?.enableComposingJsPlugins ?? false) plugins = composeJsPlugins(plugins);
2421
- const parallelPluginInitResult = await initializeParallelPlugins(plugins);
2422
- try {
2423
- const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
2424
- const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
2425
- return {
2426
- bundlerOptions: {
2427
- inputOptions: bindingInputOptions,
2428
- outputOptions: bindingOutputOptions,
2429
- parallelPluginsRegistry: parallelPluginInitResult?.registry
2430
- },
2431
- inputOptions,
2432
- onLog,
2433
- stopWorkers: parallelPluginInitResult?.stopWorkers
2434
- };
2435
- } catch (e) {
2436
- await parallelPluginInitResult?.stopWorkers();
2437
- throw e;
2438
- }
2439
- }
2440
-
2441
- //#endregion
2442
- //#region src/utils/create-bundler.ts
2443
- async function createBundler(inputOptions, outputOptions) {
2444
- const option = await createBundlerOptions(inputOptions, outputOptions);
2445
- try {
2446
- return {
2447
- bundler: new import_binding.Bundler(option.bundlerOptions),
2448
- stopWorkers: option.stopWorkers
2449
- };
2450
- } catch (e) {
2451
- await option.stopWorkers?.();
2452
- throw e;
2453
- }
2454
- }
2455
-
2456
- //#endregion
2457
- //#region src/api/rolldown/rolldown-build.ts
2458
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
2459
- var RolldownBuild = class {
2460
- #inputOptions;
2461
- #bundler;
2462
- constructor(inputOptions) {
2463
- this.#inputOptions = inputOptions;
2464
- }
2465
- get closed() {
2466
- return this.#bundler ? this.#bundler.bundler.closed : false;
2467
- }
2468
- async #getBundlerWithStopWorker(outputOptions) {
2469
- if (this.#bundler) this.#bundler.stopWorkers?.();
2470
- return this.#bundler = await createBundler(this.#inputOptions, outputOptions);
2471
- }
2472
- async generate(outputOptions = {}) {
2473
- const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
2474
- const output = await bundler.generate();
2475
- return transformToRollupOutput(output);
2476
- }
2477
- async write(outputOptions = {}) {
2478
- const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
2479
- const output = await bundler.write();
2480
- return transformToRollupOutput(output);
2481
- }
2482
- async close() {
2483
- const { bundler, stopWorkers } = await this.#getBundlerWithStopWorker({});
2484
- await stopWorkers?.();
2485
- await bundler.close();
2486
- }
2487
- async [Symbol.asyncDispose]() {
2488
- await this.close();
2489
- }
2490
- };
2491
-
2492
- //#endregion
2493
- //#region src/api/rolldown/index.ts
2494
- const rolldown = async (input) => {
2495
- const inputOptions = await PluginDriver.callOptionsHook(input);
2496
- return new RolldownBuild(inputOptions);
2497
- };
2498
-
2499
- //#endregion
2500
- //#region src/api/watch/watch-emitter.ts
2501
- var WatcherEmitter = class {
2502
- listeners = new Map();
2503
- timer;
2504
- constructor() {
2505
- this.timer = setInterval(
2506
- () => {},
2507
- 1e9
2508
- /* Low power usage */
2509
- );
2510
- }
2511
- on(event, listener) {
2512
- const listeners = this.listeners.get(event);
2513
- if (listeners) listeners.push(listener);
2514
- else this.listeners.set(event, [listener]);
2515
- return this;
2516
- }
2517
- async onEvent(event) {
2518
- const listeners = this.listeners.get(event.eventKind());
2519
- if (listeners) switch (event.eventKind()) {
2520
- case "close":
2521
- case "restart":
2522
- for (const listener of listeners) await listener();
2523
- break;
2524
- case "event":
2525
- for (const listener of listeners) {
2526
- const code = event.bundleEventKind();
2527
- switch (code) {
2528
- case "BUNDLE_END":
2529
- const { duration, output } = event.bundleEndData();
2530
- await listener({
2531
- code: "BUNDLE_END",
2532
- duration,
2533
- output: [output]
2534
- });
2535
- break;
2536
- case "ERROR":
2537
- const errors = event.errors();
2538
- await listener({
2539
- code: "ERROR",
2540
- error: normalizeErrors(errors)
2541
- });
2542
- break;
2543
- default:
2544
- await listener({ code });
2545
- break;
2546
- }
2547
- }
2548
- break;
2549
- case "change":
2550
- for (const listener of listeners) {
2551
- const { path: path$1, kind } = event.watchChangeData();
2552
- await listener(path$1, { event: kind });
2553
- }
2554
- break;
2555
- default: throw new Error(`Unknown event: ${event}`);
2556
- }
2557
- }
2558
- async close() {
2559
- clearInterval(this.timer);
2560
- }
2561
- };
2562
-
2563
- //#endregion
2564
- //#region src/api/watch/watcher.ts
2565
- var Watcher = class {
2566
- closed;
2567
- inner;
2568
- emitter;
2569
- stopWorkers;
2570
- constructor(emitter, inner, stopWorkers) {
2571
- this.closed = false;
2572
- this.inner = inner;
2573
- this.emitter = emitter;
2574
- const originClose = emitter.close.bind(emitter);
2575
- emitter.close = async () => {
2576
- await this.close();
2577
- originClose();
2578
- };
2579
- this.stopWorkers = stopWorkers;
2580
- }
2581
- async close() {
2582
- if (this.closed) return;
2583
- this.closed = true;
2584
- for (const stop of this.stopWorkers) await stop?.();
2585
- await this.inner.close();
2586
- }
2587
- start() {
2588
- process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
2589
- }
2590
- };
2591
- async function createWatcher(emitter, input) {
2592
- const options = arraify(input);
2593
- const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
2594
- const inputOptions = await PluginDriver.callOptionsHook(option);
2595
- return createBundlerOptions(inputOptions, output);
2596
- })).flat());
2597
- const notifyOptions = getValidNotifyOption(bundlerOptions);
2598
- const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
2599
- const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
2600
- watcher.start();
2601
- }
2602
- function getValidNotifyOption(bundlerOptions) {
2603
- let result;
2604
- for (const option of bundlerOptions) if (option.inputOptions.watch) {
2605
- const notifyOption = option.inputOptions.watch.notify;
2606
- if (notifyOption) if (result) {
2607
- option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
2608
- return result;
2609
- } else result = notifyOption;
2610
- }
2611
- }
2612
-
2613
- //#endregion
2614
- //#region src/api/watch/index.ts
2615
- const watch = (input) => {
2616
- const emitter = new WatcherEmitter();
2617
- createWatcher(emitter, input);
2618
- return emitter;
2619
- };
2620
-
2621
- //#endregion
2622
- //#region package.json
2623
- var version = "1.0.0-beta.2-commit.2666b23";
2624
- var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2625
-
2626
- //#endregion
2627
- //#region src/api/build.ts
2628
- async function build(options) {
2629
- if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
2630
- else {
2631
- const { output, write = true,...inputOptions } = options;
2632
- const build$1 = await rolldown(inputOptions);
2633
- try {
2634
- if (write) return await build$1.write(output);
2635
- else return await build$1.generate(output);
2636
- } finally {
2637
- await build$1.close();
2638
- }
2639
- }
2640
- }
2641
-
2642
- //#endregion
2643
- //#region src/index.ts
2644
- const VERSION = version;
2645
-
2646
- //#endregion
2647
- export { BuiltinPlugin, PluginContextData, VERSION, arraify, bindingifyPlugin, build, buildImportAnalysisPlugin, composeJsPlugins, createBundler, defineConfig, description, dynamicImportVarsPlugin, getInputCliKeys, getJsonSchema, getOutputCliKeys, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, moduleFederationPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, rolldown, validateCliOptions, version, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin, watch };