@modern-js/module-tools 1.5.8 → 1.6.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 (116) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/js/modern/cli/build.js +5 -4
  3. package/dist/js/modern/commands/build.js +55 -28
  4. package/dist/js/modern/features/build/bundle/index.js +9 -0
  5. package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
  6. package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
  7. package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -56
  8. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -71
  9. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +10 -10
  10. package/dist/js/modern/features/build/bundleless/index.js +23 -0
  11. package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
  12. package/dist/js/modern/features/build/bundleless/style.js +266 -0
  13. package/dist/js/modern/features/build/constants.js +94 -59
  14. package/dist/js/modern/features/build/error.js +150 -0
  15. package/dist/js/modern/features/build/index.js +87 -18
  16. package/dist/js/modern/features/build/legacy-constants.js +99 -0
  17. package/dist/js/modern/features/build/normalize.js +301 -0
  18. package/dist/js/modern/features/build/types.js +0 -0
  19. package/dist/js/modern/features/build/utils.js +39 -136
  20. package/dist/js/modern/index.js +3 -1
  21. package/dist/js/modern/locale/en.js +5 -3
  22. package/dist/js/modern/locale/zh.js +5 -3
  23. package/dist/js/modern/schema/build-config.js +111 -0
  24. package/dist/js/modern/schema/index.js +2 -1
  25. package/dist/js/modern/schema/output.js +18 -9
  26. package/dist/js/modern/schema/source.js +2 -10
  27. package/dist/js/modern/schema/tools.js +6 -0
  28. package/dist/js/modern/schema/types.js +0 -0
  29. package/dist/js/modern/utils/babel.js +4 -1
  30. package/dist/js/modern/utils/constants.js +3 -0
  31. package/dist/js/modern/utils/copy.js +2 -2
  32. package/dist/js/node/cli/build.js +5 -4
  33. package/dist/js/node/commands/build.js +62 -29
  34. package/dist/js/node/features/build/bundle/index.js +23 -0
  35. package/dist/js/node/features/build/bundle/runRollup.js +174 -0
  36. package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
  37. package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -56
  38. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +58 -73
  39. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
  40. package/dist/js/node/features/build/bundleless/index.js +40 -0
  41. package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
  42. package/dist/js/node/features/build/bundleless/style.js +299 -0
  43. package/dist/js/node/features/build/constants.js +115 -67
  44. package/dist/js/node/features/build/error.js +175 -0
  45. package/dist/js/node/features/build/index.js +104 -18
  46. package/dist/js/node/features/build/legacy-constants.js +107 -0
  47. package/dist/js/node/features/build/normalize.js +330 -0
  48. package/dist/js/node/features/build/types.js +0 -0
  49. package/dist/js/node/features/build/utils.js +48 -145
  50. package/dist/js/node/index.js +20 -1
  51. package/dist/js/node/locale/en.js +5 -3
  52. package/dist/js/node/locale/zh.js +5 -3
  53. package/dist/js/node/schema/build-config.js +120 -0
  54. package/dist/js/node/schema/index.js +3 -1
  55. package/dist/js/node/schema/output.js +20 -9
  56. package/dist/js/node/schema/source.js +2 -10
  57. package/dist/js/node/schema/tools.js +13 -0
  58. package/dist/js/node/schema/types.js +0 -0
  59. package/dist/js/node/utils/babel.js +4 -1
  60. package/dist/js/node/utils/constants.js +11 -0
  61. package/dist/js/node/utils/copy.js +1 -1
  62. package/dist/types/cli/build.d.ts +1 -1
  63. package/dist/types/commands/build.d.ts +12 -12
  64. package/dist/types/features/build/bundle/index.d.ts +3 -0
  65. package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
  66. package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
  67. package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
  68. package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
  69. package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
  70. package/dist/types/features/build/bundleless/index.d.ts +4 -0
  71. package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
  72. package/dist/types/features/build/bundleless/style.d.ts +25 -0
  73. package/dist/types/features/build/constants.d.ts +17 -13
  74. package/dist/types/features/build/error.d.ts +33 -0
  75. package/dist/types/features/build/index.d.ts +12 -3
  76. package/dist/types/features/build/legacy-constants.d.ts +8 -0
  77. package/dist/types/features/build/normalize.d.ts +19 -0
  78. package/dist/types/features/build/types.d.ts +15 -0
  79. package/dist/types/features/build/utils.d.ts +10 -31
  80. package/dist/types/index.d.ts +1 -0
  81. package/dist/types/locale/en.d.ts +2 -0
  82. package/dist/types/locale/index.d.ts +4 -0
  83. package/dist/types/locale/zh.d.ts +2 -0
  84. package/dist/types/schema/build-config.d.ts +197 -0
  85. package/dist/types/schema/index.d.ts +184 -18
  86. package/dist/types/schema/output.d.ts +188 -10
  87. package/dist/types/schema/source.d.ts +2 -11
  88. package/dist/types/schema/tools.d.ts +6 -0
  89. package/dist/types/schema/types.d.ts +46 -0
  90. package/dist/types/types.d.ts +29 -28
  91. package/dist/types/utils/babel.d.ts +3 -2
  92. package/dist/types/utils/constants.d.ts +2 -0
  93. package/package.json +23 -9
  94. package/dist/js/modern/features/build/build-watch.js +0 -101
  95. package/dist/js/modern/features/build/build.js +0 -123
  96. package/dist/js/modern/tasks/build-source-code.js +0 -208
  97. package/dist/js/modern/tasks/build-style.js +0 -169
  98. package/dist/js/modern/tasks/build-watch-source-code.js +0 -162
  99. package/dist/js/modern/tasks/build-watch-style.js +0 -216
  100. package/dist/js/modern/tasks/constants.js +0 -1
  101. package/dist/js/node/features/build/build-watch.js +0 -121
  102. package/dist/js/node/features/build/build.js +0 -143
  103. package/dist/js/node/tasks/build-source-code.js +0 -234
  104. package/dist/js/node/tasks/build-style.js +0 -184
  105. package/dist/js/node/tasks/build-watch-source-code.js +0 -174
  106. package/dist/js/node/tasks/build-watch-style.js +0 -233
  107. package/dist/js/node/tasks/constants.js +0 -8
  108. package/dist/types/features/build/build-watch.d.ts +0 -3
  109. package/dist/types/features/build/build.d.ts +0 -3
  110. package/dist/types/tasks/build-source-code.d.ts +0 -25
  111. package/dist/types/tasks/build-style.d.ts +0 -1
  112. package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
  113. package/dist/types/tasks/build-watch-style.d.ts +0 -1
  114. package/dist/types/tasks/constants.d.ts +0 -1
  115. package/dist/types/tasks/copy-assets.d.ts +0 -1
  116. package/dist/types/tasks/generator-dts/index.d.ts +0 -1
@@ -3,33 +3,37 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.build = void 0;
6
+ exports.runBuild = exports.checkPlatformAndRunBuild = exports.buildInNormalMode = exports.build = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
10
10
  var _utils = require("@modern-js/utils");
11
11
 
12
+ var _pMap = _interopRequireDefault(require("p-map"));
13
+
14
+ var _readline = require("../../utils/readline");
15
+
16
+ var _normalize = require("./normalize");
17
+
18
+ var _constants = require("./constants");
19
+
20
+ var _error = require("./error");
21
+
22
+ var _utils2 = require("./utils");
23
+
12
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
25
 
14
- const buildFeature = _utils.Import.lazy('./build', require);
26
+ const bundle = _utils.Import.lazy('./bundle', require);
15
27
 
16
- const buildWatchFeature = _utils.Import.lazy('./build-watch', require);
28
+ const bundleless = _utils.Import.lazy('./bundleless', require);
17
29
 
18
30
  const bp = _utils.Import.lazy('./build-platform', require);
19
31
 
20
- const build = async (api, config, modernConfig) => {
32
+ const checkPlatformAndRunBuild = async (platform, options) => {
21
33
  const {
22
- appDirectory,
23
- enableWatchMode,
24
- platform,
25
- clear = true,
34
+ api,
26
35
  isTsProject
27
- } = config;
28
- const {
29
- output: {
30
- path: outputPath = 'dist'
31
- }
32
- } = modernConfig; // TODO: maybe need watch mode in build platform
36
+ } = options;
33
37
 
34
38
  if (typeof platform === 'boolean' && platform) {
35
39
  if (process.env.RUN_PLATFORM) {
@@ -39,7 +43,9 @@ const build = async (api, config, modernConfig) => {
39
43
  });
40
44
  }
41
45
 
42
- return;
46
+ return {
47
+ exit: true
48
+ };
43
49
  }
44
50
 
45
51
  if (typeof platform === 'string') {
@@ -50,6 +56,77 @@ const build = async (api, config, modernConfig) => {
50
56
  });
51
57
  }
52
58
 
59
+ return {
60
+ exit: true
61
+ };
62
+ }
63
+
64
+ return {
65
+ exit: false
66
+ };
67
+ };
68
+
69
+ exports.checkPlatformAndRunBuild = checkPlatformAndRunBuild;
70
+
71
+ const runBuild = async (api, normalizedModuleConfig, config) => {
72
+ await (0, _pMap.default)(normalizedModuleConfig, async moduleConfig => {
73
+ if (moduleConfig.buildType === 'bundle') {
74
+ await bundle.build(api, moduleConfig);
75
+ } else {
76
+ await bundleless.build(api, moduleConfig, config);
77
+ }
78
+ });
79
+ };
80
+
81
+ exports.runBuild = runBuild;
82
+
83
+ const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
84
+ console.info(_utils.chalk.blue.bold(_constants.buildingText));
85
+
86
+ try {
87
+ // eslint-disable-next-line no-console
88
+ console.time(_constants.buildSuccessText);
89
+ await runBuild(api, normalizedModuleConfig, config);
90
+
91
+ _readline.ReadlineUtils.clearPrevLine(process.stdout); // eslint-disable-next-line no-console
92
+
93
+
94
+ console.timeEnd(_constants.buildSuccessText);
95
+ } catch (e) {
96
+ _readline.ReadlineUtils.clearPrevLine(process.stdout);
97
+
98
+ if ((0, _error.isInternalError)(e)) {
99
+ throw new _error.ModuleBuildError(e);
100
+ } else {
101
+ throw e;
102
+ }
103
+ }
104
+ };
105
+
106
+ exports.buildInNormalMode = buildInNormalMode;
107
+
108
+ const build = async (api, config) => {
109
+ const {
110
+ platform,
111
+ clear = true,
112
+ isTsProject
113
+ } = config;
114
+ const {
115
+ appDirectory
116
+ } = api.useAppContext();
117
+ const modernConfig = api.useResolvedConfigContext();
118
+ const {
119
+ output: {
120
+ path: outputPath = 'dist'
121
+ }
122
+ } = modernConfig; // build platform
123
+
124
+ const platformBuildRet = await checkPlatformAndRunBuild(platform, {
125
+ api,
126
+ isTsProject
127
+ });
128
+
129
+ if (platformBuildRet.exit) {
53
130
  return;
54
131
  }
55
132
 
@@ -57,10 +134,19 @@ const build = async (api, config, modernConfig) => {
57
134
  _utils.fs.removeSync(_path.default.join(appDirectory, outputPath));
58
135
  }
59
136
 
60
- if (enableWatchMode) {
61
- await buildWatchFeature.buildInWatchMode(api, config, modernConfig);
137
+ const deps = (0, _utils2.getAllDeps)(appDirectory); // should normalize module tool config here, ensure the same config for build
138
+
139
+ const normalizedModuleConfig = (0, _normalize.normalizeModuleConfig)({
140
+ buildFeatOption: config,
141
+ api,
142
+ deps
143
+ });
144
+
145
+ if (config.enableWatchMode) {
146
+ console.info(_utils.chalk.blue.underline('start build in watch mode...\n'));
147
+ await runBuild(api, normalizedModuleConfig, config);
62
148
  } else {
63
- await buildFeature.buildSourceCode(api, config, modernConfig);
149
+ await buildInNormalMode(api, normalizedModuleConfig, config);
64
150
  }
65
151
  };
66
152
 
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PACKAGE_MODES = exports.DEFAULT_PACKAGE_MODE = void 0;
7
+ // Universal JS 的默认选择,三份构建产物,支持 Node.js,对现代浏览器有优化
8
+ const universalJs = [{
9
+ format: 'esm',
10
+ target: 'es5',
11
+ outputPath: './js/treeshaking',
12
+ bundlelessOptions: {
13
+ style: {
14
+ compileMode: 'only-source-code'
15
+ }
16
+ }
17
+ }, {
18
+ format: 'cjs',
19
+ target: 'es6',
20
+ outputPath: './js/node'
21
+ }, {
22
+ format: 'esm',
23
+ target: 'es6',
24
+ outputPath: './js/modern'
25
+ }]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
26
+
27
+ const universalJsLite = [{
28
+ format: 'esm',
29
+ target: 'es5',
30
+ outputPath: './js/treeshaking',
31
+ bundlelessOptions: {
32
+ style: {
33
+ compileMode: 'only-source-code'
34
+ }
35
+ }
36
+ }, {
37
+ format: 'cjs',
38
+ target: 'es6',
39
+ outputPath: './js/node'
40
+ }, {
41
+ format: 'esm',
42
+ target: 'es5',
43
+ outputPath: './js/modern'
44
+ }]; // 纯前端代码的默认选择,两份构建产物
45
+
46
+ const browserJs = [{
47
+ format: 'esm',
48
+ target: 'es5',
49
+ outputPath: './js/treeshaking',
50
+ bundlelessOptions: {
51
+ style: {
52
+ compileMode: 'only-source-code'
53
+ }
54
+ }
55
+ }, {
56
+ format: 'esm',
57
+ target: 'es6',
58
+ outputPath: './js/node'
59
+ }, {
60
+ format: 'esm',
61
+ target: 'es6',
62
+ outputPath: './js/modern'
63
+ }]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
64
+
65
+ const browserJsLite = [{
66
+ format: 'esm',
67
+ target: 'es5',
68
+ outputPath: './js/treeshaking',
69
+ bundlelessOptions: {
70
+ style: {
71
+ compileMode: 'only-source-code'
72
+ }
73
+ }
74
+ }, {
75
+ format: 'esm',
76
+ target: 'es5',
77
+ outputPath: './js/node'
78
+ }, {
79
+ format: 'esm',
80
+ target: 'es5',
81
+ outputPath: './js/modern'
82
+ }]; // 纯 Node.js 代码的默认选择,两份构建产物
83
+
84
+ const nodeJs = [{
85
+ format: 'cjs',
86
+ target: 'es6',
87
+ outputPath: './js/node',
88
+ bundlelessOptions: {
89
+ style: {
90
+ compileMode: 'only-source-code'
91
+ }
92
+ }
93
+ }, {
94
+ format: 'esm',
95
+ target: 'es6',
96
+ outputPath: './js/modern'
97
+ }];
98
+ const DEFAULT_PACKAGE_MODE = 'universal-js';
99
+ exports.DEFAULT_PACKAGE_MODE = DEFAULT_PACKAGE_MODE;
100
+ const PACKAGE_MODES = {
101
+ 'universal-js': universalJs,
102
+ 'universal-js-lite': universalJsLite,
103
+ 'browser-js': browserJs,
104
+ 'browser-js-lite': browserJsLite,
105
+ 'node-js': nodeJs
106
+ };
107
+ exports.PACKAGE_MODES = PACKAGE_MODES;
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeModuleConfig = exports.normalizeBuildConfig = exports.getSourceMap = exports.getNormalizeModuleConfigByPackageModeAndFileds = exports.getFinalTsconfig = exports.getFinalDts = void 0;
7
+
8
+ var _utils = require("@modern-js/utils");
9
+
10
+ var _lodash = require("@modern-js/utils/lodash");
11
+
12
+ var _constants = require("../../utils/constants");
13
+
14
+ 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
+ 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
+ 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
+ const constants = _utils.Import.lazy('./constants', require);
21
+
22
+ const legacyConstants = _utils.Import.lazy('./legacy-constants', require);
23
+
24
+ const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOption) => {
25
+ const {
26
+ output: {
27
+ packageMode,
28
+ packageFields,
29
+ disableTsChecker,
30
+ importStyle
31
+ }
32
+ } = api.useResolvedConfigContext();
33
+ let configs = [];
34
+
35
+ if (buildFeatOption.styleOnly) {
36
+ configs.push({
37
+ buildType: 'bundleless',
38
+ outputPath: './js/styles',
39
+ bundlelessOptions: {
40
+ sourceDir: './src',
41
+ style: {
42
+ compileMode: importStyle === 'source-code' ? 'only-source-code' : 'all'
43
+ }
44
+ }
45
+ });
46
+ configs.push({
47
+ buildType: 'bundleless',
48
+ outputPath: './styles',
49
+ bundlelessOptions: {
50
+ sourceDir: './styles',
51
+ style: {
52
+ compileMode: 'only-compiled-code'
53
+ }
54
+ }
55
+ });
56
+ return configs;
57
+ }
58
+
59
+ const commonConfig = {
60
+ buildType: 'bundleless',
61
+ bundlelessOptions: {
62
+ sourceDir: './src',
63
+ style: {
64
+ path: '../styles',
65
+ compileMode: false
66
+ },
67
+ static: {
68
+ path: '../styles'
69
+ }
70
+ },
71
+ outputPath: './'
72
+ };
73
+ commonConfig.tsconfig = getFinalTsconfig(commonConfig, buildFeatOption);
74
+
75
+ if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
76
+ const buildConfigs = legacyConstants.PACKAGE_MODES[packageMode || legacyConstants.DEFAULT_PACKAGE_MODE];
77
+ configs = buildConfigs.map(config => _utils.lodash.mergeWith({}, commonConfig, config));
78
+ } else {
79
+ const getConfigsByJsSyntaxType = (js, outputPath) => {
80
+ if (js === 'CJS+ES6') {
81
+ return _utils.lodash.mergeWith({}, commonConfig, {
82
+ format: 'cjs',
83
+ target: 'es6',
84
+ outputPath
85
+ });
86
+ } else if (js === 'ESM+ES5') {
87
+ return _utils.lodash.mergeWith({}, commonConfig, {
88
+ format: 'esm',
89
+ target: 'es5',
90
+ outputPath
91
+ });
92
+ }
93
+
94
+ return _utils.lodash.mergeWith({}, commonConfig, {
95
+ format: 'esm',
96
+ target: 'es6',
97
+ outputPath
98
+ });
99
+ };
100
+
101
+ if (!packageFields['jsnext:modern'] && !packageFields.main && !packageFields.module) {
102
+ 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,
104
+ // and can also be used on package.json exports field.
105
+
106
+
107
+ if (packageFields['jsnext:modern']) {
108
+ configs.push(getConfigsByJsSyntaxType(packageFields['jsnext:modern'], 'js/modern'));
109
+ }
110
+
111
+ if (packageFields.main) {
112
+ configs.push(getConfigsByJsSyntaxType(packageFields.main, 'js/node'));
113
+ }
114
+
115
+ if (packageFields.module) {
116
+ configs.push(getConfigsByJsSyntaxType(packageFields.module, 'js/treeshaking'));
117
+ }
118
+ }
119
+
120
+ if (configs.length > 0) {
121
+ const firstConfig = configs[0];
122
+ firstConfig.bundlelessOptions = _utils.lodash.mergeWith({}, firstConfig.bundlelessOptions, {
123
+ style: {
124
+ compileMode: importStyle === 'source-code' ? 'only-source-code' : 'all'
125
+ }
126
+ });
127
+ } // [compatibe mode]: dts gen
128
+
129
+
130
+ if (buildFeatOption.legacyTsc && !disableTsChecker) {
131
+ configs.push({
132
+ buildType: 'bundleless',
133
+ outputPath: './types',
134
+ enableDts: true,
135
+ dtsOnly: true
136
+ });
137
+ }
138
+
139
+ configs.push({
140
+ buildType: 'bundleless',
141
+ outputPath: './styles',
142
+ bundlelessOptions: {
143
+ sourceDir: './styles',
144
+ style: {
145
+ compileMode: 'only-compiled-code'
146
+ }
147
+ }
148
+ });
149
+ return configs;
150
+ };
151
+
152
+ exports.getNormalizeModuleConfigByPackageModeAndFileds = getNormalizeModuleConfigByPackageModeAndFileds;
153
+
154
+ const getFinalTsconfig = (config, buildFeatOption) => {
155
+ var _config$tsconfig;
156
+
157
+ // cli tsconfig option > buildPreset tsconfig option
158
+ // Since tsconfig configuration has default values,
159
+ // compare the two to see if the user is configured with cli tsconfig
160
+ if (buildFeatOption.tsconfigName !== _constants.cliTsConfigDefaultValue) {
161
+ return buildFeatOption.tsconfigName;
162
+ }
163
+
164
+ return (_config$tsconfig = config.tsconfig) !== null && _config$tsconfig !== void 0 ? _config$tsconfig : './tsconfig.json';
165
+ };
166
+
167
+ exports.getFinalTsconfig = getFinalTsconfig;
168
+
169
+ const getFinalDts = (config, buildFeatOption) => {
170
+ var _config$enableDts;
171
+
172
+ // is js project, should return false
173
+ if (!buildFeatOption.isTsProject) {
174
+ return false;
175
+ } // when `build --dts`, then all build tasks`s enableDts is true
176
+
177
+
178
+ if (buildFeatOption.enableDtsGen) {
179
+ return true;
180
+ }
181
+
182
+ return (_config$enableDts = config.enableDts) !== null && _config$enableDts !== void 0 ? _config$enableDts : false;
183
+ };
184
+
185
+ exports.getFinalDts = getFinalDts;
186
+
187
+ const getSourceMap = (config, buildType, api) => {
188
+ // TODO: remove
189
+ const {
190
+ output: {
191
+ disableSourceMap
192
+ }
193
+ } = api.useResolvedConfigContext();
194
+
195
+ if (disableSourceMap) {
196
+ return false;
197
+ }
198
+
199
+ if (config.sourceMap !== undefined) {
200
+ return config.sourceMap;
201
+ }
202
+
203
+ return buildType === 'bundle';
204
+ };
205
+
206
+ exports.getSourceMap = getSourceMap;
207
+
208
+ const normalizeBuildConfig = (context, buildConfig, deps = []) => {
209
+ const {
210
+ buildFeatOption,
211
+ api
212
+ } = context;
213
+ const configArray = Array.isArray(buildConfig) ? buildConfig : [buildConfig];
214
+ const normalizedModule = configArray.map(config => {
215
+ var _config$format, _config$target, _bundleOptions$skipDe, _bundleOptions$minify, _bundleOptions$splitt, _config$outputPath, _config$dtsOnly;
216
+
217
+ const format = (_config$format = config.format) !== null && _config$format !== void 0 ? _config$format : 'cjs';
218
+ const target = (_config$target = config.target) !== null && _config$target !== void 0 ? _config$target : 'esnext';
219
+ const {
220
+ bundleOptions
221
+ } = config;
222
+ const skipDeps = (_bundleOptions$skipDe = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.skipDeps) !== null && _bundleOptions$skipDe !== void 0 ? _bundleOptions$skipDe : true;
223
+ 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) || [])];
224
+
225
+ const normalizedBundleOption = _objectSpread(_objectSpread({}, bundleOptions), {}, {
226
+ entry: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.entry) || {
227
+ index: `src/index.${buildFeatOption.isTsProject ? 'ts' : 'js'}`
228
+ },
229
+ platform: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.platform) || 'node',
230
+ minify: (_bundleOptions$minify = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.minify) !== null && _bundleOptions$minify !== void 0 ? _bundleOptions$minify : false,
231
+ externals,
232
+ splitting: (_bundleOptions$splitt = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.splitting) !== null && _bundleOptions$splitt !== void 0 ? _bundleOptions$splitt : false,
233
+ skipDeps
234
+ });
235
+
236
+ const normalizedBundlelessOptions = (0, _lodash.mergeWith)({}, {
237
+ sourceDir: './src',
238
+ style: {
239
+ compileMode: 'all',
240
+ path: './'
241
+ },
242
+ static: {
243
+ path: './'
244
+ }
245
+ }, config.bundlelessOptions);
246
+ const watch = buildFeatOption.enableWatchMode || false;
247
+ const tsconfig = getFinalTsconfig(config, buildFeatOption);
248
+ const enableDts = getFinalDts(config, buildFeatOption);
249
+ const outputPath = (_config$outputPath = config.outputPath) !== null && _config$outputPath !== void 0 ? _config$outputPath : './';
250
+ const sourceMap = getSourceMap(config, config.buildType, api);
251
+ const dtsOnly = (_config$dtsOnly = config.dtsOnly) !== null && _config$dtsOnly !== void 0 ? _config$dtsOnly : false;
252
+ const commmonConfig = {
253
+ format,
254
+ target,
255
+ watch,
256
+ tsconfig,
257
+ enableDts,
258
+ outputPath,
259
+ dtsOnly,
260
+ sourceMap
261
+ };
262
+
263
+ if (!buildFeatOption.isTsProject && (dtsOnly || enableDts)) {
264
+ console.warn('[WARN] dtsOnly、enableDts 配置仅在 Ts 项目下生效');
265
+ } else if (buildFeatOption.isTsProject && dtsOnly && !enableDts) {
266
+ console.warn('[WARN] dtsOnly 配置仅在 enableDts 为 true 的时候生效. 请检查当前的 dtsOnly、enableDts 是否配置正确');
267
+ }
268
+
269
+ if (config.buildType === 'bundle') {
270
+ return _objectSpread(_objectSpread({}, commmonConfig), {}, {
271
+ buildType: 'bundle',
272
+ bundleOptions: normalizedBundleOption
273
+ });
274
+ } else {
275
+ return _objectSpread(_objectSpread({}, commmonConfig), {}, {
276
+ buildType: 'bundleless',
277
+ bundlelessOptions: normalizedBundlelessOptions
278
+ });
279
+ }
280
+ });
281
+ return normalizedModule;
282
+ };
283
+
284
+ exports.normalizeBuildConfig = normalizeBuildConfig;
285
+
286
+ const normalizeModuleConfig = context => {
287
+ const {
288
+ buildFeatOption,
289
+ api,
290
+ deps
291
+ } = context;
292
+ const {
293
+ output: {
294
+ buildConfig,
295
+ buildPreset
296
+ }
297
+ } = api.useResolvedConfigContext(); // buildConfig is the most important.
298
+
299
+ if (buildConfig) {
300
+ return normalizeBuildConfig(context, buildConfig, deps);
301
+ } // buildPreset is the second important. It can be used when buildConfig is not defined.
302
+ // buildPreset -> buildConfig
303
+
304
+
305
+ if (buildPreset) {
306
+ const {
307
+ unPresetConfigs,
308
+ unPresetWithTargetConfigs
309
+ } = constants;
310
+
311
+ if (unPresetConfigs[buildPreset]) {
312
+ return normalizeBuildConfig(context, unPresetConfigs[buildPreset], deps);
313
+ } else if (unPresetWithTargetConfigs[buildPreset]) {
314
+ return normalizeBuildConfig(context, unPresetWithTargetConfigs[buildPreset], deps);
315
+ } // If the buildPreset is not found, then it is used 'npm-library'
316
+ // TODO: Warning: The buildPreset 'npm-library' is not supported.
317
+
318
+
319
+ return normalizeBuildConfig(context, unPresetConfigs['npm-library'], deps);
320
+ } // If the user does not configure buildConfig and buildPreset,
321
+ // the configuration is generated based on packageMode and packageField
322
+
323
+
324
+ const legacyBuildConfig = getNormalizeModuleConfigByPackageModeAndFileds(api, buildFeatOption);
325
+ return normalizeBuildConfig(context, legacyBuildConfig, deps);
326
+ };
327
+ /* eslint-enable max-lines */
328
+
329
+
330
+ exports.normalizeModuleConfig = normalizeModuleConfig;
File without changes