@modern-js/app-tools 1.6.6 → 1.6.7

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 1.6.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 64cf62697: feat(app-tools): support modern inspect command
8
+ - b7a1cea52: feat: support utils in tools.babel
9
+ - Updated dependencies [ded45811c]
10
+ - Updated dependencies [209d0a927]
11
+ - Updated dependencies [9d649884b]
12
+ - Updated dependencies [9377d2d9d]
13
+ - Updated dependencies [8e1cedd8a]
14
+ - Updated dependencies [8c9ad1749]
15
+ - Updated dependencies [6b2523f44]
16
+ - Updated dependencies [b7a1cea52]
17
+ - Updated dependencies [002dab527]
18
+ - Updated dependencies [1ac68424f]
19
+ - Updated dependencies [3dfee700c]
20
+ - @modern-js/webpack@1.11.0
21
+ - @modern-js/server@1.4.20
22
+ - @modern-js/core@1.12.0
23
+ - @modern-js/utils@1.7.7
24
+ - @modern-js/plugin@1.3.7
25
+ - @modern-js/plugin-analyze@1.4.6
26
+ - @modern-js/prod-server@1.1.8
27
+
3
28
  ## 1.6.6
4
29
 
5
30
  ### Patch Changes
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  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; }
6
6
 
7
- import { fs, logger, chalk, isSSR, clearConsole } from '@modern-js/utils';
7
+ import { fs, logger, chalk, isSSR } from '@modern-js/utils';
8
8
  import { manager, ResolvedConfigContext } from '@modern-js/core';
9
9
  import { createCompiler } from "../utils/createCompiler";
10
10
  import { createServer } from "../utils/createServer";
@@ -93,7 +93,6 @@ export const dev = async (api, options) => {
93
93
  return printInstructions(hookRunners, appContext, userConfig);
94
94
  }
95
95
 
96
- clearConsole();
97
96
  return logger.log(chalk.cyan(`Starting the development server...`));
98
97
  });
99
98
  };
@@ -0,0 +1,69 @@
1
+ import path from 'path';
2
+ import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
3
+ import { fs, logger, signale, isUseSSRBundle, chalk } from '@modern-js/utils';
4
+ import WebpackChain from '@modern-js/utils/webpack-chain';
5
+ export const formatWebpackConfig = (config, verbose) => {
6
+ const stringify = WebpackChain.toString;
7
+ return `module.exports = ${stringify(config, {
8
+ verbose
9
+ })};`;
10
+ };
11
+ export const inspect = (api, options) => {
12
+ process.env.NODE_ENV = options.env;
13
+ const resolvedConfig = api.useResolvedConfigContext();
14
+ const appContext = api.useAppContext();
15
+ const outputFiles = [];
16
+ outputFiles.push(printInspectResult(WebpackConfigTarget.CLIENT, appContext, resolvedConfig, options));
17
+
18
+ if (resolvedConfig.output.enableModernMode) {
19
+ outputFiles.push(printInspectResult(WebpackConfigTarget.MODERN, appContext, resolvedConfig, options));
20
+ }
21
+
22
+ if (isUseSSRBundle(resolvedConfig)) {
23
+ outputFiles.push(printInspectResult(WebpackConfigTarget.NODE, appContext, resolvedConfig, options));
24
+ }
25
+
26
+ signale.success('Inspect succeed, you can open following files to view the full webpack config: \n');
27
+ outputFiles.forEach(file => {
28
+ signale.log(` - ${chalk.yellow(path.relative(appContext.appDirectory, file))}`);
29
+ });
30
+ signale.log();
31
+ };
32
+ export const getTagByWebpackTarget = webpackTarget => {
33
+ switch (webpackTarget) {
34
+ case WebpackConfigTarget.CLIENT:
35
+ return 'client';
36
+
37
+ case WebpackConfigTarget.MODERN:
38
+ return 'modern';
39
+
40
+ case WebpackConfigTarget.NODE:
41
+ return 'ssr';
42
+
43
+ default:
44
+ throw Error(`Unsupported webpack target: ${webpackTarget}`);
45
+ }
46
+ };
47
+ export const printInspectResult = (webpackTarget, appContext, resolvedConfig, options) => {
48
+ const webpackConfig = getWebpackConfig(webpackTarget, appContext, resolvedConfig);
49
+ const {
50
+ output,
51
+ verbose,
52
+ console = true
53
+ } = options;
54
+ const outputPath = output ? path.posix.join(appContext.distDirectory, output) : appContext.distDirectory;
55
+ const tag = getTagByWebpackTarget(webpackTarget);
56
+ const outputFile = `webpack.${tag}.inspect.js`;
57
+ const outputFilePath = path.posix.join(outputPath, outputFile);
58
+ const rawWebpackConfig = formatWebpackConfig(webpackConfig, verbose);
59
+ fs.outputFileSync(outputFilePath, rawWebpackConfig);
60
+
61
+ if (console) {
62
+ logger.log(`
63
+ webpack config for ${tag} build:
64
+ ${rawWebpackConfig}
65
+ `);
66
+ }
67
+
68
+ return outputFilePath;
69
+ };
@@ -64,6 +64,12 @@ export default (() => ({
64
64
  locale
65
65
  }));
66
66
  });
67
+ program.command('inspect').description('inspect internal webpack config').option(`--env <env>`, i18n.t(localeKeys.command.inspect.env), 'development').option('--output <output>', i18n.t(localeKeys.command.inspect.output), '/').option('--no-console', i18n.t(localeKeys.command.inspect.noConsole)).option('--verbose', i18n.t(localeKeys.command.inspect.verbose)).action(async options => {
68
+ const {
69
+ inspect
70
+ } = await import("./commands/inspect");
71
+ inspect(api, options);
72
+ });
67
73
  },
68
74
 
69
75
  // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
@@ -24,6 +24,12 @@ export const EN_LOCALE = {
24
24
  config: 'set default generator config(json string)',
25
25
  distTag: `use specified tag version for it's generator`,
26
26
  registry: 'set npm registry url to run npm command'
27
+ },
28
+ inspect: {
29
+ env: 'specify env mode',
30
+ output: 'specify inspect content output path',
31
+ noConsole: 'do not log the result in terminal',
32
+ verbose: 'show full function definitions in output'
27
33
  }
28
34
  }
29
35
  };
@@ -24,6 +24,12 @@ export const ZH_LOCALE = {
24
24
  config: '生成器运行默认配置(JSON 字符串)',
25
25
  distTag: '生成器使用特殊的 npm Tag 版本',
26
26
  registry: '生成器运行过程中定制 npm Registry'
27
+ },
28
+ inspect: {
29
+ env: '查看指定环境下的配置',
30
+ output: '指定在 dist 目录下输出的路径',
31
+ noConsole: '不在终端中输出完整结果',
32
+ verbose: '在结果中展示函数的完整内容'
27
33
  }
28
34
  }
29
35
  };
@@ -117,7 +117,6 @@ const dev = async (api, options) => {
117
117
  return (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
118
118
  }
119
119
 
120
- (0, _utils.clearConsole)();
121
120
  return _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
122
121
  });
123
122
  };
@@ -0,0 +1,98 @@
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.signale.success('Inspect succeed, you can open following files to view the full webpack config: \n');
43
+
44
+ outputFiles.forEach(file => {
45
+ _utils.signale.log(` - ${_utils.chalk.yellow(_path.default.relative(appContext.appDirectory, file))}`);
46
+ });
47
+
48
+ _utils.signale.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;
@@ -94,6 +94,12 @@ var _default = () => ({
94
94
  locale
95
95
  }));
96
96
  });
97
+ 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)).action(async options => {
98
+ const {
99
+ inspect
100
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/inspect")));
101
+ inspect(api, options);
102
+ });
97
103
  },
98
104
 
99
105
  // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
@@ -30,6 +30,12 @@ const EN_LOCALE = {
30
30
  config: 'set default generator config(json string)',
31
31
  distTag: `use specified tag version for it's generator`,
32
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'
33
39
  }
34
40
  }
35
41
  };
@@ -30,6 +30,12 @@ const ZH_LOCALE = {
30
30
  config: '生成器运行默认配置(JSON 字符串)',
31
31
  distTag: '生成器使用特殊的 npm Tag 版本',
32
32
  registry: '生成器运行过程中定制 npm Registry'
33
+ },
34
+ inspect: {
35
+ env: '查看指定环境下的配置',
36
+ output: '指定在 dist 目录下输出的路径',
37
+ noConsole: '不在终端中输出完整结果',
38
+ verbose: '在结果中展示函数的完整内容'
33
39
  }
34
40
  }
35
41
  };
@@ -0,0 +1,7 @@
1
+ import { Configuration, WebpackConfigTarget } from '@modern-js/webpack';
2
+ import type { PluginAPI, NormalizedConfig, IAppContext } from '@modern-js/core';
3
+ import type { InspectOptions } from '../utils/types';
4
+ export declare const formatWebpackConfig: (config: Configuration, verbose?: boolean | undefined) => string;
5
+ export declare const inspect: (api: PluginAPI, options: InspectOptions) => void;
6
+ export declare const getTagByWebpackTarget: (webpackTarget: WebpackConfigTarget) => "modern" | "client" | "ssr";
7
+ export declare const printInspectResult: (webpackTarget: WebpackConfigTarget, appContext: IAppContext, resolvedConfig: NormalizedConfig, options: InspectOptions) => string;
@@ -25,5 +25,11 @@ export declare const EN_LOCALE: {
25
25
  distTag: string;
26
26
  registry: string;
27
27
  };
28
+ inspect: {
29
+ env: string;
30
+ output: string;
31
+ noConsole: string;
32
+ verbose: string;
33
+ };
28
34
  };
29
35
  };
@@ -27,6 +27,12 @@ declare const localeKeys: {
27
27
  distTag: string;
28
28
  registry: string;
29
29
  };
30
+ inspect: {
31
+ env: string;
32
+ output: string;
33
+ noConsole: string;
34
+ verbose: string;
35
+ };
30
36
  };
31
37
  } | {
32
38
  command: {
@@ -55,6 +61,12 @@ declare const localeKeys: {
55
61
  distTag: string;
56
62
  registry: string;
57
63
  };
64
+ inspect: {
65
+ env: string;
66
+ output: string;
67
+ noConsole: string;
68
+ verbose: string;
69
+ };
58
70
  };
59
71
  };
60
72
  export { i18n, localeKeys };
@@ -25,5 +25,11 @@ export declare const ZH_LOCALE: {
25
25
  distTag: string;
26
26
  registry: string;
27
27
  };
28
+ inspect: {
29
+ env: string;
30
+ output: string;
31
+ noConsole: string;
32
+ verbose: string;
33
+ };
28
34
  };
29
35
  };
@@ -13,4 +13,10 @@ export declare type DeployOptions = {
13
13
  };
14
14
  export declare type StartOptions = {
15
15
  apiOnly?: boolean;
16
+ };
17
+ export declare type InspectOptions = {
18
+ env?: string;
19
+ output?: string;
20
+ console?: boolean;
21
+ verbose?: boolean;
16
22
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.6.6",
14
+ "version": "1.6.7",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -57,18 +57,18 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@babel/runtime": "^7.18.0",
60
- "@modern-js/core": "^1.11.2",
60
+ "@modern-js/core": "^1.12.0",
61
61
  "@modern-js/i18n-cli-language-detector": "^1.2.4",
62
62
  "@modern-js/new-action": "^1.3.10",
63
63
  "@modern-js/node-bundle-require": "^1.3.5",
64
- "@modern-js/plugin": "^1.3.6",
64
+ "@modern-js/plugin": "^1.3.7",
65
65
  "@modern-js/plugin-analyze": "^1.4.6",
66
66
  "@modern-js/plugin-i18n": "^1.2.7",
67
67
  "@modern-js/prod-server": "^1.1.8",
68
- "@modern-js/server": "^1.4.18",
68
+ "@modern-js/server": "^1.4.20",
69
69
  "@modern-js/types": "^1.5.4",
70
- "@modern-js/utils": "^1.7.6",
71
- "@modern-js/webpack": "^1.10.0"
70
+ "@modern-js/utils": "^1.7.7",
71
+ "@modern-js/webpack": "^1.11.0"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@modern-js/server-core": "1.3.5",