@appshell/loader 0.1.0-alpha.1 → 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 +13 -0
- package/README.md +5 -5
- package/__tests__/remoteLoader.spec.ts +25 -10
- package/dist/types/config/src/generate.env.d.ts +1 -1
- package/dist/types/config/src/generate.env.d.ts.map +1 -1
- package/dist/types/config/src/generate.index.d.ts.map +1 -1
- package/dist/types/config/src/generate.manifest.d.ts +8 -0
- package/dist/types/config/src/generate.manifest.d.ts.map +1 -0
- package/dist/types/config/src/generate.metadata.d.ts.map +1 -1
- package/dist/types/config/src/index.d.ts +2 -2
- package/dist/types/config/src/index.d.ts.map +1 -1
- package/dist/types/config/src/register.d.ts.map +1 -1
- package/dist/types/config/src/utils/loadJson.d.ts +2 -2
- package/dist/types/config/src/utils/loadJson.d.ts.map +1 -1
- package/dist/types/config/src/validators/appshell.index.d.ts +4 -0
- package/dist/types/config/src/validators/appshell.index.d.ts.map +1 -0
- package/dist/types/config/src/validators/appshell.metadata.d.ts +4 -0
- package/dist/types/config/src/validators/appshell.metadata.d.ts.map +1 -0
- package/dist/types/config/src/validators/index.d.ts +2 -0
- package/dist/types/config/src/validators/index.d.ts.map +1 -1
- package/dist/types/loader/src/remoteLoader.d.ts +1 -1
- package/package.json +2 -2
- package/dist/types/config/src/generate.d.ts +0 -9
- package/dist/types/config/src/generate.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.1.0](https://github.com/navaris/appshell/compare/@appshell/loader@0.1.0-alpha.1...@appshell/loader@0.1.0) (2023-07-11)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* registry projection, enable env overwrite, refactor docker workflow, consolidate env names ([33a28fe](https://github.com/navaris/appshell/commit/33a28fe76b58e05c5b6b6b33d4b402e52bb29e70))
|
|
12
|
+
* rename @appshell/react-federated-component package to @appshell/react ([0b74498](https://github.com/navaris/appshell/commit/0b74498bf17ba73db4d936c8a012af1d3b111a28))
|
|
13
|
+
* replace config intermediate file with template ([9b79e65](https://github.com/navaris/appshell/commit/9b79e65b355686a0cca273c89c7164bb031e8437))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
# [0.1.0-alpha.1](https://github.com/navaris/appshell/compare/@appshell/loader@0.0.3...@appshell/loader@0.1.0-alpha.1) (2023-07-05)
|
|
7
20
|
|
|
8
21
|
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
# @appshell/loader
|
|
13
13
|
|
|
14
|
-
Dynamically load federated components for Webpack Module federation
|
|
14
|
+
Dynamically load federated components for micro-frontends built with Appshell and Webpack Module federation.
|
|
15
15
|
|
|
16
16
|
Working examples can be found [here](https://github.com/navaris/appshell/tree/main/examples).
|
|
17
17
|
|
|
@@ -40,21 +40,21 @@ The default export from this package is the loader function. It is given a manif
|
|
|
40
40
|
```ts
|
|
41
41
|
import componentLoader from '@appshell/loader';
|
|
42
42
|
|
|
43
|
-
const load = componentLoader(
|
|
43
|
+
const load = componentLoader(index);
|
|
44
44
|
|
|
45
45
|
const Component = load<MyComponent>('MyModule/MyComponent');
|
|
46
46
|
|
|
47
47
|
render(<Component />);
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
**Where does the
|
|
50
|
+
**Where does the index come from?**
|
|
51
51
|
|
|
52
52
|
> See [@appshell/cli](https://www.npmjs.com/package/@appshell/cli)
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
|
-
appshell generate
|
|
55
|
+
appshell generate index --manifest dist/appshell.manifest.json
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
**Do you have any framework specific loaders?**
|
|
59
59
|
|
|
60
|
-
> See [@appshell/react
|
|
60
|
+
> See [@appshell/react](https://www.npmjs.com/package/@appshell/react) for a `React` loader.
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/** @jest-environment jsdom */
|
|
2
|
-
import { AppshellManifest } from '@appshell/config';
|
|
2
|
+
import { AppshellIndex, AppshellManifest } from '@appshell/config';
|
|
3
|
+
import fetch, { enableFetchMocks } from 'jest-fetch-mock';
|
|
3
4
|
import * as fetchDynamicScript from '../src/fetchDynamicScript';
|
|
4
5
|
import * as loadFederatedComponent from '../src/loadFederatedComponent';
|
|
5
6
|
import remoteLoader from '../src/remoteLoader';
|
|
6
7
|
|
|
8
|
+
enableFetchMocks();
|
|
9
|
+
|
|
7
10
|
jest.mock('../src/fetchDynamicScript');
|
|
8
11
|
jest.mock('../src/loadFederatedComponent');
|
|
9
12
|
|
|
@@ -14,25 +17,36 @@ describe('remoteLoader', () => {
|
|
|
14
17
|
id: 'test-component',
|
|
15
18
|
scope: 'TestModule',
|
|
16
19
|
module: './TestComponent',
|
|
17
|
-
|
|
20
|
+
manifestUrl: 'http://test.com/appshell.manifest.json',
|
|
21
|
+
remoteEntryUrl: 'http://test.com/remoteEntry.js',
|
|
18
22
|
metadata: {},
|
|
19
23
|
},
|
|
20
24
|
},
|
|
21
25
|
modules: {},
|
|
22
26
|
environment: {},
|
|
23
27
|
};
|
|
28
|
+
const index: AppshellIndex = {
|
|
29
|
+
'TestModule/TestComponent': 'http://test.com/appshell.manifest.json',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
fetch.mockIf('http://test.com/appshell.manifest.json', () =>
|
|
34
|
+
Promise.resolve({ ok: true, body: JSON.stringify(manifest) }),
|
|
35
|
+
);
|
|
36
|
+
});
|
|
24
37
|
|
|
25
|
-
it('should return the federated component if it is found in the
|
|
38
|
+
it('should return the federated component if it is found in the registry', async () => {
|
|
26
39
|
const ExpectedComponent = () => 'test component';
|
|
27
40
|
jest.spyOn(fetchDynamicScript, 'default').mockReturnValueOnce(Promise.resolve(true));
|
|
28
41
|
jest
|
|
29
42
|
.spyOn(loadFederatedComponent, 'default')
|
|
30
43
|
.mockResolvedValue(Promise.resolve(ExpectedComponent));
|
|
31
44
|
|
|
32
|
-
const loadRemote = remoteLoader(
|
|
33
|
-
const ActualComponent = await loadRemote('TestModule/TestComponent');
|
|
45
|
+
const loadRemote = remoteLoader(index);
|
|
46
|
+
const [ActualComponent, actualManifest] = await loadRemote('TestModule/TestComponent');
|
|
34
47
|
|
|
35
48
|
expect(ActualComponent).toEqual(ExpectedComponent);
|
|
49
|
+
expect(actualManifest).toEqual(manifest);
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
it('should not fetch remote entry more than once', async () => {
|
|
@@ -44,7 +58,7 @@ describe('remoteLoader', () => {
|
|
|
44
58
|
.spyOn(loadFederatedComponent, 'default')
|
|
45
59
|
.mockResolvedValue(Promise.resolve(ExpectedComponent));
|
|
46
60
|
|
|
47
|
-
const loadRemote = remoteLoader(
|
|
61
|
+
const loadRemote = remoteLoader(index);
|
|
48
62
|
|
|
49
63
|
await loadRemote('TestModule/TestComponent');
|
|
50
64
|
await loadRemote('TestModule/TestComponent');
|
|
@@ -53,21 +67,22 @@ describe('remoteLoader', () => {
|
|
|
53
67
|
expect(fetchDynamicScriptSpy).toHaveBeenCalledTimes(1);
|
|
54
68
|
});
|
|
55
69
|
|
|
56
|
-
it('should throw if remote key is not found in the
|
|
70
|
+
it('should throw if remote key is not found in the registry', async () => {
|
|
57
71
|
const ExpectedComponent = () => 'test component';
|
|
58
72
|
jest.spyOn(loadFederatedComponent, 'default').mockResolvedValue(ExpectedComponent);
|
|
59
73
|
|
|
60
|
-
const loadRemote = remoteLoader(
|
|
74
|
+
const loadRemote = remoteLoader(index);
|
|
61
75
|
|
|
62
76
|
await expect(loadRemote('TestModule/DoesNotExist')).rejects.toThrow(
|
|
63
|
-
/Remote resource not found in
|
|
77
|
+
/Remote resource not found in registry/i,
|
|
64
78
|
);
|
|
65
79
|
});
|
|
66
80
|
|
|
67
81
|
it('should throw if load federated component fails', async () => {
|
|
82
|
+
jest.spyOn(fetchDynamicScript, 'default').mockReturnValueOnce(Promise.resolve(true));
|
|
68
83
|
jest.spyOn(loadFederatedComponent, 'default').mockRejectedValue(new Error('failed'));
|
|
69
84
|
|
|
70
|
-
const loadRemote = remoteLoader(
|
|
85
|
+
const loadRemote = remoteLoader(index);
|
|
71
86
|
|
|
72
87
|
await expect(loadRemote('TestModule/TestComponent')).rejects.toThrow(
|
|
73
88
|
/Failed to load component/i,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const _default: (env: string, prefix?: string) => Promise<Map<string, string
|
|
1
|
+
declare const _default: (env: string, prefix?: string, overwrite?: boolean) => Promise<Map<string, string>>;
|
|
2
2
|
export default _default;
|
|
3
3
|
//# sourceMappingURL=generate.env.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.env.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.env.ts"],"names":[],"mappings":"8BAO2B,MAAM;AAAjC,
|
|
1
|
+
{"version":3,"file":"generate.env.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.env.ts"],"names":[],"mappings":"8BAO2B,MAAM;AAAjC,wBA8BK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.index.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"generate.index.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;qCAKN,MAAM,EAAE,KAAG,QAAQ,aAAa,CAAC;AAAnE,wBAyBE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates an appshell manifest
|
|
3
|
+
* @param templatePath path of the appshell manifest template to compile into an appshell manifest
|
|
4
|
+
* @returns an appshell manifest
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: <TMetadata extends Record<string, unknown>>(templatePath: string) => Promise<import("./types").AppshellManifest<TMetadata> | null>;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=generate.manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.manifest.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.manifest.ts"],"names":[],"mappings":"AAOA;;;;GAIG;kFAC4E,MAAM;AAArF,wBAaE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.metadata.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.metadata.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"generate.metadata.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.metadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;mEAK6B,MAAM,EAAE;AAAxE,wBAyBE"}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* @appshell/config package API
|
|
3
3
|
*/
|
|
4
4
|
export { default as configmap } from './configmap';
|
|
5
|
-
export { default as generateManifest } from './generate';
|
|
6
5
|
export { default as generateEnv } from './generate.env';
|
|
7
6
|
export { default as generateIndex } from './generate.index';
|
|
7
|
+
export { default as generateManifest } from './generate.manifest';
|
|
8
8
|
export { default as generateMetadata } from './generate.metadata';
|
|
9
9
|
export { default as register } from './register';
|
|
10
|
-
export type { AppshellConfig, AppshellConfigRemote, AppshellIndex, AppshellManifest, AppshellRemote, Schema, } from './types';
|
|
10
|
+
export type { AppshellConfig, AppshellConfigRemote, AppshellIndex, AppshellManifest, AppshellRemote, Metadata, Schema, } from './types';
|
|
11
11
|
export * as utils from './utils';
|
|
12
12
|
export * as validators from './validators';
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../config/src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../config/src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,QAAQ,EACR,MAAM,GACP,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../../config/src/register.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../../config/src/register.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAmB,MAAM,SAAS,CAAC;mCAc5B,gBAAgB,YAAY,MAAM;AAAlE,wBA4BE"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const
|
|
2
|
-
export default
|
|
1
|
+
declare const _default: <T = Record<string, unknown>>(jsonPathOrUrl: string, target?: string | RegExp) => Promise<T[]>;
|
|
2
|
+
export default _default;
|
|
3
3
|
//# sourceMappingURL=loadJson.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadJson.d.ts","sourceRoot":"","sources":["../../../../../../config/src/utils/loadJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadJson.d.ts","sourceRoot":"","sources":["../../../../../../config/src/utils/loadJson.ts"],"names":[],"mappings":"qEAkCiB,MAAM,WACb,MAAM,GAAG,MAAM;AAFzB,wBAOE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appshell.index.d.ts","sourceRoot":"","sources":["../../../../../../config/src/validators/appshell.index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,eAAe,EAAE,MAAM,UAAU,CAAC;;AAE1D,wBAKqB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appshell.metadata.d.ts","sourceRoot":"","sources":["../../../../../../config/src/validators/appshell.metadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,eAAe,EAAE,MAAM,UAAU,CAAC;;AAE1D,wBAKqB"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { default as appshell_config } from './appshell.config';
|
|
2
|
+
export { default as appshell_index } from './appshell.index';
|
|
2
3
|
export { default as appshell_manifest } from './appshell.manifest';
|
|
4
|
+
export { default as appshell_metadata } from './appshell.metadata';
|
|
3
5
|
export { default as merge_manifests } from './merge.manifests';
|
|
4
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../config/src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../config/src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type AppshellIndex, type AppshellManifest } from '@appshell/config';
|
|
2
|
-
declare const _default: (index: AppshellIndex) => <TComponent>(key: string) => Promise<readonly [TComponent, AppshellManifest<import("
|
|
2
|
+
declare const _default: (index: AppshellIndex) => <TComponent>(key: string) => Promise<readonly [TComponent, AppshellManifest<import("@appshell/config").Metadata>] | readonly [null, null]>;
|
|
3
3
|
export default _default;
|
|
4
4
|
//# sourceMappingURL=remoteLoader.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appshell/loader",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Utility for loading federated components",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/loader/src/index.d.ts",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"appshell"
|
|
26
26
|
],
|
|
27
27
|
"license": "MIT",
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a20c074472f1f55b0479b07e95d63aa0ccdd4be9"
|
|
29
29
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates an appshell manifest
|
|
3
|
-
* @param configPath path of the appshell config to compile into an appshell manifest
|
|
4
|
-
* @param webpackConfig path of the webpack config
|
|
5
|
-
* @returns an appshell manifest
|
|
6
|
-
*/
|
|
7
|
-
declare const _default: <TMetadata extends Record<string, unknown>>(configPath: string, webpackConfig?: string, webpackEnv?: {}, webpackArgs?: {}) => Promise<import("./types").AppshellManifest<TMetadata> | null>;
|
|
8
|
-
export default _default;
|
|
9
|
-
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../../../config/src/generate.ts"],"names":[],"mappings":"AAyHA;;;;;GAKG;gFAEW,MAAM;AADpB,wBAsBE"}
|