@cloudbase/cals 1.2.22 → 1.2.24
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.
|
@@ -492,67 +492,73 @@ _Dependencies_schema = new WeakMap(), _Dependencies_request = new WeakMap(), _De
|
|
|
492
492
|
});
|
|
493
493
|
};
|
|
494
494
|
function loadProdMetaScript(bundleName, filename) {
|
|
495
|
-
return
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
"
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
return new Promise((resolve, reject) => {
|
|
497
|
+
try {
|
|
498
|
+
const iframe = document.createElement('iframe');
|
|
499
|
+
iframe.setAttribute('sandbox', 'allow-scripts');
|
|
500
|
+
iframe.setAttribute('allow', 'local-network-access');
|
|
501
|
+
iframe.style.position = 'absolute'; // 脱离文档流
|
|
502
|
+
iframe.style.left = '-9999px'; // 移到屏幕左侧很远的地方
|
|
503
|
+
iframe.style.top = '-9999px'; // 移到屏幕上方很远的地方
|
|
504
|
+
iframe.style.width = '1px'; // 保持一个最小的尺寸
|
|
505
|
+
iframe.style.height = '1px'; // 保持一个最小的尺寸
|
|
506
|
+
iframe.style.border = 'none'; // 确保没有边框
|
|
507
|
+
const moduleName = `@weapps-materials-control-${bundleName}`;
|
|
508
|
+
const messageHandler = (event) => {
|
|
509
|
+
// 安全检查:确保消息来自我们刚刚创建的iframe
|
|
510
|
+
if (event.source !== iframe.contentWindow) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
const { status, data, error } = event.data;
|
|
514
|
+
document.body.removeChild(iframe);
|
|
515
|
+
window.removeEventListener('message', messageHandler);
|
|
516
|
+
if (status === 'success') {
|
|
517
|
+
resolve(data);
|
|
518
|
+
}
|
|
519
|
+
else if (status === 'error') {
|
|
520
|
+
reject(new Error(error));
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
window.addEventListener('message', messageHandler);
|
|
524
|
+
// 从下面这段是 iframe-srcdoc.src.js 中搞出来的
|
|
525
|
+
const scriptStr = "window.addEventListener('error', (event) => {\n" +
|
|
526
|
+
' parent.postMessage({\n' +
|
|
527
|
+
" status: 'error',\n" +
|
|
528
|
+
" error: `meta bundle load failed: ${event?.message || ''} ${document.currentScript.src}`,\n" +
|
|
529
|
+
' });\n' +
|
|
530
|
+
'});\n' +
|
|
531
|
+
"window.addEventListener('message', (event) => {\n" +
|
|
532
|
+
' const { data, origin } = event;\n' +
|
|
533
|
+
' const { filename, bundleName, moduleName } = data;\n' +
|
|
534
|
+
' if (!filename || !bundleName || !moduleName) {\n' +
|
|
535
|
+
' return;\n' +
|
|
536
|
+
' }\n' +
|
|
537
|
+
" const script = document.createElement('script');\n" +
|
|
538
|
+
" script.setAttribute('src', filename);\n" +
|
|
539
|
+
" script.setAttribute('class', '@weapps-materials-control');\n" +
|
|
540
|
+
" script.addEventListener('load', () => {\n" +
|
|
541
|
+
' if (Object.prototype.hasOwnProperty.call(window, moduleName)) {\n' +
|
|
542
|
+
" parent.postMessage({ status: 'success', data: window[moduleName] }, origin);\n" +
|
|
543
|
+
' } else {\n' +
|
|
544
|
+
" parent.postMessage({ status: 'error', error: `meta bundle [${bundleName}] must build with UMD` }, origin);\n" +
|
|
545
|
+
' }\n' +
|
|
546
|
+
' });\n' +
|
|
547
|
+
" script.addEventListener('error', (e) => {\n" +
|
|
548
|
+
' parent.postMessage(\n' +
|
|
549
|
+
" { status: 'error', error: `meta bundle [${bundleName}] load failed: ${e?.message || ''}` },\n" +
|
|
550
|
+
' origin,\n' +
|
|
551
|
+
' );\n' +
|
|
552
|
+
' });\n' +
|
|
553
|
+
' document.body.appendChild(script);\n' +
|
|
554
|
+
'});\n';
|
|
555
|
+
// 软件化环境下 filename 可能是纯路径,不含 origin,例如:
|
|
556
|
+
// /comps/comp-public/lca/comGroup/cg-jgjmnsvid6ot/prod/1.10.4/build/dist/comps.main.js
|
|
557
|
+
// 此时 new URL(filename) 会抛错,传入 base 可兼容两种情况:
|
|
558
|
+
// 绝对 URL 时 base 被忽略,相对路径时以当前页面 origin 补全
|
|
559
|
+
const scriptOrigin = new URL(filename, window.location.origin).origin;
|
|
560
|
+
const csp = `default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' ${scriptOrigin};`;
|
|
561
|
+
iframe.srcdoc = `
|
|
556
562
|
<html>
|
|
557
563
|
<head>
|
|
558
564
|
<meta http-equiv="Content-Security-Policy" content="${csp}">
|
|
@@ -562,40 +568,41 @@ function loadProdMetaScript(bundleName, filename) {
|
|
|
562
568
|
</body>
|
|
563
569
|
</html>
|
|
564
570
|
`;
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
catch (e) {
|
|
571
|
-
const isNode = typeof global === 'object' && global.global === global;
|
|
572
|
-
if (isNode) {
|
|
573
|
-
// node 环境
|
|
574
|
-
// TODO: 流水线会报错,待解决
|
|
575
|
-
// const vm = require('vm');
|
|
576
|
-
// const _fetch = require('node-fetch');
|
|
577
|
-
// const fetch = _fetch.default || _fetch;
|
|
578
|
-
// const sandbox: any = {
|
|
579
|
-
// window: {},
|
|
580
|
-
// this: {},
|
|
581
|
-
// };
|
|
582
|
-
// try {
|
|
583
|
-
// const fetchRes = await fetch(filename);
|
|
584
|
-
// const content = await fetchRes.text();
|
|
585
|
-
// vm.createContext(sandbox);
|
|
586
|
-
// vm.runInContext(content, sandbox);
|
|
587
|
-
// const moduleName = `@weapps-materials-control-${bundleName}`;
|
|
588
|
-
// return resolve(sandbox.window[moduleName] || sandbox.this[moduleName]);
|
|
589
|
-
// } catch (e) {
|
|
590
|
-
// console.error(e);
|
|
591
|
-
// return resolve({ components: [], actions: {} } as any);
|
|
592
|
-
// }
|
|
571
|
+
iframe.addEventListener('load', () => {
|
|
572
|
+
iframe.contentWindow.postMessage({ filename, bundleName, moduleName }, '*');
|
|
573
|
+
});
|
|
574
|
+
document.body.appendChild(iframe);
|
|
593
575
|
}
|
|
594
|
-
|
|
595
|
-
|
|
576
|
+
catch (e) {
|
|
577
|
+
const isNode = typeof global === 'object' && global.global === global;
|
|
578
|
+
if (isNode) {
|
|
579
|
+
// node 环境
|
|
580
|
+
// TODO: 流水线会报错,待解决
|
|
581
|
+
// const vm = require('vm');
|
|
582
|
+
// const _fetch = require('node-fetch');
|
|
583
|
+
// const fetch = _fetch.default || _fetch;
|
|
584
|
+
// const sandbox: any = {
|
|
585
|
+
// window: {},
|
|
586
|
+
// this: {},
|
|
587
|
+
// };
|
|
588
|
+
// try {
|
|
589
|
+
// const fetchRes = await fetch(filename);
|
|
590
|
+
// const content = await fetchRes.text();
|
|
591
|
+
// vm.createContext(sandbox);
|
|
592
|
+
// vm.runInContext(content, sandbox);
|
|
593
|
+
// const moduleName = `@weapps-materials-control-${bundleName}`;
|
|
594
|
+
// return resolve(sandbox.window[moduleName] || sandbox.this[moduleName]);
|
|
595
|
+
// } catch (e) {
|
|
596
|
+
// console.error(e);
|
|
597
|
+
// return resolve({ components: [], actions: {} } as any);
|
|
598
|
+
// }
|
|
599
|
+
}
|
|
600
|
+
else {
|
|
601
|
+
reject(e);
|
|
602
|
+
}
|
|
596
603
|
}
|
|
597
|
-
}
|
|
598
|
-
})
|
|
604
|
+
});
|
|
605
|
+
});
|
|
599
606
|
}
|
|
600
607
|
function loadProdMetaStyle(bundleName, filename, entryDoc = document, isLess = false) {
|
|
601
608
|
if (!filename) {
|
|
@@ -488,67 +488,73 @@ _Dependencies_schema = new WeakMap(), _Dependencies_request = new WeakMap(), _De
|
|
|
488
488
|
});
|
|
489
489
|
};
|
|
490
490
|
function loadProdMetaScript(bundleName, filename) {
|
|
491
|
-
return
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
"
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
491
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
492
|
+
return new Promise((resolve, reject) => {
|
|
493
|
+
try {
|
|
494
|
+
const iframe = document.createElement('iframe');
|
|
495
|
+
iframe.setAttribute('sandbox', 'allow-scripts');
|
|
496
|
+
iframe.setAttribute('allow', 'local-network-access');
|
|
497
|
+
iframe.style.position = 'absolute'; // 脱离文档流
|
|
498
|
+
iframe.style.left = '-9999px'; // 移到屏幕左侧很远的地方
|
|
499
|
+
iframe.style.top = '-9999px'; // 移到屏幕上方很远的地方
|
|
500
|
+
iframe.style.width = '1px'; // 保持一个最小的尺寸
|
|
501
|
+
iframe.style.height = '1px'; // 保持一个最小的尺寸
|
|
502
|
+
iframe.style.border = 'none'; // 确保没有边框
|
|
503
|
+
const moduleName = `@weapps-materials-control-${bundleName}`;
|
|
504
|
+
const messageHandler = (event) => {
|
|
505
|
+
// 安全检查:确保消息来自我们刚刚创建的iframe
|
|
506
|
+
if (event.source !== iframe.contentWindow) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
const { status, data, error } = event.data;
|
|
510
|
+
document.body.removeChild(iframe);
|
|
511
|
+
window.removeEventListener('message', messageHandler);
|
|
512
|
+
if (status === 'success') {
|
|
513
|
+
resolve(data);
|
|
514
|
+
}
|
|
515
|
+
else if (status === 'error') {
|
|
516
|
+
reject(new Error(error));
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
window.addEventListener('message', messageHandler);
|
|
520
|
+
// 从下面这段是 iframe-srcdoc.src.js 中搞出来的
|
|
521
|
+
const scriptStr = "window.addEventListener('error', (event) => {\n" +
|
|
522
|
+
' parent.postMessage({\n' +
|
|
523
|
+
" status: 'error',\n" +
|
|
524
|
+
" error: `meta bundle load failed: ${event?.message || ''} ${document.currentScript.src}`,\n" +
|
|
525
|
+
' });\n' +
|
|
526
|
+
'});\n' +
|
|
527
|
+
"window.addEventListener('message', (event) => {\n" +
|
|
528
|
+
' const { data, origin } = event;\n' +
|
|
529
|
+
' const { filename, bundleName, moduleName } = data;\n' +
|
|
530
|
+
' if (!filename || !bundleName || !moduleName) {\n' +
|
|
531
|
+
' return;\n' +
|
|
532
|
+
' }\n' +
|
|
533
|
+
" const script = document.createElement('script');\n" +
|
|
534
|
+
" script.setAttribute('src', filename);\n" +
|
|
535
|
+
" script.setAttribute('class', '@weapps-materials-control');\n" +
|
|
536
|
+
" script.addEventListener('load', () => {\n" +
|
|
537
|
+
' if (Object.prototype.hasOwnProperty.call(window, moduleName)) {\n' +
|
|
538
|
+
" parent.postMessage({ status: 'success', data: window[moduleName] }, origin);\n" +
|
|
539
|
+
' } else {\n' +
|
|
540
|
+
" parent.postMessage({ status: 'error', error: `meta bundle [${bundleName}] must build with UMD` }, origin);\n" +
|
|
541
|
+
' }\n' +
|
|
542
|
+
' });\n' +
|
|
543
|
+
" script.addEventListener('error', (e) => {\n" +
|
|
544
|
+
' parent.postMessage(\n' +
|
|
545
|
+
" { status: 'error', error: `meta bundle [${bundleName}] load failed: ${e?.message || ''}` },\n" +
|
|
546
|
+
' origin,\n' +
|
|
547
|
+
' );\n' +
|
|
548
|
+
' });\n' +
|
|
549
|
+
' document.body.appendChild(script);\n' +
|
|
550
|
+
'});\n';
|
|
551
|
+
// 软件化环境下 filename 可能是纯路径,不含 origin,例如:
|
|
552
|
+
// /comps/comp-public/lca/comGroup/cg-jgjmnsvid6ot/prod/1.10.4/build/dist/comps.main.js
|
|
553
|
+
// 此时 new URL(filename) 会抛错,传入 base 可兼容两种情况:
|
|
554
|
+
// 绝对 URL 时 base 被忽略,相对路径时以当前页面 origin 补全
|
|
555
|
+
const scriptOrigin = new URL(filename, window.location.origin).origin;
|
|
556
|
+
const csp = `default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' ${scriptOrigin};`;
|
|
557
|
+
iframe.srcdoc = `
|
|
552
558
|
<html>
|
|
553
559
|
<head>
|
|
554
560
|
<meta http-equiv="Content-Security-Policy" content="${csp}">
|
|
@@ -558,40 +564,41 @@ function loadProdMetaScript(bundleName, filename) {
|
|
|
558
564
|
</body>
|
|
559
565
|
</html>
|
|
560
566
|
`;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
catch (e) {
|
|
567
|
-
const isNode = typeof global === 'object' && global.global === global;
|
|
568
|
-
if (isNode) {
|
|
569
|
-
// node 环境
|
|
570
|
-
// TODO: 流水线会报错,待解决
|
|
571
|
-
// const vm = require('vm');
|
|
572
|
-
// const _fetch = require('node-fetch');
|
|
573
|
-
// const fetch = _fetch.default || _fetch;
|
|
574
|
-
// const sandbox: any = {
|
|
575
|
-
// window: {},
|
|
576
|
-
// this: {},
|
|
577
|
-
// };
|
|
578
|
-
// try {
|
|
579
|
-
// const fetchRes = await fetch(filename);
|
|
580
|
-
// const content = await fetchRes.text();
|
|
581
|
-
// vm.createContext(sandbox);
|
|
582
|
-
// vm.runInContext(content, sandbox);
|
|
583
|
-
// const moduleName = `@weapps-materials-control-${bundleName}`;
|
|
584
|
-
// return resolve(sandbox.window[moduleName] || sandbox.this[moduleName]);
|
|
585
|
-
// } catch (e) {
|
|
586
|
-
// console.error(e);
|
|
587
|
-
// return resolve({ components: [], actions: {} } as any);
|
|
588
|
-
// }
|
|
567
|
+
iframe.addEventListener('load', () => {
|
|
568
|
+
iframe.contentWindow.postMessage({ filename, bundleName, moduleName }, '*');
|
|
569
|
+
});
|
|
570
|
+
document.body.appendChild(iframe);
|
|
589
571
|
}
|
|
590
|
-
|
|
591
|
-
|
|
572
|
+
catch (e) {
|
|
573
|
+
const isNode = typeof global === 'object' && global.global === global;
|
|
574
|
+
if (isNode) {
|
|
575
|
+
// node 环境
|
|
576
|
+
// TODO: 流水线会报错,待解决
|
|
577
|
+
// const vm = require('vm');
|
|
578
|
+
// const _fetch = require('node-fetch');
|
|
579
|
+
// const fetch = _fetch.default || _fetch;
|
|
580
|
+
// const sandbox: any = {
|
|
581
|
+
// window: {},
|
|
582
|
+
// this: {},
|
|
583
|
+
// };
|
|
584
|
+
// try {
|
|
585
|
+
// const fetchRes = await fetch(filename);
|
|
586
|
+
// const content = await fetchRes.text();
|
|
587
|
+
// vm.createContext(sandbox);
|
|
588
|
+
// vm.runInContext(content, sandbox);
|
|
589
|
+
// const moduleName = `@weapps-materials-control-${bundleName}`;
|
|
590
|
+
// return resolve(sandbox.window[moduleName] || sandbox.this[moduleName]);
|
|
591
|
+
// } catch (e) {
|
|
592
|
+
// console.error(e);
|
|
593
|
+
// return resolve({ components: [], actions: {} } as any);
|
|
594
|
+
// }
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
reject(e);
|
|
598
|
+
}
|
|
592
599
|
}
|
|
593
|
-
}
|
|
594
|
-
})
|
|
600
|
+
});
|
|
601
|
+
});
|
|
595
602
|
}
|
|
596
603
|
function loadProdMetaStyle(bundleName, filename, entryDoc = document, isLess = false) {
|
|
597
604
|
if (!filename) {
|