@jsenv/core 39.14.2 → 39.14.3

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 (2) hide show
  1. package/dist/jsenv_core.js +460 -259
  2. package/package.json +6 -6
@@ -3512,203 +3512,6 @@ const writeDirectory = async (
3512
3512
  }
3513
3513
  };
3514
3514
 
3515
- const mediaTypeInfos = {
3516
- "application/json": {
3517
- extensions: ["json", "map"],
3518
- isTextual: true,
3519
- },
3520
- "application/importmap+json": {
3521
- extensions: ["importmap"],
3522
- isTextual: true,
3523
- },
3524
- "application/manifest+json": {
3525
- extensions: ["webmanifest"],
3526
- isTextual: true,
3527
- },
3528
- "application/octet-stream": {},
3529
- "application/pdf": {
3530
- extensions: ["pdf"],
3531
- },
3532
- "application/xml": {
3533
- extensions: ["xml"],
3534
- isTextual: true,
3535
- },
3536
- "application/x-gzip": {
3537
- extensions: ["gz"],
3538
- },
3539
- "application/wasm": {
3540
- extensions: ["wasm"],
3541
- },
3542
- "application/zip": {
3543
- extensions: ["zip"],
3544
- },
3545
- "audio/basic": {
3546
- extensions: ["au", "snd"],
3547
- },
3548
- "audio/mpeg": {
3549
- extensions: ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"],
3550
- },
3551
- "audio/midi": {
3552
- extensions: ["midi", "mid", "kar", "rmi"],
3553
- },
3554
- "audio/mp4": {
3555
- extensions: ["m4a", "mp4a"],
3556
- },
3557
- "audio/ogg": {
3558
- extensions: ["oga", "ogg", "spx"],
3559
- },
3560
- "audio/webm": {
3561
- extensions: ["weba"],
3562
- },
3563
- "audio/x-wav": {
3564
- extensions: ["wav"],
3565
- },
3566
- "font/ttf": {
3567
- extensions: ["ttf"],
3568
- },
3569
- "font/woff": {
3570
- extensions: ["woff"],
3571
- },
3572
- "font/woff2": {
3573
- extensions: ["woff2"],
3574
- },
3575
- "image/png": {
3576
- extensions: ["png"],
3577
- },
3578
- "image/gif": {
3579
- extensions: ["gif"],
3580
- },
3581
- "image/jpeg": {
3582
- extensions: ["jpg"],
3583
- },
3584
- "image/svg+xml": {
3585
- extensions: ["svg", "svgz"],
3586
- isTextual: true,
3587
- },
3588
- "text/plain": {
3589
- extensions: ["txt"],
3590
- isTextual: true,
3591
- },
3592
- "text/html": {
3593
- extensions: ["html"],
3594
- isTextual: true,
3595
- },
3596
- "text/css": {
3597
- extensions: ["css"],
3598
- isTextual: true,
3599
- },
3600
- "text/javascript": {
3601
- extensions: ["js", "cjs", "mjs", "ts", "jsx", "tsx"],
3602
- isTextual: true,
3603
- },
3604
- "text/markdown": {
3605
- extensions: ["md", "mdx"],
3606
- isTextual: true,
3607
- },
3608
- "text/x-sass": {
3609
- extensions: ["sass"],
3610
- isTextual: true,
3611
- },
3612
- "text/x-scss": {
3613
- extensions: ["scss"],
3614
- isTextual: true,
3615
- },
3616
- "text/cache-manifest": {
3617
- extensions: ["appcache"],
3618
- },
3619
- "video/mp4": {
3620
- extensions: ["mp4", "mp4v", "mpg4"],
3621
- },
3622
- "video/mpeg": {
3623
- extensions: ["mpeg", "mpg", "mpe", "m1v", "m2v"],
3624
- },
3625
- "video/ogg": {
3626
- extensions: ["ogv"],
3627
- },
3628
- "video/webm": {
3629
- extensions: ["webm"],
3630
- },
3631
- };
3632
-
3633
- const CONTENT_TYPE = {
3634
- parse: (string) => {
3635
- const [mediaType, charset] = string.split(";");
3636
- return { mediaType: normalizeMediaType(mediaType), charset };
3637
- },
3638
-
3639
- stringify: ({ mediaType, charset }) => {
3640
- if (charset) {
3641
- return `${mediaType};${charset}`;
3642
- }
3643
- return mediaType;
3644
- },
3645
-
3646
- asMediaType: (value) => {
3647
- if (typeof value === "string") {
3648
- return CONTENT_TYPE.parse(value).mediaType;
3649
- }
3650
- if (typeof value === "object") {
3651
- return value.mediaType;
3652
- }
3653
- return null;
3654
- },
3655
-
3656
- isJson: (value) => {
3657
- const mediaType = CONTENT_TYPE.asMediaType(value);
3658
- return (
3659
- mediaType === "application/json" ||
3660
- /^application\/\w+\+json$/.test(mediaType)
3661
- );
3662
- },
3663
-
3664
- isTextual: (value) => {
3665
- const mediaType = CONTENT_TYPE.asMediaType(value);
3666
- if (mediaType.startsWith("text/")) {
3667
- return true;
3668
- }
3669
- const mediaTypeInfo = mediaTypeInfos[mediaType];
3670
- if (mediaTypeInfo && mediaTypeInfo.isTextual) {
3671
- return true;
3672
- }
3673
- // catch things like application/manifest+json, application/importmap+json
3674
- if (/^application\/\w+\+json$/.test(mediaType)) {
3675
- return true;
3676
- }
3677
- return false;
3678
- },
3679
-
3680
- isBinary: (value) => !CONTENT_TYPE.isTextual(value),
3681
-
3682
- asFileExtension: (value) => {
3683
- const mediaType = CONTENT_TYPE.asMediaType(value);
3684
- const mediaTypeInfo = mediaTypeInfos[mediaType];
3685
- return mediaTypeInfo ? `.${mediaTypeInfo.extensions[0]}` : "";
3686
- },
3687
-
3688
- fromUrlExtension: (url) => {
3689
- const { pathname } = new URL(url);
3690
- const extensionWithDot = extname(pathname);
3691
- if (!extensionWithDot || extensionWithDot === ".") {
3692
- return "application/octet-stream";
3693
- }
3694
- const extension = extensionWithDot.slice(1);
3695
- const mediaTypeFound = Object.keys(mediaTypeInfos).find((mediaType) => {
3696
- const mediaTypeInfo = mediaTypeInfos[mediaType];
3697
- return (
3698
- mediaTypeInfo.extensions && mediaTypeInfo.extensions.includes(extension)
3699
- );
3700
- });
3701
- return mediaTypeFound || "application/octet-stream";
3702
- },
3703
- };
3704
-
3705
- const normalizeMediaType = (value) => {
3706
- if (value === "application/javascript") {
3707
- return "text/javascript";
3708
- }
3709
- return value;
3710
- };
3711
-
3712
3515
  const removeEntrySync = (
3713
3516
  source,
3714
3517
  {
@@ -7786,65 +7589,262 @@ const PROCESS_TEARDOWN_EVENTS_MAP = {
7786
7589
  exit: STOP_REASON_PROCESS_EXIT,
7787
7590
  };
7788
7591
 
7789
- const pickAcceptedContent = ({
7790
- availables,
7791
- accepteds,
7792
- getAcceptanceScore,
7793
- }) => {
7794
- let highestScore = -1;
7795
- let availableWithHighestScore = null;
7796
- let availableIndex = 0;
7797
- while (availableIndex < availables.length) {
7798
- const available = availables[availableIndex];
7799
- availableIndex++;
7800
-
7801
- let acceptedIndex = 0;
7802
- while (acceptedIndex < accepteds.length) {
7803
- const accepted = accepteds[acceptedIndex];
7804
- acceptedIndex++;
7805
-
7806
- const score = getAcceptanceScore(accepted, available);
7807
- if (score > highestScore) {
7808
- availableWithHighestScore = available;
7809
- highestScore = score;
7810
- }
7811
- }
7812
- }
7813
- return availableWithHighestScore;
7814
- };
7815
-
7816
- const pickContentEncoding = (request, availableEncodings) => {
7817
- const { headers = {} } = request;
7818
- const requestAcceptEncodingHeader = headers["accept-encoding"];
7819
- if (!requestAcceptEncodingHeader) {
7820
- return null;
7821
- }
7822
-
7823
- const encodingsAccepted = parseAcceptEncodingHeader(
7824
- requestAcceptEncodingHeader,
7825
- );
7826
- return pickAcceptedContent({
7827
- accepteds: encodingsAccepted,
7828
- availables: availableEncodings,
7829
- getAcceptanceScore: getEncodingAcceptanceScore,
7830
- });
7831
- };
7832
-
7833
- const parseAcceptEncodingHeader = (acceptEncodingHeaderString) => {
7834
- const acceptEncodingHeader = parseMultipleHeader(acceptEncodingHeaderString, {
7835
- validateProperty: ({ name }) => {
7836
- // read only q, anything else is ignored
7837
- return name === "q";
7838
- },
7839
- });
7840
-
7841
- const encodingsAccepted = [];
7842
- Object.keys(acceptEncodingHeader).forEach((key) => {
7843
- const { q = 1 } = acceptEncodingHeader[key];
7844
- const value = key;
7845
- encodingsAccepted.push({
7846
- value,
7847
- quality: q,
7592
+ const mediaTypeInfos$1 = {
7593
+ "application/json": {
7594
+ extensions: ["json", "map"],
7595
+ isTextual: true,
7596
+ },
7597
+ "application/importmap+json": {
7598
+ extensions: ["importmap"],
7599
+ isTextual: true,
7600
+ },
7601
+ "application/manifest+json": {
7602
+ extensions: ["webmanifest"],
7603
+ isTextual: true,
7604
+ },
7605
+ "application/octet-stream": {},
7606
+ "application/pdf": {
7607
+ extensions: ["pdf"],
7608
+ },
7609
+ "application/xml": {
7610
+ extensions: ["xml"],
7611
+ isTextual: true,
7612
+ },
7613
+ "application/x-gzip": {
7614
+ extensions: ["gz"],
7615
+ },
7616
+ "application/wasm": {
7617
+ extensions: ["wasm"],
7618
+ },
7619
+ "application/zip": {
7620
+ extensions: ["zip"],
7621
+ },
7622
+ "audio/basic": {
7623
+ extensions: ["au", "snd"],
7624
+ },
7625
+ "audio/mpeg": {
7626
+ extensions: ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"],
7627
+ },
7628
+ "audio/midi": {
7629
+ extensions: ["midi", "mid", "kar", "rmi"],
7630
+ },
7631
+ "audio/mp4": {
7632
+ extensions: ["m4a", "mp4a"],
7633
+ },
7634
+ "audio/ogg": {
7635
+ extensions: ["oga", "ogg", "spx"],
7636
+ },
7637
+ "audio/webm": {
7638
+ extensions: ["weba"],
7639
+ },
7640
+ "audio/x-wav": {
7641
+ extensions: ["wav"],
7642
+ },
7643
+ "font/ttf": {
7644
+ extensions: ["ttf"],
7645
+ },
7646
+ "font/woff": {
7647
+ extensions: ["woff"],
7648
+ },
7649
+ "font/woff2": {
7650
+ extensions: ["woff2"],
7651
+ },
7652
+ "image/png": {
7653
+ extensions: ["png"],
7654
+ },
7655
+ "image/gif": {
7656
+ extensions: ["gif"],
7657
+ },
7658
+ "image/jpeg": {
7659
+ extensions: ["jpg"],
7660
+ },
7661
+ "image/svg+xml": {
7662
+ extensions: ["svg", "svgz"],
7663
+ isTextual: true,
7664
+ },
7665
+ "text/plain": {
7666
+ extensions: ["txt"],
7667
+ isTextual: true,
7668
+ },
7669
+ "text/html": {
7670
+ extensions: ["html"],
7671
+ isTextual: true,
7672
+ },
7673
+ "text/css": {
7674
+ extensions: ["css"],
7675
+ isTextual: true,
7676
+ },
7677
+ "text/javascript": {
7678
+ extensions: ["js", "cjs", "mjs", "ts", "jsx", "tsx"],
7679
+ isTextual: true,
7680
+ },
7681
+ "text/markdown": {
7682
+ extensions: ["md", "mdx"],
7683
+ isTextual: true,
7684
+ },
7685
+ "text/x-sass": {
7686
+ extensions: ["sass"],
7687
+ isTextual: true,
7688
+ },
7689
+ "text/x-scss": {
7690
+ extensions: ["scss"],
7691
+ isTextual: true,
7692
+ },
7693
+ "text/cache-manifest": {
7694
+ extensions: ["appcache"],
7695
+ },
7696
+ "video/mp4": {
7697
+ extensions: ["mp4", "mp4v", "mpg4"],
7698
+ },
7699
+ "video/mpeg": {
7700
+ extensions: ["mpeg", "mpg", "mpe", "m1v", "m2v"],
7701
+ },
7702
+ "video/ogg": {
7703
+ extensions: ["ogv"],
7704
+ },
7705
+ "video/webm": {
7706
+ extensions: ["webm"],
7707
+ },
7708
+ };
7709
+
7710
+ const CONTENT_TYPE$1 = {
7711
+ parse: (string) => {
7712
+ const [mediaType, charset] = string.split(";");
7713
+ return { mediaType: normalizeMediaType$1(mediaType), charset };
7714
+ },
7715
+
7716
+ stringify: ({ mediaType, charset }) => {
7717
+ if (charset) {
7718
+ return `${mediaType};${charset}`;
7719
+ }
7720
+ return mediaType;
7721
+ },
7722
+
7723
+ asMediaType: (value) => {
7724
+ if (typeof value === "string") {
7725
+ return CONTENT_TYPE$1.parse(value).mediaType;
7726
+ }
7727
+ if (typeof value === "object") {
7728
+ return value.mediaType;
7729
+ }
7730
+ return null;
7731
+ },
7732
+
7733
+ isJson: (value) => {
7734
+ const mediaType = CONTENT_TYPE$1.asMediaType(value);
7735
+ return (
7736
+ mediaType === "application/json" ||
7737
+ /^application\/\w+\+json$/.test(mediaType)
7738
+ );
7739
+ },
7740
+
7741
+ isTextual: (value) => {
7742
+ const mediaType = CONTENT_TYPE$1.asMediaType(value);
7743
+ if (mediaType.startsWith("text/")) {
7744
+ return true;
7745
+ }
7746
+ const mediaTypeInfo = mediaTypeInfos$1[mediaType];
7747
+ if (mediaTypeInfo && mediaTypeInfo.isTextual) {
7748
+ return true;
7749
+ }
7750
+ // catch things like application/manifest+json, application/importmap+json
7751
+ if (/^application\/\w+\+json$/.test(mediaType)) {
7752
+ return true;
7753
+ }
7754
+ return false;
7755
+ },
7756
+
7757
+ isBinary: (value) => !CONTENT_TYPE$1.isTextual(value),
7758
+
7759
+ asFileExtension: (value) => {
7760
+ const mediaType = CONTENT_TYPE$1.asMediaType(value);
7761
+ const mediaTypeInfo = mediaTypeInfos$1[mediaType];
7762
+ return mediaTypeInfo ? `.${mediaTypeInfo.extensions[0]}` : "";
7763
+ },
7764
+
7765
+ fromUrlExtension: (url) => {
7766
+ const { pathname } = new URL(url);
7767
+ const extensionWithDot = extname(pathname);
7768
+ if (!extensionWithDot || extensionWithDot === ".") {
7769
+ return "application/octet-stream";
7770
+ }
7771
+ const extension = extensionWithDot.slice(1);
7772
+ const mediaTypeFound = Object.keys(mediaTypeInfos$1).find((mediaType) => {
7773
+ const mediaTypeInfo = mediaTypeInfos$1[mediaType];
7774
+ return (
7775
+ mediaTypeInfo.extensions && mediaTypeInfo.extensions.includes(extension)
7776
+ );
7777
+ });
7778
+ return mediaTypeFound || "application/octet-stream";
7779
+ },
7780
+ };
7781
+
7782
+ const normalizeMediaType$1 = (value) => {
7783
+ if (value === "application/javascript") {
7784
+ return "text/javascript";
7785
+ }
7786
+ return value;
7787
+ };
7788
+
7789
+ const pickAcceptedContent = ({
7790
+ availables,
7791
+ accepteds,
7792
+ getAcceptanceScore,
7793
+ }) => {
7794
+ let highestScore = -1;
7795
+ let availableWithHighestScore = null;
7796
+ let availableIndex = 0;
7797
+ while (availableIndex < availables.length) {
7798
+ const available = availables[availableIndex];
7799
+ availableIndex++;
7800
+
7801
+ let acceptedIndex = 0;
7802
+ while (acceptedIndex < accepteds.length) {
7803
+ const accepted = accepteds[acceptedIndex];
7804
+ acceptedIndex++;
7805
+
7806
+ const score = getAcceptanceScore(accepted, available);
7807
+ if (score > highestScore) {
7808
+ availableWithHighestScore = available;
7809
+ highestScore = score;
7810
+ }
7811
+ }
7812
+ }
7813
+ return availableWithHighestScore;
7814
+ };
7815
+
7816
+ const pickContentEncoding = (request, availableEncodings) => {
7817
+ const { headers = {} } = request;
7818
+ const requestAcceptEncodingHeader = headers["accept-encoding"];
7819
+ if (!requestAcceptEncodingHeader) {
7820
+ return null;
7821
+ }
7822
+
7823
+ const encodingsAccepted = parseAcceptEncodingHeader(
7824
+ requestAcceptEncodingHeader,
7825
+ );
7826
+ return pickAcceptedContent({
7827
+ accepteds: encodingsAccepted,
7828
+ availables: availableEncodings,
7829
+ getAcceptanceScore: getEncodingAcceptanceScore,
7830
+ });
7831
+ };
7832
+
7833
+ const parseAcceptEncodingHeader = (acceptEncodingHeaderString) => {
7834
+ const acceptEncodingHeader = parseMultipleHeader(acceptEncodingHeaderString, {
7835
+ validateProperty: ({ name }) => {
7836
+ // read only q, anything else is ignored
7837
+ return name === "q";
7838
+ },
7839
+ });
7840
+
7841
+ const encodingsAccepted = [];
7842
+ Object.keys(acceptEncodingHeader).forEach((key) => {
7843
+ const { q = 1 } = acceptEncodingHeader[key];
7844
+ const value = key;
7845
+ encodingsAccepted.push({
7846
+ value,
7847
+ quality: q,
7848
7848
  });
7849
7849
  });
7850
7850
  encodingsAccepted.sort((a, b) => {
@@ -8468,8 +8468,8 @@ const getMtimeResponse = async ({ headers, fileStat }) => {
8468
8468
  };
8469
8469
 
8470
8470
  const getCompressedResponse = async ({ fileUrl, headers }) => {
8471
- const contentType = CONTENT_TYPE.fromUrlExtension(fileUrl);
8472
- if (CONTENT_TYPE.isBinary(contentType)) {
8471
+ const contentType = CONTENT_TYPE$1.fromUrlExtension(fileUrl);
8472
+ if (CONTENT_TYPE$1.isBinary(contentType)) {
8473
8473
  return null;
8474
8474
  }
8475
8475
  const acceptedCompressionFormat = pickContentEncoding(
@@ -8523,7 +8523,7 @@ const getRawResponse = async ({ fileUrl, fileStat }) => {
8523
8523
  return {
8524
8524
  status: 200,
8525
8525
  headers: {
8526
- "content-type": CONTENT_TYPE.fromUrlExtension(fileUrl),
8526
+ "content-type": CONTENT_TYPE$1.fromUrlExtension(fileUrl),
8527
8527
  "content-length": fileStat.size,
8528
8528
  },
8529
8529
  body: fileUrlToReadableStream(fileUrl),
@@ -11749,6 +11749,207 @@ const watchSourceFiles = (
11749
11749
 
11750
11750
  const jsenvCoreDirectoryUrl = new URL("../", import.meta.url);
11751
11751
 
11752
+ const mediaTypeInfos = {
11753
+ "application/json": {
11754
+ extensions: ["json", "map"],
11755
+ isTextual: true,
11756
+ },
11757
+ "application/importmap+json": {
11758
+ extensions: ["importmap"],
11759
+ isTextual: true,
11760
+ },
11761
+ "application/manifest+json": {
11762
+ extensions: ["webmanifest"],
11763
+ isTextual: true,
11764
+ },
11765
+ "application/octet-stream": {},
11766
+ "application/pdf": {
11767
+ extensions: ["pdf"],
11768
+ },
11769
+ "application/xml": {
11770
+ extensions: ["xml"],
11771
+ isTextual: true,
11772
+ },
11773
+ "application/x-gzip": {
11774
+ extensions: ["gz"],
11775
+ },
11776
+ "application/yaml": {
11777
+ extensions: ["yml", "yaml"],
11778
+ isTextual: true,
11779
+ },
11780
+ "application/wasm": {
11781
+ extensions: ["wasm"],
11782
+ },
11783
+ "application/zip": {
11784
+ extensions: ["zip"],
11785
+ },
11786
+ "audio/basic": {
11787
+ extensions: ["au", "snd"],
11788
+ },
11789
+ "audio/mpeg": {
11790
+ extensions: ["mpga", "mp2", "mp2a", "mp3", "m2a", "m3a"],
11791
+ },
11792
+ "audio/midi": {
11793
+ extensions: ["midi", "mid", "kar", "rmi"],
11794
+ },
11795
+ "audio/mp4": {
11796
+ extensions: ["m4a", "mp4a"],
11797
+ },
11798
+ "audio/ogg": {
11799
+ extensions: ["oga", "ogg", "spx"],
11800
+ },
11801
+ "audio/webm": {
11802
+ extensions: ["weba"],
11803
+ },
11804
+ "audio/x-wav": {
11805
+ extensions: ["wav"],
11806
+ },
11807
+ "font/ttf": {
11808
+ extensions: ["ttf"],
11809
+ },
11810
+ "font/woff": {
11811
+ extensions: ["woff"],
11812
+ },
11813
+ "font/woff2": {
11814
+ extensions: ["woff2"],
11815
+ },
11816
+ "image/png": {
11817
+ extensions: ["png"],
11818
+ },
11819
+ "image/gif": {
11820
+ extensions: ["gif"],
11821
+ },
11822
+ "image/jpeg": {
11823
+ extensions: ["jpg"],
11824
+ },
11825
+ "image/svg+xml": {
11826
+ extensions: ["svg", "svgz"],
11827
+ isTextual: true,
11828
+ },
11829
+ "text/plain": {
11830
+ extensions: ["txt"],
11831
+ isTextual: true,
11832
+ },
11833
+ "text/html": {
11834
+ extensions: ["html"],
11835
+ isTextual: true,
11836
+ },
11837
+ "text/css": {
11838
+ extensions: ["css"],
11839
+ isTextual: true,
11840
+ },
11841
+ "text/javascript": {
11842
+ extensions: ["js", "cjs", "mjs", "ts", "jsx", "tsx"],
11843
+ isTextual: true,
11844
+ },
11845
+ "text/markdown": {
11846
+ extensions: ["md", "mdx"],
11847
+ isTextual: true,
11848
+ },
11849
+ "text/x-sass": {
11850
+ extensions: ["sass"],
11851
+ isTextual: true,
11852
+ },
11853
+ "text/x-scss": {
11854
+ extensions: ["scss"],
11855
+ isTextual: true,
11856
+ },
11857
+ "text/cache-manifest": {
11858
+ extensions: ["appcache"],
11859
+ },
11860
+ "video/mp4": {
11861
+ extensions: ["mp4", "mp4v", "mpg4"],
11862
+ },
11863
+ "video/mpeg": {
11864
+ extensions: ["mpeg", "mpg", "mpe", "m1v", "m2v"],
11865
+ },
11866
+ "video/ogg": {
11867
+ extensions: ["ogv"],
11868
+ },
11869
+ "video/webm": {
11870
+ extensions: ["webm"],
11871
+ },
11872
+ };
11873
+
11874
+ const CONTENT_TYPE = {
11875
+ parse: (string) => {
11876
+ const [mediaType, charset] = string.split(";");
11877
+ return { mediaType: normalizeMediaType(mediaType), charset };
11878
+ },
11879
+
11880
+ stringify: ({ mediaType, charset }) => {
11881
+ if (charset) {
11882
+ return `${mediaType};${charset}`;
11883
+ }
11884
+ return mediaType;
11885
+ },
11886
+
11887
+ asMediaType: (value) => {
11888
+ if (typeof value === "string") {
11889
+ return CONTENT_TYPE.parse(value).mediaType;
11890
+ }
11891
+ if (typeof value === "object") {
11892
+ return value.mediaType;
11893
+ }
11894
+ return null;
11895
+ },
11896
+
11897
+ isJson: (value) => {
11898
+ const mediaType = CONTENT_TYPE.asMediaType(value);
11899
+ return (
11900
+ mediaType === "application/json" ||
11901
+ /^application\/\w+\+json$/.test(mediaType)
11902
+ );
11903
+ },
11904
+
11905
+ isTextual: (value) => {
11906
+ const mediaType = CONTENT_TYPE.asMediaType(value);
11907
+ if (mediaType.startsWith("text/")) {
11908
+ return true;
11909
+ }
11910
+ const mediaTypeInfo = mediaTypeInfos[mediaType];
11911
+ if (mediaTypeInfo && mediaTypeInfo.isTextual) {
11912
+ return true;
11913
+ }
11914
+ // catch things like application/manifest+json, application/importmap+json
11915
+ if (/^application\/\w+\+json$/.test(mediaType)) {
11916
+ return true;
11917
+ }
11918
+ return false;
11919
+ },
11920
+
11921
+ isBinary: (value) => !CONTENT_TYPE.isTextual(value),
11922
+
11923
+ asFileExtension: (value) => {
11924
+ const mediaType = CONTENT_TYPE.asMediaType(value);
11925
+ const mediaTypeInfo = mediaTypeInfos[mediaType];
11926
+ return mediaTypeInfo ? `.${mediaTypeInfo.extensions[0]}` : "";
11927
+ },
11928
+
11929
+ fromUrlExtension: (url) => {
11930
+ const { pathname } = new URL(url);
11931
+ const extensionWithDot = extname(pathname);
11932
+ if (!extensionWithDot || extensionWithDot === ".") {
11933
+ return "application/octet-stream";
11934
+ }
11935
+ const extension = extensionWithDot.slice(1);
11936
+ const mediaTypeFound = Object.keys(mediaTypeInfos).find((mediaType) => {
11937
+ const mediaTypeInfo = mediaTypeInfos[mediaType];
11938
+ return (
11939
+ mediaTypeInfo.extensions && mediaTypeInfo.extensions.includes(extension)
11940
+ );
11941
+ });
11942
+ return mediaTypeFound || "application/octet-stream";
11943
+ },
11944
+ };
11945
+
11946
+ const normalizeMediaType = (value) => {
11947
+ if (value === "application/javascript") {
11948
+ return "text/javascript";
11949
+ }
11950
+ return value;
11951
+ };
11952
+
11752
11953
  const jsenvPluginHtmlSyntaxErrorFallback = () => {
11753
11954
  const htmlSyntaxErrorFileUrl = new URL(
11754
11955
  "./html/html_syntax_error.html",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "39.14.2",
3
+ "version": "39.14.3",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -73,7 +73,7 @@
73
73
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
74
74
  "@jsenv/abort": "4.3.0",
75
75
  "@jsenv/ast": "6.5.2",
76
- "@jsenv/filesystem": "4.13.4",
76
+ "@jsenv/filesystem": "4.13.5",
77
77
  "@jsenv/humanize": "1.2.8",
78
78
  "@jsenv/importmap": "1.2.1",
79
79
  "@jsenv/integrity": "0.0.2",
@@ -82,13 +82,13 @@
82
82
  "@jsenv/plugin-bundling": "2.7.25",
83
83
  "@jsenv/plugin-minification": "1.5.13",
84
84
  "@jsenv/plugin-supervisor": "1.6.6",
85
- "@jsenv/plugin-transpilation": "1.4.95",
86
- "@jsenv/runtime-compat": "1.3.1",
87
- "@jsenv/server": "15.5.2",
85
+ "@jsenv/plugin-transpilation": "1.4.96",
86
+ "@jsenv/runtime-compat": "1.3.2",
87
+ "@jsenv/server": "15.5.3",
88
88
  "@jsenv/sourcemap": "1.2.30",
89
89
  "@jsenv/url-meta": "8.5.3",
90
90
  "@jsenv/urls": "2.6.0",
91
- "@jsenv/utils": "2.1.2",
91
+ "@jsenv/utils": "2.1.3",
92
92
  "string-width": "7.2.0"
93
93
  },
94
94
  "devDependencies": {