rollipop 1.0.0-beta.2 → 1.0.0-beta.3

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.
@@ -6,11 +6,12 @@ import { InteractiveCommand } from "../node/commands/start/setup-interactive-mod
6
6
  import "../node/cli-utils.js";
7
7
  import { Plugin } from "../core/plugins/types.js";
8
8
  import * as swc from "@swc/core";
9
- import { DevWatchOptions, RollipopReactNativeFlowConfig as FlowConfig, RollipopReactNativeReactConfig, RollipopReactNativeSwcConfig as SwcConfig, RollipopReactNativeWorkletsConfig as WorkletsConfig } from "@rollipop/rolldown/experimental";
9
+ import { DevWatchOptions, RollipopReactNativeFlowConfig as FlowConfig, RollipopReactNativeReactConfig, RollipopReactNativeSwcConfig as SwcConfig, RollipopReactNativeWorkletsConfig } from "@rollipop/rolldown/experimental";
10
10
  import * as rolldown from "@rollipop/rolldown";
11
11
  import { TopLevelFilterExpression } from "@rollipop/rolldown/filter";
12
12
  import * as babel from "@babel/core";
13
13
  //#region src/config/types.d.ts
14
+ type WorkletsConfig = Partial<RollipopReactNativeWorkletsConfig>;
14
15
  type RolldownExperimentalOptions = NonNullable<rolldown.InputOptions['experimental']>;
15
16
  type RolldownTransformOptions = NonNullable<rolldown.InputOptions['transform']>;
16
17
  type RolldownJsxOptions = ExtractObject<NonNullable<RolldownTransformOptions['jsx']>>;
@@ -227,7 +228,7 @@ export interface TransformRule<T = unknown> {
227
228
  }
228
229
  export interface ExperimentalConfig extends RolldownExperimentalOptions {
229
230
  /**
230
- * `react-native-worklets` transformation configuration.
231
+ * Worklets or Reanimated 3 transformation configuration. Installed versions are detected by default.
231
232
  */
232
233
  worklets?: WorkletsConfig;
233
234
  }
package/dist/constants.js CHANGED
@@ -20,7 +20,7 @@ var constants_exports = /* @__PURE__ */ __exportAll({
20
20
  ROLLIPOP_VIRTUAL_ENTRY_ID: () => ROLLIPOP_VIRTUAL_ENTRY_ID,
21
21
  ROLLIPOP_VIRTUAL_PREFIX: () => ROLLIPOP_VIRTUAL_PREFIX
22
22
  });
23
- const ROLLIPOP_VERSION = "1.0.0-beta.2";
23
+ const ROLLIPOP_VERSION = "1.0.0-beta.3";
24
24
  const ROLLIPOP_VIRTUAL_PREFIX = "\0rollipop/";
25
25
  const ROLLIPOP_VIRTUAL_BOOTSTRAP_ID = `${ROLLIPOP_VIRTUAL_PREFIX}bootstrap`;
26
26
  const ROLLIPOP_VIRTUAL_ENTRY_ID = `${ROLLIPOP_VIRTUAL_PREFIX}entry`;
@@ -62,7 +62,7 @@ function transform(code, id, options) {
62
62
  sourceMaps: true,
63
63
  ...options
64
64
  });
65
- invariant(result?.code, `Failed to transform with babel: ${id}`);
65
+ invariant(result?.code != null, `Failed to transform with babel: ${id}`);
66
66
  const map = result.map && {
67
67
  ...result.map,
68
68
  names: [...result.map.names],
@@ -2,7 +2,7 @@ import { ROLLIPOP_VIRTUAL_ENTRY_ID } from "../constants.js";
2
2
  import { isDebugEnabled } from "../common/env.js";
3
3
  import { CompatStatusReporter, ProgressBarStatusReporter } from "../events/builtin-reporters.js";
4
4
  import { asLiteral, iife, nodeEnvironment } from "../common/code.js";
5
- import { resolveFrom, resolvePackageJson } from "../utils/node-resolve.js";
5
+ import { resolveFrom } from "../utils/node-resolve.js";
6
6
  import { getGlobalVariables } from "../internal/react-native.js";
7
7
  import { printPluginLog } from "./plugins/context.js";
8
8
  import { applyRolldownOptionsConfig } from "../config/compose-override.js";
@@ -12,6 +12,7 @@ import { resolveHmrConfig } from "../utils/config.js";
12
12
  import { defineEnvFromObject } from "../utils/env.js";
13
13
  import { getBaseUrl } from "../utils/server.js";
14
14
  import { getBuildTotalModules, setBuildTotalModules } from "../utils/storage.js";
15
+ import { resolveWorkletsConfig } from "../utils/worklets.js";
15
16
  import { transformWithRollipop } from "../utils/transform.js";
16
17
  import { loadEnv } from "./env.js";
17
18
  import { withTransformBoundary } from "./plugins/utils/transform-utils.js";
@@ -218,17 +219,9 @@ function resolveReactNativeBuiltinPluginConfig(config) {
218
219
  runtimeTarget: config.runtimeTarget,
219
220
  flow: config.transform.flow,
220
221
  swc: resolveNativeSwcConfig(config.transform),
221
- worklets: resolveWorkletsConfig(config)
222
+ worklets: resolveWorkletsConfig(config.experimental.worklets, config)
222
223
  };
223
224
  }
224
- function resolveWorkletsConfig(config) {
225
- const { worklets } = config.experimental ?? {};
226
- if (worklets == null) return;
227
- return toMerged({
228
- isRelease: config.mode === "production",
229
- pluginVersion: resolvePackageJson(config.root, "react-native-worklets")?.version
230
- }, worklets);
231
- }
232
225
  function resolveRolldownTransformConfig(config) {
233
226
  const { flow: _flow, babel: _babel, swc: _swc, ...transform } = config;
234
227
  if (transform.jsx != null && typeof transform.jsx === "object") {
@@ -232,29 +232,29 @@ var __rolldown_runtime__ = (function() {
232
232
  if (e === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
233
233
  return e;
234
234
  }
235
- function asyncGeneratorStep(e, t, r, n, o, a, i) {
235
+ function asyncGeneratorStep(e, t, r, n, o, i, u) {
236
236
  try {
237
- var u = e[a](i);
238
- var l = u.value;
237
+ var l = e[i](u);
238
+ var a = l.value;
239
239
  } catch (e) {
240
240
  r(e);
241
241
  return;
242
242
  }
243
- if (u.done) t(l);
244
- else Promise.resolve(l).then(n, o);
243
+ if (l.done) t(a);
244
+ else Promise.resolve(a).then(n, o);
245
245
  }
246
246
  function _async_to_generator(e) {
247
247
  return function() {
248
248
  var t = this, r = arguments;
249
249
  return new Promise(function(n, o) {
250
- var a = e.apply(t, r);
251
- function i(e) {
252
- asyncGeneratorStep(a, n, o, i, u, "next", e);
253
- }
250
+ var i = e.apply(t, r);
254
251
  function u(e) {
255
- asyncGeneratorStep(a, n, o, i, u, "throw", e);
252
+ asyncGeneratorStep(i, n, o, u, l, "next", e);
253
+ }
254
+ function l(e) {
255
+ asyncGeneratorStep(i, n, o, u, l, "throw", e);
256
256
  }
257
- i(void 0);
257
+ u(void 0);
258
258
  });
259
259
  };
260
260
  }
@@ -279,6 +279,17 @@ var __rolldown_runtime__ = (function() {
279
279
  if (r) _defineProperties(e, r);
280
280
  return e;
281
281
  }
282
+ function _get(e, t, r) {
283
+ if (typeof Reflect !== "undefined" && Reflect.get) _get = Reflect.get;
284
+ else _get = function e(e, t, r) {
285
+ var n = _super_prop_base(e, t);
286
+ if (!n) return;
287
+ var o = Object.getOwnPropertyDescriptor(n, t);
288
+ if (o.get) return o.get.call(r || e);
289
+ return o.value;
290
+ };
291
+ return _get(e, t, r || e);
292
+ }
282
293
  function _get_prototype_of(e) {
283
294
  _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function e(e) {
284
295
  return e.__proto__ || Object.getPrototypeOf(e);
@@ -310,21 +321,21 @@ var __rolldown_runtime__ = (function() {
310
321
  if (r == null) return;
311
322
  var n = [];
312
323
  var o = true;
313
- var a = false;
314
- var i, u;
324
+ var i = false;
325
+ var u, l;
315
326
  try {
316
- for (r = r.call(e); !(o = (i = r.next()).done); o = true) {
317
- n.push(i.value);
327
+ for (r = r.call(e); !(o = (u = r.next()).done); o = true) {
328
+ n.push(u.value);
318
329
  if (t && n.length === t) break;
319
330
  }
320
331
  } catch (e) {
321
- a = true;
322
- u = e;
332
+ i = true;
333
+ l = e;
323
334
  } finally {
324
335
  try {
325
336
  if (!o && r["return"] != null) r["return"]();
326
337
  } finally {
327
- if (a) throw u;
338
+ if (i) throw l;
328
339
  }
329
340
  }
330
341
  return n;
@@ -349,11 +360,18 @@ var __rolldown_runtime__ = (function() {
349
360
  function _sliced_to_array(e, t) {
350
361
  return _array_with_holes(e) || _iterable_to_array_limit(e, t) || _unsupported_iterable_to_array(e, t) || _non_iterable_rest();
351
362
  }
363
+ function _super_prop_base(e, t) {
364
+ while (!Object.prototype.hasOwnProperty.call(e, t)) {
365
+ e = _get_prototype_of(e);
366
+ if (e === null) break;
367
+ }
368
+ return e;
369
+ }
352
370
  function _to_consumable_array(e) {
353
371
  return _array_without_holes(e) || _iterable_to_array(e) || _unsupported_iterable_to_array(e) || _non_iterable_spread();
354
372
  }
355
373
  function _ts_generator(e, t) {
356
- var r, n, o, a = {
374
+ var r, n, o, i = {
357
375
  label: 0,
358
376
  sent: function() {
359
377
  if (o[0] & 1) throw o[1];
@@ -361,73 +379,73 @@ var __rolldown_runtime__ = (function() {
361
379
  },
362
380
  trys: [],
363
381
  ops: []
364
- }, i = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), u = Object.defineProperty;
365
- return u(i, "next", { value: l(0) }), u(i, "throw", { value: l(1) }), u(i, "return", { value: l(2) }), typeof Symbol === "function" && u(i, Symbol.iterator, { value: function() {
382
+ }, u = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), l = Object.defineProperty;
383
+ return l(u, "next", { value: a(0) }), l(u, "throw", { value: a(1) }), l(u, "return", { value: a(2) }), typeof Symbol === "function" && l(u, Symbol.iterator, { value: function() {
366
384
  return this;
367
- } }), i;
368
- function l(e) {
385
+ } }), u;
386
+ function a(e) {
369
387
  return function(t) {
370
388
  return s([e, t]);
371
389
  };
372
390
  }
373
- function s(u) {
391
+ function s(l) {
374
392
  if (r) throw new TypeError("Generator is already executing.");
375
- while (i && (i = 0, u[0] && (a = 0)), a) try {
376
- if (r = 1, n && (o = u[0] & 2 ? n["return"] : u[0] ? n["throw"] || ((o = n["return"]) && o.call(n), 0) : n.next) && !(o = o.call(n, u[1])).done) return o;
377
- if (n = 0, o) u = [u[0] & 2, o.value];
378
- switch (u[0]) {
393
+ while (u && (u = 0, l[0] && (i = 0)), i) try {
394
+ if (r = 1, n && (o = l[0] & 2 ? n["return"] : l[0] ? n["throw"] || ((o = n["return"]) && o.call(n), 0) : n.next) && !(o = o.call(n, l[1])).done) return o;
395
+ if (n = 0, o) l = [l[0] & 2, o.value];
396
+ switch (l[0]) {
379
397
  case 0:
380
398
  case 1:
381
- o = u;
399
+ o = l;
382
400
  break;
383
401
  case 4:
384
- a.label++;
402
+ i.label++;
385
403
  return {
386
- value: u[1],
404
+ value: l[1],
387
405
  done: false
388
406
  };
389
407
  case 5:
390
- a.label++;
391
- n = u[1];
392
- u = [0];
408
+ i.label++;
409
+ n = l[1];
410
+ l = [0];
393
411
  continue;
394
412
  case 7:
395
- u = a.ops.pop();
396
- a.trys.pop();
413
+ l = i.ops.pop();
414
+ i.trys.pop();
397
415
  continue;
398
416
  default:
399
- if (!(o = a.trys, o = o.length > 0 && o[o.length - 1]) && (u[0] === 6 || u[0] === 2)) {
400
- a = 0;
417
+ if (!(o = i.trys, o = o.length > 0 && o[o.length - 1]) && (l[0] === 6 || l[0] === 2)) {
418
+ i = 0;
401
419
  continue;
402
420
  }
403
- if (u[0] === 3 && (!o || u[1] > o[0] && u[1] < o[3])) {
404
- a.label = u[1];
421
+ if (l[0] === 3 && (!o || l[1] > o[0] && l[1] < o[3])) {
422
+ i.label = l[1];
405
423
  break;
406
424
  }
407
- if (u[0] === 6 && a.label < o[1]) {
408
- a.label = o[1];
409
- o = u;
425
+ if (l[0] === 6 && i.label < o[1]) {
426
+ i.label = o[1];
427
+ o = l;
410
428
  break;
411
429
  }
412
- if (o && a.label < o[2]) {
413
- a.label = o[2];
414
- a.ops.push(u);
430
+ if (o && i.label < o[2]) {
431
+ i.label = o[2];
432
+ i.ops.push(l);
415
433
  break;
416
434
  }
417
- if (o[2]) a.ops.pop();
418
- a.trys.pop();
435
+ if (o[2]) i.ops.pop();
436
+ i.trys.pop();
419
437
  continue;
420
438
  }
421
- u = t.call(e, a);
439
+ l = t.call(e, i);
422
440
  } catch (e) {
423
- u = [6, e];
441
+ l = [6, e];
424
442
  n = 0;
425
443
  } finally {
426
444
  r = o = 0;
427
445
  }
428
- if (u[0] & 5) throw u[1];
446
+ if (l[0] & 5) throw l[1];
429
447
  return {
430
- value: u[0] ? u[1] : void 0,
448
+ value: l[0] ? l[1] : void 0,
431
449
  done: true
432
450
  };
433
451
  }
@@ -449,13 +467,13 @@ var __rolldown_runtime__ = (function() {
449
467
  var BaseDevRuntime = DevRuntime;
450
468
  var ModuleHotContext = /*#__PURE__*/ function() {
451
469
  "use strict";
452
- function e(t, r, n, o, a) {
470
+ function e(t, r, n, o, i) {
453
471
  _class_call_check(this, e);
454
472
  this.moduleId = t;
455
473
  this.socketHolder = r;
456
474
  this.runtime = n;
457
475
  this.data = o;
458
- this.invalidateModule = a;
476
+ this.invalidateModule = i;
459
477
  this.removeListeners = [];
460
478
  this.acceptCallbacks = [];
461
479
  }
@@ -527,8 +545,8 @@ var __rolldown_runtime__ = (function() {
527
545
  var e = true, t = false, r = void 0;
528
546
  try {
529
547
  for (var n = this.removeListeners[Symbol.iterator](), o; !(e = (o = n.next()).done); e = true) {
530
- var a = o.value;
531
- a();
548
+ var i = o.value;
549
+ i();
532
550
  }
533
551
  } catch (e) {
534
552
  t = true;
@@ -623,8 +641,8 @@ var __rolldown_runtime__ = (function() {
623
641
  var e = true, t = false, r = void 0;
624
642
  try {
625
643
  for (var n = this.queuedMessages[Symbol.iterator](), o; !(e = (o = n.next()).done); e = true) {
626
- var a = o.value;
627
- this._socket.send(a);
644
+ var i = o.value;
645
+ this._socket.send(i);
628
646
  }
629
647
  } catch (e) {
630
648
  t = true;
@@ -669,6 +687,62 @@ var __rolldown_runtime__ = (function() {
669
687
  return e;
670
688
  }
671
689
  _create_class(ReactNativeDevRuntime, [
690
+ {
691
+ key: "hasFactory",
692
+ value: function e(e) {
693
+ return _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "hasFactory", this).call(this, e) || typeof __rollipop_require__ !== "undefined" && __rollipop_require__.m[e] != null;
694
+ }
695
+ },
696
+ {
697
+ key: "isExecuted",
698
+ value: function e(e) {
699
+ return _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "isExecuted", this).call(this, e) || typeof __rollipop_require__ !== "undefined" && __rollipop_require__.c[e] != null;
700
+ }
701
+ },
702
+ {
703
+ key: "loadExports",
704
+ value: function e(e) {
705
+ if (!_get(_get_prototype_of(ReactNativeDevRuntime.prototype), "isExecuted", this).call(this, e) && typeof __rollipop_require__ !== "undefined") {
706
+ var t = __rollipop_require__.c[e];
707
+ if (t != null) return t.exports;
708
+ }
709
+ return _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "loadExports", this).call(this, e);
710
+ }
711
+ },
712
+ {
713
+ key: "initModule",
714
+ value: function e(e) {
715
+ if (this.isExecuted(e)) return this.loadExports(e);
716
+ if (_get(_get_prototype_of(ReactNativeDevRuntime.prototype), "hasFactory", this).call(this, e) || !this.hasFactory(e)) return _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "initModule", this).call(this, e);
717
+ return __rollipop_require__(e);
718
+ }
719
+ },
720
+ {
721
+ key: "registerFactory",
722
+ value: function e(e, t, r) {
723
+ var n = this;
724
+ _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "registerFactory", this).call(this, e, t, r);
725
+ if (typeof __rollipop_require__ !== "undefined") __rollipop_require__.m[e] = function(t, r) {
726
+ r.exports = _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "initModule", n).call(n, e);
727
+ };
728
+ }
729
+ },
730
+ {
731
+ key: "registerModule",
732
+ value: function e(e, t) {
733
+ t !== null && t !== void 0 || (t = typeof __rollipop_require__ !== "undefined" ? __rollipop_require__.c[e] : void 0);
734
+ t !== null && t !== void 0 || (t = { exports: {} });
735
+ _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "registerModule", this).call(this, e, t);
736
+ if (typeof __rollipop_require__ !== "undefined") __rollipop_require__.c[e] = t;
737
+ }
738
+ },
739
+ {
740
+ key: "removeModuleCache",
741
+ value: function e(e) {
742
+ if (typeof __rollipop_require__ !== "undefined") delete __rollipop_require__.c[e];
743
+ _get(_get_prototype_of(ReactNativeDevRuntime.prototype), "removeModuleCache", this).call(this, e);
744
+ }
745
+ },
672
746
  {
673
747
  key: "createHotContext",
674
748
  value: function e(e) {
@@ -709,10 +783,10 @@ var __rolldown_runtime__ = (function() {
709
783
  e.addEventListener("message", function(t) {
710
784
  var n = JSON.parse(t.data);
711
785
  if (isCustomHMRMessage(n)) {
712
- var o, a;
786
+ var o, i;
713
787
  debug("[HMR]: Custom HMR message received: ".concat(n.type));
714
788
  r.socketHolder.emit(n.type, n.payload);
715
- (a = globalThis.__rollipop_runtime__) === null || a === void 0 || (o = a.customHMRHandler) == null || o.call(a, e, n);
789
+ (i = globalThis.__rollipop_runtime__) === null || i === void 0 || (o = i.customHMRHandler) == null || o.call(i, e, n);
716
790
  return;
717
791
  }
718
792
  switch (n.type) {
@@ -782,23 +856,23 @@ var __rolldown_runtime__ = (function() {
782
856
  {
783
857
  key: "applyPush",
784
858
  value: function e(e) {
785
- var t = e.changedIds, r = e.code, n = e.filename, o = e.seq, a = e.sourceURL;
859
+ var t = e.changedIds, r = e.code, n = e.filename, o = e.seq, i = e.sourceURL;
786
860
  if (o !== this.lastSeq + 1) {
787
861
  this.reload("HMR update sequence gap (expected ".concat(this.lastSeq + 1, ", got ").concat(o, ")"));
788
862
  return;
789
863
  }
790
864
  this.lastSeq = o;
791
- var i = this.computeHmrUpdate(t);
792
- if (i.type === "full-reload") {
793
- this.reload(i.reason);
865
+ var u = this.computeHmrUpdate(t);
866
+ if (u.type === "full-reload") {
867
+ this.reload(u.reason);
794
868
  return;
795
869
  }
796
- this.evaluate(r, a);
870
+ this.evaluate(r, i);
797
871
  this.socketHolder.send(JSON.stringify({
798
872
  type: "hmr:payload-delivered",
799
873
  filename: n
800
874
  }));
801
- if (i.type === "boundaries") this.applyUpdate(i);
875
+ if (u.type === "boundaries") this.applyUpdate(u);
802
876
  }
803
877
  },
804
878
  {
@@ -827,22 +901,22 @@ var __rolldown_runtime__ = (function() {
827
901
  var r = [];
828
902
  var n = /* @__PURE__ */ new Set();
829
903
  var o = /* @__PURE__ */ new Set();
830
- var a = true, i = false, u = void 0;
904
+ var i = true, u = false, l = void 0;
831
905
  try {
832
- for (var l = e[Symbol.iterator](), s; !(a = (s = l.next()).done); a = true) {
906
+ for (var a = e[Symbol.iterator](), s; !(i = (s = a.next()).done); i = true) {
833
907
  var c = s.value;
834
908
  if (!this.isExecuted(c)) continue;
835
909
  var f = this.bubble(c, [c], n, r, o, t);
836
910
  if (f != null) return f;
837
911
  }
838
912
  } catch (e) {
839
- i = true;
840
- u = e;
913
+ u = true;
914
+ l = e;
841
915
  } finally {
842
916
  try {
843
- if (!a && l.return != null) l.return();
917
+ if (!i && a.return != null) a.return();
844
918
  } finally {
845
- if (i) throw u;
919
+ if (u) throw l;
846
920
  }
847
921
  }
848
922
  return r.length === 0 ? { type: "noop" } : {
@@ -854,47 +928,47 @@ var __rolldown_runtime__ = (function() {
854
928
  },
855
929
  {
856
930
  key: "bubble",
857
- value: function e(e, t, r, n, o, a) {
858
- var i = this;
931
+ value: function e(e, t, r, n, o, i) {
932
+ var u = this;
859
933
  if (o.has(e)) return;
860
934
  o.add(e);
861
935
  r.add(e);
862
- if (a != null && e === a) return {
936
+ if (i != null && e === i) return {
863
937
  type: "full-reload",
864
- reason: "Update propagated back to ".concat(a)
938
+ reason: "Update propagated back to ".concat(i)
865
939
  };
866
940
  if (this.isSelfAccepted(e)) {
867
941
  n.push([e, e]);
868
942
  return;
869
943
  }
870
- var u = this.getImporters(e).filter(function(e) {
871
- return i.isExecuted(e);
944
+ var l = this.getImporters(e).filter(function(e) {
945
+ return u.isExecuted(e);
872
946
  });
873
- if (u.length === 0) return {
947
+ if (l.length === 0) return {
874
948
  type: "full-reload",
875
949
  reason: "No HMR boundary found for ".concat(e)
876
950
  };
877
- var l = true, s = false, c = void 0;
951
+ var a = true, s = false, c = void 0;
878
952
  try {
879
- for (var f = u[Symbol.iterator](), d; !(l = (d = f.next()).done); l = true) {
880
- var h = d.value;
881
- if (this.acceptsDependency(h, e)) {
882
- n.push([h, e]);
953
+ for (var f = l[Symbol.iterator](), d; !(a = (d = f.next()).done); a = true) {
954
+ var p = d.value;
955
+ if (this.acceptsDependency(p, e)) {
956
+ n.push([p, e]);
883
957
  continue;
884
958
  }
885
- if (t.includes(h)) return {
959
+ if (t.includes(p)) return {
886
960
  type: "full-reload",
887
- reason: "Circular import chain between ".concat(e, " and ").concat(h)
961
+ reason: "Circular import chain between ".concat(e, " and ").concat(p)
888
962
  };
889
- var v = this.bubble(h, _to_consumable_array(t).concat([h]), r, n, o, a);
890
- if (v != null) return v;
963
+ var h = this.bubble(p, _to_consumable_array(t).concat([p]), r, n, o, i);
964
+ if (h != null) return h;
891
965
  }
892
966
  } catch (e) {
893
967
  s = true;
894
968
  c = e;
895
969
  } finally {
896
970
  try {
897
- if (!l && f.return != null) f.return();
971
+ if (!a && f.return != null) f.return();
898
972
  } finally {
899
973
  if (s) throw c;
900
974
  }
@@ -925,110 +999,110 @@ var __rolldown_runtime__ = (function() {
925
999
  key: "applyUpdate",
926
1000
  value: function e(e, t) {
927
1001
  var r = this;
928
- var n = true, o = false, a = void 0;
1002
+ var n = true, o = false, i = void 0;
929
1003
  try {
930
- for (var i = e.updateSet[Symbol.iterator](), u; !(n = (u = i.next()).done); n = true) {
931
- var l = u.value;
932
- if (!this.hasFactory(l)) {
933
- this.reload("No factory registered for ".concat(l));
1004
+ for (var u = e.updateSet[Symbol.iterator](), l; !(n = (l = u.next()).done); n = true) {
1005
+ var a = l.value;
1006
+ if (!this.hasFactory(a)) {
1007
+ this.reload("No factory registered for ".concat(a));
934
1008
  return;
935
1009
  }
936
1010
  }
937
1011
  } catch (e) {
938
1012
  o = true;
939
- a = e;
1013
+ i = e;
940
1014
  } finally {
941
1015
  try {
942
- if (!n && i.return != null) i.return();
1016
+ if (!n && u.return != null) u.return();
943
1017
  } finally {
944
- if (o) throw a;
1018
+ if (o) throw i;
945
1019
  }
946
1020
  }
947
1021
  var s = e.boundaries.map(function(e) {
948
1022
  var t = _sliced_to_array(e, 2), n = t[0], o = t[1];
949
- var a;
950
1023
  var i;
1024
+ var u;
951
1025
  return {
952
1026
  acceptedVia: o,
953
- callbacks: (a = (i = r.moduleHotContexts.get(n)) === null || i === void 0 ? void 0 : i.acceptCallbacks.filter(function(e) {
1027
+ callbacks: (i = (u = r.moduleHotContexts.get(n)) === null || u === void 0 ? void 0 : u.acceptCallbacks.filter(function(e) {
954
1028
  return e.deps.includes(o);
955
- })) !== null && a !== void 0 ? a : []
1029
+ })) !== null && i !== void 0 ? i : []
956
1030
  };
957
1031
  });
958
1032
  var c = true, f = false, d = void 0;
959
1033
  try {
960
- for (var h = e.updateSet[Symbol.iterator](), v; !(c = (v = h.next()).done); c = true) {
961
- var p = v.value;
962
- this.removeModuleCache(p);
1034
+ for (var p = e.updateSet[Symbol.iterator](), h; !(c = (h = p.next()).done); c = true) {
1035
+ var v = h.value;
1036
+ this.removeModuleCache(v);
963
1037
  }
964
1038
  } catch (e) {
965
1039
  f = true;
966
1040
  d = e;
967
1041
  } finally {
968
1042
  try {
969
- if (!c && h.return != null) h.return();
1043
+ if (!c && p.return != null) p.return();
970
1044
  } finally {
971
1045
  if (f) throw d;
972
1046
  }
973
1047
  }
974
- var y = true, m = false, b = void 0;
1048
+ var y = true, m = false, _ = void 0;
975
1049
  try {
976
- var k, g = function() {
977
- var e = _.value, r = e.acceptedVia, n = e.callbacks;
978
- k.initModule(r);
979
- var o = k.loadExports(r);
1050
+ var b, k = function() {
1051
+ var e = w.value, r = e.acceptedVia, n = e.callbacks;
1052
+ b.initModule(r);
1053
+ var o = b.loadExports(r);
980
1054
  try {
981
- k.currentFirstInvalidatedBy = t;
982
- var a = true, i = false, u = void 0;
1055
+ b.currentFirstInvalidatedBy = t;
1056
+ var i = true, u = false, l = void 0;
983
1057
  try {
984
- for (var l = n[Symbol.iterator](), s; !(a = (s = l.next()).done); a = true) {
1058
+ for (var a = n[Symbol.iterator](), s; !(i = (s = a.next()).done); i = true) {
985
1059
  var c = s.value, f = c.deps, d = c.fn;
986
1060
  d(f.map(function(e) {
987
1061
  return e === r ? o : void 0;
988
1062
  }));
989
1063
  }
990
1064
  } catch (e) {
991
- i = true;
992
- u = e;
1065
+ u = true;
1066
+ l = e;
993
1067
  } finally {
994
1068
  try {
995
- if (!a && l.return != null) l.return();
1069
+ if (!i && a.return != null) a.return();
996
1070
  } finally {
997
- if (i) throw u;
1071
+ if (u) throw l;
998
1072
  }
999
1073
  }
1000
1074
  } finally {
1001
- k.currentFirstInvalidatedBy = void 0;
1075
+ b.currentFirstInvalidatedBy = void 0;
1002
1076
  }
1003
1077
  };
1004
- for (var w = s[Symbol.iterator](), _; !(y = (_ = w.next()).done); y = true) k = this, g();
1078
+ for (var g = s[Symbol.iterator](), w; !(y = (w = g.next()).done); y = true) b = this, k();
1005
1079
  } catch (e) {
1006
1080
  m = true;
1007
- b = e;
1081
+ _ = e;
1008
1082
  } finally {
1009
1083
  try {
1010
- if (!y && w.return != null) w.return();
1084
+ if (!y && g.return != null) g.return();
1011
1085
  } finally {
1012
- if (m) throw b;
1086
+ if (m) throw _;
1013
1087
  }
1014
1088
  }
1015
- var H = true, S = false, x = void 0;
1089
+ var x = true, H = false, S = void 0;
1016
1090
  try {
1017
- for (var M = this.moduleHotContextsToBeUpdated[Symbol.iterator](), C; !(H = (C = M.next()).done); H = true) {
1018
- var R = _sliced_to_array(C.value, 2), U = R[0], E = R[1];
1019
- var O;
1020
- (O = this.moduleHotContexts.get(U)) === null || O === void 0 || O.cleanup();
1021
- if (E == null) this.moduleHotContexts.delete(U);
1022
- else this.moduleHotContexts.set(U, E);
1091
+ for (var M = this.moduleHotContextsToBeUpdated[Symbol.iterator](), C; !(x = (C = M.next()).done); x = true) {
1092
+ var R = _sliced_to_array(C.value, 2), E = R[0], q = R[1];
1093
+ var U;
1094
+ (U = this.moduleHotContexts.get(E)) === null || U === void 0 || U.cleanup();
1095
+ if (q == null) this.moduleHotContexts.delete(E);
1096
+ else this.moduleHotContexts.set(E, q);
1023
1097
  }
1024
1098
  } catch (e) {
1025
- S = true;
1026
- x = e;
1099
+ H = true;
1100
+ S = e;
1027
1101
  } finally {
1028
1102
  try {
1029
- if (!H && M.return != null) M.return();
1103
+ if (!x && M.return != null) M.return();
1030
1104
  } finally {
1031
- if (S) throw x;
1105
+ if (H) throw S;
1032
1106
  }
1033
1107
  }
1034
1108
  this.moduleHotContextsToBeUpdated.clear();
@@ -1088,20 +1162,20 @@ var __rolldown_runtime__ = (function() {
1088
1162
  return;
1089
1163
  }
1090
1164
  e.set(r.id, r);
1091
- var o = true, a = false, i = void 0;
1165
+ var o = true, i = false, u = void 0;
1092
1166
  try {
1093
- for (var u = t[Symbol.iterator](), l; !(o = (l = u.next()).done); o = true) {
1094
- var s = l.value;
1167
+ for (var l = t[Symbol.iterator](), a; !(o = (a = l.next()).done); o = true) {
1168
+ var s = a.value;
1095
1169
  s(r);
1096
1170
  }
1097
1171
  } catch (e) {
1098
- a = true;
1099
- i = e;
1172
+ i = true;
1173
+ u = e;
1100
1174
  } finally {
1101
1175
  try {
1102
- if (!o && u.return != null) u.return();
1176
+ if (!o && l.return != null) l.return();
1103
1177
  } finally {
1104
- if (a) throw i;
1178
+ if (i) throw u;
1105
1179
  }
1106
1180
  }
1107
1181
  },
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ import { resetCache } from "./utils/reset-cache.js";
19
19
  import { Bundler } from "./core/bundler.js";
20
20
  import { assets_d_exports } from "./core/assets.js";
21
21
  import { LoadEnvOptions, loadEnv } from "./core/env.js";
22
+ import { resolveWorkletsConfig } from "./utils/worklets.js";
22
23
  import { constants_d_exports } from "./constants.js";
23
24
  import { HMRClientLogLevel, HMRClientMessage, HMRContext, HMRCustomHandler, HMRCustomMessage, HMRServerError, HMRServerMessage } from "./types/hmr.js";
24
25
  import { cli_d_exports } from "./node/cli.js";
@@ -29,4 +30,4 @@ import { OutputChunk } from "@rollipop/rolldown";
29
30
  export declare function runBuild(config: ResolvedConfig, options: BuildOptions): Promise<OutputChunk>;
30
31
  export declare function runServer(config: ResolvedConfig, options: ServerOptions): Promise<DevServer>;
31
32
  //#endregion
32
- export { type AliasConfig, type AnalyzerConfig, assets_d_exports as AssetUtils, type AsyncResult, type BabelTransformConfig, type BuildDiagnosticLog, type BuildOptions, type BuildType, type BundleDetails, Bundler, type BundlerContext, type BundlerState, type ChangeEvent, type Config, constants_d_exports as Constants, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, type DeepRequired, DefaultConfig, DefineConfigContext, type DevConfig, type DevEngine, type DevEngineOptions, type DevServer, type DevServerContext, type DevServerEvents, type DevToolsPluginOptions, DynamicUserConfig, type ExperimentalConfig, type ExtractObject, type FastifyInstance, type FlowConfig, type FlowConfig as RollipopReactNativeFlowConfig, type FormattedError, type HMRClientLogLevel, type HMRClientMessage, type HMRContext, type HMRCustomHandler, type HMRCustomMessage, type HMRServerError, type HMRServerMessage, type HmrConfig, type HotUpdateOptions, InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, InternalConfig, type JsxOptions, LoadConfigOptions, LoadEnvOptions, type MaybePromise, type Middlewares, type NullValue, type OptimizationConfig, type OutputConfig, type PackageJson, type Plugin, type PluginConfig, PluginFlattenConfig, type PluginOption, type PluginWithHotUpdate, type Polyfill, type PolyfillOptions, type PolyfillType, type PolyfillWithCode, type PolyfillWithPath, type ReactNativeConfig, type ReportableEvent, type Reporter, type ResolveConfig, ResolvedConfig, type RolldownOptions, type RolldownOptionsConfig, type RolldownOptionsContext, type RolldownOptionsFunction, type RollipopDevToolsNodeContext, type SwcConfig as RollipopReactNativeSwcConfig, type SwcConfig, type WorkletsConfig as RollipopReactNativeWorkletsConfig, type WorkletsConfig, type ServerOptions, type SwcTransformConfig, type TransformConfig, type TransformRule, UserConfig, type WatcherConfig, cli_d_exports as cli, createCommand, createDevServer, createReactNativeCliCommand, defineConfig, flattenPluginOption, getDefaultConfig, invokeConfigResolved, loadConfig, loadEnv, mergeConfig, index_d_exports as plugins, resetCache, resolvePluginConfig, rolldown, rolldownExperimental, setupInteractiveMode };
33
+ export { type AliasConfig, type AnalyzerConfig, assets_d_exports as AssetUtils, type AsyncResult, type BabelTransformConfig, type BuildDiagnosticLog, type BuildOptions, type BuildType, type BundleDetails, Bundler, type BundlerContext, type BundlerState, type ChangeEvent, type Config, constants_d_exports as Constants, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, type DeepRequired, DefaultConfig, DefineConfigContext, type DevConfig, type DevEngine, type DevEngineOptions, type DevServer, type DevServerContext, type DevServerEvents, type DevToolsPluginOptions, DynamicUserConfig, type ExperimentalConfig, type ExtractObject, type FastifyInstance, type FlowConfig, type FlowConfig as RollipopReactNativeFlowConfig, type FormattedError, type HMRClientLogLevel, type HMRClientMessage, type HMRContext, type HMRCustomHandler, type HMRCustomMessage, type HMRServerError, type HMRServerMessage, type HmrConfig, type HotUpdateOptions, InteractiveCommand, InteractiveCommandContext, InteractiveModeOptions, InternalConfig, type JsxOptions, LoadConfigOptions, LoadEnvOptions, type MaybePromise, type Middlewares, type NullValue, type OptimizationConfig, type OutputConfig, type PackageJson, type Plugin, type PluginConfig, PluginFlattenConfig, type PluginOption, type PluginWithHotUpdate, type Polyfill, type PolyfillOptions, type PolyfillType, type PolyfillWithCode, type PolyfillWithPath, type ReactNativeConfig, type ReportableEvent, type Reporter, type ResolveConfig, ResolvedConfig, type RolldownOptions, type RolldownOptionsConfig, type RolldownOptionsContext, type RolldownOptionsFunction, type RollipopDevToolsNodeContext, type SwcConfig as RollipopReactNativeSwcConfig, type SwcConfig, type WorkletsConfig as RollipopReactNativeWorkletsConfig, type WorkletsConfig, type ServerOptions, type SwcTransformConfig, type TransformConfig, type TransformRule, UserConfig, type WatcherConfig, cli_d_exports as cli, createCommand, createDevServer, createReactNativeCliCommand, defineConfig, flattenPluginOption, getDefaultConfig, invokeConfigResolved, loadConfig, loadEnv, mergeConfig, index_d_exports as plugins, resetCache, resolvePluginConfig, resolveWorkletsConfig, rolldown, rolldownExperimental, setupInteractiveMode };
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import { mergeConfig } from "./config/merge-config.js";
5
5
  import { flattenPluginOption, invokeConfigResolved, loadConfig, resolvePluginConfig } from "./config/load-config.js";
6
6
  import "./config/index.js";
7
7
  import { resetCache } from "./utils/reset-cache.js";
8
+ import { resolveWorkletsConfig } from "./utils/worklets.js";
8
9
  import { loadEnv } from "./core/env.js";
9
10
  import { DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH } from "./server/constants.js";
10
11
  import { createDevServer } from "./server/index.js";
@@ -26,4 +27,4 @@ async function runServer(config, options) {
26
27
  return runServer(config, options);
27
28
  }
28
29
  //#endregion
29
- export { assets_exports as AssetUtils, Bundler, constants_exports as Constants, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, cli_exports as cli, createCommand, createDevServer, createReactNativeCliCommand, defineConfig, flattenPluginOption, getDefaultConfig, invokeConfigResolved, loadConfig, loadEnv, mergeConfig, plugins_exports as plugins, resetCache, resolvePluginConfig, rolldown, rolldownExperimental, runBuild, runServer, setupInteractiveMode };
30
+ export { assets_exports as AssetUtils, Bundler, constants_exports as Constants, DEFAULT_HOST, DEFAULT_PORT, DEV_SERVER_ASSET_PATH, cli_exports as cli, createCommand, createDevServer, createReactNativeCliCommand, defineConfig, flattenPluginOption, getDefaultConfig, invokeConfigResolved, loadConfig, loadEnv, mergeConfig, plugins_exports as plugins, resetCache, resolvePluginConfig, resolveWorkletsConfig, rolldown, rolldownExperimental, runBuild, runServer, setupInteractiveMode };
@@ -14,6 +14,14 @@ const command = {
14
14
  description: "Path to the CLI configuration file",
15
15
  parse: resolvePath
16
16
  },
17
+ {
18
+ name: "--config-cmd <string>",
19
+ description: "Accepted for React Native Xcode compatibility; ignored."
20
+ },
21
+ {
22
+ name: "--load-config <string>",
23
+ description: "Accepted for React Native Xcode compatibility; ignored."
24
+ },
17
25
  {
18
26
  name: "--entry-file <path>",
19
27
  description: "Path to the root JS file, either absolute or relative to JS root"
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "1.0.0-beta.2";
2
+ var version = "1.0.0-beta.3";
3
3
  //#endregion
4
4
  export { version };
@@ -21,7 +21,7 @@ var RollipopDevframeController = class {
21
21
  this.definition = defineDevframe({
22
22
  id: "rollipop",
23
23
  name: "Rollipop",
24
- version: "1.0.0-beta.2",
24
+ version: "1.0.0-beta.3",
25
25
  packageName: "rollipop",
26
26
  homepage: "https://github.com/rollipop-dev/rollipop",
27
27
  description: "React Native development dashboard powered by Rollipop.",
@@ -16,7 +16,7 @@ async function setupDevframe(context, server, inspectorDeviceServer) {
16
16
  const controller = new RollipopDevframeController(context, createAgentToolContext(context));
17
17
  const devtools = initHub({
18
18
  name: DEVFRAME_NAME,
19
- version: "1.0.0-beta.2",
19
+ version: "1.0.0-beta.3",
20
20
  base: ROLLIPOP_DEVFRAME_BASE,
21
21
  cwd: context.config.root,
22
22
  ui: createUi({
@@ -39,6 +39,9 @@ async function setupDevframe(context, server, inspectorDeviceServer) {
39
39
  mcp: mcpEnabled ? { path: ROLLIPOP_DEVFRAME_MCP_PATH } : false,
40
40
  origin: context.serverBaseUrl,
41
41
  configure: async (devtoolsContext) => {
42
+ (await devtoolsContext.rpc.sharedState.get("devframe:user-settings")).mutate((state) => {
43
+ state.autoCollapseEdgeToolbar ??= false;
44
+ });
42
45
  await controller.definition.setup(devtoolsContext);
43
46
  await invokeDevToolsSetup(devtoolsContext, server, context.config.plugins ?? []);
44
47
  }
@@ -28,7 +28,7 @@ var FileStorage = class FileStorage {
28
28
  this.dataFilePath = path.join(FileStorage.getPath(basePath, { prepare: true }), DATA_FILENAME);
29
29
  if (fs.existsSync(this.dataFilePath)) {
30
30
  const loadedData = JSON.parse(fs.readFileSync(this.dataFilePath, "utf-8"));
31
- if ("version" in loadedData && loadedData.version === "1.0.0-beta.2") this.data = loadedData;
31
+ if ("version" in loadedData && loadedData.version === "1.0.0-beta.3") this.data = loadedData;
32
32
  else {
33
33
  this.data = createDefaultData();
34
34
  this.flush();
@@ -1,3 +1,4 @@
1
+ import { resolveWorkletsConfig } from "./worklets.js";
1
2
  import { RollipopReactNativeTransformer } from "@rollipop/rolldown/experimental";
2
3
  //#region src/utils/transform.ts
3
4
  const transformers = /* @__PURE__ */ new WeakMap();
@@ -8,7 +9,7 @@ function transformWithRollipop(id, code, config) {
8
9
  envName: config.mode,
9
10
  runtimeTarget: config.runtimeTarget,
10
11
  flow: config.transform.flow,
11
- worklets: config.experimental.worklets,
12
+ worklets: resolveWorkletsConfig(config.experimental.worklets, config),
12
13
  swc: {
13
14
  externalHelpers: true,
14
15
  ...config.transform.swc?.native
@@ -0,0 +1,7 @@
1
+ import { RollipopReactNativeWorkletsConfig as WorkletsConfig } from "../config/types.js";
2
+ import "../config/index.js";
3
+ import { ResolvedConfig } from "../config/defaults.js";
4
+ import { RollipopReactNativeWorkletsConfig } from "@rollipop/rolldown/experimental";
5
+ //#region src/utils/worklets.d.ts
6
+ export declare function resolveWorkletsConfig(worklets: WorkletsConfig | undefined, { root, mode }: Pick<ResolvedConfig, 'root' | 'mode'>): RollipopReactNativeWorkletsConfig | undefined;
7
+ //#endregion
@@ -0,0 +1,32 @@
1
+ import { resolvePackageJson } from "./node-resolve.js";
2
+ import { satisfies } from "semver";
3
+ //#region src/utils/worklets.ts
4
+ function resolveWorkletsConfig(worklets, { root, mode }) {
5
+ if (worklets == null) return;
6
+ const { pluginVersion, reanimatedVersion, ...options } = worklets;
7
+ const defaults = {
8
+ ...options,
9
+ isRelease: options.isRelease ?? mode === "production"
10
+ };
11
+ if (pluginVersion != null) return {
12
+ ...defaults,
13
+ pluginVersion
14
+ };
15
+ if (reanimatedVersion != null) return {
16
+ ...defaults,
17
+ reanimatedVersion
18
+ };
19
+ const installedReanimatedVersion = resolvePackageJson(root, "react-native-reanimated")?.version;
20
+ if (installedReanimatedVersion != null && satisfies(installedReanimatedVersion, "3.x", { includePrerelease: true })) return {
21
+ ...defaults,
22
+ reanimatedVersion: installedReanimatedVersion
23
+ };
24
+ const installedWorkletsVersion = resolvePackageJson(root, "react-native-worklets")?.version;
25
+ if (installedWorkletsVersion != null) return {
26
+ ...defaults,
27
+ pluginVersion: installedWorkletsVersion
28
+ };
29
+ throw new Error("Could not resolve a worklet runtime. Install react-native-reanimated 3.x or react-native-worklets, or set reanimatedVersion or pluginVersion in the worklets configuration.");
30
+ }
31
+ //#endregion
32
+ export { resolveWorkletsConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollipop",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "homepage": "https://github.com/rollipop-dev/rollipop#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/rollipop-dev/rollipop/issues"
@@ -67,8 +67,8 @@
67
67
  "@react-native-community/cli-server-api": "20.2.0",
68
68
  "@react-native-community/cli-types": "20.2.0",
69
69
  "@react-native/dev-middleware": "0.88.0",
70
- "@rollipop/dashboard": "1.0.0-beta.2",
71
- "@rollipop/rolldown": "1.1.1",
70
+ "@rollipop/dashboard": "1.0.0-beta.3",
71
+ "@rollipop/rolldown": "1.2.0",
72
72
  "@swc/core": "1.16.13",
73
73
  "@swc/helpers": "0.5.23",
74
74
  "@types/ws": "8.18.2",
@@ -2,12 +2,13 @@ import fs from 'node:fs';
2
2
  import { stripVTControlCharacters } from 'node:util';
3
3
  import vm from 'node:vm';
4
4
 
5
+ import { DevRuntime } from '@rollipop/rolldown/experimental/runtime';
5
6
  import { transformSync } from '@swc/core';
6
7
  import * as prettyFormat from 'pretty-format';
7
8
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vite-plus/test';
8
9
 
9
10
  import type { HMRContext } from '../../types/hmr';
10
- import type { HMRGraphRuntime, ModuleGraphDelta } from '../../types/runtime';
11
+ import type { HMRGraphRuntime } from '../../types/runtime';
11
12
 
12
13
  const clientCode = transformSync(
13
14
  fs.readFileSync(new URL('../hmr-client.ts', import.meta.url), 'utf8'),
@@ -18,73 +19,6 @@ const clientCode = transformSync(
18
19
  },
19
20
  ).code;
20
21
 
21
- class FakeDevRuntime {
22
- clientId: string;
23
- hooks: {
24
- createModuleHotContext(moduleId: string): unknown;
25
- onModuleCacheRemoval(moduleId: string): void;
26
- } | null = null;
27
- private readonly factories = new Map<string, (id: string) => void>();
28
- private readonly importers = new Map<string, Set<string>>();
29
- private readonly modules = new Map<string, { exports: any }>();
30
-
31
- constructor(clientId: string) {
32
- this.clientId = clientId;
33
- }
34
-
35
- registerGraph(delta: ModuleGraphDelta) {
36
- for (let index = 0; index < delta.localCount; index++) {
37
- const importer = delta.ids[index];
38
- for (const targetIndex of delta.edges[index]) {
39
- const target = delta.ids[targetIndex];
40
- const importers = this.importers.get(target) ?? new Set();
41
- importers.add(importer);
42
- this.importers.set(target, importers);
43
- }
44
- }
45
- }
46
-
47
- registerFactory(id: string, _kind: 'esm' | 'cjs', factory: (id: string) => void) {
48
- this.factories.set(id, factory);
49
- }
50
-
51
- registerModule(id: string, exportsHolder: { exports: any }) {
52
- this.modules.set(id, exportsHolder);
53
- }
54
-
55
- getImporters(id: string) {
56
- return [...(this.importers.get(id) ?? [])];
57
- }
58
-
59
- isExecuted(id: string) {
60
- return this.modules.has(id);
61
- }
62
-
63
- hasFactory(id: string) {
64
- return this.factories.has(id);
65
- }
66
-
67
- removeModuleCache(id: string) {
68
- this.modules.delete(id);
69
- this.hooks?.onModuleCacheRemoval(id);
70
- }
71
-
72
- initModule(id: string) {
73
- if (!this.modules.has(id)) {
74
- this.factories.get(id)?.(id);
75
- }
76
- return this.loadExports(id);
77
- }
78
-
79
- loadExports(id: string) {
80
- return this.modules.get(id)?.exports ?? {};
81
- }
82
-
83
- createModuleHotContext(moduleId: string) {
84
- return this.hooks?.createModuleHotContext(moduleId);
85
- }
86
- }
87
-
88
22
  class FakeWebSocket {
89
23
  static readonly CONNECTING = 0;
90
24
  static readonly OPEN = 1;
@@ -124,7 +58,7 @@ describe('HMR runtime', () => {
124
58
  reload.mockReset();
125
59
  FakeWebSocket.instances = [];
126
60
  Object.assign(globalThis, {
127
- DevRuntime: FakeDevRuntime,
61
+ DevRuntime,
128
62
  WebSocket: FakeWebSocket,
129
63
  __rollipop_runtime__: undefined,
130
64
  __turboModuleProxy: undefined,
@@ -133,6 +67,7 @@ describe('HMR runtime', () => {
133
67
  });
134
68
 
135
69
  afterEach(() => {
70
+ delete (globalThis as any).__rollipop_require__;
136
71
  delete (globalThis as any).globalEvalWithSourceUrl;
137
72
  delete (globalThis as any).__rollipop_runtime__;
138
73
  });
@@ -143,6 +78,145 @@ describe('HMR runtime', () => {
143
78
  expect((runtime.createModuleHotContext('entry.js') as any).runtime).toBe(runtime);
144
79
  });
145
80
 
81
+ describe('initial bundle factories and cache', () => {
82
+ it.each(['esm', 'cjs'])(
83
+ 'reuses an initial %s factory after eviction through either executor',
84
+ async (kind) => {
85
+ const { runtime } = await setupRuntime();
86
+ const bundleRequire = createBundleRequire();
87
+ let executions = 0;
88
+ bundleRequire.m['parent.js'] = (_global, module, exports) => {
89
+ const value = ++executions;
90
+ if (kind === 'esm') {
91
+ Object.defineProperty(exports, 'value', { get: () => value });
92
+ runtime.registerModule('parent.js', { exports });
93
+ } else {
94
+ runtime.registerModule('parent.js', module);
95
+ module.exports = () => value;
96
+ }
97
+ };
98
+ const readValue = (exports: any) => (kind === 'esm' ? exports.value : exports());
99
+
100
+ expect(runtime.hasFactory('parent.js')).toBe(true);
101
+ expect(runtime.isExecuted('parent.js')).toBe(false);
102
+ const first = bundleRequire('parent.js');
103
+ expect(runtime.initModule('parent.js')).toBe(first);
104
+ expect(runtime.loadExports('parent.js')).toBe(first);
105
+ expect(readValue(first)).toBe(1);
106
+
107
+ runtime.removeModuleCache('parent.js');
108
+ expect(bundleRequire.c['parent.js']).toBeUndefined();
109
+ expect(runtime.isExecuted('parent.js')).toBe(false);
110
+ const second = runtime.initModule('parent.js');
111
+ expect(bundleRequire('parent.js')).toBe(second);
112
+ expect(readValue(second)).toBe(2);
113
+
114
+ runtime.removeModuleCache('parent.js');
115
+ const third = bundleRequire('parent.js');
116
+ expect(runtime.loadExports('parent.js')).toBe(third);
117
+ expect(readValue(third)).toBe(3);
118
+ },
119
+ );
120
+
121
+ it.each(['esm', 'cjs'])(
122
+ 'uses the latest %s patch from ordinary require after repeated eviction',
123
+ async (kind) => {
124
+ const { runtime } = await setupRuntime();
125
+ const bundleRequire = createBundleRequire();
126
+ const original = vi.fn((_global, module: BundleModule) => {
127
+ runtime.registerModule('dep.js', module);
128
+ module.exports = { value: 'initial' };
129
+ });
130
+ bundleRequire.m['dep.js'] = original;
131
+ expect(bundleRequire('dep.js')).toEqual({ value: 'initial' });
132
+
133
+ for (let version = 1; version <= 2; version++) {
134
+ const factory = vi.fn((id: string) => {
135
+ const holder = { exports: {} as any };
136
+ runtime.registerModule(id, holder);
137
+ if (kind === 'esm') {
138
+ Object.defineProperty(holder.exports, 'value', { get: () => version });
139
+ } else {
140
+ holder.exports = () => version;
141
+ }
142
+ });
143
+ runtime.registerFactory('dep.js', factory, version);
144
+ runtime.removeModuleCache('dep.js');
145
+ const updated = runtime.initModule('dep.js');
146
+ expect(bundleRequire('dep.js')).toBe(updated);
147
+ expect(kind === 'esm' ? (updated as any).value : (updated as any)()).toBe(version);
148
+
149
+ const stale = vi.fn();
150
+ runtime.registerFactory('dep.js', stale, version - 1);
151
+ runtime.removeModuleCache('dep.js');
152
+ const reexecuted = bundleRequire('dep.js');
153
+ expect(runtime.initModule('dep.js')).toBe(reexecuted);
154
+ expect(runtime.loadExports('dep.js')).toBe(reexecuted);
155
+ expect(kind === 'esm' ? reexecuted.value : reexecuted()).toBe(version);
156
+ expect(factory).toHaveBeenCalledTimes(2);
157
+ expect(stale).not.toHaveBeenCalled();
158
+ }
159
+ expect(original).toHaveBeenCalledOnce();
160
+ },
161
+ );
162
+
163
+ it.each([null, undefined, 0, false])(
164
+ 'shares CommonJS module.exports reassignment to %s',
165
+ async (value) => {
166
+ const { runtime } = await setupRuntime();
167
+ const bundleRequire = createBundleRequire();
168
+ const module = { exports: {} as any };
169
+ runtime.registerModule('dep.cjs', module);
170
+ module.exports = value;
171
+ expect(bundleRequire('dep.cjs')).toBe(value);
172
+ expect(runtime.loadExports('dep.cjs')).toBe(value);
173
+ expect(runtime.initModule('dep.cjs')).toBe(value);
174
+ },
175
+ );
176
+
177
+ it('recognizes modules cached only by the bundle and removes both caches before disposal', async () => {
178
+ const { runtime } = await setupRuntime();
179
+ const bundleRequire = createBundleRequire();
180
+ const exports = { value: 'cached' };
181
+ bundleRequire.c['helper.js'] = { exports };
182
+ expect(runtime.isExecuted('helper.js')).toBe(true);
183
+ expect(runtime.loadExports('helper.js')).toBe(exports);
184
+ expect(runtime.initModule('helper.js')).toBe(exports);
185
+ const dispose = vi.fn(() => {
186
+ expect(bundleRequire.c['helper.js']).toBeUndefined();
187
+ expect(runtime.isExecuted('helper.js')).toBe(false);
188
+ });
189
+ runtime.createModuleHotContext('helper.js').dispose(dispose);
190
+ runtime.removeModuleCache('helper.js');
191
+ expect(dispose).toHaveBeenCalledOnce();
192
+ });
193
+
194
+ it('shares the bundle holder when a side-effect module registers without exports', async () => {
195
+ const { runtime } = await setupRuntime();
196
+ const bundleRequire = createBundleRequire();
197
+ bundleRequire.m['side-effect.js'] = () => runtime.registerModule('side-effect.js');
198
+ const exports = bundleRequire('side-effect.js');
199
+ expect(bundleRequire('side-effect.js')).toBe(exports);
200
+ expect(runtime.initModule('side-effect.js')).toBe(exports);
201
+ expect(runtime.loadExports('side-effect.js')).toBe(exports);
202
+ });
203
+
204
+ it('reloads when an invalidated non-component module has no accepting ancestor', async () => {
205
+ const { runtime } = await setupRuntime();
206
+ const bundleRequire = createBundleRequire();
207
+ runtime.registerGraph({ ids: ['route.js', 'entry.js'], localCount: 2, edges: [[], [0]] });
208
+ const entry = vi.fn((_global, module: BundleModule) => {
209
+ runtime.registerModule('entry.js', module);
210
+ runtime.registerModule('route.js', { exports: { Router: {} } });
211
+ });
212
+ bundleRequire.m['entry.js'] = entry;
213
+ bundleRequire('entry.js');
214
+ runtime.createModuleHotContext('route.js').invalidate();
215
+ await vi.waitFor(() => expect(reload).toHaveBeenCalledOnce());
216
+ expect(entry).toHaveBeenCalledOnce();
217
+ });
218
+ });
219
+
146
220
  describe('client logs', () => {
147
221
  const formatter = { format: prettyFormat.format, plugins: prettyFormat.plugins };
148
222
 
@@ -527,7 +601,7 @@ describe('HMR runtime', () => {
527
601
  const evaluate = vi.fn((source: string) => (0, eval)(source));
528
602
  globalThis.globalEvalWithSourceUrl = evaluate;
529
603
  const { runtime, socket } = await setupRuntime();
530
- runtime.registerFactory('dep.js', 'esm', (id) => {
604
+ runtime.registerFactory('dep.js', (id) => {
531
605
  runtime.registerModule(id, { exports: { value: 'before' } });
532
606
  });
533
607
 
@@ -565,7 +639,7 @@ describe('HMR runtime', () => {
565
639
  });
566
640
  runtime.registerModule('dep.js', { exports: {} });
567
641
  runtime.registerModule('entry.js', { exports: { value: 'before' } });
568
- runtime.registerFactory('entry.js', 'esm', (id) => {
642
+ runtime.registerFactory('entry.js', (id) => {
569
643
  runtime.registerModule(id, { exports: { value: 'after' } });
570
644
  runtime.createModuleHotContext(id).accept();
571
645
  });
@@ -711,9 +785,34 @@ function createPatch(value: string, createHotContext = true) {
711
785
  edges: [[], [0]],
712
786
  dynamicEdges: [[], []]
713
787
  });
714
- __rolldown_runtime__.registerFactory("dep.js", "esm", function (id) {
788
+ __rolldown_runtime__.registerFactory("dep.js", function (id) {
715
789
  __rolldown_runtime__.registerModule(id, { exports: { value: "${value}" } });
716
790
  ${createHotContext ? '__rolldown_runtime__.createModuleHotContext(id);' : ''}
717
791
  });
718
792
  })(globalThis.__rollipop_runtime__.graphs.get("host").runtime);`;
719
793
  }
794
+
795
+ type BundleModule = { exports: any };
796
+ type BundleRequire = {
797
+ (id: string): any;
798
+ m: Record<
799
+ string,
800
+ (global: unknown, module: BundleModule, exports: any, require: BundleRequire) => void
801
+ >;
802
+ c: Record<string, BundleModule>;
803
+ };
804
+
805
+ function createBundleRequire() {
806
+ const require: BundleRequire = Object.assign(
807
+ (id: string) => {
808
+ if (require.c[id] !== undefined) return require.c[id].exports;
809
+ const module = { exports: {} };
810
+ require.c[id] = module;
811
+ require.m[id].call(module.exports, globalThis, module, module.exports, require);
812
+ return module.exports;
813
+ },
814
+ { m: {} as BundleRequire['m'], c: {} as BundleRequire['c'] },
815
+ );
816
+ (globalThis as any).__rollipop_require__ = require;
817
+ return require;
818
+ }
@@ -315,7 +315,7 @@ class HMRClient implements HMRClientNativeInterface {
315
315
  case 'hmr:update-start':
316
316
  connection.pendingUpdatesCount++;
317
317
  connection.compileErrorMessage = null;
318
- DevLoadingView.showMessage(`Refreshing ${connection.graph.id}...`, 'refresh');
318
+ DevLoadingView.showMessage('Refreshing...', 'refresh');
319
319
  break;
320
320
  case 'hmr:update':
321
321
  this.dismissRedbox();
@@ -25,6 +25,19 @@ declare global {
25
25
  // DO NOT EDIT THIS CLASS NAME (`DevRuntime`)
26
26
  declare const DevRuntime: typeof DefaultDevRuntime;
27
27
 
28
+ type BundleModule = { exports: any };
29
+ interface BundleRequire {
30
+ (id: string): any;
31
+ m: Record<
32
+ string,
33
+ (global: unknown, module: BundleModule, exports: any, require: BundleRequire) => void
34
+ >;
35
+ c: Record<string, BundleModule>;
36
+ }
37
+
38
+ // Defined in the enclosing Rollipop bundle, separately for each bundle runtime.
39
+ declare const __rollipop_require__: BundleRequire;
40
+
28
41
  var BaseDevRuntime = DevRuntime;
29
42
 
30
43
  interface AcceptCallback {
@@ -194,6 +207,69 @@ class ReactNativeDevRuntime extends BaseDevRuntime {
194
207
  };
195
208
  }
196
209
 
210
+ hasFactory(moduleId: string) {
211
+ return (
212
+ super.hasFactory(moduleId) ||
213
+ (typeof __rollipop_require__ !== 'undefined' && __rollipop_require__.m[moduleId] != null)
214
+ );
215
+ }
216
+
217
+ isExecuted(moduleId: string) {
218
+ return (
219
+ super.isExecuted(moduleId) ||
220
+ (typeof __rollipop_require__ !== 'undefined' && __rollipop_require__.c[moduleId] != null)
221
+ );
222
+ }
223
+
224
+ loadExports(moduleId: string) {
225
+ if (!super.isExecuted(moduleId) && typeof __rollipop_require__ !== 'undefined') {
226
+ const module = __rollipop_require__.c[moduleId];
227
+ if (module != null) {
228
+ return module.exports;
229
+ }
230
+ }
231
+ return super.loadExports(moduleId);
232
+ }
233
+
234
+ initModule(moduleId: string) {
235
+ if (this.isExecuted(moduleId)) {
236
+ return this.loadExports(moduleId);
237
+ }
238
+ if (super.hasFactory(moduleId) || !this.hasFactory(moduleId)) {
239
+ return super.initModule(moduleId);
240
+ }
241
+ return __rollipop_require__(moduleId);
242
+ }
243
+
244
+ registerFactory(moduleId: string, factory: (id: string) => void, stamp?: number) {
245
+ super.registerFactory(moduleId, factory, stamp);
246
+ if (typeof __rollipop_require__ !== 'undefined') {
247
+ __rollipop_require__.m[moduleId] = (_global, module) => {
248
+ // require() has already inserted an empty cache entry.
249
+ // The base executor bypasses that entry and selects the latest factory accepted by its stamp.
250
+ module.exports = super.initModule(moduleId);
251
+ };
252
+ }
253
+ }
254
+
255
+ registerModule(moduleId: string, module?: BundleModule) {
256
+ module ??=
257
+ typeof __rollipop_require__ !== 'undefined' ? __rollipop_require__.c[moduleId] : undefined;
258
+ module ??= { exports: {} };
259
+ super.registerModule(moduleId, module);
260
+ if (typeof __rollipop_require__ !== 'undefined') {
261
+ // Share the holder itself so CommonJS module.exports reassignments stay live.
262
+ __rollipop_require__.c[moduleId] = module;
263
+ }
264
+ }
265
+
266
+ removeModuleCache(moduleId: string) {
267
+ if (typeof __rollipop_require__ !== 'undefined') {
268
+ delete __rollipop_require__.c[moduleId];
269
+ }
270
+ super.removeModuleCache(moduleId);
271
+ }
272
+
197
273
  private createHotContext(moduleId: string) {
198
274
  let data = this.moduleHotData.get(moduleId);
199
275
  if (data == null) {