@modern-js/server-core 1.2.2 → 1.2.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/.eslintrc.js ADDED
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ extends: ['@modern-js'],
3
+ parserOptions: {
4
+ project: require.resolve('./tsconfig.json'),
5
+ },
6
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @modern-js/server-plugin
2
2
 
3
+ ## 1.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - d95f28c3: should enable babel register before server plugin require
8
+ - 2e8dec93: feat: adust `ServerPlugin` type to define new plugin
9
+ - 2008fdbd: convert two packages server part, support server load plugin itself
10
+ - 2e8dec93: add `useAppContext`、`useConfigContext` to plugin api
11
+ - Updated dependencies [5bf5868d]
12
+ - Updated dependencies [80d8ddfe]
13
+ - Updated dependencies [491145e3]
14
+ - @modern-js/utils@1.3.5
15
+ - @modern-js/plugin@1.3.0
16
+
3
17
  ## 1.2.2
4
18
 
5
19
  ### Patch Changes
@@ -1,2 +1,3 @@
1
1
  export * from "./plugin";
2
- export * from '@modern-js/plugin';
2
+ export * from '@modern-js/plugin';
3
+ export * from "./loadPlugins";
@@ -0,0 +1,67 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ import { compatRequire } from '@modern-js/utils';
8
+ import { createPlugin } from "./plugin";
9
+
10
+ const tryResolve = (name, appDirectory) => {
11
+ let filePath = '';
12
+
13
+ try {
14
+ filePath = require.resolve(name, {
15
+ paths: [appDirectory]
16
+ });
17
+ delete require.cache[filePath];
18
+ } catch (err) {
19
+ if (err.code === 'MODULE_NOT_FOUND') {
20
+ throw new Error(`Can not find plugin ${name}.`);
21
+ }
22
+
23
+ throw err;
24
+ }
25
+
26
+ return filePath;
27
+ };
28
+
29
+ export const loadPlugins = (plugins, appDirectory) => {
30
+ const resolvePlugin = p => {
31
+ const isPluginInstance = typeof p !== 'string' && !Array.isArray(p);
32
+
33
+ if (isPluginInstance) {
34
+ return {
35
+ module: p
36
+ };
37
+ }
38
+
39
+ const [pkg, options] = typeof p === 'string' ? [p, undefined] : p;
40
+ const pluginPath = tryResolve(pkg, appDirectory);
41
+ let module = compatRequire(pluginPath);
42
+ const useNewSyntax = typeof module === 'function';
43
+
44
+ if (useNewSyntax) {
45
+ const plugin = module(options);
46
+ module = createPlugin(plugin.setup, plugin);
47
+ }
48
+
49
+ return {
50
+ pkg,
51
+ path: pluginPath,
52
+ module
53
+ };
54
+ };
55
+
56
+ return plugins.map(plugin => {
57
+ const {
58
+ pkg,
59
+ path,
60
+ module
61
+ } = resolvePlugin(plugin);
62
+ return _objectSpread(_objectSpread({}, module), {}, {
63
+ pluginPath: path,
64
+ pkg
65
+ });
66
+ });
67
+ };
@@ -1,4 +1,4 @@
1
- import { createAsyncManager, createAsyncPipeline, createParallelWorkflow, createAsyncWaterfall, createContext } from '@modern-js/plugin';
1
+ import { createContext, createAsyncManager, createAsyncPipeline, createAsyncWaterfall, createParallelWorkflow } from '@modern-js/plugin';
2
2
  import { enable } from '@modern-js/plugin/node';
3
3
  enable(); // collect all middleware register in server plugins
4
4
 
@@ -35,7 +35,23 @@ const afterRender = createAsyncPipeline();
35
35
  const beforeSend = createAsyncPipeline();
36
36
  const afterSend = createParallelWorkflow();
37
37
  const reset = createParallelWorkflow();
38
- export const createServerManager = () => createAsyncManager({
38
+ export const AppContext = createContext({});
39
+ export const ConfigContext = createContext({});
40
+ /**
41
+ * Get original content of user config.
42
+ */
43
+
44
+ export const useConfigContext = () => ConfigContext.use().value;
45
+ /**
46
+ * Get app context, including directories, plugins and some static infos.
47
+ */
48
+
49
+ export const useAppContext = () => AppContext.use().value;
50
+ const pluginAPI = {
51
+ useAppContext,
52
+ useConfigContext
53
+ };
54
+ const serverHooks = {
39
55
  // server hook
40
56
  gather,
41
57
  create,
@@ -64,12 +80,13 @@ export const createServerManager = () => createAsyncManager({
64
80
  beforeSend,
65
81
  afterSend,
66
82
  reset
67
- });
83
+ };
84
+ /** All hooks of server plugin. */
85
+
86
+ export const createServerManager = () => createAsyncManager(serverHooks, pluginAPI);
68
87
  export const serverManager = createServerManager();
88
+ /** Plugin options of a server plugin. */
89
+
69
90
  export const {
70
91
  createPlugin
71
- } = serverManager;
72
- export const AppContext = createContext({});
73
- export const ConfigContext = createContext({});
74
- export const useConfigContext = () => ConfigContext.use().value;
75
- export const useAppContext = () => AppContext.use().value;
92
+ } = serverManager;
@@ -28,4 +28,17 @@ Object.keys(_plugin2).forEach(function (key) {
28
28
  return _plugin2[key];
29
29
  }
30
30
  });
31
+ });
32
+
33
+ var _loadPlugins = require("./loadPlugins");
34
+
35
+ Object.keys(_loadPlugins).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _loadPlugins[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _loadPlugins[key];
42
+ }
43
+ });
31
44
  });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadPlugins = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ var _plugin = require("./plugin");
11
+
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+
16
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+
18
+ const tryResolve = (name, appDirectory) => {
19
+ let filePath = '';
20
+
21
+ try {
22
+ filePath = require.resolve(name, {
23
+ paths: [appDirectory]
24
+ });
25
+ delete require.cache[filePath];
26
+ } catch (err) {
27
+ if (err.code === 'MODULE_NOT_FOUND') {
28
+ throw new Error(`Can not find plugin ${name}.`);
29
+ }
30
+
31
+ throw err;
32
+ }
33
+
34
+ return filePath;
35
+ };
36
+
37
+ const loadPlugins = (plugins, appDirectory) => {
38
+ const resolvePlugin = p => {
39
+ const isPluginInstance = typeof p !== 'string' && !Array.isArray(p);
40
+
41
+ if (isPluginInstance) {
42
+ return {
43
+ module: p
44
+ };
45
+ }
46
+
47
+ const [pkg, options] = typeof p === 'string' ? [p, undefined] : p;
48
+ const pluginPath = tryResolve(pkg, appDirectory);
49
+ let module = (0, _utils.compatRequire)(pluginPath);
50
+ const useNewSyntax = typeof module === 'function';
51
+
52
+ if (useNewSyntax) {
53
+ const plugin = module(options);
54
+ module = (0, _plugin.createPlugin)(plugin.setup, plugin);
55
+ }
56
+
57
+ return {
58
+ pkg,
59
+ path: pluginPath,
60
+ module
61
+ };
62
+ };
63
+
64
+ return plugins.map(plugin => {
65
+ const {
66
+ pkg,
67
+ path,
68
+ module
69
+ } = resolvePlugin(plugin);
70
+ return _objectSpread(_objectSpread({}, module), {}, {
71
+ pluginPath: path,
72
+ pkg
73
+ });
74
+ });
75
+ };
76
+
77
+ exports.loadPlugins = loadPlugins;
@@ -44,8 +44,31 @@ const afterRender = (0, _plugin.createAsyncPipeline)();
44
44
  const beforeSend = (0, _plugin.createAsyncPipeline)();
45
45
  const afterSend = (0, _plugin.createParallelWorkflow)();
46
46
  const reset = (0, _plugin.createParallelWorkflow)();
47
+ const AppContext = (0, _plugin.createContext)({});
48
+ exports.AppContext = AppContext;
49
+ const ConfigContext = (0, _plugin.createContext)({});
50
+ /**
51
+ * Get original content of user config.
52
+ */
53
+
54
+ exports.ConfigContext = ConfigContext;
55
+
56
+ const useConfigContext = () => ConfigContext.use().value;
57
+ /**
58
+ * Get app context, including directories, plugins and some static infos.
59
+ */
47
60
 
48
- const createServerManager = () => (0, _plugin.createAsyncManager)({
61
+
62
+ exports.useConfigContext = useConfigContext;
63
+
64
+ const useAppContext = () => AppContext.use().value;
65
+
66
+ exports.useAppContext = useAppContext;
67
+ const pluginAPI = {
68
+ useAppContext,
69
+ useConfigContext
70
+ };
71
+ const serverHooks = {
49
72
  // server hook
50
73
  gather,
51
74
  create,
@@ -74,24 +97,17 @@ const createServerManager = () => (0, _plugin.createAsyncManager)({
74
97
  beforeSend,
75
98
  afterSend,
76
99
  reset
77
- });
100
+ };
101
+ /** All hooks of server plugin. */
102
+
103
+ const createServerManager = () => (0, _plugin.createAsyncManager)(serverHooks, pluginAPI);
78
104
 
79
105
  exports.createServerManager = createServerManager;
80
106
  const serverManager = createServerManager();
107
+ /** Plugin options of a server plugin. */
108
+
81
109
  exports.serverManager = serverManager;
82
110
  const {
83
111
  createPlugin
84
112
  } = serverManager;
85
- exports.createPlugin = createPlugin;
86
- const AppContext = (0, _plugin.createContext)({});
87
- exports.AppContext = AppContext;
88
- const ConfigContext = (0, _plugin.createContext)({});
89
- exports.ConfigContext = ConfigContext;
90
-
91
- const useConfigContext = () => ConfigContext.use().value;
92
-
93
- exports.useConfigContext = useConfigContext;
94
-
95
- const useAppContext = () => AppContext.use().value;
96
-
97
- exports.useAppContext = useAppContext;
113
+ exports.createPlugin = createPlugin;
@@ -1,2 +1,3 @@
1
1
  export * from './plugin';
2
- export * from '@modern-js/plugin';
2
+ export * from '@modern-js/plugin';
3
+ export * from './loadPlugins';
@@ -0,0 +1,4 @@
1
+ import { ServerPlugin } from './plugin';
2
+ declare type Plugin = string | [string, any] | ServerPlugin;
3
+ export declare const loadPlugins: (plugins: Plugin[], appDirectory: string) => any[];
4
+ export {};
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
3
  import type { Component } from 'react';
4
- import { PluginFromAsyncManager } from '@modern-js/plugin';
4
+ import { CommonAPI, ToThreads, AsyncSetup, PluginOptions } from '@modern-js/plugin';
5
5
  import type { ModernServerContext, BaseSSRServerContext, Metrics, Logger } from '@modern-js/types/server';
6
6
  import type { NormalizedConfig, UserConfig } from '@modern-js/core';
7
- import type { IAppContext } from '@modern-js/types';
7
+ import type { ISAppContext } from '@modern-js/types';
8
8
  declare type ServerInitInput = {
9
9
  loggerOptions: any;
10
10
  metricsOptions: any;
@@ -32,7 +32,85 @@ export declare type RequestResult = {
32
32
  };
33
33
  export declare type SSRServerContext = {};
34
34
  export declare type RenderContext = {};
35
- export declare const createServerManager: () => import("@modern-js/plugin").AsyncManager<{}, {
35
+ export declare const AppContext: import("@modern-js/plugin").Context<ISAppContext>;
36
+ export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
37
+ /**
38
+ * Get original content of user config.
39
+ */
40
+
41
+ export declare const useConfigContext: () => UserConfig;
42
+ /**
43
+ * Get app context, including directories, plugins and some static infos.
44
+ */
45
+
46
+ export declare const useAppContext: () => ISAppContext;
47
+ declare const pluginAPI: {
48
+ useAppContext: () => ISAppContext;
49
+ useConfigContext: () => UserConfig;
50
+ };
51
+ declare const serverHooks: {
52
+ gather: import("@modern-js/plugin").ParallelWorkflow<{
53
+ addWebMiddleware: (_input: any) => void;
54
+ addAPIMiddleware: (_input: any) => void;
55
+ }, unknown>;
56
+ create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
57
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
58
+ prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
59
+ preDevServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
60
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
61
+ postDevServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
62
+ beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
63
+ afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
64
+ preServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
65
+ postServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
66
+ listen: import("@modern-js/plugin").ParallelWorkflow<{
67
+ ip: string;
68
+ port: number;
69
+ }, any[]>;
70
+ beforeServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
71
+ afterServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
72
+ extendSSRContext: import("@modern-js/plugin").AsyncWaterfall<BaseSSRServerContext>;
73
+ extendContext: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, ModernServerContext>;
74
+ handleError: import("@modern-js/plugin").ParallelWorkflow<{
75
+ error: Error;
76
+ }, unknown>;
77
+ beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
78
+ context: ModernServerContext;
79
+ }, any>;
80
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<{
81
+ context: ModernServerContext;
82
+ routeAPI: any;
83
+ }, any>;
84
+ prefetch: import("@modern-js/plugin").ParallelWorkflow<{
85
+ context: SSRServerContext;
86
+ }, unknown>;
87
+ renderToString: import("@modern-js/plugin").AsyncPipeline<{
88
+ App: Component;
89
+ context: RenderContext;
90
+ }, string>;
91
+ beforeRender: import("@modern-js/plugin").AsyncPipeline<{
92
+ context: ModernServerContext;
93
+ }, any>;
94
+ afterRender: import("@modern-js/plugin").AsyncPipeline<{
95
+ context: ModernServerContext;
96
+ templateAPI: any;
97
+ }, any>;
98
+ beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
99
+ afterSend: import("@modern-js/plugin").ParallelWorkflow<{
100
+ context: ModernServerContext;
101
+ }, unknown>;
102
+ reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
103
+ };
104
+ /** All hooks of server plugin. */
105
+
106
+ export declare type ServerHooks = typeof serverHooks;
107
+ /** All hook callbacks of server plugin. */
108
+
109
+ export declare type ServerHookCallbacks = ToThreads<ServerHooks>;
110
+ /** All apis for server plugin. */
111
+
112
+ export declare type PluginAPI = typeof pluginAPI & CommonAPI<ServerHooks>;
113
+ export declare const createServerManager: () => import("@modern-js/plugin").AsyncManager<{
36
114
  gather: import("@modern-js/plugin").ParallelWorkflow<{
37
115
  addWebMiddleware: (_input: any) => void;
38
116
  addAPIMiddleware: (_input: any) => void;
@@ -84,8 +162,11 @@ export declare const createServerManager: () => import("@modern-js/plugin").Asyn
84
162
  context: ModernServerContext;
85
163
  }, unknown>;
86
164
  reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
165
+ }, {
166
+ useAppContext: () => ISAppContext;
167
+ useConfigContext: () => UserConfig;
87
168
  }>;
88
- export declare const serverManager: import("@modern-js/plugin").AsyncManager<{}, {
169
+ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
89
170
  gather: import("@modern-js/plugin").ParallelWorkflow<{
90
171
  addWebMiddleware: (_input: any) => void;
91
172
  addAPIMiddleware: (_input: any) => void;
@@ -137,9 +218,14 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{},
137
218
  context: ModernServerContext;
138
219
  }, unknown>;
139
220
  reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
221
+ }, {
222
+ useAppContext: () => ISAppContext;
223
+ useConfigContext: () => UserConfig;
140
224
  }>;
141
- export declare type ServerPlugin = PluginFromAsyncManager<typeof serverManager>;
142
- export declare const createPlugin: (initializer: import("@modern-js/plugin").AsyncInitializer<Partial<import("@modern-js/plugin").Progresses2Threads<{
225
+ /** Plugin options of a server plugin. */
226
+
227
+ export declare type ServerPlugin = PluginOptions<ServerHooks, AsyncSetup<ServerHooks, PluginAPI>>;
228
+ export declare const createPlugin: (setup?: AsyncSetup<{
143
229
  gather: import("@modern-js/plugin").ParallelWorkflow<{
144
230
  addWebMiddleware: (_input: any) => void;
145
231
  addAPIMiddleware: (_input: any) => void;
@@ -191,7 +277,10 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
191
277
  context: ModernServerContext;
192
278
  }, unknown>;
193
279
  reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
194
- } & import("@modern-js/plugin").ClearDraftProgress<{}>>>>, options?: import("@modern-js/plugin").PluginOptions | undefined) => import("@modern-js/plugin").AsyncPlugin<Partial<import("@modern-js/plugin").Progresses2Threads<{
280
+ }, {
281
+ useAppContext: () => ISAppContext;
282
+ useConfigContext: () => UserConfig;
283
+ }> | undefined, options?: PluginOptions<{
195
284
  gather: import("@modern-js/plugin").ParallelWorkflow<{
196
285
  addWebMiddleware: (_input: any) => void;
197
286
  addAPIMiddleware: (_input: any) => void;
@@ -243,9 +332,115 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
243
332
  context: ModernServerContext;
244
333
  }, unknown>;
245
334
  reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
246
- } & import("@modern-js/plugin").ClearDraftProgress<{}>>>>;
247
- export declare const AppContext: import("@modern-js/plugin").Context<IAppContext>;
248
- export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
249
- export declare const useConfigContext: () => UserConfig;
250
- export declare const useAppContext: () => IAppContext;
335
+ }, AsyncSetup<{
336
+ gather: import("@modern-js/plugin").ParallelWorkflow<{
337
+ addWebMiddleware: (_input: any) => void;
338
+ addAPIMiddleware: (_input: any) => void;
339
+ }, unknown>;
340
+ create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
341
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
342
+ prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
343
+ preDevServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
344
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
345
+ postDevServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
346
+ beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
347
+ afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
348
+ preServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
349
+ postServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
350
+ listen: import("@modern-js/plugin").ParallelWorkflow<{
351
+ ip: string;
352
+ port: number;
353
+ }, any[]>;
354
+ beforeServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
355
+ afterServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
356
+ extendSSRContext: import("@modern-js/plugin").AsyncWaterfall<BaseSSRServerContext>;
357
+ extendContext: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, ModernServerContext>;
358
+ handleError: import("@modern-js/plugin").ParallelWorkflow<{
359
+ error: Error;
360
+ }, unknown>;
361
+ beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
362
+ context: ModernServerContext;
363
+ }, any>;
364
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<{
365
+ context: ModernServerContext;
366
+ routeAPI: any;
367
+ }, any>;
368
+ prefetch: import("@modern-js/plugin").ParallelWorkflow<{
369
+ context: SSRServerContext;
370
+ }, unknown>;
371
+ renderToString: import("@modern-js/plugin").AsyncPipeline<{
372
+ App: Component;
373
+ context: RenderContext;
374
+ }, string>;
375
+ beforeRender: import("@modern-js/plugin").AsyncPipeline<{
376
+ context: ModernServerContext;
377
+ }, any>;
378
+ afterRender: import("@modern-js/plugin").AsyncPipeline<{
379
+ context: ModernServerContext;
380
+ templateAPI: any;
381
+ }, any>;
382
+ beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
383
+ afterSend: import("@modern-js/plugin").ParallelWorkflow<{
384
+ context: ModernServerContext;
385
+ }, unknown>;
386
+ reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
387
+ }, {
388
+ useAppContext: () => ISAppContext;
389
+ useConfigContext: () => UserConfig;
390
+ }>> | undefined) => import("@modern-js/plugin").AsyncPlugin<{
391
+ gather: import("@modern-js/plugin").ParallelWorkflow<{
392
+ addWebMiddleware: (_input: any) => void;
393
+ addAPIMiddleware: (_input: any) => void;
394
+ }, unknown>;
395
+ create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
396
+ prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
397
+ prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
398
+ preDevServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
399
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
400
+ postDevServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
401
+ beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
402
+ afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
403
+ preServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
404
+ postServerInit: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
405
+ listen: import("@modern-js/plugin").ParallelWorkflow<{
406
+ ip: string;
407
+ port: number;
408
+ }, any[]>;
409
+ beforeServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
410
+ afterServerReset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
411
+ extendSSRContext: import("@modern-js/plugin").AsyncWaterfall<BaseSSRServerContext>;
412
+ extendContext: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, ModernServerContext>;
413
+ handleError: import("@modern-js/plugin").ParallelWorkflow<{
414
+ error: Error;
415
+ }, unknown>;
416
+ beforeMatch: import("@modern-js/plugin").AsyncPipeline<{
417
+ context: ModernServerContext;
418
+ }, any>;
419
+ afterMatch: import("@modern-js/plugin").AsyncPipeline<{
420
+ context: ModernServerContext;
421
+ routeAPI: any;
422
+ }, any>;
423
+ prefetch: import("@modern-js/plugin").ParallelWorkflow<{
424
+ context: SSRServerContext;
425
+ }, unknown>;
426
+ renderToString: import("@modern-js/plugin").AsyncPipeline<{
427
+ App: Component;
428
+ context: RenderContext;
429
+ }, string>;
430
+ beforeRender: import("@modern-js/plugin").AsyncPipeline<{
431
+ context: ModernServerContext;
432
+ }, any>;
433
+ afterRender: import("@modern-js/plugin").AsyncPipeline<{
434
+ context: ModernServerContext;
435
+ templateAPI: any;
436
+ }, any>;
437
+ beforeSend: import("@modern-js/plugin").AsyncPipeline<ModernServerContext, RequestResult>;
438
+ afterSend: import("@modern-js/plugin").ParallelWorkflow<{
439
+ context: ModernServerContext;
440
+ }, unknown>;
441
+ reset: import("@modern-js/plugin").ParallelWorkflow<void, unknown>;
442
+ }, {
443
+ useAppContext: () => ISAppContext;
444
+ useConfigContext: () => UserConfig;
445
+ }>;
251
446
  export {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.2",
14
+ "version": "1.2.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,11 +28,12 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/plugin": "^1.2.1"
31
+ "@modern-js/plugin": "^1.3.0",
32
+ "@modern-js/utils": "^1.3.5"
32
33
  },
33
34
  "devDependencies": {
34
- "@modern-js/core": "^1.4.0",
35
- "@modern-js/types": "^1.3.0",
35
+ "@modern-js/core": "^1.5.0",
36
+ "@modern-js/types": "^1.3.5",
36
37
  "@types/jest": "^26",
37
38
  "@types/node": "^14",
38
39
  "@types/react": "^17",
@@ -51,8 +52,7 @@
51
52
  },
52
53
  "publishConfig": {
53
54
  "registry": "https://registry.npmjs.org/",
54
- "access": "public",
55
- "types": "./dist/types/index.d.ts"
55
+ "access": "public"
56
56
  },
57
57
  "scripts": {
58
58
  "new": "modern new",
@@ -0,0 +1,3 @@
1
+ module.exports = () => ({
2
+ name: 'test-a',
3
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "test-a"
3
+ }
@@ -0,0 +1,33 @@
1
+ import path from 'path';
2
+ import { loadPlugins } from '../src/loadPlugins';
3
+
4
+ const modulePath = path.join(__dirname, './fixtures/load-plugins');
5
+ describe('test load plugin', () => {
6
+ it('should load string plugin correctly', () => {
7
+ const loaded = loadPlugins(['test-a'], modulePath);
8
+ expect(loaded[0].pluginPath).toBe(
9
+ path.join(__dirname, './fixtures/load-plugins/test-a/index.js'),
10
+ );
11
+ });
12
+
13
+ it('should load plugin instance correctly', () => {
14
+ const loaded = loadPlugins(
15
+ [
16
+ {
17
+ name: 'modern',
18
+ },
19
+ ],
20
+ modulePath,
21
+ );
22
+
23
+ expect(loaded[0].name).toBe('modern');
24
+ });
25
+
26
+ it('should throw error if plugin not found', () => {
27
+ try {
28
+ loadPlugins(['test-b'], modulePath);
29
+ } catch (e: any) {
30
+ expect(e.message).toMatch('Can not find plugin test-b.');
31
+ }
32
+ });
33
+ });