rollipop 0.1.0-alpha.13 → 0.1.0-alpha.15

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/commands.cjs CHANGED
@@ -41,11 +41,8 @@ let node_tty = require("node:tty");
41
41
  let _inquirer_prompts = require("@inquirer/prompts");
42
42
  let node_fs = require("node:fs");
43
43
  node_fs = __toESM(node_fs);
44
- let _babel_generator = require("@babel/generator");
45
- let flow_remove_types = require("flow-remove-types");
46
- flow_remove_types = __toESM(flow_remove_types);
47
- let hermes_parser = require("hermes-parser");
48
- hermes_parser = __toESM(hermes_parser);
44
+ let fast_flow_transform = require("fast-flow-transform");
45
+ fast_flow_transform = __toESM(fast_flow_transform);
49
46
  let wrap_ansi = require("wrap-ansi");
50
47
  wrap_ansi = __toESM(wrap_ansi);
51
48
  let c12 = require("c12");
@@ -58,7 +55,7 @@ let _rollipop_rolldown_experimental = require("@rollipop/rolldown/experimental")
58
55
  _rollipop_rolldown_experimental = __toESM(_rollipop_rolldown_experimental);
59
56
  let node_crypto = require("node:crypto");
60
57
  node_crypto = __toESM(node_crypto);
61
- let _node_rs_xxhash = require("@node-rs/xxhash");
58
+ require("@node-rs/xxhash");
62
59
  let dedent = require("dedent");
63
60
  dedent = __toESM(dedent);
64
61
  let dotenv = require("dotenv");
@@ -155,7 +152,7 @@ const DEBUG_KEY = "rollipop";
155
152
  const SHARED_DATA_PATH = ".rollipop";
156
153
 
157
154
  //#endregion
158
- //#region src/common/debug.ts
155
+ //#region src/common/env.ts
159
156
  const TRUTHY_VALUES = [
160
157
  "yes",
161
158
  "on",
@@ -185,6 +182,13 @@ function isDebugEnabled() {
185
182
  if (debugKeys == null) debugKeys = parseDebugKeys();
186
183
  return debugKeys[DEBUG_KEY] ?? false;
187
184
  }
185
+ function getBundleStoreMode() {
186
+ switch (process.env.BUNDLE_STORE) {
187
+ case "fs":
188
+ case "memory": return process.env.BUNDLE_STORE;
189
+ default: return "memory";
190
+ }
191
+ }
188
192
 
189
193
  //#endregion
190
194
  //#region src/common/logger.ts
@@ -265,7 +269,7 @@ var Logger = class Logger {
265
269
 
266
270
  //#endregion
267
271
  //#region src/node/logger.ts
268
- const logger$2 = new Logger("cli");
272
+ const logger$3 = new Logger("cli");
269
273
 
270
274
  //#endregion
271
275
  //#region src/node/utils.ts
@@ -313,12 +317,12 @@ var DebuggerOpener = class DebuggerOpener {
313
317
  this.settings = loadSettings(projectRoot);
314
318
  }
315
319
  async openDebuggerForTarget(target) {
316
- logger$2.debug(`Opening debugger for target: ${target.id}`);
320
+ logger$3.debug(`Opening debugger for target: ${target.id}`);
317
321
  try {
318
322
  await fetch(new URL("/open-debugger?target=" + encodeURIComponent(target.id), this.serverUrl), { method: "POST" });
319
323
  } catch (error) {
320
- logger$2.error(`Failed to open debugger for ${target.title}`);
321
- logger$2.debug("Reason", error);
324
+ logger$3.error(`Failed to open debugger for ${target.title}`);
325
+ logger$3.debug("Reason", error);
322
326
  }
323
327
  }
324
328
  async autoOpen() {
@@ -327,18 +331,18 @@ var DebuggerOpener = class DebuggerOpener {
327
331
  if (this.isAutoOpenEnabled()) await this.open();
328
332
  }
329
333
  async open() {
330
- logger$2.debug("Fetching available debugging targets...");
334
+ logger$3.debug("Fetching available debugging targets...");
331
335
  const response = await fetch(new URL("/json/list", this.serverUrl), { method: "POST" });
332
336
  if (response.status !== 200) throw new Error(`Unexpected status code: ${response.status}`);
333
337
  const targets = await response.json();
334
338
  if (!Array.isArray(targets)) throw new Error("Unexpected response format");
335
- logger$2.debug(`Found ${targets.length} debugging targets:`);
336
- if (targets.length === 0) logger$2.warn("No connected targets");
339
+ logger$3.debug(`Found ${targets.length} debugging targets:`);
340
+ if (targets.length === 0) logger$3.warn("No connected targets");
337
341
  else if (targets.length === 1) {
338
342
  const target = targets[0];
339
343
  await this.openDebuggerForTarget(target);
340
344
  } else {
341
- if (targets.length > DebuggerOpener.MAX_TARGETS_SHOWN) logger$2.warn(`More than ${DebuggerOpener.MAX_TARGETS_SHOWN} debug targets available, showing the first ${DebuggerOpener.MAX_TARGETS_SHOWN}.`);
345
+ if (targets.length > DebuggerOpener.MAX_TARGETS_SHOWN) logger$3.warn(`More than ${DebuggerOpener.MAX_TARGETS_SHOWN} debug targets available, showing the first ${DebuggerOpener.MAX_TARGETS_SHOWN}.`);
342
346
  const slicedTargets = targets.slice(0, DebuggerOpener.MAX_TARGETS_SHOWN);
343
347
  Logger.block();
344
348
  this._prompting = true;
@@ -378,7 +382,7 @@ function setupInteractiveMode(options) {
378
382
  const { devServer, extraCommands = [] } = options;
379
383
  if (!devServer.instance.server.listening) throw new Error("Dev server is not listening. Please call `devServer.instance.listen()` first.");
380
384
  if (!(process.stdin.isTTY && process.stdin instanceof node_tty.ReadStream)) {
381
- logger$2.warn("Interactive mode is not supported in non-interactive environments");
385
+ logger$3.warn("Interactive mode is not supported in non-interactive environments");
382
386
  return;
383
387
  }
384
388
  const debuggerOpener = new DebuggerOpener(devServer.config.root, devServer.instance.listeningOrigin);
@@ -389,7 +393,7 @@ function setupInteractiveMode(options) {
389
393
  process.stdin.setRawMode(true);
390
394
  devServer.on("device.connected", () => {
391
395
  debuggerOpener.autoOpen().catch(() => {
392
- logger$2.error("Failed to open debugger");
396
+ logger$3.error("Failed to open debugger");
393
397
  });
394
398
  });
395
399
  process.stdin.on("keypress", (_, key) => {
@@ -405,7 +409,7 @@ function setupInteractiveMode(options) {
405
409
  const targetCommand = allCommands.find((command) => command.key === sequence && (command.shift ?? false) === shift);
406
410
  if (targetCommand) targetCommand.handler.call({
407
411
  server: devServer,
408
- logger: logger$2
412
+ logger: logger$3
409
413
  });
410
414
  });
411
415
  console.log();
@@ -422,7 +426,7 @@ function getDefaultCommands(devServer, debuggerOpener) {
422
426
  key: "r",
423
427
  description: "Reload app",
424
428
  handler: (0, es_toolkit.throttle)(() => {
425
- logger$2.info("Reloading app...");
429
+ logger$3.info("Reloading app...");
426
430
  devServer.message.broadcast("reload");
427
431
  }, BROADCAST_THROTTLE_DELAY)
428
432
  },
@@ -431,7 +435,7 @@ function getDefaultCommands(devServer, debuggerOpener) {
431
435
  description: "Open DevTools",
432
436
  handler: () => {
433
437
  debuggerOpener.open().catch(() => {
434
- logger$2.error("Failed to open debugger");
438
+ logger$3.error("Failed to open debugger");
435
439
  });
436
440
  }
437
441
  },
@@ -439,7 +443,7 @@ function getDefaultCommands(devServer, debuggerOpener) {
439
443
  key: "d",
440
444
  description: "Show developer menu",
441
445
  handler: (0, es_toolkit.throttle)(() => {
442
- logger$2.info("Showing developer menu...");
446
+ logger$3.info("Showing developer menu...");
443
447
  devServer.message.broadcast("devMenu");
444
448
  }, BROADCAST_THROTTLE_DELAY)
445
449
  },
@@ -453,7 +457,7 @@ function getDefaultCommands(devServer, debuggerOpener) {
453
457
  handler: () => {
454
458
  const newAutoOpenEnabled = !debuggerOpener.isAutoOpenEnabled();
455
459
  debuggerOpener.setAutoOpenEnabled(newAutoOpenEnabled);
456
- logger$2.info(`Auto opening developer tools: ${chalk.default.bold(newAutoOpenEnabled ? "enabled" : "disabled")}`);
460
+ logger$3.info(`Auto opening developer tools: ${chalk.default.bold(newAutoOpenEnabled ? "enabled" : "disabled")}`);
457
461
  }
458
462
  }
459
463
  ];
@@ -490,36 +494,15 @@ const UNSUPPORTED_OPTION_DESCRIPTION = "This option is not supported by Rollipop
490
494
 
491
495
  //#endregion
492
496
  //#region src/common/transformer.ts
493
- function stripFlowTypes(code) {
494
- const typeRemoved = (0, flow_remove_types.default)(code, {
495
- all: true,
496
- removeEmptyImports: true
497
- });
498
- return {
499
- code: typeRemoved.toString(),
500
- map: typeRemoved.generateMap()
501
- };
502
- }
503
- function stripFlowSyntax(code) {
504
- const { code: typeRemovedCode } = stripFlowTypes(code);
505
- return parseFlowSyntax(typeRemovedCode);
506
- }
507
- function parseFlowSyntax(code) {
508
- return hermes_parser.parse(code, {
509
- flow: "all",
510
- babel: true
497
+ async function stripFlowTypes(id, code) {
498
+ return await (0, fast_flow_transform.default)({
499
+ filename: id,
500
+ source: code,
501
+ sourcemap: true,
502
+ dialect: "flow",
503
+ format: "pretty"
511
504
  });
512
505
  }
513
- function generateSourceFromAst(ast, id) {
514
- const generated = (0, _babel_generator.generate)(ast, {
515
- sourceMaps: true,
516
- sourceFileName: node_path.default.basename(id)
517
- });
518
- return {
519
- code: generated.code,
520
- map: generated.map
521
- };
522
- }
523
506
 
524
507
  //#endregion
525
508
  //#region src/constants.ts
@@ -921,7 +904,7 @@ var ProgressBarRenderManager = class ProgressBarRenderManager {
921
904
 
922
905
  //#endregion
923
906
  //#region src/logger.ts
924
- const logger$1 = new Logger("bundler");
907
+ const logger$2 = new Logger("bundler");
925
908
 
926
909
  //#endregion
927
910
  //#region src/utils/reporters.ts
@@ -983,7 +966,7 @@ var ProgressBarStatusReporter = class {
983
966
  case "transform":
984
967
  const { id, totalModules, transformedModules } = event;
985
968
  if (this.flags & ProgressFlags.FILE_CHANGED) {
986
- logger$1.debug("Transformed changed file", { id });
969
+ logger$2.debug("Transformed changed file", { id });
987
970
  return;
988
971
  }
989
972
  this.renderProgress(id, totalModules, transformedModules);
@@ -998,16 +981,16 @@ var CompatStatusReporter = class {
998
981
  update(event) {
999
982
  switch (event.type) {
1000
983
  case "bundle_build_started":
1001
- logger$1.info("Build started...");
984
+ logger$2.info("Build started...");
1002
985
  break;
1003
986
  case "bundle_build_failed":
1004
- logger$1.error(`Build failed`);
987
+ logger$2.error(`Build failed`);
1005
988
  break;
1006
989
  case "bundle_build_done":
1007
990
  const { duration, totalModules } = event;
1008
991
  const time = chalk.default.blue(`${duration.toFixed(2)}ms`);
1009
992
  const modules = chalk.default.blue(`(${totalModules} modules)`);
1010
- logger$1.info(`Build completed in ${time} ${modules}`);
993
+ logger$2.info(`Build completed in ${time} ${modules}`);
1011
994
  break;
1012
995
  }
1013
996
  }
@@ -1015,7 +998,7 @@ var CompatStatusReporter = class {
1015
998
 
1016
999
  //#endregion
1017
1000
  //#region src/config/defaults.ts
1018
- function getDefaultConfig(projectRoot, mode) {
1001
+ async function getDefaultConfig(projectRoot, mode) {
1019
1002
  let reactNativePath;
1020
1003
  try {
1021
1004
  reactNativePath = process.env.ROLLIPOP_REACT_NATIVE_PATH ?? resolvePackagePath(projectRoot, "react-native");
@@ -1043,9 +1026,11 @@ function getDefaultConfig(projectRoot, mode) {
1043
1026
  },
1044
1027
  serializer: {
1045
1028
  prelude: [getInitializeCorePath(projectRoot)],
1046
- polyfills: getPolyfillScriptPaths(reactNativePath).map((path) => ({
1047
- type: "iife",
1048
- code: generateSourceFromAst(stripFlowSyntax(node_fs.default.readFileSync(path, "utf-8")), path).code
1029
+ polyfills: await Promise.all(getPolyfillScriptPaths(reactNativePath).map(async (path) => {
1030
+ return {
1031
+ type: "iife",
1032
+ code: (await stripFlowTypes(path, node_fs.default.readFileSync(path, "utf-8"))).code
1033
+ };
1049
1034
  }))
1050
1035
  },
1051
1036
  watcher: {
@@ -1116,7 +1101,7 @@ function mergeConfig(baseConfig, ...overrideConfigs) {
1116
1101
  const CONFIG_FILE_NAME = "rollipop";
1117
1102
  async function loadConfig(options = {}) {
1118
1103
  const { cwd = process.cwd(), configFile, mode, context = {} } = options;
1119
- const defaultConfig = getDefaultConfig(cwd, mode);
1104
+ const defaultConfig = await getDefaultConfig(cwd, mode);
1120
1105
  const commonOptions = {
1121
1106
  context: {
1122
1107
  ...context,
@@ -1183,7 +1168,7 @@ var FileSystemCache = class FileSystemCache {
1183
1168
  constructor(projectRoot, id) {
1184
1169
  this.cacheDirectory = node_path.default.join(FileSystemCache.getCacheDirectory(projectRoot), id);
1185
1170
  this.ensureCacheDirectory(this.cacheDirectory);
1186
- logger$1.debug("cache directory:", this.cacheDirectory);
1171
+ logger$2.debug("cache directory:", this.cacheDirectory);
1187
1172
  }
1188
1173
  ensureCacheDirectory(cacheDirectory) {
1189
1174
  if (!node_fs.default.existsSync(cacheDirectory)) node_fs.default.mkdirSync(cacheDirectory, { recursive: true });
@@ -1205,11 +1190,11 @@ var FileSystemCache = class FileSystemCache {
1205
1190
  try {
1206
1191
  await node_fs.default.promises.writeFile(node_path.default.join(this.cacheDirectory, key), value);
1207
1192
  } catch (error) {
1208
- logger$1.error("Failed to write cache file", key);
1209
- logger$1.debug(error);
1193
+ logger$2.error("Failed to write cache file", key);
1194
+ logger$2.debug(error);
1210
1195
  }
1211
1196
  }))).catch((error) => {
1212
- logger$1.error("Failed to flush cache", error);
1197
+ logger$2.error("Failed to flush cache", error);
1213
1198
  });
1214
1199
  this.pendingData.clear();
1215
1200
  }
@@ -1245,9 +1230,6 @@ function resolveBuildOptions(config, buildOptions) {
1245
1230
 
1246
1231
  //#endregion
1247
1232
  //#region src/utils/hash.ts
1248
- function xxhash(data) {
1249
- return (0, _node_rs_xxhash.xxh32)(data).toString(16);
1250
- }
1251
1233
  function md5(data) {
1252
1234
  return node_crypto.default.createHash("md5").update(data).digest("hex");
1253
1235
  }
@@ -1417,7 +1399,7 @@ function loadEnv(options) {
1417
1399
  for (const envFile of envFilesToLoad) {
1418
1400
  const envPath = node_path.default.resolve(envDir, envFile);
1419
1401
  if (!node_fs.default.existsSync(envPath)) continue;
1420
- logger$1.trace(`Loading environment variables from ${envPath}`);
1402
+ logger$2.trace(`Loading environment variables from ${envPath}`);
1421
1403
  const parsed = dotenv.default.parse(node_fs.default.readFileSync(envPath, "utf-8"));
1422
1404
  const expanded = dotenv_expand.default.expand({
1423
1405
  parsed,
@@ -1427,35 +1409,35 @@ function loadEnv(options) {
1427
1409
  if (key.startsWith(envPrefix)) env[key] = key in process.env ? process.env[key] : value;
1428
1410
  });
1429
1411
  }
1430
- logger$1.trace("Loaded environment variables:", env);
1412
+ logger$2.trace("Loaded environment variables:", env);
1431
1413
  return env;
1432
1414
  }
1433
1415
 
1434
1416
  //#endregion
1435
1417
  //#region src/server/logger.ts
1436
- const logger = new Logger("dev-server");
1418
+ const logger$1 = new Logger("dev-server");
1437
1419
  var DevServerLogger = class {
1438
1420
  level = "trace";
1439
1421
  trace(...args) {
1440
- logger.trace(...args);
1422
+ logger$1.trace(...args);
1441
1423
  }
1442
1424
  debug(...args) {
1443
- logger.debug(...args);
1425
+ logger$1.debug(...args);
1444
1426
  }
1445
1427
  info(...args) {
1446
- logger.info(...args);
1428
+ logger$1.info(...args);
1447
1429
  }
1448
1430
  warn(...args) {
1449
- logger.warn(...args);
1431
+ logger$1.warn(...args);
1450
1432
  }
1451
1433
  error(...args) {
1452
- logger.error(...args);
1434
+ logger$1.error(...args);
1453
1435
  }
1454
1436
  silent(...args) {
1455
- logger.trace(chalk.default.gray("(silent)"), ...args);
1437
+ logger$1.trace(chalk.default.gray("(silent)"), ...args);
1456
1438
  }
1457
1439
  fatal(...args) {
1458
- logger.error(chalk.default.magenta("(fatal)"), ...args);
1440
+ logger$1.error(chalk.default.magenta("(fatal)"), ...args);
1459
1441
  }
1460
1442
  child(_bindings) {
1461
1443
  return this;
@@ -1470,11 +1452,11 @@ async function assertDevServerStatus(options) {
1470
1452
  let shouldExit = false;
1471
1453
  switch (status) {
1472
1454
  case DevServerStatus.MATCHED_SERVER_RUNNING:
1473
- logger.warn(`A dev server is already running for this project on port ${port}. Exiting.`);
1455
+ logger$1.warn(`A dev server is already running for this project on port ${port}. Exiting.`);
1474
1456
  shouldExit = true;
1475
1457
  break;
1476
1458
  case DevServerStatus.PORT_TAKEN:
1477
- logger.error(`Another process is running on port ${port}. Please terminate this process and try again, or use another port with "--port".`);
1459
+ logger$1.error(`Another process is running on port ${port}. Please terminate this process and try again, or use another port with "--port".`);
1478
1460
  shouldExit = true;
1479
1461
  break;
1480
1462
  }
@@ -1564,7 +1546,7 @@ function replaceSourceMappingURL(code, sourceMappingURL) {
1564
1546
 
1565
1547
  //#endregion
1566
1548
  //#region src/server/bundle.ts
1567
- var InMemoryBundle = class {
1549
+ var InMemoryBundleStore = class {
1568
1550
  lazySourceMapConsumer = null;
1569
1551
  constructor(_code, _sourceMap, sourceMappingURL) {
1570
1552
  this._code = _code;
@@ -1583,6 +1565,42 @@ var InMemoryBundle = class {
1583
1565
  return this.lazySourceMapConsumer;
1584
1566
  }
1585
1567
  };
1568
+ var FileSystemBundleStore = class {
1569
+ bundleFilePath;
1570
+ holder;
1571
+ constructor(projectRoot, id, code) {
1572
+ const sharedDataPath = getSharedDataPath(projectRoot);
1573
+ const bundlesPath = node_path.default.join(sharedDataPath, "bundles");
1574
+ const bundleFilePath = node_path.default.join(bundlesPath, `${id}.bundle`);
1575
+ if (!node_fs.default.existsSync(bundlesPath)) node_fs.default.mkdirSync(bundlesPath, { recursive: true });
1576
+ node_fs.default.writeFileSync(bundleFilePath, code, { encoding: "utf-8" });
1577
+ const stats = node_fs.default.statSync(bundleFilePath);
1578
+ this.bundleFilePath = bundleFilePath;
1579
+ this.holder = {
1580
+ code,
1581
+ mtimeMs: stats.mtimeMs
1582
+ };
1583
+ logger$2.info(`File system bundle created at ${bundleFilePath}`);
1584
+ }
1585
+ update() {
1586
+ this.holder = {
1587
+ code: node_fs.default.readFileSync(this.bundleFilePath, { encoding: "utf-8" }),
1588
+ mtimeMs: node_fs.default.statSync(this.bundleFilePath).mtimeMs
1589
+ };
1590
+ }
1591
+ get code() {
1592
+ if (this.isStale()) {
1593
+ logger$2.info("File system bundle is stale, updating...");
1594
+ this.update();
1595
+ } else logger$2.trace("File system bundle is up to date");
1596
+ return this.holder.code;
1597
+ }
1598
+ get sourceMap() {}
1599
+ get sourceMapConsumer() {}
1600
+ isStale() {
1601
+ return this.holder.mtimeMs !== node_fs.default.statSync(this.bundleFilePath).mtimeMs;
1602
+ }
1603
+ };
1586
1604
 
1587
1605
  //#endregion
1588
1606
  //#region src/server/bundler-pool.ts
@@ -1590,7 +1608,7 @@ var BundlerDevEngine = class extends node_events.default {
1590
1608
  initializeHandle;
1591
1609
  isHmrEnabled;
1592
1610
  _id;
1593
- bundle = null;
1611
+ bundleStore = null;
1594
1612
  buildFailedError = null;
1595
1613
  _devEngine = null;
1596
1614
  _state = "idle";
@@ -1629,14 +1647,14 @@ var BundlerDevEngine = class extends node_events.default {
1629
1647
  onHmrUpdates: (errorOrResult) => {
1630
1648
  if (!this.isHmrEnabled) return;
1631
1649
  if (errorOrResult instanceof Error) {
1632
- logger.error("Failed to handle HMR updates", {
1650
+ logger$1.error("Failed to handle HMR updates", {
1633
1651
  bundlerId: this.id,
1634
1652
  error: errorOrResult
1635
1653
  });
1636
1654
  const normalizedError = normalizeRolldownError(errorOrResult);
1637
1655
  this.emit("buildFailed", normalizedError);
1638
1656
  } else {
1639
- logger.trace("Detected changed files", {
1657
+ logger$1.trace("Detected changed files", {
1640
1658
  bundlerId: this.id,
1641
1659
  changedFiles: errorOrResult.changedFiles
1642
1660
  });
@@ -1646,16 +1664,15 @@ var BundlerDevEngine = class extends node_events.default {
1646
1664
  onOutput: (errorOrResult) => {
1647
1665
  if (errorOrResult instanceof Error) {
1648
1666
  const normalizedError = normalizeRolldownError(errorOrResult);
1649
- logger.trace("onOutput", { bundlerId: this.id });
1650
- logger.error(errorOrResult.message);
1667
+ logger$1.trace("onOutput", { bundlerId: this.id });
1668
+ logger$1.error(errorOrResult.message);
1651
1669
  this.buildFailedError = normalizedError;
1652
1670
  this.emit("buildFailed", normalizedError);
1653
1671
  } else {
1654
1672
  const output = errorOrResult.output[0];
1655
- const sourceMap = output.map?.toString();
1656
- this.bundle = new InMemoryBundle(output.code, sourceMap, this.sourceMappingURL);
1673
+ this.updateBundleStore(output);
1657
1674
  this.buildFailedError = null;
1658
- logger.debug("Build completed", {
1675
+ logger$1.debug("Build completed", {
1659
1676
  bundlerId: this.id,
1660
1677
  bundleName: output.name
1661
1678
  });
@@ -1668,17 +1685,20 @@ var BundlerDevEngine = class extends node_events.default {
1668
1685
  this._state = "ready";
1669
1686
  this.initializeHandle.resolve();
1670
1687
  }
1688
+ updateBundleStore(output) {
1689
+ this.bundleStore = getBundleStoreMode() === "fs" ? new FileSystemBundleStore(this.config.root, this.id, output.code) : new InMemoryBundleStore(output.code, output.map?.toString(), this.sourceMappingURL);
1690
+ }
1671
1691
  async getBundle() {
1672
1692
  await this.ensureInitialized;
1673
1693
  const state = await this.devEngine.getBundleState();
1674
- logger.debug("Bundle state", {
1694
+ logger$1.debug("Bundle state", {
1675
1695
  bundlerId: this.id,
1676
1696
  state
1677
1697
  });
1678
1698
  if (state.lastFullBuildFailed) throw new Error(this.buildFailedError?.message ?? "Build failed");
1679
- if (state.hasStaleOutput || this.bundle == null) await this.devEngine.ensureLatestBuildOutput();
1680
- (0, es_toolkit.invariant)(this.bundle, "Bundle is not available");
1681
- return this.bundle;
1699
+ if (state.hasStaleOutput || this.bundleStore == null) await this.devEngine.ensureLatestBuildOutput();
1700
+ (0, es_toolkit.invariant)(this.bundleStore, "Bundle is not available");
1701
+ return this.bundleStore;
1682
1702
  }
1683
1703
  };
1684
1704
  var BundlerPool = class BundlerPool {
@@ -1695,12 +1715,12 @@ var BundlerPool = class BundlerPool {
1695
1715
  const instance = BundlerPool.instances.get(key);
1696
1716
  if (instance) return instance;
1697
1717
  else {
1698
- logger.debug("Preparing new bundler instance", {
1718
+ logger$1.debug("Preparing new bundler instance", {
1699
1719
  bundleName,
1700
1720
  key
1701
1721
  });
1702
1722
  const instance = new BundlerDevEngine({ server: this.resolvedServerOptions }, this.config, buildOptions);
1703
- logger.debug("Setting new bundler instance", { key });
1723
+ logger$1.debug("Setting new bundler instance", { key });
1704
1724
  BundlerPool.instances.set(key, instance);
1705
1725
  return instance;
1706
1726
  }
@@ -1716,8 +1736,8 @@ const DEV_SERVER_ASSET_PATH = "assets";
1716
1736
  //#endregion
1717
1737
  //#region src/server/error.ts
1718
1738
  function errorHandler(error, request, reply) {
1719
- logger.error(`An error occurred while processing the request (${request.method} ${request.url}):`, error.message);
1720
- logger.debug(error);
1739
+ logger$1.error(`An error occurred while processing the request (${request.method} ${request.url}):`, error.message);
1740
+ logger$1.debug(error);
1721
1741
  reply.status(500).send("Internal Server Error");
1722
1742
  }
1723
1743
 
@@ -1725,9 +1745,9 @@ function errorHandler(error, request, reply) {
1725
1745
  //#region src/server/middlewares/request-logger.ts
1726
1746
  const requestLogger = (req, _res, next) => {
1727
1747
  if (isDebugEnabled()) {
1728
- logger.trace(chalk.default.bgBlue(` ${req.method} `), chalk.default.gray(req.url));
1748
+ logger$1.trace(chalk.default.bgBlue(` ${req.method} `), chalk.default.gray(req.url));
1729
1749
  Object.entries(req.headers).forEach(([key, value]) => {
1730
- logger.trace(`${chalk.default.bold(key)}: ${chalk.default.gray(value)}`);
1750
+ logger$1.trace(`${chalk.default.bold(key)}: ${chalk.default.gray(value)}`);
1731
1751
  });
1732
1752
  }
1733
1753
  next();
@@ -1997,12 +2017,12 @@ const INTERNAL_CALLSITES_REGEX = new RegExp([
1997
2017
  "/node_modules/scheduler/.+\\.js$",
1998
2018
  "^\\[native code\\]$"
1999
2019
  ].map((pathPattern) => pathPattern.replaceAll("/", "[/\\\\]")).join("|"));
2000
- async function symbolicate(bundle, stack) {
2001
- const sourceMapConsumer = await bundle.sourceMapConsumer;
2002
- const symbolicatedStack = stack.filter((frame) => frame.file?.startsWith("http")).map((frame) => originalPositionFor(sourceMapConsumer, frame)).map((frame) => collapseFrame(frame));
2020
+ async function symbolicate(bundleStore, stack) {
2021
+ const sourceMapConsumer = await bundleStore.sourceMapConsumer;
2022
+ const symbolicatedStack = stack.filter((frame) => frame.file?.startsWith("http")).map((frame) => sourceMapConsumer ? originalPositionFor(sourceMapConsumer, frame) : frame).map((frame) => collapseFrame(frame));
2003
2023
  return {
2004
2024
  stack: symbolicatedStack,
2005
- codeFrame: getCodeFrame(sourceMapConsumer, symbolicatedStack, bundle)
2025
+ codeFrame: getCodeFrame(symbolicatedStack, bundleStore, sourceMapConsumer)
2006
2026
  };
2007
2027
  }
2008
2028
  function originalPositionFor(sourceMapConsumer, frame) {
@@ -2034,7 +2054,7 @@ function convertFrameKey(key) {
2034
2054
  else if (key === "name") return "methodName";
2035
2055
  return key;
2036
2056
  }
2037
- function getCodeFrame(sourceMapConsumer, frames, bundle) {
2057
+ function getCodeFrame(frames, bundleStore, sourceMapConsumer) {
2038
2058
  const frame = frames.find((frame) => {
2039
2059
  return frame.lineNumber != null && frame.column != null && !isCollapsed(frame);
2040
2060
  });
@@ -2042,7 +2062,7 @@ function getCodeFrame(sourceMapConsumer, frames, bundle) {
2042
2062
  try {
2043
2063
  const { lineNumber, column, file } = frame;
2044
2064
  const unresolved = file.startsWith("http");
2045
- const source = unresolved ? bundle.code : sourceMapConsumer.sourceContentFor(frame.file);
2065
+ const source = sourceMapConsumer == null || unresolved ? bundleStore.code : sourceMapConsumer.sourceContentFor(frame.file);
2046
2066
  const fileName = unresolved ? parseUrl(file).pathname ?? "unknown" : file;
2047
2067
  let content = "";
2048
2068
  if (source) content = (0, _babel_code_frame.codeFrameColumns)(source, { start: {
@@ -2087,14 +2107,40 @@ const plugin = (0, fastify_plugin.default)((fastify, options) => {
2087
2107
  (0, es_toolkit.invariant)(pathname, "No pathname found in bundle URL");
2088
2108
  (0, es_toolkit.invariant)(query.platform, "No platform found in query");
2089
2109
  (0, es_toolkit.invariant)(query.dev, "No dev found in query");
2090
- const bundle = await getBundler(getBaseBundleName(pathname), {
2110
+ const symbolicateResult = await symbolicate(await getBundler(getBaseBundleName(pathname), {
2091
2111
  platform: query.platform,
2092
2112
  dev: query.dev === "true"
2093
- }).getBundle();
2094
- await reply.header("Content-Type", "application/json").send(await symbolicate(bundle, stack));
2113
+ }).getBundle(), stack);
2114
+ if (isDebugEnabled()) printSymbolicateResult(stack, symbolicateResult);
2115
+ await reply.header("Content-Type", "application/json").send(symbolicateResult);
2095
2116
  }
2096
2117
  });
2097
2118
  }, { name: "symbolicate" });
2119
+ function printSymbolicateResult(rawStackFrame, symbolicateResult) {
2120
+ console.log();
2121
+ console.log("Symbolicate result:");
2122
+ console.log();
2123
+ if (symbolicateResult.codeFrame != null) {
2124
+ console.log(symbolicateResult.codeFrame.content);
2125
+ console.log();
2126
+ }
2127
+ console.log("Stack trace:");
2128
+ symbolicateResult.stack.forEach((stackFrame) => {
2129
+ const symbol = stackFrame.methodName ?? "<anonymous>";
2130
+ const file = stackFrame.file ?? "unknown";
2131
+ const location = stackFrame.lineNumber != null && stackFrame.column != null ? `(${chalk.default.gray.underline(`${file}:${stackFrame.lineNumber}:${stackFrame.column}`)})` : "";
2132
+ console.log(` at ${symbol} ${location}`);
2133
+ });
2134
+ console.log();
2135
+ console.log("Raw stack trace:");
2136
+ rawStackFrame.filter((stackFrame) => stackFrame.file?.startsWith("http")).forEach((stackFrame) => {
2137
+ const bundleName = new URL(stackFrame.file).pathname.slice(1);
2138
+ const symbol = stackFrame.methodName ?? "<anonymous>";
2139
+ const location = stackFrame.lineNumber != null && stackFrame.column != null ? `(${chalk.default.gray.underline(`${bundleName}:${stackFrame.lineNumber}:${stackFrame.column}`)})` : "";
2140
+ console.log(` at ${symbol} ${location}`);
2141
+ });
2142
+ console.log();
2143
+ }
2098
2144
 
2099
2145
  //#endregion
2100
2146
  //#region src/server/wss/server.ts
@@ -2104,7 +2150,7 @@ var WebSocketServer = class extends node_events.default {
2104
2150
  logger;
2105
2151
  constructor(name, options) {
2106
2152
  super();
2107
- const logger$3 = logger.child(name);
2153
+ const logger = logger$1.child(name);
2108
2154
  const wss = new ws.WebSocketServer(options);
2109
2155
  wss.on("connection", (socket) => {
2110
2156
  const client = Object.defineProperty(socket, "id", {
@@ -2127,7 +2173,7 @@ var WebSocketServer = class extends node_events.default {
2127
2173
  });
2128
2174
  });
2129
2175
  this.wss = wss;
2130
- this.logger = logger$3;
2176
+ this.logger = logger;
2131
2177
  }
2132
2178
  get server() {
2133
2179
  return this.wss;
@@ -2405,10 +2451,10 @@ async function createDevServer(config, options) {
2405
2451
  logger: {
2406
2452
  info(...args) {
2407
2453
  if (args[0].includes("JavaScript logs have moved")) return;
2408
- logger.info(...args);
2454
+ logger$1.info(...args);
2409
2455
  },
2410
- warn: logger.warn.bind(logger),
2411
- error: logger.error.bind(logger)
2456
+ warn: logger$1.warn.bind(logger$1),
2457
+ error: logger$1.error.bind(logger$1)
2412
2458
  },
2413
2459
  unstable_experiments: {
2414
2460
  enableNetworkInspector: true,
@@ -2730,8 +2776,7 @@ function getFlagFromModuleInfo(moduleInfo) {
2730
2776
  if (moduleInfo && hasFlag(moduleInfo.meta)) return moduleInfo.meta[TRANSFORM_FLAGS_KEY];
2731
2777
  return TransformFlag.NONE;
2732
2778
  }
2733
- function withTransformBoundary(plugins, options) {
2734
- const { context } = options;
2779
+ function withTransformBoundary(context, plugins) {
2735
2780
  return [
2736
2781
  {
2737
2782
  name: "rollipop:transform-initializer",
@@ -2751,107 +2796,10 @@ function withTransformBoundary(plugins, options) {
2751
2796
  context.state.hmrUpdates.add(id);
2752
2797
  }
2753
2798
  },
2754
- options?.beforeTransform,
2755
- plugins,
2756
- options?.afterTransform
2799
+ plugins
2757
2800
  ];
2758
2801
  }
2759
2802
 
2760
- //#endregion
2761
- //#region src/core/plugins/utils/persist-cache.ts
2762
- function getPersistCachePlugins(options) {
2763
- if (!options.enabled) return {
2764
- beforeTransform: null,
2765
- afterTransform: null
2766
- };
2767
- const { sourceExtensions, context } = options;
2768
- const includePattern = new RegExp(`\\.(?:${sourceExtensions.join("|")})$`);
2769
- const filter = [(0, _rollipop_rolldown_pluginutils.exclude)((0, _rollipop_rolldown_pluginutils.or)((0, _rollipop_rolldown_pluginutils.id)(/rolldown\/runtime/), (0, _rollipop_rolldown_pluginutils.id)(/@oxc-project\+runtime/))), (0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)(includePattern))];
2770
- let cacheHits = 0;
2771
- return {
2772
- beforeTransform: {
2773
- name: "rollipop:persist-cache-start",
2774
- buildStart() {
2775
- cacheHits = 0;
2776
- },
2777
- buildEnd() {
2778
- this.debug(`Cache hits: ${cacheHits}`);
2779
- },
2780
- transform: {
2781
- order: "pre",
2782
- filter,
2783
- handler(_code, id) {
2784
- const key = getCacheKey(id, context.id);
2785
- const cache = context.cache.get(key);
2786
- if (cache != null) {
2787
- cacheHits++;
2788
- return {
2789
- code: cache,
2790
- moduleType: "tsx",
2791
- meta: setFlag(this, id, TransformFlag.SKIP_ALL)
2792
- };
2793
- }
2794
- }
2795
- }
2796
- },
2797
- afterTransform: {
2798
- name: "rollipop:persist-cache-end",
2799
- transform: {
2800
- order: "post",
2801
- filter,
2802
- handler(code, id) {
2803
- if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
2804
- context.cache.set(getCacheKey(id, context.id), code);
2805
- }
2806
- },
2807
- buildEnd() {
2808
- context.cache.flush().then(() => logger$1.trace("Cache flushed"));
2809
- }
2810
- }
2811
- };
2812
- }
2813
- function getCacheKey(id, buildHash) {
2814
- const { mtimeMs } = node_fs.default.statSync(id);
2815
- return xxhash(`${id}${buildHash}${mtimeMs}`);
2816
- }
2817
- /**
2818
- * Enhance a plugin to cache the result. (transform hook only)
2819
- */
2820
- function cacheable(plugin) {
2821
- let configured = false;
2822
- const originalTransform = plugin.transform;
2823
- if (typeof originalTransform === "function") {
2824
- plugin.transform = function(code, id, meta) {
2825
- if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
2826
- return originalTransform.call(this, code, id, meta);
2827
- };
2828
- configured = true;
2829
- }
2830
- if (typeof originalTransform === "object") {
2831
- plugin.transform = {
2832
- ...originalTransform,
2833
- handler(code, id, meta) {
2834
- if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
2835
- return originalTransform.handler.call(this, code, id, meta);
2836
- }
2837
- };
2838
- configured = true;
2839
- }
2840
- if (configured) plugin.name = `${plugin.name}:cacheable`;
2841
- else logger$1.warn(`Plugin '${plugin.name}' is could not be cached`);
2842
- return plugin;
2843
- }
2844
-
2845
- //#endregion
2846
- //#region src/core/plugins/utils/source.ts
2847
- const TS_EXTENSION_REGEXP = /\.tsx?$/;
2848
- function isTS(id) {
2849
- return TS_EXTENSION_REGEXP.test(id);
2850
- }
2851
- function isJSX(id) {
2852
- return id.endsWith("x");
2853
- }
2854
-
2855
2803
  //#endregion
2856
2804
  //#region src/core/plugins/react-native-plugin.ts
2857
2805
  function reactNativePlugin(config, options) {
@@ -2872,11 +2820,11 @@ function reactNativePlugin(config, options) {
2872
2820
  transform: {
2873
2821
  order: "pre",
2874
2822
  filter: flowFilter,
2875
- handler(code, id) {
2823
+ async handler(code, id) {
2876
2824
  const flags = getFlag(this, id);
2877
2825
  if (flags & TransformFlag.SKIP_ALL) return;
2878
2826
  if (flags & TransformFlag.CODEGEN_REQUIRED) return { meta: setFlag(this, id, TransformFlag.STRIP_FLOW_REQUIRED) };
2879
- const result = generateSourceFromAst(stripFlowSyntax(code), id);
2827
+ const result = await stripFlowTypes(id, code);
2880
2828
  return {
2881
2829
  code: result.code,
2882
2830
  map: result.map,
@@ -2924,113 +2872,24 @@ function reactNativePlugin(config, options) {
2924
2872
  };
2925
2873
  const defaultRuntimeImplements = getDefaultRuntimeImplements();
2926
2874
  const hmrConfig = resolveHmrConfig(config);
2927
- const hmrClientPath = require.resolve(process.env.ROLLIPOP_HMR_CLIENT_PATH ?? DEFAULT_HMR_CLIENT_PATH, { paths: [config.root] });
2928
2875
  const replaceHMRClientPlugin = {
2929
2876
  name: "rollipop:react-native-replace-hmr-client",
2930
- resolveId: {
2931
- filter: [(0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)(/\/HMRClient\.js$/))],
2932
- async handler(id, importer) {
2933
- const resolvedId = await this.resolve(id, importer, { skipSelf: true });
2934
- if (resolvedId?.id === hmrClientPath) await this.load({ id: resolvedId.id });
2935
- }
2936
- },
2937
2877
  load: {
2938
- filter: [(0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)((0, _rollipop_rolldown_pluginutils.exactRegex)(hmrClientPath)))],
2878
+ filter: [(0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)((0, _rollipop_rolldown_pluginutils.exactRegex)(require.resolve(process.env.ROLLIPOP_HMR_CLIENT_PATH ?? DEFAULT_HMR_CLIENT_PATH, { paths: [config.root] }))))],
2939
2879
  handler(id) {
2940
2880
  this.debug(`Replacing HMR client: ${id}`);
2941
2881
  return hmrConfig?.clientImplement ?? defaultRuntimeImplements.clientImplement;
2942
2882
  }
2943
2883
  }
2944
2884
  };
2945
- const devServerPlugins = buildType === "serve" ? [replaceHMRClientPlugin] : null;
2946
2885
  return [
2947
- cacheable(codegenPlugin),
2948
- cacheable(stripFlowSyntaxPlugin),
2886
+ codegenPlugin,
2887
+ stripFlowSyntaxPlugin,
2949
2888
  assetPlugin,
2950
- ...devServerPlugins ?? []
2889
+ ...(buildType === "serve" ? [replaceHMRClientPlugin] : null) ?? []
2951
2890
  ];
2952
2891
  }
2953
2892
 
2954
- //#endregion
2955
- //#region src/core/plugins/react-refresh-plugin.ts
2956
- const DEFAULT_INCLUDE_REGEX = /\.[tj]sx?(?:$|\?)/;
2957
- const DEFAULT_EXCLUDE_REGEX = /\/node_modules\//;
2958
- const HAS_REFRESH_REGEX = /\$RefreshReg\$\(/;
2959
- const ONLY_REACT_COMPONENT_REGEX = /extends\s+(?:React\.)?(?:Pure)?Component/;
2960
- function reactRefreshPlugin(options) {
2961
- const { include = DEFAULT_INCLUDE_REGEX, exclude = DEFAULT_EXCLUDE_REGEX } = options ?? {};
2962
- return [{
2963
- name: "rollipop:transform-react-refresh",
2964
- transform: {
2965
- filter: { id: {
2966
- include,
2967
- exclude
2968
- } },
2969
- handler(code, id) {
2970
- if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
2971
- const result = (0, _rollipop_rolldown_experimental.transformSync)(id, code, {
2972
- sourcemap: true,
2973
- jsx: {
2974
- runtime: "automatic",
2975
- development: true,
2976
- refresh: {
2977
- refreshReg: `${GLOBAL_IDENTIFIER}.$RefreshReg$`,
2978
- refreshSig: `${GLOBAL_IDENTIFIER}.$RefreshSig$`
2979
- }
2980
- }
2981
- });
2982
- return {
2983
- code: result.code,
2984
- map: result.map
2985
- };
2986
- }
2987
- }
2988
- }, {
2989
- name: "rollipop:react-refresh-boundary",
2990
- transform: {
2991
- filter: { id: {
2992
- include,
2993
- exclude
2994
- } },
2995
- handler(code, id, meta) {
2996
- if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
2997
- const { magicString } = meta;
2998
- (0, es_toolkit.invariant)(magicString != null, "magicString is not available");
2999
- applyRefreshWrapper(magicString, {
3000
- id,
3001
- hasRefresh: HAS_REFRESH_REGEX.test(code),
3002
- onlyReactComponent: ONLY_REACT_COMPONENT_REGEX.test(code)
3003
- });
3004
- return { code: magicString };
3005
- }
3006
- }
3007
- }];
3008
- }
3009
- function applyRefreshWrapper(s, options) {
3010
- const { id, hasRefresh, onlyReactComponent } = options;
3011
- if (!(hasRefresh || onlyReactComponent)) return;
3012
- if (hasRefresh) s.prepend(`
3013
- var __prev$RefreshReg$ = global.$RefreshReg$;
3014
- var __prev$RefreshSig$ = global.$RefreshSig$;
3015
- global.$RefreshReg$ = function(type, id) { return __ReactRefresh.register(type, ${JSON.stringify(id)} + ' ' + id) }
3016
- global.$RefreshSig$ = function() { return __ReactRefresh.createSignatureFunctionForTransform(); }
3017
- `);
3018
- s.append(`
3019
- if (import.meta.hot) {
3020
- if (import.meta.hot.refresh == null) throw new Error('react-refresh runtime is not initialized');
3021
- import.meta.hot.accept((nextExports) => {
3022
- if (!nextExports) return;
3023
- if (import.meta.hot.refreshUtils.isReactRefreshBoundary(nextExports)) {
3024
- import.meta.hot.refreshUtils.enqueueUpdate();
3025
- }
3026
- });
3027
- }`);
3028
- if (hasRefresh) s.append(`
3029
- global.$RefreshReg$ = __prev$RefreshReg$;
3030
- global.$RefreshSig$ = __prev$RefreshSig$;
3031
- `);
3032
- }
3033
-
3034
2893
  //#endregion
3035
2894
  //#region src/core/plugins/prelude-plugin.ts
3036
2895
  const IS_ENTRY = Symbol("IS_ENTRY");
@@ -3127,6 +2986,16 @@ function merge$3(target, source, key) {
3127
2986
  if (key === "presets") return [...target ?? [], ...source ?? []];
3128
2987
  }
3129
2988
 
2989
+ //#endregion
2990
+ //#region src/core/plugins/utils/source.ts
2991
+ const TS_EXTENSION_REGEXP = /\.tsx?$/;
2992
+ function isTS(id) {
2993
+ return TS_EXTENSION_REGEXP.test(id);
2994
+ }
2995
+ function isJSX(id) {
2996
+ return id.endsWith("x");
2997
+ }
2998
+
3130
2999
  //#endregion
3131
3000
  //#region src/core/plugins/babel-plugin.ts
3132
3001
  function babelPlugin(options) {
@@ -3170,7 +3039,7 @@ function babelPlugin(options) {
3170
3039
  };
3171
3040
  } }
3172
3041
  };
3173
- return [...babelRules, babelPlugin].map(cacheable);
3042
+ return [...babelRules, babelPlugin];
3174
3043
  }
3175
3044
  function getPreset$1(flags, id) {
3176
3045
  const presets = [];
@@ -3204,11 +3073,25 @@ function merge$2(target, source, key) {
3204
3073
  if (key === "plugins") return [...target ?? [], ...source ?? []];
3205
3074
  }
3206
3075
 
3076
+ //#endregion
3077
+ //#region src/core/plugins/shared/filters.ts
3078
+ const ROLLDOWN_RUNTIME_EXCLUDE_FILTER = (0, _rollipop_rolldown_pluginutils.exclude)((0, _rollipop_rolldown_pluginutils.or)((0, _rollipop_rolldown_pluginutils.id)(/rolldown\/runtime/), (0, _rollipop_rolldown_pluginutils.id)(/@oxc-project\+runtime/)));
3079
+
3207
3080
  //#endregion
3208
3081
  //#region src/core/plugins/swc-plugin.ts
3209
3082
  function swcPlugin(options) {
3210
3083
  const { rules = [] } = options ?? {};
3211
3084
  const swcOptionsById = /* @__PURE__ */ new Map();
3085
+ const swcHelpersResolvePlugin = {
3086
+ name: "rollipop:swc-helpers-resolve",
3087
+ resolveId: {
3088
+ order: "pre",
3089
+ filter: [(0, _rollipop_rolldown_pluginutils.include)((0, _rollipop_rolldown_pluginutils.id)(/^@swc\/helpers/)), ROLLDOWN_RUNTIME_EXCLUDE_FILTER],
3090
+ handler(source, _importer, extraOptions) {
3091
+ return this.resolve(source, __dirname, extraOptions);
3092
+ }
3093
+ }
3094
+ };
3212
3095
  const swcRules = rules.map(({ filter, options }, index) => {
3213
3096
  return {
3214
3097
  name: `rollipop:swc-rule-${index}`,
@@ -3227,43 +3110,53 @@ function swcPlugin(options) {
3227
3110
  buildStart() {
3228
3111
  swcOptionsById.clear();
3229
3112
  },
3230
- transform: { handler(code, id) {
3231
- if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
3232
- const swcOptions = swcOptionsById.get(id) ?? [];
3233
- const baseOptions = getPreset();
3234
- const result = _swc_core.transformSync(code, {
3235
- filename: id,
3236
- configFile: false,
3237
- swcrc: false,
3238
- sourceMaps: true,
3239
- inputSourceMap: false,
3240
- ...mergeSwcOptions(baseOptions, ...swcOptions)
3241
- });
3242
- return {
3243
- code: result.code,
3244
- map: result.map
3245
- };
3246
- } }
3113
+ transform: {
3114
+ filter: [ROLLDOWN_RUNTIME_EXCLUDE_FILTER],
3115
+ handler(code, id) {
3116
+ if (getFlag(this, id) & TransformFlag.SKIP_ALL) return;
3117
+ const swcOptions = swcOptionsById.get(id) ?? [];
3118
+ const baseOptions = getPreset(id);
3119
+ const result = _swc_core.transformSync(code, {
3120
+ filename: id,
3121
+ configFile: false,
3122
+ swcrc: false,
3123
+ sourceMaps: true,
3124
+ inputSourceMap: false,
3125
+ ...mergeSwcOptions(baseOptions, ...swcOptions)
3126
+ });
3127
+ return {
3128
+ code: result.code,
3129
+ map: result.map
3130
+ };
3131
+ }
3132
+ }
3247
3133
  };
3248
- return [...swcRules, swcPlugin].map(cacheable);
3134
+ return [
3135
+ swcHelpersResolvePlugin,
3136
+ ...swcRules,
3137
+ swcPlugin
3138
+ ];
3249
3139
  }
3250
- function getPreset() {
3140
+ function getPreset(id) {
3251
3141
  return {
3142
+ env: {
3143
+ targets: { node: 9999 },
3144
+ include: [
3145
+ "transform-block-scoping",
3146
+ "transform-class-properties",
3147
+ "transform-private-methods",
3148
+ "transform-private-property-in-object"
3149
+ ]
3150
+ },
3252
3151
  jsc: {
3253
- target: "es5",
3254
3152
  parser: {
3255
3153
  syntax: "typescript",
3256
3154
  tsx: true
3257
3155
  },
3258
- keepClassNames: true,
3259
- loose: false,
3260
3156
  transform: { react: { runtime: "preserve" } },
3261
- assumptions: {
3262
- setPublicClassFields: true,
3263
- privateFieldsAsProperties: true
3264
- }
3157
+ externalHelpers: true
3265
3158
  },
3266
- isModule: true
3159
+ isModule: id.endsWith(".cjs") ? "commonjs" : true
3267
3160
  };
3268
3161
  }
3269
3162
 
@@ -3348,7 +3241,7 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
3348
3241
  }) }, rolldownResolve);
3349
3242
  const mergedTransformOptions = (0, es_toolkit.merge)({
3350
3243
  cwd: config.root,
3351
- target: "es2015",
3244
+ target: "esnext",
3352
3245
  jsx: {
3353
3246
  runtime: "automatic",
3354
3247
  development: dev
@@ -3361,16 +3254,13 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
3361
3254
  ...defineEnvFromObject(env),
3362
3255
  ...defineEnvFromObject(builtInEnv)
3363
3256
  },
3364
- typescript: { removeClassFieldsWithoutInitializer: true },
3365
- assumptions: { setPublicClassFields: true },
3366
3257
  helpers: { mode: "Runtime" }
3367
3258
  }, rolldownTransform);
3368
- const devServerPlugins = isDevServerMode ? [reactRefreshPlugin()] : null;
3369
- const { beforeTransform, afterTransform } = getPersistCachePlugins({
3370
- enabled: cache,
3371
- sourceExtensions,
3372
- context
3373
- });
3259
+ const devServerPlugins = isDevServerMode ? [(0, _rollipop_rolldown_experimental.rollipopReactRefreshWrapperPlugin)({
3260
+ cwd: config.root,
3261
+ include: [/\.[tj]sx?(?:$|\?)/],
3262
+ exclude: [/\/node_modules\//]
3263
+ })] : null;
3374
3264
  const defaultReporters = [(() => {
3375
3265
  switch (config.terminal.status) {
3376
3266
  case "compat": return new CompatStatusReporter();
@@ -3388,12 +3278,15 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
3388
3278
  tsconfig: config.tsconfig,
3389
3279
  resolve: mergedResolveOptions,
3390
3280
  transform: mergedTransformOptions,
3391
- optimization: rolldownOptimization,
3392
3281
  treeshake: rolldownTreeshake,
3393
3282
  external: rolldownExternal,
3394
3283
  shimMissingExports: rolldownShimMissingExports,
3284
+ optimization: {
3285
+ ...rolldownOptimization,
3286
+ inlineConst: false
3287
+ },
3395
3288
  experimental: { lazyBarrel: rolldownLazyBarrel },
3396
- plugins: withTransformBoundary([
3289
+ plugins: withTransformBoundary(context, [
3397
3290
  preludePlugin({ modulePaths: preludePaths }),
3398
3291
  reactNativePlugin(config, {
3399
3292
  dev,
@@ -3412,11 +3305,7 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
3412
3305
  reporterPlugin(reporterOptions),
3413
3306
  devServerPlugins,
3414
3307
  config.plugins
3415
- ], {
3416
- context,
3417
- beforeTransform,
3418
- afterTransform
3419
- }),
3308
+ ]),
3420
3309
  checks: {
3421
3310
  eval: false,
3422
3311
  pluginTimings: isDebugEnabled()
@@ -3425,7 +3314,8 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
3425
3314
  onLog(level, log, defaultHandler) {
3426
3315
  if (log.code?.startsWith("PLUGIN_")) printPluginLog(level, log, log.plugin);
3427
3316
  else defaultHandler(level, log);
3428
- }
3317
+ },
3318
+ id: context.id
3429
3319
  }, {
3430
3320
  format: "esm",
3431
3321
  file: buildOptions.outfile,
@@ -3449,7 +3339,8 @@ async function resolveRolldownOptions(context, config, buildOptions, devEngineOp
3449
3339
  sourcemapPathTransform: rolldownSourcemapPathTransform,
3450
3340
  codeSplitting: false,
3451
3341
  strictExecutionOrder: true,
3452
- globalIdentifiers: rolldownGlobalIdentifiers
3342
+ globalIdentifiers: rolldownGlobalIdentifiers,
3343
+ persistentCache: cache
3453
3344
  });
3454
3345
  resolveRolldownOptions.cache.set(context.id, finalOptions);
3455
3346
  return finalOptions;
@@ -3584,6 +3475,10 @@ async function runServer(config, options) {
3584
3475
  return devServer;
3585
3476
  }
3586
3477
 
3478
+ //#endregion
3479
+ //#region src/plugins/logger.ts
3480
+ const logger = new Logger("plugin:builtin");
3481
+
3587
3482
  //#endregion
3588
3483
  //#region src/node/commands/start/action.ts
3589
3484
  const action$1 = async function(options) {
@@ -3596,7 +3491,7 @@ const action$1 = async function(options) {
3596
3491
  });
3597
3492
  if (options.resetCache) {
3598
3493
  resetCache(cwd);
3599
- logger$2.info("The transform cache was reset");
3494
+ logger$3.info("The transform cache was reset");
3600
3495
  }
3601
3496
  if (options.clientLogs === false) config.reporter = { update: es_toolkit.noop };
3602
3497
  const devServer = await runServer(config, {
@@ -3710,7 +3605,7 @@ const action = async function(options) {
3710
3605
  });
3711
3606
  if (options.resetCache) {
3712
3607
  resetCache(cwd);
3713
- logger$2.info("The transform cache was reset");
3608
+ logger$3.info("The transform cache was reset");
3714
3609
  }
3715
3610
  if (options.entryFile) config.entry = options.entryFile;
3716
3611
  await runBuild(config, {