From da93e3c51d35df938e33cb695d23af09fa6ad9a6 Mon Sep 17 00:00:00 2001 From: Hermann Rolfes Date: Thu, 30 Nov 2023 15:50:10 +0100 Subject: [PATCH] Fix repl/importmap.js (#64) --- repl/importmap.js | 51 +++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/repl/importmap.js b/repl/importmap.js index e174e69..c342f36 100644 --- a/repl/importmap.js +++ b/repl/importmap.js @@ -1,11 +1,16 @@ +/** + * @param {string} content - The content. + * @returns {string} data:text string + */ function importFile(content) { return "data:text/javascript;base64," + btoa(content); } let rti = "../"; if (location.host === 'runtimetypeinspector.org') { - rti = '/node_modules/runtime-type-inspector/'; + rti = '/node_modules/runtime-type-inspector/'; } const imports = { + "@runtime-type-inspector/runtime": rti + 'src-runtime/index.mjs', "runtime-type-inspector/": rti, //"@babel/core": "./babel-core.mjs", "@babel/parser": "./babel-parser.mjs", @@ -13,31 +18,29 @@ const imports = { //"@babel/plugin-syntax-typescript": "./babel-plugin-syntax-typescript.mjs", "fs": importFile("export default {};"), "typescript": importFile("export default ts;"), // UMD import - /* - "path": importFile("export default {};"), - "stream/web": importFile("export default {};"), - "sharp": importFile("export default {};"), - "onnxruntime-node": importFile("export default {};"), - "onnxruntime-web": importFile(` - //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.15.0/ort.es6.min.js"); - await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); - //http://127.0.0.1/transformer/onnxruntime/js/common/dist/ - //await import("http://127.0.0.1/transformer/onnxruntime/js/common/dist/ort-common.js"); - //await import("http://127.0.0.1/transformer/onnxruntime/js/web/dist/ort-webgl.js"); - //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); - let ONNX = globalThis.ort; - export default ONNX; - export { - ONNX - }; - `), - */ + // "path": importFile("export default {};"), + // "stream/web": importFile("export default {};"), + // "sharp": importFile("export default {};"), + // "onnxruntime-node": importFile("export default {};"), + // "onnxruntime-web": importFile(` + // //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.15.0/ort.es6.min.js"); + // await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); + // //http://127.0.0.1/transformer/onnxruntime/js/common/dist/ + // //await import("http://127.0.0.1/transformer/onnxruntime/js/common/dist/ort-common.js"); + // //await import("http://127.0.0.1/transformer/onnxruntime/js/web/dist/ort-webgl.js"); + // //await import("https://cdnjs.cloudflare.com/ajax/libs/onnxruntime-web/1.14.0/ort.es6.min.js"); + // let ONNX = globalThis.ort; + // export default ONNX; + // export { + // ONNX + // }; + // `), }; const importmap = document.createElement("script"); importmap.type = "importmap"; importmap.textContent = JSON.stringify({imports}); -const parent = document.body || document.head; -if (!parent) { - throw "neither nor available to append importmap"; +const dom = document.body || document.head; +if (!dom) { + throw new Error("neither nor available to append importmap"); } -parent.append(importmap); +dom.append(importmap);