evolit 0.1.0-alpha.18 → 0.1.0-alpha.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "evolit",
3
- "version": "0.1.0-alpha.18",
3
+ "version": "0.1.0-alpha.19",
4
4
  "description": "A convention-driven application framework for LitSX and web components.",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@4.10.3",
@@ -923,10 +923,25 @@ export function getClientOutputRoot(projectRoot, mode) {
923
923
  }
924
924
 
925
925
  export function toClientModuleRelativePath(projectRoot, sourcePath) {
926
- const relativePath = path.relative(projectRoot, sourcePath);
926
+ const relativePath = toClientSourceRelativePath(projectRoot, sourcePath);
927
927
  return toCompiledClientModuleRelativePath(relativePath);
928
928
  }
929
929
 
930
+ function toClientSourceRelativePath(projectRoot, sourcePath) {
931
+ const relativePath = path.relative(projectRoot, sourcePath);
932
+ const isOutsideProject = relativePath === ".."
933
+ || relativePath.startsWith(`..${path.sep}`)
934
+ || path.isAbsolute(relativePath);
935
+ if (!isOutsideProject) {
936
+ return relativePath;
937
+ }
938
+
939
+ return path.join(
940
+ "__unmanaged__",
941
+ ...relativePath.split(path.sep).map((segment) => segment === ".." ? "__up__" : segment),
942
+ );
943
+ }
944
+
930
945
  function toCompiledClientModuleRelativePath(relativePath) {
931
946
  const extension = path.extname(relativePath);
932
947
  return extension
@@ -983,17 +998,17 @@ function getClientModulePublicUrl(assetManifest, clientModule) {
983
998
  return null;
984
999
  }
985
1000
 
1001
+ function isVirtualClientModuleId(moduleId) {
1002
+ return moduleId.startsWith("/app/") || moduleId.startsWith("/__unmanaged__/");
1003
+ }
1004
+
986
1005
  function toPublicHydrationModuleId(projectRoot, moduleId) {
987
1006
  if (typeof moduleId !== "string" || moduleId.length === 0) {
988
1007
  return null;
989
1008
  }
990
1009
 
991
1010
  if (path.isAbsolute(moduleId)) {
992
- if (!moduleId.startsWith(projectRoot)) {
993
- return null;
994
- }
995
-
996
- const relativePath = path.relative(projectRoot, moduleId).split(path.sep).join("/");
1011
+ const relativePath = toClientSourceRelativePath(projectRoot, moduleId).split(path.sep).join("/");
997
1012
  return `/${relativePath}`;
998
1013
  }
999
1014
 
@@ -1035,14 +1050,10 @@ export function createAssetResolver(projectRoot, options = {}) {
1035
1050
  }
1036
1051
 
1037
1052
  let relativeClientModule = null;
1038
- if (moduleId.startsWith("/") && !moduleId.startsWith(projectRoot)) {
1039
- relativeClientModule = toCompiledClientModuleRelativePath(moduleId.slice(1));
1040
- } else if (path.isAbsolute(moduleId)) {
1041
- if (!moduleId.startsWith(projectRoot)) {
1042
- return null;
1043
- }
1044
-
1053
+ if (path.isAbsolute(moduleId) && !isVirtualClientModuleId(moduleId)) {
1045
1054
  relativeClientModule = toClientModuleRelativePath(projectRoot, moduleId);
1055
+ } else if (moduleId.startsWith("/")) {
1056
+ relativeClientModule = toCompiledClientModuleRelativePath(moduleId.slice(1));
1046
1057
  }
1047
1058
 
1048
1059
  if (!relativeClientModule) {
@@ -1075,7 +1086,7 @@ export function createHydrationBootstrap({
1075
1086
  hydrationModuleUrl = "@litsx/ssr/hydration",
1076
1087
  }) {
1077
1088
  const normalizedHydrationData = normalizeHydrationDataForClient(hydrationData);
1078
- const moduleUrls = [...new Set([
1089
+ const rootModuleUrls = [...new Set([
1079
1090
  ...(normalizedHydrationData?.roots ?? [])
1080
1091
  .map((root) => {
1081
1092
  if (typeof root?.moduleId !== "string" || root.moduleId.length === 0) {
@@ -1085,16 +1096,18 @@ export function createHydrationBootstrap({
1085
1096
  return assetResolver?.(root.moduleId) ?? null;
1086
1097
  })
1087
1098
  .filter((moduleUrl) => typeof moduleUrl === "string" && moduleUrl.length > 0),
1088
- ...(Array.isArray(normalizedHydrationData?.clientImports)
1099
+ ])];
1100
+ const clientImports = [...new Set(
1101
+ (Array.isArray(normalizedHydrationData?.clientImports)
1089
1102
  ? normalizedHydrationData.clientImports
1090
- : []),
1091
- ].filter((moduleUrl) => typeof moduleUrl === "string" && moduleUrl.length > 0))];
1103
+ : []).filter((moduleUrl) => typeof moduleUrl === "string" && moduleUrl.length > 0),
1104
+ )];
1092
1105
 
1093
- if (moduleUrls.length === 0) {
1106
+ if (rootModuleUrls.length === 0 && clientImports.length === 0) {
1094
1107
  return "";
1095
1108
  }
1096
1109
 
1097
- const moduleLoaders = moduleUrls
1110
+ const moduleLoaders = rootModuleUrls
1098
1111
  .map((moduleUrl) => ` () => import(${JSON.stringify(moduleUrl)})`)
1099
1112
  .join(",\n");
1100
1113
 
@@ -1102,7 +1115,7 @@ export function createHydrationBootstrap({
1102
1115
  import { hydratePage, registerHydrationModules } from ${JSON.stringify(hydrationModuleUrl)};
1103
1116
 
1104
1117
  await hydratePage({
1105
- clientImports: [],
1118
+ clientImports: ${JSON.stringify(clientImports)},
1106
1119
  register: () => registerHydrationModules([
1107
1120
  ${moduleLoaders}
1108
1121
  ])