@modern-js/server 1.3.2 → 1.4.2

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/js/modern/dev-tools/babel/register.js +1 -0
  3. package/dist/js/modern/dev-tools/dev-server-plugin.js +1 -2
  4. package/dist/js/modern/dev-tools/mock/getMockData.js +24 -1
  5. package/dist/js/modern/dev-tools/mock/index.js +1 -26
  6. package/dist/js/modern/dev-tools/socket-server.js +65 -46
  7. package/dist/js/modern/dev-tools/watcher/index.js +3 -4
  8. package/dist/js/modern/dev-tools/watcher/stats-cache.js +32 -20
  9. package/dist/js/modern/libs/context/context.js +6 -0
  10. package/dist/js/modern/libs/hook-api/route.js +6 -4
  11. package/dist/js/modern/libs/render/index.js +1 -0
  12. package/dist/js/modern/libs/render/reader.js +1 -2
  13. package/dist/js/modern/libs/render/ssr.js +7 -2
  14. package/dist/js/modern/libs/route/index.js +0 -1
  15. package/dist/js/modern/libs/route/matcher.js +15 -3
  16. package/dist/js/modern/libs/route/route.js +1 -0
  17. package/dist/js/modern/server/dev-server/dev-server.js +7 -0
  18. package/dist/js/modern/server/index.js +5 -4
  19. package/dist/js/modern/server/modern-server-split.js +1 -1
  20. package/dist/js/modern/server/modern-server.js +13 -34
  21. package/dist/js/modern/utils.js +39 -0
  22. package/dist/js/node/dev-tools/babel/register.js +1 -0
  23. package/dist/js/node/dev-tools/dev-server-plugin.js +1 -2
  24. package/dist/js/node/dev-tools/mock/getMockData.js +29 -2
  25. package/dist/js/node/dev-tools/mock/index.js +5 -26
  26. package/dist/js/node/dev-tools/socket-server.js +65 -46
  27. package/dist/js/node/dev-tools/watcher/index.js +6 -2
  28. package/dist/js/node/dev-tools/watcher/stats-cache.js +33 -20
  29. package/dist/js/node/libs/context/context.js +6 -0
  30. package/dist/js/node/libs/hook-api/route.js +6 -4
  31. package/dist/js/node/libs/render/index.js +1 -0
  32. package/dist/js/node/libs/render/reader.js +2 -1
  33. package/dist/js/node/libs/render/ssr.js +8 -2
  34. package/dist/js/node/libs/route/index.js +0 -1
  35. package/dist/js/node/libs/route/matcher.js +16 -3
  36. package/dist/js/node/libs/route/route.js +1 -0
  37. package/dist/js/node/server/dev-server/dev-server.js +7 -0
  38. package/dist/js/node/server/index.js +9 -6
  39. package/dist/js/node/server/modern-server-split.js +1 -1
  40. package/dist/js/node/server/modern-server.js +12 -33
  41. package/dist/js/node/utils.js +51 -2
  42. package/dist/types/dev-tools/mock/getMockData.d.ts +2 -1
  43. package/dist/types/dev-tools/socket-server.d.ts +4 -1
  44. package/dist/types/dev-tools/watcher/index.d.ts +2 -1
  45. package/dist/types/dev-tools/watcher/stats-cache.d.ts +3 -2
  46. package/dist/types/libs/context/context.d.ts +2 -0
  47. package/dist/types/libs/hook-api/route.d.ts +3 -2
  48. package/dist/types/libs/render/reader.d.ts +13 -0
  49. package/dist/types/libs/render/ssr.d.ts +1 -0
  50. package/dist/types/libs/route/matcher.d.ts +1 -1
  51. package/dist/types/libs/route/route.d.ts +1 -0
  52. package/dist/types/server/dev-server/dev-server-split.d.ts +3 -3
  53. package/dist/types/server/modern-server-split.d.ts +3 -3
  54. package/dist/types/server/modern-server.d.ts +1 -2
  55. package/dist/types/type.d.ts +5 -3
  56. package/dist/types/utils.d.ts +5 -1
  57. package/package.json +9 -8
  58. package/tests/context.test.ts +12 -1
  59. package/tests/dev.test.ts +316 -5
  60. package/tests/fixtures/mock/exist/config/mock/index.ts +11 -0
  61. package/tests/fixtures/mock/zero/config/mock/index.ts +1 -0
  62. package/tests/fixtures/reader/index.ts +3 -0
  63. package/tests/fixtures/route-spec/dynamic.json +13 -0
  64. package/tests/fixtures/ssr/bundle.js +5 -0
  65. package/tests/fixtures/static-dir/bar.html +11 -0
  66. package/tests/fixtures/static-dir/baz/index.html +11 -0
  67. package/tests/fixtures/static-dir/foo/index.html +11 -0
  68. package/tests/fixtures/watch/a.ts +3 -0
  69. package/tests/fixtures/watch/index.ts +5 -0
  70. package/tests/fixtures/watch/stats.txt +1 -0
  71. package/tests/hook.test.ts +1 -1
  72. package/tests/render.test.ts +102 -0
  73. package/tests/route.test.ts +26 -3
  74. package/tests/utils.test.ts +35 -0
@@ -9,6 +9,8 @@ var _utils = require("@modern-js/utils");
9
9
 
10
10
  var _pathToRegexp = require("path-to-regexp");
11
11
 
12
+ var _utils2 = require("../../utils");
13
+
12
14
  var _route = require("./route");
13
15
 
14
16
  // eslint-disable-next-line no-useless-escape
@@ -25,8 +27,16 @@ class RouteMatcher {
25
27
  } // generate modern route object
26
28
 
27
29
 
28
- generate() {
29
- return new _route.ModernRoute(this.spec);
30
+ generate(url) {
31
+ const route = new _route.ModernRoute(this.spec);
32
+
33
+ if (this.urlPath) {
34
+ const params = this.parseURLParams(url);
35
+ route.urlPath = (0, _utils2.toPath)(route.urlPath, params);
36
+ route.params = params;
37
+ }
38
+
39
+ return route;
30
40
  }
31
41
 
32
42
  parseURLParams(pathname) {
@@ -84,9 +94,12 @@ class RouteMatcher {
84
94
 
85
95
  if (useReg) {
86
96
  this.urlMatcher = (0, _pathToRegexp.match)(urlPath, {
97
+ end: false,
87
98
  decode: decodeURIComponent
88
99
  });
89
- this.urlReg = (0, _pathToRegexp.pathToRegexp)(urlPath);
100
+ this.urlReg = (0, _pathToRegexp.pathToRegexp)(urlPath, [], {
101
+ end: false
102
+ });
90
103
  }
91
104
  }
92
105
 
@@ -17,6 +17,7 @@ class ModernRoute {
17
17
  this.isSSR = void 0;
18
18
  this.isSPA = void 0;
19
19
  this.enableModernMode = void 0;
20
+ this.params = {};
20
21
  this.entryName = routeSpec.entryName || '';
21
22
  this.urlPath = routeSpec.urlPath;
22
23
  this.entryPath = routeSpec.entryPath || '';
@@ -147,6 +147,8 @@ class ModernDevServer extends _modernServer.ModernServer {
147
147
  }
148
148
 
149
149
  async close() {
150
+ var _this$socketServer2;
151
+
150
152
  super.close();
151
153
  await this.watcher.close();
152
154
  await new Promise(resolve => {
@@ -158,6 +160,7 @@ class ModernDevServer extends _modernServer.ModernServer {
158
160
  resolve();
159
161
  }
160
162
  });
163
+ (_this$socketServer2 = this.socketServer) === null || _this$socketServer2 === void 0 ? void 0 : _this$socketServer2.close();
161
164
  }
162
165
 
163
166
  async createHTTPServer(handler) {
@@ -209,6 +212,10 @@ class ModernDevServer extends _modernServer.ModernServer {
209
212
  };
210
213
 
211
214
  const addHooks = compiler => {
215
+ if (compiler.name === 'server') {
216
+ return;
217
+ }
218
+
212
219
  const {
213
220
  compile,
214
221
  invalid,
@@ -7,7 +7,7 @@ exports.Server = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
10
- var _serverPlugin = require("@modern-js/server-plugin");
10
+ var _serverCore = require("@modern-js/server-core");
11
11
 
12
12
  var _utils = require("@modern-js/utils");
13
13
 
@@ -131,22 +131,25 @@ class Server {
131
131
  const {
132
132
  options
133
133
  } = this;
134
+
135
+ _serverCore.serverManager.clear();
136
+
134
137
  (_options$plugins = options.plugins) === null || _options$plugins === void 0 ? void 0 : _options$plugins.forEach(p => {
135
- _serverPlugin.serverManager.usePlugin(p);
138
+ _serverCore.serverManager.usePlugin((0, _utils.compatRequire)(p.pluginPath));
136
139
  });
137
140
  const appContext = await this.initAppContext();
138
141
 
139
- _serverPlugin.serverManager.run(() => {
142
+ _serverCore.serverManager.run(() => {
140
143
  var _options$config$outpu;
141
144
 
142
- _core.ConfigContext.set(this.options.config);
145
+ _serverCore.ConfigContext.set(this.options.config);
143
146
 
144
- _core.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
147
+ _serverCore.AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
145
148
  distDirectory: _path.default.join(options.pwd, ((_options$config$outpu = options.config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.path) || 'dist')
146
149
  }));
147
150
  });
148
151
 
149
- return _serverPlugin.serverManager.init({});
152
+ return _serverCore.serverManager.init({});
150
153
  }
151
154
 
152
155
  async initAppContext() {
@@ -13,7 +13,7 @@ class ModernSSRServer extends _modernServer.ModernServer {
13
13
  }
14
14
 
15
15
  verifyMatch(context, matched) {
16
- if (matched.generate().isApi) {
16
+ if (matched.generate(context.url).isApi) {
17
17
  this.render404(context);
18
18
  }
19
19
  }
@@ -156,15 +156,10 @@ class ModernServer {
156
156
  this.warmupSSRBundle();
157
157
  }
158
158
 
159
- await this.prepareFrameHandler();
160
- const {
161
- favicon,
162
- faviconByEntries
163
- } = this.conf.output || {};
164
- const favicons = this.prepareFavicons(favicon, faviconByEntries); // Only work when without setting `assetPrefix`.
159
+ await this.prepareFrameHandler(); // Only work when without setting `assetPrefix`.
165
160
  // Setting `assetPrefix` means these resources should be uploaded to CDN.
166
161
 
167
- const staticPathRegExp = new RegExp(`^/(static/|upload/|favicon.ico|icon.png${favicons.length > 0 ? `|${favicons.join('|')}` : ''})`);
162
+ const staticPathRegExp = (0, _utils2.getStaticReg)(this.conf.output || {});
168
163
  this.staticFileHandler = (0, _serveFile.createStaticFileHandler)([{
169
164
  path: staticPathRegExp,
170
165
  target: distDir
@@ -388,7 +383,7 @@ class ModernServer {
388
383
  return;
389
384
  }
390
385
 
391
- const routeAPI = (0, _route2.createRouteAPI)(matched, this.router);
386
+ const routeAPI = (0, _route2.createRouteAPI)(matched, this.router, context.url);
392
387
  await this.emitRouteHook('afterMatch', {
393
388
  context,
394
389
  routeAPI
@@ -401,12 +396,15 @@ class ModernServer {
401
396
  const {
402
397
  current
403
398
  } = routeAPI;
404
- const route = current.generate();
405
- const params = current.parseURLParams(context.url);
406
- context.setParams(params); // route is api service
399
+ const route = current.generate(context.url);
400
+ context.setParams(route.params);
401
+ context.setServerData('router', {
402
+ baseUrl: route.urlPath,
403
+ params: route.params
404
+ }); // route is api service
407
405
 
408
406
  if (route.isApi) {
409
- this.handleAPI(context);
407
+ await this.handleAPI(context);
410
408
  return;
411
409
  }
412
410
 
@@ -448,6 +446,7 @@ class ModernServer {
448
446
  templateAPI
449
447
  });
450
448
  await this.injectMicroFE(context, templateAPI);
449
+ templateAPI.appendHead(`<script>window._SERVER_DATA=${JSON.stringify(context.serverData)}</script>`);
451
450
  response = templateAPI.get();
452
451
  }
453
452
 
@@ -590,7 +589,7 @@ class ModernServer {
590
589
  const matched = this.router.match(statusPage) || this.router.match(customErrorPage); // if no custom status page find
591
590
 
592
591
  if (matched) {
593
- const route = matched.generate();
592
+ const route = matched.generate(context.url);
594
593
  const {
595
594
  entryName
596
595
  } = route; // check entryName, aviod matched '/' route
@@ -616,26 +615,6 @@ class ModernServer {
616
615
  res.end((0, _utils2.createErrorDocument)(status, text));
617
616
  }
618
617
 
619
- prepareFavicons(favicon, faviconByEntries) {
620
- const faviconNames = [];
621
-
622
- if (favicon) {
623
- faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
624
- }
625
-
626
- if (faviconByEntries) {
627
- Object.keys(faviconByEntries).forEach(f => {
628
- const curFavicon = faviconByEntries[f];
629
-
630
- if (curFavicon) {
631
- faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf('/') + 1));
632
- }
633
- });
634
- }
635
-
636
- return faviconNames;
637
- }
638
-
639
618
  }
640
619
  /* eslint-enable max-lines */
641
620
 
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toMessage = exports.noop = exports.mergeExtension = exports.createMiddlewareCollecter = exports.createErrorDocument = void 0;
6
+ exports.toPath = exports.toMessage = exports.prepareFavicons = exports.noop = exports.mergeExtension = exports.getStaticReg = exports.createMiddlewareCollecter = exports.createErrorDocument = void 0;
7
+
8
+ var _pathToRegexp = require("path-to-regexp");
7
9
 
8
10
  const mergeExtension = users => {
9
11
  const output = [];
@@ -91,4 +93,51 @@ const createMiddlewareCollecter = () => {
91
93
  };
92
94
  };
93
95
 
94
- exports.createMiddlewareCollecter = createMiddlewareCollecter;
96
+ exports.createMiddlewareCollecter = createMiddlewareCollecter;
97
+
98
+ const toPath = (reg, params) => {
99
+ const fn = (0, _pathToRegexp.compile)(reg, {
100
+ encode: encodeURIComponent
101
+ });
102
+ return fn(params);
103
+ };
104
+
105
+ exports.toPath = toPath;
106
+
107
+ const getStaticReg = (output = {}) => {
108
+ const {
109
+ favicon,
110
+ faviconByEntries,
111
+ cssPath,
112
+ jsPath,
113
+ mediaPath
114
+ } = output;
115
+ const favicons = prepareFavicons(favicon, faviconByEntries);
116
+ const staticFiles = [cssPath, jsPath, mediaPath].filter(v => Boolean(v));
117
+ const staticPathRegExp = new RegExp(`^/(static/|upload/|favicon.ico|icon.png${favicons.length > 0 ? `|${favicons.join('|')}` : ''}|${staticFiles.join('|')})`);
118
+ return staticPathRegExp;
119
+ };
120
+
121
+ exports.getStaticReg = getStaticReg;
122
+
123
+ const prepareFavicons = (favicon, faviconByEntries) => {
124
+ const faviconNames = [];
125
+
126
+ if (favicon) {
127
+ faviconNames.push(favicon.substring(favicon.lastIndexOf('/') + 1));
128
+ }
129
+
130
+ if (faviconByEntries) {
131
+ Object.keys(faviconByEntries).forEach(f => {
132
+ const curFavicon = faviconByEntries[f];
133
+
134
+ if (curFavicon) {
135
+ faviconNames.push(curFavicon.substring(curFavicon.lastIndexOf('/') + 1));
136
+ }
137
+ });
138
+ }
139
+
140
+ return faviconNames;
141
+ };
142
+
143
+ exports.prepareFavicons = prepareFavicons;
@@ -15,4 +15,5 @@ declare const createStaticDataHandler: (method: string, handler: Record<string,
15
15
 
16
16
  declare const _default: (filepath: string) => MockApi[];
17
17
 
18
- export default _default;
18
+ export default _default;
19
+ export declare const getMatched: (context: ModernServerContext, mockApiList: MockApi[]) => MockApi | undefined;
@@ -9,11 +9,14 @@ export default class SocketServer {
9
9
  private readonly options;
10
10
  private app?;
11
11
  private stats?;
12
+ private timer;
12
13
  constructor(options: DevServerOptions);
13
14
  prepare(app: Server): void;
14
15
  updateStats(stats: Stats): void;
15
16
  sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
16
- close(connection: ws): void;
17
+ singleWrite(socket: ws, type: string, data?: Record<string, any> | string | boolean): void;
18
+ close(): void;
19
+ private onConnect;
17
20
  private getStats;
18
21
  private sendStats;
19
22
  private send;
@@ -1,4 +1,5 @@
1
- import { WatchOptions } from 'chokidar';
1
+ import chokidar, { FSWatcher, WatchOptions } from 'chokidar';
2
+ export declare const getWatchedFiles: (watcher: chokidar.FSWatcher) => string[];
2
3
  export default class Watcher {
3
4
  private dependencyTree;
4
5
  private watcher;
@@ -1,9 +1,10 @@
1
1
  export declare class StatsCache {
2
- private readonly cachedStats;
2
+ private readonly cachedHash;
3
+ private readonly cachedSize;
3
4
  add(files: string[]): void;
4
5
  refresh(filename: string): void;
5
6
  del(filename: string): void;
6
7
  isDiff(filename: string): boolean;
7
8
  has(filename: string): boolean;
8
- private sign;
9
+ private hash;
9
10
  }
@@ -26,9 +26,11 @@ export declare class ModernServerContext implements ModernServerContextInterface
26
26
  params: Record<string, string>;
27
27
  logger: Logger;
28
28
  metrics?: Metrics;
29
+ serverData: Record<string, any>;
29
30
  constructor(req: IncomingMessage, res: ServerResponse);
30
31
  private bind;
31
32
  setParams(params: Record<string, string>): void;
33
+ setServerData(key: string, value: any): void;
32
34
  getReqHeader(key: string): string | string[];
33
35
  get headers(): import("http").IncomingHttpHeaders;
34
36
  get method(): string;
@@ -3,11 +3,12 @@ import { RouteMatchManager, RouteMatcher } from '../route';
3
3
  declare class RouteAPI {
4
4
  private readonly router;
5
5
  private current;
6
- constructor(matched: RouteMatcher, router: RouteMatchManager);
6
+ private readonly url;
7
+ constructor(matched: RouteMatcher, router: RouteMatchManager, url: string);
7
8
  cur(): import("../route").ModernRoute;
8
9
  get(entryName: string): import("../route").ModernRoute | null;
9
10
  use(entryName: string): boolean;
10
11
  }
11
12
 
12
- export declare const createRouteAPI: (matched: RouteMatcher, router: RouteMatchManager) => RouteAPI;
13
+ export declare const createRouteAPI: (matched: RouteMatcher, router: RouteMatchManager, url: string) => RouteAPI;
13
14
  export {};
@@ -1,4 +1,17 @@
1
1
  /// <reference types="node" />
2
+ export declare class LruReader {
3
+ private readonly cache;
4
+ constructor();
5
+ init(): void;
6
+ close(): void;
7
+ read(filepath: string): Promise<{
8
+ content: Buffer;
9
+ mtime: Date;
10
+ } | {
11
+ content: Buffer;
12
+ } | null>;
13
+ update(): void;
14
+ }
2
15
  export declare const readFile: (filepath: string) => Promise<Buffer | undefined>;
3
16
  export declare const updateFile: () => void;
4
17
  export declare const init: () => void;
@@ -3,6 +3,7 @@ import { RenderResult, ServerHookRunner } from '../../type';
3
3
  export declare const render: (ctx: ModernServerContext, renderOptions: {
4
4
  distDir: string;
5
5
  bundle: string;
6
+ urlPath: string;
6
7
  template: string;
7
8
  entryName: string;
8
9
  staticGenerate: boolean;
@@ -6,7 +6,7 @@ export declare class RouteMatcher {
6
6
  urlMatcher?: MatchFunction;
7
7
  urlReg?: RegExp;
8
8
  constructor(spec: ModernRouteInterface);
9
- generate(): ModernRoute;
9
+ generate(url: string): ModernRoute;
10
10
  parseURLParams(pathname: string): Record<string, string>;
11
11
  matchLength(pathname: string): number | null;
12
12
  matchUrlPath(requestUrl: string): boolean;
@@ -9,5 +9,6 @@ export declare class ModernRoute implements ModernRouteInterface {
9
9
  isSSR: boolean;
10
10
  isSPA: boolean;
11
11
  enableModernMode?: boolean;
12
+ params: Record<string, any>;
12
13
  constructor(routeSpec: ModernRouteInterface);
13
14
  }
@@ -1,15 +1,15 @@
1
- import type { APIServerStartInput } from '@modern-js/server-plugin';
1
+ import type { APIServerStartInput } from '@modern-js/server-core';
2
2
  import { mergeExtension } from '../../utils';
3
3
  import { ModernRouteInterface } from '../../libs/route';
4
4
  import { ApiServerMode } from '../../constants';
5
5
  import { ModernDevServer } from './dev-server';
6
6
  export declare class ModernSSRDevServer extends ModernDevServer {
7
7
  protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
8
- protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
8
+ protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-core").Adapter>;
9
9
  protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
10
10
  }
11
11
  export declare class ModernAPIDevServer extends ModernDevServer {
12
- protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-plugin").Adapter>;
12
+ protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-core").Adapter>;
13
13
  protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
14
14
  protected preServerInit(): Promise<void>;
15
15
  }
@@ -1,4 +1,4 @@
1
- import { APIServerStartInput } from '@modern-js/server-plugin';
1
+ import { APIServerStartInput } from '@modern-js/server-core';
2
2
  import { mergeExtension } from '../utils';
3
3
  import { ModernRoute, ModernRouteInterface, RouteMatcher } from '../libs/route';
4
4
  import { ApiServerMode } from '../constants';
@@ -8,14 +8,14 @@ export declare class ModernSSRServer extends ModernServer {
8
8
  protected warmupSSRBundle(): Promise<void>;
9
9
  protected verifyMatch(context: ModernServerContext, matched: RouteMatcher): void;
10
10
  protected prepareAPIHandler(_m: ApiServerMode, _: APIServerStartInput['config']): any;
11
- protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-plugin").Adapter>;
11
+ protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<import("@modern-js/server-core").Adapter>;
12
12
  protected preServerInit(): Promise<void>;
13
13
  }
14
14
  export declare class ModernAPIServer extends ModernServer {
15
15
  protected emitRouteHook(_: string, _input: any): Promise<void>;
16
16
  protected warmupSSRBundle(): Promise<void>;
17
17
  protected prepareWebHandler(_: ReturnType<typeof mergeExtension>): any;
18
- protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-plugin").Adapter>;
18
+ protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<import("@modern-js/server-core").Adapter>;
19
19
  protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
20
20
  protected preServerInit(): Promise<void>;
21
21
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingMessage, ServerResponse, Server } from 'http';
3
- import { Adapter, APIServerStartInput } from '@modern-js/server-plugin';
3
+ import { Adapter, APIServerStartInput } from '@modern-js/server-core';
4
4
  import type { NormalizedConfig } from '@modern-js/core';
5
5
  import { ModernServerOptions, NextFunction, ServerHookRunner, Metrics, Logger, ReadyOptions } from '../type';
6
6
  import { RouteMatchManager, ModernRouteInterface, ModernRoute, RouteMatcher } from '../libs/route';
@@ -68,6 +68,5 @@ export declare class ModernServer {
68
68
  private requestHandler;
69
69
  private onError;
70
70
  private renderErrorPage;
71
- private prepareFavicons;
72
71
  }
73
72
  export {};
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type Webpack from 'webpack';
3
- import { serverManager } from '@modern-js/server-plugin';
3
+ import { serverManager } from '@modern-js/server-core';
4
4
  import type { NormalizedConfig } from '@modern-js/core';
5
5
  import type { Metrics, Logger, NextFunction } from '@modern-js/types/server';
6
6
  import { ModernRouteInterface } from './libs/route';
@@ -41,9 +41,11 @@ export declare type DevServerOptions = {
41
41
  export declare type ModernServerOptions = {
42
42
  pwd: string;
43
43
  config: NormalizedConfig;
44
- plugins?: any[];
44
+ plugins?: {
45
+ pluginPath: string;
46
+ }[];
45
47
  dev?: boolean | Partial<DevServerOptions>;
46
- compiler?: Webpack.MultiCompiler | Webpack.Compiler;
48
+ compiler?: Webpack.MultiCompiler | Webpack.Compiler | null;
47
49
  routes?: ModernRouteInterface[];
48
50
  staticGenerate?: boolean;
49
51
  customServer?: boolean;
@@ -1,3 +1,4 @@
1
+ import type { NormalizedConfig } from '@modern-js/core';
1
2
  export declare const mergeExtension: (users: any[]) => {
2
3
  middleware: any[];
3
4
  };
@@ -12,4 +13,7 @@ export declare const createMiddlewareCollecter: () => {
12
13
  getMiddlewares: () => CollectMiddlewaresResult;
13
14
  addWebMiddleware: (input: any) => void;
14
15
  addAPIMiddleware: (input: any) => void;
15
- };
16
+ };
17
+ export declare const toPath: (reg: string, params: Record<string, any>) => string;
18
+ export declare const getStaticReg: (output?: NormalizedConfig['output']) => RegExp;
19
+ export declare const prepareFavicons: (favicon: string | undefined, faviconByEntries?: Record<string, string | undefined> | undefined) => string[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.2",
14
+ "version": "1.4.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -34,12 +34,12 @@
34
34
  "@babel/preset-typescript": "^7.15.0",
35
35
  "@babel/register": "^7.15.3",
36
36
  "@babel/runtime": "^7",
37
- "@modern-js/core": "^1.3.2",
37
+ "@modern-js/core": "^1.4.2",
38
38
  "@modern-js/hmr-client": "^1.2.1",
39
- "@modern-js/server-plugin": "^1.2.1",
39
+ "@modern-js/server-core": "^1.2.2",
40
40
  "@modern-js/server-utils": "^1.2.1",
41
41
  "@modern-js/bff-utils": "^1.2.2",
42
- "@modern-js/utils": "^1.2.2",
42
+ "@modern-js/utils": "^1.3.1",
43
43
  "axios": "^0.24.0",
44
44
  "babel-plugin-module-resolver": "^4.1.0",
45
45
  "chokidar": "^3.5.2",
@@ -60,11 +60,12 @@
60
60
  "ua-parser-js": "^0.7.28",
61
61
  "webpack-dev-middleware": "^5.0.0",
62
62
  "ws": "^8.2.0",
63
- "lodash.clone": "^4.5.0"
63
+ "lodash.clone": "^4.5.0",
64
+ "cookie": "^0.4.2"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@scripts/build": "0.0.0",
67
- "@modern-js/types": "^1.2.1",
68
+ "@modern-js/types": "^1.3.2",
68
69
  "@types/jest": "^26",
69
70
  "@types/lru-cache": "^5.1.1",
70
71
  "@types/mime-types": "^2.1.0",
@@ -79,6 +80,7 @@
79
80
  "@types/webpack-dev-middleware": "^5.0.2",
80
81
  "@types/ws": "^7.4.7",
81
82
  "@types/lodash.clone": "^4",
83
+ "@types/cookie": "^0.4.1",
82
84
  "typescript": "^4",
83
85
  "webpack": "^5.54.0",
84
86
  "node-mocks-http": "^1.11.0",
@@ -98,8 +100,7 @@
98
100
  },
99
101
  "publishConfig": {
100
102
  "registry": "https://registry.npmjs.org/",
101
- "access": "public",
102
- "types": "./dist/types/index.d.ts"
103
+ "access": "public"
103
104
  },
104
105
  "scripts": {
105
106
  "new": "modern new",
@@ -14,6 +14,7 @@ describe('test server context', () => {
14
14
  method: 'GET',
15
15
  });
16
16
  const res = httpMocks.createResponse({ eventEmitter: EventEmitter });
17
+ const context = createContext(req, res);
17
18
  const {
18
19
  method,
19
20
  url,
@@ -25,7 +26,7 @@ describe('test server context', () => {
25
26
  querystring,
26
27
  protocol,
27
28
  params,
28
- } = createContext(req, res);
29
+ } = context;
29
30
 
30
31
  expect(method).toBe('GET');
31
32
  expect(url).toBe('/pathname?foo=baz');
@@ -37,5 +38,15 @@ describe('test server context', () => {
37
38
  expect(querystring).toBe('foo=baz');
38
39
  expect(protocol).toBe('http');
39
40
  expect(params).toEqual({});
41
+
42
+ expect(context.serverData).toEqual({});
43
+ context.setServerData('foo', {
44
+ name: 'foo',
45
+ });
46
+ expect(context.serverData).toEqual({
47
+ foo: {
48
+ name: 'foo',
49
+ },
50
+ });
40
51
  });
41
52
  });