@modern-js/babel-compiler 2.14.0 → 2.16.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 +19 -0
- package/dist/cjs/build.js +16 -47
- package/dist/cjs/buildWatch.js +119 -89
- package/dist/cjs/compiler.js +73 -75
- package/dist/cjs/compilerErrorResult.js +28 -34
- package/dist/cjs/constants.js +7 -25
- package/dist/cjs/defaults.js +9 -27
- package/dist/cjs/getFinalOption.js +33 -50
- package/dist/cjs/index.js +29 -36
- package/dist/cjs/type.js +4 -15
- package/dist/cjs/utils.js +49 -37
- package/dist/cjs/validate.js +21 -33
- package/dist/esm/build.js +217 -210
- package/dist/esm/buildWatch.js +389 -375
- package/dist/esm/compiler.js +118 -119
- package/dist/esm/compilerErrorResult.js +103 -100
- package/dist/esm/constants.js +5 -6
- package/dist/esm/defaults.js +36 -37
- package/dist/esm/getFinalOption.js +124 -116
- package/dist/esm/index.js +154 -148
- package/dist/esm/type.js +1 -1
- package/dist/esm/utils.js +2 -3
- package/dist/esm/validate.js +31 -32
- package/dist/esm-node/build.js +4 -20
- package/dist/esm-node/buildWatch.js +60 -51
- package/dist/esm-node/compiler.js +8 -31
- package/dist/esm-node/compilerErrorResult.js +21 -12
- package/dist/esm-node/constants.js +1 -4
- package/dist/esm-node/defaults.js +1 -4
- package/dist/esm-node/getFinalOption.js +16 -24
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/type.js +1 -0
- package/dist/esm-node/utils.js +1 -4
- package/dist/esm-node/validate.js +10 -13
- package/package.json +9 -5
package/dist/esm/build.js
CHANGED
|
@@ -1,224 +1,231 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
|
-
var __generator =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
var __generator = function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1)
|
|
35
|
+
throw t[1];
|
|
36
|
+
return t[1];
|
|
37
|
+
},
|
|
38
|
+
trys: [],
|
|
39
|
+
ops: []
|
|
40
|
+
};
|
|
41
|
+
return g = {
|
|
42
|
+
next: verb(0),
|
|
43
|
+
"throw": verb(1),
|
|
44
|
+
"return": verb(2)
|
|
45
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
46
|
+
return this;
|
|
47
|
+
}), g;
|
|
48
|
+
function verb(n) {
|
|
49
|
+
return function(v) {
|
|
50
|
+
return step([
|
|
51
|
+
n,
|
|
52
|
+
v
|
|
53
|
+
]);
|
|
39
54
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
break;
|
|
68
|
-
case 4:
|
|
69
|
-
_.label++;
|
|
70
|
-
return {
|
|
71
|
-
value: op[1],
|
|
72
|
-
done: false
|
|
73
|
-
};
|
|
74
|
-
case 5:
|
|
75
|
-
_.label++;
|
|
76
|
-
y = op[1];
|
|
77
|
-
op = [
|
|
78
|
-
0
|
|
79
|
-
];
|
|
80
|
-
continue;
|
|
81
|
-
case 7:
|
|
82
|
-
op = _.ops.pop();
|
|
83
|
-
_.trys.pop();
|
|
84
|
-
continue;
|
|
85
|
-
default:
|
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
-
_ = 0;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
-
_.label = op[1];
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
-
_.label = t[1];
|
|
96
|
-
t = op;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (t && _.label < t[2]) {
|
|
100
|
-
_.label = t[2];
|
|
101
|
-
_.ops.push(op);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
if (t[2]) _.ops.pop();
|
|
105
|
-
_.trys.pop();
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
op = body.call(thisArg, _);
|
|
109
|
-
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
function step(op) {
|
|
57
|
+
if (f)
|
|
58
|
+
throw new TypeError("Generator is already executing.");
|
|
59
|
+
while (_)
|
|
60
|
+
try {
|
|
61
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
62
|
+
return t;
|
|
63
|
+
if (y = 0, t)
|
|
64
|
+
op = [
|
|
65
|
+
op[0] & 2,
|
|
66
|
+
t.value
|
|
67
|
+
];
|
|
68
|
+
switch (op[0]) {
|
|
69
|
+
case 0:
|
|
70
|
+
case 1:
|
|
71
|
+
t = op;
|
|
72
|
+
break;
|
|
73
|
+
case 4:
|
|
74
|
+
_.label++;
|
|
75
|
+
return {
|
|
76
|
+
value: op[1],
|
|
77
|
+
done: false
|
|
78
|
+
};
|
|
79
|
+
case 5:
|
|
80
|
+
_.label++;
|
|
81
|
+
y = op[1];
|
|
110
82
|
op = [
|
|
111
|
-
|
|
112
|
-
e
|
|
83
|
+
0
|
|
113
84
|
];
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
85
|
+
continue;
|
|
86
|
+
case 7:
|
|
87
|
+
op = _.ops.pop();
|
|
88
|
+
_.trys.pop();
|
|
89
|
+
continue;
|
|
90
|
+
default:
|
|
91
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
92
|
+
_ = 0;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
96
|
+
_.label = op[1];
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
100
|
+
_.label = t[1];
|
|
101
|
+
t = op;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t && _.label < t[2]) {
|
|
105
|
+
_.label = t[2];
|
|
106
|
+
_.ops.push(op);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (t[2])
|
|
110
|
+
_.ops.pop();
|
|
111
|
+
_.trys.pop();
|
|
112
|
+
continue;
|
|
117
113
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
op = body.call(thisArg, _);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
op = [
|
|
117
|
+
6,
|
|
118
|
+
e
|
|
119
|
+
];
|
|
120
|
+
y = 0;
|
|
121
|
+
} finally {
|
|
122
|
+
f = t = 0;
|
|
123
|
+
}
|
|
124
|
+
if (op[0] & 5)
|
|
125
|
+
throw op[1];
|
|
126
|
+
return {
|
|
127
|
+
value: op[0] ? op[1] : void 0,
|
|
128
|
+
done: true
|
|
129
|
+
};
|
|
130
|
+
}
|
|
124
131
|
};
|
|
125
132
|
import { fs, logger } from "@modern-js/utils";
|
|
126
133
|
import { defaultDistFileExtMap } from "./constants";
|
|
127
134
|
import { compiler } from "./compiler";
|
|
128
|
-
var build = function() {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
happenError = messageDetails.length > 0;
|
|
192
|
-
if (!quiet) {
|
|
193
|
-
if (happenError) {
|
|
194
|
-
logger.error("Compilation failure ".concat(messageDetails.length, " ").concat(messageDetails.length !== 1 ? "files" : "file", " with Babel."));
|
|
195
|
-
} else {
|
|
196
|
-
logger.info("Successfully compiled ".concat(filenames.length, " ").concat(filenames.length !== 1 ? "files" : "file", " with Babel."));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
if (happenError) {
|
|
200
|
-
return [
|
|
201
|
-
2,
|
|
202
|
-
{
|
|
203
|
-
code: 1,
|
|
204
|
-
message: "Compilation failure ".concat(messageDetails.length, " ").concat(messageDetails.length !== 1 ? "files" : "file", " with Babel."),
|
|
205
|
-
messageDetails: messageDetails
|
|
206
|
-
}
|
|
207
|
-
];
|
|
208
|
-
}
|
|
209
|
-
return [
|
|
210
|
-
2,
|
|
211
|
-
{
|
|
212
|
-
code: 0,
|
|
213
|
-
message: "Successfully compiled ".concat(filenames.length, " ").concat(filenames.length !== 1 ? "files" : "file", " with Babel."),
|
|
214
|
-
virtualDists: virtualDists
|
|
215
|
-
}
|
|
216
|
-
];
|
|
135
|
+
export var build = function() {
|
|
136
|
+
var _ref = _async_to_generator(function(option) {
|
|
137
|
+
var babelConfig, rootDir, enableVirtualDist, filenames, clean, distDir, _option_distFileExtMap, distFileExtMap, _option_verbose, verbose, _option_quiet, quiet, virtualDists, messageDetails, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, filename, dist, happenError;
|
|
138
|
+
var _arguments = arguments;
|
|
139
|
+
return __generator(this, function(_state) {
|
|
140
|
+
switch (_state.label) {
|
|
141
|
+
case 0:
|
|
142
|
+
babelConfig = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
|
|
143
|
+
rootDir = option.rootDir, enableVirtualDist = option.enableVirtualDist, filenames = option.filenames, clean = option.clean, distDir = option.distDir, _option_distFileExtMap = option.distFileExtMap, distFileExtMap = _option_distFileExtMap === void 0 ? defaultDistFileExtMap : _option_distFileExtMap, _option_verbose = option.verbose, verbose = _option_verbose === void 0 ? false : _option_verbose, _option_quiet = option.quiet, quiet = _option_quiet === void 0 ? false : _option_quiet;
|
|
144
|
+
virtualDists = [];
|
|
145
|
+
if (!clean)
|
|
146
|
+
return [
|
|
147
|
+
3,
|
|
148
|
+
2
|
|
149
|
+
];
|
|
150
|
+
return [
|
|
151
|
+
4,
|
|
152
|
+
fs.remove(distDir)
|
|
153
|
+
];
|
|
154
|
+
case 1:
|
|
155
|
+
_state.sent();
|
|
156
|
+
_state.label = 2;
|
|
157
|
+
case 2:
|
|
158
|
+
fs.ensureDir(distDir);
|
|
159
|
+
messageDetails = [];
|
|
160
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
161
|
+
try {
|
|
162
|
+
for (_iterator = filenames[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
163
|
+
filename = _step.value;
|
|
164
|
+
try {
|
|
165
|
+
dist = compiler({
|
|
166
|
+
rootDir,
|
|
167
|
+
enableVirtualDist,
|
|
168
|
+
filepath: filename,
|
|
169
|
+
distDir,
|
|
170
|
+
verbose,
|
|
171
|
+
quiet,
|
|
172
|
+
babelConfig,
|
|
173
|
+
distFileExtMap
|
|
174
|
+
});
|
|
175
|
+
if (enableVirtualDist && dist) {
|
|
176
|
+
virtualDists.push(dist);
|
|
177
|
+
}
|
|
178
|
+
} catch (e) {
|
|
179
|
+
messageDetails.push({
|
|
180
|
+
filename,
|
|
181
|
+
content: e.toString()
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
_didIteratorError = true;
|
|
187
|
+
_iteratorError = err;
|
|
188
|
+
} finally {
|
|
189
|
+
try {
|
|
190
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
191
|
+
_iterator.return();
|
|
192
|
+
}
|
|
193
|
+
} finally {
|
|
194
|
+
if (_didIteratorError) {
|
|
195
|
+
throw _iteratorError;
|
|
196
|
+
}
|
|
217
197
|
}
|
|
218
|
-
|
|
198
|
+
}
|
|
199
|
+
happenError = messageDetails.length > 0;
|
|
200
|
+
if (!quiet) {
|
|
201
|
+
if (happenError) {
|
|
202
|
+
logger.error("Compilation failure ".concat(messageDetails.length, " ").concat(messageDetails.length !== 1 ? "files" : "file", " with Babel."));
|
|
203
|
+
} else {
|
|
204
|
+
logger.info("Successfully compiled ".concat(filenames.length, " ").concat(filenames.length !== 1 ? "files" : "file", " with Babel."));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (happenError) {
|
|
208
|
+
return [
|
|
209
|
+
2,
|
|
210
|
+
{
|
|
211
|
+
code: 1,
|
|
212
|
+
message: "Compilation failure ".concat(messageDetails.length, " ").concat(messageDetails.length !== 1 ? "files" : "file", " with Babel."),
|
|
213
|
+
messageDetails
|
|
214
|
+
}
|
|
215
|
+
];
|
|
216
|
+
}
|
|
217
|
+
return [
|
|
218
|
+
2,
|
|
219
|
+
{
|
|
220
|
+
code: 0,
|
|
221
|
+
message: "Successfully compiled ".concat(filenames.length, " ").concat(filenames.length !== 1 ? "files" : "file", " with Babel."),
|
|
222
|
+
virtualDists
|
|
223
|
+
}
|
|
224
|
+
];
|
|
225
|
+
}
|
|
219
226
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
227
|
+
});
|
|
228
|
+
return function build2(option) {
|
|
229
|
+
return _ref.apply(this, arguments);
|
|
230
|
+
};
|
|
223
231
|
}();
|
|
224
|
-
export { build };
|