@modern-js/server-core 1.2.5 → 1.3.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 CHANGED
@@ -1,5 +1,35 @@
1
1
  # @modern-js/server-plugin
2
2
 
3
+ ## 1.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
8
+ - 60f7d8bf: feat: add tests dir to npmignore
9
+ - Updated dependencies [b8599d09]
10
+ - Updated dependencies [6cffe99d]
11
+ - Updated dependencies [60f7d8bf]
12
+ - Updated dependencies [3bf4f8b0]
13
+ - @modern-js/utils@1.5.0
14
+ - @modern-js/plugin@1.3.3
15
+
16
+ ## 1.3.0
17
+
18
+ ### Minor Changes
19
+
20
+ - d2d1d6b2: feat: support server config
21
+
22
+ ### Patch Changes
23
+
24
+ - d2d1d6b2: feat: add prepare hook
25
+ - Updated dependencies [77ff9754]
26
+ - Updated dependencies [d2d1d6b2]
27
+ - Updated dependencies [07a4887e]
28
+ - Updated dependencies [ea2ae711]
29
+ - Updated dependencies [17d0cc46]
30
+ - Updated dependencies [d2d1d6b2]
31
+ - @modern-js/utils@1.4.0
32
+
3
33
  ## 1.2.5
4
34
 
5
35
  ### Patch Changes
@@ -1,8 +1,11 @@
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();
@@ -50,6 +53,8 @@ const pluginAPI = {
50
53
  const serverHooks = {
51
54
  // server hook
52
55
  gather,
56
+ config,
57
+ prepare,
53
58
  create,
54
59
  prepareWebServer,
55
60
  prepareApiServer,
@@ -12,6 +12,9 @@ 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)();
@@ -67,6 +70,8 @@ const pluginAPI = {
67
70
  const serverHooks = {
68
71
  // server hook
69
72
  gather,
73
+ config,
74
+ prepare,
70
75
  create,
71
76
  prepareWebServer,
72
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;
@@ -53,6 +54,8 @@ 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>;
@@ -115,6 +118,8 @@ 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>;
@@ -171,6 +176,8 @@ 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>;
@@ -225,11 +232,19 @@ 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>;
@@ -285,6 +300,8 @@ 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>;
@@ -337,6 +354,8 @@ 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>;
@@ -392,6 +411,8 @@ 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>;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.5",
14
+ "version": "1.3.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,21 +28,22 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/plugin": "^1.3.2",
32
- "@modern-js/utils": "^1.3.7"
31
+ "@modern-js/plugin": "^1.3.3",
32
+ "@modern-js/utils": "^1.5.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@modern-js/core": "1.6.1",
36
- "@modern-js/types": "^1.3.6",
35
+ "@modern-js/core": "1.8.0",
36
+ "@modern-js/types": "^1.5.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,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,3 +0,0 @@
1
- module.exports = () => ({
2
- name: 'test-a',
3
- });
@@ -1,3 +0,0 @@
1
- {
2
- "name": "test-a"
3
- }
@@ -1,33 +0,0 @@
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
- });
@@ -1,22 +0,0 @@
1
- import { serverManager } from '../src';
2
-
3
- describe('Default cases', () => {
4
- it('Have returns plugins', async () => {
5
- let count = 0;
6
-
7
- serverManager.usePlugin(
8
- serverManager.createPlugin(() => ({
9
- prepareApiServer: () => {
10
- count = 1;
11
- // eslint-disable-next-line @typescript-eslint/no-empty-function
12
- return () => {};
13
- },
14
- })),
15
- );
16
-
17
- const runner = await serverManager.init();
18
- await runner.prepareApiServer({ pwd: '', mode: 'function', config: {} });
19
-
20
- expect(count).toBe(1);
21
- });
22
- });
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "isolatedModules": true,
8
- "paths": {},
9
- "types": ["node", "jest"]
10
- }
11
- }