@@ -15,6 +15,17 @@ import {getFeature, getFeatureReferenceMap, getStringLiteralValue, isStringLiter
15
15
type ImportNode = ImportDeclaration | ImportExpression ;
16
16
type ExportNode = ExportAllDeclaration | ExportNamedDeclaration ;
17
17
18
+ let npmVersionResolutionEnabled = true ;
19
+ let remoteModulePreloadEnabled = true ;
20
+
21
+ export function enableNpmVersionResolution ( enabled = true ) {
22
+ npmVersionResolutionEnabled = enabled ;
23
+ }
24
+
25
+ export function enableRemoteModulePreload ( enabled = true ) {
26
+ remoteModulePreloadEnabled = enabled ;
27
+ }
28
+
18
29
export interface ImportsAndFeatures {
19
30
imports : ImportReference [ ] ;
20
31
features : Feature [ ] ;
@@ -305,6 +316,7 @@ function formatNpmSpecifier({name, range, path}: {name: string; range?: string;
305
316
const fetchCache = new Map < string , Promise < { headers : Headers ; body : any } > > ( ) ;
306
317
307
318
async function cachedFetch ( href : string ) : Promise < { headers : Headers ; body : any } > {
319
+ if ( ! remoteModulePreloadEnabled ) throw new Error ( "remote module preload is not enabled" ) ;
308
320
let promise = fetchCache . get ( href ) ;
309
321
if ( promise ) return promise ;
310
322
promise = ( async ( ) => {
@@ -320,6 +332,7 @@ async function cachedFetch(href: string): Promise<{headers: Headers; body: any}>
320
332
}
321
333
322
334
async function resolveNpmVersion ( specifier : string ) : Promise < string > {
335
+ if ( ! npmVersionResolutionEnabled ) throw new Error ( "npm version resolution is not enabled" ) ;
323
336
const { name, range} = parseNpmSpecifier ( specifier ) ; // ignore path
324
337
specifier = formatNpmSpecifier ( { name, range} ) ;
325
338
const search = range ? `?specifier=${ range } ` : "" ;
@@ -396,6 +409,7 @@ const integrityCache = new Map<string, string>();
396
409
* precomputes the subresource integrity hash for each fetched module.
397
410
*/
398
411
export async function resolveModulePreloads ( hrefs : Set < string > ) : Promise < void > {
412
+ if ( ! remoteModulePreloadEnabled ) return ;
399
413
let resolve : ( ) => void ;
400
414
const visited = new Set < string > ( ) ;
401
415
const queue = new Set < Promise < void > > ( ) ;
0 commit comments