@modern-js/module-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 (93) hide show
  1. package/CHANGELOG.md +51 -0
  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 +5 -14
  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 +12 -14
  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 +5 -30
  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 +0 -1
  90. package/dist/types/index.d.ts +0 -2
  91. package/dist/types/schema/types.d.ts +1 -3
  92. package/dist/types/types.d.ts +0 -1
  93. package/package.json +19 -19
@@ -4,39 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.runBuild = exports.checkPlatformAndRunBuild = exports.buildInNormalMode = exports.build = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _pMap = _interopRequireDefault(require("p-map"));
13
-
14
10
  var _readline = require("../../utils/readline");
15
-
16
11
  var _normalize = require("./normalize");
17
-
18
12
  var _constants = require("./constants");
19
-
20
13
  var _error = require("./error");
21
-
22
14
  var _utils2 = require("./utils");
23
-
24
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
16
  const bundle = _utils.Import.lazy('./bundle', require);
27
-
28
17
  const bundleless = _utils.Import.lazy('./bundleless', require);
29
-
30
18
  const bp = _utils.Import.lazy('./build-platform', require);
31
-
32
19
  const copyUtils = _utils.Import.lazy('../../utils/copy', require);
33
-
34
20
  const checkPlatformAndRunBuild = async (platform, options) => {
35
21
  const {
36
22
  api,
37
23
  isTsProject
38
24
  } = options;
39
-
40
25
  if (typeof platform === 'boolean' && platform) {
41
26
  if (process.env.RUN_PLATFORM) {
42
27
  await bp.buildPlatform(api, {
@@ -44,12 +29,10 @@ const checkPlatformAndRunBuild = async (platform, options) => {
44
29
  isTsProject
45
30
  });
46
31
  }
47
-
48
32
  return {
49
33
  exit: true
50
34
  };
51
35
  }
52
-
53
36
  if (typeof platform === 'string') {
54
37
  if (process.env.RUN_PLATFORM) {
55
38
  await bp.buildPlatform(api, {
@@ -57,19 +40,15 @@ const checkPlatformAndRunBuild = async (platform, options) => {
57
40
  isTsProject
58
41
  });
59
42
  }
60
-
61
43
  return {
62
44
  exit: true
63
45
  };
64
46
  }
65
-
66
47
  return {
67
48
  exit: false
68
49
  };
69
50
  };
70
-
71
51
  exports.checkPlatformAndRunBuild = checkPlatformAndRunBuild;
72
-
73
52
  const runBuild = async (api, normalizedModuleConfig, config) => {
74
53
  await (0, _pMap.default)(normalizedModuleConfig, async moduleConfig => {
75
54
  if (moduleConfig.buildType === 'bundle') {
@@ -79,24 +58,18 @@ const runBuild = async (api, normalizedModuleConfig, config) => {
79
58
  }
80
59
  });
81
60
  };
82
-
83
61
  exports.runBuild = runBuild;
84
-
85
62
  const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
86
63
  console.info(_utils.chalk.blue.bold(_constants.buildingText));
87
-
88
64
  try {
89
65
  // eslint-disable-next-line no-console
90
66
  console.time(_constants.buildSuccessText);
91
67
  await runBuild(api, normalizedModuleConfig, config);
92
-
93
- _readline.ReadlineUtils.clearPrevLine(process.stdout); // eslint-disable-next-line no-console
94
-
95
-
68
+ _readline.ReadlineUtils.clearPrevLine(process.stdout);
69
+ // eslint-disable-next-line no-console
96
70
  console.timeEnd(_constants.buildSuccessText);
97
71
  } catch (e) {
98
72
  _readline.ReadlineUtils.clearPrevLine(process.stdout);
99
-
100
73
  if ((0, _error.isInternalError)(e)) {
101
74
  throw new _error.ModuleBuildError(e);
102
75
  } else {
@@ -104,9 +77,7 @@ const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
104
77
  }
105
78
  }
106
79
  };
107
-
108
80
  exports.buildInNormalMode = buildInNormalMode;
109
-
110
81
  const build = async (api, config) => {
111
82
  const {
112
83
  platform,
@@ -122,23 +93,22 @@ const build = async (api, config) => {
122
93
  output: {
123
94
  path: outputPath = 'dist'
124
95
  }
125
- } = modernConfig; // build platform
96
+ } = modernConfig;
126
97
 
98
+ // build platform
127
99
  const platformBuildRet = await checkPlatformAndRunBuild(platform, {
128
100
  api,
129
101
  isTsProject
130
102
  });
131
-
132
103
  if (platformBuildRet.exit) {
133
104
  return;
134
105
  }
135
-
136
106
  if (clear) {
137
107
  _utils.fs.removeSync(_path.default.join(appDirectory, outputPath));
138
108
  }
109
+ const deps = (0, _utils2.getAllDeps)(appDirectory);
139
110
 
140
- const deps = (0, _utils2.getAllDeps)(appDirectory); // should normalize module tool config here, ensure the same config for build
141
-
111
+ // should normalize module tool config here, ensure the same config for build
142
112
  const normalizedModuleConfig = (0, _normalize.normalizeModuleConfig)({
143
113
  buildFeatOption: config,
144
114
  api,
@@ -148,7 +118,6 @@ const build = async (api, config) => {
148
118
  modernConfig,
149
119
  appContext
150
120
  });
151
-
152
121
  if (config.enableWatchMode) {
153
122
  console.info(_utils.chalk.blue.underline('start build in watch mode...\n'));
154
123
  await runBuild(api, normalizedModuleConfig, config);
@@ -156,5 +125,4 @@ const build = async (api, config) => {
156
125
  await buildInNormalMode(api, normalizedModuleConfig, config);
157
126
  }
158
127
  };
159
-
160
128
  exports.build = build;
@@ -22,8 +22,9 @@ const universalJs = [{
22
22
  format: 'esm',
23
23
  target: 'es6',
24
24
  outputPath: './js/modern'
25
- }]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
25
+ }];
26
26
 
27
+ // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
27
28
  const universalJsLite = [{
28
29
  format: 'esm',
29
30
  target: 'es5',
@@ -41,8 +42,9 @@ const universalJsLite = [{
41
42
  format: 'esm',
42
43
  target: 'es5',
43
44
  outputPath: './js/modern'
44
- }]; // 纯前端代码的默认选择,两份构建产物
45
+ }];
45
46
 
47
+ // 纯前端代码的默认选择,两份构建产物
46
48
  const browserJs = [{
47
49
  format: 'esm',
48
50
  target: 'es5',
@@ -60,8 +62,9 @@ const browserJs = [{
60
62
  format: 'esm',
61
63
  target: 'es6',
62
64
  outputPath: './js/modern'
63
- }]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
65
+ }];
64
66
 
67
+ // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
65
68
  const browserJsLite = [{
66
69
  format: 'esm',
67
70
  target: 'es5',
@@ -79,8 +82,9 @@ const browserJsLite = [{
79
82
  format: 'esm',
80
83
  target: 'es5',
81
84
  outputPath: './js/modern'
82
- }]; // 纯 Node.js 代码的默认选择,两份构建产物
85
+ }];
83
86
 
87
+ // 纯 Node.js 代码的默认选择,两份构建产物
84
88
  const nodeJs = [{
85
89
  format: 'cjs',
86
90
  target: 'es6',
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _logText = require("./logText");
8
-
9
7
  Object.keys(_logText).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _logText[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_logText).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _loggerManager = require("./loggerManager");
21
-
22
18
  Object.keys(_loggerManager).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _loggerManager[key]) return;
@@ -4,18 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.logTemplate = exports.colors = exports.clearFlag = exports.LoggerText = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  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; }
11
-
12
9
  const colors = {
13
10
  title: _utils.chalk.rgb(218, 152, 92)
14
11
  };
15
12
  exports.colors = colors;
16
13
  const clearFlag = '\x1Bc';
17
14
  exports.clearFlag = clearFlag;
18
-
19
15
  const logTemplate = (title, messageStack, {
20
16
  noBottomBorder: _noBottomBorder = false,
21
17
  bottomBorderText: _bottomBorderText = '',
@@ -24,7 +20,6 @@ const logTemplate = (title, messageStack, {
24
20
  contentColor: _contentColor = s => s
25
21
  } = {}) => {
26
22
  const maxLength = Infinity; // TODO: 考虑后面是否提供该参数
27
-
28
23
  const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
29
24
  const messageFragments = messageStack.map(p => {
30
25
  p.trim();
@@ -32,44 +27,33 @@ const logTemplate = (title, messageStack, {
32
27
  }) // 移除 clearFlag
33
28
  .filter(s => s !== leftBorderFlag) // 过滤空字符串
34
29
  .slice(0, maxLength); // 控制长度
35
-
36
30
  const template = `${colors.title(title)}:
37
31
  ${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
38
32
  return template;
39
33
  };
40
-
41
34
  exports.logTemplate = logTemplate;
42
-
43
35
  // 处理Log内容如何展示
44
36
  class LoggerText {
45
37
  constructor(option) {
46
38
  _defineProperty(this, "messages", void 0);
47
-
48
39
  _defineProperty(this, "hasErrorMessage", void 0);
49
-
50
40
  _defineProperty(this, "option", void 0);
51
-
52
41
  this.messages = [];
53
42
  this.option = option;
54
43
  this.hasErrorMessage = false;
55
44
  }
56
-
57
45
  append(message) {
58
46
  if (message.includes(clearFlag)) {
59
47
  this.messages = [];
60
48
  }
61
-
62
49
  this.messages.push(message);
63
50
  }
64
-
65
51
  errorHappen() {
66
52
  this.hasErrorMessage = true;
67
53
  }
68
-
69
54
  hasMessages() {
70
55
  return this.messages.length > 0;
71
56
  }
72
-
73
57
  get value() {
74
58
  const {
75
59
  title,
@@ -78,7 +62,5 @@ class LoggerText {
78
62
  const messages = [...new Set(this.messages)];
79
63
  return logTemplate(title, messages, contentConfig);
80
64
  }
81
-
82
65
  }
83
-
84
66
  exports.LoggerText = LoggerText;
@@ -4,38 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.LoggerManager = void 0;
7
-
8
7
  var _events = _interopRequireDefault(require("events"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  let _ = t => t,
13
- _t;
14
-
10
+ _t;
15
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
12
  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; }
18
-
19
13
  const logText = _utils.Import.lazy('./logText', require);
20
-
21
14
  const readline = _utils.Import.lazy('../../../utils/readline', require);
22
-
23
15
  class LoggerManager extends _events.default {
24
16
  constructor() {
25
17
  super();
26
-
27
18
  _defineProperty(this, "_compilering", void 0);
28
-
29
19
  _defineProperty(this, "_listeners", void 0);
30
-
31
20
  this._compilering = false;
32
21
  this._listeners = [];
33
22
  }
34
-
35
23
  createLoggerText(option) {
36
24
  return new logText.LoggerText(option);
37
25
  }
38
-
39
26
  addStdout(loggerText, stdout, config = {}) {
40
27
  const {
41
28
  event = {
@@ -48,7 +35,6 @@ class LoggerManager extends _events.default {
48
35
  warning: _utils.chalk.yellow
49
36
  }
50
37
  } = config;
51
-
52
38
  if (event.data) {
53
39
  stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
54
40
  const data = chunk.toString();
@@ -57,7 +43,6 @@ class LoggerManager extends _events.default {
57
43
  this.emit('data');
58
44
  });
59
45
  }
60
-
61
46
  if (event.error) {
62
47
  stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
63
48
  console.info('error');
@@ -68,10 +53,8 @@ class LoggerManager extends _events.default {
68
53
  this.emit('data');
69
54
  });
70
55
  }
71
-
72
56
  this._listeners.push(stdout);
73
57
  }
74
-
75
58
  addStderr(loggerText, stderr, color = _utils.chalk.red) {
76
59
  stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
77
60
  const data = chunk.toString();
@@ -80,29 +63,27 @@ class LoggerManager extends _events.default {
80
63
  this.emit('data');
81
64
  });
82
65
  }
83
-
84
66
  showCompiling() {
85
67
  if (!this._compilering) {
86
68
  this._compilering = true;
87
69
  console.info(_utils.chalk.green(_t || (_t = _`Compiling in progress...`)));
88
70
  }
89
71
  }
90
-
91
72
  disappearCompiling() {
92
73
  if (this._compilering) {
93
74
  readline.ReadlineUtils.clearLine(process.stdout);
94
75
  this._compilering = false;
95
76
  }
96
77
  }
97
-
98
- listenDateAndShow(logTexts // stdout: NodeJS.WriteStream & {
78
+ listenDateAndShow(logTexts
79
+ // stdout: NodeJS.WriteStream & {
99
80
  // fd: 1;
100
81
  // } = process.stdout,
101
82
  ) {
102
83
  this.on('data', () => {
103
84
  this.disappearCompiling();
104
- const content = logTexts.map(logtext => logtext.value).join(''); // 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
105
-
85
+ const content = logTexts.map(logtext => logtext.value).join('');
86
+ // 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
106
87
  console.info(content);
107
88
  });
108
89
  return () => {
@@ -110,7 +91,5 @@ class LoggerManager extends _events.default {
110
91
  process.exit(0);
111
92
  };
112
93
  }
113
-
114
94
  }
115
-
116
95
  exports.LoggerManager = LoggerManager;
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.normalizeModuleConfig = exports.normalizeBuildConfig = exports.getSourceMap = exports.getNormalizeModuleConfigByPackageModeAndFileds = exports.getFinalTsconfig = exports.getFinalDts = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  var _lodash = require("@modern-js/utils/lodash");
11
-
12
9
  var _constants = require("../../utils/constants");
13
-
14
10
  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; }
15
-
16
11
  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; }
17
-
18
12
  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; }
19
-
20
13
  const constants = _utils.Import.lazy('./constants', require);
21
-
22
14
  const legacyConstants = _utils.Import.lazy('./legacy-constants', require);
23
-
24
15
  const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) => {
25
16
  const {
26
17
  output: {
@@ -31,7 +22,6 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
31
22
  }
32
23
  } = api.useResolvedConfigContext();
33
24
  let configs = [];
34
-
35
25
  if (buildFeatOption.styleOnly) {
36
26
  configs.push({
37
27
  buildType: 'bundleless',
@@ -55,7 +45,6 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
55
45
  });
56
46
  return configs;
57
47
  }
58
-
59
48
  const commonConfig = {
60
49
  buildType: 'bundleless',
61
50
  bundlelessOptions: {
@@ -71,7 +60,6 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
71
60
  outputPath: './'
72
61
  };
73
62
  commonConfig.tsconfig = getFinalTsconfig(commonConfig, buildFeatOption);
74
-
75
63
  if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
76
64
  const buildConfigs = legacyConstants.PACKAGE_MODES[packageMode || legacyConstants.DEFAULT_PACKAGE_MODE];
77
65
  configs = buildConfigs.map(config => _utils.lodash.mergeWith({}, commonConfig, config));
@@ -90,33 +78,27 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
90
78
  outputPath
91
79
  });
92
80
  }
93
-
94
81
  return _utils.lodash.mergeWith({}, commonConfig, {
95
82
  format: 'esm',
96
83
  target: 'es6',
97
84
  outputPath
98
85
  });
99
86
  };
100
-
101
87
  if (!packageFields['jsnext:modern'] && !packageFields.main && !packageFields.module) {
102
88
  throw new Error(`Unrecognized ${JSON.stringify(packageFields)} configuration, please use keys: 'modern, main, jupiter:modern' and use values: 'CJS+ES6, ESM+ES5, ESM+ES6'`);
103
- } // The fields configured in packageFields correspond to the main, module, and jsnext:modern fields on package.json,
89
+ }
90
+ // The fields configured in packageFields correspond to the main, module, and jsnext:modern fields on package.json,
104
91
  // and can also be used on package.json exports field.
105
-
106
-
107
92
  if (packageFields['jsnext:modern']) {
108
93
  configs.push(getConfigsByJsSyntaxType(packageFields['jsnext:modern'], 'js/modern'));
109
94
  }
110
-
111
95
  if (packageFields.main) {
112
96
  configs.push(getConfigsByJsSyntaxType(packageFields.main, 'js/node'));
113
97
  }
114
-
115
98
  if (packageFields.module) {
116
99
  configs.push(getConfigsByJsSyntaxType(packageFields.module, 'js/treeshaking'));
117
100
  }
118
101
  }
119
-
120
102
  if (configs.length > 0) {
121
103
  const firstConfig = configs[0];
122
104
  firstConfig.bundlelessOptions = _utils.lodash.mergeWith({}, firstConfig.bundlelessOptions, {
@@ -124,9 +106,9 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
124
106
  compileMode: importStyle === 'source-code' ? 'only-source-code' : 'all'
125
107
  }
126
108
  });
127
- } // [compatibe mode]: dts gen
128
-
109
+ }
129
110
 
111
+ // [compatibe mode]: dts gen
130
112
  if (buildFeatOption.legacyTsc && !disableTsChecker) {
131
113
  configs.push({
132
114
  buildType: 'bundleless',
@@ -135,7 +117,6 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
135
117
  dtsOnly: true
136
118
  });
137
119
  }
138
-
139
120
  configs.push({
140
121
  buildType: 'bundleless',
141
122
  outputPath: './styles',
@@ -148,43 +129,33 @@ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) =>
148
129
  });
149
130
  return configs;
150
131
  };
151
-
152
132
  exports.getNormalizeModuleConfigByPackageModeAndFileds = getNormalizeModuleConfigByPackageModeAndFileds;
153
-
154
133
  const getFinalTsconfig = (config, buildFeatOption) => {
155
134
  var _config$tsconfig;
156
-
157
135
  // cli tsconfig option > buildPreset tsconfig option
136
+
158
137
  // Since tsconfig configuration has default values,
159
138
  // compare the two to see if the user is configured with cli tsconfig
160
139
  if (buildFeatOption.tsconfigName !== _constants.cliTsConfigDefaultValue) {
161
140
  // TODO: transform tsconfig to absPath
162
141
  return buildFeatOption.tsconfigName;
163
142
  }
164
-
165
143
  return (_config$tsconfig = config.tsconfig) !== null && _config$tsconfig !== void 0 ? _config$tsconfig : './tsconfig.json';
166
144
  };
167
-
168
145
  exports.getFinalTsconfig = getFinalTsconfig;
169
-
170
146
  const getFinalDts = (config, buildFeatOption) => {
171
147
  var _config$enableDts;
172
-
173
148
  // is js project, should return false
174
149
  if (!buildFeatOption.isTsProject) {
175
150
  return false;
176
- } // when `build --dts`, then all build tasks`s enableDts is true
177
-
178
-
151
+ }
152
+ // when `build --dts`, then all build tasks`s enableDts is true
179
153
  if (buildFeatOption.enableDtsGen) {
180
154
  return true;
181
155
  }
182
-
183
156
  return (_config$enableDts = config.enableDts) !== null && _config$enableDts !== void 0 ? _config$enableDts : false;
184
157
  };
185
-
186
158
  exports.getFinalDts = getFinalDts;
187
-
188
159
  const getSourceMap = (config, buildType, api) => {
189
160
  // TODO: remove
190
161
  const {
@@ -192,20 +163,15 @@ const getSourceMap = (config, buildType, api) => {
192
163
  disableSourceMap
193
164
  }
194
165
  } = api.useResolvedConfigContext();
195
-
196
166
  if (disableSourceMap) {
197
167
  return false;
198
168
  }
199
-
200
169
  if (config.sourceMap !== undefined) {
201
170
  return config.sourceMap;
202
171
  }
203
-
204
172
  return buildType === 'bundle';
205
173
  };
206
-
207
174
  exports.getSourceMap = getSourceMap;
208
-
209
175
  const normalizeBuildConfig = (context, buildConfig, deps = []) => {
210
176
  const {
211
177
  buildFeatOption,
@@ -214,7 +180,6 @@ const normalizeBuildConfig = (context, buildConfig, deps = []) => {
214
180
  const configArray = Array.isArray(buildConfig) ? buildConfig : [buildConfig];
215
181
  const normalizedModule = configArray.map(config => {
216
182
  var _config$format, _config$target, _bundleOptions$skipDe, _bundleOptions$minify, _bundleOptions$splitt, _config$outputPath, _config$dtsOnly;
217
-
218
183
  const format = (_config$format = config.format) !== null && _config$format !== void 0 ? _config$format : 'cjs';
219
184
  const target = (_config$target = config.target) !== null && _config$target !== void 0 ? _config$target : 'esnext';
220
185
  const {
@@ -222,7 +187,6 @@ const normalizeBuildConfig = (context, buildConfig, deps = []) => {
222
187
  } = config;
223
188
  const skipDeps = (_bundleOptions$skipDe = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.skipDeps) !== null && _bundleOptions$skipDe !== void 0 ? _bundleOptions$skipDe : true;
224
189
  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) || [])];
225
-
226
190
  const normalizedBundleOption = _objectSpread(_objectSpread({}, bundleOptions), {}, {
227
191
  entry: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.entry) || {
228
192
  index: `src/index.${buildFeatOption.isTsProject ? 'ts' : 'js'}`
@@ -233,7 +197,6 @@ const normalizeBuildConfig = (context, buildConfig, deps = []) => {
233
197
  splitting: (_bundleOptions$splitt = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.splitting) !== null && _bundleOptions$splitt !== void 0 ? _bundleOptions$splitt : false,
234
198
  skipDeps
235
199
  });
236
-
237
200
  const normalizedBundlelessOptions = (0, _lodash.mergeWith)({}, {
238
201
  sourceDir: './src',
239
202
  style: {
@@ -260,13 +223,11 @@ const normalizeBuildConfig = (context, buildConfig, deps = []) => {
260
223
  dtsOnly,
261
224
  sourceMap
262
225
  };
263
-
264
226
  if (!buildFeatOption.isTsProject && (dtsOnly || enableDts)) {
265
227
  console.warn('[WARN] dtsOnly、enableDts 配置仅在 Ts 项目下生效');
266
228
  } else if (buildFeatOption.isTsProject && dtsOnly && !enableDts) {
267
229
  console.warn('[WARN] dtsOnly 配置仅在 enableDts 为 true 的时候生效. 请检查当前的 dtsOnly、enableDts 是否配置正确');
268
230
  }
269
-
270
231
  if (config.buildType === 'bundle') {
271
232
  return _objectSpread(_objectSpread({}, commmonConfig), {}, {
272
233
  buildType: 'bundle',
@@ -281,9 +242,7 @@ const normalizeBuildConfig = (context, buildConfig, deps = []) => {
281
242
  });
282
243
  return normalizedModule;
283
244
  };
284
-
285
245
  exports.normalizeBuildConfig = normalizeBuildConfig;
286
-
287
246
  const normalizeModuleConfig = context => {
288
247
  const {
289
248
  buildFeatOption,
@@ -295,37 +254,35 @@ const normalizeModuleConfig = context => {
295
254
  buildConfig,
296
255
  buildPreset
297
256
  }
298
- } = api.useResolvedConfigContext(); // buildConfig is the most important.
257
+ } = api.useResolvedConfigContext();
299
258
 
259
+ // buildConfig is the most important.
300
260
  if (buildConfig) {
301
261
  return normalizeBuildConfig(context, buildConfig, deps);
302
- } // buildPreset is the second important. It can be used when buildConfig is not defined.
303
- // buildPreset -> buildConfig
304
-
262
+ }
305
263
 
264
+ // buildPreset is the second important. It can be used when buildConfig is not defined.
265
+ // buildPreset -> buildConfig
306
266
  if (buildPreset) {
307
267
  const {
308
268
  unPresetConfigs,
309
269
  unPresetWithTargetConfigs
310
270
  } = constants;
311
-
312
271
  if (unPresetConfigs[buildPreset]) {
313
272
  return normalizeBuildConfig(context, unPresetConfigs[buildPreset], deps);
314
273
  } else if (unPresetWithTargetConfigs[buildPreset]) {
315
274
  return normalizeBuildConfig(context, unPresetWithTargetConfigs[buildPreset], deps);
316
- } // If the buildPreset is not found, then it is used 'npm-library'
317
- // TODO: Warning: The buildPreset 'npm-library' is not supported.
318
-
275
+ }
319
276
 
277
+ // If the buildPreset is not found, then it is used 'npm-library'
278
+ // TODO: Warning: The buildPreset 'npm-library' is not supported.
320
279
  return normalizeBuildConfig(context, unPresetConfigs['npm-library'], deps);
321
- } // If the user does not configure buildConfig and buildPreset,
322
- // the configuration is generated based on packageMode and packageField
323
-
280
+ }
324
281
 
282
+ // If the user does not configure buildConfig and buildPreset,
283
+ // the configuration is generated based on packageMode and packageField
325
284
  const legacyBuildConfig = getNormalizeModuleConfigByPackageModeAndFileds(api, buildFeatOption);
326
285
  return normalizeBuildConfig(context, legacyBuildConfig, deps);
327
286
  };
328
287
  /* eslint-enable max-lines */
329
-
330
-
331
288
  exports.normalizeModuleConfig = normalizeModuleConfig;