@modern-js/server-core 2.0.0-beta.0 → 2.0.0-beta.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/CHANGELOG.md +33 -0
- package/dist/js/modern/loadPlugins.js +0 -4
- package/dist/js/modern/plugin.js +15 -6
- package/dist/js/node/index.js +0 -6
- package/dist/js/node/loadPlugins.js +0 -7
- package/dist/js/node/plugin.js +15 -16
- package/dist/types/plugin.d.ts +0 -7
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @modern-js/server-plugin
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 543be9558e: feat: compile server loader and support handle loader request
|
|
12
|
+
feat: 编译 server loader 并支持处理 loader 的请求
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 15bf09d9c8: feat: support completely custom server, export render() api for render single page
|
|
17
|
+
feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
|
|
18
|
+
- cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
|
|
19
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
|
20
|
+
- Updated dependencies [92f0ead]
|
|
21
|
+
- Updated dependencies [edd1cfb1af]
|
|
22
|
+
- Updated dependencies [cc971eabfc]
|
|
23
|
+
- Updated dependencies [5b9049f]
|
|
24
|
+
- Updated dependencies [92004d1]
|
|
25
|
+
- Updated dependencies [b8bbe036c7]
|
|
26
|
+
- Updated dependencies [d5a31df781]
|
|
27
|
+
- Updated dependencies [dda38c9]
|
|
28
|
+
- Updated dependencies [3bbea92b2a]
|
|
29
|
+
- Updated dependencies [f179749]
|
|
30
|
+
- Updated dependencies [abf3421]
|
|
31
|
+
- Updated dependencies [543be9558e]
|
|
32
|
+
- Updated dependencies [14b712d]
|
|
33
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
34
|
+
- @modern-js/plugin@2.0.0-beta.1
|
|
35
|
+
|
|
3
36
|
## 2.0.0-beta.0
|
|
4
37
|
|
|
5
38
|
### Major Changes
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { compatRequire, getInternalPlugins, tryResolve } from '@modern-js/utils';
|
|
2
2
|
import { createPlugin } from "./plugin";
|
|
3
|
-
|
|
4
3
|
const resolvePlugin = (p, appDirectory) => {
|
|
5
4
|
const isPluginInstance = typeof p !== 'string';
|
|
6
|
-
|
|
7
5
|
if (isPluginInstance) {
|
|
8
6
|
return {
|
|
9
7
|
module: createPlugin(p.setup, p)
|
|
10
8
|
};
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
const pluginPath = tryResolve(p, appDirectory);
|
|
14
11
|
const module = compatRequire(pluginPath);
|
|
15
12
|
const pluginInstance = module();
|
|
@@ -17,7 +14,6 @@ const resolvePlugin = (p, appDirectory) => {
|
|
|
17
14
|
module: createPlugin(pluginInstance.setup, pluginInstance)
|
|
18
15
|
};
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
export const loadPlugins = (appDirectory, configPlugins, options) => {
|
|
22
18
|
const loadedPlugins = getInternalPlugins(appDirectory, options.internalPlugins);
|
|
23
19
|
return [...loadedPlugins, ...configPlugins].map(plugin => {
|
package/dist/js/modern/plugin.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createContext, createAsyncManager, createAsyncPipeline, createAsyncWaterfall, createParallelWorkflow, createWaterfall } from '@modern-js/plugin';
|
|
2
2
|
// collect all middleware register in server plugins
|
|
3
|
-
const gather = createParallelWorkflow();
|
|
3
|
+
const gather = createParallelWorkflow();
|
|
4
4
|
|
|
5
|
+
// config
|
|
5
6
|
const config = createWaterfall();
|
|
6
7
|
const prepare = createWaterfall();
|
|
7
8
|
const preparebeforeRouteHandler = createAsyncPipeline();
|
|
@@ -10,7 +11,9 @@ const prepareApiServer = createAsyncPipeline();
|
|
|
10
11
|
const onApiChange = createWaterfall();
|
|
11
12
|
const beforeDevServer = createParallelWorkflow();
|
|
12
13
|
const setupCompiler = createParallelWorkflow();
|
|
13
|
-
const afterDevServer = createParallelWorkflow();
|
|
14
|
+
const afterDevServer = createParallelWorkflow();
|
|
15
|
+
|
|
16
|
+
// TODO FIXME
|
|
14
17
|
|
|
15
18
|
const beforeRouteSet = createAsyncPipeline();
|
|
16
19
|
const afterRouteSet = createAsyncPipeline();
|
|
@@ -23,9 +26,13 @@ const extendSSRContext = createAsyncWaterfall();
|
|
|
23
26
|
const extendContext = createAsyncPipeline();
|
|
24
27
|
const handleError = createParallelWorkflow();
|
|
25
28
|
const beforeMatch = createAsyncPipeline();
|
|
26
|
-
const afterMatch = createAsyncPipeline();
|
|
29
|
+
const afterMatch = createAsyncPipeline();
|
|
30
|
+
|
|
31
|
+
// TODO FIXME
|
|
32
|
+
|
|
33
|
+
const prefetch = createParallelWorkflow();
|
|
27
34
|
|
|
28
|
-
|
|
35
|
+
// TODO FIXME
|
|
29
36
|
|
|
30
37
|
const renderToString = createAsyncPipeline();
|
|
31
38
|
const beforeRender = createAsyncPipeline();
|
|
@@ -36,15 +43,15 @@ const reset = createParallelWorkflow();
|
|
|
36
43
|
export const AppContext = createContext({});
|
|
37
44
|
export const setAppContext = value => AppContext.set(value);
|
|
38
45
|
export const ConfigContext = createContext({});
|
|
46
|
+
|
|
39
47
|
/**
|
|
40
48
|
* Get original content of user config.
|
|
41
49
|
*/
|
|
42
|
-
|
|
43
50
|
export const useConfigContext = () => ConfigContext.use().value;
|
|
51
|
+
|
|
44
52
|
/**
|
|
45
53
|
* Get app context, including directories, plugins and some static infos.
|
|
46
54
|
*/
|
|
47
|
-
|
|
48
55
|
export const useAppContext = () => AppContext.use().value;
|
|
49
56
|
const pluginAPI = {
|
|
50
57
|
useAppContext,
|
|
@@ -84,10 +91,12 @@ const serverHooks = {
|
|
|
84
91
|
afterSend,
|
|
85
92
|
reset
|
|
86
93
|
};
|
|
94
|
+
|
|
87
95
|
/** All hooks of server plugin. */
|
|
88
96
|
|
|
89
97
|
export const createServerManager = () => createAsyncManager(serverHooks, pluginAPI);
|
|
90
98
|
export const serverManager = createServerManager();
|
|
99
|
+
|
|
91
100
|
/** Plugin options of a server plugin. */
|
|
92
101
|
|
|
93
102
|
export const {
|
package/dist/js/node/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _plugin = require("./plugin");
|
|
8
|
-
|
|
9
7
|
Object.keys(_plugin).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _plugin[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_plugin).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _plugin2 = require("@modern-js/plugin");
|
|
21
|
-
|
|
22
18
|
Object.keys(_plugin2).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _plugin2[key]) return;
|
|
@@ -29,9 +25,7 @@ Object.keys(_plugin2).forEach(function (key) {
|
|
|
29
25
|
}
|
|
30
26
|
});
|
|
31
27
|
});
|
|
32
|
-
|
|
33
28
|
var _loadPlugins = require("./loadPlugins");
|
|
34
|
-
|
|
35
29
|
Object.keys(_loadPlugins).forEach(function (key) {
|
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
|
37
31
|
if (key in exports && exports[key] === _loadPlugins[key]) return;
|
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.loadPlugins = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
var _plugin = require("./plugin");
|
|
11
|
-
|
|
12
9
|
const resolvePlugin = (p, appDirectory) => {
|
|
13
10
|
const isPluginInstance = typeof p !== 'string';
|
|
14
|
-
|
|
15
11
|
if (isPluginInstance) {
|
|
16
12
|
return {
|
|
17
13
|
module: (0, _plugin.createPlugin)(p.setup, p)
|
|
18
14
|
};
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
const pluginPath = (0, _utils.tryResolve)(p, appDirectory);
|
|
22
17
|
const module = (0, _utils.compatRequire)(pluginPath);
|
|
23
18
|
const pluginInstance = module();
|
|
@@ -25,7 +20,6 @@ const resolvePlugin = (p, appDirectory) => {
|
|
|
25
20
|
module: (0, _plugin.createPlugin)(pluginInstance.setup, pluginInstance)
|
|
26
21
|
};
|
|
27
22
|
};
|
|
28
|
-
|
|
29
23
|
const loadPlugins = (appDirectory, configPlugins, options) => {
|
|
30
24
|
const loadedPlugins = (0, _utils.getInternalPlugins)(appDirectory, options.internalPlugins);
|
|
31
25
|
return [...loadedPlugins, ...configPlugins].map(plugin => {
|
|
@@ -35,5 +29,4 @@ const loadPlugins = (appDirectory, configPlugins, options) => {
|
|
|
35
29
|
return module;
|
|
36
30
|
});
|
|
37
31
|
};
|
|
38
|
-
|
|
39
32
|
exports.loadPlugins = loadPlugins;
|
package/dist/js/node/plugin.js
CHANGED
|
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useConfigContext = exports.useAppContext = exports.setAppContext = exports.serverManager = exports.createServerManager = exports.createPlugin = exports.ConfigContext = exports.AppContext = void 0;
|
|
7
|
-
|
|
8
7
|
var _plugin = require("@modern-js/plugin");
|
|
9
|
-
|
|
10
8
|
// collect all middleware register in server plugins
|
|
11
|
-
const gather = (0, _plugin.createParallelWorkflow)();
|
|
9
|
+
const gather = (0, _plugin.createParallelWorkflow)();
|
|
12
10
|
|
|
11
|
+
// config
|
|
13
12
|
const config = (0, _plugin.createWaterfall)();
|
|
14
13
|
const prepare = (0, _plugin.createWaterfall)();
|
|
15
14
|
const preparebeforeRouteHandler = (0, _plugin.createAsyncPipeline)();
|
|
@@ -18,7 +17,9 @@ const prepareApiServer = (0, _plugin.createAsyncPipeline)();
|
|
|
18
17
|
const onApiChange = (0, _plugin.createWaterfall)();
|
|
19
18
|
const beforeDevServer = (0, _plugin.createParallelWorkflow)();
|
|
20
19
|
const setupCompiler = (0, _plugin.createParallelWorkflow)();
|
|
21
|
-
const afterDevServer = (0, _plugin.createParallelWorkflow)();
|
|
20
|
+
const afterDevServer = (0, _plugin.createParallelWorkflow)();
|
|
21
|
+
|
|
22
|
+
// TODO FIXME
|
|
22
23
|
|
|
23
24
|
const beforeRouteSet = (0, _plugin.createAsyncPipeline)();
|
|
24
25
|
const afterRouteSet = (0, _plugin.createAsyncPipeline)();
|
|
@@ -31,9 +32,13 @@ const extendSSRContext = (0, _plugin.createAsyncWaterfall)();
|
|
|
31
32
|
const extendContext = (0, _plugin.createAsyncPipeline)();
|
|
32
33
|
const handleError = (0, _plugin.createParallelWorkflow)();
|
|
33
34
|
const beforeMatch = (0, _plugin.createAsyncPipeline)();
|
|
34
|
-
const afterMatch = (0, _plugin.createAsyncPipeline)();
|
|
35
|
+
const afterMatch = (0, _plugin.createAsyncPipeline)();
|
|
36
|
+
|
|
37
|
+
// TODO FIXME
|
|
38
|
+
|
|
39
|
+
const prefetch = (0, _plugin.createParallelWorkflow)();
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
// TODO FIXME
|
|
37
42
|
|
|
38
43
|
const renderToString = (0, _plugin.createAsyncPipeline)();
|
|
39
44
|
const beforeRender = (0, _plugin.createAsyncPipeline)();
|
|
@@ -43,27 +48,21 @@ const afterSend = (0, _plugin.createParallelWorkflow)();
|
|
|
43
48
|
const reset = (0, _plugin.createParallelWorkflow)();
|
|
44
49
|
const AppContext = (0, _plugin.createContext)({});
|
|
45
50
|
exports.AppContext = AppContext;
|
|
46
|
-
|
|
47
51
|
const setAppContext = value => AppContext.set(value);
|
|
48
|
-
|
|
49
52
|
exports.setAppContext = setAppContext;
|
|
50
53
|
const ConfigContext = (0, _plugin.createContext)({});
|
|
54
|
+
|
|
51
55
|
/**
|
|
52
56
|
* Get original content of user config.
|
|
53
57
|
*/
|
|
54
|
-
|
|
55
58
|
exports.ConfigContext = ConfigContext;
|
|
56
|
-
|
|
57
59
|
const useConfigContext = () => ConfigContext.use().value;
|
|
60
|
+
|
|
58
61
|
/**
|
|
59
62
|
* Get app context, including directories, plugins and some static infos.
|
|
60
63
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
64
|
exports.useConfigContext = useConfigContext;
|
|
64
|
-
|
|
65
65
|
const useAppContext = () => AppContext.use().value;
|
|
66
|
-
|
|
67
66
|
exports.useAppContext = useAppContext;
|
|
68
67
|
const pluginAPI = {
|
|
69
68
|
useAppContext,
|
|
@@ -103,14 +102,14 @@ const serverHooks = {
|
|
|
103
102
|
afterSend,
|
|
104
103
|
reset
|
|
105
104
|
};
|
|
105
|
+
|
|
106
106
|
/** All hooks of server plugin. */
|
|
107
107
|
|
|
108
108
|
const createServerManager = () => (0, _plugin.createAsyncManager)(serverHooks, pluginAPI);
|
|
109
|
-
|
|
110
109
|
exports.createServerManager = createServerManager;
|
|
111
110
|
const serverManager = createServerManager();
|
|
112
|
-
/** Plugin options of a server plugin. */
|
|
113
111
|
|
|
112
|
+
/** Plugin options of a server plugin. */
|
|
114
113
|
exports.serverManager = serverManager;
|
|
115
114
|
const {
|
|
116
115
|
createPlugin
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type { ModernServerContext, BaseSSRServerContext, AfterMatchContext, Afte
|
|
|
6
6
|
import type { NormalizedConfig, UserConfig } from '@modern-js/core';
|
|
7
7
|
import type { Options } from 'http-proxy-middleware';
|
|
8
8
|
/** The subset of NormalizedConfig, which really need in server */
|
|
9
|
-
|
|
10
9
|
export declare type ServerOptions = {
|
|
11
10
|
output: Pick<NormalizedConfig['output'], 'path' | 'assetPrefix'>;
|
|
12
11
|
source: Pick<NormalizedConfig['source'], 'alias' | 'envVars' | 'globalVars'>;
|
|
@@ -48,12 +47,10 @@ export declare const ConfigContext: import("@modern-js/plugin").Context<UserConf
|
|
|
48
47
|
/**
|
|
49
48
|
* Get original content of user config.
|
|
50
49
|
*/
|
|
51
|
-
|
|
52
50
|
export declare const useConfigContext: () => UserConfig;
|
|
53
51
|
/**
|
|
54
52
|
* Get app context, including directories, plugins and some static infos.
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
54
|
export declare const useAppContext: () => ISAppContext;
|
|
58
55
|
declare const pluginAPI: {
|
|
59
56
|
useAppContext: () => ISAppContext;
|
|
@@ -114,13 +111,10 @@ declare const serverHooks: {
|
|
|
114
111
|
reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
|
|
115
112
|
};
|
|
116
113
|
/** All hooks of server plugin. */
|
|
117
|
-
|
|
118
114
|
export declare type ServerHooks = typeof serverHooks;
|
|
119
115
|
/** All hook callbacks of server plugin. */
|
|
120
|
-
|
|
121
116
|
export declare type ServerHookCallbacks = ToThreads<ServerHooks>;
|
|
122
117
|
/** All apis for server plugin. */
|
|
123
|
-
|
|
124
118
|
export declare type PluginAPI = typeof pluginAPI & CommonAPI<ServerHooks>;
|
|
125
119
|
export declare const createServerManager: () => import("@modern-js/plugin").AsyncManager<{
|
|
126
120
|
gather: import("@modern-js/plugin").ParallelWorkflow<{
|
|
@@ -237,7 +231,6 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
|
|
|
237
231
|
setAppContext: (value: ISAppContext) => void;
|
|
238
232
|
}>;
|
|
239
233
|
/** Plugin options of a server plugin. */
|
|
240
|
-
|
|
241
234
|
export declare type ServerPlugin = PluginOptions<ServerHooks, AsyncSetup<ServerHooks, PluginAPI>>;
|
|
242
235
|
export declare type ServerConfig = {
|
|
243
236
|
bff?: Partial<{
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.1",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@modern-js/plugin": "2.0.0-beta.
|
|
33
|
-
"@modern-js/utils": "2.0.0-beta.
|
|
32
|
+
"@modern-js/plugin": "2.0.0-beta.1",
|
|
33
|
+
"@modern-js/utils": "2.0.0-beta.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@modern-js/core": "2.0.0-beta.0",
|
|
37
|
-
"@modern-js/types": "2.0.0-beta.0",
|
|
38
|
-
"@scripts/build": "2.0.0-beta.0",
|
|
39
|
-
"@scripts/jest-config": "2.0.0-beta.0",
|
|
40
36
|
"@types/jest": "^27",
|
|
41
37
|
"@types/node": "^14",
|
|
42
38
|
"http-proxy-middleware": "^2.0.4",
|
|
43
39
|
"jest": "^27",
|
|
44
40
|
"ts-jest": "^27.0.4",
|
|
45
|
-
"typescript": "^4"
|
|
41
|
+
"typescript": "^4",
|
|
42
|
+
"@modern-js/core": "2.0.0-beta.1",
|
|
43
|
+
"@modern-js/types": "2.0.0-beta.1",
|
|
44
|
+
"@scripts/build": "2.0.0-beta.1",
|
|
45
|
+
"@scripts/jest-config": "2.0.0-beta.1"
|
|
46
46
|
},
|
|
47
47
|
"sideEffects": false,
|
|
48
48
|
"modernConfig": {
|