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