@modern-js/module-tools 1.5.7 → 1.6.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 +48 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +55 -28
- package/dist/js/modern/features/build/bundle/index.js +9 -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 +10 -10
- package/dist/js/modern/features/build/bundleless/index.js +23 -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 +87 -18
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +301 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +39 -136
- package/dist/js/modern/index.js +4 -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 +111 -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/modern/utils/copy.js +2 -2
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +62 -29
- package/dist/js/node/features/build/bundle/index.js +23 -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 +9 -10
- package/dist/js/node/features/build/bundleless/index.js +40 -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 +104 -18
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +330 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +48 -145
- package/dist/js/node/index.js +22 -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 +120 -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/js/node/utils/copy.js +1 -1
- 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 +12 -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 +19 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +10 -31
- package/dist/types/index.d.ts +1 -0
- 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 +197 -0
- package/dist/types/schema/index.d.ts +184 -18
- package/dist/types/schema/output.d.ts +188 -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 +46 -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 -13
- 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,266 @@
|
|
|
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
|
+
import * as path from 'path';
|
|
8
|
+
import { fs, glob, Import, watch as watcher, WatchChangeType, chalk, globby, slash } from '@modern-js/utils';
|
|
9
|
+
import { InternalBuildError } from "../error";
|
|
10
|
+
import { watchSectionTitle, SectionTitleStatus, getPostcssOption } from "../utils";
|
|
11
|
+
const compiler = Import.lazy('@modern-js/style-compiler', require);
|
|
12
|
+
export class StyleBuildError extends Error {
|
|
13
|
+
constructor(message, opts) {
|
|
14
|
+
super(message);
|
|
15
|
+
|
|
16
|
+
_defineProperty(this, "summary", void 0);
|
|
17
|
+
|
|
18
|
+
_defineProperty(this, "details", void 0);
|
|
19
|
+
|
|
20
|
+
Error.captureStackTrace(this, this.constructor);
|
|
21
|
+
this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
|
|
22
|
+
this.details = opts === null || opts === void 0 ? void 0 : opts.details;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return this.formatError().join('\n');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
formatError() {
|
|
30
|
+
const msgs = [];
|
|
31
|
+
const {
|
|
32
|
+
summary,
|
|
33
|
+
details = []
|
|
34
|
+
} = this;
|
|
35
|
+
msgs.push(chalk.red.bold(summary));
|
|
36
|
+
|
|
37
|
+
for (const detail of details) {
|
|
38
|
+
if (detail.error) {
|
|
39
|
+
msgs.push(detail.error);
|
|
40
|
+
msgs.push('\n');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return msgs;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* when modern build, only throw Error or silent
|
|
50
|
+
* @param result
|
|
51
|
+
* @param context
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
const generatorFileOrLogError = (result, context) => {
|
|
55
|
+
if (result.code === 0) {
|
|
56
|
+
for (const file of result.dists) {
|
|
57
|
+
fs.ensureFileSync(file.filename);
|
|
58
|
+
fs.writeFileSync(file.filename, file.content);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
// for (const file of result.errors) {
|
|
62
|
+
// console.error(file.error);
|
|
63
|
+
// }
|
|
64
|
+
const styleError = new StyleBuildError('bundleless failed', {
|
|
65
|
+
summary: 'Style Compiler Failed',
|
|
66
|
+
details: result.errors
|
|
67
|
+
});
|
|
68
|
+
throw new InternalBuildError(styleError, _objectSpread({
|
|
69
|
+
buildType: 'bundleless'
|
|
70
|
+
}, context));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const generatorFileAndLog = (result, titleText) => {
|
|
75
|
+
if (result.code === 0) {
|
|
76
|
+
for (const file of result.dists) {
|
|
77
|
+
fs.ensureFileSync(file.filename);
|
|
78
|
+
fs.writeFileSync(file.filename, file.content);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
|
|
82
|
+
} else {
|
|
83
|
+
console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
|
|
84
|
+
|
|
85
|
+
for (const file of result.errors) {
|
|
86
|
+
console.error(file.error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const copyOriginStyleFiles = ({
|
|
92
|
+
targetDir,
|
|
93
|
+
outputDir
|
|
94
|
+
}) => {
|
|
95
|
+
const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
|
|
96
|
+
|
|
97
|
+
if (styleFiles.length > 0) {
|
|
98
|
+
fs.ensureDirSync(outputDir);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (const styleFile of styleFiles) {
|
|
102
|
+
const file = path.relative(targetDir, styleFile);
|
|
103
|
+
fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
|
|
104
|
+
fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const runBuild = async option => {
|
|
109
|
+
const {
|
|
110
|
+
watch,
|
|
111
|
+
appDirectory,
|
|
112
|
+
srcDir,
|
|
113
|
+
outDir,
|
|
114
|
+
lessOption,
|
|
115
|
+
sassOption,
|
|
116
|
+
postcssOption
|
|
117
|
+
} = option;
|
|
118
|
+
|
|
119
|
+
if (watch) {
|
|
120
|
+
const srcStyleEmitter = compiler.styleCompiler({
|
|
121
|
+
watch: true,
|
|
122
|
+
projectDir: appDirectory,
|
|
123
|
+
stylesDir: srcDir,
|
|
124
|
+
outDir,
|
|
125
|
+
enableVirtualDist: true,
|
|
126
|
+
compilerOption: {
|
|
127
|
+
less: lessOption,
|
|
128
|
+
sass: sassOption,
|
|
129
|
+
postcss: postcssOption
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
return srcStyleEmitter;
|
|
133
|
+
} else {
|
|
134
|
+
const srcStyleResult = await compiler.styleCompiler({
|
|
135
|
+
projectDir: appDirectory,
|
|
136
|
+
stylesDir: srcDir,
|
|
137
|
+
outDir,
|
|
138
|
+
enableVirtualDist: true,
|
|
139
|
+
compilerOption: {
|
|
140
|
+
less: lessOption,
|
|
141
|
+
sass: sassOption,
|
|
142
|
+
postcss: postcssOption
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return srcStyleResult;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export const styleFileSuffix = ['css', 'less', 'sass', 'scss'];
|
|
149
|
+
export const haveNotAnyStyles = async sourceDir => {
|
|
150
|
+
const files = await globby(slash(`${sourceDir}/**/*.{${styleFileSuffix.join(',')}}`));
|
|
151
|
+
return files.length === 0;
|
|
152
|
+
};
|
|
153
|
+
export const buildStyle = async (api, config) => {
|
|
154
|
+
var _style$path;
|
|
155
|
+
|
|
156
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
157
|
+
const {
|
|
158
|
+
appDirectory
|
|
159
|
+
} = api.useAppContext();
|
|
160
|
+
const {
|
|
161
|
+
watch = false,
|
|
162
|
+
outputPath,
|
|
163
|
+
bundlelessOptions
|
|
164
|
+
} = config;
|
|
165
|
+
const {
|
|
166
|
+
style,
|
|
167
|
+
sourceDir
|
|
168
|
+
} = bundlelessOptions;
|
|
169
|
+
const {
|
|
170
|
+
output: {
|
|
171
|
+
path: distPath = 'dist'
|
|
172
|
+
}
|
|
173
|
+
} = modernConfig;
|
|
174
|
+
const titleText = `[Bundleless:Style:${sourceDir}]`;
|
|
175
|
+
|
|
176
|
+
if ((await haveNotAnyStyles(sourceDir)) || style.compileMode === false) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const runner = api.useHookRunners();
|
|
181
|
+
const lessOption = await runner.moduleLessConfig({
|
|
182
|
+
modernConfig
|
|
183
|
+
}, {
|
|
184
|
+
onLast: async _ => undefined
|
|
185
|
+
});
|
|
186
|
+
const sassOption = await runner.moduleSassConfig({
|
|
187
|
+
modernConfig
|
|
188
|
+
}, {
|
|
189
|
+
onLast: async _ => undefined
|
|
190
|
+
});
|
|
191
|
+
const tailwindPlugin = await runner.moduleTailwindConfig({
|
|
192
|
+
modernConfig
|
|
193
|
+
}, {
|
|
194
|
+
onLast: async _ => undefined
|
|
195
|
+
});
|
|
196
|
+
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
197
|
+
|
|
198
|
+
if (tailwindPlugin) {
|
|
199
|
+
var _postcssOption$plugin;
|
|
200
|
+
|
|
201
|
+
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const srcDir = path.resolve(appDirectory, sourceDir);
|
|
205
|
+
const outputDirToSrc = path.join(appDirectory, distPath, outputPath, (_style$path = style.path) !== null && _style$path !== void 0 ? _style$path : './');
|
|
206
|
+
|
|
207
|
+
if (style.compileMode === 'all' || style.compileMode === 'only-compiled-code') {
|
|
208
|
+
const result = await runBuild({
|
|
209
|
+
appDirectory,
|
|
210
|
+
srcDir,
|
|
211
|
+
watch,
|
|
212
|
+
outDir: outputDirToSrc,
|
|
213
|
+
lessOption,
|
|
214
|
+
sassOption,
|
|
215
|
+
postcssOption
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (watch) {
|
|
219
|
+
const emitter = result;
|
|
220
|
+
emitter.on(compiler.BuildWatchEvent.firstCompiler, result => {
|
|
221
|
+
generatorFileAndLog(result, titleText);
|
|
222
|
+
});
|
|
223
|
+
emitter.on(compiler.BuildWatchEvent.watchingCompiler, srcStyleResult => {
|
|
224
|
+
generatorFileAndLog(srcStyleResult, titleText);
|
|
225
|
+
});
|
|
226
|
+
await emitter.watch();
|
|
227
|
+
} else {
|
|
228
|
+
const srcStyleResult = result;
|
|
229
|
+
generatorFileOrLogError(srcStyleResult, {
|
|
230
|
+
target: config.target,
|
|
231
|
+
format: config.format
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (style.compileMode === 'all' || style.compileMode === 'only-source-code') {
|
|
237
|
+
if (watch) {
|
|
238
|
+
copyOriginStyleFiles({
|
|
239
|
+
targetDir: srcDir,
|
|
240
|
+
outputDir: outputDirToSrc
|
|
241
|
+
});
|
|
242
|
+
console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
|
|
243
|
+
watcher(`${srcDir}/**/*.{css,less,sass,scss}`, ({
|
|
244
|
+
changeType,
|
|
245
|
+
changedFilePath
|
|
246
|
+
}) => {
|
|
247
|
+
if (changeType === WatchChangeType.UNLINK) {
|
|
248
|
+
const removeFile = path.normalize(`${outputDirToSrc}/${path.relative(srcDir, changedFilePath)}`);
|
|
249
|
+
fs.removeSync(removeFile);
|
|
250
|
+
} else {
|
|
251
|
+
copyOriginStyleFiles({
|
|
252
|
+
targetDir: srcDir,
|
|
253
|
+
outputDir: outputDirToSrc
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
copyOriginStyleFiles({
|
|
261
|
+
targetDir: srcDir,
|
|
262
|
+
outputDir: outputDirToSrc
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
@@ -1,66 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
import { chalk } from '@modern-js/utils';
|
|
8
|
+
export const clearFlag = '\x1Bc';
|
|
9
|
+
export const buildingText = chalk.blue('Building...');
|
|
10
|
+
export const buildSuccessText = chalk.green('Build succeed');
|
|
11
|
+
export const buildFailText = chalk.red('Build Failed:');
|
|
12
|
+
export const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext'];
|
|
13
|
+
export const npmLibraryPresetConfig = [{
|
|
14
|
+
format: 'cjs',
|
|
15
|
+
target: 'es6',
|
|
16
|
+
buildType: 'bundle',
|
|
17
|
+
outputPath: './lib'
|
|
6
18
|
}, {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
format: 'esm',
|
|
20
|
+
target: 'es6',
|
|
21
|
+
buildType: 'bundle',
|
|
22
|
+
outputPath: './es'
|
|
10
23
|
}, {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
buildType: 'bundle',
|
|
25
|
+
outputPath: './types',
|
|
26
|
+
enableDts: true,
|
|
27
|
+
dtsOnly: true
|
|
28
|
+
}];
|
|
29
|
+
export const npmLibraryWithUmdPresetConfig = [{
|
|
30
|
+
format: 'cjs',
|
|
31
|
+
target: 'es6',
|
|
32
|
+
buildType: 'bundle',
|
|
33
|
+
outputPath: './lib'
|
|
20
34
|
}, {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}]; // 纯前端代码的默认选择,两份构建产物
|
|
26
|
-
|
|
27
|
-
const browserJs = [{
|
|
28
|
-
type: 'module',
|
|
29
|
-
syntax: 'es5',
|
|
30
|
-
outDir: 'treeshaking',
|
|
31
|
-
copyDirs: ['node']
|
|
35
|
+
format: 'esm',
|
|
36
|
+
target: 'es6',
|
|
37
|
+
buildType: 'bundle',
|
|
38
|
+
outputPath: './es'
|
|
32
39
|
}, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
format: 'umd',
|
|
41
|
+
target: 'es6',
|
|
42
|
+
buildType: 'bundle',
|
|
43
|
+
outputPath: './umd'
|
|
44
|
+
}, {
|
|
45
|
+
buildType: 'bundle',
|
|
46
|
+
outputPath: './types',
|
|
47
|
+
enableDts: true,
|
|
48
|
+
dtsOnly: true
|
|
49
|
+
}];
|
|
50
|
+
export const npmComponentPresetConfig = [{
|
|
51
|
+
format: 'cjs',
|
|
52
|
+
target: 'es6',
|
|
53
|
+
buildType: 'bundleless',
|
|
54
|
+
outputPath: './lib'
|
|
55
|
+
}, {
|
|
56
|
+
format: 'esm',
|
|
57
|
+
target: 'es6',
|
|
58
|
+
buildType: 'bundleless',
|
|
59
|
+
outputPath: './es'
|
|
60
|
+
}, {
|
|
61
|
+
buildType: 'bundleless',
|
|
62
|
+
outputPath: './types',
|
|
63
|
+
enableDts: true,
|
|
64
|
+
dtsOnly: true
|
|
65
|
+
}];
|
|
66
|
+
export const npmComponentWithUmdPresetConfig = [{
|
|
67
|
+
format: 'cjs',
|
|
68
|
+
target: 'es6',
|
|
69
|
+
buildType: 'bundleless',
|
|
70
|
+
outputPath: './lib'
|
|
71
|
+
}, {
|
|
72
|
+
format: 'esm',
|
|
73
|
+
target: 'es6',
|
|
74
|
+
buildType: 'bundleless',
|
|
75
|
+
outputPath: './es'
|
|
76
|
+
}, {
|
|
77
|
+
format: 'umd',
|
|
78
|
+
target: 'es6',
|
|
79
|
+
buildType: 'bundle',
|
|
80
|
+
outputPath: './umd'
|
|
49
81
|
}, {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
82
|
+
buildType: 'bundleless',
|
|
83
|
+
outputPath: './types',
|
|
84
|
+
enableDts: true,
|
|
85
|
+
dtsOnly: true
|
|
53
86
|
}];
|
|
54
|
-
export const
|
|
55
|
-
|
|
56
|
-
'
|
|
57
|
-
'
|
|
58
|
-
'
|
|
59
|
-
'browser-js-lite': browserJsLite,
|
|
60
|
-
'node-js': nodeJs
|
|
87
|
+
export const unPresetConfigs = {
|
|
88
|
+
'npm-library': npmLibraryPresetConfig,
|
|
89
|
+
'npm-library-with-umd': npmLibraryWithUmdPresetConfig,
|
|
90
|
+
'npm-component': npmComponentPresetConfig,
|
|
91
|
+
'npm-component-with-umd': npmComponentWithUmdPresetConfig
|
|
61
92
|
};
|
|
62
|
-
export const
|
|
63
|
-
export const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
export const unPresets = Object.keys(unPresetConfigs);
|
|
94
|
+
export const unPresetWithTargetConfigs = unPresets.reduce((o, presetStr) => {
|
|
95
|
+
const rets = targets.map(target => [`${presetStr}-${target}`.toLowerCase(), unPresetConfigs[presetStr].map(config => {
|
|
96
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
97
|
+
target
|
|
98
|
+
});
|
|
99
|
+
})]);
|
|
100
|
+
return _objectSpread(_objectSpread({}, o), Object.fromEntries(rets));
|
|
101
|
+
}, {});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
import { chalk } from '@modern-js/utils';
|
|
4
|
+
export const padSpaceWith = (str, targetL, opts = {}) => {
|
|
5
|
+
const {
|
|
6
|
+
endStr = '|',
|
|
7
|
+
style
|
|
8
|
+
} = opts;
|
|
9
|
+
const l = str.length;
|
|
10
|
+
const endStrL = endStr.length;
|
|
11
|
+
const resetL = targetL - l - endStrL; // str is 'aaa', targetL is 4, result is 'aaa|'
|
|
12
|
+
|
|
13
|
+
if (resetL === 0) {
|
|
14
|
+
return (style ? style(str) : str) + endStr;
|
|
15
|
+
} // str is 'aaa', targetL is 5, result is 'aaa |'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if (resetL > 0) {
|
|
19
|
+
const padStr = str.padEnd(targetL - 1, ' ');
|
|
20
|
+
|
|
21
|
+
if (style) {
|
|
22
|
+
return style(str) + padStr.replace(str, '') + endStr;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return padStr + endStr;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return str;
|
|
29
|
+
};
|
|
30
|
+
export class InternalBuildError extends Error {
|
|
31
|
+
constructor(e, opts) {
|
|
32
|
+
super(e.message);
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "buildType", void 0);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "target", void 0);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "format", void 0);
|
|
39
|
+
|
|
40
|
+
_defineProperty(this, "e", void 0);
|
|
41
|
+
|
|
42
|
+
Error.captureStackTrace(this, this.constructor);
|
|
43
|
+
this.e = e;
|
|
44
|
+
this.buildType = opts.buildType;
|
|
45
|
+
this.target = opts.target;
|
|
46
|
+
this.format = opts.format;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toString() {
|
|
50
|
+
return this.formatError().join('\n');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
formatError() {
|
|
54
|
+
const msgs = [];
|
|
55
|
+
const {
|
|
56
|
+
e,
|
|
57
|
+
buildType,
|
|
58
|
+
target,
|
|
59
|
+
format
|
|
60
|
+
} = this;
|
|
61
|
+
const textL = 25;
|
|
62
|
+
const title = `│ ${padSpaceWith(`${buildType} failed:`, textL - 2, {
|
|
63
|
+
style: chalk.red.underline,
|
|
64
|
+
endStr: '│'
|
|
65
|
+
})}`;
|
|
66
|
+
const formatMsg = padSpaceWith(`│ - format is "${format}"`, textL, {
|
|
67
|
+
endStr: '│'
|
|
68
|
+
});
|
|
69
|
+
const targetMsg = padSpaceWith(`│ - target is "${target}"`, textL, {
|
|
70
|
+
endStr: '│'
|
|
71
|
+
});
|
|
72
|
+
const startLine = padSpaceWith('╭'.padEnd(textL - 1, '─'), textL, {
|
|
73
|
+
endStr: '╮'
|
|
74
|
+
});
|
|
75
|
+
const endLine = padSpaceWith('╰'.padEnd(textL - 1, '─'), textL, {
|
|
76
|
+
endStr: '╯'
|
|
77
|
+
});
|
|
78
|
+
msgs.push(startLine, title, formatMsg, targetMsg, endLine, chalk.blue.bold.underline(`\nDetailed Information: `));
|
|
79
|
+
msgs.push(e.toString());
|
|
80
|
+
msgs.push(e.stack || '');
|
|
81
|
+
return msgs;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
export class InternalDTSError extends Error {
|
|
86
|
+
constructor(e, opts) {
|
|
87
|
+
super(e.message);
|
|
88
|
+
|
|
89
|
+
_defineProperty(this, "buildType", void 0);
|
|
90
|
+
|
|
91
|
+
_defineProperty(this, "e", void 0);
|
|
92
|
+
|
|
93
|
+
Error.captureStackTrace(this, this.constructor);
|
|
94
|
+
this.e = e;
|
|
95
|
+
this.buildType = opts.buildType;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
toString() {
|
|
99
|
+
return this.formatError().join('\n');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
formatError() {
|
|
103
|
+
const msgs = [];
|
|
104
|
+
const {
|
|
105
|
+
e,
|
|
106
|
+
buildType
|
|
107
|
+
} = this;
|
|
108
|
+
msgs.push(chalk.red.bold(`${buildType} DTS failed:`));
|
|
109
|
+
|
|
110
|
+
if (isExecaError(e)) {
|
|
111
|
+
/**
|
|
112
|
+
* `shortMeessage` content like:
|
|
113
|
+
* 'Command failed with exit code 2: /Users/github/modern.js/playground/module/node_modules/.bin/tsc -p /Users/github/modern.js/playground/module/node_modules/tsconfig.temp.json --pretty'
|
|
114
|
+
* Don`t need it.
|
|
115
|
+
*/
|
|
116
|
+
if (e.stack) {
|
|
117
|
+
var _e$stack;
|
|
118
|
+
|
|
119
|
+
msgs.push((_e$stack = e.stack) === null || _e$stack === void 0 ? void 0 : _e$stack.replace(`${e.name}: ${e.shortMessage}`, ''));
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
msgs.push(e.stack);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return msgs;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
export class ModuleBuildError extends Error {
|
|
130
|
+
constructor(e) {
|
|
131
|
+
super(`\n\n${e}`);
|
|
132
|
+
Error.captureStackTrace(this, this.constructor);
|
|
133
|
+
this.name = 'ModuleBuildError';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
export const isInternalError = e => {
|
|
138
|
+
if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return false;
|
|
143
|
+
};
|
|
144
|
+
export const isExecaError = e => {
|
|
145
|
+
if (e.stdout) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return false;
|
|
150
|
+
};
|