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

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 (96) hide show
  1. package/esm/shared/appTypes.d.ts +2 -2
  2. package/esm/shared/configTypes.d.ts +14 -0
  3. package/esm/shared/configTypes.js +1 -0
  4. package/esm/shared/index.d.ts +1 -0
  5. package/esm/shared/index.js +1 -0
  6. package/esm/shared/routeTypes.d.ts +1 -1
  7. package/esm/shuvi-app/app/client.d.ts +2 -0
  8. package/esm/shuvi-app/app/client.js +2 -1
  9. package/esm/shuvi-app/dev/eventsource.d.ts +1 -0
  10. package/esm/shuvi-app/dev/eventsource.js +60 -0
  11. package/esm/shuvi-app/dev/hotDevClient.d.ts +33 -0
  12. package/esm/shuvi-app/dev/hotDevClient.js +348 -0
  13. package/esm/shuvi-app/dev/index.d.ts +3 -0
  14. package/esm/shuvi-app/dev/index.js +27 -0
  15. package/esm/shuvi-app/dev/websocket.d.ts +17 -0
  16. package/esm/shuvi-app/dev/websocket.js +61 -0
  17. package/esm/shuvi-app/entry/client/app.d.ts +2 -1
  18. package/esm/shuvi-app/entry/client/app.js +2 -2
  19. package/esm/shuvi-app/entry/client/run.dev.js +4 -4
  20. package/esm/shuvi-app/entry/server/index.d.ts +5 -4
  21. package/esm/shuvi-app/entry/server/index.js +5 -4
  22. package/esm/shuvi-app/react/getRoutes.d.ts +2 -2
  23. package/esm/shuvi-app/react/getRoutes.js +6 -7
  24. package/{lib/node/targets → esm/shuvi-app}/react/redox-react/RedoxWrapper.d.ts +0 -0
  25. package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +11 -0
  26. package/{lib/node/targets → esm/shuvi-app}/react/redox-react/runtime.d.ts +6 -0
  27. package/{lib/node/targets → esm/shuvi-app}/react/redox-react/runtime.js +6 -6
  28. package/esm/shuvi-app/shuvi-runtime-index.js +1 -1
  29. package/lib/node/features/custom-server/index.d.ts +1 -13
  30. package/lib/node/features/custom-server/index.js +0 -17
  31. package/lib/node/features/custom-server/server.d.ts +1 -1
  32. package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +1 -0
  33. package/lib/node/features/filesystem-routes/api/middleware.d.ts +1 -1
  34. package/lib/node/features/filesystem-routes/api/middleware.js +3 -5
  35. package/lib/node/features/filesystem-routes/hooks.d.ts +2 -2
  36. package/lib/node/features/filesystem-routes/index.d.ts +4 -4
  37. package/lib/node/features/filesystem-routes/index.js +20 -12
  38. package/lib/node/features/filesystem-routes/page/index.d.ts +1 -1
  39. package/lib/node/features/filesystem-routes/page/routes.d.ts +6 -6
  40. package/lib/node/features/filesystem-routes/page/routes.js +29 -11
  41. package/lib/node/features/filesystem-routes/page/store.d.ts +3 -3
  42. package/lib/node/features/html-render/index.d.ts +3 -17
  43. package/lib/node/features/html-render/index.js +87 -16
  44. package/lib/node/features/{main → html-render/lib}/buildHtml.d.ts +0 -0
  45. package/lib/node/features/{main → html-render/lib}/buildHtml.js +0 -0
  46. package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +2 -2
  47. package/lib/node/features/html-render/lib/generateFilesByRoutId.js +3 -3
  48. package/lib/node/features/{main → html-render/lib}/generateResource.d.ts +0 -0
  49. package/lib/node/features/{main → html-render/lib}/generateResource.js +10 -12
  50. package/lib/node/features/html-render/server.d.ts +1 -1
  51. package/lib/node/features/html-render/serverHooks.d.ts +1 -0
  52. package/lib/node/features/html-render/shuvi-app.d.ts +1 -6
  53. package/lib/node/features/index.d.ts +3 -42
  54. package/lib/node/features/index.js +9 -8
  55. package/lib/node/features/middlewares.d.ts +1 -1
  56. package/lib/node/features/middlewares.js +5 -4
  57. package/lib/node/features/model/index.d.ts +3 -2
  58. package/lib/node/features/model/runtime.js +11 -17
  59. package/lib/node/features/model/server.js +2 -3
  60. package/lib/node/features/model/shuvi-app.d.ts +1 -1
  61. package/lib/node/features/on-demand-compile-page/index.d.ts +15 -12
  62. package/lib/node/features/on-demand-compile-page/index.js +4 -1
  63. package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +2 -4
  64. package/lib/node/features/webpack-watch-wait-for-file-builder/index.d.ts +16 -0
  65. package/lib/node/features/webpack-watch-wait-for-file-builder/index.js +25 -0
  66. package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.d.ts +12 -0
  67. package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.js +32 -0
  68. package/lib/node/index.d.ts +4 -2
  69. package/lib/node/index.js +2 -5
  70. package/lib/node/paths.js +26 -6
  71. package/lib/node/shuvi-type-extensions-node.d.ts +44 -0
  72. package/lib/node/{shuvi-node-extensions.js → shuvi-type-extensions-node.js} +1 -0
  73. package/lib/node/targets/react/bundler/index.d.ts +3 -2
  74. package/lib/node/targets/react/bundler/index.js +5 -0
  75. package/lib/node/targets/react/index.d.ts +6 -4
  76. package/lib/node/targets/react/redox-react/index.d.ts +3 -2
  77. package/lib/node/targets/react/redox-react/index.js +1 -1
  78. package/lib/shared/appTypes.d.ts +2 -2
  79. package/lib/shared/configTypes.d.ts +14 -0
  80. package/lib/{node/features/filesystem-routes/shuvi-app.js → shared/configTypes.js} +0 -0
  81. package/lib/shared/index.d.ts +1 -0
  82. package/lib/shared/index.js +1 -0
  83. package/lib/shared/routeTypes.d.ts +1 -1
  84. package/package.json +40 -25
  85. package/shuvi-env.d.ts +10 -0
  86. package/shuvi-image.d.ts +54 -0
  87. package/shuvi-type-extensions-node.d.ts +2 -0
  88. package/shuvi-type-extensions-node.js +1 -0
  89. package/{shuvi-app-extensions.d.ts → shuvi-type-extensions-runtime.d.ts} +7 -7
  90. package/esm/shuvi-app/dev/webpackHotDevClient.d.ts +0 -5
  91. package/esm/shuvi-app/dev/webpackHotDevClient.js +0 -33
  92. package/lib/node/features/filesystem-routes/shuvi-app.d.ts +0 -7
  93. package/lib/node/features/main/index.d.ts +0 -3
  94. package/lib/node/features/main/index.js +0 -82
  95. package/lib/node/shuvi-node-extensions.d.ts +0 -17
  96. package/lib/node/targets/react/redox-react/RedoxWrapper.js +0 -37
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  /// <reference lib="dom" />
11
11
  import { DEV_STYLE_HIDE_FOUC, DEV_STYLE_PREPARE } from '@shuvi/shared/lib/constants';
12
- import initWebpackHMR from '../../dev/webpackHotDevClient';
13
- import { run } from './app';
12
+ import { initHMRAndDevClient } from '../../dev';
13
+ import { run, app } from './app';
14
14
  function init() {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
- initWebpackHMR();
16
+ initHMRAndDevClient(app);
17
17
  // reduce FOUC caused by style-loader
18
18
  const styleReady = new Promise(resolve => {
19
19
  (window.requestAnimationFrame || setTimeout)(() => __awaiter(this, void 0, void 0, function* () {
@@ -27,4 +27,4 @@ function init() {
27
27
  yield styleReady;
28
28
  });
29
29
  }
30
- init().then(run);
30
+ init().then(() => run());
@@ -1,6 +1,7 @@
1
- import * as application from '../../app/server';
2
- import * as server from '@shuvi/app/files/user/server';
1
+ import { default as pageRoutes } from '@shuvi/app/files/routes';
3
2
  import { default as apiRoutes } from '@shuvi/app/files/apiRoutes';
4
3
  import { default as middlewareRoutes } from '@shuvi/app/files/middlewareRoutes';
5
- export { server, application, apiRoutes, middlewareRoutes };
6
- export { view } from '@shuvi/app/core/platform';
4
+ import { view } from '@shuvi/app/core/platform';
5
+ import * as server from '@shuvi/app/user/server';
6
+ import * as application from '../../app/server';
7
+ export { pageRoutes, apiRoutes, middlewareRoutes, server, view, application };
@@ -1,7 +1,8 @@
1
1
  // This is the shuvi server-side main module exports collection
2
- import * as application from '../../app/server';
3
- import * as server from '@shuvi/app/files/user/server';
2
+ import { default as pageRoutes } from '@shuvi/app/files/routes';
4
3
  import { default as apiRoutes } from '@shuvi/app/files/apiRoutes';
5
4
  import { default as middlewareRoutes } from '@shuvi/app/files/middlewareRoutes';
6
- export { server, application, apiRoutes, middlewareRoutes };
7
- export { view } from '@shuvi/app/core/platform';
5
+ import { view } from '@shuvi/app/core/platform';
6
+ import * as server from '@shuvi/app/user/server';
7
+ import * as application from '../../app/server';
8
+ export { pageRoutes, apiRoutes, middlewareRoutes, server, view, application };
@@ -1,2 +1,2 @@
1
- import { IPageRouteRecord, IRawPageRouteRecord } from '@shuvi/platform-shared/shared';
2
- export default function getRoutes(routes: IRawPageRouteRecord[]): IPageRouteRecord[];
1
+ import { IPageRouteRecord } from '@shuvi/platform-shared/shared';
2
+ export default function getRoutes(routes: IPageRouteRecord[]): IPageRouteRecord[];
@@ -13,18 +13,17 @@ import { loadRouteComponent } from './loadRouteComponent';
13
13
  export default function getRoutes(routes) {
14
14
  const getRoutesWithRequire = (routes) => routes.map(x => {
15
15
  const originalRoute = Object.assign({}, x);
16
- const { __componentSource__, __componentSourceWithAffix__, __import__, __resolveWeak__, children } = originalRoute, rest = __rest(originalRoute, ["__componentSource__", "__componentSourceWithAffix__", "__import__", "__resolveWeak__", "children"]);
16
+ const { __componentRawRequest__, __import__, __resolveWeak__, children } = originalRoute, rest = __rest(originalRoute, ["__componentRawRequest__", "__import__", "__resolveWeak__", "children"]);
17
17
  const route = Object.assign({}, rest);
18
18
  if (children) {
19
19
  route.children = getRoutesWithRequire(children);
20
20
  }
21
- if (__componentSourceWithAffix__ && __import__) {
22
- route.component = loadRouteComponent(__import__, {
23
- webpack: __resolveWeak__,
24
- modules: [__componentSourceWithAffix__]
25
- });
21
+ if (__import__) {
22
+ route.component = loadRouteComponent(__import__, Object.assign({ webpack: __resolveWeak__ }, (__componentRawRequest__ && {
23
+ modules: [__componentRawRequest__]
24
+ })));
26
25
  }
27
- return Object.assign({ __componentSourceWithAffix__, __resolveWeak__ }, route);
26
+ return Object.assign({ __componentRawRequest__, __resolveWeak__ }, route);
28
27
  });
29
28
  const routesWithRequire = getRoutesWithRequire(routes || []);
30
29
  return routesWithRequire;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { RedoxRoot } from '@shuvi/redox-react';
3
+ export const RedoxWrapper = (App, appContext) => {
4
+ function RedoxAppWrapper(appProps) {
5
+ return (<RedoxRoot storeManager={appContext.storeManager}>
6
+ <App {...appProps}/>
7
+ </RedoxRoot>);
8
+ }
9
+ RedoxAppWrapper.displayName = 'RedoxAppWrapper';
10
+ return RedoxAppWrapper;
11
+ };
@@ -1,2 +1,8 @@
1
+ import { IStoreManager } from '@shuvi/redox';
2
+ declare module '@shuvi/runtime' {
3
+ interface CustomAppContext {
4
+ store: IStoreManager;
5
+ }
6
+ }
1
7
  declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/runtime").CustomRuntimePluginHooks, void>;
2
8
  export default _default;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -8,11 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
8
  });
10
9
  };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const shared_1 = require("@shuvi/platform-shared/shared");
13
- const RedoxWrapper_1 = require("./RedoxWrapper");
14
- exports.default = (0, shared_1.createRuntimePlugin)({
10
+ import { createRuntimePlugin } from '@shuvi/platform-shared/shared';
11
+ import { RedoxWrapper } from './RedoxWrapper';
12
+ export default createRuntimePlugin({
15
13
  appComponent: (App, appContext) => __awaiter(void 0, void 0, void 0, function* () {
16
- return (0, RedoxWrapper_1.RedoxWrapper)(App, appContext);
14
+ return RedoxWrapper(App, {
15
+ storeManager: appContext.store
16
+ });
17
17
  })
18
18
  });
@@ -1,2 +1,2 @@
1
- // exported by @shuvi/runtme
1
+ // exported by @shuvi/runtime
2
2
  export {};
@@ -1,16 +1,4 @@
1
1
  declare const _default: {
2
- core: import("@shuvi/hook").IPluginInstance<{
3
- afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
4
- afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
5
- afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
6
- afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
7
- afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
8
- configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
9
- addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
10
- addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
11
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
12
- addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
13
- } & import("@shuvi/runtime").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
14
- server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/runtime").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
2
+ server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/service/lib/server/pluginTypes").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
15
3
  };
16
4
  export default _default;
@@ -3,24 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const service_1 = require("@shuvi/service");
7
- const file_utils_1 = require("@shuvi/service/lib/project/file-utils");
8
6
  const server_1 = __importDefault(require("./server"));
9
- const core = (0, service_1.createPlugin)({
10
- addRuntimeFile: ({ defineFile }, context) => {
11
- const { paths } = context;
12
- const serverCandidates = (0, file_utils_1.getUserCustomFileCandidates)(paths.rootDir, 'server', 'noop');
13
- const userServerFile = defineFile({
14
- name: 'user/server.js',
15
- content: () => {
16
- return (0, file_utils_1.getFirstModuleExport)((0, file_utils_1.getAllFiles)(serverCandidates), serverCandidates);
17
- },
18
- dependencies: serverCandidates
19
- });
20
- return [userServerFile];
21
- }
22
- });
23
7
  exports.default = {
24
- core,
25
8
  server: server_1.default
26
9
  };
@@ -1,2 +1,2 @@
1
- declare const _default: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/runtime").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
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>;
2
2
  export default _default;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { IncomingMessage } from 'http';
2
3
  import { IResponse, IRequest } from '@shuvi/service';
3
4
  import { IApiRequestHandler, IApiResponse } from '../../../../shared';
@@ -1,2 +1,2 @@
1
1
  import { IServerPluginContext, IRequestHandlerWithNext } from '@shuvi/service';
2
- export declare function middleware(ctx: IServerPluginContext): IRequestHandlerWithNext;
2
+ export declare function middleware(_ctx: IServerPluginContext): IRequestHandlerWithNext;
@@ -13,11 +13,10 @@ exports.middleware = void 0;
13
13
  const router_1 = require("@shuvi/router");
14
14
  const resources_1 = require("@shuvi/service/lib/resources");
15
15
  const apiRouteHandler_1 = require("./apiRouteHandler");
16
- function middleware(ctx) {
16
+ function middleware(_ctx) {
17
17
  return function (req, res, next) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  const { apiRoutes } = resources_1.server;
20
- const commonApiConfig = ctx.config.apiConfig || {};
21
20
  let tempApiModule;
22
21
  for (const { path, api } of apiRoutes) {
23
22
  const match = (0, router_1.matchPathname)(path, req.pathname);
@@ -29,9 +28,8 @@ function middleware(ctx) {
29
28
  }
30
29
  if (tempApiModule) {
31
30
  try {
32
- const { config: { apiConfig = {} } = {}, default: resolver } = tempApiModule;
33
- let overridesConfig = Object.assign(Object.assign({}, commonApiConfig), apiConfig);
34
- yield (0, apiRouteHandler_1.apiRouteHandler)(req, res, resolver, overridesConfig);
31
+ const { config, default: resolver } = tempApiModule;
32
+ yield (0, apiRouteHandler_1.apiRouteHandler)(req, res, resolver, (config === null || config === void 0 ? void 0 : config.api) || { bodyParser: true });
35
33
  }
36
34
  catch (error) {
37
35
  next(error);
@@ -1,3 +1,3 @@
1
- import { IUserRouteConfig, IMiddlewareRouteConfig } from '@shuvi/service';
2
- export declare const addRoutes: import("@shuvi/hook").AsyncParallelHook<void, void, IUserRouteConfig[]>;
1
+ import { IPageRouteConfig, IMiddlewareRouteConfig } from '@shuvi/platform-shared/shared';
2
+ export declare const addRoutes: import("@shuvi/hook").AsyncParallelHook<void, void, IPageRouteConfig[]>;
3
3
  export declare const addMiddlewareRoutes: import("@shuvi/hook").AsyncParallelHook<void, void, IMiddlewareRouteConfig[]>;
@@ -3,7 +3,8 @@ import { middleware as getMiddlewareMiddleware } from './middleware';
3
3
  import { IApiRequestHandler, middleware as getApiMiddleware } from './api';
4
4
  export { IApiRequestHandler, getRoutes, getMiddlewareMiddleware, getApiMiddleware };
5
5
  declare const _default: {
6
- core: import("@shuvi/hook").IPluginInstance<{
6
+ core: import("@shuvi/platform-shared/shared").IPluginInstance<{
7
+ extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
7
8
  afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
8
9
  afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
9
10
  afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
@@ -12,9 +13,8 @@ declare const _default: {
12
13
  configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
13
14
  addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
14
15
  addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
15
- addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
16
+ 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>[]>;
16
17
  addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
17
- } & import("@shuvi/runtime").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
18
- types: string;
18
+ } & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
19
19
  };
20
20
  export default _default;
@@ -38,7 +38,6 @@ const path = __importStar(require("path"));
38
38
  const build_loaders_1 = require("@shuvi/toolpack/lib/utils/build-loaders");
39
39
  const service_1 = require("@shuvi/service");
40
40
  const node_1 = require("@shuvi/platform-shared/node");
41
- const paths_1 = require("../../paths");
42
41
  const lib_1 = require("../html-render/lib");
43
42
  const hooks_1 = require("./hooks");
44
43
  const page_1 = require("./page");
@@ -51,9 +50,18 @@ const plugin = (0, service_1.createPlugin)({
51
50
  setup: ({ addHooks }) => {
52
51
  addHooks({ addRoutes: hooks_1.addRoutes, addMiddlewareRoutes: hooks_1.addMiddlewareRoutes });
53
52
  },
54
- addRuntimeFile: ({ defineFile }, context) => __awaiter(void 0, void 0, void 0, function* () {
55
- const { config: { routes: pageRoutes, middlewareRoutes, apiRoutes }, paths, pluginRunner, phase } = context;
53
+ addRuntimeFile: ({ defineFile, getContent }, context) => __awaiter(void 0, void 0, void 0, function* () {
54
+ const { config: { routes: pageRoutes, middlewareRoutes, apiRoutes, conventionRoutes }, paths, pluginRunner, phase } = context;
56
55
  const isBuildPhase = phase === 'PHASE_PRODUCTION_BUILD';
56
+ const rawRoutes = defineFile({
57
+ name: 'virtual-raw-routes.js',
58
+ virtual: true,
59
+ content: () => __awaiter(void 0, void 0, void 0, function* () {
60
+ const rawRoutes = yield (0, node_1.getRawRoutesFromDir)(paths.routesDir, conventionRoutes.exclude);
61
+ return rawRoutes;
62
+ }),
63
+ dependencies: [paths.routesDir]
64
+ });
57
65
  const pageRoutesFile = defineFile({
58
66
  name: 'routes.js',
59
67
  content: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -63,7 +71,7 @@ const plugin = (0, service_1.createPlugin)({
63
71
  routes = pageRoutes;
64
72
  }
65
73
  else {
66
- const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(paths.routesDir);
74
+ const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
67
75
  if (isBuildPhase) {
68
76
  warnings.forEach(warning => {
69
77
  console.warn(warning.msg);
@@ -78,18 +86,18 @@ const plugin = (0, service_1.createPlugin)({
78
86
  (0, page_1.setRoutes)(normalizedRoutes);
79
87
  return (0, page_1.generateRoutesContent)(normalizedRoutes);
80
88
  }),
81
- dependencies: [paths.routesDir]
89
+ dependencies: [rawRoutes]
82
90
  });
83
91
  const apiRoutesFile = defineFile({
84
92
  name: 'apiRoutes.js',
85
93
  content: () => __awaiter(void 0, void 0, void 0, function* () {
86
- let routes = [];
94
+ let routes;
87
95
  const hasConfigRoutes = Array.isArray(apiRoutes);
88
96
  if (hasConfigRoutes) {
89
97
  routes = apiRoutes;
90
98
  }
91
99
  else {
92
- const { routes: _routes, warnings } = yield (0, node_1.getApiRoutes)(paths.routesDir);
100
+ const { routes: _routes, warnings } = yield (0, node_1.getApiRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
93
101
  if (isBuildPhase) {
94
102
  warnings.forEach(warning => {
95
103
  console.warn(warning);
@@ -99,7 +107,7 @@ const plugin = (0, service_1.createPlugin)({
99
107
  }
100
108
  return (0, api_1.generateRoutesContent)(routes, paths.routesDir);
101
109
  }),
102
- dependencies: [paths.routesDir]
110
+ dependencies: [rawRoutes]
103
111
  });
104
112
  const middlewareRoutesFile = defineFile({
105
113
  name: 'middlewareRoutes.js',
@@ -110,7 +118,7 @@ const plugin = (0, service_1.createPlugin)({
110
118
  routes = middlewareRoutes;
111
119
  }
112
120
  else {
113
- const { routes: _routes, warnings } = yield (0, node_1.getMiddlewareRoutes)(paths.routesDir);
121
+ const { routes: _routes, warnings } = yield (0, node_1.getMiddlewareRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
114
122
  if (isBuildPhase) {
115
123
  warnings.forEach(warning => {
116
124
  console.warn(warning);
@@ -123,7 +131,7 @@ const plugin = (0, service_1.createPlugin)({
123
131
  baseDir: paths.routesDir
124
132
  });
125
133
  }),
126
- dependencies: [paths.routesDir]
134
+ dependencies: [rawRoutes]
127
135
  });
128
136
  const loadersFile = defineFile({
129
137
  name: 'loaders.js',
@@ -168,6 +176,7 @@ const plugin = (0, service_1.createPlugin)({
168
176
  dependencies: [loadersFile]
169
177
  });
170
178
  return [
179
+ rawRoutes,
171
180
  pageRoutesFile,
172
181
  apiRoutesFile,
173
182
  middlewareRoutesFile,
@@ -177,6 +186,5 @@ const plugin = (0, service_1.createPlugin)({
177
186
  })
178
187
  });
179
188
  exports.default = {
180
- core: plugin,
181
- types: (0, paths_1.resolvePkgFile)('lib/node/features/filesystem-routes/shuvi-app.d.ts')
189
+ core: plugin
182
190
  };
@@ -1,2 +1,2 @@
1
- export { normalizeRoutes, generateRoutesContent, IUserRouteConfig } from './routes';
1
+ export { normalizeRoutes, generateRoutesContent, IPageRouteConfig } from './routes';
2
2
  export * from './store';
@@ -1,8 +1,8 @@
1
- import { IUserRouteConfig, IRouteConfig } from '@shuvi/service';
2
- export { IUserRouteConfig };
1
+ import { IPageRouteConfig, IPageRouteConfigWithId } from '@shuvi/platform-shared/shared';
2
+ export { IPageRouteConfig };
3
3
  /**
4
- * returns JSON string of IRawPageRouteRecord
4
+ * returns JSON string of IPageRouteConfigWithId
5
5
  */
6
- export declare function serializeRoutes(routes: IRouteConfig[]): string;
7
- export declare function normalizeRoutes(routes: (IUserRouteConfig | IUserRouteConfig)[], componentDir: string, parentPath?: string): IRouteConfig[];
8
- export declare const generateRoutesContent: (routes: IRouteConfig[]) => string;
6
+ export declare function serializeRoutes(routes: IPageRouteConfigWithId[], isServer: boolean): string;
7
+ export declare function normalizeRoutes(routes: IPageRouteConfig[], componentDir: string, parentPath?: string): IPageRouteConfigWithId[];
8
+ export declare const generateRoutesContent: (routes: IPageRouteConfigWithId[]) => string;
@@ -10,18 +10,23 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  }
11
11
  return t;
12
12
  };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
13
16
  Object.defineProperty(exports, "__esModule", { value: true });
14
17
  exports.generateRoutesContent = exports.normalizeRoutes = exports.serializeRoutes = void 0;
15
18
  const crypto_1 = require("crypto");
19
+ const querystring_1 = __importDefault(require("querystring"));
16
20
  const constants_1 = require("@shuvi/shared/lib/constants");
17
21
  const file_1 = require("@shuvi/utils/lib/file");
18
22
  function genRouteId(filepath) {
19
23
  return (0, crypto_1.createHash)('md4').update(filepath).digest('hex').substr(0, 4);
20
24
  }
25
+ const KEEP_SYMBOL = querystring_1.default.stringify({ keep: ['default'] });
21
26
  /**
22
- * returns JSON string of IRawPageRouteRecord
27
+ * returns JSON string of IPageRouteConfigWithId
23
28
  */
24
- function serializeRoutes(routes) {
29
+ function serializeRoutes(routes, isServer) {
25
30
  let res = '';
26
31
  for (let index = 0; index < routes.length; index++) {
27
32
  const _a = routes[index], { children: childRoutes } = _a, route = __rest(_a, ["children"]);
@@ -33,16 +38,18 @@ function serializeRoutes(routes) {
33
38
  if (key === 'component') {
34
39
  const { component } = route;
35
40
  const componentSource = component;
36
- const componentSourceWithAffix = `${componentSource}?${constants_1.ROUTE_RESOURCE_QUERYSTRING}`;
41
+ const componentRequest = `${componentSource}?${constants_1.ROUTE_RESOURCE_QUERYSTRING}&${KEEP_SYMBOL}`;
37
42
  // `webpackExports` works with production and optimization.minimize, check compiled dist
38
- strRoute +=
39
- `__componentSourceWithAffix__: "${componentSourceWithAffix}",
40
- __componentSource__: "${componentSource}",
43
+ if (isServer) {
44
+ strRoute += `__componentRawRequest__: "${componentRequest}",\n`;
45
+ strRoute += `__componentSource__: "${componentSource}",\n`;
46
+ }
47
+ strRoute += `
41
48
  __import__: () => import(
42
49
  /* webpackChunkName: "page-${id}" */
43
50
  /* webpackExports: "default" */
44
- "${componentSourceWithAffix}"),
45
- __resolveWeak__: () => [require.resolveWeak("${componentSourceWithAffix}")]`.trim();
51
+ "${componentRequest}"),
52
+ __resolveWeak__: () => [require.resolveWeak("${componentRequest}")]`.trim();
46
53
  }
47
54
  else {
48
55
  strRoute += `${key}: ${JSON.stringify(route[key])}`;
@@ -50,7 +57,7 @@ __resolveWeak__: () => [require.resolveWeak("${componentSourceWithAffix}")]`.tri
50
57
  strRoute += `,\n`;
51
58
  }
52
59
  if (childRoutes && childRoutes.length > 0) {
53
- strRoute += `children: ${serializeRoutes(childRoutes)},\n`;
60
+ strRoute += `children: ${serializeRoutes(childRoutes, isServer)},\n`;
54
61
  }
55
62
  res += `{${strRoute}},\n`;
56
63
  }
@@ -77,7 +84,18 @@ function normalizeRoutes(routes, componentDir, parentPath = '') {
77
84
  }
78
85
  exports.normalizeRoutes = normalizeRoutes;
79
86
  const generateRoutesContent = (routes) => {
80
- const serialized = serializeRoutes(routes);
81
- return `export default ${serialized}`;
87
+ const serverRoutes = serializeRoutes(routes, true);
88
+ const clientRoutes = serializeRoutes(routes, false);
89
+ return `
90
+ let routes;
91
+
92
+ if (typeof windows === 'undefined') {
93
+ routes = ${serverRoutes}
94
+ } else {
95
+ routes = ${clientRoutes}
96
+ }
97
+
98
+ export default routes
99
+ `;
82
100
  };
83
101
  exports.generateRoutesContent = generateRoutesContent;
@@ -1,3 +1,3 @@
1
- import { IRouteConfig } from '@shuvi/service';
2
- export declare const setRoutes: (newRoutes: IRouteConfig[]) => void;
3
- export declare const getRoutes: () => IRouteConfig[];
1
+ import { IPageRouteConfigWithId } from '@shuvi/platform-shared/shared';
2
+ export declare const setRoutes: (newRoutes: IPageRouteConfigWithId[]) => void;
3
+ export declare const getRoutes: () => IPageRouteConfigWithId[];
@@ -1,18 +1,4 @@
1
+ import { IPlatformContext, ResolvedPlugin } from '@shuvi/service/lib/core';
1
2
  export { getPageMiddleware, IHtmlDocument, ITemplateData, IViewServer, IViewClient } from './lib';
2
- declare const _default: {
3
- core: import("@shuvi/hook").IPluginInstance<{
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").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<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/runtime").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
15
- server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/runtime").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
16
- types: string;
17
- };
18
- export default _default;
3
+ /** This plugin uses `platformContext` so that it is set to a plugin getter */
4
+ export declare const getPlugin: (platformContext: IPlatformContext) => ResolvedPlugin;
@@ -1,28 +1,99 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getPageMiddleware = void 0;
15
+ exports.getPlugin = exports.getPageMiddleware = void 0;
7
16
  const service_1 = require("@shuvi/service");
17
+ const constants_1 = require("@shuvi/shared/lib/constants");
18
+ const config_1 = require("@shuvi/toolpack/lib/webpack/config");
8
19
  const paths_1 = require("../../paths");
20
+ const middlewares_1 = require("../middlewares");
21
+ const generateResource_1 = __importDefault(require("./lib/generateResource"));
22
+ const buildHtml_1 = require("./lib/buildHtml");
9
23
  const server_1 = __importDefault(require("./server"));
24
+ function getServerEntry() {
25
+ return {
26
+ [service_1.BUILD_SERVER_FILE_SERVER]: [(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/server')]
27
+ };
28
+ }
10
29
  var lib_1 = require("./lib");
11
30
  Object.defineProperty(exports, "getPageMiddleware", { enumerable: true, get: function () { return lib_1.getPageMiddleware; } });
12
- const core = (0, service_1.createPlugin)({
13
- addRuntimeFile: ({ defineFile }, context) => {
14
- const { config: { router: { history } } } = context;
15
- const routerConfigFile = defineFile({
16
- name: 'routerConfig.js',
17
- content: () => {
18
- return `export const historyMode = "${history}";`;
31
+ /** This plugin uses `platformContext` so that it is set to a plugin getter */
32
+ const getPlugin = (platformContext) => {
33
+ const core = (0, service_1.createPlugin)({
34
+ configWebpack: (chain, { name }) => {
35
+ if (name === constants_1.BUNDLER_DEFAULT_TARGET) {
36
+ chain.merge({
37
+ entry: {
38
+ [service_1.BUILD_CLIENT_RUNTIME_POLYFILL]: ['@shuvi/app/core/polyfill'],
39
+ [service_1.BUILD_CLIENT_RUNTIME_MAIN]: [
40
+ (0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/client')
41
+ ]
42
+ }
43
+ });
44
+ }
45
+ return chain;
46
+ },
47
+ addExtraTarget: ({ createConfig }, context) => {
48
+ const serverWebpackHelpers = (0, config_1.webpackHelpers)();
49
+ const serverChain = createConfig({
50
+ name: constants_1.BUNDLER_TARGET_SERVER,
51
+ node: true,
52
+ entry: getServerEntry(),
53
+ outputDir: service_1.BUILD_SERVER_DIR,
54
+ webpackHelpers: serverWebpackHelpers
55
+ });
56
+ return {
57
+ name: constants_1.BUNDLER_TARGET_SERVER,
58
+ chain: serverChain
59
+ };
60
+ },
61
+ addRuntimeFile: ({ defineFile }, context) => {
62
+ const { config: { router: { history } } } = context;
63
+ const routerConfigFile = defineFile({
64
+ name: 'routerConfig.js',
65
+ content: () => {
66
+ return `export const historyMode = "${history}";`;
67
+ }
68
+ });
69
+ return [routerConfigFile];
70
+ },
71
+ addRuntimeService: () => [
72
+ {
73
+ source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-index'),
74
+ exported: '*'
75
+ },
76
+ {
77
+ source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-server'),
78
+ filepath: 'server.ts',
79
+ exported: '*'
19
80
  }
20
- });
21
- return [routerConfigFile];
22
- }
23
- });
24
- exports.default = {
25
- core,
26
- server: server_1.default,
27
- types: (0, paths_1.resolvePkgFile)('lib/node/features/html-render/shuvi-app.d.ts')
81
+ ],
82
+ addResource: context => (0, generateResource_1.default)(context),
83
+ afterBuild: (context) => __awaiter(void 0, void 0, void 0, function* () {
84
+ yield (0, buildHtml_1.buildHtml)({
85
+ context,
86
+ serverPlugins: platformContext.serverPlugins,
87
+ getMiddlewares: middlewares_1.getMiddlewares,
88
+ pathname: '/',
89
+ filename: 'index.html'
90
+ });
91
+ })
92
+ });
93
+ return {
94
+ core,
95
+ server: server_1.default,
96
+ types: (0, paths_1.resolvePkgFile)('lib/node/features/html-render/shuvi-app.d.ts')
97
+ };
28
98
  };
99
+ exports.getPlugin = getPlugin;
@@ -1,3 +1,3 @@
1
1
  import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
2
- import { IRouteRecord } from '@shuvi/router';
3
- export default function generateFilesByRoutId(assetMap: IManifest, routes: IRouteRecord[]): Record<string, string[]>;
2
+ import { IPageRouteRecord } from '@shuvi/platform-shared/shared';
3
+ export default function generateFilesByRoutId(assetMap: IManifest, routes: IPageRouteRecord[]): Record<string, string[]>;