bindingify-input-options-DYpBf1OG.mjs 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235
  1. import { n as __toESM, t as require_binding } from "./binding-s-V_wTpj.mjs";
  2. import { a as logInvalidLogPosition, c as logPluginError, n as error, r as logCycleLoading, t as augmentCodeLocation } from "./logs-D80CXhvg.mjs";
  3. import { i as bindingifyManifestPlugin, n as BuiltinPlugin, r as bindingifyBuiltInPlugin, t as normalizedStringOrRegex } from "./normalize-string-or-regex-CVvpepxa.mjs";
  4. import { a as unreachable, o as unsupported, r as noop, t as arraify } from "./misc-DJYbNKZX.mjs";
  5. import { a as bindingifySourcemap, i as unwrapBindingResult, t as aggregateBindingErrorsIntoJsError } from "./error-w0u7biK-.mjs";
  6. import { parseAst } from "../parse-ast-index.mjs";
  7. import path from "node:path";
  8. import * as filter from "@rolldown/pluginutils";
  9. import fsp from "node:fs/promises";
  10. //#region package.json
  11. var version = "1.0.0-rc.15";
  12. var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
  13. //#endregion
  14. //#region src/constants/version.ts
  15. /**
  16. * The version of Rolldown.
  17. * @example `'1.0.0'`
  18. *
  19. * @category Plugin APIs
  20. */
  21. const VERSION = version;
  22. //#endregion
  23. //#region src/constants/index.ts
  24. /**
  25. * Runtime helper module ID
  26. */
  27. const RUNTIME_MODULE_ID = "\0rolldown/runtime.js";
  28. //#endregion
  29. //#region src/log/logging.ts
  30. const LOG_LEVEL_SILENT = "silent";
  31. const LOG_LEVEL_ERROR = "error";
  32. const LOG_LEVEL_WARN = "warn";
  33. const LOG_LEVEL_INFO = "info";
  34. const LOG_LEVEL_DEBUG = "debug";
  35. const logLevelPriority = {
  36. [LOG_LEVEL_DEBUG]: 0,
  37. [LOG_LEVEL_INFO]: 1,
  38. [LOG_LEVEL_WARN]: 2,
  39. [LOG_LEVEL_SILENT]: 3
  40. };
  41. //#endregion
  42. //#region src/log/log-handler.ts
  43. const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
  44. function getLogHandler(level, code, logger, pluginName, logLevel) {
  45. if (logLevelPriority[level] < logLevelPriority[logLevel]) return noop;
  46. return (log, pos) => {
  47. if (pos != null) logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
  48. log = normalizeLog(log);
  49. if (log.code && !log.pluginCode) log.pluginCode = log.code;
  50. log.code = code;
  51. log.plugin = pluginName;
  52. logger(level, log);
  53. };
  54. }
  55. //#endregion
  56. //#region src/utils/normalize-hook.ts
  57. function normalizeHook(hook) {
  58. if (typeof hook === "function" || typeof hook === "string") return {
  59. handler: hook,
  60. options: {},
  61. meta: {}
  62. };
  63. if (typeof hook === "object" && hook !== null) {
  64. const { handler, order, ...options } = hook;
  65. return {
  66. handler,
  67. options,
  68. meta: { order }
  69. };
  70. }
  71. unreachable("Invalid hook type");
  72. }
  73. //#endregion
  74. //#region src/plugin/minimal-plugin-context.ts
  75. var MinimalPluginContextImpl = class {
  76. info;
  77. warn;
  78. debug;
  79. meta;
  80. constructor(onLog, logLevel, pluginName, watchMode, hookName) {
  81. this.pluginName = pluginName;
  82. this.hookName = hookName;
  83. this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
  84. this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
  85. this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
  86. this.meta = {
  87. rollupVersion: "4.23.0",
  88. rolldownVersion: VERSION,
  89. watchMode
  90. };
  91. }
  92. error(e) {
  93. return error(logPluginError(normalizeLog(e), this.pluginName, { hook: this.hookName }));
  94. }
  95. };
  96. //#endregion
  97. //#region src/types/plain-object-like.ts
  98. const LAZY_FIELDS_KEY = Symbol("__lazy_fields__");
  99. /**
  100. * Base class for classes that use `@lazyProp` decorated properties.
  101. *
  102. * **Design Pattern in Rolldown:**
  103. * This is a common pattern in Rolldown due to its three-layer architecture:
  104. * TypeScript API → NAPI Bindings → Rust Core
  105. *
  106. * **Why we use getters:**
  107. * For performance - to lazily fetch data from Rust bindings only when needed,
  108. * rather than eagerly fetching all data during object construction.
  109. *
  110. * **The problem:**
  111. * Getters defined on class prototypes are non-enumerable by default, which breaks:
  112. * - Object spread operators ({...obj})
  113. * - Object.keys() and similar methods
  114. * - Standard JavaScript object semantics
  115. *
  116. * **The solution:**
  117. * This base class automatically converts `@lazyProp` decorated getters into
  118. * own enumerable getters on each instance during construction.
  119. *
  120. * **Result:**
  121. * Objects get both lazy-loading performance benefits AND plain JavaScript object behavior.
  122. *
  123. * @example
  124. * ```typescript
  125. * class MyClass extends PlainObjectLike {
  126. * @lazyProp
  127. * get myProp() {
  128. * return fetchFromRustBinding();
  129. * }
  130. * }
  131. * ```
  132. */
  133. var PlainObjectLike = class {
  134. constructor() {
  135. setupLazyProperties(this);
  136. }
  137. };
  138. /**
  139. * Set up lazy properties as own getters on an instance.
  140. * This is called automatically by the `PlainObjectLike` base class constructor.
  141. *
  142. * @param instance - The instance to set up lazy properties on
  143. * @internal
  144. */
  145. function setupLazyProperties(instance) {
  146. const lazyFields = instance.constructor[LAZY_FIELDS_KEY];
  147. if (!lazyFields) return;
  148. for (const [propertyKey, originalGetter] of lazyFields.entries()) {
  149. let cachedValue;
  150. let hasValue = false;
  151. Object.defineProperty(instance, propertyKey, {
  152. get() {
  153. if (!hasValue) {
  154. cachedValue = originalGetter.call(this);
  155. hasValue = true;
  156. }
  157. return cachedValue;
  158. },
  159. enumerable: true,
  160. configurable: true
  161. });
  162. }
  163. }
  164. /**
  165. * Get all lazy field names from a class instance.
  166. *
  167. * @param instance - Instance to inspect
  168. * @returns Set of lazy property names
  169. */
  170. function getLazyFields(instance) {
  171. const lazyFields = instance.constructor[LAZY_FIELDS_KEY];
  172. return lazyFields ? new Set(lazyFields.keys()) : /* @__PURE__ */ new Set();
  173. }
  174. //#endregion
  175. //#region src/decorators/lazy.ts
  176. /**
  177. * Decorator that marks a getter as lazy-evaluated and cached.
  178. *
  179. * **What "lazy" means here:**
  180. * 1. Data is lazily fetched from Rust bindings only when the property is accessed (not eagerly on construction)
  181. * 2. Once fetched, the data is cached for subsequent accesses (performance optimization)
  182. * 3. Despite being a getter, it behaves like a plain object property (enumerable, appears in Object.keys())
  183. *
  184. * **Important**: Properties decorated with `@lazyProp` are defined as own enumerable
  185. * properties on each instance (not on the prototype). This ensures they:
  186. * - Appear in Object.keys() and Object.getOwnPropertyNames()
  187. * - Are included in object spreads ({...obj})
  188. * - Are enumerable in for...in loops
  189. *
  190. * Classes using this decorator must extend `PlainObjectLike` base class.
  191. *
  192. * @example
  193. * ```typescript
  194. * class MyClass extends PlainObjectLike {
  195. * @lazyProp
  196. * get expensiveValue() {
  197. * return someExpensiveComputation();
  198. * }
  199. * }
  200. * ```
  201. */
  202. function lazyProp(target, propertyKey, descriptor) {
  203. if (!target.constructor[LAZY_FIELDS_KEY]) target.constructor[LAZY_FIELDS_KEY] = /* @__PURE__ */ new Map();
  204. const originalGetter = descriptor.get;
  205. target.constructor[LAZY_FIELDS_KEY].set(propertyKey, originalGetter);
  206. return {
  207. enumerable: false,
  208. configurable: true
  209. };
  210. }
  211. //#endregion
  212. //#region src/utils/asset-source.ts
  213. function transformAssetSource(bindingAssetSource) {
  214. return bindingAssetSource.inner;
  215. }
  216. function bindingAssetSource(source) {
  217. return { inner: source };
  218. }
  219. //#endregion
  220. //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
  221. function __decorate(decorators, target, key, desc) {
  222. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  223. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  224. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  225. return c > 3 && r && Object.defineProperty(target, key, r), r;
  226. }
  227. //#endregion
  228. //#region src/types/output-asset-impl.ts
  229. var OutputAssetImpl = class extends PlainObjectLike {
  230. type = "asset";
  231. constructor(bindingAsset) {
  232. super();
  233. this.bindingAsset = bindingAsset;
  234. }
  235. get fileName() {
  236. return this.bindingAsset.getFileName();
  237. }
  238. get originalFileName() {
  239. return this.bindingAsset.getOriginalFileName() || null;
  240. }
  241. get originalFileNames() {
  242. return this.bindingAsset.getOriginalFileNames();
  243. }
  244. get name() {
  245. return this.bindingAsset.getName() ?? void 0;
  246. }
  247. get names() {
  248. return this.bindingAsset.getNames();
  249. }
  250. get source() {
  251. return transformAssetSource(this.bindingAsset.getSource());
  252. }
  253. __rolldown_external_memory_handle__(keepDataAlive) {
  254. if (keepDataAlive) this.#evaluateAllLazyFields();
  255. return this.bindingAsset.dropInner();
  256. }
  257. #evaluateAllLazyFields() {
  258. for (const field of getLazyFields(this)) this[field];
  259. }
  260. };
  261. __decorate([lazyProp], OutputAssetImpl.prototype, "fileName", null);
  262. __decorate([lazyProp], OutputAssetImpl.prototype, "originalFileName", null);
  263. __decorate([lazyProp], OutputAssetImpl.prototype, "originalFileNames", null);
  264. __decorate([lazyProp], OutputAssetImpl.prototype, "name", null);
  265. __decorate([lazyProp], OutputAssetImpl.prototype, "names", null);
  266. __decorate([lazyProp], OutputAssetImpl.prototype, "source", null);
  267. //#endregion
  268. //#region src/utils/transform-rendered-module.ts
  269. function transformToRenderedModule(bindingRenderedModule) {
  270. return {
  271. get code() {
  272. return bindingRenderedModule.code;
  273. },
  274. get renderedLength() {
  275. return bindingRenderedModule.code?.length || 0;
  276. },
  277. get renderedExports() {
  278. return bindingRenderedModule.renderedExports;
  279. }
  280. };
  281. }
  282. //#endregion
  283. //#region src/utils/transform-rendered-chunk.ts
  284. function transformRenderedChunk(chunk) {
  285. let modules = null;
  286. return {
  287. type: "chunk",
  288. get name() {
  289. return chunk.name;
  290. },
  291. get isEntry() {
  292. return chunk.isEntry;
  293. },
  294. get isDynamicEntry() {
  295. return chunk.isDynamicEntry;
  296. },
  297. get facadeModuleId() {
  298. return chunk.facadeModuleId;
  299. },
  300. get moduleIds() {
  301. return chunk.moduleIds;
  302. },
  303. get exports() {
  304. return chunk.exports;
  305. },
  306. get fileName() {
  307. return chunk.fileName;
  308. },
  309. get imports() {
  310. return chunk.imports;
  311. },
  312. get dynamicImports() {
  313. return chunk.dynamicImports;
  314. },
  315. get modules() {
  316. if (!modules) modules = transformChunkModules(chunk.modules);
  317. return modules;
  318. }
  319. };
  320. }
  321. function transformChunkModules(modules) {
  322. const result = {};
  323. for (let i = 0; i < modules.values.length; i++) {
  324. let key = modules.keys[i];
  325. const mod = modules.values[i];
  326. result[key] = transformToRenderedModule(mod);
  327. }
  328. return result;
  329. }
  330. //#endregion
  331. //#region src/types/output-chunk-impl.ts
  332. var OutputChunkImpl = class extends PlainObjectLike {
  333. type = "chunk";
  334. constructor(bindingChunk) {
  335. super();
  336. this.bindingChunk = bindingChunk;
  337. }
  338. get fileName() {
  339. return this.bindingChunk.getFileName();
  340. }
  341. get name() {
  342. return this.bindingChunk.getName();
  343. }
  344. get exports() {
  345. return this.bindingChunk.getExports();
  346. }
  347. get isEntry() {
  348. return this.bindingChunk.getIsEntry();
  349. }
  350. get facadeModuleId() {
  351. return this.bindingChunk.getFacadeModuleId() || null;
  352. }
  353. get isDynamicEntry() {
  354. return this.bindingChunk.getIsDynamicEntry();
  355. }
  356. get sourcemapFileName() {
  357. return this.bindingChunk.getSourcemapFileName() || null;
  358. }
  359. get preliminaryFileName() {
  360. return this.bindingChunk.getPreliminaryFileName();
  361. }
  362. get code() {
  363. return this.bindingChunk.getCode();
  364. }
  365. get modules() {
  366. return transformChunkModules(this.bindingChunk.getModules());
  367. }
  368. get imports() {
  369. return this.bindingChunk.getImports();
  370. }
  371. get dynamicImports() {
  372. return this.bindingChunk.getDynamicImports();
  373. }
  374. get moduleIds() {
  375. return this.bindingChunk.getModuleIds();
  376. }
  377. get map() {
  378. const mapString = this.bindingChunk.getMap();
  379. return mapString ? transformToRollupSourceMap(mapString) : null;
  380. }
  381. __rolldown_external_memory_handle__(keepDataAlive) {
  382. if (keepDataAlive) this.#evaluateAllLazyFields();
  383. return this.bindingChunk.dropInner();
  384. }
  385. #evaluateAllLazyFields() {
  386. for (const field of getLazyFields(this)) this[field];
  387. }
  388. };
  389. __decorate([lazyProp], OutputChunkImpl.prototype, "fileName", null);
  390. __decorate([lazyProp], OutputChunkImpl.prototype, "name", null);
  391. __decorate([lazyProp], OutputChunkImpl.prototype, "exports", null);
  392. __decorate([lazyProp], OutputChunkImpl.prototype, "isEntry", null);
  393. __decorate([lazyProp], OutputChunkImpl.prototype, "facadeModuleId", null);
  394. __decorate([lazyProp], OutputChunkImpl.prototype, "isDynamicEntry", null);
  395. __decorate([lazyProp], OutputChunkImpl.prototype, "sourcemapFileName", null);
  396. __decorate([lazyProp], OutputChunkImpl.prototype, "preliminaryFileName", null);
  397. __decorate([lazyProp], OutputChunkImpl.prototype, "code", null);
  398. __decorate([lazyProp], OutputChunkImpl.prototype, "modules", null);
  399. __decorate([lazyProp], OutputChunkImpl.prototype, "imports", null);
  400. __decorate([lazyProp], OutputChunkImpl.prototype, "dynamicImports", null);
  401. __decorate([lazyProp], OutputChunkImpl.prototype, "moduleIds", null);
  402. __decorate([lazyProp], OutputChunkImpl.prototype, "map", null);
  403. //#endregion
  404. //#region src/utils/transform-to-rollup-output.ts
  405. function transformToRollupSourceMap(map) {
  406. const obj = {
  407. ...JSON.parse(map),
  408. toString() {
  409. return JSON.stringify(obj);
  410. },
  411. toUrl() {
  412. return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
  413. }
  414. };
  415. return obj;
  416. }
  417. function transformToRollupOutputChunk(bindingChunk) {
  418. return new OutputChunkImpl(bindingChunk);
  419. }
  420. function transformToMutableRollupOutputChunk(bindingChunk, changed) {
  421. const chunk = {
  422. type: "chunk",
  423. get code() {
  424. return bindingChunk.getCode();
  425. },
  426. fileName: bindingChunk.getFileName(),
  427. name: bindingChunk.getName(),
  428. get modules() {
  429. return transformChunkModules(bindingChunk.getModules());
  430. },
  431. get imports() {
  432. return bindingChunk.getImports();
  433. },
  434. get dynamicImports() {
  435. return bindingChunk.getDynamicImports();
  436. },
  437. exports: bindingChunk.getExports(),
  438. isEntry: bindingChunk.getIsEntry(),
  439. facadeModuleId: bindingChunk.getFacadeModuleId() || null,
  440. isDynamicEntry: bindingChunk.getIsDynamicEntry(),
  441. get moduleIds() {
  442. return bindingChunk.getModuleIds();
  443. },
  444. get map() {
  445. const map = bindingChunk.getMap();
  446. return map ? transformToRollupSourceMap(map) : null;
  447. },
  448. sourcemapFileName: bindingChunk.getSourcemapFileName() || null,
  449. preliminaryFileName: bindingChunk.getPreliminaryFileName()
  450. };
  451. const cache = {};
  452. return new Proxy(chunk, {
  453. get(target, p) {
  454. if (p in cache) return cache[p];
  455. const value = target[p];
  456. cache[p] = value;
  457. return value;
  458. },
  459. set(_target, p, newValue) {
  460. cache[p] = newValue;
  461. changed.updated.add(bindingChunk.getFileName());
  462. return true;
  463. },
  464. has(target, p) {
  465. if (p in cache) return true;
  466. return p in target;
  467. }
  468. });
  469. }
  470. function transformToRollupOutputAsset(bindingAsset) {
  471. return new OutputAssetImpl(bindingAsset);
  472. }
  473. function transformToMutableRollupOutputAsset(bindingAsset, changed) {
  474. const asset = {
  475. type: "asset",
  476. fileName: bindingAsset.getFileName(),
  477. originalFileName: bindingAsset.getOriginalFileName() || null,
  478. originalFileNames: bindingAsset.getOriginalFileNames(),
  479. get source() {
  480. return transformAssetSource(bindingAsset.getSource());
  481. },
  482. name: bindingAsset.getName() ?? void 0,
  483. names: bindingAsset.getNames()
  484. };
  485. const cache = {};
  486. return new Proxy(asset, {
  487. get(target, p) {
  488. if (p in cache) return cache[p];
  489. const value = target[p];
  490. cache[p] = value;
  491. return value;
  492. },
  493. set(_target, p, newValue) {
  494. cache[p] = newValue;
  495. changed.updated.add(bindingAsset.getFileName());
  496. return true;
  497. }
  498. });
  499. }
  500. function transformToRollupOutput(output) {
  501. const { chunks, assets } = output;
  502. return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk)), ...assets.map((asset) => transformToRollupOutputAsset(asset))] };
  503. }
  504. function transformToMutableRollupOutput(output, changed) {
  505. const { chunks, assets } = output;
  506. return { output: [...chunks.map((chunk) => transformToMutableRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToMutableRollupOutputAsset(asset, changed))] };
  507. }
  508. function transformToOutputBundle(context, output, changed) {
  509. const bundle = Object.fromEntries(transformToMutableRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
  510. return new Proxy(bundle, {
  511. set(_target, _p, _newValue, _receiver) {
  512. const originalStackTraceLimit = Error.stackTraceLimit;
  513. Error.stackTraceLimit = 2;
  514. const message = "This plugin assigns to bundle variable. This is discouraged by Rollup and is not supported by Rolldown. This will be ignored. https://rollupjs.org/plugin-development/#generatebundle:~:text=DANGER,this.emitFile.";
  515. const stack = new Error(message).stack ?? message;
  516. Error.stackTraceLimit = originalStackTraceLimit;
  517. context.warn({
  518. message: stack,
  519. code: "UNSUPPORTED_BUNDLE_ASSIGNMENT"
  520. });
  521. return true;
  522. },
  523. deleteProperty(target, property) {
  524. if (typeof property === "string") changed.deleted.add(property);
  525. return true;
  526. }
  527. });
  528. }
  529. function collectChangedBundle(changed, bundle) {
  530. const changes = {};
  531. for (const key in bundle) {
  532. if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
  533. const item = bundle[key];
  534. if (item.type === "asset") changes[key] = {
  535. filename: item.fileName,
  536. originalFileNames: item.originalFileNames,
  537. source: bindingAssetSource(item.source),
  538. names: item.names
  539. };
  540. else changes[key] = {
  541. code: item.code,
  542. filename: item.fileName,
  543. name: item.name,
  544. isEntry: item.isEntry,
  545. exports: item.exports,
  546. modules: {},
  547. imports: item.imports,
  548. dynamicImports: item.dynamicImports,
  549. facadeModuleId: item.facadeModuleId || void 0,
  550. isDynamicEntry: item.isDynamicEntry,
  551. moduleIds: item.moduleIds,
  552. map: bindingifySourcemap(item.map),
  553. sourcemapFilename: item.sourcemapFileName || void 0,
  554. preliminaryFilename: item.preliminaryFileName
  555. };
  556. }
  557. return {
  558. changes,
  559. deleted: changed.deleted
  560. };
  561. }
  562. //#endregion
  563. //#region src/binding-magic-string.ts
  564. var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
  565. Object.defineProperty(import_binding.BindingMagicString.prototype, "isRolldownMagicString", {
  566. value: true,
  567. writable: false,
  568. configurable: false
  569. });
  570. function assertString(content, msg) {
  571. if (typeof content !== "string") throw new TypeError(msg);
  572. }
  573. const nativeAppend = import_binding.BindingMagicString.prototype.append;
  574. const nativePrepend = import_binding.BindingMagicString.prototype.prepend;
  575. const nativeAppendLeft = import_binding.BindingMagicString.prototype.appendLeft;
  576. const nativeAppendRight = import_binding.BindingMagicString.prototype.appendRight;
  577. const nativePrependLeft = import_binding.BindingMagicString.prototype.prependLeft;
  578. const nativePrependRight = import_binding.BindingMagicString.prototype.prependRight;
  579. const nativeOverwrite = import_binding.BindingMagicString.prototype.overwrite;
  580. const nativeUpdate = import_binding.BindingMagicString.prototype.update;
  581. import_binding.BindingMagicString.prototype.append = function(content) {
  582. assertString(content, "outro content must be a string");
  583. return nativeAppend.call(this, content);
  584. };
  585. import_binding.BindingMagicString.prototype.prepend = function(content) {
  586. assertString(content, "outro content must be a string");
  587. return nativePrepend.call(this, content);
  588. };
  589. import_binding.BindingMagicString.prototype.appendLeft = function(index, content) {
  590. assertString(content, "inserted content must be a string");
  591. return nativeAppendLeft.call(this, index, content);
  592. };
  593. import_binding.BindingMagicString.prototype.appendRight = function(index, content) {
  594. assertString(content, "inserted content must be a string");
  595. return nativeAppendRight.call(this, index, content);
  596. };
  597. import_binding.BindingMagicString.prototype.prependLeft = function(index, content) {
  598. assertString(content, "inserted content must be a string");
  599. return nativePrependLeft.call(this, index, content);
  600. };
  601. import_binding.BindingMagicString.prototype.prependRight = function(index, content) {
  602. assertString(content, "inserted content must be a string");
  603. return nativePrependRight.call(this, index, content);
  604. };
  605. import_binding.BindingMagicString.prototype.overwrite = function(start, end, content, options) {
  606. assertString(content, "replacement content must be a string");
  607. return nativeOverwrite.call(this, start, end, content, options);
  608. };
  609. import_binding.BindingMagicString.prototype.update = function(start, end, content, options) {
  610. assertString(content, "replacement content must be a string");
  611. return nativeUpdate.call(this, start, end, content, options);
  612. };
  613. const nativeReplace = import_binding.BindingMagicString.prototype.replace;
  614. const nativeReplaceAll = import_binding.BindingMagicString.prototype.replaceAll;
  615. import_binding.BindingMagicString.prototype.replace = function(searchValue, replacement) {
  616. if (typeof searchValue === "string") return nativeReplace.call(this, searchValue, replacement);
  617. if (searchValue.global) searchValue.lastIndex = 0;
  618. const lastMatchEnd = this.replaceRegex(searchValue, replacement);
  619. if (searchValue.global) searchValue.lastIndex = 0;
  620. else if (searchValue.sticky) searchValue.lastIndex = lastMatchEnd === -1 ? 0 : lastMatchEnd;
  621. return this;
  622. };
  623. import_binding.BindingMagicString.prototype.replaceAll = function(searchValue, replacement) {
  624. if (typeof searchValue === "string") return nativeReplaceAll.call(this, searchValue, replacement);
  625. if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
  626. searchValue.lastIndex = 0;
  627. this.replaceRegex(searchValue, replacement);
  628. searchValue.lastIndex = 0;
  629. return this;
  630. };
  631. /**
  632. * A native MagicString implementation powered by Rust.
  633. *
  634. * @experimental
  635. */
  636. const RolldownMagicString = import_binding.BindingMagicString;
  637. //#endregion
  638. //#region src/utils/transform-module-info.ts
  639. function transformModuleInfo(info, option) {
  640. return {
  641. get ast() {
  642. return unsupported("ModuleInfo#ast");
  643. },
  644. get code() {
  645. return info.code;
  646. },
  647. id: info.id,
  648. importers: info.importers,
  649. dynamicImporters: info.dynamicImporters,
  650. importedIds: info.importedIds,
  651. dynamicallyImportedIds: info.dynamicallyImportedIds,
  652. exports: info.exports,
  653. isEntry: info.isEntry,
  654. inputFormat: info.inputFormat,
  655. ...option
  656. };
  657. }
  658. //#endregion
  659. //#region src/utils/transform-sourcemap.ts
  660. function isEmptySourcemapFiled(array) {
  661. if (!array) return true;
  662. if (array.length === 0 || !array[0]) return true;
  663. return false;
  664. }
  665. function normalizeTransformHookSourcemap(id, originalCode, rawMap) {
  666. if (!rawMap) return;
  667. let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
  668. if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
  669. if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id) map.sources = [id];
  670. return map;
  671. }
  672. //#endregion
  673. //#region ../../node_modules/.pnpm/remeda@2.33.7/node_modules/remeda/dist/lazyDataLastImpl-DtF3cihj.js
  674. function e(e, t, n) {
  675. let r = (n) => e(n, ...t);
  676. return n === void 0 ? r : Object.assign(r, {
  677. lazy: n,
  678. lazyArgs: t
  679. });
  680. }
  681. //#endregion
  682. //#region ../../node_modules/.pnpm/remeda@2.33.7/node_modules/remeda/dist/purry.js
  683. function t$1(t, n, r) {
  684. let i = t.length - n.length;
  685. if (i === 0) return t(...n);
  686. if (i === 1) return e(t, n, r);
  687. throw Error(`Wrong number of arguments`);
  688. }
  689. //#endregion
  690. //#region ../../node_modules/.pnpm/remeda@2.33.7/node_modules/remeda/dist/partition.js
  691. function t(...t) {
  692. return t$1(n, t);
  693. }
  694. const n = (e, t) => {
  695. let n = [[], []];
  696. for (let [r, i] of e.entries()) t(i, r, e) ? n[0].push(i) : n[1].push(i);
  697. return n;
  698. };
  699. //#endregion
  700. //#region src/plugin/bindingify-hook-filter.ts
  701. function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
  702. if (typeof matcher === "string" || matcher instanceof RegExp) return [filter.include(generateAtomMatcher(stringKind, matcher))];
  703. if (Array.isArray(matcher)) return matcher.map((m) => filter.include(generateAtomMatcher(stringKind, m)));
  704. let ret = [];
  705. if (matcher.exclude) ret.push(...arraify(matcher.exclude).map((m) => filter.exclude(generateAtomMatcher(stringKind, m))));
  706. if (matcher.include) ret.push(...arraify(matcher.include).map((m) => filter.include(generateAtomMatcher(stringKind, m))));
  707. return ret;
  708. }
  709. function generateAtomMatcher(kind, matcher) {
  710. return kind === "code" ? filter.code(matcher) : filter.id(matcher);
  711. }
  712. function transformFilterMatcherToFilterExprs(filterOption) {
  713. if (!filterOption) return;
  714. if (Array.isArray(filterOption)) return filterOption;
  715. const { id, code, moduleType } = filterOption;
  716. let ret = [];
  717. let idIncludes = [];
  718. let idExcludes = [];
  719. let codeIncludes = [];
  720. let codeExcludes = [];
  721. if (id) [idIncludes, idExcludes] = t(generalHookFilterMatcherToFilterExprs(id, "id") ?? [], (m) => m.kind === "include");
  722. if (code) [codeIncludes, codeExcludes] = t(generalHookFilterMatcherToFilterExprs(code, "code") ?? [], (m) => m.kind === "include");
  723. ret.push(...idExcludes);
  724. ret.push(...codeExcludes);
  725. let andExprList = [];
  726. if (moduleType) {
  727. let moduleTypes = Array.isArray(moduleType) ? moduleType : moduleType.include ?? [];
  728. andExprList.push(filter.or(...moduleTypes.map((m) => filter.moduleType(m))));
  729. }
  730. if (idIncludes.length) andExprList.push(filter.or(...idIncludes.map((item) => item.expr)));
  731. if (codeIncludes.length) andExprList.push(filter.or(...codeIncludes.map((item) => item.expr)));
  732. if (andExprList.length) ret.push(filter.include(filter.and(...andExprList)));
  733. return ret;
  734. }
  735. function bindingifyGeneralHookFilter(stringKind, pattern) {
  736. let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
  737. let ret = [];
  738. if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
  739. return ret.length > 0 ? { value: ret } : void 0;
  740. }
  741. function bindingifyFilterExpr(expr) {
  742. let list = [];
  743. bindingifyFilterExprImpl(expr, list);
  744. return list;
  745. }
  746. function containsImporterId(expr) {
  747. switch (expr.kind) {
  748. case "and":
  749. case "or": return expr.args.some(containsImporterId);
  750. case "not":
  751. case "include":
  752. case "exclude": return containsImporterId(expr.expr);
  753. case "importerId": return true;
  754. default: return false;
  755. }
  756. }
  757. function assertNoImporterId(filterExprs, hookName) {
  758. if (filterExprs?.some(containsImporterId)) throw new Error(`The \`importerId\` filter can only be used with the \`resolveId\` hook, but it was used with the \`${hookName}\` hook.`);
  759. }
  760. function bindingifyFilterExprImpl(expr, list) {
  761. switch (expr.kind) {
  762. case "and": {
  763. let args = expr.args;
  764. for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
  765. list.push({
  766. kind: "And",
  767. payload: args.length
  768. });
  769. break;
  770. }
  771. case "or": {
  772. let args = expr.args;
  773. for (let i = args.length - 1; i >= 0; i--) bindingifyFilterExprImpl(args[i], list);
  774. list.push({
  775. kind: "Or",
  776. payload: args.length
  777. });
  778. break;
  779. }
  780. case "not":
  781. bindingifyFilterExprImpl(expr.expr, list);
  782. list.push({ kind: "Not" });
  783. break;
  784. case "id":
  785. list.push({
  786. kind: "Id",
  787. payload: expr.pattern
  788. });
  789. if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
  790. break;
  791. case "importerId":
  792. list.push({
  793. kind: "ImporterId",
  794. payload: expr.pattern
  795. });
  796. if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
  797. break;
  798. case "moduleType":
  799. list.push({
  800. kind: "ModuleType",
  801. payload: expr.pattern
  802. });
  803. break;
  804. case "code":
  805. list.push({
  806. kind: "Code",
  807. payload: expr.pattern
  808. });
  809. break;
  810. case "include":
  811. bindingifyFilterExprImpl(expr.expr, list);
  812. list.push({ kind: "Include" });
  813. break;
  814. case "exclude":
  815. bindingifyFilterExprImpl(expr.expr, list);
  816. list.push({ kind: "Exclude" });
  817. break;
  818. case "query":
  819. list.push({
  820. kind: "QueryKey",
  821. payload: expr.key
  822. });
  823. list.push({
  824. kind: "QueryValue",
  825. payload: expr.pattern
  826. });
  827. break;
  828. default: throw new Error(`Unknown filter expression: ${expr}`);
  829. }
  830. }
  831. function bindingifyResolveIdFilter(filterOption) {
  832. if (!filterOption) return;
  833. if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
  834. return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
  835. }
  836. function bindingifyLoadFilter(filterOption) {
  837. if (!filterOption) return;
  838. if (Array.isArray(filterOption)) {
  839. assertNoImporterId(filterOption, "load");
  840. return { value: filterOption.map(bindingifyFilterExpr) };
  841. }
  842. return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
  843. }
  844. function bindingifyTransformFilter(filterOption) {
  845. if (!filterOption) return;
  846. let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
  847. assertNoImporterId(filterExprs, "transform");
  848. let ret = [];
  849. if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
  850. return { value: ret.length > 0 ? ret : void 0 };
  851. }
  852. function bindingifyRenderChunkFilter(filterOption) {
  853. if (!filterOption) return;
  854. if (Array.isArray(filterOption)) {
  855. assertNoImporterId(filterOption, "renderChunk");
  856. return { value: filterOption.map(bindingifyFilterExpr) };
  857. }
  858. return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
  859. }
  860. //#endregion
  861. //#region src/plugin/bindingify-plugin-hook-meta.ts
  862. function bindingifyPluginHookMeta(options) {
  863. return { order: bindingPluginOrder(options.order) };
  864. }
  865. function bindingPluginOrder(order) {
  866. switch (order) {
  867. case "post": return import_binding.BindingPluginOrder.Post;
  868. case "pre": return import_binding.BindingPluginOrder.Pre;
  869. case null:
  870. case void 0: return;
  871. default: throw new Error(`Unknown plugin order: ${order}`);
  872. }
  873. }
  874. //#endregion
  875. //#region src/plugin/fs.ts
  876. const fsModule = {
  877. appendFile: fsp.appendFile,
  878. copyFile: fsp.copyFile,
  879. mkdir: fsp.mkdir,
  880. mkdtemp: fsp.mkdtemp,
  881. readdir: fsp.readdir,
  882. readFile: fsp.readFile,
  883. realpath: fsp.realpath,
  884. rename: fsp.rename,
  885. rmdir: fsp.rmdir,
  886. stat: fsp.stat,
  887. lstat: fsp.lstat,
  888. unlink: fsp.unlink,
  889. writeFile: fsp.writeFile
  890. };
  891. //#endregion
  892. //#region src/plugin/plugin-context.ts
  893. var PluginContextImpl = class extends MinimalPluginContextImpl {
  894. fs = fsModule;
  895. getModuleInfo;
  896. constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
  897. super(onLog, logLevel, plugin.name, watchMode);
  898. this.outputOptions = outputOptions;
  899. this.context = context;
  900. this.data = data;
  901. this.onLog = onLog;
  902. this.currentLoadingModule = currentLoadingModule;
  903. this.getModuleInfo = (id) => this.data.getModuleInfo(id, context);
  904. }
  905. async load(options) {
  906. const id = options.id;
  907. if (id === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, logCycleLoading(this.pluginName, this.currentLoadingModule));
  908. const moduleInfo = this.data.getModuleInfo(id, this.context);
  909. if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
  910. const rawOptions = {
  911. meta: options.meta || {},
  912. moduleSideEffects: options.moduleSideEffects || null,
  913. invalidate: false
  914. };
  915. this.data.updateModuleOption(id, rawOptions);
  916. let loadPromise = this.data.loadModulePromiseMap.get(id);
  917. if (!loadPromise) {
  918. loadPromise = this.context.load(id, options.moduleSideEffects ?? void 0, options.packageJsonPath ?? void 0).catch(() => {
  919. this.data.loadModulePromiseMap.delete(id);
  920. });
  921. this.data.loadModulePromiseMap.set(id, loadPromise);
  922. }
  923. await loadPromise;
  924. return this.data.getModuleInfo(id, this.context);
  925. }
  926. async resolve(source, importer, options) {
  927. let receipt = void 0;
  928. if (options != null) receipt = this.data.saveResolveOptions(options);
  929. const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
  930. if (key.startsWith("vite:")) (acc ??= {})[key] = value;
  931. return acc;
  932. }, void 0);
  933. const res = await this.context.resolve(source, importer, {
  934. importKind: options?.kind,
  935. custom: receipt,
  936. isEntry: options?.isEntry,
  937. skipSelf: options?.skipSelf,
  938. vitePluginCustom
  939. });
  940. if (receipt != null) this.data.removeSavedResolveOptions(receipt);
  941. if (res == null) return null;
  942. const info = this.data.getModuleOption(res.id) || {};
  943. return {
  944. ...res,
  945. external: res.external === "relative" ? unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
  946. ...info,
  947. moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
  948. packageJsonPath: res.packageJsonPath
  949. };
  950. }
  951. emitFile = (file) => {
  952. if (file.type === "prebuilt-chunk") return this.context.emitPrebuiltChunk({
  953. fileName: file.fileName,
  954. name: file.name,
  955. code: file.code,
  956. exports: file.exports,
  957. map: bindingifySourcemap(file.map),
  958. sourcemapFileName: file.sourcemapFileName,
  959. facadeModuleId: file.facadeModuleId,
  960. isEntry: file.isEntry,
  961. isDynamicEntry: file.isDynamicEntry
  962. });
  963. if (file.type === "chunk") return this.context.emitChunk({
  964. preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
  965. ...file
  966. });
  967. const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
  968. const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
  969. return this.context.emitFile({
  970. ...file,
  971. originalFileName: file.originalFileName || void 0,
  972. source: bindingAssetSource(file.source)
  973. }, filename, fnSanitizedFileName);
  974. };
  975. getAssetFileNames(file) {
  976. if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
  977. type: "asset",
  978. name: file.name,
  979. names: file.name ? [file.name] : [],
  980. originalFileName: file.originalFileName,
  981. originalFileNames: file.originalFileName ? [file.originalFileName] : [],
  982. source: file.source
  983. });
  984. }
  985. getFileName(referenceId) {
  986. return this.context.getFileName(referenceId);
  987. }
  988. getModuleIds() {
  989. return this.data.getModuleIds(this.context);
  990. }
  991. addWatchFile(id) {
  992. this.context.addWatchFile(id);
  993. }
  994. parse(input, options) {
  995. return parseAst(input, options);
  996. }
  997. };
  998. //#endregion
  999. //#region src/plugin/load-plugin-context.ts
  1000. var LoadPluginContextImpl = class extends PluginContextImpl {
  1001. constructor(outputOptions, context, plugin, data, inner, moduleId, onLog, logLevelOption, watchMode) {
  1002. super(outputOptions, context, plugin, data, onLog, logLevelOption, watchMode, moduleId);
  1003. this.inner = inner;
  1004. }
  1005. addWatchFile(id) {
  1006. this.inner.addWatchFile(id);
  1007. }
  1008. };
  1009. //#endregion
  1010. //#region src/plugin/transform-plugin-context.ts
  1011. var TransformPluginContextImpl = class extends PluginContextImpl {
  1012. constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
  1013. super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
  1014. this.inner = inner;
  1015. this.moduleId = moduleId;
  1016. this.moduleSource = moduleSource;
  1017. const getLogHandler = (handler) => (log, pos) => {
  1018. log = normalizeLog(log);
  1019. if (pos) augmentCodeLocation(log, pos, moduleSource, moduleId);
  1020. log.id = moduleId;
  1021. log.hook = "transform";
  1022. handler(log);
  1023. };
  1024. this.debug = getLogHandler(this.debug);
  1025. this.warn = getLogHandler(this.warn);
  1026. this.info = getLogHandler(this.info);
  1027. }
  1028. error(e, pos) {
  1029. if (typeof e === "string") e = { message: e };
  1030. if (pos) augmentCodeLocation(e, pos, this.moduleSource, this.moduleId);
  1031. e.id = this.moduleId;
  1032. e.hook = "transform";
  1033. return error(logPluginError(normalizeLog(e), this.pluginName));
  1034. }
  1035. getCombinedSourcemap() {
  1036. return JSON.parse(this.inner.getCombinedSourcemap());
  1037. }
  1038. addWatchFile(id) {
  1039. this.inner.addWatchFile(id);
  1040. }
  1041. sendMagicString(s) {
  1042. this.inner.sendMagicString(s);
  1043. }
  1044. };
  1045. //#endregion
  1046. //#region src/plugin/bindingify-build-hooks.ts
  1047. function createPluginContext(args, ctx) {
  1048. return new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
  1049. }
  1050. function bindingifyBuildStart(args) {
  1051. const hook = args.plugin.buildStart;
  1052. if (!hook) return {};
  1053. const { handler, meta } = normalizeHook(hook);
  1054. return {
  1055. plugin: async (ctx, opts) => {
  1056. await handler.call(createPluginContext(args, ctx), args.pluginContextData.getInputOptions(opts));
  1057. },
  1058. meta: bindingifyPluginHookMeta(meta)
  1059. };
  1060. }
  1061. function bindingifyBuildEnd(args) {
  1062. const hook = args.plugin.buildEnd;
  1063. if (!hook) return {};
  1064. const { handler, meta } = normalizeHook(hook);
  1065. return {
  1066. plugin: async (ctx, err) => {
  1067. await handler.call(createPluginContext(args, ctx), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
  1068. },
  1069. meta: bindingifyPluginHookMeta(meta)
  1070. };
  1071. }
  1072. function bindingifyResolveId(args) {
  1073. const hook = args.plugin.resolveId;
  1074. if (!hook) return {};
  1075. const { handler, meta, options } = normalizeHook(hook);
  1076. return {
  1077. plugin: async (ctx, specifier, importer, extraOptions) => {
  1078. const contextResolveOptions = extraOptions.custom != null ? args.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
  1079. const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0, {
  1080. ...extraOptions,
  1081. custom: contextResolveOptions?.custom
  1082. });
  1083. if (ret == null) return;
  1084. if (ret === false) return {
  1085. id: specifier,
  1086. external: true,
  1087. normalizeExternalId: true
  1088. };
  1089. if (typeof ret === "string") return {
  1090. id: ret,
  1091. normalizeExternalId: false
  1092. };
  1093. let exist = args.pluginContextData.updateModuleOption(ret.id, {
  1094. meta: ret.meta || {},
  1095. moduleSideEffects: ret.moduleSideEffects ?? null,
  1096. invalidate: false
  1097. });
  1098. return {
  1099. id: ret.id,
  1100. external: ret.external,
  1101. normalizeExternalId: false,
  1102. moduleSideEffects: exist.moduleSideEffects ?? void 0,
  1103. packageJsonPath: ret.packageJsonPath
  1104. };
  1105. },
  1106. meta: bindingifyPluginHookMeta(meta),
  1107. filter: bindingifyResolveIdFilter(options.filter)
  1108. };
  1109. }
  1110. function bindingifyResolveDynamicImport(args) {
  1111. const hook = args.plugin.resolveDynamicImport;
  1112. if (!hook) return {};
  1113. const { handler, meta } = normalizeHook(hook);
  1114. return {
  1115. plugin: async (ctx, specifier, importer) => {
  1116. const ret = await handler.call(createPluginContext(args, ctx), specifier, importer ?? void 0);
  1117. if (ret == null) return;
  1118. if (ret === false) return {
  1119. id: specifier,
  1120. external: true
  1121. };
  1122. if (typeof ret === "string") return { id: ret };
  1123. const result = {
  1124. id: ret.id,
  1125. external: ret.external,
  1126. packageJsonPath: ret.packageJsonPath
  1127. };
  1128. if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
  1129. args.pluginContextData.updateModuleOption(ret.id, {
  1130. meta: ret.meta || {},
  1131. moduleSideEffects: ret.moduleSideEffects || null,
  1132. invalidate: false
  1133. });
  1134. return result;
  1135. },
  1136. meta: bindingifyPluginHookMeta(meta)
  1137. };
  1138. }
  1139. function bindingifyTransform(args) {
  1140. const hook = args.plugin.transform;
  1141. if (!hook) return {};
  1142. const { handler, meta, options } = normalizeHook(hook);
  1143. return {
  1144. plugin: async (ctx, code, id, meta) => {
  1145. let magicStringInstance, astInstance;
  1146. Object.defineProperties(meta, {
  1147. magicString: { get() {
  1148. if (magicStringInstance) return magicStringInstance;
  1149. magicStringInstance = new RolldownMagicString(code);
  1150. return magicStringInstance;
  1151. } },
  1152. ast: { get() {
  1153. if (astInstance) return astInstance;
  1154. let lang = "js";
  1155. switch (meta.moduleType) {
  1156. case "js":
  1157. case "jsx":
  1158. case "ts":
  1159. case "tsx":
  1160. lang = meta.moduleType;
  1161. break;
  1162. default: break;
  1163. }
  1164. astInstance = parseAst(code, {
  1165. astType: meta.moduleType.includes("ts") ? "ts" : "js",
  1166. lang
  1167. });
  1168. return astInstance;
  1169. } }
  1170. });
  1171. const transformCtx = new TransformPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, code, args.onLog, args.logLevel, args.watchMode);
  1172. const ret = await handler.call(transformCtx, code, id, meta);
  1173. if (ret == null) return;
  1174. if (typeof ret === "string") return { code: ret };
  1175. let moduleOption = args.pluginContextData.updateModuleOption(id, {
  1176. meta: ret.meta ?? {},
  1177. moduleSideEffects: ret.moduleSideEffects ?? null,
  1178. invalidate: false
  1179. });
  1180. let normalizedCode = void 0;
  1181. let map = ret.map;
  1182. if (typeof ret.code === "string") normalizedCode = ret.code;
  1183. else if (ret.code instanceof RolldownMagicString) {
  1184. let magicString = ret.code;
  1185. normalizedCode = magicString.toString();
  1186. let fallbackSourcemap = ctx.sendMagicString(magicString);
  1187. if (fallbackSourcemap != void 0) map = fallbackSourcemap;
  1188. }
  1189. return {
  1190. code: normalizedCode,
  1191. map: bindingifySourcemap(normalizeTransformHookSourcemap(id, code, map)),
  1192. moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
  1193. moduleType: ret.moduleType
  1194. };
  1195. },
  1196. meta: bindingifyPluginHookMeta(meta),
  1197. filter: bindingifyTransformFilter(options.filter)
  1198. };
  1199. }
  1200. function bindingifyLoad(args) {
  1201. const hook = args.plugin.load;
  1202. if (!hook) return {};
  1203. const { handler, meta, options } = normalizeHook(hook);
  1204. return {
  1205. plugin: async (ctx, id) => {
  1206. const ret = await handler.call(new LoadPluginContextImpl(args.outputOptions, ctx.inner(), args.plugin, args.pluginContextData, ctx, id, args.onLog, args.logLevel, args.watchMode), id);
  1207. if (ret == null) return;
  1208. if (typeof ret === "string") return { code: ret };
  1209. let moduleOption = args.pluginContextData.updateModuleOption(id, {
  1210. meta: ret.meta || {},
  1211. moduleSideEffects: ret.moduleSideEffects ?? null,
  1212. invalidate: false
  1213. });
  1214. let map = preProcessSourceMap(ret, id);
  1215. return {
  1216. code: ret.code,
  1217. map: bindingifySourcemap(map),
  1218. moduleType: ret.moduleType,
  1219. moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
  1220. };
  1221. },
  1222. meta: bindingifyPluginHookMeta(meta),
  1223. filter: bindingifyLoadFilter(options.filter)
  1224. };
  1225. }
  1226. function preProcessSourceMap(ret, id) {
  1227. if (!ret.map) return;
  1228. let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
  1229. if (!isEmptySourcemapFiled(map.sources)) {
  1230. const directory = path.dirname(id) || ".";
  1231. const sourceRoot = map.sourceRoot || ".";
  1232. map.sources = map.sources.map((source) => path.resolve(directory, sourceRoot, source));
  1233. }
  1234. return map;
  1235. }
  1236. function bindingifyModuleParsed(args) {
  1237. const hook = args.plugin.moduleParsed;
  1238. if (!hook) return {};
  1239. const { handler, meta } = normalizeHook(hook);
  1240. return {
  1241. plugin: async (ctx, moduleInfo) => {
  1242. await handler.call(createPluginContext(args, ctx), transformModuleInfo(moduleInfo, args.pluginContextData.getModuleOption(moduleInfo.id)));
  1243. },
  1244. meta: bindingifyPluginHookMeta(meta)
  1245. };
  1246. }
  1247. //#endregion
  1248. //#region src/plugin/bindingify-output-hooks.ts
  1249. function bindingifyRenderStart(args) {
  1250. const hook = args.plugin.renderStart;
  1251. if (!hook) return {};
  1252. const { handler, meta } = normalizeHook(hook);
  1253. return {
  1254. plugin: async (ctx, opts) => {
  1255. handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), args.pluginContextData.getOutputOptions(opts), args.pluginContextData.getInputOptions(opts));
  1256. },
  1257. meta: bindingifyPluginHookMeta(meta)
  1258. };
  1259. }
  1260. function bindingifyRenderChunk(args) {
  1261. const hook = args.plugin.renderChunk;
  1262. if (!hook) return {};
  1263. const { handler, meta, options } = normalizeHook(hook);
  1264. return {
  1265. plugin: async (ctx, code, chunk, opts, meta) => {
  1266. if (args.pluginContextData.getRenderChunkMeta() == null) args.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
  1267. const renderChunkMeta = args.pluginContextData.getRenderChunkMeta();
  1268. let magicStringInstance;
  1269. if (args.options.experimental?.nativeMagicString) Object.defineProperty(renderChunkMeta, "magicString", {
  1270. get() {
  1271. if (magicStringInstance) return magicStringInstance;
  1272. magicStringInstance = new RolldownMagicString(code);
  1273. return magicStringInstance;
  1274. },
  1275. configurable: true
  1276. });
  1277. const ret = await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), code, transformRenderedChunk(chunk), args.pluginContextData.getOutputOptions(opts), renderChunkMeta);
  1278. if (ret == null) return;
  1279. if (ret instanceof RolldownMagicString) {
  1280. const normalizedCode = ret.toString();
  1281. const generatedMap = ret.generateMap();
  1282. return {
  1283. code: normalizedCode,
  1284. map: bindingifySourcemap({
  1285. file: generatedMap.file,
  1286. mappings: generatedMap.mappings,
  1287. names: generatedMap.names,
  1288. sources: generatedMap.sources,
  1289. sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
  1290. })
  1291. };
  1292. }
  1293. if (typeof ret === "string") return { code: ret };
  1294. if (ret.code instanceof RolldownMagicString) {
  1295. const magicString = ret.code;
  1296. const normalizedCode = magicString.toString();
  1297. if (ret.map === null) return { code: normalizedCode };
  1298. if (ret.map === void 0) {
  1299. const generatedMap = magicString.generateMap();
  1300. return {
  1301. code: normalizedCode,
  1302. map: bindingifySourcemap({
  1303. file: generatedMap.file,
  1304. mappings: generatedMap.mappings,
  1305. names: generatedMap.names,
  1306. sources: generatedMap.sources,
  1307. sourcesContent: generatedMap.sourcesContent.map((s) => s ?? null)
  1308. })
  1309. };
  1310. }
  1311. return {
  1312. code: normalizedCode,
  1313. map: bindingifySourcemap(ret.map)
  1314. };
  1315. }
  1316. if (!ret.map) return { code: ret.code };
  1317. return {
  1318. code: ret.code,
  1319. map: bindingifySourcemap(ret.map)
  1320. };
  1321. },
  1322. meta: bindingifyPluginHookMeta(meta),
  1323. filter: bindingifyRenderChunkFilter(options.filter)
  1324. };
  1325. }
  1326. function bindingifyAugmentChunkHash(args) {
  1327. const hook = args.plugin.augmentChunkHash;
  1328. if (!hook) return {};
  1329. const { handler, meta } = normalizeHook(hook);
  1330. return {
  1331. plugin: async (ctx, chunk) => {
  1332. return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
  1333. },
  1334. meta: bindingifyPluginHookMeta(meta)
  1335. };
  1336. }
  1337. function bindingifyRenderError(args) {
  1338. const hook = args.plugin.renderError;
  1339. if (!hook) return {};
  1340. const { handler, meta } = normalizeHook(hook);
  1341. return {
  1342. plugin: async (ctx, err) => {
  1343. handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), aggregateBindingErrorsIntoJsError(err));
  1344. },
  1345. meta: bindingifyPluginHookMeta(meta)
  1346. };
  1347. }
  1348. function bindingifyGenerateBundle(args) {
  1349. const hook = args.plugin.generateBundle;
  1350. if (!hook) return {};
  1351. const { handler, meta } = normalizeHook(hook);
  1352. return {
  1353. plugin: async (ctx, bundle, isWrite, opts) => {
  1354. const changed = {
  1355. updated: /* @__PURE__ */ new Set(),
  1356. deleted: /* @__PURE__ */ new Set()
  1357. };
  1358. const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
  1359. const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
  1360. await handler.call(context, args.pluginContextData.getOutputOptions(opts), output, isWrite);
  1361. return collectChangedBundle(changed, output);
  1362. },
  1363. meta: bindingifyPluginHookMeta(meta)
  1364. };
  1365. }
  1366. function bindingifyWriteBundle(args) {
  1367. const hook = args.plugin.writeBundle;
  1368. if (!hook) return {};
  1369. const { handler, meta } = normalizeHook(hook);
  1370. return {
  1371. plugin: async (ctx, bundle, opts) => {
  1372. const changed = {
  1373. updated: /* @__PURE__ */ new Set(),
  1374. deleted: /* @__PURE__ */ new Set()
  1375. };
  1376. const context = new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode);
  1377. const output = transformToOutputBundle(context, unwrapBindingResult(bundle), changed);
  1378. await handler.call(context, args.pluginContextData.getOutputOptions(opts), output);
  1379. return collectChangedBundle(changed, output);
  1380. },
  1381. meta: bindingifyPluginHookMeta(meta)
  1382. };
  1383. }
  1384. function bindingifyCloseBundle(args) {
  1385. const hook = args.plugin.closeBundle;
  1386. if (!hook) return {};
  1387. const { handler, meta } = normalizeHook(hook);
  1388. return {
  1389. plugin: async (ctx, err) => {
  1390. await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), err ? aggregateBindingErrorsIntoJsError(err) : void 0);
  1391. },
  1392. meta: bindingifyPluginHookMeta(meta)
  1393. };
  1394. }
  1395. function bindingifyBanner(args) {
  1396. const hook = args.plugin.banner;
  1397. if (!hook) return {};
  1398. const { handler, meta } = normalizeHook(hook);
  1399. return {
  1400. plugin: async (ctx, chunk) => {
  1401. if (typeof handler === "string") return handler;
  1402. return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
  1403. },
  1404. meta: bindingifyPluginHookMeta(meta)
  1405. };
  1406. }
  1407. function bindingifyFooter(args) {
  1408. const hook = args.plugin.footer;
  1409. if (!hook) return {};
  1410. const { handler, meta } = normalizeHook(hook);
  1411. return {
  1412. plugin: async (ctx, chunk) => {
  1413. if (typeof handler === "string") return handler;
  1414. return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
  1415. },
  1416. meta: bindingifyPluginHookMeta(meta)
  1417. };
  1418. }
  1419. function bindingifyIntro(args) {
  1420. const hook = args.plugin.intro;
  1421. if (!hook) return {};
  1422. const { handler, meta } = normalizeHook(hook);
  1423. return {
  1424. plugin: async (ctx, chunk) => {
  1425. if (typeof handler === "string") return handler;
  1426. return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
  1427. },
  1428. meta: bindingifyPluginHookMeta(meta)
  1429. };
  1430. }
  1431. function bindingifyOutro(args) {
  1432. const hook = args.plugin.outro;
  1433. if (!hook) return {};
  1434. const { handler, meta } = normalizeHook(hook);
  1435. return {
  1436. plugin: async (ctx, chunk) => {
  1437. if (typeof handler === "string") return handler;
  1438. return handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), transformRenderedChunk(chunk));
  1439. },
  1440. meta: bindingifyPluginHookMeta(meta)
  1441. };
  1442. }
  1443. //#endregion
  1444. //#region src/plugin/bindingify-watch-hooks.ts
  1445. function bindingifyWatchChange(args) {
  1446. const hook = args.plugin.watchChange;
  1447. if (!hook) return {};
  1448. const { handler, meta } = normalizeHook(hook);
  1449. return {
  1450. plugin: async (ctx, id, event) => {
  1451. await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode), id, { event });
  1452. },
  1453. meta: bindingifyPluginHookMeta(meta)
  1454. };
  1455. }
  1456. function bindingifyCloseWatcher(args) {
  1457. const hook = args.plugin.closeWatcher;
  1458. if (!hook) return {};
  1459. const { handler, meta } = normalizeHook(hook);
  1460. return {
  1461. plugin: async (ctx) => {
  1462. await handler.call(new PluginContextImpl(args.outputOptions, ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel, args.watchMode));
  1463. },
  1464. meta: bindingifyPluginHookMeta(meta)
  1465. };
  1466. }
  1467. //#endregion
  1468. //#region src/plugin/generated/hook-usage.ts
  1469. let HookUsageKind = /* @__PURE__ */ function(HookUsageKind) {
  1470. HookUsageKind[HookUsageKind["buildStart"] = 1] = "buildStart";
  1471. HookUsageKind[HookUsageKind["resolveId"] = 2] = "resolveId";
  1472. HookUsageKind[HookUsageKind["resolveDynamicImport"] = 4] = "resolveDynamicImport";
  1473. HookUsageKind[HookUsageKind["load"] = 8] = "load";
  1474. HookUsageKind[HookUsageKind["transform"] = 16] = "transform";
  1475. HookUsageKind[HookUsageKind["moduleParsed"] = 32] = "moduleParsed";
  1476. HookUsageKind[HookUsageKind["buildEnd"] = 64] = "buildEnd";
  1477. HookUsageKind[HookUsageKind["renderStart"] = 128] = "renderStart";
  1478. HookUsageKind[HookUsageKind["renderError"] = 256] = "renderError";
  1479. HookUsageKind[HookUsageKind["renderChunk"] = 512] = "renderChunk";
  1480. HookUsageKind[HookUsageKind["augmentChunkHash"] = 1024] = "augmentChunkHash";
  1481. HookUsageKind[HookUsageKind["generateBundle"] = 2048] = "generateBundle";
  1482. HookUsageKind[HookUsageKind["writeBundle"] = 4096] = "writeBundle";
  1483. HookUsageKind[HookUsageKind["closeBundle"] = 8192] = "closeBundle";
  1484. HookUsageKind[HookUsageKind["watchChange"] = 16384] = "watchChange";
  1485. HookUsageKind[HookUsageKind["closeWatcher"] = 32768] = "closeWatcher";
  1486. HookUsageKind[HookUsageKind["transformAst"] = 65536] = "transformAst";
  1487. HookUsageKind[HookUsageKind["banner"] = 131072] = "banner";
  1488. HookUsageKind[HookUsageKind["footer"] = 262144] = "footer";
  1489. HookUsageKind[HookUsageKind["intro"] = 524288] = "intro";
  1490. HookUsageKind[HookUsageKind["outro"] = 1048576] = "outro";
  1491. return HookUsageKind;
  1492. }({});
  1493. var HookUsage = class {
  1494. bitflag = BigInt(0);
  1495. constructor() {}
  1496. union(kind) {
  1497. this.bitflag |= BigInt(kind);
  1498. }
  1499. inner() {
  1500. return Number(this.bitflag);
  1501. }
  1502. };
  1503. function extractHookUsage(plugin) {
  1504. let hookUsage = new HookUsage();
  1505. if (plugin.buildStart) hookUsage.union(HookUsageKind.buildStart);
  1506. if (plugin.resolveId) hookUsage.union(HookUsageKind.resolveId);
  1507. if (plugin.resolveDynamicImport) hookUsage.union(HookUsageKind.resolveDynamicImport);
  1508. if (plugin.load) hookUsage.union(HookUsageKind.load);
  1509. if (plugin.transform) hookUsage.union(HookUsageKind.transform);
  1510. if (plugin.moduleParsed) hookUsage.union(HookUsageKind.moduleParsed);
  1511. if (plugin.buildEnd) hookUsage.union(HookUsageKind.buildEnd);
  1512. if (plugin.renderStart) hookUsage.union(HookUsageKind.renderStart);
  1513. if (plugin.renderError) hookUsage.union(HookUsageKind.renderError);
  1514. if (plugin.renderChunk) hookUsage.union(HookUsageKind.renderChunk);
  1515. if (plugin.augmentChunkHash) hookUsage.union(HookUsageKind.augmentChunkHash);
  1516. if (plugin.generateBundle) hookUsage.union(HookUsageKind.generateBundle);
  1517. if (plugin.writeBundle) hookUsage.union(HookUsageKind.writeBundle);
  1518. if (plugin.closeBundle) hookUsage.union(HookUsageKind.closeBundle);
  1519. if (plugin.watchChange) hookUsage.union(HookUsageKind.watchChange);
  1520. if (plugin.closeWatcher) hookUsage.union(HookUsageKind.closeWatcher);
  1521. if (plugin.banner) hookUsage.union(HookUsageKind.banner);
  1522. if (plugin.footer) hookUsage.union(HookUsageKind.footer);
  1523. if (plugin.intro) hookUsage.union(HookUsageKind.intro);
  1524. if (plugin.outro) hookUsage.union(HookUsageKind.outro);
  1525. return hookUsage;
  1526. }
  1527. //#endregion
  1528. //#region src/plugin/bindingify-plugin.ts
  1529. function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
  1530. const args = {
  1531. plugin,
  1532. options,
  1533. outputOptions,
  1534. pluginContextData,
  1535. onLog,
  1536. logLevel,
  1537. watchMode,
  1538. normalizedOutputPlugins
  1539. };
  1540. const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args);
  1541. const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args);
  1542. const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args);
  1543. const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args);
  1544. const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args);
  1545. const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args);
  1546. const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args);
  1547. const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args);
  1548. const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args);
  1549. const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args);
  1550. const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args);
  1551. const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args);
  1552. const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args);
  1553. const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args);
  1554. const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args);
  1555. const { plugin: footer, meta: footerMeta } = bindingifyFooter(args);
  1556. const { plugin: intro, meta: introMeta } = bindingifyIntro(args);
  1557. const { plugin: outro, meta: outroMeta } = bindingifyOutro(args);
  1558. const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args);
  1559. const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args);
  1560. let hookUsage = extractHookUsage(plugin).inner();
  1561. return wrapHandlers({
  1562. name: plugin.name,
  1563. buildStart,
  1564. buildStartMeta,
  1565. resolveId,
  1566. resolveIdMeta,
  1567. resolveIdFilter,
  1568. resolveDynamicImport,
  1569. resolveDynamicImportMeta,
  1570. buildEnd,
  1571. buildEndMeta,
  1572. transform,
  1573. transformMeta,
  1574. transformFilter,
  1575. moduleParsed,
  1576. moduleParsedMeta,
  1577. load,
  1578. loadMeta,
  1579. loadFilter,
  1580. renderChunk,
  1581. renderChunkMeta,
  1582. renderChunkFilter,
  1583. augmentChunkHash,
  1584. augmentChunkHashMeta,
  1585. renderStart,
  1586. renderStartMeta,
  1587. renderError,
  1588. renderErrorMeta,
  1589. generateBundle,
  1590. generateBundleMeta,
  1591. writeBundle,
  1592. writeBundleMeta,
  1593. closeBundle,
  1594. closeBundleMeta,
  1595. banner,
  1596. bannerMeta,
  1597. footer,
  1598. footerMeta,
  1599. intro,
  1600. introMeta,
  1601. outro,
  1602. outroMeta,
  1603. watchChange,
  1604. watchChangeMeta,
  1605. closeWatcher,
  1606. closeWatcherMeta,
  1607. hookUsage
  1608. });
  1609. }
  1610. function wrapHandlers(plugin) {
  1611. for (const hookName of [
  1612. "buildStart",
  1613. "resolveId",
  1614. "resolveDynamicImport",
  1615. "buildEnd",
  1616. "transform",
  1617. "moduleParsed",
  1618. "load",
  1619. "renderChunk",
  1620. "augmentChunkHash",
  1621. "renderStart",
  1622. "renderError",
  1623. "generateBundle",
  1624. "writeBundle",
  1625. "closeBundle",
  1626. "banner",
  1627. "footer",
  1628. "intro",
  1629. "outro",
  1630. "watchChange",
  1631. "closeWatcher"
  1632. ]) {
  1633. const handler = plugin[hookName];
  1634. if (handler) plugin[hookName] = async (...args) => {
  1635. try {
  1636. return await handler(...args);
  1637. } catch (e) {
  1638. return error(logPluginError(e, plugin.name, {
  1639. hook: hookName,
  1640. id: hookName === "transform" ? args[2] : void 0
  1641. }));
  1642. }
  1643. };
  1644. }
  1645. return plugin;
  1646. }
  1647. //#endregion
  1648. //#region src/options/normalized-input-options.ts
  1649. var NormalizedInputOptionsImpl = class extends PlainObjectLike {
  1650. inner;
  1651. constructor(inner, onLog, inputPlugins) {
  1652. super();
  1653. this.onLog = onLog;
  1654. this.inputPlugins = inputPlugins;
  1655. this.inner = inner;
  1656. }
  1657. get shimMissingExports() {
  1658. return this.inner.shimMissingExports;
  1659. }
  1660. get input() {
  1661. return this.inner.input;
  1662. }
  1663. get cwd() {
  1664. return this.inner.cwd;
  1665. }
  1666. get platform() {
  1667. return this.inner.platform;
  1668. }
  1669. get context() {
  1670. return this.inner.context;
  1671. }
  1672. get plugins() {
  1673. return this.inputPlugins;
  1674. }
  1675. };
  1676. __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "shimMissingExports", null);
  1677. __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "input", null);
  1678. __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "cwd", null);
  1679. __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "platform", null);
  1680. __decorate([lazyProp], NormalizedInputOptionsImpl.prototype, "context", null);
  1681. //#endregion
  1682. //#region src/options/normalized-output-options.ts
  1683. var NormalizedOutputOptionsImpl = class extends PlainObjectLike {
  1684. constructor(inner, outputOptions, normalizedOutputPlugins) {
  1685. super();
  1686. this.inner = inner;
  1687. this.outputOptions = outputOptions;
  1688. this.normalizedOutputPlugins = normalizedOutputPlugins;
  1689. }
  1690. get dir() {
  1691. return this.inner.dir ?? void 0;
  1692. }
  1693. get entryFileNames() {
  1694. return this.inner.entryFilenames || this.outputOptions.entryFileNames;
  1695. }
  1696. get chunkFileNames() {
  1697. return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
  1698. }
  1699. get assetFileNames() {
  1700. return this.inner.assetFilenames || this.outputOptions.assetFileNames;
  1701. }
  1702. get format() {
  1703. return this.inner.format;
  1704. }
  1705. get exports() {
  1706. return this.inner.exports;
  1707. }
  1708. get sourcemap() {
  1709. return this.inner.sourcemap;
  1710. }
  1711. get sourcemapBaseUrl() {
  1712. return this.inner.sourcemapBaseUrl ?? void 0;
  1713. }
  1714. get shimMissingExports() {
  1715. return this.inner.shimMissingExports;
  1716. }
  1717. get name() {
  1718. return this.inner.name ?? void 0;
  1719. }
  1720. get file() {
  1721. return this.inner.file ?? void 0;
  1722. }
  1723. get codeSplitting() {
  1724. return this.inner.codeSplitting;
  1725. }
  1726. /**
  1727. * @deprecated Use `codeSplitting` instead.
  1728. */
  1729. get inlineDynamicImports() {
  1730. return !this.inner.codeSplitting;
  1731. }
  1732. get dynamicImportInCjs() {
  1733. return this.inner.dynamicImportInCjs;
  1734. }
  1735. get externalLiveBindings() {
  1736. return this.inner.externalLiveBindings;
  1737. }
  1738. get banner() {
  1739. return normalizeAddon(this.outputOptions.banner);
  1740. }
  1741. get footer() {
  1742. return normalizeAddon(this.outputOptions.footer);
  1743. }
  1744. get postBanner() {
  1745. return normalizeAddon(this.outputOptions.postBanner);
  1746. }
  1747. get postFooter() {
  1748. return normalizeAddon(this.outputOptions.postFooter);
  1749. }
  1750. get intro() {
  1751. return normalizeAddon(this.outputOptions.intro);
  1752. }
  1753. get outro() {
  1754. return normalizeAddon(this.outputOptions.outro);
  1755. }
  1756. get esModule() {
  1757. return this.inner.esModule;
  1758. }
  1759. get extend() {
  1760. return this.inner.extend;
  1761. }
  1762. get globals() {
  1763. return this.inner.globals || this.outputOptions.globals;
  1764. }
  1765. get paths() {
  1766. return this.outputOptions.paths;
  1767. }
  1768. get hashCharacters() {
  1769. return this.inner.hashCharacters;
  1770. }
  1771. get sourcemapDebugIds() {
  1772. return this.inner.sourcemapDebugIds;
  1773. }
  1774. get sourcemapExcludeSources() {
  1775. return this.inner.sourcemapExcludeSources;
  1776. }
  1777. get sourcemapIgnoreList() {
  1778. return this.outputOptions.sourcemapIgnoreList;
  1779. }
  1780. get sourcemapPathTransform() {
  1781. return this.outputOptions.sourcemapPathTransform;
  1782. }
  1783. get minify() {
  1784. let ret = this.inner.minify;
  1785. if (typeof ret === "object" && ret !== null) {
  1786. delete ret["codegen"];
  1787. delete ret["module"];
  1788. delete ret["sourcemap"];
  1789. }
  1790. return ret;
  1791. }
  1792. get legalComments() {
  1793. return this.inner.legalComments;
  1794. }
  1795. get comments() {
  1796. const c = this.inner.comments;
  1797. return {
  1798. legal: c.legal ?? true,
  1799. annotation: c.annotation ?? true,
  1800. jsdoc: c.jsdoc ?? true
  1801. };
  1802. }
  1803. get polyfillRequire() {
  1804. return this.inner.polyfillRequire;
  1805. }
  1806. get plugins() {
  1807. return this.normalizedOutputPlugins;
  1808. }
  1809. get preserveModules() {
  1810. return this.inner.preserveModules;
  1811. }
  1812. get preserveModulesRoot() {
  1813. return this.inner.preserveModulesRoot;
  1814. }
  1815. get virtualDirname() {
  1816. return this.inner.virtualDirname;
  1817. }
  1818. get topLevelVar() {
  1819. return this.inner.topLevelVar ?? false;
  1820. }
  1821. get minifyInternalExports() {
  1822. return this.inner.minifyInternalExports ?? false;
  1823. }
  1824. };
  1825. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dir", null);
  1826. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "entryFileNames", null);
  1827. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "chunkFileNames", null);
  1828. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "assetFileNames", null);
  1829. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "format", null);
  1830. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "exports", null);
  1831. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemap", null);
  1832. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapBaseUrl", null);
  1833. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "shimMissingExports", null);
  1834. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "name", null);
  1835. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "file", null);
  1836. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "codeSplitting", null);
  1837. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "inlineDynamicImports", null);
  1838. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "dynamicImportInCjs", null);
  1839. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "externalLiveBindings", null);
  1840. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "banner", null);
  1841. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "footer", null);
  1842. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postBanner", null);
  1843. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "postFooter", null);
  1844. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "intro", null);
  1845. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "outro", null);
  1846. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "esModule", null);
  1847. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "extend", null);
  1848. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "globals", null);
  1849. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "paths", null);
  1850. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "hashCharacters", null);
  1851. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapDebugIds", null);
  1852. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapExcludeSources", null);
  1853. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapIgnoreList", null);
  1854. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "sourcemapPathTransform", null);
  1855. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minify", null);
  1856. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "legalComments", null);
  1857. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "comments", null);
  1858. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "polyfillRequire", null);
  1859. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "plugins", null);
  1860. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModules", null);
  1861. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "preserveModulesRoot", null);
  1862. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "virtualDirname", null);
  1863. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "topLevelVar", null);
  1864. __decorate([lazyProp], NormalizedOutputOptionsImpl.prototype, "minifyInternalExports", null);
  1865. function normalizeAddon(value) {
  1866. if (typeof value === "function") return value;
  1867. return () => value || "";
  1868. }
  1869. //#endregion
  1870. //#region src/plugin/plugin-context-data.ts
  1871. var PluginContextData = class {
  1872. moduleOptionMap = /* @__PURE__ */ new Map();
  1873. resolveOptionsMap = /* @__PURE__ */ new Map();
  1874. loadModulePromiseMap = /* @__PURE__ */ new Map();
  1875. renderedChunkMeta = null;
  1876. normalizedInputOptions = null;
  1877. normalizedOutputOptions = null;
  1878. constructor(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins) {
  1879. this.onLog = onLog;
  1880. this.outputOptions = outputOptions;
  1881. this.normalizedInputPlugins = normalizedInputPlugins;
  1882. this.normalizedOutputPlugins = normalizedOutputPlugins;
  1883. }
  1884. updateModuleOption(id, option) {
  1885. const existing = this.moduleOptionMap.get(id);
  1886. if (existing) {
  1887. if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
  1888. if (option.meta != null) Object.assign(existing.meta, option.meta);
  1889. if (option.invalidate != null) existing.invalidate = option.invalidate;
  1890. } else {
  1891. this.moduleOptionMap.set(id, option);
  1892. return option;
  1893. }
  1894. return existing;
  1895. }
  1896. getModuleOption(id) {
  1897. const option = this.moduleOptionMap.get(id);
  1898. if (!option) {
  1899. const raw = {
  1900. moduleSideEffects: null,
  1901. meta: {}
  1902. };
  1903. this.moduleOptionMap.set(id, raw);
  1904. return raw;
  1905. }
  1906. return option;
  1907. }
  1908. getModuleInfo(id, context) {
  1909. const bindingInfo = context.getModuleInfo(id);
  1910. if (bindingInfo) {
  1911. const info = transformModuleInfo(bindingInfo, this.getModuleOption(id));
  1912. return this.proxyModuleInfo(id, info);
  1913. }
  1914. return null;
  1915. }
  1916. proxyModuleInfo(id, info) {
  1917. let moduleSideEffects = info.moduleSideEffects;
  1918. Object.defineProperty(info, "moduleSideEffects", {
  1919. get() {
  1920. return moduleSideEffects;
  1921. },
  1922. set: (v) => {
  1923. this.updateModuleOption(id, {
  1924. moduleSideEffects: v,
  1925. meta: info.meta,
  1926. invalidate: true
  1927. });
  1928. moduleSideEffects = v;
  1929. }
  1930. });
  1931. return info;
  1932. }
  1933. getModuleIds(context) {
  1934. return context.getModuleIds().values();
  1935. }
  1936. saveResolveOptions(options) {
  1937. const index = this.resolveOptionsMap.size;
  1938. this.resolveOptionsMap.set(index, options);
  1939. return index;
  1940. }
  1941. getSavedResolveOptions(receipt) {
  1942. return this.resolveOptionsMap.get(receipt);
  1943. }
  1944. removeSavedResolveOptions(receipt) {
  1945. this.resolveOptionsMap.delete(receipt);
  1946. }
  1947. setRenderChunkMeta(meta) {
  1948. this.renderedChunkMeta = meta;
  1949. }
  1950. getRenderChunkMeta() {
  1951. return this.renderedChunkMeta;
  1952. }
  1953. getInputOptions(opts) {
  1954. this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog, this.normalizedInputPlugins);
  1955. return this.normalizedInputOptions;
  1956. }
  1957. getOutputOptions(opts) {
  1958. this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
  1959. return this.normalizedOutputOptions;
  1960. }
  1961. clear() {
  1962. this.renderedChunkMeta = null;
  1963. this.loadModulePromiseMap.clear();
  1964. }
  1965. };
  1966. //#endregion
  1967. //#region src/utils/normalize-transform-options.ts
  1968. /**
  1969. * Normalizes transform options by extracting `define`, `inject`, and `dropLabels` separately from OXC transform options.
  1970. *
  1971. * Prioritizes values from `transform.define`, `transform.inject`, and `transform.dropLabels` over deprecated top-level options.
  1972. */
  1973. function normalizeTransformOptions(inputOptions) {
  1974. const transform = inputOptions.transform;
  1975. const define = transform?.define ? Object.entries(transform.define) : void 0;
  1976. const inject = transform?.inject;
  1977. const dropLabels = transform?.dropLabels;
  1978. let oxcTransformOptions;
  1979. if (transform) {
  1980. const { define: _define, inject: _inject, dropLabels: _dropLabels, ...rest } = transform;
  1981. if (Object.keys(rest).length > 0) {
  1982. if (rest.jsx === false) rest.jsx = "disable";
  1983. oxcTransformOptions = rest;
  1984. }
  1985. }
  1986. return {
  1987. define,
  1988. inject,
  1989. dropLabels,
  1990. oxcTransformOptions
  1991. };
  1992. }
  1993. //#endregion
  1994. //#region src/utils/bindingify-input-options.ts
  1995. function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedInputPlugins, normalizedOutputPlugins, onLog, logLevel, watchMode) {
  1996. const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedInputPlugins, normalizedOutputPlugins);
  1997. const plugins = rawPlugins.map((plugin) => {
  1998. if ("_parallel" in plugin) return;
  1999. if (plugin instanceof BuiltinPlugin) switch (plugin.name) {
  2000. case "builtin:vite-manifest": return bindingifyManifestPlugin(plugin, pluginContextData);
  2001. default: return bindingifyBuiltInPlugin(plugin);
  2002. }
  2003. return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
  2004. });
  2005. const normalizedTransform = normalizeTransformOptions(inputOptions);
  2006. return {
  2007. input: bindingifyInput(inputOptions.input),
  2008. plugins,
  2009. cwd: inputOptions.cwd ?? process.cwd(),
  2010. external: bindingifyExternal(inputOptions.external),
  2011. resolve: bindingifyResolve(inputOptions.resolve),
  2012. platform: inputOptions.platform,
  2013. shimMissingExports: inputOptions.shimMissingExports,
  2014. logLevel: bindingifyLogLevel(logLevel),
  2015. onLog: async (level, log) => onLog(level, log),
  2016. treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
  2017. moduleTypes: inputOptions.moduleTypes,
  2018. define: normalizedTransform.define,
  2019. inject: bindingifyInject(normalizedTransform.inject),
  2020. experimental: bindingifyExperimental(inputOptions.experimental),
  2021. profilerNames: outputOptions.generatedCode?.profilerNames,
  2022. transform: normalizedTransform.oxcTransformOptions,
  2023. watch: bindingifyWatch(inputOptions.watch),
  2024. dropLabels: normalizedTransform.dropLabels,
  2025. keepNames: outputOptions.keepNames,
  2026. checks: inputOptions.checks,
  2027. deferSyncScanData: () => {
  2028. let ret = [];
  2029. pluginContextData.moduleOptionMap.forEach((value, key) => {
  2030. if (value.invalidate) ret.push({
  2031. id: key,
  2032. sideEffects: value.moduleSideEffects ?? void 0
  2033. });
  2034. });
  2035. return ret;
  2036. },
  2037. makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
  2038. devtools: inputOptions.devtools,
  2039. invalidateJsSideCache: pluginContextData.clear.bind(pluginContextData),
  2040. preserveEntrySignatures: bindingifyPreserveEntrySignatures(inputOptions.preserveEntrySignatures),
  2041. optimization: inputOptions.optimization,
  2042. context: inputOptions.context,
  2043. tsconfig: inputOptions.resolve?.tsconfigFilename ?? inputOptions.tsconfig
  2044. };
  2045. }
  2046. function bindingifyDevMode(devMode) {
  2047. if (devMode) {
  2048. if (typeof devMode === "boolean") return devMode ? {} : void 0;
  2049. return devMode;
  2050. }
  2051. }
  2052. function bindingifyAttachDebugInfo(attachDebugInfo) {
  2053. switch (attachDebugInfo) {
  2054. case void 0: return;
  2055. case "full": return import_binding.BindingAttachDebugInfo.Full;
  2056. case "simple": return import_binding.BindingAttachDebugInfo.Simple;
  2057. case "none": return import_binding.BindingAttachDebugInfo.None;
  2058. }
  2059. }
  2060. function bindingifyExternal(external) {
  2061. if (external) {
  2062. if (typeof external === "function") return (id, importer, isResolved) => {
  2063. if (id.startsWith("\0")) return false;
  2064. return external(id, importer, isResolved) ?? false;
  2065. };
  2066. return arraify(external);
  2067. }
  2068. }
  2069. function bindingifyExperimental(experimental) {
  2070. let chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
  2071. if (experimental?.chunkModulesOrder) switch (experimental.chunkModulesOrder) {
  2072. case "exec-order":
  2073. chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ExecOrder;
  2074. break;
  2075. case "module-id":
  2076. chunkModulesOrder = import_binding.BindingChunkModuleOrderBy.ModuleId;
  2077. break;
  2078. default: throw new Error(`Unexpected chunkModulesOrder: ${experimental.chunkModulesOrder}`);
  2079. }
  2080. return {
  2081. viteMode: experimental?.viteMode,
  2082. resolveNewUrlToAsset: experimental?.resolveNewUrlToAsset,
  2083. devMode: bindingifyDevMode(experimental?.devMode),
  2084. attachDebugInfo: bindingifyAttachDebugInfo(experimental?.attachDebugInfo),
  2085. chunkModulesOrder,
  2086. chunkImportMap: experimental?.chunkImportMap,
  2087. onDemandWrapping: experimental?.onDemandWrapping,
  2088. incrementalBuild: experimental?.incrementalBuild,
  2089. nativeMagicString: experimental?.nativeMagicString,
  2090. chunkOptimization: experimental?.chunkOptimization,
  2091. lazyBarrel: experimental?.lazyBarrel
  2092. };
  2093. }
  2094. function bindingifyResolve(resolve) {
  2095. const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
  2096. if (resolve) {
  2097. const { alias, extensionAlias, ...rest } = resolve;
  2098. return {
  2099. alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
  2100. find: name,
  2101. replacements: replacement === false ? [void 0] : arraify(replacement)
  2102. })) : void 0,
  2103. extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
  2104. target: name,
  2105. replacements: value
  2106. })) : void 0,
  2107. yarnPnp,
  2108. ...rest
  2109. };
  2110. } else return { yarnPnp };
  2111. }
  2112. function bindingifyInject(inject) {
  2113. if (inject) return Object.entries(inject).map(([alias, item]) => {
  2114. if (Array.isArray(item)) {
  2115. if (item[1] === "*") return {
  2116. tagNamespace: true,
  2117. alias,
  2118. from: item[0]
  2119. };
  2120. return {
  2121. tagNamed: true,
  2122. alias,
  2123. from: item[0],
  2124. imported: item[1]
  2125. };
  2126. } else return {
  2127. tagNamed: true,
  2128. imported: "default",
  2129. alias,
  2130. from: item
  2131. };
  2132. });
  2133. }
  2134. function bindingifyLogLevel(logLevel) {
  2135. switch (logLevel) {
  2136. case "silent": return import_binding.BindingLogLevel.Silent;
  2137. case "debug": return import_binding.BindingLogLevel.Debug;
  2138. case "warn": return import_binding.BindingLogLevel.Warn;
  2139. case "info": return import_binding.BindingLogLevel.Info;
  2140. default: throw new Error(`Unexpected log level: ${logLevel}`);
  2141. }
  2142. }
  2143. function bindingifyInput(input) {
  2144. if (input === void 0) return [];
  2145. if (typeof input === "string") return [{ import: input }];
  2146. if (Array.isArray(input)) return input.map((src) => ({ import: src }));
  2147. return Object.entries(input).map(([name, import_path]) => {
  2148. return {
  2149. name,
  2150. import: import_path
  2151. };
  2152. });
  2153. }
  2154. function bindingifyWatch(watch) {
  2155. if (watch) {
  2156. if (watch.notify) console.warn("The \"watch.notify\" option is deprecated. Please use \"watch.watcher\" instead.");
  2157. const watcher = {
  2158. ...watch.notify,
  2159. ...watch.watcher
  2160. };
  2161. return {
  2162. buildDelay: watch.buildDelay,
  2163. skipWrite: watch.skipWrite,
  2164. usePolling: watcher.usePolling,
  2165. pollInterval: watcher.pollInterval,
  2166. compareContentsForPolling: watcher.compareContentsForPolling,
  2167. useDebounce: watcher.useDebounce,
  2168. debounceDelay: watcher.debounceDelay,
  2169. debounceTickRate: watcher.debounceTickRate,
  2170. include: normalizedStringOrRegex(watch.include),
  2171. exclude: normalizedStringOrRegex(watch.exclude),
  2172. onInvalidate: (...args) => watch.onInvalidate?.(...args)
  2173. };
  2174. }
  2175. }
  2176. function bindingifyTreeshakeOptions(config) {
  2177. if (config === false) return;
  2178. if (config === true || config === void 0) return { moduleSideEffects: true };
  2179. let normalizedConfig = {
  2180. moduleSideEffects: true,
  2181. annotations: config.annotations,
  2182. manualPureFunctions: config.manualPureFunctions,
  2183. unknownGlobalSideEffects: config.unknownGlobalSideEffects,
  2184. invalidImportSideEffects: config.invalidImportSideEffects,
  2185. commonjs: config.commonjs
  2186. };
  2187. switch (config.propertyReadSideEffects) {
  2188. case "always":
  2189. normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.Always;
  2190. break;
  2191. case false:
  2192. normalizedConfig.propertyReadSideEffects = import_binding.BindingPropertyReadSideEffects.False;
  2193. break;
  2194. default:
  2195. }
  2196. switch (config.propertyWriteSideEffects) {
  2197. case "always":
  2198. normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.Always;
  2199. break;
  2200. case false:
  2201. normalizedConfig.propertyWriteSideEffects = import_binding.BindingPropertyWriteSideEffects.False;
  2202. break;
  2203. default:
  2204. }
  2205. if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
  2206. else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
  2207. external: true,
  2208. sideEffects: false
  2209. }, {
  2210. external: false,
  2211. sideEffects: true
  2212. }];
  2213. else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
  2214. return normalizedConfig;
  2215. }
  2216. function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
  2217. if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
  2218. if (typeof makeAbsoluteExternalsRelative === "boolean") return {
  2219. type: "Bool",
  2220. field0: makeAbsoluteExternalsRelative
  2221. };
  2222. }
  2223. function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
  2224. if (preserveEntrySignatures == void 0) return;
  2225. else if (typeof preserveEntrySignatures === "string") return {
  2226. type: "String",
  2227. field0: preserveEntrySignatures
  2228. };
  2229. else return {
  2230. type: "Bool",
  2231. field0: preserveEntrySignatures
  2232. };
  2233. }
  2234. //#endregion
  2235. export { version as C, description as S, LOG_LEVEL_INFO as _, RolldownMagicString as a, RUNTIME_MODULE_ID as b, __decorate as c, PlainObjectLike as d, MinimalPluginContextImpl as f, LOG_LEVEL_ERROR as g, LOG_LEVEL_DEBUG as h, transformModuleInfo as i, transformAssetSource as l, normalizeLog as m, PluginContextData as n, transformToRollupOutput as o, normalizeHook as p, bindingifyPlugin as r, transformRenderedChunk as s, bindingifyInputOptions as t, lazyProp as u, LOG_LEVEL_WARN as v, VERSION as x, logLevelPriority as y };