@@ -17343,15 +17343,34 @@ class EmptyInspector {
1734317343
1734417344// here we need to convert from an ES6 module to an observable module
1734517345// in, well, a best-effort kind of way.
17346- function es6ImportAsObservableModule(m) {
17346+ function es6ImportAsObservableModule(modulePromise, specs) {
17347+ const promiseMap = {};
17348+ const resolveMap = {};
17349+ specs.forEach(spec => {
17350+ promiseMap[spec] = new Promise((resolve, reject) => { resolveMap[spec] = { resolve, reject }; });
17351+ });
17352+ modulePromise.then(m => {
17353+ specs.forEach(spec => {
17354+ resolveMap[spec].resolve(m[spec]);
17355+ });
17356+ }).catch(error => {
17357+ specs.forEach(spec => {
17358+ resolveMap[spec].reject(error);
17359+ });
17360+ });
1734717361 return function (runtime, observer) {
1734817362 const main = runtime.module();
1734917363
17364+ specs.forEach(key => {
17365+ main.variable(observer(key)).define(key, [], () => promiseMap[key]);
17366+ });
17367+ /*
1735017368 Object.keys(m).forEach((key) => {
1735117369 const v = m[key];
17352- main.variable(observer(key)).define(key, [], () => v);
17353- });
1735417370
17371+ main.variable(observer(key)).define(key, [], () => promiseMap[key]v);
17372+ });
17373+ */
1735517374 return main;
1735617375 };
1735717376}
@@ -17512,7 +17531,7 @@ function importPathResolver(paths, localResolverMap) {
1751217531 return path;
1751317532 }
1751417533
17515- return async (path) => {
17534+ return async (path, specs ) => {
1751617535 const isLocalModule = path.startsWith("/") || path.startsWith(".");
1751717536 const isImportFromObservableWebsite = path.match(
1751817537 /^https:\/\/(api\.|beta\.|)observablehq\.com\//i,
@@ -17562,8 +17581,8 @@ function importPathResolver(paths, localResolverMap) {
1756217581
1756317582 if (moduleType === "ts" || moduleType === "tsx") {
1756417583 try {
17565- const m = await import(importPath.replace(/\.ts$/, ".js").replace(/\.tsx$/, ".js"));
17566- return es6ImportAsObservableModule(m );
17584+ const modulePromise = import(importPath.replace(/\.ts$/, ".js").replace(/\.tsx$/, ".js"));
17585+ return es6ImportAsObservableModule(modulePromise, specs );
1756717586 } catch (e) {
1756817587 // record the error on the browser console to make debugging
1756917588 // slightly more convenient.
@@ -17572,8 +17591,8 @@ function importPathResolver(paths, localResolverMap) {
1757217591 }
1757317592 } else if (moduleType === "js") {
1757417593 try {
17575- const m = await import(importPath);
17576- return es6ImportAsObservableModule(m );
17594+ const modulePromise = import(importPath);
17595+ return es6ImportAsObservableModule(modulePromise, specs );
1757717596 } catch (e) {
1757817597 // record the error on the browser console to make debugging
1757917598 // slightly more convenient.
0 commit comments