|
7 | 7 | import * as JSON from '@ungap/structured-clone/json'; |
8 | 8 | import coincident from 'coincident/window'; |
9 | 9 |
|
10 | | -import { absoluteURL, assign, create, createFunction, createOverload, createResolved, dispatch, entries, isCSS, js_modules } from '../utils.js'; |
11 | | -import { base } from '../interpreter/_utils.js'; |
| 10 | +import { assign, create, createFunction, createOverload, createResolved, dispatch } from '../utils.js'; |
| 11 | +import createJSModules from './js_modules.js'; |
12 | 12 | import { configs, registry } from '../interpreters.js'; |
13 | 13 | import { getRuntime, getRuntimeID } from '../loader.js'; |
14 | 14 | import { patch, polluteJS, js as jsHooks, code as codeHooks } from '../hooks.js'; |
@@ -136,28 +136,14 @@ add('message', ({ data: { options, config: baseURL, code, hooks } }) => { |
136 | 136 | const { CustomEvent, document } = window; |
137 | 137 | const element = id && document.getElementById(id) || null; |
138 | 138 | const notify = kind => dispatch(element, custom || type, kind, true, CustomEvent); |
| 139 | + const JSModules = createJSModules(window, sync, mainModules); |
139 | 140 |
|
140 | 141 | let target = ''; |
141 | 142 |
|
142 | | - // set the `xworker` global reference once |
| 143 | + details.registerJSModule(interpreter, 'polyscript.js_modules', JSModules); |
143 | 144 | details.registerJSModule(interpreter, 'polyscript', { |
144 | 145 | xworker, |
145 | | - js_modules: new Proxy(globalThis[js_modules], { |
146 | | - get(map, name) { |
147 | | - if (!map.has(name) && mainModules) { |
148 | | - for (let [source, module] of entries(mainModules)) { |
149 | | - if (module !== name) continue; |
150 | | - source = absoluteURL(source, base.get(mainModules)); |
151 | | - if (isCSS(source)) sync.importCSS(source); |
152 | | - else { |
153 | | - sync.importJS(source, name); |
154 | | - map.set(name, window[js_modules].get(name)); |
155 | | - } |
156 | | - } |
157 | | - } |
158 | | - return map.get(name); |
159 | | - } |
160 | | - }), |
| 146 | + js_modules: JSModules, |
161 | 147 | get target() { |
162 | 148 | if (!target && element) { |
163 | 149 | if (tag === 'SCRIPT') { |
|
0 commit comments