react-email 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.js +464 -367
- package/cli/index.mjs +304 -239
- package/package.json +6 -5
- package/src/actions/get-email-path-from-slug.ts +5 -3
- package/src/utils/render-resolver-esbuild-plugin.ts +11 -1
package/cli/index.js
CHANGED
|
@@ -340,7 +340,7 @@ var import_commander = require("commander");
|
|
|
340
340
|
// package.json
|
|
341
341
|
var package_default = {
|
|
342
342
|
name: "react-email",
|
|
343
|
-
version: "2.1.
|
|
343
|
+
version: "2.1.4",
|
|
344
344
|
description: "A live preview of your emails right in your browser.",
|
|
345
345
|
bin: {
|
|
346
346
|
email: "./cli/index.js"
|
|
@@ -367,7 +367,8 @@ var package_default = {
|
|
|
367
367
|
node: ">=18.0.0"
|
|
368
368
|
},
|
|
369
369
|
dependencies: {
|
|
370
|
-
"@babel/
|
|
370
|
+
"@babel/core": "7.24.5",
|
|
371
|
+
"@babel/parser": "7.24.5",
|
|
371
372
|
"@radix-ui/colors": "1.0.1",
|
|
372
373
|
"@radix-ui/react-collapsible": "1.0.3",
|
|
373
374
|
"@radix-ui/react-popover": "1.0.7",
|
|
@@ -379,7 +380,6 @@ var package_default = {
|
|
|
379
380
|
"@types/react-dom": "^18.2.0",
|
|
380
381
|
"@types/webpack": "5.28.5",
|
|
381
382
|
autoprefixer: "10.4.14",
|
|
382
|
-
"babel-walk": "3.0.0",
|
|
383
383
|
chalk: "4.1.2",
|
|
384
384
|
chokidar: "3.5.3",
|
|
385
385
|
clsx: "2.1.0",
|
|
@@ -410,8 +410,9 @@ var package_default = {
|
|
|
410
410
|
typescript: "5.1.6"
|
|
411
411
|
},
|
|
412
412
|
devDependencies: {
|
|
413
|
-
"@react-email/components": "0.0.
|
|
414
|
-
"@react-email/render": "0.0.
|
|
413
|
+
"@react-email/components": "0.0.19",
|
|
414
|
+
"@react-email/render": "0.0.15",
|
|
415
|
+
"@types/babel__core": "7.20.5",
|
|
415
416
|
"@types/fs-extra": "11.0.1",
|
|
416
417
|
"@types/mime-types": "2.1.4",
|
|
417
418
|
"@types/node": "18.0.0",
|
|
@@ -570,31 +571,16 @@ var tree = function() {
|
|
|
570
571
|
};
|
|
571
572
|
}();
|
|
572
573
|
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
573
|
-
var
|
|
574
|
+
var import_node_path5 = __toESM(require("path"));
|
|
574
575
|
var import_socket = require("socket.io");
|
|
575
576
|
var import_chokidar = require("chokidar");
|
|
576
577
|
var import_debounce = __toESM(require("debounce"));
|
|
577
578
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
578
|
-
var
|
|
579
|
-
var
|
|
579
|
+
var import_node_path4 = __toESM(require("path"));
|
|
580
|
+
var import_node_fs3 = require("fs");
|
|
580
581
|
// src/cli/utils/preview/hot-reloading/get-imported-modules.ts
|
|
582
|
+
var import_core = require("@babel/core");
|
|
581
583
|
var import_parser = require("@babel/parser");
|
|
582
|
-
var walk = __toESM(require("babel-walk"));
|
|
583
|
-
var importVisitor = walk.simple({
|
|
584
|
-
ImportDeclaration: function ImportDeclaration(node, importedPaths) {
|
|
585
|
-
importedPaths.push(node.source.value);
|
|
586
|
-
},
|
|
587
|
-
CallExpression: function CallExpression(node, importedPaths) {
|
|
588
|
-
if ("name" in node.callee && node.callee.name === "require") {
|
|
589
|
-
if (node.arguments.length === 1) {
|
|
590
|
-
var importPathNode = node.arguments[0];
|
|
591
|
-
if (importPathNode.type === "StringLiteral") {
|
|
592
|
-
importedPaths.push(importPathNode.value);
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
584
|
var getImportedModules = function(contents) {
|
|
599
585
|
var importedPaths = [];
|
|
600
586
|
var parsedContents = (0, import_parser.parse)(contents, {
|
|
@@ -606,9 +592,282 @@ var getImportedModules = function(contents) {
|
|
|
606
592
|
"typescript"
|
|
607
593
|
]
|
|
608
594
|
});
|
|
609
|
-
|
|
595
|
+
(0, import_core.traverse)(parsedContents, {
|
|
596
|
+
ImportDeclaration: function ImportDeclaration(param) {
|
|
597
|
+
var node = param.node;
|
|
598
|
+
importedPaths.push(node.source.value);
|
|
599
|
+
},
|
|
600
|
+
ExportAllDeclaration: function ExportAllDeclaration(param) {
|
|
601
|
+
var node = param.node;
|
|
602
|
+
importedPaths.push(node.source.value);
|
|
603
|
+
},
|
|
604
|
+
ExportNamedDeclaration: function ExportNamedDeclaration(param) {
|
|
605
|
+
var node = param.node;
|
|
606
|
+
if (node.source) {
|
|
607
|
+
importedPaths.push(node.source.value);
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
CallExpression: function CallExpression(param) {
|
|
611
|
+
var node = param.node;
|
|
612
|
+
if ("name" in node.callee && node.callee.name === "require") {
|
|
613
|
+
if (node.arguments.length === 1) {
|
|
614
|
+
var importPathNode = node.arguments[0];
|
|
615
|
+
if (importPathNode.type === "StringLiteral") {
|
|
616
|
+
importedPaths.push(importPathNode.value);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
});
|
|
610
622
|
return importedPaths;
|
|
611
623
|
};
|
|
624
|
+
// src/cli/utils/preview/start-dev-server.ts
|
|
625
|
+
var import_node_path3 = __toESM(require("path"));
|
|
626
|
+
var import_node_http = __toESM(require("http"));
|
|
627
|
+
var import_node_url = __toESM(require("url"));
|
|
628
|
+
var import_next = __toESM(require("next"));
|
|
629
|
+
var import_ora = __toESM(require("ora"));
|
|
630
|
+
var import_log_symbols = __toESM(require("log-symbols"));
|
|
631
|
+
var import_chalk = __toESM(require("chalk"));
|
|
632
|
+
// src/cli/utils/close-ora-on-sigint.ts
|
|
633
|
+
var closeOraOnSIGNIT = function(spinner) {
|
|
634
|
+
process.on("SIGINT", function() {
|
|
635
|
+
spinner.stop();
|
|
636
|
+
});
|
|
637
|
+
};
|
|
638
|
+
// src/cli/utils/preview/serve-static-file.ts
|
|
639
|
+
var import_node_path2 = __toESM(require("path"));
|
|
640
|
+
var import_node_fs2 = require("fs");
|
|
641
|
+
var import_mime_types = require("mime-types");
|
|
642
|
+
var serveStaticFile = function() {
|
|
643
|
+
var _ref = _async_to_generator(function(res, parsedUrl, staticDirRelativePath) {
|
|
644
|
+
var staticBaseDir, pathname, ext, fileAbsolutePath, fileHandle, fileData, exception;
|
|
645
|
+
return _ts_generator(this, function(_state) {
|
|
646
|
+
switch(_state.label){
|
|
647
|
+
case 0:
|
|
648
|
+
staticBaseDir = import_node_path2.default.join(process.cwd(), staticDirRelativePath);
|
|
649
|
+
pathname = parsedUrl.pathname;
|
|
650
|
+
ext = import_node_path2.default.parse(pathname).ext;
|
|
651
|
+
fileAbsolutePath = import_node_path2.default.join(staticBaseDir, pathname);
|
|
652
|
+
return [
|
|
653
|
+
4,
|
|
654
|
+
import_node_fs2.promises.open(fileAbsolutePath, "r")
|
|
655
|
+
];
|
|
656
|
+
case 1:
|
|
657
|
+
fileHandle = _state.sent();
|
|
658
|
+
_state.label = 2;
|
|
659
|
+
case 2:
|
|
660
|
+
_state.trys.push([
|
|
661
|
+
2,
|
|
662
|
+
4,
|
|
663
|
+
5,
|
|
664
|
+
6
|
|
665
|
+
]);
|
|
666
|
+
return [
|
|
667
|
+
4,
|
|
668
|
+
import_node_fs2.promises.readFile(fileHandle)
|
|
669
|
+
];
|
|
670
|
+
case 3:
|
|
671
|
+
fileData = _state.sent();
|
|
672
|
+
res.setHeader("Content-type", (0, import_mime_types.lookup)(ext) || "text/plain");
|
|
673
|
+
res.end(fileData);
|
|
674
|
+
return [
|
|
675
|
+
3,
|
|
676
|
+
6
|
|
677
|
+
];
|
|
678
|
+
case 4:
|
|
679
|
+
exception = _state.sent();
|
|
680
|
+
console.error("Could not read file at ".concat(fileAbsolutePath, " to be served, here's the exception:"), exception);
|
|
681
|
+
res.statusCode = 500;
|
|
682
|
+
res.end("Could not read file to be served! Check your terminal for more information.");
|
|
683
|
+
return [
|
|
684
|
+
3,
|
|
685
|
+
6
|
|
686
|
+
];
|
|
687
|
+
case 5:
|
|
688
|
+
fileHandle.close();
|
|
689
|
+
return [
|
|
690
|
+
7
|
|
691
|
+
];
|
|
692
|
+
case 6:
|
|
693
|
+
return [
|
|
694
|
+
2
|
|
695
|
+
];
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
return function serveStaticFile(res, parsedUrl, staticDirRelativePath) {
|
|
700
|
+
return _ref.apply(this, arguments);
|
|
701
|
+
};
|
|
702
|
+
}();
|
|
703
|
+
// src/cli/utils/preview/get-env-variables-for-preview-app.ts
|
|
704
|
+
var import_path = __toESM(require("path"));
|
|
705
|
+
var getEnvVariablesForPreviewApp = function(relativePathToEmailsDirectory, cliPackageLocation, cwd) {
|
|
706
|
+
return {
|
|
707
|
+
NEXT_PUBLIC_EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
708
|
+
NEXT_PUBLIC_CLI_PACKAGE_LOCATION: cliPackageLocation,
|
|
709
|
+
NEXT_PUBLIC_OS_PATH_SEPARATOR: import_path.default.sep,
|
|
710
|
+
NEXT_PUBLIC_USER_PROJECT_LOCATION: cwd
|
|
711
|
+
};
|
|
712
|
+
};
|
|
713
|
+
// src/cli/utils/preview/start-dev-server.ts
|
|
714
|
+
var devServer;
|
|
715
|
+
var safeAsyncServerListen = function(server, port) {
|
|
716
|
+
return new Promise(function(resolve) {
|
|
717
|
+
server.listen(port, function() {
|
|
718
|
+
resolve({
|
|
719
|
+
portAlreadyInUse: false
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
server.on("error", function(e) {
|
|
723
|
+
if (e.code === "EADDRINUSE") {
|
|
724
|
+
resolve({
|
|
725
|
+
portAlreadyInUse: true
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
};
|
|
731
|
+
var isRunningBuilt = __filename.endsWith(import_node_path3.default.join("cli", "index.js"));
|
|
732
|
+
var cliPacakgeLocation = isRunningBuilt ? import_node_path3.default.resolve(__dirname, "..") : import_node_path3.default.resolve(__dirname, "../../../..");
|
|
733
|
+
var startDevServer = function() {
|
|
734
|
+
var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
|
|
735
|
+
var portAlreadyInUse, nextPortToTry, spinner, timeBeforeNextReady, app, isNextReady, nextReadyPromise, nextHandleRequest, secondsToNextReady;
|
|
736
|
+
return _ts_generator(this, function(_state) {
|
|
737
|
+
switch(_state.label){
|
|
738
|
+
case 0:
|
|
739
|
+
devServer = import_node_http.default.createServer(function(req, res) {
|
|
740
|
+
if (!req.url) {
|
|
741
|
+
res.end(404);
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
var parsedUrl = import_node_url.default.parse(req.url, true);
|
|
745
|
+
res.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store");
|
|
746
|
+
res.setHeader("Pragma", "no-cache");
|
|
747
|
+
res.setHeader("Expires", "-1");
|
|
748
|
+
try {
|
|
749
|
+
if (parsedUrl.path && parsedUrl.path.includes("static/") && !parsedUrl.path.includes("_next/static/")) {
|
|
750
|
+
void serveStaticFile(res, parsedUrl, staticBaseDirRelativePath);
|
|
751
|
+
} else if (!isNextReady) {
|
|
752
|
+
void nextReadyPromise.then(function() {
|
|
753
|
+
return nextHandleRequest === null || nextHandleRequest === void 0 ? void 0 : nextHandleRequest(req, res, parsedUrl);
|
|
754
|
+
});
|
|
755
|
+
} else {
|
|
756
|
+
void (nextHandleRequest === null || nextHandleRequest === void 0 ? void 0 : nextHandleRequest(req, res, parsedUrl));
|
|
757
|
+
}
|
|
758
|
+
} catch (e) {
|
|
759
|
+
console.error("caught error", e);
|
|
760
|
+
res.writeHead(500);
|
|
761
|
+
res.end();
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
return [
|
|
765
|
+
4,
|
|
766
|
+
safeAsyncServerListen(devServer, port)
|
|
767
|
+
];
|
|
768
|
+
case 1:
|
|
769
|
+
portAlreadyInUse = _state.sent().portAlreadyInUse;
|
|
770
|
+
if (!portAlreadyInUse) {
|
|
771
|
+
console.log(import_chalk.default.greenBright(" React Email ".concat(package_default.version)));
|
|
772
|
+
console.log(" Running preview at: http://localhost:".concat(port, "\n"));
|
|
773
|
+
} else {
|
|
774
|
+
nextPortToTry = port + 1;
|
|
775
|
+
console.warn(" ".concat(import_log_symbols.default.warning, " Port ").concat(port, " is already in use, trying ").concat(nextPortToTry));
|
|
776
|
+
return [
|
|
777
|
+
2,
|
|
778
|
+
startDevServer(emailsDirRelativePath, staticBaseDirRelativePath, nextPortToTry)
|
|
779
|
+
];
|
|
780
|
+
}
|
|
781
|
+
devServer.on("close", /*#__PURE__*/ _async_to_generator(function() {
|
|
782
|
+
return _ts_generator(this, function(_state) {
|
|
783
|
+
switch(_state.label){
|
|
784
|
+
case 0:
|
|
785
|
+
return [
|
|
786
|
+
4,
|
|
787
|
+
app.close()
|
|
788
|
+
];
|
|
789
|
+
case 1:
|
|
790
|
+
_state.sent();
|
|
791
|
+
return [
|
|
792
|
+
2
|
|
793
|
+
];
|
|
794
|
+
}
|
|
795
|
+
});
|
|
796
|
+
}));
|
|
797
|
+
devServer.on("error", function(e) {
|
|
798
|
+
console.error(" ".concat(import_log_symbols.default.error, " preview server error: "), JSON.stringify(e));
|
|
799
|
+
process.exit(1);
|
|
800
|
+
});
|
|
801
|
+
spinner = (0, import_ora.default)({
|
|
802
|
+
text: "Getting react-email preview server ready...\n",
|
|
803
|
+
prefixText: " "
|
|
804
|
+
}).start();
|
|
805
|
+
closeOraOnSIGNIT(spinner);
|
|
806
|
+
timeBeforeNextReady = performance.now();
|
|
807
|
+
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.
|
|
808
|
+
import_node_path3.default.normalize(emailsDirRelativePath), cliPacakgeLocation, process.cwd()));
|
|
809
|
+
app = (0, import_next.default)({
|
|
810
|
+
// passing in env here does not get the environment variables there
|
|
811
|
+
dev: true,
|
|
812
|
+
hostname: "localhost",
|
|
813
|
+
port: port,
|
|
814
|
+
dir: cliPacakgeLocation
|
|
815
|
+
});
|
|
816
|
+
isNextReady = false;
|
|
817
|
+
nextReadyPromise = app.prepare();
|
|
818
|
+
return [
|
|
819
|
+
4,
|
|
820
|
+
nextReadyPromise
|
|
821
|
+
];
|
|
822
|
+
case 2:
|
|
823
|
+
_state.sent();
|
|
824
|
+
isNextReady = true;
|
|
825
|
+
nextHandleRequest = app.getRequestHandler();
|
|
826
|
+
secondsToNextReady = ((performance.now() - timeBeforeNextReady) / 1e3).toFixed(1);
|
|
827
|
+
spinner.stopAndPersist({
|
|
828
|
+
text: "Ready in ".concat(secondsToNextReady, "s\n"),
|
|
829
|
+
symbol: import_log_symbols.default.success
|
|
830
|
+
});
|
|
831
|
+
return [
|
|
832
|
+
2,
|
|
833
|
+
devServer
|
|
834
|
+
];
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
});
|
|
838
|
+
return function startDevServer(emailsDirRelativePath, staticBaseDirRelativePath, port) {
|
|
839
|
+
return _ref.apply(this, arguments);
|
|
840
|
+
};
|
|
841
|
+
}();
|
|
842
|
+
var makeExitHandler = function(options) {
|
|
843
|
+
return function(_codeOrSignal) {
|
|
844
|
+
if (typeof devServer !== "undefined") {
|
|
845
|
+
console.log("\nshutting down dev server");
|
|
846
|
+
devServer.close();
|
|
847
|
+
devServer = void 0;
|
|
848
|
+
}
|
|
849
|
+
if (options === null || options === void 0 ? void 0 : options.shouldKillProcess) {
|
|
850
|
+
process.exit(options.killWithErrorCode ? 1 : 0);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
};
|
|
854
|
+
process.on("exit", makeExitHandler());
|
|
855
|
+
process.on("SIGINT", makeExitHandler({
|
|
856
|
+
shouldKillProcess: true,
|
|
857
|
+
killWithErrorCode: false
|
|
858
|
+
}));
|
|
859
|
+
process.on("SIGUSR1", makeExitHandler({
|
|
860
|
+
shouldKillProcess: true,
|
|
861
|
+
killWithErrorCode: false
|
|
862
|
+
}));
|
|
863
|
+
process.on("SIGUSR2", makeExitHandler({
|
|
864
|
+
shouldKillProcess: true,
|
|
865
|
+
killWithErrorCode: false
|
|
866
|
+
}));
|
|
867
|
+
process.on("uncaughtException", makeExitHandler({
|
|
868
|
+
shouldKillProcess: true,
|
|
869
|
+
killWithErrorCode: true
|
|
870
|
+
}));
|
|
612
871
|
// src/cli/utils/preview/hot-reloading/create-dependency-graph.ts
|
|
613
872
|
var readAllFilesInsideDirectory = function() {
|
|
614
873
|
var _ref = _async_to_generator(function(directory) {
|
|
@@ -619,7 +878,7 @@ var readAllFilesInsideDirectory = function() {
|
|
|
619
878
|
allFilePaths = [];
|
|
620
879
|
return [
|
|
621
880
|
4,
|
|
622
|
-
|
|
881
|
+
import_node_fs3.promises.readdir(directory, {
|
|
623
882
|
withFileTypes: true
|
|
624
883
|
})
|
|
625
884
|
];
|
|
@@ -648,7 +907,7 @@ var readAllFilesInsideDirectory = function() {
|
|
|
648
907
|
];
|
|
649
908
|
_value = _step.value;
|
|
650
909
|
dirent = _value;
|
|
651
|
-
pathToDirent =
|
|
910
|
+
pathToDirent = import_node_path4.default.join(directory, dirent.name);
|
|
652
911
|
if (!dirent.isDirectory()) return [
|
|
653
912
|
3,
|
|
654
913
|
6
|
|
@@ -735,7 +994,7 @@ var readAllFilesInsideDirectory = function() {
|
|
|
735
994
|
};
|
|
736
995
|
}();
|
|
737
996
|
var isJavascriptModule = function(filePath) {
|
|
738
|
-
var extensionName =
|
|
997
|
+
var extensionName = import_node_path4.default.extname(filePath);
|
|
739
998
|
return [
|
|
740
999
|
".js",
|
|
741
1000
|
".ts",
|
|
@@ -745,6 +1004,21 @@ var isJavascriptModule = function(filePath) {
|
|
|
745
1004
|
".cjs"
|
|
746
1005
|
].includes(extensionName);
|
|
747
1006
|
};
|
|
1007
|
+
var checkFileExtensionsUntilItExists = function(pathWithoutExtension) {
|
|
1008
|
+
if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".ts"))) {
|
|
1009
|
+
return "".concat(pathWithoutExtension, ".ts");
|
|
1010
|
+
} else if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".tsx"))) {
|
|
1011
|
+
return "".concat(pathWithoutExtension, ".tsx");
|
|
1012
|
+
} else if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".js"))) {
|
|
1013
|
+
return "".concat(pathWithoutExtension, ".js");
|
|
1014
|
+
} else if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".jsx"))) {
|
|
1015
|
+
return "".concat(pathWithoutExtension, ".jsx");
|
|
1016
|
+
} else if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".mjs"))) {
|
|
1017
|
+
return "".concat(pathWithoutExtension, ".mjs");
|
|
1018
|
+
} else if ((0, import_node_fs3.existsSync)("".concat(pathWithoutExtension, ".cjs"))) {
|
|
1019
|
+
return "".concat(pathWithoutExtension, ".cjs");
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
748
1022
|
var createDependencyGraph = function() {
|
|
749
1023
|
var _ref = _async_to_generator(function(directory) {
|
|
750
1024
|
var filePaths, modulePaths, graph, getDependencyPaths, updateModuleDependenciesInGraph, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, filePath, err, removeModuleFromGraph;
|
|
@@ -777,23 +1051,41 @@ var createDependencyGraph = function() {
|
|
|
777
1051
|
case 0:
|
|
778
1052
|
return [
|
|
779
1053
|
4,
|
|
780
|
-
|
|
1054
|
+
import_node_fs3.promises.readFile(filePath, "utf8")
|
|
781
1055
|
];
|
|
782
1056
|
case 1:
|
|
783
1057
|
contents = _state.sent();
|
|
784
1058
|
importedPaths = getImportedModules(contents);
|
|
785
1059
|
importedPathsRelativeToDirectory = importedPaths.map(function(dependencyPath) {
|
|
786
1060
|
var isModulePath = !dependencyPath.startsWith(".");
|
|
787
|
-
if (!isModulePath && !
|
|
788
|
-
var pathToDependencyFromDirectory =
|
|
1061
|
+
if (!isModulePath && !import_node_path4.default.isAbsolute(dependencyPath)) {
|
|
1062
|
+
var pathToDependencyFromDirectory = import_node_path4.default.resolve(/*
|
|
789
1063
|
path.resolve resolves paths differently from what imports on javascript do.
|
|
790
1064
|
|
|
791
1065
|
So if we wouldn't do this, for an email at "/path/to/email.tsx" with a dependecy path of "./other-email"
|
|
792
1066
|
would end up going into /path/to/email.tsx/other-email instead of /path/to/other-email which is the
|
|
793
1067
|
one the import is meant to go to
|
|
794
|
-
*/
|
|
1068
|
+
*/ import_node_path4.default.dirname(filePath), dependencyPath);
|
|
1069
|
+
var isDirectory = false;
|
|
1070
|
+
try {
|
|
1071
|
+
isDirectory = (0, import_node_fs3.statSync)(pathToDependencyFromDirectory).isDirectory();
|
|
1072
|
+
} catch (_) {}
|
|
1073
|
+
if (isDirectory) {
|
|
1074
|
+
var pathToSubDirectory = pathToDependencyFromDirectory;
|
|
1075
|
+
var pathWithExtension = checkFileExtensionsUntilItExists("".concat(pathToSubDirectory, "/index"));
|
|
1076
|
+
if (pathWithExtension) {
|
|
1077
|
+
pathToDependencyFromDirectory = pathWithExtension;
|
|
1078
|
+
} else if (!isRunningBuilt) {
|
|
1079
|
+
console.warn("Could not find index file for directory at ".concat(pathToDependencyFromDirectory, ". This is probably going to cause issues with both hot reloading and your code."));
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
795
1082
|
if (!isJavascriptModule(pathToDependencyFromDirectory)) {
|
|
796
|
-
|
|
1083
|
+
var pathWithExtension1 = checkFileExtensionsUntilItExists(pathToDependencyFromDirectory);
|
|
1084
|
+
if (pathWithExtension1) {
|
|
1085
|
+
pathToDependencyFromDirectory = pathWithExtension1;
|
|
1086
|
+
} else if (!isRunningBuilt) {
|
|
1087
|
+
console.warn("Could not determine the file extension for the file at ".concat(pathWithExtension1));
|
|
1088
|
+
}
|
|
797
1089
|
}
|
|
798
1090
|
return pathToDependencyFromDirectory;
|
|
799
1091
|
} else {
|
|
@@ -801,10 +1093,10 @@ var createDependencyGraph = function() {
|
|
|
801
1093
|
}
|
|
802
1094
|
});
|
|
803
1095
|
moduleDependencies = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
|
|
804
|
-
return !dependencyPath.startsWith(".") && !
|
|
1096
|
+
return !dependencyPath.startsWith(".") && !import_node_path4.default.isAbsolute(dependencyPath);
|
|
805
1097
|
});
|
|
806
1098
|
nonNodeModuleImportPathsRelativeToDirectory = importedPathsRelativeToDirectory.filter(function(dependencyPath) {
|
|
807
|
-
return dependencyPath.startsWith(".") ||
|
|
1099
|
+
return dependencyPath.startsWith(".") || import_node_path4.default.isAbsolute(dependencyPath);
|
|
808
1100
|
});
|
|
809
1101
|
return [
|
|
810
1102
|
2,
|
|
@@ -1274,363 +1566,163 @@ var createDependencyGraph = function() {
|
|
|
1274
1566
|
];
|
|
1275
1567
|
}
|
|
1276
1568
|
});
|
|
1277
|
-
});
|
|
1278
|
-
return function(event, pathToModified) {
|
|
1279
|
-
return _ref.apply(this, arguments);
|
|
1280
|
-
};
|
|
1281
|
-
}()
|
|
1282
|
-
]
|
|
1283
|
-
];
|
|
1284
|
-
}
|
|
1285
|
-
});
|
|
1286
|
-
});
|
|
1287
|
-
return function createDependencyGraph(directory) {
|
|
1288
|
-
return _ref.apply(this, arguments);
|
|
1289
|
-
};
|
|
1290
|
-
}();
|
|
1291
|
-
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
1292
|
-
var setupHotreloading = function() {
|
|
1293
|
-
var _ref = _async_to_generator(function(devServer2, emailDirRelativePath) {
|
|
1294
|
-
var clients, io, watcher, exit, changes, reload, absolutePathToEmailsDirectory, _ref, dependencyGraph, updateDependencyGraph;
|
|
1295
|
-
return _ts_generator(this, function(_state) {
|
|
1296
|
-
switch(_state.label){
|
|
1297
|
-
case 0:
|
|
1298
|
-
clients = [];
|
|
1299
|
-
io = new import_socket.Server(devServer2);
|
|
1300
|
-
io.on("connection", function(client) {
|
|
1301
|
-
clients.push(client);
|
|
1302
|
-
client.on("disconnect", function() {
|
|
1303
|
-
clients = clients.filter(function(item) {
|
|
1304
|
-
return item !== client;
|
|
1305
|
-
});
|
|
1306
|
-
});
|
|
1307
|
-
});
|
|
1308
|
-
watcher = (0, import_chokidar.watch)(emailDirRelativePath, {
|
|
1309
|
-
ignoreInitial: true,
|
|
1310
|
-
cwd: import_node_path3.default.resolve(process.cwd()),
|
|
1311
|
-
// eslint-disable-next-line prefer-named-capture-group
|
|
1312
|
-
ignored: /(^|[/\\])\../
|
|
1313
|
-
});
|
|
1314
|
-
exit = function() {
|
|
1315
|
-
void watcher.close();
|
|
1316
|
-
};
|
|
1317
|
-
process.on("SIGINT", exit);
|
|
1318
|
-
process.on("uncaughtException", exit);
|
|
1319
|
-
changes = [];
|
|
1320
|
-
reload = (0, import_debounce.default)(function() {
|
|
1321
|
-
clients.forEach(function(client) {
|
|
1322
|
-
client.emit("reload", changes);
|
|
1323
|
-
});
|
|
1324
|
-
changes = [];
|
|
1325
|
-
}, 150);
|
|
1326
|
-
absolutePathToEmailsDirectory = import_node_path3.default.resolve(process.cwd(), emailDirRelativePath);
|
|
1327
|
-
return [
|
|
1328
|
-
4,
|
|
1329
|
-
createDependencyGraph(absolutePathToEmailsDirectory)
|
|
1330
|
-
];
|
|
1331
|
-
case 1:
|
|
1332
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
1333
|
-
_state.sent(),
|
|
1334
|
-
2
|
|
1335
|
-
]), dependencyGraph = _ref[0], updateDependencyGraph = _ref[1];
|
|
1336
|
-
watcher.on("all", function() {
|
|
1337
|
-
var _ref = _async_to_generator(function(event, relativePathToChangeTarget) {
|
|
1338
|
-
var _changes, _dependencyGraph_pathToChangeTarget, file, pathToChangeTarget, _dependencyGraph_pathToChangeTarget_dependentPaths;
|
|
1339
|
-
return _ts_generator(this, function(_state) {
|
|
1340
|
-
switch(_state.label){
|
|
1341
|
-
case 0:
|
|
1342
|
-
file = relativePathToChangeTarget.split(import_node_path3.default.sep);
|
|
1343
|
-
if (file.length === 0) {
|
|
1344
|
-
return [
|
|
1345
|
-
2
|
|
1346
|
-
];
|
|
1347
|
-
}
|
|
1348
|
-
pathToChangeTarget = import_node_path3.default.resolve(process.cwd(), relativePathToChangeTarget);
|
|
1349
|
-
return [
|
|
1350
|
-
4,
|
|
1351
|
-
updateDependencyGraph(event, pathToChangeTarget)
|
|
1352
|
-
];
|
|
1353
|
-
case 1:
|
|
1354
|
-
_state.sent();
|
|
1355
|
-
changes.push({
|
|
1356
|
-
event: event,
|
|
1357
|
-
filename: relativePathToChangeTarget
|
|
1358
|
-
});
|
|
1359
|
-
(_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) {
|
|
1360
|
-
return {
|
|
1361
|
-
event: "change",
|
|
1362
|
-
filename: import_node_path3.default.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
1363
|
-
};
|
|
1364
|
-
})));
|
|
1365
|
-
reload();
|
|
1366
|
-
return [
|
|
1367
|
-
2
|
|
1368
|
-
];
|
|
1369
|
-
}
|
|
1370
|
-
});
|
|
1371
|
-
});
|
|
1372
|
-
return function(event, relativePathToChangeTarget) {
|
|
1373
|
-
return _ref.apply(this, arguments);
|
|
1374
|
-
};
|
|
1375
|
-
}());
|
|
1376
|
-
return [
|
|
1377
|
-
2,
|
|
1378
|
-
watcher
|
|
1379
|
-
];
|
|
1380
|
-
}
|
|
1381
|
-
});
|
|
1382
|
-
});
|
|
1383
|
-
return function setupHotreloading(devServer2, emailDirRelativePath) {
|
|
1384
|
-
return _ref.apply(this, arguments);
|
|
1385
|
-
};
|
|
1386
|
-
}();
|
|
1387
|
-
// src/cli/utils/preview/start-dev-server.ts
|
|
1388
|
-
var import_node_path5 = __toESM(require("path"));
|
|
1389
|
-
var import_node_http = __toESM(require("http"));
|
|
1390
|
-
var import_node_url = __toESM(require("url"));
|
|
1391
|
-
var import_next = __toESM(require("next"));
|
|
1392
|
-
var import_ora = __toESM(require("ora"));
|
|
1393
|
-
var import_log_symbols = __toESM(require("log-symbols"));
|
|
1394
|
-
var import_chalk = __toESM(require("chalk"));
|
|
1395
|
-
// src/cli/utils/close-ora-on-sigint.ts
|
|
1396
|
-
var closeOraOnSIGNIT = function(spinner) {
|
|
1397
|
-
process.on("SIGINT", function() {
|
|
1398
|
-
spinner.stop();
|
|
1399
|
-
});
|
|
1400
|
-
};
|
|
1401
|
-
// src/cli/utils/preview/serve-static-file.ts
|
|
1402
|
-
var import_node_path4 = __toESM(require("path"));
|
|
1403
|
-
var import_node_fs3 = require("fs");
|
|
1404
|
-
var import_mime_types = require("mime-types");
|
|
1405
|
-
var serveStaticFile = function() {
|
|
1406
|
-
var _ref = _async_to_generator(function(res, parsedUrl, staticDirRelativePath) {
|
|
1407
|
-
var staticBaseDir, pathname, ext, fileAbsolutePath, fileHandle, fileData, exception;
|
|
1408
|
-
return _ts_generator(this, function(_state) {
|
|
1409
|
-
switch(_state.label){
|
|
1410
|
-
case 0:
|
|
1411
|
-
staticBaseDir = import_node_path4.default.join(process.cwd(), staticDirRelativePath);
|
|
1412
|
-
pathname = parsedUrl.pathname;
|
|
1413
|
-
ext = import_node_path4.default.parse(pathname).ext;
|
|
1414
|
-
fileAbsolutePath = import_node_path4.default.join(staticBaseDir, pathname);
|
|
1415
|
-
return [
|
|
1416
|
-
4,
|
|
1417
|
-
import_node_fs3.promises.open(fileAbsolutePath, "r")
|
|
1418
|
-
];
|
|
1419
|
-
case 1:
|
|
1420
|
-
fileHandle = _state.sent();
|
|
1421
|
-
_state.label = 2;
|
|
1422
|
-
case 2:
|
|
1423
|
-
_state.trys.push([
|
|
1424
|
-
2,
|
|
1425
|
-
4,
|
|
1426
|
-
5,
|
|
1427
|
-
6
|
|
1428
|
-
]);
|
|
1429
|
-
return [
|
|
1430
|
-
4,
|
|
1431
|
-
import_node_fs3.promises.readFile(fileHandle)
|
|
1432
|
-
];
|
|
1433
|
-
case 3:
|
|
1434
|
-
fileData = _state.sent();
|
|
1435
|
-
res.setHeader("Content-type", (0, import_mime_types.lookup)(ext) || "text/plain");
|
|
1436
|
-
res.end(fileData);
|
|
1437
|
-
return [
|
|
1438
|
-
3,
|
|
1439
|
-
6
|
|
1440
|
-
];
|
|
1441
|
-
case 4:
|
|
1442
|
-
exception = _state.sent();
|
|
1443
|
-
console.error("Could not read file at ".concat(fileAbsolutePath, " to be served, here's the exception:"), exception);
|
|
1444
|
-
res.statusCode = 500;
|
|
1445
|
-
res.end("Could not read file to be served! Check your terminal for more information.");
|
|
1446
|
-
return [
|
|
1447
|
-
3,
|
|
1448
|
-
6
|
|
1449
|
-
];
|
|
1450
|
-
case 5:
|
|
1451
|
-
fileHandle.close();
|
|
1452
|
-
return [
|
|
1453
|
-
7
|
|
1454
|
-
];
|
|
1455
|
-
case 6:
|
|
1456
|
-
return [
|
|
1457
|
-
2
|
|
1569
|
+
});
|
|
1570
|
+
return function(event, pathToModified) {
|
|
1571
|
+
return _ref.apply(this, arguments);
|
|
1572
|
+
};
|
|
1573
|
+
}()
|
|
1574
|
+
]
|
|
1458
1575
|
];
|
|
1459
1576
|
}
|
|
1460
1577
|
});
|
|
1461
1578
|
});
|
|
1462
|
-
return function
|
|
1579
|
+
return function createDependencyGraph(directory) {
|
|
1463
1580
|
return _ref.apply(this, arguments);
|
|
1464
1581
|
};
|
|
1465
1582
|
}();
|
|
1466
|
-
// src/cli/utils/preview/
|
|
1467
|
-
var
|
|
1468
|
-
var
|
|
1469
|
-
|
|
1470
|
-
NEXT_PUBLIC_EMAILS_DIR_RELATIVE_PATH: relativePathToEmailsDirectory,
|
|
1471
|
-
NEXT_PUBLIC_CLI_PACKAGE_LOCATION: cliPackageLocation,
|
|
1472
|
-
NEXT_PUBLIC_OS_PATH_SEPARATOR: import_path.default.sep,
|
|
1473
|
-
NEXT_PUBLIC_USER_PROJECT_LOCATION: cwd
|
|
1474
|
-
};
|
|
1475
|
-
};
|
|
1476
|
-
// src/cli/utils/preview/start-dev-server.ts
|
|
1477
|
-
var devServer;
|
|
1478
|
-
var safeAsyncServerListen = function(server, port) {
|
|
1479
|
-
return new Promise(function(resolve) {
|
|
1480
|
-
server.listen(port, function() {
|
|
1481
|
-
resolve({
|
|
1482
|
-
portAlreadyInUse: false
|
|
1483
|
-
});
|
|
1484
|
-
});
|
|
1485
|
-
server.on("error", function(e) {
|
|
1486
|
-
if (e.code === "EADDRINUSE") {
|
|
1487
|
-
resolve({
|
|
1488
|
-
portAlreadyInUse: true
|
|
1489
|
-
});
|
|
1490
|
-
}
|
|
1491
|
-
});
|
|
1492
|
-
});
|
|
1493
|
-
};
|
|
1494
|
-
var isRunningBuilt = __filename.endsWith(import_node_path5.default.join("cli", "index.js"));
|
|
1495
|
-
var cliPacakgeLocation = isRunningBuilt ? import_node_path5.default.resolve(__dirname, "..") : import_node_path5.default.resolve(__dirname, "../../../..");
|
|
1496
|
-
var startDevServer = function() {
|
|
1497
|
-
var _ref = _async_to_generator(function(emailsDirRelativePath, staticBaseDirRelativePath, port) {
|
|
1498
|
-
var portAlreadyInUse, nextPortToTry, spinner, timeBeforeNextReady, app, isNextReady, nextReadyPromise, nextHandleRequest, secondsToNextReady;
|
|
1583
|
+
// src/cli/utils/preview/hot-reloading/setup-hot-reloading.ts
|
|
1584
|
+
var setupHotreloading = function() {
|
|
1585
|
+
var _ref = _async_to_generator(function(devServer2, emailDirRelativePath) {
|
|
1586
|
+
var clients, io, watcher, exit, changes, reload, absolutePathToEmailsDirectory, _ref, dependencyGraph, updateDependencyGraph, resolveDependentsOf;
|
|
1499
1587
|
return _ts_generator(this, function(_state) {
|
|
1500
1588
|
switch(_state.label){
|
|
1501
1589
|
case 0:
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
});
|
|
1518
|
-
} else {
|
|
1519
|
-
void (nextHandleRequest === null || nextHandleRequest === void 0 ? void 0 : nextHandleRequest(req, res, parsedUrl));
|
|
1520
|
-
}
|
|
1521
|
-
} catch (e) {
|
|
1522
|
-
console.error("caught error", e);
|
|
1523
|
-
res.writeHead(500);
|
|
1524
|
-
res.end();
|
|
1525
|
-
}
|
|
1590
|
+
clients = [];
|
|
1591
|
+
io = new import_socket.Server(devServer2);
|
|
1592
|
+
io.on("connection", function(client) {
|
|
1593
|
+
clients.push(client);
|
|
1594
|
+
client.on("disconnect", function() {
|
|
1595
|
+
clients = clients.filter(function(item) {
|
|
1596
|
+
return item !== client;
|
|
1597
|
+
});
|
|
1598
|
+
});
|
|
1599
|
+
});
|
|
1600
|
+
watcher = (0, import_chokidar.watch)(emailDirRelativePath, {
|
|
1601
|
+
ignoreInitial: true,
|
|
1602
|
+
cwd: import_node_path5.default.resolve(process.cwd()),
|
|
1603
|
+
// eslint-disable-next-line prefer-named-capture-group
|
|
1604
|
+
ignored: /(^|[/\\])\../
|
|
1526
1605
|
});
|
|
1606
|
+
exit = function() {
|
|
1607
|
+
void watcher.close();
|
|
1608
|
+
};
|
|
1609
|
+
process.on("SIGINT", exit);
|
|
1610
|
+
process.on("uncaughtException", exit);
|
|
1611
|
+
changes = [];
|
|
1612
|
+
reload = (0, import_debounce.default)(function() {
|
|
1613
|
+
clients.forEach(function(client) {
|
|
1614
|
+
client.emit("reload", changes);
|
|
1615
|
+
});
|
|
1616
|
+
changes = [];
|
|
1617
|
+
}, 150);
|
|
1618
|
+
absolutePathToEmailsDirectory = import_node_path5.default.resolve(process.cwd(), emailDirRelativePath);
|
|
1527
1619
|
return [
|
|
1528
1620
|
4,
|
|
1529
|
-
|
|
1621
|
+
createDependencyGraph(absolutePathToEmailsDirectory)
|
|
1530
1622
|
];
|
|
1531
1623
|
case 1:
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
return
|
|
1555
|
-
|
|
1556
|
-
|
|
1624
|
+
_ref = _sliced_to_array.apply(void 0, [
|
|
1625
|
+
_state.sent(),
|
|
1626
|
+
2
|
|
1627
|
+
]), dependencyGraph = _ref[0], updateDependencyGraph = _ref[1];
|
|
1628
|
+
resolveDependentsOf = function(pathToChangeTarget) {
|
|
1629
|
+
var moduleEntry = dependencyGraph[pathToChangeTarget];
|
|
1630
|
+
var dependentPaths = [];
|
|
1631
|
+
if (moduleEntry) {
|
|
1632
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1633
|
+
try {
|
|
1634
|
+
for(var _iterator = moduleEntry.dependentPaths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1635
|
+
var dependentPath = _step.value;
|
|
1636
|
+
var _dependentPaths;
|
|
1637
|
+
var dependentsOfDependent = resolveDependentsOf(dependentPath);
|
|
1638
|
+
(_dependentPaths = dependentPaths).push.apply(_dependentPaths, _to_consumable_array(dependentsOfDependent));
|
|
1639
|
+
dependentPaths.push(dependentPath);
|
|
1640
|
+
}
|
|
1641
|
+
} catch (err) {
|
|
1642
|
+
_didIteratorError = true;
|
|
1643
|
+
_iteratorError = err;
|
|
1644
|
+
} finally{
|
|
1645
|
+
try {
|
|
1646
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1647
|
+
_iterator.return();
|
|
1648
|
+
}
|
|
1649
|
+
} finally{
|
|
1650
|
+
if (_didIteratorError) {
|
|
1651
|
+
throw _iteratorError;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1557
1654
|
}
|
|
1655
|
+
}
|
|
1656
|
+
return dependentPaths;
|
|
1657
|
+
};
|
|
1658
|
+
watcher.on("all", function() {
|
|
1659
|
+
var _ref = _async_to_generator(function(event, relativePathToChangeTarget) {
|
|
1660
|
+
var file, pathToChangeTarget, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, dependentPath;
|
|
1661
|
+
return _ts_generator(this, function(_state) {
|
|
1662
|
+
switch(_state.label){
|
|
1663
|
+
case 0:
|
|
1664
|
+
file = relativePathToChangeTarget.split(import_node_path5.default.sep);
|
|
1665
|
+
if (file.length === 0) {
|
|
1666
|
+
return [
|
|
1667
|
+
2
|
|
1668
|
+
];
|
|
1669
|
+
}
|
|
1670
|
+
pathToChangeTarget = import_node_path5.default.resolve(process.cwd(), relativePathToChangeTarget);
|
|
1671
|
+
return [
|
|
1672
|
+
4,
|
|
1673
|
+
updateDependencyGraph(event, pathToChangeTarget)
|
|
1674
|
+
];
|
|
1675
|
+
case 1:
|
|
1676
|
+
_state.sent();
|
|
1677
|
+
changes.push({
|
|
1678
|
+
event: event,
|
|
1679
|
+
filename: relativePathToChangeTarget
|
|
1680
|
+
});
|
|
1681
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1682
|
+
try {
|
|
1683
|
+
for(_iterator = resolveDependentsOf(pathToChangeTarget)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1684
|
+
dependentPath = _step.value;
|
|
1685
|
+
changes.push({
|
|
1686
|
+
event: "change",
|
|
1687
|
+
filename: import_node_path5.default.relative(absolutePathToEmailsDirectory, dependentPath)
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
} catch (err) {
|
|
1691
|
+
_didIteratorError = true;
|
|
1692
|
+
_iteratorError = err;
|
|
1693
|
+
} finally{
|
|
1694
|
+
try {
|
|
1695
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1696
|
+
_iterator.return();
|
|
1697
|
+
}
|
|
1698
|
+
} finally{
|
|
1699
|
+
if (_didIteratorError) {
|
|
1700
|
+
throw _iteratorError;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
reload();
|
|
1705
|
+
return [
|
|
1706
|
+
2
|
|
1707
|
+
];
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1558
1710
|
});
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
});
|
|
1564
|
-
spinner = (0, import_ora.default)({
|
|
1565
|
-
text: "Getting react-email preview server ready...\n",
|
|
1566
|
-
prefixText: " "
|
|
1567
|
-
}).start();
|
|
1568
|
-
closeOraOnSIGNIT(spinner);
|
|
1569
|
-
timeBeforeNextReady = performance.now();
|
|
1570
|
-
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.
|
|
1571
|
-
import_node_path5.default.normalize(emailsDirRelativePath), cliPacakgeLocation, process.cwd()));
|
|
1572
|
-
app = (0, import_next.default)({
|
|
1573
|
-
// passing in env here does not get the environment variables there
|
|
1574
|
-
dev: true,
|
|
1575
|
-
hostname: "localhost",
|
|
1576
|
-
port: port,
|
|
1577
|
-
dir: cliPacakgeLocation
|
|
1578
|
-
});
|
|
1579
|
-
isNextReady = false;
|
|
1580
|
-
nextReadyPromise = app.prepare();
|
|
1581
|
-
return [
|
|
1582
|
-
4,
|
|
1583
|
-
nextReadyPromise
|
|
1584
|
-
];
|
|
1585
|
-
case 2:
|
|
1586
|
-
_state.sent();
|
|
1587
|
-
isNextReady = true;
|
|
1588
|
-
nextHandleRequest = app.getRequestHandler();
|
|
1589
|
-
secondsToNextReady = ((performance.now() - timeBeforeNextReady) / 1e3).toFixed(1);
|
|
1590
|
-
spinner.stopAndPersist({
|
|
1591
|
-
text: "Ready in ".concat(secondsToNextReady, "s\n"),
|
|
1592
|
-
symbol: import_log_symbols.default.success
|
|
1593
|
-
});
|
|
1711
|
+
return function(event, relativePathToChangeTarget) {
|
|
1712
|
+
return _ref.apply(this, arguments);
|
|
1713
|
+
};
|
|
1714
|
+
}());
|
|
1594
1715
|
return [
|
|
1595
1716
|
2,
|
|
1596
|
-
|
|
1717
|
+
watcher
|
|
1597
1718
|
];
|
|
1598
1719
|
}
|
|
1599
1720
|
});
|
|
1600
1721
|
});
|
|
1601
|
-
return function
|
|
1722
|
+
return function setupHotreloading(devServer2, emailDirRelativePath) {
|
|
1602
1723
|
return _ref.apply(this, arguments);
|
|
1603
1724
|
};
|
|
1604
1725
|
}();
|
|
1605
|
-
var makeExitHandler = function(options) {
|
|
1606
|
-
return function(_codeOrSignal) {
|
|
1607
|
-
if (typeof devServer !== "undefined") {
|
|
1608
|
-
console.log("\nshutting down dev server");
|
|
1609
|
-
devServer.close();
|
|
1610
|
-
devServer = void 0;
|
|
1611
|
-
}
|
|
1612
|
-
if (options === null || options === void 0 ? void 0 : options.shouldKillProcess) {
|
|
1613
|
-
process.exit(options.killWithErrorCode ? 1 : 0);
|
|
1614
|
-
}
|
|
1615
|
-
};
|
|
1616
|
-
};
|
|
1617
|
-
process.on("exit", makeExitHandler());
|
|
1618
|
-
process.on("SIGINT", makeExitHandler({
|
|
1619
|
-
shouldKillProcess: true,
|
|
1620
|
-
killWithErrorCode: false
|
|
1621
|
-
}));
|
|
1622
|
-
process.on("SIGUSR1", makeExitHandler({
|
|
1623
|
-
shouldKillProcess: true,
|
|
1624
|
-
killWithErrorCode: false
|
|
1625
|
-
}));
|
|
1626
|
-
process.on("SIGUSR2", makeExitHandler({
|
|
1627
|
-
shouldKillProcess: true,
|
|
1628
|
-
killWithErrorCode: false
|
|
1629
|
-
}));
|
|
1630
|
-
process.on("uncaughtException", makeExitHandler({
|
|
1631
|
-
shouldKillProcess: true,
|
|
1632
|
-
killWithErrorCode: true
|
|
1633
|
-
}));
|
|
1634
1726
|
// src/cli/commands/dev.ts
|
|
1635
1727
|
var dev = function() {
|
|
1636
1728
|
var _ref = _async_to_generator(function(param) {
|
|
@@ -1777,12 +1869,17 @@ var getEmailsDirectoryMetadata = function() {
|
|
|
1777
1869
|
// src/utils/render-resolver-esbuild-plugin.ts
|
|
1778
1870
|
var import_node_path7 = __toESM(require("path"));
|
|
1779
1871
|
var import_node_fs6 = require("fs");
|
|
1872
|
+
function escapeStringForRegex(string) {
|
|
1873
|
+
return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
1874
|
+
}
|
|
1780
1875
|
var renderResolver = function(emailTemplates) {
|
|
1781
1876
|
return {
|
|
1782
1877
|
name: "render-resolver",
|
|
1783
1878
|
setup: function(b) {
|
|
1784
1879
|
b.onLoad({
|
|
1785
|
-
filter: new RegExp(emailTemplates.
|
|
1880
|
+
filter: new RegExp(emailTemplates.map(function(emailPath) {
|
|
1881
|
+
return escapeStringForRegex(emailPath);
|
|
1882
|
+
}).join("|"))
|
|
1786
1883
|
}, function() {
|
|
1787
1884
|
var _ref = _async_to_generator(function(param) {
|
|
1788
1885
|
var pathToFile, _tmp, _, _1;
|