xpe 1.0.3 → 1.0.5

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.
@@ -191,7 +191,8 @@ export default function importHTML(params) {
191
191
  .then((response) => {
192
192
  if (response.status >= 400) {
193
193
  error(XPE_TIPS_HTML_ERROR_REQUESTED, { url, response });
194
- throw new Error(XPE_TIPS_HTML_ERROR_REQUESTED);
194
+ loadError?.(url, new Error(XPE_TIPS_HTML_ERROR_REQUESTED));
195
+ return "";
195
196
  }
196
197
  return response.text();
197
198
  })
@@ -923,7 +923,7 @@ export function syncIframeUrlToWindow(iframeWindow) {
923
923
  * @param rawElement 原始的脚本
924
924
  */
925
925
  export function insertScriptToIframe(scriptResult, iframeWindow, rawElement) {
926
- const { src, module, content, crossorigin, crossoriginType, async, attrs, callback, onload } = scriptResult;
926
+ const { src, module, isEntry, content, crossorigin, crossoriginType, async, attrs, callback, onload } = scriptResult;
927
927
  const sandbox = getActiveSandbox(iframeWindow);
928
928
  const container = rawDocumentQuerySelector.call(iframeWindow.document, "head");
929
929
  const execNextScript = () => {
@@ -1001,7 +1001,7 @@ export function insertScriptToIframe(scriptResult, iframeWindow, rawElement) {
1001
1001
  scriptElement.onerror = afterExecScript;
1002
1002
  }
1003
1003
  container.appendChild(scriptElement);
1004
- if (isOutlineScript && module) {
1004
+ if (isOutlineScript && module && isEntry) {
1005
1005
  waitForModuleLifecycleReady(iframeWindow, afterExecScript);
1006
1006
  }
1007
1007
  // 调用回调
@@ -26,11 +26,8 @@ function loadRuntimeEngine() {
26
26
  if (runtimeEngineModule)
27
27
  return Promise.resolve(runtimeEngineModule);
28
28
  if (!runtimeEngineModulePromise) {
29
- // 保持字面量动态 import:Vite/Rollup 等消费方只有在构建期看见静态 specifier,
30
- // 才会把懒加载内核生成成可部署 chunk。通过变量 import 会在 npm 消费方产物中
31
- // 留下 ./runtime-engine.js,并错误解析到 Host 自己的 /assets 目录。
32
- // @ts-expect-error Vite/Rollup 会解析查询参数并生成独立 chunk,TypeScript 不解析该运行时 specifier。
33
- runtimeEngineModulePromise = import("./runtime-engine.js?xpe-runtime").then((module) => {
29
+ const runtimeEnginePath = "./runtime-engine.js";
30
+ runtimeEngineModulePromise = import(runtimeEnginePath).then((module) => {
34
31
  runtimeEngineModule = module;
35
32
  return runtimeEngineModule;
36
33
  });
@@ -8,6 +8,8 @@ export interface ScriptObjectLoader {
8
8
  src?: string;
9
9
  /** 脚本是否为module模块 */
10
10
  module?: boolean;
11
+ /** 是否为应用入口脚本。仅入口模块需要等待 XPE 生命周期挂载。 */
12
+ isEntry?: boolean;
11
13
  /** 脚本是否为async执行 */
12
14
  async?: boolean;
13
15
  /** 脚本是否设置crossorigin */
@@ -11,6 +11,8 @@ export interface ScriptBaseObject {
11
11
  defer?: boolean;
12
12
  /** 脚本是否为module模块 */
13
13
  module?: boolean;
14
+ /** 是否为应用入口脚本。仅入口模块需要等待 XPE 生命周期挂载。 */
15
+ isEntry?: boolean;
14
16
  /** 脚本是否设置crossorigin */
15
17
  crossorigin?: boolean;
16
18
  /** 脚本crossorigin的类型 */
@@ -212,9 +212,17 @@ export default function processTpl(tpl, baseURI, postProcessTemplate) {
212
212
  return inlineScriptReplaceSymbol;
213
213
  }
214
214
  });
215
+ const entrySrc = typeof entry === "string" ? entry : entry?.src;
216
+ const entryIndex = entrySrc
217
+ ? scripts.findIndex((script) => script.src === entrySrc)
218
+ : scripts.length - 1;
219
+ const scriptsWithEntry = scripts.map((script, index) => ({
220
+ ...script,
221
+ isEntry: index === entryIndex,
222
+ }));
215
223
  let tplResult = {
216
224
  template,
217
- scripts,
225
+ scripts: scriptsWithEntry,
218
226
  styles,
219
227
  // set the last script as entry if have not set
220
228
  entry: entry || scripts[scripts.length - 1],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpe",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "下一代微前端应用运行底座",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -46,12 +46,11 @@
46
46
  "check:example-build": "pnpm run typecheck:browser-smoke && pnpm run build:example",
47
47
  "check:host-child-smoke": "node scripts/check-host-child-smoke.mjs",
48
48
  "check:dist-surface": "node scripts/check-dist-surface.mjs",
49
- "check:vite-consumer-build": "node scripts/check-vite-consumer-build.mjs",
50
49
  "check:kernel-surface": "node scripts/check-kernel-surface.mjs",
51
50
  "check:pack": "pnpm pack --dry-run",
52
51
  "check:public-surface": "node scripts/check-public-surface.mjs",
53
52
  "check:release-metadata": "node scripts/check-release-metadata.mjs",
54
- "verify": "pnpm run check:release-metadata && pnpm run typecheck && pnpm test && pnpm run build && pnpm run check:vite-consumer-build && pnpm run check:pack",
53
+ "verify": "pnpm run check:release-metadata && pnpm run typecheck && pnpm test && pnpm run build && pnpm run check:pack",
55
54
  "prepack": "pnpm run build",
56
55
  "prepublishOnly": "pnpm run verify",
57
56
  "test": "vitest run",