@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/compiler.js
CHANGED
|
@@ -1,34 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var compiler_exports = {};
|
|
42
|
+
__export(compiler_exports, {
|
|
43
|
+
compiler: () => compiler,
|
|
44
|
+
getDistFilePath: () => getDistFilePath,
|
|
45
|
+
isRes: () => isRes,
|
|
46
|
+
resolveSourceMap: () => resolveSourceMap
|
|
5
47
|
});
|
|
6
|
-
|
|
7
|
-
var path =
|
|
8
|
-
var babel =
|
|
9
|
-
var
|
|
10
|
-
var utils =
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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; }
|
|
17
|
-
const defaultDistDir = 'dist';
|
|
18
|
-
const isRes = r => Boolean(r);
|
|
19
|
-
exports.isRes = isRes;
|
|
20
|
-
const getDistFilePath = option => {
|
|
21
|
-
const {
|
|
22
|
-
filepath,
|
|
23
|
-
rootDir,
|
|
24
|
-
distDir,
|
|
25
|
-
extMap
|
|
26
|
-
} = option;
|
|
48
|
+
module.exports = __toCommonJS(compiler_exports);
|
|
49
|
+
var path = __toESM(require("path"));
|
|
50
|
+
var babel = __toESM(require("@babel/core"));
|
|
51
|
+
var import_utils = require("@modern-js/utils");
|
|
52
|
+
var utils = __toESM(require("./utils"));
|
|
53
|
+
var import_constants = require("./constants");
|
|
54
|
+
const defaultDistDir = "dist";
|
|
55
|
+
const isRes = (r) => Boolean(r);
|
|
56
|
+
const getDistFilePath = (option) => {
|
|
57
|
+
const { filepath, rootDir, distDir, extMap } = option;
|
|
27
58
|
const ext = path.extname(filepath);
|
|
28
|
-
return path.join(
|
|
59
|
+
return path.join(
|
|
60
|
+
distDir,
|
|
61
|
+
path.relative(rootDir, filepath).replace(ext, extMap[ext])
|
|
62
|
+
);
|
|
29
63
|
};
|
|
30
|
-
|
|
31
|
-
const resolveSourceMap = option => {
|
|
64
|
+
const resolveSourceMap = (option) => {
|
|
32
65
|
const {
|
|
33
66
|
babelRes,
|
|
34
67
|
sourceFilePath,
|
|
@@ -39,7 +72,9 @@ const resolveSourceMap = option => {
|
|
|
39
72
|
babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
|
|
40
73
|
if (babelRes.map) {
|
|
41
74
|
babelRes.map.file = path.basename(distFilePath);
|
|
42
|
-
babelRes.map.sources = [
|
|
75
|
+
babelRes.map.sources = [
|
|
76
|
+
path.relative(path.dirname(distFilePath), sourceFilePath)
|
|
77
|
+
];
|
|
43
78
|
}
|
|
44
79
|
const sourceMapVirtualDist = {
|
|
45
80
|
sourcemap: JSON.stringify(babelRes.map),
|
|
@@ -48,12 +83,11 @@ const resolveSourceMap = option => {
|
|
|
48
83
|
if (enableVirtualDist) {
|
|
49
84
|
return sourceMapVirtualDist;
|
|
50
85
|
}
|
|
51
|
-
|
|
52
|
-
|
|
86
|
+
import_utils.fs.ensureDirSync(path.dirname(mapLoc));
|
|
87
|
+
import_utils.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
53
88
|
return sourceMapVirtualDist;
|
|
54
89
|
};
|
|
55
|
-
|
|
56
|
-
const compiler = option => {
|
|
90
|
+
const compiler = (option) => {
|
|
57
91
|
const {
|
|
58
92
|
filepath,
|
|
59
93
|
rootDir,
|
|
@@ -61,7 +95,7 @@ const compiler = option => {
|
|
|
61
95
|
distDir = path.join(path.dirname(rootDir), defaultDistDir),
|
|
62
96
|
verbose = false,
|
|
63
97
|
babelConfig = {},
|
|
64
|
-
distFileExtMap =
|
|
98
|
+
distFileExtMap = import_constants.defaultDistFileExtMap,
|
|
65
99
|
quiet = false
|
|
66
100
|
} = option;
|
|
67
101
|
const babelRes = babel.transformFileSync(filepath, babelConfig);
|
|
@@ -78,14 +112,14 @@ const compiler = option => {
|
|
|
78
112
|
if (enableVirtualDist) {
|
|
79
113
|
virtualDist = {
|
|
80
114
|
distPath: distFilePath,
|
|
81
|
-
sourceMapPath:
|
|
82
|
-
code:
|
|
83
|
-
sourcemap:
|
|
115
|
+
sourceMapPath: "",
|
|
116
|
+
code: "",
|
|
117
|
+
sourcemap: ""
|
|
84
118
|
};
|
|
85
119
|
}
|
|
86
|
-
if (babelRes
|
|
120
|
+
if ((babelRes == null ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
|
|
87
121
|
if (virtualDist) {
|
|
88
|
-
virtualDist =
|
|
122
|
+
virtualDist = __spreadValues(__spreadValues({}, virtualDist), resolveSourceMap({
|
|
89
123
|
babelRes,
|
|
90
124
|
sourceFilePath: filepath,
|
|
91
125
|
distFilePath,
|
|
@@ -101,17 +135,23 @@ const compiler = option => {
|
|
|
101
135
|
}
|
|
102
136
|
}
|
|
103
137
|
if (virtualDist) {
|
|
104
|
-
virtualDist =
|
|
138
|
+
virtualDist = __spreadProps(__spreadValues({}, virtualDist), {
|
|
105
139
|
distPath: distFilePath,
|
|
106
140
|
code: babelRes.code
|
|
107
141
|
});
|
|
108
142
|
} else {
|
|
109
|
-
|
|
110
|
-
|
|
143
|
+
import_utils.fs.ensureDirSync(path.dirname(distFilePath));
|
|
144
|
+
import_utils.fs.writeFileSync(distFilePath, babelRes.code);
|
|
111
145
|
}
|
|
112
146
|
if (verbose && !quiet) {
|
|
113
|
-
|
|
147
|
+
import_utils.logger.info(`${filepath} => ${distFilePath}`);
|
|
114
148
|
}
|
|
115
149
|
return virtualDist;
|
|
116
150
|
};
|
|
117
|
-
|
|
151
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
152
|
+
0 && (module.exports = {
|
|
153
|
+
compiler,
|
|
154
|
+
getDistFilePath,
|
|
155
|
+
isRes,
|
|
156
|
+
resolveSourceMap
|
|
157
|
+
});
|
|
@@ -1,24 +1,36 @@
|
|
|
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 compilerErrorResult_exports = {};
|
|
19
|
+
__export(compilerErrorResult_exports, {
|
|
20
|
+
CompilerErrorResult: () => CompilerErrorResult
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
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; }
|
|
22
|
+
module.exports = __toCommonJS(compilerErrorResult_exports);
|
|
8
23
|
class CompilerErrorResult {
|
|
9
24
|
constructor(initErrorResult) {
|
|
10
|
-
_defineProperty(this, "_messageDetails", void 0);
|
|
11
25
|
this.init(initErrorResult);
|
|
12
26
|
}
|
|
13
27
|
init(initErrorResult) {
|
|
14
|
-
this._messageDetails = (initErrorResult
|
|
28
|
+
this._messageDetails = (initErrorResult == null ? void 0 : initErrorResult.messageDetails) || [];
|
|
15
29
|
}
|
|
16
30
|
update(messageDetails) {
|
|
17
31
|
for (const messageDetail of messageDetails) {
|
|
18
|
-
|
|
19
|
-
const addError = !this._messageDetails.some(detail => {
|
|
32
|
+
const addError = !this._messageDetails.some((detail) => {
|
|
20
33
|
if (detail.filename === messageDetail.filename) {
|
|
21
|
-
// 如果错误栈里存在该文件报错信息,则更新内容
|
|
22
34
|
detail.content = messageDetail.content;
|
|
23
35
|
return true;
|
|
24
36
|
}
|
|
@@ -30,13 +42,15 @@ class CompilerErrorResult {
|
|
|
30
42
|
}
|
|
31
43
|
}
|
|
32
44
|
removeByFileName(filename) {
|
|
33
|
-
this._messageDetails = this._messageDetails.filter(
|
|
45
|
+
this._messageDetails = this._messageDetails.filter(
|
|
46
|
+
(detail) => detail.filename !== filename
|
|
47
|
+
);
|
|
34
48
|
}
|
|
35
49
|
get value() {
|
|
36
|
-
var
|
|
50
|
+
var _a;
|
|
37
51
|
return {
|
|
38
52
|
code: 1,
|
|
39
|
-
message: `Compilation failure ${(
|
|
53
|
+
message: `Compilation failure ${(_a = this._messageDetails) == null ? void 0 : _a.length} files with Babel.`,
|
|
40
54
|
messageDetails: this._messageDetails
|
|
41
55
|
};
|
|
42
56
|
}
|
|
@@ -44,4 +58,7 @@ class CompilerErrorResult {
|
|
|
44
58
|
return this._messageDetails.length > 0;
|
|
45
59
|
}
|
|
46
60
|
}
|
|
47
|
-
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
CompilerErrorResult
|
|
64
|
+
});
|
|
@@ -1,13 +1,32 @@
|
|
|
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 constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
defaultDistFileExtMap: () => defaultDistFileExtMap
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
22
|
+
module.exports = __toCommonJS(constants_exports);
|
|
7
23
|
const defaultDistFileExtMap = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
24
|
+
".js": ".js",
|
|
25
|
+
".jsx": ".js",
|
|
26
|
+
".ts": ".js",
|
|
27
|
+
".tsx": ".js"
|
|
12
28
|
};
|
|
13
|
-
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
defaultDistFileExtMap
|
|
32
|
+
});
|
package/dist/js/node/defaults.js
CHANGED
|
@@ -1,23 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
var defaults_exports = {};
|
|
33
|
+
__export(defaults_exports, {
|
|
34
|
+
mergeDefaultOption: () => mergeDefaultOption
|
|
5
35
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
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; }
|
|
36
|
+
module.exports = __toCommonJS(defaults_exports);
|
|
37
|
+
var import_constants = require("./constants");
|
|
11
38
|
const defaultOptions = {
|
|
12
39
|
enableWatch: false,
|
|
13
40
|
enableVirtualDist: false,
|
|
14
41
|
extensions: [],
|
|
15
42
|
filenames: [],
|
|
16
|
-
distFileExtMap:
|
|
43
|
+
distFileExtMap: import_constants.defaultDistFileExtMap,
|
|
17
44
|
ignore: [],
|
|
18
45
|
quiet: false,
|
|
19
46
|
verbose: false,
|
|
20
47
|
clean: false
|
|
21
48
|
};
|
|
22
|
-
const mergeDefaultOption = compilerOptions =>
|
|
23
|
-
|
|
49
|
+
const mergeDefaultOption = (compilerOptions) => __spreadValues(__spreadValues({}, defaultOptions), compilerOptions);
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
mergeDefaultOption
|
|
53
|
+
});
|
|
@@ -1,58 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var getFinalOption_exports = {};
|
|
36
|
+
__export(getFinalOption_exports, {
|
|
37
|
+
getFilesFromDir: () => getFilesFromDir,
|
|
38
|
+
getFinalCompilerOption: () => getFinalCompilerOption,
|
|
39
|
+
getFinalExtensions: () => getFinalExtensions,
|
|
40
|
+
getGlobPattern: () => getGlobPattern
|
|
5
41
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
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; }
|
|
11
|
-
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; }
|
|
12
|
-
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; }
|
|
42
|
+
module.exports = __toCommonJS(getFinalOption_exports);
|
|
43
|
+
var import_utils = require("@modern-js/utils");
|
|
44
|
+
var import_core = require("@babel/core");
|
|
45
|
+
var import_defaults = require("./defaults");
|
|
13
46
|
const getGlobPattern = (dir, extensions) => {
|
|
14
47
|
if (extensions.length > 1) {
|
|
15
|
-
return `${dir}/**/*{${extensions.join(
|
|
48
|
+
return `${dir}/**/*{${extensions.join(",")}}`;
|
|
16
49
|
} else if (extensions.length === 1) {
|
|
17
50
|
return `${dir}/**/*${extensions[0]}`;
|
|
18
51
|
} else {
|
|
19
52
|
return `${dir}/**/*`;
|
|
20
53
|
}
|
|
21
54
|
};
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const isExtensionsFunc = ext => typeof ext === 'function';
|
|
55
|
+
const getFinalExtensions = (extensions) => {
|
|
56
|
+
const isExtensions = (ext) => Array.isArray(ext);
|
|
57
|
+
const isExtensionsFunc = (ext) => typeof ext === "function";
|
|
26
58
|
if (isExtensions(extensions)) {
|
|
27
|
-
return [...extensions, ...
|
|
59
|
+
return [...extensions, ...import_core.DEFAULT_EXTENSIONS];
|
|
28
60
|
} else if (isExtensionsFunc(extensions)) {
|
|
29
|
-
return extensions(
|
|
61
|
+
return extensions(import_core.DEFAULT_EXTENSIONS);
|
|
30
62
|
} else {
|
|
31
|
-
return
|
|
63
|
+
return import_core.DEFAULT_EXTENSIONS;
|
|
32
64
|
}
|
|
33
65
|
};
|
|
34
|
-
exports.getFinalExtensions = getFinalExtensions;
|
|
35
66
|
const getFilesFromDir = ({
|
|
36
67
|
dir,
|
|
37
|
-
finalExt
|
|
38
|
-
ignore
|
|
68
|
+
finalExt = [],
|
|
69
|
+
ignore = []
|
|
39
70
|
}) => {
|
|
40
71
|
let globFindFilenames = [];
|
|
41
|
-
const globPattern = getGlobPattern(dir,
|
|
42
|
-
globFindFilenames =
|
|
43
|
-
ignore: _ignore
|
|
44
|
-
});
|
|
72
|
+
const globPattern = getGlobPattern(dir, finalExt);
|
|
73
|
+
globFindFilenames = import_utils.glob.sync(globPattern, { ignore });
|
|
45
74
|
return globFindFilenames;
|
|
46
75
|
};
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const optionWithDefault = (0, _defaults.mergeDefaultOption)(option);
|
|
76
|
+
const getFinalCompilerOption = (option) => {
|
|
77
|
+
const optionWithDefault = (0, import_defaults.mergeDefaultOption)(option);
|
|
50
78
|
const {
|
|
51
79
|
sourceDir,
|
|
52
80
|
ignore,
|
|
53
81
|
enableWatch = false,
|
|
54
82
|
watchDir,
|
|
55
|
-
extensions =
|
|
83
|
+
extensions = import_core.DEFAULT_EXTENSIONS
|
|
56
84
|
} = option;
|
|
57
85
|
let globFindFilenames = [];
|
|
58
86
|
const finalExt = getFinalExtensions(extensions);
|
|
@@ -64,15 +92,20 @@ const getFinalCompilerOption = option => {
|
|
|
64
92
|
});
|
|
65
93
|
}
|
|
66
94
|
if (enableWatch) {
|
|
67
|
-
// 开启watch模式,清空通过 sourceDir 找到的文件,而改为使用watchDirs
|
|
68
95
|
globFindFilenames = getFilesFromDir({
|
|
69
96
|
dir: watchDir,
|
|
70
97
|
ignore,
|
|
71
98
|
finalExt
|
|
72
99
|
});
|
|
73
100
|
}
|
|
74
|
-
return
|
|
101
|
+
return __spreadProps(__spreadValues({}, optionWithDefault), {
|
|
75
102
|
filenames: [...optionWithDefault.filenames, ...globFindFilenames]
|
|
76
103
|
});
|
|
77
104
|
};
|
|
78
|
-
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
getFilesFromDir,
|
|
108
|
+
getFinalCompilerOption,
|
|
109
|
+
getFinalExtensions,
|
|
110
|
+
getGlobPattern
|
|
111
|
+
});
|
package/dist/js/node/index.js
CHANGED
|
@@ -1,48 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
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
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
22
37
|
});
|
|
38
|
+
};
|
|
39
|
+
var src_exports = {};
|
|
40
|
+
__export(src_exports, {
|
|
41
|
+
compiler: () => compiler
|
|
23
42
|
});
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
var import_getFinalOption = require("./getFinalOption");
|
|
45
|
+
var import_build = require("./build");
|
|
46
|
+
var import_buildWatch = require("./buildWatch");
|
|
47
|
+
var import_validate = require("./validate");
|
|
48
|
+
__reExport(src_exports, require("./buildWatch"), module.exports);
|
|
49
|
+
__reExport(src_exports, require("./type"), module.exports);
|
|
50
|
+
function compiler(_0) {
|
|
51
|
+
return __async(this, arguments, function* (compilerOptions, babelOptions = {}) {
|
|
52
|
+
const validRet = (0, import_validate.validate)(compilerOptions);
|
|
53
|
+
if (validRet) {
|
|
54
|
+
return validRet;
|
|
55
|
+
}
|
|
56
|
+
const finalCompilerOption = (0, import_getFinalOption.getFinalCompilerOption)(compilerOptions);
|
|
57
|
+
if (compilerOptions.enableWatch) {
|
|
58
|
+
return (0, import_buildWatch.buildWatch)(finalCompilerOption, babelOptions);
|
|
59
|
+
} else {
|
|
60
|
+
return (0, import_build.build)(finalCompilerOption, babelOptions);
|
|
34
61
|
}
|
|
35
62
|
});
|
|
63
|
+
}
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
compiler
|
|
36
67
|
});
|
|
37
|
-
async function compiler(compilerOptions, babelOptions = {}) {
|
|
38
|
-
const validRet = (0, _validate.validate)(compilerOptions);
|
|
39
|
-
if (validRet) {
|
|
40
|
-
return validRet;
|
|
41
|
-
}
|
|
42
|
-
const finalCompilerOption = (0, _getFinalOption.getFinalCompilerOption)(compilerOptions);
|
|
43
|
-
if (compilerOptions.enableWatch) {
|
|
44
|
-
return (0, _buildWatch.buildWatch)(finalCompilerOption, babelOptions);
|
|
45
|
-
} else {
|
|
46
|
-
return (0, _build.build)(finalCompilerOption, babelOptions);
|
|
47
|
-
}
|
|
48
|
-
}
|
package/dist/js/node/type.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var type_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(type_exports);
|