@qiankunjs/single-spa 0.0.1-rc.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.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/dist/cjs/applications/app-errors.d.ts +11 -0
  4. package/dist/cjs/applications/app-errors.js +57 -0
  5. package/dist/cjs/applications/app-errors.js.map +1 -0
  6. package/dist/cjs/applications/app.helpers.d.ts +52 -0
  7. package/dist/cjs/applications/app.helpers.js +47 -0
  8. package/dist/cjs/applications/app.helpers.js.map +1 -0
  9. package/dist/cjs/applications/apps.d.ts +23 -0
  10. package/dist/cjs/applications/apps.js +234 -0
  11. package/dist/cjs/applications/apps.js.map +1 -0
  12. package/dist/cjs/applications/timeouts.d.ts +19 -0
  13. package/dist/cjs/applications/timeouts.js +115 -0
  14. package/dist/cjs/applications/timeouts.js.map +1 -0
  15. package/dist/cjs/declarations.d.ts +4 -0
  16. package/dist/cjs/devtools/devtools.d.ts +16 -0
  17. package/dist/cjs/devtools/devtools.js +24 -0
  18. package/dist/cjs/devtools/devtools.js.map +1 -0
  19. package/dist/cjs/devtools/profiler.d.ts +11 -0
  20. package/dist/cjs/devtools/profiler.js +25 -0
  21. package/dist/cjs/devtools/profiler.js.map +1 -0
  22. package/dist/cjs/index.d.ts +1 -0
  23. package/dist/cjs/index.js +32 -0
  24. package/dist/cjs/jquery-support.d.ts +7 -0
  25. package/dist/cjs/jquery-support.js +34 -0
  26. package/dist/cjs/jquery-support.js.map +1 -0
  27. package/dist/cjs/lifecycles/bootstrap.d.ts +2 -0
  28. package/dist/cjs/lifecycles/bootstrap.js +27 -0
  29. package/dist/cjs/lifecycles/bootstrap.js.map +1 -0
  30. package/dist/cjs/lifecycles/lifecycle.helpers.d.ts +90 -0
  31. package/dist/cjs/lifecycles/lifecycle.helpers.js +33 -0
  32. package/dist/cjs/lifecycles/lifecycle.helpers.js.map +1 -0
  33. package/dist/cjs/lifecycles/load.d.ts +3 -0
  34. package/dist/cjs/lifecycles/load.js +73 -0
  35. package/dist/cjs/lifecycles/load.js.map +1 -0
  36. package/dist/cjs/lifecycles/mount.d.ts +2 -0
  37. package/dist/cjs/lifecycles/mount.js +40 -0
  38. package/dist/cjs/lifecycles/mount.js.map +1 -0
  39. package/dist/cjs/lifecycles/prop.helpers.d.ts +9 -0
  40. package/dist/cjs/lifecycles/prop.helpers.js +23 -0
  41. package/dist/cjs/lifecycles/prop.helpers.js.map +1 -0
  42. package/dist/cjs/lifecycles/unload.d.ts +12 -0
  43. package/dist/cjs/lifecycles/unload.js +63 -0
  44. package/dist/cjs/lifecycles/unload.js.map +1 -0
  45. package/dist/cjs/lifecycles/unmount.d.ts +2 -0
  46. package/dist/cjs/lifecycles/unmount.js +32 -0
  47. package/dist/cjs/lifecycles/unmount.js.map +1 -0
  48. package/dist/cjs/lifecycles/update.d.ts +2 -0
  49. package/dist/cjs/lifecycles/update.js +22 -0
  50. package/dist/cjs/lifecycles/update.js.map +1 -0
  51. package/dist/cjs/navigation/navigation-events.d.ts +8 -0
  52. package/dist/cjs/navigation/navigation-events.js +102 -0
  53. package/dist/cjs/navigation/navigation-events.js.map +1 -0
  54. package/dist/cjs/navigation/reroute.d.ts +9 -0
  55. package/dist/cjs/navigation/reroute.js +182 -0
  56. package/dist/cjs/navigation/reroute.js.map +1 -0
  57. package/dist/cjs/parcels/mount-parcel.d.ts +3 -0
  58. package/dist/cjs/parcels/mount-parcel.js +122 -0
  59. package/dist/cjs/parcels/mount-parcel.js.map +1 -0
  60. package/dist/cjs/single-spa.d.ts +19 -0
  61. package/dist/cjs/single-spa.js +39 -0
  62. package/dist/cjs/single-spa.js.map +1 -0
  63. package/dist/cjs/start.d.ts +5 -0
  64. package/dist/cjs/start.js +21 -0
  65. package/dist/cjs/start.js.map +1 -0
  66. package/dist/cjs/utils/runtime-environment.d.ts +1 -0
  67. package/dist/cjs/utils/runtime-environment.js +7 -0
  68. package/dist/cjs/utils/runtime-environment.js.map +1 -0
  69. package/dist/cjs/window-globals.d.ts +8 -0
  70. package/dist/esm/applications/app-errors.d.ts +11 -0
  71. package/dist/esm/applications/app-errors.js +52 -0
  72. package/dist/esm/applications/app-errors.js.map +1 -0
  73. package/dist/esm/applications/app.helpers.d.ts +52 -0
  74. package/dist/esm/applications/app.helpers.js +41 -0
  75. package/dist/esm/applications/app.helpers.js.map +1 -0
  76. package/dist/esm/applications/apps.d.ts +23 -0
  77. package/dist/esm/applications/apps.js +223 -0
  78. package/dist/esm/applications/apps.js.map +1 -0
  79. package/dist/esm/applications/timeouts.d.ts +19 -0
  80. package/dist/esm/applications/timeouts.js +109 -0
  81. package/dist/esm/applications/timeouts.js.map +1 -0
  82. package/dist/esm/declarations.d.ts +4 -0
  83. package/dist/esm/devtools/devtools.d.ts +16 -0
  84. package/dist/esm/devtools/devtools.js +20 -0
  85. package/dist/esm/devtools/devtools.js.map +1 -0
  86. package/dist/esm/devtools/profiler.d.ts +11 -0
  87. package/dist/esm/devtools/profiler.js +22 -0
  88. package/dist/esm/devtools/profiler.js.map +1 -0
  89. package/dist/esm/index.d.ts +1 -0
  90. package/dist/esm/index.js +10 -0
  91. package/dist/esm/jquery-support.d.ts +7 -0
  92. package/dist/esm/jquery-support.js +33 -0
  93. package/dist/esm/jquery-support.js.map +1 -0
  94. package/dist/esm/lifecycles/bootstrap.d.ts +2 -0
  95. package/dist/esm/lifecycles/bootstrap.js +26 -0
  96. package/dist/esm/lifecycles/bootstrap.js.map +1 -0
  97. package/dist/esm/lifecycles/lifecycle.helpers.d.ts +90 -0
  98. package/dist/esm/lifecycles/lifecycle.helpers.js +30 -0
  99. package/dist/esm/lifecycles/lifecycle.helpers.js.map +1 -0
  100. package/dist/esm/lifecycles/load.d.ts +3 -0
  101. package/dist/esm/lifecycles/load.js +72 -0
  102. package/dist/esm/lifecycles/load.js.map +1 -0
  103. package/dist/esm/lifecycles/mount.d.ts +2 -0
  104. package/dist/esm/lifecycles/mount.js +39 -0
  105. package/dist/esm/lifecycles/mount.js.map +1 -0
  106. package/dist/esm/lifecycles/prop.helpers.d.ts +9 -0
  107. package/dist/esm/lifecycles/prop.helpers.js +22 -0
  108. package/dist/esm/lifecycles/prop.helpers.js.map +1 -0
  109. package/dist/esm/lifecycles/unload.d.ts +12 -0
  110. package/dist/esm/lifecycles/unload.js +60 -0
  111. package/dist/esm/lifecycles/unload.js.map +1 -0
  112. package/dist/esm/lifecycles/unmount.d.ts +2 -0
  113. package/dist/esm/lifecycles/unmount.js +31 -0
  114. package/dist/esm/lifecycles/unmount.js.map +1 -0
  115. package/dist/esm/lifecycles/update.d.ts +2 -0
  116. package/dist/esm/lifecycles/update.js +21 -0
  117. package/dist/esm/lifecycles/update.js.map +1 -0
  118. package/dist/esm/navigation/navigation-events.d.ts +8 -0
  119. package/dist/esm/navigation/navigation-events.js +92 -0
  120. package/dist/esm/navigation/navigation-events.js.map +1 -0
  121. package/dist/esm/navigation/reroute.d.ts +9 -0
  122. package/dist/esm/navigation/reroute.js +180 -0
  123. package/dist/esm/navigation/reroute.js.map +1 -0
  124. package/dist/esm/parcels/mount-parcel.d.ts +3 -0
  125. package/dist/esm/parcels/mount-parcel.js +120 -0
  126. package/dist/esm/parcels/mount-parcel.js.map +1 -0
  127. package/dist/esm/single-spa.d.ts +19 -0
  128. package/dist/esm/single-spa.js +17 -0
  129. package/dist/esm/single-spa.js.map +1 -0
  130. package/dist/esm/start.d.ts +5 -0
  131. package/dist/esm/start.js +19 -0
  132. package/dist/esm/start.js.map +1 -0
  133. package/dist/esm/utils/runtime-environment.d.ts +1 -0
  134. package/dist/esm/utils/runtime-environment.js +6 -0
  135. package/dist/esm/utils/runtime-environment.js.map +1 -0
  136. package/dist/esm/window-globals.d.ts +8 -0
  137. package/package.json +25 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ License (MIT)
2
+
3
+ Copyright (c) 2020 single-spa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @qiankunjs/single-spa
2
+
3
+ qiankun's vendored fork of [single-spa](https://github.com/single-spa/single-spa), consumed by the `qiankun` package as its application/parcel lifecycle router. See the vendoring RFC in [umijs/qiankun#3168](https://github.com/umijs/qiankun/issues/3168) for the full rationale and plan.
4
+
5
+ ## Fork baseline
6
+
7
+ - Upstream: `single-spa/single-spa`, `7.0` branch @ [`ce0f925a`](https://github.com/single-spa/single-spa/commit/ce0f925a40a81809c598de21b36ad79706222a73) (tag `v7.0.0-beta.13`, 2025-09-22).
8
+ - Imported verbatim (`src/`, `spec/`, `node-spec/`, `LICENSE`), then naturalized to this monorepo's toolchain (Vite 8 build, `tsc` declarations, vitest). Upstream rollup/babel/jest configs were not carried over; the compile-time constants they injected (`__DEV__`, `__PROFILE__`, `process.env.BABEL_ENV`) are provided by `vite.library.config.ts` (build) and the root `vitest.config.ts` (tests).
9
+ - The profile variant entry (`src/single-spa.profile.ts` + `src/devtools/profiler-api.ts`) is kept in the tree but not built or published yet; `__PROFILE__` is compiled to `false`.
10
+ - Versioning is independent of upstream beta numbering and follows this monorepo's changesets flow.
11
+
12
+ ## Behavioral divergences from upstream
13
+
14
+ Maintained deliberately; this list is the contract (keep it in sync when adding divergences):
15
+
16
+ 1. **The upstream `bootstrap` → `init` rename ([single-spa#1307](https://github.com/single-spa/single-spa/pull/1307), completed by [#1333](https://github.com/single-spa/single-spa/pull/1333)) is reverted wholesale — this fork speaks pure v6 vocabulary, with no `init` aliases.** qiankun's ecosystem was built on the bootstrap vocabulary and there was no reason to break it. Concretely:
17
+ - the `bootstrap` lifecycle is the only recognized name for applications and parcels (a v7-style `init` export is ignored, exactly as v6 ignored unknown fields);
18
+ - `parcel.bootstrapPromise`, `setBootstrapMaxTime` and the `timeouts.bootstrap` key are back; `initPromise`, `setInitMaxTime` and `timeouts.init` do not exist;
19
+ - the `NOT_BOOTSTRAPPED` / `BOOTSTRAPPING` statuses are restored, both as `AppOrParcelStatus` member names and as the raw `getStatus()` string values (v7's `NOT_INITIALIZED` / `INITIALIZING` strings do not exist in this fork);
20
+ - error message texts use the bootstrap vocabulary again;
21
+ - the vendored upstream specs were migrated back to the bootstrap vocabulary along with the sources.
22
+
23
+ If upstream ever ships a stable (non-beta) v7 that still carries the rename, re-evaluate aligning with it then — until that day this fork does not track it.
24
+
25
+ ## Invariant contracts (never break)
26
+
27
+ - All `single-spa:*` window events (`single-spa:before-routing-event`, `single-spa:routing-event`, `single-spa:no-app-change`, `single-spa:first-mount`, …) — qiankun and the wider ecosystem listen to them.
28
+ - The `window.__SINGLE_SPA_DEVTOOLS__` hook (single-spa-inspector support).
29
+ - Public API and type signatures stay 1:1 with the upstream baseline during phase one, except for the bootstrap-naming revert above — qiankun-observable behavior stays 1:1 with what its ecosystem shipped against, which is the higher-priority contract.
30
+ - Zero runtime dependencies; this package sits at the bottom of the workspace dependency graph and must not import `@qiankunjs/shared`, `@qiankunjs/sandbox` or `@qiankunjs/loader`.
31
+
32
+ ## Known semantics now owned by this fork
33
+
34
+ - `urlRerouteOnly` (documented at length in qiankun's `docs/api/start.md`) — qiankun passes it through untouched; the implementation and its semantics live here now.
35
+ - **Single-instance assumption**: single-spa is a stateful routing singleton. Loading both the ESM and CJS builds in one page (or mixing this fork with a separately installed npm `single-spa`) silently creates two independent routers — two history patches, two event streams, two `started` flags. Don't.
36
+
37
+ ## Upstream sync
38
+
39
+ Expected cadence ≈ zero (upstream is dormant). If a fix is worth absorbing:
40
+
41
+ ```bash
42
+ git remote add single-spa-upstream https://github.com/single-spa/single-spa.git
43
+ git fetch single-spa-upstream 7.0
44
+ git log ce0f925a..single-spa-upstream/7.0 --oneline # review the delta
45
+ # apply selected commits manually onto packages/single-spa/src/ (path prefixes differ)
46
+ ```
47
+
48
+ Update the baseline note above after absorbing anything; on conflict with the divergence list, the divergence list wins.
49
+
50
+ ## License
51
+
52
+ MIT — upstream's [LICENSE](./LICENSE) is preserved.
@@ -0,0 +1,11 @@
1
+ import { AppOrParcel } from '../lifecycles/lifecycle.helpers';
2
+ import { AppOrParcelStatus } from './app.helpers';
3
+ export type SingleSpaError = Error & {
4
+ appOrParcelName: string;
5
+ };
6
+ export type ErrorHandler = (err: SingleSpaError) => any;
7
+ export declare function handleAppError(err: Error, app: AppOrParcel, newStatus: AppOrParcelStatus): void;
8
+ export declare function addErrorHandler(handler: any): void;
9
+ export declare function removeErrorHandler(handler: any): boolean;
10
+ export declare function formatErrorMessage(code: any, msg: any, ...args: any[]): string;
11
+ export declare function transformErr(ogErr: Error, appOrParcel: AppOrParcel, newStatus: AppOrParcelStatus): SingleSpaError;
@@ -0,0 +1,57 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_applications_app_helpers = require("./app.helpers.js");
3
+ //#region src/applications/app-errors.ts
4
+ var errorHandlers = [];
5
+ function handleAppError(err, app, newStatus) {
6
+ const transformedErr = transformErr(err, app, newStatus);
7
+ if (errorHandlers.length) errorHandlers.forEach((handler) => handler(transformedErr));
8
+ else setTimeout(() => {
9
+ throw transformedErr;
10
+ });
11
+ }
12
+ function addErrorHandler(handler) {
13
+ if (typeof handler !== "function") throw Error(formatErrorMessage(28, process.env.NODE_ENV !== "production" && "a single-spa error handler must be a function"));
14
+ errorHandlers.push(handler);
15
+ }
16
+ function removeErrorHandler(handler) {
17
+ if (typeof handler !== "function") throw Error(formatErrorMessage(29, process.env.NODE_ENV !== "production" && "a single-spa error handler must be a function"));
18
+ let removedSomething = false;
19
+ errorHandlers = errorHandlers.filter((h) => {
20
+ const isHandler = h === handler;
21
+ removedSomething = removedSomething || isHandler;
22
+ return !isHandler;
23
+ });
24
+ return removedSomething;
25
+ }
26
+ function formatErrorMessage(code, msg, ...args) {
27
+ return `single-spa minified message #${code}: ${msg ? msg + " " : ""}See https://single-spa.js.org/error/?code=${code}${args.length ? `&arg=${args.join("&arg=")}` : ""}`;
28
+ }
29
+ function transformErr(ogErr, appOrParcel, newStatus) {
30
+ const errPrefix = `${require_applications_app_helpers.objectType(appOrParcel)} '${require_applications_app_helpers.toName(appOrParcel)}' died in status ${appOrParcel.status}: `;
31
+ let result;
32
+ if (ogErr instanceof Error) {
33
+ try {
34
+ ogErr.message = errPrefix + ogErr.message;
35
+ } catch (err) {}
36
+ result = ogErr;
37
+ } else {
38
+ console.warn(formatErrorMessage(30, process.env.NODE_ENV !== "production" && `While ${appOrParcel.status}, '${require_applications_app_helpers.toName(appOrParcel)}' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate.`, appOrParcel.status, require_applications_app_helpers.toName(appOrParcel)));
39
+ try {
40
+ result = Error(errPrefix + JSON.stringify(ogErr));
41
+ } catch (err) {
42
+ result = ogErr;
43
+ }
44
+ }
45
+ const singleSpaErr = result;
46
+ singleSpaErr.appOrParcelName = require_applications_app_helpers.toName(appOrParcel);
47
+ appOrParcel.status = newStatus;
48
+ return singleSpaErr;
49
+ }
50
+ //#endregion
51
+ exports.addErrorHandler = addErrorHandler;
52
+ exports.formatErrorMessage = formatErrorMessage;
53
+ exports.handleAppError = handleAppError;
54
+ exports.removeErrorHandler = removeErrorHandler;
55
+ exports.transformErr = transformErr;
56
+
57
+ //# sourceMappingURL=app-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-errors.js","names":[],"sources":["../../../src/applications/app-errors.ts"],"sourcesContent":["import { AppOrParcel } from '../lifecycles/lifecycle.helpers';\nimport { AppOrParcelStatus, objectType, toName } from './app.helpers';\n\nlet errorHandlers: ErrorHandler[] = [];\n\nexport type SingleSpaError = Error & {\n appOrParcelName: string;\n};\n\nexport type ErrorHandler = (err: SingleSpaError) => any;\n\nexport function handleAppError(err: Error, app: AppOrParcel, newStatus: AppOrParcelStatus) {\n const transformedErr = transformErr(err, app, newStatus);\n\n if (errorHandlers.length) {\n errorHandlers.forEach((handler) => handler(transformedErr));\n } else {\n setTimeout(() => {\n throw transformedErr;\n });\n }\n}\n\nexport function addErrorHandler(handler) {\n if (typeof handler !== 'function') {\n throw Error(formatErrorMessage(28, __DEV__ && 'a single-spa error handler must be a function'));\n }\n\n errorHandlers.push(handler);\n}\n\nexport function removeErrorHandler(handler) {\n if (typeof handler !== 'function') {\n throw Error(formatErrorMessage(29, __DEV__ && 'a single-spa error handler must be a function'));\n }\n\n let removedSomething = false;\n errorHandlers = errorHandlers.filter((h) => {\n const isHandler = h === handler;\n removedSomething = removedSomething || isHandler;\n return !isHandler;\n });\n\n return removedSomething;\n}\n\nexport function formatErrorMessage(code, msg, ...args) {\n return `single-spa minified message #${code}: ${\n msg ? msg + ' ' : ''\n }See https://single-spa.js.org/error/?code=${code}${args.length ? `&arg=${args.join('&arg=')}` : ''}`;\n}\n\nexport function transformErr(ogErr: Error, appOrParcel: AppOrParcel, newStatus: AppOrParcelStatus): SingleSpaError {\n const errPrefix = `${objectType(appOrParcel)} '${toName(appOrParcel)}' died in status ${appOrParcel.status}: `;\n\n let result: Error;\n\n if (ogErr instanceof Error) {\n try {\n ogErr.message = errPrefix + ogErr.message;\n } catch (err) {\n /* Some errors have read-only message properties, in which case there is nothing\n * that we can do.\n */\n }\n result = ogErr;\n } else {\n console.warn(\n formatErrorMessage(\n 30,\n __DEV__ &&\n `While ${appOrParcel.status}, '${toName(\n appOrParcel,\n )}' rejected its lifecycle function promise with a non-Error. This will cause stack traces to not be accurate.`,\n appOrParcel.status,\n toName(appOrParcel),\n ),\n );\n try {\n result = Error(errPrefix + JSON.stringify(ogErr));\n } catch (err) {\n // If it's not an Error and you can't stringify it, then what else can you even do to it?\n result = ogErr;\n }\n }\n\n const singleSpaErr = result as SingleSpaError;\n singleSpaErr.appOrParcelName = toName(appOrParcel);\n\n // We set the status after transforming the error so that the error message\n // references the state the application was in before the status change.\n appOrParcel.status = newStatus;\n\n return singleSpaErr;\n}\n"],"mappings":";;;AAGA,IAAI,gBAAgC,CAAC;AAQrC,SAAgB,eAAe,KAAY,KAAkB,WAA8B;CACzF,MAAM,iBAAiB,aAAa,KAAK,KAAK,SAAS;CAEvD,IAAI,cAAc,QAChB,cAAc,SAAS,YAAY,QAAQ,cAAc,CAAC;MAE1D,iBAAiB;EACf,MAAM;CACR,CAAC;AAEL;AAEA,SAAgB,gBAAgB,SAAS;CACvC,IAAI,OAAO,YAAY,YACrB,MAAM,MAAM,mBAAmB,IAAA,QAAA,IAAA,aAAA,gBAAe,+CAA+C,CAAC;CAGhG,cAAc,KAAK,OAAO;AAC5B;AAEA,SAAgB,mBAAmB,SAAS;CAC1C,IAAI,OAAO,YAAY,YACrB,MAAM,MAAM,mBAAmB,IAAA,QAAA,IAAA,aAAA,gBAAe,+CAA+C,CAAC;CAGhG,IAAI,mBAAmB;CACvB,gBAAgB,cAAc,QAAQ,MAAM;EAC1C,MAAM,YAAY,MAAM;EACxB,mBAAmB,oBAAoB;EACvC,OAAO,CAAC;CACV,CAAC;CAED,OAAO;AACT;AAEA,SAAgB,mBAAmB,MAAM,KAAK,GAAG,MAAM;CACrD,OAAO,gCAAgC,KAAK,IAC1C,MAAM,MAAM,MAAM,GACnB,4CAA4C,OAAO,KAAK,SAAS,QAAQ,KAAK,KAAK,OAAO,MAAM;AACnG;AAEA,SAAgB,aAAa,OAAc,aAA0B,WAA8C;CACjH,MAAM,YAAY,GAAG,iCAAA,WAAW,WAAW,EAAE,IAAI,iCAAA,OAAO,WAAW,EAAE,mBAAmB,YAAY,OAAO;CAE3G,IAAI;CAEJ,IAAI,iBAAiB,OAAO;EAC1B,IAAI;GACF,MAAM,UAAU,YAAY,MAAM;EACpC,SAAS,KAAK,CAId;EACA,SAAS;CACX,OAAO;EACL,QAAQ,KACN,mBACE,IAAA,QAAA,IAAA,aAAA,gBAEE,SAAS,YAAY,OAAO,KAAK,iCAAA,OAC/B,WACF,EAAE,+GACJ,YAAY,QACZ,iCAAA,OAAO,WAAW,CACpB,CACF;EACA,IAAI;GACF,SAAS,MAAM,YAAY,KAAK,UAAU,KAAK,CAAC;EAClD,SAAS,KAAK;GAEZ,SAAS;EACX;CACF;CAEA,MAAM,eAAe;CACrB,aAAa,kBAAkB,iCAAA,OAAO,WAAW;CAIjD,YAAY,SAAS;CAErB,OAAO;AACT"}
@@ -0,0 +1,52 @@
1
+ import { ActivityFn, AppOrParcel, CustomProps, InternalParcel, LoadApp, ParcelMap } from '../lifecycles/lifecycle.helpers';
2
+ import { AppOrParcelTimeouts } from './timeouts';
3
+ export declare enum AppOrParcelStatus {
4
+ NOT_LOADED = "NOT_LOADED",
5
+ LOADING_SOURCE_CODE = "LOADING_SOURCE_CODE",
6
+ NOT_BOOTSTRAPPED = "NOT_BOOTSTRAPPED",
7
+ BOOTSTRAPPING = "BOOTSTRAPPING",
8
+ NOT_MOUNTED = "NOT_MOUNTED",
9
+ MOUNTING = "MOUNTING",
10
+ MOUNTED = "MOUNTED",
11
+ UPDATING = "UPDATING",
12
+ UNMOUNTING = "UNMOUNTING",
13
+ UNLOADING = "UNLOADING",
14
+ LOAD_ERROR = "LOAD_ERROR",
15
+ SKIP_BECAUSE_BROKEN = "SKIP_BECAUSE_BROKEN"
16
+ }
17
+ export declare function isActive(app: any): boolean;
18
+ export declare function shouldBeActive(app: any): any;
19
+ export declare function toName(app: any): any;
20
+ export declare function isParcel(appOrParcel: AppOrParcel): appOrParcel is InternalParcel;
21
+ export declare function objectType(appOrParcel: AppOrParcel): 'parcel' | 'application';
22
+ export interface InternalApplication {
23
+ name: string;
24
+ activeWhen: ActivityFn;
25
+ loadApp: LoadApp;
26
+ status: AppOrParcelStatus;
27
+ loadErrorTime: number;
28
+ parcels: ParcelMap;
29
+ customProps?: CustomProps;
30
+ timeouts?: AppOrParcelTimeouts;
31
+ devtools: AppDevtools;
32
+ }
33
+ export interface AppDevtools {
34
+ overlays: {
35
+ options: OverlayOptions;
36
+ selectors: string[];
37
+ };
38
+ }
39
+ interface OverlayOptions {
40
+ color?: string;
41
+ background?: string;
42
+ classes?: string[];
43
+ height?: string;
44
+ left?: string;
45
+ position?: string;
46
+ top?: string;
47
+ width?: string;
48
+ zIndex?: string | number;
49
+ textColor?: string;
50
+ textBlocks?: string[];
51
+ }
52
+ export {};
@@ -0,0 +1,47 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_applications_app_errors = require("./app-errors.js");
3
+ //#region src/applications/app.helpers.ts
4
+ var AppOrParcelStatus = /* @__PURE__ */ function(AppOrParcelStatus) {
5
+ AppOrParcelStatus["NOT_LOADED"] = "NOT_LOADED";
6
+ AppOrParcelStatus["LOADING_SOURCE_CODE"] = "LOADING_SOURCE_CODE";
7
+ AppOrParcelStatus["NOT_BOOTSTRAPPED"] = "NOT_BOOTSTRAPPED";
8
+ AppOrParcelStatus["BOOTSTRAPPING"] = "BOOTSTRAPPING";
9
+ AppOrParcelStatus["NOT_MOUNTED"] = "NOT_MOUNTED";
10
+ AppOrParcelStatus["MOUNTING"] = "MOUNTING";
11
+ AppOrParcelStatus["MOUNTED"] = "MOUNTED";
12
+ AppOrParcelStatus["UPDATING"] = "UPDATING";
13
+ AppOrParcelStatus["UNMOUNTING"] = "UNMOUNTING";
14
+ AppOrParcelStatus["UNLOADING"] = "UNLOADING";
15
+ AppOrParcelStatus["LOAD_ERROR"] = "LOAD_ERROR";
16
+ AppOrParcelStatus["SKIP_BECAUSE_BROKEN"] = "SKIP_BECAUSE_BROKEN";
17
+ return AppOrParcelStatus;
18
+ }({});
19
+ function isActive(app) {
20
+ return app.status === "MOUNTED";
21
+ }
22
+ function shouldBeActive(app) {
23
+ try {
24
+ return app.activeWhen(window.location);
25
+ } catch (err) {
26
+ require_applications_app_errors.handleAppError(err, app, "SKIP_BECAUSE_BROKEN");
27
+ return false;
28
+ }
29
+ }
30
+ function toName(app) {
31
+ return app.name;
32
+ }
33
+ function isParcel(appOrParcel) {
34
+ return Boolean(appOrParcel.unmountThisParcel);
35
+ }
36
+ function objectType(appOrParcel) {
37
+ return isParcel(appOrParcel) ? "parcel" : "application";
38
+ }
39
+ //#endregion
40
+ exports.AppOrParcelStatus = AppOrParcelStatus;
41
+ exports.isActive = isActive;
42
+ exports.isParcel = isParcel;
43
+ exports.objectType = objectType;
44
+ exports.shouldBeActive = shouldBeActive;
45
+ exports.toName = toName;
46
+
47
+ //# sourceMappingURL=app.helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.helpers.js","names":[],"sources":["../../../src/applications/app.helpers.ts"],"sourcesContent":["import {\n ActivityFn,\n AppOrParcel,\n CustomProps,\n InternalParcel,\n LoadApp,\n ParcelMap,\n} from '../lifecycles/lifecycle.helpers';\nimport { handleAppError } from './app-errors';\nimport { AppOrParcelTimeouts } from './timeouts';\n\n// App statuses\nexport enum AppOrParcelStatus {\n NOT_LOADED = 'NOT_LOADED',\n LOADING_SOURCE_CODE = 'LOADING_SOURCE_CODE',\n NOT_BOOTSTRAPPED = 'NOT_BOOTSTRAPPED',\n BOOTSTRAPPING = 'BOOTSTRAPPING',\n NOT_MOUNTED = 'NOT_MOUNTED',\n MOUNTING = 'MOUNTING',\n MOUNTED = 'MOUNTED',\n UPDATING = 'UPDATING',\n UNMOUNTING = 'UNMOUNTING',\n UNLOADING = 'UNLOADING',\n LOAD_ERROR = 'LOAD_ERROR',\n SKIP_BECAUSE_BROKEN = 'SKIP_BECAUSE_BROKEN',\n}\n\nexport function isActive(app) {\n return app.status === AppOrParcelStatus.MOUNTED;\n}\n\nexport function shouldBeActive(app) {\n try {\n return app.activeWhen(window.location);\n } catch (err) {\n handleAppError(err, app, AppOrParcelStatus.SKIP_BECAUSE_BROKEN);\n return false;\n }\n}\n\nexport function toName(app) {\n return app.name;\n}\n\nexport function isParcel(appOrParcel: AppOrParcel): appOrParcel is InternalParcel {\n return Boolean((appOrParcel as InternalParcel).unmountThisParcel);\n}\n\nexport function objectType(appOrParcel: AppOrParcel): 'parcel' | 'application' {\n return isParcel(appOrParcel) ? 'parcel' : 'application';\n}\n\nexport interface InternalApplication {\n name: string;\n activeWhen: ActivityFn;\n loadApp: LoadApp;\n status: AppOrParcelStatus;\n loadErrorTime: number;\n parcels: ParcelMap;\n customProps?: CustomProps;\n // The ensureValidAppTimeouts function gets called once the app is loaded\n timeouts?: AppOrParcelTimeouts;\n devtools: AppDevtools;\n}\n\nexport interface AppDevtools {\n overlays: {\n options: OverlayOptions;\n selectors: string[];\n };\n}\n\n// https://github.com/single-spa/single-spa-inspector/blob/ac3e1ded68e94239dd02d04f8a094ed8e6dfefc2/src/inspected-window-helpers/overlay-helpers.js#L53\ninterface OverlayOptions {\n color?: string;\n background?: string;\n classes?: string[];\n height?: string;\n left?: string;\n position?: string;\n top?: string;\n width?: string;\n zIndex?: string | number;\n textColor?: string;\n textBlocks?: string[];\n}\n"],"mappings":";;;AAYA,IAAY,oBAAL,yBAAA,mBAAA;CACL,kBAAA,gBAAA;CACA,kBAAA,yBAAA;CACA,kBAAA,sBAAA;CACA,kBAAA,mBAAA;CACA,kBAAA,iBAAA;CACA,kBAAA,cAAA;CACA,kBAAA,aAAA;CACA,kBAAA,cAAA;CACA,kBAAA,gBAAA;CACA,kBAAA,eAAA;CACA,kBAAA,gBAAA;CACA,kBAAA,yBAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,SAAS,KAAK;CAC5B,OAAO,IAAI,WAAA;AACb;AAEA,SAAgB,eAAe,KAAK;CAClC,IAAI;EACF,OAAO,IAAI,WAAW,OAAO,QAAQ;CACvC,SAAS,KAAK;EACZ,gCAAA,eAAe,KAAK,KAAA,qBAA0C;EAC9D,OAAO;CACT;AACF;AAEA,SAAgB,OAAO,KAAK;CAC1B,OAAO,IAAI;AACb;AAEA,SAAgB,SAAS,aAAyD;CAChF,OAAO,QAAS,YAA+B,iBAAiB;AAClE;AAEA,SAAgB,WAAW,aAAoD;CAC7E,OAAO,SAAS,WAAW,IAAI,WAAW;AAC5C"}
@@ -0,0 +1,23 @@
1
+ import { InternalApplication, AppOrParcelStatus } from './app.helpers';
2
+ import { Activity, ActivityFn, Application, CustomProps, CustomPropsFn, RegisterApplicationConfig, SingleSpaLocation } from '../lifecycles/lifecycle.helpers';
3
+ interface AppChanges {
4
+ appsToUnload: InternalApplication[];
5
+ appsToUnmount: InternalApplication[];
6
+ appsToLoad: InternalApplication[];
7
+ appsToMount: InternalApplication[];
8
+ }
9
+ export declare function getAppChanges(): AppChanges;
10
+ export declare function getMountedApps(): string[];
11
+ export declare function getAppNames(): string[];
12
+ export declare function getRawAppData(): InternalApplication[];
13
+ export declare function getAppStatus(appName: any): AppOrParcelStatus | null;
14
+ export declare function registerApplication<ExtraProps extends CustomProps = {}>(RegisterApplicationConfig: any): void;
15
+ export declare function registerApplication<ExtraProps extends CustomProps = {}>(appName: string, app: Application, activeWhen: Activity, customProps: ExtraProps | CustomPropsFn<ExtraProps>): void;
16
+ export declare function checkActivityFunctions(location?: SingleSpaLocation): string[];
17
+ export declare function unregisterApplication(appName: string): Promise<void>;
18
+ export declare function unloadApplication(appName: string, opts?: {
19
+ waitForUnmount: boolean;
20
+ }): Promise<void>;
21
+ export declare function validateRegisterWithConfig(config: Partial<RegisterApplicationConfig>): void;
22
+ export declare function pathToActiveWhen(path: string, exactMatch?: boolean): ActivityFn;
23
+ export {};
@@ -0,0 +1,234 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_applications_app_helpers = require("./app.helpers.js");
3
+ const require_applications_app_errors = require("./app-errors.js");
4
+ const require_utils_runtime_environment = require("../utils/runtime-environment.js");
5
+ const require_start = require("../start.js");
6
+ const require_lifecycles_unmount = require("../lifecycles/unmount.js");
7
+ const require_lifecycles_unload = require("../lifecycles/unload.js");
8
+ const require_navigation_reroute = require("../navigation/reroute.js");
9
+ const require_jquery_support = require("../jquery-support.js");
10
+ //#region src/applications/apps.ts
11
+ var apps = [];
12
+ function getAppChanges() {
13
+ const appsToUnload = [], appsToUnmount = [], appsToLoad = [], appsToMount = [];
14
+ const currentTime = (/* @__PURE__ */ new Date()).getTime();
15
+ apps.forEach((app) => {
16
+ const appShouldBeActive = app.status !== require_applications_app_helpers.AppOrParcelStatus.SKIP_BECAUSE_BROKEN && require_applications_app_helpers.shouldBeActive(app);
17
+ switch (app.status) {
18
+ case require_applications_app_helpers.AppOrParcelStatus.LOAD_ERROR:
19
+ if (appShouldBeActive && currentTime - app.loadErrorTime >= 200) appsToLoad.push(app);
20
+ break;
21
+ case require_applications_app_helpers.AppOrParcelStatus.NOT_LOADED:
22
+ case require_applications_app_helpers.AppOrParcelStatus.LOADING_SOURCE_CODE:
23
+ if (appShouldBeActive) appsToLoad.push(app);
24
+ break;
25
+ case require_applications_app_helpers.AppOrParcelStatus.NOT_BOOTSTRAPPED:
26
+ case require_applications_app_helpers.AppOrParcelStatus.NOT_MOUNTED:
27
+ if (!appShouldBeActive && require_lifecycles_unload.getAppUnloadInfo(require_applications_app_helpers.toName(app))) appsToUnload.push(app);
28
+ else if (appShouldBeActive) appsToMount.push(app);
29
+ break;
30
+ case require_applications_app_helpers.AppOrParcelStatus.MOUNTED:
31
+ if (!appShouldBeActive) appsToUnmount.push(app);
32
+ break;
33
+ }
34
+ });
35
+ return {
36
+ appsToUnload,
37
+ appsToUnmount,
38
+ appsToLoad,
39
+ appsToMount
40
+ };
41
+ }
42
+ function getMountedApps() {
43
+ return apps.filter(require_applications_app_helpers.isActive).map(require_applications_app_helpers.toName);
44
+ }
45
+ function getAppNames() {
46
+ return apps.map(require_applications_app_helpers.toName);
47
+ }
48
+ function getRawAppData() {
49
+ return [...apps];
50
+ }
51
+ function getAppStatus(appName) {
52
+ const app = apps.find((app) => require_applications_app_helpers.toName(app) === appName);
53
+ return app ? app.status : null;
54
+ }
55
+ var startWarningInitialized = false;
56
+ function registerApplication(appNameOrConfig, appOrLoadApp, activeWhen, customProps) {
57
+ const registration = sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps);
58
+ if (!require_start.isStarted() && !startWarningInitialized) {
59
+ startWarningInitialized = true;
60
+ setTimeout(() => {
61
+ if (!require_start.isStarted()) console.warn(require_applications_app_errors.formatErrorMessage(1, process.env.NODE_ENV !== "production" && `singleSpa.start() has not been called, 5000ms after single-spa was loaded. Before start() is called, apps can be declared and loaded, but not initialized or mounted.`));
62
+ }, 5e3);
63
+ }
64
+ if (getAppNames().indexOf(registration.name) !== -1) throw Error(require_applications_app_errors.formatErrorMessage(21, process.env.NODE_ENV !== "production" && `There is already an app registered with name ${registration.name}`, registration.name));
65
+ apps.push(Object.assign({
66
+ loadErrorTime: null,
67
+ status: require_applications_app_helpers.AppOrParcelStatus.NOT_LOADED,
68
+ parcels: {},
69
+ devtools: { overlays: {
70
+ options: {},
71
+ selectors: []
72
+ } }
73
+ }, registration));
74
+ if (require_utils_runtime_environment.isInBrowser) {
75
+ require_jquery_support.ensureJQuerySupport();
76
+ require_navigation_reroute.reroute();
77
+ }
78
+ }
79
+ function checkActivityFunctions(location = window.location) {
80
+ return apps.filter((app) => app.activeWhen(location)).map(require_applications_app_helpers.toName);
81
+ }
82
+ function unregisterApplication(appName) {
83
+ if (apps.filter((app) => require_applications_app_helpers.toName(app) === appName).length === 0) throw Error(require_applications_app_errors.formatErrorMessage(25, process.env.NODE_ENV !== "production" && `Cannot unregister application '${appName}' because no such application has been registered`, appName));
84
+ return (require_utils_runtime_environment.isInBrowser ? unloadApplication(appName, { waitForUnmount: false }) : Promise.resolve()).then(() => {
85
+ const appIndex = apps.map(require_applications_app_helpers.toName).indexOf(appName);
86
+ apps.splice(appIndex, 1);
87
+ });
88
+ }
89
+ function unloadApplication(appName, opts = { waitForUnmount: false }) {
90
+ if (typeof appName !== "string") throw Error(require_applications_app_errors.formatErrorMessage(26, process.env.NODE_ENV !== "production" && `unloadApplication requires a string 'appName'`));
91
+ const app = apps.find((app) => require_applications_app_helpers.toName(app) === appName);
92
+ if (!app) throw Error(require_applications_app_errors.formatErrorMessage(27, process.env.NODE_ENV !== "production" && `Could not unload application '${appName}' because no such application has been registered`, appName));
93
+ const appUnloadInfo = require_lifecycles_unload.getAppUnloadInfo(require_applications_app_helpers.toName(app));
94
+ if (opts === null || opts === void 0 ? void 0 : opts.waitForUnmount) if (appUnloadInfo) return appUnloadInfo.promise;
95
+ else {
96
+ const promise = new Promise((resolve, reject) => {
97
+ require_lifecycles_unload.addAppToUnload(app, () => promise, resolve, reject);
98
+ });
99
+ return promise;
100
+ }
101
+ else {
102
+ let resultPromise;
103
+ if (appUnloadInfo) {
104
+ resultPromise = appUnloadInfo.promise;
105
+ immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject);
106
+ } else resultPromise = new Promise((resolve, reject) => {
107
+ require_lifecycles_unload.addAppToUnload(app, () => resultPromise, resolve, reject);
108
+ immediatelyUnloadApp(app, resolve, reject);
109
+ });
110
+ return resultPromise;
111
+ }
112
+ }
113
+ function immediatelyUnloadApp(app, resolve, reject) {
114
+ Promise.resolve().then(() => {
115
+ if (checkActivityFunctions().find((activeApp) => activeApp === require_applications_app_helpers.toName(app))) return require_navigation_reroute.triggerAppChange();
116
+ }).then(() => {
117
+ return require_lifecycles_unmount.toUnmountPromise(app).then(require_lifecycles_unload.toUnloadPromise).then(() => {
118
+ resolve();
119
+ setTimeout(() => {
120
+ require_navigation_reroute.reroute();
121
+ });
122
+ });
123
+ }).catch(reject);
124
+ }
125
+ function validateRegisterWithArguments(name, appOrLoadApp, activeWhen, customProps) {
126
+ if (typeof name !== "string" || name.length === 0) throw Error(require_applications_app_errors.formatErrorMessage(20, process.env.NODE_ENV !== "production" && `The 1st argument to registerApplication must be a non-empty string 'appName'`));
127
+ if (!appOrLoadApp) throw Error(require_applications_app_errors.formatErrorMessage(23, process.env.NODE_ENV !== "production" && "The 2nd argument to registerApplication must be an application or loading application function"));
128
+ if (typeof activeWhen !== "function") throw Error(require_applications_app_errors.formatErrorMessage(24, process.env.NODE_ENV !== "production" && "The 3rd argument to registerApplication must be an activeWhen function"));
129
+ if (!validCustomProps(customProps)) throw Error(require_applications_app_errors.formatErrorMessage(22, process.env.NODE_ENV !== "production" && "The optional 4th argument is a customProps and must be an object"));
130
+ }
131
+ function validateRegisterWithConfig(config) {
132
+ if (Array.isArray(config) || config === null) throw Error(require_applications_app_errors.formatErrorMessage(39, process.env.NODE_ENV !== "production" && "Configuration object can't be an Array or null!"));
133
+ const validKeys = [
134
+ "name",
135
+ "app",
136
+ "activeWhen",
137
+ "customProps"
138
+ ];
139
+ const invalidKeys = Object.keys(config).reduce((invalidKeys, prop) => validKeys.indexOf(prop) >= 0 ? invalidKeys : invalidKeys.concat(prop), []);
140
+ if (invalidKeys.length !== 0) throw Error(require_applications_app_errors.formatErrorMessage(38, process.env.NODE_ENV !== "production" && `The configuration object accepts only: ${validKeys.join(", ")}. Invalid keys: ${invalidKeys.join(", ")}.`, validKeys.join(", "), invalidKeys.join(", ")));
141
+ if (typeof config.name !== "string" || config.name.length === 0) throw Error(require_applications_app_errors.formatErrorMessage(20, process.env.NODE_ENV !== "production" && "The config.name on registerApplication must be a non-empty string"));
142
+ if (typeof config.app !== "object" && typeof config.app !== "function") throw Error(require_applications_app_errors.formatErrorMessage(20, process.env.NODE_ENV !== "production" && "The config.app on registerApplication must be an application or a loading function"));
143
+ const allowsStringAndFunction = (activeWhen) => typeof activeWhen === "string" || typeof activeWhen === "function";
144
+ if (!allowsStringAndFunction(config.activeWhen) && !(Array.isArray(config.activeWhen) && config.activeWhen.every(allowsStringAndFunction))) throw Error(require_applications_app_errors.formatErrorMessage(24, process.env.NODE_ENV !== "production" && "The config.activeWhen on registerApplication must be a string, function or an array with both"));
145
+ if (!validCustomProps(config.customProps)) throw Error(require_applications_app_errors.formatErrorMessage(22, process.env.NODE_ENV !== "production" && "The optional config.customProps must be an object"));
146
+ }
147
+ function validCustomProps(customProps) {
148
+ return !customProps || typeof customProps === "function" || typeof customProps === "object" && customProps !== null && !Array.isArray(customProps);
149
+ }
150
+ function sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps) {
151
+ const usingObjectAPI = typeof appNameOrConfig === "object";
152
+ let unsanitizedRegistration;
153
+ if (usingObjectAPI) {
154
+ validateRegisterWithConfig(appNameOrConfig);
155
+ unsanitizedRegistration = {
156
+ name: appNameOrConfig.name,
157
+ app: appNameOrConfig.app,
158
+ activeWhen: appNameOrConfig.activeWhen,
159
+ customProps: appNameOrConfig.customProps
160
+ };
161
+ } else {
162
+ validateRegisterWithArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps);
163
+ unsanitizedRegistration = {
164
+ name: appNameOrConfig,
165
+ app: appOrLoadApp,
166
+ activeWhen,
167
+ customProps
168
+ };
169
+ }
170
+ return {
171
+ name: unsanitizedRegistration.name,
172
+ loadApp: sanitizeLoadApp(unsanitizedRegistration.app),
173
+ customProps: sanitizeCustomProps(unsanitizedRegistration.customProps),
174
+ activeWhen: sanitizeActiveWhen(unsanitizedRegistration.activeWhen)
175
+ };
176
+ }
177
+ function sanitizeLoadApp(loadApp) {
178
+ if (typeof loadApp !== "function") return () => Promise.resolve(loadApp);
179
+ return loadApp;
180
+ }
181
+ function sanitizeCustomProps(customProps) {
182
+ return customProps ? customProps : {};
183
+ }
184
+ function sanitizeActiveWhen(activeWhen) {
185
+ const activityFnArray = (Array.isArray(activeWhen) ? activeWhen : [activeWhen]).map((activeWhenOrPath) => typeof activeWhenOrPath === "function" ? activeWhenOrPath : pathToActiveWhen(activeWhenOrPath, false));
186
+ return (location) => activityFnArray.some((activeWhen) => activeWhen(location));
187
+ }
188
+ function pathToActiveWhen(path, exactMatch) {
189
+ const regex = toDynamicPathValidatorRegex(path, exactMatch);
190
+ return (location) => {
191
+ const route = location.href.replace(location.origin, "").replace(location.search, "").split("?")[0];
192
+ return regex.test(route);
193
+ };
194
+ }
195
+ function toDynamicPathValidatorRegex(path, exactMatch) {
196
+ let lastIndex = 0, inDynamic = false, regexStr = "^";
197
+ if (path[0] !== "/") path = "/" + path;
198
+ for (let charIndex = 0; charIndex < path.length; charIndex++) {
199
+ const char = path[charIndex];
200
+ if (!inDynamic && char === ":" || inDynamic && char === "/") appendToRegex(charIndex);
201
+ }
202
+ appendToRegex(path.length);
203
+ return new RegExp(regexStr, "i");
204
+ function appendToRegex(index) {
205
+ const anyCharMaybeTrailingSlashRegex = "[^/]+/?";
206
+ const commonStringSubPath = escapeStrRegex(path.slice(lastIndex, index));
207
+ regexStr += inDynamic ? anyCharMaybeTrailingSlashRegex : commonStringSubPath;
208
+ if (index === path.length) if (inDynamic) {
209
+ if (exactMatch) regexStr += "$";
210
+ } else {
211
+ const suffix = exactMatch ? "" : ".*";
212
+ regexStr = regexStr.charAt(regexStr.length - 1) === "/" ? `${regexStr}${suffix}$` : `${regexStr}(/${suffix})?(#.*)?$`;
213
+ }
214
+ inDynamic = !inDynamic;
215
+ lastIndex = index;
216
+ }
217
+ function escapeStrRegex(str) {
218
+ return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
219
+ }
220
+ }
221
+ //#endregion
222
+ exports.checkActivityFunctions = checkActivityFunctions;
223
+ exports.getAppChanges = getAppChanges;
224
+ exports.getAppNames = getAppNames;
225
+ exports.getAppStatus = getAppStatus;
226
+ exports.getMountedApps = getMountedApps;
227
+ exports.getRawAppData = getRawAppData;
228
+ exports.pathToActiveWhen = pathToActiveWhen;
229
+ exports.registerApplication = registerApplication;
230
+ exports.unloadApplication = unloadApplication;
231
+ exports.unregisterApplication = unregisterApplication;
232
+ exports.validateRegisterWithConfig = validateRegisterWithConfig;
233
+
234
+ //# sourceMappingURL=apps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apps.js","names":[],"sources":["../../../src/applications/apps.ts"],"sourcesContent":["import { ensureJQuerySupport } from '../jquery-support';\nimport { isActive, toName, shouldBeActive, InternalApplication, AppOrParcelStatus } from './app.helpers';\nimport { reroute, triggerAppChange } from '../navigation/reroute';\nimport { toUnmountPromise } from '../lifecycles/unmount';\nimport { toUnloadPromise, getAppUnloadInfo, addAppToUnload } from '../lifecycles/unload';\nimport { formatErrorMessage } from './app-errors';\nimport { isInBrowser } from '../utils/runtime-environment';\nimport { isStarted } from '../start';\nimport {\n Activity,\n ActivityFn,\n AppProps,\n Application,\n CustomProps,\n CustomPropsFn,\n LifeCycles,\n LoadApp,\n LoadedApp,\n RegisterApplicationConfig,\n SingleSpaLocation,\n} from '../lifecycles/lifecycle.helpers';\n\nconst apps: InternalApplication[] = [];\n\ninterface AppChanges {\n appsToUnload: InternalApplication[];\n appsToUnmount: InternalApplication[];\n appsToLoad: InternalApplication[];\n appsToMount: InternalApplication[];\n}\n\nexport function getAppChanges(): AppChanges {\n const appsToUnload: InternalApplication[] = [],\n appsToUnmount: InternalApplication[] = [],\n appsToLoad: InternalApplication[] = [],\n appsToMount: InternalApplication[] = [];\n\n // We re-attempt to download applications in LOAD_ERROR after a timeout of 200 milliseconds\n const currentTime: number = new Date().getTime();\n\n apps.forEach((app) => {\n const appShouldBeActive = app.status !== AppOrParcelStatus.SKIP_BECAUSE_BROKEN && shouldBeActive(app);\n\n switch (app.status) {\n case AppOrParcelStatus.LOAD_ERROR:\n if (appShouldBeActive && currentTime - app.loadErrorTime >= 200) {\n appsToLoad.push(app);\n }\n break;\n case AppOrParcelStatus.NOT_LOADED:\n case AppOrParcelStatus.LOADING_SOURCE_CODE:\n if (appShouldBeActive) {\n appsToLoad.push(app);\n }\n break;\n case AppOrParcelStatus.NOT_BOOTSTRAPPED:\n case AppOrParcelStatus.NOT_MOUNTED:\n if (!appShouldBeActive && getAppUnloadInfo(toName(app))) {\n appsToUnload.push(app);\n } else if (appShouldBeActive) {\n appsToMount.push(app);\n }\n break;\n case AppOrParcelStatus.MOUNTED:\n if (!appShouldBeActive) {\n appsToUnmount.push(app);\n }\n break;\n // all other statuses are ignored\n }\n });\n\n return { appsToUnload, appsToUnmount, appsToLoad, appsToMount };\n}\n\nexport function getMountedApps(): string[] {\n return apps.filter(isActive).map(toName);\n}\n\nexport function getAppNames(): string[] {\n return apps.map(toName);\n}\n\n// used in devtools, not (currently) exposed as a single-spa API\nexport function getRawAppData(): InternalApplication[] {\n return [...apps];\n}\n\nexport function getAppStatus(appName): AppOrParcelStatus | null {\n const app = apps.find((app) => toName(app) === appName);\n return app ? app.status : null;\n}\n\nlet startWarningInitialized: boolean = false;\n\nexport function registerApplication<ExtraProps extends CustomProps = {}>(RegisterApplicationConfig): void;\nexport function registerApplication<ExtraProps extends CustomProps = {}>(\n appName: string,\n app: Application,\n activeWhen: Activity,\n customProps: ExtraProps | CustomPropsFn<ExtraProps>,\n): void;\nexport function registerApplication<ExtraProps extends CustomProps = {}>(\n appNameOrConfig: string | RegisterApplicationConfig,\n appOrLoadApp?: Application,\n activeWhen?: Activity,\n customProps?: ExtraProps | CustomPropsFn<ExtraProps>,\n): void {\n const registration = sanitizeArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps);\n\n if (!isStarted() && !startWarningInitialized) {\n startWarningInitialized = true;\n\n setTimeout(() => {\n if (!isStarted()) {\n console.warn(\n formatErrorMessage(\n 1,\n __DEV__ &&\n `singleSpa.start() has not been called, 5000ms after single-spa was loaded. Before start() is called, apps can be declared and loaded, but not initialized or mounted.`,\n ),\n );\n }\n }, 5000);\n }\n\n if (getAppNames().indexOf(registration.name) !== -1)\n throw Error(\n formatErrorMessage(\n 21,\n __DEV__ && `There is already an app registered with name ${registration.name}`,\n registration.name,\n ),\n );\n\n apps.push(\n Object.assign(\n {\n loadErrorTime: null,\n status: AppOrParcelStatus.NOT_LOADED,\n parcels: {},\n devtools: {\n overlays: {\n options: {},\n selectors: [],\n },\n },\n },\n registration,\n ),\n );\n\n if (isInBrowser) {\n ensureJQuerySupport();\n reroute();\n }\n}\n\nexport function checkActivityFunctions(location: SingleSpaLocation = window.location): string[] {\n return apps.filter((app) => app.activeWhen(location)).map(toName);\n}\n\nexport function unregisterApplication(appName: string): Promise<void> {\n if (apps.filter((app) => toName(app) === appName).length === 0) {\n throw Error(\n formatErrorMessage(\n 25,\n __DEV__ && `Cannot unregister application '${appName}' because no such application has been registered`,\n appName,\n ),\n );\n }\n\n const unloadPromise = isInBrowser\n ? // See https://github.com/single-spa/single-spa/issues/871 for why waitForUnmount is false\n unloadApplication(appName, { waitForUnmount: false })\n : Promise.resolve();\n\n return unloadPromise.then(() => {\n const appIndex = apps.map(toName).indexOf(appName);\n apps.splice(appIndex, 1);\n });\n}\n\nexport function unloadApplication(\n appName: string,\n opts: { waitForUnmount: boolean } = { waitForUnmount: false },\n): Promise<void> {\n if (typeof appName !== 'string') {\n throw Error(formatErrorMessage(26, __DEV__ && `unloadApplication requires a string 'appName'`));\n }\n const app = apps.find((app) => toName(app) === appName);\n if (!app) {\n throw Error(\n formatErrorMessage(\n 27,\n __DEV__ && `Could not unload application '${appName}' because no such application has been registered`,\n appName,\n ),\n );\n }\n\n const appUnloadInfo = getAppUnloadInfo(toName(app));\n if (opts?.waitForUnmount) {\n // We need to wait for unmount before unloading the app\n\n if (appUnloadInfo) {\n // Someone else is already waiting for this, too\n return appUnloadInfo.promise;\n } else {\n // We're the first ones wanting the app to be resolved.\n const promise = new Promise<void>((resolve, reject) => {\n addAppToUnload(app, () => promise, resolve, reject);\n });\n return promise;\n }\n } else {\n /* We should unmount the app, unload it, and remount it immediately.\n */\n\n let resultPromise;\n\n if (appUnloadInfo) {\n // Someone else is already waiting for this app to unload\n resultPromise = appUnloadInfo.promise;\n immediatelyUnloadApp(app, appUnloadInfo.resolve, appUnloadInfo.reject);\n } else {\n // We're the first ones wanting the app to be resolved.\n resultPromise = new Promise((resolve, reject) => {\n addAppToUnload(app, () => resultPromise, resolve, reject);\n immediatelyUnloadApp(app, resolve, reject);\n });\n }\n\n return resultPromise;\n }\n}\n\nfunction immediatelyUnloadApp(\n app: InternalApplication,\n resolve: (value?: any) => void,\n reject: (value?: any) => void,\n): void {\n Promise.resolve()\n .then(() => {\n // Before unmounting the application, we first must wait for it to finish mounting\n // Otherwise, the test for issue 871 in unregister-application.spec.js fails because\n // the application isn't really unmounted.\n if (checkActivityFunctions().find((activeApp) => activeApp === toName(app))) {\n return triggerAppChange();\n }\n })\n .then(() => {\n return toUnmountPromise(app as LoadedApp)\n .then(toUnloadPromise)\n .then(() => {\n resolve();\n setTimeout(() => {\n // reroute, but the unload promise is done\n reroute();\n });\n });\n })\n .catch(reject);\n}\n\nfunction validateRegisterWithArguments(\n name: string,\n appOrLoadApp: Application,\n activeWhen: Activity,\n customProps?: CustomProps | CustomPropsFn,\n): void {\n if (typeof name !== 'string' || name.length === 0)\n throw Error(\n formatErrorMessage(20, __DEV__ && `The 1st argument to registerApplication must be a non-empty string 'appName'`),\n );\n\n if (!appOrLoadApp)\n throw Error(\n formatErrorMessage(\n 23,\n __DEV__ && 'The 2nd argument to registerApplication must be an application or loading application function',\n ),\n );\n\n if (typeof activeWhen !== 'function')\n throw Error(\n formatErrorMessage(24, __DEV__ && 'The 3rd argument to registerApplication must be an activeWhen function'),\n );\n\n if (!validCustomProps(customProps))\n throw Error(formatErrorMessage(22, __DEV__ && 'The optional 4th argument is a customProps and must be an object'));\n}\n\nexport function validateRegisterWithConfig(config: Partial<RegisterApplicationConfig>): void {\n if (Array.isArray(config) || config === null)\n throw Error(formatErrorMessage(39, __DEV__ && \"Configuration object can't be an Array or null!\"));\n const validKeys = ['name', 'app', 'activeWhen', 'customProps'];\n const invalidKeys = Object.keys(config).reduce(\n (invalidKeys, prop) => (validKeys.indexOf(prop) >= 0 ? invalidKeys : invalidKeys.concat(prop)),\n [],\n );\n if (invalidKeys.length !== 0)\n throw Error(\n formatErrorMessage(\n 38,\n __DEV__ &&\n `The configuration object accepts only: ${validKeys.join(', ')}. Invalid keys: ${invalidKeys.join(', ')}.`,\n validKeys.join(', '),\n invalidKeys.join(', '),\n ),\n );\n if (typeof config.name !== 'string' || config.name.length === 0)\n throw Error(formatErrorMessage(20, __DEV__ && 'The config.name on registerApplication must be a non-empty string'));\n if (typeof config.app !== 'object' && typeof config.app !== 'function')\n throw Error(\n formatErrorMessage(\n 20,\n __DEV__ && 'The config.app on registerApplication must be an application or a loading function',\n ),\n );\n const allowsStringAndFunction = (activeWhen) => typeof activeWhen === 'string' || typeof activeWhen === 'function';\n if (\n !allowsStringAndFunction(config.activeWhen) &&\n !(Array.isArray(config.activeWhen) && config.activeWhen.every(allowsStringAndFunction))\n )\n throw Error(\n formatErrorMessage(\n 24,\n __DEV__ && 'The config.activeWhen on registerApplication must be a string, function or an array with both',\n ),\n );\n if (!validCustomProps(config.customProps))\n throw Error(formatErrorMessage(22, __DEV__ && 'The optional config.customProps must be an object'));\n}\n\nfunction validCustomProps(customProps: unknown): boolean {\n return (\n !customProps ||\n typeof customProps === 'function' ||\n (typeof customProps === 'object' && customProps !== null && !Array.isArray(customProps))\n );\n}\n\ninterface ApplicationRegistration {\n name: string;\n loadApp: LoadApp;\n activeWhen: ActivityFn;\n customProps?: CustomProps;\n}\n\nfunction sanitizeArguments<ExtraProps extends CustomProps = {}>(\n appNameOrConfig: string | RegisterApplicationConfig,\n appOrLoadApp: Application,\n activeWhen: Activity,\n customProps?: ExtraProps | CustomPropsFn<ExtraProps>,\n): ApplicationRegistration {\n const usingObjectAPI = typeof appNameOrConfig === 'object';\n\n let unsanitizedRegistration: {\n name: string;\n app: Application;\n activeWhen: Activity;\n customProps: CustomProps | CustomPropsFn<CustomProps>;\n };\n\n if (usingObjectAPI) {\n validateRegisterWithConfig(appNameOrConfig);\n unsanitizedRegistration = {\n name: appNameOrConfig.name,\n app: appNameOrConfig.app,\n activeWhen: appNameOrConfig.activeWhen,\n customProps: appNameOrConfig.customProps,\n };\n } else {\n validateRegisterWithArguments(appNameOrConfig, appOrLoadApp, activeWhen, customProps);\n unsanitizedRegistration = {\n name: appNameOrConfig,\n app: appOrLoadApp,\n activeWhen,\n customProps,\n };\n }\n\n return {\n name: unsanitizedRegistration.name,\n loadApp: sanitizeLoadApp(unsanitizedRegistration.app),\n customProps: sanitizeCustomProps(unsanitizedRegistration.customProps),\n activeWhen: sanitizeActiveWhen(unsanitizedRegistration.activeWhen),\n };\n}\n\nfunction sanitizeLoadApp<ExtraProps extends CustomProps = {}>(\n loadApp: Application,\n): (config: ExtraProps & AppProps) => Promise<LifeCycles<ExtraProps>> {\n if (typeof loadApp !== 'function') {\n return () => Promise.resolve(loadApp);\n }\n\n return loadApp;\n}\n\nfunction sanitizeCustomProps(customProps?: CustomProps): CustomProps {\n return customProps ? customProps : {};\n}\n\nfunction sanitizeActiveWhen(activeWhen: Activity): ActivityFn {\n const activeWhenArray: (ActivityFn | string)[] = Array.isArray(activeWhen) ? activeWhen : [activeWhen];\n const activityFnArray: ActivityFn[] = activeWhenArray.map((activeWhenOrPath) =>\n typeof activeWhenOrPath === 'function' ? activeWhenOrPath : pathToActiveWhen(activeWhenOrPath, false),\n );\n\n return (location) => activityFnArray.some((activeWhen) => activeWhen(location));\n}\n\nexport function pathToActiveWhen(path: string, exactMatch?: boolean): ActivityFn {\n const regex = toDynamicPathValidatorRegex(path, exactMatch);\n\n return (location: Location) => {\n const route = location.href.replace(location.origin, '').replace(location.search, '').split('?')[0];\n return regex.test(route);\n };\n}\n\nfunction toDynamicPathValidatorRegex(path: string, exactMatch?: boolean) {\n let lastIndex: number = 0,\n inDynamic: boolean = false,\n regexStr: string = '^';\n\n if (path[0] !== '/') {\n path = '/' + path;\n }\n\n for (let charIndex = 0; charIndex < path.length; charIndex++) {\n const char = path[charIndex];\n const startOfDynamic = !inDynamic && char === ':';\n const endOfDynamic = inDynamic && char === '/';\n if (startOfDynamic || endOfDynamic) {\n appendToRegex(charIndex);\n }\n }\n\n appendToRegex(path.length);\n return new RegExp(regexStr, 'i');\n\n function appendToRegex(index) {\n const anyCharMaybeTrailingSlashRegex = '[^/]+/?';\n const commonStringSubPath = escapeStrRegex(path.slice(lastIndex, index));\n\n regexStr += inDynamic ? anyCharMaybeTrailingSlashRegex : commonStringSubPath;\n\n if (index === path.length) {\n if (inDynamic) {\n if (exactMatch) {\n // Ensure exact match paths that end in a dynamic portion don't match\n // urls with characters after a slash after the dynamic portion.\n regexStr += '$';\n }\n } else {\n // For exact matches, expect no more characters. Otherwise, allow\n // any characters.\n const suffix = exactMatch ? '' : '.*';\n\n regexStr =\n // use charAt instead as we could not use es6 method endsWith\n regexStr.charAt(regexStr.length - 1) === '/' ? `${regexStr}${suffix}$` : `${regexStr}(/${suffix})?(#.*)?$`;\n }\n }\n\n inDynamic = !inDynamic;\n lastIndex = index;\n }\n\n function escapeStrRegex(str) {\n // borrowed from https://github.com/sindresorhus/escape-string-regexp/blob/master/index.js\n return str.replace(/[|\\\\{}()[\\]^$+*?.]/g, '\\\\$&');\n }\n}\n"],"mappings":";;;;;;;;;;AAsBA,IAAM,OAA8B,CAAC;AASrC,SAAgB,gBAA4B;CAC1C,MAAM,eAAsC,CAAC,GAC3C,gBAAuC,CAAC,GACxC,aAAoC,CAAC,GACrC,cAAqC,CAAC;CAGxC,MAAM,+BAAsB,IAAI,KAAK,EAAC,CAAC,QAAQ;CAE/C,KAAK,SAAS,QAAQ;EACpB,MAAM,oBAAoB,IAAI,WAAW,iCAAA,kBAAkB,uBAAuB,iCAAA,eAAe,GAAG;EAEpG,QAAQ,IAAI,QAAZ;GACE,KAAK,iCAAA,kBAAkB;IACrB,IAAI,qBAAqB,cAAc,IAAI,iBA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,SAAS,KAAK,QAAQ,SAAS,QAAQ,EAAE,CAAC,CAAC,QAAQ,SAAS,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;EACjG,OAAO,MAAM,KAAK,KAAK;CACzB;AACF;AAEA,SAAS,4BAA4B,MAAc,YAAsB;CACvE,IAAI,YAAoB,GACtB,YAAqB,OACrB,WAAmB;CAErB,IAAI,KAAK,OAAO,KACd,OAAO,MAAM;CAGf,KAAK,IAAI,YAAY,GAAG,YAAY,KAAK,QAAQ,aAAa;EAC5D,MAAM,OAAO,KAAK;EAGlB,IAFuB,CAAC,aAAa,SAAS,OACzB,aAAa,SAAS,KAEzC,cAAc,SAAS;CAE3B;CAEA,cAAc,KAAK,MAAM;CACzB,OAAO,IAAI,OAAO,UAAU,GAAG;CAE/B,SAAS,cAAc,OAAO;EAC5B,MAAM,iCAAiC;EACvC,MAAM,sBAAsB,eAAe,KAAK,MAAM,WAAW,KAAK,CAAC;EAEvE,YAAY,YAAY,iCAAiC;EAEzD,IAAI,UAAU,KAAK,QACjB,IAAI,WACF;OAAI,YAGF,YAAY;EACd,OACK;GAGL,MAAM,SAAS,aAAa,KAAK;GAEjC,WAEE,SAAS,OAAO,SAAS,SAAS,CAAC,MAAM,MAAM,GAAG,WAAW,OAAO,KAAK,GAAG,SAAS,IAAI,OAAO;EACpG;EAGF,YAAY,CAAC;EACb,YAAY;CACd;CAEA,SAAS,eAAe,KAAK;EAE3B,OAAO,IAAI,QAAQ,uBAAuB,MAAM;CAClD;AACF"}
@@ -0,0 +1,19 @@
1
+ import { AppOrParcel } from '../lifecycles/lifecycle.helpers';
2
+ export interface AppOrParcelTimeouts {
3
+ bootstrap: Timeout;
4
+ mount: Timeout;
5
+ unmount: Timeout;
6
+ unload: Timeout;
7
+ update: Timeout;
8
+ }
9
+ export interface Timeout {
10
+ millis: number;
11
+ dieOnTimeout: boolean;
12
+ warningMillis: number;
13
+ }
14
+ export declare function setBootstrapMaxTime(time: number, dieOnTimeout: boolean, warningMillis: number): void;
15
+ export declare function setMountMaxTime(time: number, dieOnTimeout: boolean, warningMillis: number): void;
16
+ export declare function setUnmountMaxTime(time: number, dieOnTimeout: boolean, warningMillis: number): void;
17
+ export declare function setUnloadMaxTime(time: number, dieOnTimeout: boolean, warningMillis: number): void;
18
+ export declare function reasonableTime(appOrParcel: AppOrParcel, lifecycle: 'bootstrap' | 'mount' | 'update' | 'unmount' | 'unload'): Promise<any>;
19
+ export declare function ensureValidAppTimeouts(timeouts: Partial<AppOrParcelTimeouts>): AppOrParcelTimeouts;