@modern-js/app-tools 2.53.1-alpha.3 → 2.54.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/dependencies/index.js +16 -25
  20. package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
  21. package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
  22. package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
  23. package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
  24. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  25. package/dist/cjs/plugins/serverBuild.js +10 -4
  26. package/dist/cjs/utils/createServer.js +1 -1
  27. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  28. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  29. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  30. package/dist/esm/commands/build.js +16 -9
  31. package/dist/esm/commands/deploy.js +2 -2
  32. package/dist/esm/commands/dev.js +13 -9
  33. package/dist/esm/commands/index.js +411 -3
  34. package/dist/esm/commands/serve.js +12 -8
  35. package/dist/esm/hooks.js +5 -0
  36. package/dist/esm/index.js +12 -394
  37. package/dist/esm/plugins/analyze/constants.js +24 -0
  38. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  39. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  40. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  41. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  42. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  43. package/dist/esm/plugins/analyze/templates.js +22 -0
  44. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  45. package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
  46. package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
  47. package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
  48. package/dist/esm/plugins/deploy/platforms/node.js +8 -14
  49. package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
  50. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  51. package/dist/esm/plugins/serverBuild.js +13 -6
  52. package/dist/esm/utils/createServer.js +2 -2
  53. package/dist/esm/utils/loadPlugins.js +64 -0
  54. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  55. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  56. package/dist/esm-node/commands/build.js +2 -0
  57. package/dist/esm-node/commands/deploy.js +2 -2
  58. package/dist/esm-node/commands/dev.js +11 -7
  59. package/dist/esm-node/commands/index.js +92 -3
  60. package/dist/esm-node/commands/serve.js +10 -6
  61. package/dist/esm-node/hooks.js +5 -0
  62. package/dist/esm-node/index.js +12 -79
  63. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  64. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  65. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  66. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  67. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  68. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  69. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  70. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  71. package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
  72. package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
  73. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
  74. package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
  75. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
  76. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  77. package/dist/esm-node/plugins/serverBuild.js +11 -5
  78. package/dist/esm-node/utils/createServer.js +2 -2
  79. package/dist/esm-node/utils/loadPlugins.js +21 -0
  80. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  81. package/dist/types/commands/index.d.ts +10 -3
  82. package/dist/types/config/initialize/inits.d.ts +1 -1
  83. package/dist/types/exports/server.d.ts +4 -0
  84. package/dist/types/index.d.ts +2 -5
  85. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  86. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  87. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  88. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  89. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  90. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  91. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  92. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  93. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  94. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -9
  95. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
  96. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  97. package/dist/types/types/hooks.d.ts +11 -1
  98. package/dist/types/utils/loadPlugins.d.ts +5 -0
  99. package/package.json +22 -30
  100. package/dist/cjs/analyze/constants.js +0 -122
  101. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  102. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  103. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  104. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  105. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  106. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  107. package/dist/cjs/analyze/templates.js +0 -444
  108. package/dist/cjs/plugins/deploy/exports.js +0 -28
  109. package/dist/esm/analyze/constants.js +0 -76
  110. package/dist/esm/analyze/getBundleEntry.js +0 -75
  111. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  112. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  113. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  114. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  115. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  116. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  117. package/dist/esm/analyze/nestedRoutes.js +0 -398
  118. package/dist/esm/analyze/templates.js +0 -435
  119. package/dist/esm/plugins/deploy/exports.js +0 -4
  120. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  121. package/dist/esm-node/analyze/constants.js +0 -76
  122. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  123. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  124. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  125. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  126. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  127. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  128. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  129. package/dist/esm-node/analyze/templates.js +0 -405
  130. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  131. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  132. package/dist/js/modern/analyze/constants.js +0 -15
  133. package/dist/js/modern/analyze/generateCode.js +0 -179
  134. package/dist/js/modern/analyze/getBundleEntry.js +0 -75
  135. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  136. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
  137. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
  138. package/dist/js/modern/analyze/getServerRoutes.js +0 -192
  139. package/dist/js/modern/analyze/index.js +0 -148
  140. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
  141. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
  142. package/dist/js/modern/analyze/templates.js +0 -88
  143. package/dist/js/modern/analyze/utils.js +0 -92
  144. package/dist/js/modern/commands/build.js +0 -154
  145. package/dist/js/modern/commands/deploy.js +0 -5
  146. package/dist/js/modern/commands/dev.js +0 -95
  147. package/dist/js/modern/commands/index.js +0 -3
  148. package/dist/js/modern/commands/inspect.js +0 -69
  149. package/dist/js/modern/commands/start.js +0 -31
  150. package/dist/js/modern/exports/server.js +0 -1
  151. package/dist/js/modern/hooks.js +0 -21
  152. package/dist/js/modern/index.js +0 -109
  153. package/dist/js/modern/locale/en.js +0 -35
  154. package/dist/js/modern/locale/index.js +0 -9
  155. package/dist/js/modern/locale/zh.js +0 -35
  156. package/dist/js/modern/utils/config.js +0 -78
  157. package/dist/js/modern/utils/createCompiler.js +0 -61
  158. package/dist/js/modern/utils/createServer.js +0 -18
  159. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
  160. package/dist/js/modern/utils/language.js +0 -5
  161. package/dist/js/modern/utils/printInstructions.js +0 -11
  162. package/dist/js/modern/utils/routes.js +0 -15
  163. package/dist/js/modern/utils/types.js +0 -0
  164. package/dist/js/node/analyze/constants.js +0 -36
  165. package/dist/js/node/analyze/generateCode.js +0 -208
  166. package/dist/js/node/analyze/getBundleEntry.js +0 -89
  167. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  168. package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
  169. package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
  170. package/dist/js/node/analyze/getServerRoutes.js +0 -208
  171. package/dist/js/node/analyze/index.js +0 -178
  172. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
  173. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
  174. package/dist/js/node/analyze/templates.js +0 -106
  175. package/dist/js/node/analyze/utils.js +0 -113
  176. package/dist/js/node/commands/build.js +0 -174
  177. package/dist/js/node/commands/deploy.js +0 -14
  178. package/dist/js/node/commands/dev.js +0 -120
  179. package/dist/js/node/commands/index.js +0 -44
  180. package/dist/js/node/commands/inspect.js +0 -98
  181. package/dist/js/node/commands/start.js +0 -47
  182. package/dist/js/node/exports/server.js +0 -13
  183. package/dist/js/node/hooks.js +0 -39
  184. package/dist/js/node/index.js +0 -141
  185. package/dist/js/node/locale/en.js +0 -42
  186. package/dist/js/node/locale/index.js +0 -20
  187. package/dist/js/node/locale/zh.js +0 -42
  188. package/dist/js/node/utils/config.js +0 -103
  189. package/dist/js/node/utils/createCompiler.js +0 -81
  190. package/dist/js/node/utils/createServer.js +0 -35
  191. package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
  192. package/dist/js/node/utils/language.js +0 -13
  193. package/dist/js/node/utils/printInstructions.js +0 -22
  194. package/dist/js/node/utils/routes.js +0 -25
  195. package/dist/js/node/utils/types.js +0 -0
  196. package/dist/types/analyze/constants.d.ts +0 -42
  197. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  198. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  199. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  200. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  201. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  202. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  203. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  204. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  205. package/dist/types/analyze/templates.d.ts +0 -30
  206. package/dist/types/plugins/deploy/exports.d.ts +0 -1
  207. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  208. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  209. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  210. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  211. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  212. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  213. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  214. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.dev = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- var _core = require("@modern-js/core");
11
-
12
- var _createCompiler = require("../utils/createCompiler");
13
-
14
- var _createServer = require("../utils/createServer");
15
-
16
- var _routes = require("../utils/routes");
17
-
18
- var _printInstructions = require("../utils/printInstructions");
19
-
20
- var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
21
-
22
- var _config = require("../utils/config");
23
-
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
- 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; }
29
-
30
- 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; }
31
-
32
- 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; }
33
-
34
- const dev = async (api, options) => {
35
- let userConfig = api.useResolvedConfigContext();
36
- const appContext = api.useAppContext();
37
- const hookRunners = api.useHookRunners();
38
- userConfig = _objectSpread(_objectSpread({}, userConfig), {}, {
39
- cliOptions: options
40
- });
41
-
42
- _core.ResolvedConfigContext.set(userConfig);
43
-
44
- const {
45
- appDirectory,
46
- distDirectory,
47
- port,
48
- apiOnly,
49
- entrypoints,
50
- serverConfigFile
51
- } = appContext;
52
- const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
53
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
54
- checkedEntries
55
- }));
56
- appContext.checkedEntries = checkedEntries;
57
-
58
- _utils.fs.emptyDirSync(distDirectory);
59
-
60
- await (0, _config.buildServerConfig)({
61
- appDirectory,
62
- distDirectory,
63
- configFile: serverConfigFile,
64
- options: {
65
- esbuildOptions: {
66
- watch: true
67
- }
68
- }
69
- });
70
- await hookRunners.beforeDev();
71
- let compiler = null;
72
-
73
- if (!apiOnly) {
74
- const {
75
- getWebpackConfig,
76
- WebpackConfigTarget
77
- } = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
78
- const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE, appContext, userConfig), getWebpackConfig(WebpackConfigTarget.CLIENT, appContext, userConfig)].filter(Boolean);
79
- compiler = await (0, _createCompiler.createCompiler)({
80
- api,
81
- webpackConfigs,
82
- userConfig,
83
- appContext
84
- });
85
- }
86
-
87
- await (0, _routes.generateRoutes)(appContext);
88
- const app = await (0, _createServer.createServer)({
89
- dev: _objectSpread(_objectSpread({}, {
90
- client: {
91
- port: port.toString()
92
- },
93
- devMiddleware: {
94
- writeToDisk: file => !file.includes('.hot-update.')
95
- },
96
- hot: true,
97
- liveReload: true,
98
- port,
99
- https: userConfig.dev.https
100
- }), userConfig.tools.devServer),
101
- compiler,
102
- pwd: appDirectory,
103
- config: userConfig,
104
- serverConfigFile,
105
- plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
106
- });
107
- app.listen(port, async err => {
108
- if (err) {
109
- throw err;
110
- }
111
-
112
- if (apiOnly) {
113
- return (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
114
- }
115
-
116
- return _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
117
- });
118
- };
119
-
120
- exports.dev = dev;
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _dev = require("./dev");
8
-
9
- Object.keys(_dev).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _dev[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _dev[key];
16
- }
17
- });
18
- });
19
-
20
- var _build = require("./build");
21
-
22
- Object.keys(_build).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _build[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _build[key];
29
- }
30
- });
31
- });
32
-
33
- var _start = require("./start");
34
-
35
- Object.keys(_start).forEach(function (key) {
36
- if (key === "default" || key === "__esModule") return;
37
- if (key in exports && exports[key] === _start[key]) return;
38
- Object.defineProperty(exports, key, {
39
- enumerable: true,
40
- get: function () {
41
- return _start[key];
42
- }
43
- });
44
- });
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.printInspectResult = exports.inspect = exports.getTagByWebpackTarget = exports.formatWebpackConfig = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _webpack = require("@modern-js/webpack");
11
-
12
- var _utils = require("@modern-js/utils");
13
-
14
- var _webpackChain = _interopRequireDefault(require("@modern-js/utils/webpack-chain"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const formatWebpackConfig = (config, verbose) => {
19
- const stringify = _webpackChain.default.toString;
20
- return `module.exports = ${stringify(config, {
21
- verbose
22
- })};`;
23
- };
24
-
25
- exports.formatWebpackConfig = formatWebpackConfig;
26
-
27
- const inspect = (api, options) => {
28
- process.env.NODE_ENV = options.env;
29
- const resolvedConfig = api.useResolvedConfigContext();
30
- const appContext = api.useAppContext();
31
- const outputFiles = [];
32
- outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig, options));
33
-
34
- if (resolvedConfig.output.enableModernMode) {
35
- outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig, options));
36
- }
37
-
38
- if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
39
- outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig, options));
40
- }
41
-
42
- _utils.logger.success('Inspect succeed, you can open following files to view the full webpack config: \n');
43
-
44
- outputFiles.forEach(file => {
45
- _utils.logger.log(` - ${_utils.chalk.yellow(_path.default.relative(appContext.appDirectory, file))}`);
46
- });
47
-
48
- _utils.logger.log();
49
- };
50
-
51
- exports.inspect = inspect;
52
-
53
- const getTagByWebpackTarget = webpackTarget => {
54
- switch (webpackTarget) {
55
- case _webpack.WebpackConfigTarget.CLIENT:
56
- return 'client';
57
-
58
- case _webpack.WebpackConfigTarget.MODERN:
59
- return 'modern';
60
-
61
- case _webpack.WebpackConfigTarget.NODE:
62
- return 'ssr';
63
-
64
- default:
65
- throw Error(`Unsupported webpack target: ${webpackTarget}`);
66
- }
67
- };
68
-
69
- exports.getTagByWebpackTarget = getTagByWebpackTarget;
70
-
71
- const printInspectResult = (webpackTarget, appContext, resolvedConfig, options) => {
72
- const webpackConfig = (0, _webpack.getWebpackConfig)(webpackTarget, appContext, resolvedConfig);
73
- const {
74
- output,
75
- verbose,
76
- console = true
77
- } = options;
78
- const outputPath = output ? _path.default.posix.join(appContext.distDirectory, output) : appContext.distDirectory;
79
- const tag = getTagByWebpackTarget(webpackTarget);
80
- const outputFile = `webpack.${tag}.inspect.js`;
81
-
82
- const outputFilePath = _path.default.posix.join(outputPath, outputFile);
83
-
84
- const rawWebpackConfig = formatWebpackConfig(webpackConfig, verbose);
85
-
86
- _utils.fs.outputFileSync(outputFilePath, rawWebpackConfig);
87
-
88
- if (console) {
89
- _utils.logger.log(`
90
- webpack config for ${tag} build:
91
- ${rawWebpackConfig}
92
- `);
93
- }
94
-
95
- return outputFilePath;
96
- };
97
-
98
- exports.printInspectResult = printInspectResult;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.start = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
11
-
12
- var _printInstructions = require("../utils/printInstructions");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const start = async api => {
17
- var _userConfig$source;
18
-
19
- const appContext = api.useAppContext();
20
- const userConfig = api.useResolvedConfigContext();
21
- const hookRunners = api.useHookRunners();
22
- const {
23
- appDirectory,
24
- port,
25
- serverConfigFile
26
- } = appContext;
27
-
28
- _utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
29
-
30
- const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
31
- const app = await (0, _prodServer.default)({
32
- pwd: appDirectory,
33
- config: userConfig,
34
- plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
35
- serverConfigFile,
36
- apiOnly
37
- });
38
- app.listen(port, async err => {
39
- if (err) {
40
- throw err;
41
- }
42
-
43
- await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
44
- });
45
- };
46
-
47
- exports.start = start;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "defineConfig", {
7
- enumerable: true,
8
- get: function () {
9
- return _config.defineServerConfig;
10
- }
11
- });
12
-
13
- var _config = require("../utils/config");
@@ -1,39 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hooks = exports.beforePrintInstructions = exports.beforeDev = exports.beforeDeploy = exports.beforeCreateCompiler = exports.beforeBuild = exports.afterDev = exports.afterDeploy = exports.afterCreateCompiler = exports.afterBuild = void 0;
7
-
8
- var _plugin = require("@modern-js/plugin");
9
-
10
- const beforeDev = (0, _plugin.createAsyncWorkflow)();
11
- exports.beforeDev = beforeDev;
12
- const afterDev = (0, _plugin.createAsyncWorkflow)();
13
- exports.afterDev = afterDev;
14
- const beforeCreateCompiler = (0, _plugin.createAsyncWorkflow)();
15
- exports.beforeCreateCompiler = beforeCreateCompiler;
16
- const afterCreateCompiler = (0, _plugin.createAsyncWorkflow)();
17
- exports.afterCreateCompiler = afterCreateCompiler;
18
- const beforePrintInstructions = (0, _plugin.createAsyncWaterfall)();
19
- exports.beforePrintInstructions = beforePrintInstructions;
20
- const beforeBuild = (0, _plugin.createAsyncWorkflow)();
21
- exports.beforeBuild = beforeBuild;
22
- const afterBuild = (0, _plugin.createAsyncWorkflow)();
23
- exports.afterBuild = afterBuild;
24
- const beforeDeploy = (0, _plugin.createAsyncWorkflow)();
25
- exports.beforeDeploy = beforeDeploy;
26
- const afterDeploy = (0, _plugin.createAsyncWorkflow)();
27
- exports.afterDeploy = afterDeploy;
28
- const hooks = {
29
- beforeDev,
30
- afterDev,
31
- beforeCreateCompiler,
32
- afterCreateCompiler,
33
- beforePrintInstructions,
34
- beforeBuild,
35
- afterBuild,
36
- beforeDeploy,
37
- afterDeploy
38
- };
39
- exports.hooks = hooks;
@@ -1,141 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- Object.defineProperty(exports, "defineConfig", {
8
- enumerable: true,
9
- get: function () {
10
- return _core.defineConfig;
11
- }
12
- });
13
-
14
- var _path = _interopRequireDefault(require("path"));
15
-
16
- var _core = require("@modern-js/core");
17
-
18
- var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
19
-
20
- var _utils = require("@modern-js/utils");
21
-
22
- var _analyze = _interopRequireDefault(require("./analyze"));
23
-
24
- var _hooks = require("./hooks");
25
-
26
- var _locale = require("./locale");
27
-
28
- var _language = require("./utils/language");
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- 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; }
33
-
34
- 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; }
35
-
36
- 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; }
37
-
38
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
-
40
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
-
42
- const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
43
-
44
- var _default = () => ({
45
- name: '@modern-js/app-tools',
46
- post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
47
- registerHook: _hooks.hooks,
48
- usePlugins: [(0, _analyze.default)(), (0, _pluginJarvis.default)()],
49
- setup: api => {
50
- const locale = (0, _language.getLocaleLanguage)();
51
-
52
- _locale.i18n.changeLanguage({
53
- locale
54
- });
55
-
56
- return {
57
- commands({
58
- program
59
- }) {
60
- program.command('dev').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.dev.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).option('-e --entry [entry...]', _locale.i18n.t(_locale.localeKeys.command.dev.entry)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.shared.analyze)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).action(async options => {
61
- const {
62
- dev
63
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/dev")));
64
- await dev(api, options);
65
- });
66
- program.command('build').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.build.describe)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).option('--analyze', _locale.i18n.t(_locale.localeKeys.command.shared.analyze)).action(async options => {
67
- const {
68
- build
69
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
70
- await build(api, options); // force exit after build.
71
- // eslint-disable-next-line no-process-exit
72
-
73
- process.exit(0);
74
- });
75
- program.command('start').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.start.describe)).option('--api-only', _locale.i18n.t(_locale.localeKeys.command.dev.apiOnly)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async () => {
76
- const {
77
- start
78
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/start")));
79
- await start(api);
80
- });
81
- program.command('deploy').usage('[options]').option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).description(_locale.i18n.t(_locale.localeKeys.command.deploy.describe)).action(async options => {
82
- const {
83
- build
84
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/build")));
85
- await build(api);
86
- const {
87
- deploy
88
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/deploy")));
89
- await deploy(api, options); // eslint-disable-next-line no-process-exit
90
-
91
- process.exit(0);
92
- });
93
- program.command('new').usage('[options]').description(_locale.i18n.t(_locale.localeKeys.command.new.describe)).option('-d, --debug', _locale.i18n.t(_locale.localeKeys.command.new.debug), false).option('-c, --config <config>', _locale.i18n.t(_locale.localeKeys.command.new.config)).option('--dist-tag <tag>', _locale.i18n.t(_locale.localeKeys.command.new.distTag)).option('--registry', _locale.i18n.t(_locale.localeKeys.command.new.registry)).action(async options => {
94
- const {
95
- MWANewAction
96
- } = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/new-action')));
97
- await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
98
- locale
99
- }));
100
- });
101
- program.command('inspect').description('inspect internal webpack config').option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), 'development').option('--output <output>', _locale.i18n.t(_locale.localeKeys.command.inspect.output), '/').option('--no-console', _locale.i18n.t(_locale.localeKeys.command.inspect.noConsole)).option('--verbose', _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async options => {
102
- const {
103
- inspect
104
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/inspect")));
105
- inspect(api, options);
106
- });
107
- upgradeModel.defineCommand(program.command('upgrade'));
108
- },
109
-
110
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
111
- async fileChange(e) {
112
- const {
113
- filename,
114
- eventType
115
- } = e;
116
- const appContext = api.useAppContext();
117
- const {
118
- appDirectory,
119
- srcDirectory
120
- } = appContext;
121
-
122
- const absolutePath = _path.default.resolve(appDirectory, filename);
123
-
124
- if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
125
- const {
126
- closeServer
127
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./utils/createServer")));
128
- await closeServer();
129
- await _core.cli.restart();
130
- }
131
- },
132
-
133
- async beforeRestart() {
134
- (0, _utils.cleanRequireCache)([require.resolve("./analyze")]);
135
- }
136
-
137
- };
138
- }
139
- });
140
-
141
- exports.default = _default;
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.EN_LOCALE = void 0;
7
- const EN_LOCALE = {
8
- command: {
9
- shared: {
10
- analyze: 'analyze bundle size',
11
- config: 'specify config file'
12
- },
13
- dev: {
14
- describe: 'start dev server',
15
- entry: 'compiler by entry',
16
- apiOnly: 'start api server only'
17
- },
18
- build: {
19
- describe: 'build application'
20
- },
21
- start: {
22
- describe: 'start server'
23
- },
24
- deploy: {
25
- describe: 'deploy application'
26
- },
27
- new: {
28
- describe: 'generator runner for MWA project',
29
- debug: 'using debug mode to log something',
30
- config: 'set default generator config(json string)',
31
- distTag: `use specified tag version for it's generator`,
32
- registry: 'set npm registry url to run npm command'
33
- },
34
- inspect: {
35
- env: 'specify env mode',
36
- output: 'specify inspect content output path',
37
- noConsole: 'do not log the result in terminal',
38
- verbose: 'show full function definitions in output'
39
- }
40
- }
41
- };
42
- exports.EN_LOCALE = EN_LOCALE;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.localeKeys = exports.i18n = void 0;
7
-
8
- var _pluginI18n = require("@modern-js/plugin-i18n");
9
-
10
- var _zh = require("./zh");
11
-
12
- var _en = require("./en");
13
-
14
- const i18n = new _pluginI18n.I18n();
15
- exports.i18n = i18n;
16
- const localeKeys = i18n.init('zh', {
17
- zh: _zh.ZH_LOCALE,
18
- en: _en.EN_LOCALE
19
- });
20
- exports.localeKeys = localeKeys;
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ZH_LOCALE = void 0;
7
- const ZH_LOCALE = {
8
- command: {
9
- shared: {
10
- analyze: '分析构建产物体积,查看各个模块打包后的大小',
11
- config: '指定配置文件路径,可以为相对路径或绝对路径'
12
- },
13
- dev: {
14
- describe: '本地开发命令',
15
- entry: '指定入口,编译特定的页面',
16
- apiOnly: '仅启动 API 接口服务'
17
- },
18
- build: {
19
- describe: '构建应用命令'
20
- },
21
- start: {
22
- describe: '应用启动命令'
23
- },
24
- deploy: {
25
- describe: '部署应用命令'
26
- },
27
- new: {
28
- describe: 'MWA 项目中执行生成器',
29
- debug: '开启 Debug 模式,打印调试日志信息',
30
- config: '生成器运行默认配置(JSON 字符串)',
31
- distTag: '生成器使用特殊的 npm Tag 版本',
32
- registry: '生成器运行过程中定制 npm Registry'
33
- },
34
- inspect: {
35
- env: '查看指定环境下的配置',
36
- output: '指定在 dist 目录下输出的路径',
37
- noConsole: '不在终端中输出完整结果',
38
- verbose: '在结果中展示函数的完整内容'
39
- }
40
- }
41
- };
42
- exports.ZH_LOCALE = ZH_LOCALE;