@modern-js/app-tools 2.0.0-beta.0 → 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 (126) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/dist/js/modern/analyze/generateCode.js +29 -37
  3. package/dist/js/modern/analyze/getBundleEntry.js +4 -12
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
  6. package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +4 -17
  8. package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
  9. package/dist/js/modern/analyze/getServerRoutes.js +15 -32
  10. package/dist/js/modern/analyze/index.js +79 -22
  11. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  12. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  13. package/dist/js/modern/analyze/nestedRoutes.js +8 -33
  14. package/dist/js/modern/analyze/templates.js +22 -37
  15. package/dist/js/modern/analyze/utils.js +0 -7
  16. package/dist/js/modern/builder/builderPlugins/compatModern.js +30 -48
  17. package/dist/js/modern/builder/createHtmlConfig.js +2 -2
  18. package/dist/js/modern/builder/createOutputConfig.js +7 -4
  19. package/dist/js/modern/builder/createSourceConfig.js +0 -11
  20. package/dist/js/modern/builder/createToolsConfig.js +3 -10
  21. package/dist/js/modern/builder/index.js +24 -22
  22. package/dist/js/modern/builder/share.js +0 -4
  23. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
  24. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
  25. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  26. package/dist/js/modern/commands/build.js +6 -46
  27. package/dist/js/modern/commands/dev.js +4 -16
  28. package/dist/js/modern/commands/inspect.js +3 -20
  29. package/dist/js/modern/commands/start.js +0 -2
  30. package/dist/js/modern/index.js +6 -15
  31. package/dist/js/modern/utils/config.js +1 -12
  32. package/dist/js/modern/utils/createServer.js +0 -5
  33. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  34. package/dist/js/modern/utils/printInstructions.js +2 -1
  35. package/dist/js/modern/utils/routes.js +0 -2
  36. package/dist/js/node/analyze/generateCode.js +29 -60
  37. package/dist/js/node/analyze/getBundleEntry.js +4 -18
  38. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
  39. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
  40. package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
  41. package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
  42. package/dist/js/node/analyze/getFileSystemEntry.js +4 -25
  43. package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
  44. package/dist/js/node/analyze/getServerRoutes.js +14 -40
  45. package/dist/js/node/analyze/index.js +79 -32
  46. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  47. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  48. package/dist/js/node/analyze/nestedRoutes.js +8 -41
  49. package/dist/js/node/analyze/templates.js +22 -47
  50. package/dist/js/node/analyze/utils.js +0 -20
  51. package/dist/js/node/builder/builderPlugins/compatModern.js +30 -59
  52. package/dist/js/node/builder/createHtmlConfig.js +2 -10
  53. package/dist/js/node/builder/createOutputConfig.js +7 -6
  54. package/dist/js/node/builder/createSourceConfig.js +0 -17
  55. package/dist/js/node/builder/createToolsConfig.js +3 -12
  56. package/dist/js/node/builder/index.js +24 -36
  57. package/dist/js/node/builder/share.js +0 -12
  58. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
  59. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
  60. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  61. package/dist/js/node/commands/build.js +4 -57
  62. package/dist/js/node/commands/deploy.js +0 -2
  63. package/dist/js/node/commands/dev.js +3 -27
  64. package/dist/js/node/commands/index.js +0 -6
  65. package/dist/js/node/commands/inspect.js +3 -27
  66. package/dist/js/node/commands/start.js +0 -11
  67. package/dist/js/node/exports/server.js +0 -1
  68. package/dist/js/node/hooks.js +0 -2
  69. package/dist/js/node/index.js +7 -34
  70. package/dist/js/node/locale/index.js +0 -4
  71. package/dist/js/node/utils/commands.js +0 -2
  72. package/dist/js/node/utils/config.js +1 -25
  73. package/dist/js/node/utils/createServer.js +0 -15
  74. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  75. package/dist/js/node/utils/language.js +0 -2
  76. package/dist/js/node/utils/printInstructions.js +2 -5
  77. package/dist/js/node/utils/routes.js +0 -5
  78. package/dist/js/treeshaking/analyze/generateCode.js +57 -100
  79. package/dist/js/treeshaking/analyze/getBundleEntry.js +11 -19
  80. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
  81. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
  82. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
  83. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +4 -17
  84. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +2 -26
  85. package/dist/js/treeshaking/analyze/getServerRoutes.js +24 -37
  86. package/dist/js/treeshaking/analyze/index.js +185 -65
  87. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
  88. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
  89. package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
  90. package/dist/js/treeshaking/analyze/templates.js +31 -50
  91. package/dist/js/treeshaking/analyze/utils.js +7 -14
  92. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +40 -59
  93. package/dist/js/treeshaking/builder/createHtmlConfig.js +15 -15
  94. package/dist/js/treeshaking/builder/createOutputConfig.js +26 -23
  95. package/dist/js/treeshaking/builder/createSourceConfig.js +7 -19
  96. package/dist/js/treeshaking/builder/createToolsConfig.js +16 -21
  97. package/dist/js/treeshaking/builder/index.js +38 -49
  98. package/dist/js/treeshaking/builder/share.js +0 -4
  99. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
  100. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
  101. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  102. package/dist/js/treeshaking/commands/build.js +26 -111
  103. package/dist/js/treeshaking/commands/deploy.js +0 -3
  104. package/dist/js/treeshaking/commands/dev.js +13 -35
  105. package/dist/js/treeshaking/commands/inspect.js +5 -28
  106. package/dist/js/treeshaking/commands/start.js +0 -9
  107. package/dist/js/treeshaking/index.js +2 -39
  108. package/dist/js/treeshaking/utils/config.js +1 -17
  109. package/dist/js/treeshaking/utils/createServer.js +0 -10
  110. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
  111. package/dist/js/treeshaking/utils/printInstructions.js +0 -5
  112. package/dist/js/treeshaking/utils/routes.js +0 -4
  113. package/dist/types/analyze/index.d.ts +2 -3
  114. package/dist/types/analyze/nestedRoutes.d.ts +1 -1
  115. package/dist/types/analyze/templates.d.ts +3 -1
  116. package/dist/types/builder/builderPlugins/compatModern.d.ts +0 -1
  117. package/dist/types/builder/index.d.ts +2 -6
  118. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  119. package/dist/types/commands/inspect.d.ts +1 -4
  120. package/dist/types/index.d.ts +0 -2
  121. package/dist/types/utils/config.d.ts +0 -1
  122. package/package.json +23 -22
  123. package/dist/js/modern/utils/createCompiler.js +0 -58
  124. package/dist/js/node/utils/createCompiler.js +0 -75
  125. package/dist/js/treeshaking/utils/createCompiler.js +0 -117
  126. package/dist/types/utils/createCompiler.d.ts +0 -12
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.0",
14
+ "version": "2.0.0-beta.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -59,33 +59,34 @@
59
59
  "@babel/runtime": "^7.18.0",
60
60
  "@babel/traverse": "^7.18.0",
61
61
  "@babel/types": "^7.18.0",
62
- "@modern-js/core": "2.0.0-beta.0",
63
- "@modern-js/new-action": "2.0.0-beta.0",
64
- "@modern-js/node-bundle-require": "2.0.0-beta.0",
65
- "@modern-js/plugin": "2.0.0-beta.0",
66
- "@modern-js/plugin-data-loader": "2.0.0-beta.0",
67
- "@modern-js/plugin-i18n": "2.0.0-beta.0",
68
- "@modern-js/plugin-jarvis": "2.0.0-beta.0",
69
- "@modern-js/prod-server": "2.0.0-beta.0",
70
- "@modern-js/server": "2.0.0-beta.0",
71
- "@modern-js/types": "2.0.0-beta.0",
72
- "@modern-js/upgrade": "2.0.0-beta.0",
73
- "@modern-js/utils": "2.0.0-beta.0",
74
- "@modern-js/builder": "2.0.0-beta.0",
75
- "@modern-js/builder-shared": "2.0.0-beta.0",
76
- "@modern-js/builder-webpack-provider": "2.0.0-beta.0",
77
- "@modern-js/builder-plugin-node-polyfill": "2.0.0-beta.0",
78
- "@modern-js/builder-plugin-esbuild": "2.0.0-beta.0"
62
+ "@modern-js/builder": "2.0.0-beta.1",
63
+ "@modern-js/builder-plugin-esbuild": "2.0.0-beta.1",
64
+ "@modern-js/builder-plugin-node-polyfill": "2.0.0-beta.1",
65
+ "@modern-js/builder-shared": "2.0.0-beta.1",
66
+ "@modern-js/builder-webpack-provider": "2.0.0-beta.1",
67
+ "@modern-js/core": "2.0.0-beta.1",
68
+ "@modern-js/new-action": "2.0.0-beta.1",
69
+ "@modern-js/node-bundle-require": "2.0.0-beta.1",
70
+ "@modern-js/plugin": "2.0.0-beta.1",
71
+ "@modern-js/plugin-data-loader": "2.0.0-beta.1",
72
+ "@modern-js/plugin-i18n": "2.0.0-beta.1",
73
+ "@modern-js/plugin-lint": "2.0.0-beta.1",
74
+ "@modern-js/prod-server": "2.0.0-beta.1",
75
+ "@modern-js/server": "2.0.0-beta.1",
76
+ "@modern-js/types": "2.0.0-beta.1",
77
+ "@modern-js/upgrade": "2.0.0-beta.1",
78
+ "@modern-js/utils": "2.0.0-beta.1"
79
79
  },
80
80
  "devDependencies": {
81
- "@modern-js/server-core": "2.0.0-beta.0",
82
- "@scripts/build": "2.0.0-beta.0",
83
- "@scripts/jest-config": "2.0.0-beta.0",
84
81
  "@types/babel__traverse": "^7.14.2",
85
82
  "@types/jest": "^27",
86
83
  "@types/node": "^14",
87
84
  "jest": "^27",
88
- "typescript": "^4"
85
+ "typescript": "^4",
86
+ "webpack": "^5.75.0",
87
+ "@modern-js/server-core": "2.0.0-beta.1",
88
+ "@scripts/build": "2.0.0-beta.1",
89
+ "@scripts/jest-config": "2.0.0-beta.1"
89
90
  },
90
91
  "sideEffects": false,
91
92
  "publishConfig": {
@@ -1,58 +0,0 @@
1
- import { chalk, logger } from '@modern-js/utils';
2
- import createBuilder from "../builder";
3
- import { printInstructions } from "./printInstructions";
4
- export const createDevCompiler = async ({
5
- api,
6
- target,
7
- normalizedConfig,
8
- appContext
9
- }) => {
10
- try {
11
- const hookRunners = api.useHookRunners();
12
- const builder = await createBuilder({
13
- target,
14
- normalizedConfig,
15
- appContext,
16
- compatPluginConfig: {
17
- async onDevCompileDone({
18
- isFirstCompile
19
- }) {
20
- if (process.stdout.isTTY || isFirstCompile) {
21
- hookRunners.afterDev();
22
-
23
- if (isFirstCompile) {
24
- printInstructions(hookRunners, appContext, normalizedConfig);
25
- }
26
- }
27
- },
28
-
29
- async onBeforeCreateCompiler({
30
- bundlerConfigs
31
- }) {
32
- // run modernjs framework `beforeCreateCompiler` hook
33
- await hookRunners.beforeCreateCompiler({
34
- bundlerConfigs
35
- });
36
- },
37
-
38
- async onAfterCreateCompiler({
39
- compiler
40
- }) {
41
- // run modernjs framework afterCreateCompiler hooks
42
- await hookRunners.afterCreateCompiler({
43
- compiler
44
- });
45
- }
46
-
47
- }
48
- });
49
- return builder.createCompiler();
50
- } catch (err) {
51
- logger.log(chalk.red(`Failed to compile.`));
52
- logger.log();
53
- logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
54
- // eslint-disable-next-line no-process-exit
55
-
56
- process.exit(1);
57
- }
58
- };
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createDevCompiler = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- var _builder = _interopRequireDefault(require("../builder"));
11
-
12
- var _printInstructions = require("./printInstructions");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- const createDevCompiler = async ({
17
- api,
18
- target,
19
- normalizedConfig,
20
- appContext
21
- }) => {
22
- try {
23
- const hookRunners = api.useHookRunners();
24
- const builder = await (0, _builder.default)({
25
- target,
26
- normalizedConfig,
27
- appContext,
28
- compatPluginConfig: {
29
- async onDevCompileDone({
30
- isFirstCompile
31
- }) {
32
- if (process.stdout.isTTY || isFirstCompile) {
33
- hookRunners.afterDev();
34
-
35
- if (isFirstCompile) {
36
- (0, _printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
37
- }
38
- }
39
- },
40
-
41
- async onBeforeCreateCompiler({
42
- bundlerConfigs
43
- }) {
44
- // run modernjs framework `beforeCreateCompiler` hook
45
- await hookRunners.beforeCreateCompiler({
46
- bundlerConfigs
47
- });
48
- },
49
-
50
- async onAfterCreateCompiler({
51
- compiler
52
- }) {
53
- // run modernjs framework afterCreateCompiler hooks
54
- await hookRunners.afterCreateCompiler({
55
- compiler
56
- });
57
- }
58
-
59
- }
60
- });
61
- return builder.createCompiler();
62
- } catch (err) {
63
- _utils.logger.log(_utils.chalk.red(`Failed to compile.`));
64
-
65
- _utils.logger.log();
66
-
67
- _utils.logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
68
- // eslint-disable-next-line no-process-exit
69
-
70
-
71
- process.exit(1);
72
- }
73
- };
74
-
75
- exports.createDevCompiler = createDevCompiler;
@@ -1,117 +0,0 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import { chalk, logger } from '@modern-js/utils';
4
- import createBuilder from "../builder";
5
- import { printInstructions } from "./printInstructions";
6
- export var createDevCompiler = /*#__PURE__*/function () {
7
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref) {
8
- var api, target, normalizedConfig, appContext, hookRunners, builder;
9
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
10
- while (1) {
11
- switch (_context4.prev = _context4.next) {
12
- case 0:
13
- api = _ref.api, target = _ref.target, normalizedConfig = _ref.normalizedConfig, appContext = _ref.appContext;
14
- _context4.prev = 1;
15
- hookRunners = api.useHookRunners();
16
- _context4.next = 5;
17
- return createBuilder({
18
- target: target,
19
- normalizedConfig: normalizedConfig,
20
- appContext: appContext,
21
- compatPluginConfig: {
22
- onDevCompileDone: function onDevCompileDone(_ref3) {
23
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
24
- var isFirstCompile;
25
- return _regeneratorRuntime().wrap(function _callee$(_context) {
26
- while (1) {
27
- switch (_context.prev = _context.next) {
28
- case 0:
29
- isFirstCompile = _ref3.isFirstCompile;
30
-
31
- if (process.stdout.isTTY || isFirstCompile) {
32
- hookRunners.afterDev();
33
-
34
- if (isFirstCompile) {
35
- printInstructions(hookRunners, appContext, normalizedConfig);
36
- }
37
- }
38
-
39
- case 2:
40
- case "end":
41
- return _context.stop();
42
- }
43
- }
44
- }, _callee);
45
- }))();
46
- },
47
- onBeforeCreateCompiler: function onBeforeCreateCompiler(_ref4) {
48
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
49
- var bundlerConfigs;
50
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
51
- while (1) {
52
- switch (_context2.prev = _context2.next) {
53
- case 0:
54
- bundlerConfigs = _ref4.bundlerConfigs;
55
- _context2.next = 3;
56
- return hookRunners.beforeCreateCompiler({
57
- bundlerConfigs: bundlerConfigs
58
- });
59
-
60
- case 3:
61
- case "end":
62
- return _context2.stop();
63
- }
64
- }
65
- }, _callee2);
66
- }))();
67
- },
68
- onAfterCreateCompiler: function onAfterCreateCompiler(_ref5) {
69
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
70
- var compiler;
71
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
72
- while (1) {
73
- switch (_context3.prev = _context3.next) {
74
- case 0:
75
- compiler = _ref5.compiler;
76
- _context3.next = 3;
77
- return hookRunners.afterCreateCompiler({
78
- compiler: compiler
79
- });
80
-
81
- case 3:
82
- case "end":
83
- return _context3.stop();
84
- }
85
- }
86
- }, _callee3);
87
- }))();
88
- }
89
- }
90
- });
91
-
92
- case 5:
93
- builder = _context4.sent;
94
- return _context4.abrupt("return", builder.createCompiler());
95
-
96
- case 9:
97
- _context4.prev = 9;
98
- _context4.t0 = _context4["catch"](1);
99
- logger.log(chalk.red("Failed to compile."));
100
- logger.log();
101
- logger.log(_context4.t0); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
102
- // eslint-disable-next-line no-process-exit
103
-
104
- process.exit(1);
105
-
106
- case 15:
107
- case "end":
108
- return _context4.stop();
109
- }
110
- }
111
- }, _callee4, null, [[1, 9]]);
112
- }));
113
-
114
- return function createDevCompiler(_x) {
115
- return _ref2.apply(this, arguments);
116
- };
117
- }();
@@ -1,12 +0,0 @@
1
- import type webpack from '@modern-js/builder-webpack-provider/webpack';
2
- import type { PluginAPI } from '@modern-js/core';
3
- import type { AppHooks } from '../hooks';
4
- import { BuilderOptions } from '../builder';
5
- export declare const createDevCompiler: ({
6
- api,
7
- target,
8
- normalizedConfig,
9
- appContext
10
- }: {
11
- api: PluginAPI<AppHooks>;
12
- } & BuilderOptions) => Promise<webpack.Compiler | webpack.MultiCompiler>;