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