33// https://raw.githubusercontent.com/node-loader/
44//
55
6- import path from " path" ;
7- import url from " url" ;
8- import { promises as fs } from "fs" ;
6+ import path from ' path' ;
7+ import url from ' url' ;
8+ import { promises as fs } from 'fs' ;
99
10- export const IMPORT_MAP_FILE_NAME = " node.importmap" ;
10+ export const IMPORT_MAP_FILE_NAME = ' node.importmap' ;
1111
1212const baseURL = url . pathToFileURL ( process . cwd ( ) ) + path . sep ;
1313
@@ -25,7 +25,7 @@ export function resolveSpecifier(importMap, specifier, parentURL) {
2525 for ( let scopePrefix in importMap . scopes ) {
2626 if (
2727 scopePrefix === currentBaseURL ||
28- ( scopePrefix . endsWith ( "/" ) && currentBaseURL . startsWith ( scopePrefix ) )
28+ ( scopePrefix . endsWith ( '/' ) && currentBaseURL . startsWith ( scopePrefix ) )
2929 ) {
3030 const scopeImportsMatch = resolveImportsMatch (
3131 normalizedSpecifier ,
@@ -61,7 +61,7 @@ function resolveImportsMatch(normalizedSpecifier, specifierMap) {
6161 }
6262 return resolutionResult ;
6363 } else if (
64- specifierKey . endsWith ( "/" ) &&
64+ specifierKey . endsWith ( '/' ) &&
6565 normalizedSpecifier . startsWith ( specifierKey )
6666 ) {
6767 if ( resolutionResult === null ) {
@@ -94,7 +94,7 @@ export function resolveAndComposeImportMap(parsed) {
9494 let sortedAndNormalizedImports = { } ;
9595
9696 // Step 4
97- if ( parsed . hasOwnProperty ( " imports" ) ) {
97+ if ( parsed . hasOwnProperty ( ' imports' ) ) {
9898 // Step 4.1
9999 if ( ! isPlainObject ( parsed . imports ) ) {
100100 throw Error ( `Invalid import map - "imports" property must be an object` ) ;
@@ -111,7 +111,7 @@ export function resolveAndComposeImportMap(parsed) {
111111 let sortedAndNormalizedScopes = { } ;
112112
113113 // Step 6
114- if ( parsed . hasOwnProperty ( " scopes" ) ) {
114+ if ( parsed . hasOwnProperty ( ' scopes' ) ) {
115115 // Step 6.1
116116 if ( ! isPlainObject ( parsed . scopes ) ) {
117117 throw Error ( `Invalid import map - "scopes" property must be an object` ) ;
@@ -123,13 +123,13 @@ export function resolveAndComposeImportMap(parsed) {
123123
124124 // Step 7
125125 const invalidKeys = Object . keys ( parsed ) . filter (
126- ( key ) => key !== " imports" && key !== " scopes"
126+ ( key ) => key !== ' imports' && key !== ' scopes'
127127 ) ;
128128 if ( invalidKeys . length > 0 ) {
129129 console . warn (
130130 `Invalid top-level key${
131- invalidKeys . length > 0 ? "s" : ""
132- } in import map - ${ invalidKeys . join ( ", " ) } `
131+ invalidKeys . length > 0 ? 's' : ''
132+ } in import map - ${ invalidKeys . join ( ', ' ) } `
133133 ) ;
134134 }
135135
@@ -161,7 +161,7 @@ function sortAndNormalizeSpecifierMap(map, baseURL) {
161161 continue ;
162162 }
163163
164- if ( specifierKey . endsWith ( "/" ) && ! addressURL . endsWith ( "/" ) ) {
164+ if ( specifierKey . endsWith ( '/' ) && ! addressURL . endsWith ( '/' ) ) {
165165 console . warn (
166166 `Invalid URL address for import map specifier '${ specifierKey } ' - since the specifier ends in slash, so must the address`
167167 ) ;
@@ -177,7 +177,7 @@ function sortAndNormalizeSpecifierMap(map, baseURL) {
177177
178178// https://wicg.github.io/import-maps/#normalize-a-specifier-key
179179function normalizeSpecifierKey ( key ) {
180- if ( key === "" ) {
180+ if ( key === '' ) {
181181 console . warn ( `Specifier keys in import maps may not be the empty string` ) ;
182182 return null ;
183183 }
@@ -188,9 +188,9 @@ function normalizeSpecifierKey(key) {
188188// https://wicg.github.io/import-maps/#parse-a-url-like-import-specifier
189189function parseURLLikeSpecifier ( specifier , baseURL ) {
190190 const useBaseUrlAsParent =
191- specifier . startsWith ( "/" ) ||
192- specifier . startsWith ( "./" ) ||
193- specifier . startsWith ( " ../" ) ;
191+ specifier . startsWith ( '/' ) ||
192+ specifier . startsWith ( './' ) ||
193+ specifier . startsWith ( ' ../' ) ;
194194
195195 try {
196196 return new URL ( specifier , useBaseUrlAsParent ? baseURL : undefined ) . href ;
@@ -236,21 +236,23 @@ function isPlainObject(obj) {
236236
237237// ---
238238
239-
240239let importMapPromise = getImportMapPromise ( ) ;
241240
242241export async function resolve ( specifier , context , defaultResolve ) {
243242 const { parentURL = null } = context ;
244243 const importMap = await importMapPromise ;
245244 let importMapUrl = resolveSpecifier ( importMap , specifier , parentURL ) ;
246245
247- if ( importMapUrl ?. startsWith ( 'http://' ) || importMapUrl ?. startsWith ( 'https://' ) ) {
246+ if (
247+ importMapUrl ?. startsWith ( 'http://' ) ||
248+ importMapUrl ?. startsWith ( 'https://' )
249+ ) {
248250 importMapUrl = await cacheBundle ( importMapUrl ) ;
249251 }
250252
251253 const r = defaultResolve ( importMapUrl ?? specifier , context , defaultResolve ) ;
252254
253- return r . then ( r => {
255+ return r . then ( ( r ) => {
254256 return { ...r , format : 'module' } ;
255257 } ) ;
256258}
@@ -259,7 +261,7 @@ async function cacheBundle(importMapUrl) {
259261 const fileName = importMapUrl . replace ( / [ ^ a - z A - Z 0 - 9 . ] / g, '_' ) ;
260262 const filePath = path . join ( './cache' , fileName ) ;
261263
262- if ( ! await exists ( filePath ) ) {
264+ if ( ! ( await exists ( filePath ) ) ) {
263265 const res = await fetch ( importMapUrl ) ;
264266 const source = await res . text ( ) ;
265267 await ensureCacheFolder ( ) ;
@@ -271,7 +273,7 @@ async function cacheBundle(importMapUrl) {
271273}
272274
273275async function ensureCacheFolder ( ) {
274- if ( ! await exists ( './cache' ) ) {
276+ if ( ! ( await exists ( './cache' ) ) ) {
275277 await fs . mkdir ( './cache' ) ;
276278 }
277279}
@@ -321,7 +323,6 @@ function emptyMap() {
321323 return { imports : { } , scopes : { } } ;
322324}
323325
324-
325326async function exists ( path ) {
326327 try {
327328 await fs . access ( path ) ;
0 commit comments