@modern-js/module-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 (94) hide show
  1. package/CHANGELOG.md +83 -46
  2. package/dist/js/modern/cli/build.js +2 -1
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/cli/new.js +0 -3
  5. package/dist/js/modern/commands/build.js +0 -4
  6. package/dist/js/modern/commands/dev.js +2 -5
  7. package/dist/js/modern/features/build/build-platform.js +11 -14
  8. package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
  9. package/dist/js/modern/features/build/bundle/runSpeedy.js +4 -18
  10. package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
  11. package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
  12. package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
  13. package/dist/js/modern/features/build/bundleless/index.js +0 -2
  14. package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
  15. package/dist/js/modern/features/build/bundleless/style.js +1 -30
  16. package/dist/js/modern/features/build/constants.js +0 -3
  17. package/dist/js/modern/features/build/error.js +4 -27
  18. package/dist/js/modern/features/build/index.js +6 -15
  19. package/dist/js/modern/features/build/legacy-constants.js +8 -4
  20. package/dist/js/modern/features/build/logger/logText.js +0 -12
  21. package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
  22. package/dist/js/modern/features/build/normalize.js +18 -43
  23. package/dist/js/modern/features/build/utils.js +14 -19
  24. package/dist/js/modern/features/dev/index.js +4 -9
  25. package/dist/js/modern/hooks/index.js +0 -3
  26. package/dist/js/modern/index.js +5 -9
  27. package/dist/js/modern/schema/build-config.js +2 -1
  28. package/dist/js/modern/schema/output.js +5 -10
  29. package/dist/js/modern/utils/babel.js +13 -15
  30. package/dist/js/modern/utils/copy.js +6 -15
  31. package/dist/js/modern/utils/init-env.js +0 -1
  32. package/dist/js/modern/utils/logger.js +1 -16
  33. package/dist/js/modern/utils/readline.js +2 -4
  34. package/dist/js/modern/utils/tsconfig.js +0 -1
  35. package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
  36. package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
  37. package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
  38. package/dist/js/modern/utils/valide.js +2 -6
  39. package/dist/js/node/cli/build.js +2 -6
  40. package/dist/js/node/cli/dev.js +2 -7
  41. package/dist/js/node/cli/index.js +0 -6
  42. package/dist/js/node/cli/new.js +0 -8
  43. package/dist/js/node/commands/build.js +0 -19
  44. package/dist/js/node/commands/dev.js +2 -15
  45. package/dist/js/node/commands/index.js +0 -2
  46. package/dist/js/node/features/build/build-platform.js +11 -20
  47. package/dist/js/node/features/build/bundle/index.js +0 -6
  48. package/dist/js/node/features/build/bundle/runRollup.js +3 -32
  49. package/dist/js/node/features/build/bundle/runSpeedy.js +4 -32
  50. package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
  51. package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
  52. package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
  53. package/dist/js/node/features/build/bundleless/index.js +0 -11
  54. package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
  55. package/dist/js/node/features/build/bundleless/style.js +1 -50
  56. package/dist/js/node/features/build/constants.js +0 -11
  57. package/dist/js/node/features/build/error.js +4 -40
  58. package/dist/js/node/features/build/index.js +6 -38
  59. package/dist/js/node/features/build/legacy-constants.js +8 -4
  60. package/dist/js/node/features/build/logger/index.js +0 -4
  61. package/dist/js/node/features/build/logger/logText.js +0 -18
  62. package/dist/js/node/features/build/logger/loggerManager.js +5 -26
  63. package/dist/js/node/features/build/normalize.js +18 -61
  64. package/dist/js/node/features/build/utils.js +13 -35
  65. package/dist/js/node/features/dev/index.js +4 -17
  66. package/dist/js/node/hooks/build.js +0 -5
  67. package/dist/js/node/hooks/dev.js +0 -5
  68. package/dist/js/node/hooks/index.js +0 -10
  69. package/dist/js/node/index.js +6 -26
  70. package/dist/js/node/locale/index.js +0 -5
  71. package/dist/js/node/schema/build-config.js +2 -1
  72. package/dist/js/node/schema/index.js +0 -5
  73. package/dist/js/node/schema/output.js +5 -12
  74. package/dist/js/node/utils/babel.js +12 -22
  75. package/dist/js/node/utils/color.js +0 -3
  76. package/dist/js/node/utils/copy.js +6 -23
  77. package/dist/js/node/utils/init-env.js +0 -3
  78. package/dist/js/node/utils/json.js +0 -2
  79. package/dist/js/node/utils/language.js +0 -3
  80. package/dist/js/node/utils/logger.js +1 -26
  81. package/dist/js/node/utils/readline.js +0 -8
  82. package/dist/js/node/utils/tsconfig.js +0 -7
  83. package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
  84. package/dist/js/node/utils/tspaths-transform/index.js +2 -34
  85. package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
  86. package/dist/js/node/utils/valide.js +2 -11
  87. package/dist/types/commands/build.d.ts +0 -1
  88. package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
  89. package/dist/types/features/build/utils.d.ts +1 -3
  90. package/dist/types/hooks/index.d.ts +2 -1
  91. package/dist/types/index.d.ts +2 -2
  92. package/dist/types/schema/types.d.ts +1 -3
  93. package/dist/types/types.d.ts +0 -1
  94. package/package.json +20 -44
@@ -16,8 +16,9 @@ const universalJs = [{
16
16
  format: 'esm',
17
17
  target: 'es6',
18
18
  outputPath: './js/modern'
19
- }]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
19
+ }];
20
20
 
21
+ // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
21
22
  const universalJsLite = [{
22
23
  format: 'esm',
23
24
  target: 'es5',
@@ -35,8 +36,9 @@ const universalJsLite = [{
35
36
  format: 'esm',
36
37
  target: 'es5',
37
38
  outputPath: './js/modern'
38
- }]; // 纯前端代码的默认选择,两份构建产物
39
+ }];
39
40
 
41
+ // 纯前端代码的默认选择,两份构建产物
40
42
  const browserJs = [{
41
43
  format: 'esm',
42
44
  target: 'es5',
@@ -54,8 +56,9 @@ const browserJs = [{
54
56
  format: 'esm',
55
57
  target: 'es6',
56
58
  outputPath: './js/modern'
57
- }]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
59
+ }];
58
60
 
61
+ // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
59
62
  const browserJsLite = [{
60
63
  format: 'esm',
61
64
  target: 'es5',
@@ -73,8 +76,9 @@ const browserJsLite = [{
73
76
  format: 'esm',
74
77
  target: 'es5',
75
78
  outputPath: './js/modern'
76
- }]; // 纯 Node.js 代码的默认选择,两份构建产物
79
+ }];
77
80
 
81
+ // 纯 Node.js 代码的默认选择,两份构建产物
78
82
  const nodeJs = [{
79
83
  format: 'cjs',
80
84
  target: 'es6',
@@ -1,5 +1,4 @@
1
1
  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; }
2
-
3
2
  import { chalk } from '@modern-js/utils';
4
3
  export const colors = {
5
4
  title: chalk.rgb(218, 152, 92)
@@ -13,7 +12,6 @@ export const logTemplate = (title, messageStack, {
13
12
  contentColor: _contentColor = s => s
14
13
  } = {}) => {
15
14
  const maxLength = Infinity; // TODO: 考虑后面是否提供该参数
16
-
17
15
  const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
18
16
  const messageFragments = messageStack.map(p => {
19
17
  p.trim();
@@ -21,7 +19,6 @@ export const logTemplate = (title, messageStack, {
21
19
  }) // 移除 clearFlag
22
20
  .filter(s => s !== leftBorderFlag) // 过滤空字符串
23
21
  .slice(0, maxLength); // 控制长度
24
-
25
22
  const template = `${colors.title(title)}:
26
23
  ${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
27
24
  return template;
@@ -30,32 +27,24 @@ ${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottom
30
27
  export class LoggerText {
31
28
  constructor(option) {
32
29
  _defineProperty(this, "messages", void 0);
33
-
34
30
  _defineProperty(this, "hasErrorMessage", void 0);
35
-
36
31
  _defineProperty(this, "option", void 0);
37
-
38
32
  this.messages = [];
39
33
  this.option = option;
40
34
  this.hasErrorMessage = false;
41
35
  }
42
-
43
36
  append(message) {
44
37
  if (message.includes(clearFlag)) {
45
38
  this.messages = [];
46
39
  }
47
-
48
40
  this.messages.push(message);
49
41
  }
50
-
51
42
  errorHappen() {
52
43
  this.hasErrorMessage = true;
53
44
  }
54
-
55
45
  hasMessages() {
56
46
  return this.messages.length > 0;
57
47
  }
58
-
59
48
  get value() {
60
49
  const {
61
50
  title,
@@ -64,5 +53,4 @@ export class LoggerText {
64
53
  const messages = [...new Set(this.messages)];
65
54
  return logTemplate(title, messages, contentConfig);
66
55
  }
67
-
68
56
  }
@@ -1,13 +1,12 @@
1
1
  let _ = t => t,
2
- _t;
3
-
2
+ _t;
4
3
  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; }
5
-
6
4
  /**
7
5
  * 1. 注册构建任务
8
6
  * 2. 监听各个构建任务进程中的信息:process.stdout.on('data' | 'error')
9
7
  * 3. 分别输出内容
10
8
  */
9
+
11
10
  import EventEmitter from 'events';
12
11
  import { chalk, Import } from '@modern-js/utils';
13
12
  const logText = Import.lazy('./logText', require);
@@ -15,19 +14,14 @@ const readline = Import.lazy('../../../utils/readline', require);
15
14
  export class LoggerManager extends EventEmitter {
16
15
  constructor() {
17
16
  super();
18
-
19
17
  _defineProperty(this, "_compilering", void 0);
20
-
21
18
  _defineProperty(this, "_listeners", void 0);
22
-
23
19
  this._compilering = false;
24
20
  this._listeners = [];
25
21
  }
26
-
27
22
  createLoggerText(option) {
28
23
  return new logText.LoggerText(option);
29
24
  }
30
-
31
25
  addStdout(loggerText, stdout, config = {}) {
32
26
  const {
33
27
  event = {
@@ -40,7 +34,6 @@ export class LoggerManager extends EventEmitter {
40
34
  warning: chalk.yellow
41
35
  }
42
36
  } = config;
43
-
44
37
  if (event.data) {
45
38
  stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
46
39
  const data = chunk.toString();
@@ -49,7 +42,6 @@ export class LoggerManager extends EventEmitter {
49
42
  this.emit('data');
50
43
  });
51
44
  }
52
-
53
45
  if (event.error) {
54
46
  stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
55
47
  console.info('error');
@@ -60,10 +52,8 @@ export class LoggerManager extends EventEmitter {
60
52
  this.emit('data');
61
53
  });
62
54
  }
63
-
64
55
  this._listeners.push(stdout);
65
56
  }
66
-
67
57
  addStderr(loggerText, stderr, color = chalk.red) {
68
58
  stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
69
59
  const data = chunk.toString();
@@ -72,29 +62,27 @@ export class LoggerManager extends EventEmitter {
72
62
  this.emit('data');
73
63
  });
74
64
  }
75
-
76
65
  showCompiling() {
77
66
  if (!this._compilering) {
78
67
  this._compilering = true;
79
68
  console.info(chalk.green(_t || (_t = _`Compiling in progress...`)));
80
69
  }
81
70
  }
82
-
83
71
  disappearCompiling() {
84
72
  if (this._compilering) {
85
73
  readline.ReadlineUtils.clearLine(process.stdout);
86
74
  this._compilering = false;
87
75
  }
88
76
  }
89
-
90
- listenDateAndShow(logTexts // stdout: NodeJS.WriteStream & {
77
+ listenDateAndShow(logTexts
78
+ // stdout: NodeJS.WriteStream & {
91
79
  // fd: 1;
92
80
  // } = process.stdout,
93
81
  ) {
94
82
  this.on('data', () => {
95
83
  this.disappearCompiling();
96
- const content = logTexts.map(logtext => logtext.value).join(''); // 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
97
-
84
+ const content = logTexts.map(logtext => logtext.value).join('');
85
+ // 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
98
86
  console.info(content);
99
87
  });
100
88
  return () => {
@@ -102,5 +90,4 @@ export class LoggerManager extends EventEmitter {
102
90
  process.exit(0);
103
91
  };
104
92
  }
105
-
106
93
  }
@@ -1,9 +1,6 @@
1
1
  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; }
2
-
3
2
  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; }
4
-
5
3
  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
-
7
4
  /* eslint-disable max-lines */
8
5
  import { Import, lodash } from '@modern-js/utils';
9
6
  import { mergeWith } from '@modern-js/utils/lodash';
@@ -20,7 +17,6 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
20
17
  }
21
18
  } = api.useResolvedConfigContext();
22
19
  let configs = [];
23
-
24
20
  if (buildFeatOption.styleOnly) {
25
21
  configs.push({
26
22
  buildType: 'bundleless',
@@ -44,7 +40,6 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
44
40
  });
45
41
  return configs;
46
42
  }
47
-
48
43
  const commonConfig = {
49
44
  buildType: 'bundleless',
50
45
  bundlelessOptions: {
@@ -60,7 +55,6 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
60
55
  outputPath: './'
61
56
  };
62
57
  commonConfig.tsconfig = getFinalTsconfig(commonConfig, buildFeatOption);
63
-
64
58
  if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
65
59
  const buildConfigs = legacyConstants.PACKAGE_MODES[packageMode || legacyConstants.DEFAULT_PACKAGE_MODE];
66
60
  configs = buildConfigs.map(config => lodash.mergeWith({}, commonConfig, config));
@@ -79,33 +73,27 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
79
73
  outputPath
80
74
  });
81
75
  }
82
-
83
76
  return lodash.mergeWith({}, commonConfig, {
84
77
  format: 'esm',
85
78
  target: 'es6',
86
79
  outputPath
87
80
  });
88
81
  };
89
-
90
82
  if (!packageFields['jsnext:modern'] && !packageFields.main && !packageFields.module) {
91
83
  throw new Error(`Unrecognized ${JSON.stringify(packageFields)} configuration, please use keys: 'modern, main, jupiter:modern' and use values: 'CJS+ES6, ESM+ES5, ESM+ES6'`);
92
- } // The fields configured in packageFields correspond to the main, module, and jsnext:modern fields on package.json,
84
+ }
85
+ // The fields configured in packageFields correspond to the main, module, and jsnext:modern fields on package.json,
93
86
  // and can also be used on package.json exports field.
94
-
95
-
96
87
  if (packageFields['jsnext:modern']) {
97
88
  configs.push(getConfigsByJsSyntaxType(packageFields['jsnext:modern'], 'js/modern'));
98
89
  }
99
-
100
90
  if (packageFields.main) {
101
91
  configs.push(getConfigsByJsSyntaxType(packageFields.main, 'js/node'));
102
92
  }
103
-
104
93
  if (packageFields.module) {
105
94
  configs.push(getConfigsByJsSyntaxType(packageFields.module, 'js/treeshaking'));
106
95
  }
107
96
  }
108
-
109
97
  if (configs.length > 0) {
110
98
  const firstConfig = configs[0];
111
99
  firstConfig.bundlelessOptions = lodash.mergeWith({}, firstConfig.bundlelessOptions, {
@@ -113,9 +101,9 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
113
101
  compileMode: importStyle === 'source-code' ? 'only-source-code' : 'all'
114
102
  }
115
103
  });
116
- } // [compatibe mode]: dts gen
117
-
104
+ }
118
105
 
106
+ // [compatibe mode]: dts gen
119
107
  if (buildFeatOption.legacyTsc && !disableTsChecker) {
120
108
  configs.push({
121
109
  buildType: 'bundleless',
@@ -124,7 +112,6 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
124
112
  dtsOnly: true
125
113
  });
126
114
  }
127
-
128
115
  configs.push({
129
116
  buildType: 'bundleless',
130
117
  outputPath: './styles',
@@ -139,30 +126,26 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
139
126
  };
140
127
  export const getFinalTsconfig = (config, buildFeatOption) => {
141
128
  var _config$tsconfig;
142
-
143
129
  // cli tsconfig option > buildPreset tsconfig option
130
+
144
131
  // Since tsconfig configuration has default values,
145
132
  // compare the two to see if the user is configured with cli tsconfig
146
133
  if (buildFeatOption.tsconfigName !== cliTsConfigDefaultValue) {
147
134
  // TODO: transform tsconfig to absPath
148
135
  return buildFeatOption.tsconfigName;
149
136
  }
150
-
151
137
  return (_config$tsconfig = config.tsconfig) !== null && _config$tsconfig !== void 0 ? _config$tsconfig : './tsconfig.json';
152
138
  };
153
139
  export const getFinalDts = (config, buildFeatOption) => {
154
140
  var _config$enableDts;
155
-
156
141
  // is js project, should return false
157
142
  if (!buildFeatOption.isTsProject) {
158
143
  return false;
159
- } // when `build --dts`, then all build tasks`s enableDts is true
160
-
161
-
144
+ }
145
+ // when `build --dts`, then all build tasks`s enableDts is true
162
146
  if (buildFeatOption.enableDtsGen) {
163
147
  return true;
164
148
  }
165
-
166
149
  return (_config$enableDts = config.enableDts) !== null && _config$enableDts !== void 0 ? _config$enableDts : false;
167
150
  };
168
151
  export const getSourceMap = (config, buildType, api) => {
@@ -172,15 +155,12 @@ export const getSourceMap = (config, buildType, api) => {
172
155
  disableSourceMap
173
156
  }
174
157
  } = api.useResolvedConfigContext();
175
-
176
158
  if (disableSourceMap) {
177
159
  return false;
178
160
  }
179
-
180
161
  if (config.sourceMap !== undefined) {
181
162
  return config.sourceMap;
182
163
  }
183
-
184
164
  return buildType === 'bundle';
185
165
  };
186
166
  export const normalizeBuildConfig = (context, buildConfig, deps = []) => {
@@ -191,7 +171,6 @@ export const normalizeBuildConfig = (context, buildConfig, deps = []) => {
191
171
  const configArray = Array.isArray(buildConfig) ? buildConfig : [buildConfig];
192
172
  const normalizedModule = configArray.map(config => {
193
173
  var _config$format, _config$target, _bundleOptions$skipDe, _bundleOptions$minify, _bundleOptions$splitt, _config$outputPath, _config$dtsOnly;
194
-
195
174
  const format = (_config$format = config.format) !== null && _config$format !== void 0 ? _config$format : 'cjs';
196
175
  const target = (_config$target = config.target) !== null && _config$target !== void 0 ? _config$target : 'esnext';
197
176
  const {
@@ -199,7 +178,6 @@ export const normalizeBuildConfig = (context, buildConfig, deps = []) => {
199
178
  } = config;
200
179
  const skipDeps = (_bundleOptions$skipDe = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.skipDeps) !== null && _bundleOptions$skipDe !== void 0 ? _bundleOptions$skipDe : true;
201
180
  const externals = skipDeps === false ? (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.externals) || [] : [...deps.map(dep => new RegExp(`^${dep}($|\\/|\\\\)`)), ...((bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.externals) || [])];
202
-
203
181
  const normalizedBundleOption = _objectSpread(_objectSpread({}, bundleOptions), {}, {
204
182
  entry: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.entry) || {
205
183
  index: `src/index.${buildFeatOption.isTsProject ? 'ts' : 'js'}`
@@ -210,7 +188,6 @@ export const normalizeBuildConfig = (context, buildConfig, deps = []) => {
210
188
  splitting: (_bundleOptions$splitt = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.splitting) !== null && _bundleOptions$splitt !== void 0 ? _bundleOptions$splitt : false,
211
189
  skipDeps
212
190
  });
213
-
214
191
  const normalizedBundlelessOptions = mergeWith({}, {
215
192
  sourceDir: './src',
216
193
  style: {
@@ -237,13 +214,11 @@ export const normalizeBuildConfig = (context, buildConfig, deps = []) => {
237
214
  dtsOnly,
238
215
  sourceMap
239
216
  };
240
-
241
217
  if (!buildFeatOption.isTsProject && (dtsOnly || enableDts)) {
242
218
  console.warn('[WARN] dtsOnly、enableDts 配置仅在 Ts 项目下生效');
243
219
  } else if (buildFeatOption.isTsProject && dtsOnly && !enableDts) {
244
220
  console.warn('[WARN] dtsOnly 配置仅在 enableDts 为 true 的时候生效. 请检查当前的 dtsOnly、enableDts 是否配置正确');
245
221
  }
246
-
247
222
  if (config.buildType === 'bundle') {
248
223
  return _objectSpread(_objectSpread({}, commmonConfig), {}, {
249
224
  buildType: 'bundle',
@@ -269,33 +244,33 @@ export const normalizeModuleConfig = context => {
269
244
  buildConfig,
270
245
  buildPreset
271
246
  }
272
- } = api.useResolvedConfigContext(); // buildConfig is the most important.
247
+ } = api.useResolvedConfigContext();
273
248
 
249
+ // buildConfig is the most important.
274
250
  if (buildConfig) {
275
251
  return normalizeBuildConfig(context, buildConfig, deps);
276
- } // buildPreset is the second important. It can be used when buildConfig is not defined.
277
- // buildPreset -> buildConfig
278
-
252
+ }
279
253
 
254
+ // buildPreset is the second important. It can be used when buildConfig is not defined.
255
+ // buildPreset -> buildConfig
280
256
  if (buildPreset) {
281
257
  const {
282
258
  unPresetConfigs,
283
259
  unPresetWithTargetConfigs
284
260
  } = constants;
285
-
286
261
  if (unPresetConfigs[buildPreset]) {
287
262
  return normalizeBuildConfig(context, unPresetConfigs[buildPreset], deps);
288
263
  } else if (unPresetWithTargetConfigs[buildPreset]) {
289
264
  return normalizeBuildConfig(context, unPresetWithTargetConfigs[buildPreset], deps);
290
- } // If the buildPreset is not found, then it is used 'npm-library'
291
- // TODO: Warning: The buildPreset 'npm-library' is not supported.
292
-
265
+ }
293
266
 
267
+ // If the buildPreset is not found, then it is used 'npm-library'
268
+ // TODO: Warning: The buildPreset 'npm-library' is not supported.
294
269
  return normalizeBuildConfig(context, unPresetConfigs['npm-library'], deps);
295
- } // If the user does not configure buildConfig and buildPreset,
296
- // the configuration is generated based on packageMode and packageField
297
-
270
+ }
298
271
 
272
+ // If the user does not configure buildConfig and buildPreset,
273
+ // the configuration is generated based on packageMode and packageField
299
274
  const legacyBuildConfig = getNormalizeModuleConfigByPackageModeAndFileds(api, buildFeatOption);
300
275
  return normalizeBuildConfig(context, legacyBuildConfig, deps);
301
276
  };
@@ -1,21 +1,17 @@
1
1
  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; }
2
-
3
2
  import * as os from 'os';
4
3
  import path from 'path';
5
4
  import { chalk, Import, fs } from '@modern-js/utils';
6
5
  const constants = Import.lazy('./constants', require);
7
- const cssConfig = Import.lazy('@modern-js/css-config', require);
6
+
8
7
  /**
9
8
  * 处理日志信息
10
9
  */
11
-
12
10
  export class LogStack {
13
11
  constructor() {
14
12
  _defineProperty(this, "_codeLogStack", void 0);
15
-
16
13
  this._codeLogStack = [];
17
14
  }
18
-
19
15
  update(latestLog, {
20
16
  splitEOL = false
21
17
  } = {}) {
@@ -25,18 +21,14 @@ export class LogStack {
25
21
  });
26
22
  return;
27
23
  }
28
-
29
24
  this._codeLogStack.unshift(latestLog.trim());
30
25
  }
31
-
32
26
  clear() {
33
27
  this._codeLogStack = [];
34
28
  }
35
-
36
29
  get value() {
37
30
  return [...new Set(this._codeLogStack)];
38
31
  }
39
-
40
32
  }
41
33
  export const logTemplate = (title, messageStack, maxLength, {
42
34
  noBottomBorder: _noBottomBorder = false,
@@ -53,42 +45,45 @@ export const logTemplate = (title, messageStack, maxLength, {
53
45
  .slice(0, maxLength) // 控制长度
54
46
  .filter(s => s !== leftBorderFlag) // 过滤空字符串
55
47
  .reverse(); // 调换顺序,最新的消息在最后面
56
-
57
48
  const template = `${title}:
58
49
  ${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
59
50
  return template;
60
51
  };
61
52
  export let SectionTitleStatus;
62
-
63
53
  (function (SectionTitleStatus) {
64
54
  SectionTitleStatus[SectionTitleStatus["Success"] = 0] = "Success";
65
55
  SectionTitleStatus[SectionTitleStatus["Fail"] = 1] = "Fail";
66
56
  SectionTitleStatus[SectionTitleStatus["Log"] = 2] = "Log";
67
57
  })(SectionTitleStatus || (SectionTitleStatus = {}));
68
-
69
58
  export const watchSectionTitle = (str, status) => {
70
59
  if (status === SectionTitleStatus.Success) {
71
60
  return `${chalk.bgWhite.gray.underline(str)} ${chalk.green.underline('Successful')}`;
72
61
  } else if (status === SectionTitleStatus.Fail) {
73
62
  return `${chalk.bgWhite.gray.underline(str)} ${chalk.red.underline('Build Failed')}`;
74
63
  }
75
-
76
64
  return `${chalk.bgWhite.gray.underline(str)} ${chalk.blue.underline('Log')}`;
77
65
  };
78
- export const getPostcssOption = (appDirectory, modernConfig) => {
79
- var _postcssOption$postcs;
80
66
 
81
- const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
67
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
68
+ export const getPostcssOption = (...args) => {
69
+ // const postcssOption: any = cssConfig.getPostcssConfig(
70
+ // appDirectory,
71
+ // modernConfig,
72
+ // false,
73
+ // );
82
74
  return {
83
- plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
84
- enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
75
+ plugins: [],
76
+ enableSourceMap: false,
77
+ // plugins: postcssOption?.postcssOptions?.plugins || [],
78
+ // enableSourceMap: (postcssOption as any)?.sourceMap || false,
85
79
  options: {}
86
80
  };
87
81
  };
88
82
  export const getAllDeps = appDirectory => {
89
83
  try {
90
- const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, './package.json'), 'utf8')); // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
84
+ const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, './package.json'), 'utf8'));
91
85
 
86
+ // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
92
87
  return [...Object.keys(json.dependencies || {}), ...Object.keys(json.devDependencies || {}), ...Object.keys(json.peerDependencies || {})];
93
88
  } catch (e) {
94
89
  console.warn('[WARN] package.json is broken');
@@ -3,13 +3,11 @@ const color = Import.lazy('../../utils/color', require);
3
3
  export const showMenu = async (api, config) => {
4
4
  const runners = api.useHookRunners();
5
5
  const metas = await runners.moduleToolsMenu(undefined);
6
-
7
6
  if (metas.length <= 0) {
8
- console.info(chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
9
-
7
+ console.info(chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features'));
8
+ // eslint-disable-next-line no-process-exit
10
9
  process.exit(0);
11
10
  }
12
-
13
11
  const menuMessage = color.devMenuTitle('Select the debug mode:');
14
12
  const {
15
13
  type
@@ -20,7 +18,6 @@ export const showMenu = async (api, config) => {
20
18
  choices: metas
21
19
  }]);
22
20
  const devMeta = metas.find(meta => meta.value === type);
23
-
24
21
  if (devMeta) {
25
22
  await devMeta.runTask(config);
26
23
  }
@@ -29,12 +26,11 @@ export const devStorybook = async (api, config) => {
29
26
  const runners = api.useHookRunners();
30
27
  const metas = await runners.moduleToolsMenu(undefined);
31
28
  const findStorybook = metas.find(meta => meta.value === 'storybook');
32
-
33
29
  if (findStorybook) {
34
30
  await findStorybook.runTask(config);
35
31
  } else {
36
- console.info(chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
37
-
32
+ console.info(chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features'));
33
+ // eslint-disable-next-line no-process-exit
38
34
  process.exit(0);
39
35
  }
40
36
  };
@@ -42,7 +38,6 @@ export const runSubCmd = async (api, subCmd, config) => {
42
38
  const runners = api.useHookRunners();
43
39
  const metas = await runners.moduleToolsMenu(undefined);
44
40
  const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
45
-
46
41
  if (devMeta) {
47
42
  await devMeta.runTask(config);
48
43
  } else {
@@ -1,9 +1,6 @@
1
1
  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; }
2
-
3
2
  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; }
4
-
5
3
  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
-
7
4
  import { createAsyncWaterfall } from '@modern-js/plugin';
8
5
  import { buildHooks, lifecycle as buildLifeCycle } from "./build";
9
6
  import { devHooks, lifecycle as devLifeCycle } from "./dev";
@@ -1,6 +1,6 @@
1
1
  import { Import, fs } from '@modern-js/utils';
2
2
  import ChangesetPlugin from '@modern-js/plugin-changeset';
3
- import LintPlugin from '@modern-js/plugin-jarvis';
3
+ import LintPlugin from '@modern-js/plugin-lint';
4
4
  import { hooks } from "./hooks";
5
5
  export * from "./types";
6
6
  const upgradeModel = Import.lazy('@modern-js/upgrade', require);
@@ -25,19 +25,16 @@ export default (() => ({
25
25
  async prepare() {
26
26
  const appContext = api.useAppContext();
27
27
  const hookRunners = api.useHookRunners();
28
-
29
28
  try {
30
29
  fs.emptydirSync(appContext.internalDirectory);
31
- } catch (_unused) {// FIXME:
30
+ } catch (_unused) {
31
+ // FIXME:
32
32
  }
33
-
34
33
  await hookRunners.addRuntimeExports();
35
34
  },
36
-
37
35
  validateSchema() {
38
36
  return schema.addSchema();
39
37
  },
40
-
41
38
  config() {
42
39
  return {
43
40
  output: {
@@ -46,18 +43,17 @@ export default (() => ({
46
43
  }
47
44
  };
48
45
  },
49
-
50
46
  commands({
51
47
  program
52
48
  }) {
53
49
  cli.devCli(program, api);
54
50
  cli.buildCli(program, api);
55
51
  cli.newCli(program, locale);
56
- upgradeModel.defineCommand(program.command('upgrade')); // 便于其他插件辨别
52
+ upgradeModel.defineCommand(program.command('upgrade'));
57
53
 
54
+ // 便于其他插件辨别
58
55
  program.$$libraryName = 'module-tools';
59
56
  }
60
-
61
57
  };
62
58
  }
63
59
  }));
@@ -1,4 +1,5 @@
1
- export const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.
1
+ export const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020',
2
+ // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.
2
3
  'esnext'];
3
4
  export const presets = ['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd', ...['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd'].reduce((ret, crt) => {
4
5
  return [...ret, ...targets.map(t => `${crt}-${t}`)];
@@ -1,35 +1,30 @@
1
1
  import { buildSchema } from "./build-config";
2
2
  const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
3
- export const outputSchema = [
4
- /** packageMode will deprecated */
3
+ export const outputSchema = [/** packageMode will deprecated */
5
4
  {
6
5
  target: 'output.packageMode',
7
6
  schema: {
8
7
  enum: PACKAGE_MODE_LIST
9
8
  }
10
- },
11
- /** packageFields will deprecated */
9
+ }, /** packageFields will deprecated */
12
10
  {
13
11
  target: 'output.packageFields',
14
12
  schema: {
15
13
  typeof: 'object'
16
14
  }
17
- },
18
- /** enableSourceMap will deprecated */
15
+ }, /** enableSourceMap will deprecated */
19
16
  {
20
17
  target: 'output.enableSourceMap',
21
18
  schema: {
22
19
  typeof: 'boolean'
23
20
  }
24
- },
25
- /** importStyle will deprecated */
21
+ }, /** importStyle will deprecated */
26
22
  {
27
23
  target: 'output.importStyle',
28
24
  schema: {
29
25
  enum: ['compiled-code', 'source-code']
30
26
  }
31
- },
32
- /** assetsPath will deprecated */
27
+ }, /** assetsPath will deprecated */
33
28
  {
34
29
  target: 'output.assetsPath',
35
30
  schema: {