elit 3.0.2 → 3.0.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/dist/cli.js +254 -44
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +713 -150
- package/dist/server.mjs +712 -150
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +5 -13
- package/src/server.ts +339 -38
- package/src/types.ts +0 -6
package/dist/server.mjs
CHANGED
|
@@ -634,6 +634,464 @@ var init_http = __esm({
|
|
|
634
634
|
}
|
|
635
635
|
});
|
|
636
636
|
|
|
637
|
+
// src/fs.ts
|
|
638
|
+
var fs_exports = {};
|
|
639
|
+
__export(fs_exports, {
|
|
640
|
+
appendFile: () => appendFile,
|
|
641
|
+
appendFileSync: () => appendFileSync,
|
|
642
|
+
copyFile: () => copyFile,
|
|
643
|
+
copyFileSync: () => copyFileSync,
|
|
644
|
+
default: () => fs_default,
|
|
645
|
+
exists: () => exists,
|
|
646
|
+
existsSync: () => existsSync,
|
|
647
|
+
getRuntime: () => getRuntime2,
|
|
648
|
+
mkdir: () => mkdir,
|
|
649
|
+
mkdirSync: () => mkdirSync,
|
|
650
|
+
promises: () => promises,
|
|
651
|
+
readFile: () => readFile,
|
|
652
|
+
readFileSync: () => readFileSync,
|
|
653
|
+
readdir: () => readdir,
|
|
654
|
+
readdirSync: () => readdirSync,
|
|
655
|
+
realpath: () => realpath,
|
|
656
|
+
realpathSync: () => realpathSync,
|
|
657
|
+
rename: () => rename,
|
|
658
|
+
renameSync: () => renameSync,
|
|
659
|
+
rmdir: () => rmdir,
|
|
660
|
+
rmdirSync: () => rmdirSync,
|
|
661
|
+
stat: () => stat,
|
|
662
|
+
statSync: () => statSync,
|
|
663
|
+
unlink: () => unlink,
|
|
664
|
+
unlinkSync: () => unlinkSync,
|
|
665
|
+
writeFile: () => writeFile,
|
|
666
|
+
writeFileSync: () => writeFileSync
|
|
667
|
+
});
|
|
668
|
+
function parseOptions(options, defaultValue) {
|
|
669
|
+
return typeof options === "string" ? { encoding: options } : options || defaultValue;
|
|
670
|
+
}
|
|
671
|
+
function decodeContent(content, encoding) {
|
|
672
|
+
if (encoding) {
|
|
673
|
+
return new TextDecoder(encoding).decode(content);
|
|
674
|
+
}
|
|
675
|
+
return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
|
|
676
|
+
}
|
|
677
|
+
function dataToUint8Array(data) {
|
|
678
|
+
if (typeof data === "string") {
|
|
679
|
+
return new TextEncoder().encode(data);
|
|
680
|
+
}
|
|
681
|
+
if (data instanceof Buffer) {
|
|
682
|
+
return new Uint8Array(data);
|
|
683
|
+
}
|
|
684
|
+
return data;
|
|
685
|
+
}
|
|
686
|
+
function processDenoEntries(iterator, withFileTypes) {
|
|
687
|
+
const entries = [];
|
|
688
|
+
for (const entry of iterator) {
|
|
689
|
+
if (withFileTypes) {
|
|
690
|
+
entries.push(createDirentFromDenoEntry(entry));
|
|
691
|
+
} else {
|
|
692
|
+
entries.push(entry.name);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return entries;
|
|
696
|
+
}
|
|
697
|
+
async function processDenoEntriesAsync(iterator, withFileTypes) {
|
|
698
|
+
const entries = [];
|
|
699
|
+
for await (const entry of iterator) {
|
|
700
|
+
if (withFileTypes) {
|
|
701
|
+
entries.push(createDirentFromDenoEntry(entry));
|
|
702
|
+
} else {
|
|
703
|
+
entries.push(entry.name);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return entries;
|
|
707
|
+
}
|
|
708
|
+
async function readFile(path, options) {
|
|
709
|
+
const opts = parseOptions(options, {});
|
|
710
|
+
if (isNode) {
|
|
711
|
+
return fsPromises.readFile(path, opts);
|
|
712
|
+
} else if (isBun) {
|
|
713
|
+
const file = Bun.file(path);
|
|
714
|
+
const content = await file.arrayBuffer();
|
|
715
|
+
return decodeContent(content, opts.encoding);
|
|
716
|
+
} else if (isDeno) {
|
|
717
|
+
const content = await Deno.readFile(path);
|
|
718
|
+
return decodeContent(content, opts.encoding);
|
|
719
|
+
}
|
|
720
|
+
throw new Error("Unsupported runtime");
|
|
721
|
+
}
|
|
722
|
+
function readFileSync(path, options) {
|
|
723
|
+
const opts = parseOptions(options, {});
|
|
724
|
+
if (isNode) {
|
|
725
|
+
return fs.readFileSync(path, opts);
|
|
726
|
+
} else if (isBun) {
|
|
727
|
+
const file = Bun.file(path);
|
|
728
|
+
const content = file.arrayBuffer();
|
|
729
|
+
return decodeContent(content, opts.encoding);
|
|
730
|
+
} else if (isDeno) {
|
|
731
|
+
const content = Deno.readFileSync(path);
|
|
732
|
+
return decodeContent(content, opts.encoding);
|
|
733
|
+
}
|
|
734
|
+
throw new Error("Unsupported runtime");
|
|
735
|
+
}
|
|
736
|
+
async function writeFile(path, data, options) {
|
|
737
|
+
const opts = parseOptions(options, {});
|
|
738
|
+
if (isNode) {
|
|
739
|
+
return fsPromises.writeFile(path, data, opts);
|
|
740
|
+
} else if (isBun) {
|
|
741
|
+
await Bun.write(path, data);
|
|
742
|
+
} else if (isDeno) {
|
|
743
|
+
await Deno.writeFile(path, dataToUint8Array(data));
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function writeFileSync(path, data, options) {
|
|
747
|
+
const opts = parseOptions(options, {});
|
|
748
|
+
if (isNode) {
|
|
749
|
+
fs.writeFileSync(path, data, opts);
|
|
750
|
+
} else if (isBun) {
|
|
751
|
+
Bun.write(path, data);
|
|
752
|
+
} else if (isDeno) {
|
|
753
|
+
Deno.writeFileSync(path, dataToUint8Array(data));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
async function appendFile(path, data, options) {
|
|
757
|
+
const opts = parseOptions(options, {});
|
|
758
|
+
if (isNode) {
|
|
759
|
+
return fsPromises.appendFile(path, data, opts);
|
|
760
|
+
} else {
|
|
761
|
+
if (await exists(path)) {
|
|
762
|
+
const existing = await readFile(path);
|
|
763
|
+
const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
|
|
764
|
+
await writeFile(path, combined, opts);
|
|
765
|
+
} else {
|
|
766
|
+
await writeFile(path, data, opts);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
function appendFileSync(path, data, options) {
|
|
771
|
+
const opts = parseOptions(options, {});
|
|
772
|
+
if (isNode) {
|
|
773
|
+
fs.appendFileSync(path, data, opts);
|
|
774
|
+
} else {
|
|
775
|
+
if (existsSync(path)) {
|
|
776
|
+
const existing = readFileSync(path);
|
|
777
|
+
const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
|
|
778
|
+
writeFileSync(path, combined, opts);
|
|
779
|
+
} else {
|
|
780
|
+
writeFileSync(path, data, opts);
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
async function exists(path) {
|
|
785
|
+
try {
|
|
786
|
+
await stat(path);
|
|
787
|
+
return true;
|
|
788
|
+
} catch {
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function existsSync(path) {
|
|
793
|
+
try {
|
|
794
|
+
statSync(path);
|
|
795
|
+
return true;
|
|
796
|
+
} catch {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
async function stat(path) {
|
|
801
|
+
if (isNode) {
|
|
802
|
+
return fsPromises.stat(path);
|
|
803
|
+
} else if (isBun) {
|
|
804
|
+
const file = Bun.file(path);
|
|
805
|
+
const size = file.size;
|
|
806
|
+
const exists2 = await file.exists();
|
|
807
|
+
if (!exists2) {
|
|
808
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
809
|
+
}
|
|
810
|
+
return createStatsObject(path, size, false);
|
|
811
|
+
} else if (isDeno) {
|
|
812
|
+
const info = await Deno.stat(path);
|
|
813
|
+
return createStatsFromDenoFileInfo(info);
|
|
814
|
+
}
|
|
815
|
+
throw new Error("Unsupported runtime");
|
|
816
|
+
}
|
|
817
|
+
function statSync(path) {
|
|
818
|
+
if (isNode) {
|
|
819
|
+
return fs.statSync(path);
|
|
820
|
+
} else if (isBun) {
|
|
821
|
+
const file = Bun.file(path);
|
|
822
|
+
const size = file.size;
|
|
823
|
+
try {
|
|
824
|
+
file.arrayBuffer();
|
|
825
|
+
} catch {
|
|
826
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
827
|
+
}
|
|
828
|
+
return createStatsObject(path, size, false);
|
|
829
|
+
} else if (isDeno) {
|
|
830
|
+
const info = Deno.statSync(path);
|
|
831
|
+
return createStatsFromDenoFileInfo(info);
|
|
832
|
+
}
|
|
833
|
+
throw new Error("Unsupported runtime");
|
|
834
|
+
}
|
|
835
|
+
async function mkdir(path, options) {
|
|
836
|
+
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
837
|
+
if (isNode) {
|
|
838
|
+
await fsPromises.mkdir(path, opts);
|
|
839
|
+
} else if (isBun) {
|
|
840
|
+
await Deno.mkdir(path, { recursive: opts.recursive });
|
|
841
|
+
} else if (isDeno) {
|
|
842
|
+
await Deno.mkdir(path, { recursive: opts.recursive });
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
function mkdirSync(path, options) {
|
|
846
|
+
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
847
|
+
if (isNode) {
|
|
848
|
+
fs.mkdirSync(path, opts);
|
|
849
|
+
} else if (isBun) {
|
|
850
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
851
|
+
} else if (isDeno) {
|
|
852
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
async function readdir(path, options) {
|
|
856
|
+
const opts = parseOptions(options, {});
|
|
857
|
+
if (isNode) {
|
|
858
|
+
return fsPromises.readdir(path, opts);
|
|
859
|
+
} else if (isBunOrDeno) {
|
|
860
|
+
return processDenoEntriesAsync(Deno.readDir(path), opts.withFileTypes);
|
|
861
|
+
}
|
|
862
|
+
throw new Error("Unsupported runtime");
|
|
863
|
+
}
|
|
864
|
+
function readdirSync(path, options) {
|
|
865
|
+
const opts = parseOptions(options, {});
|
|
866
|
+
if (isNode) {
|
|
867
|
+
return fs.readdirSync(path, opts);
|
|
868
|
+
} else if (isBunOrDeno) {
|
|
869
|
+
return processDenoEntries(Deno.readDirSync(path), opts.withFileTypes);
|
|
870
|
+
}
|
|
871
|
+
throw new Error("Unsupported runtime");
|
|
872
|
+
}
|
|
873
|
+
async function unlink(path) {
|
|
874
|
+
if (isNode) {
|
|
875
|
+
return fsPromises.unlink(path);
|
|
876
|
+
} else if (isBun) {
|
|
877
|
+
await Deno.remove(path);
|
|
878
|
+
} else if (isDeno) {
|
|
879
|
+
await Deno.remove(path);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
function unlinkSync(path) {
|
|
883
|
+
if (isNode) {
|
|
884
|
+
fs.unlinkSync(path);
|
|
885
|
+
} else if (isBun) {
|
|
886
|
+
Deno.removeSync(path);
|
|
887
|
+
} else if (isDeno) {
|
|
888
|
+
Deno.removeSync(path);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
async function rmdir(path, options) {
|
|
892
|
+
if (isNode) {
|
|
893
|
+
return fsPromises.rmdir(path, options);
|
|
894
|
+
} else if (isBun) {
|
|
895
|
+
await Deno.remove(path, { recursive: options?.recursive });
|
|
896
|
+
} else if (isDeno) {
|
|
897
|
+
await Deno.remove(path, { recursive: options?.recursive });
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
function rmdirSync(path, options) {
|
|
901
|
+
if (isNode) {
|
|
902
|
+
fs.rmdirSync(path, options);
|
|
903
|
+
} else if (isBun) {
|
|
904
|
+
Deno.removeSync(path, { recursive: options?.recursive });
|
|
905
|
+
} else if (isDeno) {
|
|
906
|
+
Deno.removeSync(path, { recursive: options?.recursive });
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
async function rename(oldPath, newPath) {
|
|
910
|
+
if (isNode) {
|
|
911
|
+
return fsPromises.rename(oldPath, newPath);
|
|
912
|
+
} else if (isBun) {
|
|
913
|
+
await Deno.rename(oldPath, newPath);
|
|
914
|
+
} else if (isDeno) {
|
|
915
|
+
await Deno.rename(oldPath, newPath);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
function renameSync(oldPath, newPath) {
|
|
919
|
+
if (isNode) {
|
|
920
|
+
fs.renameSync(oldPath, newPath);
|
|
921
|
+
} else if (isBun) {
|
|
922
|
+
Deno.renameSync(oldPath, newPath);
|
|
923
|
+
} else if (isDeno) {
|
|
924
|
+
Deno.renameSync(oldPath, newPath);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
async function copyFile(src, dest, flags) {
|
|
928
|
+
if (isNode) {
|
|
929
|
+
return fsPromises.copyFile(src, dest, flags);
|
|
930
|
+
} else if (isBun) {
|
|
931
|
+
await Deno.copyFile(src, dest);
|
|
932
|
+
} else if (isDeno) {
|
|
933
|
+
await Deno.copyFile(src, dest);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
function copyFileSync(src, dest, flags) {
|
|
937
|
+
if (isNode) {
|
|
938
|
+
fs.copyFileSync(src, dest, flags);
|
|
939
|
+
} else if (isBun) {
|
|
940
|
+
Deno.copyFileSync(src, dest);
|
|
941
|
+
} else if (isDeno) {
|
|
942
|
+
Deno.copyFileSync(src, dest);
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
async function realpath(path, options) {
|
|
946
|
+
if (isNode) {
|
|
947
|
+
return fsPromises.realpath(path, options);
|
|
948
|
+
} else if (isBun) {
|
|
949
|
+
const fs2 = __require("fs/promises");
|
|
950
|
+
return fs2.realpath(path, options);
|
|
951
|
+
} else if (isDeno) {
|
|
952
|
+
return await Deno.realPath(path);
|
|
953
|
+
}
|
|
954
|
+
return path;
|
|
955
|
+
}
|
|
956
|
+
function realpathSync(path, options) {
|
|
957
|
+
if (isNode) {
|
|
958
|
+
return fs.realpathSync(path, options);
|
|
959
|
+
} else if (isBun) {
|
|
960
|
+
const fs2 = __require("fs");
|
|
961
|
+
return fs2.realpathSync(path, options);
|
|
962
|
+
} else if (isDeno) {
|
|
963
|
+
return Deno.realPathSync(path);
|
|
964
|
+
}
|
|
965
|
+
return path;
|
|
966
|
+
}
|
|
967
|
+
function createStatsObject(_path, size, isDir) {
|
|
968
|
+
const now = Date.now();
|
|
969
|
+
return {
|
|
970
|
+
isFile: () => !isDir,
|
|
971
|
+
isDirectory: () => isDir,
|
|
972
|
+
isBlockDevice: () => false,
|
|
973
|
+
isCharacterDevice: () => false,
|
|
974
|
+
isSymbolicLink: () => false,
|
|
975
|
+
isFIFO: () => false,
|
|
976
|
+
isSocket: () => false,
|
|
977
|
+
dev: 0,
|
|
978
|
+
ino: 0,
|
|
979
|
+
mode: isDir ? 16877 : 33188,
|
|
980
|
+
nlink: 1,
|
|
981
|
+
uid: 0,
|
|
982
|
+
gid: 0,
|
|
983
|
+
rdev: 0,
|
|
984
|
+
size,
|
|
985
|
+
blksize: 4096,
|
|
986
|
+
blocks: Math.ceil(size / 512),
|
|
987
|
+
atimeMs: now,
|
|
988
|
+
mtimeMs: now,
|
|
989
|
+
ctimeMs: now,
|
|
990
|
+
birthtimeMs: now,
|
|
991
|
+
atime: new Date(now),
|
|
992
|
+
mtime: new Date(now),
|
|
993
|
+
ctime: new Date(now),
|
|
994
|
+
birthtime: new Date(now)
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
function createStatsFromDenoFileInfo(info) {
|
|
998
|
+
return {
|
|
999
|
+
isFile: () => info.isFile,
|
|
1000
|
+
isDirectory: () => info.isDirectory,
|
|
1001
|
+
isBlockDevice: () => false,
|
|
1002
|
+
isCharacterDevice: () => false,
|
|
1003
|
+
isSymbolicLink: () => info.isSymlink || false,
|
|
1004
|
+
isFIFO: () => false,
|
|
1005
|
+
isSocket: () => false,
|
|
1006
|
+
dev: info.dev || 0,
|
|
1007
|
+
ino: info.ino || 0,
|
|
1008
|
+
mode: info.mode || 0,
|
|
1009
|
+
nlink: info.nlink || 1,
|
|
1010
|
+
uid: info.uid || 0,
|
|
1011
|
+
gid: info.gid || 0,
|
|
1012
|
+
rdev: 0,
|
|
1013
|
+
size: info.size,
|
|
1014
|
+
blksize: info.blksize || 4096,
|
|
1015
|
+
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
1016
|
+
atimeMs: info.atime?.getTime() || Date.now(),
|
|
1017
|
+
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
1018
|
+
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1019
|
+
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1020
|
+
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
1021
|
+
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
1022
|
+
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
1023
|
+
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
function createDirentFromDenoEntry(entry) {
|
|
1027
|
+
return {
|
|
1028
|
+
name: entry.name,
|
|
1029
|
+
isFile: () => entry.isFile,
|
|
1030
|
+
isDirectory: () => entry.isDirectory,
|
|
1031
|
+
isBlockDevice: () => false,
|
|
1032
|
+
isCharacterDevice: () => false,
|
|
1033
|
+
isSymbolicLink: () => entry.isSymlink || false,
|
|
1034
|
+
isFIFO: () => false,
|
|
1035
|
+
isSocket: () => false
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
function getRuntime2() {
|
|
1039
|
+
return runtime;
|
|
1040
|
+
}
|
|
1041
|
+
var isBunOrDeno, fs, fsPromises, promises, fs_default;
|
|
1042
|
+
var init_fs = __esm({
|
|
1043
|
+
"src/fs.ts"() {
|
|
1044
|
+
"use strict";
|
|
1045
|
+
init_runtime();
|
|
1046
|
+
isBunOrDeno = isBun || isDeno;
|
|
1047
|
+
if (isNode) {
|
|
1048
|
+
fs = __require("fs");
|
|
1049
|
+
fsPromises = __require("fs/promises");
|
|
1050
|
+
}
|
|
1051
|
+
promises = {
|
|
1052
|
+
readFile,
|
|
1053
|
+
writeFile,
|
|
1054
|
+
appendFile,
|
|
1055
|
+
stat,
|
|
1056
|
+
mkdir,
|
|
1057
|
+
readdir,
|
|
1058
|
+
unlink,
|
|
1059
|
+
rmdir,
|
|
1060
|
+
rename,
|
|
1061
|
+
copyFile,
|
|
1062
|
+
realpath
|
|
1063
|
+
};
|
|
1064
|
+
fs_default = {
|
|
1065
|
+
readFile,
|
|
1066
|
+
readFileSync,
|
|
1067
|
+
writeFile,
|
|
1068
|
+
writeFileSync,
|
|
1069
|
+
appendFile,
|
|
1070
|
+
appendFileSync,
|
|
1071
|
+
exists,
|
|
1072
|
+
existsSync,
|
|
1073
|
+
stat,
|
|
1074
|
+
statSync,
|
|
1075
|
+
mkdir,
|
|
1076
|
+
mkdirSync,
|
|
1077
|
+
readdir,
|
|
1078
|
+
readdirSync,
|
|
1079
|
+
unlink,
|
|
1080
|
+
unlinkSync,
|
|
1081
|
+
rmdir,
|
|
1082
|
+
rmdirSync,
|
|
1083
|
+
rename,
|
|
1084
|
+
renameSync,
|
|
1085
|
+
copyFile,
|
|
1086
|
+
copyFileSync,
|
|
1087
|
+
realpath,
|
|
1088
|
+
realpathSync,
|
|
1089
|
+
promises,
|
|
1090
|
+
getRuntime: getRuntime2
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
|
|
637
1095
|
// src/server.ts
|
|
638
1096
|
init_http();
|
|
639
1097
|
|
|
@@ -1208,124 +1666,8 @@ function watch(paths, options) {
|
|
|
1208
1666
|
return watcher;
|
|
1209
1667
|
}
|
|
1210
1668
|
|
|
1211
|
-
// src/
|
|
1212
|
-
|
|
1213
|
-
function parseOptions(options, defaultValue) {
|
|
1214
|
-
return typeof options === "string" ? { encoding: options } : options || defaultValue;
|
|
1215
|
-
}
|
|
1216
|
-
function decodeContent(content, encoding) {
|
|
1217
|
-
if (encoding) {
|
|
1218
|
-
return new TextDecoder(encoding).decode(content);
|
|
1219
|
-
}
|
|
1220
|
-
return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
|
|
1221
|
-
}
|
|
1222
|
-
var fs;
|
|
1223
|
-
var fsPromises;
|
|
1224
|
-
if (isNode) {
|
|
1225
|
-
fs = __require("fs");
|
|
1226
|
-
fsPromises = __require("fs/promises");
|
|
1227
|
-
}
|
|
1228
|
-
async function readFile(path, options) {
|
|
1229
|
-
const opts = parseOptions(options, {});
|
|
1230
|
-
if (isNode) {
|
|
1231
|
-
return fsPromises.readFile(path, opts);
|
|
1232
|
-
} else if (isBun) {
|
|
1233
|
-
const file = Bun.file(path);
|
|
1234
|
-
const content = await file.arrayBuffer();
|
|
1235
|
-
return decodeContent(content, opts.encoding);
|
|
1236
|
-
} else if (isDeno) {
|
|
1237
|
-
const content = await Deno.readFile(path);
|
|
1238
|
-
return decodeContent(content, opts.encoding);
|
|
1239
|
-
}
|
|
1240
|
-
throw new Error("Unsupported runtime");
|
|
1241
|
-
}
|
|
1242
|
-
async function stat(path) {
|
|
1243
|
-
if (isNode) {
|
|
1244
|
-
return fsPromises.stat(path);
|
|
1245
|
-
} else if (isBun) {
|
|
1246
|
-
const file = Bun.file(path);
|
|
1247
|
-
const size = file.size;
|
|
1248
|
-
const exists = await file.exists();
|
|
1249
|
-
if (!exists) {
|
|
1250
|
-
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
1251
|
-
}
|
|
1252
|
-
return createStatsObject(path, size, false);
|
|
1253
|
-
} else if (isDeno) {
|
|
1254
|
-
const info = await Deno.stat(path);
|
|
1255
|
-
return createStatsFromDenoFileInfo(info);
|
|
1256
|
-
}
|
|
1257
|
-
throw new Error("Unsupported runtime");
|
|
1258
|
-
}
|
|
1259
|
-
async function realpath(path, options) {
|
|
1260
|
-
if (isNode) {
|
|
1261
|
-
return fsPromises.realpath(path, options);
|
|
1262
|
-
} else if (isBun) {
|
|
1263
|
-
const fs2 = __require("fs/promises");
|
|
1264
|
-
return fs2.realpath(path, options);
|
|
1265
|
-
} else if (isDeno) {
|
|
1266
|
-
return await Deno.realPath(path);
|
|
1267
|
-
}
|
|
1268
|
-
return path;
|
|
1269
|
-
}
|
|
1270
|
-
function createStatsObject(_path, size, isDir) {
|
|
1271
|
-
const now = Date.now();
|
|
1272
|
-
return {
|
|
1273
|
-
isFile: () => !isDir,
|
|
1274
|
-
isDirectory: () => isDir,
|
|
1275
|
-
isBlockDevice: () => false,
|
|
1276
|
-
isCharacterDevice: () => false,
|
|
1277
|
-
isSymbolicLink: () => false,
|
|
1278
|
-
isFIFO: () => false,
|
|
1279
|
-
isSocket: () => false,
|
|
1280
|
-
dev: 0,
|
|
1281
|
-
ino: 0,
|
|
1282
|
-
mode: isDir ? 16877 : 33188,
|
|
1283
|
-
nlink: 1,
|
|
1284
|
-
uid: 0,
|
|
1285
|
-
gid: 0,
|
|
1286
|
-
rdev: 0,
|
|
1287
|
-
size,
|
|
1288
|
-
blksize: 4096,
|
|
1289
|
-
blocks: Math.ceil(size / 512),
|
|
1290
|
-
atimeMs: now,
|
|
1291
|
-
mtimeMs: now,
|
|
1292
|
-
ctimeMs: now,
|
|
1293
|
-
birthtimeMs: now,
|
|
1294
|
-
atime: new Date(now),
|
|
1295
|
-
mtime: new Date(now),
|
|
1296
|
-
ctime: new Date(now),
|
|
1297
|
-
birthtime: new Date(now)
|
|
1298
|
-
};
|
|
1299
|
-
}
|
|
1300
|
-
function createStatsFromDenoFileInfo(info) {
|
|
1301
|
-
return {
|
|
1302
|
-
isFile: () => info.isFile,
|
|
1303
|
-
isDirectory: () => info.isDirectory,
|
|
1304
|
-
isBlockDevice: () => false,
|
|
1305
|
-
isCharacterDevice: () => false,
|
|
1306
|
-
isSymbolicLink: () => info.isSymlink || false,
|
|
1307
|
-
isFIFO: () => false,
|
|
1308
|
-
isSocket: () => false,
|
|
1309
|
-
dev: info.dev || 0,
|
|
1310
|
-
ino: info.ino || 0,
|
|
1311
|
-
mode: info.mode || 0,
|
|
1312
|
-
nlink: info.nlink || 1,
|
|
1313
|
-
uid: info.uid || 0,
|
|
1314
|
-
gid: info.gid || 0,
|
|
1315
|
-
rdev: 0,
|
|
1316
|
-
size: info.size,
|
|
1317
|
-
blksize: info.blksize || 4096,
|
|
1318
|
-
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
1319
|
-
atimeMs: info.atime?.getTime() || Date.now(),
|
|
1320
|
-
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
1321
|
-
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1322
|
-
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1323
|
-
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
1324
|
-
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
1325
|
-
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
1326
|
-
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
1327
|
-
};
|
|
1328
|
-
}
|
|
1669
|
+
// src/server.ts
|
|
1670
|
+
init_fs();
|
|
1329
1671
|
|
|
1330
1672
|
// src/path.ts
|
|
1331
1673
|
init_runtime();
|
|
@@ -2380,22 +2722,23 @@ var sendError = (res, code, msg) => {
|
|
|
2380
2722
|
var send404 = (res, msg = "Not Found") => sendError(res, 404, msg);
|
|
2381
2723
|
var send403 = (res, msg = "Forbidden") => sendError(res, 403, msg);
|
|
2382
2724
|
var send500 = (res, msg = "Internal Server Error") => sendError(res, 500, msg);
|
|
2383
|
-
var createElitImportMap = (basePath = "", mode = "dev") => {
|
|
2725
|
+
var createElitImportMap = async (rootDir, basePath = "", mode = "dev") => {
|
|
2384
2726
|
const srcPath = mode === "dev" ? basePath ? `${basePath}/node_modules/elit/src` : "/node_modules/elit/src" : basePath ? `${basePath}/node_modules/elit/dist` : "/node_modules/elit/dist";
|
|
2385
2727
|
const fileExt = mode === "dev" ? ".ts" : ".mjs";
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
"elit":
|
|
2389
|
-
"elit/":
|
|
2390
|
-
"elit/
|
|
2391
|
-
"elit/
|
|
2392
|
-
"elit/
|
|
2393
|
-
"elit/
|
|
2394
|
-
"elit/
|
|
2395
|
-
"elit/
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
}
|
|
2728
|
+
const elitImports = {
|
|
2729
|
+
"elit": `${srcPath}/index${fileExt}`,
|
|
2730
|
+
"elit/": `${srcPath}/`,
|
|
2731
|
+
"elit/dom": `${srcPath}/dom${fileExt}`,
|
|
2732
|
+
"elit/state": `${srcPath}/state${fileExt}`,
|
|
2733
|
+
"elit/style": `${srcPath}/style${fileExt}`,
|
|
2734
|
+
"elit/el": `${srcPath}/el${fileExt}`,
|
|
2735
|
+
"elit/router": `${srcPath}/router${fileExt}`,
|
|
2736
|
+
"elit/hmr": `${srcPath}/hmr${fileExt}`,
|
|
2737
|
+
"elit/types": `${srcPath}/types${fileExt}`
|
|
2738
|
+
};
|
|
2739
|
+
const externalImports = await generateExternalImportMaps(rootDir, basePath);
|
|
2740
|
+
const allImports = { ...externalImports, ...elitImports };
|
|
2741
|
+
return `<script type="importmap">${JSON.stringify({ imports: allImports }, null, 2)}</script>`;
|
|
2399
2742
|
};
|
|
2400
2743
|
var createHMRScript = (port, wsPath) => `<script>(function(){let ws;let retries=0;let maxRetries=5;function connect(){ws=new WebSocket('ws://'+window.location.hostname+':${port}${wsPath}');ws.onopen=()=>{console.log('[Elit HMR] Connected');retries=0};ws.onmessage=(e)=>{const d=JSON.parse(e.data);if(d.type==='update'){console.log('[Elit HMR] File updated:',d.path);window.location.reload()}else if(d.type==='reload'){console.log('[Elit HMR] Reloading...');window.location.reload()}else if(d.type==='error')console.error('[Elit HMR] Error:',d.error)};ws.onclose=()=>{if(retries<maxRetries){retries++;setTimeout(connect,1000*retries)}else if(retries===maxRetries){console.log('[Elit HMR] Connection closed. Start dev server to reconnect.')}};ws.onerror=()=>{ws.close()}}connect()})();</script>`;
|
|
2401
2744
|
var rewriteRelativePaths = (html2, basePath) => {
|
|
@@ -2423,6 +2766,223 @@ async function findSpecialDir(startDir, targetDir) {
|
|
|
2423
2766
|
}
|
|
2424
2767
|
return null;
|
|
2425
2768
|
}
|
|
2769
|
+
var importMapCache = /* @__PURE__ */ new Map();
|
|
2770
|
+
function clearImportMapCache() {
|
|
2771
|
+
importMapCache.clear();
|
|
2772
|
+
}
|
|
2773
|
+
async function generateExternalImportMaps(rootDir, basePath = "") {
|
|
2774
|
+
const cacheKey = `${rootDir}:${basePath}`;
|
|
2775
|
+
if (importMapCache.has(cacheKey)) {
|
|
2776
|
+
return importMapCache.get(cacheKey);
|
|
2777
|
+
}
|
|
2778
|
+
const importMap = {};
|
|
2779
|
+
const nodeModulesPath = await findNodeModules(rootDir);
|
|
2780
|
+
if (!nodeModulesPath) {
|
|
2781
|
+
importMapCache.set(cacheKey, importMap);
|
|
2782
|
+
return importMap;
|
|
2783
|
+
}
|
|
2784
|
+
try {
|
|
2785
|
+
const { readdir: readdir2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
2786
|
+
const packages = await readdir2(nodeModulesPath);
|
|
2787
|
+
for (const pkgEntry of packages) {
|
|
2788
|
+
const pkg = typeof pkgEntry === "string" ? pkgEntry : pkgEntry.name;
|
|
2789
|
+
if (pkg.startsWith(".")) continue;
|
|
2790
|
+
if (pkg.startsWith("@")) {
|
|
2791
|
+
try {
|
|
2792
|
+
const scopedPackages = await readdir2(join(nodeModulesPath, pkg));
|
|
2793
|
+
for (const scopedEntry of scopedPackages) {
|
|
2794
|
+
const scopedPkg = typeof scopedEntry === "string" ? scopedEntry : scopedEntry.name;
|
|
2795
|
+
const fullPkgName = `${pkg}/${scopedPkg}`;
|
|
2796
|
+
await processPackage(nodeModulesPath, fullPkgName, importMap, basePath);
|
|
2797
|
+
}
|
|
2798
|
+
} catch {
|
|
2799
|
+
}
|
|
2800
|
+
} else {
|
|
2801
|
+
await processPackage(nodeModulesPath, pkg, importMap, basePath);
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
} catch (error) {
|
|
2805
|
+
console.error("[Import Maps] Error scanning node_modules:", error);
|
|
2806
|
+
}
|
|
2807
|
+
importMapCache.set(cacheKey, importMap);
|
|
2808
|
+
return importMap;
|
|
2809
|
+
}
|
|
2810
|
+
async function findNodeModules(startDir) {
|
|
2811
|
+
const foundDir = await findSpecialDir(startDir, "node_modules");
|
|
2812
|
+
return foundDir ? join(foundDir, "node_modules") : null;
|
|
2813
|
+
}
|
|
2814
|
+
function isBrowserCompatible(pkgName, pkgJson) {
|
|
2815
|
+
const buildTools = [
|
|
2816
|
+
"typescript",
|
|
2817
|
+
"esbuild",
|
|
2818
|
+
"@esbuild/",
|
|
2819
|
+
"tsx",
|
|
2820
|
+
"tsup",
|
|
2821
|
+
"rollup",
|
|
2822
|
+
"vite",
|
|
2823
|
+
"webpack",
|
|
2824
|
+
"parcel",
|
|
2825
|
+
"terser",
|
|
2826
|
+
"uglify",
|
|
2827
|
+
"babel",
|
|
2828
|
+
"@babel/",
|
|
2829
|
+
"postcss",
|
|
2830
|
+
"autoprefixer",
|
|
2831
|
+
"cssnano",
|
|
2832
|
+
"sass",
|
|
2833
|
+
"less",
|
|
2834
|
+
"stylus"
|
|
2835
|
+
];
|
|
2836
|
+
const nodeOnly = [
|
|
2837
|
+
"node-",
|
|
2838
|
+
"@node-",
|
|
2839
|
+
"fsevents",
|
|
2840
|
+
"chokidar",
|
|
2841
|
+
"express",
|
|
2842
|
+
"koa",
|
|
2843
|
+
"fastify",
|
|
2844
|
+
"nest",
|
|
2845
|
+
"commander",
|
|
2846
|
+
"yargs",
|
|
2847
|
+
"inquirer",
|
|
2848
|
+
"chalk",
|
|
2849
|
+
"ora",
|
|
2850
|
+
"nodemon",
|
|
2851
|
+
"pm2",
|
|
2852
|
+
"dotenv"
|
|
2853
|
+
];
|
|
2854
|
+
const testingTools = [
|
|
2855
|
+
"jest",
|
|
2856
|
+
"vitest",
|
|
2857
|
+
"mocha",
|
|
2858
|
+
"chai",
|
|
2859
|
+
"jasmine",
|
|
2860
|
+
"@jest/",
|
|
2861
|
+
"@testing-library/",
|
|
2862
|
+
"@vitest/",
|
|
2863
|
+
"playwright",
|
|
2864
|
+
"puppeteer",
|
|
2865
|
+
"cypress"
|
|
2866
|
+
];
|
|
2867
|
+
const linters = [
|
|
2868
|
+
"eslint",
|
|
2869
|
+
"@eslint/",
|
|
2870
|
+
"prettier",
|
|
2871
|
+
"tslint",
|
|
2872
|
+
"stylelint",
|
|
2873
|
+
"commitlint"
|
|
2874
|
+
];
|
|
2875
|
+
const typeDefinitions = [
|
|
2876
|
+
"@types/",
|
|
2877
|
+
"@typescript-eslint/"
|
|
2878
|
+
];
|
|
2879
|
+
const utilities = [
|
|
2880
|
+
"get-tsconfig",
|
|
2881
|
+
"resolve-pkg-maps",
|
|
2882
|
+
"pkg-types",
|
|
2883
|
+
"fast-glob",
|
|
2884
|
+
"globby",
|
|
2885
|
+
"micromatch",
|
|
2886
|
+
"execa",
|
|
2887
|
+
"cross-spawn",
|
|
2888
|
+
"shelljs"
|
|
2889
|
+
];
|
|
2890
|
+
const skipPatterns = [
|
|
2891
|
+
...buildTools,
|
|
2892
|
+
...nodeOnly,
|
|
2893
|
+
...testingTools,
|
|
2894
|
+
...linters,
|
|
2895
|
+
...typeDefinitions,
|
|
2896
|
+
...utilities
|
|
2897
|
+
];
|
|
2898
|
+
if (skipPatterns.some((pattern) => pkgName.startsWith(pattern))) {
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
if (pkgName === "lodash") {
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
if (pkgJson.browser || pkgJson.module) {
|
|
2905
|
+
return true;
|
|
2906
|
+
}
|
|
2907
|
+
if (pkgJson.exports) {
|
|
2908
|
+
const exportsStr = JSON.stringify(pkgJson.exports);
|
|
2909
|
+
if (exportsStr.includes('"import"') || exportsStr.includes('"browser"')) {
|
|
2910
|
+
return true;
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
if (pkgJson.type === "commonjs" && !pkgJson.module && !pkgJson.browser) {
|
|
2914
|
+
return false;
|
|
2915
|
+
}
|
|
2916
|
+
return !!(pkgJson.exports || pkgJson.type === "module" || pkgJson.module);
|
|
2917
|
+
}
|
|
2918
|
+
async function processPackage(nodeModulesPath, pkgName, importMap, basePath) {
|
|
2919
|
+
const pkgPath = join(nodeModulesPath, pkgName);
|
|
2920
|
+
const pkgJsonPath = join(pkgPath, "package.json");
|
|
2921
|
+
try {
|
|
2922
|
+
const pkgJsonContent = await readFile(pkgJsonPath);
|
|
2923
|
+
const pkgJson = JSON.parse(pkgJsonContent.toString());
|
|
2924
|
+
if (!isBrowserCompatible(pkgName, pkgJson)) {
|
|
2925
|
+
return;
|
|
2926
|
+
}
|
|
2927
|
+
const baseUrl = basePath ? `${basePath}/node_modules/${pkgName}` : `/node_modules/${pkgName}`;
|
|
2928
|
+
if (pkgJson.exports) {
|
|
2929
|
+
processExportsField(pkgName, pkgJson.exports, baseUrl, importMap);
|
|
2930
|
+
} else {
|
|
2931
|
+
const entryPoint = pkgJson.browser || pkgJson.module || pkgJson.main || "index.js";
|
|
2932
|
+
importMap[pkgName] = `${baseUrl}/${entryPoint}`;
|
|
2933
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
2934
|
+
}
|
|
2935
|
+
} catch {
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
function processExportsField(pkgName, exports, baseUrl, importMap) {
|
|
2939
|
+
if (typeof exports === "string") {
|
|
2940
|
+
importMap[pkgName] = `${baseUrl}/${exports}`;
|
|
2941
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
2942
|
+
return;
|
|
2943
|
+
}
|
|
2944
|
+
if (typeof exports === "object" && exports !== null) {
|
|
2945
|
+
if ("." in exports) {
|
|
2946
|
+
const dotExport = exports["."];
|
|
2947
|
+
const resolved = resolveExport(dotExport);
|
|
2948
|
+
if (resolved) {
|
|
2949
|
+
importMap[pkgName] = `${baseUrl}/${resolved}`;
|
|
2950
|
+
}
|
|
2951
|
+
} else if ("import" in exports) {
|
|
2952
|
+
const resolved = resolveExport(exports);
|
|
2953
|
+
if (resolved) {
|
|
2954
|
+
importMap[pkgName] = `${baseUrl}/${resolved}`;
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
for (const [key, value] of Object.entries(exports)) {
|
|
2958
|
+
if (key === "." || key === "import" || key === "require" || key === "types" || key === "default") {
|
|
2959
|
+
continue;
|
|
2960
|
+
}
|
|
2961
|
+
const resolved = resolveExport(value);
|
|
2962
|
+
if (resolved) {
|
|
2963
|
+
const cleanKey = key.startsWith("./") ? key.slice(2) : key;
|
|
2964
|
+
const importName = cleanKey ? `${pkgName}/${cleanKey}` : pkgName;
|
|
2965
|
+
importMap[importName] = `${baseUrl}/${resolved}`;
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
function resolveExport(exportValue) {
|
|
2972
|
+
if (typeof exportValue === "string") {
|
|
2973
|
+
return exportValue.startsWith("./") ? exportValue.slice(2) : exportValue;
|
|
2974
|
+
}
|
|
2975
|
+
if (typeof exportValue === "object" && exportValue !== null) {
|
|
2976
|
+
const resolved = exportValue.import || exportValue.browser || exportValue.default || exportValue.require;
|
|
2977
|
+
if (typeof resolved === "object" && resolved !== null) {
|
|
2978
|
+
return resolveExport(resolved);
|
|
2979
|
+
}
|
|
2980
|
+
if (typeof resolved === "string") {
|
|
2981
|
+
return resolved.startsWith("./") ? resolved.slice(2) : resolved;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
return null;
|
|
2985
|
+
}
|
|
2426
2986
|
function cors(options = {}) {
|
|
2427
2987
|
const { origin = "*", methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"], credentials = true, maxAge = 86400 } = options;
|
|
2428
2988
|
return async (ctx, next) => {
|
|
@@ -2578,8 +3138,9 @@ function createProxyHandler(proxyConfigs) {
|
|
|
2578
3138
|
}
|
|
2579
3139
|
if (changeOrigin) {
|
|
2580
3140
|
proxyReqHeaders.host = targetUrl.host;
|
|
3141
|
+
} else {
|
|
3142
|
+
delete proxyReqHeaders["host"];
|
|
2581
3143
|
}
|
|
2582
|
-
delete proxyReqHeaders["host"];
|
|
2583
3144
|
const proxyReqOptions = {
|
|
2584
3145
|
method: req.method,
|
|
2585
3146
|
headers: proxyReqHeaders
|
|
@@ -2716,7 +3277,6 @@ var defaultOptions = {
|
|
|
2716
3277
|
watch: ["**/*.ts", "**/*.js", "**/*.html", "**/*.css"],
|
|
2717
3278
|
ignore: ["node_modules/**", "dist/**", ".git/**", "**/*.d.ts"],
|
|
2718
3279
|
logging: true,
|
|
2719
|
-
middleware: [],
|
|
2720
3280
|
worker: [],
|
|
2721
3281
|
mode: "dev"
|
|
2722
3282
|
};
|
|
@@ -2788,7 +3348,7 @@ function createDevServer(options) {
|
|
|
2788
3348
|
}
|
|
2789
3349
|
let filePath;
|
|
2790
3350
|
if (url === "/" && matchedClient.ssr && !matchedClient.index) {
|
|
2791
|
-
return serveSSR(res, matchedClient);
|
|
3351
|
+
return await serveSSR(res, matchedClient);
|
|
2792
3352
|
} else {
|
|
2793
3353
|
filePath = url === "/" ? matchedClient.index || "/index.html" : url;
|
|
2794
3354
|
}
|
|
@@ -2870,7 +3430,7 @@ function createDevServer(options) {
|
|
|
2870
3430
|
if (!resolvedPath) {
|
|
2871
3431
|
if (!res.headersSent) {
|
|
2872
3432
|
if (filePath === "/index.html" && matchedClient.ssr) {
|
|
2873
|
-
return serveSSR(res, matchedClient);
|
|
3433
|
+
return await serveSSR(res, matchedClient);
|
|
2874
3434
|
}
|
|
2875
3435
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
2876
3436
|
return send404(res, "404 Not Found");
|
|
@@ -2894,7 +3454,7 @@ function createDevServer(options) {
|
|
|
2894
3454
|
} catch {
|
|
2895
3455
|
if (config.logging) console.log(`[DEBUG] No index file found in directory`);
|
|
2896
3456
|
if (matchedClient.ssr) {
|
|
2897
|
-
return serveSSR(res, matchedClient);
|
|
3457
|
+
return await serveSSR(res, matchedClient);
|
|
2898
3458
|
}
|
|
2899
3459
|
return send404(res, "404 Not Found");
|
|
2900
3460
|
}
|
|
@@ -2914,12 +3474,12 @@ function createDevServer(options) {
|
|
|
2914
3474
|
return send403(res, "403 Forbidden");
|
|
2915
3475
|
}
|
|
2916
3476
|
await stat(indexPath);
|
|
2917
|
-
return serveFile(indexPath, res, matchedClient);
|
|
3477
|
+
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
2918
3478
|
} catch {
|
|
2919
3479
|
return send404(res, "404 Not Found");
|
|
2920
3480
|
}
|
|
2921
3481
|
}
|
|
2922
|
-
await serveFile(fullPath, res, matchedClient);
|
|
3482
|
+
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
2923
3483
|
} catch (error) {
|
|
2924
3484
|
if (!res.headersSent) {
|
|
2925
3485
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
@@ -2927,16 +3487,12 @@ function createDevServer(options) {
|
|
|
2927
3487
|
}
|
|
2928
3488
|
}
|
|
2929
3489
|
});
|
|
2930
|
-
async function serveFile(filePath, res, client) {
|
|
3490
|
+
async function serveFile(filePath, res, client, isNodeModulesOrDist = false) {
|
|
2931
3491
|
try {
|
|
2932
3492
|
const rootDir = await realpath(resolve(client.root));
|
|
2933
3493
|
const unresolvedPath = resolve(filePath);
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
const projectRoot = await realpath(resolve(client.root, ".."));
|
|
2937
|
-
const isInProjectRoot = unresolvedPath.startsWith(projectRoot + sep) || unresolvedPath === projectRoot;
|
|
2938
|
-
if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir && !isInProjectRoot) {
|
|
2939
|
-
if (!isNodeModules && !isDist) {
|
|
3494
|
+
if (!isNodeModulesOrDist) {
|
|
3495
|
+
if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir) {
|
|
2940
3496
|
if (config.logging) console.log(`[403] Attempted to serve file outside allowed directories: ${filePath}`);
|
|
2941
3497
|
return send403(res, "403 Forbidden");
|
|
2942
3498
|
}
|
|
@@ -2944,9 +3500,14 @@ function createDevServer(options) {
|
|
|
2944
3500
|
let resolvedPath;
|
|
2945
3501
|
try {
|
|
2946
3502
|
resolvedPath = await realpath(unresolvedPath);
|
|
3503
|
+
if (isNodeModulesOrDist && resolvedPath) {
|
|
3504
|
+
if (config.logging && !resolvedPath.startsWith(rootDir + sep)) {
|
|
3505
|
+
console.log(`[DEBUG] Serving symlinked file: ${resolvedPath}`);
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
2947
3508
|
} catch {
|
|
2948
3509
|
if (filePath.endsWith("index.html") && client.ssr) {
|
|
2949
|
-
return serveSSR(res, client);
|
|
3510
|
+
return await serveSSR(res, client);
|
|
2950
3511
|
}
|
|
2951
3512
|
return send404(res, "404 Not Found");
|
|
2952
3513
|
}
|
|
@@ -3050,7 +3611,7 @@ ${error}`);
|
|
|
3050
3611
|
}
|
|
3051
3612
|
}
|
|
3052
3613
|
}
|
|
3053
|
-
const elitImportMap = createElitImportMap(basePath, client.mode);
|
|
3614
|
+
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
3054
3615
|
const headInjection = ssrStyles ? `${ssrStyles}
|
|
3055
3616
|
${elitImportMap}` : elitImportMap;
|
|
3056
3617
|
html2 = html2.includes("</head>") ? html2.replace("</head>", `${headInjection}</head>`) : html2;
|
|
@@ -3080,7 +3641,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3080
3641
|
send500(res, "500 Internal Server Error");
|
|
3081
3642
|
}
|
|
3082
3643
|
}
|
|
3083
|
-
function serveSSR(res, client) {
|
|
3644
|
+
async function serveSSR(res, client) {
|
|
3084
3645
|
try {
|
|
3085
3646
|
if (!client.ssr) {
|
|
3086
3647
|
return send500(res, "SSR function not configured");
|
|
@@ -3102,7 +3663,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3102
3663
|
const basePath = normalizeBasePath(client.basePath);
|
|
3103
3664
|
html2 = rewriteRelativePaths(html2, basePath);
|
|
3104
3665
|
const hmrScript = createHMRScript(config.port, basePath);
|
|
3105
|
-
const elitImportMap = createElitImportMap(basePath, client.mode);
|
|
3666
|
+
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
3106
3667
|
html2 = html2.includes("</head>") ? html2.replace("</head>", `${elitImportMap}</head>`) : html2;
|
|
3107
3668
|
html2 = html2.includes("</body>") ? html2.replace("</body>", `${hmrScript}</body>`) : html2 + hmrScript;
|
|
3108
3669
|
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
@@ -3238,6 +3799,7 @@ export {
|
|
|
3238
3799
|
StateManager,
|
|
3239
3800
|
bodyLimit,
|
|
3240
3801
|
cacheControl,
|
|
3802
|
+
clearImportMapCache,
|
|
3241
3803
|
compress,
|
|
3242
3804
|
cors,
|
|
3243
3805
|
createDevServer,
|