@modern-js/app-tools 2.0.0-beta.3 → 2.0.0-canary.0

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 (221) hide show
  1. package/dist/js/modern/analyze/constants.js +38 -18
  2. package/dist/js/modern/analyze/generateCode.js +261 -221
  3. package/dist/js/modern/analyze/getBundleEntry.js +31 -32
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
  6. package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
  7. package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
  8. package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
  9. package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
  10. package/dist/js/modern/analyze/getServerRoutes.js +122 -126
  11. package/dist/js/modern/analyze/index.js +193 -159
  12. package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
  13. package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
  14. package/dist/js/modern/analyze/nestedRoutes.js +106 -60
  15. package/dist/js/modern/analyze/templates.js +161 -80
  16. package/dist/js/modern/analyze/utils.js +87 -66
  17. package/dist/js/modern/builder/builderPlugins/compatModern.js +121 -109
  18. package/dist/js/modern/builder/index.js +122 -83
  19. package/dist/js/modern/builder/loaders/routerLoader.js +9 -12
  20. package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -1
  21. package/dist/js/modern/builder/share.js +22 -20
  22. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
  23. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
  24. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +98 -84
  25. package/dist/js/modern/commands/build.js +67 -42
  26. package/dist/js/modern/commands/deploy.js +27 -4
  27. package/dist/js/modern/commands/dev.js +77 -27
  28. package/dist/js/modern/commands/index.js +1 -1
  29. package/dist/js/modern/commands/inspect.js +30 -5
  30. package/dist/js/modern/commands/start.js +37 -15
  31. package/dist/js/modern/config/default.js +103 -113
  32. package/dist/js/modern/config/index.js +8 -2
  33. package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
  34. package/dist/js/modern/config/initial/createOutputConfig.js +9 -10
  35. package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
  36. package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
  37. package/dist/js/modern/config/initial/index.js +9 -4
  38. package/dist/js/modern/config/initial/inits.js +109 -73
  39. package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
  40. package/dist/js/modern/defineConfig.js +26 -11
  41. package/dist/js/modern/exports/server.js +4 -1
  42. package/dist/js/modern/hooks.js +10 -3
  43. package/dist/js/modern/index.js +140 -89
  44. package/dist/js/modern/initialize/index.js +98 -51
  45. package/dist/js/modern/locale/en.js +20 -21
  46. package/dist/js/modern/locale/index.js +6 -6
  47. package/dist/js/modern/locale/zh.js +21 -22
  48. package/dist/js/modern/schema/Schema.js +6 -5
  49. package/dist/js/modern/schema/index.js +51 -100
  50. package/dist/js/modern/schema/legacy.js +96 -231
  51. package/dist/js/modern/types/config/index.js +0 -1
  52. package/dist/js/modern/types/index.js +0 -1
  53. package/dist/js/modern/types/legacyConfig/output.js +0 -1
  54. package/dist/js/modern/utils/commands.js +5 -2
  55. package/dist/js/modern/utils/config.js +102 -41
  56. package/dist/js/modern/utils/createFileWatcher.js +84 -51
  57. package/dist/js/modern/utils/createServer.js +63 -17
  58. package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
  59. package/dist/js/modern/utils/language.js +6 -3
  60. package/dist/js/modern/utils/printInstructions.js +27 -8
  61. package/dist/js/modern/utils/restart.js +43 -16
  62. package/dist/js/modern/utils/routes.js +29 -12
  63. package/dist/js/node/analyze/constants.js +54 -39
  64. package/dist/js/node/analyze/generateCode.js +281 -239
  65. package/dist/js/node/analyze/getBundleEntry.js +55 -44
  66. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
  67. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
  68. package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
  69. package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
  70. package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
  71. package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
  72. package/dist/js/node/analyze/getServerRoutes.js +143 -137
  73. package/dist/js/node/analyze/index.js +240 -174
  74. package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
  75. package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
  76. package/dist/js/node/analyze/nestedRoutes.js +137 -75
  77. package/dist/js/node/analyze/templates.js +183 -89
  78. package/dist/js/node/analyze/utils.js +114 -81
  79. package/dist/js/node/builder/builderPlugins/compatModern.js +149 -122
  80. package/dist/js/node/builder/index.js +150 -92
  81. package/dist/js/node/builder/loaders/routerLoader.js +27 -18
  82. package/dist/js/node/builder/loaders/serverModuleLoader.js +22 -7
  83. package/dist/js/node/builder/share.js +45 -25
  84. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
  85. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
  86. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +116 -90
  87. package/dist/js/node/commands/build.js +89 -52
  88. package/dist/js/node/commands/deploy.js +45 -10
  89. package/dist/js/node/commands/dev.js +99 -41
  90. package/dist/js/node/commands/index.js +19 -38
  91. package/dist/js/node/commands/inspect.js +48 -11
  92. package/dist/js/node/commands/start.js +65 -26
  93. package/dist/js/node/config/default.js +119 -117
  94. package/dist/js/node/config/index.js +25 -29
  95. package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
  96. package/dist/js/node/config/initial/createOutputConfig.js +26 -14
  97. package/dist/js/node/config/initial/createSourceConfig.js +22 -6
  98. package/dist/js/node/config/initial/createToolsConfig.js +24 -10
  99. package/dist/js/node/config/initial/index.js +28 -17
  100. package/dist/js/node/config/initial/inits.js +126 -81
  101. package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
  102. package/dist/js/node/defineConfig.js +43 -17
  103. package/dist/js/node/exports/server.js +21 -10
  104. package/dist/js/node/hooks.js +44 -29
  105. package/dist/js/node/index.js +190 -130
  106. package/dist/js/node/initialize/index.js +116 -61
  107. package/dist/js/node/locale/en.js +36 -25
  108. package/dist/js/node/locale/index.js +27 -15
  109. package/dist/js/node/locale/zh.js +37 -26
  110. package/dist/js/node/schema/Schema.js +23 -10
  111. package/dist/js/node/schema/index.js +77 -114
  112. package/dist/js/node/schema/legacy.js +117 -240
  113. package/dist/js/node/types/config/index.js +17 -16
  114. package/dist/js/node/types/index.js +19 -38
  115. package/dist/js/node/types/legacyConfig/output.js +0 -5
  116. package/dist/js/node/utils/commands.js +21 -6
  117. package/dist/js/node/utils/config.js +120 -51
  118. package/dist/js/node/utils/createFileWatcher.js +104 -61
  119. package/dist/js/node/utils/createServer.js +86 -25
  120. package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
  121. package/dist/js/node/utils/language.js +24 -8
  122. package/dist/js/node/utils/printInstructions.js +47 -16
  123. package/dist/js/node/utils/restart.js +61 -21
  124. package/dist/js/node/utils/routes.js +53 -18
  125. package/dist/js/treeshaking/analyze/constants.js +28 -18
  126. package/dist/js/treeshaking/analyze/generateCode.js +599 -406
  127. package/dist/js/treeshaking/analyze/getBundleEntry.js +52 -63
  128. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
  129. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
  130. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
  131. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
  132. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
  133. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
  134. package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -147
  135. package/dist/js/treeshaking/analyze/index.js +558 -303
  136. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
  137. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
  138. package/dist/js/treeshaking/analyze/nestedRoutes.js +411 -200
  139. package/dist/js/treeshaking/analyze/templates.js +433 -236
  140. package/dist/js/treeshaking/analyze/utils.js +358 -153
  141. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +281 -200
  142. package/dist/js/treeshaking/builder/index.js +371 -163
  143. package/dist/js/treeshaking/builder/loaders/routerLoader.js +11 -12
  144. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +3 -2
  145. package/dist/js/treeshaking/builder/share.js +41 -44
  146. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
  147. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
  148. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +332 -112
  149. package/dist/js/treeshaking/commands/build.js +286 -88
  150. package/dist/js/treeshaking/commands/deploy.js +153 -25
  151. package/dist/js/treeshaking/commands/dev.js +318 -131
  152. package/dist/js/treeshaking/commands/index.js +1 -1
  153. package/dist/js/treeshaking/commands/inspect.js +147 -32
  154. package/dist/js/treeshaking/commands/start.js +190 -67
  155. package/dist/js/treeshaking/config/default.js +210 -198
  156. package/dist/js/treeshaking/config/index.js +3 -2
  157. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
  158. package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -70
  159. package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
  160. package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
  161. package/dist/js/treeshaking/config/initial/index.js +10 -9
  162. package/dist/js/treeshaking/config/initial/inits.js +205 -106
  163. package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
  164. package/dist/js/treeshaking/defineConfig.js +60 -13
  165. package/dist/js/treeshaking/exports/server.js +2 -1
  166. package/dist/js/treeshaking/hooks.js +26 -25
  167. package/dist/js/treeshaking/index.js +465 -257
  168. package/dist/js/treeshaking/initialize/index.js +290 -112
  169. package/dist/js/treeshaking/locale/en.js +34 -33
  170. package/dist/js/treeshaking/locale/index.js +5 -5
  171. package/dist/js/treeshaking/locale/zh.js +34 -33
  172. package/dist/js/treeshaking/schema/Schema.js +267 -69
  173. package/dist/js/treeshaking/schema/index.js +165 -121
  174. package/dist/js/treeshaking/schema/legacy.js +323 -256
  175. package/dist/js/treeshaking/types/config/deploy.js +1 -0
  176. package/dist/js/treeshaking/types/config/dev.js +1 -0
  177. package/dist/js/treeshaking/types/config/experiments.js +1 -0
  178. package/dist/js/treeshaking/types/config/html.js +1 -0
  179. package/dist/js/treeshaking/types/config/index.js +0 -1
  180. package/dist/js/treeshaking/types/config/output.js +1 -0
  181. package/dist/js/treeshaking/types/config/performance.js +1 -0
  182. package/dist/js/treeshaking/types/config/security.js +1 -0
  183. package/dist/js/treeshaking/types/config/source.js +1 -0
  184. package/dist/js/treeshaking/types/config/tools.js +1 -0
  185. package/dist/js/treeshaking/types/hooks.js +1 -0
  186. package/dist/js/treeshaking/types/index.js +0 -1
  187. package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
  188. package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
  189. package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
  190. package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
  191. package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
  192. package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
  193. package/dist/js/treeshaking/utils/commands.js +6 -5
  194. package/dist/js/treeshaking/utils/config.js +295 -117
  195. package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
  196. package/dist/js/treeshaking/utils/createServer.js +252 -67
  197. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
  198. package/dist/js/treeshaking/utils/language.js +6 -5
  199. package/dist/js/treeshaking/utils/printInstructions.js +151 -29
  200. package/dist/js/treeshaking/utils/restart.js +184 -42
  201. package/dist/js/treeshaking/utils/routes.js +151 -27
  202. package/dist/js/treeshaking/utils/types.js +1 -0
  203. package/dist/types/analyze/index.d.ts +2 -0
  204. package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
  205. package/dist/types/builder/index.d.ts +2 -2
  206. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
  207. package/dist/types/defineConfig.d.ts +1 -0
  208. package/dist/types/index.d.ts +2 -0
  209. package/dist/types/initialize/index.d.ts +2 -0
  210. package/dist/types/types/config/index.d.ts +1 -0
  211. package/dist/types/types/config/output.d.ts +0 -1
  212. package/dist/types/types/config/source.d.ts +1 -0
  213. package/dist/types/types/config/tools.d.ts +2 -0
  214. package/dist/types/types/legacyConfig/dev.d.ts +1 -0
  215. package/dist/types/types/legacyConfig/output.d.ts +1 -1
  216. package/dist/types/types/legacyConfig/source.d.ts +1 -0
  217. package/dist/types/types/legacyConfig/tools.d.ts +1 -0
  218. package/dist/types/utils/config.d.ts +1 -0
  219. package/dist/types/utils/createServer.d.ts +1 -0
  220. package/dist/types/utils/restart.d.ts +1 -1
  221. package/package.json +9 -8
@@ -1,97 +1,111 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- import path from 'path';
3
- import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from '@modern-js/utils';
4
- const PLUGIN_NAME = 'ModernjsRoutePlugin';
5
- export default class RouterPlugin {
6
- constructor(options) {
7
- _defineProperty(this, "existNestedRoutes", void 0);
8
- this.existNestedRoutes = options.existNestedRoutes;
9
- }
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import path from "path";
22
+ import {
23
+ fs,
24
+ ROUTE_MANIFEST,
25
+ logger,
26
+ ROUTE_MINIFEST_FILE
27
+ } from "@modern-js/utils";
28
+ const PLUGIN_NAME = "ModernjsRoutePlugin";
29
+ class RouterPlugin {
10
30
  apply(compiler) {
11
- const {
12
- existNestedRoutes
13
- } = this;
14
- const {
15
- target
16
- } = compiler.options;
17
- if (target === 'node' || Array.isArray(target) && target.includes('node')) {
18
- return;
19
- }
20
- if (!existNestedRoutes) {
31
+ const { target } = compiler.options;
32
+ if (target === "node" || Array.isArray(target) && target.includes("node")) {
21
33
  return;
22
34
  }
23
- const {
24
- webpack
25
- } = compiler;
26
- const {
27
- Compilation,
28
- sources
29
- } = webpack;
30
- const {
31
- RawSource
32
- } = sources;
33
- const {
34
- PROCESS_ASSETS_STAGE_REPORT
35
- } = Compilation;
35
+ const { webpack } = compiler;
36
+ const { Compilation, sources } = webpack;
37
+ const { RawSource } = sources;
38
+ const { PROCESS_ASSETS_STAGE_REPORT } = Compilation;
36
39
  const outputPath = compiler.options.output.path;
37
- const newAssetsMap = new Map();
38
- const normalizePath = path => {
39
- if (!path.endsWith('/')) {
40
- return `${path}/`;
40
+ const newAssetsMap = /* @__PURE__ */ new Map();
41
+ const normalizePath = (path2) => {
42
+ if (!path2.endsWith("/")) {
43
+ return `${path2}/`;
41
44
  }
42
- return path;
45
+ return path2;
43
46
  };
44
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
45
- compilation.hooks.processAssets.tapPromise({
46
- name: PLUGIN_NAME,
47
- stage: PROCESS_ASSETS_STAGE_REPORT
48
- }, async () => {
49
- const stats = compilation.getStats().toJson({
50
- chunkGroups: true,
51
- chunks: true
52
- });
53
- const {
54
- publicPath
55
- } = stats;
56
- const routeAssets = {};
57
- const {
58
- namedChunkGroups,
59
- assetsByChunkName
60
- } = stats;
61
- if (!namedChunkGroups || !assetsByChunkName) {
62
- logger.warn('Route manifest does not exist, performance will be affected');
63
- return;
64
- }
65
- for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
66
- routeAssets[name] = {
67
- chunkIds: chunkGroup.chunks,
68
- assets: assetsByChunkName[name].map(item => publicPath ? normalizePath(publicPath) + item : item)
47
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
48
+ compilation.hooks.processAssets.tapPromise(
49
+ {
50
+ name: PLUGIN_NAME,
51
+ stage: PROCESS_ASSETS_STAGE_REPORT
52
+ },
53
+ () => __async(this, null, function* () {
54
+ const stats = compilation.getStats().toJson({
55
+ chunkGroups: true,
56
+ chunks: true
57
+ });
58
+ const { publicPath } = stats;
59
+ const routeAssets = {};
60
+ const { namedChunkGroups, assetsByChunkName } = stats;
61
+ if (!namedChunkGroups || !assetsByChunkName) {
62
+ logger.warn(
63
+ "Route manifest does not exist, performance will be affected"
64
+ );
65
+ return;
66
+ }
67
+ for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
68
+ if (assetsByChunkName[name]) {
69
+ routeAssets[name] = {
70
+ chunkIds: chunkGroup.chunks,
71
+ assets: assetsByChunkName[name].map(
72
+ (item) => publicPath ? normalizePath(publicPath) + item : item
73
+ )
74
+ };
75
+ }
76
+ }
77
+ const manifest = {
78
+ routeAssets
69
79
  };
70
- }
71
- const manifest = {
72
- routeAssets
73
- };
74
- const injectedContent = `
80
+ const injectedContent = `
75
81
  ;(function(){
76
82
  window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest)};
77
83
  })();
78
84
  `;
79
- const entrypointsArray = Array.from(compilation.entrypoints.entries());
80
- const entryChunkIds = entrypointsArray.map(entrypoint => entrypoint[0]);
81
- const entryChunks = [...compilation.chunks].filter(chunk => {
82
- return entryChunkIds.includes(chunk.name);
83
- });
84
- const entryChunkFiles = entryChunks.map(chunk => [...chunk.files][0]);
85
- for (const file of entryChunkFiles) {
86
- const asset = compilation.assets[file];
87
- const newContent = `${injectedContent}${asset.source().toString()}`;
88
- newAssetsMap.set(path.join(outputPath, file), newContent);
89
- compilation.updateAsset(file, new RawSource(newContent));
90
- }
91
- const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
92
- await fs.ensureFile(filename);
93
- await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
94
- });
85
+ const entrypointsArray = Array.from(
86
+ compilation.entrypoints.entries()
87
+ );
88
+ const entryChunkIds = entrypointsArray.map(
89
+ (entrypoint) => entrypoint[0]
90
+ );
91
+ const entryChunks = [...compilation.chunks].filter((chunk) => {
92
+ return entryChunkIds.includes(chunk.name);
93
+ });
94
+ const entryChunkFiles = entryChunks.map((chunk) => [...chunk.files][0]);
95
+ for (const file of entryChunkFiles) {
96
+ const asset = compilation.assets[file];
97
+ const newContent = `${injectedContent}${asset.source().toString()}`;
98
+ newAssetsMap.set(path.join(outputPath, file), newContent);
99
+ compilation.updateAsset(file, new RawSource(newContent));
100
+ }
101
+ const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
102
+ yield fs.ensureFile(filename);
103
+ yield fs.writeFile(filename, JSON.stringify(manifest, null, 2));
104
+ })
105
+ );
95
106
  });
96
107
  }
97
- }
108
+ }
109
+ export {
110
+ RouterPlugin as default
111
+ };
@@ -1,66 +1,91 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import { ResolvedConfigContext } from '@modern-js/core';
5
- import { logger, printBuildError } from '@modern-js/utils';
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import { ResolvedConfigContext } from "@modern-js/core";
41
+ import { logger, printBuildError } from "@modern-js/utils";
6
42
  import { generateRoutes } from "../utils/routes";
7
43
  import { buildServerConfig } from "../utils/config";
8
- export const build = async (api, options) => {
9
- if (options !== null && options !== void 0 && options.analyze) {
10
- // Builder will read this env var to enable bundle analyzer
11
- process.env.BUNDLE_ANALYZE = 'true';
44
+ const build = (api, options) => __async(void 0, null, function* () {
45
+ if (options == null ? void 0 : options.analyze) {
46
+ process.env.BUNDLE_ANALYZE = "true";
12
47
  }
13
48
  let resolvedConfig = api.useResolvedConfigContext();
14
49
  const appContext = api.useAppContext();
15
50
  const hookRunners = api.useHookRunners();
16
- const {
17
- apiOnly
18
- } = appContext;
51
+ const { apiOnly } = appContext;
19
52
  if (apiOnly) {
20
- const {
21
- appDirectory,
22
- distDirectory,
23
- serverConfigFile
24
- } = appContext;
25
- await hookRunners.beforeBuild({
26
- // "null" bundlerConfigs
27
- bundlerConfigs: undefined
53
+ const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
54
+ yield hookRunners.beforeBuild({
55
+ bundlerConfigs: void 0
28
56
  });
29
- await buildServerConfig({
30
- appDirectory,
31
- distDirectory,
32
- configFile: serverConfigFile
57
+ yield buildServerConfig({
58
+ appDirectory: appDirectory2,
59
+ distDirectory: distDirectory2,
60
+ configFile: serverConfigFile2
33
61
  });
34
- await generateRoutes(appContext);
35
- await hookRunners.afterBuild({
36
- // "null" stats
37
- stats: undefined
62
+ yield generateRoutes(appContext);
63
+ yield hookRunners.afterBuild({
64
+ stats: void 0
38
65
  });
39
66
  return;
40
67
  }
41
- resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
42
- cliOptions: options
43
- });
68
+ resolvedConfig = __spreadProps(__spreadValues({}, resolvedConfig), { cliOptions: options });
44
69
  ResolvedConfigContext.set(resolvedConfig);
45
- const {
46
- distDirectory,
47
- appDirectory,
48
- serverConfigFile
49
- } = appContext;
50
- await buildServerConfig({
70
+ const { distDirectory, appDirectory, serverConfigFile } = appContext;
71
+ yield buildServerConfig({
51
72
  appDirectory,
52
73
  distDirectory,
53
74
  configFile: serverConfigFile
54
75
  });
55
76
  try {
56
- logger.info('Create a production build...\n');
77
+ logger.info("Create a production build...\n");
57
78
  if (!appContext.builder) {
58
- throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
79
+ throw new Error(
80
+ "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
81
+ );
59
82
  }
60
- await appContext.builder.build();
83
+ yield appContext.builder.build();
61
84
  } catch (error) {
62
85
  printBuildError(error);
63
- // eslint-disable-next-line no-process-exit
64
86
  process.exit(1);
65
87
  }
66
- };
88
+ });
89
+ export {
90
+ build
91
+ };
@@ -1,5 +1,28 @@
1
- export const deploy = async (api, options) => {
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ const deploy = (api, options) => __async(void 0, null, function* () {
2
22
  const hookRunners = api.useHookRunners();
3
- await hookRunners.beforeDeploy(options);
4
- await hookRunners.afterDeploy(options);
5
- };
23
+ yield hookRunners.beforeDeploy(options);
24
+ yield hookRunners.afterDeploy(options);
25
+ });
26
+ export {
27
+ deploy
28
+ };
@@ -1,25 +1,62 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import { ResolvedConfigContext } from '@modern-js/core';
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import { ResolvedConfigContext } from "@modern-js/core";
5
41
  import { createFileWatcher } from "../utils/createFileWatcher";
6
42
  import { printInstructions } from "../utils/printInstructions";
7
- import { createServer, injectDataLoaderPlugin } from "../utils/createServer";
43
+ import {
44
+ setServer,
45
+ createServer,
46
+ injectDataLoaderPlugin
47
+ } from "../utils/createServer";
8
48
  import { generateRoutes } from "../utils/routes";
9
49
  import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
10
50
  import { buildServerConfig } from "../utils/config";
11
- export const dev = async (api, options) => {
12
- var _normalizedConfig$too;
51
+ const dev = (api, options) => __async(void 0, null, function* () {
52
+ var _a;
13
53
  if (options.analyze) {
14
- // Builder will read this env var to enable bundle analyzer
15
- process.env.BUNDLE_ANALYZE = 'true';
54
+ process.env.BUNDLE_ANALYZE = "true";
16
55
  }
17
56
  let normalizedConfig = api.useResolvedConfigContext();
18
57
  const appContext = api.useAppContext();
19
58
  const hookRunners = api.useHookRunners();
20
- normalizedConfig = _objectSpread(_objectSpread({}, normalizedConfig), {}, {
21
- cliOptions: options
22
- });
59
+ normalizedConfig = __spreadProps(__spreadValues({}, normalizedConfig), { cliOptions: options });
23
60
  ResolvedConfigContext.set(normalizedConfig);
24
61
  const {
25
62
  appDirectory,
@@ -30,12 +67,15 @@ export const dev = async (api, options) => {
30
67
  serverConfigFile,
31
68
  serverInternalPlugins
32
69
  } = appContext;
33
- const checkedEntries = await getSpecifiedEntries(options.entry || false, entrypoints);
34
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
70
+ const checkedEntries = yield getSpecifiedEntries(
71
+ options.entry || false,
72
+ entrypoints
73
+ );
74
+ api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
35
75
  checkedEntries
36
76
  }));
37
77
  appContext.checkedEntries = checkedEntries;
38
- await buildServerConfig({
78
+ yield buildServerConfig({
39
79
  appDirectory,
40
80
  distDirectory,
41
81
  configFile: serverConfigFile,
@@ -45,20 +85,22 @@ export const dev = async (api, options) => {
45
85
  }
46
86
  }
47
87
  });
48
- await hookRunners.beforeDev();
88
+ yield hookRunners.beforeDev();
49
89
  let compiler;
50
90
  if (!appContext.builder && !apiOnly) {
51
- throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
91
+ throw new Error(
92
+ "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
93
+ );
52
94
  }
53
95
  if (!apiOnly) {
54
- compiler = await appContext.builder.createCompiler();
96
+ compiler = yield appContext.builder.createCompiler();
55
97
  }
56
- await generateRoutes(appContext);
98
+ yield generateRoutes(appContext);
57
99
  const serverOptions = {
58
- dev: _objectSpread({
100
+ dev: __spreadValues({
59
101
  port,
60
102
  https: normalizedConfig.dev.https
61
- }, (_normalizedConfig$too = normalizedConfig.tools) === null || _normalizedConfig$too === void 0 ? void 0 : _normalizedConfig$too.devServer),
103
+ }, (_a = normalizedConfig.tools) == null ? void 0 : _a.devServer),
62
104
  compiler: compiler || null,
63
105
  pwd: appDirectory,
64
106
  config: normalizedConfig,
@@ -66,19 +108,27 @@ export const dev = async (api, options) => {
66
108
  internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
67
109
  };
68
110
  if (apiOnly) {
69
- const app = await createServer(serverOptions);
70
- app.listen(port, async err => {
111
+ const app = yield createServer(serverOptions);
112
+ app.listen(port, (err) => __async(void 0, null, function* () {
71
113
  if (err) {
72
114
  throw err;
73
115
  }
74
116
  printInstructions(hookRunners, appContext, normalizedConfig);
75
- });
117
+ }));
76
118
  } else {
77
- await appContext.builder.startDevServer({
119
+ const { server } = yield appContext.builder.startDevServer({
78
120
  compiler,
79
121
  printURLs: false,
80
122
  serverOptions
81
123
  });
124
+ setServer(server);
82
125
  }
83
- await createFileWatcher(appContext, normalizedConfig.source.configDir, hookRunners);
84
- };
126
+ yield createFileWatcher(
127
+ appContext,
128
+ normalizedConfig.source.configDir,
129
+ hookRunners
130
+ );
131
+ });
132
+ export {
133
+ dev
134
+ };
@@ -1,3 +1,3 @@
1
1
  export * from "./dev";
2
2
  export * from "./build";
3
- export * from "./start";
3
+ export * from "./start";
@@ -1,13 +1,38 @@
1
- import { join } from 'path';
2
- export const inspect = async (api, options) => {
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { join } from "path";
22
+ const inspect = (api, options) => __async(void 0, null, function* () {
3
23
  const appContext = api.useAppContext();
4
24
  if (!appContext.builder) {
5
- throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
25
+ throw new Error(
26
+ "Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
27
+ );
6
28
  }
7
29
  return appContext.builder.inspectConfig({
8
30
  env: options.env,
9
31
  verbose: options.verbose,
10
- outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
32
+ outputPath: join(appContext == null ? void 0 : appContext.builder.context.distPath, options.output),
11
33
  writeToDisk: true
12
34
  });
13
- };
35
+ });
36
+ export {
37
+ inspect
38
+ };
@@ -1,30 +1,52 @@
1
- import { logger, chalk, isApiOnly } from '@modern-js/utils';
2
- import server from '@modern-js/prod-server';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { logger, chalk, isApiOnly } from "@modern-js/utils";
22
+ import server from "@modern-js/prod-server";
3
23
  import { printInstructions } from "../utils/printInstructions";
4
24
  import { injectDataLoaderPlugin } from "../utils/createServer";
5
- export const start = async api => {
6
- var _userConfig$source;
25
+ const start = (api) => __async(void 0, null, function* () {
26
+ var _a;
7
27
  const appContext = api.useAppContext();
8
28
  const userConfig = api.useResolvedConfigContext();
9
29
  const hookRunners = api.useHookRunners();
10
- const {
11
- appDirectory,
12
- port,
13
- serverConfigFile
14
- } = appContext;
30
+ const { appDirectory, port, serverConfigFile } = appContext;
15
31
  logger.log(chalk.cyan(`Starting the modern server...`));
16
- const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
17
- const app = await server({
32
+ const apiOnly = yield isApiOnly(
33
+ appContext.appDirectory,
34
+ (_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.entriesDir
35
+ );
36
+ const app = yield server({
18
37
  pwd: appDirectory,
19
38
  config: userConfig,
20
39
  serverConfigFile,
21
40
  internalPlugins: injectDataLoaderPlugin(appContext.serverInternalPlugins),
22
41
  apiOnly
23
42
  });
24
- app.listen(port, async err => {
43
+ app.listen(port, (err) => __async(void 0, null, function* () {
25
44
  if (err) {
26
45
  throw err;
27
46
  }
28
- await printInstructions(hookRunners, appContext, userConfig);
29
- });
30
- };
47
+ yield printInstructions(hookRunners, appContext, userConfig);
48
+ }));
49
+ });
50
+ export {
51
+ start
52
+ };