@modern-js/plugin-v2 2.65.2-alpha.1 → 2.65.3
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/dist/cjs/hooks.js +0 -29
- package/dist/cjs/index.js +0 -2
- package/dist/esm/hooks.js +0 -129
- package/dist/esm/index.js +1 -2
- package/dist/esm-node/hooks.js +0 -28
- package/dist/esm-node/index.js +1 -2
- package/dist/types/hooks.d.ts +1 -2
- package/dist/types/index.d.ts +2 -3
- package/dist/types/types/hooks.d.ts +1 -5
- package/package.json +10 -21
- package/dist/cjs/server/api.js +0 -94
- package/dist/cjs/server/context.js +0 -64
- package/dist/cjs/server/hooks.js +0 -35
- package/dist/cjs/server/index.js +0 -41
- package/dist/cjs/server/run/create.js +0 -75
- package/dist/cjs/server/run/index.js +0 -31
- package/dist/cjs/server/run/types.js +0 -16
- package/dist/cjs/types/server/api.js +0 -16
- package/dist/cjs/types/server/context.js +0 -16
- package/dist/cjs/types/server/hooks.js +0 -16
- package/dist/cjs/types/server/index.js +0 -16
- package/dist/cjs/types/server/plugin.js +0 -16
- package/dist/esm/server/api.js +0 -76
- package/dist/esm/server/context.js +0 -38
- package/dist/esm/server/hooks.js +0 -11
- package/dist/esm/server/index.js +0 -12
- package/dist/esm/server/run/create.js +0 -95
- package/dist/esm/server/run/index.js +0 -6
- package/dist/esm/server/run/types.js +0 -0
- package/dist/esm/types/server/api.js +0 -0
- package/dist/esm/types/server/context.js +0 -0
- package/dist/esm/types/server/hooks.js +0 -0
- package/dist/esm/types/server/index.js +0 -0
- package/dist/esm/types/server/plugin.js +0 -0
- package/dist/esm-node/server/api.js +0 -69
- package/dist/esm-node/server/context.js +0 -39
- package/dist/esm-node/server/hooks.js +0 -11
- package/dist/esm-node/server/index.js +0 -12
- package/dist/esm-node/server/run/create.js +0 -51
- package/dist/esm-node/server/run/index.js +0 -6
- package/dist/esm-node/server/run/types.js +0 -0
- package/dist/esm-node/types/server/api.js +0 -0
- package/dist/esm-node/types/server/context.js +0 -0
- package/dist/esm-node/types/server/hooks.js +0 -0
- package/dist/esm-node/types/server/index.js +0 -0
- package/dist/esm-node/types/server/plugin.js +0 -0
- package/dist/types/server/api.d.ts +0 -9
- package/dist/types/server/context.d.ts +0 -13
- package/dist/types/server/hooks.d.ts +0 -9
- package/dist/types/server/index.d.ts +0 -4
- package/dist/types/server/run/create.d.ts +0 -7
- package/dist/types/server/run/index.d.ts +0 -8
- package/dist/types/server/run/types.d.ts +0 -21
- package/dist/types/types/server/api.d.ts +0 -16
- package/dist/types/types/server/context.d.ts +0 -28
- package/dist/types/types/server/hooks.d.ts +0 -24
- package/dist/types/types/server/index.d.ts +0 -4
- package/dist/types/types/server/plugin.d.ts +0 -14
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var create_exports = {};
|
|
20
|
-
__export(create_exports, {
|
|
21
|
-
createServer: () => createServer
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(create_exports);
|
|
24
|
-
var import_manager = require("../../manager");
|
|
25
|
-
var import_api = require("../../server/api");
|
|
26
|
-
var import_context = require("../../server/context");
|
|
27
|
-
const createServer = () => {
|
|
28
|
-
let initOptions;
|
|
29
|
-
const pluginManager = (0, import_manager.createPluginManager)();
|
|
30
|
-
function init(options) {
|
|
31
|
-
pluginManager.clear();
|
|
32
|
-
initOptions = options;
|
|
33
|
-
const { plugins: allPlugins, options: runOptions, handleSetupResult } = initOptions;
|
|
34
|
-
pluginManager.addPlugins(allPlugins);
|
|
35
|
-
const plugins = pluginManager.getPlugins();
|
|
36
|
-
const context = (0, import_context.createServerContext)({
|
|
37
|
-
serverContext: (0, import_context.initServerContext)({
|
|
38
|
-
plugins,
|
|
39
|
-
options: runOptions
|
|
40
|
-
}),
|
|
41
|
-
config: initOptions.config
|
|
42
|
-
});
|
|
43
|
-
const pluginAPI = (0, import_api.initPluginAPI)({
|
|
44
|
-
context,
|
|
45
|
-
pluginManager
|
|
46
|
-
});
|
|
47
|
-
context.pluginAPI = pluginAPI;
|
|
48
|
-
for (const plugin of plugins) {
|
|
49
|
-
var _plugin_setup;
|
|
50
|
-
const setupResult = (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI);
|
|
51
|
-
if (handleSetupResult) {
|
|
52
|
-
handleSetupResult(setupResult, pluginAPI);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
serverContext: context
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
async function run(options) {
|
|
60
|
-
const { serverContext } = init(options);
|
|
61
|
-
const config = await serverContext.hooks.modifyConfig.call(serverContext.config);
|
|
62
|
-
serverContext.config = config;
|
|
63
|
-
await serverContext.hooks.onPrepare.call();
|
|
64
|
-
return {
|
|
65
|
-
serverContext
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
run
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
createServer
|
|
75
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var run_exports = {};
|
|
20
|
-
__export(run_exports, {
|
|
21
|
-
createServer: () => import_create.createServer,
|
|
22
|
-
server: () => server
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(run_exports);
|
|
25
|
-
var import_create = require("./create");
|
|
26
|
-
const server = (0, import_create.createServer)();
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
createServer,
|
|
30
|
-
server
|
|
31
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var types_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(types_exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var api_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(api_exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var context_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(context_exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var hooks_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(hooks_exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var server_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(server_exports);
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var plugin_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(plugin_exports);
|
package/dist/esm/server/api.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
-
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
3
|
-
import { createDebugger } from "@modern-js/utils";
|
|
4
|
-
import { assign } from "@modern-js/utils/lodash";
|
|
5
|
-
var debug = createDebugger("plugin-server-v2");
|
|
6
|
-
function initPluginAPI(param) {
|
|
7
|
-
var context = param.context, pluginManager = param.pluginManager;
|
|
8
|
-
var hooks = context.hooks, extendsHooks = context.extendsHooks, plugins = context.plugins;
|
|
9
|
-
function getServerContext() {
|
|
10
|
-
if (context) {
|
|
11
|
-
var hooks2 = context.hooks, extendsHooks2 = context.extendsHooks, config = context.config, pluginAPI2 = context.pluginAPI, serverContext = _object_without_properties(context, [
|
|
12
|
-
"hooks",
|
|
13
|
-
"extendsHooks",
|
|
14
|
-
"config",
|
|
15
|
-
"pluginAPI"
|
|
16
|
-
]);
|
|
17
|
-
serverContext._internalContext = context;
|
|
18
|
-
return serverContext;
|
|
19
|
-
}
|
|
20
|
-
throw new Error("Cannot access context");
|
|
21
|
-
}
|
|
22
|
-
function getConfig() {
|
|
23
|
-
if (context.config) {
|
|
24
|
-
return context.config;
|
|
25
|
-
}
|
|
26
|
-
throw new Error("Cannot access config");
|
|
27
|
-
}
|
|
28
|
-
function getHooks() {
|
|
29
|
-
return context.hooks;
|
|
30
|
-
}
|
|
31
|
-
var extendsPluginApi = {};
|
|
32
|
-
plugins.forEach(function(plugin) {
|
|
33
|
-
var _registryApi = plugin._registryApi;
|
|
34
|
-
if (_registryApi) {
|
|
35
|
-
var apis = _registryApi(getServerContext, updateServerContext);
|
|
36
|
-
Object.keys(apis).forEach(function(apiName) {
|
|
37
|
-
extendsPluginApi[apiName] = apis[apiName];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (extendsHooks) {
|
|
42
|
-
Object.keys(extendsHooks).forEach(function(hookName) {
|
|
43
|
-
extendsPluginApi[hookName] = extendsHooks[hookName].tap;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function updateServerContext(updateContext) {
|
|
47
|
-
context = assign(context, updateContext);
|
|
48
|
-
}
|
|
49
|
-
var pluginAPI = _object_spread({
|
|
50
|
-
isPluginExists: pluginManager.isPluginExists,
|
|
51
|
-
getServerContext,
|
|
52
|
-
getConfig,
|
|
53
|
-
getHooks,
|
|
54
|
-
updateServerContext,
|
|
55
|
-
modifyConfig: hooks.modifyConfig.tap,
|
|
56
|
-
onPrepare: hooks.onPrepare.tap,
|
|
57
|
-
onReset: hooks.onReset.tap
|
|
58
|
-
}, extendsPluginApi);
|
|
59
|
-
return new Proxy(pluginAPI, {
|
|
60
|
-
get: function get(target, prop) {
|
|
61
|
-
if (prop === "then") {
|
|
62
|
-
return void 0;
|
|
63
|
-
}
|
|
64
|
-
if (prop in target) {
|
|
65
|
-
return target[prop];
|
|
66
|
-
}
|
|
67
|
-
return function() {
|
|
68
|
-
debug("api.".concat(prop.toString(), " not exist"));
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
debug,
|
|
75
|
-
initPluginAPI
|
|
76
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
|
-
import { initHooks } from "./hooks";
|
|
4
|
-
function initServerContext(params) {
|
|
5
|
-
var options = params.options, plugins = params.plugins;
|
|
6
|
-
return {
|
|
7
|
-
routes: options.routes || [],
|
|
8
|
-
appDirectory: options.appContext.appDirectory || "",
|
|
9
|
-
apiDirectory: options.appContext.apiDirectory,
|
|
10
|
-
lambdaDirectory: options.appContext.lambdaDirectory,
|
|
11
|
-
internalDirectory: options.appContext.internalDirectory || "",
|
|
12
|
-
sharedDirectory: options.appContext.sharedDirectory || "",
|
|
13
|
-
distDirectory: options.pwd,
|
|
14
|
-
metaName: options.metaName || "modern-js",
|
|
15
|
-
plugins,
|
|
16
|
-
middlewares: []
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function createServerContext(param) {
|
|
20
|
-
var serverContext = param.serverContext, config = param.config;
|
|
21
|
-
var plugins = serverContext.plugins;
|
|
22
|
-
var extendsHooks = {};
|
|
23
|
-
plugins.forEach(function(plugin) {
|
|
24
|
-
var _plugin_registryHooks = plugin.registryHooks, registryHooks = _plugin_registryHooks === void 0 ? {} : _plugin_registryHooks;
|
|
25
|
-
Object.keys(registryHooks).forEach(function(hookName) {
|
|
26
|
-
extendsHooks[hookName] = registryHooks[hookName];
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
return _object_spread_props(_object_spread({}, serverContext), {
|
|
30
|
-
hooks: _object_spread({}, initHooks(), extendsHooks),
|
|
31
|
-
extendsHooks,
|
|
32
|
-
config
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
createServerContext,
|
|
37
|
-
initServerContext
|
|
38
|
-
};
|
package/dist/esm/server/hooks.js
DELETED
package/dist/esm/server/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { initPluginAPI } from "./api";
|
|
2
|
-
import { initServerContext, createServerContext } from "./context";
|
|
3
|
-
import { initHooks } from "./hooks";
|
|
4
|
-
import { server, createServer } from "./run";
|
|
5
|
-
export {
|
|
6
|
-
createServer,
|
|
7
|
-
createServerContext,
|
|
8
|
-
initHooks,
|
|
9
|
-
initPluginAPI,
|
|
10
|
-
initServerContext,
|
|
11
|
-
server
|
|
12
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { createPluginManager } from "../../manager";
|
|
4
|
-
import { initPluginAPI } from "../../server/api";
|
|
5
|
-
import { createServerContext, initServerContext } from "../../server/context";
|
|
6
|
-
var createServer = function() {
|
|
7
|
-
var init = function init2(options) {
|
|
8
|
-
pluginManager.clear();
|
|
9
|
-
initOptions = options;
|
|
10
|
-
var allPlugins = initOptions.plugins, runOptions = initOptions.options, handleSetupResult = initOptions.handleSetupResult;
|
|
11
|
-
pluginManager.addPlugins(allPlugins);
|
|
12
|
-
var plugins = pluginManager.getPlugins();
|
|
13
|
-
var context = createServerContext({
|
|
14
|
-
serverContext: initServerContext({
|
|
15
|
-
plugins,
|
|
16
|
-
options: runOptions
|
|
17
|
-
}),
|
|
18
|
-
config: initOptions.config
|
|
19
|
-
});
|
|
20
|
-
var pluginAPI = initPluginAPI({
|
|
21
|
-
context,
|
|
22
|
-
pluginManager
|
|
23
|
-
});
|
|
24
|
-
context.pluginAPI = pluginAPI;
|
|
25
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
26
|
-
try {
|
|
27
|
-
for (var _iterator = plugins[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
28
|
-
var plugin = _step.value;
|
|
29
|
-
var _plugin_setup;
|
|
30
|
-
var setupResult = (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI);
|
|
31
|
-
if (handleSetupResult) {
|
|
32
|
-
handleSetupResult(setupResult, pluginAPI);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} catch (err) {
|
|
36
|
-
_didIteratorError = true;
|
|
37
|
-
_iteratorError = err;
|
|
38
|
-
} finally {
|
|
39
|
-
try {
|
|
40
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
41
|
-
_iterator.return();
|
|
42
|
-
}
|
|
43
|
-
} finally {
|
|
44
|
-
if (_didIteratorError) {
|
|
45
|
-
throw _iteratorError;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
serverContext: context
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
var run = function run2(options) {
|
|
54
|
-
return _run.apply(this, arguments);
|
|
55
|
-
};
|
|
56
|
-
var initOptions;
|
|
57
|
-
var pluginManager = createPluginManager();
|
|
58
|
-
function _run() {
|
|
59
|
-
_run = _async_to_generator(function(options) {
|
|
60
|
-
var serverContext, config;
|
|
61
|
-
return _ts_generator(this, function(_state) {
|
|
62
|
-
switch (_state.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
serverContext = init(options).serverContext;
|
|
65
|
-
return [
|
|
66
|
-
4,
|
|
67
|
-
serverContext.hooks.modifyConfig.call(serverContext.config)
|
|
68
|
-
];
|
|
69
|
-
case 1:
|
|
70
|
-
config = _state.sent();
|
|
71
|
-
serverContext.config = config;
|
|
72
|
-
return [
|
|
73
|
-
4,
|
|
74
|
-
serverContext.hooks.onPrepare.call()
|
|
75
|
-
];
|
|
76
|
-
case 2:
|
|
77
|
-
_state.sent();
|
|
78
|
-
return [
|
|
79
|
-
2,
|
|
80
|
-
{
|
|
81
|
-
serverContext
|
|
82
|
-
}
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
return _run.apply(this, arguments);
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
run
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
export {
|
|
94
|
-
createServer
|
|
95
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { createDebugger } from "@modern-js/utils";
|
|
2
|
-
import { assign } from "@modern-js/utils/lodash";
|
|
3
|
-
const debug = createDebugger("plugin-server-v2");
|
|
4
|
-
function initPluginAPI({ context, pluginManager }) {
|
|
5
|
-
const { hooks, extendsHooks, plugins } = context;
|
|
6
|
-
function getServerContext() {
|
|
7
|
-
if (context) {
|
|
8
|
-
const { hooks: hooks2, extendsHooks: extendsHooks2, config, pluginAPI: pluginAPI2, ...serverContext } = context;
|
|
9
|
-
serverContext._internalContext = context;
|
|
10
|
-
return serverContext;
|
|
11
|
-
}
|
|
12
|
-
throw new Error("Cannot access context");
|
|
13
|
-
}
|
|
14
|
-
function getConfig() {
|
|
15
|
-
if (context.config) {
|
|
16
|
-
return context.config;
|
|
17
|
-
}
|
|
18
|
-
throw new Error("Cannot access config");
|
|
19
|
-
}
|
|
20
|
-
function getHooks() {
|
|
21
|
-
return context.hooks;
|
|
22
|
-
}
|
|
23
|
-
const extendsPluginApi = {};
|
|
24
|
-
plugins.forEach((plugin) => {
|
|
25
|
-
const { _registryApi } = plugin;
|
|
26
|
-
if (_registryApi) {
|
|
27
|
-
const apis = _registryApi(getServerContext, updateServerContext);
|
|
28
|
-
Object.keys(apis).forEach((apiName) => {
|
|
29
|
-
extendsPluginApi[apiName] = apis[apiName];
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
if (extendsHooks) {
|
|
34
|
-
Object.keys(extendsHooks).forEach((hookName) => {
|
|
35
|
-
extendsPluginApi[hookName] = extendsHooks[hookName].tap;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function updateServerContext(updateContext) {
|
|
39
|
-
context = assign(context, updateContext);
|
|
40
|
-
}
|
|
41
|
-
const pluginAPI = {
|
|
42
|
-
isPluginExists: pluginManager.isPluginExists,
|
|
43
|
-
getServerContext,
|
|
44
|
-
getConfig,
|
|
45
|
-
getHooks,
|
|
46
|
-
updateServerContext,
|
|
47
|
-
modifyConfig: hooks.modifyConfig.tap,
|
|
48
|
-
onPrepare: hooks.onPrepare.tap,
|
|
49
|
-
onReset: hooks.onReset.tap,
|
|
50
|
-
...extendsPluginApi
|
|
51
|
-
};
|
|
52
|
-
return new Proxy(pluginAPI, {
|
|
53
|
-
get(target, prop) {
|
|
54
|
-
if (prop === "then") {
|
|
55
|
-
return void 0;
|
|
56
|
-
}
|
|
57
|
-
if (prop in target) {
|
|
58
|
-
return target[prop];
|
|
59
|
-
}
|
|
60
|
-
return () => {
|
|
61
|
-
debug(`api.${prop.toString()} not exist`);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export {
|
|
67
|
-
debug,
|
|
68
|
-
initPluginAPI
|
|
69
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { initHooks } from "./hooks";
|
|
2
|
-
function initServerContext(params) {
|
|
3
|
-
const { options, plugins } = params;
|
|
4
|
-
return {
|
|
5
|
-
routes: options.routes || [],
|
|
6
|
-
appDirectory: options.appContext.appDirectory || "",
|
|
7
|
-
apiDirectory: options.appContext.apiDirectory,
|
|
8
|
-
lambdaDirectory: options.appContext.lambdaDirectory,
|
|
9
|
-
internalDirectory: options.appContext.internalDirectory || "",
|
|
10
|
-
sharedDirectory: options.appContext.sharedDirectory || "",
|
|
11
|
-
distDirectory: options.pwd,
|
|
12
|
-
metaName: options.metaName || "modern-js",
|
|
13
|
-
plugins,
|
|
14
|
-
middlewares: []
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function createServerContext({ serverContext, config }) {
|
|
18
|
-
const { plugins } = serverContext;
|
|
19
|
-
const extendsHooks = {};
|
|
20
|
-
plugins.forEach((plugin) => {
|
|
21
|
-
const { registryHooks = {} } = plugin;
|
|
22
|
-
Object.keys(registryHooks).forEach((hookName) => {
|
|
23
|
-
extendsHooks[hookName] = registryHooks[hookName];
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
return {
|
|
27
|
-
...serverContext,
|
|
28
|
-
hooks: {
|
|
29
|
-
...initHooks(),
|
|
30
|
-
...extendsHooks
|
|
31
|
-
},
|
|
32
|
-
extendsHooks,
|
|
33
|
-
config
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
createServerContext,
|
|
38
|
-
initServerContext
|
|
39
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { initPluginAPI } from "./api";
|
|
2
|
-
import { initServerContext, createServerContext } from "./context";
|
|
3
|
-
import { initHooks } from "./hooks";
|
|
4
|
-
import { server, createServer } from "./run";
|
|
5
|
-
export {
|
|
6
|
-
createServer,
|
|
7
|
-
createServerContext,
|
|
8
|
-
initHooks,
|
|
9
|
-
initPluginAPI,
|
|
10
|
-
initServerContext,
|
|
11
|
-
server
|
|
12
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { createPluginManager } from "../../manager";
|
|
2
|
-
import { initPluginAPI } from "../../server/api";
|
|
3
|
-
import { createServerContext, initServerContext } from "../../server/context";
|
|
4
|
-
const createServer = () => {
|
|
5
|
-
let initOptions;
|
|
6
|
-
const pluginManager = createPluginManager();
|
|
7
|
-
function init(options) {
|
|
8
|
-
pluginManager.clear();
|
|
9
|
-
initOptions = options;
|
|
10
|
-
const { plugins: allPlugins, options: runOptions, handleSetupResult } = initOptions;
|
|
11
|
-
pluginManager.addPlugins(allPlugins);
|
|
12
|
-
const plugins = pluginManager.getPlugins();
|
|
13
|
-
const context = createServerContext({
|
|
14
|
-
serverContext: initServerContext({
|
|
15
|
-
plugins,
|
|
16
|
-
options: runOptions
|
|
17
|
-
}),
|
|
18
|
-
config: initOptions.config
|
|
19
|
-
});
|
|
20
|
-
const pluginAPI = initPluginAPI({
|
|
21
|
-
context,
|
|
22
|
-
pluginManager
|
|
23
|
-
});
|
|
24
|
-
context.pluginAPI = pluginAPI;
|
|
25
|
-
for (const plugin of plugins) {
|
|
26
|
-
var _plugin_setup;
|
|
27
|
-
const setupResult = (_plugin_setup = plugin.setup) === null || _plugin_setup === void 0 ? void 0 : _plugin_setup.call(plugin, pluginAPI);
|
|
28
|
-
if (handleSetupResult) {
|
|
29
|
-
handleSetupResult(setupResult, pluginAPI);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
serverContext: context
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async function run(options) {
|
|
37
|
-
const { serverContext } = init(options);
|
|
38
|
-
const config = await serverContext.hooks.modifyConfig.call(serverContext.config);
|
|
39
|
-
serverContext.config = config;
|
|
40
|
-
await serverContext.hooks.onPrepare.call();
|
|
41
|
-
return {
|
|
42
|
-
serverContext
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
run
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
export {
|
|
50
|
-
createServer
|
|
51
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|