@jsenv/core 40.12.3 → 40.12.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.
@@ -6611,7 +6611,7 @@ const jsenvPluginDirectoryListing = ({
6611
6611
  if (!acceptsHtml) {
6612
6612
  return null;
6613
6613
  }
6614
- reference.fsStat = null; // reset fsStat, now it's not a directory anyor
6614
+ reference.fsStat = null; // reset fsStat as it's not a directory anymore
6615
6615
  return `${htmlFileUrlForDirectory}?url=${encodeURIComponent(url)}`;
6616
6616
  },
6617
6617
  transformUrlContent: {
@@ -7030,13 +7030,13 @@ const jsenvPluginFsRedirection = ({
7030
7030
  applyFsStatEffectsOnUrlObject(urlObject, fsStat);
7031
7031
  }
7032
7032
  }
7033
- if (!fsStat) {
7034
- // for SPA we want to serve the root HTML file only when:
7035
- // 1. There is no corresponding file on the filesystem
7036
- // 2. The url pathname does not have an extension
7037
- // This point assume client is requesting a file when there is an extension
7038
- // and it assumes all routes will not use extension
7039
- if (spa && !urlToExtension(urlObject)) {
7033
+ if (spa) {
7034
+ // for SPA we want to serve the root HTML file most of the time
7035
+ if (!fsStat) {
7036
+ if (urlToExtension(urlObject)) {
7037
+ // url has an extension, we assume it's a file request -> let 404 happen
7038
+ return null;
7039
+ }
7040
7040
  const { requestedUrl, rootDirectoryUrl, mainFilePath } =
7041
7041
  reference.ownerUrlInfo.context;
7042
7042
  const closestHtmlRootFile = getClosestHtmlRootFile(
@@ -7048,6 +7048,16 @@ const jsenvPluginFsRedirection = ({
7048
7048
  }
7049
7049
  return new URL(mainFilePath, rootDirectoryUrl);
7050
7050
  }
7051
+ if (fsStat.isDirectory()) {
7052
+ // When requesting a directory, check if we have an HTML entry file for that directory
7053
+ const directoryEntryFileUrl = getDirectoryEntryFileUrl(urlObject);
7054
+ if (directoryEntryFileUrl) {
7055
+ reference.fsStat = readEntryStatSync(directoryEntryFileUrl);
7056
+ return directoryEntryFileUrl;
7057
+ }
7058
+ }
7059
+ }
7060
+ if (!fsStat) {
7051
7061
  return null;
7052
7062
  }
7053
7063
  const urlBeforeSymlinkResolution = urlObject.href;
@@ -7095,17 +7105,24 @@ const resolveSymlink = (fileUrl) => {
7095
7105
  return realUrlObject.href;
7096
7106
  };
7097
7107
 
7108
+ const getDirectoryEntryFileUrl = (directoryUrl) => {
7109
+ const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
7110
+ if (existsSync(indexHtmlFileUrl)) {
7111
+ return indexHtmlFileUrl.href;
7112
+ }
7113
+ const filename = urlToFilename(directoryUrl);
7114
+ const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
7115
+ if (existsSync(htmlFileUrlCandidate)) {
7116
+ return htmlFileUrlCandidate.href;
7117
+ }
7118
+ return null;
7119
+ };
7098
7120
  const getClosestHtmlRootFile = (requestedUrl, serverRootDirectoryUrl) => {
7099
7121
  let directoryUrl = new URL("./", requestedUrl);
7100
7122
  while (true) {
7101
- const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
7102
- if (existsSync(indexHtmlFileUrl)) {
7103
- return indexHtmlFileUrl.href;
7104
- }
7105
- const filename = urlToFilename(directoryUrl);
7106
- const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
7107
- if (existsSync(htmlFileUrlCandidate)) {
7108
- return htmlFileUrlCandidate.href;
7123
+ const directoryEntryFileUrl = getDirectoryEntryFileUrl(directoryUrl);
7124
+ if (directoryEntryFileUrl) {
7125
+ return directoryEntryFileUrl;
7109
7126
  }
7110
7127
  if (!urlIsOrIsInsideOf(directoryUrl, serverRootDirectoryUrl)) {
7111
7128
  return null;
@@ -6316,7 +6316,7 @@ const jsenvPluginDirectoryListing = ({
6316
6316
  if (!acceptsHtml) {
6317
6317
  return null;
6318
6318
  }
6319
- reference.fsStat = null; // reset fsStat, now it's not a directory anyor
6319
+ reference.fsStat = null; // reset fsStat as it's not a directory anymore
6320
6320
  return `${htmlFileUrlForDirectory}?url=${encodeURIComponent(url)}`;
6321
6321
  },
6322
6322
  transformUrlContent: {
@@ -6735,13 +6735,13 @@ const jsenvPluginFsRedirection = ({
6735
6735
  applyFsStatEffectsOnUrlObject(urlObject, fsStat);
6736
6736
  }
6737
6737
  }
6738
- if (!fsStat) {
6739
- // for SPA we want to serve the root HTML file only when:
6740
- // 1. There is no corresponding file on the filesystem
6741
- // 2. The url pathname does not have an extension
6742
- // This point assume client is requesting a file when there is an extension
6743
- // and it assumes all routes will not use extension
6744
- if (spa && !urlToExtension(urlObject)) {
6738
+ if (spa) {
6739
+ // for SPA we want to serve the root HTML file most of the time
6740
+ if (!fsStat) {
6741
+ if (urlToExtension(urlObject)) {
6742
+ // url has an extension, we assume it's a file request -> let 404 happen
6743
+ return null;
6744
+ }
6745
6745
  const { requestedUrl, rootDirectoryUrl, mainFilePath } =
6746
6746
  reference.ownerUrlInfo.context;
6747
6747
  const closestHtmlRootFile = getClosestHtmlRootFile(
@@ -6753,6 +6753,16 @@ const jsenvPluginFsRedirection = ({
6753
6753
  }
6754
6754
  return new URL(mainFilePath, rootDirectoryUrl);
6755
6755
  }
6756
+ if (fsStat.isDirectory()) {
6757
+ // When requesting a directory, check if we have an HTML entry file for that directory
6758
+ const directoryEntryFileUrl = getDirectoryEntryFileUrl(urlObject);
6759
+ if (directoryEntryFileUrl) {
6760
+ reference.fsStat = readEntryStatSync(directoryEntryFileUrl);
6761
+ return directoryEntryFileUrl;
6762
+ }
6763
+ }
6764
+ }
6765
+ if (!fsStat) {
6756
6766
  return null;
6757
6767
  }
6758
6768
  const urlBeforeSymlinkResolution = urlObject.href;
@@ -6800,17 +6810,24 @@ const resolveSymlink = (fileUrl) => {
6800
6810
  return realUrlObject.href;
6801
6811
  };
6802
6812
 
6813
+ const getDirectoryEntryFileUrl = (directoryUrl) => {
6814
+ const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
6815
+ if (existsSync(indexHtmlFileUrl)) {
6816
+ return indexHtmlFileUrl.href;
6817
+ }
6818
+ const filename = urlToFilename(directoryUrl);
6819
+ const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
6820
+ if (existsSync(htmlFileUrlCandidate)) {
6821
+ return htmlFileUrlCandidate.href;
6822
+ }
6823
+ return null;
6824
+ };
6803
6825
  const getClosestHtmlRootFile = (requestedUrl, serverRootDirectoryUrl) => {
6804
6826
  let directoryUrl = new URL("./", requestedUrl);
6805
6827
  while (true) {
6806
- const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
6807
- if (existsSync(indexHtmlFileUrl)) {
6808
- return indexHtmlFileUrl.href;
6809
- }
6810
- const filename = urlToFilename(directoryUrl);
6811
- const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
6812
- if (existsSync(htmlFileUrlCandidate)) {
6813
- return htmlFileUrlCandidate.href;
6828
+ const directoryEntryFileUrl = getDirectoryEntryFileUrl(directoryUrl);
6829
+ if (directoryEntryFileUrl) {
6830
+ return directoryEntryFileUrl;
6814
6831
  }
6815
6832
  if (!urlIsOrIsInsideOf(directoryUrl, serverRootDirectoryUrl)) {
6816
6833
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "40.12.3",
3
+ "version": "40.12.4",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -102,7 +102,7 @@ export const jsenvPluginDirectoryListing = ({
102
102
  if (!acceptsHtml) {
103
103
  return null;
104
104
  }
105
- reference.fsStat = null; // reset fsStat, now it's not a directory anyor
105
+ reference.fsStat = null; // reset fsStat as it's not a directory anymore
106
106
  return `${htmlFileUrlForDirectory}?url=${encodeURIComponent(url)}`;
107
107
  },
108
108
  transformUrlContent: {
@@ -89,13 +89,13 @@ export const jsenvPluginFsRedirection = ({
89
89
  applyFsStatEffectsOnUrlObject(urlObject, fsStat);
90
90
  }
91
91
  }
92
- if (!fsStat) {
93
- // for SPA we want to serve the root HTML file only when:
94
- // 1. There is no corresponding file on the filesystem
95
- // 2. The url pathname does not have an extension
96
- // This point assume client is requesting a file when there is an extension
97
- // and it assumes all routes will not use extension
98
- if (spa && !urlToExtension(urlObject)) {
92
+ if (spa) {
93
+ // for SPA we want to serve the root HTML file most of the time
94
+ if (!fsStat) {
95
+ if (urlToExtension(urlObject)) {
96
+ // url has an extension, we assume it's a file request -> let 404 happen
97
+ return null;
98
+ }
99
99
  const { requestedUrl, rootDirectoryUrl, mainFilePath } =
100
100
  reference.ownerUrlInfo.context;
101
101
  const closestHtmlRootFile = getClosestHtmlRootFile(
@@ -107,6 +107,16 @@ export const jsenvPluginFsRedirection = ({
107
107
  }
108
108
  return new URL(mainFilePath, rootDirectoryUrl);
109
109
  }
110
+ if (fsStat.isDirectory()) {
111
+ // When requesting a directory, check if we have an HTML entry file for that directory
112
+ const directoryEntryFileUrl = getDirectoryEntryFileUrl(urlObject);
113
+ if (directoryEntryFileUrl) {
114
+ reference.fsStat = readEntryStatSync(directoryEntryFileUrl);
115
+ return directoryEntryFileUrl;
116
+ }
117
+ }
118
+ }
119
+ if (!fsStat) {
110
120
  return null;
111
121
  }
112
122
  const urlBeforeSymlinkResolution = urlObject.href;
@@ -154,17 +164,24 @@ const resolveSymlink = (fileUrl) => {
154
164
  return realUrlObject.href;
155
165
  };
156
166
 
167
+ const getDirectoryEntryFileUrl = (directoryUrl) => {
168
+ const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
169
+ if (existsSync(indexHtmlFileUrl)) {
170
+ return indexHtmlFileUrl.href;
171
+ }
172
+ const filename = urlToFilename(directoryUrl);
173
+ const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
174
+ if (existsSync(htmlFileUrlCandidate)) {
175
+ return htmlFileUrlCandidate.href;
176
+ }
177
+ return null;
178
+ };
157
179
  const getClosestHtmlRootFile = (requestedUrl, serverRootDirectoryUrl) => {
158
180
  let directoryUrl = new URL("./", requestedUrl);
159
181
  while (true) {
160
- const indexHtmlFileUrl = new URL(`index.html`, directoryUrl);
161
- if (existsSync(indexHtmlFileUrl)) {
162
- return indexHtmlFileUrl.href;
163
- }
164
- const filename = urlToFilename(directoryUrl);
165
- const htmlFileUrlCandidate = new URL(`${filename}.html`, directoryUrl);
166
- if (existsSync(htmlFileUrlCandidate)) {
167
- return htmlFileUrlCandidate.href;
182
+ const directoryEntryFileUrl = getDirectoryEntryFileUrl(directoryUrl);
183
+ if (directoryEntryFileUrl) {
184
+ return directoryEntryFileUrl;
168
185
  }
169
186
  if (!urlIsOrIsInsideOf(directoryUrl, serverRootDirectoryUrl)) {
170
187
  return null;