@shuvi/platform-web 1.0.0-rc.4 → 1.0.0-rc.7

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 (77) hide show
  1. package/esm/shared/appTypes.d.ts +4 -2
  2. package/esm/shared/renderTypes.d.ts +6 -5
  3. package/esm/shared/routeTypes.d.ts +4 -9
  4. package/esm/shuvi-app/app/client.js +11 -16
  5. package/esm/shuvi-app/app/server.js +10 -9
  6. package/esm/shuvi-app/dev/hotDevClient.d.ts +0 -1
  7. package/esm/shuvi-app/dev/hotDevClient.js +30 -51
  8. package/esm/shuvi-app/dev/websocket.d.ts +0 -1
  9. package/esm/shuvi-app/helper/serializeServerError.d.ts +2 -0
  10. package/esm/shuvi-app/helper/serializeServerError.js +21 -0
  11. package/esm/shuvi-app/react/AppContainer.d.ts +2 -3
  12. package/esm/shuvi-app/react/AppContainer.jsx +3 -4
  13. package/esm/shuvi-app/react/getRoutes.js +5 -3
  14. package/esm/shuvi-app/react/{redox-react → model}/RedoxWrapper.d.ts +3 -3
  15. package/esm/shuvi-app/react/{redox-react → model}/RedoxWrapper.jsx +3 -3
  16. package/esm/shuvi-app/react/model/runtime.d.ts +8 -0
  17. package/esm/shuvi-app/react/{redox-react → model}/runtime.js +6 -3
  18. package/esm/shuvi-app/react/store.d.ts +5 -0
  19. package/esm/shuvi-app/react/store.js +3 -0
  20. package/esm/shuvi-app/react/types.d.ts +0 -7
  21. package/esm/shuvi-app/react/useLoaderData.js +9 -20
  22. package/esm/shuvi-app/react/view/ReactView.client.jsx +25 -4
  23. package/esm/shuvi-app/react/view/ReactView.server.jsx +17 -14
  24. package/esm/shuvi-app/shuvi-runtime-index.d.ts +3 -3
  25. package/lib/node/features/custom-server/index.d.ts +1 -1
  26. package/lib/node/features/custom-server/server.d.ts +1 -1
  27. package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +7 -7
  28. package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +0 -4
  29. package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -2
  30. package/lib/node/features/filesystem-routes/index.d.ts +1 -13
  31. package/lib/node/features/filesystem-routes/index.js +3 -41
  32. package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -2
  33. package/lib/node/features/filesystem-routes/page/routes.js +1 -1
  34. package/lib/node/features/html-render/index.js +1 -1
  35. package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -2
  36. package/lib/node/features/html-render/lib/index.d.ts +0 -1
  37. package/lib/node/features/html-render/lib/index.js +1 -3
  38. package/lib/node/features/html-render/lib/renderToHTML.d.ts +2 -2
  39. package/lib/node/features/html-render/lib/renderToHTML.js +7 -48
  40. package/lib/node/features/html-render/lib/renderer/base.d.ts +6 -6
  41. package/lib/node/features/html-render/lib/renderer/base.js +5 -5
  42. package/lib/node/features/html-render/lib/renderer/index.d.ts +5 -4
  43. package/lib/node/features/html-render/lib/renderer/index.js +69 -6
  44. package/lib/node/features/html-render/lib/renderer/spa.d.ts +2 -2
  45. package/lib/node/features/html-render/lib/renderer/spa.js +4 -6
  46. package/lib/node/features/html-render/lib/renderer/ssr.d.ts +2 -2
  47. package/lib/node/features/html-render/lib/renderer/ssr.js +5 -6
  48. package/lib/node/features/html-render/lib/renderer/types.d.ts +8 -5
  49. package/lib/node/features/html-render/server.d.ts +1 -1
  50. package/lib/node/features/index.js +1 -3
  51. package/lib/node/features/model/index.d.ts +1 -13
  52. package/lib/node/features/model/runtime.d.ts +3 -3
  53. package/lib/node/features/model/runtime.js +2 -0
  54. package/lib/node/features/model/shuvi-app.d.ts +2 -2
  55. package/lib/node/features/on-demand-compile-page/index.d.ts +1 -13
  56. package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +3 -3
  57. package/lib/node/paths.js +0 -2
  58. package/lib/node/shuvi-runtime-server.d.ts +18 -0
  59. package/lib/node/shuvi-runtime-server.js +2 -0
  60. package/lib/node/shuvi-type-extensions-node.d.ts +0 -6
  61. package/lib/node/targets/react/bundler/index.d.ts +1 -13
  62. package/lib/node/targets/react/index.d.ts +2 -26
  63. package/lib/node/targets/react/index.js +2 -2
  64. package/lib/node/targets/react/model/index.d.ts +6 -0
  65. package/lib/node/targets/react/{redox-react → model}/index.js +7 -6
  66. package/lib/shared/appTypes.d.ts +4 -2
  67. package/lib/shared/renderTypes.d.ts +6 -5
  68. package/lib/shared/routeTypes.d.ts +4 -9
  69. package/package.json +14 -14
  70. package/esm/shuvi-app/react/redox-react/runtime.d.ts +0 -8
  71. package/esm/shuvi-app/shuvi-runtime-server.d.ts +0 -6
  72. package/esm/shuvi-app/shuvi-runtime-server.js +0 -1
  73. package/lib/node/features/webpack-watch-wait-for-file-builder/index.d.ts +0 -16
  74. package/lib/node/features/webpack-watch-wait-for-file-builder/index.js +0 -25
  75. package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.d.ts +0 -12
  76. package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.js +0 -32
  77. package/lib/node/targets/react/redox-react/index.d.ts +0 -18
@@ -13,14 +13,54 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
16
25
  Object.defineProperty(exports, "__esModule", { value: true });
17
26
  exports.Renderer = void 0;
18
27
  const resources_1 = require("@shuvi/service/lib/resources");
28
+ const shared_1 = require("@shuvi/platform-shared/shared");
19
29
  const htmlTag_1 = require("./htmlTag");
20
30
  const viewTemplate_1 = require("../viewTemplate");
21
31
  const spa_1 = require("./spa");
22
32
  const ssr_1 = require("./ssr");
33
+ const htmlTag_2 = require("./htmlTag");
23
34
  __exportStar(require("./types"), exports);
35
+ function addEssentialTagsIfMissing(document) {
36
+ let hasMetaCharset = false;
37
+ let hasMetaViewport = false;
38
+ for (const { tagName, attrs } of document.headTags) {
39
+ if (hasMetaCharset && hasMetaViewport) {
40
+ break;
41
+ }
42
+ if (tagName === 'meta') {
43
+ if (attrs.charset) {
44
+ hasMetaCharset = true;
45
+ }
46
+ else if (attrs.name === 'viewport') {
47
+ hasMetaViewport = true;
48
+ }
49
+ }
50
+ }
51
+ if (!hasMetaCharset) {
52
+ document.headTags.unshift((0, htmlTag_2.tag)('meta', {
53
+ charset: 'utf-8'
54
+ }));
55
+ }
56
+ if (!hasMetaViewport) {
57
+ document.headTags.unshift((0, htmlTag_2.tag)('meta', {
58
+ name: 'viewport',
59
+ content: 'width=device-width,minimum-scale=1,initial-scale=1'
60
+ }));
61
+ }
62
+ return document;
63
+ }
24
64
  class Renderer {
25
65
  constructor(options) {
26
66
  this._serverPluginContext = options.serverPluginContext;
@@ -28,13 +68,36 @@ class Renderer {
28
68
  this._ssrRenderer = new ssr_1.SsrRenderer(options);
29
69
  this._spaRenderer = new spa_1.SpaRenderer(options);
30
70
  }
31
- renderDocument(options) {
32
- if (this._serverPluginContext.config.ssr) {
33
- return this._ssrRenderer.renderDocument(options);
34
- }
35
- return this._spaRenderer.renderDocument(options);
71
+ renderView(options) {
72
+ var _a, _b;
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ let result;
75
+ const { app } = options;
76
+ const doc = yield this._renderDocument(options);
77
+ if ((0, shared_1.isResponse)(doc)) {
78
+ result = doc;
79
+ }
80
+ else {
81
+ addEssentialTagsIfMissing(doc);
82
+ yield this._serverPluginContext.serverPluginRunner.modifyHtml(doc, app.context);
83
+ const htmlStr = this._renderDocumentToString(doc);
84
+ result = (0, shared_1.text)(htmlStr, {
85
+ status: (_b = (_a = app.error) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : 200
86
+ });
87
+ }
88
+ return result;
89
+ });
90
+ }
91
+ _renderDocument(options) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ // todo: fallback to spa
94
+ if (options.ssr) {
95
+ return yield this._ssrRenderer.renderDocument(options);
96
+ }
97
+ return yield this._spaRenderer.renderDocument(options);
98
+ });
36
99
  }
37
- renderDocumentToString(document, templateData = {}) {
100
+ _renderDocumentToString(document, templateData = {}) {
38
101
  const htmlAttrs = (0, htmlTag_1.stringifyAttrs)(document.htmlAttrs);
39
102
  const head = document.headTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
40
103
  const main = document.mainTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
@@ -1,5 +1,5 @@
1
1
  import { BaseRenderer } from './base';
2
- import { IRenderDocumentOptions, IHtmlDocument } from './types';
2
+ import { IRenderViewOptions, IHtmlDocument } from './types';
3
3
  export declare class SpaRenderer extends BaseRenderer {
4
- renderDocument({ app }: IRenderDocumentOptions): IHtmlDocument;
4
+ renderDocument({ req, app }: IRenderViewOptions): IHtmlDocument;
5
5
  }
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SpaRenderer = void 0;
4
4
  const base_1 = require("./base");
5
5
  class SpaRenderer extends base_1.BaseRenderer {
6
- renderDocument({ app }) {
7
- const assets = this._getMainAssetTags();
8
- const serverPluginContext = this._serverPluginContext;
6
+ renderDocument({ req, app }) {
7
+ const assets = this._getMainAssetTags(req);
9
8
  const appData = {
10
- pageData: {},
11
- ssr: serverPluginContext.config.ssr,
12
- loadersData: {}
9
+ ssr: false,
10
+ pageData: {}
13
11
  };
14
12
  const document = {
15
13
  htmlAttrs: {},
@@ -1,5 +1,5 @@
1
1
  import { BaseRenderer } from './base';
2
- import { IHtmlDocument, IRenderDocumentOptions } from './types';
2
+ import { IHtmlDocument, IRenderViewOptions } from './types';
3
3
  export declare class SsrRenderer extends BaseRenderer {
4
- renderDocument({ app, req }: IRenderDocumentOptions): Promise<import("@shuvi/platform-shared/shared").Response | IHtmlDocument>;
4
+ renderDocument({ app, req, isDev }: IRenderViewOptions): Promise<import("@shuvi/platform-shared/shared").Response | IHtmlDocument>;
5
5
  }
@@ -17,12 +17,11 @@ const resources_1 = require("@shuvi/service/lib/resources");
17
17
  const base_1 = require("./base");
18
18
  const htmlTag_1 = require("./htmlTag");
19
19
  class SsrRenderer extends base_1.BaseRenderer {
20
- renderDocument({ app, req }) {
20
+ renderDocument({ app, req, isDev }) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
- const { router, context } = app;
22
+ const { store, router, context } = app;
23
23
  const serverPluginContext = this._serverPluginContext;
24
24
  const { view } = resources_1.server;
25
- const { getAssetPublicUrl } = serverPluginContext;
26
25
  if (!router) {
27
26
  throw new Error('router is null');
28
27
  }
@@ -30,18 +29,18 @@ class SsrRenderer extends base_1.BaseRenderer {
30
29
  app,
31
30
  req,
32
31
  manifest: resources_1.clientManifest,
33
- getAssetPublicUrl
32
+ isDev
34
33
  });
35
34
  if ((0, shared_1.isResponse)(result)) {
36
35
  return result;
37
36
  }
38
- const mainAssetsTags = this._getMainAssetTags();
37
+ const mainAssetsTags = this._getMainAssetTags(req);
39
38
  const pageDataList = yield serverPluginContext.serverPluginRunner.getPageData(context);
40
39
  const pageData = pageDataList.reduce((acc, data) => {
41
40
  Object.assign(acc, data);
42
41
  return acc;
43
42
  }, {});
44
- const appData = Object.assign(Object.assign({}, result.appData), { pageData, ssr: serverPluginContext.config.ssr });
43
+ const appData = Object.assign(Object.assign({}, result.appData), { ssr: true, appState: store.getState(), pageData });
45
44
  appData.runtimeConfig = (0, shuvi_singleton_runtimeConfig_1.getPublicRuntimeConfig)() || {};
46
45
  const document = {
47
46
  htmlAttrs: Object.assign({}, result.htmlAttrs),
@@ -1,20 +1,23 @@
1
- import { IApplication, IRequest } from '@shuvi/platform-shared/shared';
1
+ import { IApplication, Response } from '@shuvi/platform-shared/shared';
2
+ import { ShuviRequest, IServerPluginContext } from '@shuvi/service';
2
3
  import { IHtmlAttrs, IHtmlTag, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer, IRenderAppServerResult } from '../../../../../shared';
3
- import { IServerPluginContext } from '@shuvi/service';
4
4
  export { IHtmlAttrs, IHtmlTag, IApplication };
5
5
  export interface IRendererConstructorOptions {
6
6
  serverPluginContext: IServerPluginContext;
7
7
  }
8
- export declare type IRenderDocumentOptions = {
8
+ export declare type IRenderViewOptions = {
9
9
  app: IApplication;
10
- req: IRequest;
10
+ req: ShuviRequest;
11
+ ssr: boolean;
12
+ isDev: boolean;
11
13
  };
14
+ export declare type IRenderDocumentResult = Promise<IHtmlDocument | Response> | IHtmlDocument | Response;
12
15
  export interface IHtmlDocument {
13
16
  htmlAttrs: IHtmlAttrs;
14
17
  headTags: IHtmlTag<'meta' | 'link' | 'style' | 'script' | 'noscript' | 'title'>[];
15
18
  mainTags: IHtmlTag[];
16
19
  scriptTags: IHtmlTag<'script'>[];
17
20
  }
18
- export interface IRenderOptions extends IRenderDocumentOptions {
21
+ export interface IRenderOptions extends IRenderViewOptions {
19
22
  }
20
23
  export { IRenderAppServerResult, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer };
@@ -1,2 +1,2 @@
1
- declare const _default: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/service/lib/server/pluginTypes").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
1
+ declare const _default: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").ServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
2
2
  export default _default;
@@ -9,7 +9,6 @@ const html_render_1 = require("./html-render");
9
9
  const custom_server_1 = __importDefault(require("./custom-server"));
10
10
  const model_1 = __importDefault(require("./model"));
11
11
  const filesystem_routes_1 = __importDefault(require("./filesystem-routes"));
12
- const webpack_watch_wait_for_file_builder_1 = __importDefault(require("./webpack-watch-wait-for-file-builder"));
13
12
  var buildHtml_1 = require("./html-render/lib/buildHtml");
14
13
  Object.defineProperty(exports, "buildHtml", { enumerable: true, get: function () { return buildHtml_1.buildHtml; } });
15
14
  var middlewares_1 = require("./middlewares");
@@ -20,7 +19,6 @@ const getPlugins = (platformContext) => [
20
19
  on_demand_compile_page_1.default,
21
20
  filesystem_routes_1.default,
22
21
  custom_server_1.default,
23
- model_1.default,
24
- webpack_watch_wait_for_file_builder_1.default
22
+ model_1.default
25
23
  ];
26
24
  exports.getPlugins = getPlugins;
@@ -1,17 +1,5 @@
1
1
  declare const _default: {
2
- core: import("@shuvi/hook").IPluginInstance<{
3
- extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
4
- afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
- afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
- afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
7
- afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
8
- afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
9
- configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
10
- addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
11
- addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
12
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
13
- addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
14
- } & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
2
+ core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
15
3
  runtime: {
16
4
  plugin: string;
17
5
  };
@@ -1,8 +1,8 @@
1
- import { IStoreManager } from '@shuvi/redox';
1
+ import { RedoxStore } from '@shuvi/redox';
2
2
  import { IAppContext } from '@shuvi/platform-shared/shared';
3
3
  export declare type InitRedox = (params: {
4
4
  initialState: any;
5
5
  ctx: IAppContext;
6
- }) => IStoreManager;
7
- declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/runtime").CustomRuntimePluginHooks, void>;
6
+ }) => RedoxStore;
7
+ declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").RuntimePluginHooks, void>;
8
8
  export default _default;
@@ -38,4 +38,6 @@ exports.default = (0, shared_1.createRuntimePlugin)({
38
38
  });
39
39
  return ctx;
40
40
  }
41
+ }, {
42
+ name: 'model'
41
43
  });
@@ -1,6 +1,6 @@
1
- import type { IStoreManager } from '@shuvi/redox';
1
+ import type { RedoxStore } from '@shuvi/redox';
2
2
  declare module '@shuvi/runtime' {
3
3
  interface CustomAppContext {
4
- store: IStoreManager;
4
+ store: RedoxStore;
5
5
  }
6
6
  }
@@ -1,17 +1,5 @@
1
1
  declare const _default: {
2
- core: import("@shuvi/hook").IPluginInstance<{
3
- extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
4
- afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
- afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
- afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
7
- afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
8
- afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
9
- configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
10
- addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
11
- addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
12
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
13
- addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
14
- } & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
2
+ core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
15
3
  };
16
4
  export default _default;
17
5
  export { default as OnDemandRouteManager } from './onDemandRouteManager';
@@ -1,11 +1,11 @@
1
- import { IRequestHandlerWithNext, IServerPluginContext } from '@shuvi/service';
1
+ import { ShuviRequestHandler, IServerPluginContext } from '@shuvi/service';
2
2
  import { DevMiddleware } from '@shuvi/service/lib/server/middlewares/dev';
3
3
  export default class OnDemandRouteManager {
4
4
  devMiddleware: DevMiddleware | null;
5
5
  _serverPluginContext: IServerPluginContext;
6
6
  constructor(serverPluginContext: IServerPluginContext);
7
- getServerMiddleware(): IRequestHandlerWithNext;
8
- ensureRoutesMiddleware(): IRequestHandlerWithNext;
7
+ getServerMiddleware(): ShuviRequestHandler;
8
+ ensureRoutesMiddleware(): ShuviRequestHandler;
9
9
  ensureRoutes(pathname: string): Promise<void>;
10
10
  private _activateModules;
11
11
  }
package/lib/node/paths.js CHANGED
@@ -26,8 +26,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.resolvePkgFile = exports.resolveLib = exports.resolveDep = void 0;
27
27
  const path = __importStar(require("path"));
28
28
  const PACKAGE_DIR = path.resolve(__dirname, '..', '..');
29
- // export const resolveToModulePath = (...paths: string[]) =>
30
- // `@shuvi/platform-web/${paths.join('/')}`;
31
29
  const resolveDep = (module) => require.resolve(module);
32
30
  exports.resolveDep = resolveDep;
33
31
  const resolveLib = (module) => path.dirname((0, exports.resolveDep)(path.join(module, 'package.json')));
@@ -0,0 +1,18 @@
1
+ import { IServerModule as _IServerModule } from '../shared/index';
2
+ import { extendedHooks } from './features/html-render/serverHooks';
3
+ declare type Head<T extends any[]> = T extends [...infer Head, any] ? Head : never;
4
+ declare type RemoveLast<T extends (...args: any) => any> = (...args: Head<Parameters<T>>) => ReturnType<T>;
5
+ declare global {
6
+ namespace ShuviService {
7
+ interface CustomServerPluginHooks {
8
+ getPageData: typeof extendedHooks.getPageData;
9
+ handlePageRequest: typeof extendedHooks.handlePageRequest;
10
+ modifyHtml: typeof extendedHooks.modifyHtml;
11
+ }
12
+ }
13
+ }
14
+ declare type ServerModule = Required<_IServerModule>;
15
+ export declare type GetPageDataFunction = RemoveLast<ServerModule['getPageData']>;
16
+ export declare type HandlePageRequestFunction = RemoveLast<ServerModule['handlePageRequest']>;
17
+ export declare type ModifyHtmlFunction = RemoveLast<ServerModule['modifyHtml']>;
18
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,7 +4,6 @@ import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
4
4
  import { IMiddlewareRoutes, CreateAppServer, IApiRoutes, IServerModule, PlatformWebCustomConfig } from '../shared/index';
5
5
  import { IViewServer } from './features/html-render/index';
6
6
  import { addRoutes, addMiddlewareRoutes } from './features/filesystem-routes/hooks';
7
- import { extendedHooks } from './features/html-render/serverHooks';
8
7
  export {};
9
8
  declare module '@shuvi/service/lib/resources' {
10
9
  const server: {
@@ -35,10 +34,5 @@ declare global {
35
34
  addRoutes: typeof addRoutes;
36
35
  addMiddlewareRoutes: typeof addMiddlewareRoutes;
37
36
  }
38
- interface CustomServerPluginHooks {
39
- getPageData: typeof extendedHooks.getPageData;
40
- handlePageRequest: typeof extendedHooks.handlePageRequest;
41
- modifyHtml: typeof extendedHooks.modifyHtml;
42
- }
43
37
  }
44
38
  }
@@ -1,16 +1,4 @@
1
1
  declare const _default: {
2
- core: import("@shuvi/hook").IPluginInstance<{
3
- extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
4
- afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
- afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
- afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
7
- afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
8
- afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
9
- configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
10
- addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
11
- addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
12
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
13
- addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
14
- } & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
2
+ core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
15
3
  };
16
4
  export default _default;
@@ -1,30 +1,6 @@
1
1
  declare const platformWebReact: () => {
2
- plugins: (import("@shuvi/hook").IPluginInstance<{
3
- extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
4
- afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
- afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
- afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
7
- afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
8
- afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
9
- configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
10
- addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
11
- addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
12
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
13
- addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
14
- } & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext> | {
15
- core: import("@shuvi/hook").IPluginInstance<{
16
- extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
17
- afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
18
- afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
19
- afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
20
- afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
21
- afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
22
- configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
23
- addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
24
- addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
25
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
26
- addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
27
- } & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
2
+ plugins: (import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext> | {
3
+ core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
28
4
  })[];
29
5
  platformModule: string;
30
6
  polyfills: string[];
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const service_1 = require("@shuvi/service");
7
7
  const bundler_1 = __importDefault(require("./bundler"));
8
- const redox_react_1 = require("./redox-react");
8
+ const model_1 = require("./model");
9
9
  const paths_1 = require("../../paths");
10
10
  const webReactMainPlugin = (0, service_1.createPlugin)({
11
11
  addRuntimeService: () => [
@@ -17,7 +17,7 @@ const webReactMainPlugin = (0, service_1.createPlugin)({
17
17
  });
18
18
  const platformWebReact = () => {
19
19
  return {
20
- plugins: [webReactMainPlugin, bundler_1.default, redox_react_1.RedoxReactPlugin],
20
+ plugins: [webReactMainPlugin, bundler_1.default, model_1.ModelReactPlugin],
21
21
  platformModule: (0, paths_1.resolvePkgFile)('esm/shuvi-app/react/index'),
22
22
  polyfills: [
23
23
  (0, paths_1.resolveDep)('react-app-polyfill/ie11'),
@@ -0,0 +1,6 @@
1
+ export declare const ModelReactPlugin: {
2
+ core: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/core/plugin").PluginHooks, import("@shuvi/service").IPluginContext>;
3
+ runtime: {
4
+ plugin: string;
5
+ };
6
+ };
@@ -23,13 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.RedoxReactPlugin = void 0;
26
+ exports.ModelReactPlugin = void 0;
27
27
  const path = __importStar(require("path"));
28
28
  const service_1 = require("@shuvi/service");
29
29
  const paths_1 = require("../../../paths");
30
- // todo: optimize this
31
- const runtimePath = require.resolve(path.join(__dirname, '../../../../../esm/shuvi-app/react/redox-react/runtime'));
32
- const core = (0, service_1.createPlugin)({
30
+ const core = (0, service_1.createPluginAfter)({
33
31
  addRuntimeService: () => [
34
32
  {
35
33
  source: path.dirname(require.resolve('@shuvi/redox-react/package.json')),
@@ -41,10 +39,13 @@ const core = (0, service_1.createPlugin)({
41
39
  config.resolve.alias.set('@shuvi/redox', (0, paths_1.resolveLib)('@shuvi/redox'));
42
40
  return config;
43
41
  }
42
+ }, {
43
+ name: 'model-react'
44
44
  });
45
- exports.RedoxReactPlugin = {
45
+ exports.ModelReactPlugin = {
46
46
  core,
47
47
  runtime: {
48
- plugin: runtimePath
48
+ // this need
49
+ plugin: (0, paths_1.resolvePkgFile)('esm/shuvi-app/react/model/runtime')
49
50
  }
50
51
  };
@@ -1,9 +1,11 @@
1
- import { IRequest, IPageRouteRecord, IAppData, IAppState } from '@shuvi/platform-shared/shared';
1
+ import { IPageRouteRecord, IAppData, IAppState } from '@shuvi/platform-shared/shared';
2
2
  import { Application } from '@shuvi/platform-shared/shuvi-app/application';
3
+ import type { ShuviRequest } from '@shuvi/service';
3
4
  export interface CreateAppServer {
4
5
  (options: {
5
- req: IRequest;
6
+ req: ShuviRequest;
6
7
  ssr: boolean;
8
+ isDev: boolean;
7
9
  }): Application;
8
10
  }
9
11
  export interface CreateAppClient {
@@ -1,10 +1,10 @@
1
1
  import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
2
- import { Response, IApplication, IRequest, IAppData } from '@shuvi/platform-shared/shared';
3
- export declare type IRenderDocumentOptions = {
2
+ import type { ShuviRequest } from '@shuvi/service';
3
+ import { Response, IApplication, IAppData } from '@shuvi/platform-shared/shared';
4
+ export declare type IRenderViewOptions = {
4
5
  app: IApplication;
5
- req?: IRequest;
6
6
  };
7
- export interface IRenderOptions extends IRenderDocumentOptions {
7
+ export interface IRenderOptions extends IRenderViewOptions {
8
8
  }
9
9
  export interface IView<RenderOption extends IRenderOptions = any, RenderResult = void> {
10
10
  renderApp(options: RenderOption): RenderResult;
@@ -35,8 +35,9 @@ export interface IClientRendererOptions<ExtraAppData = {}> extends IRenderOption
35
35
  appData: IAppData<ExtraAppData>;
36
36
  }
37
37
  export interface IServerRendererOptions extends IRenderOptions {
38
+ req: ShuviRequest;
38
39
  manifest: IManifest;
39
- getAssetPublicUrl(path: string): string;
40
+ isDev?: boolean;
40
41
  }
41
42
  export interface IViewClient<ExtraAppData = {}> extends IView<IClientRendererOptions<ExtraAppData>> {
42
43
  }
@@ -1,10 +1,5 @@
1
- import { IURLParams, IURLQuery } from '@shuvi/platform-shared/shared';
2
- import { IRequestHandlerWithNext } from '@shuvi/service';
3
- import { IResponse, IRequest } from '@shuvi/service';
1
+ import { ShuviRequest, ShuviResponse, ShuviRequestHandler } from '@shuvi/service';
4
2
  export interface IApiReq {
5
- pathname: string;
6
- query: IURLQuery;
7
- params: IURLParams;
8
3
  cookies: {
9
4
  [key: string]: string;
10
5
  };
@@ -12,7 +7,7 @@ export interface IApiReq {
12
7
  [key: string]: any;
13
8
  };
14
9
  }
15
- export declare type IApiRequest = IRequest & IApiReq;
10
+ export declare type IApiRequest = ShuviRequest & IApiReq;
16
11
  export declare type Send<T> = (body: T) => void;
17
12
  export declare type IApiRes<T = any> = {
18
13
  send: Send<T>;
@@ -21,7 +16,7 @@ export declare type IApiRes<T = any> = {
21
16
  redirect(url: string): IApiRes<T>;
22
17
  redirect(status: number, url: string): IApiRes<T>;
23
18
  };
24
- export declare type IApiResponse<T = any> = IResponse & IApiRes<T>;
19
+ export declare type IApiResponse<T = any> = ShuviResponse & IApiRes<T>;
25
20
  export declare type IApiRequestHandler<T = any> = (req: IApiRequest, res: IApiResponse<T>) => void | Promise<void>;
26
21
  export interface IApiConfig {
27
22
  api?: {
@@ -35,7 +30,7 @@ export interface IApiHandler {
35
30
  config?: IApiConfig;
36
31
  }
37
32
  export interface IMiddlewareConfig {
38
- default: IRequestHandlerWithNext;
33
+ default: ShuviRequestHandler;
39
34
  }
40
35
  export declare type IApiRoutes = {
41
36
  path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "1.0.0-rc.4",
3
+ "version": "1.0.0-rc.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -65,17 +65,18 @@
65
65
  },
66
66
  "dependencies": {
67
67
  "@next/react-refresh-utils": "12.1.6",
68
- "@shuvi/hook": "1.0.0-rc.4",
69
- "@shuvi/platform-shared": "1.0.0-rc.4",
70
- "@shuvi/redox": "0.0.3",
71
- "@shuvi/redox-react": "0.0.3",
72
- "@shuvi/router": "1.0.0-rc.4",
73
- "@shuvi/router-react": "1.0.0-rc.4",
74
- "@shuvi/runtime": "1.0.0-rc.4",
75
- "@shuvi/service": "1.0.0-rc.4",
76
- "@shuvi/shared": "1.0.0-rc.4",
77
- "@shuvi/toolpack": "1.0.0-rc.4",
78
- "@shuvi/utils": "1.0.0-rc.4",
68
+ "@shuvi/hook": "1.0.0-rc.7",
69
+ "@shuvi/platform-shared": "1.0.0-rc.7",
70
+ "@shuvi/redox": "0.0.6",
71
+ "@shuvi/redox-react": "0.0.6",
72
+ "@shuvi/router": "1.0.0-rc.7",
73
+ "@shuvi/router-react": "1.0.0-rc.7",
74
+ "@shuvi/runtime": "1.0.0-rc.7",
75
+ "@shuvi/service": "1.0.0-rc.7",
76
+ "@shuvi/shared": "1.0.0-rc.7",
77
+ "@shuvi/toolpack": "1.0.0-rc.7",
78
+ "@shuvi/utils": "1.0.0-rc.7",
79
+ "@shuvi/error-overlay": "1.0.0-rc.7",
79
80
  "content-type": "1.0.4",
80
81
  "cookie": "0.4.1",
81
82
  "ejs": "3.1.5",
@@ -91,13 +92,12 @@
91
92
  "use-sync-external-store": "1.1.0"
92
93
  },
93
94
  "peerDependencies": {
94
- "@shuvi/service": "1.0.0-rc.4"
95
+ "@shuvi/service": "1.0.0-rc.7"
95
96
  },
96
97
  "devDependencies": {
97
98
  "@types/react": "18.0.9",
98
99
  "@types/react-dom": "18.0.6",
99
100
  "@types/react-test-renderer": "18.0.0",
100
- "@shuvi/redox": "0.0.3",
101
101
  "@testing-library/react": "^13.2.0",
102
102
  "@types/content-type": "^1.1.5",
103
103
  "@types/cookie": "^0.4.1",