@modern-js/prod-server 1.1.5 → 1.1.6

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,16 @@
1
1
  # @modern-js/prod-server
2
2
 
3
+ ## 1.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 430d417e: optimize server side hot reload
8
+ - Updated dependencies [6451a098]
9
+ - Updated dependencies [d5a2cfd8]
10
+ - Updated dependencies [437367c6]
11
+ - @modern-js/utils@1.7.6
12
+ - @modern-js/server-core@1.3.5
13
+
3
14
  ## 1.1.5
4
15
 
5
16
  ### Patch Changes
@@ -167,8 +167,24 @@ export class ModernServer {
167
167
  onListening(_) {// empty
168
168
  }
169
169
 
170
- onServerChange(_) {
171
- this.prepareFrameHandler();
170
+ onServerChange({
171
+ filepath
172
+ }) {
173
+ const {
174
+ pwd
175
+ } = this;
176
+ const {
177
+ api,
178
+ server
179
+ } = AGGRED_DIR;
180
+ const apiPath = path.normalize(path.join(pwd, api));
181
+ const serverPath = path.normalize(path.join(pwd, server));
182
+ const onlyApi = filepath.startsWith(apiPath);
183
+ const onlyWeb = filepath.startsWith(serverPath);
184
+ this.prepareFrameHandler({
185
+ onlyWeb,
186
+ onlyApi
187
+ });
172
188
  } // exposed requestHandler
173
189
 
174
190
 
@@ -217,11 +233,15 @@ export class ModernServer {
217
233
  } // gather frame extension and get framework handler
218
234
 
219
235
 
220
- async prepareFrameHandler() {
236
+ async prepareFrameHandler(options) {
221
237
  const {
222
238
  workDir,
223
239
  runner
224
- } = this; // server hook, gather plugin inject
240
+ } = this;
241
+ const {
242
+ onlyApi,
243
+ onlyWeb
244
+ } = options || {}; // server hook, gather plugin inject
225
245
 
226
246
  const _createMiddlewareColl = createMiddlewareCollecter(),
227
247
  {
@@ -237,12 +257,12 @@ export class ModernServer {
237
257
  const apiDir = path.join(workDir, API_DIR);
238
258
  const serverDir = path.join(workDir, SERVER_DIR); // get api or web server handler from server-framework plugin
239
259
 
240
- if (await fs.pathExists(path.join(serverDir))) {
260
+ if ((await fs.pathExists(path.join(serverDir))) && !onlyApi) {
241
261
  const webExtension = mergeExtension(pluginWebExt);
242
262
  this.frameWebHandler = await this.prepareWebHandler(webExtension);
243
263
  }
244
264
 
245
- if (fs.existsSync(apiDir)) {
265
+ if (fs.existsSync(apiDir) && !onlyWeb) {
246
266
  const mode = fs.existsSync(path.join(apiDir, AGGRED_DIR.lambda)) ? ApiServerMode.frame : ApiServerMode.func;
247
267
  debug('exists api dir', mode); // if use lambda/, mean framework style of writing, then discard user extension
248
268
 
@@ -196,8 +196,27 @@ class ModernServer {
196
196
  onListening(_) {// empty
197
197
  }
198
198
 
199
- onServerChange(_) {
200
- this.prepareFrameHandler();
199
+ onServerChange({
200
+ filepath
201
+ }) {
202
+ const {
203
+ pwd
204
+ } = this;
205
+ const {
206
+ api,
207
+ server
208
+ } = _constants.AGGRED_DIR;
209
+
210
+ const apiPath = _path.default.normalize(_path.default.join(pwd, api));
211
+
212
+ const serverPath = _path.default.normalize(_path.default.join(pwd, server));
213
+
214
+ const onlyApi = filepath.startsWith(apiPath);
215
+ const onlyWeb = filepath.startsWith(serverPath);
216
+ this.prepareFrameHandler({
217
+ onlyWeb,
218
+ onlyApi
219
+ });
201
220
  } // exposed requestHandler
202
221
 
203
222
 
@@ -247,11 +266,15 @@ class ModernServer {
247
266
  } // gather frame extension and get framework handler
248
267
 
249
268
 
250
- async prepareFrameHandler() {
269
+ async prepareFrameHandler(options) {
251
270
  const {
252
271
  workDir,
253
272
  runner
254
- } = this; // server hook, gather plugin inject
273
+ } = this;
274
+ const {
275
+ onlyApi,
276
+ onlyWeb
277
+ } = options || {}; // server hook, gather plugin inject
255
278
 
256
279
  const _createMiddlewareColl = (0, _utils2.createMiddlewareCollecter)(),
257
280
  {
@@ -270,12 +293,12 @@ class ModernServer {
270
293
  const serverDir = _path.default.join(workDir, SERVER_DIR); // get api or web server handler from server-framework plugin
271
294
 
272
295
 
273
- if (await _utils.fs.pathExists(_path.default.join(serverDir))) {
296
+ if ((await _utils.fs.pathExists(_path.default.join(serverDir))) && !onlyApi) {
274
297
  const webExtension = (0, _utils2.mergeExtension)(pluginWebExt);
275
298
  this.frameWebHandler = await this.prepareWebHandler(webExtension);
276
299
  }
277
300
 
278
- if (_utils.fs.existsSync(apiDir)) {
301
+ if (_utils.fs.existsSync(apiDir) && !onlyWeb) {
279
302
  const mode = _utils.fs.existsSync(_path.default.join(apiDir, _constants.AGGRED_DIR.lambda)) ? _constants.ApiServerMode.frame : _constants.ApiServerMode.func;
280
303
  (0, _utils2.debug)('exists api dir', mode); // if use lambda/, mean framework style of writing, then discard user extension
281
304
 
@@ -45,13 +45,20 @@ export declare class ModernServer implements ModernServerInterface {
45
45
  onClose(): Promise<void>;
46
46
  onRepack(_: BuildOptions): void;
47
47
  onListening(_: Server): void;
48
- protected onServerChange(_: Record<string, any>): void;
48
+ protected onServerChange({
49
+ filepath
50
+ }: {
51
+ filepath: string;
52
+ }): void;
49
53
  getRequestHandler(): (req: IncomingMessage, res: ServerResponse, next?: () => void) => void | ServerResponse;
50
54
  createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<Server>;
51
55
  protected getRoutes(): ModernRouteInterface[];
52
56
  protected addHandler(handler: ModernServerHandler): void;
53
57
  protected render404(context: ModernServerContext): void;
54
- protected prepareFrameHandler(): Promise<void>;
58
+ protected prepareFrameHandler(options?: {
59
+ onlyApi: boolean;
60
+ onlyWeb: boolean;
61
+ }): Promise<void>;
55
62
  protected prepareWebHandler(extension: ReturnType<typeof mergeExtension>): Promise<Adapter>;
56
63
  protected prepareAPIHandler(mode: ApiServerMode, extension: APIServerStartInput['config']): Promise<Adapter>;
57
64
  protected filterRoutes(routes: ModernRouteInterface[]): ModernRouteInterface[];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.5",
14
+ "version": "1.1.6",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -28,7 +28,7 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@modern-js/utils": "^1.7.3",
31
+ "@modern-js/utils": "^1.7.6",
32
32
  "@babel/compat-data": "^7.17.0",
33
33
  "@modern-js/server-core": "^1.3.5",
34
34
  "axios": "^0.24.0",
@@ -43,8 +43,8 @@
43
43
  "ua-parser-js": "^0.7.28"
44
44
  },
45
45
  "devDependencies": {
46
- "@modern-js/types": "1.5.3",
47
- "@modern-js/core": "1.10.2",
46
+ "@modern-js/types": "1.5.4",
47
+ "@modern-js/core": "1.11.1",
48
48
  "@scripts/jest-config": "0.0.0",
49
49
  "@scripts/build": "0.0.0",
50
50
  "@types/cookie": "^0.4.1",
@@ -86,7 +86,8 @@
86
86
  "files": [
87
87
  "src/**/*",
88
88
  "tsconfig.json",
89
- "package.json"
89
+ "package.json",
90
+ "tests/**/*"
90
91
  ],
91
92
  "output": []
92
93
  }