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