react-email 2.1.1-canary.1 → 2.1.1

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.
Files changed (3) hide show
  1. package/cli/index.js +963 -108
  2. package/cli/index.mjs +300 -72
  3. package/package.json +5 -2
package/cli/index.js CHANGED
@@ -4,9 +4,53 @@ function _array_like_to_array(arr, len) {
4
4
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
5
  return arr2;
6
6
  }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
7
10
  function _array_without_holes(arr) {
8
11
  if (Array.isArray(arr)) return _array_like_to_array(arr);
9
12
  }
13
+ function _async_iterator(iterable) {
14
+ var method, async, sync, retry = 2;
15
+ for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
16
+ if (async && null != (method = iterable[async])) return method.call(iterable);
17
+ if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
18
+ async = "@@asyncIterator", sync = "@@iterator";
19
+ }
20
+ throw new TypeError("Object is not async iterable");
21
+ }
22
+ function AsyncFromSyncIterator(s) {
23
+ function AsyncFromSyncIteratorContinuation(r) {
24
+ if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
25
+ var done = r.done;
26
+ return Promise.resolve(r.value).then(function(value) {
27
+ return {
28
+ value: value,
29
+ done: done
30
+ };
31
+ });
32
+ }
33
+ return AsyncFromSyncIterator = function(s) {
34
+ this.s = s, this.n = s.next;
35
+ }, AsyncFromSyncIterator.prototype = {
36
+ s: null,
37
+ n: null,
38
+ next: function() {
39
+ return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
40
+ },
41
+ return: function(value) {
42
+ var ret = this.s.return;
43
+ return void 0 === ret ? Promise.resolve({
44
+ value: value,
45
+ done: !0
46
+ }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
47
+ },
48
+ throw: function(value) {
49
+ var thr = this.s.return;
50
+ return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
51
+ }
52
+ }, new AsyncFromSyncIterator(s);
53
+ }
10
54
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
55
  try {
12
56
  var info = gen[key](arg);
@@ -52,6 +96,33 @@ function _define_property(obj, key, value) {
52
96
  function _iterable_to_array(iter) {
53
97
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
54
98
  }
99
+ function _iterable_to_array_limit(arr, i) {
100
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
101
+ if (_i == null) return;
102
+ var _arr = [];
103
+ var _n = true;
104
+ var _d = false;
105
+ var _s, _e;
106
+ try {
107
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
108
+ _arr.push(_s.value);
109
+ if (i && _arr.length === i) break;
110
+ }
111
+ } catch (err) {
112
+ _d = true;
113
+ _e = err;
114
+ } finally{
115
+ try {
116
+ if (!_n && _i["return"] != null) _i["return"]();
117
+ } finally{
118
+ if (_d) throw _e;
119
+ }
120
+ }
121
+ return _arr;
122
+ }
123
+ function _non_iterable_rest() {
124
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
125
+ }
55
126
  function _non_iterable_spread() {
56
127
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
128
  }
@@ -94,6 +165,9 @@ function _object_spread_props(target, source) {
94
165
  }
95
166
  return target;
96
167
  }
168
+ function _sliced_to_array(arr, i) {
169
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
170
+ }
97
171
  function _to_consumable_array(arr) {
98
172
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
99
173
  }
@@ -266,7 +340,7 @@ var import_commander = require("commander");
266
340
  // package.json
267
341
  var package_default = {
268
342
  name: "react-email",
269
- version: "2.1.1-canary.1",
343
+ version: "2.1.1",
270
344
  description: "A live preview of your emails right in your browser.",
271
345
  bin: {
272
346
  email: "./cli/index.js"
@@ -275,6 +349,7 @@ var package_default = {
275
349
  build: "tsup",
276
350
  dev: "tsup --watch",
277
351
  test: "vitest run",
352
+ "test:watch": "vitest",
278
353
  clean: "rm -rf dist",
279
354
  lint: "eslint . && tsc"
280
355
  },
@@ -292,19 +367,21 @@ var package_default = {
292
367
  node: ">=18.0.0"
293
368
  },
294
369
  dependencies: {
370
+ "@babel/parser": "7.24.1",
295
371
  "@radix-ui/colors": "1.0.1",
296
372
  "@radix-ui/react-collapsible": "1.0.3",
297
373
  "@radix-ui/react-popover": "1.0.7",
298
374
  "@radix-ui/react-slot": "1.0.2",
299
375
  "@radix-ui/react-toggle-group": "1.0.4",
300
376
  "@radix-ui/react-tooltip": "1.0.6",
301
- "@react-email/components": "0.0.16-canary.1",
377
+ "@react-email/components": "0.0.16",
302
378
  "@react-email/render": "0.0.12",
303
379
  "@swc/core": "1.3.101",
304
380
  "@types/react": "^18.2.0",
305
381
  "@types/react-dom": "^18.2.0",
306
382
  "@types/webpack": "5.28.5",
307
383
  autoprefixer: "10.4.14",
384
+ "babel-walk": "3.0.0",
308
385
  chalk: "4.1.2",
309
386
  chokidar: "3.5.3",
310
387
  clsx: "2.1.0",
@@ -349,7 +426,7 @@ var package_default = {
349
426
  }
350
427
  };
351
428
  // src/cli/commands/dev.ts
352
- var import_node_fs3 = __toESM(require("fs"));
429
+ var import_node_fs4 = __toESM(require("fs"));
353
430
  // src/cli/utils/tree.ts
354
431
  var import_node_fs = require("fs");
355
432
  var import_node_os = __toESM(require("os"));
@@ -493,55 +570,823 @@ var tree = function() {
493
570
  return _ref.apply(this, arguments);
494
571
  };
495
572
  }();
496
- // src/cli/utils/preview/setup-hot-reloading.ts
497
- var import_node_path2 = __toESM(require("path"));
573
+ // src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
574
+ var import_node_path3 = __toESM(require("path"));
498
575
  var import_socket = require("socket.io");
499
576
  var import_chokidar = require("chokidar");
500
577
  var import_debounce = __toESM(require("debounce"));
501
- var setupHotreloading = function(devServer2, emailDirRelativePath) {
502
- var clients = [];
503
- var io = new import_socket.Server(devServer2);
504
- io.on("connection", function(client) {
505
- clients.push(client);
506
- client.on("disconnect", function() {
507
- clients = clients.filter(function(item) {
508
- return item !== client;
509
- });
510
- });
578
+ // src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
579
+ var import_node_path2 = __toESM(require("path"));
580
+ var import_node_fs2 = require("fs");
581
+ // src/cli/utils/preview/hot-reloading/get-imported-modules.ts
582
+ var import_parser = require("@babel/parser");
583
+ var walk = __toESM(require("babel-walk"));
584
+ var importVisitor = walk.simple({
585
+ ImportDeclaration: function ImportDeclaration(node, importedPaths) {
586
+ importedPaths.push(node.source.value);
587
+ },
588
+ CallExpression: function CallExpression(node, importedPaths) {
589
+ if ("name" in node.callee && node.callee.name === "require") {
590
+ if (node.arguments.length === 1) {
591
+ var importPathNode = node.arguments[0];
592
+ if (importPathNode.type === "StringLiteral") {
593
+ importedPaths.push(importPathNode.value);
594
+ }
595
+ }
596
+ }
597
+ }
598
+ });
599
+ var getImportedModules = function(contents) {
600
+ var importedPaths = [];
601
+ var parsedContents = (0, import_parser.parse)(contents, {
602
+ sourceType: "unambiguous",
603
+ strictMode: false,
604
+ errorRecovery: true,
605
+ plugins: [
606
+ "jsx",
607
+ "typescript"
608
+ ]
511
609
  });
512
- var watcher = (0, import_chokidar.watch)(emailDirRelativePath, {
513
- ignoreInitial: true,
514
- cwd: import_node_path2.default.resolve(process.cwd()),
515
- // eslint-disable-next-line prefer-named-capture-group
516
- ignored: /(^|[/\\])\../
610
+ importVisitor(parsedContents, importedPaths);
611
+ return importedPaths;
612
+ };
613
+ // src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
614
+ var readAllFilesInsideDirectory = function() {
615
+ var _ref = _async_to_generator(function(directory) {
616
+ var allFilePaths, topLevelDirents, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, dirent, pathToDirent, _, err;
617
+ return _ts_generator(this, function(_state) {
618
+ switch(_state.label){
619
+ case 0:
620
+ allFilePaths = [];
621
+ return [
622
+ 4,
623
+ import_node_fs2.promises.readdir(directory, {
624
+ withFileTypes: true
625
+ })
626
+ ];
627
+ case 1:
628
+ topLevelDirents = _state.sent();
629
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
630
+ _state.label = 2;
631
+ case 2:
632
+ _state.trys.push([
633
+ 2,
634
+ 9,
635
+ 10,
636
+ 15
637
+ ]);
638
+ _iterator = _async_iterator(topLevelDirents);
639
+ _state.label = 3;
640
+ case 3:
641
+ return [
642
+ 4,
643
+ _iterator.next()
644
+ ];
645
+ case 4:
646
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
647
+ 3,
648
+ 8
649
+ ];
650
+ _value = _step.value;
651
+ dirent = _value;
652
+ pathToDirent = import_node_path2.default.join(directory, dirent.name);
653
+ if (!dirent.isDirectory()) return [
654
+ 3,
655
+ 6
656
+ ];
657
+ _ = allFilePaths.concat;
658
+ return [
659
+ 4,
660
+ readAllFilesInsideDirectory(pathToDirent)
661
+ ];
662
+ case 5:
663
+ allFilePaths = _.apply(allFilePaths, [
664
+ _state.sent()
665
+ ]);
666
+ return [
667
+ 3,
668
+ 7
669
+ ];
670
+ case 6:
671
+ allFilePaths.push(pathToDirent);
672
+ _state.label = 7;
673
+ case 7:
674
+ _iteratorAbruptCompletion = false;
675
+ return [
676
+ 3,
677
+ 3
678
+ ];
679
+ case 8:
680
+ return [
681
+ 3,
682
+ 15
683
+ ];
684
+ case 9:
685
+ err = _state.sent();
686
+ _didIteratorError = true;
687
+ _iteratorError = err;
688
+ return [
689
+ 3,
690
+ 15
691
+ ];
692
+ case 10:
693
+ _state.trys.push([
694
+ 10,
695
+ ,
696
+ 13,
697
+ 14
698
+ ]);
699
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
700
+ 3,
701
+ 12
702
+ ];
703
+ return [
704
+ 4,
705
+ _iterator.return()
706
+ ];
707
+ case 11:
708
+ _state.sent();
709
+ _state.label = 12;
710
+ case 12:
711
+ return [
712
+ 3,
713
+ 14
714
+ ];
715
+ case 13:
716
+ if (_didIteratorError) {
717
+ throw _iteratorError;
718
+ }
719
+ return [
720
+ 7
721
+ ];
722
+ case 14:
723
+ return [
724
+ 7
725
+ ];
726
+ case 15:
727
+ return [
728
+ 2,
729
+ allFilePaths
730
+ ];
731
+ }
732
+ });
517
733
  });
518
- var exit = function() {
519
- void watcher.close();
734
+ return function readAllFilesInsideDirectory(directory) {
735
+ return _ref.apply(this, arguments);
520
736
  };
521
- process.on("SIGINT", exit);
522
- process.on("uncaughtException", exit);
523
- var changes = [];
524
- var reload = (0, import_debounce.default)(function() {
525
- clients.forEach(function(client) {
526
- client.emit("reload", changes);
737
+ }();
738
+ var isJavascriptModule = function(filePath) {
739
+ var extensionName = import_node_path2.default.extname(filePath);
740
+ return [
741
+ ".js",
742
+ ".ts",
743
+ ".jsx",
744
+ ".tsx",
745
+ ".mjs",
746
+ ".cjs"
747
+ ].includes(extensionName);
748
+ };
749
+ var createDependencyGraph = function() {
750
+ var _ref = _async_to_generator(function(directory) {
751
+ var filePaths, modulePaths, graph, getDependencyPaths, updateModuleDependenciesInGraph, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, filePath, err, removeModuleFromGraph;
752
+ return _ts_generator(this, function(_state) {
753
+ switch(_state.label){
754
+ case 0:
755
+ return [
756
+ 4,
757
+ readAllFilesInsideDirectory(directory)
758
+ ];
759
+ case 1:
760
+ filePaths = _state.sent();
761
+ modulePaths = filePaths.filter(isJavascriptModule);
762
+ graph = Object.fromEntries(modulePaths.map(function(path11) {
763
+ return [
764
+ path11,
765
+ {
766
+ path: path11,
767
+ dependencyPaths: [],
768
+ dependentPaths: [],
769
+ moduleDependencies: []
770
+ }
771
+ ];
772
+ }));
773
+ getDependencyPaths = function() {
774
+ var _ref = _async_to_generator(function(filePath) {
775
+ var contents, importedPaths, importedPathsRelativeToDirectory, moduleDependencies, nonNodeModuleImportPathsRelativeToDirectory;
776
+ return _ts_generator(this, function(_state) {
777
+ switch(_state.label){
778
+ case 0:
779
+ return [
780
+ 4,
781
+ import_node_fs2.promises.readFile(filePath, "utf8")
782
+ ];
783
+ case 1:
784
+ contents = _state.sent();
785
+ importedPaths = getImportedModules(contents);
786
+ importedPathsRelativeToDirectory = importedPaths.map(function(dependencyPath) {
787
+ var isModulePath = !dependencyPath.startsWith(".");
788
+ if (!isModulePath && !import_node_path2.default.isAbsolute(dependencyPath)) {
789
+ var pathToDependencyFromDirectory = import_node_path2.default.resolve(/*
790
+ path.resolve resolves paths differently from what imports on javascript do.
791
+
792
+ So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
793
+ would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
794
+ one the import is meant to go to
795
+ */ import_node_path2.default.dirname(filePath), dependencyPath);
796
+ if (!isJavascriptModule(pathToDependencyFromDirectory)) {
797
+ pathToDependencyFromDirectory = "".concat(pathToDependencyFromDirectory).concat(import_node_path2.default.extname(filePath));
798
+ }
799
+ return pathToDependencyFromDirectory;
800
+ } else {
801
+ return dependencyPath;
802
+ }
803
+ });
804
+ moduleDependencies = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
805
+ return !dependencyPath.startsWith(".") && !import_node_path2.default.isAbsolute(dependencyPath);
806
+ });
807
+ nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
808
+ return dependencyPath.startsWith(".") || import_node_path2.default.isAbsolute(dependencyPath);
809
+ });
810
+ return [
811
+ 2,
812
+ {
813
+ dependencyPaths: nonNodeModuleImportPathsRelativeToDirectory,
814
+ moduleDependencies: moduleDependencies
815
+ }
816
+ ];
817
+ }
818
+ });
819
+ });
820
+ return function getDependencyPaths(filePath) {
821
+ return _ref.apply(this, arguments);
822
+ };
823
+ }();
824
+ updateModuleDependenciesInGraph = function() {
825
+ var _ref = _async_to_generator(function(moduleFilePath) {
826
+ var _graph_moduleFilePath, module2, _ref, moduleDependencies, newDependencyPaths, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, dependencyPath, dependencyModule, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, dependencyPath1, dependencyModule1;
827
+ return _ts_generator(this, function(_state) {
828
+ switch(_state.label){
829
+ case 0:
830
+ module2 = (_graph_moduleFilePath = graph[moduleFilePath]) !== null && _graph_moduleFilePath !== void 0 ? _graph_moduleFilePath : {
831
+ path: moduleFilePath,
832
+ dependencyPaths: [],
833
+ dependentPaths: [],
834
+ moduleDependencies: []
835
+ };
836
+ return [
837
+ 4,
838
+ getDependencyPaths(moduleFilePath)
839
+ ];
840
+ case 1:
841
+ _ref = _state.sent(), moduleDependencies = _ref.moduleDependencies, newDependencyPaths = _ref.dependencyPaths;
842
+ module2.moduleDependencies = moduleDependencies;
843
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
844
+ try {
845
+ for(_iterator = module2.dependencyPaths[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
846
+ dependencyPath = _step.value;
847
+ if (newDependencyPaths.includes(dependencyPath)) continue;
848
+ dependencyModule = graph[dependencyPath];
849
+ if (dependencyModule !== void 0) {
850
+ dependencyModule.dependentPaths = dependencyModule.dependentPaths.filter(function(dependentPath) {
851
+ return dependentPath !== moduleFilePath;
852
+ });
853
+ }
854
+ }
855
+ } catch (err) {
856
+ _didIteratorError = true;
857
+ _iteratorError = err;
858
+ } finally{
859
+ try {
860
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
861
+ _iterator.return();
862
+ }
863
+ } finally{
864
+ if (_didIteratorError) {
865
+ throw _iteratorError;
866
+ }
867
+ }
868
+ }
869
+ module2.dependencyPaths = newDependencyPaths;
870
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
871
+ try {
872
+ for(_iterator1 = newDependencyPaths[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
873
+ dependencyPath1 = _step1.value;
874
+ dependencyModule1 = graph[dependencyPath1];
875
+ if (dependencyModule1 !== void 0 && !dependencyModule1.dependentPaths.includes(moduleFilePath)) {
876
+ dependencyModule1.dependentPaths.push(moduleFilePath);
877
+ } else {
878
+ graph[dependencyPath1] = {
879
+ path: dependencyPath1,
880
+ moduleDependencies: [],
881
+ dependencyPaths: [],
882
+ dependentPaths: [
883
+ moduleFilePath
884
+ ]
885
+ };
886
+ }
887
+ }
888
+ } catch (err) {
889
+ _didIteratorError1 = true;
890
+ _iteratorError1 = err;
891
+ } finally{
892
+ try {
893
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
894
+ _iterator1.return();
895
+ }
896
+ } finally{
897
+ if (_didIteratorError1) {
898
+ throw _iteratorError1;
899
+ }
900
+ }
901
+ }
902
+ graph[moduleFilePath] = module2;
903
+ return [
904
+ 2
905
+ ];
906
+ }
907
+ });
908
+ });
909
+ return function updateModuleDependenciesInGraph(moduleFilePath) {
910
+ return _ref.apply(this, arguments);
911
+ };
912
+ }();
913
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
914
+ _state.label = 2;
915
+ case 2:
916
+ _state.trys.push([
917
+ 2,
918
+ 7,
919
+ 8,
920
+ 9
921
+ ]);
922
+ _iterator = modulePaths[Symbol.iterator]();
923
+ _state.label = 3;
924
+ case 3:
925
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
926
+ 3,
927
+ 6
928
+ ];
929
+ filePath = _step.value;
930
+ return [
931
+ 4,
932
+ updateModuleDependenciesInGraph(filePath)
933
+ ];
934
+ case 4:
935
+ _state.sent();
936
+ _state.label = 5;
937
+ case 5:
938
+ _iteratorNormalCompletion = true;
939
+ return [
940
+ 3,
941
+ 3
942
+ ];
943
+ case 6:
944
+ return [
945
+ 3,
946
+ 9
947
+ ];
948
+ case 7:
949
+ err = _state.sent();
950
+ _didIteratorError = true;
951
+ _iteratorError = err;
952
+ return [
953
+ 3,
954
+ 9
955
+ ];
956
+ case 8:
957
+ try {
958
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
959
+ _iterator.return();
960
+ }
961
+ } finally{
962
+ if (_didIteratorError) {
963
+ throw _iteratorError;
964
+ }
965
+ }
966
+ return [
967
+ 7
968
+ ];
969
+ case 9:
970
+ removeModuleFromGraph = function(filePath) {
971
+ var module2 = graph[filePath];
972
+ if (module2) {
973
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
974
+ try {
975
+ for(var _iterator = module2.dependencyPaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
976
+ var dependencyPath = _step.value;
977
+ if (graph[dependencyPath]) {
978
+ graph[dependencyPath].dependentPaths = graph[dependencyPath].dependentPaths.filter(function(dependentPath) {
979
+ return dependentPath !== filePath;
980
+ });
981
+ }
982
+ }
983
+ } catch (err) {
984
+ _didIteratorError = true;
985
+ _iteratorError = err;
986
+ } finally{
987
+ try {
988
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
989
+ _iterator.return();
990
+ }
991
+ } finally{
992
+ if (_didIteratorError) {
993
+ throw _iteratorError;
994
+ }
995
+ }
996
+ }
997
+ delete graph[filePath];
998
+ }
999
+ };
1000
+ return [
1001
+ 2,
1002
+ [
1003
+ graph,
1004
+ function() {
1005
+ var _ref = /**
1006
+ * @param pathToModified - A path relative to the previosuly provided {@link directory}.
1007
+ */ _async_to_generator(function(event, pathToModified) {
1008
+ var filesInsideAddedDirectory, modulesInsideAddedDirectory, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, filePath, err, filesInsideDeletedDirectory, modulesInsideDeletedDirectory, _iteratorAbruptCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _value1, filePath1, err1;
1009
+ return _ts_generator(this, function(_state) {
1010
+ switch(_state.label){
1011
+ case 0:
1012
+ switch(event){
1013
+ case "change":
1014
+ return [
1015
+ 3,
1016
+ 1
1017
+ ];
1018
+ case "add":
1019
+ return [
1020
+ 3,
1021
+ 4
1022
+ ];
1023
+ case "addDir":
1024
+ return [
1025
+ 3,
1026
+ 7
1027
+ ];
1028
+ case "unlink":
1029
+ return [
1030
+ 3,
1031
+ 22
1032
+ ];
1033
+ case "unlinkDir":
1034
+ return [
1035
+ 3,
1036
+ 23
1037
+ ];
1038
+ }
1039
+ return [
1040
+ 3,
1041
+ 37
1042
+ ];
1043
+ case 1:
1044
+ if (!isJavascriptModule(pathToModified)) return [
1045
+ 3,
1046
+ 3
1047
+ ];
1048
+ return [
1049
+ 4,
1050
+ updateModuleDependenciesInGraph(pathToModified)
1051
+ ];
1052
+ case 2:
1053
+ _state.sent();
1054
+ _state.label = 3;
1055
+ case 3:
1056
+ return [
1057
+ 3,
1058
+ 37
1059
+ ];
1060
+ case 4:
1061
+ if (!isJavascriptModule(pathToModified)) return [
1062
+ 3,
1063
+ 6
1064
+ ];
1065
+ return [
1066
+ 4,
1067
+ updateModuleDependenciesInGraph(pathToModified)
1068
+ ];
1069
+ case 5:
1070
+ _state.sent();
1071
+ _state.label = 6;
1072
+ case 6:
1073
+ return [
1074
+ 3,
1075
+ 37
1076
+ ];
1077
+ case 7:
1078
+ return [
1079
+ 4,
1080
+ readAllFilesInsideDirectory(pathToModified)
1081
+ ];
1082
+ case 8:
1083
+ filesInsideAddedDirectory = _state.sent();
1084
+ modulesInsideAddedDirectory = filesInsideAddedDirectory.filter(isJavascriptModule);
1085
+ _iteratorAbruptCompletion = false, _didIteratorError = false;
1086
+ _state.label = 9;
1087
+ case 9:
1088
+ _state.trys.push([
1089
+ 9,
1090
+ 15,
1091
+ 16,
1092
+ 21
1093
+ ]);
1094
+ _iterator = _async_iterator(modulesInsideAddedDirectory);
1095
+ _state.label = 10;
1096
+ case 10:
1097
+ return [
1098
+ 4,
1099
+ _iterator.next()
1100
+ ];
1101
+ case 11:
1102
+ if (!(_iteratorAbruptCompletion = !(_step = _state.sent()).done)) return [
1103
+ 3,
1104
+ 14
1105
+ ];
1106
+ _value = _step.value;
1107
+ filePath = _value;
1108
+ return [
1109
+ 4,
1110
+ updateModuleDependenciesInGraph(filePath)
1111
+ ];
1112
+ case 12:
1113
+ _state.sent();
1114
+ _state.label = 13;
1115
+ case 13:
1116
+ _iteratorAbruptCompletion = false;
1117
+ return [
1118
+ 3,
1119
+ 10
1120
+ ];
1121
+ case 14:
1122
+ return [
1123
+ 3,
1124
+ 21
1125
+ ];
1126
+ case 15:
1127
+ err = _state.sent();
1128
+ _didIteratorError = true;
1129
+ _iteratorError = err;
1130
+ return [
1131
+ 3,
1132
+ 21
1133
+ ];
1134
+ case 16:
1135
+ _state.trys.push([
1136
+ 16,
1137
+ ,
1138
+ 19,
1139
+ 20
1140
+ ]);
1141
+ if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
1142
+ 3,
1143
+ 18
1144
+ ];
1145
+ return [
1146
+ 4,
1147
+ _iterator.return()
1148
+ ];
1149
+ case 17:
1150
+ _state.sent();
1151
+ _state.label = 18;
1152
+ case 18:
1153
+ return [
1154
+ 3,
1155
+ 20
1156
+ ];
1157
+ case 19:
1158
+ if (_didIteratorError) {
1159
+ throw _iteratorError;
1160
+ }
1161
+ return [
1162
+ 7
1163
+ ];
1164
+ case 20:
1165
+ return [
1166
+ 7
1167
+ ];
1168
+ case 21:
1169
+ return [
1170
+ 3,
1171
+ 37
1172
+ ];
1173
+ case 22:
1174
+ if (isJavascriptModule(pathToModified)) {
1175
+ removeModuleFromGraph(pathToModified);
1176
+ }
1177
+ return [
1178
+ 3,
1179
+ 37
1180
+ ];
1181
+ case 23:
1182
+ return [
1183
+ 4,
1184
+ readAllFilesInsideDirectory(pathToModified)
1185
+ ];
1186
+ case 24:
1187
+ filesInsideDeletedDirectory = _state.sent();
1188
+ modulesInsideDeletedDirectory = filesInsideDeletedDirectory.filter(isJavascriptModule);
1189
+ _iteratorAbruptCompletion1 = false, _didIteratorError1 = false;
1190
+ _state.label = 25;
1191
+ case 25:
1192
+ _state.trys.push([
1193
+ 25,
1194
+ 30,
1195
+ 31,
1196
+ 36
1197
+ ]);
1198
+ _iterator1 = _async_iterator(modulesInsideDeletedDirectory);
1199
+ _state.label = 26;
1200
+ case 26:
1201
+ return [
1202
+ 4,
1203
+ _iterator1.next()
1204
+ ];
1205
+ case 27:
1206
+ if (!(_iteratorAbruptCompletion1 = !(_step1 = _state.sent()).done)) return [
1207
+ 3,
1208
+ 29
1209
+ ];
1210
+ _value1 = _step1.value;
1211
+ filePath1 = _value1;
1212
+ removeModuleFromGraph(filePath1);
1213
+ _state.label = 28;
1214
+ case 28:
1215
+ _iteratorAbruptCompletion1 = false;
1216
+ return [
1217
+ 3,
1218
+ 26
1219
+ ];
1220
+ case 29:
1221
+ return [
1222
+ 3,
1223
+ 36
1224
+ ];
1225
+ case 30:
1226
+ err1 = _state.sent();
1227
+ _didIteratorError1 = true;
1228
+ _iteratorError1 = err1;
1229
+ return [
1230
+ 3,
1231
+ 36
1232
+ ];
1233
+ case 31:
1234
+ _state.trys.push([
1235
+ 31,
1236
+ ,
1237
+ 34,
1238
+ 35
1239
+ ]);
1240
+ if (!(_iteratorAbruptCompletion1 && _iterator1.return != null)) return [
1241
+ 3,
1242
+ 33
1243
+ ];
1244
+ return [
1245
+ 4,
1246
+ _iterator1.return()
1247
+ ];
1248
+ case 32:
1249
+ _state.sent();
1250
+ _state.label = 33;
1251
+ case 33:
1252
+ return [
1253
+ 3,
1254
+ 35
1255
+ ];
1256
+ case 34:
1257
+ if (_didIteratorError1) {
1258
+ throw _iteratorError1;
1259
+ }
1260
+ return [
1261
+ 7
1262
+ ];
1263
+ case 35:
1264
+ return [
1265
+ 7
1266
+ ];
1267
+ case 36:
1268
+ return [
1269
+ 3,
1270
+ 37
1271
+ ];
1272
+ case 37:
1273
+ return [
1274
+ 2
1275
+ ];
1276
+ }
1277
+ });
1278
+ });
1279
+ return function(event, pathToModified) {
1280
+ return _ref.apply(this, arguments);
1281
+ };
1282
+ }()
1283
+ ]
1284
+ ];
1285
+ }
527
1286
  });
528
- changes = [];
529
- }, 150);
530
- watcher.on("all", function(event, filename) {
531
- var file = filename.split(import_node_path2.default.sep);
532
- if (file.length === 0) {
533
- return;
534
- }
535
- changes.push({
536
- event: event,
537
- filename: filename
1287
+ });
1288
+ return function createDependencyGraph(directory) {
1289
+ return _ref.apply(this, arguments);
1290
+ };
1291
+ }();
1292
+ // src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
1293
+ var setupHotreloading = function() {
1294
+ var _ref = _async_to_generator(function(devServer2, emailDirRelativePath) {
1295
+ var clients, io, watcher, exit, changes, reload, absolutePathToEmailsDirectory, _ref, dependencyGraph, updateDependencyGraph;
1296
+ return _ts_generator(this, function(_state) {
1297
+ switch(_state.label){
1298
+ case 0:
1299
+ clients = [];
1300
+ io = new import_socket.Server(devServer2);
1301
+ io.on("connection", function(client) {
1302
+ clients.push(client);
1303
+ client.on("disconnect", function() {
1304
+ clients = clients.filter(function(item) {
1305
+ return item !== client;
1306
+ });
1307
+ });
1308
+ });
1309
+ watcher = (0, import_chokidar.watch)(emailDirRelativePath, {
1310
+ ignoreInitial: true,
1311
+ cwd: import_node_path3.default.resolve(process.cwd()),
1312
+ // eslint-disable-next-line prefer-named-capture-group
1313
+ ignored: /(^|[/\\])\../
1314
+ });
1315
+ exit = function() {
1316
+ void watcher.close();
1317
+ };
1318
+ process.on("SIGINT", exit);
1319
+ process.on("uncaughtException", exit);
1320
+ changes = [];
1321
+ reload = (0, import_debounce.default)(function() {
1322
+ clients.forEach(function(client) {
1323
+ client.emit("reload", changes);
1324
+ });
1325
+ changes = [];
1326
+ }, 150);
1327
+ absolutePathToEmailsDirectory = import_node_path3.default.resolve(process.cwd(), emailDirRelativePath);
1328
+ return [
1329
+ 4,
1330
+ createDependencyGraph(absolutePathToEmailsDirectory)
1331
+ ];
1332
+ case 1:
1333
+ _ref = _sliced_to_array.apply(void 0, [
1334
+ _state.sent(),
1335
+ 2
1336
+ ]), dependencyGraph = _ref[0], updateDependencyGraph = _ref[1];
1337
+ watcher.on("all", function() {
1338
+ var _ref = _async_to_generator(function(event, relativePathToChangeTarget) {
1339
+ var _changes, _dependencyGraph_pathToChangeTarget, file, pathToChangeTarget, _dependencyGraph_pathToChangeTarget_dependentPaths;
1340
+ return _ts_generator(this, function(_state) {
1341
+ switch(_state.label){
1342
+ case 0:
1343
+ file = relativePathToChangeTarget.split(import_node_path3.default.sep);
1344
+ if (file.length === 0) {
1345
+ return [
1346
+ 2
1347
+ ];
1348
+ }
1349
+ pathToChangeTarget = import_node_path3.default.resolve(process.cwd(), relativePathToChangeTarget);
1350
+ return [
1351
+ 4,
1352
+ updateDependencyGraph(event, pathToChangeTarget)
1353
+ ];
1354
+ case 1:
1355
+ _state.sent();
1356
+ changes.push({
1357
+ event: event,
1358
+ filename: relativePathToChangeTarget
1359
+ });
1360
+ (_changes = changes).push.apply(_changes, _to_consumable_array(((_dependencyGraph_pathToChangeTarget_dependentPaths = (_dependencyGraph_pathToChangeTarget = dependencyGraph[pathToChangeTarget]) === null || _dependencyGraph_pathToChangeTarget === void 0 ? void 0 : _dependencyGraph_pathToChangeTarget.dependentPaths) !== null && _dependencyGraph_pathToChangeTarget_dependentPaths !== void 0 ? _dependencyGraph_pathToChangeTarget_dependentPaths : []).map(function(dependentPath) {
1361
+ return {
1362
+ event: "change",
1363
+ filename: import_node_path3.default.relative(absolutePathToEmailsDirectory, dependentPath)
1364
+ };
1365
+ })));
1366
+ reload();
1367
+ return [
1368
+ 2
1369
+ ];
1370
+ }
1371
+ });
1372
+ });
1373
+ return function(event, relativePathToChangeTarget) {
1374
+ return _ref.apply(this, arguments);
1375
+ };
1376
+ }());
1377
+ return [
1378
+ 2,
1379
+ watcher
1380
+ ];
1381
+ }
538
1382
  });
539
- reload();
540
1383
  });
541
- return watcher;
542
- };
1384
+ return function setupHotreloading(devServer2, emailDirRelativePath) {
1385
+ return _ref.apply(this, arguments);
1386
+ };
1387
+ }();
543
1388
  // src/cli/utils/preview/start-dev-server.ts
544
- var import_node_path4 = __toESM(require("path"));
1389
+ var import_node_path5 = __toESM(require("path"));
545
1390
  var import_node_http = __toESM(require("http"));
546
1391
  var import_node_url = __toESM(require("url"));
547
1392
  var import_next = __toESM(require("next"));
@@ -555,8 +1400,8 @@ var closeOraOnSIGNIT = function(spinner) {
555
1400
  });
556
1401
  };
557
1402
  // src/cli/utils/preview/serve-static-file.ts
558
- var import_node_path3 = __toESM(require("path"));
559
- var import_node_fs2 = require("fs");
1403
+ var import_node_path4 = __toESM(require("path"));
1404
+ var import_node_fs3 = require("fs");
560
1405
  var import_mime_types = require("mime-types");
561
1406
  var serveStaticFile = function() {
562
1407
  var _ref = _async_to_generator(function(res, parsedUrl, staticDirRelativePath) {
@@ -564,11 +1409,11 @@ var serveStaticFile = function() {
564
1409
  return _ts_generator(this, function(_state) {
565
1410
  switch(_state.label){
566
1411
  case 0:
567
- staticBaseDir = import_node_path3.default.join(process.cwd(), staticDirRelativePath);
1412
+ staticBaseDir = import_node_path4.default.join(process.cwd(), staticDirRelativePath);
568
1413
  pathname = parsedUrl.pathname;
569
- ext = import_node_path3.default.parse(pathname).ext;
570
- fileAbsolutePath = import_node_path3.default.join(staticBaseDir, pathname);
571
- doesFileExist = (0, import_node_fs2.existsSync)(fileAbsolutePath);
1414
+ ext = import_node_path4.default.parse(pathname).ext;
1415
+ fileAbsolutePath = import_node_path4.default.join(staticBaseDir, pathname);
1416
+ doesFileExist = (0, import_node_fs3.existsSync)(fileAbsolutePath);
572
1417
  if (!!doesFileExist) return [
573
1418
  3,
574
1419
  1
@@ -582,7 +1427,7 @@ var serveStaticFile = function() {
582
1427
  case 1:
583
1428
  return [
584
1429
  4,
585
- import_node_fs2.promises.stat(fileAbsolutePath)
1430
+ import_node_fs3.promises.stat(fileAbsolutePath)
586
1431
  ];
587
1432
  case 2:
588
1433
  fileStat = _state.sent();
@@ -591,7 +1436,7 @@ var serveStaticFile = function() {
591
1436
  }
592
1437
  return [
593
1438
  4,
594
- import_node_fs2.promises.readFile(fileAbsolutePath)
1439
+ import_node_fs3.promises.readFile(fileAbsolutePath)
595
1440
  ];
596
1441
  case 3:
597
1442
  fileData = _state.sent();
@@ -637,8 +1482,8 @@ var safeAsyncServerListen = function(server, port) {
637
1482
  });
638
1483
  });
639
1484
  };
640
- var isRunningBuilt = __filename.endsWith(import_node_path4.default.join("cli", "index.js"));
641
- var cliPacakgeLocation = isRunningBuilt ? import_node_path4.default.resolve(__dirname, "..") : import_node_path4.default.resolve(__dirname, "../../../..");
1485
+ var isRunningBuilt = __filename.endsWith(import_node_path5.default.join("cli", "index.js"));
1486
+ var cliPacakgeLocation = isRunningBuilt ? import_node_path5.default.resolve(__dirname, "..") : import_node_path5.default.resolve(__dirname, "../../../..");
642
1487
  var startDevServer = function() {
643
1488
  var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
644
1489
  var portAlreadyInUse, nextPortToTry, spinner, timeBeforeNextReady, app, isNextReady, nextReadyPromise, nextHandleRequest, secondsToNextReady;
@@ -714,7 +1559,7 @@ var startDevServer = function() {
714
1559
  closeOraOnSIGNIT(spinner);
715
1560
  timeBeforeNextReady = performance.now();
716
1561
  process.env = _object_spread({}, process.env, getEnvVariablesForPreviewApp(// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
717
- import_node_path4.default.normalize(emailsDirRelativePath), cliPacakgeLocation, process.cwd()));
1562
+ import_node_path5.default.normalize(emailsDirRelativePath), cliPacakgeLocation, process.cwd()));
718
1563
  app = (0, import_next.default)({
719
1564
  // passing in env here does not get the environment variables there
720
1565
  dev: true,
@@ -789,11 +1634,11 @@ var dev = function() {
789
1634
  case 1:
790
1635
  _state.trys.push([
791
1636
  1,
792
- 3,
1637
+ 4,
793
1638
  ,
794
- 4
1639
+ 5
795
1640
  ]);
796
- if (!import_node_fs3.default.existsSync(emailsDirRelativePath)) {
1641
+ if (!import_node_fs4.default.existsSync(emailsDirRelativePath)) {
797
1642
  throw new Error("Missing ".concat(emailsDirRelativePath, " folder"));
798
1643
  }
799
1644
  return [
@@ -803,20 +1648,25 @@ var dev = function() {
803
1648
  ];
804
1649
  case 2:
805
1650
  devServer2 = _state.sent();
806
- setupHotreloading(devServer2, emailsDirRelativePath);
807
1651
  return [
808
- 3,
809
- 4
1652
+ 4,
1653
+ setupHotreloading(devServer2, emailsDirRelativePath)
810
1654
  ];
811
1655
  case 3:
1656
+ _state.sent();
1657
+ return [
1658
+ 3,
1659
+ 5
1660
+ ];
1661
+ case 4:
812
1662
  error = _state.sent();
813
1663
  console.log(error);
814
1664
  process.exit(1);
815
1665
  return [
816
1666
  3,
817
- 4
1667
+ 5
818
1668
  ];
819
- case 4:
1669
+ case 5:
820
1670
  return [
821
1671
  2
822
1672
  ];
@@ -828,8 +1678,8 @@ var dev = function() {
828
1678
  };
829
1679
  }();
830
1680
  // src/cli/commands/export.ts
831
- var import_node_fs5 = __toESM(require("fs"));
832
- var import_node_path6 = __toESM(require("path"));
1681
+ var import_node_fs6 = __toESM(require("fs"));
1682
+ var import_node_path7 = __toESM(require("path"));
833
1683
  var import_glob = require("glob");
834
1684
  var import_esbuild = require("esbuild");
835
1685
  var import_ora2 = __toESM(require("ora"));
@@ -838,18 +1688,18 @@ var import_render = require("@react-email/render");
838
1688
  var import_normalize_path = __toESM(require("normalize-path"));
839
1689
  var import_shelljs = require("shelljs");
840
1690
  // src/actions/get-emails-directory-metadata.ts
841
- var import_node_fs4 = __toESM(require("fs"));
842
- var import_node_path5 = __toESM(require("path"));
1691
+ var import_node_fs5 = __toESM(require("fs"));
1692
+ var import_node_path6 = __toESM(require("path"));
843
1693
  var isFileAnEmail = function(fullPath) {
844
- var stat = import_node_fs4.default.statSync(fullPath);
1694
+ var stat = import_node_fs5.default.statSync(fullPath);
845
1695
  if (stat.isDirectory()) return false;
846
- var ext = import_node_path5.default.parse(fullPath).ext;
1696
+ var ext = import_node_path6.default.parse(fullPath).ext;
847
1697
  if (![
848
1698
  ".js",
849
1699
  ".tsx",
850
1700
  ".jsx"
851
1701
  ].includes(ext)) return false;
852
- var fileContents = import_node_fs4.default.readFileSync(fullPath, "utf8");
1702
+ var fileContents = import_node_fs5.default.readFileSync(fullPath, "utf8");
853
1703
  return /\bexport\s+default\b/gm.test(fileContents);
854
1704
  };
855
1705
  var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
@@ -860,7 +1710,7 @@ var mergeDirectoriesWithSubDirectories = function(emailsDirectoryMetadata) {
860
1710
  subDirectories: onlySubDirectory.subDirectories,
861
1711
  emailFilenames: onlySubDirectory.emailFilenames,
862
1712
  absolutePath: onlySubDirectory.absolutePath,
863
- directoryName: import_node_path5.default.join(currentResultingMergedDirectory.directoryName, onlySubDirectory.directoryName)
1713
+ directoryName: import_node_path6.default.join(currentResultingMergedDirectory.directoryName, onlySubDirectory.directoryName)
864
1714
  };
865
1715
  }
866
1716
  return currentResultingMergedDirectory;
@@ -871,28 +1721,28 @@ var getEmailsDirectoryMetadata = function() {
871
1721
  return _ts_generator(this, function(_state) {
872
1722
  switch(_state.label){
873
1723
  case 0:
874
- if (!import_node_fs4.default.existsSync(absolutePathToEmailsDirectory)) return [
1724
+ if (!import_node_fs5.default.existsSync(absolutePathToEmailsDirectory)) return [
875
1725
  2
876
1726
  ];
877
1727
  return [
878
1728
  4,
879
- import_node_fs4.default.promises.readdir(absolutePathToEmailsDirectory, {
1729
+ import_node_fs5.default.promises.readdir(absolutePathToEmailsDirectory, {
880
1730
  withFileTypes: true
881
1731
  })
882
1732
  ];
883
1733
  case 1:
884
1734
  dirents = _state.sent();
885
1735
  emailFilenames = dirents.filter(function(dirent) {
886
- return isFileAnEmail(import_node_path5.default.join(absolutePathToEmailsDirectory, dirent.name));
1736
+ return isFileAnEmail(import_node_path6.default.join(absolutePathToEmailsDirectory, dirent.name));
887
1737
  }).map(function(dirent) {
888
- return dirent.name.replace(import_node_path5.default.extname(dirent.name), "");
1738
+ return dirent.name.replace(import_node_path6.default.extname(dirent.name), "");
889
1739
  });
890
1740
  return [
891
1741
  4,
892
1742
  Promise.all(dirents.filter(function(dirent) {
893
1743
  return dirent.isDirectory() && !dirent.name.startsWith("_") && dirent.name !== "static";
894
1744
  }).map(function(dirent) {
895
- return getEmailsDirectoryMetadata(import_node_path5.default.join(absolutePathToEmailsDirectory, dirent.name));
1745
+ return getEmailsDirectoryMetadata(import_node_path6.default.join(absolutePathToEmailsDirectory, dirent.name));
896
1746
  }))
897
1747
  ];
898
1748
  case 2:
@@ -901,7 +1751,7 @@ var getEmailsDirectoryMetadata = function() {
901
1751
  2,
902
1752
  mergeDirectoriesWithSubDirectories({
903
1753
  absolutePath: absolutePathToEmailsDirectory,
904
- directoryName: absolutePathToEmailsDirectory.split(import_node_path5.default.sep).pop(),
1754
+ directoryName: absolutePathToEmailsDirectory.split(import_node_path6.default.sep).pop(),
905
1755
  emailFilenames: emailFilenames,
906
1756
  subDirectories: subDirectories
907
1757
  })
@@ -917,7 +1767,7 @@ var getEmailsDirectoryMetadata = function() {
917
1767
  var getEmailTemplatesFromDirectory = function(emailDirectory) {
918
1768
  var templatePaths = [];
919
1769
  emailDirectory.emailFilenames.forEach(function(filename) {
920
- return templatePaths.push(import_node_path6.default.join(emailDirectory.absolutePath, filename));
1770
+ return templatePaths.push(import_node_path7.default.join(emailDirectory.absolutePath, filename));
921
1771
  });
922
1772
  emailDirectory.subDirectories.forEach(function(directory) {
923
1773
  var _templatePaths;
@@ -931,11 +1781,16 @@ var exportTemplates = function() {
931
1781
  return _ts_generator(this, function(_state) {
932
1782
  switch(_state.label){
933
1783
  case 0:
1784
+ if (import_node_fs6.default.existsSync(pathToWhereEmailMarkupShouldBeDumped)) {
1785
+ import_node_fs6.default.rmSync(pathToWhereEmailMarkupShouldBeDumped, {
1786
+ recursive: true
1787
+ });
1788
+ }
934
1789
  spinner = (0, import_ora2.default)("Preparing files...\n").start();
935
1790
  closeOraOnSIGNIT(spinner);
936
1791
  return [
937
1792
  4,
938
- getEmailsDirectoryMetadata(import_node_path6.default.join(process.cwd(), emailsDirectoryPath))
1793
+ getEmailsDirectoryMetadata(import_node_path7.default.join(process.cwd(), emailsDirectoryPath))
939
1794
  ];
940
1795
  case 1:
941
1796
  emailsDirectoryMetadata = _state.sent();
@@ -992,8 +1847,8 @@ var exportTemplates = function() {
992
1847
  component = require(template);
993
1848
  rendered = (0, import_render.render)(component.default({}), options);
994
1849
  htmlPath = template.replace(".cjs", options.plainText ? ".txt" : ".html");
995
- (0, import_node_fs5.writeFileSync)(htmlPath, rendered);
996
- (0, import_node_fs5.unlinkSync)(template);
1850
+ (0, import_node_fs6.writeFileSync)(htmlPath, rendered);
1851
+ (0, import_node_fs6.unlinkSync)(template);
997
1852
  } catch (exception) {
998
1853
  spinner.stopAndPersist({
999
1854
  symbol: import_log_symbols2.default.error,
@@ -1020,19 +1875,19 @@ var exportTemplates = function() {
1020
1875
  spinner.succeed("Rendered all files");
1021
1876
  spinner.text = "Copying static files";
1022
1877
  spinner.render();
1023
- staticDirectoryPath = import_node_path6.default.join(emailsDirectoryPath, "static");
1024
- if (!import_node_fs5.default.existsSync(staticDirectoryPath)) return [
1878
+ staticDirectoryPath = import_node_path7.default.join(emailsDirectoryPath, "static");
1879
+ if (!import_node_fs6.default.existsSync(staticDirectoryPath)) return [
1025
1880
  3,
1026
1881
  4
1027
1882
  ];
1028
- pathToDumpStaticFilesInto = import_node_path6.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
1029
- if (!import_node_fs5.default.existsSync(pathToDumpStaticFilesInto)) return [
1883
+ pathToDumpStaticFilesInto = import_node_path7.default.join(pathToWhereEmailMarkupShouldBeDumped, "static");
1884
+ if (!import_node_fs6.default.existsSync(pathToDumpStaticFilesInto)) return [
1030
1885
  3,
1031
1886
  3
1032
1887
  ];
1033
1888
  return [
1034
1889
  4,
1035
- import_node_fs5.default.promises.rm(pathToDumpStaticFilesInto, {
1890
+ import_node_fs6.default.promises.rm(pathToDumpStaticFilesInto, {
1036
1891
  recursive: true
1037
1892
  })
1038
1893
  ];
@@ -1040,7 +1895,7 @@ var exportTemplates = function() {
1040
1895
  _state.sent();
1041
1896
  _state.label = 3;
1042
1897
  case 3:
1043
- result = (0, import_shelljs.cp)("-r", staticDirectoryPath, import_node_path6.default.join(pathToWhereEmailMarkupShouldBeDumped, "static"));
1898
+ result = (0, import_shelljs.cp)("-r", staticDirectoryPath, import_node_path7.default.join(pathToWhereEmailMarkupShouldBeDumped, "static"));
1044
1899
  if (result.code > 0) {
1045
1900
  spinner.stopAndPersist({
1046
1901
  symbol: import_log_symbols2.default.error,
@@ -1074,8 +1929,8 @@ var exportTemplates = function() {
1074
1929
  };
1075
1930
  }();
1076
1931
  // src/cli/commands/build.ts
1077
- var import_node_fs6 = __toESM(require("fs"));
1078
- var import_node_path7 = __toESM(require("path"));
1932
+ var import_node_fs7 = __toESM(require("fs"));
1933
+ var import_node_path8 = __toESM(require("path"));
1079
1934
  var import_ora3 = __toESM(require("ora"));
1080
1935
  var import_shelljs2 = __toESM(require("shelljs"));
1081
1936
  var import_node_child_process = require("child_process");
@@ -1110,13 +1965,13 @@ var setNextEnvironmentVariablesForBuild = function() {
1110
1965
  switch(_state.label){
1111
1966
  case 0:
1112
1967
  envVariables = _object_spread_props(_object_spread({}, getEnvVariablesForPreviewApp(// If we don't do normalization here, stuff like https://github.com/resend/react-email/issues/1354 happens.
1113
- import_node_path7.default.normalize(emailsDirRelativePath), "PLACEHOLDER", "PLACEHOLDER")), {
1968
+ import_node_path8.default.normalize(emailsDirRelativePath), "PLACEHOLDER", "PLACEHOLDER")), {
1114
1969
  NEXT_PUBLIC_IS_BUILDING: "true"
1115
1970
  });
1116
1971
  nextConfigContents = "\nconst path = require('path');\n/** @type {import('next').NextConfig} */\nmodule.exports = {\n env: {\n ...".concat(JSON.stringify(envVariables), ",\n NEXT_PUBLIC_USER_PROJECT_LOCATION: path.resolve(process.cwd(), '../'),\n NEXT_PUBLIC_CLI_PACKAGE_LOCATION: process.cwd(),\n },\n // this is needed so that the code for building emails works properly\n webpack: (\n /** @type {import('webpack').Configuration & { externals: string[] }} */\n config,\n { isServer }\n ) => {\n if (isServer) {\n config.externals.push('esbuild');\n }\n\n return config;\n },\n typescript: {\n ignoreBuildErrors: true\n },\n eslint: {\n ignoreDuringBuilds: true\n },\n experimental: {\n webpackBuildWorker: true,\n serverComponentsExternalPackages: [\n '@react-email/components',\n '@react-email/render',\n '@react-email/tailwind',\n ],\n },\n}");
1117
1972
  return [
1118
1973
  4,
1119
- import_node_fs6.default.promises.writeFile(import_node_path7.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
1974
+ import_node_fs7.default.promises.writeFile(import_node_path8.default.resolve(builtPreviewAppPath, "./next.config.js"), nextConfigContents, "utf8")
1120
1975
  ];
1121
1976
  case 1:
1122
1977
  _state.sent();
@@ -1134,7 +1989,7 @@ var getEmailSlugsFromEmailDirectory = function(emailDirectory, emailsDirectoryAb
1134
1989
  var directoryPathRelativeToEmailsDirectory = emailDirectory.absolutePath.replace(emailsDirectoryAbsolutePath, "").trim();
1135
1990
  var slugs = [];
1136
1991
  emailDirectory.emailFilenames.forEach(function(filename) {
1137
- return slugs.push(import_node_path7.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path7.default.sep).filter(function(segment) {
1992
+ return slugs.push(import_node_path8.default.join(directoryPathRelativeToEmailsDirectory, filename).split(import_node_path8.default.sep).filter(function(segment) {
1138
1993
  return segment.length > 0;
1139
1994
  }));
1140
1995
  });
@@ -1164,7 +2019,7 @@ var forceSSGForEmailPreviews = function() {
1164
2019
  });
1165
2020
  return [
1166
2021
  4,
1167
- import_node_fs6.default.promises.appendFile(import_node_path7.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"), "\n\nexport async function generateStaticParams() { \n return ".concat(JSON.stringify(parameters), ";\n}"), "utf8")
2022
+ import_node_fs7.default.promises.appendFile(import_node_path8.default.resolve(builtPreviewAppPath, "./src/app/preview/[...slug]/page.tsx"), "\n\nexport async function generateStaticParams() { \n return ".concat(JSON.stringify(parameters), ";\n}"), "utf8")
1168
2023
  ];
1169
2024
  case 2:
1170
2025
  _state.sent();
@@ -1184,11 +2039,11 @@ var updatePackageJson = function() {
1184
2039
  return _ts_generator(this, function(_state) {
1185
2040
  switch(_state.label){
1186
2041
  case 0:
1187
- packageJsonPath = import_node_path7.default.resolve(builtPreviewAppPath, "./package.json");
2042
+ packageJsonPath = import_node_path8.default.resolve(builtPreviewAppPath, "./package.json");
1188
2043
  _ = JSON.parse;
1189
2044
  return [
1190
2045
  4,
1191
- import_node_fs6.default.promises.readFile(packageJsonPath, "utf8")
2046
+ import_node_fs7.default.promises.readFile(packageJsonPath, "utf8")
1192
2047
  ];
1193
2048
  case 1:
1194
2049
  packageJson = _.apply(JSON, [
@@ -1199,7 +2054,7 @@ var updatePackageJson = function() {
1199
2054
  packageJson.dependencies.sharp = "0.33.2";
1200
2055
  return [
1201
2056
  4,
1202
- import_node_fs6.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
2057
+ import_node_fs7.default.promises.writeFile(packageJsonPath, JSON.stringify(packageJson), "utf8")
1203
2058
  ];
1204
2059
  case 2:
1205
2060
  _state.sent();
@@ -1257,20 +2112,20 @@ var build = function() {
1257
2112
  }).start();
1258
2113
  closeOraOnSIGNIT(spinner);
1259
2114
  spinner.text = "Checking if emails folder exists";
1260
- if (!import_node_fs6.default.existsSync(emailsDirRelativePath)) {
2115
+ if (!import_node_fs7.default.existsSync(emailsDirRelativePath)) {
1261
2116
  throw new Error("Missing ".concat(emailsDirRelativePath, " folder"));
1262
2117
  }
1263
- emailsDirPath = import_node_path7.default.join(process.cwd(), emailsDirRelativePath);
1264
- staticPath = import_node_path7.default.join(emailsDirPath, "static");
1265
- builtPreviewAppPath = import_node_path7.default.join(process.cwd(), ".react-email");
1266
- if (!import_node_fs6.default.existsSync(builtPreviewAppPath)) return [
2118
+ emailsDirPath = import_node_path8.default.join(process.cwd(), emailsDirRelativePath);
2119
+ staticPath = import_node_path8.default.join(emailsDirPath, "static");
2120
+ builtPreviewAppPath = import_node_path8.default.join(process.cwd(), ".react-email");
2121
+ if (!import_node_fs7.default.existsSync(builtPreviewAppPath)) return [
1267
2122
  3,
1268
2123
  3
1269
2124
  ];
1270
2125
  spinner.text = "Deleting pre-existing `.react-email` folder";
1271
2126
  return [
1272
2127
  4,
1273
- import_node_fs6.default.promises.rm(builtPreviewAppPath, {
2128
+ import_node_fs7.default.promises.rm(builtPreviewAppPath, {
1274
2129
  recursive: true
1275
2130
  })
1276
2131
  ];
@@ -1281,7 +2136,7 @@ var build = function() {
1281
2136
  spinner.text = "Copying preview app from CLI to `.react-email`";
1282
2137
  return [
1283
2138
  4,
1284
- import_node_fs6.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
2139
+ import_node_fs7.default.promises.cp(cliPacakgeLocation, builtPreviewAppPath, {
1285
2140
  recursive: true,
1286
2141
  filter: function(source) {
1287
2142
  return !source.includes("/cli/") && !source.includes("/.next/") && !/\/node_modules\/?$/.test(source);
@@ -1290,15 +2145,15 @@ var build = function() {
1290
2145
  ];
1291
2146
  case 4:
1292
2147
  _state.sent();
1293
- if (!import_node_fs6.default.existsSync(staticPath)) return [
2148
+ if (!import_node_fs7.default.existsSync(staticPath)) return [
1294
2149
  3,
1295
2150
  6
1296
2151
  ];
1297
2152
  spinner.text = "Copying `static` folder into `.react-email/public/static`";
1298
- builtStaticDirectory = import_node_path7.default.resolve(builtPreviewAppPath, "./public/static");
2153
+ builtStaticDirectory = import_node_path8.default.resolve(builtPreviewAppPath, "./public/static");
1299
2154
  return [
1300
2155
  4,
1301
- import_node_fs6.default.promises.cp(staticPath, builtStaticDirectory, {
2156
+ import_node_fs7.default.promises.cp(staticPath, builtStaticDirectory, {
1302
2157
  recursive: true
1303
2158
  })
1304
2159
  ];
@@ -1368,8 +2223,8 @@ var build = function() {
1368
2223
  };
1369
2224
  }();
1370
2225
  // src/cli/commands/start.ts
1371
- var import_node_fs7 = __toESM(require("fs"));
1372
- var import_node_path8 = __toESM(require("path"));
2226
+ var import_node_fs8 = __toESM(require("fs"));
2227
+ var import_node_path9 = __toESM(require("path"));
1373
2228
  var import_node_child_process2 = require("child_process");
1374
2229
  var start = function() {
1375
2230
  var _ref = _async_to_generator(function() {
@@ -1377,8 +2232,8 @@ var start = function() {
1377
2232
  return _ts_generator(this, function(_state) {
1378
2233
  try {
1379
2234
  usersProjectLocation = process.cwd();
1380
- builtPreviewPath = import_node_path8.default.resolve(usersProjectLocation, "./.react-email");
1381
- if (!import_node_fs7.default.existsSync(builtPreviewPath)) {
2235
+ builtPreviewPath = import_node_path9.default.resolve(usersProjectLocation, "./.react-email");
2236
+ if (!import_node_fs8.default.existsSync(builtPreviewPath)) {
1382
2237
  throw new Error("Could not find `.react-email`, maybe you haven't ran `email build`?");
1383
2238
  }
1384
2239
  nextStart = (0, import_node_child_process2.spawn)("npm", [