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