@@ -33,9 +33,11 @@ let currentMockVersion = 0;
3333// assert(namespace1 === namespace2);
3434// ```
3535
36-
37- export async function initialize ( { port } ) {
38- port . on ( 'message' , ( { mockVersion, resolved, exports } ) => {
36+ /** @type {string } */
37+ let mainImportURL ;
38+ export async function initialize ( data ) {
39+ mainImportURL = data . mainImportURL ;
40+ data . port . on ( 'message' , ( { mockVersion, resolved, exports } ) => {
3941 currentMockVersion = mockVersion ;
4042 mockedModuleExports . set ( resolved , exports ) ;
4143 } ) ;
@@ -75,7 +77,6 @@ export async function load(url, context, defaultLoad) {
7577 return defaultLoad ( url , context ) ;
7678}
7779
78- const mainImportURL = new URL ( './mock.mjs' , import . meta. url ) ;
7980/**
8081 * Generate the source code for a mocked module.
8182 * @param {string } encodedTargetURL the module being mocked
@@ -86,7 +87,7 @@ function generateModule(encodedTargetURL) {
8687 decodeURIComponent ( encodedTargetURL )
8788 ) ;
8889 let body = [
89- `import { mockedModules } from ' ${ mainImportURL } ' ;` ,
90+ `import { mockedModules } from ${ JSON . stringify ( mainImportURL ) } ;` ,
9091 'export {};' ,
9192 'let mapping = {__proto__: null};'
9293 ] ;
0 commit comments