@jsenv/core 40.6.0 → 40.6.1

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.
@@ -1144,7 +1144,7 @@ const prepareEntryPointBuild = async (
1144
1144
  // - no plugin putting reference.mustIgnore on https urls
1145
1145
  // At this stage it's only about redirecting urls to the build directory
1146
1146
  // consequently only a subset or urls are supported
1147
- supportedProtocols: ["file:", "data:", "virtual:", "ignore:"],
1147
+ includedProtocols: ["file:", "data:", "virtual:", "ignore:"],
1148
1148
  ignore,
1149
1149
  ignoreProtocol: "remove",
1150
1150
  build: true,
@@ -4,7 +4,7 @@ import {
4
4
  lookupPackageDirectory,
5
5
  readPackageAtOrNull,
6
6
  } from "@jsenv/filesystem";
7
- import { createLogger, createTaskLog } from "@jsenv/humanize";
7
+ import { createLogger, createTaskLog, formatError } from "@jsenv/humanize";
8
8
  import {
9
9
  composeTwoResponses,
10
10
  jsenvAccessControlAllowedHeaders,
@@ -605,7 +605,7 @@ export const startDevServer = async ({
605
605
  url: reference.url,
606
606
  status: 500,
607
607
  statusText: error.reason,
608
- statusMessage: error.stack,
608
+ statusMessage: formatError(error),
609
609
  headers: {
610
610
  "cache-control": "no-store",
611
611
  },
@@ -53,6 +53,12 @@ ${reason}`,
53
53
  });
54
54
  return error;
55
55
  }
56
+ if (error.code === "PROTOCOL_NOT_SUPPORTED") {
57
+ const notSupportedError = createFailedToResolveUrlError({
58
+ reason: error.message,
59
+ });
60
+ return notSupportedError;
61
+ }
56
62
  return createFailedToResolveUrlError({
57
63
  reason: `An error occured during specifier resolution`,
58
64
  ...detailsFromValueThrown(error),
@@ -93,7 +99,6 @@ ${reason}`,
93
99
  });
94
100
  return fetchError;
95
101
  };
96
-
97
102
  if (error.code === "EPERM") {
98
103
  return createFailedToFetchUrlContentError({
99
104
  code: "NOT_ALLOWED",
@@ -140,6 +145,9 @@ export const createTransformUrlContentError = ({
140
145
  if (error.code === "MODULE_NOT_FOUND") {
141
146
  return error;
142
147
  }
148
+ if (error.code === "PROTOCOL_NOT_SUPPORTED") {
149
+ return error;
150
+ }
143
151
  if (error.code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
144
152
  return error;
145
153
  }
@@ -147,47 +155,8 @@ export const createTransformUrlContentError = ({
147
155
  if (error.isJsenvCookingError) {
148
156
  return error;
149
157
  }
158
+ const trace = getErrorTrace(error, urlInfo.firstReference);
150
159
  const reference = urlInfo.firstReference;
151
- let trace = reference.trace;
152
- let line = error.line;
153
- let column = error.column;
154
- if (urlInfo.isInline) {
155
- line = trace.line + line;
156
- line = line - 1;
157
- trace = {
158
- ...trace,
159
- line,
160
- column,
161
- codeFrame: generateContentFrame({
162
- line,
163
- column,
164
- content: urlInfo.inlineUrlSite.content,
165
- }),
166
- message: stringifyUrlSite({
167
- url: urlInfo.inlineUrlSite.url,
168
- line,
169
- column,
170
- content: urlInfo.inlineUrlSite.content,
171
- }),
172
- };
173
- } else {
174
- trace = {
175
- url: urlInfo.url,
176
- line,
177
- column: error.column,
178
- codeFrame: generateContentFrame({
179
- line,
180
- column: error.column,
181
- content: urlInfo.content,
182
- }),
183
- message: stringifyUrlSite({
184
- url: urlInfo.url,
185
- line,
186
- column: error.column,
187
- content: urlInfo.content,
188
- }),
189
- };
190
- }
191
160
  const transformError = new Error(
192
161
  createDetailedMessage(
193
162
  `parse error on "${urlInfo.type}"
@@ -278,9 +247,55 @@ ${reference.trace.message}`,
278
247
  return finalizeError;
279
248
  };
280
249
 
250
+ const getErrorTrace = (error, reference) => {
251
+ const urlInfo = reference.urlInfo;
252
+ let trace = reference.trace;
253
+ let line = error.line;
254
+ let column = error.column;
255
+ if (urlInfo.isInline) {
256
+ line = trace.line + line;
257
+ line = line - 1;
258
+ return {
259
+ ...trace,
260
+ line,
261
+ column,
262
+ codeFrame: generateContentFrame({
263
+ line,
264
+ column,
265
+ content: urlInfo.inlineUrlSite.content,
266
+ }),
267
+ message: stringifyUrlSite({
268
+ url: urlInfo.inlineUrlSite.url,
269
+ line,
270
+ column,
271
+ content: urlInfo.inlineUrlSite.content,
272
+ }),
273
+ };
274
+ }
275
+ return {
276
+ url: urlInfo.url,
277
+ line,
278
+ column: error.column,
279
+ codeFrame: generateContentFrame({
280
+ line,
281
+ column: error.column,
282
+ content: urlInfo.content,
283
+ }),
284
+ message: stringifyUrlSite({
285
+ url: urlInfo.url,
286
+ line,
287
+ column: error.column,
288
+ content: urlInfo.content,
289
+ }),
290
+ };
291
+ };
292
+
281
293
  const detailsFromFirstReference = (reference) => {
282
294
  const referenceInProject = getFirstReferenceInProject(reference);
283
- if (referenceInProject === reference) {
295
+ if (
296
+ referenceInProject === reference ||
297
+ referenceInProject.type === "http_request"
298
+ ) {
284
299
  return {};
285
300
  }
286
301
  return {
@@ -289,6 +304,9 @@ const detailsFromFirstReference = (reference) => {
289
304
  };
290
305
  const getFirstReferenceInProject = (reference) => {
291
306
  const ownerUrlInfo = reference.ownerUrlInfo;
307
+ if (ownerUrlInfo.isRoot) {
308
+ return reference;
309
+ }
292
310
  if (
293
311
  !ownerUrlInfo.url.includes("/node_modules/") &&
294
312
  ownerUrlInfo.packageDirectoryUrl ===
@@ -296,7 +314,8 @@ const getFirstReferenceInProject = (reference) => {
296
314
  ) {
297
315
  return reference;
298
316
  }
299
- return getFirstReferenceInProject(ownerUrlInfo.firstReference);
317
+ const { firstReference } = ownerUrlInfo;
318
+ return getFirstReferenceInProject(firstReference);
300
319
  };
301
320
 
302
321
  const detailsFromPluginController = (pluginController) => {
@@ -37,7 +37,28 @@ export const createKitchen = ({
37
37
 
38
38
  ignore,
39
39
  ignoreProtocol = "remove",
40
- supportedProtocols = ["file:", "data:", "virtual:", "http:", "https:"],
40
+ supportedProtocols = [
41
+ "file:",
42
+ "data:",
43
+ // eslint-disable-next-line no-script-url
44
+ "javascript:",
45
+ "virtual:",
46
+ "ignore:",
47
+ "http:",
48
+ "https:",
49
+ "chrome:",
50
+ "chrome-extension:",
51
+ "chrome-untrusted:",
52
+ "isolated-app:",
53
+ ],
54
+ includedProtocols = [
55
+ "file:",
56
+ "data:",
57
+ "virtual:",
58
+ "ignore:",
59
+ "http:",
60
+ "https:",
61
+ ],
41
62
 
42
63
  // during dev/test clientRuntimeCompat is a single runtime
43
64
  // during build clientRuntimeCompat is runtimeCompat
@@ -57,6 +78,9 @@ export const createKitchen = ({
57
78
 
58
79
  const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
59
80
  const packageConditions = [nodeRuntimeEnabled ? "node" : "browser", "import"];
81
+ if (nodeRuntimeEnabled) {
82
+ supportedProtocols.push("node:");
83
+ }
60
84
 
61
85
  if (packageDependencies === "auto") {
62
86
  packageDependencies = build && nodeRuntimeEnabled ? "ignore" : "include";
@@ -128,8 +152,11 @@ export const createKitchen = ({
128
152
 
129
153
  const isIgnoredByProtocol = (url) => {
130
154
  const { protocol } = new URL(url);
131
- const protocolIsSupported = supportedProtocols.includes(protocol);
132
- return !protocolIsSupported;
155
+ const protocolIsIncluded = includedProtocols.includes(protocol);
156
+ if (protocolIsIncluded) {
157
+ return false;
158
+ }
159
+ return true;
133
160
  };
134
161
  const isIgnoredBecauseInPackageDependencies = (() => {
135
162
  if (packageDependencies === undefined) {
@@ -336,6 +363,21 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
336
363
  }
337
364
  reference.generatedUrl = reference.url;
338
365
  reference.generatedSearchParams = reference.searchParams;
366
+ if (dev) {
367
+ let url = reference.url;
368
+ let { protocol } = new URL(url);
369
+ if (protocol === "ignore:") {
370
+ url = url.slice("ignore:".length);
371
+ protocol = new URL(url, "http://example.com").protocol;
372
+ }
373
+ if (!supportedProtocols.includes(protocol)) {
374
+ const protocolNotSupportedError = new Error(
375
+ `Unsupported protocol "${protocol}" for url "${url}"`,
376
+ );
377
+ protocolNotSupportedError.code = "PROTOCOL_NOT_SUPPORTED";
378
+ throw protocolNotSupportedError;
379
+ }
380
+ }
339
381
  return reference;
340
382
  } catch (error) {
341
383
  throw createResolveUrlError({
@@ -88,6 +88,9 @@ export const jsenvPluginProtocolFile = ({
88
88
  name: "jsenv:directory_as_json",
89
89
  appliesDuring: "*",
90
90
  fetchUrlContent: (urlInfo) => {
91
+ if (!urlInfo.url.startsWith("file:")) {
92
+ return null;
93
+ }
91
94
  const { firstReference } = urlInfo;
92
95
  let { fsStat } = firstReference;
93
96
  if (!fsStat) {