@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/cjs/defaults.js
CHANGED
|
@@ -1,32 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 defaults_exports = {};
|
|
19
|
-
__export(defaults_exports, {
|
|
20
|
-
mergeDefaultOption: () => mergeDefaultOption
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
Object.defineProperty(exports, "mergeDefaultOption", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => mergeDefaultOption
|
|
8
|
+
});
|
|
9
|
+
const _constants = require("./constants");
|
|
24
10
|
const defaultOptions = {
|
|
25
11
|
enableWatch: false,
|
|
26
12
|
enableVirtualDist: false,
|
|
27
13
|
extensions: [],
|
|
28
14
|
filenames: [],
|
|
29
|
-
distFileExtMap:
|
|
15
|
+
distFileExtMap: _constants.defaultDistFileExtMap,
|
|
30
16
|
ignore: [],
|
|
31
17
|
quiet: false,
|
|
32
18
|
verbose: false,
|
|
@@ -36,7 +22,3 @@ const mergeDefaultOption = (compilerOptions) => ({
|
|
|
36
22
|
...defaultOptions,
|
|
37
23
|
...compilerOptions
|
|
38
24
|
});
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 && (module.exports = {
|
|
41
|
-
mergeDefaultOption
|
|
42
|
-
});
|
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var getFinalOption_exports = {};
|
|
19
|
-
__export(getFinalOption_exports, {
|
|
20
|
-
getFilesFromDir: () => getFilesFromDir,
|
|
21
|
-
getFinalCompilerOption: () => getFinalCompilerOption,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
getGlobPattern: () => getGlobPattern,
|
|
22
14
|
getFinalExtensions: () => getFinalExtensions,
|
|
23
|
-
|
|
15
|
+
getFilesFromDir: () => getFilesFromDir,
|
|
16
|
+
getFinalCompilerOption: () => getFinalCompilerOption
|
|
24
17
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var import_defaults = require("./defaults");
|
|
18
|
+
const _utils = require("@modern-js/utils");
|
|
19
|
+
const _core = require("@babel/core");
|
|
20
|
+
const _defaults = require("./defaults");
|
|
29
21
|
const getGlobPattern = (dir, extensions) => {
|
|
30
22
|
if (extensions.length > 1) {
|
|
31
23
|
return `${dir}/**/*{${extensions.join(",")}}`;
|
|
@@ -39,32 +31,27 @@ const getFinalExtensions = (extensions) => {
|
|
|
39
31
|
const isExtensions = (ext) => Array.isArray(ext);
|
|
40
32
|
const isExtensionsFunc = (ext) => typeof ext === "function";
|
|
41
33
|
if (isExtensions(extensions)) {
|
|
42
|
-
return [
|
|
34
|
+
return [
|
|
35
|
+
...extensions,
|
|
36
|
+
..._core.DEFAULT_EXTENSIONS
|
|
37
|
+
];
|
|
43
38
|
} else if (isExtensionsFunc(extensions)) {
|
|
44
|
-
return extensions(
|
|
39
|
+
return extensions(_core.DEFAULT_EXTENSIONS);
|
|
45
40
|
} else {
|
|
46
|
-
return
|
|
41
|
+
return _core.DEFAULT_EXTENSIONS;
|
|
47
42
|
}
|
|
48
43
|
};
|
|
49
|
-
const getFilesFromDir = ({
|
|
50
|
-
dir,
|
|
51
|
-
finalExt = [],
|
|
52
|
-
ignore = []
|
|
53
|
-
}) => {
|
|
44
|
+
const getFilesFromDir = ({ dir, finalExt = [], ignore = [] }) => {
|
|
54
45
|
let globFindFilenames = [];
|
|
55
46
|
const globPattern = getGlobPattern(dir, finalExt);
|
|
56
|
-
globFindFilenames =
|
|
47
|
+
globFindFilenames = _utils.glob.sync(globPattern, {
|
|
48
|
+
ignore
|
|
49
|
+
});
|
|
57
50
|
return globFindFilenames;
|
|
58
51
|
};
|
|
59
52
|
const getFinalCompilerOption = (option) => {
|
|
60
|
-
const optionWithDefault = (0,
|
|
61
|
-
const {
|
|
62
|
-
sourceDir,
|
|
63
|
-
ignore,
|
|
64
|
-
enableWatch = false,
|
|
65
|
-
watchDir,
|
|
66
|
-
extensions = import_core.DEFAULT_EXTENSIONS
|
|
67
|
-
} = option;
|
|
53
|
+
const optionWithDefault = (0, _defaults.mergeDefaultOption)(option);
|
|
54
|
+
const { sourceDir, ignore, enableWatch = false, watchDir, extensions = _core.DEFAULT_EXTENSIONS } = option;
|
|
68
55
|
let globFindFilenames = [];
|
|
69
56
|
const finalExt = getFinalExtensions(extensions);
|
|
70
57
|
if (sourceDir) {
|
|
@@ -83,13 +70,9 @@ const getFinalCompilerOption = (option) => {
|
|
|
83
70
|
}
|
|
84
71
|
return {
|
|
85
72
|
...optionWithDefault,
|
|
86
|
-
filenames: [
|
|
73
|
+
filenames: [
|
|
74
|
+
...optionWithDefault.filenames,
|
|
75
|
+
...globFindFilenames
|
|
76
|
+
]
|
|
87
77
|
};
|
|
88
78
|
};
|
|
89
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
-
0 && (module.exports = {
|
|
91
|
-
getFilesFromDir,
|
|
92
|
-
getFinalCompilerOption,
|
|
93
|
-
getFinalExtensions,
|
|
94
|
-
getGlobPattern
|
|
95
|
-
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 __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 src_exports = {};
|
|
20
|
-
__export(src_exports, {
|
|
21
|
-
compiler: () => compiler
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "compiler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => compiler
|
|
22
8
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
9
|
+
const _getFinalOption = require("./getFinalOption");
|
|
10
|
+
const _build = require("./build");
|
|
11
|
+
const _buildWatch = _export_star(require("./buildWatch"), exports);
|
|
12
|
+
const _validate = require("./validate");
|
|
13
|
+
_export_star(require("./type"), exports);
|
|
14
|
+
function _export_star(from, to) {
|
|
15
|
+
Object.keys(from).forEach(function(k) {
|
|
16
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
17
|
+
Object.defineProperty(to, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return from[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return from;
|
|
26
|
+
}
|
|
30
27
|
async function compiler(compilerOptions, babelOptions = {}) {
|
|
31
|
-
const validRet = (0,
|
|
28
|
+
const validRet = (0, _validate.validate)(compilerOptions);
|
|
32
29
|
if (validRet) {
|
|
33
30
|
return validRet;
|
|
34
31
|
}
|
|
35
|
-
const finalCompilerOption = (0,
|
|
32
|
+
const finalCompilerOption = (0, _getFinalOption.getFinalCompilerOption)(compilerOptions);
|
|
36
33
|
if (compilerOptions.enableWatch) {
|
|
37
|
-
return (0,
|
|
34
|
+
return (0, _buildWatch.buildWatch)(finalCompilerOption, babelOptions);
|
|
38
35
|
} else {
|
|
39
|
-
return (0,
|
|
36
|
+
return (0, _build.build)(finalCompilerOption, babelOptions);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
-
0 && (module.exports = {
|
|
44
|
-
compiler
|
|
45
|
-
});
|
package/dist/cjs/type.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,41 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var utils_exports = {};
|
|
29
|
-
__export(utils_exports, {
|
|
30
|
-
addSourceMappingUrl: () => addSourceMappingUrl
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "addSourceMappingUrl", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => addSourceMappingUrl
|
|
31
8
|
});
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
11
|
+
if (typeof WeakMap !== "function")
|
|
12
|
+
return null;
|
|
13
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
16
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
17
|
+
})(nodeInterop);
|
|
18
|
+
}
|
|
19
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
20
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
24
|
+
return {
|
|
25
|
+
default: obj
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
29
|
+
if (cache && cache.has(obj)) {
|
|
30
|
+
return cache.get(obj);
|
|
31
|
+
}
|
|
32
|
+
var newObj = {};
|
|
33
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
34
|
+
for (var key in obj) {
|
|
35
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
36
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
37
|
+
if (desc && (desc.get || desc.set)) {
|
|
38
|
+
Object.defineProperty(newObj, key, desc);
|
|
39
|
+
} else {
|
|
40
|
+
newObj[key] = obj[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
newObj.default = obj;
|
|
45
|
+
if (cache) {
|
|
46
|
+
cache.set(obj, newObj);
|
|
47
|
+
}
|
|
48
|
+
return newObj;
|
|
49
|
+
}
|
|
34
50
|
function addSourceMappingUrl(code, loc) {
|
|
35
51
|
return `${code}
|
|
36
|
-
//# sourceMappingURL=${
|
|
52
|
+
//# sourceMappingURL=${_path.normalize(_path.basename(loc))}`;
|
|
37
53
|
}
|
|
38
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
-
0 && (module.exports = {
|
|
40
|
-
addSourceMappingUrl
|
|
41
|
-
});
|
package/dist/cjs/validate.js
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
sourceDirAndFileNamesValidMessage: () => sourceDirAndFileNamesValidMessage,
|
|
21
|
-
|
|
14
|
+
watchDirValidMessage: () => watchDirValidMessage,
|
|
22
15
|
validateSourceDirAndFileNames: () => validateSourceDirAndFileNames,
|
|
23
16
|
validateWatchDir: () => validateWatchDir,
|
|
24
|
-
|
|
17
|
+
validate: () => validate
|
|
25
18
|
});
|
|
26
|
-
|
|
27
|
-
var import_utils = require("@modern-js/utils");
|
|
19
|
+
const _utils = require("@modern-js/utils");
|
|
28
20
|
const sourceDirAndFileNamesValidMessage = "At least one of the sourceDir and filenames configurations must be configured";
|
|
29
21
|
const watchDirValidMessage = "should set watchDir when enableWatch is true";
|
|
30
22
|
const validateSourceDirAndFileNames = (compilerOptions) => {
|
|
31
23
|
const { sourceDir, filenames, quiet } = compilerOptions;
|
|
32
24
|
if (!sourceDir && !filenames) {
|
|
33
25
|
if (!quiet) {
|
|
34
|
-
|
|
26
|
+
_utils.logger.error(sourceDirAndFileNamesValidMessage);
|
|
35
27
|
}
|
|
36
28
|
return {
|
|
37
29
|
code: 1,
|
|
@@ -45,9 +37,13 @@ const validateWatchDir = (compilerOptions) => {
|
|
|
45
37
|
const { watchDir, enableWatch, quiet } = compilerOptions;
|
|
46
38
|
if (enableWatch && !watchDir) {
|
|
47
39
|
if (!quiet) {
|
|
48
|
-
|
|
40
|
+
_utils.logger.error(watchDirValidMessage);
|
|
49
41
|
}
|
|
50
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
code: 1,
|
|
44
|
+
message: watchDirValidMessage,
|
|
45
|
+
virtualDists: []
|
|
46
|
+
};
|
|
51
47
|
}
|
|
52
48
|
return null;
|
|
53
49
|
};
|
|
@@ -57,11 +53,3 @@ const validate = (compilerOptions) => {
|
|
|
57
53
|
}
|
|
58
54
|
return validateSourceDirAndFileNames(compilerOptions);
|
|
59
55
|
};
|
|
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
|
-
});
|