index.mjs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. // node_modules/.pnpm/tsup@8.0.1_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js
  2. import { fileURLToPath } from "url";
  3. import path from "path";
  4. var getFilename = () => fileURLToPath(import.meta.url);
  5. var getDirname = () => path.dirname(getFilename());
  6. var __dirname = /* @__PURE__ */ getDirname();
  7. // src/esbuild/index.ts
  8. import fs2 from "fs";
  9. import path3 from "path";
  10. // src/esbuild/utils.ts
  11. import fs from "fs";
  12. import path2 from "path";
  13. import { Buffer as Buffer2 } from "buffer";
  14. // node_modules/.pnpm/@jridgewell+sourcemap-codec@1.4.14/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
  15. var comma = ",".charCodeAt(0);
  16. var semicolon = ";".charCodeAt(0);
  17. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  18. var intToChar = new Uint8Array(64);
  19. var charToInt = new Uint8Array(128);
  20. for (let i2 = 0; i2 < chars.length; i2++) {
  21. const c = chars.charCodeAt(i2);
  22. intToChar[i2] = c;
  23. charToInt[c] = i2;
  24. }
  25. var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
  26. decode(buf) {
  27. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  28. return out.toString();
  29. }
  30. } : {
  31. decode(buf) {
  32. let out = "";
  33. for (let i2 = 0; i2 < buf.length; i2++) {
  34. out += String.fromCharCode(buf[i2]);
  35. }
  36. return out;
  37. }
  38. };
  39. function decode(mappings) {
  40. const state = new Int32Array(5);
  41. const decoded = [];
  42. let index = 0;
  43. do {
  44. const semi = indexOf(mappings, index);
  45. const line = [];
  46. let sorted = true;
  47. let lastCol = 0;
  48. state[0] = 0;
  49. for (let i2 = index; i2 < semi; i2++) {
  50. let seg;
  51. i2 = decodeInteger(mappings, i2, state, 0);
  52. const col = state[0];
  53. if (col < lastCol)
  54. sorted = false;
  55. lastCol = col;
  56. if (hasMoreVlq(mappings, i2, semi)) {
  57. i2 = decodeInteger(mappings, i2, state, 1);
  58. i2 = decodeInteger(mappings, i2, state, 2);
  59. i2 = decodeInteger(mappings, i2, state, 3);
  60. if (hasMoreVlq(mappings, i2, semi)) {
  61. i2 = decodeInteger(mappings, i2, state, 4);
  62. seg = [col, state[1], state[2], state[3], state[4]];
  63. } else {
  64. seg = [col, state[1], state[2], state[3]];
  65. }
  66. } else {
  67. seg = [col];
  68. }
  69. line.push(seg);
  70. }
  71. if (!sorted)
  72. sort(line);
  73. decoded.push(line);
  74. index = semi + 1;
  75. } while (index <= mappings.length);
  76. return decoded;
  77. }
  78. function indexOf(mappings, index) {
  79. const idx = mappings.indexOf(";", index);
  80. return idx === -1 ? mappings.length : idx;
  81. }
  82. function decodeInteger(mappings, pos, state, j) {
  83. let value = 0;
  84. let shift = 0;
  85. let integer = 0;
  86. do {
  87. const c = mappings.charCodeAt(pos++);
  88. integer = charToInt[c];
  89. value |= (integer & 31) << shift;
  90. shift += 5;
  91. } while (integer & 32);
  92. const shouldNegate = value & 1;
  93. value >>>= 1;
  94. if (shouldNegate) {
  95. value = -2147483648 | -value;
  96. }
  97. state[j] += value;
  98. return pos;
  99. }
  100. function hasMoreVlq(mappings, i2, length) {
  101. if (i2 >= length)
  102. return false;
  103. return mappings.charCodeAt(i2) !== comma;
  104. }
  105. function sort(line) {
  106. line.sort(sortComparator);
  107. }
  108. function sortComparator(a, b) {
  109. return a[0] - b[0];
  110. }
  111. function encode(decoded) {
  112. const state = new Int32Array(5);
  113. const bufLength = 1024 * 16;
  114. const subLength = bufLength - 36;
  115. const buf = new Uint8Array(bufLength);
  116. const sub = buf.subarray(0, subLength);
  117. let pos = 0;
  118. let out = "";
  119. for (let i2 = 0; i2 < decoded.length; i2++) {
  120. const line = decoded[i2];
  121. if (i2 > 0) {
  122. if (pos === bufLength) {
  123. out += td.decode(buf);
  124. pos = 0;
  125. }
  126. buf[pos++] = semicolon;
  127. }
  128. if (line.length === 0)
  129. continue;
  130. state[0] = 0;
  131. for (let j = 0; j < line.length; j++) {
  132. const segment = line[j];
  133. if (pos > subLength) {
  134. out += td.decode(sub);
  135. buf.copyWithin(0, subLength, pos);
  136. pos -= subLength;
  137. }
  138. if (j > 0)
  139. buf[pos++] = comma;
  140. pos = encodeInteger(buf, pos, state, segment, 0);
  141. if (segment.length === 1)
  142. continue;
  143. pos = encodeInteger(buf, pos, state, segment, 1);
  144. pos = encodeInteger(buf, pos, state, segment, 2);
  145. pos = encodeInteger(buf, pos, state, segment, 3);
  146. if (segment.length === 4)
  147. continue;
  148. pos = encodeInteger(buf, pos, state, segment, 4);
  149. }
  150. }
  151. return out + td.decode(buf.subarray(0, pos));
  152. }
  153. function encodeInteger(buf, pos, state, segment, j) {
  154. const next = segment[j];
  155. let num = next - state[j];
  156. state[j] = next;
  157. num = num < 0 ? -num << 1 | 1 : num << 1;
  158. do {
  159. let clamped = num & 31;
  160. num >>>= 5;
  161. if (num > 0)
  162. clamped |= 32;
  163. buf[pos++] = intToChar[clamped];
  164. } while (num > 0);
  165. return pos;
  166. }
  167. // node_modules/.pnpm/@jridgewell+resolve-uri@3.1.0/node_modules/@jridgewell/resolve-uri/dist/resolve-uri.mjs
  168. var schemeRegex = /^[\w+.-]+:\/\//;
  169. var urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
  170. var fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
  171. var UrlType;
  172. (function(UrlType2) {
  173. UrlType2[UrlType2["Empty"] = 1] = "Empty";
  174. UrlType2[UrlType2["Hash"] = 2] = "Hash";
  175. UrlType2[UrlType2["Query"] = 3] = "Query";
  176. UrlType2[UrlType2["RelativePath"] = 4] = "RelativePath";
  177. UrlType2[UrlType2["AbsolutePath"] = 5] = "AbsolutePath";
  178. UrlType2[UrlType2["SchemeRelative"] = 6] = "SchemeRelative";
  179. UrlType2[UrlType2["Absolute"] = 7] = "Absolute";
  180. })(UrlType || (UrlType = {}));
  181. function isAbsoluteUrl(input) {
  182. return schemeRegex.test(input);
  183. }
  184. function isSchemeRelativeUrl(input) {
  185. return input.startsWith("//");
  186. }
  187. function isAbsolutePath(input) {
  188. return input.startsWith("/");
  189. }
  190. function isFileUrl(input) {
  191. return input.startsWith("file:");
  192. }
  193. function isRelative(input) {
  194. return /^[.?#]/.test(input);
  195. }
  196. function parseAbsoluteUrl(input) {
  197. const match = urlRegex.exec(input);
  198. return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
  199. }
  200. function parseFileUrl(input) {
  201. const match = fileRegex.exec(input);
  202. const path4 = match[2];
  203. return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path4) ? path4 : "/" + path4, match[3] || "", match[4] || "");
  204. }
  205. function makeUrl(scheme, user, host, port, path4, query, hash) {
  206. return {
  207. scheme,
  208. user,
  209. host,
  210. port,
  211. path: path4,
  212. query,
  213. hash,
  214. type: UrlType.Absolute
  215. };
  216. }
  217. function parseUrl(input) {
  218. if (isSchemeRelativeUrl(input)) {
  219. const url2 = parseAbsoluteUrl("http:" + input);
  220. url2.scheme = "";
  221. url2.type = UrlType.SchemeRelative;
  222. return url2;
  223. }
  224. if (isAbsolutePath(input)) {
  225. const url2 = parseAbsoluteUrl("http://foo.com" + input);
  226. url2.scheme = "";
  227. url2.host = "";
  228. url2.type = UrlType.AbsolutePath;
  229. return url2;
  230. }
  231. if (isFileUrl(input))
  232. return parseFileUrl(input);
  233. if (isAbsoluteUrl(input))
  234. return parseAbsoluteUrl(input);
  235. const url = parseAbsoluteUrl("http://foo.com/" + input);
  236. url.scheme = "";
  237. url.host = "";
  238. url.type = input ? input.startsWith("?") ? UrlType.Query : input.startsWith("#") ? UrlType.Hash : UrlType.RelativePath : UrlType.Empty;
  239. return url;
  240. }
  241. function stripPathFilename(path4) {
  242. if (path4.endsWith("/.."))
  243. return path4;
  244. const index = path4.lastIndexOf("/");
  245. return path4.slice(0, index + 1);
  246. }
  247. function mergePaths(url, base) {
  248. normalizePath(base, base.type);
  249. if (url.path === "/") {
  250. url.path = base.path;
  251. } else {
  252. url.path = stripPathFilename(base.path) + url.path;
  253. }
  254. }
  255. function normalizePath(url, type) {
  256. const rel = type <= UrlType.RelativePath;
  257. const pieces = url.path.split("/");
  258. let pointer = 1;
  259. let positive = 0;
  260. let addTrailingSlash = false;
  261. for (let i2 = 1; i2 < pieces.length; i2++) {
  262. const piece = pieces[i2];
  263. if (!piece) {
  264. addTrailingSlash = true;
  265. continue;
  266. }
  267. addTrailingSlash = false;
  268. if (piece === ".")
  269. continue;
  270. if (piece === "..") {
  271. if (positive) {
  272. addTrailingSlash = true;
  273. positive--;
  274. pointer--;
  275. } else if (rel) {
  276. pieces[pointer++] = piece;
  277. }
  278. continue;
  279. }
  280. pieces[pointer++] = piece;
  281. positive++;
  282. }
  283. let path4 = "";
  284. for (let i2 = 1; i2 < pointer; i2++) {
  285. path4 += "/" + pieces[i2];
  286. }
  287. if (!path4 || addTrailingSlash && !path4.endsWith("/..")) {
  288. path4 += "/";
  289. }
  290. url.path = path4;
  291. }
  292. function resolve(input, base) {
  293. if (!input && !base)
  294. return "";
  295. const url = parseUrl(input);
  296. let inputType = url.type;
  297. if (base && inputType !== UrlType.Absolute) {
  298. const baseUrl = parseUrl(base);
  299. const baseType = baseUrl.type;
  300. switch (inputType) {
  301. case UrlType.Empty:
  302. url.hash = baseUrl.hash;
  303. case UrlType.Hash:
  304. url.query = baseUrl.query;
  305. case UrlType.Query:
  306. case UrlType.RelativePath:
  307. mergePaths(url, baseUrl);
  308. case UrlType.AbsolutePath:
  309. url.user = baseUrl.user;
  310. url.host = baseUrl.host;
  311. url.port = baseUrl.port;
  312. case UrlType.SchemeRelative:
  313. url.scheme = baseUrl.scheme;
  314. }
  315. if (baseType > inputType)
  316. inputType = baseType;
  317. }
  318. normalizePath(url, inputType);
  319. const queryHash = url.query + url.hash;
  320. switch (inputType) {
  321. case UrlType.Hash:
  322. case UrlType.Query:
  323. return queryHash;
  324. case UrlType.RelativePath: {
  325. const path4 = url.path.slice(1);
  326. if (!path4)
  327. return queryHash || ".";
  328. if (isRelative(base || input) && !isRelative(path4)) {
  329. return "./" + path4 + queryHash;
  330. }
  331. return path4 + queryHash;
  332. }
  333. case UrlType.AbsolutePath:
  334. return url.path + queryHash;
  335. default:
  336. return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
  337. }
  338. }
  339. // node_modules/.pnpm/@jridgewell+trace-mapping@0.3.17/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs
  340. function resolve2(input, base) {
  341. if (base && !base.endsWith("/"))
  342. base += "/";
  343. return resolve(input, base);
  344. }
  345. function stripFilename(path4) {
  346. if (!path4)
  347. return "";
  348. const index = path4.lastIndexOf("/");
  349. return path4.slice(0, index + 1);
  350. }
  351. var COLUMN = 0;
  352. var SOURCES_INDEX = 1;
  353. var SOURCE_LINE = 2;
  354. var SOURCE_COLUMN = 3;
  355. var NAMES_INDEX = 4;
  356. var REV_GENERATED_LINE = 1;
  357. var REV_GENERATED_COLUMN = 2;
  358. function maybeSort(mappings, owned) {
  359. const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
  360. if (unsortedIndex === mappings.length)
  361. return mappings;
  362. if (!owned)
  363. mappings = mappings.slice();
  364. for (let i2 = unsortedIndex; i2 < mappings.length; i2 = nextUnsortedSegmentLine(mappings, i2 + 1)) {
  365. mappings[i2] = sortSegments(mappings[i2], owned);
  366. }
  367. return mappings;
  368. }
  369. function nextUnsortedSegmentLine(mappings, start) {
  370. for (let i2 = start; i2 < mappings.length; i2++) {
  371. if (!isSorted(mappings[i2]))
  372. return i2;
  373. }
  374. return mappings.length;
  375. }
  376. function isSorted(line) {
  377. for (let j = 1; j < line.length; j++) {
  378. if (line[j][COLUMN] < line[j - 1][COLUMN]) {
  379. return false;
  380. }
  381. }
  382. return true;
  383. }
  384. function sortSegments(line, owned) {
  385. if (!owned)
  386. line = line.slice();
  387. return line.sort(sortComparator2);
  388. }
  389. function sortComparator2(a, b) {
  390. return a[COLUMN] - b[COLUMN];
  391. }
  392. var found = false;
  393. function binarySearch(haystack, needle, low, high) {
  394. while (low <= high) {
  395. const mid = low + (high - low >> 1);
  396. const cmp = haystack[mid][COLUMN] - needle;
  397. if (cmp === 0) {
  398. found = true;
  399. return mid;
  400. }
  401. if (cmp < 0) {
  402. low = mid + 1;
  403. } else {
  404. high = mid - 1;
  405. }
  406. }
  407. found = false;
  408. return low - 1;
  409. }
  410. function upperBound(haystack, needle, index) {
  411. for (let i2 = index + 1; i2 < haystack.length; index = i2++) {
  412. if (haystack[i2][COLUMN] !== needle)
  413. break;
  414. }
  415. return index;
  416. }
  417. function lowerBound(haystack, needle, index) {
  418. for (let i2 = index - 1; i2 >= 0; index = i2--) {
  419. if (haystack[i2][COLUMN] !== needle)
  420. break;
  421. }
  422. return index;
  423. }
  424. function memoizedState() {
  425. return {
  426. lastKey: -1,
  427. lastNeedle: -1,
  428. lastIndex: -1
  429. };
  430. }
  431. function memoizedBinarySearch(haystack, needle, state, key) {
  432. const { lastKey, lastNeedle, lastIndex } = state;
  433. let low = 0;
  434. let high = haystack.length - 1;
  435. if (key === lastKey) {
  436. if (needle === lastNeedle) {
  437. found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
  438. return lastIndex;
  439. }
  440. if (needle >= lastNeedle) {
  441. low = lastIndex === -1 ? 0 : lastIndex;
  442. } else {
  443. high = lastIndex;
  444. }
  445. }
  446. state.lastKey = key;
  447. state.lastNeedle = needle;
  448. return state.lastIndex = binarySearch(haystack, needle, low, high);
  449. }
  450. function buildBySources(decoded, memos) {
  451. const sources3 = memos.map(buildNullArray);
  452. for (let i2 = 0; i2 < decoded.length; i2++) {
  453. const line = decoded[i2];
  454. for (let j = 0; j < line.length; j++) {
  455. const seg = line[j];
  456. if (seg.length === 1)
  457. continue;
  458. const sourceIndex = seg[SOURCES_INDEX];
  459. const sourceLine = seg[SOURCE_LINE];
  460. const sourceColumn = seg[SOURCE_COLUMN];
  461. const originalSource = sources3[sourceIndex];
  462. const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
  463. const memo = memos[sourceIndex];
  464. const index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
  465. insert(originalLine, memo.lastIndex = index + 1, [sourceColumn, i2, seg[COLUMN]]);
  466. }
  467. }
  468. return sources3;
  469. }
  470. function insert(array, index, value) {
  471. for (let i2 = array.length; i2 > index; i2--) {
  472. array[i2] = array[i2 - 1];
  473. }
  474. array[index] = value;
  475. }
  476. function buildNullArray() {
  477. return { __proto__: null };
  478. }
  479. var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
  480. var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
  481. var LEAST_UPPER_BOUND = -1;
  482. var GREATEST_LOWER_BOUND = 1;
  483. var encodedMappings;
  484. var decodedMappings;
  485. var traceSegment;
  486. var originalPositionFor;
  487. var generatedPositionFor;
  488. var allGeneratedPositionsFor;
  489. var eachMapping;
  490. var sourceContentFor;
  491. var presortedDecodedMap;
  492. var decodedMap;
  493. var encodedMap;
  494. var TraceMap = class {
  495. constructor(map, mapUrl) {
  496. const isString = typeof map === "string";
  497. if (!isString && map._decodedMemo)
  498. return map;
  499. const parsed = isString ? JSON.parse(map) : map;
  500. const { version, file, names, sourceRoot, sources: sources3, sourcesContent } = parsed;
  501. this.version = version;
  502. this.file = file;
  503. this.names = names;
  504. this.sourceRoot = sourceRoot;
  505. this.sources = sources3;
  506. this.sourcesContent = sourcesContent;
  507. const from = resolve2(sourceRoot || "", stripFilename(mapUrl));
  508. this.resolvedSources = sources3.map((s) => resolve2(s || "", from));
  509. const { mappings } = parsed;
  510. if (typeof mappings === "string") {
  511. this._encoded = mappings;
  512. this._decoded = void 0;
  513. } else {
  514. this._encoded = void 0;
  515. this._decoded = maybeSort(mappings, isString);
  516. }
  517. this._decodedMemo = memoizedState();
  518. this._bySources = void 0;
  519. this._bySourceMemos = void 0;
  520. }
  521. };
  522. (() => {
  523. encodedMappings = (map) => {
  524. var _a;
  525. return (_a = map._encoded) !== null && _a !== void 0 ? _a : map._encoded = encode(map._decoded);
  526. };
  527. decodedMappings = (map) => {
  528. return map._decoded || (map._decoded = decode(map._encoded));
  529. };
  530. traceSegment = (map, line, column) => {
  531. const decoded = decodedMappings(map);
  532. if (line >= decoded.length)
  533. return null;
  534. const segments = decoded[line];
  535. const index = traceSegmentInternal(segments, map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
  536. return index === -1 ? null : segments[index];
  537. };
  538. originalPositionFor = (map, { line, column, bias }) => {
  539. line--;
  540. if (line < 0)
  541. throw new Error(LINE_GTR_ZERO);
  542. if (column < 0)
  543. throw new Error(COL_GTR_EQ_ZERO);
  544. const decoded = decodedMappings(map);
  545. if (line >= decoded.length)
  546. return OMapping(null, null, null, null);
  547. const segments = decoded[line];
  548. const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
  549. if (index === -1)
  550. return OMapping(null, null, null, null);
  551. const segment = segments[index];
  552. if (segment.length === 1)
  553. return OMapping(null, null, null, null);
  554. const { names, resolvedSources } = map;
  555. return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
  556. };
  557. allGeneratedPositionsFor = (map, { source, line, column, bias }) => {
  558. return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
  559. };
  560. generatedPositionFor = (map, { source, line, column, bias }) => {
  561. return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
  562. };
  563. eachMapping = (map, cb) => {
  564. const decoded = decodedMappings(map);
  565. const { names, resolvedSources } = map;
  566. for (let i2 = 0; i2 < decoded.length; i2++) {
  567. const line = decoded[i2];
  568. for (let j = 0; j < line.length; j++) {
  569. const seg = line[j];
  570. const generatedLine = i2 + 1;
  571. const generatedColumn = seg[0];
  572. let source = null;
  573. let originalLine = null;
  574. let originalColumn = null;
  575. let name = null;
  576. if (seg.length !== 1) {
  577. source = resolvedSources[seg[1]];
  578. originalLine = seg[2] + 1;
  579. originalColumn = seg[3];
  580. }
  581. if (seg.length === 5)
  582. name = names[seg[4]];
  583. cb({
  584. generatedLine,
  585. generatedColumn,
  586. source,
  587. originalLine,
  588. originalColumn,
  589. name
  590. });
  591. }
  592. }
  593. };
  594. sourceContentFor = (map, source) => {
  595. const { sources: sources3, resolvedSources, sourcesContent } = map;
  596. if (sourcesContent == null)
  597. return null;
  598. let index = sources3.indexOf(source);
  599. if (index === -1)
  600. index = resolvedSources.indexOf(source);
  601. return index === -1 ? null : sourcesContent[index];
  602. };
  603. presortedDecodedMap = (map, mapUrl) => {
  604. const tracer = new TraceMap(clone(map, []), mapUrl);
  605. tracer._decoded = map.mappings;
  606. return tracer;
  607. };
  608. decodedMap = (map) => {
  609. return clone(map, decodedMappings(map));
  610. };
  611. encodedMap = (map) => {
  612. return clone(map, encodedMappings(map));
  613. };
  614. function generatedPosition(map, source, line, column, bias, all) {
  615. line--;
  616. if (line < 0)
  617. throw new Error(LINE_GTR_ZERO);
  618. if (column < 0)
  619. throw new Error(COL_GTR_EQ_ZERO);
  620. const { sources: sources3, resolvedSources } = map;
  621. let sourceIndex = sources3.indexOf(source);
  622. if (sourceIndex === -1)
  623. sourceIndex = resolvedSources.indexOf(source);
  624. if (sourceIndex === -1)
  625. return all ? [] : GMapping(null, null);
  626. const generated = map._bySources || (map._bySources = buildBySources(decodedMappings(map), map._bySourceMemos = sources3.map(memoizedState)));
  627. const segments = generated[sourceIndex][line];
  628. if (segments == null)
  629. return all ? [] : GMapping(null, null);
  630. const memo = map._bySourceMemos[sourceIndex];
  631. if (all)
  632. return sliceGeneratedPositions(segments, memo, line, column, bias);
  633. const index = traceSegmentInternal(segments, memo, line, column, bias);
  634. if (index === -1)
  635. return GMapping(null, null);
  636. const segment = segments[index];
  637. return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
  638. }
  639. })();
  640. function clone(map, mappings) {
  641. return {
  642. version: map.version,
  643. file: map.file,
  644. names: map.names,
  645. sourceRoot: map.sourceRoot,
  646. sources: map.sources,
  647. sourcesContent: map.sourcesContent,
  648. mappings
  649. };
  650. }
  651. function OMapping(source, line, column, name) {
  652. return { source, line, column, name };
  653. }
  654. function GMapping(line, column) {
  655. return { line, column };
  656. }
  657. function traceSegmentInternal(segments, memo, line, column, bias) {
  658. let index = memoizedBinarySearch(segments, column, memo, line);
  659. if (found) {
  660. index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
  661. } else if (bias === LEAST_UPPER_BOUND)
  662. index++;
  663. if (index === -1 || index === segments.length)
  664. return -1;
  665. return index;
  666. }
  667. function sliceGeneratedPositions(segments, memo, line, column, bias) {
  668. let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
  669. if (!found && bias === LEAST_UPPER_BOUND)
  670. min++;
  671. if (min === -1 || min === segments.length)
  672. return [];
  673. const matchedColumn = found ? column : segments[min][COLUMN];
  674. if (!found)
  675. min = lowerBound(segments, matchedColumn, min);
  676. const max = upperBound(segments, matchedColumn, min);
  677. const result = [];
  678. for (; min <= max; min++) {
  679. const segment = segments[min];
  680. result.push(GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]));
  681. }
  682. return result;
  683. }
  684. // node_modules/.pnpm/@jridgewell+set-array@1.1.2/node_modules/@jridgewell/set-array/dist/set-array.mjs
  685. var get;
  686. var put;
  687. var pop;
  688. var SetArray = class {
  689. constructor() {
  690. this._indexes = { __proto__: null };
  691. this.array = [];
  692. }
  693. };
  694. (() => {
  695. get = (strarr, key) => strarr._indexes[key];
  696. put = (strarr, key) => {
  697. const index = get(strarr, key);
  698. if (index !== void 0)
  699. return index;
  700. const { array, _indexes: indexes } = strarr;
  701. return indexes[key] = array.push(key) - 1;
  702. };
  703. pop = (strarr) => {
  704. const { array, _indexes: indexes } = strarr;
  705. if (array.length === 0)
  706. return;
  707. const last = array.pop();
  708. indexes[last] = void 0;
  709. };
  710. })();
  711. // node_modules/.pnpm/@jridgewell+sourcemap-codec@1.4.15/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
  712. var comma2 = ",".charCodeAt(0);
  713. var semicolon2 = ";".charCodeAt(0);
  714. var chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  715. var intToChar2 = new Uint8Array(64);
  716. var charToInt2 = new Uint8Array(128);
  717. for (let i2 = 0; i2 < chars2.length; i2++) {
  718. const c = chars2.charCodeAt(i2);
  719. intToChar2[i2] = c;
  720. charToInt2[c] = i2;
  721. }
  722. var td2 = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
  723. decode(buf) {
  724. const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
  725. return out.toString();
  726. }
  727. } : {
  728. decode(buf) {
  729. let out = "";
  730. for (let i2 = 0; i2 < buf.length; i2++) {
  731. out += String.fromCharCode(buf[i2]);
  732. }
  733. return out;
  734. }
  735. };
  736. function encode2(decoded) {
  737. const state = new Int32Array(5);
  738. const bufLength = 1024 * 16;
  739. const subLength = bufLength - 36;
  740. const buf = new Uint8Array(bufLength);
  741. const sub = buf.subarray(0, subLength);
  742. let pos = 0;
  743. let out = "";
  744. for (let i2 = 0; i2 < decoded.length; i2++) {
  745. const line = decoded[i2];
  746. if (i2 > 0) {
  747. if (pos === bufLength) {
  748. out += td2.decode(buf);
  749. pos = 0;
  750. }
  751. buf[pos++] = semicolon2;
  752. }
  753. if (line.length === 0)
  754. continue;
  755. state[0] = 0;
  756. for (let j = 0; j < line.length; j++) {
  757. const segment = line[j];
  758. if (pos > subLength) {
  759. out += td2.decode(sub);
  760. buf.copyWithin(0, subLength, pos);
  761. pos -= subLength;
  762. }
  763. if (j > 0)
  764. buf[pos++] = comma2;
  765. pos = encodeInteger2(buf, pos, state, segment, 0);
  766. if (segment.length === 1)
  767. continue;
  768. pos = encodeInteger2(buf, pos, state, segment, 1);
  769. pos = encodeInteger2(buf, pos, state, segment, 2);
  770. pos = encodeInteger2(buf, pos, state, segment, 3);
  771. if (segment.length === 4)
  772. continue;
  773. pos = encodeInteger2(buf, pos, state, segment, 4);
  774. }
  775. }
  776. return out + td2.decode(buf.subarray(0, pos));
  777. }
  778. function encodeInteger2(buf, pos, state, segment, j) {
  779. const next = segment[j];
  780. let num = next - state[j];
  781. state[j] = next;
  782. num = num < 0 ? -num << 1 | 1 : num << 1;
  783. do {
  784. let clamped = num & 31;
  785. num >>>= 5;
  786. if (num > 0)
  787. clamped |= 32;
  788. buf[pos++] = intToChar2[clamped];
  789. } while (num > 0);
  790. return pos;
  791. }
  792. // node_modules/.pnpm/@jridgewell+gen-mapping@0.3.2/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
  793. var COLUMN2 = 0;
  794. var SOURCES_INDEX2 = 1;
  795. var SOURCE_LINE2 = 2;
  796. var SOURCE_COLUMN2 = 3;
  797. var NAMES_INDEX2 = 4;
  798. var NO_NAME = -1;
  799. var addSegment;
  800. var addMapping;
  801. var maybeAddSegment;
  802. var maybeAddMapping;
  803. var setSourceContent;
  804. var toDecodedMap;
  805. var toEncodedMap;
  806. var fromMap;
  807. var allMappings;
  808. var addSegmentInternal;
  809. var GenMapping = class {
  810. constructor({ file, sourceRoot } = {}) {
  811. this._names = new SetArray();
  812. this._sources = new SetArray();
  813. this._sourcesContent = [];
  814. this._mappings = [];
  815. this.file = file;
  816. this.sourceRoot = sourceRoot;
  817. }
  818. };
  819. (() => {
  820. addSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
  821. return addSegmentInternal(false, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
  822. };
  823. maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
  824. return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
  825. };
  826. addMapping = (map, mapping) => {
  827. return addMappingInternal(false, map, mapping);
  828. };
  829. maybeAddMapping = (map, mapping) => {
  830. return addMappingInternal(true, map, mapping);
  831. };
  832. setSourceContent = (map, source, content) => {
  833. const { _sources: sources3, _sourcesContent: sourcesContent } = map;
  834. sourcesContent[put(sources3, source)] = content;
  835. };
  836. toDecodedMap = (map) => {
  837. const { file, sourceRoot, _mappings: mappings, _sources: sources3, _sourcesContent: sourcesContent, _names: names } = map;
  838. removeEmptyFinalLines(mappings);
  839. return {
  840. version: 3,
  841. file: file || void 0,
  842. names: names.array,
  843. sourceRoot: sourceRoot || void 0,
  844. sources: sources3.array,
  845. sourcesContent,
  846. mappings
  847. };
  848. };
  849. toEncodedMap = (map) => {
  850. const decoded = toDecodedMap(map);
  851. return Object.assign(Object.assign({}, decoded), { mappings: encode2(decoded.mappings) });
  852. };
  853. allMappings = (map) => {
  854. const out = [];
  855. const { _mappings: mappings, _sources: sources3, _names: names } = map;
  856. for (let i2 = 0; i2 < mappings.length; i2++) {
  857. const line = mappings[i2];
  858. for (let j = 0; j < line.length; j++) {
  859. const seg = line[j];
  860. const generated = { line: i2 + 1, column: seg[COLUMN2] };
  861. let source = void 0;
  862. let original = void 0;
  863. let name = void 0;
  864. if (seg.length !== 1) {
  865. source = sources3.array[seg[SOURCES_INDEX2]];
  866. original = { line: seg[SOURCE_LINE2] + 1, column: seg[SOURCE_COLUMN2] };
  867. if (seg.length === 5)
  868. name = names.array[seg[NAMES_INDEX2]];
  869. }
  870. out.push({ generated, source, original, name });
  871. }
  872. }
  873. return out;
  874. };
  875. fromMap = (input) => {
  876. const map = new TraceMap(input);
  877. const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
  878. putAll(gen._names, map.names);
  879. putAll(gen._sources, map.sources);
  880. gen._sourcesContent = map.sourcesContent || map.sources.map(() => null);
  881. gen._mappings = decodedMappings(map);
  882. return gen;
  883. };
  884. addSegmentInternal = (skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
  885. const { _mappings: mappings, _sources: sources3, _sourcesContent: sourcesContent, _names: names } = map;
  886. const line = getLine(mappings, genLine);
  887. const index = getColumnIndex(line, genColumn);
  888. if (!source) {
  889. if (skipable && skipSourceless(line, index))
  890. return;
  891. return insert2(line, index, [genColumn]);
  892. }
  893. const sourcesIndex = put(sources3, source);
  894. const namesIndex = name ? put(names, name) : NO_NAME;
  895. if (sourcesIndex === sourcesContent.length)
  896. sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
  897. if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
  898. return;
  899. }
  900. return insert2(line, index, name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
  901. };
  902. })();
  903. function getLine(mappings, index) {
  904. for (let i2 = mappings.length; i2 <= index; i2++) {
  905. mappings[i2] = [];
  906. }
  907. return mappings[index];
  908. }
  909. function getColumnIndex(line, genColumn) {
  910. let index = line.length;
  911. for (let i2 = index - 1; i2 >= 0; index = i2--) {
  912. const current = line[i2];
  913. if (genColumn >= current[COLUMN2])
  914. break;
  915. }
  916. return index;
  917. }
  918. function insert2(array, index, value) {
  919. for (let i2 = array.length; i2 > index; i2--) {
  920. array[i2] = array[i2 - 1];
  921. }
  922. array[index] = value;
  923. }
  924. function removeEmptyFinalLines(mappings) {
  925. const { length } = mappings;
  926. let len = length;
  927. for (let i2 = len - 1; i2 >= 0; len = i2, i2--) {
  928. if (mappings[i2].length > 0)
  929. break;
  930. }
  931. if (len < length)
  932. mappings.length = len;
  933. }
  934. function putAll(strarr, array) {
  935. for (let i2 = 0; i2 < array.length; i2++)
  936. put(strarr, array[i2]);
  937. }
  938. function skipSourceless(line, index) {
  939. if (index === 0)
  940. return true;
  941. const prev = line[index - 1];
  942. return prev.length === 1;
  943. }
  944. function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
  945. if (index === 0)
  946. return false;
  947. const prev = line[index - 1];
  948. if (prev.length === 1)
  949. return false;
  950. return sourcesIndex === prev[SOURCES_INDEX2] && sourceLine === prev[SOURCE_LINE2] && sourceColumn === prev[SOURCE_COLUMN2] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX2] : NO_NAME);
  951. }
  952. function addMappingInternal(skipable, map, mapping) {
  953. const { generated, source, original, name, content } = mapping;
  954. if (!source) {
  955. return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
  956. }
  957. const s = source;
  958. return addSegmentInternal(skipable, map, generated.line - 1, generated.column, s, original.line - 1, original.column, name, content);
  959. }
  960. // node_modules/.pnpm/@ampproject+remapping@2.2.1/node_modules/@ampproject/remapping/dist/remapping.mjs
  961. var SOURCELESS_MAPPING = /* @__PURE__ */ SegmentObject("", -1, -1, "", null);
  962. var EMPTY_SOURCES = [];
  963. function SegmentObject(source, line, column, name, content) {
  964. return { source, line, column, name, content };
  965. }
  966. function Source(map, sources3, source, content) {
  967. return {
  968. map,
  969. sources: sources3,
  970. source,
  971. content
  972. };
  973. }
  974. function MapSource(map, sources3) {
  975. return Source(map, sources3, "", null);
  976. }
  977. function OriginalSource(source, content) {
  978. return Source(null, EMPTY_SOURCES, source, content);
  979. }
  980. function traceMappings(tree) {
  981. const gen = new GenMapping({ file: tree.map.file });
  982. const { sources: rootSources, map } = tree;
  983. const rootNames = map.names;
  984. const rootMappings = decodedMappings(map);
  985. for (let i2 = 0; i2 < rootMappings.length; i2++) {
  986. const segments = rootMappings[i2];
  987. for (let j = 0; j < segments.length; j++) {
  988. const segment = segments[j];
  989. const genCol = segment[0];
  990. let traced = SOURCELESS_MAPPING;
  991. if (segment.length !== 1) {
  992. const source2 = rootSources[segment[1]];
  993. traced = originalPositionFor2(source2, segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : "");
  994. if (traced == null)
  995. continue;
  996. }
  997. const { column, line, name, content, source } = traced;
  998. maybeAddSegment(gen, i2, genCol, source, line, column, name);
  999. if (source && content != null)
  1000. setSourceContent(gen, source, content);
  1001. }
  1002. }
  1003. return gen;
  1004. }
  1005. function originalPositionFor2(source, line, column, name) {
  1006. if (!source.map) {
  1007. return SegmentObject(source.source, line, column, name, source.content);
  1008. }
  1009. const segment = traceSegment(source.map, line, column);
  1010. if (segment == null)
  1011. return null;
  1012. if (segment.length === 1)
  1013. return SOURCELESS_MAPPING;
  1014. return originalPositionFor2(source.sources[segment[1]], segment[2], segment[3], segment.length === 5 ? source.map.names[segment[4]] : name);
  1015. }
  1016. function asArray(value) {
  1017. if (Array.isArray(value))
  1018. return value;
  1019. return [value];
  1020. }
  1021. function buildSourceMapTree(input, loader) {
  1022. const maps = asArray(input).map((m) => new TraceMap(m, ""));
  1023. const map = maps.pop();
  1024. for (let i2 = 0; i2 < maps.length; i2++) {
  1025. if (maps[i2].sources.length > 1) {
  1026. throw new Error(`Transformation map ${i2} must have exactly one source file.
  1027. Did you specify these with the most recent transformation maps first?`);
  1028. }
  1029. }
  1030. let tree = build(map, loader, "", 0);
  1031. for (let i2 = maps.length - 1; i2 >= 0; i2--) {
  1032. tree = MapSource(maps[i2], [tree]);
  1033. }
  1034. return tree;
  1035. }
  1036. function build(map, loader, importer, importerDepth) {
  1037. const { resolvedSources, sourcesContent } = map;
  1038. const depth = importerDepth + 1;
  1039. const children = resolvedSources.map((sourceFile, i2) => {
  1040. const ctx = {
  1041. importer,
  1042. depth,
  1043. source: sourceFile || "",
  1044. content: void 0
  1045. };
  1046. const sourceMap = loader(ctx.source, ctx);
  1047. const { source, content } = ctx;
  1048. if (sourceMap)
  1049. return build(new TraceMap(sourceMap, source), loader, source, depth);
  1050. const sourceContent = content !== void 0 ? content : sourcesContent ? sourcesContent[i2] : null;
  1051. return OriginalSource(source, sourceContent);
  1052. });
  1053. return MapSource(map, children);
  1054. }
  1055. var SourceMap = class {
  1056. constructor(map, options) {
  1057. const out = options.decodedMappings ? toDecodedMap(map) : toEncodedMap(map);
  1058. this.version = out.version;
  1059. this.file = out.file;
  1060. this.mappings = out.mappings;
  1061. this.names = out.names;
  1062. this.sourceRoot = out.sourceRoot;
  1063. this.sources = out.sources;
  1064. if (!options.excludeContent) {
  1065. this.sourcesContent = out.sourcesContent;
  1066. }
  1067. }
  1068. toString() {
  1069. return JSON.stringify(this);
  1070. }
  1071. };
  1072. function remapping(input, loader, options) {
  1073. const opts = typeof options === "object" ? options : { excludeContent: !!options, decodedMappings: false };
  1074. const tree = buildSourceMapTree(input, loader);
  1075. return new SourceMap(traceMappings(tree), opts);
  1076. }
  1077. // src/esbuild/utils.ts
  1078. import { Parser } from "acorn";
  1079. // src/utils.ts
  1080. import { isAbsolute, normalize } from "path";
  1081. function normalizeAbsolutePath(path4) {
  1082. if (isAbsolute(path4))
  1083. return normalize(path4);
  1084. else
  1085. return path4;
  1086. }
  1087. function toArray(array) {
  1088. array = array || [];
  1089. if (Array.isArray(array))
  1090. return array;
  1091. return [array];
  1092. }
  1093. function shouldLoad(id, plugin, externalModules) {
  1094. if (id.startsWith(plugin.__virtualModulePrefix))
  1095. id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
  1096. if (plugin.loadInclude && !plugin.loadInclude(id))
  1097. return false;
  1098. return !externalModules.has(id);
  1099. }
  1100. function transformUse(data, plugin, transformLoader) {
  1101. if (data.resource == null)
  1102. return [];
  1103. const id = normalizeAbsolutePath(data.resource + (data.resourceQuery || ""));
  1104. if (!plugin.transformInclude || plugin.transformInclude(id)) {
  1105. return [{
  1106. loader: `${transformLoader}?unpluginName=${encodeURIComponent(plugin.name)}`
  1107. }];
  1108. }
  1109. return [];
  1110. }
  1111. // src/esbuild/utils.ts
  1112. var ExtToLoader = {
  1113. ".js": "js",
  1114. ".mjs": "js",
  1115. ".cjs": "js",
  1116. ".jsx": "jsx",
  1117. ".ts": "ts",
  1118. ".cts": "ts",
  1119. ".mts": "ts",
  1120. ".tsx": "tsx",
  1121. ".css": "css",
  1122. ".less": "css",
  1123. ".stylus": "css",
  1124. ".scss": "css",
  1125. ".sass": "css",
  1126. ".json": "json",
  1127. ".txt": "text"
  1128. };
  1129. function guessLoader(code, id) {
  1130. return ExtToLoader[path2.extname(id).toLowerCase()] || "js";
  1131. }
  1132. function unwrapLoader(loader, code, id) {
  1133. if (typeof loader === "function")
  1134. return loader(code, id);
  1135. return loader;
  1136. }
  1137. function fixSourceMap(map) {
  1138. if (!("toString" in map)) {
  1139. Object.defineProperty(map, "toString", {
  1140. enumerable: false,
  1141. value: function toString() {
  1142. return JSON.stringify(this);
  1143. }
  1144. });
  1145. }
  1146. if (!("toUrl" in map)) {
  1147. Object.defineProperty(map, "toUrl", {
  1148. enumerable: false,
  1149. value: function toUrl() {
  1150. return `data:application/json;charset=utf-8;base64,${Buffer2.from(this.toString()).toString("base64")}`;
  1151. }
  1152. });
  1153. }
  1154. return map;
  1155. }
  1156. var nullSourceMap = {
  1157. names: [],
  1158. sources: [],
  1159. mappings: "",
  1160. version: 3
  1161. };
  1162. function combineSourcemaps(filename, sourcemapList) {
  1163. sourcemapList = sourcemapList.filter((m) => m.sources);
  1164. if (sourcemapList.length === 0 || sourcemapList.every((m) => m.sources.length === 0))
  1165. return { ...nullSourceMap };
  1166. let map;
  1167. let mapIndex = 1;
  1168. const useArrayInterface = sourcemapList.slice(0, -1).find((m) => m.sources.length !== 1) === void 0;
  1169. if (useArrayInterface) {
  1170. map = remapping(sourcemapList, () => null, true);
  1171. } else {
  1172. map = remapping(
  1173. sourcemapList[0],
  1174. (sourcefile) => {
  1175. if (sourcefile === filename && sourcemapList[mapIndex])
  1176. return sourcemapList[mapIndex++];
  1177. else
  1178. return { ...nullSourceMap };
  1179. },
  1180. true
  1181. );
  1182. }
  1183. if (!map.file)
  1184. delete map.file;
  1185. return map;
  1186. }
  1187. function createBuildContext(initialOptions) {
  1188. const watchFiles = [];
  1189. return {
  1190. parse(code, opts = {}) {
  1191. return Parser.parse(code, {
  1192. sourceType: "module",
  1193. ecmaVersion: "latest",
  1194. locations: true,
  1195. ...opts
  1196. });
  1197. },
  1198. addWatchFile() {
  1199. throw new Error("unplugin/esbuild: addWatchFile outside supported hooks (resolveId, load, transform)");
  1200. },
  1201. emitFile(emittedFile) {
  1202. if (initialOptions.outdir && !fs.existsSync(initialOptions.outdir))
  1203. fs.mkdirSync(initialOptions.outdir, { recursive: true });
  1204. const outFileName = emittedFile.fileName || emittedFile.name;
  1205. if (initialOptions.outdir && emittedFile.source && outFileName)
  1206. fs.writeFileSync(path2.resolve(initialOptions.outdir, outFileName), emittedFile.source);
  1207. },
  1208. getWatchFiles() {
  1209. return watchFiles;
  1210. }
  1211. };
  1212. }
  1213. function createPluginContext(context) {
  1214. const errors = [];
  1215. const warnings = [];
  1216. const pluginContext = {
  1217. error(message) {
  1218. errors.push(normalizeMessage2(message));
  1219. },
  1220. warn(message) {
  1221. warnings.push(normalizeMessage2(message));
  1222. }
  1223. };
  1224. function normalizeMessage2(message) {
  1225. if (typeof message === "string")
  1226. message = { message };
  1227. return {
  1228. id: message.id,
  1229. pluginName: message.plugin,
  1230. text: message.message,
  1231. location: message.loc ? {
  1232. file: message.loc.file,
  1233. line: message.loc.line,
  1234. column: message.loc.column
  1235. } : null,
  1236. detail: message.meta,
  1237. notes: []
  1238. };
  1239. }
  1240. const mixedContext = {
  1241. ...context,
  1242. ...pluginContext,
  1243. addWatchFile(id) {
  1244. context.getWatchFiles().push(id);
  1245. }
  1246. };
  1247. return {
  1248. errors,
  1249. warnings,
  1250. mixedContext
  1251. };
  1252. }
  1253. function processCodeWithSourceMap(map, code) {
  1254. if (map) {
  1255. if (!map.sourcesContent || map.sourcesContent.length === 0)
  1256. map.sourcesContent = [code];
  1257. map = fixSourceMap(map);
  1258. code += `
  1259. //# sourceMappingURL=${map.toUrl()}`;
  1260. }
  1261. return code;
  1262. }
  1263. // src/esbuild/index.ts
  1264. var i = 0;
  1265. function getEsbuildPlugin(factory) {
  1266. return (userOptions) => {
  1267. const meta = {
  1268. framework: "esbuild"
  1269. };
  1270. const plugins = toArray(factory(userOptions, meta));
  1271. const setup = (plugin) => plugin.esbuild?.setup ?? ((build2) => {
  1272. meta.build = build2;
  1273. const { onStart, onEnd, onResolve, onLoad, initialOptions } = build2;
  1274. const onResolveFilter = plugin.esbuild?.onResolveFilter ?? /.*/;
  1275. const onLoadFilter = plugin.esbuild?.onLoadFilter ?? /.*/;
  1276. const loader = plugin.esbuild?.loader ?? guessLoader;
  1277. const context = createBuildContext(initialOptions);
  1278. if (plugin.esbuild?.config)
  1279. plugin.esbuild.config.call(context, initialOptions);
  1280. if (plugin.buildStart)
  1281. onStart(() => plugin.buildStart.call(context));
  1282. if (plugin.buildEnd || plugin.writeBundle) {
  1283. onEnd(async () => {
  1284. if (plugin.buildEnd)
  1285. await plugin.buildEnd.call(context);
  1286. if (plugin.writeBundle)
  1287. await plugin.writeBundle();
  1288. });
  1289. }
  1290. if (plugin.resolveId) {
  1291. onResolve({ filter: onResolveFilter }, async (args) => {
  1292. if (initialOptions.external?.includes(args.path)) {
  1293. return void 0;
  1294. }
  1295. const { errors, warnings, mixedContext } = createPluginContext(context);
  1296. const isEntry = args.kind === "entry-point";
  1297. const result = await plugin.resolveId.call(
  1298. mixedContext,
  1299. args.path,
  1300. // We explicitly have this if statement here for consistency with the integration of other bundlers.
  1301. // Here, `args.importer` is just an empty string on entry files whereas the equivalent on other bundlers is `undefined.`
  1302. isEntry ? void 0 : args.importer,
  1303. { isEntry }
  1304. );
  1305. if (typeof result === "string") {
  1306. return {
  1307. path: result,
  1308. namespace: plugin.name,
  1309. errors,
  1310. warnings,
  1311. watchFiles: mixedContext.getWatchFiles()
  1312. };
  1313. } else if (typeof result === "object" && result !== null) {
  1314. return {
  1315. path: result.id,
  1316. external: result.external,
  1317. namespace: plugin.name,
  1318. errors,
  1319. warnings,
  1320. watchFiles: mixedContext.getWatchFiles()
  1321. };
  1322. }
  1323. });
  1324. }
  1325. if (plugin.load || plugin.transform) {
  1326. onLoad({ filter: onLoadFilter }, async (args) => {
  1327. const id = args.path + args.suffix;
  1328. const { errors, warnings, mixedContext } = createPluginContext(context);
  1329. const resolveDir = path3.dirname(args.path);
  1330. let code, map;
  1331. if (plugin.load && (!plugin.loadInclude || plugin.loadInclude(id))) {
  1332. const result = await plugin.load.call(mixedContext, id);
  1333. if (typeof result === "string") {
  1334. code = result;
  1335. } else if (typeof result === "object" && result !== null) {
  1336. code = result.code;
  1337. map = result.map;
  1338. }
  1339. }
  1340. if (!plugin.transform) {
  1341. if (code === void 0)
  1342. return null;
  1343. if (map)
  1344. code = processCodeWithSourceMap(map, code);
  1345. return {
  1346. contents: code,
  1347. errors,
  1348. warnings,
  1349. watchFiles: mixedContext.getWatchFiles(),
  1350. loader: unwrapLoader(loader, code, args.path),
  1351. resolveDir
  1352. };
  1353. }
  1354. if (!plugin.transformInclude || plugin.transformInclude(id)) {
  1355. if (!code) {
  1356. code = await fs2.promises.readFile(args.path, "utf8");
  1357. }
  1358. const result = await plugin.transform.call(mixedContext, code, id);
  1359. if (typeof result === "string") {
  1360. code = result;
  1361. } else if (typeof result === "object" && result !== null) {
  1362. code = result.code;
  1363. if (map && result.map) {
  1364. map = combineSourcemaps(args.path, [
  1365. result.map,
  1366. map
  1367. ]);
  1368. } else {
  1369. map = result.map;
  1370. }
  1371. }
  1372. }
  1373. if (code) {
  1374. if (map)
  1375. code = processCodeWithSourceMap(map, code);
  1376. return {
  1377. contents: code,
  1378. errors,
  1379. warnings,
  1380. watchFiles: mixedContext.getWatchFiles(),
  1381. loader: unwrapLoader(loader, code, args.path),
  1382. resolveDir
  1383. };
  1384. }
  1385. });
  1386. }
  1387. });
  1388. const setupMultiplePlugins = () => (build2) => {
  1389. for (const plugin of plugins)
  1390. setup(plugin)(build2);
  1391. };
  1392. return plugins.length === 1 ? { name: plugins[0].name, setup: setup(plugins[0]) } : { name: meta.esbuildHostName ?? `unplugin-host-${i++}`, setup: setupMultiplePlugins() };
  1393. };
  1394. }
  1395. // src/rollup/index.ts
  1396. function getRollupPlugin(factory) {
  1397. return (userOptions) => {
  1398. const meta = {
  1399. framework: "rollup"
  1400. };
  1401. const rawPlugins = toArray(factory(userOptions, meta));
  1402. const plugins = rawPlugins.map((plugin) => toRollupPlugin(plugin));
  1403. return plugins.length === 1 ? plugins[0] : plugins;
  1404. };
  1405. }
  1406. function toRollupPlugin(plugin, containRollupOptions = true) {
  1407. if (plugin.transform && plugin.transformInclude) {
  1408. const _transform = plugin.transform;
  1409. plugin.transform = function(code, id) {
  1410. if (plugin.transformInclude && !plugin.transformInclude(id))
  1411. return null;
  1412. return _transform.call(this, code, id);
  1413. };
  1414. }
  1415. if (plugin.load && plugin.loadInclude) {
  1416. const _load = plugin.load;
  1417. plugin.load = function(id) {
  1418. if (plugin.loadInclude && !plugin.loadInclude(id))
  1419. return null;
  1420. return _load.call(this, id);
  1421. };
  1422. }
  1423. if (plugin.rollup && containRollupOptions)
  1424. Object.assign(plugin, plugin.rollup);
  1425. return plugin;
  1426. }
  1427. // src/rspack/index.ts
  1428. import { resolve as resolve3 } from "path";
  1429. // src/rspack/context.ts
  1430. import { Buffer as Buffer3 } from "buffer";
  1431. import sources from "webpack-sources";
  1432. import { Parser as Parser2 } from "acorn";
  1433. function createBuildContext2(compilation) {
  1434. return {
  1435. parse(code, opts = {}) {
  1436. return Parser2.parse(code, {
  1437. sourceType: "module",
  1438. ecmaVersion: "latest",
  1439. locations: true,
  1440. ...opts
  1441. });
  1442. },
  1443. addWatchFile() {
  1444. },
  1445. emitFile(emittedFile) {
  1446. const outFileName = emittedFile.fileName || emittedFile.name;
  1447. if (emittedFile.source && outFileName) {
  1448. compilation.emitAsset(
  1449. outFileName,
  1450. new sources.RawSource(
  1451. // @ts-expect-error types mismatch
  1452. typeof emittedFile.source === "string" ? emittedFile.source : Buffer3.from(emittedFile.source)
  1453. )
  1454. );
  1455. }
  1456. },
  1457. getWatchFiles() {
  1458. return [];
  1459. }
  1460. };
  1461. }
  1462. // src/rspack/index.ts
  1463. var TRANSFORM_LOADER = resolve3(
  1464. __dirname,
  1465. false ? "../../dist/rspack/loaders/transform.js" : "rspack/loaders/transform"
  1466. );
  1467. var LOAD_LOADER = resolve3(
  1468. __dirname,
  1469. false ? "../../dist/rspack/loaders/load.js" : "rspack/loaders/load"
  1470. );
  1471. var VIRTUAL_MODULE_PREFIX = resolve3(process.cwd(), "_virtual_");
  1472. function getRspackPlugin(factory) {
  1473. return (userOptions) => {
  1474. return {
  1475. apply(compiler) {
  1476. const injected = compiler.$unpluginContext || {};
  1477. compiler.$unpluginContext = injected;
  1478. const meta = {
  1479. framework: "rspack",
  1480. rspack: {
  1481. compiler
  1482. }
  1483. };
  1484. const rawPlugins = toArray(factory(userOptions, meta));
  1485. for (const rawPlugin of rawPlugins) {
  1486. const plugin = Object.assign(
  1487. rawPlugin,
  1488. {
  1489. __unpluginMeta: meta,
  1490. __virtualModulePrefix: VIRTUAL_MODULE_PREFIX
  1491. }
  1492. );
  1493. injected[plugin.name] = plugin;
  1494. compiler.hooks.thisCompilation.tap(plugin.name, (compilation) => {
  1495. if (typeof compilation.hooks.childCompiler === "undefined")
  1496. throw new Error("`compilation.hooks.childCompiler` only support by @rspack/core>=0.4.1");
  1497. compilation.hooks.childCompiler.tap(plugin.name, (childCompiler) => {
  1498. childCompiler.$unpluginContext = injected;
  1499. });
  1500. });
  1501. const externalModules = /* @__PURE__ */ new Set();
  1502. if (plugin.load) {
  1503. compiler.options.module.rules.unshift({
  1504. enforce: plugin.enforce,
  1505. include(id) {
  1506. return shouldLoad(id, plugin, externalModules);
  1507. },
  1508. use: [{
  1509. loader: LOAD_LOADER,
  1510. options: {
  1511. unpluginName: plugin.name
  1512. }
  1513. }]
  1514. });
  1515. }
  1516. if (plugin.transform) {
  1517. compiler.options.module.rules.unshift({
  1518. enforce: plugin.enforce,
  1519. use(data) {
  1520. return transformUse(data, plugin, TRANSFORM_LOADER);
  1521. }
  1522. });
  1523. }
  1524. if (plugin.rspack)
  1525. plugin.rspack(compiler);
  1526. if (plugin.buildStart) {
  1527. compiler.hooks.make.tapPromise(plugin.name, async (compilation) => {
  1528. const context = createBuildContext2(compilation);
  1529. return plugin.buildStart.call(context);
  1530. });
  1531. }
  1532. if (plugin.buildEnd) {
  1533. compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => {
  1534. await plugin.buildEnd.call(createBuildContext2(compilation));
  1535. });
  1536. }
  1537. if (plugin.writeBundle) {
  1538. compiler.hooks.afterEmit.tap(plugin.name, () => {
  1539. plugin.writeBundle();
  1540. });
  1541. }
  1542. }
  1543. }
  1544. };
  1545. };
  1546. }
  1547. // src/vite/index.ts
  1548. function getVitePlugin(factory) {
  1549. return (userOptions) => {
  1550. const meta = {
  1551. framework: "vite"
  1552. };
  1553. const rawPlugins = toArray(factory(userOptions, meta));
  1554. const plugins = rawPlugins.map((rawPlugin) => {
  1555. const plugin = toRollupPlugin(rawPlugin, false);
  1556. if (rawPlugin.vite)
  1557. Object.assign(plugin, rawPlugin.vite);
  1558. return plugin;
  1559. });
  1560. return plugins.length === 1 ? plugins[0] : plugins;
  1561. };
  1562. }
  1563. // src/webpack/index.ts
  1564. import fs3 from "fs";
  1565. import { resolve as resolve5 } from "path";
  1566. import process3 from "process";
  1567. import VirtualModulesPlugin from "webpack-virtual-modules";
  1568. // src/webpack/context.ts
  1569. import { resolve as resolve4 } from "path";
  1570. import { Buffer as Buffer4 } from "buffer";
  1571. import process2 from "process";
  1572. import sources2 from "webpack-sources";
  1573. import { Parser as Parser3 } from "acorn";
  1574. function contextOptionsFromCompilation(compilation) {
  1575. return {
  1576. addWatchFile(file) {
  1577. (compilation.fileDependencies ?? compilation.compilationDependencies).add(file);
  1578. },
  1579. getWatchFiles() {
  1580. return Array.from(compilation.fileDependencies ?? compilation.compilationDependencies);
  1581. }
  1582. };
  1583. }
  1584. function createBuildContext3(options, compilation) {
  1585. return {
  1586. parse(code, opts = {}) {
  1587. return Parser3.parse(code, {
  1588. sourceType: "module",
  1589. ecmaVersion: "latest",
  1590. locations: true,
  1591. ...opts
  1592. });
  1593. },
  1594. addWatchFile(id) {
  1595. options.addWatchFile(resolve4(process2.cwd(), id));
  1596. },
  1597. emitFile(emittedFile) {
  1598. const outFileName = emittedFile.fileName || emittedFile.name;
  1599. if (emittedFile.source && outFileName) {
  1600. if (!compilation)
  1601. throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
  1602. compilation.emitAsset(
  1603. outFileName,
  1604. sources2 ? new sources2.RawSource(
  1605. // @ts-expect-error types mismatch
  1606. typeof emittedFile.source === "string" ? emittedFile.source : Buffer4.from(emittedFile.source)
  1607. ) : {
  1608. source: () => emittedFile.source,
  1609. size: () => emittedFile.source.length
  1610. }
  1611. );
  1612. }
  1613. },
  1614. getWatchFiles() {
  1615. return options.getWatchFiles();
  1616. }
  1617. };
  1618. }
  1619. function normalizeMessage(error) {
  1620. const err = new Error(typeof error === "string" ? error : error.message);
  1621. if (typeof error === "object") {
  1622. err.stack = error.stack;
  1623. err.cause = error.meta;
  1624. }
  1625. return err;
  1626. }
  1627. // src/webpack/index.ts
  1628. var TRANSFORM_LOADER2 = resolve5(
  1629. __dirname,
  1630. false ? "../../dist/webpack/loaders/transform" : "webpack/loaders/transform"
  1631. );
  1632. var LOAD_LOADER2 = resolve5(
  1633. __dirname,
  1634. false ? "../../dist/webpack/loaders/load" : "webpack/loaders/load"
  1635. );
  1636. var VIRTUAL_MODULE_PREFIX2 = resolve5(process3.cwd(), "_virtual_");
  1637. function getWebpackPlugin(factory) {
  1638. return (userOptions) => {
  1639. return {
  1640. apply(compiler) {
  1641. const injected = compiler.$unpluginContext || {};
  1642. compiler.$unpluginContext = injected;
  1643. const meta = {
  1644. framework: "webpack",
  1645. webpack: {
  1646. compiler
  1647. }
  1648. };
  1649. const rawPlugins = toArray(factory(userOptions, meta));
  1650. for (const rawPlugin of rawPlugins) {
  1651. const plugin = Object.assign(
  1652. rawPlugin,
  1653. {
  1654. __unpluginMeta: meta,
  1655. __virtualModulePrefix: VIRTUAL_MODULE_PREFIX2
  1656. }
  1657. );
  1658. injected[plugin.name] = plugin;
  1659. compiler.hooks.thisCompilation.tap(plugin.name, (compilation) => {
  1660. compilation.hooks.childCompiler.tap(plugin.name, (childCompiler) => {
  1661. childCompiler.$unpluginContext = injected;
  1662. });
  1663. });
  1664. const externalModules = /* @__PURE__ */ new Set();
  1665. if (plugin.resolveId) {
  1666. let vfs = compiler.options.plugins.find((i2) => i2 instanceof VirtualModulesPlugin);
  1667. if (!vfs) {
  1668. vfs = new VirtualModulesPlugin();
  1669. compiler.options.plugins.push(vfs);
  1670. }
  1671. plugin.__vfsModules = /* @__PURE__ */ new Set();
  1672. plugin.__vfs = vfs;
  1673. const resolverPlugin = {
  1674. apply(resolver) {
  1675. const target = resolver.ensureHook("resolve");
  1676. resolver.getHook("resolve").tapAsync(plugin.name, async (request, resolveContext, callback) => {
  1677. if (!request.request)
  1678. return callback();
  1679. if (normalizeAbsolutePath(request.request).startsWith(plugin.__virtualModulePrefix))
  1680. return callback();
  1681. const id = normalizeAbsolutePath(request.request);
  1682. const requestContext = request.context;
  1683. const importer = requestContext.issuer !== "" ? requestContext.issuer : void 0;
  1684. const isEntry = requestContext.issuer === "";
  1685. const fileDependencies = /* @__PURE__ */ new Set();
  1686. const context = createBuildContext3({
  1687. addWatchFile(file) {
  1688. fileDependencies.add(file);
  1689. resolveContext.fileDependencies?.add(file);
  1690. },
  1691. getWatchFiles() {
  1692. return Array.from(fileDependencies);
  1693. }
  1694. });
  1695. let error;
  1696. const pluginContext = {
  1697. error(msg) {
  1698. if (error == null)
  1699. error = normalizeMessage(msg);
  1700. else
  1701. console.error(`unplugin/webpack: multiple errors returned from resolveId hook: ${msg}`);
  1702. },
  1703. warn(msg) {
  1704. console.warn(`unplugin/webpack: warning from resolveId hook: ${msg}`);
  1705. }
  1706. };
  1707. const resolveIdResult = await plugin.resolveId.call({ ...context, ...pluginContext }, id, importer, { isEntry });
  1708. if (error != null)
  1709. return callback(error);
  1710. if (resolveIdResult == null)
  1711. return callback();
  1712. let resolved = typeof resolveIdResult === "string" ? resolveIdResult : resolveIdResult.id;
  1713. const isExternal = typeof resolveIdResult === "string" ? false : resolveIdResult.external === true;
  1714. if (isExternal)
  1715. externalModules.add(resolved);
  1716. if (!fs3.existsSync(resolved)) {
  1717. resolved = normalizeAbsolutePath(
  1718. plugin.__virtualModulePrefix + encodeURIComponent(resolved)
  1719. // URI encode id so webpack doesn't think it's part of the path
  1720. );
  1721. if (!plugin.__vfsModules.has(resolved)) {
  1722. plugin.__vfs.writeModule(resolved, "");
  1723. plugin.__vfsModules.add(resolved);
  1724. }
  1725. }
  1726. const newRequest = {
  1727. ...request,
  1728. request: resolved
  1729. };
  1730. resolver.doResolve(target, newRequest, null, resolveContext, callback);
  1731. });
  1732. }
  1733. };
  1734. compiler.options.resolve.plugins = compiler.options.resolve.plugins || [];
  1735. compiler.options.resolve.plugins.push(resolverPlugin);
  1736. }
  1737. if (plugin.load) {
  1738. compiler.options.module.rules.unshift({
  1739. include(id) {
  1740. return shouldLoad(id, plugin, externalModules);
  1741. },
  1742. enforce: plugin.enforce,
  1743. use: [{
  1744. loader: LOAD_LOADER2,
  1745. options: {
  1746. unpluginName: plugin.name
  1747. }
  1748. }]
  1749. });
  1750. }
  1751. if (plugin.transform) {
  1752. compiler.options.module.rules.unshift({
  1753. enforce: plugin.enforce,
  1754. use(data) {
  1755. return transformUse(data, plugin, TRANSFORM_LOADER2);
  1756. }
  1757. });
  1758. }
  1759. if (plugin.webpack)
  1760. plugin.webpack(compiler);
  1761. if (plugin.watchChange || plugin.buildStart) {
  1762. compiler.hooks.make.tapPromise(plugin.name, async (compilation) => {
  1763. const context = createBuildContext3(contextOptionsFromCompilation(compilation), compilation);
  1764. if (plugin.watchChange && (compiler.modifiedFiles || compiler.removedFiles)) {
  1765. const promises = [];
  1766. if (compiler.modifiedFiles) {
  1767. compiler.modifiedFiles.forEach(
  1768. (file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "update" })))
  1769. );
  1770. }
  1771. if (compiler.removedFiles) {
  1772. compiler.removedFiles.forEach(
  1773. (file) => promises.push(Promise.resolve(plugin.watchChange.call(context, file, { event: "delete" })))
  1774. );
  1775. }
  1776. await Promise.all(promises);
  1777. }
  1778. if (plugin.buildStart)
  1779. return await plugin.buildStart.call(context);
  1780. });
  1781. }
  1782. if (plugin.buildEnd) {
  1783. compiler.hooks.emit.tapPromise(plugin.name, async (compilation) => {
  1784. await plugin.buildEnd.call(createBuildContext3(contextOptionsFromCompilation(compilation), compilation));
  1785. });
  1786. }
  1787. if (plugin.writeBundle) {
  1788. compiler.hooks.afterEmit.tap(plugin.name, () => {
  1789. plugin.writeBundle();
  1790. });
  1791. }
  1792. }
  1793. }
  1794. };
  1795. };
  1796. }
  1797. // src/define.ts
  1798. function createUnplugin(factory) {
  1799. return {
  1800. get esbuild() {
  1801. return getEsbuildPlugin(factory);
  1802. },
  1803. get rollup() {
  1804. return getRollupPlugin(factory);
  1805. },
  1806. get vite() {
  1807. return getVitePlugin(factory);
  1808. },
  1809. get webpack() {
  1810. return getWebpackPlugin(factory);
  1811. },
  1812. /** @experimental do not use it in production */
  1813. get rspack() {
  1814. return getRspackPlugin(factory);
  1815. },
  1816. get raw() {
  1817. return factory;
  1818. }
  1819. };
  1820. }
  1821. function createEsbuildPlugin(factory) {
  1822. return getEsbuildPlugin(factory);
  1823. }
  1824. function createRollupPlugin(factory) {
  1825. return getRollupPlugin(factory);
  1826. }
  1827. function createVitePlugin(factory) {
  1828. return getVitePlugin(factory);
  1829. }
  1830. function createWebpackPlugin(factory) {
  1831. return getWebpackPlugin(factory);
  1832. }
  1833. function createRspackPlugin(factory) {
  1834. return getRspackPlugin(factory);
  1835. }
  1836. export {
  1837. createEsbuildPlugin,
  1838. createRollupPlugin,
  1839. createRspackPlugin,
  1840. createUnplugin,
  1841. createVitePlugin,
  1842. createWebpackPlugin
  1843. };