@@ -43,7 +43,7 @@ import { LockResolutions } from "./install/lock.js";
43
43
import { getDefaultProviderStrings , type Provider } from "./providers/index.js" ;
44
44
import * as nodemodules from "./providers/nodemodules.js" ;
45
45
import { Resolver } from "./trace/resolver.js" ;
46
- import { getMaybeWrapperUrl } from ' ./common/wrapper.js' ;
46
+ import { getMaybeWrapperUrl } from " ./common/wrapper.js" ;
47
47
48
48
// Utility exports for users:
49
49
export { analyzeHtml } ;
@@ -297,7 +297,7 @@ export interface GeneratorOptions {
297
297
* Disabled by default.
298
298
*/
299
299
commonJS ?: boolean ;
300
-
300
+
301
301
/**
302
302
* Support tracing TypeScript dependencies when generating the import map.
303
303
* Disabled by default.
@@ -311,7 +311,14 @@ export interface GeneratorOptions {
311
311
}
312
312
313
313
export interface ModuleAnalysis {
314
- format : "commonjs" | "esm" | "system" | "json" | "css" | "typescript" | "wasm" ;
314
+ format :
315
+ | "commonjs"
316
+ | "esm"
317
+ | "system"
318
+ | "json"
319
+ | "css"
320
+ | "typescript"
321
+ | "wasm" ;
315
322
staticDeps : string [ ] ;
316
323
dynamicDeps : string [ ] ;
317
324
cjsLazyDeps : string [ ] | null ;
@@ -417,11 +424,9 @@ export class Generator {
417
424
timeout : 10000 ,
418
425
...fetchOptions ,
419
426
headers : { "Accept-Encoding" : "gzip, br" } ,
420
- }
421
- if ( cache === "offline" )
422
- fetchOpts . cache = "force-cache"
423
- else if ( ! cache )
424
- fetchOpts . cache = "no-store" ;
427
+ } ;
428
+ if ( cache === "offline" ) fetchOpts . cache = "force-cache" ;
429
+ else if ( ! cache ) fetchOpts . cache = "no-store" ;
425
430
426
431
// Default logic for the mapUrl, baseUrl and rootUrl:
427
432
if ( mapUrl && ! baseUrl ) {
@@ -461,7 +466,14 @@ export class Generator {
461
466
this . integrity = integrity ;
462
467
463
468
// Initialise the resolver:
464
- const resolver = new Resolver ( { env, log, fetchOpts, preserveSymlinks : true , traceCjs : commonJS , traceTs : typeScript } ) ;
469
+ const resolver = new Resolver ( {
470
+ env,
471
+ log,
472
+ fetchOpts,
473
+ preserveSymlinks : true ,
474
+ traceCjs : commonJS ,
475
+ traceTs : typeScript ,
476
+ } ) ;
465
477
if ( customProviders ) {
466
478
for ( const provider of Object . keys ( customProviders ) ) {
467
479
resolver . addCustomProvider ( provider , customProviders [ provider ] ) ;
@@ -495,16 +507,15 @@ export class Generator {
495
507
providers,
496
508
ignore,
497
509
resolutions,
498
- commonJS
510
+ commonJS,
499
511
} ,
500
512
log ,
501
513
resolver
502
514
) ;
503
515
504
516
// Reconstruct constraints and locks from the input map:
505
517
this . map = new ImportMap ( { mapUrl : this . mapUrl , rootUrl : this . rootUrl } ) ;
506
- if ( ! integrity )
507
- this . map . integrity = { } ;
518
+ if ( ! integrity ) this . map . integrity = { } ;
508
519
if ( inputMap ) this . addMappings ( inputMap ) ;
509
520
}
510
521
@@ -669,9 +680,7 @@ export class Generator {
669
680
" Generated by @jspm/generator - https://github.com/jspm/generator " ;
670
681
if ( typeof htmlUrl === "string" ) htmlUrl = new URL ( htmlUrl ) ;
671
682
if ( this . installCnt !== 0 )
672
- throw new JspmError (
673
- "htmlInject cannot run alongside other install ops"
674
- ) ;
683
+ throw new JspmError ( "htmlInject cannot run alongside other install ops" ) ;
675
684
676
685
const analysis = analyzeHtml ( html , htmlUrl ) ;
677
686
@@ -696,13 +705,16 @@ export class Generator {
696
705
) ;
697
706
}
698
707
699
- const preloadDeps = preload === "all" ? [ ...new Set ( [ ...staticDeps , ...dynamicDeps ] ) ] : staticDeps ;
708
+ const preloadDeps =
709
+ preload === "all"
710
+ ? [ ...new Set ( [ ...staticDeps , ...dynamicDeps ] ) ]
711
+ : staticDeps ;
700
712
701
713
const newlineTab = ! whitespace
702
714
? analysis . newlineTab
703
715
: analysis . newlineTab . includes ( "\n" )
704
- ? analysis . newlineTab
705
- : "\n" + analysis . newlineTab ;
716
+ ? analysis . newlineTab
717
+ : "\n" + analysis . newlineTab ;
706
718
707
719
const replacer = new Replacer ( html ) ;
708
720
@@ -740,7 +752,10 @@ export class Generator {
740
752
) ) + "dist/es-module-shims.js" ;
741
753
742
754
// detect esmsUrl as a wrapper URL
743
- esmsUrl = await getMaybeWrapperUrl ( esmsUrl , this . traceMap . resolver . fetchOpts ) ;
755
+ esmsUrl = await getMaybeWrapperUrl (
756
+ esmsUrl ,
757
+ this . traceMap . resolver . fetchOpts
758
+ ) ;
744
759
745
760
if ( htmlUrl || rootUrl )
746
761
esmsUrl = relativeUrl (
@@ -749,12 +764,17 @@ export class Generator {
749
764
! ! rootUrl
750
765
) ;
751
766
752
- esms = `<script async src="${ esmsUrl } " crossorigin="anonymous"${ integrity
753
- ? ` integrity="${ getIntegrity (
754
- new Uint8Array ( await ( await fetch ( esmsUrl , this . traceMap . resolver . fetchOpts ) ) . arrayBuffer ( ) )
755
- ) } "`
756
- : ""
757
- } ></script>${ newlineTab } `;
767
+ esms = `<script async src="${ esmsUrl } " crossorigin="anonymous"${
768
+ integrity
769
+ ? ` integrity="${ getIntegrity (
770
+ new Uint8Array (
771
+ await (
772
+ await fetch ( esmsUrl , this . traceMap . resolver . fetchOpts )
773
+ ) . arrayBuffer ( )
774
+ )
775
+ ) } "`
776
+ : ""
777
+ } ></script>${ newlineTab } `;
758
778
759
779
if ( analysis . esModuleShims )
760
780
replacer . remove (
@@ -774,14 +794,11 @@ export class Generator {
774
794
for ( let dep of preloadDeps . sort ( ) ) {
775
795
if ( first || whitespace ) preloads += newlineTab ;
776
796
if ( first ) first = false ;
777
- preloads += `<link rel="modulepreload" href="${ rootUrl || htmlUrl
778
- ? relativeUrl (
779
- new URL ( dep ) ,
780
- new URL ( rootUrl || htmlUrl ) ,
781
- ! ! rootUrl
782
- )
783
- : dep
784
- } " />`;
797
+ preloads += `<link rel="modulepreload" href="${
798
+ rootUrl || htmlUrl
799
+ ? relativeUrl ( new URL ( dep ) , new URL ( rootUrl || htmlUrl ) , ! ! rootUrl )
800
+ : dep
801
+ } " />`;
785
802
}
786
803
}
787
804
@@ -800,17 +817,17 @@ export class Generator {
800
817
analysis . map . start ,
801
818
analysis . map . end ,
802
819
( comment ? "<!--" + comment + "-->" + newlineTab : "" ) +
803
- esms +
804
- '<script type="importmap">' +
805
- ( whitespace ? newlineTab : "" ) +
806
- JSON . stringify ( map , null , whitespace ? 2 : 0 ) . replace (
807
- / \n / g,
808
- newlineTab
809
- ) +
810
- ( whitespace ? newlineTab : "" ) +
811
- "</script>" +
812
- preloads +
813
- ( analysis . map . newScript ? newlineTab : "" )
820
+ esms +
821
+ '<script type="importmap">' +
822
+ ( whitespace ? newlineTab : "" ) +
823
+ JSON . stringify ( map , null , whitespace ? 2 : 0 ) . replace (
824
+ / \n / g,
825
+ newlineTab
826
+ ) +
827
+ ( whitespace ? newlineTab : "" ) +
828
+ "</script>" +
829
+ preloads +
830
+ ( analysis . map . newScript ? newlineTab : "" )
814
831
) ;
815
832
816
833
return replacer . source ;
@@ -850,7 +867,6 @@ export class Generator {
850
867
install ?: string | Install | ( string | Install ) [ ] ,
851
868
mode ?: InstallMode
852
869
) : Promise < void | { staticDeps : string [ ] ; dynamicDeps : string [ ] } > {
853
-
854
870
// If there are no arguments, then we reinstall all the top-level locks:
855
871
if ( install === null || install === undefined ) {
856
872
await this . traceMap . processInputMap ;
@@ -1097,7 +1113,8 @@ export class Generator {
1097
1113
}
1098
1114
this . traceMap . pins = pins ;
1099
1115
if ( -- this . installCnt === 0 ) {
1100
- const { staticDeps, dynamicDeps, map } = await this . traceMap . finishInstall ( this . traceMap . pins , this . integrity ) ;
1116
+ const { staticDeps, dynamicDeps, map } =
1117
+ await this . traceMap . finishInstall ( this . traceMap . pins , this . integrity ) ;
1101
1118
this . map = map ;
1102
1119
return { staticDeps, dynamicDeps } ;
1103
1120
}
@@ -1112,7 +1129,7 @@ export class Generator {
1112
1129
if ( typeof mapUrl === "string" ) mapUrl = new URL ( mapUrl , this . baseUrl ) ;
1113
1130
if ( typeof rootUrl === "string" ) rootUrl = new URL ( rootUrl , this . baseUrl ) ;
1114
1131
if ( ! Array . isArray ( pins ) ) pins = [ pins ] ;
1115
- if ( typeof integrity !== ' boolean' ) integrity = this . integrity ;
1132
+ if ( typeof integrity !== " boolean" ) integrity = this . integrity ;
1116
1133
if ( this . installCnt ++ !== 0 )
1117
1134
throw new JspmError ( `Cannot run extract map during installs` ) ;
1118
1135
this . traceMap . startInstall ( ) ;
@@ -1374,10 +1391,12 @@ async function installToTarget(
1374
1391
( install . subpath !== "." && ! install . subpath . startsWith ( "./" ) ) )
1375
1392
)
1376
1393
throw new Error (
1377
- `Install subpath "${ install . subpath
1378
- } " must be a string equal to "." or starting with "./".${ typeof install . subpath === "string"
1379
- ? `\nTry setting the subpath to "./${ install . subpath } "`
1380
- : ""
1394
+ `Install subpath "${
1395
+ install . subpath
1396
+ } " must be a string equal to "." or starting with "./".${
1397
+ typeof install . subpath === "string"
1398
+ ? `\nTry setting the subpath to "./${ install . subpath } "`
1399
+ : ""
1381
1400
} `
1382
1401
) ;
1383
1402
0 commit comments