@@ -46,10 +46,9 @@ formatProviders.set('cjs', async (url) => {
4646// through normal resolution
4747formatProviders . set ( 'native' , async ( url ) => {
4848 const ctx = createDynamicModule ( [ 'default' ] , url , ( reflect ) => {
49- debug ( `Loading CJSModule ${ url . pathname } ` ) ;
50- const CJSModule = require ( 'module' ) ;
51- const pathname = internalURLModule . getPathFromURL ( url ) ;
52- ctx . reflect . exports . default . set ( CJSModule . _load ( pathname ) ) ;
49+ debug ( `Loading NativeModule ${ url . pathname } ` ) ;
50+ const exports = NativeModule . require ( url . pathname ) ;
51+ reflect . exports . default . set ( exports ) ;
5352 } ) ;
5453 return ctx . module ;
5554} ) ;
@@ -66,31 +65,24 @@ formatProviders.set('json', async (url) => {
6665
6766// TODO: make this native binary handling only
6867formatProviders . set ( 'binary' , async ( url ) => {
69- const source = `${ await asyncReadFile ( url ) } ` ;
7068 const ctx = createDynamicModule ( [ 'default' ] , url , ( reflect ) => {
71- debug ( `Loading JSONModule ${ url . pathname } ` ) ;
72- const json = JSON . parse ( source ) ;
73- ctx . reflect . exports . default . set ( json ) ;
69+ debug ( `Loading CJSModule ${ url . pathname } ` ) ;
70+ const CJSModule = require ( 'module' ) ;
71+ const pathname = internalURLModule . getPathFromURL ( url ) ;
72+ ctx . reflect . exports . default . set ( CJSModule . _load ( pathname ) ) ;
7473 } ) ;
7574 return ctx . module ;
7675} ) ;
7776
78- function normalizeBaseURL ( baseURLOrString ) {
79- if ( baseURLOrString instanceof URL ) return baseURLOrString ;
80- if ( typeof baseURLOrString === 'string' ) return new URL ( baseURLOrString ) ;
81- return undefined ;
82- }
83-
8477exports . resolve = resolve ;
85- function resolve ( specifier , parentURLOrString ) {
78+ function resolve ( specifier , parentURL ) {
8679 if ( NativeModule . nonInternalExists ( specifier ) ) {
8780 return {
8881 url : new URL ( `node:${ specifier } ` ) ,
8982 format : 'native'
9083 } ;
9184 }
9285
93- const parentURL = normalizeBaseURL ( parentURLOrString ) ;
9486 let url = search ( specifier , parentURL ) ;
9587
9688 if ( url . protocol !== 'file:' ) {
0 commit comments