@cloudbase/cals 1.2.5 → 1.2.6-alpha.0

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.
@@ -103,7 +103,7 @@ export class Dependencies {
103
103
  // 普通组件
104
104
  const [{ lcds, components, plugins, actions }] = yield Promise.all([
105
105
  loadProdMetaScript(materialName, controlJsPath),
106
- loadProdMetaStyle(materialName, controlCssPath),
106
+ typeof document === 'object' ? loadProdMetaStyle(materialName, controlCssPath) : null,
107
107
  ]);
108
108
  return handleLcdsCompPluginsActions({
109
109
  materialName,
@@ -488,21 +488,44 @@ _Dependencies_schema = new WeakMap(), _Dependencies_request = new WeakMap(), _De
488
488
  });
489
489
  };
490
490
  function loadProdMetaScript(bundleName, filename) {
491
- return new Promise((resolve, reject) => {
492
- const script = document.createElement('script');
493
- script.setAttribute('src', filename);
494
- script.setAttribute('class', '@weapps-materials-control');
495
- script.addEventListener('load', () => {
496
- const moduleName = `@weapps-materials-control-${bundleName}`;
497
- if (Object.prototype.hasOwnProperty.call(window, moduleName)) {
498
- const value = window[moduleName];
499
- return resolve(value);
491
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
492
+ try {
493
+ const script = document.createElement('script');
494
+ script.setAttribute('src', filename);
495
+ script.setAttribute('class', '@weapps-materials-control');
496
+ script.addEventListener('load', () => {
497
+ const moduleName = `@weapps-materials-control-${bundleName}`;
498
+ if (Object.prototype.hasOwnProperty.call(window, moduleName)) {
499
+ const value = window[moduleName];
500
+ return resolve(value);
501
+ }
502
+ return reject(new Error(`meta bundle [${bundleName}] must build with UMD`));
503
+ });
504
+ script.addEventListener('error', (e) => reject(`meta bundle [${bundleName}] load failed: ${(e === null || e === void 0 ? void 0 : e.message) || ''}`));
505
+ document.body.appendChild(script);
506
+ }
507
+ catch (e) {
508
+ const isNode = typeof global === 'object' && global.global === global;
509
+ if (isNode) {
510
+ // node 环境
511
+ const vm = require('vm');
512
+ const _fetch = require('node-fetch');
513
+ const fetch = _fetch.default || _fetch;
514
+ const sandbox = {
515
+ window: {},
516
+ };
517
+ const fetchRes = yield fetch(filename);
518
+ const content = yield fetchRes.text();
519
+ vm.createContext(sandbox);
520
+ vm.runInContext(content, sandbox);
521
+ const moduleName = `@weapps-materials-control-${bundleName}`;
522
+ return resolve(sandbox.window[moduleName]);
500
523
  }
501
- return reject(new Error(`meta bundle [${bundleName}] must build with UMD`));
502
- });
503
- script.addEventListener('error', (e) => reject(`meta bundle [${bundleName}] load failed: ${(e === null || e === void 0 ? void 0 : e.message) || ''}`));
504
- document.body.appendChild(script);
505
- });
524
+ else {
525
+ throw e;
526
+ }
527
+ }
528
+ }));
506
529
  }
507
530
  function loadProdMetaStyle(bundleName, filename, entryDoc = document, isLess = false) {
508
531
  if (!filename) {