@rollipop/core 0.1.0-alpha.1 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as __require, t as __export } from "./chunk-BYW8Mqxw.js";
1
+ import { n as __export, r as __require, t as __commonJSMin } from "./chunk-DJulfCLt.js";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import { DEV_SERVER_ASSET_PATH, FileStorage, Logger, Logo, chalk, getCachePath } from "@rollipop/common";
@@ -19,6 +19,18 @@ import flowRemoveTypes from "flow-remove-types";
19
19
  import * as hermesParser from "hermes-parser";
20
20
  import { imageSize } from "image-size";
21
21
  import { transform } from "@svgr/core";
22
+ import url from "url";
23
+ import { createDevServerMiddleware } from "@react-native-community/cli-server-api";
24
+ import { createDevMiddleware } from "@react-native/dev-middleware";
25
+ import Fastify from "fastify";
26
+ import http from "node:http";
27
+ import EventEmitter from "node:events";
28
+ import { SourceMapConsumer } from "source-map";
29
+ import fp from "fastify-plugin";
30
+ import { asConst } from "json-schema-to-ts";
31
+ import mime from "mime";
32
+ import Ajv from "ajv";
33
+ import * as ws from "ws";
22
34
  import * as c12 from "c12";
23
35
 
24
36
  //#region src/utils/build-options.ts
@@ -35,7 +47,7 @@ function resolveBuildOptions(projectRoot, buildOptions) {
35
47
 
36
48
  //#endregion
37
49
  //#region src/constants.ts
38
- const ROLLIPOP_VERSION = "0.1.0-alpha.1";
50
+ const ROLLIPOP_VERSION = "0.1.0-alpha.2";
39
51
  const GLOBAL_IDENTIFIER = "__ROLLIPOP_GLOBAL__";
40
52
  /**
41
53
  * Unlike the Metro bundler configuration, this prioritizes resolving module(ESM) fields first.
@@ -134,7 +146,7 @@ function createId(config, buildOptions) {
134
146
 
135
147
  //#endregion
136
148
  //#region src/logger.ts
137
- const logger = new Logger("bundler");
149
+ const logger$1 = new Logger("bundler");
138
150
 
139
151
  //#endregion
140
152
  //#region src/core/cache/file-system-cache.ts
@@ -142,7 +154,7 @@ var FileSystemCache = class {
142
154
  constructor(cacheDirectory) {
143
155
  this.cacheDirectory = cacheDirectory;
144
156
  this.ensureCacheDirectory();
145
- logger.debug("cache directory:", cacheDirectory);
157
+ logger$1.debug("cache directory:", cacheDirectory);
146
158
  }
147
159
  ensureCacheDirectory() {
148
160
  if (!fs.existsSync(this.cacheDirectory)) fs.mkdirSync(this.cacheDirectory, { recursive: true });
@@ -158,7 +170,7 @@ var FileSystemCache = class {
158
170
  try {
159
171
  fs.writeFileSync(path.join(this.cacheDirectory, key), value);
160
172
  } catch {
161
- logger.error("Failed to write cache file", key);
173
+ logger$1.error("Failed to write cache file", key);
162
174
  }
163
175
  }
164
176
  clear() {
@@ -483,7 +495,7 @@ function progressBar(reporter, context, label) {
483
495
  renderProgress(id, totalModules, transformedModules);
484
496
  break;
485
497
  case Boolean(flags & ProgressFlags.WATCH_CHANGE):
486
- logger.debug("Transformed changed file", { id });
498
+ logger$1.debug("Transformed changed file", { id });
487
499
  break;
488
500
  }
489
501
  },
@@ -495,12 +507,12 @@ function progressBar(reporter, context, label) {
495
507
  function compat(reporter) {
496
508
  return withReporter(reporter, {
497
509
  onStart() {
498
- logger.info("Build started...");
510
+ logger$1.info("Build started...");
499
511
  },
500
512
  onEnd({ totalModules, duration }) {
501
513
  const time = chalk.blue(`${duration.toFixed(2)}ms`);
502
514
  const modules = chalk.blue(`(${totalModules} modules)`);
503
- logger.info(`Build finished in ${time} ${modules}`);
515
+ logger$1.info(`Build finished in ${time} ${modules}`);
504
516
  }
505
517
  });
506
518
  }
@@ -906,14 +918,14 @@ function getCacheKey(id, buildHash) {
906
918
  /**
907
919
  * Enhance a plugin to cache the result. (transform hook only)
908
920
  */
909
- function cacheable(plugin) {
910
- const originalTransform = plugin.transform;
911
- if (typeof originalTransform === "function") plugin.transform = function(code, id, meta) {
921
+ function cacheable(plugin$3) {
922
+ const originalTransform = plugin$3.transform;
923
+ if (typeof originalTransform === "function") plugin$3.transform = function(code, id, meta) {
912
924
  const moduleInfo = this.getModuleInfo(id);
913
925
  if (moduleInfo && isCacheHit(moduleInfo.meta)) return;
914
926
  return originalTransform.call(this, code, id, meta);
915
927
  };
916
- if (typeof originalTransform === "object") plugin.transform = {
928
+ if (typeof originalTransform === "object") plugin$3.transform = {
917
929
  ...originalTransform,
918
930
  handler(code, id, meta) {
919
931
  const moduleInfo = this.getModuleInfo(id);
@@ -921,7 +933,7 @@ function cacheable(plugin) {
921
933
  return originalTransform.handler.call(this, code, id, meta);
922
934
  }
923
935
  };
924
- return plugin;
936
+ return plugin$3;
925
937
  }
926
938
  const PluginUtils = Object.freeze({ cacheable });
927
939
 
@@ -1260,17 +1272,17 @@ function jsonPlugin() {
1260
1272
  }
1261
1273
  function jsonToEsm(data) {
1262
1274
  const declarations = [];
1263
- const exports = [];
1275
+ const exports$1 = [];
1264
1276
  const exportDefaultMappings = [];
1265
1277
  Object.entries(data).forEach(([key, value], index) => {
1266
1278
  const identifier = `_${index}`;
1267
1279
  declarations.push(`const ${identifier} = ${JSON.stringify(value)};`);
1268
- exports.push(`export { ${identifier} as "${key}" };`);
1280
+ exports$1.push(`export { ${identifier} as "${key}" };`);
1269
1281
  exportDefaultMappings.push(`"${key}":${identifier}`);
1270
1282
  });
1271
1283
  return [
1272
1284
  ...declarations,
1273
- ...exports,
1285
+ ...exports$1,
1274
1286
  `export default {${exportDefaultMappings.join(",")}};`
1275
1287
  ].join("\n");
1276
1288
  }
@@ -1321,9 +1333,30 @@ var plugins_exports = /* @__PURE__ */ __export({
1321
1333
  svg: () => svgPlugin
1322
1334
  });
1323
1335
 
1336
+ //#endregion
1337
+ //#region src/core/plugins/context.ts
1338
+ const pluginLogger = new Logger();
1339
+ function createPluginContext(name) {
1340
+ return {
1341
+ debug: (log) => {
1342
+ printPluginLog("debug", log, name);
1343
+ },
1344
+ info: (log) => {
1345
+ printPluginLog("info", log, name);
1346
+ },
1347
+ warn: (log) => {
1348
+ printPluginLog("warn", log, name);
1349
+ }
1350
+ };
1351
+ }
1352
+ function printPluginLog(level, log, pluginName = "unknown") {
1353
+ const pluginLabel = chalk.magenta(`plugin:${pluginName}`);
1354
+ if (typeof log === "string") pluginLogger[level](pluginLabel, log);
1355
+ else pluginLogger[level](pluginLabel, log.stack ?? log.message);
1356
+ }
1357
+
1324
1358
  //#endregion
1325
1359
  //#region src/core/rolldown.ts
1326
- const rolldownLogger = new Logger("rolldown");
1327
1360
  resolveRolldownOptions.cache = /* @__PURE__ */ new Map();
1328
1361
  async function resolveRolldownOptions(context, config, buildOptions) {
1329
1362
  const cachedOptions = resolveRolldownOptions.cache.get(context.id);
@@ -1393,20 +1426,9 @@ async function resolveRolldownOptions(context, config, buildOptions) {
1393
1426
  pluginTimings: false
1394
1427
  },
1395
1428
  logLevel: isDebugEnabled() ? "debug" : "info",
1396
- onLog(level, log) {
1397
- const { message, code } = log;
1398
- const logArgs = [code, message].filter(isNotNil);
1399
- switch (level) {
1400
- case "debug":
1401
- rolldownLogger.debug(...logArgs);
1402
- break;
1403
- case "info":
1404
- rolldownLogger.info(...logArgs);
1405
- break;
1406
- case "warn":
1407
- rolldownLogger.warn(...logArgs);
1408
- break;
1409
- }
1429
+ onLog(level, log, defaultHandler) {
1430
+ if (log.code?.startsWith("PLUGIN_")) printPluginLog(level, log, log.plugin);
1431
+ else defaultHandler(level, log);
1410
1432
  }
1411
1433
  }, {
1412
1434
  postBanner: [...getGlobalVariables(dev$1, context.mode)].join("\n"),
@@ -1518,6 +1540,2348 @@ var Bundler = class Bundler {
1518
1540
  }
1519
1541
  };
1520
1542
 
1543
+ //#endregion
1544
+ //#region src/server/logger.ts
1545
+ const logger = new Logger("dev-server");
1546
+ var DevServerLogger = class {
1547
+ level = "trace";
1548
+ trace(...args) {
1549
+ logger.trace(...args);
1550
+ }
1551
+ debug(...args) {
1552
+ logger.debug(...args);
1553
+ }
1554
+ info(...args) {
1555
+ logger.info(...args);
1556
+ }
1557
+ warn(...args) {
1558
+ logger.warn(...args);
1559
+ }
1560
+ error(...args) {
1561
+ logger.error(...args);
1562
+ }
1563
+ silent(...args) {
1564
+ logger.trace(chalk.gray("(silent)"), ...args);
1565
+ }
1566
+ fatal(...args) {
1567
+ logger.error(chalk.magenta("(fatal)"), ...args);
1568
+ }
1569
+ child(_bindings) {
1570
+ return this;
1571
+ }
1572
+ };
1573
+
1574
+ //#endregion
1575
+ //#region src/utils/dev-server.ts
1576
+ async function assertDevServerStatus(options) {
1577
+ const { devServerUrl, projectRoot, port } = options;
1578
+ const status = await getDevServerStatus(devServerUrl, projectRoot);
1579
+ let shouldExit = false;
1580
+ switch (status) {
1581
+ case DevServerStatus.MATCHED_SERVER_RUNNING:
1582
+ logger.warn(`A dev server is already running for this project on port ${port}. Exiting.`);
1583
+ shouldExit = true;
1584
+ break;
1585
+ case DevServerStatus.PORT_TAKEN:
1586
+ logger.error(`Another process is running on port ${port}. Please terminate this process and try again, or use another port with "--port".`);
1587
+ shouldExit = true;
1588
+ break;
1589
+ }
1590
+ if (shouldExit) process.exit(1);
1591
+ }
1592
+ var DevServerStatus = /* @__PURE__ */ function(DevServerStatus$1) {
1593
+ DevServerStatus$1[DevServerStatus$1["NOT_RUNNING"] = 0] = "NOT_RUNNING";
1594
+ DevServerStatus$1[DevServerStatus$1["MATCHED_SERVER_RUNNING"] = 1] = "MATCHED_SERVER_RUNNING";
1595
+ DevServerStatus$1[DevServerStatus$1["PORT_TAKEN"] = 2] = "PORT_TAKEN";
1596
+ DevServerStatus$1[DevServerStatus$1["UNKNOWN"] = 3] = "UNKNOWN";
1597
+ return DevServerStatus$1;
1598
+ }(DevServerStatus || {});
1599
+ async function getDevServerStatus(devServerUrl, projectRoot) {
1600
+ const { hostname, port } = new URL(devServerUrl);
1601
+ try {
1602
+ if (!await isPortOccupied(hostname, port)) return DevServerStatus.NOT_RUNNING;
1603
+ const statusResponse = await fetch(`${devServerUrl}/status`);
1604
+ return await statusResponse.text() === "packager-status:running" && statusResponse.headers.get("X-React-Native-Project-Root") === projectRoot ? DevServerStatus.MATCHED_SERVER_RUNNING : DevServerStatus.PORT_TAKEN;
1605
+ } catch {
1606
+ return DevServerStatus.UNKNOWN;
1607
+ }
1608
+ }
1609
+ async function isPortOccupied(host, port) {
1610
+ let result = false;
1611
+ const server = http.createServer();
1612
+ return new Promise((resolve, reject) => {
1613
+ server.once("error", (error) => {
1614
+ server.close();
1615
+ if (error.code === "EADDRINUSE") result = true;
1616
+ else reject(error);
1617
+ });
1618
+ server.once("listening", () => {
1619
+ result = false;
1620
+ server.close();
1621
+ });
1622
+ server.once("close", () => resolve(result));
1623
+ server.listen({
1624
+ host,
1625
+ port
1626
+ });
1627
+ });
1628
+ }
1629
+
1630
+ //#endregion
1631
+ //#region src/utils/bundle.ts
1632
+ function getBaseBundleName(name) {
1633
+ return name.replace(/^\//, "").replace(/\.bundle$/, "");
1634
+ }
1635
+
1636
+ //#endregion
1637
+ //#region src/utils/config.ts
1638
+ function bindReporter(config, eventSource) {
1639
+ const originalReporter = config.reporter;
1640
+ config.reporter = { update(event) {
1641
+ switch (event.type) {
1642
+ case "bundle_build_started":
1643
+ eventSource.emit("buildStart");
1644
+ break;
1645
+ case "bundle_build_done":
1646
+ eventSource.emit("buildDone");
1647
+ break;
1648
+ case "bundle_build_failed":
1649
+ eventSource.emit("buildFailed", event.error);
1650
+ break;
1651
+ case "transform":
1652
+ eventSource.emit("transform", event.id, event.totalModules, event.transformedModules);
1653
+ break;
1654
+ case "watch_change":
1655
+ eventSource.emit("watchChange", event.id);
1656
+ break;
1657
+ }
1658
+ originalReporter.update(event);
1659
+ } };
1660
+ return config;
1661
+ }
1662
+
1663
+ //#endregion
1664
+ //#region src/utils/promise.ts
1665
+ function taskHandler() {
1666
+ let resolver;
1667
+ let rejector;
1668
+ return {
1669
+ task: new Promise((resolve, reject) => {
1670
+ resolver = resolve;
1671
+ rejector = reject;
1672
+ }),
1673
+ resolve: () => resolver?.(void 0),
1674
+ reject: (reason) => rejector?.(reason)
1675
+ };
1676
+ }
1677
+
1678
+ //#endregion
1679
+ //#region src/utils/source-map.ts
1680
+ function replaceSourceMappingURL(code, sourceMappingURL) {
1681
+ const marker = "//# sourceMappingURL=";
1682
+ const lastIndex = code.lastIndexOf(marker);
1683
+ if (lastIndex === -1) return code;
1684
+ let endIndex = code.indexOf("\n", lastIndex);
1685
+ if (endIndex === -1) endIndex = code.length;
1686
+ return [
1687
+ code.slice(0, lastIndex),
1688
+ `${marker}${sourceMappingURL}`,
1689
+ code.slice(endIndex)
1690
+ ].join("");
1691
+ }
1692
+
1693
+ //#endregion
1694
+ //#region src/server/bundle.ts
1695
+ var InMemoryBundle = class {
1696
+ lazySourceMapConsumer = null;
1697
+ constructor(_code, _sourceMap, sourceMappingURL) {
1698
+ this._code = _code;
1699
+ this._sourceMap = _sourceMap;
1700
+ this._code = replaceSourceMappingURL(this._code, sourceMappingURL);
1701
+ }
1702
+ get code() {
1703
+ return this._code;
1704
+ }
1705
+ get sourceMap() {
1706
+ return this._sourceMap;
1707
+ }
1708
+ get sourceMapConsumer() {
1709
+ invariant(this._sourceMap, "Source map is not available");
1710
+ if (this.lazySourceMapConsumer == null) this.lazySourceMapConsumer = new SourceMapConsumer(this._sourceMap);
1711
+ return this.lazySourceMapConsumer;
1712
+ }
1713
+ };
1714
+
1715
+ //#endregion
1716
+ //#region src/server/bundler-pool.ts
1717
+ var BundlerDevEngine = class extends EventEmitter {
1718
+ initializeHandle;
1719
+ _id;
1720
+ bundle = null;
1721
+ _devEngine = null;
1722
+ _state = "idle";
1723
+ constructor(options, config, buildOptions) {
1724
+ super();
1725
+ this.options = options;
1726
+ this.config = config;
1727
+ this.buildOptions = buildOptions;
1728
+ this._id = Bundler.createId(config, buildOptions);
1729
+ this.initializeHandle = taskHandler();
1730
+ this.initialize();
1731
+ }
1732
+ get id() {
1733
+ return this._id;
1734
+ }
1735
+ get devEngine() {
1736
+ invariant(this._devEngine, "DevEngine is not initialized");
1737
+ return this._devEngine;
1738
+ }
1739
+ get ensureInitialized() {
1740
+ return this.initializeHandle.task;
1741
+ }
1742
+ get sourceMappingURL() {
1743
+ const { host, port } = this.options.server;
1744
+ const { platform, dev: dev$1 } = this.buildOptions;
1745
+ const [name] = this.config.entry.split(".");
1746
+ return `http://${host}:${port}/${name}.bundle.map?platform=${platform}&dev=${dev$1}`;
1747
+ }
1748
+ async initialize() {
1749
+ if (this._state !== "idle" || this._devEngine != null) return this;
1750
+ this._state = "initializing";
1751
+ const devEngine = await Bundler.devEngine(bindReporter(this.config, this), this.buildOptions, {
1752
+ host: this.options.server.host,
1753
+ port: this.options.server.port,
1754
+ onHmrUpdates: (errorOrResult) => {
1755
+ if (errorOrResult instanceof Error) logger.error("Failed to handle HMR updates", {
1756
+ bundlerId: this.id,
1757
+ error: errorOrResult
1758
+ });
1759
+ else {
1760
+ logger.trace("Detected changed files", {
1761
+ bundlerId: this.id,
1762
+ changedFiles: errorOrResult.changedFiles
1763
+ });
1764
+ this.emit("hmrUpdates", errorOrResult.updates);
1765
+ }
1766
+ },
1767
+ onOutput: (errorOrResult) => {
1768
+ if (errorOrResult instanceof Error) logger.error("Failed to build bundle", {
1769
+ bundlerId: this.id,
1770
+ error: errorOrResult
1771
+ });
1772
+ else {
1773
+ const output = errorOrResult.output[0];
1774
+ const sourceMap = output.map?.toString();
1775
+ this.bundle = new InMemoryBundle(output.code, sourceMap, this.sourceMappingURL);
1776
+ logger.debug("Build completed", {
1777
+ bundlerId: this.id,
1778
+ bundleName: output.name
1779
+ });
1780
+ }
1781
+ },
1782
+ rebuildStrategy: "auto",
1783
+ watch: this.config.watcher
1784
+ });
1785
+ await devEngine.run();
1786
+ this._devEngine = devEngine;
1787
+ this._state = "ready";
1788
+ this.initializeHandle.resolve();
1789
+ }
1790
+ async getBundle() {
1791
+ await this.ensureInitialized;
1792
+ if ((await this.devEngine.getBundleState()).hasStaleOutput || this.bundle == null) await this.devEngine.ensureLatestBuildOutput();
1793
+ invariant(this.bundle, "Bundle is not available");
1794
+ return this.bundle;
1795
+ }
1796
+ };
1797
+ var BundlerPool = class BundlerPool {
1798
+ static instances = /* @__PURE__ */ new Map();
1799
+ constructor(config, resolvedServerOptions) {
1800
+ this.config = config;
1801
+ this.resolvedServerOptions = resolvedServerOptions;
1802
+ }
1803
+ instanceKey(bundleName, buildOptions) {
1804
+ return `${bundleName}-${Bundler.createId(this.config, buildOptions)}`;
1805
+ }
1806
+ get(bundleName, buildOptions) {
1807
+ const key = this.instanceKey(getBaseBundleName(bundleName), buildOptions);
1808
+ const instance = BundlerPool.instances.get(key);
1809
+ if (instance) return instance;
1810
+ else {
1811
+ logger.debug("Preparing new bundler instance", {
1812
+ bundleName,
1813
+ key
1814
+ });
1815
+ const instance$1 = new BundlerDevEngine({ server: this.resolvedServerOptions }, this.config, buildOptions);
1816
+ logger.debug("Setting new bundler instance", { key });
1817
+ BundlerPool.instances.set(key, instance$1);
1818
+ return instance$1;
1819
+ }
1820
+ }
1821
+ };
1822
+
1823
+ //#endregion
1824
+ //#region src/server/constants.ts
1825
+ const DEFAULT_PORT = 8081;
1826
+ const DEFAULT_HOST = "localhost";
1827
+
1828
+ //#endregion
1829
+ //#region src/server/error.ts
1830
+ function errorHandler(error, request, reply) {
1831
+ logger.error(`An error occurred while processing the request (${request.method} ${request.url}):`, error.message);
1832
+ logger.debug(error);
1833
+ reply.status(500).send("Internal Server Error");
1834
+ }
1835
+
1836
+ //#endregion
1837
+ //#region src/server/middlewares/serve-assets.ts
1838
+ const queryParamSchema = asConst({
1839
+ type: "object",
1840
+ properties: {
1841
+ platform: { type: "string" },
1842
+ hash: { type: "string" }
1843
+ },
1844
+ required: ["platform"]
1845
+ });
1846
+ const plugin$2 = fp((fastify, options) => {
1847
+ const { projectRoot, host, port, https, preferNativePlatform } = options;
1848
+ const baseUrl = https ? `https://${host}:${port}` : `http://${host}:${port}`;
1849
+ function resolveAsset(asset) {
1850
+ return path.resolve(projectRoot, asset);
1851
+ }
1852
+ fastify.get(`/${DEV_SERVER_ASSET_PATH}/*`, {
1853
+ schema: { querystring: queryParamSchema },
1854
+ async handler(request, reply) {
1855
+ const { url: url$1, query } = request;
1856
+ const { pathname } = new URL(url$1, baseUrl);
1857
+ const assetPath = resolveAsset(pathname.replace(/* @__PURE__ */ new RegExp(`^/${DEV_SERVER_ASSET_PATH}/?`), ""));
1858
+ let handle = null;
1859
+ try {
1860
+ handle = await fs.promises.open(resolveAssetPath(assetPath, {
1861
+ platform: query.platform,
1862
+ preferNativePlatform
1863
+ }, 1), "r");
1864
+ const assetData = await handle.readFile();
1865
+ const { size } = await handle.stat();
1866
+ await reply.header("Content-Type", mime.getType(assetPath) ?? "").header("Content-Length", size).send(assetData);
1867
+ } catch (error) {
1868
+ fastify.log.error(error, "Failed to serve asset (scale assets resolving is not implemented yet)");
1869
+ await reply.status(500).send();
1870
+ } finally {
1871
+ await handle?.close();
1872
+ }
1873
+ }
1874
+ });
1875
+ }, { name: "serve-assets" });
1876
+
1877
+ //#endregion
1878
+ //#region src/utils/response.ts
1879
+ var BundleResponse = class BundleResponse {
1880
+ static CRLF = "\r\n";
1881
+ static THROTTLE_DELAY = 10;
1882
+ done = 0;
1883
+ total = 0;
1884
+ boundary;
1885
+ throttleTimer = null;
1886
+ constructor(reply) {
1887
+ this.reply = reply;
1888
+ const boundary = performance.now().toString();
1889
+ this.boundary = boundary;
1890
+ this.reply.raw.writeHead(200, { "Content-Type": `multipart/mixed; boundary="${boundary}"` });
1891
+ }
1892
+ writeChunk(data, headers, end = false) {
1893
+ if (this.reply.raw.writableEnded) return;
1894
+ const CRLF = BundleResponse.CRLF;
1895
+ this.reply.raw.write(`${CRLF}--${this.boundary}${CRLF}`);
1896
+ this.reply.raw.write(Object.entries(headers).map(([key, value]) => `${key}: ${value}`).join(CRLF) + CRLF + CRLF);
1897
+ if (data) this.reply.raw.write(data);
1898
+ if (end) {
1899
+ this.reply.raw.write(`${CRLF}--${this.boundary}--${CRLF}`);
1900
+ this.reply.raw.end();
1901
+ }
1902
+ }
1903
+ /**
1904
+ * Sample
1905
+ *
1906
+ * ```
1907
+ * --boundary
1908
+ *
1909
+ * Content-Type: application/json
1910
+ *
1911
+ * {"done":10,"total":100}
1912
+ * ```
1913
+ */
1914
+ writeBundleState(done, total) {
1915
+ const previousProgress = this.done / this.total;
1916
+ const currentProgress = done / total;
1917
+ this.done = done;
1918
+ this.total = total;
1919
+ if (total < 10 || this.throttleTimer != null || previousProgress >= currentProgress) return;
1920
+ this.writeChunk(JSON.stringify({
1921
+ done,
1922
+ total
1923
+ }), { "Content-Type": "application/json" });
1924
+ this.throttleTimer = setTimeout(() => {
1925
+ this.throttleTimer = null;
1926
+ }, BundleResponse.THROTTLE_DELAY);
1927
+ }
1928
+ /**
1929
+ * Sample
1930
+ *
1931
+ * ```
1932
+ * --boundary
1933
+ *
1934
+ * X-Metro-Files-Changed-Count: 0
1935
+ * Content-Type: application/json
1936
+ * Content-Length: 100
1937
+ * Last-Modified: Thu, 10 Aug 2023 12:00:00 GMT
1938
+ *
1939
+ * <bundle result>
1940
+ * ```
1941
+ */
1942
+ endWithBundle(bundle) {
1943
+ this.writeChunk(JSON.stringify({
1944
+ done: this.total,
1945
+ total: this.total
1946
+ }), { "Content-Type": "application/json" });
1947
+ this.writeChunk(bundle, {
1948
+ "X-Metro-Files-Changed-Count": String(0),
1949
+ "Content-Type": "application/javascript; charset=UTF-8",
1950
+ "Content-Length": String(Buffer.byteLength(bundle)),
1951
+ "Last-Modified": (/* @__PURE__ */ new Date()).toUTCString()
1952
+ }, true);
1953
+ }
1954
+ endWithError(error) {
1955
+ const errorData = JSON.stringify({
1956
+ type: error?.name ?? "InternalError",
1957
+ message: error?.message ?? "internal error",
1958
+ errors: []
1959
+ });
1960
+ this.writeChunk(errorData, {
1961
+ "Content-Type": "application/json",
1962
+ "X-Http-Status": "500"
1963
+ }, true);
1964
+ }
1965
+ };
1966
+
1967
+ //#endregion
1968
+ //#region src/server/common/schema.ts
1969
+ const bundleRequestSchema = asConst({
1970
+ type: "object",
1971
+ properties: {
1972
+ platform: { type: "string" },
1973
+ app: { type: "string" },
1974
+ dev: { type: "boolean" },
1975
+ minify: { type: "boolean" },
1976
+ runModule: { type: "boolean" },
1977
+ inlineSourceMap: { type: "boolean" },
1978
+ modulesOnly: { type: "boolean" }
1979
+ },
1980
+ required: ["platform"]
1981
+ });
1982
+ const validateBundleRequest = new Ajv().compile(bundleRequestSchema);
1983
+
1984
+ //#endregion
1985
+ //#region src/server/middlewares/serve-bundle.ts
1986
+ const routeParamSchema = asConst({
1987
+ type: "object",
1988
+ properties: { name: { type: "string" } }
1989
+ });
1990
+ const plugin$1 = fp((fastify, options) => {
1991
+ const { getBundler } = options;
1992
+ fastify.get("/:name.bundle", {
1993
+ schema: {
1994
+ params: routeParamSchema,
1995
+ querystring: bundleRequestSchema
1996
+ },
1997
+ async handler(request, reply) {
1998
+ const { params, query: buildOptions, headers: { accept } } = request;
1999
+ if (!params.name) {
2000
+ await reply.status(400).send("invalid bundle name");
2001
+ return;
2002
+ }
2003
+ const bundler = getBundler(params.name, buildOptions);
2004
+ if (accept?.includes("multipart/mixed") ?? false) {
2005
+ const bundleResponse = new BundleResponse(reply);
2006
+ const transformHandler = (_id, totalModules = 0, transformedModules) => {
2007
+ bundleResponse.writeBundleState(transformedModules, totalModules);
2008
+ };
2009
+ bundler.on("transform", transformHandler);
2010
+ await bundler.getBundle().then((bundle) => bundleResponse.endWithBundle(bundle.code)).catch((error) => {
2011
+ bundleResponse.endWithError(error);
2012
+ throw error;
2013
+ }).finally(() => bundler.off("transform", transformHandler));
2014
+ } else {
2015
+ this.log.debug(`client is not support multipart/mixed content: ${accept ?? "<empty>"}`);
2016
+ const code = (await bundler.getBundle()).code;
2017
+ await reply.header("Content-Type", "application/javascript").header("Content-Length", Buffer.byteLength(code)).status(200).send(code);
2018
+ }
2019
+ }
2020
+ });
2021
+ fastify.get("/:name.map", {
2022
+ schema: {
2023
+ params: routeParamSchema,
2024
+ querystring: bundleRequestSchema
2025
+ },
2026
+ async handler(request, reply) {
2027
+ const { params, query: buildOptions } = request;
2028
+ if (!params.name) {
2029
+ await reply.status(400).send("invalid bundle name");
2030
+ return;
2031
+ }
2032
+ const sourceMap = (await getBundler(params.name, buildOptions).getBundle()).sourceMap;
2033
+ invariant(sourceMap, "Source map is not available");
2034
+ await reply.header("Access-Control-Allow-Origin", "devtools://devtools").header("Content-Type", "application/json").header("Content-Length", Buffer.byteLength(sourceMap)).status(200).send(sourceMap);
2035
+ }
2036
+ });
2037
+ }, { name: "serve-bundle" });
2038
+
2039
+ //#endregion
2040
+ //#region node_modules/picocolors/picocolors.js
2041
+ var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2042
+ let p = process || {}, argv = p.argv || [], env = p.env || {};
2043
+ let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
2044
+ let formatter = (open, close, replace = open) => (input) => {
2045
+ let string = "" + input, index = string.indexOf(close, open.length);
2046
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
2047
+ };
2048
+ let replaceClose = (string, close, replace, index) => {
2049
+ let result = "", cursor = 0;
2050
+ do {
2051
+ result += string.substring(cursor, index) + replace;
2052
+ cursor = index + close.length;
2053
+ index = string.indexOf(close, cursor);
2054
+ } while (~index);
2055
+ return result + string.substring(cursor);
2056
+ };
2057
+ let createColors = (enabled = isColorSupported) => {
2058
+ let f = enabled ? formatter : () => String;
2059
+ return {
2060
+ isColorSupported: enabled,
2061
+ reset: f("\x1B[0m", "\x1B[0m"),
2062
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
2063
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
2064
+ italic: f("\x1B[3m", "\x1B[23m"),
2065
+ underline: f("\x1B[4m", "\x1B[24m"),
2066
+ inverse: f("\x1B[7m", "\x1B[27m"),
2067
+ hidden: f("\x1B[8m", "\x1B[28m"),
2068
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
2069
+ black: f("\x1B[30m", "\x1B[39m"),
2070
+ red: f("\x1B[31m", "\x1B[39m"),
2071
+ green: f("\x1B[32m", "\x1B[39m"),
2072
+ yellow: f("\x1B[33m", "\x1B[39m"),
2073
+ blue: f("\x1B[34m", "\x1B[39m"),
2074
+ magenta: f("\x1B[35m", "\x1B[39m"),
2075
+ cyan: f("\x1B[36m", "\x1B[39m"),
2076
+ white: f("\x1B[37m", "\x1B[39m"),
2077
+ gray: f("\x1B[90m", "\x1B[39m"),
2078
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
2079
+ bgRed: f("\x1B[41m", "\x1B[49m"),
2080
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
2081
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
2082
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
2083
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
2084
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
2085
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
2086
+ blackBright: f("\x1B[90m", "\x1B[39m"),
2087
+ redBright: f("\x1B[91m", "\x1B[39m"),
2088
+ greenBright: f("\x1B[92m", "\x1B[39m"),
2089
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
2090
+ blueBright: f("\x1B[94m", "\x1B[39m"),
2091
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
2092
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
2093
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
2094
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
2095
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
2096
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
2097
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
2098
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
2099
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
2100
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
2101
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
2102
+ };
2103
+ };
2104
+ module.exports = createColors();
2105
+ module.exports.createColors = createColors;
2106
+ }));
2107
+
2108
+ //#endregion
2109
+ //#region node_modules/js-tokens/index.js
2110
+ var require_js_tokens = /* @__PURE__ */ __commonJSMin(((exports) => {
2111
+ Object.defineProperty(exports, "__esModule", { value: true });
2112
+ exports.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
2113
+ exports.matchToToken = function(match) {
2114
+ var token = {
2115
+ type: "invalid",
2116
+ value: match[0],
2117
+ closed: void 0
2118
+ };
2119
+ if (match[1]) token.type = "string", token.closed = !!(match[3] || match[4]);
2120
+ else if (match[5]) token.type = "comment";
2121
+ else if (match[6]) token.type = "comment", token.closed = !!match[7];
2122
+ else if (match[8]) token.type = "regex";
2123
+ else if (match[9]) token.type = "number";
2124
+ else if (match[10]) token.type = "name";
2125
+ else if (match[11]) token.type = "punctuator";
2126
+ else if (match[12]) token.type = "whitespace";
2127
+ return token;
2128
+ };
2129
+ }));
2130
+
2131
+ //#endregion
2132
+ //#region node_modules/@babel/helper-validator-identifier/lib/identifier.js
2133
+ var require_identifier = /* @__PURE__ */ __commonJSMin(((exports) => {
2134
+ Object.defineProperty(exports, "__esModule", { value: true });
2135
+ exports.isIdentifierChar = isIdentifierChar;
2136
+ exports.isIdentifierName = isIdentifierName;
2137
+ exports.isIdentifierStart = isIdentifierStart;
2138
+ let nonASCIIidentifierStartChars = "ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈא-תׯ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࡠ-ࡪࡰ-ࢇࢉ-࢏ࢠ-ࣉऄ-हऽॐक़-ॡॱ-ঀঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱৼਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡૹଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-హఽౘ-ౚ౜ౝౠౡಀಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽ೜-ೞೠೡೱೲഄ-ഌഎ-ഐഒ-ഺഽൎൔ-ൖൟ-ൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄຆ-ຊຌ-ຣລວ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜑᜟ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡸᢀ-ᢨᢪᢰ-ᣵᤀ-ᤞᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭌᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᲀ-ᲊᲐ-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳳᳵᳶᳺᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕ℘-ℝℤΩℨK-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞ々-〇〡-〩〱-〵〸-〼ぁ-ゖ゛-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆿㇰ-ㇿ㐀-䶿一-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚝꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-Ƛ꟱-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꣽꣾꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꧠ-ꧤꧦ-ꧯꧺ-ꧾꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꩾ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭩꭰ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ";
2139
+ let nonASCIIidentifierChars = "·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࢗ-࢟࣊-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍୕-ୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄ఼ా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ೳഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ඁ-ඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ຼ່-໎໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜕ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠏-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᪿ-᫝᫠-᫫ᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭᳴᳷-᳹᷀-᷿‌‍‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯・꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧ꠬ꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_・";
2140
+ const nonASCIIidentifierStart = /* @__PURE__ */ new RegExp("[" + nonASCIIidentifierStartChars + "]");
2141
+ const nonASCIIidentifier = /* @__PURE__ */ new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
2142
+ nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
2143
+ const astralIdentifierStartCodes = [
2144
+ 0,
2145
+ 11,
2146
+ 2,
2147
+ 25,
2148
+ 2,
2149
+ 18,
2150
+ 2,
2151
+ 1,
2152
+ 2,
2153
+ 14,
2154
+ 3,
2155
+ 13,
2156
+ 35,
2157
+ 122,
2158
+ 70,
2159
+ 52,
2160
+ 268,
2161
+ 28,
2162
+ 4,
2163
+ 48,
2164
+ 48,
2165
+ 31,
2166
+ 14,
2167
+ 29,
2168
+ 6,
2169
+ 37,
2170
+ 11,
2171
+ 29,
2172
+ 3,
2173
+ 35,
2174
+ 5,
2175
+ 7,
2176
+ 2,
2177
+ 4,
2178
+ 43,
2179
+ 157,
2180
+ 19,
2181
+ 35,
2182
+ 5,
2183
+ 35,
2184
+ 5,
2185
+ 39,
2186
+ 9,
2187
+ 51,
2188
+ 13,
2189
+ 10,
2190
+ 2,
2191
+ 14,
2192
+ 2,
2193
+ 6,
2194
+ 2,
2195
+ 1,
2196
+ 2,
2197
+ 10,
2198
+ 2,
2199
+ 14,
2200
+ 2,
2201
+ 6,
2202
+ 2,
2203
+ 1,
2204
+ 4,
2205
+ 51,
2206
+ 13,
2207
+ 310,
2208
+ 10,
2209
+ 21,
2210
+ 11,
2211
+ 7,
2212
+ 25,
2213
+ 5,
2214
+ 2,
2215
+ 41,
2216
+ 2,
2217
+ 8,
2218
+ 70,
2219
+ 5,
2220
+ 3,
2221
+ 0,
2222
+ 2,
2223
+ 43,
2224
+ 2,
2225
+ 1,
2226
+ 4,
2227
+ 0,
2228
+ 3,
2229
+ 22,
2230
+ 11,
2231
+ 22,
2232
+ 10,
2233
+ 30,
2234
+ 66,
2235
+ 18,
2236
+ 2,
2237
+ 1,
2238
+ 11,
2239
+ 21,
2240
+ 11,
2241
+ 25,
2242
+ 7,
2243
+ 25,
2244
+ 39,
2245
+ 55,
2246
+ 7,
2247
+ 1,
2248
+ 65,
2249
+ 0,
2250
+ 16,
2251
+ 3,
2252
+ 2,
2253
+ 2,
2254
+ 2,
2255
+ 28,
2256
+ 43,
2257
+ 28,
2258
+ 4,
2259
+ 28,
2260
+ 36,
2261
+ 7,
2262
+ 2,
2263
+ 27,
2264
+ 28,
2265
+ 53,
2266
+ 11,
2267
+ 21,
2268
+ 11,
2269
+ 18,
2270
+ 14,
2271
+ 17,
2272
+ 111,
2273
+ 72,
2274
+ 56,
2275
+ 50,
2276
+ 14,
2277
+ 50,
2278
+ 14,
2279
+ 35,
2280
+ 39,
2281
+ 27,
2282
+ 10,
2283
+ 22,
2284
+ 251,
2285
+ 41,
2286
+ 7,
2287
+ 1,
2288
+ 17,
2289
+ 5,
2290
+ 57,
2291
+ 28,
2292
+ 11,
2293
+ 0,
2294
+ 9,
2295
+ 21,
2296
+ 43,
2297
+ 17,
2298
+ 47,
2299
+ 20,
2300
+ 28,
2301
+ 22,
2302
+ 13,
2303
+ 52,
2304
+ 58,
2305
+ 1,
2306
+ 3,
2307
+ 0,
2308
+ 14,
2309
+ 44,
2310
+ 33,
2311
+ 24,
2312
+ 27,
2313
+ 35,
2314
+ 30,
2315
+ 0,
2316
+ 3,
2317
+ 0,
2318
+ 9,
2319
+ 34,
2320
+ 4,
2321
+ 0,
2322
+ 13,
2323
+ 47,
2324
+ 15,
2325
+ 3,
2326
+ 22,
2327
+ 0,
2328
+ 2,
2329
+ 0,
2330
+ 36,
2331
+ 17,
2332
+ 2,
2333
+ 24,
2334
+ 20,
2335
+ 1,
2336
+ 64,
2337
+ 6,
2338
+ 2,
2339
+ 0,
2340
+ 2,
2341
+ 3,
2342
+ 2,
2343
+ 14,
2344
+ 2,
2345
+ 9,
2346
+ 8,
2347
+ 46,
2348
+ 39,
2349
+ 7,
2350
+ 3,
2351
+ 1,
2352
+ 3,
2353
+ 21,
2354
+ 2,
2355
+ 6,
2356
+ 2,
2357
+ 1,
2358
+ 2,
2359
+ 4,
2360
+ 4,
2361
+ 0,
2362
+ 19,
2363
+ 0,
2364
+ 13,
2365
+ 4,
2366
+ 31,
2367
+ 9,
2368
+ 2,
2369
+ 0,
2370
+ 3,
2371
+ 0,
2372
+ 2,
2373
+ 37,
2374
+ 2,
2375
+ 0,
2376
+ 26,
2377
+ 0,
2378
+ 2,
2379
+ 0,
2380
+ 45,
2381
+ 52,
2382
+ 19,
2383
+ 3,
2384
+ 21,
2385
+ 2,
2386
+ 31,
2387
+ 47,
2388
+ 21,
2389
+ 1,
2390
+ 2,
2391
+ 0,
2392
+ 185,
2393
+ 46,
2394
+ 42,
2395
+ 3,
2396
+ 37,
2397
+ 47,
2398
+ 21,
2399
+ 0,
2400
+ 60,
2401
+ 42,
2402
+ 14,
2403
+ 0,
2404
+ 72,
2405
+ 26,
2406
+ 38,
2407
+ 6,
2408
+ 186,
2409
+ 43,
2410
+ 117,
2411
+ 63,
2412
+ 32,
2413
+ 7,
2414
+ 3,
2415
+ 0,
2416
+ 3,
2417
+ 7,
2418
+ 2,
2419
+ 1,
2420
+ 2,
2421
+ 23,
2422
+ 16,
2423
+ 0,
2424
+ 2,
2425
+ 0,
2426
+ 95,
2427
+ 7,
2428
+ 3,
2429
+ 38,
2430
+ 17,
2431
+ 0,
2432
+ 2,
2433
+ 0,
2434
+ 29,
2435
+ 0,
2436
+ 11,
2437
+ 39,
2438
+ 8,
2439
+ 0,
2440
+ 22,
2441
+ 0,
2442
+ 12,
2443
+ 45,
2444
+ 20,
2445
+ 0,
2446
+ 19,
2447
+ 72,
2448
+ 200,
2449
+ 32,
2450
+ 32,
2451
+ 8,
2452
+ 2,
2453
+ 36,
2454
+ 18,
2455
+ 0,
2456
+ 50,
2457
+ 29,
2458
+ 113,
2459
+ 6,
2460
+ 2,
2461
+ 1,
2462
+ 2,
2463
+ 37,
2464
+ 22,
2465
+ 0,
2466
+ 26,
2467
+ 5,
2468
+ 2,
2469
+ 1,
2470
+ 2,
2471
+ 31,
2472
+ 15,
2473
+ 0,
2474
+ 24,
2475
+ 43,
2476
+ 261,
2477
+ 18,
2478
+ 16,
2479
+ 0,
2480
+ 2,
2481
+ 12,
2482
+ 2,
2483
+ 33,
2484
+ 125,
2485
+ 0,
2486
+ 80,
2487
+ 921,
2488
+ 103,
2489
+ 110,
2490
+ 18,
2491
+ 195,
2492
+ 2637,
2493
+ 96,
2494
+ 16,
2495
+ 1071,
2496
+ 18,
2497
+ 5,
2498
+ 26,
2499
+ 3994,
2500
+ 6,
2501
+ 582,
2502
+ 6842,
2503
+ 29,
2504
+ 1763,
2505
+ 568,
2506
+ 8,
2507
+ 30,
2508
+ 18,
2509
+ 78,
2510
+ 18,
2511
+ 29,
2512
+ 19,
2513
+ 47,
2514
+ 17,
2515
+ 3,
2516
+ 32,
2517
+ 20,
2518
+ 6,
2519
+ 18,
2520
+ 433,
2521
+ 44,
2522
+ 212,
2523
+ 63,
2524
+ 33,
2525
+ 24,
2526
+ 3,
2527
+ 24,
2528
+ 45,
2529
+ 74,
2530
+ 6,
2531
+ 0,
2532
+ 67,
2533
+ 12,
2534
+ 65,
2535
+ 1,
2536
+ 2,
2537
+ 0,
2538
+ 15,
2539
+ 4,
2540
+ 10,
2541
+ 7381,
2542
+ 42,
2543
+ 31,
2544
+ 98,
2545
+ 114,
2546
+ 8702,
2547
+ 3,
2548
+ 2,
2549
+ 6,
2550
+ 2,
2551
+ 1,
2552
+ 2,
2553
+ 290,
2554
+ 16,
2555
+ 0,
2556
+ 30,
2557
+ 2,
2558
+ 3,
2559
+ 0,
2560
+ 15,
2561
+ 3,
2562
+ 9,
2563
+ 395,
2564
+ 2309,
2565
+ 106,
2566
+ 6,
2567
+ 12,
2568
+ 4,
2569
+ 8,
2570
+ 8,
2571
+ 9,
2572
+ 5991,
2573
+ 84,
2574
+ 2,
2575
+ 70,
2576
+ 2,
2577
+ 1,
2578
+ 3,
2579
+ 0,
2580
+ 3,
2581
+ 1,
2582
+ 3,
2583
+ 3,
2584
+ 2,
2585
+ 11,
2586
+ 2,
2587
+ 0,
2588
+ 2,
2589
+ 6,
2590
+ 2,
2591
+ 64,
2592
+ 2,
2593
+ 3,
2594
+ 3,
2595
+ 7,
2596
+ 2,
2597
+ 6,
2598
+ 2,
2599
+ 27,
2600
+ 2,
2601
+ 3,
2602
+ 2,
2603
+ 4,
2604
+ 2,
2605
+ 0,
2606
+ 4,
2607
+ 6,
2608
+ 2,
2609
+ 339,
2610
+ 3,
2611
+ 24,
2612
+ 2,
2613
+ 24,
2614
+ 2,
2615
+ 30,
2616
+ 2,
2617
+ 24,
2618
+ 2,
2619
+ 30,
2620
+ 2,
2621
+ 24,
2622
+ 2,
2623
+ 30,
2624
+ 2,
2625
+ 24,
2626
+ 2,
2627
+ 30,
2628
+ 2,
2629
+ 24,
2630
+ 2,
2631
+ 7,
2632
+ 1845,
2633
+ 30,
2634
+ 7,
2635
+ 5,
2636
+ 262,
2637
+ 61,
2638
+ 147,
2639
+ 44,
2640
+ 11,
2641
+ 6,
2642
+ 17,
2643
+ 0,
2644
+ 322,
2645
+ 29,
2646
+ 19,
2647
+ 43,
2648
+ 485,
2649
+ 27,
2650
+ 229,
2651
+ 29,
2652
+ 3,
2653
+ 0,
2654
+ 208,
2655
+ 30,
2656
+ 2,
2657
+ 2,
2658
+ 2,
2659
+ 1,
2660
+ 2,
2661
+ 6,
2662
+ 3,
2663
+ 4,
2664
+ 10,
2665
+ 1,
2666
+ 225,
2667
+ 6,
2668
+ 2,
2669
+ 3,
2670
+ 2,
2671
+ 1,
2672
+ 2,
2673
+ 14,
2674
+ 2,
2675
+ 196,
2676
+ 60,
2677
+ 67,
2678
+ 8,
2679
+ 0,
2680
+ 1205,
2681
+ 3,
2682
+ 2,
2683
+ 26,
2684
+ 2,
2685
+ 1,
2686
+ 2,
2687
+ 0,
2688
+ 3,
2689
+ 0,
2690
+ 2,
2691
+ 9,
2692
+ 2,
2693
+ 3,
2694
+ 2,
2695
+ 0,
2696
+ 2,
2697
+ 0,
2698
+ 7,
2699
+ 0,
2700
+ 5,
2701
+ 0,
2702
+ 2,
2703
+ 0,
2704
+ 2,
2705
+ 0,
2706
+ 2,
2707
+ 2,
2708
+ 2,
2709
+ 1,
2710
+ 2,
2711
+ 0,
2712
+ 3,
2713
+ 0,
2714
+ 2,
2715
+ 0,
2716
+ 2,
2717
+ 0,
2718
+ 2,
2719
+ 0,
2720
+ 2,
2721
+ 0,
2722
+ 2,
2723
+ 1,
2724
+ 2,
2725
+ 0,
2726
+ 3,
2727
+ 3,
2728
+ 2,
2729
+ 6,
2730
+ 2,
2731
+ 3,
2732
+ 2,
2733
+ 3,
2734
+ 2,
2735
+ 0,
2736
+ 2,
2737
+ 9,
2738
+ 2,
2739
+ 16,
2740
+ 6,
2741
+ 2,
2742
+ 2,
2743
+ 4,
2744
+ 2,
2745
+ 16,
2746
+ 4421,
2747
+ 42719,
2748
+ 33,
2749
+ 4381,
2750
+ 3,
2751
+ 5773,
2752
+ 3,
2753
+ 7472,
2754
+ 16,
2755
+ 621,
2756
+ 2467,
2757
+ 541,
2758
+ 1507,
2759
+ 4938,
2760
+ 6,
2761
+ 8489
2762
+ ];
2763
+ const astralIdentifierCodes = [
2764
+ 509,
2765
+ 0,
2766
+ 227,
2767
+ 0,
2768
+ 150,
2769
+ 4,
2770
+ 294,
2771
+ 9,
2772
+ 1368,
2773
+ 2,
2774
+ 2,
2775
+ 1,
2776
+ 6,
2777
+ 3,
2778
+ 41,
2779
+ 2,
2780
+ 5,
2781
+ 0,
2782
+ 166,
2783
+ 1,
2784
+ 574,
2785
+ 3,
2786
+ 9,
2787
+ 9,
2788
+ 7,
2789
+ 9,
2790
+ 32,
2791
+ 4,
2792
+ 318,
2793
+ 1,
2794
+ 78,
2795
+ 5,
2796
+ 71,
2797
+ 10,
2798
+ 50,
2799
+ 3,
2800
+ 123,
2801
+ 2,
2802
+ 54,
2803
+ 14,
2804
+ 32,
2805
+ 10,
2806
+ 3,
2807
+ 1,
2808
+ 11,
2809
+ 3,
2810
+ 46,
2811
+ 10,
2812
+ 8,
2813
+ 0,
2814
+ 46,
2815
+ 9,
2816
+ 7,
2817
+ 2,
2818
+ 37,
2819
+ 13,
2820
+ 2,
2821
+ 9,
2822
+ 6,
2823
+ 1,
2824
+ 45,
2825
+ 0,
2826
+ 13,
2827
+ 2,
2828
+ 49,
2829
+ 13,
2830
+ 9,
2831
+ 3,
2832
+ 2,
2833
+ 11,
2834
+ 83,
2835
+ 11,
2836
+ 7,
2837
+ 0,
2838
+ 3,
2839
+ 0,
2840
+ 158,
2841
+ 11,
2842
+ 6,
2843
+ 9,
2844
+ 7,
2845
+ 3,
2846
+ 56,
2847
+ 1,
2848
+ 2,
2849
+ 6,
2850
+ 3,
2851
+ 1,
2852
+ 3,
2853
+ 2,
2854
+ 10,
2855
+ 0,
2856
+ 11,
2857
+ 1,
2858
+ 3,
2859
+ 6,
2860
+ 4,
2861
+ 4,
2862
+ 68,
2863
+ 8,
2864
+ 2,
2865
+ 0,
2866
+ 3,
2867
+ 0,
2868
+ 2,
2869
+ 3,
2870
+ 2,
2871
+ 4,
2872
+ 2,
2873
+ 0,
2874
+ 15,
2875
+ 1,
2876
+ 83,
2877
+ 17,
2878
+ 10,
2879
+ 9,
2880
+ 5,
2881
+ 0,
2882
+ 82,
2883
+ 19,
2884
+ 13,
2885
+ 9,
2886
+ 214,
2887
+ 6,
2888
+ 3,
2889
+ 8,
2890
+ 28,
2891
+ 1,
2892
+ 83,
2893
+ 16,
2894
+ 16,
2895
+ 9,
2896
+ 82,
2897
+ 12,
2898
+ 9,
2899
+ 9,
2900
+ 7,
2901
+ 19,
2902
+ 58,
2903
+ 14,
2904
+ 5,
2905
+ 9,
2906
+ 243,
2907
+ 14,
2908
+ 166,
2909
+ 9,
2910
+ 71,
2911
+ 5,
2912
+ 2,
2913
+ 1,
2914
+ 3,
2915
+ 3,
2916
+ 2,
2917
+ 0,
2918
+ 2,
2919
+ 1,
2920
+ 13,
2921
+ 9,
2922
+ 120,
2923
+ 6,
2924
+ 3,
2925
+ 6,
2926
+ 4,
2927
+ 0,
2928
+ 29,
2929
+ 9,
2930
+ 41,
2931
+ 6,
2932
+ 2,
2933
+ 3,
2934
+ 9,
2935
+ 0,
2936
+ 10,
2937
+ 10,
2938
+ 47,
2939
+ 15,
2940
+ 199,
2941
+ 7,
2942
+ 137,
2943
+ 9,
2944
+ 54,
2945
+ 7,
2946
+ 2,
2947
+ 7,
2948
+ 17,
2949
+ 9,
2950
+ 57,
2951
+ 21,
2952
+ 2,
2953
+ 13,
2954
+ 123,
2955
+ 5,
2956
+ 4,
2957
+ 0,
2958
+ 2,
2959
+ 1,
2960
+ 2,
2961
+ 6,
2962
+ 2,
2963
+ 0,
2964
+ 9,
2965
+ 9,
2966
+ 49,
2967
+ 4,
2968
+ 2,
2969
+ 1,
2970
+ 2,
2971
+ 4,
2972
+ 9,
2973
+ 9,
2974
+ 55,
2975
+ 9,
2976
+ 266,
2977
+ 3,
2978
+ 10,
2979
+ 1,
2980
+ 2,
2981
+ 0,
2982
+ 49,
2983
+ 6,
2984
+ 4,
2985
+ 4,
2986
+ 14,
2987
+ 10,
2988
+ 5350,
2989
+ 0,
2990
+ 7,
2991
+ 14,
2992
+ 11465,
2993
+ 27,
2994
+ 2343,
2995
+ 9,
2996
+ 87,
2997
+ 9,
2998
+ 39,
2999
+ 4,
3000
+ 60,
3001
+ 6,
3002
+ 26,
3003
+ 9,
3004
+ 535,
3005
+ 9,
3006
+ 470,
3007
+ 0,
3008
+ 2,
3009
+ 54,
3010
+ 8,
3011
+ 3,
3012
+ 82,
3013
+ 0,
3014
+ 12,
3015
+ 1,
3016
+ 19628,
3017
+ 1,
3018
+ 4178,
3019
+ 9,
3020
+ 519,
3021
+ 45,
3022
+ 3,
3023
+ 22,
3024
+ 543,
3025
+ 4,
3026
+ 4,
3027
+ 5,
3028
+ 9,
3029
+ 7,
3030
+ 3,
3031
+ 6,
3032
+ 31,
3033
+ 3,
3034
+ 149,
3035
+ 2,
3036
+ 1418,
3037
+ 49,
3038
+ 513,
3039
+ 54,
3040
+ 5,
3041
+ 49,
3042
+ 9,
3043
+ 0,
3044
+ 15,
3045
+ 0,
3046
+ 23,
3047
+ 4,
3048
+ 2,
3049
+ 14,
3050
+ 1361,
3051
+ 6,
3052
+ 2,
3053
+ 16,
3054
+ 3,
3055
+ 6,
3056
+ 2,
3057
+ 1,
3058
+ 2,
3059
+ 4,
3060
+ 101,
3061
+ 0,
3062
+ 161,
3063
+ 6,
3064
+ 10,
3065
+ 9,
3066
+ 357,
3067
+ 0,
3068
+ 62,
3069
+ 13,
3070
+ 499,
3071
+ 13,
3072
+ 245,
3073
+ 1,
3074
+ 2,
3075
+ 9,
3076
+ 233,
3077
+ 0,
3078
+ 3,
3079
+ 0,
3080
+ 8,
3081
+ 1,
3082
+ 6,
3083
+ 0,
3084
+ 475,
3085
+ 6,
3086
+ 110,
3087
+ 6,
3088
+ 6,
3089
+ 9,
3090
+ 4759,
3091
+ 9,
3092
+ 787719,
3093
+ 239
3094
+ ];
3095
+ function isInAstralSet(code, set) {
3096
+ let pos = 65536;
3097
+ for (let i = 0, length = set.length; i < length; i += 2) {
3098
+ pos += set[i];
3099
+ if (pos > code) return false;
3100
+ pos += set[i + 1];
3101
+ if (pos >= code) return true;
3102
+ }
3103
+ return false;
3104
+ }
3105
+ function isIdentifierStart(code) {
3106
+ if (code < 65) return code === 36;
3107
+ if (code <= 90) return true;
3108
+ if (code < 97) return code === 95;
3109
+ if (code <= 122) return true;
3110
+ if (code <= 65535) return code >= 170 && nonASCIIidentifierStart.test(String.fromCharCode(code));
3111
+ return isInAstralSet(code, astralIdentifierStartCodes);
3112
+ }
3113
+ function isIdentifierChar(code) {
3114
+ if (code < 48) return code === 36;
3115
+ if (code < 58) return true;
3116
+ if (code < 65) return false;
3117
+ if (code <= 90) return true;
3118
+ if (code < 97) return code === 95;
3119
+ if (code <= 122) return true;
3120
+ if (code <= 65535) return code >= 170 && nonASCIIidentifier.test(String.fromCharCode(code));
3121
+ return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
3122
+ }
3123
+ function isIdentifierName(name) {
3124
+ let isFirst = true;
3125
+ for (let i = 0; i < name.length; i++) {
3126
+ let cp = name.charCodeAt(i);
3127
+ if ((cp & 64512) === 55296 && i + 1 < name.length) {
3128
+ const trail = name.charCodeAt(++i);
3129
+ if ((trail & 64512) === 56320) cp = 65536 + ((cp & 1023) << 10) + (trail & 1023);
3130
+ }
3131
+ if (isFirst) {
3132
+ isFirst = false;
3133
+ if (!isIdentifierStart(cp)) return false;
3134
+ } else if (!isIdentifierChar(cp)) return false;
3135
+ }
3136
+ return !isFirst;
3137
+ }
3138
+ }));
3139
+
3140
+ //#endregion
3141
+ //#region node_modules/@babel/helper-validator-identifier/lib/keyword.js
3142
+ var require_keyword = /* @__PURE__ */ __commonJSMin(((exports) => {
3143
+ Object.defineProperty(exports, "__esModule", { value: true });
3144
+ exports.isKeyword = isKeyword;
3145
+ exports.isReservedWord = isReservedWord;
3146
+ exports.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
3147
+ exports.isStrictBindReservedWord = isStrictBindReservedWord;
3148
+ exports.isStrictReservedWord = isStrictReservedWord;
3149
+ const reservedWords = {
3150
+ keyword: [
3151
+ "break",
3152
+ "case",
3153
+ "catch",
3154
+ "continue",
3155
+ "debugger",
3156
+ "default",
3157
+ "do",
3158
+ "else",
3159
+ "finally",
3160
+ "for",
3161
+ "function",
3162
+ "if",
3163
+ "return",
3164
+ "switch",
3165
+ "throw",
3166
+ "try",
3167
+ "var",
3168
+ "const",
3169
+ "while",
3170
+ "with",
3171
+ "new",
3172
+ "this",
3173
+ "super",
3174
+ "class",
3175
+ "extends",
3176
+ "export",
3177
+ "import",
3178
+ "null",
3179
+ "true",
3180
+ "false",
3181
+ "in",
3182
+ "instanceof",
3183
+ "typeof",
3184
+ "void",
3185
+ "delete"
3186
+ ],
3187
+ strict: [
3188
+ "implements",
3189
+ "interface",
3190
+ "let",
3191
+ "package",
3192
+ "private",
3193
+ "protected",
3194
+ "public",
3195
+ "static",
3196
+ "yield"
3197
+ ],
3198
+ strictBind: ["eval", "arguments"]
3199
+ };
3200
+ const keywords = new Set(reservedWords.keyword);
3201
+ const reservedWordsStrictSet = new Set(reservedWords.strict);
3202
+ const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
3203
+ function isReservedWord(word, inModule) {
3204
+ return inModule && word === "await" || word === "enum";
3205
+ }
3206
+ function isStrictReservedWord(word, inModule) {
3207
+ return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
3208
+ }
3209
+ function isStrictBindOnlyReservedWord(word) {
3210
+ return reservedWordsStrictBindSet.has(word);
3211
+ }
3212
+ function isStrictBindReservedWord(word, inModule) {
3213
+ return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
3214
+ }
3215
+ function isKeyword(word) {
3216
+ return keywords.has(word);
3217
+ }
3218
+ }));
3219
+
3220
+ //#endregion
3221
+ //#region node_modules/@babel/helper-validator-identifier/lib/index.js
3222
+ var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
3223
+ Object.defineProperty(exports, "__esModule", { value: true });
3224
+ Object.defineProperty(exports, "isIdentifierChar", {
3225
+ enumerable: true,
3226
+ get: function() {
3227
+ return _identifier.isIdentifierChar;
3228
+ }
3229
+ });
3230
+ Object.defineProperty(exports, "isIdentifierName", {
3231
+ enumerable: true,
3232
+ get: function() {
3233
+ return _identifier.isIdentifierName;
3234
+ }
3235
+ });
3236
+ Object.defineProperty(exports, "isIdentifierStart", {
3237
+ enumerable: true,
3238
+ get: function() {
3239
+ return _identifier.isIdentifierStart;
3240
+ }
3241
+ });
3242
+ Object.defineProperty(exports, "isKeyword", {
3243
+ enumerable: true,
3244
+ get: function() {
3245
+ return _keyword.isKeyword;
3246
+ }
3247
+ });
3248
+ Object.defineProperty(exports, "isReservedWord", {
3249
+ enumerable: true,
3250
+ get: function() {
3251
+ return _keyword.isReservedWord;
3252
+ }
3253
+ });
3254
+ Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
3255
+ enumerable: true,
3256
+ get: function() {
3257
+ return _keyword.isStrictBindOnlyReservedWord;
3258
+ }
3259
+ });
3260
+ Object.defineProperty(exports, "isStrictBindReservedWord", {
3261
+ enumerable: true,
3262
+ get: function() {
3263
+ return _keyword.isStrictBindReservedWord;
3264
+ }
3265
+ });
3266
+ Object.defineProperty(exports, "isStrictReservedWord", {
3267
+ enumerable: true,
3268
+ get: function() {
3269
+ return _keyword.isStrictReservedWord;
3270
+ }
3271
+ });
3272
+ var _identifier = require_identifier();
3273
+ var _keyword = require_keyword();
3274
+ }));
3275
+
3276
+ //#endregion
3277
+ //#region node_modules/@babel/code-frame/lib/index.js
3278
+ var require_lib = /* @__PURE__ */ __commonJSMin(((exports) => {
3279
+ Object.defineProperty(exports, "__esModule", { value: true });
3280
+ var picocolors = require_picocolors();
3281
+ var jsTokens = require_js_tokens();
3282
+ var helperValidatorIdentifier = require_lib$1();
3283
+ function isColorSupported() {
3284
+ return typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? false : picocolors.isColorSupported;
3285
+ }
3286
+ const compose = (f, g) => (v) => f(g(v));
3287
+ function buildDefs(colors) {
3288
+ return {
3289
+ keyword: colors.cyan,
3290
+ capitalized: colors.yellow,
3291
+ jsxIdentifier: colors.yellow,
3292
+ punctuator: colors.yellow,
3293
+ number: colors.magenta,
3294
+ string: colors.green,
3295
+ regex: colors.magenta,
3296
+ comment: colors.gray,
3297
+ invalid: compose(compose(colors.white, colors.bgRed), colors.bold),
3298
+ gutter: colors.gray,
3299
+ marker: compose(colors.red, colors.bold),
3300
+ message: compose(colors.red, colors.bold),
3301
+ reset: colors.reset
3302
+ };
3303
+ }
3304
+ const defsOn = buildDefs(picocolors.createColors(true));
3305
+ const defsOff = buildDefs(picocolors.createColors(false));
3306
+ function getDefs(enabled) {
3307
+ return enabled ? defsOn : defsOff;
3308
+ }
3309
+ const sometimesKeywords = new Set([
3310
+ "as",
3311
+ "async",
3312
+ "from",
3313
+ "get",
3314
+ "of",
3315
+ "set"
3316
+ ]);
3317
+ const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/;
3318
+ const BRACKET = /^[()[\]{}]$/;
3319
+ let tokenize;
3320
+ {
3321
+ const JSX_TAG = /^[a-z][\w-]*$/i;
3322
+ const getTokenType = function(token, offset, text) {
3323
+ if (token.type === "name") {
3324
+ if (helperValidatorIdentifier.isKeyword(token.value) || helperValidatorIdentifier.isStrictReservedWord(token.value, true) || sometimesKeywords.has(token.value)) return "keyword";
3325
+ if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) return "jsxIdentifier";
3326
+ if (token.value[0] !== token.value[0].toLowerCase()) return "capitalized";
3327
+ }
3328
+ if (token.type === "punctuator" && BRACKET.test(token.value)) return "bracket";
3329
+ if (token.type === "invalid" && (token.value === "@" || token.value === "#")) return "punctuator";
3330
+ return token.type;
3331
+ };
3332
+ tokenize = function* (text) {
3333
+ let match;
3334
+ while (match = jsTokens.default.exec(text)) {
3335
+ const token = jsTokens.matchToToken(match);
3336
+ yield {
3337
+ type: getTokenType(token, match.index, text),
3338
+ value: token.value
3339
+ };
3340
+ }
3341
+ };
3342
+ }
3343
+ function highlight(text) {
3344
+ if (text === "") return "";
3345
+ const defs = getDefs(true);
3346
+ let highlighted = "";
3347
+ for (const { type, value } of tokenize(text)) if (type in defs) highlighted += value.split(NEWLINE$1).map((str) => defs[type](str)).join("\n");
3348
+ else highlighted += value;
3349
+ return highlighted;
3350
+ }
3351
+ const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
3352
+ function getMarkerLines(loc, source, opts) {
3353
+ const startLoc = Object.assign({
3354
+ column: 0,
3355
+ line: -1
3356
+ }, loc.start);
3357
+ const endLoc = Object.assign({}, startLoc, loc.end);
3358
+ const { linesAbove = 2, linesBelow = 3 } = opts || {};
3359
+ const startLine = startLoc.line;
3360
+ const startColumn = startLoc.column;
3361
+ const endLine = endLoc.line;
3362
+ const endColumn = endLoc.column;
3363
+ let start = Math.max(startLine - (linesAbove + 1), 0);
3364
+ let end = Math.min(source.length, endLine + linesBelow);
3365
+ if (startLine === -1) start = 0;
3366
+ if (endLine === -1) end = source.length;
3367
+ const lineDiff = endLine - startLine;
3368
+ const markerLines = {};
3369
+ if (lineDiff) for (let i = 0; i <= lineDiff; i++) {
3370
+ const lineNumber = i + startLine;
3371
+ if (!startColumn) markerLines[lineNumber] = true;
3372
+ else if (i === 0) markerLines[lineNumber] = [startColumn, source[lineNumber - 1].length - startColumn + 1];
3373
+ else if (i === lineDiff) markerLines[lineNumber] = [0, endColumn];
3374
+ else markerLines[lineNumber] = [0, source[lineNumber - i].length];
3375
+ }
3376
+ else if (startColumn === endColumn) if (startColumn) markerLines[startLine] = [startColumn, 0];
3377
+ else markerLines[startLine] = true;
3378
+ else markerLines[startLine] = [startColumn, endColumn - startColumn];
3379
+ return {
3380
+ start,
3381
+ end,
3382
+ markerLines
3383
+ };
3384
+ }
3385
+ function codeFrameColumns(rawLines, loc, opts = {}) {
3386
+ const shouldHighlight = opts.forceColor || isColorSupported() && opts.highlightCode;
3387
+ const defs = getDefs(shouldHighlight);
3388
+ const { start, end, markerLines } = getMarkerLines(loc, rawLines.split(NEWLINE), opts);
3389
+ const hasColumns = loc.start && typeof loc.start.column === "number";
3390
+ const numberMaxWidth = String(end).length;
3391
+ let frame = (shouldHighlight ? highlight(rawLines) : rawLines).split(NEWLINE, end).slice(start, end).map((line, index) => {
3392
+ const number = start + 1 + index;
3393
+ const gutter = ` ${` ${number}`.slice(-numberMaxWidth)} |`;
3394
+ const hasMarker = markerLines[number];
3395
+ const lastMarkerLine = !markerLines[number + 1];
3396
+ if (hasMarker) {
3397
+ let markerLine = "";
3398
+ if (Array.isArray(hasMarker)) {
3399
+ const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
3400
+ const numberOfMarkers = hasMarker[1] || 1;
3401
+ markerLine = [
3402
+ "\n ",
3403
+ defs.gutter(gutter.replace(/\d/g, " ")),
3404
+ " ",
3405
+ markerSpacing,
3406
+ defs.marker("^").repeat(numberOfMarkers)
3407
+ ].join("");
3408
+ if (lastMarkerLine && opts.message) markerLine += " " + defs.message(opts.message);
3409
+ }
3410
+ return [
3411
+ defs.marker(">"),
3412
+ defs.gutter(gutter),
3413
+ line.length > 0 ? ` ${line}` : "",
3414
+ markerLine
3415
+ ].join("");
3416
+ } else return ` ${defs.gutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
3417
+ }).join("\n");
3418
+ if (opts.message && !hasColumns) frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
3419
+ if (shouldHighlight) return defs.reset(frame);
3420
+ else return frame;
3421
+ }
3422
+ exports.codeFrameColumns = codeFrameColumns;
3423
+ }));
3424
+
3425
+ //#endregion
3426
+ //#region src/server/symbolicate.ts
3427
+ var import_lib = require_lib();
3428
+ /**
3429
+ * @see https://github.com/facebook/react-native/blob/0.83-stable/packages/metro-config/src/index.flow.js#L17
3430
+ */
3431
+ const INTERNAL_CALLSITES_REGEX = new RegExp([
3432
+ "/Libraries/BatchedBridge/MessageQueue\\.js$",
3433
+ "/Libraries/Core/.+\\.js$",
3434
+ "/Libraries/LogBox/.+\\.js$",
3435
+ "/Libraries/Network/.+\\.js$",
3436
+ "/Libraries/Pressability/.+\\.js$",
3437
+ "/Libraries/Renderer/implementations/.+\\.js$",
3438
+ "/Libraries/Utilities/.+\\.js$",
3439
+ "/Libraries/vendor/.+\\.js$",
3440
+ "/Libraries/WebSocket/.+\\.js$",
3441
+ "/src/private/renderer/errorhandling/.+\\.js$",
3442
+ "/metro-runtime/.+\\.js$",
3443
+ "/node_modules/@babel/runtime/.+\\.js$",
3444
+ "/node_modules/@react-native/js-polyfills/.+\\.js$",
3445
+ "/node_modules/invariant/.+\\.js$",
3446
+ "/node_modules/react-devtools-core/.+\\.js$",
3447
+ "/node_modules/react-native/index.js$",
3448
+ "/node_modules/react-refresh/.+\\.js$",
3449
+ "/node_modules/scheduler/.+\\.js$",
3450
+ "^\\[native code\\]$"
3451
+ ].map((pathPattern) => pathPattern.replaceAll("/", "[/\\\\]")).join("|"));
3452
+ async function symbolicate(bundle, stack) {
3453
+ const sourceMapConsumer = await bundle.sourceMapConsumer;
3454
+ const symbolicatedStack = stack.filter((frame) => frame.file?.startsWith("http")).map((frame) => originalPositionFor(sourceMapConsumer, frame)).map((frame) => collapseFrame(frame));
3455
+ return {
3456
+ stack: symbolicatedStack,
3457
+ codeFrame: getCodeFrame(sourceMapConsumer, symbolicatedStack, bundle)
3458
+ };
3459
+ }
3460
+ function originalPositionFor(sourceMapConsumer, frame) {
3461
+ if (frame.column == null || frame.lineNumber == null) return frame;
3462
+ const originalPosition = sourceMapConsumer.originalPositionFor({
3463
+ column: frame.column,
3464
+ line: frame.lineNumber
3465
+ });
3466
+ return Object.entries(originalPosition).reduce((frame$1, [key, value]) => {
3467
+ const targetKey = convertFrameKey(key);
3468
+ return {
3469
+ ...frame$1,
3470
+ ...value ? { [targetKey]: value } : null
3471
+ };
3472
+ }, frame);
3473
+ }
3474
+ function collapseFrame(frame) {
3475
+ return {
3476
+ ...frame,
3477
+ collapse: Boolean(frame.file && INTERNAL_CALLSITES_REGEX.test(frame.file))
3478
+ };
3479
+ }
3480
+ function isCollapsed(frame) {
3481
+ return "collapse" in frame && frame.collapse;
3482
+ }
3483
+ function convertFrameKey(key) {
3484
+ if (key === "line") return "lineNumber";
3485
+ else if (key === "source") return "file";
3486
+ else if (key === "name") return "methodName";
3487
+ return key;
3488
+ }
3489
+ function getCodeFrame(sourceMapConsumer, frames, bundle) {
3490
+ const frame = frames.find((frame$1) => {
3491
+ return frame$1.lineNumber != null && frame$1.column != null && !isCollapsed(frame$1);
3492
+ });
3493
+ if (frame?.file == null || frame.column == null || frame.lineNumber == null) return null;
3494
+ try {
3495
+ const { lineNumber, column, file } = frame;
3496
+ const unresolved = file.startsWith("http");
3497
+ const source = unresolved ? bundle.code : sourceMapConsumer.sourceContentFor(frame.file);
3498
+ const fileName = unresolved ? url.parse(file).pathname ?? "unknown" : file;
3499
+ let content = "";
3500
+ if (source) content = (0, import_lib.codeFrameColumns)(source, { start: {
3501
+ column,
3502
+ line: lineNumber
3503
+ } }, { highlightCode: true });
3504
+ return {
3505
+ content,
3506
+ fileName,
3507
+ location: {
3508
+ column,
3509
+ row: lineNumber
3510
+ }
3511
+ };
3512
+ } catch {
3513
+ return null;
3514
+ }
3515
+ }
3516
+
3517
+ //#endregion
3518
+ //#region src/server/middlewares/symbolicate.ts
3519
+ const bodySchema = asConst({
3520
+ type: "object",
3521
+ properties: {
3522
+ stack: {
3523
+ type: "array",
3524
+ items: {}
3525
+ },
3526
+ extraData: {}
3527
+ },
3528
+ required: ["stack"]
3529
+ });
3530
+ const plugin = fp((fastify, options) => {
3531
+ const { getBundler } = options;
3532
+ fastify.post("/symbolicate", {
3533
+ schema: { body: bodySchema },
3534
+ async handler(request, reply) {
3535
+ const { stack } = request.body;
3536
+ const bundleUrl = stack.find((frame) => frame.file?.startsWith("http"));
3537
+ invariant(bundleUrl?.file, "No bundle URL found in stack frames");
3538
+ const { pathname, query } = url.parse(bundleUrl.file, true);
3539
+ invariant(pathname, "No pathname found in bundle URL");
3540
+ invariant(query.platform, "No platform found in query");
3541
+ invariant(query.dev, "No dev found in query");
3542
+ const bundle = await getBundler(getBaseBundleName(pathname), {
3543
+ platform: query.platform,
3544
+ dev: query.dev === "true"
3545
+ }).getBundle();
3546
+ await reply.header("Content-Type", "application/json").send(await symbolicate(bundle, stack));
3547
+ }
3548
+ });
3549
+ }, { name: "symbolicate" });
3550
+
3551
+ //#endregion
3552
+ //#region src/server/wss/server.ts
3553
+ var WebSocketServer = class extends EventEmitter {
3554
+ clientId = 0;
3555
+ wss;
3556
+ logger;
3557
+ constructor(name, options) {
3558
+ super();
3559
+ const logger$2 = logger.child(name);
3560
+ const wss = new ws.WebSocketServer(options);
3561
+ wss.on("connection", (socket) => {
3562
+ const client = Object.defineProperty(socket, "id", {
3563
+ value: this.clientId++,
3564
+ writable: false
3565
+ });
3566
+ this.onConnection(client);
3567
+ this.emit("connection", client);
3568
+ client.on("message", (data) => {
3569
+ this.onMessage(client, data);
3570
+ this.emit("message", client, data);
3571
+ });
3572
+ client.on("error", (error) => {
3573
+ this.onError(client, error);
3574
+ this.emit("error", client, error);
3575
+ });
3576
+ client.on("close", () => {
3577
+ this.onClose(client);
3578
+ this.emit("close", client);
3579
+ });
3580
+ });
3581
+ this.wss = wss;
3582
+ this.logger = logger$2;
3583
+ }
3584
+ get server() {
3585
+ return this.wss;
3586
+ }
3587
+ send(client, data) {
3588
+ if (client.readyState === ws.WebSocket.OPEN) client.send(data);
3589
+ }
3590
+ sendAll(data) {
3591
+ this.wss.clients.forEach((client) => {
3592
+ if (client.readyState === ws.WebSocket.OPEN) client.send(data);
3593
+ });
3594
+ }
3595
+ rawDataToString(data) {
3596
+ if (Buffer.isBuffer(data)) return data.toString("utf8");
3597
+ if (Array.isArray(data)) return Buffer.concat(data).toString("utf8");
3598
+ return Buffer.from(data).toString("utf8");
3599
+ }
3600
+ };
3601
+ function getWebSocketUpgradeHandler(websocketEndpoints) {
3602
+ return (request, socket, head) => {
3603
+ if (request.url == null) {
3604
+ socket.destroy();
3605
+ return;
3606
+ }
3607
+ const { pathname } = url.parse(request.url, true);
3608
+ if (pathname != null && websocketEndpoints[pathname]) {
3609
+ const wss = websocketEndpoints[pathname];
3610
+ wss.handleUpgrade(request, socket, head, (socket$1) => {
3611
+ wss.emit("connection", socket$1, request);
3612
+ });
3613
+ } else socket.destroy();
3614
+ };
3615
+ }
3616
+
3617
+ //#endregion
3618
+ //#region src/server/wss/hmr-server.ts
3619
+ var HMRServer = class extends WebSocketServer {
3620
+ bundlerPool;
3621
+ reportEvent;
3622
+ instances = /* @__PURE__ */ new Map();
3623
+ bindings = /* @__PURE__ */ new Map();
3624
+ constructor({ bundlerPool, reportEvent }) {
3625
+ super("hmr", { noServer: true });
3626
+ this.bundlerPool = bundlerPool;
3627
+ this.reportEvent = reportEvent;
3628
+ }
3629
+ parseClientMessage(data) {
3630
+ const parsedData = JSON.parse(this.rawDataToString(data));
3631
+ const clientMessage = "type" in parsedData ? parsedData : null;
3632
+ invariant(clientMessage, "Invalid HMR client message");
3633
+ return clientMessage;
3634
+ }
3635
+ async handleConnected(client, platform, bundleEntry) {
3636
+ try {
3637
+ this.logger.trace(`HMR client connected (clientId: ${client.id})`, {
3638
+ platform,
3639
+ bundleEntry
3640
+ });
3641
+ const devEngineInstance = this.bundlerPool.get(bundleEntry, {
3642
+ platform,
3643
+ dev: true
3644
+ });
3645
+ this.bindEvents(client, devEngineInstance);
3646
+ this.instances.set(client.id, devEngineInstance);
3647
+ this.logger.trace(`Bundler instance prepared (bundlerId: ${devEngineInstance.id})`);
3648
+ } catch (error) {
3649
+ this.logger.error(`Failed to prepare bundler instance`, error);
3650
+ }
3651
+ }
3652
+ bindEvents(client, instance) {
3653
+ if (this.bindings.get(client.id) == null) {
3654
+ const handleHmrUpdates = (updates) => {
3655
+ this.handleUpdates(client, updates);
3656
+ };
3657
+ const handleWatchChange = () => {
3658
+ this.send(client, JSON.stringify({ type: "hmr:update-start" }));
3659
+ };
3660
+ instance.addListener("hmrUpdates", handleHmrUpdates);
3661
+ instance.addListener("watchChange", handleWatchChange);
3662
+ this.bindings.set(client.id, {
3663
+ hmrUpdates: handleHmrUpdates,
3664
+ watchChange: handleWatchChange
3665
+ });
3666
+ this.logger.trace(`HMR event binding established (clientId: ${client.id})`);
3667
+ }
3668
+ }
3669
+ async handleModuleRegistered(client, modules) {
3670
+ try {
3671
+ const instance = this.instances.get(client.id);
3672
+ invariant(instance != null, `Bundler instance not found for client clientId: ${client.id}`);
3673
+ await instance.ensureInitialized;
3674
+ await instance.devEngine.registerModules(client.id.toString(), modules);
3675
+ } catch (error) {
3676
+ this.logger.error(`Failed to handle module registered`, error);
3677
+ }
3678
+ }
3679
+ async handleInvalidate(client, moduleId) {
3680
+ try {
3681
+ const instance = this.instances.get(client.id);
3682
+ invariant(instance != null, `Bundler instance not found for client clientId: ${client.id}`);
3683
+ await instance.ensureInitialized;
3684
+ const updates = await instance.devEngine.invalidate(moduleId);
3685
+ await this.handleUpdates(client, updates);
3686
+ } catch (error) {
3687
+ this.logger.error(`Failed to handle invalidate`, error);
3688
+ }
3689
+ }
3690
+ async handleUpdates(client, updates) {
3691
+ this.logger.trace(`HMR updates found (clientId: ${client.id})`, { updatesCount: updates.length });
3692
+ for (const clientUpdate of updates) {
3693
+ const update = clientUpdate.update;
3694
+ switch (update.type) {
3695
+ case "Patch":
3696
+ this.sendUpdateToClient(client, update);
3697
+ break;
3698
+ case "FullReload":
3699
+ this.sendReloadToClient(client);
3700
+ break;
3701
+ case "Noop":
3702
+ this.logger.warn(`Client ${clientUpdate.clientId} received noop update`);
3703
+ break;
3704
+ }
3705
+ }
3706
+ }
3707
+ sendUpdateToClient(client, update) {
3708
+ invariant(update.type === "Patch", "Invalid HMR update type");
3709
+ const updateMessage = {
3710
+ type: "hmr:update",
3711
+ code: update.code
3712
+ };
3713
+ this.send(client, JSON.stringify(updateMessage));
3714
+ this.send(client, JSON.stringify({ type: "hmr:update-done" }));
3715
+ this.done(client);
3716
+ }
3717
+ sendReloadToClient(client) {
3718
+ this.logger.trace(`Sending HMR reload message to client (clientId: ${client.id})`);
3719
+ this.send(client, JSON.stringify({ type: "hmr:reload" }));
3720
+ this.done(client);
3721
+ }
3722
+ done(client) {
3723
+ this.send(client, JSON.stringify({ type: "hmr:update-done" }));
3724
+ }
3725
+ sendError(client, error) {
3726
+ try {
3727
+ this.send(client, JSON.stringify(error));
3728
+ } catch (error$1) {
3729
+ this.logger.error(`Failed to send HMR error message to client (clientId: ${client.id})`, error$1);
3730
+ }
3731
+ }
3732
+ cleanup(client) {
3733
+ this.logger.trace(`HMR client cleanup (clientId: ${client.id})`);
3734
+ const binding = this.bindings.get(client.id);
3735
+ const instance = this.instances.get(client.id);
3736
+ if (binding != null && instance != null) {
3737
+ instance.removeListener("hmrUpdates", binding.hmrUpdates);
3738
+ instance.removeListener("watchChange", binding.watchChange);
3739
+ }
3740
+ if (instance != null) instance.devEngine.removeClient(String(client.id));
3741
+ this.bindings.delete(client.id);
3742
+ this.instances.delete(client.id);
3743
+ }
3744
+ onMessage(client, data) {
3745
+ let message;
3746
+ try {
3747
+ message = this.parseClientMessage(data);
3748
+ this.logger.trace("HMR client message received", message);
3749
+ } catch (error) {
3750
+ const message$1 = "Failed to parse HMR client message";
3751
+ this.logger.error(message$1, error);
3752
+ this.sendError(client, {
3753
+ type: "InternalError",
3754
+ errors: [{ description: error instanceof Error ? error.message : String(error) }],
3755
+ message: message$1
3756
+ });
3757
+ return;
3758
+ }
3759
+ switch (message.type) {
3760
+ case "hmr:connected":
3761
+ this.handleConnected(client, message.platform, message.bundleEntry);
3762
+ break;
3763
+ case "hmr:module-registered":
3764
+ this.handleModuleRegistered(client, message.modules);
3765
+ break;
3766
+ case "hmr:invalidate":
3767
+ this.handleInvalidate(client, message.moduleId);
3768
+ break;
3769
+ case "hmr:log":
3770
+ this.reportEvent({
3771
+ type: "client_log",
3772
+ level: message.level,
3773
+ data: message.data
3774
+ });
3775
+ break;
3776
+ }
3777
+ }
3778
+ onConnection(client) {
3779
+ this.logger.trace(`connection established (clientId: ${client.id})`);
3780
+ }
3781
+ onError(client, error) {
3782
+ this.logger.error(`connection error (clientId: ${client.id})`, error);
3783
+ this.cleanup(client);
3784
+ }
3785
+ onClose(client) {
3786
+ this.logger.trace(`connection closed (clientId: ${client.id})`);
3787
+ this.cleanup(client);
3788
+ }
3789
+ };
3790
+
3791
+ //#endregion
3792
+ //#region src/server/create-dev-server.ts
3793
+ async function createDevServer(config, options) {
3794
+ const projectRoot = config.root;
3795
+ const { port = DEFAULT_PORT, host = DEFAULT_HOST, https = false, onDeviceConnected, onDeviceMessage, onDeviceConnectionError, onDeviceDisconnected } = options ?? {};
3796
+ if (https) throw new Error("HTTPS is not supported yet");
3797
+ const serverBaseUrl = url.format({
3798
+ protocol: https ? "https" : "http",
3799
+ hostname: host,
3800
+ port
3801
+ });
3802
+ await assertDevServerStatus({
3803
+ devServerUrl: serverBaseUrl,
3804
+ projectRoot,
3805
+ port
3806
+ });
3807
+ const fastify = Fastify({
3808
+ loggerInstance: new DevServerLogger(),
3809
+ disableRequestLogging: true
3810
+ });
3811
+ const bundlerPool = new BundlerPool(config, {
3812
+ host,
3813
+ port
3814
+ });
3815
+ const getBundler = (bundleName, buildOptions) => {
3816
+ return bundlerPool.get(bundleName, buildOptions);
3817
+ };
3818
+ const { middleware: communityMiddleware, websocketEndpoints: communityWebsocketEndpoints, messageSocketEndpoint: { server: messageServer, broadcast }, eventsSocketEndpoint: { server: eventsServer, reportEvent } } = createDevServerMiddleware({
3819
+ port,
3820
+ host,
3821
+ watchFolders: []
3822
+ });
3823
+ const { middleware: devMiddleware, websocketEndpoints } = createDevMiddleware({
3824
+ serverBaseUrl,
3825
+ logger: {
3826
+ info(...args) {
3827
+ if (args[0].includes("JavaScript logs have moved")) return;
3828
+ logger.info(...args);
3829
+ },
3830
+ warn: logger.warn.bind(logger),
3831
+ error: logger.error.bind(logger)
3832
+ },
3833
+ unstable_experiments: {
3834
+ enableNetworkInspector: true,
3835
+ enableStandaloneFuseboxShell: true
3836
+ }
3837
+ });
3838
+ const hmrServer = new HMRServer({
3839
+ bundlerPool,
3840
+ reportEvent: (event) => {
3841
+ reportEvent?.(event);
3842
+ config.reporter.update(event);
3843
+ }
3844
+ }).on("connection", (client) => onDeviceConnected?.(client)).on("message", (client, data) => onDeviceMessage?.(client, data)).on("error", (client, error) => onDeviceConnectionError?.(client, error)).on("close", (client) => onDeviceDisconnected?.(client));
3845
+ await fastify.register(import("@fastify/middie"));
3846
+ const devServer = {
3847
+ config,
3848
+ instance: fastify,
3849
+ middlewares: { use: fastify.use.bind(fastify) },
3850
+ message: Object.assign(messageServer, { broadcast }),
3851
+ events: Object.assign(eventsServer, { reportEvent }),
3852
+ hot: Object.assign(hmrServer.server, {
3853
+ send: hmrServer.send.bind(hmrServer),
3854
+ sendAll: hmrServer.sendAll.bind(hmrServer)
3855
+ })
3856
+ };
3857
+ const { invokePostConfigureServer } = await invokeConfigureServer(devServer, config.plugins ?? []);
3858
+ fastify.use(communityMiddleware).use(devMiddleware).register(plugin, { getBundler }).register(plugin$1, { getBundler }).register(plugin$2, {
3859
+ projectRoot,
3860
+ host,
3861
+ port,
3862
+ https,
3863
+ preferNativePlatform: config.resolver.preferNativePlatform
3864
+ }).setErrorHandler(errorHandler);
3865
+ fastify.server.on("upgrade", getWebSocketUpgradeHandler({
3866
+ ...communityWebsocketEndpoints,
3867
+ ...websocketEndpoints,
3868
+ "/hot": hmrServer.server
3869
+ }));
3870
+ await invokePostConfigureServer();
3871
+ return devServer;
3872
+ }
3873
+ async function invokeConfigureServer(server, plugins) {
3874
+ const postConfigureServerHandlers = [];
3875
+ for (const plugin$3 of plugins) {
3876
+ const context = createPluginContext(plugin$3.name);
3877
+ const result = await plugin$3.configureServer?.call(context, server);
3878
+ if (typeof result === "function") postConfigureServerHandlers.push(result);
3879
+ }
3880
+ return { invokePostConfigureServer: async () => {
3881
+ for (const handler of postConfigureServerHandlers) await handler();
3882
+ } };
3883
+ }
3884
+
1521
3885
  //#endregion
1522
3886
  //#region src/reporter.ts
1523
3887
  var TerminalReporter = class {
@@ -1538,18 +3902,17 @@ var TerminalReporter = class {
1538
3902
  function resolvePackagePath(basePath, packageName) {
1539
3903
  let packagePath = null;
1540
3904
  try {
1541
- packagePath = resolvePackagePathWithNodeRequire(basePath, packageName);
3905
+ packagePath = resolvePackagePathWithNodeRequire(basePath, packageName, "package.json");
1542
3906
  if (packagePath) return packagePath;
1543
3907
  } catch {}
1544
3908
  try {
1545
- packagePath = resolvePackagePathWithNodeRequire(basePath, packageName, "");
3909
+ packagePath = resolvePackagePathWithNodeRequire(basePath, packageName);
1546
3910
  if (packagePath) return packagePath;
1547
3911
  } catch {}
1548
3912
  throw new Error(`Failed to resolve package path for '${packageName}'`);
1549
3913
  }
1550
- function resolvePackagePathWithNodeRequire(basePath, packageName, lookupSubpath = "package.json") {
1551
- const lookupPath = lookupSubpath ? `/${lookupSubpath}` : "";
1552
- const resolvedPath = __require.resolve(`${packageName}${lookupPath}`, { paths: [basePath] });
3914
+ function resolvePackagePathWithNodeRequire(basePath, packageName, subpath) {
3915
+ const resolvedPath = __require.resolve(subpath ? `${packageName}/${subpath}` : packageName, { paths: [basePath] });
1553
3916
  const root = path.parse(resolvedPath).root;
1554
3917
  let currentPath = path.dirname(resolvedPath);
1555
3918
  while (currentPath !== root) {
@@ -1646,20 +4009,26 @@ async function loadConfig(options = {}) {
1646
4009
  ...commonOptions
1647
4010
  });
1648
4011
  const resolvedConfig = mergeConfig(defaultConfig, userConfig, await resolvePluginConfig(userConfig, userConfig.plugins ?? []));
1649
- await invokePluginConfigResolved(resolvedConfig, userConfig.plugins ?? []);
4012
+ await invokeConfigResolved(resolvedConfig, userConfig.plugins ?? []);
1650
4013
  return resolvedConfig;
1651
4014
  }
1652
4015
  async function resolvePluginConfig(baseConfig, plugins) {
1653
4016
  let mergedConfig = omit(baseConfig, ["plugins", "dangerously_overrideRolldownOptions"]);
1654
- for (const plugin of plugins) if (typeof plugin.config === "function") {
1655
- const config = await plugin.config(mergedConfig);
1656
- if (config != null) mergedConfig = mergeConfig(mergedConfig, config);
1657
- } else if (typeof plugin.config === "object") mergedConfig = mergeConfig(mergedConfig, plugin.config);
4017
+ for (const plugin$3 of plugins) {
4018
+ const context = createPluginContext(plugin$3.name);
4019
+ if (typeof plugin$3.config === "function") {
4020
+ const config = await plugin$3.config.call(context, mergedConfig);
4021
+ if (config != null) mergedConfig = mergeConfig(mergedConfig, config);
4022
+ } else if (typeof plugin$3.config === "object") mergedConfig = mergeConfig(mergedConfig, plugin$3.config);
4023
+ }
1658
4024
  return mergedConfig;
1659
4025
  }
1660
- async function invokePluginConfigResolved(config, plugins) {
1661
- for (const plugin of plugins) await plugin.configResolved?.(config);
4026
+ async function invokeConfigResolved(config, plugins) {
4027
+ await Promise.all(plugins.map((plugin$3) => {
4028
+ const context = createPluginContext(plugin$3.name);
4029
+ return plugin$3.configResolved?.call(context, config);
4030
+ }));
1662
4031
  }
1663
4032
 
1664
4033
  //#endregion
1665
- export { assets_exports as AssetUtils, Bundler, TerminalReporter as DefaultReporter, PluginUtils, defineConfig, getDefaultConfig, invokePluginConfigResolved, loadConfig, mergeConfig, plugins_exports as plugins, resolvePluginConfig, rolldown, rolldownExperimental };
4034
+ export { assets_exports as AssetUtils, Bundler, DEFAULT_HOST, DEFAULT_PORT, TerminalReporter as DefaultReporter, PluginUtils, createDevServer, defineConfig, getDefaultConfig, invokeConfigResolved, loadConfig, mergeConfig, plugins_exports as plugins, resolvePluginConfig, rolldown, rolldownExperimental };