@modern-js/app-tools 1.21.5 → 2.0.0-beta.1

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 (170) hide show
  1. package/CHANGELOG.md +319 -51
  2. package/dist/js/modern/analyze/constants.js +1 -0
  3. package/dist/js/modern/analyze/generateCode.js +126 -32
  4. package/dist/js/modern/analyze/getBundleEntry.js +7 -14
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +173 -0
  6. package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +13 -58
  7. package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
  8. package/dist/js/modern/analyze/getClientRoutes/utils.js +18 -0
  9. package/dist/js/modern/analyze/getFileSystemEntry.js +27 -21
  10. package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
  11. package/dist/js/modern/analyze/getServerRoutes.js +15 -32
  12. package/dist/js/modern/analyze/index.js +81 -23
  13. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  14. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  15. package/dist/js/modern/analyze/nestedRoutes.js +102 -0
  16. package/dist/js/modern/analyze/templates.js +151 -12
  17. package/dist/js/modern/analyze/utils.js +2 -8
  18. package/dist/js/modern/builder/builderPlugins/compatModern.js +208 -0
  19. package/dist/js/modern/builder/createHtmlConfig.js +58 -0
  20. package/dist/js/modern/builder/createOutputConfig.js +70 -0
  21. package/dist/js/modern/builder/createSourceConfig.js +74 -0
  22. package/dist/js/modern/builder/createToolsConfig.js +87 -0
  23. package/dist/js/modern/builder/index.js +108 -0
  24. package/dist/js/modern/builder/share.js +44 -0
  25. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +29 -0
  26. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +33 -0
  27. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  28. package/dist/js/modern/commands/build.js +16 -110
  29. package/dist/js/modern/commands/dev.js +12 -28
  30. package/dist/js/modern/commands/inspect.js +8 -66
  31. package/dist/js/modern/commands/start.js +2 -3
  32. package/dist/js/modern/index.js +17 -16
  33. package/dist/js/modern/locale/en.js +0 -1
  34. package/dist/js/modern/locale/zh.js +0 -1
  35. package/dist/js/modern/utils/commands.js +5 -0
  36. package/dist/js/modern/utils/config.js +1 -12
  37. package/dist/js/modern/utils/createServer.js +12 -1
  38. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  39. package/dist/js/modern/utils/printInstructions.js +3 -2
  40. package/dist/js/modern/utils/routes.js +0 -2
  41. package/dist/js/node/analyze/constants.js +3 -1
  42. package/dist/js/node/analyze/generateCode.js +123 -47
  43. package/dist/js/node/analyze/getBundleEntry.js +7 -20
  44. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +181 -0
  45. package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +19 -78
  46. package/dist/js/node/analyze/getClientRoutes/index.js +19 -0
  47. package/dist/js/node/analyze/getClientRoutes/utils.js +28 -0
  48. package/dist/js/node/analyze/getFileSystemEntry.js +26 -28
  49. package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
  50. package/dist/js/node/analyze/getServerRoutes.js +14 -40
  51. package/dist/js/node/analyze/index.js +81 -33
  52. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  53. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  54. package/dist/js/node/analyze/nestedRoutes.js +111 -0
  55. package/dist/js/node/analyze/templates.js +153 -21
  56. package/dist/js/node/analyze/utils.js +4 -20
  57. package/dist/js/node/builder/builderPlugins/compatModern.js +216 -0
  58. package/dist/js/node/builder/createHtmlConfig.js +68 -0
  59. package/dist/js/node/builder/createOutputConfig.js +76 -0
  60. package/dist/js/node/builder/createSourceConfig.js +82 -0
  61. package/dist/js/node/builder/createToolsConfig.js +94 -0
  62. package/dist/js/node/builder/index.js +117 -0
  63. package/dist/js/node/builder/share.js +51 -0
  64. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +36 -0
  65. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +40 -0
  66. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  67. package/dist/js/node/commands/build.js +14 -121
  68. package/dist/js/node/commands/deploy.js +0 -2
  69. package/dist/js/node/commands/dev.js +10 -44
  70. package/dist/js/node/commands/index.js +0 -6
  71. package/dist/js/node/commands/inspect.js +10 -90
  72. package/dist/js/node/commands/start.js +2 -11
  73. package/dist/js/node/exports/server.js +0 -1
  74. package/dist/js/node/hooks.js +0 -2
  75. package/dist/js/node/index.js +22 -32
  76. package/dist/js/node/locale/en.js +0 -1
  77. package/dist/js/node/locale/index.js +0 -4
  78. package/dist/js/node/locale/zh.js +0 -1
  79. package/dist/js/node/utils/commands.js +12 -0
  80. package/dist/js/node/utils/config.js +1 -25
  81. package/dist/js/node/utils/createServer.js +15 -11
  82. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  83. package/dist/js/node/utils/language.js +0 -2
  84. package/dist/js/node/utils/printInstructions.js +3 -6
  85. package/dist/js/node/utils/routes.js +0 -5
  86. package/dist/js/treeshaking/analyze/constants.js +16 -0
  87. package/dist/js/treeshaking/analyze/generateCode.js +369 -0
  88. package/dist/js/treeshaking/analyze/getBundleEntry.js +69 -0
  89. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +184 -0
  90. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +185 -0
  91. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
  92. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +24 -0
  93. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +96 -0
  94. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +129 -0
  95. package/dist/js/treeshaking/analyze/getServerRoutes.js +157 -0
  96. package/dist/js/treeshaking/analyze/index.js +334 -0
  97. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +28 -0
  98. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +16 -0
  99. package/dist/js/treeshaking/analyze/nestedRoutes.js +165 -0
  100. package/dist/js/treeshaking/analyze/templates.js +170 -0
  101. package/dist/js/treeshaking/analyze/utils.js +88 -0
  102. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +212 -0
  103. package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
  104. package/dist/js/treeshaking/builder/createOutputConfig.js +70 -0
  105. package/dist/js/treeshaking/builder/createSourceConfig.js +88 -0
  106. package/dist/js/treeshaking/builder/createToolsConfig.js +85 -0
  107. package/dist/js/treeshaking/builder/index.js +161 -0
  108. package/dist/js/treeshaking/builder/share.js +46 -0
  109. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
  110. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +41 -0
  111. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  112. package/dist/js/treeshaking/commands/build.js +83 -0
  113. package/dist/js/treeshaking/commands/deploy.js +26 -0
  114. package/dist/js/treeshaking/commands/dev.js +124 -0
  115. package/dist/js/treeshaking/commands/index.js +3 -0
  116. package/dist/js/treeshaking/commands/inspect.js +29 -0
  117. package/dist/js/treeshaking/commands/start.js +69 -0
  118. package/dist/js/treeshaking/exports/server.js +1 -0
  119. package/dist/js/treeshaking/hooks.js +21 -0
  120. package/dist/js/treeshaking/index.js +267 -0
  121. package/dist/js/treeshaking/locale/en.js +34 -0
  122. package/dist/js/treeshaking/locale/index.js +9 -0
  123. package/dist/js/treeshaking/locale/zh.js +34 -0
  124. package/dist/js/treeshaking/utils/commands.js +5 -0
  125. package/dist/js/treeshaking/utils/config.js +124 -0
  126. package/dist/js/treeshaking/utils/createServer.js +73 -0
  127. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +58 -0
  128. package/dist/js/treeshaking/utils/language.js +5 -0
  129. package/dist/js/treeshaking/utils/printInstructions.js +30 -0
  130. package/dist/js/treeshaking/utils/routes.js +29 -0
  131. package/dist/js/treeshaking/utils/types.js +0 -0
  132. package/dist/types/analyze/constants.d.ts +1 -0
  133. package/dist/types/analyze/generateCode.d.ts +1 -1
  134. package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
  135. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
  136. package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
  137. package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
  138. package/dist/types/analyze/index.d.ts +4 -5
  139. package/dist/types/analyze/nestedRoutes.d.ts +5 -0
  140. package/dist/types/analyze/templates.d.ts +19 -3
  141. package/dist/types/analyze/utils.d.ts +2 -1
  142. package/dist/types/builder/builderPlugins/compatModern.d.ts +13 -0
  143. package/dist/types/builder/createHtmlConfig.d.ts +6 -0
  144. package/dist/types/builder/createOutputConfig.d.ts +3 -0
  145. package/dist/types/builder/createSourceConfig.d.ts +5 -0
  146. package/dist/types/builder/createToolsConfig.d.ts +13 -0
  147. package/dist/types/builder/index.d.ts +15 -0
  148. package/dist/types/builder/share.d.ts +26 -0
  149. package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
  150. package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
  151. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  152. package/dist/types/commands/build.d.ts +2 -1
  153. package/dist/types/commands/deploy.d.ts +2 -1
  154. package/dist/types/commands/dev.d.ts +2 -1
  155. package/dist/types/commands/inspect.d.ts +2 -6
  156. package/dist/types/commands/start.d.ts +2 -1
  157. package/dist/types/hooks.d.ts +15 -10
  158. package/dist/types/index.d.ts +4 -4
  159. package/dist/types/locale/en.d.ts +0 -1
  160. package/dist/types/locale/index.d.ts +0 -2
  161. package/dist/types/locale/zh.d.ts +0 -1
  162. package/dist/types/utils/commands.d.ts +1 -0
  163. package/dist/types/utils/config.d.ts +0 -1
  164. package/dist/types/utils/createServer.d.ts +8 -1
  165. package/dist/types/utils/printInstructions.d.ts +3 -2
  166. package/dist/types/utils/types.d.ts +2 -3
  167. package/package.json +25 -42
  168. package/dist/js/modern/utils/createCompiler.js +0 -61
  169. package/dist/js/node/utils/createCompiler.js +0 -81
  170. package/dist/types/utils/createCompiler.d.ts +0 -13
@@ -0,0 +1,121 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
7
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import path from 'path';
10
+ import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from '@modern-js/utils';
11
+ var PLUGIN_NAME = 'ModernjsRoutePlugin';
12
+ var RouterPlugin = /*#__PURE__*/function () {
13
+ function RouterPlugin(options) {
14
+ _classCallCheck(this, RouterPlugin);
15
+ _defineProperty(this, "existNestedRoutes", void 0);
16
+ this.existNestedRoutes = options.existNestedRoutes;
17
+ }
18
+ _createClass(RouterPlugin, [{
19
+ key: "apply",
20
+ value: function apply(compiler) {
21
+ var existNestedRoutes = this.existNestedRoutes;
22
+ var target = compiler.options.target;
23
+ if (target === 'node' || Array.isArray(target) && target.includes('node')) {
24
+ return;
25
+ }
26
+ if (!existNestedRoutes) {
27
+ return;
28
+ }
29
+ var webpack = compiler.webpack;
30
+ var Compilation = webpack.Compilation,
31
+ sources = webpack.sources;
32
+ var RawSource = sources.RawSource;
33
+ var PROCESS_ASSETS_STAGE_REPORT = Compilation.PROCESS_ASSETS_STAGE_REPORT;
34
+ var outputPath = compiler.options.output.path;
35
+ var newAssetsMap = new Map();
36
+ var normalizePath = function normalizePath(path) {
37
+ if (!path.endsWith('/')) {
38
+ return "".concat(path, "/");
39
+ }
40
+ return path;
41
+ };
42
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function (compilation) {
43
+ compilation.hooks.processAssets.tapPromise({
44
+ name: PLUGIN_NAME,
45
+ stage: PROCESS_ASSETS_STAGE_REPORT
46
+ }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
47
+ var stats, publicPath, routeAssets, namedChunkGroups, assetsByChunkName, _i, _Object$entries, _Object$entries$_i, name, chunkGroup, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iterator, _step, file, asset, newContent, filename;
48
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ stats = compilation.getStats().toJson({
53
+ chunkGroups: true,
54
+ chunks: true
55
+ });
56
+ publicPath = stats.publicPath;
57
+ routeAssets = {};
58
+ namedChunkGroups = stats.namedChunkGroups, assetsByChunkName = stats.assetsByChunkName;
59
+ if (!(!namedChunkGroups || !assetsByChunkName)) {
60
+ _context.next = 7;
61
+ break;
62
+ }
63
+ logger.warn('Route manifest does not exist, performance will be affected');
64
+ return _context.abrupt("return");
65
+ case 7:
66
+ for (_i = 0, _Object$entries = Object.entries(namedChunkGroups); _i < _Object$entries.length; _i++) {
67
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), name = _Object$entries$_i[0], chunkGroup = _Object$entries$_i[1];
68
+ routeAssets[name] = {
69
+ chunkIds: chunkGroup.chunks,
70
+ assets: assetsByChunkName[name].map(function (item) {
71
+ return publicPath ? normalizePath(publicPath) + item : item;
72
+ })
73
+ };
74
+ }
75
+ manifest = {
76
+ routeAssets: routeAssets
77
+ };
78
+ injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest), ";\n })();\n ");
79
+ entrypointsArray = Array.from(compilation.entrypoints.entries());
80
+ entryChunkIds = entrypointsArray.map(function (entrypoint) {
81
+ return entrypoint[0];
82
+ });
83
+ entryChunks = _toConsumableArray(compilation.chunks).filter(function (chunk) {
84
+ return entryChunkIds.includes(chunk.name);
85
+ });
86
+ entryChunkFiles = entryChunks.map(function (chunk) {
87
+ return _toConsumableArray(chunk.files)[0];
88
+ });
89
+ _iterator = _createForOfIteratorHelper(entryChunkFiles);
90
+ try {
91
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
92
+ file = _step.value;
93
+ asset = compilation.assets[file];
94
+ newContent = "".concat(injectedContent).concat(asset.source().toString());
95
+ newAssetsMap.set(path.join(outputPath, file), newContent);
96
+ compilation.updateAsset(file, new RawSource(newContent));
97
+ }
98
+ } catch (err) {
99
+ _iterator.e(err);
100
+ } finally {
101
+ _iterator.f();
102
+ }
103
+ filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
104
+ _context.next = 19;
105
+ return fs.ensureFile(filename);
106
+ case 19:
107
+ _context.next = 21;
108
+ return fs.writeFile(filename, JSON.stringify(manifest, null, 2));
109
+ case 21:
110
+ case "end":
111
+ return _context.stop();
112
+ }
113
+ }
114
+ }, _callee);
115
+ })));
116
+ });
117
+ }
118
+ }]);
119
+ return RouterPlugin;
120
+ }();
121
+ export { RouterPlugin as default };
@@ -0,0 +1,83 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import { ResolvedConfigContext } from '@modern-js/core';
5
+ import { logger, printBuildError } from '@modern-js/utils';
6
+ import { generateRoutes } from "../utils/routes";
7
+ import { buildServerConfig } from "../utils/config";
8
+ export var build = /*#__PURE__*/function () {
9
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
10
+ var resolvedConfig, appContext, hookRunners, apiOnly, _appDirectory, _distDirectory, _serverConfigFile, distDirectory, appDirectory, serverConfigFile, _appContext$builder;
11
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
12
+ while (1) {
13
+ switch (_context.prev = _context.next) {
14
+ case 0:
15
+ resolvedConfig = api.useResolvedConfigContext();
16
+ appContext = api.useAppContext();
17
+ hookRunners = api.useHookRunners();
18
+ apiOnly = appContext.apiOnly;
19
+ if (!apiOnly) {
20
+ _context.next = 15;
21
+ break;
22
+ }
23
+ _appDirectory = appContext.appDirectory, _distDirectory = appContext.distDirectory, _serverConfigFile = appContext.serverConfigFile;
24
+ _context.next = 8;
25
+ return hookRunners.beforeBuild({
26
+ // "null" bundlerConfigs
27
+ bundlerConfigs: undefined
28
+ });
29
+ case 8:
30
+ _context.next = 10;
31
+ return buildServerConfig({
32
+ appDirectory: _appDirectory,
33
+ distDirectory: _distDirectory,
34
+ configFile: _serverConfigFile
35
+ });
36
+ case 10:
37
+ _context.next = 12;
38
+ return generateRoutes(appContext);
39
+ case 12:
40
+ _context.next = 14;
41
+ return hookRunners.afterBuild({
42
+ // "null" stats
43
+ stats: undefined
44
+ });
45
+ case 14:
46
+ return _context.abrupt("return");
47
+ case 15:
48
+ resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
49
+ cliOptions: options
50
+ });
51
+ ResolvedConfigContext.set(resolvedConfig);
52
+ distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, serverConfigFile = appContext.serverConfigFile;
53
+ _context.next = 20;
54
+ return buildServerConfig({
55
+ appDirectory: appDirectory,
56
+ distDirectory: distDirectory,
57
+ configFile: serverConfigFile
58
+ });
59
+ case 20:
60
+ _context.prev = 20;
61
+ logger.info('Create a production build...\n');
62
+ _context.next = 24;
63
+ return (_appContext$builder = appContext.builder) === null || _appContext$builder === void 0 ? void 0 : _appContext$builder.build();
64
+ case 24:
65
+ _context.next = 30;
66
+ break;
67
+ case 26:
68
+ _context.prev = 26;
69
+ _context.t0 = _context["catch"](20);
70
+ printBuildError(_context.t0);
71
+ // eslint-disable-next-line no-process-exit
72
+ process.exit(1);
73
+ case 30:
74
+ case "end":
75
+ return _context.stop();
76
+ }
77
+ }
78
+ }, _callee, null, [[20, 26]]);
79
+ }));
80
+ return function build(_x, _x2) {
81
+ return _ref.apply(this, arguments);
82
+ };
83
+ }();
@@ -0,0 +1,26 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ export var deploy = /*#__PURE__*/function () {
4
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
5
+ var hookRunners;
6
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7
+ while (1) {
8
+ switch (_context.prev = _context.next) {
9
+ case 0:
10
+ hookRunners = api.useHookRunners();
11
+ _context.next = 3;
12
+ return hookRunners.beforeDeploy(options);
13
+ case 3:
14
+ _context.next = 5;
15
+ return hookRunners.afterDeploy(options);
16
+ case 5:
17
+ case "end":
18
+ return _context.stop();
19
+ }
20
+ }
21
+ }, _callee);
22
+ }));
23
+ return function deploy(_x, _x2) {
24
+ return _ref.apply(this, arguments);
25
+ };
26
+ }();
@@ -0,0 +1,124 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ import { logger } from '@modern-js/utils';
5
+ import { ResolvedConfigContext } from '@modern-js/core';
6
+ import { printInstructions } from "../utils/printInstructions";
7
+ import { createServer, injectDataLoaderPlugin } from "../utils/createServer";
8
+ import { generateRoutes } from "../utils/routes";
9
+ import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
10
+ import { buildServerConfig } from "../utils/config";
11
+ export var dev = /*#__PURE__*/function () {
12
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(api, options) {
13
+ var userConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile, serverInternalPlugins, checkedEntries, compiler, _appContext$builder, app;
14
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
15
+ while (1) {
16
+ switch (_context2.prev = _context2.next) {
17
+ case 0:
18
+ userConfig = api.useResolvedConfigContext();
19
+ appContext = api.useAppContext();
20
+ hookRunners = api.useHookRunners();
21
+ userConfig = _objectSpread(_objectSpread({}, userConfig), {}, {
22
+ cliOptions: options
23
+ });
24
+ ResolvedConfigContext.set(userConfig);
25
+ appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile, serverInternalPlugins = appContext.serverInternalPlugins;
26
+ _context2.next = 8;
27
+ return getSpecifiedEntries(options.entry || false, entrypoints);
28
+ case 8:
29
+ checkedEntries = _context2.sent;
30
+ api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
31
+ checkedEntries: checkedEntries
32
+ }));
33
+ appContext.checkedEntries = checkedEntries;
34
+ _context2.next = 13;
35
+ return buildServerConfig({
36
+ appDirectory: appDirectory,
37
+ distDirectory: distDirectory,
38
+ configFile: serverConfigFile,
39
+ options: {
40
+ esbuildOptions: {
41
+ watch: true
42
+ }
43
+ }
44
+ });
45
+ case 13:
46
+ _context2.next = 15;
47
+ return hookRunners.beforeDev();
48
+ case 15:
49
+ compiler = null;
50
+ if (apiOnly) {
51
+ _context2.next = 20;
52
+ break;
53
+ }
54
+ _context2.next = 19;
55
+ return (_appContext$builder = appContext.builder) === null || _appContext$builder === void 0 ? void 0 : _appContext$builder.createCompiler();
56
+ case 19:
57
+ compiler = _context2.sent;
58
+ case 20:
59
+ _context2.next = 22;
60
+ return generateRoutes(appContext);
61
+ case 22:
62
+ _context2.next = 24;
63
+ return createServer({
64
+ dev: _objectSpread(_objectSpread({}, {
65
+ client: {
66
+ port: port.toString()
67
+ },
68
+ devMiddleware: {
69
+ writeToDisk: function writeToDisk(file) {
70
+ return !file.includes('.hot-update.');
71
+ }
72
+ },
73
+ hot: true,
74
+ liveReload: true,
75
+ port: port,
76
+ https: userConfig.dev.https
77
+ }), userConfig.tools.devServer),
78
+ compiler: compiler,
79
+ pwd: appDirectory,
80
+ config: userConfig,
81
+ serverConfigFile: serverConfigFile,
82
+ internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
83
+ });
84
+ case 24:
85
+ app = _context2.sent;
86
+ app.listen(port, /*#__PURE__*/function () {
87
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
88
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
89
+ while (1) {
90
+ switch (_context.prev = _context.next) {
91
+ case 0:
92
+ if (!err) {
93
+ _context.next = 2;
94
+ break;
95
+ }
96
+ throw err;
97
+ case 2:
98
+ if (!apiOnly) {
99
+ logger.info("Starting dev server...\n");
100
+ } else {
101
+ printInstructions(hookRunners, appContext, userConfig);
102
+ }
103
+ case 3:
104
+ case "end":
105
+ return _context.stop();
106
+ }
107
+ }
108
+ }, _callee);
109
+ }));
110
+ return function (_x3) {
111
+ return _ref2.apply(this, arguments);
112
+ };
113
+ }());
114
+ case 26:
115
+ case "end":
116
+ return _context2.stop();
117
+ }
118
+ }
119
+ }, _callee2);
120
+ }));
121
+ return function dev(_x, _x2) {
122
+ return _ref.apply(this, arguments);
123
+ };
124
+ }();
@@ -0,0 +1,3 @@
1
+ export * from "./dev";
2
+ export * from "./build";
3
+ export * from "./start";
@@ -0,0 +1,29 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import { join } from 'path';
4
+ export var inspect = /*#__PURE__*/function () {
5
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
6
+ var _appContext$builder;
7
+ var appContext;
8
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
9
+ while (1) {
10
+ switch (_context.prev = _context.next) {
11
+ case 0:
12
+ appContext = api.useAppContext();
13
+ return _context.abrupt("return", (_appContext$builder = appContext.builder) === null || _appContext$builder === void 0 ? void 0 : _appContext$builder.inspectConfig({
14
+ env: options.env,
15
+ verbose: options.verbose,
16
+ outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
17
+ writeToDisk: true
18
+ }));
19
+ case 2:
20
+ case "end":
21
+ return _context.stop();
22
+ }
23
+ }
24
+ }, _callee);
25
+ }));
26
+ return function inspect(_x, _x2) {
27
+ return _ref.apply(this, arguments);
28
+ };
29
+ }();
@@ -0,0 +1,69 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import { logger, chalk, isApiOnly } from '@modern-js/utils';
4
+ import server from '@modern-js/prod-server';
5
+ import { printInstructions } from "../utils/printInstructions";
6
+ import { injectDataLoaderPlugin } from "../utils/createServer";
7
+ export var start = /*#__PURE__*/function () {
8
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(api) {
9
+ var _userConfig$source;
10
+ var appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, app;
11
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
12
+ while (1) {
13
+ switch (_context2.prev = _context2.next) {
14
+ case 0:
15
+ appContext = api.useAppContext();
16
+ userConfig = api.useResolvedConfigContext();
17
+ hookRunners = api.useHookRunners();
18
+ appDirectory = appContext.appDirectory, port = appContext.port, serverConfigFile = appContext.serverConfigFile;
19
+ logger.log(chalk.cyan("Starting the modern server..."));
20
+ _context2.next = 7;
21
+ return isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
22
+ case 7:
23
+ apiOnly = _context2.sent;
24
+ _context2.next = 10;
25
+ return server({
26
+ pwd: appDirectory,
27
+ config: userConfig,
28
+ serverConfigFile: serverConfigFile,
29
+ internalPlugins: injectDataLoaderPlugin(appContext.serverInternalPlugins),
30
+ apiOnly: apiOnly
31
+ });
32
+ case 10:
33
+ app = _context2.sent;
34
+ app.listen(port, /*#__PURE__*/function () {
35
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
36
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
37
+ while (1) {
38
+ switch (_context.prev = _context.next) {
39
+ case 0:
40
+ if (!err) {
41
+ _context.next = 2;
42
+ break;
43
+ }
44
+ throw err;
45
+ case 2:
46
+ _context.next = 4;
47
+ return printInstructions(hookRunners, appContext, userConfig);
48
+ case 4:
49
+ case "end":
50
+ return _context.stop();
51
+ }
52
+ }
53
+ }, _callee);
54
+ }));
55
+ return function (_x2) {
56
+ return _ref2.apply(this, arguments);
57
+ };
58
+ }());
59
+ case 12:
60
+ case "end":
61
+ return _context2.stop();
62
+ }
63
+ }
64
+ }, _callee2);
65
+ }));
66
+ return function start(_x) {
67
+ return _ref.apply(this, arguments);
68
+ };
69
+ }();
@@ -0,0 +1 @@
1
+ export { defineServerConfig as defineConfig } from "../utils/config";
@@ -0,0 +1,21 @@
1
+ import { createAsyncWaterfall, createAsyncWorkflow } from '@modern-js/plugin';
2
+ export var beforeDev = createAsyncWorkflow();
3
+ export var afterDev = createAsyncWorkflow();
4
+ export var beforeCreateCompiler = createAsyncWorkflow();
5
+ export var afterCreateCompiler = createAsyncWorkflow();
6
+ export var beforePrintInstructions = createAsyncWaterfall();
7
+ export var beforeBuild = createAsyncWorkflow();
8
+ export var afterBuild = createAsyncWorkflow();
9
+ export var beforeDeploy = createAsyncWorkflow();
10
+ export var afterDeploy = createAsyncWorkflow();
11
+ export var hooks = {
12
+ beforeDev: beforeDev,
13
+ afterDev: afterDev,
14
+ beforeCreateCompiler: beforeCreateCompiler,
15
+ afterCreateCompiler: afterCreateCompiler,
16
+ beforePrintInstructions: beforePrintInstructions,
17
+ beforeBuild: beforeBuild,
18
+ afterBuild: afterBuild,
19
+ beforeDeploy: beforeDeploy,
20
+ afterDeploy: afterDeploy
21
+ };