Skip to content

Commit

Permalink
Fix repl/importmap.js (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfooman authored Nov 30, 2023
1 parent c56affc commit da93e3c
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions repl/importmap.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
/**
* @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",
//"@babel/helper-plugin-utils": "./babel-helper-plugin-utils.mjs",
//"@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 <body> nor <head> available to append importmap";
const dom = document.body || document.head;
if (!dom) {
throw new Error("neither <body> nor <head> available to append importmap");
}
parent.append(importmap);
dom.append(importmap);

0 comments on commit da93e3c

Please sign in to comment.