index.js 61 KB

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