@modern-js/app-tools 2.54.1-alpha.1 → 2.54.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. package/dist/cjs/commands/build.js +1 -1
  2. package/dist/cjs/commands/deploy.js +2 -1
  3. package/dist/cjs/commands/dev.js +1 -1
  4. package/dist/cjs/commands/serve.js +1 -1
  5. package/dist/cjs/plugins/deploy/dependencies/index.js +17 -26
  6. package/dist/cjs/plugins/deploy/dependencies/utils.js +20 -14
  7. package/dist/cjs/plugins/deploy/platforms/netlify.js +3 -7
  8. package/dist/cjs/plugins/deploy/platforms/node.js +3 -8
  9. package/dist/cjs/plugins/deploy/platforms/vercel.js +3 -7
  10. package/dist/cjs/utils/loadPlugins.js +6 -5
  11. package/dist/esm/commands/build.js +1 -1
  12. package/dist/esm/commands/deploy.js +3 -2
  13. package/dist/esm/commands/dev.js +1 -1
  14. package/dist/esm/commands/serve.js +1 -1
  15. package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
  16. package/dist/esm/plugins/deploy/dependencies/utils.js +39 -19
  17. package/dist/esm/plugins/deploy/platforms/netlify.js +3 -7
  18. package/dist/esm/plugins/deploy/platforms/node.js +3 -8
  19. package/dist/esm/plugins/deploy/platforms/vercel.js +3 -7
  20. package/dist/esm/utils/loadPlugins.js +11 -6
  21. package/dist/esm-node/commands/build.js +1 -1
  22. package/dist/esm-node/commands/deploy.js +2 -1
  23. package/dist/esm-node/commands/dev.js +1 -1
  24. package/dist/esm-node/commands/serve.js +1 -1
  25. package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
  26. package/dist/esm-node/plugins/deploy/dependencies/utils.js +21 -15
  27. package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -7
  28. package/dist/esm-node/plugins/deploy/platforms/node.js +3 -8
  29. package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -7
  30. package/dist/esm-node/utils/loadPlugins.js +6 -5
  31. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -11
  32. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
  33. package/dist/types/utils/loadPlugins.d.ts +2 -2
  34. package/package.json +17 -17
  35. package/dist/cjs/plugins/deploy/exports.js +0 -28
  36. package/dist/esm/plugins/deploy/exports.js +0 -4
  37. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  38. package/dist/js/modern/analyze/constants.js +0 -15
  39. package/dist/js/modern/analyze/generateCode.js +0 -179
  40. package/dist/js/modern/analyze/getBundleEntry.js +0 -75
  41. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  42. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
  43. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
  44. package/dist/js/modern/analyze/getServerRoutes.js +0 -192
  45. package/dist/js/modern/analyze/index.js +0 -148
  46. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
  47. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
  48. package/dist/js/modern/analyze/templates.js +0 -88
  49. package/dist/js/modern/analyze/utils.js +0 -92
  50. package/dist/js/modern/commands/build.js +0 -154
  51. package/dist/js/modern/commands/deploy.js +0 -5
  52. package/dist/js/modern/commands/dev.js +0 -95
  53. package/dist/js/modern/commands/index.js +0 -3
  54. package/dist/js/modern/commands/inspect.js +0 -69
  55. package/dist/js/modern/commands/start.js +0 -31
  56. package/dist/js/modern/exports/server.js +0 -1
  57. package/dist/js/modern/hooks.js +0 -21
  58. package/dist/js/modern/index.js +0 -109
  59. package/dist/js/modern/locale/en.js +0 -35
  60. package/dist/js/modern/locale/index.js +0 -9
  61. package/dist/js/modern/locale/zh.js +0 -35
  62. package/dist/js/modern/utils/config.js +0 -78
  63. package/dist/js/modern/utils/createCompiler.js +0 -61
  64. package/dist/js/modern/utils/createServer.js +0 -18
  65. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
  66. package/dist/js/modern/utils/language.js +0 -5
  67. package/dist/js/modern/utils/printInstructions.js +0 -11
  68. package/dist/js/modern/utils/routes.js +0 -15
  69. package/dist/js/modern/utils/types.js +0 -0
  70. package/dist/js/node/analyze/constants.js +0 -36
  71. package/dist/js/node/analyze/generateCode.js +0 -208
  72. package/dist/js/node/analyze/getBundleEntry.js +0 -89
  73. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  74. package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
  75. package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
  76. package/dist/js/node/analyze/getServerRoutes.js +0 -208
  77. package/dist/js/node/analyze/index.js +0 -178
  78. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
  79. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
  80. package/dist/js/node/analyze/templates.js +0 -106
  81. package/dist/js/node/analyze/utils.js +0 -113
  82. package/dist/js/node/commands/build.js +0 -174
  83. package/dist/js/node/commands/deploy.js +0 -14
  84. package/dist/js/node/commands/dev.js +0 -120
  85. package/dist/js/node/commands/index.js +0 -44
  86. package/dist/js/node/commands/inspect.js +0 -98
  87. package/dist/js/node/commands/start.js +0 -47
  88. package/dist/js/node/exports/server.js +0 -13
  89. package/dist/js/node/hooks.js +0 -39
  90. package/dist/js/node/index.js +0 -141
  91. package/dist/js/node/locale/en.js +0 -42
  92. package/dist/js/node/locale/index.js +0 -20
  93. package/dist/js/node/locale/zh.js +0 -42
  94. package/dist/js/node/utils/config.js +0 -103
  95. package/dist/js/node/utils/createCompiler.js +0 -81
  96. package/dist/js/node/utils/createServer.js +0 -35
  97. package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
  98. package/dist/js/node/utils/language.js +0 -13
  99. package/dist/js/node/utils/printInstructions.js +0 -22
  100. package/dist/js/node/utils/routes.js +0 -25
  101. package/dist/js/node/utils/types.js +0 -0
  102. package/dist/types/plugins/deploy/exports.d.ts +0 -1
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.safeReplacer = exports.emitResolvedConfig = exports.defineServerConfig = exports.buildServerConfig = void 0;
7
-
8
- var path = _interopRequireWildcard(require("path"));
9
-
10
- var _nodeBundleRequire = require("@modern-js/node-bundle-require");
11
-
12
- var _utils = require("@modern-js/utils");
13
-
14
- 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); }
15
-
16
- 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; }
17
-
18
- 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; }
19
-
20
- 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; }
21
-
22
- 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; }
23
-
24
- const defineServerConfig = config => config;
25
-
26
- exports.defineServerConfig = defineServerConfig;
27
-
28
- const buildServerConfig = async ({
29
- appDirectory,
30
- distDirectory,
31
- configFile,
32
- options
33
- }) => {
34
- const configFilePath = await (0, _utils.getServerConfig)(appDirectory, configFile);
35
-
36
- const getOutputFile = async filepath => path.resolve(distDirectory, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
37
-
38
- if (configFilePath) {
39
- const configHelperFilePath = path.normalize(path.join(distDirectory, './config-helper.js'));
40
- const helperCode = `
41
- export const defineConfig = (config) => config;
42
- `;
43
- await _utils.fs.ensureDir(distDirectory);
44
- await _utils.fs.writeFile(configHelperFilePath, helperCode);
45
- await (0, _nodeBundleRequire.bundle)(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
46
- getOutputFile,
47
- esbuildPlugins: [{
48
- name: 'native-build-config',
49
-
50
- setup(ctx) {
51
- ctx.onResolve({
52
- filter: /app-tools\/server/
53
- }, () => {
54
- return {
55
- path: configHelperFilePath
56
- };
57
- });
58
- }
59
-
60
- }]
61
- }));
62
- }
63
- };
64
- /**
65
- *
66
- * 处理循环引用的 replacer
67
- */
68
-
69
-
70
- exports.buildServerConfig = buildServerConfig;
71
-
72
- const safeReplacer = () => {
73
- const cache = [];
74
- const keyCache = [];
75
- return function (key, value) {
76
- if (typeof value === 'object' && value !== null) {
77
- const index = cache.indexOf(value);
78
-
79
- if (index !== -1) {
80
- return `[Circular ${keyCache[index]}]`;
81
- }
82
-
83
- cache.push(value);
84
- keyCache.push(key || 'root');
85
- }
86
-
87
- return value;
88
- };
89
- };
90
-
91
- exports.safeReplacer = safeReplacer;
92
-
93
- const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
94
- var _resolvedConfig$outpu;
95
-
96
- const outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', _utils.OUTPUT_CONFIG_FILE);
97
- await _utils.fs.writeJSON(outputPath, resolvedConfig, {
98
- spaces: 2,
99
- replacer: safeReplacer()
100
- });
101
- };
102
-
103
- exports.emitResolvedConfig = emitResolvedConfig;
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createCompiler = void 0;
7
-
8
- var _webpack = require("@modern-js/webpack");
9
-
10
- var _utils = require("@modern-js/utils");
11
-
12
- var _printInstructions = require("./printInstructions");
13
-
14
- const createCompiler = async ({
15
- api,
16
- webpackConfigs,
17
- // TODO: params
18
- userConfig,
19
- appContext
20
- }) => {
21
- try {
22
- const hookRunners = api.useHookRunners();
23
- await hookRunners.beforeCreateCompiler({
24
- webpackConfigs
25
- });
26
- const compiler = (0, _webpack.webpack)(webpackConfigs);
27
- await hookRunners.afterCreateCompiler({
28
- compiler
29
- });
30
- let isFirstCompile = true;
31
- compiler.hooks.invalid.tap('invalid', () => {
32
- (0, _utils.clearConsole)();
33
-
34
- _utils.logger.log('Compiling...');
35
- });
36
- compiler.hooks.done.tap('done', async stats => {
37
- const statsData = stats.toJson({
38
- preset: 'errors-warnings'
39
- });
40
- const {
41
- errors,
42
- warnings
43
- } = (0, _utils.formatWebpackMessages)(statsData);
44
-
45
- if (errors.length) {
46
- _utils.logger.log(_utils.chalk.red(`Failed to compile.\n`));
47
-
48
- _utils.logger.log(errors.join('\n\n'));
49
-
50
- _utils.logger.log();
51
- } else if (process.stdout.isTTY || isFirstCompile) {
52
- await hookRunners.afterDev();
53
-
54
- if (warnings.length) {
55
- _utils.logger.log(_utils.chalk.yellow(`Compiled with warnings.\n`));
56
-
57
- _utils.logger.log(warnings.join('\n\n'));
58
-
59
- _utils.logger.log();
60
- }
61
-
62
- await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
63
- }
64
-
65
- isFirstCompile = false;
66
- });
67
- return compiler;
68
- } catch (err) {
69
- _utils.logger.log(_utils.chalk.red(`Failed to compile.`));
70
-
71
- _utils.logger.log();
72
-
73
- _utils.logger.log(err); // FIXME: 这里最好抛出异常,执行 process.exit 的地方尽可能少或者控制在几个统一的地方比较合适
74
- // eslint-disable-next-line no-process-exit
75
-
76
-
77
- process.exit(1);
78
- }
79
- };
80
-
81
- exports.createCompiler = createCompiler;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getServer = exports.createServer = exports.closeServer = void 0;
7
-
8
- var _server = require("@modern-js/server");
9
-
10
- let server = null;
11
-
12
- const getServer = () => server;
13
-
14
- exports.getServer = getServer;
15
-
16
- const closeServer = async () => {
17
- if (server) {
18
- await server.close();
19
- server = null;
20
- }
21
- };
22
-
23
- exports.closeServer = closeServer;
24
-
25
- const createServer = async options => {
26
- if (server) {
27
- await server.close();
28
- }
29
-
30
- server = new _server.Server(options);
31
- const app = await server.init();
32
- return app;
33
- };
34
-
35
- exports.createServer = createServer;
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getSpecifiedEntries = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- const getSpecifiedEntries = async (entry, entrypoints) => {
11
- const entryNames = entrypoints.map(e => e.entryName);
12
-
13
- if (!entry) {
14
- return entryNames;
15
- }
16
-
17
- if (typeof entry === 'boolean') {
18
- const {
19
- selected
20
- } = await _utils.inquirer.prompt([{
21
- type: 'checkbox',
22
- name: 'selected',
23
- choices: entryNames,
24
- message: '请选择需要构建的入口',
25
-
26
- validate(answer) {
27
- if (answer.length < 1) {
28
- return 'You must choose at least one topping.';
29
- }
30
-
31
- return true;
32
- }
33
-
34
- }]);
35
- return selected;
36
- }
37
-
38
- entry.forEach(name => {
39
- if (!entryNames.includes(name)) {
40
- throw new Error(`can not found entry ${name}, compiler entry should in ${entryNames.join(', ')}`);
41
- }
42
- });
43
- return entry;
44
- };
45
-
46
- exports.getSpecifiedEntries = getSpecifiedEntries;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getLocaleLanguage = getLocaleLanguage;
7
-
8
- var _languageDetector = require("@modern-js/plugin-i18n/language-detector");
9
-
10
- function getLocaleLanguage() {
11
- const detector = new _languageDetector.I18CLILanguageDetector();
12
- return detector.detect();
13
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.printInstructions = void 0;
7
-
8
- var _utils = require("@modern-js/utils");
9
-
10
- const printInstructions = async (hookRunners, appContext, config) => {
11
- const message = (0, _utils.prettyInstructions)(appContext, config); // call beforePrintInstructions hook.
12
-
13
- const {
14
- instructions
15
- } = await hookRunners.beforePrintInstructions({
16
- instructions: message
17
- });
18
-
19
- _utils.logger.log(instructions);
20
- };
21
-
22
- exports.printInstructions = printInstructions;
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateRoutes = void 0;
7
-
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _utils = require("@modern-js/utils");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const generateRoutes = async appContext => {
15
- const {
16
- serverRoutes,
17
- distDirectory
18
- } = appContext;
19
- const output = JSON.stringify({
20
- routes: serverRoutes
21
- }, null, 2);
22
- await _utils.fs.outputFile(_path.default.join(distDirectory, _utils.ROUTE_SPEC_FILE), output);
23
- };
24
-
25
- exports.generateRoutes = generateRoutes;
File without changes
@@ -1 +0,0 @@
1
- export { handleDependencies } from './dependencies';