@elliemae/pui-app-sdk 5.23.3 → 5.24.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.
@@ -74,7 +74,8 @@ const getMicroFrontEndAppConfig = (appInfo) => {
74
74
  {
75
75
  mode: "production",
76
76
  hostUrl: "./",
77
- manifestPath: "./{SYSTEM_VERSION}"
77
+ manifestPath: "./{SYSTEM_VERSION}",
78
+ isJsModule: false
78
79
  },
79
80
  microFEAppConfig,
80
81
  envConfig
@@ -205,7 +205,7 @@ const removeAppFromGlobalVariable = (id, uuid) => {
205
205
  }
206
206
  };
207
207
  const loadApp = async (appConfig) => {
208
- const { id, uuid, documentEle } = appConfig;
208
+ const { id, uuid, documentEle, isJsModule } = appConfig;
209
209
  addAppToGlobalVariable({ id, uuid, documentEle });
210
210
  try {
211
211
  (0, import_micro_frontend.getLogger)().info(import_log_records.logRecords.APP_LOADING(id, uuid));
@@ -215,7 +215,7 @@ const loadApp = async (appConfig) => {
215
215
  let counter = 0;
216
216
  const requests = assets.map((fileName) => {
217
217
  counter += 1;
218
- return !isCss(fileName) ? (0, import_script.addScriptToDOM)(appConfig, fileName, counter) : (0, import_style.addStylesToDOM)(appConfig, fileName, counter);
218
+ return !isCss(fileName) ? (0, import_script.addScriptToDOM)(appConfig, fileName, counter, isJsModule) : (0, import_style.addStylesToDOM)(appConfig, fileName, counter);
219
219
  });
220
220
  await waitAndInitApplication(appConfig, requests);
221
221
  (0, import_micro_frontend.getLogger)().info(import_log_records.logRecords.APP_LOADING_COMPLETE(id, uuid));
@@ -29,7 +29,8 @@ var import_url = require("../../../utils/url.js");
29
29
  const APP_SCRIPT_ID_PREFIX = "emui-script-";
30
30
  const HEAD_SCRIPTS = /(?:emuiDiagnostics|global|global-prod|emuiUserMonitoring)(?:..*)?.js/;
31
31
  const isHeadScript = (scriptSrc) => HEAD_SCRIPTS.test(scriptSrc);
32
- const addScriptToDOM = ({ name, hostUrl, documentEle }, fileName, index) => {
32
+ const isJSDOM = () => window.navigator.userAgent.includes("jsdom");
33
+ const addScriptToDOM = ({ name, hostUrl, documentEle }, fileName, index, isJsModule = false) => {
33
34
  if (!hostUrl)
34
35
  throw new Error("Unable to add scripts to DOM. hostUrl is required.");
35
36
  return new Promise((resolve, reject) => {
@@ -40,7 +41,8 @@ const addScriptToDOM = ({ name, hostUrl, documentEle }, fileName, index) => {
40
41
  ele.src = (0, import_url.removeDoubleSlash)(url.href);
41
42
  ele.onload = resolve.bind(null, ele.id);
42
43
  ele.onerror = reject.bind(null, ele.id);
43
- ele.async = false;
44
+ if (isJSDOM() || !isJsModule) ele.async = false;
45
+ else ele.type = "module";
44
46
  if (isHeadScript(ele.src)) documentEle.head.appendChild(ele);
45
47
  else documentEle.body.appendChild(ele);
46
48
  });
@@ -19,6 +19,7 @@
19
19
  "name": "Task",
20
20
  "hostUrl": "./task",
21
21
  "mode": "development",
22
+ "isJsModule": true,
22
23
  "development": {
23
24
  "files": ["index.dev.js"]
24
25
  },
@@ -37,7 +37,8 @@ const getMicroFrontEndAppConfig = (appInfo) => {
37
37
  {
38
38
  mode: "production",
39
39
  hostUrl: "./",
40
- manifestPath: "./{SYSTEM_VERSION}"
40
+ manifestPath: "./{SYSTEM_VERSION}",
41
+ isJsModule: false
41
42
  },
42
43
  microFEAppConfig,
43
44
  envConfig
@@ -192,7 +192,7 @@ const removeAppFromGlobalVariable = (id, uuid) => {
192
192
  }
193
193
  };
194
194
  const loadApp = async (appConfig) => {
195
- const { id, uuid, documentEle } = appConfig;
195
+ const { id, uuid, documentEle, isJsModule } = appConfig;
196
196
  addAppToGlobalVariable({ id, uuid, documentEle });
197
197
  try {
198
198
  getLogger().info(logRecords.APP_LOADING(id, uuid));
@@ -202,7 +202,7 @@ const loadApp = async (appConfig) => {
202
202
  let counter = 0;
203
203
  const requests = assets.map((fileName) => {
204
204
  counter += 1;
205
- return !isCss(fileName) ? addScriptToDOM(appConfig, fileName, counter) : addStylesToDOM(appConfig, fileName, counter);
205
+ return !isCss(fileName) ? addScriptToDOM(appConfig, fileName, counter, isJsModule) : addStylesToDOM(appConfig, fileName, counter);
206
206
  });
207
207
  await waitAndInitApplication(appConfig, requests);
208
208
  getLogger().info(logRecords.APP_LOADING_COMPLETE(id, uuid));
@@ -2,7 +2,8 @@ import { removeDoubleSlash } from "../../../utils/url.js";
2
2
  const APP_SCRIPT_ID_PREFIX = "emui-script-";
3
3
  const HEAD_SCRIPTS = /(?:emuiDiagnostics|global|global-prod|emuiUserMonitoring)(?:..*)?.js/;
4
4
  const isHeadScript = (scriptSrc) => HEAD_SCRIPTS.test(scriptSrc);
5
- const addScriptToDOM = ({ name, hostUrl, documentEle }, fileName, index) => {
5
+ const isJSDOM = () => window.navigator.userAgent.includes("jsdom");
6
+ const addScriptToDOM = ({ name, hostUrl, documentEle }, fileName, index, isJsModule = false) => {
6
7
  if (!hostUrl)
7
8
  throw new Error("Unable to add scripts to DOM. hostUrl is required.");
8
9
  return new Promise((resolve, reject) => {
@@ -13,7 +14,8 @@ const addScriptToDOM = ({ name, hostUrl, documentEle }, fileName, index) => {
13
14
  ele.src = removeDoubleSlash(url.href);
14
15
  ele.onload = resolve.bind(null, ele.id);
15
16
  ele.onerror = reject.bind(null, ele.id);
16
- ele.async = false;
17
+ if (isJSDOM() || !isJsModule) ele.async = false;
18
+ else ele.type = "module";
17
19
  if (isHeadScript(ele.src)) documentEle.head.appendChild(ele);
18
20
  else documentEle.body.appendChild(ele);
19
21
  });
@@ -19,6 +19,7 @@
19
19
  "name": "Task",
20
20
  "hostUrl": "./task",
21
21
  "mode": "development",
22
+ "isJsModule": true,
22
23
  "development": {
23
24
  "files": ["index.dev.js"]
24
25
  },
@@ -10,6 +10,7 @@ export type MicroAppConfig = {
10
10
  hostUrl?: string;
11
11
  manifestPath?: string;
12
12
  homeRoute: string;
13
+ isJsModule?: boolean;
13
14
  files?: Array<string>;
14
15
  development?: EnvConfig;
15
16
  production?: EnvConfig;
@@ -1,6 +1,6 @@
1
1
  import { MicroAppConfig } from '../../../utils/micro-frontend/types.js';
2
2
  export declare const APP_SCRIPT_ID_PREFIX = "emui-script-";
3
- export declare const addScriptToDOM: ({ name, hostUrl, documentEle }: MicroAppConfig, fileName: string, index: number) => Promise<string>;
3
+ export declare const addScriptToDOM: ({ name, hostUrl, documentEle }: MicroAppConfig, fileName: string, index: number, isJsModule?: boolean) => Promise<string>;
4
4
  export declare const removeScriptFromDOM: (elementId?: string, documentEle?: Document) => Promise<void>;
5
5
  export declare const removeDynamicImportedScripts: (hostUrl: string, documentEle: HTMLDocument) => void;
6
6
  export declare const removePrefetchLinks: (hostUrl: string, documentEle: HTMLDocument) => void;