@modern-js/babel-compiler 2.0.0-beta.3 → 2.0.0-beta.6
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 +61 -0
- package/dist/js/modern/build.js +35 -9
- package/dist/js/modern/buildWatch.js +107 -68
- package/dist/js/modern/compiler.js +48 -26
- package/dist/js/modern/compilerErrorResult.js +12 -11
- package/dist/js/modern/constants.js +9 -6
- package/dist/js/modern/defaults.js +20 -4
- package/dist/js/modern/getFinalOption.js +40 -21
- package/dist/js/modern/index.js +37 -12
- package/dist/js/modern/utils.js +8 -4
- package/dist/js/modern/validate.js +17 -22
- package/dist/js/node/build.js +62 -20
- package/dist/js/node/buildWatch.js +136 -79
- package/dist/js/node/compiler.js +84 -44
- package/dist/js/node/compilerErrorResult.js +32 -15
- package/dist/js/node/constants.js +29 -10
- package/dist/js/node/defaults.js +42 -12
- package/dist/js/node/getFinalOption.js +66 -33
- package/dist/js/node/index.js +61 -42
- package/dist/js/node/type.js +15 -0
- package/dist/js/node/utils.js +35 -10
- package/dist/js/node/validate.js +44 -33
- package/dist/js/treeshaking/build.js +224 -0
- package/dist/js/treeshaking/buildWatch.js +417 -0
- package/dist/js/treeshaking/compiler.js +140 -0
- package/dist/js/treeshaking/compilerErrorResult.js +110 -0
- package/dist/js/treeshaking/constants.js +7 -0
- package/dist/js/treeshaking/defaults.js +44 -0
- package/dist/js/treeshaking/getFinalOption.js +137 -0
- package/dist/js/treeshaking/index.js +166 -0
- package/dist/js/treeshaking/type.js +1 -0
- package/dist/js/treeshaking/utils.js +5 -0
- package/dist/js/treeshaking/validate.js +38 -0
- package/package.json +4 -4
package/dist/js/node/utils.js
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var utils_exports = {};
|
|
25
|
+
__export(utils_exports, {
|
|
26
|
+
addSourceMappingUrl: () => addSourceMappingUrl
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var path =
|
|
8
|
-
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); }
|
|
9
|
-
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; }
|
|
28
|
+
module.exports = __toCommonJS(utils_exports);
|
|
29
|
+
var path = __toESM(require("path"));
|
|
10
30
|
function addSourceMappingUrl(code, loc) {
|
|
11
|
-
return `${code}
|
|
12
|
-
}
|
|
31
|
+
return `${code}
|
|
32
|
+
//# sourceMappingURL=${path.normalize(path.basename(loc))}`;
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
addSourceMappingUrl
|
|
37
|
+
});
|
package/dist/js/node/validate.js
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var validate_exports = {};
|
|
19
|
+
__export(validate_exports, {
|
|
20
|
+
sourceDirAndFileNamesValidMessage: () => sourceDirAndFileNamesValidMessage,
|
|
21
|
+
validate: () => validate,
|
|
22
|
+
validateSourceDirAndFileNames: () => validateSourceDirAndFileNames,
|
|
23
|
+
validateWatchDir: () => validateWatchDir,
|
|
24
|
+
watchDirValidMessage: () => watchDirValidMessage
|
|
5
25
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
const sourceDirAndFileNamesValidMessage =
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const validateSourceDirAndFileNames = compilerOptions => {
|
|
13
|
-
const {
|
|
14
|
-
sourceDir,
|
|
15
|
-
filenames,
|
|
16
|
-
quiet
|
|
17
|
-
} = compilerOptions;
|
|
26
|
+
module.exports = __toCommonJS(validate_exports);
|
|
27
|
+
var import_utils = require("@modern-js/utils");
|
|
28
|
+
const sourceDirAndFileNamesValidMessage = "At least one of the sourceDir and filenames configurations must be configured";
|
|
29
|
+
const watchDirValidMessage = "should set watchDir when enableWatch is true";
|
|
30
|
+
const validateSourceDirAndFileNames = (compilerOptions) => {
|
|
31
|
+
const { sourceDir, filenames, quiet } = compilerOptions;
|
|
18
32
|
if (!sourceDir && !filenames) {
|
|
19
33
|
if (!quiet) {
|
|
20
|
-
|
|
34
|
+
import_utils.logger.error(sourceDirAndFileNamesValidMessage);
|
|
21
35
|
}
|
|
22
36
|
return {
|
|
23
37
|
code: 1,
|
|
@@ -27,30 +41,27 @@ const validateSourceDirAndFileNames = compilerOptions => {
|
|
|
27
41
|
}
|
|
28
42
|
return null;
|
|
29
43
|
};
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const {
|
|
33
|
-
watchDir,
|
|
34
|
-
enableWatch,
|
|
35
|
-
quiet
|
|
36
|
-
} = compilerOptions;
|
|
44
|
+
const validateWatchDir = (compilerOptions) => {
|
|
45
|
+
const { watchDir, enableWatch, quiet } = compilerOptions;
|
|
37
46
|
if (enableWatch && !watchDir) {
|
|
38
47
|
if (!quiet) {
|
|
39
|
-
|
|
48
|
+
import_utils.logger.error(watchDirValidMessage);
|
|
40
49
|
}
|
|
41
|
-
return {
|
|
42
|
-
code: 1,
|
|
43
|
-
message: watchDirValidMessage,
|
|
44
|
-
virtualDists: []
|
|
45
|
-
};
|
|
50
|
+
return { code: 1, message: watchDirValidMessage, virtualDists: [] };
|
|
46
51
|
}
|
|
47
52
|
return null;
|
|
48
53
|
};
|
|
49
|
-
|
|
50
|
-
const validate = compilerOptions => {
|
|
54
|
+
const validate = (compilerOptions) => {
|
|
51
55
|
if (compilerOptions.enableWatch) {
|
|
52
56
|
return validateWatchDir(compilerOptions);
|
|
53
57
|
}
|
|
54
58
|
return validateSourceDirAndFileNames(compilerOptions);
|
|
55
59
|
};
|
|
56
|
-
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
sourceDirAndFileNamesValidMessage,
|
|
63
|
+
validate,
|
|
64
|
+
validateSourceDirAndFileNames,
|
|
65
|
+
validateWatchDir,
|
|
66
|
+
watchDirValidMessage
|
|
67
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
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
|
+
}
|
|
15
|
+
function _asyncToGenerator(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(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return(g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g);
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
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) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
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) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
import { fs, logger } from "@modern-js/utils";
|
|
126
|
+
import { defaultDistFileExtMap } from "./constants";
|
|
127
|
+
import { compiler } from "./compiler";
|
|
128
|
+
var build = function() {
|
|
129
|
+
var _ref = _asyncToGenerator(function(option) {
|
|
130
|
+
var babelConfig, rootDir, enableVirtualDist, filenames, clean, distDir, _distFileExtMap, distFileExtMap, _verbose, verbose, _quiet, quiet, virtualDists, messageDetails, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, filename, dist, happenError;
|
|
131
|
+
var _arguments = arguments;
|
|
132
|
+
return __generator(this, function(_state) {
|
|
133
|
+
switch(_state.label){
|
|
134
|
+
case 0:
|
|
135
|
+
babelConfig = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
|
|
136
|
+
rootDir = option.rootDir, enableVirtualDist = option.enableVirtualDist, filenames = option.filenames, clean = option.clean, distDir = option.distDir, _distFileExtMap = option.distFileExtMap, distFileExtMap = _distFileExtMap === void 0 ? defaultDistFileExtMap : _distFileExtMap, _verbose = option.verbose, verbose = _verbose === void 0 ? false : _verbose, _quiet = option.quiet, quiet = _quiet === void 0 ? false : _quiet;
|
|
137
|
+
virtualDists = [];
|
|
138
|
+
if (!clean) return [
|
|
139
|
+
3,
|
|
140
|
+
2
|
|
141
|
+
];
|
|
142
|
+
return [
|
|
143
|
+
4,
|
|
144
|
+
fs.remove(distDir)
|
|
145
|
+
];
|
|
146
|
+
case 1:
|
|
147
|
+
_state.sent();
|
|
148
|
+
_state.label = 2;
|
|
149
|
+
case 2:
|
|
150
|
+
fs.ensureDir(distDir);
|
|
151
|
+
messageDetails = [];
|
|
152
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
153
|
+
try {
|
|
154
|
+
for(_iterator = filenames[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
155
|
+
filename = _step.value;
|
|
156
|
+
try {
|
|
157
|
+
dist = compiler({
|
|
158
|
+
rootDir: rootDir,
|
|
159
|
+
enableVirtualDist: enableVirtualDist,
|
|
160
|
+
filepath: filename,
|
|
161
|
+
distDir: distDir,
|
|
162
|
+
verbose: verbose,
|
|
163
|
+
quiet: quiet,
|
|
164
|
+
babelConfig: babelConfig,
|
|
165
|
+
distFileExtMap: distFileExtMap
|
|
166
|
+
});
|
|
167
|
+
if (enableVirtualDist && dist) {
|
|
168
|
+
virtualDists.push(dist);
|
|
169
|
+
}
|
|
170
|
+
} catch (e) {
|
|
171
|
+
messageDetails.push({
|
|
172
|
+
filename: filename,
|
|
173
|
+
content: e.toString()
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} catch (err) {
|
|
178
|
+
_didIteratorError = true;
|
|
179
|
+
_iteratorError = err;
|
|
180
|
+
} finally{
|
|
181
|
+
try {
|
|
182
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
183
|
+
_iterator.return();
|
|
184
|
+
}
|
|
185
|
+
} finally{
|
|
186
|
+
if (_didIteratorError) {
|
|
187
|
+
throw _iteratorError;
|
|
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
|
+
];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
return function build(option) {
|
|
221
|
+
return _ref.apply(this, arguments);
|
|
222
|
+
};
|
|
223
|
+
}();
|
|
224
|
+
export { build };
|