File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11require . resolve = resolve ;
22
3- const cache = new WeakMap < object , object > ( ) ;
3+ const cache = new WeakMap < object , unknown > ( ) ;
44
55export function require ( ...specifiers : unknown [ ] ) : unknown {
66 return specifiers . length === 1
@@ -36,10 +36,16 @@ function resolve(_specifier: unknown): string {
3636 return `https://cdn.jsdelivr.net/npm/${ name } ${ range } ${ path + ( isFile ( path ) || isDirectory ( path ) ? "" : "/+esm" ) } ` ;
3737}
3838
39+ /** Promote exclusive default export to module. */
40+ function defaultify ( module : object ) : unknown {
41+ for ( const key in module ) if ( key !== "default" ) return { ...module } ; // any named export
42+ return "default" in module ? module . default : { ...module } ; // promote exclusive default export
43+ }
44+
3945/** Allow mutation of required modules while maintaining a canonical instance; ugly! */
40- function objectify ( module : object ) : object {
46+ function objectify ( module : object ) : unknown {
4147 let object = cache . get ( module ) ;
42- if ( ! object ) cache . set ( module , ( object = { ... module } ) ) ;
48+ if ( ! object ) cache . set ( module , ( object = defaultify ( module ) ) ) ;
4349 return object ;
4450}
4551
You can’t perform that action at this time.
0 commit comments