@@ -83,14 +83,22 @@ export async function populateNpmCache(root: string, path: string): Promise<stri
83
83
let promise = npmRequests . get ( outputPath ) ;
84
84
if ( promise ) return promise ; // coalesce concurrent requests
85
85
promise = ( async ( ) => {
86
- const specifier = extractNpmSpecifier ( path ) ;
86
+ let specifier = extractNpmSpecifier ( path ) ;
87
+ const s = parseNpmSpecifier ( specifier ) ;
88
+ // https://github.com/sql-js/sql.js/issues/284
89
+ if ( s . name === "sql.js" && s . path === "+esm" ) {
90
+ specifier = formatNpmSpecifier ( { ...s , path : "dist/sql-wasm.js" } ) ;
91
+ }
87
92
const href = `https://cdn.jsdelivr.net/npm/${ specifier } ` ;
88
93
console . log ( `npm:${ specifier } ${ faint ( "→" ) } ${ outputPath } ` ) ;
89
94
const response = await fetch ( href ) ;
90
95
if ( ! response . ok ) throw new Error ( `unable to fetch: ${ href } ` ) ;
91
96
await mkdir ( dirname ( outputPath ) , { recursive : true } ) ;
92
97
if ( / ^ a p p l i c a t i o n \/ j a v a s c r i p t ( ; | $ ) / i. test ( response . headers . get ( "content-type" ) ! ) ) {
93
- const source = await response . text ( ) ;
98
+ let source = await response . text ( ) ;
99
+ if ( s . name === "sql.js" && s . path === "+esm" ) {
100
+ source = "var module;\n" + source + "\nexport default initSqlJs;" ;
101
+ }
94
102
const resolver = await getDependencyResolver ( root , path , source ) ;
95
103
await writeFile ( outputPath , rewriteNpmImports ( source , resolver ) , "utf-8" ) ;
96
104
} else {
0 commit comments