@shuvi/platform-web 0.0.1-rc.34 → 1.0.0-rc.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 (238) hide show
  1. package/esm/shared/appTypes.d.ts +15 -0
  2. package/esm/shared/appTypes.js +1 -0
  3. package/esm/shared/configTypes.d.ts +14 -0
  4. package/esm/shared/configTypes.js +1 -0
  5. package/esm/shared/index.d.ts +5 -0
  6. package/esm/shared/index.js +5 -0
  7. package/esm/shared/renderTypes.d.ts +44 -0
  8. package/esm/shared/renderTypes.js +1 -0
  9. package/esm/shared/routeTypes.d.ts +47 -0
  10. package/esm/shared/routeTypes.js +1 -0
  11. package/esm/shared/serverTypes.d.ts +6 -0
  12. package/esm/shared/serverTypes.js +1 -0
  13. package/esm/shuvi-app/app/client.d.ts +2 -0
  14. package/esm/shuvi-app/app/client.js +125 -0
  15. package/esm/shuvi-app/app/server.d.ts +2 -0
  16. package/esm/shuvi-app/app/server.js +67 -0
  17. package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.d.ts +0 -0
  18. package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.js +2 -1
  19. package/esm/shuvi-app/entry/client/app.d.ts +2 -0
  20. package/esm/shuvi-app/entry/client/app.js +57 -0
  21. package/esm/shuvi-app/entry/client/index.d.ts +2 -0
  22. package/esm/shuvi-app/entry/client/index.js +12 -0
  23. package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.d.ts +0 -0
  24. package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.js +2 -2
  25. package/{shuvi-app → esm/shuvi-app}/entry/client/run.prod.d.ts +0 -0
  26. package/esm/shuvi-app/entry/client/run.prod.js +3 -0
  27. package/{shuvi-app → esm/shuvi-app}/entry/client/setup-env.d.ts +1 -1
  28. package/esm/shuvi-app/entry/client/setup-env.js +17 -0
  29. package/esm/shuvi-app/entry/server/index.d.ts +6 -0
  30. package/esm/shuvi-app/entry/server/index.js +7 -0
  31. package/esm/shuvi-app/react/AppComponent.d.ts +4 -0
  32. package/esm/shuvi-app/react/AppComponent.jsx +6 -0
  33. package/esm/shuvi-app/react/AppContainer.d.ts +6 -0
  34. package/esm/shuvi-app/react/AppContainer.jsx +23 -0
  35. package/esm/shuvi-app/react/Error.d.ts +5 -0
  36. package/esm/shuvi-app/react/Error.jsx +38 -0
  37. package/esm/shuvi-app/react/ErrorBoundary.d.ts +16 -0
  38. package/esm/shuvi-app/react/ErrorBoundary.jsx +25 -0
  39. package/esm/shuvi-app/react/ErrorPage.d.ts +5 -0
  40. package/esm/shuvi-app/react/ErrorPage.jsx +7 -0
  41. package/esm/shuvi-app/react/Link.d.ts +7 -0
  42. package/esm/shuvi-app/react/Link.jsx +115 -0
  43. package/esm/shuvi-app/react/applicationContext.d.ts +7 -0
  44. package/esm/shuvi-app/react/applicationContext.jsx +10 -0
  45. package/esm/shuvi-app/react/dynamic.d.ts +31 -0
  46. package/esm/shuvi-app/react/dynamic.jsx +62 -0
  47. package/esm/shuvi-app/react/getRoutes.d.ts +2 -0
  48. package/esm/shuvi-app/react/getRoutes.js +31 -0
  49. package/esm/shuvi-app/react/head/head-manager-context.d.ts +2 -0
  50. package/esm/shuvi-app/react/head/head-manager-context.js +2 -0
  51. package/esm/shuvi-app/react/head/head-manager.d.ts +10 -0
  52. package/esm/shuvi-app/react/head/head-manager.js +93 -0
  53. package/esm/shuvi-app/react/head/head.d.ts +33 -0
  54. package/esm/shuvi-app/react/head/head.jsx +178 -0
  55. package/esm/shuvi-app/react/head/index.d.ts +4 -0
  56. package/esm/shuvi-app/react/head/index.js +4 -0
  57. package/esm/shuvi-app/react/head/side-effect.d.ts +30 -0
  58. package/esm/shuvi-app/react/head/side-effect.jsx +44 -0
  59. package/esm/shuvi-app/react/head/types.d.ts +15 -0
  60. package/esm/shuvi-app/react/head/types.js +1 -0
  61. package/esm/shuvi-app/react/index.d.ts +4 -0
  62. package/esm/shuvi-app/react/index.js +4 -0
  63. package/esm/shuvi-app/react/loadRouteComponent.d.ts +4 -0
  64. package/esm/shuvi-app/react/loadRouteComponent.jsx +9 -0
  65. package/esm/shuvi-app/react/loadable/index.d.ts +2 -0
  66. package/esm/shuvi-app/react/loadable/index.js +2 -0
  67. package/esm/shuvi-app/react/loadable/loadable-context.d.ts +4 -0
  68. package/esm/shuvi-app/react/loadable/loadable-context.js +3 -0
  69. package/esm/shuvi-app/react/loadable/loadable.d.ts +30 -0
  70. package/esm/shuvi-app/react/loadable/loadable.js +277 -0
  71. package/esm/shuvi-app/react/redox-react/RedoxWrapper.d.ts +8 -0
  72. package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +11 -0
  73. package/esm/shuvi-app/react/redox-react/runtime.d.ts +2 -0
  74. package/esm/shuvi-app/react/redox-react/runtime.js +16 -0
  75. package/esm/shuvi-app/react/shuvi-runtime-api.d.ts +5 -0
  76. package/esm/shuvi-app/react/shuvi-runtime-api.js +5 -0
  77. package/esm/shuvi-app/react/types.d.ts +14 -0
  78. package/esm/shuvi-app/react/types.js +1 -0
  79. package/esm/shuvi-app/react/useLoaderData.d.ts +2 -0
  80. package/esm/shuvi-app/react/useLoaderData.js +27 -0
  81. package/esm/shuvi-app/react/utils/getDisplayName.d.ts +2 -0
  82. package/esm/shuvi-app/react/utils/getDisplayName.js +3 -0
  83. package/esm/shuvi-app/react/utils/requestIdleCallback.d.ts +2 -0
  84. package/esm/shuvi-app/react/utils/requestIdleCallback.js +20 -0
  85. package/esm/shuvi-app/react/utils/useIntersection.d.ts +8 -0
  86. package/esm/shuvi-app/react/utils/useIntersection.jsx +91 -0
  87. package/esm/shuvi-app/react/view/ReactView.client.d.ts +5 -0
  88. package/esm/shuvi-app/react/view/ReactView.client.jsx +64 -0
  89. package/esm/shuvi-app/react/view/ReactView.server.d.ts +4 -0
  90. package/esm/shuvi-app/react/view/ReactView.server.jsx +109 -0
  91. package/esm/shuvi-app/react/view/clientView.d.ts +3 -0
  92. package/esm/shuvi-app/react/view/clientView.js +2 -0
  93. package/esm/shuvi-app/react/view/index.d.ts +2 -0
  94. package/esm/shuvi-app/react/view/index.js +7 -0
  95. package/esm/shuvi-app/react/view/render-action.d.ts +10 -0
  96. package/esm/shuvi-app/react/view/render-action.js +29 -0
  97. package/esm/shuvi-app/react/view/serverView.d.ts +3 -0
  98. package/esm/shuvi-app/react/view/serverView.js +2 -0
  99. package/esm/shuvi-app/react/view/transformRoutes.d.ts +2 -0
  100. package/esm/shuvi-app/react/view/transformRoutes.js +3 -0
  101. package/esm/shuvi-app/shuvi-runtime-index.d.ts +4 -0
  102. package/esm/shuvi-app/shuvi-runtime-index.js +2 -0
  103. package/esm/shuvi-app/shuvi-runtime-server.d.ts +6 -0
  104. package/esm/shuvi-app/shuvi-runtime-server.js +1 -0
  105. package/lib/node/features/custom-server/index.d.ts +4 -0
  106. package/lib/node/features/custom-server/index.js +9 -0
  107. package/lib/node/features/custom-server/server.d.ts +2 -0
  108. package/lib/node/features/custom-server/server.js +28 -0
  109. package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +51 -0
  110. package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +237 -0
  111. package/lib/node/features/filesystem-routes/api/apiRoutes.d.ts +7 -0
  112. package/lib/node/features/filesystem-routes/api/apiRoutes.js +35 -0
  113. package/lib/node/features/filesystem-routes/api/index.d.ts +3 -0
  114. package/lib/node/features/filesystem-routes/api/index.js +7 -0
  115. package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -0
  116. package/lib/node/features/filesystem-routes/api/middleware.js +44 -0
  117. package/lib/node/features/filesystem-routes/hooks.d.ts +3 -0
  118. package/lib/node/features/filesystem-routes/hooks.js +6 -0
  119. package/lib/node/features/filesystem-routes/index.d.ts +20 -0
  120. package/lib/node/features/filesystem-routes/index.js +180 -0
  121. package/lib/node/features/filesystem-routes/middleware/index.d.ts +2 -0
  122. package/lib/node/features/filesystem-routes/middleware/index.js +7 -0
  123. package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -0
  124. package/lib/node/features/filesystem-routes/middleware/middleware.js +42 -0
  125. package/lib/node/features/filesystem-routes/middleware/routes.d.ts +9 -0
  126. package/lib/node/features/filesystem-routes/middleware/routes.js +34 -0
  127. package/lib/node/features/filesystem-routes/page/index.d.ts +2 -0
  128. package/lib/node/features/filesystem-routes/page/index.js +21 -0
  129. package/lib/node/features/filesystem-routes/page/routes.d.ts +8 -0
  130. package/lib/node/features/filesystem-routes/page/routes.js +83 -0
  131. package/lib/node/features/filesystem-routes/page/store.d.ts +3 -0
  132. package/lib/node/features/filesystem-routes/page/store.js +10 -0
  133. package/lib/node/features/html-render/index.d.ts +19 -0
  134. package/lib/node/features/html-render/index.js +28 -0
  135. package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -0
  136. package/lib/node/features/html-render/lib/generateFilesByRoutId.js +13 -0
  137. package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -0
  138. package/lib/node/features/html-render/lib/getPageMiddleware.js +56 -0
  139. package/lib/node/features/html-render/lib/index.d.ts +4 -0
  140. package/lib/node/features/html-render/lib/index.js +23 -0
  141. package/lib/node/features/html-render/lib/pageLoader.d.ts +1 -0
  142. package/lib/node/features/html-render/lib/pageLoader.js +42 -0
  143. package/lib/node/features/html-render/lib/renderToHTML.d.ts +6 -0
  144. package/lib/node/features/html-render/lib/renderToHTML.js +81 -0
  145. package/lib/node/features/html-render/lib/renderer/base.d.ts +17 -0
  146. package/lib/node/features/html-render/lib/renderer/base.js +70 -0
  147. package/lib/node/features/html-render/lib/renderer/htmlTag.d.ts +4 -0
  148. package/lib/node/features/html-render/lib/renderer/htmlTag.js +70 -0
  149. package/lib/node/features/html-render/lib/renderer/index.d.ts +15 -0
  150. package/lib/node/features/html-render/lib/renderer/index.js +48 -0
  151. package/lib/node/features/html-render/lib/renderer/spa.d.ts +5 -0
  152. package/lib/node/features/html-render/lib/renderer/spa.js +26 -0
  153. package/lib/node/features/html-render/lib/renderer/ssr.d.ts +5 -0
  154. package/lib/node/features/html-render/lib/renderer/ssr.js +70 -0
  155. package/lib/node/features/html-render/lib/renderer/types.d.ts +20 -0
  156. package/lib/node/features/html-render/lib/renderer/types.js +2 -0
  157. package/lib/node/features/html-render/lib/viewTemplate.d.ts +5 -0
  158. package/lib/node/features/html-render/lib/viewTemplate.js +37 -0
  159. package/lib/node/features/html-render/server.d.ts +2 -0
  160. package/lib/node/features/html-render/server.js +9 -0
  161. package/lib/node/features/html-render/serverHooks.d.ts +10 -0
  162. package/lib/node/features/html-render/serverHooks.js +13 -0
  163. package/lib/node/features/html-render/shuvi-app.d.ts +6 -0
  164. package/lib/node/features/html-render/shuvi-app.js +2 -0
  165. package/lib/node/features/index.d.ts +32 -0
  166. package/lib/node/features/index.js +25 -0
  167. package/lib/node/features/main/buildHtml.d.ts +8 -0
  168. package/lib/node/features/main/buildHtml.js +64 -0
  169. package/lib/node/features/main/generateResource.d.ts +3 -0
  170. package/lib/node/features/main/generateResource.js +56 -0
  171. package/lib/node/features/main/index.d.ts +3 -0
  172. package/lib/node/features/main/index.js +82 -0
  173. package/lib/node/features/middlewares.d.ts +4 -0
  174. package/lib/node/features/middlewares.js +23 -0
  175. package/lib/node/features/model/index.d.ts +21 -0
  176. package/lib/node/features/model/index.js +54 -0
  177. package/lib/node/features/model/runtime.d.ts +13 -0
  178. package/lib/node/features/model/runtime.js +47 -0
  179. package/lib/node/features/model/server.d.ts +3 -0
  180. package/lib/node/features/model/server.js +12 -0
  181. package/lib/node/features/model/shuvi-app.d.ts +6 -0
  182. package/lib/node/features/model/shuvi-app.js +2 -0
  183. package/lib/node/features/on-demand-compile-page/emptyComponent.d.ts +1 -0
  184. package/lib/node/features/on-demand-compile-page/emptyComponent.js +7 -0
  185. package/lib/node/features/on-demand-compile-page/index.d.ts +15 -0
  186. package/lib/node/features/on-demand-compile-page/index.js +36 -0
  187. package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +11 -0
  188. package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +104 -0
  189. package/lib/node/index.d.ts +6 -0
  190. package/lib/node/index.js +38 -0
  191. package/lib/{paths.d.ts → node/paths.d.ts} +1 -2
  192. package/lib/node/paths.js +36 -0
  193. package/lib/node/shuvi-type-extensions-node.d.ts +42 -0
  194. package/lib/node/shuvi-type-extensions-node.js +3 -0
  195. package/lib/node/targets/react/bundler/index.d.ts +16 -0
  196. package/lib/node/targets/react/bundler/index.js +102 -0
  197. package/lib/node/targets/react/index.d.ts +32 -0
  198. package/lib/node/targets/react/index.js +28 -0
  199. package/lib/node/targets/react/redox-react/index.d.ts +18 -0
  200. package/lib/node/targets/react/redox-react/index.js +50 -0
  201. package/lib/shared/appTypes.d.ts +15 -0
  202. package/lib/shared/appTypes.js +2 -0
  203. package/lib/shared/configTypes.d.ts +14 -0
  204. package/lib/shared/configTypes.js +2 -0
  205. package/lib/shared/index.d.ts +5 -0
  206. package/lib/shared/index.js +21 -0
  207. package/lib/shared/renderTypes.d.ts +44 -0
  208. package/lib/shared/renderTypes.js +2 -0
  209. package/lib/shared/routeTypes.d.ts +47 -0
  210. package/lib/shared/routeTypes.js +2 -0
  211. package/lib/shared/serverTypes.d.ts +6 -0
  212. package/lib/shared/serverTypes.js +2 -0
  213. package/package.json +78 -15
  214. package/shuvi-type-extensions-node.d.ts +2 -0
  215. package/shuvi-type-extensions-runtime.d.ts +36 -0
  216. package/lib/index.d.ts +0 -3
  217. package/lib/index.js +0 -44
  218. package/lib/paths.js +0 -7
  219. package/shuvi-app/application/client/create-application-factory.d.ts +0 -3
  220. package/shuvi-app/application/client/create-application-factory.js +0 -70
  221. package/shuvi-app/application/client/create-application-history-browser.d.ts +0 -1
  222. package/shuvi-app/application/client/create-application-history-browser.js +0 -3
  223. package/shuvi-app/application/client/create-application-history-hash.d.ts +0 -1
  224. package/shuvi-app/application/client/create-application-history-hash.js +0 -3
  225. package/shuvi-app/application/client/create-application-history-memory.d.ts +0 -1
  226. package/shuvi-app/application/client/create-application-history-memory.js +0 -3
  227. package/shuvi-app/application/server/create-application-spa.d.ts +0 -2
  228. package/shuvi-app/application/server/create-application-spa.js +0 -8
  229. package/shuvi-app/application/server/create-application.d.ts +0 -2
  230. package/shuvi-app/application/server/create-application.js +0 -25
  231. package/shuvi-app/entry/client/index.d.ts +0 -1
  232. package/shuvi-app/entry/client/index.js +0 -11
  233. package/shuvi-app/entry/client/run.prod.js +0 -3
  234. package/shuvi-app/entry/client/setup-app.d.ts +0 -3
  235. package/shuvi-app/entry/client/setup-app.js +0 -38
  236. package/shuvi-app/entry/client/setup-env.js +0 -27
  237. package/shuvi-app/entry/server/index.d.ts +0 -6
  238. package/shuvi-app/entry/server/index.js +0 -7
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const service_1 = require("@shuvi/service");
7
+ const bundler_1 = __importDefault(require("./bundler"));
8
+ const redox_react_1 = require("./redox-react");
9
+ const paths_1 = require("../../paths");
10
+ const webReactMainPlugin = (0, service_1.createPlugin)({
11
+ addRuntimeService: () => [
12
+ {
13
+ source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/react/shuvi-runtime-api'),
14
+ exported: '*'
15
+ }
16
+ ]
17
+ });
18
+ const platformWebReact = () => {
19
+ return {
20
+ plugins: [webReactMainPlugin, bundler_1.default, redox_react_1.RedoxReactPlugin],
21
+ platformModule: (0, paths_1.resolvePkgFile)('esm/shuvi-app/react/index'),
22
+ polyfills: [
23
+ (0, paths_1.resolveDep)('react-app-polyfill/ie11'),
24
+ (0, paths_1.resolveDep)('react-app-polyfill/stable')
25
+ ]
26
+ };
27
+ };
28
+ exports.default = platformWebReact;
@@ -0,0 +1,18 @@
1
+ export declare const RedoxReactPlugin: {
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").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/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
15
+ runtime: {
16
+ plugin: string;
17
+ };
18
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.RedoxReactPlugin = void 0;
27
+ const path = __importStar(require("path"));
28
+ const service_1 = require("@shuvi/service");
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)({
33
+ addRuntimeService: () => [
34
+ {
35
+ source: path.dirname(require.resolve('@shuvi/redox-react/package.json')),
36
+ exported: '*',
37
+ filepath: 'model.ts'
38
+ }
39
+ ],
40
+ configWebpack: config => {
41
+ config.resolve.alias.set('@shuvi/redox', (0, paths_1.resolveLib)('@shuvi/redox'));
42
+ return config;
43
+ }
44
+ });
45
+ exports.RedoxReactPlugin = {
46
+ core,
47
+ runtime: {
48
+ plugin: runtimePath
49
+ }
50
+ };
@@ -0,0 +1,15 @@
1
+ import { IRequest, IRawPageRouteRecord, IAppData, IAppState } from '@shuvi/platform-shared/shared';
2
+ import { Application } from '@shuvi/platform-shared/shuvi-app/application';
3
+ export interface CreateAppServer {
4
+ (options: {
5
+ req: IRequest;
6
+ ssr: boolean;
7
+ }): Application;
8
+ }
9
+ export interface CreateAppClient {
10
+ (options: {
11
+ routes: IRawPageRouteRecord[];
12
+ appComponent: any;
13
+ appData: IAppData<any, IAppState>;
14
+ }): Application;
15
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { IRouterHistoryMode, IPageRouteConfig, IMiddlewareRouteConfig, IApiRouteConfig } from '@shuvi/platform-shared/shared';
2
+ export interface IRouterConfig {
3
+ history: IRouterHistoryMode | 'auto';
4
+ }
5
+ export interface PlatformWebCustomConfig {
6
+ ssr: boolean;
7
+ router: IRouterConfig;
8
+ routes?: IPageRouteConfig[];
9
+ middlewareRoutes?: IMiddlewareRouteConfig[];
10
+ apiRoutes?: IApiRouteConfig[];
11
+ conventionRoutes: {
12
+ exclude?: string[];
13
+ };
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './appTypes';
2
+ export * from './configTypes';
3
+ export * from './renderTypes';
4
+ export * from './routeTypes';
5
+ export * from './serverTypes';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./appTypes"), exports);
18
+ __exportStar(require("./configTypes"), exports);
19
+ __exportStar(require("./renderTypes"), exports);
20
+ __exportStar(require("./routeTypes"), exports);
21
+ __exportStar(require("./serverTypes"), exports);
@@ -0,0 +1,44 @@
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 = {
4
+ app: IApplication;
5
+ req?: IRequest;
6
+ };
7
+ export interface IRenderOptions extends IRenderDocumentOptions {
8
+ }
9
+ export interface IView<RenderOption extends IRenderOptions = any, RenderResult = void> {
10
+ renderApp(options: RenderOption): RenderResult;
11
+ }
12
+ export declare type IHtmlAttrs = {
13
+ textContent?: string;
14
+ } & {
15
+ [x: string]: string | number | undefined | boolean;
16
+ };
17
+ export interface IHtmlTag<TagNames = string> {
18
+ tagName: TagNames;
19
+ attrs: IHtmlAttrs;
20
+ innerHTML?: string;
21
+ }
22
+ export declare type IRenderAppServerResult<ExtraAppData = {}> = {
23
+ htmlAttrs?: IHtmlAttrs;
24
+ headBeginTags?: IHtmlTag[];
25
+ headEndTags?: IHtmlTag[];
26
+ mainBeginTags?: IHtmlTag[];
27
+ mainEndTags?: IHtmlTag[];
28
+ scriptBeginTags?: IHtmlTag[];
29
+ scriptEndTags?: IHtmlTag[];
30
+ appData?: ExtraAppData;
31
+ content?: string;
32
+ };
33
+ export interface IClientRendererOptions<ExtraAppData = {}> extends IRenderOptions {
34
+ appContainer: HTMLElement;
35
+ appData: IAppData<ExtraAppData>;
36
+ }
37
+ export interface IServerRendererOptions extends IRenderOptions {
38
+ manifest: IManifest;
39
+ getAssetPublicUrl(path: string): string;
40
+ }
41
+ export interface IViewClient<ExtraAppData = {}> extends IView<IClientRendererOptions<ExtraAppData>> {
42
+ }
43
+ export interface IViewServer<ExtraAppData = {}> extends IView<IServerRendererOptions, Promise<IRenderAppServerResult<ExtraAppData> | Response>> {
44
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,47 @@
1
+ import { IURLParams, IURLQuery } from '@shuvi/platform-shared/shared';
2
+ import { IRequestHandlerWithNext } from '@shuvi/service';
3
+ import { IResponse, IRequest } from '@shuvi/service';
4
+ export interface IApiReq {
5
+ pathname: string;
6
+ query: IURLQuery;
7
+ params: IURLParams;
8
+ cookies: {
9
+ [key: string]: string;
10
+ };
11
+ body?: {
12
+ [key: string]: any;
13
+ };
14
+ }
15
+ export declare type IApiRequest = IRequest & IApiReq;
16
+ export declare type Send<T> = (body: T) => void;
17
+ export declare type IApiRes<T = any> = {
18
+ send: Send<T>;
19
+ json: Send<T>;
20
+ status: (statusCode: number) => IApiRes<T>;
21
+ redirect(url: string): IApiRes<T>;
22
+ redirect(status: number, url: string): IApiRes<T>;
23
+ };
24
+ export declare type IApiResponse<T = any> = IResponse & IApiRes<T>;
25
+ export declare type IApiRequestHandler<T = any> = (req: IApiRequest, res: IApiResponse<T>) => void | Promise<void>;
26
+ export interface IApiConfig {
27
+ api?: {
28
+ bodyParser?: {
29
+ sizeLimit: number | string;
30
+ } | boolean;
31
+ };
32
+ }
33
+ export interface IApiHandler {
34
+ default: IApiRequestHandler;
35
+ config?: IApiConfig;
36
+ }
37
+ export interface IMiddlewareConfig {
38
+ default: IRequestHandlerWithNext;
39
+ }
40
+ export declare type IApiRoutes = {
41
+ path: string;
42
+ api: IApiHandler;
43
+ }[];
44
+ export declare type IMiddlewareRoutes = {
45
+ path: string;
46
+ middleware: IMiddlewareConfig;
47
+ }[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { ServerPluginConstructor } from '@shuvi/service';
2
+ export interface IServerModule {
3
+ getPageData?: ServerPluginConstructor['getPageData'];
4
+ handlePageRequest?: ServerPluginConstructor['handlePageRequest'];
5
+ modifyHtml?: ServerPluginConstructor['modifyHtml'];
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/platform-web",
3
- "version": "0.0.1-rc.34",
3
+ "version": "1.0.0-rc.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -11,30 +11,93 @@
11
11
  "sideEffects": [
12
12
  "**/shuvi-app/entry/client/**"
13
13
  ],
14
- "main": "./lib/index.js",
15
- "module": "./es/index.js",
16
14
  "files": [
17
15
  "lib",
18
- "shuvi-app"
16
+ "esm",
17
+ "shuvi-type-extensions-node.d.ts",
18
+ "shuvi-type-extensions-runtime.d.ts"
19
19
  ],
20
+ "exports": {
21
+ ".": {
22
+ "default": "./lib/node/index.js"
23
+ },
24
+ "./node": {
25
+ "default": "./lib/node/index.js"
26
+ },
27
+ "./node/*": {
28
+ "default": "./lib/node/*.js"
29
+ },
30
+ "./shared": {
31
+ "default": "./esm/shared/index.js"
32
+ },
33
+ "./shared/*": {
34
+ "default": "./esm/shared/*.js"
35
+ },
36
+ "./shuvi-app": {
37
+ "default": "./esm/shuvi-app/index.js"
38
+ },
39
+ "./shuvi-app/*": {
40
+ "default": [
41
+ "./esm/shuvi-app/*.js",
42
+ "./esm/shuvi-app/*.jsx"
43
+ ]
44
+ },
45
+ "./shuvi-type-extensions-node": {
46
+ "types": "./shuvi-type-extensions-node.d.js",
47
+ "default": "./shuvi-type-extensions-node.js"
48
+ },
49
+ "./shuvi-type-extensions-runtime": "./shuvi-type-extensions-runtime.d.ts"
50
+ },
20
51
  "scripts": {
21
52
  "dev": "run-p watch:*",
22
- "watch:app": "tsc -p tsconfig.build.app.json -w",
23
- "watch:node": "tsc -p tsconfig.build.node.json -w",
24
- "prebuild": "rimraf lib shuvi-app",
53
+ "watch:esm": "tsc -p tsconfig.build.browser.json -w",
54
+ "watch:cjs": "tsc -p tsconfig.build.node.json -w",
55
+ "prebuild": "rimraf lib esm types",
25
56
  "build": "run-p build:*",
26
- "build:app": "tsc -p tsconfig.build.app.json",
27
- "build:node": "tsc -p tsconfig.build.node.json"
57
+ "build:esm": "tsc -p tsconfig.build.browser.json",
58
+ "build:cjs": "tsc -p tsconfig.build.node.json"
28
59
  },
29
60
  "engines": {
30
61
  "node": ">= 12.0.0"
31
62
  },
32
63
  "dependencies": {
33
- "@shuvi/app": "0.0.1-rc.34",
34
- "@shuvi/platform-core": "0.0.1-rc.34",
35
- "@shuvi/platform-web-react": "0.0.1-rc.34",
36
- "@shuvi/service": "0.0.1-rc.34",
37
- "@shuvi/shared": "0.0.1-rc.34"
64
+ "@next/react-refresh-utils": "12.1.6",
65
+ "@shuvi/hook": "1.0.0-rc.2",
66
+ "@shuvi/platform-shared": "1.0.0-rc.2",
67
+ "@shuvi/redox": "0.0.3",
68
+ "@shuvi/redox-react": "0.0.3",
69
+ "@shuvi/router": "1.0.0-rc.2",
70
+ "@shuvi/router-react": "1.0.0-rc.2",
71
+ "@shuvi/runtime": "1.0.0-rc.2",
72
+ "@shuvi/service": "1.0.0-rc.2",
73
+ "@shuvi/shared": "1.0.0-rc.2",
74
+ "@shuvi/toolpack": "1.0.0-rc.2",
75
+ "@shuvi/utils": "1.0.0-rc.2",
76
+ "content-type": "1.0.4",
77
+ "cookie": "0.4.1",
78
+ "ejs": "3.1.5",
79
+ "fs-extra": "9.0.1",
80
+ "node-mocks-http": "1.11.0",
81
+ "raw-body": "2.4.1",
82
+ "react": "18.1.0",
83
+ "react-app-polyfill": "2.0.0",
84
+ "react-dom": "18.1.0",
85
+ "react-refresh": "0.12.0",
86
+ "use-sync-external-store": "1.1.0"
87
+ },
88
+ "peerDependencies": {
89
+ "@shuvi/service": "1.0.0-rc.2"
38
90
  },
39
- "gitHead": "10ebaa2a20fd06bc7f34be0feeddef9a26f9dddd"
91
+ "devDependencies": {
92
+ "@types/react": "18.0.9",
93
+ "@types/react-dom": "18.0.6",
94
+ "@types/react-test-renderer": "18.0.0",
95
+ "@shuvi/redox": "0.0.3",
96
+ "@testing-library/react": "^13.2.0",
97
+ "@types/content-type": "^1.1.5",
98
+ "@types/cookie": "^0.4.1",
99
+ "@types/ejs": "^3.1.0",
100
+ "@types/raw-body": "^2.3.0",
101
+ "webpack": "5.73.0"
102
+ }
40
103
  }
@@ -0,0 +1,2 @@
1
+ // ts has bug with package.exports, so we use a module to proxy the real module
2
+ import './lib/node/shuvi-type-extensions-node';
@@ -0,0 +1,36 @@
1
+ /// <reference types="@shuvi/platform-shared/shuvi-type-extensions-runtime" />
2
+
3
+ declare module '@shuvi/app/files/routes' {
4
+ import { IRawPageRouteRecord } from '@shuvi/platform-shared/shared';
5
+ declare const routes: IRawPageRouteRecord[];
6
+ export default routes;
7
+ }
8
+
9
+ declare module '@shuvi/app/files/routerConfig' {
10
+ export const historyMode: 'browser' | 'hash';
11
+ }
12
+
13
+ declare module '@shuvi/app/files/page-loaders' {
14
+ import { IRouteLoaderContext, Loader } from '@shuvi/platform-shared/shared';
15
+
16
+ const loaders: Record<string, Loader>;
17
+ export default loaders;
18
+ }
19
+
20
+ declare module '@shuvi/app/files/apiRoutes' {
21
+ import { IApiRoutes } from '@shuvi/platform-web/shared';
22
+
23
+ declare const apiRoutes: IApiRoutes[];
24
+ export default apiRoutes;
25
+ }
26
+
27
+ declare module '@shuvi/app/files/middlewareRoutes' {
28
+ import { IMiddlewareRoutes } from '@shuvi/platform-web/shared';
29
+
30
+ declare const middlewareRoutes: IMiddlewareRoutes[];
31
+ export default middlewareRoutes;
32
+ }
33
+
34
+ declare module '@shuvi/app/user/server' {
35
+ export {};
36
+ }
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Runtime } from '@shuvi/service';
2
- declare const platform: Runtime.IRuntime<any>;
3
- export default platform;
package/lib/index.js DELETED
@@ -1,44 +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
- const paths_1 = require("./paths");
13
- const platform = {
14
- install(api) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- // set application and entry
17
- const { ssr, router: { history } } = api.config;
18
- let ApplicationModule;
19
- if (history === 'browser') {
20
- ApplicationModule = 'create-application-history-browser';
21
- }
22
- else if (history === 'hash') {
23
- ApplicationModule = 'create-application-history-hash';
24
- }
25
- else {
26
- ApplicationModule = 'create-application-history-memory';
27
- }
28
- api.setServerModule({
29
- application: paths_1.resolveAppFile('application', 'server', ssr ? 'create-application' : 'create-application-spa'),
30
- entry: paths_1.resolveAppFile('entry', 'server')
31
- });
32
- api.setClientModule({
33
- application: paths_1.resolveAppFile('application', 'client', ApplicationModule),
34
- entry: paths_1.resolveAppFile('entry', 'client')
35
- });
36
- // install framework
37
- const { framework = 'react' } = api.config.platform || {};
38
- const frameworkInstance = require(`@shuvi/platform-web-${framework}`)
39
- .default;
40
- frameworkInstance.install(api);
41
- });
42
- }
43
- };
44
- exports.default = platform;
package/lib/paths.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- exports.PACKAGE_DIR = path_1.dirname(require.resolve('@shuvi/platform-web/package.json'));
5
- exports.resolveAppFile = (...paths) => `${path_1.resolve(exports.PACKAGE_DIR, 'shuvi-app', ...paths)}`;
6
- exports.resolveDep = (module) => require.resolve(module);
7
- exports.resolveLib = (module) => path_1.dirname(exports.resolveDep(path_1.join(module, 'package.json')));
@@ -1,3 +0,0 @@
1
- import { History } from '@shuvi/router/lib/types';
2
- import { Runtime } from '@shuvi/service';
3
- export declare const createFactory: (historyCreater: () => History) => Runtime.ApplicationCreater;
@@ -1,70 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import AppComponent from '@shuvi/app/core/app';
11
- import routes from '@shuvi/app/core/routes';
12
- import { getRoutes } from '@shuvi/app/core/platform';
13
- import { Application } from '@shuvi/platform-core';
14
- import runPlugins from '@shuvi/platform-core/lib/runPlugins';
15
- import { createRouter } from '@shuvi/router';
16
- let app;
17
- let history;
18
- let appContext;
19
- export const createFactory = (historyCreater) => {
20
- const create = function (context, options) {
21
- appContext = context;
22
- // app is a singleton in client side
23
- if (app) {
24
- return app;
25
- }
26
- history = historyCreater();
27
- const router = createRouter({
28
- history,
29
- routes: getRoutes(routes, context)
30
- });
31
- app = new Application({
32
- AppComponent,
33
- router,
34
- context,
35
- render: options.render
36
- });
37
- runPlugins(app);
38
- return app;
39
- };
40
- return create;
41
- };
42
- if (module.hot) {
43
- module.hot.accept([
44
- '@shuvi/app/entry.client',
45
- '@shuvi/app/core/app',
46
- '@shuvi/app/core/routes',
47
- '@shuvi/app/user/plugin'
48
- ], () => __awaiter(void 0, void 0, void 0, function* () {
49
- const rerender = () => {
50
- const AppComponent = require('@shuvi/app/core/app').default;
51
- const routes = require('@shuvi/app/core/routes').default;
52
- const router = createRouter({
53
- history,
54
- routes: getRoutes(routes, appContext)
55
- });
56
- app.rerender({ router, AppComponent });
57
- };
58
- // to solve routing problem, we need to rerender routes
59
- // wait navigation complete only rerender to ensure getInitialProps is called
60
- if (__SHUVI.router._pending) {
61
- const removelistener = __SHUVI.router.afterEach(() => {
62
- rerender();
63
- removelistener();
64
- });
65
- }
66
- else {
67
- rerender();
68
- }
69
- }));
70
- }
@@ -1 +0,0 @@
1
- export declare const create: import("@shuvi/service/lib/types/runtime").ApplicationCreater;
@@ -1,3 +0,0 @@
1
- import { createFactory } from './create-application-factory';
2
- import { createBrowserHistory } from '@shuvi/router';
3
- export const create = createFactory(createBrowserHistory);
@@ -1 +0,0 @@
1
- export declare const create: import("@shuvi/service/lib/types/runtime").ApplicationCreater;
@@ -1,3 +0,0 @@
1
- import { createFactory } from './create-application-factory';
2
- import { createHashHistory } from '@shuvi/router';
3
- export const create = createFactory(createHashHistory);
@@ -1 +0,0 @@
1
- export declare const create: import("@shuvi/service/lib/types/runtime").ApplicationCreater;
@@ -1,3 +0,0 @@
1
- import { createFactory } from './create-application-factory';
2
- import { createMemoryHistory } from '@shuvi/router';
3
- export const create = createFactory(createMemoryHistory);
@@ -1,2 +0,0 @@
1
- import { Runtime } from '@shuvi/service';
2
- export declare const create: Runtime.ApplicationCreater;
@@ -1,8 +0,0 @@
1
- import { Application } from '@shuvi/platform-core';
2
- export const create = function (context, options) {
3
- return new Application({
4
- AppComponent: null,
5
- context,
6
- render: options.render
7
- });
8
- };
@@ -1,2 +0,0 @@
1
- import { Runtime } from '@shuvi/service';
2
- export declare const create: Runtime.ApplicationCreater;
@@ -1,25 +0,0 @@
1
- import AppComponent from '@shuvi/app/core/app';
2
- import routes from '@shuvi/app/core/routes';
3
- import { getRoutes } from '@shuvi/app/core/platform';
4
- import { Application } from '@shuvi/platform-core';
5
- import runPlugins from '@shuvi/platform-core/lib/runPlugins';
6
- import { createRouter, createMemoryHistory } from '@shuvi/router';
7
- export const create = function (context, options) {
8
- const { req } = context;
9
- const history = createMemoryHistory({
10
- initialEntries: [(req && req.url) || '/'],
11
- initialIndex: 0
12
- });
13
- const router = createRouter({
14
- history,
15
- routes: getRoutes(routes, context)
16
- });
17
- const app = new Application({
18
- AppComponent,
19
- router,
20
- context,
21
- render: options.render
22
- });
23
- runPlugins(app);
24
- return app;
25
- };
@@ -1 +0,0 @@
1
- import './setup-env';