bindingify-input-options-ClrST5Xx.mjs 75 KB

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