@module-federation/utilities 0.0.4 → 0.1.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/CHANGELOG.md +31 -0
- package/README.md +25 -0
- package/package.json +21 -4
- package/src/utils/react.d.ts +10 -0
- package/src/utils/react.js +42 -0
- package/src/utils/react.js.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
# [0.2.0](https://github.com/module-federation/nextjs-mf/compare/utils-0.1.0...utils-0.2.0) (2022-10-05)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# [0.1.0](https://github.com/module-federation/nextjs-mf/compare/utils-0.0.3...utils-0.1.0) (2022-10-05)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **update versions:** bumping versions ([f72209a](https://github.com/module-federation/nextjs-mf/commit/f72209ae070fb50c9d317e764caf872facd4b887))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## [0.0.4](https://github.com/module-federation/nextjs-mf/compare/utils-0.0.3...utils-0.0.4) (2022-10-05)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **update versions:** bumping versions ([f72209a](https://github.com/module-federation/nextjs-mf/commit/f72209ae070fb50c9d317e764caf872facd4b887))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## [0.0.4](https://github.com/module-federation/nextjs-mf/compare/utils-0.0.3...utils-0.0.4) (2022-10-05)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Bug Fixes
|
|
31
|
+
|
|
32
|
+
* **update versions:** bumping versions ([f72209a](https://github.com/module-federation/nextjs-mf/commit/f72209ae070fb50c9d317e764caf872facd4b887))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
5
36
|
## [0.0.4](https://github.com/module-federation/nextjs-mf/compare/utils-0.0.3...utils-0.0.4) (2022-10-04)
|
|
6
37
|
|
|
7
38
|
|
package/README.md
CHANGED
|
@@ -9,3 +9,28 @@ Run `nx build utils` to build the library.
|
|
|
9
9
|
## Running unit tests
|
|
10
10
|
|
|
11
11
|
Run `nx test utils` to execute the unit tests via [Jest](https://jestjs.io).
|
|
12
|
+
|
|
13
|
+
## React utilities
|
|
14
|
+
---
|
|
15
|
+
`FederatedBoundary`
|
|
16
|
+
|
|
17
|
+
A component wrapper that provides a fallback for safe imports if something were to fail when grabbing a module off of a remote host.
|
|
18
|
+
|
|
19
|
+
This wrapper also exposes an optional property for a custom react error boundary component.
|
|
20
|
+
|
|
21
|
+
Any extra props will be passed directly to the imported module.
|
|
22
|
+
|
|
23
|
+
Usage looks something like this:
|
|
24
|
+
```js
|
|
25
|
+
import { FederationBoundary } from "@module-federation/utilities/react";
|
|
26
|
+
|
|
27
|
+
const MyPage = () => {
|
|
28
|
+
return (
|
|
29
|
+
<FederationBoundary
|
|
30
|
+
dynamicImport={() => import("some_remote_host_name").then((m) => m.Component)}
|
|
31
|
+
fallback={() => import("@npm/backup").then((m) => m.Component)}
|
|
32
|
+
customBoundary={CustomErrorBoundary}
|
|
33
|
+
/>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
```
|
package/package.json
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/utilities",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./src/index.js",
|
|
10
|
+
"require": "./src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json",
|
|
13
|
+
"./react": {
|
|
14
|
+
"import": "./src/utils/react.js",
|
|
15
|
+
"require": "./src/utils/react.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
7
18
|
"repository": "https://github.com/module-federation/nextjs-mf/tree/main/packages/utilities",
|
|
8
|
-
"typings": "./src/index.d.ts",
|
|
9
|
-
"dependencies": {},
|
|
10
19
|
"peerDependencies": {
|
|
20
|
+
"react": "^12 || ^18",
|
|
21
|
+
"next": "^11 || ^12",
|
|
11
22
|
"webpack": "^5.74.0",
|
|
12
23
|
"tslib": "^2.3.0"
|
|
13
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"react": "18.2.0",
|
|
27
|
+
"next": "12.3.0"
|
|
28
|
+
},
|
|
29
|
+
"typings": "./src/index.d.ts",
|
|
30
|
+
"dependencies": {}
|
|
14
31
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper around dynamic import.
|
|
4
|
+
* Adds error boundaries and fallback options
|
|
5
|
+
*/
|
|
6
|
+
export declare const FederationBoundary: ({ dynamicImporter, fallback, customBoundary: CustomBoundary, ...rest }: {
|
|
7
|
+
dynamicImporter: () => Promise<any>;
|
|
8
|
+
fallback: () => Promise<any> | null;
|
|
9
|
+
customBoundary: ComponentType;
|
|
10
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FederationBoundary = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var react_1 = tslib_1.__importStar(require("react"));
|
|
6
|
+
var dynamic_1 = tslib_1.__importDefault(require("next/dynamic"));
|
|
7
|
+
var ErrorBoundary = /** @class */ (function (_super) {
|
|
8
|
+
tslib_1.__extends(ErrorBoundary, _super);
|
|
9
|
+
function ErrorBoundary(props) {
|
|
10
|
+
return _super.call(this, props) || this;
|
|
11
|
+
}
|
|
12
|
+
ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
|
|
13
|
+
// You can also log the error to an error reporting service
|
|
14
|
+
console.error(error, errorInfo);
|
|
15
|
+
};
|
|
16
|
+
ErrorBoundary.prototype.render = function () {
|
|
17
|
+
return this.props['children'];
|
|
18
|
+
};
|
|
19
|
+
return ErrorBoundary;
|
|
20
|
+
}(react_1.default.Component));
|
|
21
|
+
/**
|
|
22
|
+
* Wrapper around dynamic import.
|
|
23
|
+
* Adds error boundaries and fallback options
|
|
24
|
+
*/
|
|
25
|
+
var FederationBoundary = function (_a) {
|
|
26
|
+
var dynamicImporter = _a.dynamicImporter, _b = _a.fallback, fallback = _b === void 0 ? function () { return null; } : _b, CustomBoundary = _a.customBoundary, rest = tslib_1.__rest(_a, ["dynamicImporter", "fallback", "customBoundary"]);
|
|
27
|
+
return (0, react_1.useMemo)(function () {
|
|
28
|
+
var ImportResult = (0, dynamic_1.default)(function () {
|
|
29
|
+
return dynamicImporter().catch(function (e) {
|
|
30
|
+
console.error(e);
|
|
31
|
+
return fallback();
|
|
32
|
+
});
|
|
33
|
+
}, {
|
|
34
|
+
ssr: false,
|
|
35
|
+
});
|
|
36
|
+
var Boundary = CustomBoundary !== undefined ? CustomBoundary : ErrorBoundary;
|
|
37
|
+
return (react_1.default.createElement(Boundary, null,
|
|
38
|
+
react_1.default.createElement(ImportResult, tslib_1.__assign({}, rest))));
|
|
39
|
+
}, [dynamicImporter, fallback]);
|
|
40
|
+
};
|
|
41
|
+
exports.FederationBoundary = FederationBoundary;
|
|
42
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../../../../packages/utilities/src/utils/react.tsx"],"names":[],"mappings":";;;;AACA,qDAAuC;AACvC,iEAAmC;AAQnC;IAA4B,yCAAyB;IACnD,uBAAY,KAAoB;eAC9B,kBAAM,KAAK,CAAC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