@qiankunjs/shared 0.0.1-rc.4 → 0.0.1-rc.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.
Files changed (42) hide show
  1. package/dist/cjs/assets-transpilers/index.d.ts +7 -0
  2. package/dist/cjs/assets-transpilers/index.js +7 -0
  3. package/dist/cjs/assets-transpilers/index.js.map +1 -1
  4. package/dist/cjs/assets-transpilers/script.d.ts +2 -2
  5. package/dist/cjs/assets-transpilers/script.js +105 -70
  6. package/dist/cjs/assets-transpilers/script.js.map +1 -1
  7. package/dist/cjs/assets-transpilers/types.d.ts +8 -0
  8. package/dist/cjs/assets-transpilers/types.js +1 -2
  9. package/dist/cjs/assets-transpilers/types.js.map +1 -1
  10. package/dist/cjs/assets-transpilers/utils.js +2 -4
  11. package/dist/cjs/assets-transpilers/utils.js.map +1 -1
  12. package/dist/cjs/error/QiankunError.js +1 -2
  13. package/dist/cjs/error/QiankunError.js.map +1 -1
  14. package/dist/cjs/utils.d.ts +8 -1
  15. package/dist/cjs/utils.js +89 -35
  16. package/dist/cjs/utils.js.map +1 -1
  17. package/dist/esm/assets-transpilers/index.d.ts +7 -0
  18. package/dist/esm/assets-transpilers/index.js +7 -0
  19. package/dist/esm/assets-transpilers/index.js.map +1 -1
  20. package/dist/esm/assets-transpilers/script.d.ts +2 -2
  21. package/dist/esm/assets-transpilers/script.js +105 -69
  22. package/dist/esm/assets-transpilers/script.js.map +1 -1
  23. package/dist/esm/assets-transpilers/types.d.ts +8 -0
  24. package/dist/esm/assets-transpilers/types.js.map +1 -1
  25. package/dist/esm/utils.d.ts +8 -1
  26. package/dist/esm/utils.js +78 -19
  27. package/dist/esm/utils.js.map +1 -1
  28. package/package.json +4 -5
  29. package/src/assets-transpilers/index.ts +0 -42
  30. package/src/assets-transpilers/link.ts +0 -130
  31. package/src/assets-transpilers/script.ts +0 -169
  32. package/src/assets-transpilers/types.ts +0 -22
  33. package/src/assets-transpilers/utils.ts +0 -27
  34. package/src/common.ts +0 -3
  35. package/src/error/QiankunError.ts +0 -5
  36. package/src/error/index.ts +0 -1
  37. package/src/index.ts +0 -9
  38. package/src/module-resolver/__tests__/index.ts +0 -75
  39. package/src/module-resolver/index.ts +0 -92
  40. package/src/module-resolver/types.ts +0 -9
  41. package/src/typings.d.ts +0 -13
  42. package/src/utils.ts +0 -37
@@ -1,4 +1,11 @@
1
1
  import type { AssetsTranspilerOpts } from './types';
2
+ /**
3
+ * transpile the assets to support micro frontend
4
+ * @param node the original node
5
+ * @param baseURI the baseURI of the node
6
+ * @param opts
7
+ * @returns original node after transpiled
8
+ */
2
9
  export declare function transpileAssets<T extends Node>(node: T, baseURI: string, opts: AssetsTranspilerOpts): T;
3
10
  export type * from './types';
4
11
  export { isValidJavaScriptType } from './utils';
@@ -4,6 +4,13 @@
4
4
  */
5
5
  import transpileLink from "./link";
6
6
  import transpileScript from "./script";
7
+ /**
8
+ * transpile the assets to support micro frontend
9
+ * @param node the original node
10
+ * @param baseURI the baseURI of the node
11
+ * @param opts
12
+ * @returns original node after transpiled
13
+ */
7
14
  export function transpileAssets(node, baseURI, opts) {
8
15
  var htmlElement = node;
9
16
  var tagName = htmlElement.tagName;
@@ -1 +1 @@
1
- {"version":3,"names":["transpileLink","transpileScript","transpileAssets","node","baseURI","opts","htmlElement","tagName","isValidJavaScriptType"],"sources":["../../../src/assets-transpilers/index.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-14\n */\nimport transpileLink from './link';\nimport transpileScript from './script';\nimport type { AssetsTranspilerOpts } from './types';\n\nexport function transpileAssets<T extends Node>(node: T, baseURI: string, opts: AssetsTranspilerOpts): T {\n const htmlElement = node as unknown as HTMLElement;\n const { tagName } = htmlElement;\n\n switch (tagName) {\n case 'SCRIPT': {\n return transpileScript(htmlElement as HTMLScriptElement, baseURI, opts) as unknown as T;\n }\n\n case 'LINK': {\n return transpileLink(htmlElement as HTMLLinkElement, baseURI, opts) as unknown as T;\n }\n\n default:\n break;\n }\n\n // TODO need to deal with the text scenario of script\n // const { nodeType } = node;\n // switch (nodeType) {\n // case Node.TEXT_NODE: {\n // if (node.parentNode?.nodeName === 'script') {\n // break;\n // }\n // }\n //\n // }\n // }\n return node;\n}\n\nexport type * from './types';\n\nexport { isValidJavaScriptType } from './utils';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,aAAa;AACpB,OAAOC,eAAe;AAGtB,OAAO,SAASC,eAAeA,CAAiBC,IAAO,EAAEC,OAAe,EAAEC,IAA0B,EAAK;EACvG,IAAMC,WAAW,GAAGH,IAA8B;EAClD,IAAQI,OAAO,GAAKD,WAAW,CAAvBC,OAAO;EAEf,QAAQA,OAAO;IACb,KAAK,QAAQ;MAAE;QACb,OAAON,eAAe,CAACK,WAAW,EAAuBF,OAAO,EAAEC,IAAI,CAAC;MACzE;IAEA,KAAK,MAAM;MAAE;QACX,OAAOL,aAAa,CAACM,WAAW,EAAqBF,OAAO,EAAEC,IAAI,CAAC;MACrE;IAEA;MACE;EACJ;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAOF,IAAI;AACb;AAIA,SAASK,qBAAqB"}
1
+ {"version":3,"names":["transpileLink","transpileScript","transpileAssets","node","baseURI","opts","htmlElement","tagName","isValidJavaScriptType"],"sources":["../../../src/assets-transpilers/index.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-14\n */\nimport transpileLink from './link';\nimport transpileScript from './script';\nimport type { AssetsTranspilerOpts } from './types';\n\n/**\n * transpile the assets to support micro frontend\n * @param node the original node\n * @param baseURI the baseURI of the node\n * @param opts\n * @returns original node after transpiled\n */\nexport function transpileAssets<T extends Node>(node: T, baseURI: string, opts: AssetsTranspilerOpts): T {\n const htmlElement = node as unknown as HTMLElement;\n const { tagName } = htmlElement;\n\n switch (tagName) {\n case 'SCRIPT': {\n return transpileScript(htmlElement as HTMLScriptElement, baseURI, opts) as unknown as T;\n }\n\n case 'LINK': {\n return transpileLink(htmlElement as HTMLLinkElement, baseURI, opts) as unknown as T;\n }\n\n default:\n break;\n }\n\n // TODO need to deal with the text scenario of script\n // const { nodeType } = node;\n // switch (nodeType) {\n // case Node.TEXT_NODE: {\n // if (node.parentNode?.nodeName === 'script') {\n // break;\n // }\n // }\n //\n // }\n // }\n return node;\n}\n\nexport type * from './types';\n\nexport { isValidJavaScriptType } from './utils';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,aAAa;AACpB,OAAOC,eAAe;AAGtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAAiBC,IAAO,EAAEC,OAAe,EAAEC,IAA0B,EAAK;EACvG,IAAMC,WAAW,GAAGH,IAA8B;EAClD,IAAQI,OAAO,GAAKD,WAAW,CAAvBC,OAAO;EAEf,QAAQA,OAAO;IACb,KAAK,QAAQ;MAAE;QACb,OAAON,eAAe,CAACK,WAAW,EAAuBF,OAAO,EAAEC,IAAI,CAAC;MACzE;IAEA,KAAK,MAAM;MAAE;QACX,OAAOL,aAAa,CAACM,WAAW,EAAqBF,OAAO,EAAEC,IAAI,CAAC;MACrE;IAEA;MACE;EACJ;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OAAOF,IAAI;AACb;AAIA,SAASK,qBAAqB"}
@@ -3,7 +3,7 @@
3
3
  * @since 2023-03-16
4
4
  */
5
5
  import type { MatchResult } from '../module-resolver';
6
- import type { AssetsTranspilerOpts } from './types';
6
+ import type { AssetsTranspilerOpts, ScriptTranspilerOpts } from './types';
7
7
  import { Mode } from './types';
8
8
  type PreTranspileResult = {
9
9
  mode: Mode.REMOTE_ASSETS_IN_SANDBOX;
@@ -25,5 +25,5 @@ type PreTranspileResult = {
25
25
  result?: never;
26
26
  };
27
27
  export declare const preTranspile: (script: Partial<Pick<HTMLScriptElement, 'src' | 'type' | 'textContent'>>, baseURI: string, opts: AssetsTranspilerOpts) => PreTranspileResult;
28
- export default function transpileScript(script: HTMLScriptElement, baseURI: string, opts: AssetsTranspilerOpts): HTMLScriptElement;
28
+ export default function transpileScript(script: HTMLScriptElement, baseURI: string, opts: ScriptTranspilerOpts): HTMLScriptElement;
29
29
  export {};
@@ -1,10 +1,12 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
1
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
4
  /**
3
5
  * @author Kuitos
4
6
  * @since 2023-03-16
5
7
  */
6
8
 
7
- import { getEntireUrl } from "../utils";
9
+ import { getEntireUrl, waitUntilSettled } from "../utils";
8
10
  import { Mode } from "./types";
9
11
  import { createReusingObjectUrl, isValidJavaScriptType } from "./utils";
10
12
  var getCredentials = function getCredentials(crossOrigin) {
@@ -64,86 +66,120 @@ export default function transpileScript(script, baseURI, opts) {
64
66
  // Such as <script src="./foo.js"></script> will be resolved to http://localhost:8000/foo.js while read script.src
65
67
  var srcAttribute = script.getAttribute('src');
66
68
  var sandbox = opts.sandbox,
67
- fetch = opts.fetch;
69
+ scriptTranspiledDeferred = opts.scriptTranspiledDeferred;
68
70
 
69
71
  // To prevent webpack from skipping reload logic and causing the js not to re-execute when a micro app is loaded multiple times, the data-webpack attribute of the script must be removed.
70
72
  // see https://github.com/webpack/webpack/blob/1f13ff9fe587e094df59d660b4611b1bd19aed4c/lib/runtime/LoadScriptRuntimeModule.js#L131-L136
71
73
  // FIXME We should determine whether the current micro application is being loaded for the second time. If not, this removal should not be performed.
72
74
  script.removeAttribute('data-webpack');
73
- var _preTranspile = preTranspile({
74
- src: srcAttribute || undefined,
75
- type: script.type,
76
- textContent: script.textContent
77
- }, baseURI, opts),
78
- mode = _preTranspile.mode,
79
- result = _preTranspile.result;
80
- switch (mode) {
81
- case Mode.REMOTE_ASSETS_IN_SANDBOX:
82
- {
83
- var src = result.src;
84
-
85
- // We must remove script src to avoid self execution as we need to fetch the script content and transpile it
86
- script.removeAttribute('src');
87
- script.dataset.src = src;
88
- var syncMode = !script.hasAttribute('async');
89
- var priority = syncMode ? 'high' : 'low';
90
- var credentials = getCredentials(script.crossOrigin);
91
- void fetch(src, {
92
- credentials: credentials,
93
- priority: priority
94
- }).then(function (res) {
95
- return res.text();
96
- }).then(function (code) {
97
- var codeFactory = sandbox.makeEvaluateFactory(code, src);
75
+ try {
76
+ var _preTranspile = preTranspile({
77
+ src: srcAttribute || undefined,
78
+ type: script.type,
79
+ textContent: script.textContent
80
+ }, baseURI, opts),
81
+ mode = _preTranspile.mode,
82
+ result = _preTranspile.result;
83
+ switch (mode) {
84
+ case Mode.REMOTE_ASSETS_IN_SANDBOX:
85
+ {
86
+ var fetch = opts.fetch;
87
+ var src = result.src;
98
88
 
89
+ // We must remove script src to avoid self execution as we need to fetch the script content and transpile it
90
+ script.removeAttribute('src');
91
+ script.dataset.src = src;
92
+ var syncMode = !script.hasAttribute('async');
93
+ var priority = syncMode ? 'high' : 'low';
94
+ var credentials = getCredentials(script.crossOrigin);
95
+ void fetch(src, {
96
+ credentials: credentials,
97
+ priority: priority
98
+ }).then(function (res) {
99
+ return res.text();
100
+ }).then( /*#__PURE__*/function () {
101
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(code) {
102
+ var prevScriptTranspiledDeferred, codeFactory;
103
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
104
+ while (1) switch (_context.prev = _context.next) {
105
+ case 0:
106
+ prevScriptTranspiledDeferred = opts.prevScriptTranspiledDeferred;
107
+ codeFactory = sandbox.makeEvaluateFactory(code, src);
108
+ if (!syncMode) {
109
+ _context.next = 7;
110
+ break;
111
+ }
112
+ if (!(prevScriptTranspiledDeferred && !prevScriptTranspiledDeferred.isSettled())) {
113
+ _context.next = 6;
114
+ break;
115
+ }
116
+ _context.next = 6;
117
+ return waitUntilSettled(prevScriptTranspiledDeferred.promise);
118
+ case 6:
119
+ // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script
120
+ script.fetchPriority = 'high';
121
+ case 7:
122
+ script.src = URL.createObjectURL(new Blob([codeFactory], {
123
+ type: 'text/javascript'
124
+ }));
125
+ scriptTranspiledDeferred === null || scriptTranspiledDeferred === void 0 || scriptTranspiledDeferred.resolve();
126
+ case 9:
127
+ case "end":
128
+ return _context.stop();
129
+ }
130
+ }, _callee);
131
+ }));
132
+ return function (_x) {
133
+ return _ref.apply(this, arguments);
134
+ };
135
+ }()).catch(function (e) {
136
+ scriptTranspiledDeferred === null || scriptTranspiledDeferred === void 0 || scriptTranspiledDeferred.reject();
137
+ throw e;
138
+ });
139
+ return script;
140
+ }
141
+ case Mode.INLINE_CODE_IN_SANDBOX:
142
+ {
143
+ var rawNode = opts.rawNode;
144
+ var scriptNode = script.textContent ? script : rawNode.childNodes[0];
145
+ var code = result.code;
146
+ scriptNode.textContent = sandbox.makeEvaluateFactory(code, baseURI);
147
+ // mark the script have consumed
148
+ script.dataset.consumed = 'true';
149
+ scriptTranspiledDeferred === null || scriptTranspiledDeferred === void 0 || scriptTranspiledDeferred.resolve();
150
+ return script;
151
+ }
152
+ case Mode.REUSED_DEP_IN_SANDBOX:
153
+ {
154
+ var url = result.url,
155
+ version = result.version,
156
+ _src = result.src;
157
+ script.dataset.src = _src;
158
+ script.dataset.version = version;
159
+ var _syncMode = !script.getAttribute('async');
99
160
  // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script
100
- if (syncMode) {
161
+ if (_syncMode) {
101
162
  script.fetchPriority = 'high';
102
163
  }
103
- script.src = URL.createObjectURL(new Blob([codeFactory], {
104
- type: 'text/javascript'
105
- }));
106
- });
107
- return script;
108
- }
109
- case Mode.INLINE_CODE_IN_SANDBOX:
110
- {
111
- var rawNode = opts.rawNode;
112
- var scriptNode = script.textContent ? script : rawNode.childNodes[0];
113
- var code = result.code;
114
- scriptNode.textContent = sandbox.makeEvaluateFactory(code, baseURI);
115
- // mark the script have consumed
116
- script.dataset.consumed = 'true';
117
- return script;
118
- }
119
- case Mode.REUSED_DEP_IN_SANDBOX:
120
- {
121
- var url = result.url,
122
- version = result.version,
123
- _src = result.src;
124
- script.dataset.src = _src;
125
- script.dataset.version = version;
126
- var _syncMode = !script.getAttribute('async');
127
- // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script
128
- if (_syncMode) {
129
- script.fetchPriority = 'high';
130
- }
131
164
 
132
- // When the script hits the dependency reuse logic, the current script is not executed, and an empty script is returned directly
133
- script.src = createReusingObjectUrl(_src, url, 'text/javascript');
134
- return script;
135
- }
136
- case Mode.NONE:
137
- default:
138
- {
139
- if (srcAttribute) {
140
- script.src = getEntireUrl(srcAttribute, baseURI);
165
+ // When the script hits the dependency reuse logic, the current script is not executed, and an empty script is returned directly
166
+ script.src = createReusingObjectUrl(_src, url, 'text/javascript');
167
+ scriptTranspiledDeferred === null || scriptTranspiledDeferred === void 0 || scriptTranspiledDeferred.resolve();
141
168
  return script;
142
169
  }
143
- return script;
144
- }
170
+ case Mode.NONE:
171
+ default:
172
+ {
173
+ if (srcAttribute) {
174
+ script.src = getEntireUrl(srcAttribute, baseURI);
175
+ }
176
+ scriptTranspiledDeferred === null || scriptTranspiledDeferred === void 0 || scriptTranspiledDeferred.resolve();
177
+ return script;
178
+ }
179
+ }
180
+ } catch (e) {
181
+ scriptTranspiledDeferred === null || scriptTranspiledDeferred === void 0 || scriptTranspiledDeferred.reject(e);
182
+ throw e;
145
183
  }
146
-
147
- // TODO find entry exports
148
184
  }
149
185
  //# sourceMappingURL=script.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getEntireUrl","Mode","createReusingObjectUrl","isValidJavaScriptType","getCredentials","crossOrigin","undefined","preTranspile","script","baseURI","opts","sandbox","moduleResolver","src","type","entireUrl","matchedScript","mode","REUSED_DEP_IN_SANDBOX","result","_objectSpread","REMOTE_ASSETS_IN_SANDBOX","rawNode","scriptNode","textContent","childNodes","code","INLINE_CODE_IN_SANDBOX","NONE","transpileScript","srcAttribute","getAttribute","fetch","removeAttribute","_preTranspile","dataset","syncMode","hasAttribute","priority","credentials","then","res","text","codeFactory","makeEvaluateFactory","fetchPriority","URL","createObjectURL","Blob","consumed","url","version"],"sources":["../../../src/assets-transpilers/script.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-16\n */\n\nimport type { MatchResult } from '../module-resolver';\nimport { getEntireUrl } from '../utils';\nimport type { AssetsTranspilerOpts } from './types';\nimport { Mode } from './types';\nimport { createReusingObjectUrl, isValidJavaScriptType } from './utils';\n\nconst getCredentials = (crossOrigin: string | null): RequestInit['credentials'] | undefined => {\n switch (crossOrigin) {\n case 'anonymous':\n return 'same-origin';\n case 'use-credentials':\n return 'include';\n default:\n return undefined;\n }\n};\n\ntype PreTranspileResult =\n | { mode: Mode.REMOTE_ASSETS_IN_SANDBOX; result: { src: string } }\n | { mode: Mode.REUSED_DEP_IN_SANDBOX; result: { src: string } & MatchResult }\n | { mode: Mode.INLINE_CODE_IN_SANDBOX; result: { code: string } }\n | { mode: Mode.NONE; result?: never };\n\nexport const preTranspile = (\n script: Partial<Pick<HTMLScriptElement, 'src' | 'type' | 'textContent'>>,\n baseURI: string,\n opts: AssetsTranspilerOpts,\n): PreTranspileResult => {\n const { sandbox, moduleResolver } = opts;\n\n const { src, type } = script;\n\n if (sandbox) {\n if (src) {\n const entireUrl = getEntireUrl(src, baseURI);\n const matchedScript = moduleResolver?.(entireUrl);\n if (matchedScript) {\n return {\n mode: Mode.REUSED_DEP_IN_SANDBOX,\n result: { src: entireUrl, ...matchedScript },\n };\n }\n\n return {\n mode: Mode.REMOTE_ASSETS_IN_SANDBOX,\n result: { src: entireUrl },\n };\n }\n\n if (isValidJavaScriptType(type)) {\n const rawNode = opts.rawNode as HTMLScriptElement;\n const scriptNode = script.textContent ? script : rawNode.childNodes[0];\n\n const code = scriptNode.textContent;\n if (code) {\n return {\n mode: Mode.INLINE_CODE_IN_SANDBOX,\n result: {\n code,\n },\n };\n }\n }\n }\n\n return { mode: Mode.NONE };\n};\n\nexport default function transpileScript(\n script: HTMLScriptElement,\n baseURI: string,\n opts: AssetsTranspilerOpts,\n): HTMLScriptElement {\n // Can't use script.src directly, because it will be resolved to absolute path by browser with Node.baseURI\n // Such as <script src=\"./foo.js\"></script> will be resolved to http://localhost:8000/foo.js while read script.src\n const srcAttribute = script.getAttribute('src');\n const { sandbox, fetch } = opts;\n\n // To prevent webpack from skipping reload logic and causing the js not to re-execute when a micro app is loaded multiple times, the data-webpack attribute of the script must be removed.\n // see https://github.com/webpack/webpack/blob/1f13ff9fe587e094df59d660b4611b1bd19aed4c/lib/runtime/LoadScriptRuntimeModule.js#L131-L136\n // FIXME We should determine whether the current micro application is being loaded for the second time. If not, this removal should not be performed.\n script.removeAttribute('data-webpack');\n\n const { mode, result } = preTranspile(\n {\n src: srcAttribute || undefined,\n type: script.type,\n textContent: script.textContent,\n },\n baseURI,\n opts,\n );\n\n switch (mode) {\n case Mode.REMOTE_ASSETS_IN_SANDBOX: {\n const { src } = result;\n\n // We must remove script src to avoid self execution as we need to fetch the script content and transpile it\n script.removeAttribute('src');\n script.dataset.src = src;\n\n const syncMode = !script.hasAttribute('async');\n const priority: Priority = syncMode ? 'high' : 'low';\n const credentials = getCredentials(script.crossOrigin);\n\n void fetch(src, { credentials, priority })\n .then((res) => res.text())\n .then((code) => {\n const codeFactory = sandbox!.makeEvaluateFactory(code, src);\n\n // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script\n if (syncMode) {\n script.fetchPriority = 'high';\n }\n\n script.src = URL.createObjectURL(new Blob([codeFactory], { type: 'text/javascript' }));\n });\n\n return script;\n }\n\n case Mode.INLINE_CODE_IN_SANDBOX: {\n const rawNode = opts.rawNode as HTMLScriptElement;\n const scriptNode = script.textContent ? script : rawNode.childNodes[0];\n const { code } = result;\n\n scriptNode.textContent = sandbox!.makeEvaluateFactory(code, baseURI);\n // mark the script have consumed\n script.dataset.consumed = 'true';\n\n return script;\n }\n\n case Mode.REUSED_DEP_IN_SANDBOX: {\n const { url, version, src } = result;\n\n script.dataset.src = src;\n script.dataset.version = version;\n\n const syncMode = !script.getAttribute('async');\n // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script\n if (syncMode) {\n script.fetchPriority = 'high';\n }\n\n // When the script hits the dependency reuse logic, the current script is not executed, and an empty script is returned directly\n script.src = createReusingObjectUrl(src, url, 'text/javascript');\n\n return script;\n }\n\n case Mode.NONE:\n default: {\n if (srcAttribute) {\n script.src = getEntireUrl(srcAttribute, baseURI);\n return script;\n }\n\n return script;\n }\n }\n\n // TODO find entry exports\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;;AAGA,SAASA,YAAY;AAErB,SAASC,IAAI;AACb,SAASC,sBAAsB,EAAEC,qBAAqB;AAEtD,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,WAA0B,EAA6C;EAC7F,QAAQA,WAAW;IACjB,KAAK,WAAW;MACd,OAAO,aAAa;IACtB,KAAK,iBAAiB;MACpB,OAAO,SAAS;IAClB;MACE,OAAOC,SAAS;EACpB;AACF,CAAC;AAQD,OAAO,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CACvBC,MAAwE,EACxEC,OAAe,EACfC,IAA0B,EACH;EACvB,IAAQC,OAAO,GAAqBD,IAAI,CAAhCC,OAAO;IAAEC,cAAc,GAAKF,IAAI,CAAvBE,cAAc;EAE/B,IAAQC,GAAG,GAAWL,MAAM,CAApBK,GAAG;IAAEC,IAAI,GAAKN,MAAM,CAAfM,IAAI;EAEjB,IAAIH,OAAO,EAAE;IACX,IAAIE,GAAG,EAAE;MACP,IAAME,SAAS,GAAGf,YAAY,CAACa,GAAG,EAAEJ,OAAO,CAAC;MAC5C,IAAMO,aAAa,GAAGJ,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAGG,SAAS,CAAC;MACjD,IAAIC,aAAa,EAAE;QACjB,OAA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AAC,CAAC,CAAC;QACtE,IAAQC,IAAI,GAAKP,MAAM,CAAfO,IAAI;QAEZH,UAAU,CAACC,WAAW,GAAGb,OAAO,CAAEiC,mBAAmB,CAAClB,IAAI,EAAEjB,OAAO,CAAC;QACpE;QACAD,MAAM,CAAC2B,OAAO,CAACc,QAAQ,GAAG,MAAM;QAEhC,OAAOzC,MAAM;MACf;IAEA,KAAKP,IAAI,CAACiB,qBAAqB;MAAE;QAC/B,IAAQgC,GAAG,GAAmB/B,MAAM,CAA5B+B,GAAG;UAAEC,OAAO,GAAUhC,MAAM,CAAvBgC,OAAO;UAAEtC,IAAG,GAAKM,MAAM,CAAdN,GAAG;QAEzBL,MAAM,CAAC2B,OAAO,CAACtB,GAAG,GAAGA,IAAG;QACxBL,MAAM,CAAC2B,OAAO,CAACgB,OAAO,GAAGA,OAAO;QAEhC,IAAMf,SAAQ,GAAG,CAAC5B,MAAM,CAACuB,YAAY,CAAC,OAAO,CAAC;QAC9C;QACA,IAAIK,SAAQ,EAAE;UACZ5B,MAAM,CAACqC,aAAa,GAAG,MAAM;QAC/B;;QAEA;QACArC,MAAM,CAACK,GAAG,GAAGX,sBAAsB,CAACW,IAAG,EAAEqC,GAAG,EAAE,iBAAiB,CAAC;QAEhE,OAAO1C,MAAM;MACf;IAEA,KAAKP,IAAI,CAAC2B,IAAI;IACd;MAAS;QACP,IAAIE,YAAY,EAAE;UAChBtB,MAAM,CAACK,GAAG,GAAGb,YAAY,CAAC8B,YAAY,EAAErB,OAAO,CAAC;UAChD,OAAOD,MAAM;QACf;QAEA,OAAOA,MAAM;MACf;EACF;;EAEA;AACF"}
1
+ {"version":3,"names":["getEntireUrl","waitUntilSettled","Mode","createReusingObjectUrl","isValidJavaScriptType","getCredentials","crossOrigin","undefined","preTranspile","script","baseURI","opts","sandbox","moduleResolver","src","type","entireUrl","matchedScript","mode","REUSED_DEP_IN_SANDBOX","result","_objectSpread","REMOTE_ASSETS_IN_SANDBOX","rawNode","scriptNode","textContent","childNodes","code","INLINE_CODE_IN_SANDBOX","NONE","transpileScript","srcAttribute","getAttribute","scriptTranspiledDeferred","removeAttribute","_preTranspile","fetch","dataset","syncMode","hasAttribute","priority","credentials","then","res","text","_ref","_asyncToGenerator","_regeneratorRuntime","mark","_callee","prevScriptTranspiledDeferred","codeFactory","wrap","_callee$","_context","prev","next","makeEvaluateFactory","isSettled","promise","fetchPriority","URL","createObjectURL","Blob","resolve","stop","_x","apply","arguments","catch","e","reject","consumed","url","version"],"sources":["../../../src/assets-transpilers/script.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-16\n */\n\nimport type { MatchResult } from '../module-resolver';\nimport { getEntireUrl, waitUntilSettled } from '../utils';\nimport type { AssetsTranspilerOpts, ScriptTranspilerOpts } from './types';\nimport { Mode } from './types';\nimport { createReusingObjectUrl, isValidJavaScriptType } from './utils';\n\nconst getCredentials = (crossOrigin: string | null): RequestInit['credentials'] | undefined => {\n switch (crossOrigin) {\n case 'anonymous':\n return 'same-origin';\n case 'use-credentials':\n return 'include';\n default:\n return undefined;\n }\n};\n\ntype PreTranspileResult =\n | { mode: Mode.REMOTE_ASSETS_IN_SANDBOX; result: { src: string } }\n | { mode: Mode.REUSED_DEP_IN_SANDBOX; result: { src: string } & MatchResult }\n | { mode: Mode.INLINE_CODE_IN_SANDBOX; result: { code: string } }\n | { mode: Mode.NONE; result?: never };\n\nexport const preTranspile = (\n script: Partial<Pick<HTMLScriptElement, 'src' | 'type' | 'textContent'>>,\n baseURI: string,\n opts: AssetsTranspilerOpts,\n): PreTranspileResult => {\n const { sandbox, moduleResolver } = opts;\n\n const { src, type } = script;\n\n if (sandbox) {\n if (src) {\n const entireUrl = getEntireUrl(src, baseURI);\n const matchedScript = moduleResolver?.(entireUrl);\n if (matchedScript) {\n return {\n mode: Mode.REUSED_DEP_IN_SANDBOX,\n result: { src: entireUrl, ...matchedScript },\n };\n }\n\n return {\n mode: Mode.REMOTE_ASSETS_IN_SANDBOX,\n result: { src: entireUrl },\n };\n }\n\n if (isValidJavaScriptType(type)) {\n const rawNode = opts.rawNode as HTMLScriptElement;\n const scriptNode = script.textContent ? script : rawNode.childNodes[0];\n\n const code = scriptNode.textContent;\n if (code) {\n return {\n mode: Mode.INLINE_CODE_IN_SANDBOX,\n result: {\n code,\n },\n };\n }\n }\n }\n\n return { mode: Mode.NONE };\n};\n\nexport default function transpileScript(\n script: HTMLScriptElement,\n baseURI: string,\n opts: ScriptTranspilerOpts,\n): HTMLScriptElement {\n // Can't use script.src directly, because it will be resolved to absolute path by browser with Node.baseURI\n // Such as <script src=\"./foo.js\"></script> will be resolved to http://localhost:8000/foo.js while read script.src\n const srcAttribute = script.getAttribute('src');\n const { sandbox, scriptTranspiledDeferred } = opts;\n\n // To prevent webpack from skipping reload logic and causing the js not to re-execute when a micro app is loaded multiple times, the data-webpack attribute of the script must be removed.\n // see https://github.com/webpack/webpack/blob/1f13ff9fe587e094df59d660b4611b1bd19aed4c/lib/runtime/LoadScriptRuntimeModule.js#L131-L136\n // FIXME We should determine whether the current micro application is being loaded for the second time. If not, this removal should not be performed.\n script.removeAttribute('data-webpack');\n\n try {\n const { mode, result } = preTranspile(\n {\n src: srcAttribute || undefined,\n type: script.type,\n textContent: script.textContent,\n },\n baseURI,\n opts,\n );\n\n switch (mode) {\n case Mode.REMOTE_ASSETS_IN_SANDBOX: {\n const { fetch } = opts;\n const { src } = result;\n\n // We must remove script src to avoid self execution as we need to fetch the script content and transpile it\n script.removeAttribute('src');\n script.dataset.src = src;\n\n const syncMode = !script.hasAttribute('async');\n const priority: Priority = syncMode ? 'high' : 'low';\n const credentials = getCredentials(script.crossOrigin);\n\n void fetch(src, { credentials, priority })\n .then((res) => res.text())\n .then(async (code) => {\n const { prevScriptTranspiledDeferred } = opts;\n const codeFactory = sandbox!.makeEvaluateFactory(code, src);\n\n if (syncMode) {\n // if it's a sync script and there is a previous sync script, we should wait it to finish fetching\n if (prevScriptTranspiledDeferred && !prevScriptTranspiledDeferred.isSettled()) {\n await waitUntilSettled(prevScriptTranspiledDeferred.promise);\n }\n\n // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script\n script.fetchPriority = 'high';\n }\n\n script.src = URL.createObjectURL(new Blob([codeFactory], { type: 'text/javascript' }));\n scriptTranspiledDeferred?.resolve();\n })\n .catch((e) => {\n scriptTranspiledDeferred?.reject();\n throw e;\n });\n\n return script;\n }\n\n case Mode.INLINE_CODE_IN_SANDBOX: {\n const rawNode = opts.rawNode as HTMLScriptElement;\n const scriptNode = script.textContent ? script : rawNode.childNodes[0];\n const { code } = result;\n\n scriptNode.textContent = sandbox!.makeEvaluateFactory(code, baseURI);\n // mark the script have consumed\n script.dataset.consumed = 'true';\n\n scriptTranspiledDeferred?.resolve();\n\n return script;\n }\n\n case Mode.REUSED_DEP_IN_SANDBOX: {\n const { url, version, src } = result;\n\n script.dataset.src = src;\n script.dataset.version = version;\n\n const syncMode = !script.getAttribute('async');\n // HTMLScriptElement default fetchPriority is 'auto', we should set it to 'high' to make it execute earlier while it's not async script\n if (syncMode) {\n script.fetchPriority = 'high';\n }\n\n // When the script hits the dependency reuse logic, the current script is not executed, and an empty script is returned directly\n script.src = createReusingObjectUrl(src, url, 'text/javascript');\n\n scriptTranspiledDeferred?.resolve();\n\n return script;\n }\n\n case Mode.NONE:\n default: {\n if (srcAttribute) {\n script.src = getEntireUrl(srcAttribute, baseURI);\n }\n\n scriptTranspiledDeferred?.resolve();\n\n return script;\n }\n }\n } catch (e) {\n scriptTranspiledDeferred?.reject(e);\n throw e;\n }\n}\n"],"mappings":";;;AAAA;AACA;AACA;AACA;;AAGA,SAASA,YAAY,EAAEC,gBAAgB;AAEvC,SAASC,IAAI;AACb,SAASC,sBAAsB,EAAEC,qBAAqB;AAEtD,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,WAA0B,EAA6C;EAC7F,QAAQA,WAAW;IACjB,KAAK,WAAW;MACd,OAAO,aAAa;IACtB,KAAK,iBAAiB;M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OAAOvD,MAAM;QACf;MAEA,KAAKP,IAAI,CAAC2B,IAAI;MACd;QAAS;UACP,IAAIE,YAAY,EAAE;YAChBtB,MAAM,CAACK,GAAG,GAAGd,YAAY,CAAC+B,YAAY,EAAErB,OAAO,CAAC;UAClD;UAEAuB,wBAAwB,aAAxBA,wBAAwB,eAAxBA,wBAAwB,CAAE+B,OAAO,CAAC,CAAC;UAEnC,OAAOvD,MAAM;QACf;IACF;EACF,CAAC,CAAC,OAAO6D,CAAC,EAAE;IACVrC,wBAAwB,aAAxBA,wBAAwB,eAAxBA,wBAAwB,CAAEsC,MAAM,CAACD,CAAC,CAAC;IACnC,MAAMA,CAAC;EACT;AACF"}
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import type { BaseLoaderOpts } from '../common';
6
6
  import type { MatchResult } from '../module-resolver';
7
+ import type { Deferred } from '../utils';
7
8
  export type BaseTranspilerOpts = BaseLoaderOpts & {
8
9
  moduleResolver?: (url: string) => MatchResult | undefined;
9
10
  sandbox?: {
@@ -13,6 +14,13 @@ export type BaseTranspilerOpts = BaseLoaderOpts & {
13
14
  export type AssetsTranspilerOpts = BaseTranspilerOpts & {
14
15
  rawNode: Node;
15
16
  };
17
+ export type ScriptTranspilerOpts = AssetsTranspilerOpts & ({
18
+ prevScriptTranspiledDeferred: Deferred<void>;
19
+ scriptTranspiledDeferred: Deferred<void>;
20
+ } | {
21
+ prevScriptTranspiledDeferred?: undefined;
22
+ scriptTranspiledDeferred?: undefined;
23
+ });
16
24
  export declare enum Mode {
17
25
  REMOTE_ASSETS_IN_SANDBOX = "RAIS",
18
26
  REUSED_DEP_IN_SANDBOX = "RDIS",
@@ -1 +1 @@
1
- {"version":3,"names":["Mode"],"sources":["../../../src/assets-transpilers/types.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-08-26\n */\nimport type { BaseLoaderOpts } from '../common';\nimport type { MatchResult } from '../module-resolver';\n\nexport type BaseTranspilerOpts = BaseLoaderOpts & {\n moduleResolver?: (url: string) => MatchResult | undefined;\n sandbox?: {\n makeEvaluateFactory(source: string, sourceURL?: string): string;\n };\n};\n\nexport type AssetsTranspilerOpts = BaseTranspilerOpts & { rawNode: Node };\n\nexport enum Mode {\n REMOTE_ASSETS_IN_SANDBOX = 'RAIS',\n REUSED_DEP_IN_SANDBOX = 'RDIS',\n INLINE_CODE_IN_SANDBOX = 'ICIS',\n NONE = 'NONE',\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAaA,WAAYA,IAAI,0BAAJA,IAAI;EAAJA,IAAI;EAAJA,IAAI;EAAJA,IAAI;EAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA"}
1
+ {"version":3,"names":["Mode"],"sources":["../../../src/assets-transpilers/types.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-08-26\n */\nimport type { BaseLoaderOpts } from '../common';\nimport type { MatchResult } from '../module-resolver';\nimport type { Deferred } from '../utils';\n\nexport type BaseTranspilerOpts = BaseLoaderOpts & {\n moduleResolver?: (url: string) => MatchResult | undefined;\n sandbox?: {\n makeEvaluateFactory(source: string, sourceURL?: string): string;\n };\n};\n\nexport type AssetsTranspilerOpts = BaseTranspilerOpts & { rawNode: Node };\n\nexport type ScriptTranspilerOpts = AssetsTranspilerOpts &\n (\n | { prevScriptTranspiledDeferred: Deferred<void>; scriptTranspiledDeferred: Deferred<void> }\n | { prevScriptTranspiledDeferred?: undefined; scriptTranspiledDeferred?: undefined }\n );\n\nexport enum Mode {\n REMOTE_ASSETS_IN_SANDBOX = 'RAIS',\n REUSED_DEP_IN_SANDBOX = 'RDIS',\n INLINE_CODE_IN_SANDBOX = 'ICIS',\n NONE = 'NONE',\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAoBA,WAAYA,IAAI,0BAAJA,IAAI;EAAJA,IAAI;EAAJA,IAAI;EAAJA,IAAI;EAAJA,IAAI;EAAA,OAAJA,IAAI;AAAA"}
@@ -17,10 +17,17 @@ export declare const create: {
17
17
  };
18
18
  export declare const hasOwnProperty: (caller: unknown, p: PropertyKey) => boolean;
19
19
  export declare class Deferred<T> {
20
+ #private;
20
21
  promise: Promise<T>;
21
- status: 'pending' | 'fulfilled' | 'rejected';
22
22
  resolve: (value: T | PromiseLike<T>) => void;
23
23
  reject: (reason?: unknown) => void;
24
24
  constructor();
25
+ isSettled(): boolean;
25
26
  }
27
+ export declare function waitUntilSettled(promise: Promise<void>): Promise<void>;
26
28
  export declare function getEntireUrl(uri: string, baseURI: string): string;
29
+ /**
30
+ * Check if the running environment support qiankun3.0
31
+ *
32
+ */
33
+ export declare function isRuntimeCompatible(): boolean;
package/dist/esm/utils.js CHANGED
@@ -1,6 +1,12 @@
1
- import _createClass from "@babel/runtime/helpers/esm/createClass";
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
4
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
+ import _classPrivateFieldGet from "@babel/runtime/helpers/esm/classPrivateFieldGet";
6
+ import _classPrivateFieldSet from "@babel/runtime/helpers/esm/classPrivateFieldSet";
7
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
8
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
9
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
4
10
  /**
5
11
  * @author Kuitos
6
12
  * @since 2023-04-26
@@ -17,27 +23,80 @@ export { create, defineProperty, getOwnPropertyDescriptor, getOwnPropertyNames,
17
23
  export var hasOwnProperty = function hasOwnProperty(caller, p) {
18
24
  return Object.prototype.hasOwnProperty.call(caller, p);
19
25
  };
20
- export var Deferred = /*#__PURE__*/_createClass(function Deferred() {
21
- var _this = this;
22
- _classCallCheck(this, Deferred);
23
- _defineProperty(this, "promise", void 0);
24
- _defineProperty(this, "status", 'pending');
25
- _defineProperty(this, "resolve", void 0);
26
- _defineProperty(this, "reject", void 0);
27
- this.promise = new Promise(function (resolve, reject) {
28
- _this.resolve = function (value) {
29
- _this.status = 'fulfilled';
30
- resolve(value);
31
- };
32
- _this.reject = function (reason) {
33
- _this.status = 'rejected';
34
- reject(reason);
35
- };
36
- });
37
- });
26
+ var _status = /*#__PURE__*/new WeakMap();
27
+ export var Deferred = /*#__PURE__*/function () {
28
+ function Deferred() {
29
+ var _this = this;
30
+ _classCallCheck(this, Deferred);
31
+ _defineProperty(this, "promise", void 0);
32
+ _classPrivateFieldInitSpec(this, _status, {
33
+ writable: true,
34
+ value: 'pending'
35
+ });
36
+ _defineProperty(this, "resolve", void 0);
37
+ _defineProperty(this, "reject", void 0);
38
+ this.promise = new Promise(function (resolve, reject) {
39
+ _this.resolve = function (value) {
40
+ _classPrivateFieldSet(_this, _status, 'fulfilled');
41
+ resolve(value);
42
+ };
43
+ _this.reject = function (reason) {
44
+ _classPrivateFieldSet(_this, _status, 'rejected');
45
+ reject(reason);
46
+ };
47
+ });
48
+ }
49
+ _createClass(Deferred, [{
50
+ key: "isSettled",
51
+ value: function isSettled() {
52
+ return _classPrivateFieldGet(this, _status) !== 'pending';
53
+ }
54
+ }]);
55
+ return Deferred;
56
+ }();
57
+ export function waitUntilSettled(_x) {
58
+ return _waitUntilSettled.apply(this, arguments);
59
+ }
60
+ function _waitUntilSettled() {
61
+ _waitUntilSettled = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(promise) {
62
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
63
+ while (1) switch (_context.prev = _context.next) {
64
+ case 0:
65
+ _context.prev = 0;
66
+ _context.next = 3;
67
+ return promise;
68
+ case 3:
69
+ _context.next = 8;
70
+ break;
71
+ case 5:
72
+ _context.prev = 5;
73
+ _context.t0 = _context["catch"](0);
74
+ if (process.env.NODE_ENV === 'development') {
75
+ console.warn('waitUntilSettled error', _context.t0);
76
+ }
77
+ case 8:
78
+ case "end":
79
+ return _context.stop();
80
+ }
81
+ }, _callee, null, [[0, 5]]);
82
+ }));
83
+ return _waitUntilSettled.apply(this, arguments);
84
+ }
38
85
  export function getEntireUrl(uri, baseURI) {
39
86
  var publicPath = new URL(baseURI, window.location.href);
40
87
  var entireUrl = new URL(uri, publicPath.toString());
41
88
  return entireUrl.toString();
42
89
  }
90
+
91
+ /**
92
+ * Check if the running environment support qiankun3.0
93
+ *
94
+ */
95
+ export function isRuntimeCompatible() {
96
+ var _URL;
97
+ return (
98
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
99
+ typeof Proxy === 'function' && typeof TransformStream === 'function' && typeof ((_URL = URL) === null || _URL === void 0 ? void 0 : _URL.createObjectURL) === 'function'
100
+ );
101
+ }
43
102
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["create","Object","defineProperty","getOwnPropertyDescriptor","getOwnPropertyNames","freeze","keys","hasOwnProperty","caller","p","prototype","call","Deferred","_createClass","_this","_classCallCheck","_defineProperty","promise","Promise","resolve","reject","value","status","reason","getEntireUrl","uri","baseURI","publicPath","URL","window","location","href","entireUrl","toString"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-04-26\n */\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nexport const { create, defineProperty, getOwnPropertyDescriptor, getOwnPropertyNames, freeze, keys } = Object;\nexport const hasOwnProperty = (caller: unknown, p: PropertyKey) => Object.prototype.hasOwnProperty.call(caller, p);\n\nexport class Deferred<T> {\n promise: Promise<T>;\n\n status: 'pending' | 'fulfilled' | 'rejected' = 'pending';\n\n resolve!: (value: T | PromiseLike<T>) => void;\n\n reject!: (reason?: unknown) => void;\n\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.resolve = (value: T | PromiseLike<T>) => {\n this.status = 'fulfilled';\n resolve(value);\n };\n this.reject = (reason?: unknown) => {\n this.status = 'rejected';\n reject(reason);\n };\n });\n }\n}\n\nexport function getEntireUrl(uri: string, baseURI: string): string {\n const publicPath = new URL(baseURI, window.location.href);\n const entireUrl = new URL(uri, publicPath.toString());\n return entireUrl.toString();\n}\n"],"mappings":";;;AAAA;AACA;AACA;AACA;;AAEA;AACO,IAAQA,MAAM,GAAkFC,MAAM,CAA9FD,MAAM;EAAEE,cAAc,GAAkED,MAAM,CAAtFC,cAAc;EAAEC,wBAAwB,GAAwCF,MAAM,CAAtEE,wBAAwB;EAAEC,mBAAmB,GAAmBH,MAAM,CAA5CG,mBAAmB;EAAEC,MAAM,GAAWJ,MAAM,CAAvBI,MAAM;EAAEC,IAAI,GAAKL,MAAM,CAAfK,IAAI;AAAY,SAAAN,MAAA,EAAAE,cAAA,EAAAC,wBAAA,EAAAC,mBAAA,EAAAC,MAAA,EAAAC,IAAA;AAC9G,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,MAAe,EAAEC,CAAc;EAAA,OAAKR,MAAM,CAACS,SAAS,CAACH,cAAc,CAACI,IAAI,CAACH,MAAM,EAAEC,CAAC,CAAC;AAAA;AAElH,WAAaG,QAAQ,gBAAAC,YAAA,CASnB,SAAAD,SAAA,EAAc;EAAA,IAAAE,KAAA;EAAAC,eAAA,OAAAH,QAAA;EAAAI,eAAA;EAAAA,eAAA,iBANiC,SAAS;EAAAA,eAAA;EAAAA,eAAA;EAOtD,IAAI,CAACC,OAAO,GAAG,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IAC9CN,KAAI,CAACK,OAAO,GAAG,UAACE,KAAyB,EAAK;MAC5CP,KAAI,CAACQ,MAAM,GAAG,WAAW;MACzBH,OAAO,CAACE,KAAK,CAAC;IAChB,CAAC;IACDP,KAAI,CAACM,MAAM,GAAG,UAACG,MAAgB,EAAK;MAClCT,KAAI,CAACQ,MAAM,GAAG,UAAU;MACxBF,MAAM,CAACG,MAAM,CAAC;IAChB,CAAC;EACH,CAAC,CAAC;AACJ,CAAC;AAGH,OAAO,SAASC,YAAYA,CAACC,GAAW,EAAEC,OAAe,EAAU;EACjE,IAAMC,UAAU,GAAG,IAAIC,GAAG,CAACF,OAAO,EAAEG,MAAM,CAACC,QAAQ,CAACC,IAAI,CAAC;EACzD,IAAMC,SAAS,GAAG,IAAIJ,GAAG,CAACH,GAAG,EAAEE,UAAU,CAACM,QAAQ,CAAC,CAAC,CAAC;EACrD,OAAOD,SAAS,CAACC,QAAQ,CAAC,CAAC;AAC7B"}
1
+ {"version":3,"names":["create","Object","defineProperty","getOwnPropertyDescriptor","getOwnPropertyNames","freeze","keys","hasOwnProperty","caller","p","prototype","call","_status","WeakMap","Deferred","_this","_classCallCheck","_defineProperty","_classPrivateFieldInitSpec","writable","value","promise","Promise","resolve","reject","_classPrivateFieldSet","reason","_createClass","key","isSettled","_classPrivateFieldGet","waitUntilSettled","_x","_waitUntilSettled","apply","arguments","_asyncToGenerator","_regeneratorRuntime","mark","_callee","wrap","_callee$","_context","prev","next","t0","process","env","NODE_ENV","console","warn","stop","getEntireUrl","uri","baseURI","publicPath","URL","window","location","href","entireUrl","toString","isRuntimeCompatible","_URL","Proxy","TransformStream","createObjectURL"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-04-26\n */\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nexport const { create, defineProperty, getOwnPropertyDescriptor, getOwnPropertyNames, freeze, keys } = Object;\nexport const hasOwnProperty = (caller: unknown, p: PropertyKey) => Object.prototype.hasOwnProperty.call(caller, p);\n\nexport class Deferred<T> {\n promise: Promise<T>;\n\n #status: 'pending' | 'fulfilled' | 'rejected' = 'pending';\n\n resolve!: (value: T | PromiseLike<T>) => void;\n\n reject!: (reason?: unknown) => void;\n\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.resolve = (value: T | PromiseLike<T>) => {\n this.#status = 'fulfilled';\n resolve(value);\n };\n this.reject = (reason?: unknown) => {\n this.#status = 'rejected';\n reject(reason);\n };\n });\n }\n\n isSettled(): boolean {\n return this.#status !== 'pending';\n }\n}\n\nexport async function waitUntilSettled(promise: Promise<void>): Promise<void> {\n try {\n await promise;\n } catch (e) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('waitUntilSettled error', e);\n }\n }\n}\n\nexport function getEntireUrl(uri: string, baseURI: string): string {\n const publicPath = new URL(baseURI, window.location.href);\n const entireUrl = new URL(uri, publicPath.toString());\n return entireUrl.toString();\n}\n\n/**\n * Check if the running environment support qiankun3.0\n *\n */\nexport function isRuntimeCompatible(): boolean {\n return (\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n typeof Proxy === 'function' && typeof TransformStream === 'function' && typeof URL?.createObjectURL === 'function'\n );\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;;AAEA;AACO,IAAQA,MAAM,GAAkFC,MAAM,CAA9FD,MAAM;EAAEE,cAAc,GAAkED,MAAM,CAAtFC,cAAc;EAAEC,wBAAwB,GAAwCF,MAAM,CAAtEE,wBAAwB;EAAEC,mBAAmB,GAAmBH,MAAM,CAA5CG,mBAAmB;EAAEC,MAAM,GAAWJ,MAAM,CAAvBI,MAAM;EAAEC,IAAI,GAAKL,MAAM,CAAfK,IAAI;AAAY,SAAAN,MAAA,EAAAE,cAAA,EAAAC,wBAAA,EAAAC,mBAAA,EAAAC,MAAA,EAAAC,IAAA;AAC9G,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,MAAe,EAAEC,CAAc;EAAA,OAAKR,MAAM,CAACS,SAAS,CAACH,cAAc,CAACI,IAAI,CAACH,MAAM,EAAEC,CAAC,CAAC;AAAA;AAAC,IAAAG,OAAA,oBAAAC,OAAA;AAEnH,WAAaC,QAAQ;EASnB,SAAAA,SAAA,EAAc;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAF,QAAA;IAAAG,eAAA;IAAAC,0BAAA,OAAAN,OAAA;MAAAO,QAAA;MAAAC,KAAA,EANkC;IAAS;IAAAH,e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3C;QAAC;QAAA;UAAA,OAAAH,QAAA,CAAAS,IAAA;MAAA;IAAA,GAAAZ,OAAA;EAAA,CAEJ;EAAA,OAAAN,iBAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AAED,OAAO,SAASiB,YAAYA,CAACC,GAAW,EAAEC,OAAe,EAAU;EACjE,IAAMC,UAAU,GAAG,IAAIC,GAAG,CAACF,OAAO,EAAEG,MAAM,CAACC,QAAQ,CAACC,IAAI,CAAC;EACzD,IAAMC,SAAS,GAAG,IAAIJ,GAAG,CAACH,GAAG,EAAEE,UAAU,CAACM,QAAQ,CAAC,CAAC,CAAC;EACrD,OAAOD,SAAS,CAACC,QAAQ,CAAC,CAAC;AAC7B;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAAA,EAAY;EAAA,IAAAC,IAAA;EAC7C;IACE;IACA,OAAOC,KAAK,KAAK,UAAU,IAAI,OAAOC,eAAe,KAAK,UAAU,IAAI,SAAAF,IAAA,GAAOP,GAAG,cAAAO,IAAA,uBAAHA,IAAA,CAAKG,eAAe,MAAK;EAAU;AAEtH"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@qiankunjs/shared",
3
- "version": "0.0.1-rc.4",
4
- "description": "",
3
+ "version": "0.0.1-rc.5",
4
+ "description": "internal shared package for qiankun",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
7
- "types": "./src/index.ts",
7
+ "types": "./dist/esm/index.d.ts",
8
8
  "sideEffects": false,
9
9
  "author": "Kuitos",
10
10
  "license": "MIT",
@@ -14,8 +14,7 @@
14
14
  "semver": "^7.5.3"
15
15
  },
16
16
  "files": [
17
- "dist",
18
- "src"
17
+ "dist"
19
18
  ],
20
19
  "publishConfig": {
21
20
  "registry": "https://registry.npmjs.org/"
@@ -1,42 +0,0 @@
1
- /**
2
- * @author Kuitos
3
- * @since 2023-03-14
4
- */
5
- import transpileLink from './link';
6
- import transpileScript from './script';
7
- import type { AssetsTranspilerOpts } from './types';
8
-
9
- export function transpileAssets<T extends Node>(node: T, baseURI: string, opts: AssetsTranspilerOpts): T {
10
- const htmlElement = node as unknown as HTMLElement;
11
- const { tagName } = htmlElement;
12
-
13
- switch (tagName) {
14
- case 'SCRIPT': {
15
- return transpileScript(htmlElement as HTMLScriptElement, baseURI, opts) as unknown as T;
16
- }
17
-
18
- case 'LINK': {
19
- return transpileLink(htmlElement as HTMLLinkElement, baseURI, opts) as unknown as T;
20
- }
21
-
22
- default:
23
- break;
24
- }
25
-
26
- // TODO need to deal with the text scenario of script
27
- // const { nodeType } = node;
28
- // switch (nodeType) {
29
- // case Node.TEXT_NODE: {
30
- // if (node.parentNode?.nodeName === 'script') {
31
- // break;
32
- // }
33
- // }
34
- //
35
- // }
36
- // }
37
- return node;
38
- }
39
-
40
- export type * from './types';
41
-
42
- export { isValidJavaScriptType } from './utils';