@modern-js/server-core 1.2.4 → 1.3.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # @modern-js/server-plugin
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d2d1d6b2: feat: support server config
8
+
9
+ ### Patch Changes
10
+
11
+ - d2d1d6b2: feat: add prepare hook
12
+ - Updated dependencies [77ff9754]
13
+ - Updated dependencies [d2d1d6b2]
14
+ - Updated dependencies [07a4887e]
15
+ - Updated dependencies [ea2ae711]
16
+ - Updated dependencies [17d0cc46]
17
+ - Updated dependencies [d2d1d6b2]
18
+ - @modern-js/utils@1.4.0
19
+
20
+ ## 1.2.5
21
+
22
+ ### Patch Changes
23
+
24
+ - bebb39b6: chore: improve devDependencies and peerDependencies
25
+ - Updated dependencies [132f7b53]
26
+ - @modern-js/utils@1.3.7
27
+
3
28
  ## 1.2.4
4
29
 
5
30
  ### Patch Changes
@@ -1,16 +1,17 @@
1
- import { createContext, createAsyncManager, createAsyncPipeline, createAsyncWaterfall, createParallelWorkflow } from '@modern-js/plugin';
1
+ import { createContext, createAsyncManager, createAsyncPipeline, createAsyncWaterfall, createParallelWorkflow, createWaterfall } 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
 
5
5
  const gather = createParallelWorkflow();
6
+ // config
7
+ const config = createWaterfall();
8
+ const prepare = createWaterfall();
6
9
  const create = createAsyncPipeline();
7
10
  const prepareWebServer = createAsyncPipeline();
8
11
  const prepareApiServer = createAsyncPipeline();
9
- const beforeDevServer = createParallelWorkflow(); // eslint-disable-next-line @typescript-eslint/ban-types
10
-
12
+ const beforeDevServer = createParallelWorkflow();
11
13
  const setupCompiler = createParallelWorkflow();
12
14
  const afterDevServer = createParallelWorkflow(); // TODO FIXME
13
- // eslint-disable-next-line @typescript-eslint/ban-types
14
15
 
15
16
  const beforeRouteSet = createAsyncPipeline();
16
17
  const afterRouteSet = createAsyncPipeline();
@@ -24,10 +25,8 @@ const extendContext = createAsyncPipeline();
24
25
  const handleError = createParallelWorkflow();
25
26
  const beforeMatch = createAsyncPipeline();
26
27
  const afterMatch = createAsyncPipeline(); // TODO FIXME
27
- // eslint-disable-next-line @typescript-eslint/ban-types
28
28
 
29
29
  const prefetch = createParallelWorkflow(); // TODO FIXME
30
- // eslint-disable-next-line @typescript-eslint/ban-types
31
30
 
32
31
  const renderToString = createAsyncPipeline();
33
32
  const beforeRender = createAsyncPipeline();
@@ -54,6 +53,8 @@ const pluginAPI = {
54
53
  const serverHooks = {
55
54
  // server hook
56
55
  gather,
56
+ config,
57
+ prepare,
57
58
  create,
58
59
  prepareWebServer,
59
60
  prepareApiServer,
@@ -12,14 +12,15 @@ var _node = require("@modern-js/plugin/node");
12
12
  (0, _node.enable)(); // collect all middleware register in server plugins
13
13
 
14
14
  const gather = (0, _plugin.createParallelWorkflow)();
15
+ // config
16
+ const config = (0, _plugin.createWaterfall)();
17
+ const prepare = (0, _plugin.createWaterfall)();
15
18
  const create = (0, _plugin.createAsyncPipeline)();
16
19
  const prepareWebServer = (0, _plugin.createAsyncPipeline)();
17
20
  const prepareApiServer = (0, _plugin.createAsyncPipeline)();
18
- const beforeDevServer = (0, _plugin.createParallelWorkflow)(); // eslint-disable-next-line @typescript-eslint/ban-types
19
-
21
+ const beforeDevServer = (0, _plugin.createParallelWorkflow)();
20
22
  const setupCompiler = (0, _plugin.createParallelWorkflow)();
21
23
  const afterDevServer = (0, _plugin.createParallelWorkflow)(); // TODO FIXME
22
- // eslint-disable-next-line @typescript-eslint/ban-types
23
24
 
24
25
  const beforeRouteSet = (0, _plugin.createAsyncPipeline)();
25
26
  const afterRouteSet = (0, _plugin.createAsyncPipeline)();
@@ -33,10 +34,8 @@ const extendContext = (0, _plugin.createAsyncPipeline)();
33
34
  const handleError = (0, _plugin.createParallelWorkflow)();
34
35
  const beforeMatch = (0, _plugin.createAsyncPipeline)();
35
36
  const afterMatch = (0, _plugin.createAsyncPipeline)(); // TODO FIXME
36
- // eslint-disable-next-line @typescript-eslint/ban-types
37
37
 
38
38
  const prefetch = (0, _plugin.createParallelWorkflow)(); // TODO FIXME
39
- // eslint-disable-next-line @typescript-eslint/ban-types
40
39
 
41
40
  const renderToString = (0, _plugin.createAsyncPipeline)();
42
41
  const beforeRender = (0, _plugin.createAsyncPipeline)();
@@ -71,6 +70,8 @@ const pluginAPI = {
71
70
  const serverHooks = {
72
71
  // server hook
73
72
  gather,
73
+ config,
74
+ prepare,
74
75
  create,
75
76
  prepareWebServer,
76
77
  prepareApiServer,
@@ -5,6 +5,7 @@ import { CommonAPI, ToThreads, AsyncSetup, PluginOptions } from '@modern-js/plug
5
5
  import type { ModernServerContext, BaseSSRServerContext, Metrics, Logger } from '@modern-js/types/server';
6
6
  import type { NormalizedConfig, UserConfig } from '@modern-js/core';
7
7
  import type { ISAppContext } from '@modern-js/types';
8
+ import type { Options } from 'http-proxy-middleware';
8
9
  declare type ServerInitInput = {
9
10
  loggerOptions: any;
10
11
  metricsOptions: any;
@@ -26,12 +27,12 @@ export declare type APIServerStartInput = {
26
27
  middleware?: Array<any>;
27
28
  };
28
29
  };
29
- export declare type Route = {};
30
+ export declare type Route = Record<string, unknown>;
30
31
  export declare type RequestResult = {
31
32
  isfinish: boolean;
32
33
  };
33
- export declare type SSRServerContext = {};
34
- export declare type RenderContext = {};
34
+ export declare type SSRServerContext = Record<string, unknown>;
35
+ export declare type RenderContext = Record<string, unknown>;
35
36
  export declare const AppContext: import("@modern-js/plugin").Context<ISAppContext>;
36
37
  export declare const ConfigContext: import("@modern-js/plugin").Context<UserConfig>;
37
38
  /**
@@ -53,11 +54,13 @@ declare const serverHooks: {
53
54
  addWebMiddleware: (_input: any) => void;
54
55
  addAPIMiddleware: (_input: any) => void;
55
56
  }, unknown>;
57
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
58
+ prepare: import("@modern-js/plugin").Waterfall<void>;
56
59
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
57
60
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
58
61
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
59
62
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
60
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
63
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
61
64
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
62
65
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
63
66
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
@@ -115,11 +118,13 @@ export declare const createServerManager: () => import("@modern-js/plugin").Asyn
115
118
  addWebMiddleware: (_input: any) => void;
116
119
  addAPIMiddleware: (_input: any) => void;
117
120
  }, unknown>;
121
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
122
+ prepare: import("@modern-js/plugin").Waterfall<void>;
118
123
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
119
124
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
120
125
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
121
126
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
122
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
127
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
123
128
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
124
129
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
125
130
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
@@ -171,11 +176,13 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
171
176
  addWebMiddleware: (_input: any) => void;
172
177
  addAPIMiddleware: (_input: any) => void;
173
178
  }, unknown>;
179
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
180
+ prepare: import("@modern-js/plugin").Waterfall<void>;
174
181
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
175
182
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
176
183
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
177
184
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
178
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
185
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
179
186
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
180
187
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
181
188
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
@@ -225,16 +232,24 @@ export declare const serverManager: import("@modern-js/plugin").AsyncManager<{
225
232
  /** Plugin options of a server plugin. */
226
233
 
227
234
  export declare type ServerPlugin = PluginOptions<ServerHooks, AsyncSetup<ServerHooks, PluginAPI>>;
235
+ export declare type ServerConfig = {
236
+ bff?: Partial<{
237
+ proxy: Record<string, Options>;
238
+ }>;
239
+ plugins?: ServerPlugin[];
240
+ };
228
241
  export declare const createPlugin: (setup?: AsyncSetup<{
229
242
  gather: import("@modern-js/plugin").ParallelWorkflow<{
230
243
  addWebMiddleware: (_input: any) => void;
231
244
  addAPIMiddleware: (_input: any) => void;
232
245
  }, unknown>;
246
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
247
+ prepare: import("@modern-js/plugin").Waterfall<void>;
233
248
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
234
249
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
235
250
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
236
251
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
237
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
252
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
238
253
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
239
254
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
240
255
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
@@ -285,11 +300,13 @@ export declare const createPlugin: (setup?: AsyncSetup<{
285
300
  addWebMiddleware: (_input: any) => void;
286
301
  addAPIMiddleware: (_input: any) => void;
287
302
  }, unknown>;
303
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
304
+ prepare: import("@modern-js/plugin").Waterfall<void>;
288
305
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
289
306
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
290
307
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
291
308
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
292
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
309
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
293
310
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
294
311
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
295
312
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
@@ -337,11 +354,13 @@ export declare const createPlugin: (setup?: AsyncSetup<{
337
354
  addWebMiddleware: (_input: any) => void;
338
355
  addAPIMiddleware: (_input: any) => void;
339
356
  }, unknown>;
357
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
358
+ prepare: import("@modern-js/plugin").Waterfall<void>;
340
359
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
341
360
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
342
361
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
343
362
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
344
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
363
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
345
364
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
346
365
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
347
366
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
@@ -392,11 +411,13 @@ export declare const createPlugin: (setup?: AsyncSetup<{
392
411
  addWebMiddleware: (_input: any) => void;
393
412
  addAPIMiddleware: (_input: any) => void;
394
413
  }, unknown>;
414
+ config: import("@modern-js/plugin").Waterfall<ServerConfig>;
415
+ prepare: import("@modern-js/plugin").Waterfall<void>;
395
416
  create: import("@modern-js/plugin").AsyncPipeline<ServerInitInput, InitExtension>;
396
417
  prepareWebServer: import("@modern-js/plugin").AsyncPipeline<WebServerStartInput, Adapter>;
397
418
  prepareApiServer: import("@modern-js/plugin").AsyncPipeline<APIServerStartInput, Adapter>;
398
419
  beforeDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
399
- setupCompiler: import("@modern-js/plugin").ParallelWorkflow<{}, any[]>;
420
+ setupCompiler: import("@modern-js/plugin").ParallelWorkflow<Record<string, unknown>, any[]>;
400
421
  afterDevServer: import("@modern-js/plugin").ParallelWorkflow<NormalizedConfig, any>;
401
422
  beforeRouteSet: import("@modern-js/plugin").AsyncPipeline<Route[], Route[]>;
402
423
  afterRouteSet: import("@modern-js/plugin").AsyncPipeline<unknown, unknown>;
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.4",
14
+ "version": "1.3.0",
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,21 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@modern-js/plugin": "^1.3.2",
32
- "@modern-js/utils": "^1.3.6"
32
+ "@modern-js/utils": "^1.4.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@modern-js/core": "^1.6.0",
36
- "@modern-js/types": "^1.3.5",
35
+ "@modern-js/core": "1.7.0",
36
+ "@modern-js/types": "^1.4.0",
37
+ "@scripts/build": "0.0.0",
38
+ "@scripts/jest-config": "0.0.0",
37
39
  "@types/jest": "^26",
38
40
  "@types/node": "^14",
39
41
  "@types/react": "^17",
40
42
  "@types/react-dom": "^17",
41
- "ts-jest": "^27.0.4",
42
- "typescript": "^4",
43
- "@scripts/build": "0.0.0",
43
+ "http-proxy-middleware": "^2.0.4",
44
44
  "jest": "^27",
45
- "@scripts/jest-config": "0.0.0"
45
+ "ts-jest": "^27.0.4",
46
+ "typescript": "^4"
46
47
  },
47
48
  "sideEffects": false,
48
49
  "modernConfig": {
@@ -1,4 +1,5 @@
1
1
  import { serverManager } from '../src';
2
+ import { ServerConfig } from '../src/plugin';
2
3
 
3
4
  describe('Default cases', () => {
4
5
  it('Have returns plugins', async () => {
@@ -19,4 +20,41 @@ describe('Default cases', () => {
19
20
 
20
21
  expect(count).toBe(1);
21
22
  });
23
+
24
+ it('config hook should works correctly', async () => {
25
+ const proxy = {
26
+ '/bff': {
27
+ target: 'https://modernjs.dev',
28
+ changeOrigin: true,
29
+ },
30
+ };
31
+ const expectedServerConfig = {
32
+ bff: {
33
+ proxy,
34
+ },
35
+ };
36
+ let receivedServerConfig: ServerConfig = {};
37
+
38
+ serverManager.usePlugin(
39
+ serverManager.createPlugin(() => ({
40
+ config(serverConfig) {
41
+ serverConfig.bff = {
42
+ proxy,
43
+ };
44
+ return serverConfig;
45
+ },
46
+ })),
47
+
48
+ serverManager.createPlugin(() => ({
49
+ config(serverConfig) {
50
+ receivedServerConfig = serverConfig;
51
+ return receivedServerConfig;
52
+ },
53
+ })),
54
+ );
55
+
56
+ const runner = await serverManager.init();
57
+ runner.config({});
58
+ expect(expectedServerConfig).toEqual(receivedServerConfig);
59
+ });
22
60
  });