@shuvi/service 1.0.45-pre.0 → 1.0.46

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.
@@ -1,13 +1,10 @@
1
1
  import { IPluginInstance, IPluginHandlers, HookMap } from '@shuvi/hook';
2
2
  import { IPluginContext } from '../core';
3
3
  import { CustomServerPluginHooks } from './pluginTypes';
4
- import { IRouter } from '@shuvi/router';
5
- import { ShuviRequest } from './shuviServerTypes';
6
4
  export * from './pluginTypes';
7
5
  export interface IServerPluginContext extends IPluginContext {
8
6
  serverPluginRunner: PluginManager['runner'];
9
7
  appConfig: AppConfig;
10
- router?: IRouter;
11
8
  }
12
9
  export declare type PluginManager = ReturnType<typeof getManager>;
13
10
  export declare type PluginRunner = PluginManager['runner'];
@@ -15,18 +12,13 @@ declare const listen: import("@shuvi/hook").AsyncParallelHook<{
15
12
  port: number;
16
13
  hostname?: string | undefined;
17
14
  }, void, void>;
18
- declare type AppConfigCtx = {
19
- req: ShuviRequest;
20
- };
21
15
  declare type AppConfig = {
22
16
  router: {
23
17
  basename: string;
24
18
  };
25
19
  };
26
- declare const getAppConfig: import("@shuvi/hook").SyncBailHook<void, AppConfigCtx, AppConfig>;
27
20
  export interface BuiltInServerPluginHooks extends HookMap {
28
21
  listen: typeof listen;
29
- getAppConfig: typeof getAppConfig;
30
22
  }
31
23
  export interface ServerPluginHooks extends BuiltInServerPluginHooks, CustomServerPluginHooks {
32
24
  }
@@ -20,10 +20,8 @@ const hook_1 = require("@shuvi/hook");
20
20
  const plugins_1 = require("@shuvi/shared/plugins");
21
21
  __exportStar(require("./pluginTypes"), exports);
22
22
  const listen = (0, hook_1.createAsyncParallelHook)();
23
- const getAppConfig = (0, hook_1.createSyncBailHook)();
24
23
  const internalHooks = {
25
- listen,
26
- getAppConfig
24
+ listen
27
25
  };
28
26
  const getManager = () => (0, hook_1.createHookManager)(internalHooks);
29
27
  exports.getManager = getManager;
@@ -31,7 +29,7 @@ _a = (0, plugins_1.createPluginCreator)(), exports.createServerPluginBefore = _a
31
29
  const initServerPlugins = (manager, serverPlugins, pluginContext) => {
32
30
  const serverContext = Object.assign({
33
31
  serverPluginRunner: manager.runner,
34
- // default appConfig, can be override by setupAppConfigMiddleware
32
+ // default appConfig, can be override by `getAppConfig` hook
35
33
  appConfig: {
36
34
  router: {
37
35
  basename: ''
@@ -32,7 +32,6 @@ const devMiddleware_1 = require("./middlewares/dev/devMiddleware");
32
32
  const httpProxyMiddleware_1 = require("./middlewares/httpProxyMiddleware");
33
33
  const getAssetMiddleware_1 = require("./middlewares/getAssetMiddleware");
34
34
  const env_1 = require("../config/env");
35
- const setupAppConfigMiddleware_1 = require("./middlewares/setupAppConfigMiddleware");
36
35
  class ShuviDevServer extends shuviServer_1.ShuviServer {
37
36
  constructor(corePluginContext, _a) {
38
37
  var { bundler } = _a, options = __rest(_a, ["bundler"]);
@@ -67,7 +66,6 @@ class ShuviDevServer extends shuviServer_1.ShuviServer {
67
66
  }
68
67
  next();
69
68
  })));
70
- server.use((0, setupAppConfigMiddleware_1.setupAppConfigMiddleware)(context));
71
69
  if (this._options.getMiddlewaresBeforeDevMiddlewares) {
72
70
  const serverMiddlewaresBeforeDevMiddleware = [
73
71
  this._options.getMiddlewaresBeforeDevMiddlewares(devMiddleware, context)
@@ -12,13 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ShuviProdServer = void 0;
13
13
  const shuviServer_1 = require("./shuviServer");
14
14
  const getAssetMiddleware_1 = require("./middlewares/getAssetMiddleware");
15
- const setupAppConfigMiddleware_1 = require("./middlewares/setupAppConfigMiddleware");
16
15
  class ShuviProdServer extends shuviServer_1.ShuviServer {
17
16
  init() {
18
17
  return __awaiter(this, void 0, void 0, function* () {
19
18
  const { _serverContext: context } = this;
20
19
  this._server.use((0, getAssetMiddleware_1.getAssetMiddleware)(context));
21
- this._server.use((0, setupAppConfigMiddleware_1.setupAppConfigMiddleware)(context));
22
20
  yield this._initMiddlewares();
23
21
  });
24
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/service",
3
- "version": "1.0.45-pre.0",
3
+ "version": "1.0.46",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -29,14 +29,14 @@
29
29
  "@babel/generator": "7.14.5",
30
30
  "@babel/parser": "7.14.7",
31
31
  "@babel/traverse": "7.14.7",
32
- "@shuvi/hook": "1.0.45-pre.0",
33
- "@shuvi/router": "1.0.45-pre.0",
34
- "@shuvi/runtime": "1.0.45-pre.0",
35
- "@shuvi/shared": "1.0.45-pre.0",
36
- "@shuvi/toolpack": "1.0.45-pre.0",
37
- "@shuvi/utils": "1.0.45-pre.0",
38
- "@shuvi/error-overlay": "1.0.45-pre.0",
39
- "@shuvi/reporters": "1.0.45-pre.0",
32
+ "@shuvi/hook": "1.0.46",
33
+ "@shuvi/router": "1.0.46",
34
+ "@shuvi/runtime": "1.0.46",
35
+ "@shuvi/shared": "1.0.46",
36
+ "@shuvi/toolpack": "1.0.46",
37
+ "@shuvi/utils": "1.0.46",
38
+ "@shuvi/error-overlay": "1.0.46",
39
+ "@shuvi/reporters": "1.0.46",
40
40
  "commander": "5.1.0",
41
41
  "comment-json": "4.2.2",
42
42
  "cross-spawn": "7.0.3",
@@ -1,3 +0,0 @@
1
- import { IServerPluginContext } from '../plugin';
2
- import { ShuviRequestHandler } from '../shuviServerTypes';
3
- export declare const setupAppConfigMiddleware: (context: IServerPluginContext) => ShuviRequestHandler;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.setupAppConfigMiddleware = void 0;
13
- const setupAppConfigMiddleware = (context) => {
14
- return (req, _res, next) => __awaiter(void 0, void 0, void 0, function* () {
15
- const appConfig = context.serverPluginRunner.getAppConfig({ req });
16
- if (appConfig) {
17
- if (typeof appConfig.router.basename !== 'string') {
18
- throw new Error('[ServerPlugin Hook getAppConfig] appConfig.router.basename must be a string');
19
- }
20
- context.appConfig = appConfig;
21
- }
22
- next();
23
- });
24
- };
25
- exports.setupAppConfigMiddleware = setupAppConfigMiddleware;