@modern-js/module-tools 1.5.7 → 1.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +40 -27
- package/dist/js/modern/features/build/bundle/index.js +6 -0
- package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
- package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
- package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -55
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/modern/features/build/bundleless/index.js +13 -0
- package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
- package/dist/js/modern/features/build/bundleless/style.js +266 -0
- package/dist/js/modern/features/build/constants.js +94 -59
- package/dist/js/modern/features/build/error.js +150 -0
- package/dist/js/modern/features/build/index.js +84 -19
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +293 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +29 -137
- package/dist/js/modern/index.js +3 -1
- package/dist/js/modern/locale/en.js +5 -3
- package/dist/js/modern/locale/zh.js +5 -3
- package/dist/js/modern/schema/build-config.js +104 -0
- package/dist/js/modern/schema/index.js +2 -1
- package/dist/js/modern/schema/output.js +18 -9
- package/dist/js/modern/schema/source.js +2 -10
- package/dist/js/modern/schema/tools.js +6 -0
- package/dist/js/modern/schema/types.js +0 -0
- package/dist/js/modern/utils/babel.js +4 -1
- package/dist/js/modern/utils/constants.js +3 -0
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +50 -29
- package/dist/js/node/features/build/bundle/index.js +17 -0
- package/dist/js/node/features/build/bundle/runRollup.js +174 -0
- package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
- package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/node/features/build/bundleless/index.js +26 -0
- package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
- package/dist/js/node/features/build/bundleless/style.js +299 -0
- package/dist/js/node/features/build/constants.js +115 -67
- package/dist/js/node/features/build/error.js +175 -0
- package/dist/js/node/features/build/index.js +92 -19
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +322 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +31 -145
- package/dist/js/node/index.js +5 -1
- package/dist/js/node/locale/en.js +5 -3
- package/dist/js/node/locale/zh.js +5 -3
- package/dist/js/node/schema/build-config.js +113 -0
- package/dist/js/node/schema/index.js +3 -1
- package/dist/js/node/schema/output.js +20 -9
- package/dist/js/node/schema/source.js +2 -10
- package/dist/js/node/schema/tools.js +13 -0
- package/dist/js/node/schema/types.js +0 -0
- package/dist/js/node/utils/babel.js +4 -1
- package/dist/js/node/utils/constants.js +11 -0
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/cli/new.d.ts +1 -1
- package/dist/types/commands/build.d.ts +12 -12
- package/dist/types/features/build/bundle/index.d.ts +3 -0
- package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
- package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
- package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
- package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
- package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
- package/dist/types/features/build/bundleless/index.d.ts +4 -0
- package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
- package/dist/types/features/build/bundleless/style.d.ts +25 -0
- package/dist/types/features/build/constants.d.ts +17 -13
- package/dist/types/features/build/error.d.ts +33 -0
- package/dist/types/features/build/index.d.ts +4 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
- package/dist/types/features/build/normalize.d.ts +18 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +9 -31
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/schema/build-config.d.ts +179 -0
- package/dist/types/schema/index.d.ts +166 -18
- package/dist/types/schema/output.d.ts +170 -10
- package/dist/types/schema/source.d.ts +2 -11
- package/dist/types/schema/tools.d.ts +6 -0
- package/dist/types/schema/types.d.ts +45 -0
- package/dist/types/types.d.ts +29 -28
- package/dist/types/utils/babel.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +2 -0
- package/dist/types/utils/logger.d.ts +2 -0
- package/package.json +28 -15
- package/dist/js/modern/features/build/build-watch.js +0 -101
- package/dist/js/modern/features/build/build.js +0 -123
- package/dist/js/modern/tasks/build-source-code.js +0 -207
- package/dist/js/modern/tasks/build-style.js +0 -168
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
- package/dist/js/modern/tasks/build-watch-style.js +0 -215
- package/dist/js/modern/tasks/constants.js +0 -1
- package/dist/js/node/features/build/build-watch.js +0 -121
- package/dist/js/node/features/build/build.js +0 -143
- package/dist/js/node/tasks/build-source-code.js +0 -233
- package/dist/js/node/tasks/build-style.js +0 -183
- package/dist/js/node/tasks/build-watch-source-code.js +0 -173
- package/dist/js/node/tasks/build-watch-style.js +0 -232
- package/dist/js/node/tasks/constants.js +0 -8
- package/dist/types/features/build/build-watch.d.ts +0 -3
- package/dist/types/features/build/build.d.ts +0 -3
- package/dist/types/tasks/build-source-code.d.ts +0 -25
- package/dist/types/tasks/build-style.d.ts +0 -1
- package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
- package/dist/types/tasks/build-watch-style.d.ts +0 -1
- package/dist/types/tasks/constants.d.ts +0 -1
- package/dist/types/tasks/copy-assets.d.ts +0 -1
- package/dist/types/tasks/generator-dts/index.d.ts +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
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'], 'modern'));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (packageFields.main) {
|
|
112
|
+
configs.push(getConfigsByJsSyntaxType(packageFields.main, 'node'));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (packageFields.module) {
|
|
116
|
+
configs.push(getConfigsByJsSyntaxType(packageFields.module, '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) => {
|
|
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$minify, _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
|
+
|
|
223
|
+
const normalizedBundleOption = _objectSpread(_objectSpread({}, bundleOptions), {}, {
|
|
224
|
+
entry: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.entry) || {
|
|
225
|
+
index: `src/index.${buildFeatOption.isTsProject ? 'ts' : 'js'}`
|
|
226
|
+
},
|
|
227
|
+
platform: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.platform) || 'node',
|
|
228
|
+
minify: (_bundleOptions$minify = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.minify) !== null && _bundleOptions$minify !== void 0 ? _bundleOptions$minify : false
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const normalizedBundlelessOptions = (0, _lodash.mergeWith)({}, {
|
|
232
|
+
sourceDir: './src',
|
|
233
|
+
style: {
|
|
234
|
+
compileMode: 'all',
|
|
235
|
+
path: './'
|
|
236
|
+
},
|
|
237
|
+
static: {
|
|
238
|
+
path: './'
|
|
239
|
+
}
|
|
240
|
+
}, config.bundlelessOptions);
|
|
241
|
+
const watch = buildFeatOption.enableWatchMode || false;
|
|
242
|
+
const tsconfig = getFinalTsconfig(config, buildFeatOption);
|
|
243
|
+
const enableDts = getFinalDts(config, buildFeatOption);
|
|
244
|
+
const outputPath = (_config$outputPath = config.outputPath) !== null && _config$outputPath !== void 0 ? _config$outputPath : './';
|
|
245
|
+
const sourceMap = getSourceMap(config, config.buildType, api);
|
|
246
|
+
const dtsOnly = (_config$dtsOnly = config.dtsOnly) !== null && _config$dtsOnly !== void 0 ? _config$dtsOnly : false;
|
|
247
|
+
const commmonConfig = {
|
|
248
|
+
format,
|
|
249
|
+
target,
|
|
250
|
+
watch,
|
|
251
|
+
tsconfig,
|
|
252
|
+
enableDts,
|
|
253
|
+
outputPath,
|
|
254
|
+
dtsOnly,
|
|
255
|
+
sourceMap
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
if (!buildFeatOption.isTsProject && (dtsOnly || enableDts)) {
|
|
259
|
+
console.warn('[WARN] dtsOnly、enableDts 配置仅在 Ts 项目下生效');
|
|
260
|
+
} else if (buildFeatOption.isTsProject && dtsOnly && !enableDts) {
|
|
261
|
+
console.warn('[WARN] dtsOnly 配置仅在 enableDts 为 true 的时候生效. 请检查当前的 dtsOnly、enableDts 是否配置正确');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (config.buildType === 'bundle') {
|
|
265
|
+
return _objectSpread(_objectSpread({}, commmonConfig), {}, {
|
|
266
|
+
buildType: 'bundle',
|
|
267
|
+
bundleOptions: normalizedBundleOption
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
return _objectSpread(_objectSpread({}, commmonConfig), {}, {
|
|
271
|
+
buildType: 'bundleless',
|
|
272
|
+
bundlelessOptions: normalizedBundlelessOptions
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
return normalizedModule;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
exports.normalizeBuildConfig = normalizeBuildConfig;
|
|
280
|
+
|
|
281
|
+
const normalizeModuleConfig = context => {
|
|
282
|
+
const {
|
|
283
|
+
buildFeatOption,
|
|
284
|
+
api
|
|
285
|
+
} = context;
|
|
286
|
+
const {
|
|
287
|
+
output: {
|
|
288
|
+
buildConfig,
|
|
289
|
+
buildPreset
|
|
290
|
+
}
|
|
291
|
+
} = api.useResolvedConfigContext(); // buildConfig is the most important.
|
|
292
|
+
|
|
293
|
+
if (buildConfig) {
|
|
294
|
+
return normalizeBuildConfig(context, buildConfig);
|
|
295
|
+
} // buildPreset is the second important. It can be used when buildConfig is not defined.
|
|
296
|
+
// buildPreset -> buildConfig
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
if (buildPreset) {
|
|
300
|
+
const {
|
|
301
|
+
unPresetConfigs,
|
|
302
|
+
unPresetWithTargetConfigs
|
|
303
|
+
} = constants;
|
|
304
|
+
|
|
305
|
+
if (unPresetConfigs[buildPreset]) {
|
|
306
|
+
return normalizeBuildConfig(context, unPresetConfigs[buildPreset]);
|
|
307
|
+
} else if (unPresetWithTargetConfigs[buildPreset]) {
|
|
308
|
+
return normalizeBuildConfig(context, unPresetWithTargetConfigs[buildPreset]);
|
|
309
|
+
} // If the buildPreset is not found, then it is used 'npm-library'
|
|
310
|
+
// TODO: Warning: The buildPreset 'npm-library' is not supported.
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
return normalizeBuildConfig(context, unPresetConfigs['npm-library']);
|
|
314
|
+
} // If the user does not configure buildConfig and buildPreset,
|
|
315
|
+
// the configuration is generated based on packageMode and packageField
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
const legacyBuildConfig = getNormalizeModuleConfigByPackageModeAndFileds(api, buildFeatOption);
|
|
319
|
+
return normalizeBuildConfig(context, legacyBuildConfig);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
exports.normalizeModuleConfig = normalizeModuleConfig;
|
|
File without changes
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var path = _interopRequireWildcard(require("path"));
|
|
6
|
+
exports.watchSectionTitle = exports.logTemplate = exports.getPostcssOption = exports.SectionTitleStatus = exports.LogStack = void 0;
|
|
9
7
|
|
|
10
8
|
var os = _interopRequireWildcard(require("os"));
|
|
11
9
|
|
|
@@ -17,141 +15,14 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
17
15
|
|
|
18
16
|
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
17
|
|
|
20
|
-
const constants = _utils.Import.lazy('./constants', require);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const updateMapper = (packageFieldValue, outDir, mapper) => {
|
|
24
|
-
if (packageFieldValue === 'CJS+ES6') {
|
|
25
|
-
return [...mapper, {
|
|
26
|
-
type: 'commonjs',
|
|
27
|
-
syntax: 'es6+',
|
|
28
|
-
outDir
|
|
29
|
-
}];
|
|
30
|
-
} else if (packageFieldValue === 'ESM+ES5') {
|
|
31
|
-
return [...mapper, {
|
|
32
|
-
type: 'module',
|
|
33
|
-
syntax: 'es5',
|
|
34
|
-
outDir
|
|
35
|
-
}];
|
|
36
|
-
} else if (packageFieldValue === 'ESM+ES6') {
|
|
37
|
-
return [...mapper, {
|
|
38
|
-
type: 'module',
|
|
39
|
-
syntax: 'es6+',
|
|
40
|
-
outDir
|
|
41
|
-
}];
|
|
42
|
-
} else {
|
|
43
|
-
return [...mapper];
|
|
44
|
-
}
|
|
45
|
-
};
|
|
18
|
+
const constants = _utils.Import.lazy('./constants', require);
|
|
46
19
|
|
|
47
|
-
const
|
|
48
|
-
const {
|
|
49
|
-
output: {
|
|
50
|
-
packageFields,
|
|
51
|
-
packageMode
|
|
52
|
-
}
|
|
53
|
-
} = api.useResolvedConfigContext();
|
|
54
|
-
let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
|
|
55
|
-
|
|
56
|
-
if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
|
|
57
|
-
initMapper = constants.PACKAGE_MODES[packageMode || constants.DEFAULT_PACKAGE_MODE];
|
|
58
|
-
} else if (packageFields && Object.keys(packageFields).length > 0) {
|
|
59
|
-
if (packageFields.modern) {
|
|
60
|
-
initMapper = updateMapper(packageFields.modern, 'modern', initMapper);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (packageFields.main) {
|
|
64
|
-
initMapper = updateMapper(packageFields.main, 'node', initMapper);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (packageFields.module) {
|
|
68
|
-
initMapper = updateMapper(packageFields.module, 'treeshaking', initMapper);
|
|
69
|
-
} // TODO: 如果存在其他配置,需要提示
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (!packageFields.modern && !packageFields.main && !packageFields.module) {
|
|
73
|
-
console.error(_utils.chalk.red(`Unrecognized ${JSON.stringify(packageFields)} configuration, please use keys: 'modern, main, jupiter:modern' and use values: 'CJS+ES6, ESM+ES5, ESM+ES6'`)); // eslint-disable-next-line no-process-exit
|
|
74
|
-
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return initMapper;
|
|
80
|
-
}; // 获取执行构建源码的参数
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
exports.getCodeInitMapper = getCodeInitMapper;
|
|
84
|
-
|
|
85
|
-
const getCodeMapper = (api, {
|
|
86
|
-
logger,
|
|
87
|
-
taskPath,
|
|
88
|
-
config,
|
|
89
|
-
initMapper,
|
|
90
|
-
srcRootDir,
|
|
91
|
-
willCompilerDirOrFile
|
|
92
|
-
}) => {
|
|
93
|
-
const {
|
|
94
|
-
appDirectory
|
|
95
|
-
} = api.useAppContext();
|
|
96
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
97
|
-
const {
|
|
98
|
-
output: {
|
|
99
|
-
enableSourceMap,
|
|
100
|
-
jsPath = 'js',
|
|
101
|
-
path: distDir = 'dist'
|
|
102
|
-
}
|
|
103
|
-
} = modernConfig;
|
|
104
|
-
const {
|
|
105
|
-
tsconfigName = 'tsconfig.json'
|
|
106
|
-
} = config;
|
|
107
|
-
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
108
|
-
return initMapper.map(option => {
|
|
109
|
-
var _option$copyDirs;
|
|
110
|
-
|
|
111
|
-
// 不是output.copy配置,而是内部的js copy逻辑
|
|
112
|
-
const copyDirs = (_option$copyDirs = option.copyDirs) === null || _option$copyDirs === void 0 ? void 0 : _option$copyDirs.map(copyDir => path.join(appDirectory, `./${distDir}/${jsPath}/${copyDir}`));
|
|
113
|
-
return {
|
|
114
|
-
logger,
|
|
115
|
-
taskPath,
|
|
116
|
-
params: [`--syntax=${option.syntax}`, `--type=${option.type}`, `--srcRootDir=${srcRootDir}`, `--willCompilerDirOrFile=${willCompilerDirOrFile}`, copyDirs ? `--copyDirs=${copyDirs.join(',')}` : '', `--distDir=${path.join(appDirectory, `./${distDir}/${jsPath}/${option.outDir}`)}`, `--appDirectory=${appDirectory}`, enableSourceMap ? '--sourceMaps' : '', `--tsconfigPath=${tsconfigPath}`]
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
}; // 获取执行生成 d.ts 的参数
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
exports.getCodeMapper = getCodeMapper;
|
|
123
|
-
|
|
124
|
-
const getDtsMapper = (api, config, logger) => {
|
|
125
|
-
const {
|
|
126
|
-
appDirectory
|
|
127
|
-
} = api.useAppContext();
|
|
128
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
129
|
-
const {
|
|
130
|
-
output: {
|
|
131
|
-
disableTsChecker,
|
|
132
|
-
path: outputPath = 'dist'
|
|
133
|
-
}
|
|
134
|
-
} = modernConfig;
|
|
135
|
-
const {
|
|
136
|
-
tsconfigName = 'tsconfig.json',
|
|
137
|
-
enableWatchMode,
|
|
138
|
-
sourceDir
|
|
139
|
-
} = config;
|
|
140
|
-
const srcDir = path.join(appDirectory, './src');
|
|
141
|
-
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
142
|
-
return [{
|
|
143
|
-
logger,
|
|
144
|
-
taskPath: require.resolve("../../tasks/generator-dts"),
|
|
145
|
-
params: [`--srcDir=${srcDir}`, `--distDir=${path.join(appDirectory, `./${outputPath}/types`)}`, `--appDirectory=${appDirectory}`, `--tsconfigPath=${tsconfigPath}`, `--sourceDirName=${sourceDir}`, enableWatchMode ? `--watch` : '', disableTsChecker ? '' : `--tsCheck`]
|
|
146
|
-
}];
|
|
147
|
-
};
|
|
20
|
+
const cssConfig = _utils.Import.lazy('@modern-js/css-config', require);
|
|
148
21
|
/**
|
|
149
22
|
* 处理日志信息
|
|
150
23
|
*/
|
|
151
24
|
|
|
152
25
|
|
|
153
|
-
exports.getDtsMapper = getDtsMapper;
|
|
154
|
-
|
|
155
26
|
class LogStack {
|
|
156
27
|
constructor() {
|
|
157
28
|
_defineProperty(this, "_codeLogStack", void 0);
|
|
@@ -203,24 +74,39 @@ const logTemplate = (title, messageStack, maxLength, {
|
|
|
203
74
|
const template = `${title}:
|
|
204
75
|
${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
205
76
|
return template;
|
|
206
|
-
};
|
|
207
|
-
|
|
77
|
+
};
|
|
208
78
|
|
|
209
79
|
exports.logTemplate = logTemplate;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
80
|
+
let SectionTitleStatus;
|
|
81
|
+
exports.SectionTitleStatus = SectionTitleStatus;
|
|
82
|
+
|
|
83
|
+
(function (SectionTitleStatus) {
|
|
84
|
+
SectionTitleStatus[SectionTitleStatus["Success"] = 0] = "Success";
|
|
85
|
+
SectionTitleStatus[SectionTitleStatus["Fail"] = 1] = "Fail";
|
|
86
|
+
SectionTitleStatus[SectionTitleStatus["Log"] = 2] = "Log";
|
|
87
|
+
})(SectionTitleStatus || (exports.SectionTitleStatus = SectionTitleStatus = {}));
|
|
88
|
+
|
|
89
|
+
const watchSectionTitle = (str, status) => {
|
|
90
|
+
if (status === SectionTitleStatus.Success) {
|
|
91
|
+
return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.green.underline('Successful')}`;
|
|
92
|
+
} else if (status === SectionTitleStatus.Fail) {
|
|
93
|
+
return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.red.underline('Build Failed')}`;
|
|
214
94
|
}
|
|
215
95
|
|
|
216
|
-
|
|
217
|
-
|
|
96
|
+
return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.blue.underline('Log')}`;
|
|
97
|
+
};
|
|
218
98
|
|
|
219
|
-
|
|
220
|
-
}
|
|
99
|
+
exports.watchSectionTitle = watchSectionTitle;
|
|
221
100
|
|
|
222
|
-
|
|
101
|
+
const getPostcssOption = (appDirectory, modernConfig) => {
|
|
102
|
+
var _postcssOption$postcs;
|
|
223
103
|
|
|
224
|
-
|
|
104
|
+
const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
|
|
105
|
+
return {
|
|
106
|
+
plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
|
|
107
|
+
enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
|
|
108
|
+
options: {}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
225
111
|
|
|
226
|
-
|
|
112
|
+
exports.getPostcssOption = getPostcssOption;
|
package/dist/js/node/index.js
CHANGED
|
@@ -17,6 +17,8 @@ var _pluginChangeset = _interopRequireDefault(require("@modern-js/plugin-changes
|
|
|
17
17
|
|
|
18
18
|
var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
|
|
19
19
|
|
|
20
|
+
var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
|
|
21
|
+
|
|
20
22
|
var _hooks = require("./hooks");
|
|
21
23
|
|
|
22
24
|
var _core = require("@modern-js/core");
|
|
@@ -31,11 +33,13 @@ const schema = _utils.Import.lazy('./schema', require);
|
|
|
31
33
|
|
|
32
34
|
const lang = _utils.Import.lazy('./utils/language', require);
|
|
33
35
|
|
|
36
|
+
const isBuildMode = process.argv.slice(2)[0] === 'build';
|
|
37
|
+
|
|
34
38
|
var _default = () => ({
|
|
35
39
|
name: '@modern-js/module-tools',
|
|
36
40
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
|
|
37
41
|
registerHook: _hooks.hooks,
|
|
38
|
-
usePlugins: [(0, _pluginChangeset.default)(), (0, _pluginAnalyze.default)()],
|
|
42
|
+
usePlugins: [(0, _pluginChangeset.default)(), ...(isBuildMode ? [] : [(0, _pluginAnalyze.default)()]), (0, _pluginJarvis.default)()],
|
|
39
43
|
setup: api => {
|
|
40
44
|
const locale = lang.getLocaleLanguage();
|
|
41
45
|
local.i18n.changeLanguage({
|
|
@@ -11,9 +11,11 @@ const EN_LOCALE = {
|
|
|
11
11
|
watch: 'building module in watch mode',
|
|
12
12
|
tsconfig: 'Specify a path to the tsconfig.json file',
|
|
13
13
|
style_only: 'only build style',
|
|
14
|
-
platform: '
|
|
15
|
-
no_tsc: 'close tsc compiler to emit d.ts',
|
|
16
|
-
|
|
14
|
+
platform: 'build the specified task or all tasks, If exist. (tasks: "storybook", "docs")',
|
|
15
|
+
no_tsc: 'close tsc compiler to emit d.ts (Deprecated)',
|
|
16
|
+
dts: 'Turn on dts generation and type checking',
|
|
17
|
+
no_clear: 'disable auto clear dist dir',
|
|
18
|
+
config: 'specify config file'
|
|
17
19
|
},
|
|
18
20
|
dev: {
|
|
19
21
|
describe: 'start dev server'
|
|
@@ -11,9 +11,11 @@ const ZH_LOCALE = {
|
|
|
11
11
|
watch: '使用 Watch 模式构建模块',
|
|
12
12
|
tsconfig: '指定 tsconfig.json 文件的路径',
|
|
13
13
|
style_only: '只构建样式文件',
|
|
14
|
-
platform: '
|
|
15
|
-
no_tsc: '关闭 tsc
|
|
16
|
-
|
|
14
|
+
platform: '如果存在的话,执行指定的构建任务或者全部构建任务. (构建任务包括: "storybook", "文档")',
|
|
15
|
+
no_tsc: '关闭 tsc 编译(废弃)',
|
|
16
|
+
dts: '开启 dts 文件的生成以及类型检查',
|
|
17
|
+
no_clear: '不清理产物目录',
|
|
18
|
+
config: '指定配置文件路径,可以为相对路径或绝对路径'
|
|
17
19
|
},
|
|
18
20
|
dev: {
|
|
19
21
|
describe: '本地开发命令'
|