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.js
CHANGED
|
@@ -638,6 +638,464 @@ var init_http = __esm({
|
|
|
638
638
|
}
|
|
639
639
|
});
|
|
640
640
|
|
|
641
|
+
// src/fs.ts
|
|
642
|
+
var fs_exports = {};
|
|
643
|
+
__export(fs_exports, {
|
|
644
|
+
appendFile: () => appendFile,
|
|
645
|
+
appendFileSync: () => appendFileSync,
|
|
646
|
+
copyFile: () => copyFile,
|
|
647
|
+
copyFileSync: () => copyFileSync,
|
|
648
|
+
default: () => fs_default,
|
|
649
|
+
exists: () => exists,
|
|
650
|
+
existsSync: () => existsSync,
|
|
651
|
+
getRuntime: () => getRuntime2,
|
|
652
|
+
mkdir: () => mkdir,
|
|
653
|
+
mkdirSync: () => mkdirSync,
|
|
654
|
+
promises: () => promises,
|
|
655
|
+
readFile: () => readFile,
|
|
656
|
+
readFileSync: () => readFileSync,
|
|
657
|
+
readdir: () => readdir,
|
|
658
|
+
readdirSync: () => readdirSync,
|
|
659
|
+
realpath: () => realpath,
|
|
660
|
+
realpathSync: () => realpathSync,
|
|
661
|
+
rename: () => rename,
|
|
662
|
+
renameSync: () => renameSync,
|
|
663
|
+
rmdir: () => rmdir,
|
|
664
|
+
rmdirSync: () => rmdirSync,
|
|
665
|
+
stat: () => stat,
|
|
666
|
+
statSync: () => statSync,
|
|
667
|
+
unlink: () => unlink,
|
|
668
|
+
unlinkSync: () => unlinkSync,
|
|
669
|
+
writeFile: () => writeFile,
|
|
670
|
+
writeFileSync: () => writeFileSync
|
|
671
|
+
});
|
|
672
|
+
function parseOptions(options, defaultValue) {
|
|
673
|
+
return typeof options === "string" ? { encoding: options } : options || defaultValue;
|
|
674
|
+
}
|
|
675
|
+
function decodeContent(content, encoding) {
|
|
676
|
+
if (encoding) {
|
|
677
|
+
return new TextDecoder(encoding).decode(content);
|
|
678
|
+
}
|
|
679
|
+
return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
|
|
680
|
+
}
|
|
681
|
+
function dataToUint8Array(data) {
|
|
682
|
+
if (typeof data === "string") {
|
|
683
|
+
return new TextEncoder().encode(data);
|
|
684
|
+
}
|
|
685
|
+
if (data instanceof Buffer) {
|
|
686
|
+
return new Uint8Array(data);
|
|
687
|
+
}
|
|
688
|
+
return data;
|
|
689
|
+
}
|
|
690
|
+
function processDenoEntries(iterator, withFileTypes) {
|
|
691
|
+
const entries = [];
|
|
692
|
+
for (const entry of iterator) {
|
|
693
|
+
if (withFileTypes) {
|
|
694
|
+
entries.push(createDirentFromDenoEntry(entry));
|
|
695
|
+
} else {
|
|
696
|
+
entries.push(entry.name);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return entries;
|
|
700
|
+
}
|
|
701
|
+
async function processDenoEntriesAsync(iterator, withFileTypes) {
|
|
702
|
+
const entries = [];
|
|
703
|
+
for await (const entry of iterator) {
|
|
704
|
+
if (withFileTypes) {
|
|
705
|
+
entries.push(createDirentFromDenoEntry(entry));
|
|
706
|
+
} else {
|
|
707
|
+
entries.push(entry.name);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
return entries;
|
|
711
|
+
}
|
|
712
|
+
async function readFile(path, options) {
|
|
713
|
+
const opts = parseOptions(options, {});
|
|
714
|
+
if (isNode) {
|
|
715
|
+
return fsPromises.readFile(path, opts);
|
|
716
|
+
} else if (isBun) {
|
|
717
|
+
const file = Bun.file(path);
|
|
718
|
+
const content = await file.arrayBuffer();
|
|
719
|
+
return decodeContent(content, opts.encoding);
|
|
720
|
+
} else if (isDeno) {
|
|
721
|
+
const content = await Deno.readFile(path);
|
|
722
|
+
return decodeContent(content, opts.encoding);
|
|
723
|
+
}
|
|
724
|
+
throw new Error("Unsupported runtime");
|
|
725
|
+
}
|
|
726
|
+
function readFileSync(path, options) {
|
|
727
|
+
const opts = parseOptions(options, {});
|
|
728
|
+
if (isNode) {
|
|
729
|
+
return fs.readFileSync(path, opts);
|
|
730
|
+
} else if (isBun) {
|
|
731
|
+
const file = Bun.file(path);
|
|
732
|
+
const content = file.arrayBuffer();
|
|
733
|
+
return decodeContent(content, opts.encoding);
|
|
734
|
+
} else if (isDeno) {
|
|
735
|
+
const content = Deno.readFileSync(path);
|
|
736
|
+
return decodeContent(content, opts.encoding);
|
|
737
|
+
}
|
|
738
|
+
throw new Error("Unsupported runtime");
|
|
739
|
+
}
|
|
740
|
+
async function writeFile(path, data, options) {
|
|
741
|
+
const opts = parseOptions(options, {});
|
|
742
|
+
if (isNode) {
|
|
743
|
+
return fsPromises.writeFile(path, data, opts);
|
|
744
|
+
} else if (isBun) {
|
|
745
|
+
await Bun.write(path, data);
|
|
746
|
+
} else if (isDeno) {
|
|
747
|
+
await Deno.writeFile(path, dataToUint8Array(data));
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function writeFileSync(path, data, options) {
|
|
751
|
+
const opts = parseOptions(options, {});
|
|
752
|
+
if (isNode) {
|
|
753
|
+
fs.writeFileSync(path, data, opts);
|
|
754
|
+
} else if (isBun) {
|
|
755
|
+
Bun.write(path, data);
|
|
756
|
+
} else if (isDeno) {
|
|
757
|
+
Deno.writeFileSync(path, dataToUint8Array(data));
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
async function appendFile(path, data, options) {
|
|
761
|
+
const opts = parseOptions(options, {});
|
|
762
|
+
if (isNode) {
|
|
763
|
+
return fsPromises.appendFile(path, data, opts);
|
|
764
|
+
} else {
|
|
765
|
+
if (await exists(path)) {
|
|
766
|
+
const existing = await readFile(path);
|
|
767
|
+
const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
|
|
768
|
+
await writeFile(path, combined, opts);
|
|
769
|
+
} else {
|
|
770
|
+
await writeFile(path, data, opts);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
function appendFileSync(path, data, options) {
|
|
775
|
+
const opts = parseOptions(options, {});
|
|
776
|
+
if (isNode) {
|
|
777
|
+
fs.appendFileSync(path, data, opts);
|
|
778
|
+
} else {
|
|
779
|
+
if (existsSync(path)) {
|
|
780
|
+
const existing = readFileSync(path);
|
|
781
|
+
const combined = Buffer.isBuffer(existing) ? Buffer.concat([existing, Buffer.isBuffer(data) ? data : Buffer.from(data)]) : existing + (Buffer.isBuffer(data) ? data.toString() : data);
|
|
782
|
+
writeFileSync(path, combined, opts);
|
|
783
|
+
} else {
|
|
784
|
+
writeFileSync(path, data, opts);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
async function exists(path) {
|
|
789
|
+
try {
|
|
790
|
+
await stat(path);
|
|
791
|
+
return true;
|
|
792
|
+
} catch {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
function existsSync(path) {
|
|
797
|
+
try {
|
|
798
|
+
statSync(path);
|
|
799
|
+
return true;
|
|
800
|
+
} catch {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
async function stat(path) {
|
|
805
|
+
if (isNode) {
|
|
806
|
+
return fsPromises.stat(path);
|
|
807
|
+
} else if (isBun) {
|
|
808
|
+
const file = Bun.file(path);
|
|
809
|
+
const size = file.size;
|
|
810
|
+
const exists2 = await file.exists();
|
|
811
|
+
if (!exists2) {
|
|
812
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
813
|
+
}
|
|
814
|
+
return createStatsObject(path, size, false);
|
|
815
|
+
} else if (isDeno) {
|
|
816
|
+
const info = await Deno.stat(path);
|
|
817
|
+
return createStatsFromDenoFileInfo(info);
|
|
818
|
+
}
|
|
819
|
+
throw new Error("Unsupported runtime");
|
|
820
|
+
}
|
|
821
|
+
function statSync(path) {
|
|
822
|
+
if (isNode) {
|
|
823
|
+
return fs.statSync(path);
|
|
824
|
+
} else if (isBun) {
|
|
825
|
+
const file = Bun.file(path);
|
|
826
|
+
const size = file.size;
|
|
827
|
+
try {
|
|
828
|
+
file.arrayBuffer();
|
|
829
|
+
} catch {
|
|
830
|
+
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
831
|
+
}
|
|
832
|
+
return createStatsObject(path, size, false);
|
|
833
|
+
} else if (isDeno) {
|
|
834
|
+
const info = Deno.statSync(path);
|
|
835
|
+
return createStatsFromDenoFileInfo(info);
|
|
836
|
+
}
|
|
837
|
+
throw new Error("Unsupported runtime");
|
|
838
|
+
}
|
|
839
|
+
async function mkdir(path, options) {
|
|
840
|
+
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
841
|
+
if (isNode) {
|
|
842
|
+
await fsPromises.mkdir(path, opts);
|
|
843
|
+
} else if (isBun) {
|
|
844
|
+
await Deno.mkdir(path, { recursive: opts.recursive });
|
|
845
|
+
} else if (isDeno) {
|
|
846
|
+
await Deno.mkdir(path, { recursive: opts.recursive });
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function mkdirSync(path, options) {
|
|
850
|
+
const opts = typeof options === "number" ? { mode: options } : options || {};
|
|
851
|
+
if (isNode) {
|
|
852
|
+
fs.mkdirSync(path, opts);
|
|
853
|
+
} else if (isBun) {
|
|
854
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
855
|
+
} else if (isDeno) {
|
|
856
|
+
Deno.mkdirSync(path, { recursive: opts.recursive });
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
async function readdir(path, options) {
|
|
860
|
+
const opts = parseOptions(options, {});
|
|
861
|
+
if (isNode) {
|
|
862
|
+
return fsPromises.readdir(path, opts);
|
|
863
|
+
} else if (isBunOrDeno) {
|
|
864
|
+
return processDenoEntriesAsync(Deno.readDir(path), opts.withFileTypes);
|
|
865
|
+
}
|
|
866
|
+
throw new Error("Unsupported runtime");
|
|
867
|
+
}
|
|
868
|
+
function readdirSync(path, options) {
|
|
869
|
+
const opts = parseOptions(options, {});
|
|
870
|
+
if (isNode) {
|
|
871
|
+
return fs.readdirSync(path, opts);
|
|
872
|
+
} else if (isBunOrDeno) {
|
|
873
|
+
return processDenoEntries(Deno.readDirSync(path), opts.withFileTypes);
|
|
874
|
+
}
|
|
875
|
+
throw new Error("Unsupported runtime");
|
|
876
|
+
}
|
|
877
|
+
async function unlink(path) {
|
|
878
|
+
if (isNode) {
|
|
879
|
+
return fsPromises.unlink(path);
|
|
880
|
+
} else if (isBun) {
|
|
881
|
+
await Deno.remove(path);
|
|
882
|
+
} else if (isDeno) {
|
|
883
|
+
await Deno.remove(path);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function unlinkSync(path) {
|
|
887
|
+
if (isNode) {
|
|
888
|
+
fs.unlinkSync(path);
|
|
889
|
+
} else if (isBun) {
|
|
890
|
+
Deno.removeSync(path);
|
|
891
|
+
} else if (isDeno) {
|
|
892
|
+
Deno.removeSync(path);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
async function rmdir(path, options) {
|
|
896
|
+
if (isNode) {
|
|
897
|
+
return fsPromises.rmdir(path, options);
|
|
898
|
+
} else if (isBun) {
|
|
899
|
+
await Deno.remove(path, { recursive: options?.recursive });
|
|
900
|
+
} else if (isDeno) {
|
|
901
|
+
await Deno.remove(path, { recursive: options?.recursive });
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
function rmdirSync(path, options) {
|
|
905
|
+
if (isNode) {
|
|
906
|
+
fs.rmdirSync(path, options);
|
|
907
|
+
} else if (isBun) {
|
|
908
|
+
Deno.removeSync(path, { recursive: options?.recursive });
|
|
909
|
+
} else if (isDeno) {
|
|
910
|
+
Deno.removeSync(path, { recursive: options?.recursive });
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
async function rename(oldPath, newPath) {
|
|
914
|
+
if (isNode) {
|
|
915
|
+
return fsPromises.rename(oldPath, newPath);
|
|
916
|
+
} else if (isBun) {
|
|
917
|
+
await Deno.rename(oldPath, newPath);
|
|
918
|
+
} else if (isDeno) {
|
|
919
|
+
await Deno.rename(oldPath, newPath);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
function renameSync(oldPath, newPath) {
|
|
923
|
+
if (isNode) {
|
|
924
|
+
fs.renameSync(oldPath, newPath);
|
|
925
|
+
} else if (isBun) {
|
|
926
|
+
Deno.renameSync(oldPath, newPath);
|
|
927
|
+
} else if (isDeno) {
|
|
928
|
+
Deno.renameSync(oldPath, newPath);
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
async function copyFile(src, dest, flags) {
|
|
932
|
+
if (isNode) {
|
|
933
|
+
return fsPromises.copyFile(src, dest, flags);
|
|
934
|
+
} else if (isBun) {
|
|
935
|
+
await Deno.copyFile(src, dest);
|
|
936
|
+
} else if (isDeno) {
|
|
937
|
+
await Deno.copyFile(src, dest);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
function copyFileSync(src, dest, flags) {
|
|
941
|
+
if (isNode) {
|
|
942
|
+
fs.copyFileSync(src, dest, flags);
|
|
943
|
+
} else if (isBun) {
|
|
944
|
+
Deno.copyFileSync(src, dest);
|
|
945
|
+
} else if (isDeno) {
|
|
946
|
+
Deno.copyFileSync(src, dest);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
async function realpath(path, options) {
|
|
950
|
+
if (isNode) {
|
|
951
|
+
return fsPromises.realpath(path, options);
|
|
952
|
+
} else if (isBun) {
|
|
953
|
+
const fs2 = require("fs/promises");
|
|
954
|
+
return fs2.realpath(path, options);
|
|
955
|
+
} else if (isDeno) {
|
|
956
|
+
return await Deno.realPath(path);
|
|
957
|
+
}
|
|
958
|
+
return path;
|
|
959
|
+
}
|
|
960
|
+
function realpathSync(path, options) {
|
|
961
|
+
if (isNode) {
|
|
962
|
+
return fs.realpathSync(path, options);
|
|
963
|
+
} else if (isBun) {
|
|
964
|
+
const fs2 = require("fs");
|
|
965
|
+
return fs2.realpathSync(path, options);
|
|
966
|
+
} else if (isDeno) {
|
|
967
|
+
return Deno.realPathSync(path);
|
|
968
|
+
}
|
|
969
|
+
return path;
|
|
970
|
+
}
|
|
971
|
+
function createStatsObject(_path, size, isDir) {
|
|
972
|
+
const now = Date.now();
|
|
973
|
+
return {
|
|
974
|
+
isFile: () => !isDir,
|
|
975
|
+
isDirectory: () => isDir,
|
|
976
|
+
isBlockDevice: () => false,
|
|
977
|
+
isCharacterDevice: () => false,
|
|
978
|
+
isSymbolicLink: () => false,
|
|
979
|
+
isFIFO: () => false,
|
|
980
|
+
isSocket: () => false,
|
|
981
|
+
dev: 0,
|
|
982
|
+
ino: 0,
|
|
983
|
+
mode: isDir ? 16877 : 33188,
|
|
984
|
+
nlink: 1,
|
|
985
|
+
uid: 0,
|
|
986
|
+
gid: 0,
|
|
987
|
+
rdev: 0,
|
|
988
|
+
size,
|
|
989
|
+
blksize: 4096,
|
|
990
|
+
blocks: Math.ceil(size / 512),
|
|
991
|
+
atimeMs: now,
|
|
992
|
+
mtimeMs: now,
|
|
993
|
+
ctimeMs: now,
|
|
994
|
+
birthtimeMs: now,
|
|
995
|
+
atime: new Date(now),
|
|
996
|
+
mtime: new Date(now),
|
|
997
|
+
ctime: new Date(now),
|
|
998
|
+
birthtime: new Date(now)
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
function createStatsFromDenoFileInfo(info) {
|
|
1002
|
+
return {
|
|
1003
|
+
isFile: () => info.isFile,
|
|
1004
|
+
isDirectory: () => info.isDirectory,
|
|
1005
|
+
isBlockDevice: () => false,
|
|
1006
|
+
isCharacterDevice: () => false,
|
|
1007
|
+
isSymbolicLink: () => info.isSymlink || false,
|
|
1008
|
+
isFIFO: () => false,
|
|
1009
|
+
isSocket: () => false,
|
|
1010
|
+
dev: info.dev || 0,
|
|
1011
|
+
ino: info.ino || 0,
|
|
1012
|
+
mode: info.mode || 0,
|
|
1013
|
+
nlink: info.nlink || 1,
|
|
1014
|
+
uid: info.uid || 0,
|
|
1015
|
+
gid: info.gid || 0,
|
|
1016
|
+
rdev: 0,
|
|
1017
|
+
size: info.size,
|
|
1018
|
+
blksize: info.blksize || 4096,
|
|
1019
|
+
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
1020
|
+
atimeMs: info.atime?.getTime() || Date.now(),
|
|
1021
|
+
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
1022
|
+
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1023
|
+
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1024
|
+
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
1025
|
+
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
1026
|
+
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
1027
|
+
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
function createDirentFromDenoEntry(entry) {
|
|
1031
|
+
return {
|
|
1032
|
+
name: entry.name,
|
|
1033
|
+
isFile: () => entry.isFile,
|
|
1034
|
+
isDirectory: () => entry.isDirectory,
|
|
1035
|
+
isBlockDevice: () => false,
|
|
1036
|
+
isCharacterDevice: () => false,
|
|
1037
|
+
isSymbolicLink: () => entry.isSymlink || false,
|
|
1038
|
+
isFIFO: () => false,
|
|
1039
|
+
isSocket: () => false
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
function getRuntime2() {
|
|
1043
|
+
return runtime;
|
|
1044
|
+
}
|
|
1045
|
+
var isBunOrDeno, fs, fsPromises, promises, fs_default;
|
|
1046
|
+
var init_fs = __esm({
|
|
1047
|
+
"src/fs.ts"() {
|
|
1048
|
+
"use strict";
|
|
1049
|
+
init_runtime();
|
|
1050
|
+
isBunOrDeno = isBun || isDeno;
|
|
1051
|
+
if (isNode) {
|
|
1052
|
+
fs = require("fs");
|
|
1053
|
+
fsPromises = require("fs/promises");
|
|
1054
|
+
}
|
|
1055
|
+
promises = {
|
|
1056
|
+
readFile,
|
|
1057
|
+
writeFile,
|
|
1058
|
+
appendFile,
|
|
1059
|
+
stat,
|
|
1060
|
+
mkdir,
|
|
1061
|
+
readdir,
|
|
1062
|
+
unlink,
|
|
1063
|
+
rmdir,
|
|
1064
|
+
rename,
|
|
1065
|
+
copyFile,
|
|
1066
|
+
realpath
|
|
1067
|
+
};
|
|
1068
|
+
fs_default = {
|
|
1069
|
+
readFile,
|
|
1070
|
+
readFileSync,
|
|
1071
|
+
writeFile,
|
|
1072
|
+
writeFileSync,
|
|
1073
|
+
appendFile,
|
|
1074
|
+
appendFileSync,
|
|
1075
|
+
exists,
|
|
1076
|
+
existsSync,
|
|
1077
|
+
stat,
|
|
1078
|
+
statSync,
|
|
1079
|
+
mkdir,
|
|
1080
|
+
mkdirSync,
|
|
1081
|
+
readdir,
|
|
1082
|
+
readdirSync,
|
|
1083
|
+
unlink,
|
|
1084
|
+
unlinkSync,
|
|
1085
|
+
rmdir,
|
|
1086
|
+
rmdirSync,
|
|
1087
|
+
rename,
|
|
1088
|
+
renameSync,
|
|
1089
|
+
copyFile,
|
|
1090
|
+
copyFileSync,
|
|
1091
|
+
realpath,
|
|
1092
|
+
realpathSync,
|
|
1093
|
+
promises,
|
|
1094
|
+
getRuntime: getRuntime2
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
|
|
641
1099
|
// src/server.ts
|
|
642
1100
|
var server_exports = {};
|
|
643
1101
|
__export(server_exports, {
|
|
@@ -646,6 +1104,7 @@ __export(server_exports, {
|
|
|
646
1104
|
StateManager: () => StateManager,
|
|
647
1105
|
bodyLimit: () => bodyLimit,
|
|
648
1106
|
cacheControl: () => cacheControl,
|
|
1107
|
+
clearImportMapCache: () => clearImportMapCache,
|
|
649
1108
|
compress: () => compress,
|
|
650
1109
|
cors: () => cors,
|
|
651
1110
|
createDevServer: () => createDevServer,
|
|
@@ -1233,124 +1692,8 @@ function watch(paths, options) {
|
|
|
1233
1692
|
return watcher;
|
|
1234
1693
|
}
|
|
1235
1694
|
|
|
1236
|
-
// src/
|
|
1237
|
-
|
|
1238
|
-
function parseOptions(options, defaultValue) {
|
|
1239
|
-
return typeof options === "string" ? { encoding: options } : options || defaultValue;
|
|
1240
|
-
}
|
|
1241
|
-
function decodeContent(content, encoding) {
|
|
1242
|
-
if (encoding) {
|
|
1243
|
-
return new TextDecoder(encoding).decode(content);
|
|
1244
|
-
}
|
|
1245
|
-
return Buffer.from(content instanceof ArrayBuffer ? new Uint8Array(content) : content);
|
|
1246
|
-
}
|
|
1247
|
-
var fs;
|
|
1248
|
-
var fsPromises;
|
|
1249
|
-
if (isNode) {
|
|
1250
|
-
fs = require("fs");
|
|
1251
|
-
fsPromises = require("fs/promises");
|
|
1252
|
-
}
|
|
1253
|
-
async function readFile(path, options) {
|
|
1254
|
-
const opts = parseOptions(options, {});
|
|
1255
|
-
if (isNode) {
|
|
1256
|
-
return fsPromises.readFile(path, opts);
|
|
1257
|
-
} else if (isBun) {
|
|
1258
|
-
const file = Bun.file(path);
|
|
1259
|
-
const content = await file.arrayBuffer();
|
|
1260
|
-
return decodeContent(content, opts.encoding);
|
|
1261
|
-
} else if (isDeno) {
|
|
1262
|
-
const content = await Deno.readFile(path);
|
|
1263
|
-
return decodeContent(content, opts.encoding);
|
|
1264
|
-
}
|
|
1265
|
-
throw new Error("Unsupported runtime");
|
|
1266
|
-
}
|
|
1267
|
-
async function stat(path) {
|
|
1268
|
-
if (isNode) {
|
|
1269
|
-
return fsPromises.stat(path);
|
|
1270
|
-
} else if (isBun) {
|
|
1271
|
-
const file = Bun.file(path);
|
|
1272
|
-
const size = file.size;
|
|
1273
|
-
const exists = await file.exists();
|
|
1274
|
-
if (!exists) {
|
|
1275
|
-
throw new Error(`ENOENT: no such file or directory, stat '${path}'`);
|
|
1276
|
-
}
|
|
1277
|
-
return createStatsObject(path, size, false);
|
|
1278
|
-
} else if (isDeno) {
|
|
1279
|
-
const info = await Deno.stat(path);
|
|
1280
|
-
return createStatsFromDenoFileInfo(info);
|
|
1281
|
-
}
|
|
1282
|
-
throw new Error("Unsupported runtime");
|
|
1283
|
-
}
|
|
1284
|
-
async function realpath(path, options) {
|
|
1285
|
-
if (isNode) {
|
|
1286
|
-
return fsPromises.realpath(path, options);
|
|
1287
|
-
} else if (isBun) {
|
|
1288
|
-
const fs2 = require("fs/promises");
|
|
1289
|
-
return fs2.realpath(path, options);
|
|
1290
|
-
} else if (isDeno) {
|
|
1291
|
-
return await Deno.realPath(path);
|
|
1292
|
-
}
|
|
1293
|
-
return path;
|
|
1294
|
-
}
|
|
1295
|
-
function createStatsObject(_path, size, isDir) {
|
|
1296
|
-
const now = Date.now();
|
|
1297
|
-
return {
|
|
1298
|
-
isFile: () => !isDir,
|
|
1299
|
-
isDirectory: () => isDir,
|
|
1300
|
-
isBlockDevice: () => false,
|
|
1301
|
-
isCharacterDevice: () => false,
|
|
1302
|
-
isSymbolicLink: () => false,
|
|
1303
|
-
isFIFO: () => false,
|
|
1304
|
-
isSocket: () => false,
|
|
1305
|
-
dev: 0,
|
|
1306
|
-
ino: 0,
|
|
1307
|
-
mode: isDir ? 16877 : 33188,
|
|
1308
|
-
nlink: 1,
|
|
1309
|
-
uid: 0,
|
|
1310
|
-
gid: 0,
|
|
1311
|
-
rdev: 0,
|
|
1312
|
-
size,
|
|
1313
|
-
blksize: 4096,
|
|
1314
|
-
blocks: Math.ceil(size / 512),
|
|
1315
|
-
atimeMs: now,
|
|
1316
|
-
mtimeMs: now,
|
|
1317
|
-
ctimeMs: now,
|
|
1318
|
-
birthtimeMs: now,
|
|
1319
|
-
atime: new Date(now),
|
|
1320
|
-
mtime: new Date(now),
|
|
1321
|
-
ctime: new Date(now),
|
|
1322
|
-
birthtime: new Date(now)
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
function createStatsFromDenoFileInfo(info) {
|
|
1326
|
-
return {
|
|
1327
|
-
isFile: () => info.isFile,
|
|
1328
|
-
isDirectory: () => info.isDirectory,
|
|
1329
|
-
isBlockDevice: () => false,
|
|
1330
|
-
isCharacterDevice: () => false,
|
|
1331
|
-
isSymbolicLink: () => info.isSymlink || false,
|
|
1332
|
-
isFIFO: () => false,
|
|
1333
|
-
isSocket: () => false,
|
|
1334
|
-
dev: info.dev || 0,
|
|
1335
|
-
ino: info.ino || 0,
|
|
1336
|
-
mode: info.mode || 0,
|
|
1337
|
-
nlink: info.nlink || 1,
|
|
1338
|
-
uid: info.uid || 0,
|
|
1339
|
-
gid: info.gid || 0,
|
|
1340
|
-
rdev: 0,
|
|
1341
|
-
size: info.size,
|
|
1342
|
-
blksize: info.blksize || 4096,
|
|
1343
|
-
blocks: info.blocks || Math.ceil(info.size / 512),
|
|
1344
|
-
atimeMs: info.atime?.getTime() || Date.now(),
|
|
1345
|
-
mtimeMs: info.mtime?.getTime() || Date.now(),
|
|
1346
|
-
ctimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1347
|
-
birthtimeMs: info.birthtime?.getTime() || Date.now(),
|
|
1348
|
-
atime: info.atime || /* @__PURE__ */ new Date(),
|
|
1349
|
-
mtime: info.mtime || /* @__PURE__ */ new Date(),
|
|
1350
|
-
ctime: info.birthtime || /* @__PURE__ */ new Date(),
|
|
1351
|
-
birthtime: info.birthtime || /* @__PURE__ */ new Date()
|
|
1352
|
-
};
|
|
1353
|
-
}
|
|
1695
|
+
// src/server.ts
|
|
1696
|
+
init_fs();
|
|
1354
1697
|
|
|
1355
1698
|
// src/path.ts
|
|
1356
1699
|
init_runtime();
|
|
@@ -2405,22 +2748,23 @@ var sendError = (res, code, msg) => {
|
|
|
2405
2748
|
var send404 = (res, msg = "Not Found") => sendError(res, 404, msg);
|
|
2406
2749
|
var send403 = (res, msg = "Forbidden") => sendError(res, 403, msg);
|
|
2407
2750
|
var send500 = (res, msg = "Internal Server Error") => sendError(res, 500, msg);
|
|
2408
|
-
var createElitImportMap = (basePath = "", mode = "dev") => {
|
|
2751
|
+
var createElitImportMap = async (rootDir, basePath = "", mode = "dev") => {
|
|
2409
2752
|
const srcPath = mode === "dev" ? basePath ? `${basePath}/node_modules/elit/src` : "/node_modules/elit/src" : basePath ? `${basePath}/node_modules/elit/dist` : "/node_modules/elit/dist";
|
|
2410
2753
|
const fileExt = mode === "dev" ? ".ts" : ".mjs";
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
"elit":
|
|
2414
|
-
"elit/":
|
|
2415
|
-
"elit/
|
|
2416
|
-
"elit/
|
|
2417
|
-
"elit/
|
|
2418
|
-
"elit/
|
|
2419
|
-
"elit/
|
|
2420
|
-
"elit/
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
}
|
|
2754
|
+
const elitImports = {
|
|
2755
|
+
"elit": `${srcPath}/index${fileExt}`,
|
|
2756
|
+
"elit/": `${srcPath}/`,
|
|
2757
|
+
"elit/dom": `${srcPath}/dom${fileExt}`,
|
|
2758
|
+
"elit/state": `${srcPath}/state${fileExt}`,
|
|
2759
|
+
"elit/style": `${srcPath}/style${fileExt}`,
|
|
2760
|
+
"elit/el": `${srcPath}/el${fileExt}`,
|
|
2761
|
+
"elit/router": `${srcPath}/router${fileExt}`,
|
|
2762
|
+
"elit/hmr": `${srcPath}/hmr${fileExt}`,
|
|
2763
|
+
"elit/types": `${srcPath}/types${fileExt}`
|
|
2764
|
+
};
|
|
2765
|
+
const externalImports = await generateExternalImportMaps(rootDir, basePath);
|
|
2766
|
+
const allImports = { ...externalImports, ...elitImports };
|
|
2767
|
+
return `<script type="importmap">${JSON.stringify({ imports: allImports }, null, 2)}</script>`;
|
|
2424
2768
|
};
|
|
2425
2769
|
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>`;
|
|
2426
2770
|
var rewriteRelativePaths = (html2, basePath) => {
|
|
@@ -2448,6 +2792,223 @@ async function findSpecialDir(startDir, targetDir) {
|
|
|
2448
2792
|
}
|
|
2449
2793
|
return null;
|
|
2450
2794
|
}
|
|
2795
|
+
var importMapCache = /* @__PURE__ */ new Map();
|
|
2796
|
+
function clearImportMapCache() {
|
|
2797
|
+
importMapCache.clear();
|
|
2798
|
+
}
|
|
2799
|
+
async function generateExternalImportMaps(rootDir, basePath = "") {
|
|
2800
|
+
const cacheKey = `${rootDir}:${basePath}`;
|
|
2801
|
+
if (importMapCache.has(cacheKey)) {
|
|
2802
|
+
return importMapCache.get(cacheKey);
|
|
2803
|
+
}
|
|
2804
|
+
const importMap = {};
|
|
2805
|
+
const nodeModulesPath = await findNodeModules(rootDir);
|
|
2806
|
+
if (!nodeModulesPath) {
|
|
2807
|
+
importMapCache.set(cacheKey, importMap);
|
|
2808
|
+
return importMap;
|
|
2809
|
+
}
|
|
2810
|
+
try {
|
|
2811
|
+
const { readdir: readdir2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
2812
|
+
const packages = await readdir2(nodeModulesPath);
|
|
2813
|
+
for (const pkgEntry of packages) {
|
|
2814
|
+
const pkg = typeof pkgEntry === "string" ? pkgEntry : pkgEntry.name;
|
|
2815
|
+
if (pkg.startsWith(".")) continue;
|
|
2816
|
+
if (pkg.startsWith("@")) {
|
|
2817
|
+
try {
|
|
2818
|
+
const scopedPackages = await readdir2(join(nodeModulesPath, pkg));
|
|
2819
|
+
for (const scopedEntry of scopedPackages) {
|
|
2820
|
+
const scopedPkg = typeof scopedEntry === "string" ? scopedEntry : scopedEntry.name;
|
|
2821
|
+
const fullPkgName = `${pkg}/${scopedPkg}`;
|
|
2822
|
+
await processPackage(nodeModulesPath, fullPkgName, importMap, basePath);
|
|
2823
|
+
}
|
|
2824
|
+
} catch {
|
|
2825
|
+
}
|
|
2826
|
+
} else {
|
|
2827
|
+
await processPackage(nodeModulesPath, pkg, importMap, basePath);
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
} catch (error) {
|
|
2831
|
+
console.error("[Import Maps] Error scanning node_modules:", error);
|
|
2832
|
+
}
|
|
2833
|
+
importMapCache.set(cacheKey, importMap);
|
|
2834
|
+
return importMap;
|
|
2835
|
+
}
|
|
2836
|
+
async function findNodeModules(startDir) {
|
|
2837
|
+
const foundDir = await findSpecialDir(startDir, "node_modules");
|
|
2838
|
+
return foundDir ? join(foundDir, "node_modules") : null;
|
|
2839
|
+
}
|
|
2840
|
+
function isBrowserCompatible(pkgName, pkgJson) {
|
|
2841
|
+
const buildTools = [
|
|
2842
|
+
"typescript",
|
|
2843
|
+
"esbuild",
|
|
2844
|
+
"@esbuild/",
|
|
2845
|
+
"tsx",
|
|
2846
|
+
"tsup",
|
|
2847
|
+
"rollup",
|
|
2848
|
+
"vite",
|
|
2849
|
+
"webpack",
|
|
2850
|
+
"parcel",
|
|
2851
|
+
"terser",
|
|
2852
|
+
"uglify",
|
|
2853
|
+
"babel",
|
|
2854
|
+
"@babel/",
|
|
2855
|
+
"postcss",
|
|
2856
|
+
"autoprefixer",
|
|
2857
|
+
"cssnano",
|
|
2858
|
+
"sass",
|
|
2859
|
+
"less",
|
|
2860
|
+
"stylus"
|
|
2861
|
+
];
|
|
2862
|
+
const nodeOnly = [
|
|
2863
|
+
"node-",
|
|
2864
|
+
"@node-",
|
|
2865
|
+
"fsevents",
|
|
2866
|
+
"chokidar",
|
|
2867
|
+
"express",
|
|
2868
|
+
"koa",
|
|
2869
|
+
"fastify",
|
|
2870
|
+
"nest",
|
|
2871
|
+
"commander",
|
|
2872
|
+
"yargs",
|
|
2873
|
+
"inquirer",
|
|
2874
|
+
"chalk",
|
|
2875
|
+
"ora",
|
|
2876
|
+
"nodemon",
|
|
2877
|
+
"pm2",
|
|
2878
|
+
"dotenv"
|
|
2879
|
+
];
|
|
2880
|
+
const testingTools = [
|
|
2881
|
+
"jest",
|
|
2882
|
+
"vitest",
|
|
2883
|
+
"mocha",
|
|
2884
|
+
"chai",
|
|
2885
|
+
"jasmine",
|
|
2886
|
+
"@jest/",
|
|
2887
|
+
"@testing-library/",
|
|
2888
|
+
"@vitest/",
|
|
2889
|
+
"playwright",
|
|
2890
|
+
"puppeteer",
|
|
2891
|
+
"cypress"
|
|
2892
|
+
];
|
|
2893
|
+
const linters = [
|
|
2894
|
+
"eslint",
|
|
2895
|
+
"@eslint/",
|
|
2896
|
+
"prettier",
|
|
2897
|
+
"tslint",
|
|
2898
|
+
"stylelint",
|
|
2899
|
+
"commitlint"
|
|
2900
|
+
];
|
|
2901
|
+
const typeDefinitions = [
|
|
2902
|
+
"@types/",
|
|
2903
|
+
"@typescript-eslint/"
|
|
2904
|
+
];
|
|
2905
|
+
const utilities = [
|
|
2906
|
+
"get-tsconfig",
|
|
2907
|
+
"resolve-pkg-maps",
|
|
2908
|
+
"pkg-types",
|
|
2909
|
+
"fast-glob",
|
|
2910
|
+
"globby",
|
|
2911
|
+
"micromatch",
|
|
2912
|
+
"execa",
|
|
2913
|
+
"cross-spawn",
|
|
2914
|
+
"shelljs"
|
|
2915
|
+
];
|
|
2916
|
+
const skipPatterns = [
|
|
2917
|
+
...buildTools,
|
|
2918
|
+
...nodeOnly,
|
|
2919
|
+
...testingTools,
|
|
2920
|
+
...linters,
|
|
2921
|
+
...typeDefinitions,
|
|
2922
|
+
...utilities
|
|
2923
|
+
];
|
|
2924
|
+
if (skipPatterns.some((pattern) => pkgName.startsWith(pattern))) {
|
|
2925
|
+
return false;
|
|
2926
|
+
}
|
|
2927
|
+
if (pkgName === "lodash") {
|
|
2928
|
+
return false;
|
|
2929
|
+
}
|
|
2930
|
+
if (pkgJson.browser || pkgJson.module) {
|
|
2931
|
+
return true;
|
|
2932
|
+
}
|
|
2933
|
+
if (pkgJson.exports) {
|
|
2934
|
+
const exportsStr = JSON.stringify(pkgJson.exports);
|
|
2935
|
+
if (exportsStr.includes('"import"') || exportsStr.includes('"browser"')) {
|
|
2936
|
+
return true;
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
if (pkgJson.type === "commonjs" && !pkgJson.module && !pkgJson.browser) {
|
|
2940
|
+
return false;
|
|
2941
|
+
}
|
|
2942
|
+
return !!(pkgJson.exports || pkgJson.type === "module" || pkgJson.module);
|
|
2943
|
+
}
|
|
2944
|
+
async function processPackage(nodeModulesPath, pkgName, importMap, basePath) {
|
|
2945
|
+
const pkgPath = join(nodeModulesPath, pkgName);
|
|
2946
|
+
const pkgJsonPath = join(pkgPath, "package.json");
|
|
2947
|
+
try {
|
|
2948
|
+
const pkgJsonContent = await readFile(pkgJsonPath);
|
|
2949
|
+
const pkgJson = JSON.parse(pkgJsonContent.toString());
|
|
2950
|
+
if (!isBrowserCompatible(pkgName, pkgJson)) {
|
|
2951
|
+
return;
|
|
2952
|
+
}
|
|
2953
|
+
const baseUrl = basePath ? `${basePath}/node_modules/${pkgName}` : `/node_modules/${pkgName}`;
|
|
2954
|
+
if (pkgJson.exports) {
|
|
2955
|
+
processExportsField(pkgName, pkgJson.exports, baseUrl, importMap);
|
|
2956
|
+
} else {
|
|
2957
|
+
const entryPoint = pkgJson.browser || pkgJson.module || pkgJson.main || "index.js";
|
|
2958
|
+
importMap[pkgName] = `${baseUrl}/${entryPoint}`;
|
|
2959
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
2960
|
+
}
|
|
2961
|
+
} catch {
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
function processExportsField(pkgName, exports2, baseUrl, importMap) {
|
|
2965
|
+
if (typeof exports2 === "string") {
|
|
2966
|
+
importMap[pkgName] = `${baseUrl}/${exports2}`;
|
|
2967
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
if (typeof exports2 === "object" && exports2 !== null) {
|
|
2971
|
+
if ("." in exports2) {
|
|
2972
|
+
const dotExport = exports2["."];
|
|
2973
|
+
const resolved = resolveExport(dotExport);
|
|
2974
|
+
if (resolved) {
|
|
2975
|
+
importMap[pkgName] = `${baseUrl}/${resolved}`;
|
|
2976
|
+
}
|
|
2977
|
+
} else if ("import" in exports2) {
|
|
2978
|
+
const resolved = resolveExport(exports2);
|
|
2979
|
+
if (resolved) {
|
|
2980
|
+
importMap[pkgName] = `${baseUrl}/${resolved}`;
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
for (const [key, value] of Object.entries(exports2)) {
|
|
2984
|
+
if (key === "." || key === "import" || key === "require" || key === "types" || key === "default") {
|
|
2985
|
+
continue;
|
|
2986
|
+
}
|
|
2987
|
+
const resolved = resolveExport(value);
|
|
2988
|
+
if (resolved) {
|
|
2989
|
+
const cleanKey = key.startsWith("./") ? key.slice(2) : key;
|
|
2990
|
+
const importName = cleanKey ? `${pkgName}/${cleanKey}` : pkgName;
|
|
2991
|
+
importMap[importName] = `${baseUrl}/${resolved}`;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
function resolveExport(exportValue) {
|
|
2998
|
+
if (typeof exportValue === "string") {
|
|
2999
|
+
return exportValue.startsWith("./") ? exportValue.slice(2) : exportValue;
|
|
3000
|
+
}
|
|
3001
|
+
if (typeof exportValue === "object" && exportValue !== null) {
|
|
3002
|
+
const resolved = exportValue.import || exportValue.browser || exportValue.default || exportValue.require;
|
|
3003
|
+
if (typeof resolved === "object" && resolved !== null) {
|
|
3004
|
+
return resolveExport(resolved);
|
|
3005
|
+
}
|
|
3006
|
+
if (typeof resolved === "string") {
|
|
3007
|
+
return resolved.startsWith("./") ? resolved.slice(2) : resolved;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
return null;
|
|
3011
|
+
}
|
|
2451
3012
|
function cors(options = {}) {
|
|
2452
3013
|
const { origin = "*", methods = ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"], credentials = true, maxAge = 86400 } = options;
|
|
2453
3014
|
return async (ctx, next) => {
|
|
@@ -2603,8 +3164,9 @@ function createProxyHandler(proxyConfigs) {
|
|
|
2603
3164
|
}
|
|
2604
3165
|
if (changeOrigin) {
|
|
2605
3166
|
proxyReqHeaders.host = targetUrl.host;
|
|
3167
|
+
} else {
|
|
3168
|
+
delete proxyReqHeaders["host"];
|
|
2606
3169
|
}
|
|
2607
|
-
delete proxyReqHeaders["host"];
|
|
2608
3170
|
const proxyReqOptions = {
|
|
2609
3171
|
method: req.method,
|
|
2610
3172
|
headers: proxyReqHeaders
|
|
@@ -2741,7 +3303,6 @@ var defaultOptions = {
|
|
|
2741
3303
|
watch: ["**/*.ts", "**/*.js", "**/*.html", "**/*.css"],
|
|
2742
3304
|
ignore: ["node_modules/**", "dist/**", ".git/**", "**/*.d.ts"],
|
|
2743
3305
|
logging: true,
|
|
2744
|
-
middleware: [],
|
|
2745
3306
|
worker: [],
|
|
2746
3307
|
mode: "dev"
|
|
2747
3308
|
};
|
|
@@ -2813,7 +3374,7 @@ function createDevServer(options) {
|
|
|
2813
3374
|
}
|
|
2814
3375
|
let filePath;
|
|
2815
3376
|
if (url === "/" && matchedClient.ssr && !matchedClient.index) {
|
|
2816
|
-
return serveSSR(res, matchedClient);
|
|
3377
|
+
return await serveSSR(res, matchedClient);
|
|
2817
3378
|
} else {
|
|
2818
3379
|
filePath = url === "/" ? matchedClient.index || "/index.html" : url;
|
|
2819
3380
|
}
|
|
@@ -2895,7 +3456,7 @@ function createDevServer(options) {
|
|
|
2895
3456
|
if (!resolvedPath) {
|
|
2896
3457
|
if (!res.headersSent) {
|
|
2897
3458
|
if (filePath === "/index.html" && matchedClient.ssr) {
|
|
2898
|
-
return serveSSR(res, matchedClient);
|
|
3459
|
+
return await serveSSR(res, matchedClient);
|
|
2899
3460
|
}
|
|
2900
3461
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
2901
3462
|
return send404(res, "404 Not Found");
|
|
@@ -2919,7 +3480,7 @@ function createDevServer(options) {
|
|
|
2919
3480
|
} catch {
|
|
2920
3481
|
if (config.logging) console.log(`[DEBUG] No index file found in directory`);
|
|
2921
3482
|
if (matchedClient.ssr) {
|
|
2922
|
-
return serveSSR(res, matchedClient);
|
|
3483
|
+
return await serveSSR(res, matchedClient);
|
|
2923
3484
|
}
|
|
2924
3485
|
return send404(res, "404 Not Found");
|
|
2925
3486
|
}
|
|
@@ -2939,12 +3500,12 @@ function createDevServer(options) {
|
|
|
2939
3500
|
return send403(res, "403 Forbidden");
|
|
2940
3501
|
}
|
|
2941
3502
|
await stat(indexPath);
|
|
2942
|
-
return serveFile(indexPath, res, matchedClient);
|
|
3503
|
+
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
2943
3504
|
} catch {
|
|
2944
3505
|
return send404(res, "404 Not Found");
|
|
2945
3506
|
}
|
|
2946
3507
|
}
|
|
2947
|
-
await serveFile(fullPath, res, matchedClient);
|
|
3508
|
+
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
2948
3509
|
} catch (error) {
|
|
2949
3510
|
if (!res.headersSent) {
|
|
2950
3511
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
@@ -2952,16 +3513,12 @@ function createDevServer(options) {
|
|
|
2952
3513
|
}
|
|
2953
3514
|
}
|
|
2954
3515
|
});
|
|
2955
|
-
async function serveFile(filePath, res, client) {
|
|
3516
|
+
async function serveFile(filePath, res, client, isNodeModulesOrDist = false) {
|
|
2956
3517
|
try {
|
|
2957
3518
|
const rootDir = await realpath(resolve(client.root));
|
|
2958
3519
|
const unresolvedPath = resolve(filePath);
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
const projectRoot = await realpath(resolve(client.root, ".."));
|
|
2962
|
-
const isInProjectRoot = unresolvedPath.startsWith(projectRoot + sep) || unresolvedPath === projectRoot;
|
|
2963
|
-
if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir && !isInProjectRoot) {
|
|
2964
|
-
if (!isNodeModules && !isDist) {
|
|
3520
|
+
if (!isNodeModulesOrDist) {
|
|
3521
|
+
if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir) {
|
|
2965
3522
|
if (config.logging) console.log(`[403] Attempted to serve file outside allowed directories: ${filePath}`);
|
|
2966
3523
|
return send403(res, "403 Forbidden");
|
|
2967
3524
|
}
|
|
@@ -2969,9 +3526,14 @@ function createDevServer(options) {
|
|
|
2969
3526
|
let resolvedPath;
|
|
2970
3527
|
try {
|
|
2971
3528
|
resolvedPath = await realpath(unresolvedPath);
|
|
3529
|
+
if (isNodeModulesOrDist && resolvedPath) {
|
|
3530
|
+
if (config.logging && !resolvedPath.startsWith(rootDir + sep)) {
|
|
3531
|
+
console.log(`[DEBUG] Serving symlinked file: ${resolvedPath}`);
|
|
3532
|
+
}
|
|
3533
|
+
}
|
|
2972
3534
|
} catch {
|
|
2973
3535
|
if (filePath.endsWith("index.html") && client.ssr) {
|
|
2974
|
-
return serveSSR(res, client);
|
|
3536
|
+
return await serveSSR(res, client);
|
|
2975
3537
|
}
|
|
2976
3538
|
return send404(res, "404 Not Found");
|
|
2977
3539
|
}
|
|
@@ -3075,7 +3637,7 @@ ${error}`);
|
|
|
3075
3637
|
}
|
|
3076
3638
|
}
|
|
3077
3639
|
}
|
|
3078
|
-
const elitImportMap = createElitImportMap(basePath, client.mode);
|
|
3640
|
+
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
3079
3641
|
const headInjection = ssrStyles ? `${ssrStyles}
|
|
3080
3642
|
${elitImportMap}` : elitImportMap;
|
|
3081
3643
|
html2 = html2.includes("</head>") ? html2.replace("</head>", `${headInjection}</head>`) : html2;
|
|
@@ -3105,7 +3667,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3105
3667
|
send500(res, "500 Internal Server Error");
|
|
3106
3668
|
}
|
|
3107
3669
|
}
|
|
3108
|
-
function serveSSR(res, client) {
|
|
3670
|
+
async function serveSSR(res, client) {
|
|
3109
3671
|
try {
|
|
3110
3672
|
if (!client.ssr) {
|
|
3111
3673
|
return send500(res, "SSR function not configured");
|
|
@@ -3127,7 +3689,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3127
3689
|
const basePath = normalizeBasePath(client.basePath);
|
|
3128
3690
|
html2 = rewriteRelativePaths(html2, basePath);
|
|
3129
3691
|
const hmrScript = createHMRScript(config.port, basePath);
|
|
3130
|
-
const elitImportMap = createElitImportMap(basePath, client.mode);
|
|
3692
|
+
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
3131
3693
|
html2 = html2.includes("</head>") ? html2.replace("</head>", `${elitImportMap}</head>`) : html2;
|
|
3132
3694
|
html2 = html2.includes("</body>") ? html2.replace("</body>", `${hmrScript}</body>`) : html2 + hmrScript;
|
|
3133
3695
|
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
@@ -3264,6 +3826,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3264
3826
|
StateManager,
|
|
3265
3827
|
bodyLimit,
|
|
3266
3828
|
cacheControl,
|
|
3829
|
+
clearImportMapCache,
|
|
3267
3830
|
compress,
|
|
3268
3831
|
cors,
|
|
3269
3832
|
createDevServer,
|