@jsenv/core 29.1.8 → 29.1.9

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
@@ -1563,7 +1563,7 @@ const collectFiles = async ({
1563
1563
  });
1564
1564
 
1565
1565
  if (directoryChildNodeStats.isDirectory()) {
1566
- const subDirectoryUrl = `${directoryChildNodeUrl}/`;
1566
+ const subDirectoryUrl = `${decodeURIComponent(directoryChildNodeUrl)}/`;
1567
1567
 
1568
1568
  if (!URL_META.urlChildMayMatch({
1569
1569
  url: subDirectoryUrl,
@@ -1579,7 +1579,7 @@ const collectFiles = async ({
1579
1579
 
1580
1580
  if (directoryChildNodeStats.isFile()) {
1581
1581
  const meta = URL_META.applyAssociations({
1582
- url: directoryChildNodeUrl,
1582
+ url: decodeURIComponent(directoryChildNodeUrl),
1583
1583
  associations
1584
1584
  });
1585
1585
  if (!predicate(meta)) return;
@@ -9645,10 +9645,17 @@ const createKitchen = ({
9645
9645
  }
9646
9646
 
9647
9647
  resolvedUrl = normalizeUrl(resolvedUrl);
9648
- let referencedUrlObject = new URL(resolvedUrl);
9649
- let searchParams = referencedUrlObject.searchParams;
9650
- reference.url = resolvedUrl;
9651
- reference.searchParams = searchParams;
9648
+ let referencedUrlObject;
9649
+ let searchParams;
9650
+
9651
+ const onReferenceUrlChange = referenceUrl => {
9652
+ referencedUrlObject = new URL(referenceUrl);
9653
+ searchParams = referencedUrlObject.searchParams;
9654
+ reference.url = referenceUrl;
9655
+ reference.searchParams = searchParams;
9656
+ };
9657
+
9658
+ onReferenceUrlChange(resolvedUrl);
9652
9659
 
9653
9660
  if (reference.debug) {
9654
9661
  logger.debug(`url resolved by "${pluginController.getLastPluginUsed().name}"
@@ -9674,17 +9681,9 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
9674
9681
  const prevReference = { ...reference
9675
9682
  };
9676
9683
  updateReference(prevReference, reference);
9677
- referencedUrlObject = new URL(normalizedReturnValue);
9678
- searchParams = referencedUrlObject.searchParams;
9679
- reference.url = normalizedReturnValue;
9680
- reference.searchParams = searchParams;
9684
+ onReferenceUrlChange(normalizedReturnValue);
9681
9685
  });
9682
9686
  reference.generatedUrl = reference.url;
9683
-
9684
- if (searchParams.has("entry_point")) {
9685
- reference.isEntryPoint = true;
9686
- }
9687
-
9688
9687
  const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url);
9689
9688
  applyReferenceEffectsOnUrlInfo(reference, urlInfo, context); // This hook must touch reference.generatedUrl, NOT reference.url
9690
9689
  // And this is because this hook inject query params used to:
@@ -9809,15 +9808,8 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
9809
9808
 
9810
9809
  urlInfo.contentType = contentType;
9811
9810
  urlInfo.headers = headers;
9812
- urlInfo.type = type || reference.expectedType || inferUrlInfoType({
9813
- url: urlInfo.url,
9814
- contentType
9815
- });
9816
- urlInfo.subtype = subtype || reference.expectedSubtype || inferUrlInfoSubtype({
9817
- url: urlInfo.url,
9818
- type: urlInfo.type,
9819
- subtype: urlInfo.subtype
9820
- }); // during build urls info are reused and load returns originalUrl/originalContent
9811
+ urlInfo.type = type || reference.expectedType || inferUrlInfoType(contentType);
9812
+ urlInfo.subtype = subtype || reference.expectedSubtype || ""; // during build urls info are reused and load returns originalUrl/originalContent
9821
9813
 
9822
9814
  urlInfo.originalUrl = originalUrl || urlInfo.originalUrl;
9823
9815
  urlInfo.originalContent = originalContent === undefined ? content : originalContent;
@@ -10299,10 +10291,7 @@ const adjustUrlSite = (urlInfo, {
10299
10291
  }, urlInfo);
10300
10292
  };
10301
10293
 
10302
- const inferUrlInfoType = ({
10303
- url,
10304
- contentType
10305
- }) => {
10294
+ const inferUrlInfoType = contentType => {
10306
10295
  if (contentType === "text/html") {
10307
10296
  return "html";
10308
10297
  }
@@ -10312,12 +10301,6 @@ const inferUrlInfoType = ({
10312
10301
  }
10313
10302
 
10314
10303
  if (contentType === "text/javascript") {
10315
- const urlObject = new URL(url);
10316
-
10317
- if (urlObject.searchParams.has("js_classic")) {
10318
- return "js_classic";
10319
- }
10320
-
10321
10304
  return "js_module";
10322
10305
  }
10323
10306
 
@@ -10344,33 +10327,6 @@ const inferUrlInfoType = ({
10344
10327
  return "other";
10345
10328
  };
10346
10329
 
10347
- const inferUrlInfoSubtype = ({
10348
- type,
10349
- subtype,
10350
- url
10351
- }) => {
10352
- if (type === "js_classic" || type === "js_module") {
10353
- const urlObject = new URL(url);
10354
-
10355
- if (urlObject.searchParams.has("worker")) {
10356
- return "worker";
10357
- }
10358
-
10359
- if (urlObject.searchParams.has("service_worker")) {
10360
- return "service_worker";
10361
- }
10362
-
10363
- if (urlObject.searchParams.has("shared_worker")) {
10364
- return "shared_worker";
10365
- } // if we are currently inside a worker, all deps are consider inside worker too
10366
-
10367
-
10368
- return subtype;
10369
- }
10370
-
10371
- return "";
10372
- };
10373
-
10374
10330
  const determineFileUrlForOutDirectory = ({
10375
10331
  urlInfo,
10376
10332
  context
@@ -10698,6 +10654,56 @@ const createRepartitionMessage = ({
10698
10654
  - `)}`;
10699
10655
  };
10700
10656
 
10657
+ const jsenvPluginReferenceExpectedTypes = () => {
10658
+ const redirectJsUrls = reference => {
10659
+ const urlObject = new URL(reference.url);
10660
+ const {
10661
+ searchParams
10662
+ } = urlObject;
10663
+
10664
+ if (searchParams.has("entry_point")) {
10665
+ reference.isEntryPoint = true;
10666
+ }
10667
+
10668
+ if (searchParams.has("js_classic")) {
10669
+ searchParams.delete("js_classic");
10670
+ reference.expectedType = "js_classic";
10671
+ } else if (searchParams.has("as_js_classic") || searchParams.has("as_js_classic_library")) {
10672
+ reference.expectedType = "js_classic";
10673
+ } else if (searchParams.has("js_module")) {
10674
+ searchParams.delete("js_module");
10675
+ reference.expectedType = "js_module";
10676
+ } else if (reference.type === "js_url_specifier" && reference.expectedType === undefined && CONTENT_TYPE.fromUrlExtension(reference.url) === "text/javascript") {
10677
+ // by default, js referenced by new URL is considered as "js_module"
10678
+ // in case this is not desired code must use "?js_classic" like
10679
+ // new URL('./file.js?js_classic', import.meta.url)
10680
+ reference.expectedType = "js_module";
10681
+ }
10682
+
10683
+ if (searchParams.has("worker")) {
10684
+ reference.expectedSubtype = "worker";
10685
+ searchParams.delete("worker");
10686
+ } else if (searchParams.has("service_worker")) {
10687
+ reference.expectedSubtype = "service_worker";
10688
+ searchParams.delete("service_worker");
10689
+ } else if (searchParams.has("shared_worker")) {
10690
+ reference.expectedSubtype = "shared_worker";
10691
+ searchParams.delete("shared_worker");
10692
+ }
10693
+
10694
+ return urlObject.href;
10695
+ };
10696
+
10697
+ return {
10698
+ name: "jsenv:reference_expected_types",
10699
+ appliesDuring: "*",
10700
+ redirectUrl: {
10701
+ script_src: redirectJsUrls,
10702
+ js_url_specifier: redirectJsUrls
10703
+ }
10704
+ };
10705
+ };
10706
+
10701
10707
  const parseAndTransformHtmlUrls = async (urlInfo, context) => {
10702
10708
  const url = urlInfo.originalUrl;
10703
10709
  const content = urlInfo.content;
@@ -11179,7 +11185,7 @@ const jsenvPluginUrlAnalysis = ({
11179
11185
  };
11180
11186
  }
11181
11187
 
11182
- return {
11188
+ return [{
11183
11189
  name: "jsenv:url_analysis",
11184
11190
  appliesDuring: "*",
11185
11191
  redirectUrl: reference => {
@@ -11238,7 +11244,7 @@ const jsenvPluginUrlAnalysis = ({
11238
11244
  });
11239
11245
  }
11240
11246
  }
11241
- };
11247
+ }, jsenvPluginReferenceExpectedTypes()];
11242
11248
  };
11243
11249
 
11244
11250
  const findOriginalDirectoryReference = (urlInfo, context) => {
@@ -16521,17 +16527,8 @@ const jsenvPluginAsJsClassicConversion = ({
16521
16527
  return true;
16522
16528
  }
16523
16529
 
16524
- if (reference.type === "js_url_specifier") {
16525
- if (reference.expectedType === "js_classic") {
16526
- return false;
16527
- }
16528
-
16529
- if (reference.expectedType === undefined && CONTENT_TYPE.fromUrlExtension(reference.url) === "text/javascript") {
16530
- // by default, js referenced by new URL is considered as "js_module"
16531
- // in case this is not desired code must use "?js_classic" like
16532
- // new URL('./file.js?js_classic', import.meta.url)
16533
- return true;
16534
- }
16530
+ if (reference.type === "js_url_specifier" && reference.expectedType === "js_module") {
16531
+ return true;
16535
16532
  }
16536
16533
 
16537
16534
  return false;
@@ -16543,12 +16540,10 @@ const jsenvPluginAsJsClassicConversion = ({
16543
16540
 
16544
16541
  if (!parentUrlInfo) {
16545
16542
  return false;
16546
- } // if (parentUrlInfo.isEntryPoint) {
16547
- // return true
16548
- // }
16549
-
16543
+ }
16550
16544
 
16551
- return new URL(parentUrlInfo.url).searchParams.has("as_js_classic");
16545
+ const parentGotAsJsClassic = new URL(parentUrlInfo.url).searchParams.has("as_js_classic");
16546
+ return parentGotAsJsClassic;
16552
16547
  }
16553
16548
 
16554
16549
  return false;
@@ -16661,7 +16656,8 @@ const jsenvPluginAsJsClassicHtml = ({
16661
16656
  name: "jsenv:as_js_classic_html",
16662
16657
  appliesDuring: "*",
16663
16658
  init: context => {
16664
- shouldTransformScriptTypeModule = !context.isSupportedOnCurrentClients("script_type_module") || !context.isSupportedOnCurrentClients("import_dynamic") || !context.isSupportedOnCurrentClients("import_meta");
16659
+ const nodeRuntimeEnabled = Object.keys(context.runtimeCompat).includes("node");
16660
+ shouldTransformScriptTypeModule = nodeRuntimeEnabled ? false : !context.isSupportedOnCurrentClients("script_type_module") || !context.isSupportedOnCurrentClients("import_dynamic") || !context.isSupportedOnCurrentClients("import_meta");
16665
16661
  },
16666
16662
  redirectUrl: {
16667
16663
  link_href: reference => {
@@ -16680,6 +16676,13 @@ const jsenvPluginAsJsClassicHtml = ({
16680
16676
  return turnIntoJsClassicProxy(reference);
16681
16677
  }
16682
16678
 
16679
+ return null;
16680
+ },
16681
+ js_url_specifier: reference => {
16682
+ if (shouldTransformScriptTypeModule && reference.expectedType === "js_module") {
16683
+ return turnIntoJsClassicProxy(reference);
16684
+ }
16685
+
16683
16686
  return null;
16684
16687
  }
16685
16688
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "29.1.8",
3
+ "version": "29.1.9",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -68,7 +68,7 @@
68
68
  "@jsenv/abort": "4.2.4",
69
69
  "@jsenv/ast": "1.3.2",
70
70
  "@jsenv/babel-plugins": "1.0.7",
71
- "@jsenv/filesystem": "4.1.3",
71
+ "@jsenv/filesystem": "4.1.4",
72
72
  "@jsenv/importmap": "1.2.1",
73
73
  "@jsenv/integrity": "0.0.1",
74
74
  "@jsenv/log": "3.3.1",
@@ -105,11 +105,11 @@
105
105
  "@jsenv/https-local": "3.0.1",
106
106
  "@jsenv/package-workspace": "0.5.0",
107
107
  "@jsenv/performance-impact": "3.0.1",
108
- "eslint": "8.23.1",
108
+ "eslint": "8.24.0",
109
109
  "eslint-plugin-html": "7.1.0",
110
110
  "eslint-plugin-import": "2.26.0",
111
111
  "eslint-plugin-react": "7.31.8",
112
- "playwright": "1.26.0",
112
+ "playwright": "1.26.1",
113
113
  "prettier": "2.7.1"
114
114
  }
115
115
  }
@@ -177,10 +177,16 @@ export const createKitchen = ({
177
177
  reference.debug = true
178
178
  }
179
179
  resolvedUrl = normalizeUrl(resolvedUrl)
180
- let referencedUrlObject = new URL(resolvedUrl)
181
- let searchParams = referencedUrlObject.searchParams
182
- reference.url = resolvedUrl
183
- reference.searchParams = searchParams
180
+ let referencedUrlObject
181
+ let searchParams
182
+ const onReferenceUrlChange = (referenceUrl) => {
183
+ referencedUrlObject = new URL(referenceUrl)
184
+ searchParams = referencedUrlObject.searchParams
185
+ reference.url = referenceUrl
186
+ reference.searchParams = searchParams
187
+ }
188
+ onReferenceUrlChange(resolvedUrl)
189
+
184
190
  if (reference.debug) {
185
191
  logger.debug(`url resolved by "${
186
192
  pluginController.getLastPluginUsed().name
@@ -208,16 +214,10 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
208
214
  }
209
215
  const prevReference = { ...reference }
210
216
  updateReference(prevReference, reference)
211
- referencedUrlObject = new URL(normalizedReturnValue)
212
- searchParams = referencedUrlObject.searchParams
213
- reference.url = normalizedReturnValue
214
- reference.searchParams = searchParams
217
+ onReferenceUrlChange(normalizedReturnValue)
215
218
  },
216
219
  )
217
220
  reference.generatedUrl = reference.url
218
- if (searchParams.has("entry_point")) {
219
- reference.isEntryPoint = true
220
- }
221
221
 
222
222
  const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url)
223
223
  applyReferenceEffectsOnUrlInfo(reference, urlInfo, context)
@@ -360,17 +360,8 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
360
360
  urlInfo.contentType = contentType
361
361
  urlInfo.headers = headers
362
362
  urlInfo.type =
363
- type ||
364
- reference.expectedType ||
365
- inferUrlInfoType({ url: urlInfo.url, contentType })
366
- urlInfo.subtype =
367
- subtype ||
368
- reference.expectedSubtype ||
369
- inferUrlInfoSubtype({
370
- url: urlInfo.url,
371
- type: urlInfo.type,
372
- subtype: urlInfo.subtype,
373
- })
363
+ type || reference.expectedType || inferUrlInfoType(contentType)
364
+ urlInfo.subtype = subtype || reference.expectedSubtype || ""
374
365
  // during build urls info are reused and load returns originalUrl/originalContent
375
366
  urlInfo.originalUrl = originalUrl || urlInfo.originalUrl
376
367
  urlInfo.originalContent =
@@ -875,7 +866,7 @@ const adjustUrlSite = (urlInfo, { urlGraph, url, line, column }) => {
875
866
  )
876
867
  }
877
868
 
878
- const inferUrlInfoType = ({ url, contentType }) => {
869
+ const inferUrlInfoType = (contentType) => {
879
870
  if (contentType === "text/html") {
880
871
  return "html"
881
872
  }
@@ -883,10 +874,6 @@ const inferUrlInfoType = ({ url, contentType }) => {
883
874
  return "css"
884
875
  }
885
876
  if (contentType === "text/javascript") {
886
- const urlObject = new URL(url)
887
- if (urlObject.searchParams.has("js_classic")) {
888
- return "js_classic"
889
- }
890
877
  return "js_module"
891
878
  }
892
879
  if (contentType === "application/importmap+json") {
@@ -907,24 +894,6 @@ const inferUrlInfoType = ({ url, contentType }) => {
907
894
  return "other"
908
895
  }
909
896
 
910
- const inferUrlInfoSubtype = ({ type, subtype, url }) => {
911
- if (type === "js_classic" || type === "js_module") {
912
- const urlObject = new URL(url)
913
- if (urlObject.searchParams.has("worker")) {
914
- return "worker"
915
- }
916
- if (urlObject.searchParams.has("service_worker")) {
917
- return "service_worker"
918
- }
919
- if (urlObject.searchParams.has("shared_worker")) {
920
- return "shared_worker"
921
- }
922
- // if we are currently inside a worker, all deps are consider inside worker too
923
- return subtype
924
- }
925
- return ""
926
- }
927
-
928
897
  const determineFileUrlForOutDirectory = ({ urlInfo, context }) => {
929
898
  if (!context.outDirectoryUrl) {
930
899
  return urlInfo.url
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import { injectQueryParams } from "@jsenv/urls"
7
- import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
8
7
  import { convertJsModuleToJsClassic } from "./convert_js_module_to_js_classic.js"
9
8
 
10
9
  export const jsenvPluginAsJsClassicConversion = ({
@@ -20,19 +19,11 @@ export const jsenvPluginAsJsClassicConversion = ({
20
19
  ) {
21
20
  return true
22
21
  }
23
- if (reference.type === "js_url_specifier") {
24
- if (reference.expectedType === "js_classic") {
25
- return false
26
- }
27
- if (
28
- reference.expectedType === undefined &&
29
- CONTENT_TYPE.fromUrlExtension(reference.url) === "text/javascript"
30
- ) {
31
- // by default, js referenced by new URL is considered as "js_module"
32
- // in case this is not desired code must use "?js_classic" like
33
- // new URL('./file.js?js_classic', import.meta.url)
34
- return true
35
- }
22
+ if (
23
+ reference.type === "js_url_specifier" &&
24
+ reference.expectedType === "js_module"
25
+ ) {
26
+ return true
36
27
  }
37
28
  return false
38
29
  }
@@ -43,10 +34,10 @@ export const jsenvPluginAsJsClassicConversion = ({
43
34
  if (!parentUrlInfo) {
44
35
  return false
45
36
  }
46
- // if (parentUrlInfo.isEntryPoint) {
47
- // return true
48
- // }
49
- return new URL(parentUrlInfo.url).searchParams.has("as_js_classic")
37
+ const parentGotAsJsClassic = new URL(parentUrlInfo.url).searchParams.has(
38
+ "as_js_classic",
39
+ )
40
+ return parentGotAsJsClassic
50
41
  }
51
42
 
52
43
  return false
@@ -33,10 +33,14 @@ export const jsenvPluginAsJsClassicHtml = ({
33
33
  name: "jsenv:as_js_classic_html",
34
34
  appliesDuring: "*",
35
35
  init: (context) => {
36
- shouldTransformScriptTypeModule =
37
- !context.isSupportedOnCurrentClients("script_type_module") ||
38
- !context.isSupportedOnCurrentClients("import_dynamic") ||
39
- !context.isSupportedOnCurrentClients("import_meta")
36
+ const nodeRuntimeEnabled = Object.keys(context.runtimeCompat).includes(
37
+ "node",
38
+ )
39
+ shouldTransformScriptTypeModule = nodeRuntimeEnabled
40
+ ? false
41
+ : !context.isSupportedOnCurrentClients("script_type_module") ||
42
+ !context.isSupportedOnCurrentClients("import_dynamic") ||
43
+ !context.isSupportedOnCurrentClients("import_meta")
40
44
  },
41
45
  redirectUrl: {
42
46
  link_href: (reference) => {
@@ -64,6 +68,15 @@ export const jsenvPluginAsJsClassicHtml = ({
64
68
  }
65
69
  return null
66
70
  },
71
+ js_url_specifier: (reference) => {
72
+ if (
73
+ shouldTransformScriptTypeModule &&
74
+ reference.expectedType === "js_module"
75
+ ) {
76
+ return turnIntoJsClassicProxy(reference)
77
+ }
78
+ return null
79
+ },
67
80
  },
68
81
  finalizeUrlContent: {
69
82
  html: async (urlInfo, context) => {
@@ -0,0 +1,55 @@
1
+ import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js"
2
+
3
+ export const jsenvPluginReferenceExpectedTypes = () => {
4
+ const redirectJsUrls = (reference) => {
5
+ const urlObject = new URL(reference.url)
6
+ const { searchParams } = urlObject
7
+
8
+ if (searchParams.has("entry_point")) {
9
+ reference.isEntryPoint = true
10
+ }
11
+ if (searchParams.has("js_classic")) {
12
+ searchParams.delete("js_classic")
13
+ reference.expectedType = "js_classic"
14
+ } else if (
15
+ searchParams.has("as_js_classic") ||
16
+ searchParams.has("as_js_classic_library")
17
+ ) {
18
+ reference.expectedType = "js_classic"
19
+ } else if (searchParams.has("js_module")) {
20
+ searchParams.delete("js_module")
21
+ reference.expectedType = "js_module"
22
+ } else if (
23
+ reference.type === "js_url_specifier" &&
24
+ reference.expectedType === undefined &&
25
+ CONTENT_TYPE.fromUrlExtension(reference.url) === "text/javascript"
26
+ ) {
27
+ // by default, js referenced by new URL is considered as "js_module"
28
+ // in case this is not desired code must use "?js_classic" like
29
+ // new URL('./file.js?js_classic', import.meta.url)
30
+ reference.expectedType = "js_module"
31
+ }
32
+
33
+ if (searchParams.has("worker")) {
34
+ reference.expectedSubtype = "worker"
35
+ searchParams.delete("worker")
36
+ } else if (searchParams.has("service_worker")) {
37
+ reference.expectedSubtype = "service_worker"
38
+ searchParams.delete("service_worker")
39
+ } else if (searchParams.has("shared_worker")) {
40
+ reference.expectedSubtype = "shared_worker"
41
+ searchParams.delete("shared_worker")
42
+ }
43
+
44
+ return urlObject.href
45
+ }
46
+
47
+ return {
48
+ name: "jsenv:reference_expected_types",
49
+ appliesDuring: "*",
50
+ redirectUrl: {
51
+ script_src: redirectJsUrls,
52
+ js_url_specifier: redirectJsUrls,
53
+ },
54
+ }
55
+ }
@@ -1,6 +1,7 @@
1
1
  import { URL_META } from "@jsenv/url-meta"
2
2
  import { urlToRelativeUrl } from "@jsenv/urls"
3
3
 
4
+ import { jsenvPluginReferenceExpectedTypes } from "./jsenv_plugin_reference_expected_types.js"
4
5
  import { parseAndTransformHtmlUrls } from "./html/html_urls.js"
5
6
  import { parseAndTransformCssUrls } from "./css/css_urls.js"
6
7
  import { parseAndTransformJsUrls } from "./js/js_urls.js"
@@ -24,69 +25,72 @@ export const jsenvPluginUrlAnalysis = ({
24
25
  }
25
26
  }
26
27
 
27
- return {
28
- name: "jsenv:url_analysis",
29
- appliesDuring: "*",
30
- redirectUrl: (reference) => {
31
- if (reference.shouldHandle !== undefined) {
32
- return
33
- }
34
- if (
35
- reference.specifier[0] === "#" &&
36
- // For Html, css and in general "#" refer to a resource in the page
37
- // so that urls must be kept intact
38
- // However for js import specifiers they have a different meaning and we want
39
- // to resolve them (https://nodejs.org/api/packages.html#imports for instance)
40
- reference.type !== "js_import_export"
41
- ) {
42
- reference.shouldHandle = false
43
- return
44
- }
45
- const includeInfo = getIncludeInfo(reference.url)
46
- if (includeInfo === true) {
47
- reference.shouldHandle = true
48
- return
49
- }
50
- if (includeInfo === false) {
51
- reference.shouldHandle = false
52
- return
53
- }
54
- const { protocol } = new URL(reference.url)
55
- const protocolIsSupported = supportedProtocols.some(
56
- (supportedProtocol) => protocol === supportedProtocol,
57
- )
58
- if (protocolIsSupported) {
59
- reference.shouldHandle = true
60
- }
61
- },
62
- transformUrlContent: {
63
- html: parseAndTransformHtmlUrls,
64
- css: parseAndTransformCssUrls,
65
- js_classic: parseAndTransformJsUrls,
66
- js_module: parseAndTransformJsUrls,
67
- webmanifest: parseAndTransformWebmanifestUrls,
68
- directory: (urlInfo, context) => {
69
- const originalDirectoryReference = findOriginalDirectoryReference(
70
- urlInfo,
71
- context,
72
- )
73
- const directoryRelativeUrl = urlToRelativeUrl(
74
- urlInfo.url,
75
- context.rootDirectoryUrl,
28
+ return [
29
+ {
30
+ name: "jsenv:url_analysis",
31
+ appliesDuring: "*",
32
+ redirectUrl: (reference) => {
33
+ if (reference.shouldHandle !== undefined) {
34
+ return
35
+ }
36
+ if (
37
+ reference.specifier[0] === "#" &&
38
+ // For Html, css and in general "#" refer to a resource in the page
39
+ // so that urls must be kept intact
40
+ // However for js import specifiers they have a different meaning and we want
41
+ // to resolve them (https://nodejs.org/api/packages.html#imports for instance)
42
+ reference.type !== "js_import_export"
43
+ ) {
44
+ reference.shouldHandle = false
45
+ return
46
+ }
47
+ const includeInfo = getIncludeInfo(reference.url)
48
+ if (includeInfo === true) {
49
+ reference.shouldHandle = true
50
+ return
51
+ }
52
+ if (includeInfo === false) {
53
+ reference.shouldHandle = false
54
+ return
55
+ }
56
+ const { protocol } = new URL(reference.url)
57
+ const protocolIsSupported = supportedProtocols.some(
58
+ (supportedProtocol) => protocol === supportedProtocol,
76
59
  )
77
- JSON.parse(urlInfo.content).forEach((directoryEntryName) => {
78
- context.referenceUtils.found({
79
- type: "filesystem",
80
- subtype: "directory_entry",
81
- specifier: directoryEntryName,
82
- trace: {
83
- message: `"${directoryRelativeUrl}${directoryEntryName}" entry in directory referenced by ${originalDirectoryReference.trace.message}`,
84
- },
60
+ if (protocolIsSupported) {
61
+ reference.shouldHandle = true
62
+ }
63
+ },
64
+ transformUrlContent: {
65
+ html: parseAndTransformHtmlUrls,
66
+ css: parseAndTransformCssUrls,
67
+ js_classic: parseAndTransformJsUrls,
68
+ js_module: parseAndTransformJsUrls,
69
+ webmanifest: parseAndTransformWebmanifestUrls,
70
+ directory: (urlInfo, context) => {
71
+ const originalDirectoryReference = findOriginalDirectoryReference(
72
+ urlInfo,
73
+ context,
74
+ )
75
+ const directoryRelativeUrl = urlToRelativeUrl(
76
+ urlInfo.url,
77
+ context.rootDirectoryUrl,
78
+ )
79
+ JSON.parse(urlInfo.content).forEach((directoryEntryName) => {
80
+ context.referenceUtils.found({
81
+ type: "filesystem",
82
+ subtype: "directory_entry",
83
+ specifier: directoryEntryName,
84
+ trace: {
85
+ message: `"${directoryRelativeUrl}${directoryEntryName}" entry in directory referenced by ${originalDirectoryReference.trace.message}`,
86
+ },
87
+ })
85
88
  })
86
- })
89
+ },
87
90
  },
88
91
  },
89
- }
92
+ jsenvPluginReferenceExpectedTypes(),
93
+ ]
90
94
  }
91
95
 
92
96
  const findOriginalDirectoryReference = (urlInfo, context) => {