@pushwoosh/single-spa 1.1.0 → 1.2.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.
package/Parcel.js CHANGED
@@ -3,6 +3,7 @@ import { useMemo } from 'react';
3
3
  import { mountRootParcel } from 'single-spa';
4
4
  import SingleSpaParcel from 'single-spa-react/parcel';
5
5
  import { useSPAContext } from '@pushwoosh/spa-context';
6
+ import { loadByFormat } from './loadByFormat';
6
7
  export const Parcel = ({
7
8
  className,
8
9
  module,
@@ -14,7 +15,7 @@ export const Parcel = ({
14
15
  let parcel;
15
16
  return {
16
17
  bootstrap(props) {
17
- return System.import(module).then(imported => {
18
+ return loadByFormat(module).then(imported => {
18
19
  // eslint-disable-next-line react/prop-types, react-hooks/immutability
19
20
  parcel = imported[parcelFunctionName](props.domElement);
20
21
  });
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Parcel';
2
2
  export { createParcelFunction } from './createParcelFunction';
3
3
  export { createApplicationFunction } from './createApplicationFunction';
4
+ export { isEsmUrl, loadByFormat, resolveModuleUrl } from './loadByFormat';
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './Parcel';
2
2
  export { createParcelFunction } from './createParcelFunction';
3
- export { createApplicationFunction } from './createApplicationFunction';
3
+ export { createApplicationFunction } from './createApplicationFunction';
4
+ export { isEsmUrl, loadByFormat, resolveModuleUrl } from './loadByFormat';
@@ -0,0 +1,6 @@
1
+ /** URL the merged root-config import map assigns to `name`, or `name` itself when the map has no entry. */
2
+ export declare function resolveModuleUrl(name: string): string;
3
+ /** Whether `url` points at an ES module build (`.mjs`), ignoring query and hash. */
4
+ export declare function isEsmUrl(url: string): boolean;
5
+ /** Loads a module by import-map name: `.mjs` entries through native `import()`, the rest through SystemJS. */
6
+ export declare function loadByFormat<T = unknown>(name: string): Promise<T>;
@@ -0,0 +1,15 @@
1
+ /** URL the merged root-config import map assigns to `name`, or `name` itself when the map has no entry. */
2
+ export function resolveModuleUrl(name) {
3
+ return window.__PW_IMPORT_MAP__?.imports[name] ?? name;
4
+ }
5
+ /** Whether `url` points at an ES module build (`.mjs`), ignoring query and hash. */
6
+ export function isEsmUrl(url) {
7
+ return /\.mjs(?:[?#]|$)/.test(url);
8
+ }
9
+ /** Loads a module by import-map name: `.mjs` entries through native `import()`, the rest through SystemJS. */
10
+ export function loadByFormat(name) {
11
+ if (isEsmUrl(resolveModuleUrl(name))) {
12
+ return import(/* webpackIgnore: true */name);
13
+ }
14
+ return System.import(name);
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/single-spa",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "single-spa lifecycle helpers for Pushwoosh micro-frontends: application and parcel factories wrapped in SPAContextProvider",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,7 +24,8 @@
24
24
  "@types/react": "^19.3.0",
25
25
  "@types/react-dom": "^19.3.0",
26
26
  "react": "^19.3.0",
27
- "react-dom": "^19.3.0"
27
+ "react-dom": "^19.3.0",
28
+ "vitest": "^4.1.10"
28
29
  },
29
30
  "peerDependencies": {
30
31
  "@pushwoosh/spa-context": "^1.7.1 || ^2.0.0 || ^3.0.0",
@@ -36,9 +37,10 @@
36
37
  },
37
38
  "scripts": {
38
39
  "build": "pushwoosh-engine lib:build",
39
- "check": "pnpm run check:lint && pnpm run check:types",
40
+ "check": "pnpm run check:lint && pnpm run check:types && pnpm run test",
40
41
  "check:lint": "echo \"Run check:lint\" && NODE_ENV=production eslint ./src",
41
42
  "check:lint-fix": "echo \"Run check:lint\" && NODE_ENV=production eslint ./src --fix",
42
- "check:types": "echo \"Run check:types\" && pushwoosh-engine lib:check-types"
43
+ "check:types": "echo \"Run check:types\" && pushwoosh-engine lib:check-types",
44
+ "test": "echo \"Run test\" && vitest run"
43
45
  }
44
46
  }