@trops/dash-core 0.1.419 → 0.1.420
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/electron/index.js +61 -1
- package/dist/electron/index.js.map +1 -1
- package/dist/index.esm.js +41 -32
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/electron/index.js
CHANGED
|
@@ -27419,6 +27419,53 @@ const path$a = require$$1$2;
|
|
|
27419
27419
|
const vm = require$$2$3;
|
|
27420
27420
|
const { findWidgetsDir: findWidgetsDir$1 } = widgetCompiler$1;
|
|
27421
27421
|
|
|
27422
|
+
// Scan an ES-module source and return an object stubbing every imported
|
|
27423
|
+
// name (named, default, namespace) to `undefined`. Used to keep `vm.runInContext`
|
|
27424
|
+
// from throwing ReferenceError on identifiers referenced inside the
|
|
27425
|
+
// config literal whose real imports we don't (and can't) resolve from
|
|
27426
|
+
// here — we only need the config metadata, not the imported values.
|
|
27427
|
+
function collectImportedNames(source) {
|
|
27428
|
+
const stubs = {};
|
|
27429
|
+
if (typeof source !== "string") return stubs;
|
|
27430
|
+
|
|
27431
|
+
// import { a, b as c } from "..."
|
|
27432
|
+
const namedRe =
|
|
27433
|
+
/import\s+(?:[A-Za-z_$][\w$]*\s*,\s*)?\{\s*([^}]+)\s*\}\s*from\s*["'][^"']+["']/g;
|
|
27434
|
+
let m;
|
|
27435
|
+
while ((m = namedRe.exec(source))) {
|
|
27436
|
+
for (const part of m[1].split(",")) {
|
|
27437
|
+
const name = part
|
|
27438
|
+
.trim()
|
|
27439
|
+
.split(/\s+as\s+/)
|
|
27440
|
+
.pop()
|
|
27441
|
+
.trim();
|
|
27442
|
+
if (name) stubs[name] = undefined;
|
|
27443
|
+
}
|
|
27444
|
+
}
|
|
27445
|
+
|
|
27446
|
+
// import foo from "..."
|
|
27447
|
+
const defaultRe = /import\s+([A-Za-z_$][\w$]*)\s+from\s*["'][^"']+["']/g;
|
|
27448
|
+
while ((m = defaultRe.exec(source))) {
|
|
27449
|
+
stubs[m[1]] = undefined;
|
|
27450
|
+
}
|
|
27451
|
+
|
|
27452
|
+
// import foo, { a, b } from "..." — capture the default name too
|
|
27453
|
+
const defaultWithNamedRe =
|
|
27454
|
+
/import\s+([A-Za-z_$][\w$]*)\s*,\s*\{[^}]*\}\s*from\s*["'][^"']+["']/g;
|
|
27455
|
+
while ((m = defaultWithNamedRe.exec(source))) {
|
|
27456
|
+
stubs[m[1]] = undefined;
|
|
27457
|
+
}
|
|
27458
|
+
|
|
27459
|
+
// import * as foo from "..."
|
|
27460
|
+
const namespaceRe =
|
|
27461
|
+
/import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s*["'][^"']+["']/g;
|
|
27462
|
+
while ((m = namespaceRe.exec(source))) {
|
|
27463
|
+
stubs[m[1]] = undefined;
|
|
27464
|
+
}
|
|
27465
|
+
|
|
27466
|
+
return stubs;
|
|
27467
|
+
}
|
|
27468
|
+
|
|
27422
27469
|
class DynamicWidgetLoader {
|
|
27423
27470
|
constructor(componentManager = null) {
|
|
27424
27471
|
this.loadedWidgets = new Map();
|
|
@@ -27547,7 +27594,20 @@ class DynamicWidgetLoader {
|
|
|
27547
27594
|
'component: "$1"',
|
|
27548
27595
|
);
|
|
27549
27596
|
|
|
27550
|
-
|
|
27597
|
+
// Stub every named import in the source so references like
|
|
27598
|
+
// `providers: [algoliaProvider]` inside the literal don't throw
|
|
27599
|
+
// a ReferenceError when we eval it in a bare VM context. We
|
|
27600
|
+
// can't follow the real `./foo` imports from here — we only
|
|
27601
|
+
// care about the config metadata (events, eventHandlers,
|
|
27602
|
+
// userConfig, etc.). Imported values show up as `undefined` in
|
|
27603
|
+
// the parsed config; callers that iterate arrays (providers,
|
|
27604
|
+
// …) are expected to filter out nullish entries.
|
|
27605
|
+
const importStubs = collectImportedNames(source);
|
|
27606
|
+
|
|
27607
|
+
const context = vm.createContext({
|
|
27608
|
+
module: { exports: {} },
|
|
27609
|
+
...importStubs,
|
|
27610
|
+
});
|
|
27551
27611
|
vm.runInContext(`module.exports = ${exportedObjectStr}`, context);
|
|
27552
27612
|
|
|
27553
27613
|
return context.module.exports;
|