@jsenv/core 35.0.2 → 35.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.
Files changed (118) hide show
  1. package/dist/html/explorer.html +107 -107
  2. package/dist/js/new_stylesheet.js +3 -0
  3. package/dist/js/s.js.map +3 -3
  4. package/dist/jsenv_core.js +15 -17
  5. package/package.json +1 -1
  6. package/src/build/build.js +589 -587
  7. package/src/build/build_urls_generator.js +44 -44
  8. package/src/build/graph_utils.js +14 -14
  9. package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
  10. package/src/build/line_break_unix.js +11 -11
  11. package/src/build/start_build_server.js +37 -37
  12. package/src/build/version_generator.js +7 -7
  13. package/src/build/version_mappings_injection.js +23 -23
  14. package/src/dev/file_service.js +136 -135
  15. package/src/dev/start_dev_server.js +56 -56
  16. package/src/dev/user_agent.js +8 -8
  17. package/src/helpers/basic_fetch.js +24 -24
  18. package/src/helpers/command/command.js +28 -28
  19. package/src/helpers/lookup_package_directory.js +19 -16
  20. package/src/helpers/ping_server.js +17 -17
  21. package/src/helpers/require_from_jsenv.js +2 -2
  22. package/src/helpers/watch_source_files.js +9 -9
  23. package/src/helpers/web_url_converter.js +10 -10
  24. package/src/helpers/worker_reload.js +27 -27
  25. package/src/kitchen/compat/features_compatibility.js +1 -1
  26. package/src/kitchen/compat/runtime_compat.js +26 -24
  27. package/src/kitchen/errors.js +75 -75
  28. package/src/kitchen/fetched_content_compliance.js +8 -8
  29. package/src/kitchen/kitchen.js +251 -250
  30. package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
  31. package/src/kitchen/url_graph/url_graph_loader.js +30 -30
  32. package/src/kitchen/url_graph/url_graph_report.js +57 -57
  33. package/src/kitchen/url_graph/url_info_transformations.js +77 -77
  34. package/src/kitchen/url_graph.js +121 -121
  35. package/src/kitchen/url_specifier_encoding.js +21 -21
  36. package/src/kitchen/web_workers.js +5 -5
  37. package/src/main.js +3 -3
  38. package/src/plugins/autoreload/client/autoreload.js +96 -96
  39. package/src/plugins/autoreload/client/reload.js +56 -56
  40. package/src/plugins/autoreload/client/url_helpers.js +13 -13
  41. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
  42. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
  43. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
  44. package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
  45. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
  46. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
  47. package/src/plugins/explorer/client/explorer.html +107 -107
  48. package/src/plugins/explorer/jsenv_plugin_explorer.js +23 -25
  49. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
  50. package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
  51. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
  52. package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
  53. package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
  54. package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
  55. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
  56. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
  57. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
  58. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
  59. package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
  60. package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
  61. package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
  62. package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
  63. package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
  64. package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
  65. package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
  66. package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
  67. package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
  68. package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
  69. package/src/plugins/plugin_controller.js +124 -124
  70. package/src/plugins/plugins.js +30 -30
  71. package/src/plugins/ribbon/client/ribbon.js +6 -6
  72. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
  73. package/src/plugins/server_events/client/connection_manager.js +52 -52
  74. package/src/plugins/server_events/client/event_source_connection.js +36 -36
  75. package/src/plugins/server_events/client/events_manager.js +37 -37
  76. package/src/plugins/server_events/client/server_events_client.js +7 -7
  77. package/src/plugins/server_events/client/web_socket_connection.js +39 -39
  78. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
  79. package/src/plugins/server_events/server_events_dispatcher.js +43 -43
  80. package/src/plugins/supervisor/client/supervisor.js +455 -450
  81. package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
  82. package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
  83. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
  84. package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
  85. package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
  86. package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
  87. package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
  88. package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
  89. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
  90. package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
  91. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
  92. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
  93. package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
  94. package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
  95. package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
  96. package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
  97. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
  98. package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
  99. package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
  100. package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
  101. package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
  102. package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
  103. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
  104. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
  105. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
  106. package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
  107. package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
  108. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
  109. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
  110. package/src/plugins/url_analysis/css/css_urls.js +12 -12
  111. package/src/plugins/url_analysis/html/html_urls.js +85 -85
  112. package/src/plugins/url_analysis/js/js_urls.js +16 -16
  113. package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
  114. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
  115. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
  116. package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +36 -36
  117. package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
  118. package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
@@ -1,18 +1,18 @@
1
- import { readFileSync } from "node:fs"
2
- import { serveDirectory, composeTwoResponses } from "@jsenv/server"
3
- import { bufferToEtag } from "@jsenv/filesystem"
4
- import { asUrlWithoutSearch } from "@jsenv/urls"
5
- import { URL_META } from "@jsenv/url-meta"
1
+ import { readFileSync } from "node:fs";
2
+ import { serveDirectory, composeTwoResponses } from "@jsenv/server";
3
+ import { bufferToEtag } from "@jsenv/filesystem";
4
+ import { asUrlWithoutSearch } from "@jsenv/urls";
5
+ import { URL_META } from "@jsenv/url-meta";
6
6
 
7
- import { WEB_URL_CONVERTER } from "../helpers/web_url_converter.js"
8
- import { watchSourceFiles } from "../helpers/watch_source_files.js"
9
- import { createUrlGraph } from "../kitchen/url_graph.js"
10
- import { createKitchen } from "../kitchen/kitchen.js"
11
- import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js"
12
- import { getCorePlugins } from "../plugins/plugins.js"
13
- import { explorerHtmlFileUrl } from "../plugins/explorer/jsenv_plugin_explorer.js"
14
- import { jsenvPluginServerEventsClientInjection } from "../plugins/server_events/jsenv_plugin_server_events_client_injection.js"
15
- import { parseUserAgentHeader } from "./user_agent.js"
7
+ import { WEB_URL_CONVERTER } from "../helpers/web_url_converter.js";
8
+ import { watchSourceFiles } from "../helpers/watch_source_files.js";
9
+ import { createUrlGraph } from "../kitchen/url_graph.js";
10
+ import { createKitchen } from "../kitchen/kitchen.js";
11
+ import { RUNTIME_COMPAT } from "../kitchen/compat/runtime_compat.js";
12
+ import { getCorePlugins } from "../plugins/plugins.js";
13
+ import { explorerHtmlFileUrl } from "../plugins/explorer/jsenv_plugin_explorer.js";
14
+ import { jsenvPluginServerEventsClientInjection } from "../plugins/server_events/jsenv_plugin_server_events_client_injection.js";
15
+ import { parseUserAgentHeader } from "./user_agent.js";
16
16
 
17
17
  export const createFileService = ({
18
18
  signal,
@@ -42,65 +42,66 @@ export const createFileService = ({
42
42
  sourcemapsSourcesContent,
43
43
  outDirectoryUrl,
44
44
  }) => {
45
- const clientFileChangeCallbackList = []
46
- const clientFilesPruneCallbackList = []
45
+ const clientFileChangeCallbackList = [];
46
+ const clientFilesPruneCallbackList = [];
47
47
  const stopWatchingSourceFiles = watchSourceFiles(
48
48
  sourceDirectoryUrl,
49
49
  (fileInfo) => {
50
50
  clientFileChangeCallbackList.forEach((callback) => {
51
- callback(fileInfo)
52
- })
51
+ callback(fileInfo);
52
+ });
53
53
  },
54
54
  {
55
55
  sourceFilesConfig,
56
56
  keepProcessAlive: false,
57
57
  cooldownBetweenFileEvents,
58
58
  },
59
- )
60
- serverStopCallbacks.push(stopWatchingSourceFiles)
59
+ );
60
+ serverStopCallbacks.push(stopWatchingSourceFiles);
61
61
 
62
62
  const getOrCreateContext = (request) => {
63
63
  const { runtimeName, runtimeVersion } = parseUserAgentHeader(
64
64
  request.headers["user-agent"] || "",
65
- )
66
- const runtimeId = `${runtimeName}@${runtimeVersion}`
67
- const existingContext = contextCache.get(runtimeId)
65
+ );
66
+ const runtimeId = `${runtimeName}@${runtimeVersion}`;
67
+ const existingContext = contextCache.get(runtimeId);
68
68
  if (existingContext) {
69
- return existingContext
69
+ return existingContext;
70
70
  }
71
71
  const watchAssociations = URL_META.resolveAssociations(
72
72
  { watch: stopWatchingSourceFiles.watchPatterns },
73
73
  sourceDirectoryUrl,
74
- )
74
+ );
75
75
  const urlGraph = createUrlGraph({
76
76
  name: runtimeId,
77
- })
77
+ });
78
78
  clientFileChangeCallbackList.push(({ url }) => {
79
79
  const onUrlInfo = (urlInfo) => {
80
- urlGraph.considerModified(urlInfo)
81
- }
82
- const exactUrlInfo = urlGraph.getUrlInfo(url)
80
+ urlGraph.considerModified(urlInfo);
81
+ };
82
+ const exactUrlInfo = urlGraph.getUrlInfo(url);
83
83
  if (exactUrlInfo) {
84
- onUrlInfo(exactUrlInfo)
84
+ onUrlInfo(exactUrlInfo);
85
85
  }
86
86
  urlGraph.urlInfoMap.forEach((urlInfo) => {
87
- if (urlInfo === exactUrlInfo) return
88
- const urlWithoutSearch = asUrlWithoutSearch(urlInfo.url)
89
- if (urlWithoutSearch !== url) return
90
- if (exactUrlInfo && exactUrlInfo.dependents.has(urlInfo.url)) return
91
- onUrlInfo(urlInfo)
92
- })
93
- })
94
- const clientRuntimeCompat = { [runtimeName]: runtimeVersion }
87
+ if (urlInfo === exactUrlInfo) return;
88
+ const urlWithoutSearch = asUrlWithoutSearch(urlInfo.url);
89
+ if (urlWithoutSearch !== url) return;
90
+ if (exactUrlInfo && exactUrlInfo.dependents.has(urlInfo.url)) return;
91
+ onUrlInfo(urlInfo);
92
+ });
93
+ });
94
+ const clientRuntimeCompat = { [runtimeName]: runtimeVersion };
95
95
 
96
- let mainFileUrl
97
- if (sourceMainFilePath === undefined) {
98
- mainFileUrl = explorer
99
- ? String(explorerHtmlFileUrl)
100
- : String(new URL("./index.html", sourceDirectoryUrl))
96
+ let defaultFileUrl;
97
+ if (explorer) {
98
+ defaultFileUrl = String(explorerHtmlFileUrl);
99
+ } else if (sourceMainFilePath) {
100
+ defaultFileUrl = String(new URL(sourceMainFilePath, sourceDirectoryUrl));
101
101
  } else {
102
- mainFileUrl = String(new URL(sourceMainFilePath, sourceDirectoryUrl))
102
+ defaultFileUrl = String(new URL("./index.html", sourceDirectoryUrl));
103
103
  }
104
+
104
105
  const kitchen = createKitchen({
105
106
  signal,
106
107
  logLevel,
@@ -120,7 +121,7 @@ export const createFileService = ({
120
121
  ...plugins,
121
122
  ...getCorePlugins({
122
123
  rootDirectoryUrl: sourceDirectoryUrl,
123
- mainFileUrl,
124
+ defaultFileUrl,
124
125
  runtimeCompat,
125
126
 
126
127
  urlAnalysis,
@@ -145,77 +146,77 @@ export const createFileService = ({
145
146
  outDirectoryUrl: outDirectoryUrl
146
147
  ? new URL(`${runtimeName}@${runtimeVersion}/`, outDirectoryUrl)
147
148
  : undefined,
148
- })
149
+ });
149
150
  urlGraph.createUrlInfoCallbackRef.current = (urlInfo) => {
150
151
  const { watch } = URL_META.applyAssociations({
151
152
  url: urlInfo.url,
152
153
  associations: watchAssociations,
153
- })
154
- urlInfo.isWatched = watch
154
+ });
155
+ urlInfo.isWatched = watch;
155
156
  // si une urlInfo dépends de pleins d'autres alors
156
157
  // on voudrait check chacune de ces url infos (package.json dans mon cas)
157
158
  urlInfo.isValid = () => {
158
159
  if (!urlInfo.url.startsWith("file:")) {
159
- return false
160
+ return false;
160
161
  }
161
162
  if (watch && urlInfo.contentEtag === undefined) {
162
163
  // we trust the watching mecanism
163
164
  // doing urlInfo.contentEtag = undefined
164
165
  // when file is modified
165
- return false
166
+ return false;
166
167
  }
167
168
  if (!watch && urlInfo.contentEtag) {
168
169
  // file is not watched, check the filesystem
169
- let fileContentAsBuffer
170
+ let fileContentAsBuffer;
170
171
  try {
171
- fileContentAsBuffer = readFileSync(new URL(urlInfo.url))
172
+ fileContentAsBuffer = readFileSync(new URL(urlInfo.url));
172
173
  } catch (e) {
173
174
  if (e.code === "ENOENT") {
174
175
  // we should consider calling urlGraph.deleteUrlInfo(urlInfo)
175
- urlInfo.originalContentEtag = undefined
176
- urlInfo.contentEtag = undefined
177
- return false
176
+ urlInfo.originalContentEtag = undefined;
177
+ urlInfo.contentEtag = undefined;
178
+ return false;
178
179
  }
179
- return false
180
+ return false;
180
181
  }
181
- const fileContentEtag = bufferToEtag(fileContentAsBuffer)
182
+ const fileContentEtag = bufferToEtag(fileContentAsBuffer);
182
183
  if (fileContentEtag !== urlInfo.originalContentEtag) {
183
184
  // we should consider calling urlGraph.considerModified(urlInfo)
184
- urlInfo.originalContentEtag = undefined
185
- urlInfo.contentEtag = undefined
186
- return false
185
+ urlInfo.originalContentEtag = undefined;
186
+ urlInfo.contentEtag = undefined;
187
+ return false;
187
188
  }
188
189
  }
189
190
  for (const implicitUrl of urlInfo.implicitUrls) {
190
- const implicitUrlInfo = context.urlGraph.getUrlInfo(implicitUrl)
191
+ const implicitUrlInfo = context.urlGraph.getUrlInfo(implicitUrl);
191
192
  if (implicitUrlInfo && !implicitUrlInfo.isValid()) {
192
- return false
193
+ return false;
193
194
  }
194
195
  }
195
- return true
196
- }
197
- }
196
+ return true;
197
+ };
198
+ };
198
199
  urlGraph.prunedUrlInfosCallbackRef.current = (urlInfos, firstUrlInfo) => {
199
200
  clientFilesPruneCallbackList.forEach((callback) => {
200
- callback(urlInfos, firstUrlInfo)
201
- })
202
- }
201
+ callback(urlInfos, firstUrlInfo);
202
+ });
203
+ };
203
204
  serverStopCallbacks.push(() => {
204
- kitchen.pluginController.callHooks("destroy", kitchen.kitchenContext)
205
- })
205
+ kitchen.pluginController.callHooks("destroy", kitchen.kitchenContext);
206
+ });
206
207
  server_events: {
207
- const allServerEvents = {}
208
+ const allServerEvents = {};
208
209
  kitchen.pluginController.plugins.forEach((plugin) => {
209
- const { serverEvents } = plugin
210
+ const { serverEvents } = plugin;
210
211
  if (serverEvents) {
211
212
  Object.keys(serverEvents).forEach((serverEventName) => {
212
213
  // we could throw on serverEvent name conflict
213
214
  // we could throw if serverEvents[serverEventName] is not a function
214
- allServerEvents[serverEventName] = serverEvents[serverEventName]
215
- })
215
+ allServerEvents[serverEventName] = serverEvents[serverEventName];
216
+ });
216
217
  }
217
- })
218
- const serverEventNames = Object.keys(allServerEvents)
218
+ });
219
+ const serverEventNames = Object.keys(allServerEvents);
219
220
  if (serverEventNames.length > 0) {
220
221
  Object.keys(allServerEvents).forEach((serverEventName) => {
221
222
  allServerEvents[serverEventName]({
@@ -226,14 +227,14 @@ export const createFileService = ({
226
227
  serverEventsDispatcher.dispatch({
227
228
  type: serverEventName,
228
229
  data,
229
- })
230
+ });
230
231
  },
231
- })
232
- })
232
+ });
233
+ });
233
234
  // "pushPlugin" so that event source client connection can be put as early as possible in html
234
235
  kitchen.pluginController.pushPlugin(
235
236
  jsenvPluginServerEventsClientInjection(),
236
- )
237
+ );
237
238
  }
238
239
  }
239
240
 
@@ -244,26 +245,26 @@ export const createFileService = ({
244
245
  runtimeVersion,
245
246
  urlGraph,
246
247
  kitchen,
247
- }
248
- contextCache.set(runtimeId, context)
249
- return context
250
- }
248
+ };
249
+ contextCache.set(runtimeId, context);
250
+ return context;
251
+ };
251
252
 
252
253
  return async (request) => {
253
- const { urlGraph, kitchen } = getOrCreateContext(request)
254
+ const { urlGraph, kitchen } = getOrCreateContext(request);
254
255
  const responseFromPlugin =
255
256
  await kitchen.pluginController.callAsyncHooksUntil(
256
257
  "serve",
257
258
  request,
258
259
  kitchen.kitchenContext,
259
- )
260
+ );
260
261
  if (responseFromPlugin) {
261
- return responseFromPlugin
262
+ return responseFromPlugin;
262
263
  }
263
- let reference
264
- const parentUrl = inferParentFromRequest(request, sourceDirectoryUrl)
264
+ let reference;
265
+ const parentUrl = inferParentFromRequest(request, sourceDirectoryUrl);
265
266
  if (parentUrl) {
266
- reference = urlGraph.inferReference(request.resource, parentUrl)
267
+ reference = urlGraph.inferReference(request.resource, parentUrl);
267
268
  }
268
269
  if (!reference) {
269
270
  const entryPoint = kitchen.injectReference({
@@ -271,17 +272,17 @@ export const createFileService = ({
271
272
  parentUrl: parentUrl || sourceDirectoryUrl,
272
273
  type: "http_request",
273
274
  specifier: request.resource,
274
- })
275
- reference = entryPoint[0]
275
+ });
276
+ reference = entryPoint[0];
276
277
  }
277
- const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url)
278
- const ifNoneMatch = request.headers["if-none-match"]
279
- const urlInfoTargetedByCache = urlGraph.getParentIfInline(urlInfo)
278
+ const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url);
279
+ const ifNoneMatch = request.headers["if-none-match"];
280
+ const urlInfoTargetedByCache = urlGraph.getParentIfInline(urlInfo);
280
281
 
281
282
  try {
282
283
  if (ifNoneMatch) {
283
284
  const [clientOriginalContentEtag, clientContentEtag] =
284
- ifNoneMatch.split("_")
285
+ ifNoneMatch.split("_");
285
286
  if (
286
287
  urlInfoTargetedByCache.originalContentEtag ===
287
288
  clientOriginalContentEtag &&
@@ -290,16 +291,16 @@ export const createFileService = ({
290
291
  ) {
291
292
  const headers = {
292
293
  "cache-control": `private,max-age=0,must-revalidate`,
293
- }
294
+ };
294
295
  Object.keys(urlInfo.headers).forEach((key) => {
295
296
  if (key !== "content-length") {
296
- headers[key] = urlInfo.headers[key]
297
+ headers[key] = urlInfo.headers[key];
297
298
  }
298
- })
299
+ });
299
300
  return {
300
301
  status: 304,
301
302
  headers,
302
- }
303
+ };
303
304
  }
304
305
  }
305
306
 
@@ -309,23 +310,23 @@ export const createFileService = ({
309
310
  !urlInfo.isInline &&
310
311
  urlInfo.type !== "sourcemap"
311
312
  ) {
312
- urlInfo.error = null
313
- urlInfo.sourcemap = null
314
- urlInfo.sourcemapIsWrong = null
315
- urlInfo.sourcemapReference = null
316
- urlInfo.content = null
317
- urlInfo.originalContent = null
318
- urlInfo.type = null
319
- urlInfo.subtype = null
320
- urlInfo.timing = {}
313
+ urlInfo.error = null;
314
+ urlInfo.sourcemap = null;
315
+ urlInfo.sourcemapIsWrong = null;
316
+ urlInfo.sourcemapReference = null;
317
+ urlInfo.content = null;
318
+ urlInfo.originalContent = null;
319
+ urlInfo.type = null;
320
+ urlInfo.subtype = null;
321
+ urlInfo.timing = {};
321
322
  }
322
323
  await kitchen.cook(urlInfo, {
323
324
  request,
324
325
  reference,
325
- })
326
- let { response } = urlInfo
326
+ });
327
+ let { response } = urlInfo;
327
328
  if (response) {
328
- return response
329
+ return response;
329
330
  }
330
331
  response = {
331
332
  url: reference.url,
@@ -350,23 +351,23 @@ export const createFileService = ({
350
351
  },
351
352
  body: urlInfo.content,
352
353
  timing: urlInfo.timing,
353
- }
354
+ };
354
355
  kitchen.pluginController.callHooks(
355
356
  "augmentResponse",
356
357
  { reference, urlInfo },
357
358
  kitchen.kitchenContext,
358
359
  (returnValue) => {
359
- response = composeTwoResponses(response, returnValue)
360
+ response = composeTwoResponses(response, returnValue);
360
361
  },
361
- )
362
- return response
362
+ );
363
+ return response;
363
364
  } catch (e) {
364
- urlInfo.error = e
365
- const originalError = e ? e.cause || e : e
365
+ urlInfo.error = e;
366
+ const originalError = e ? e.cause || e : e;
366
367
  if (originalError.asResponse) {
367
- return originalError.asResponse()
368
+ return originalError.asResponse();
368
369
  }
369
- const code = originalError.code
370
+ const code = originalError.code;
370
371
  if (code === "PARSE_ERROR") {
371
372
  // when possible let browser re-throw the syntax error
372
373
  // it's not possible to do that when url info content is not available
@@ -385,7 +386,7 @@ export const createFileService = ({
385
386
  "cache-control": "no-store",
386
387
  },
387
388
  body: urlInfo.content,
388
- }
389
+ };
389
390
  }
390
391
  return {
391
392
  url: reference.url,
@@ -396,7 +397,7 @@ export const createFileService = ({
396
397
  "cache-control": "no-store",
397
398
  },
398
399
  body: urlInfo.content,
399
- }
400
+ };
400
401
  }
401
402
  if (code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
402
403
  return serveDirectory(reference.url, {
@@ -405,14 +406,14 @@ export const createFileService = ({
405
406
  },
406
407
  canReadDirectory: true,
407
408
  rootDirectoryUrl: sourceDirectoryUrl,
408
- })
409
+ });
409
410
  }
410
411
  if (code === "NOT_ALLOWED") {
411
412
  return {
412
413
  url: reference.url,
413
414
  status: 403,
414
415
  statusText: originalError.reason,
415
- }
416
+ };
416
417
  }
417
418
  if (code === "NOT_FOUND") {
418
419
  return {
@@ -420,28 +421,28 @@ export const createFileService = ({
420
421
  status: 404,
421
422
  statusText: originalError.reason,
422
423
  statusMessage: originalError.message,
423
- }
424
+ };
424
425
  }
425
426
  return {
426
427
  url: reference.url,
427
428
  status: 500,
428
429
  statusText: e.reason,
429
430
  statusMessage: e.stack,
430
- }
431
+ };
431
432
  }
432
- }
433
- }
433
+ };
434
+ };
434
435
 
435
436
  const inferParentFromRequest = (request, sourceDirectoryUrl) => {
436
- const { referer } = request.headers
437
+ const { referer } = request.headers;
437
438
  if (!referer) {
438
- return null
439
+ return null;
439
440
  }
440
- const refererUrlObject = new URL(referer)
441
- refererUrlObject.searchParams.delete("hmr")
442
- refererUrlObject.searchParams.delete("v")
441
+ const refererUrlObject = new URL(referer);
442
+ refererUrlObject.searchParams.delete("hmr");
443
+ refererUrlObject.searchParams.delete("v");
443
444
  return WEB_URL_CONVERTER.asFileUrl(referer, {
444
445
  origin: request.origin,
445
446
  rootDirectoryUrl: sourceDirectoryUrl,
446
- })
447
- }
447
+ });
448
+ };