@jsenv/core 27.5.3 → 27.6.0

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/main.js CHANGED
@@ -152,7 +152,7 @@ const generateInlineContentUrl = ({
152
152
  lineEnd,
153
153
  columnEnd
154
154
  }) => {
155
- const generatedName = line === lineEnd ? `L${line}C${column}-L${lineEnd}C${columnEnd}` : `L${line}-L${lineEnd}`;
155
+ const generatedName = `L${line}C${column}-L${lineEnd}C${columnEnd}`;
156
156
  const filenameRaw = urlToFilename$1(url);
157
157
  const filename = `${filenameRaw}@${generatedName}${extension}`; // ideally we should keep query params from url
158
158
  // maybe we could use a custom scheme like "inline:"
@@ -12047,27 +12047,6 @@ const jsenvPluginHtmlSupervisor = ({
12047
12047
  test: true
12048
12048
  },
12049
12049
  serve: (request, context) => {
12050
- if (request.ressource.startsWith("/__open_in_editor__/")) {
12051
- const file = request.ressource.slice("/__open_in_editor__/".length);
12052
-
12053
- if (!file) {
12054
- return {
12055
- status: 400,
12056
- body: "Missing file in url"
12057
- };
12058
- }
12059
-
12060
- const launch = requireFromJsenv("launch-editor");
12061
- launch(fileURLToPath(file), () => {// ignore error for now
12062
- });
12063
- return {
12064
- status: 200,
12065
- headers: {
12066
- "cache-control": "no-store"
12067
- }
12068
- };
12069
- }
12070
-
12071
12050
  if (request.ressource.startsWith("/__get_code_frame__/")) {
12072
12051
  const url = request.ressource.slice("/__get_code_frame__/".length);
12073
12052
  const match = url.match(/:([0-9]+):([0-9]+)$/);
@@ -12106,6 +12085,87 @@ const jsenvPluginHtmlSupervisor = ({
12106
12085
  };
12107
12086
  }
12108
12087
 
12088
+ if (request.ressource.startsWith("/__get_error_cause__/")) {
12089
+ const file = request.ressource.slice("/__get_error_cause__/".length);
12090
+
12091
+ if (!file) {
12092
+ return {
12093
+ status: 400,
12094
+ body: "Missing file in url"
12095
+ };
12096
+ }
12097
+
12098
+ const getErrorCauseInfo = () => {
12099
+ const urlInfo = context.urlGraph.getUrlInfo(file);
12100
+
12101
+ if (!urlInfo) {
12102
+ return null;
12103
+ }
12104
+
12105
+ const {
12106
+ error
12107
+ } = urlInfo;
12108
+
12109
+ if (error) {
12110
+ return error;
12111
+ } // search in direct dependencies (404 or 500)
12112
+
12113
+
12114
+ const {
12115
+ dependencies
12116
+ } = urlInfo;
12117
+
12118
+ for (const dependencyUrl of dependencies) {
12119
+ const dependencyUrlInfo = context.urlGraph.getUrlInfo(dependencyUrl);
12120
+
12121
+ if (dependencyUrlInfo.error) {
12122
+ return dependencyUrlInfo.error;
12123
+ }
12124
+ }
12125
+
12126
+ return null;
12127
+ };
12128
+
12129
+ const causeInfo = getErrorCauseInfo();
12130
+ const body = JSON.stringify(causeInfo ? {
12131
+ code: causeInfo.code,
12132
+ message: causeInfo.message,
12133
+ reason: causeInfo.reason,
12134
+ stack: causeInfo.stack,
12135
+ codeFrame: causeInfo.traceMessage
12136
+ } : null, null, " ");
12137
+ return {
12138
+ status: 200,
12139
+ headers: {
12140
+ "cache-control": "no-cache",
12141
+ "content-type": "application/json",
12142
+ "content-length": Buffer.byteLength(body)
12143
+ },
12144
+ body
12145
+ };
12146
+ }
12147
+
12148
+ if (request.ressource.startsWith("/__open_in_editor__/")) {
12149
+ const file = request.ressource.slice("/__open_in_editor__/".length);
12150
+
12151
+ if (!file) {
12152
+ return {
12153
+ status: 400,
12154
+ body: "Missing file in url"
12155
+ };
12156
+ }
12157
+
12158
+ const launch = requireFromJsenv("launch-editor");
12159
+ launch(fileURLToPath(file), () => {// ignore error for now
12160
+ });
12161
+ return {
12162
+ status: 200,
12163
+ headers: {
12164
+ "cache-control": "no-store"
12165
+ }
12166
+ };
12167
+ }
12168
+
12109
12169
  return null;
12110
12170
  },
12111
12171
  transformUrlContent: {
@@ -21030,6 +21090,7 @@ const createUrlGraph = ({
21030
21090
 
21031
21091
  const createUrlInfo = url => {
21032
21092
  return {
21093
+ error: null,
21033
21094
  modifiedTimestamp: 0,
21034
21095
  contentEtag: null,
21035
21096
  dependsOnPackageJson: false,
@@ -21435,12 +21496,30 @@ const returnValueAssertions = [{
21435
21496
  const createUrlInfoTransformer = ({
21436
21497
  logger,
21437
21498
  sourcemaps,
21499
+ sourcemapsSourcesProtocol,
21438
21500
  sourcemapsSourcesContent,
21439
21501
  sourcemapsRelativeSources,
21440
21502
  urlGraph,
21503
+ clientRuntimeCompat,
21441
21504
  injectSourcemapPlaceholder,
21442
21505
  foundSourcemap
21443
21506
  }) => {
21507
+ const runtimeNames = Object.keys(clientRuntimeCompat);
21508
+ const chromeAsSingleRuntime = runtimeNames.length === 1 && runtimeNames[0] === "chrome";
21509
+
21510
+ if (sourcemapsSourcesProtocol === undefined) {
21511
+ sourcemapsSourcesProtocol = "file:///";
21512
+ }
21513
+
21514
+ if (sourcemapsSourcesContent === undefined) {
21515
+ if (chromeAsSingleRuntime && sourcemapsSourcesProtocol === "file:///") {
21516
+ // chrome is able to fetch source when referenced with "file:"
21517
+ sourcemapsSourcesContent = false;
21518
+ } else {
21519
+ sourcemapsSourcesContent = true;
21520
+ }
21521
+ }
21522
+
21444
21523
  const sourcemapsEnabled = sourcemaps === "inline" || sourcemaps === "file" || sourcemaps === "programmatic";
21445
21524
 
21446
21525
  const normalizeSourcemap = (urlInfo, sourcemap) => {
@@ -21614,6 +21693,16 @@ const createUrlInfoTransformer = ({
21614
21693
  });
21615
21694
  }
21616
21695
 
21696
+ if (sourcemapsSourcesProtocol !== "file:///") {
21697
+ sourcemap.sources = sourcemap.sources.map(source => {
21698
+ if (source.startsWith("file:///")) {
21699
+ return `${sourcemapsSourcesProtocol}${source.slice("file:///".length)}`;
21700
+ }
21701
+
21702
+ return source;
21703
+ });
21704
+ }
21705
+
21617
21706
  sourcemapUrlInfo.content = JSON.stringify(sourcemap, null, " ");
21618
21707
 
21619
21708
  if (!urlInfo.sourcemapIsWrong) {
@@ -22013,6 +22102,9 @@ const createKitchen = ({
22013
22102
  rootDirectoryUrl,
22014
22103
  scenario,
22015
22104
  runtimeCompat,
22105
+ // during dev/test clientRuntimeCompat is a single runtime
22106
+ // during build clientRuntimeCompat is runtimeCompat
22107
+ clientRuntimeCompat = runtimeCompat,
22016
22108
  urlGraph,
22017
22109
  plugins,
22018
22110
  sourcemaps = {
@@ -22021,13 +22113,8 @@ const createKitchen = ({
22021
22113
  test: "inline",
22022
22114
  build: "none"
22023
22115
  }[scenario],
22024
- sourcemapsSourcesContent = {
22025
- // during dev/test, chrome is able to find the sourcemap sources
22026
- // as long as they use file:// protocol in the sourcemap files
22027
- dev: false,
22028
- test: false,
22029
- build: true
22030
- }[scenario],
22116
+ sourcemapsSourcesProtocol,
22117
+ sourcemapsSourcesContent,
22031
22118
  sourcemapsRelativeSources,
22032
22119
  writeGeneratedFiles
22033
22120
  }) => {
@@ -22046,6 +22133,10 @@ const createKitchen = ({
22046
22133
  urlGraph,
22047
22134
  scenario,
22048
22135
  runtimeCompat,
22136
+ clientRuntimeCompat,
22137
+ isSupportedOnCurrentClients: feature => {
22138
+ return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature);
22139
+ },
22049
22140
  isSupportedOnFutureClients: feature => {
22050
22141
  return RUNTIME_COMPAT.isSupported(runtimeCompat, feature);
22051
22142
  },
@@ -22194,8 +22285,10 @@ const createKitchen = ({
22194
22285
  logger,
22195
22286
  urlGraph,
22196
22287
  sourcemaps,
22288
+ sourcemapsSourcesProtocol,
22197
22289
  sourcemapsSourcesContent,
22198
22290
  sourcemapsRelativeSources,
22291
+ clientRuntimeCompat,
22199
22292
  injectSourcemapPlaceholder: ({
22200
22293
  urlInfo,
22201
22294
  specifier
@@ -22334,19 +22427,8 @@ const createKitchen = ({
22334
22427
  };
22335
22428
 
22336
22429
  const _cook = async (urlInfo, dishContext) => {
22337
- // during dev/test clientRuntimeCompat is a single runtime
22338
- // during build clientRuntimeCompat is runtimeCompat
22339
- const {
22340
- clientRuntimeCompat = runtimeCompat
22341
- } = dishContext;
22342
-
22343
- kitchenContext.isSupportedOnCurrentClients = feature => {
22344
- return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature);
22345
- };
22346
-
22347
22430
  const context = { ...kitchenContext,
22348
- ...dishContext,
22349
- clientRuntimeCompat
22431
+ ...dishContext
22350
22432
  };
22351
22433
  const {
22352
22434
  cookDuringCook = cook
@@ -22754,7 +22836,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
22754
22836
  column: reference.specifierColumn
22755
22837
  };
22756
22838
  urlInfo.contentType = reference.contentType;
22757
- urlInfo.originalContent = context === "build" ? urlInfo.originalContent === undefined ? reference.content : urlInfo.originalContent : reference.content;
22839
+ urlInfo.originalContent = context.scenario === "build" ? urlInfo.originalContent === undefined ? reference.content : urlInfo.originalContent : reference.content;
22758
22840
  urlInfo.content = reference.content;
22759
22841
  }
22760
22842
  };
@@ -23117,17 +23199,11 @@ const createFileService = ({
23117
23199
  cooldownBetweenFileEvents,
23118
23200
  explorer,
23119
23201
  sourcemaps,
23202
+ sourcemapsSourcesProtocol,
23203
+ sourcemapsSourcesContent,
23120
23204
  writeGeneratedFiles
23121
23205
  }) => {
23122
23206
  const jsenvDirectoryUrl = new URL(".jsenv/", rootDirectoryUrl).href;
23123
- const onErrorWhileServingFileCallbacks = [];
23124
-
23125
- const onErrorWhileServingFile = data => {
23126
- onErrorWhileServingFileCallbacks.forEach(onErrorWhileServingFileCallback => {
23127
- onErrorWhileServingFileCallback(data);
23128
- });
23129
- };
23130
-
23131
23207
  const clientFileChangeCallbackList = [];
23132
23208
  const clientFilesPruneCallbackList = [];
23133
23209
 
@@ -23220,6 +23296,9 @@ const createFileService = ({
23220
23296
  rootDirectoryUrl,
23221
23297
  scenario,
23222
23298
  runtimeCompat,
23299
+ clientRuntimeCompat: {
23300
+ [runtimeName]: runtimeVersion
23301
+ },
23223
23302
  urlGraph,
23224
23303
  plugins: [...plugins, ...getCorePlugins({
23225
23304
  rootDirectoryUrl,
@@ -23236,6 +23315,8 @@ const createFileService = ({
23236
23315
  explorer
23237
23316
  })],
23238
23317
  sourcemaps,
23318
+ sourcemapsSourcesProtocol,
23319
+ sourcemapsSourcesContent,
23239
23320
  writeGeneratedFiles
23240
23321
  });
23241
23322
  serverStopCallbacks.push(() => {
@@ -23276,20 +23357,6 @@ const createFileService = ({
23276
23357
  });
23277
23358
  }
23278
23359
  });
23279
- });
23280
- onErrorWhileServingFileCallbacks.push(data => {
23281
- serverEventsDispatcher.dispatchToRoomsMatching({
23282
- type: "error_while_serving_file",
23283
- data
23284
- }, room => {
23285
- // send only to page depending on this file
23286
- const errorFileUrl = data.url;
23287
- const roomEntryPointUrl = new URL(room.request.ressource.slice(1), rootDirectoryUrl).href;
23288
- const isErrorRelatedToEntryPoint = Boolean(urlGraph.findDependent(errorFileUrl, dependentUrlInfo => {
23289
- return dependentUrlInfo.url === roomEntryPointUrl;
23290
- }));
23291
- return isErrorRelatedToEntryPoint;
23292
- });
23293
23360
  }); // "unshift" because serve must come first to catch event source client request
23294
23361
 
23295
23362
  kitchen.pluginController.unshiftPlugin({
@@ -23387,6 +23454,7 @@ const createFileService = ({
23387
23454
  try {
23388
23455
  // urlInfo objects are reused, they must be "reset" before cooking them again
23389
23456
  if (urlInfo.contentEtag && !urlInfo.isInline && urlInfo.type !== "sourcemap") {
23457
+ urlInfo.error = null;
23390
23458
  urlInfo.sourcemap = null;
23391
23459
  urlInfo.sourcemapReference = null;
23392
23460
  urlInfo.content = null;
@@ -23400,9 +23468,6 @@ const createFileService = ({
23400
23468
  await kitchen.cook(urlInfo, {
23401
23469
  request,
23402
23470
  reference,
23403
- clientRuntimeCompat: {
23404
- [runtimeName]: runtimeVersion
23405
- },
23406
23471
  outDirectoryUrl: scenario === "dev" ? `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/` : `${rootDirectoryUrl}.jsenv/${scenario}/${runtimeName}@${runtimeVersion}/`
23407
23472
  });
23408
23473
  let {
@@ -23434,19 +23499,10 @@ const createFileService = ({
23434
23499
  });
23435
23500
  return response;
23436
23501
  } catch (e) {
23502
+ urlInfo.error = e;
23437
23503
  const code = e.code;
23438
23504
 
23439
23505
  if (code === "PARSE_ERROR") {
23440
- onErrorWhileServingFile({
23441
- requestedRessource: request.ressource,
23442
- code: "PARSE_ERROR",
23443
- message: e.reason,
23444
- url: e.url,
23445
- traceUrl: e.traceUrl,
23446
- traceLine: e.traceLine,
23447
- traceColumn: e.traceColumn,
23448
- traceMessage: e.traceMessage
23449
- });
23450
23506
  return {
23451
23507
  url: reference.url,
23452
23508
  status: 200,
@@ -23481,17 +23537,6 @@ const createFileService = ({
23481
23537
  }
23482
23538
 
23483
23539
  if (code === "NOT_FOUND") {
23484
- onErrorWhileServingFile({
23485
- requestedRessource: request.ressource,
23486
- isFaviconAutoRequest: request.ressource === "/favicon.ico" && reference.type === "http_request",
23487
- code: "NOT_FOUND",
23488
- message: e.reason,
23489
- url: e.url,
23490
- traceUrl: e.traceUrl,
23491
- traceLine: e.traceLine,
23492
- traceColumn: e.traceColumn,
23493
- traceMessage: e.traceMessage
23494
- });
23495
23540
  return {
23496
23541
  url: reference.url,
23497
23542
  status: 404,
@@ -23500,16 +23545,6 @@ const createFileService = ({
23500
23545
  };
23501
23546
  }
23502
23547
 
23503
- onErrorWhileServingFile({
23504
- requestedRessource: request.ressource,
23505
- code: "UNEXPECTED",
23506
- stack: e.stack,
23507
- url: e.url,
23508
- traceUrl: e.traceUrl,
23509
- traceLine: e.traceLine,
23510
- traceColumn: e.traceColumn,
23511
- traceMessage: e.traceMessage
23512
- });
23513
23548
  return {
23514
23549
  url: reference.url,
23515
23550
  status: 500,
@@ -23578,6 +23613,8 @@ const startOmegaServer = async ({
23578
23613
  cooldownBetweenFileEvents,
23579
23614
  explorer,
23580
23615
  sourcemaps,
23616
+ sourcemapsSourcesProtocol,
23617
+ sourcemapsSourcesContent,
23581
23618
  writeGeneratedFiles
23582
23619
  }) => {
23583
23620
  const serverStopCallbacks = [];
@@ -23624,6 +23661,8 @@ const startOmegaServer = async ({
23624
23661
  cooldownBetweenFileEvents,
23625
23662
  explorer,
23626
23663
  sourcemaps,
23664
+ sourcemapsSourcesProtocol,
23665
+ sourcemapsSourcesContent,
23627
23666
  writeGeneratedFiles
23628
23667
  })
23629
23668
  }, {
@@ -23736,6 +23775,8 @@ const startDevServer = async ({
23736
23775
  },
23737
23776
  // toolbar = false,
23738
23777
  sourcemaps = "inline",
23778
+ sourcemapsSourcesProtocol,
23779
+ sourcemapsSourcesContent,
23739
23780
  writeGeneratedFiles = true
23740
23781
  }) => {
23741
23782
  const logger = createLogger({
@@ -23851,6 +23892,8 @@ const startDevServer = async ({
23851
23892
  cooldownBetweenFileEvents,
23852
23893
  explorer,
23853
23894
  sourcemaps,
23895
+ sourcemapsSourcesProtocol,
23896
+ sourcemapsSourcesContent,
23854
23897
  writeGeneratedFiles
23855
23898
  });
23856
23899
  startDevServerTask.done();
@@ -27466,8 +27509,7 @@ const loadUrlGraph = async ({
27466
27509
  kitchen,
27467
27510
  startLoading,
27468
27511
  writeGeneratedFiles,
27469
- outDirectoryUrl,
27470
- clientRuntimeCompat
27512
+ outDirectoryUrl
27471
27513
  }) => {
27472
27514
  if (writeGeneratedFiles && outDirectoryUrl) {
27473
27515
  await ensureEmptyDirectory(outDirectoryUrl);
@@ -27482,7 +27524,6 @@ const loadUrlGraph = async ({
27482
27524
 
27483
27525
  const promise = _cook(urlInfo, {
27484
27526
  outDirectoryUrl,
27485
- clientRuntimeCompat,
27486
27527
  ...context
27487
27528
  });
27488
27529
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "27.5.3",
3
+ "version": "27.6.0",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -74,7 +74,7 @@
74
74
  "@jsenv/log": "3.1.0",
75
75
  "@jsenv/node-esm-resolution": "0.1.0",
76
76
  "@jsenv/server": "13.0.0",
77
- "@jsenv/sourcemap": "1.0.2",
77
+ "@jsenv/sourcemap": "1.0.3",
78
78
  "@jsenv/uneval": "1.6.0",
79
79
  "@jsenv/url-meta": "7.0.0",
80
80
  "@jsenv/urls": "1.2.7",
@@ -70,6 +70,8 @@ export const startDevServer = async ({
70
70
  // toolbar = false,
71
71
 
72
72
  sourcemaps = "inline",
73
+ sourcemapsSourcesProtocol,
74
+ sourcemapsSourcesContent,
73
75
  writeGeneratedFiles = true,
74
76
  }) => {
75
77
  const logger = createLogger({ logLevel })
@@ -171,6 +173,8 @@ export const startDevServer = async ({
171
173
  cooldownBetweenFileEvents,
172
174
  explorer,
173
175
  sourcemaps,
176
+ sourcemapsSourcesProtocol,
177
+ sourcemapsSourcesContent,
174
178
  writeGeneratedFiles,
175
179
  })
176
180
  startDevServerTask.done()
@@ -30,6 +30,9 @@ export const createKitchen = ({
30
30
  rootDirectoryUrl,
31
31
  scenario,
32
32
  runtimeCompat,
33
+ // during dev/test clientRuntimeCompat is a single runtime
34
+ // during build clientRuntimeCompat is runtimeCompat
35
+ clientRuntimeCompat = runtimeCompat,
33
36
  urlGraph,
34
37
  plugins,
35
38
  sourcemaps = {
@@ -37,13 +40,8 @@ export const createKitchen = ({
37
40
  test: "inline",
38
41
  build: "none",
39
42
  }[scenario],
40
- sourcemapsSourcesContent = {
41
- // during dev/test, chrome is able to find the sourcemap sources
42
- // as long as they use file:// protocol in the sourcemap files
43
- dev: false,
44
- test: false,
45
- build: true,
46
- }[scenario],
43
+ sourcemapsSourcesProtocol,
44
+ sourcemapsSourcesContent,
47
45
  sourcemapsRelativeSources,
48
46
  writeGeneratedFiles,
49
47
  }) => {
@@ -60,6 +58,10 @@ export const createKitchen = ({
60
58
  urlGraph,
61
59
  scenario,
62
60
  runtimeCompat,
61
+ clientRuntimeCompat,
62
+ isSupportedOnCurrentClients: (feature) => {
63
+ return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
64
+ },
63
65
  isSupportedOnFutureClients: (feature) => {
64
66
  return RUNTIME_COMPAT.isSupported(runtimeCompat, feature)
65
67
  },
@@ -214,12 +216,15 @@ export const createKitchen = ({
214
216
  }
215
217
  }
216
218
  kitchenContext.resolveReference = resolveReference
219
+
217
220
  const urlInfoTransformer = createUrlInfoTransformer({
218
221
  logger,
219
222
  urlGraph,
220
223
  sourcemaps,
224
+ sourcemapsSourcesProtocol,
221
225
  sourcemapsSourcesContent,
222
226
  sourcemapsRelativeSources,
227
+ clientRuntimeCompat,
223
228
  injectSourcemapPlaceholder: ({ urlInfo, specifier }) => {
224
229
  const sourcemapReference = createReference({
225
230
  trace: {
@@ -356,16 +361,9 @@ export const createKitchen = ({
356
361
  }
357
362
 
358
363
  const _cook = async (urlInfo, dishContext) => {
359
- // during dev/test clientRuntimeCompat is a single runtime
360
- // during build clientRuntimeCompat is runtimeCompat
361
- const { clientRuntimeCompat = runtimeCompat } = dishContext
362
- kitchenContext.isSupportedOnCurrentClients = (feature) => {
363
- return RUNTIME_COMPAT.isSupported(clientRuntimeCompat, feature)
364
- }
365
364
  const context = {
366
365
  ...kitchenContext,
367
366
  ...dishContext,
368
- clientRuntimeCompat,
369
367
  }
370
368
  const { cookDuringCook = cook } = dishContext
371
369
  context.cook = (urlInfo, nestedDishContext) => {
@@ -772,7 +770,7 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
772
770
  }
773
771
  urlInfo.contentType = reference.contentType
774
772
  urlInfo.originalContent =
775
- context === "build"
773
+ context.scenario === "build"
776
774
  ? urlInfo.originalContent === undefined
777
775
  ? reference.content
778
776
  : urlInfo.originalContent
@@ -38,6 +38,8 @@ export const startOmegaServer = async ({
38
38
  cooldownBetweenFileEvents,
39
39
  explorer,
40
40
  sourcemaps,
41
+ sourcemapsSourcesProtocol,
42
+ sourcemapsSourcesContent,
41
43
  writeGeneratedFiles,
42
44
  }) => {
43
45
  const serverStopCallbacks = []
@@ -93,6 +95,8 @@ export const startOmegaServer = async ({
93
95
  cooldownBetweenFileEvents,
94
96
  explorer,
95
97
  sourcemaps,
98
+ sourcemapsSourcesProtocol,
99
+ sourcemapsSourcesContent,
96
100
  writeGeneratedFiles,
97
101
  }),
98
102
  },
@@ -34,17 +34,11 @@ export const createFileService = ({
34
34
  cooldownBetweenFileEvents,
35
35
  explorer,
36
36
  sourcemaps,
37
+ sourcemapsSourcesProtocol,
38
+ sourcemapsSourcesContent,
37
39
  writeGeneratedFiles,
38
40
  }) => {
39
41
  const jsenvDirectoryUrl = new URL(".jsenv/", rootDirectoryUrl).href
40
- const onErrorWhileServingFileCallbacks = []
41
- const onErrorWhileServingFile = (data) => {
42
- onErrorWhileServingFileCallbacks.forEach(
43
- (onErrorWhileServingFileCallback) => {
44
- onErrorWhileServingFileCallback(data)
45
- },
46
- )
47
- }
48
42
 
49
43
  const clientFileChangeCallbackList = []
50
44
  const clientFilesPruneCallbackList = []
@@ -113,6 +107,9 @@ export const createFileService = ({
113
107
  rootDirectoryUrl,
114
108
  scenario,
115
109
  runtimeCompat,
110
+ clientRuntimeCompat: {
111
+ [runtimeName]: runtimeVersion,
112
+ },
116
113
  urlGraph,
117
114
  plugins: [
118
115
  ...plugins,
@@ -134,6 +131,8 @@ export const createFileService = ({
134
131
  }),
135
132
  ],
136
133
  sourcemaps,
134
+ sourcemapsSourcesProtocol,
135
+ sourcemapsSourcesContent,
137
136
  writeGeneratedFiles,
138
137
  })
139
138
  serverStopCallbacks.push(() => {
@@ -170,28 +169,6 @@ export const createFileService = ({
170
169
  },
171
170
  })
172
171
  })
173
- onErrorWhileServingFileCallbacks.push((data) => {
174
- serverEventsDispatcher.dispatchToRoomsMatching(
175
- {
176
- type: "error_while_serving_file",
177
- data,
178
- },
179
- (room) => {
180
- // send only to page depending on this file
181
- const errorFileUrl = data.url
182
- const roomEntryPointUrl = new URL(
183
- room.request.ressource.slice(1),
184
- rootDirectoryUrl,
185
- ).href
186
- const isErrorRelatedToEntryPoint = Boolean(
187
- urlGraph.findDependent(errorFileUrl, (dependentUrlInfo) => {
188
- return dependentUrlInfo.url === roomEntryPointUrl
189
- }),
190
- )
191
- return isErrorRelatedToEntryPoint
192
- },
193
- )
194
- })
195
172
  // "unshift" because serve must come first to catch event source client request
196
173
  kitchen.pluginController.unshiftPlugin({
197
174
  name: "jsenv:provide_server_events",
@@ -286,6 +263,7 @@ export const createFileService = ({
286
263
  !urlInfo.isInline &&
287
264
  urlInfo.type !== "sourcemap"
288
265
  ) {
266
+ urlInfo.error = null
289
267
  urlInfo.sourcemap = null
290
268
  urlInfo.sourcemapReference = null
291
269
  urlInfo.content = null
@@ -298,9 +276,6 @@ export const createFileService = ({
298
276
  await kitchen.cook(urlInfo, {
299
277
  request,
300
278
  reference,
301
- clientRuntimeCompat: {
302
- [runtimeName]: runtimeVersion,
303
- },
304
279
  outDirectoryUrl:
305
280
  scenario === "dev"
306
281
  ? `${rootDirectoryUrl}.jsenv/${runtimeName}@${runtimeVersion}/`
@@ -333,18 +308,9 @@ export const createFileService = ({
333
308
  )
334
309
  return response
335
310
  } catch (e) {
311
+ urlInfo.error = e
336
312
  const code = e.code
337
313
  if (code === "PARSE_ERROR") {
338
- onErrorWhileServingFile({
339
- requestedRessource: request.ressource,
340
- code: "PARSE_ERROR",
341
- message: e.reason,
342
- url: e.url,
343
- traceUrl: e.traceUrl,
344
- traceLine: e.traceLine,
345
- traceColumn: e.traceColumn,
346
- traceMessage: e.traceMessage,
347
- })
348
314
  return {
349
315
  url: reference.url,
350
316
  status: 200, // let the browser re-throw the syntax error
@@ -375,19 +341,6 @@ export const createFileService = ({
375
341
  }
376
342
  }
377
343
  if (code === "NOT_FOUND") {
378
- onErrorWhileServingFile({
379
- requestedRessource: request.ressource,
380
- isFaviconAutoRequest:
381
- request.ressource === "/favicon.ico" &&
382
- reference.type === "http_request",
383
- code: "NOT_FOUND",
384
- message: e.reason,
385
- url: e.url,
386
- traceUrl: e.traceUrl,
387
- traceLine: e.traceLine,
388
- traceColumn: e.traceColumn,
389
- traceMessage: e.traceMessage,
390
- })
391
344
  return {
392
345
  url: reference.url,
393
346
  status: 404,
@@ -395,16 +348,6 @@ export const createFileService = ({
395
348
  statusMessage: e.message,
396
349
  }
397
350
  }
398
- onErrorWhileServingFile({
399
- requestedRessource: request.ressource,
400
- code: "UNEXPECTED",
401
- stack: e.stack,
402
- url: e.url,
403
- traceUrl: e.traceUrl,
404
- traceLine: e.traceLine,
405
- traceColumn: e.traceColumn,
406
- traceMessage: e.traceMessage,
407
- })
408
351
  return {
409
352
  url: reference.url,
410
353
  status: 500,