@modern-js/plugin-garfish 1.3.0 → 1.4.1
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/.eslintrc.js +1 -1
- package/CHANGELOG.md +35 -0
- package/dist/js/modern/cli/index.js +204 -225
- package/dist/js/modern/cli/utils.js +85 -31
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/runtime/index.js +2 -1
- package/dist/js/modern/runtime/loadable.js +36 -19
- package/dist/js/modern/runtime/plugin.js +24 -19
- package/dist/js/modern/runtime/utils/MApp.js +7 -10
- package/dist/js/modern/runtime/utils/apps.js +3 -9
- package/dist/js/node/cli/index.js +207 -222
- package/dist/js/node/cli/utils.js +89 -31
- package/dist/js/node/index.js +18 -3
- package/dist/js/node/runtime/index.js +25 -12
- package/dist/js/node/runtime/loadable.js +36 -19
- package/dist/js/node/runtime/plugin.js +21 -18
- package/dist/js/node/runtime/utils/MApp.js +7 -10
- package/dist/js/node/runtime/utils/apps.js +3 -9
- package/dist/js/treeshaking/cli/index.js +124 -121
- package/dist/js/treeshaking/cli/utils.js +33 -4
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/runtime/index.js +2 -1
- package/dist/js/treeshaking/runtime/loadable.js +39 -25
- package/dist/js/treeshaking/runtime/plugin.js +29 -24
- package/dist/js/treeshaking/runtime/utils/MApp.js +23 -31
- package/dist/js/treeshaking/runtime/utils/apps.js +22 -24
- package/dist/types/cli/index.d.ts +18 -10
- package/dist/types/cli/utils.d.ts +5 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/runtime/index.d.ts +3 -1
- package/dist/types/runtime/loadable.d.ts +2 -8
- package/dist/types/runtime/plugin.d.ts +29 -3
- package/dist/types/runtime/useModuleApps.d.ts +7 -9
- package/dist/types/runtime/utils/MApp.d.ts +1 -15
- package/dist/types/runtime/utils/apps.d.ts +1 -1
- package/package.json +21 -9
- package/tests/cli.test.tsx +203 -33
- package/tests/hooks.test.tsx +1 -0
- package/tests/index.test.tsx +6 -3
- package/tsconfig.json +3 -2
- package/tests/__snapshots__/cli.test.tsx.snap +0 -71
package/tests/cli.test.tsx
CHANGED
|
@@ -1,51 +1,221 @@
|
|
|
1
1
|
import '@testing-library/jest-dom';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import GarfishPlugin, {
|
|
2
|
+
import { manager, useAppContext } from '@modern-js/core';
|
|
3
|
+
import WebpackChain from 'webpack-chain';
|
|
4
|
+
import GarfishPlugin, { externals, resolvedConfig } from '../src/cli';
|
|
5
|
+
import { getRuntimeConfig, makeRenderFunction, setRuntimeConfig } from '../src/cli/utils';
|
|
6
|
+
|
|
7
|
+
const mock_config_context = {
|
|
8
|
+
context: {},
|
|
9
|
+
get() {
|
|
10
|
+
return this.context;
|
|
11
|
+
},
|
|
12
|
+
set(newContext: any) {
|
|
13
|
+
Object.assign(this.context, newContext);
|
|
14
|
+
},
|
|
15
|
+
recover(newContext: any) {
|
|
16
|
+
this.context = newContext;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
5
19
|
|
|
6
20
|
jest.mock('@modern-js/core', () => {
|
|
7
21
|
const originalModule = jest.requireActual('@modern-js/core');
|
|
8
22
|
return {
|
|
9
23
|
__esModule: true,
|
|
10
24
|
...originalModule,
|
|
11
|
-
|
|
12
|
-
|
|
25
|
+
useResolvedConfigContext: ()=>{
|
|
26
|
+
return mock_config_context.get();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
describe('plugin-garfish cli', () => {
|
|
33
|
+
test('cli garfish basename', async () => {
|
|
34
|
+
expect(GarfishPlugin.name).toBe('@modern-js/plugin-garfish');
|
|
35
|
+
const basename = '/test';
|
|
36
|
+
const resolveConfig = {
|
|
37
|
+
resolved: {
|
|
38
|
+
runtime: {
|
|
39
|
+
router: {
|
|
40
|
+
historyOptions: { basename }
|
|
41
|
+
},
|
|
42
|
+
masterApp: {}
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const config = await resolvedConfig(resolveConfig as any);
|
|
47
|
+
expect(config.resolved.runtime.masterApp.basename).toBe(basename);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('cli makeRender function', ()=>{
|
|
51
|
+
const code = `
|
|
52
|
+
const router = (config)=> config;
|
|
53
|
+
const App = {};
|
|
54
|
+
const routerConfig = router({...App?.config?.router, ...App?.config?.features?.router});
|
|
55
|
+
const resultConfig = {
|
|
56
|
+
routerConfig,
|
|
57
|
+
renderByProvider: true,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (IS_BROWSER) {
|
|
61
|
+
resultConfig.renderByProvider = false;
|
|
62
|
+
}
|
|
63
|
+
return resultConfig;
|
|
64
|
+
`;
|
|
65
|
+
const generateNewRenderFn = new Function('appInfo', 'IS_BROWSER', '__GARFISH_EXPORTS__', makeRenderFunction(code));
|
|
66
|
+
|
|
67
|
+
// render byGarfish but don't provider appInfo
|
|
68
|
+
expect(generateNewRenderFn(undefined, true, false)).toBe(null);
|
|
69
|
+
|
|
70
|
+
// run alone
|
|
71
|
+
expect(generateNewRenderFn(undefined, true)).toMatchObject({
|
|
72
|
+
renderByProvider: false
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// render ByGarfish and provider appInfo
|
|
76
|
+
expect(generateNewRenderFn({ basename: '/test' }, true, true)).toMatchObject({
|
|
77
|
+
renderByProvider: true,
|
|
78
|
+
routerConfig: {
|
|
79
|
+
basename: '/test',
|
|
80
|
+
historyOptions: {
|
|
81
|
+
basename: '/test'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('cli get runtime config', ()=>{
|
|
88
|
+
const runtimeConfig = getRuntimeConfig({
|
|
13
89
|
runtime: {
|
|
14
90
|
masterApp: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
91
|
+
basename: '/test'
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
expect(runtimeConfig).toMatchObject({
|
|
96
|
+
masterApp: {
|
|
97
|
+
basename: '/test'
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('cli get runtime features config', ()=>{
|
|
103
|
+
const runtimeConfig = getRuntimeConfig({
|
|
104
|
+
runtime: {
|
|
105
|
+
masterApp: {
|
|
106
|
+
basename: '/test'
|
|
18
107
|
},
|
|
19
|
-
|
|
108
|
+
features: {
|
|
109
|
+
masterApp: {
|
|
110
|
+
basename: '/test2'
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(runtimeConfig).toMatchObject({
|
|
117
|
+
masterApp: {
|
|
118
|
+
basename: '/test2'
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('cli set runtime config', ()=>{
|
|
124
|
+
const runtimeConfig = {
|
|
125
|
+
runtime: {
|
|
126
|
+
masterApp: {
|
|
127
|
+
basename: '/test'
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
setRuntimeConfig(runtimeConfig, 'masterApp', true);
|
|
133
|
+
|
|
134
|
+
expect(runtimeConfig.runtime.masterApp).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('cli set runtime features config', ()=>{
|
|
138
|
+
const runtimeConfig = {
|
|
139
|
+
runtime: {
|
|
140
|
+
features: {
|
|
141
|
+
masterApp: {
|
|
142
|
+
basename: '/test'
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
setRuntimeConfig(runtimeConfig, 'masterApp', true);
|
|
149
|
+
|
|
150
|
+
expect(runtimeConfig.runtime.features.masterApp).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('webpack config close external and use js entry', async ()=>{
|
|
154
|
+
const main = manager.clone().usePlugin(GarfishPlugin);
|
|
155
|
+
const runner = await main.init();
|
|
156
|
+
await runner.prepare();
|
|
157
|
+
const config: any = await runner.config();
|
|
158
|
+
const webpackConfig = new WebpackChain();
|
|
159
|
+
mock_config_context.recover({
|
|
20
160
|
deploy: {
|
|
21
|
-
microFrontend:
|
|
161
|
+
microFrontend: {
|
|
162
|
+
externalBasicLibrary: true,
|
|
163
|
+
enableHtmlEntry: false,
|
|
164
|
+
},
|
|
22
165
|
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
166
|
+
server: {
|
|
167
|
+
port: '8080'
|
|
168
|
+
}
|
|
169
|
+
});
|
|
26
170
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
171
|
+
config[0].tools.webpack({}, {
|
|
172
|
+
chain: webpackConfig,
|
|
173
|
+
webpack: jest.fn(),
|
|
174
|
+
env: 'development'
|
|
175
|
+
});
|
|
32
176
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
177
|
+
const generateConfig = webpackConfig.toConfig();
|
|
178
|
+
expect(generateConfig).toMatchObject({
|
|
179
|
+
output: {
|
|
180
|
+
libraryTarget: 'umd',
|
|
181
|
+
publicPath: '//localhost:8080/',
|
|
182
|
+
filename: 'index.js'
|
|
37
183
|
},
|
|
38
|
-
externals
|
|
39
|
-
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
entrypoint: 'hello',
|
|
43
|
-
exportStatement: '',
|
|
44
|
-
});
|
|
45
|
-
expect(exportStatement).toMatchSnapshot();
|
|
46
|
-
});
|
|
184
|
+
externals,
|
|
185
|
+
optimization: { runtimeChunk: false, splitChunks: { chunks: 'async' } }
|
|
186
|
+
});
|
|
187
|
+
})
|
|
47
188
|
|
|
48
|
-
test('
|
|
49
|
-
|
|
189
|
+
test('webpack config default micro config', async ()=>{
|
|
190
|
+
const main = manager.clone().usePlugin(GarfishPlugin);
|
|
191
|
+
const runner = await main.init();
|
|
192
|
+
await runner.prepare();
|
|
193
|
+
const config: any = await runner.config();
|
|
194
|
+
const webpackConfig = new WebpackChain();
|
|
195
|
+
|
|
196
|
+
mock_config_context.recover({
|
|
197
|
+
deploy: {
|
|
198
|
+
microFrontend: true,
|
|
199
|
+
},
|
|
200
|
+
server: {
|
|
201
|
+
port: '8080'
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
config[0].tools.webpack({}, {
|
|
206
|
+
chain: webpackConfig,
|
|
207
|
+
webpack: jest.fn(),
|
|
208
|
+
env: 'development'
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const generateConfig = webpackConfig.toConfig();
|
|
212
|
+
expect(generateConfig).toMatchObject({
|
|
213
|
+
output: {
|
|
214
|
+
libraryTarget: 'umd',
|
|
215
|
+
publicPath: '//localhost:8080/'
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
expect(generateConfig.externals).toBeUndefined();
|
|
219
|
+
expect(generateConfig.output.filename).toBeUndefined();
|
|
50
220
|
});
|
|
51
221
|
});
|
package/tests/hooks.test.tsx
CHANGED
package/tests/index.test.tsx
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
useLocation,
|
|
13
13
|
MemoryRouter,
|
|
14
14
|
} from '@modern-js/plugin-router';
|
|
15
|
-
import ModernGarfishPlugin
|
|
15
|
+
import ModernGarfishPlugin from '../src/runtime';
|
|
16
|
+
import { useMicroApps } from '../src';
|
|
16
17
|
import {
|
|
17
18
|
TABLE_LIST_ESCAPE_NODE,
|
|
18
19
|
TABLE_LIST_HTML,
|
|
@@ -99,8 +100,10 @@ describe('plugin-garfish', () => {
|
|
|
99
100
|
const microFrontendConfig = {
|
|
100
101
|
apps: [tableListModuleInfo, dashBoardModuleInfo, userInfo],
|
|
101
102
|
manifest: {
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
loadable: {
|
|
104
|
+
loading: ()=> {
|
|
105
|
+
return <div data-testid="loading-id">loading</div>;
|
|
106
|
+
}
|
|
104
107
|
},
|
|
105
108
|
},
|
|
106
109
|
};
|
package/tsconfig.json
CHANGED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`plugin-garfish cli makeProvider 1`] = `
|
|
4
|
-
"
|
|
5
|
-
export const provider = function ({basename, dom, ...props}) {
|
|
6
|
-
return {
|
|
7
|
-
render({basename, dom}) {
|
|
8
|
-
const SubApp = render(props, basename);
|
|
9
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
10
|
-
|
|
11
|
-
bootstrap(SubApp, node);
|
|
12
|
-
},
|
|
13
|
-
destroy({ dom }) {
|
|
14
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
15
|
-
|
|
16
|
-
if (node) {
|
|
17
|
-
unmountComponentAtNode(node);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
SubModuleComponent: (props) => {
|
|
21
|
-
const SubApp = render(props, basename);
|
|
22
|
-
|
|
23
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
24
|
-
},
|
|
25
|
-
modernJSExportComponent: () => {
|
|
26
|
-
const SubApp = render(props, basename);
|
|
27
|
-
|
|
28
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
33
|
-
__GARFISH_EXPORTS__.provider = provider;
|
|
34
|
-
}
|
|
35
|
-
"
|
|
36
|
-
`;
|
|
37
|
-
|
|
38
|
-
exports[`plugin-garfish cli test modifyEntryExport 1`] = `
|
|
39
|
-
"
|
|
40
|
-
export const provider = function ({basename, dom, ...props}) {
|
|
41
|
-
return {
|
|
42
|
-
render({basename, dom}) {
|
|
43
|
-
const SubApp = render(props, basename);
|
|
44
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
45
|
-
|
|
46
|
-
bootstrap(SubApp, node);
|
|
47
|
-
},
|
|
48
|
-
destroy({ dom }) {
|
|
49
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
50
|
-
|
|
51
|
-
if (node) {
|
|
52
|
-
unmountComponentAtNode(node);
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
SubModuleComponent: (props) => {
|
|
56
|
-
const SubApp = render(props, basename);
|
|
57
|
-
|
|
58
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
59
|
-
},
|
|
60
|
-
test-dynamic-key: () => {
|
|
61
|
-
const SubApp = render(props, basename);
|
|
62
|
-
|
|
63
|
-
return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
68
|
-
__GARFISH_EXPORTS__.provider = provider;
|
|
69
|
-
}
|
|
70
|
-
"
|
|
71
|
-
`;
|