@modern-js/babel-compiler 2.15.0 → 2.17.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/babel-compiler
|
|
2
2
|
|
|
3
|
+
## 2.17.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @modern-js/utils@2.17.0
|
|
8
|
+
|
|
9
|
+
## 2.16.0
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
14
|
+
|
|
15
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [5954330]
|
|
18
|
+
- Updated dependencies [7596520]
|
|
19
|
+
- Updated dependencies [4e876ab]
|
|
20
|
+
- @modern-js/utils@2.16.0
|
|
21
|
+
|
|
3
22
|
## 2.15.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/cjs/build.js
CHANGED
|
@@ -1,48 +1,25 @@
|
|
|
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 build_exports = {};
|
|
19
|
-
__export(build_exports, {
|
|
20
|
-
build: () => build
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
Object.defineProperty(exports, "build", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => build
|
|
8
|
+
});
|
|
9
|
+
const _utils = require("@modern-js/utils");
|
|
10
|
+
const _constants = require("./constants");
|
|
11
|
+
const _compiler = require("./compiler");
|
|
26
12
|
const build = async (option, babelConfig = {}) => {
|
|
27
|
-
const {
|
|
28
|
-
rootDir,
|
|
29
|
-
enableVirtualDist,
|
|
30
|
-
filenames,
|
|
31
|
-
clean,
|
|
32
|
-
distDir,
|
|
33
|
-
distFileExtMap = import_constants.defaultDistFileExtMap,
|
|
34
|
-
verbose = false,
|
|
35
|
-
quiet = false
|
|
36
|
-
} = option;
|
|
13
|
+
const { rootDir, enableVirtualDist, filenames, clean, distDir, distFileExtMap = _constants.defaultDistFileExtMap, verbose = false, quiet = false } = option;
|
|
37
14
|
const virtualDists = [];
|
|
38
15
|
if (clean) {
|
|
39
|
-
await
|
|
16
|
+
await _utils.fs.remove(distDir);
|
|
40
17
|
}
|
|
41
|
-
|
|
18
|
+
_utils.fs.ensureDir(distDir);
|
|
42
19
|
const messageDetails = [];
|
|
43
20
|
for (const filename of filenames) {
|
|
44
21
|
try {
|
|
45
|
-
const dist = (0,
|
|
22
|
+
const dist = (0, _compiler.compiler)({
|
|
46
23
|
rootDir,
|
|
47
24
|
enableVirtualDist,
|
|
48
25
|
filepath: filename,
|
|
@@ -65,13 +42,9 @@ const build = async (option, babelConfig = {}) => {
|
|
|
65
42
|
const happenError = messageDetails.length > 0;
|
|
66
43
|
if (!quiet) {
|
|
67
44
|
if (happenError) {
|
|
68
|
-
|
|
69
|
-
`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`
|
|
70
|
-
);
|
|
45
|
+
_utils.logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`);
|
|
71
46
|
} else {
|
|
72
|
-
|
|
73
|
-
`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`
|
|
74
|
-
);
|
|
47
|
+
_utils.logger.info(`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`);
|
|
75
48
|
}
|
|
76
49
|
}
|
|
77
50
|
if (happenError) {
|
|
@@ -87,7 +60,3 @@ const build = async (option, babelConfig = {}) => {
|
|
|
87
60
|
virtualDists
|
|
88
61
|
};
|
|
89
62
|
};
|
|
90
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
-
0 && (module.exports = {
|
|
92
|
-
build
|
|
93
|
-
});
|
package/dist/cjs/buildWatch.js
CHANGED
|
@@ -1,49 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 buildWatch_exports = {};
|
|
29
|
-
__export(buildWatch_exports, {
|
|
30
|
-
BuildWatchEmitter: () => BuildWatchEmitter,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
31
13
|
BuildWatchEvent: () => BuildWatchEvent,
|
|
32
|
-
|
|
33
|
-
runBuildWatch: () => runBuildWatch
|
|
14
|
+
BuildWatchEmitter: () => BuildWatchEmitter,
|
|
15
|
+
runBuildWatch: () => runBuildWatch,
|
|
16
|
+
buildWatch: () => buildWatch
|
|
34
17
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
19
|
+
const _events = /* @__PURE__ */ _interop_require_wildcard(require("events"));
|
|
20
|
+
const _utils = require("@modern-js/utils");
|
|
21
|
+
const _build = require("./build");
|
|
22
|
+
const _compilerErrorResult = require("./compilerErrorResult");
|
|
23
|
+
function _define_property(obj, key, value) {
|
|
24
|
+
if (key in obj) {
|
|
25
|
+
Object.defineProperty(obj, key, {
|
|
26
|
+
value,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
37
|
+
if (typeof WeakMap !== "function")
|
|
38
|
+
return null;
|
|
39
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
40
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
41
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
42
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
43
|
+
})(nodeInterop);
|
|
44
|
+
}
|
|
45
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
46
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
50
|
+
return {
|
|
51
|
+
default: obj
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
55
|
+
if (cache && cache.has(obj)) {
|
|
56
|
+
return cache.get(obj);
|
|
57
|
+
}
|
|
58
|
+
var newObj = {};
|
|
59
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
60
|
+
for (var key in obj) {
|
|
61
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
62
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
63
|
+
if (desc && (desc.get || desc.set)) {
|
|
64
|
+
Object.defineProperty(newObj, key, desc);
|
|
65
|
+
} else {
|
|
66
|
+
newObj[key] = obj[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
newObj.default = obj;
|
|
71
|
+
if (cache) {
|
|
72
|
+
cache.set(obj, newObj);
|
|
73
|
+
}
|
|
74
|
+
return newObj;
|
|
75
|
+
}
|
|
41
76
|
const BuildWatchEvent = {
|
|
42
77
|
firstCompiler: "first-compiler",
|
|
43
78
|
compiling: "compiling",
|
|
44
79
|
watchingCompiler: "watching-compiler"
|
|
45
80
|
};
|
|
46
|
-
class BuildWatchEmitter extends
|
|
81
|
+
class BuildWatchEmitter extends _events.EventEmitter {
|
|
47
82
|
setInitFn(fn) {
|
|
48
83
|
this._initFn = fn;
|
|
49
84
|
}
|
|
@@ -53,13 +88,17 @@ class BuildWatchEmitter extends Event.EventEmitter {
|
|
|
53
88
|
}
|
|
54
89
|
return null;
|
|
55
90
|
}
|
|
91
|
+
constructor(...args) {
|
|
92
|
+
super(...args);
|
|
93
|
+
_define_property(this, "_initFn", void 0);
|
|
94
|
+
}
|
|
56
95
|
}
|
|
57
96
|
const runBuildWatch = async (option, babelConfig = {}, emitter) => {
|
|
58
97
|
emitter.emit(BuildWatchEvent.compiling);
|
|
59
|
-
const errorResult = new
|
|
98
|
+
const errorResult = new _compilerErrorResult.CompilerErrorResult();
|
|
60
99
|
const watchDir = option.watchDir;
|
|
61
100
|
const { distDir, quiet } = option;
|
|
62
|
-
const firstBuildResult = await (0,
|
|
101
|
+
const firstBuildResult = await (0, _build.build)(option, babelConfig);
|
|
63
102
|
const { code } = firstBuildResult;
|
|
64
103
|
if (code === 1) {
|
|
65
104
|
errorResult.init(firstBuildResult);
|
|
@@ -67,61 +106,52 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
|
|
|
67
106
|
} else {
|
|
68
107
|
emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
69
108
|
}
|
|
70
|
-
return (0,
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
)
|
|
79
|
-
];
|
|
80
|
-
if (!quiet) {
|
|
81
|
-
import_utils.logger.info(`remove file: ${removeFiles.join(",")}`);
|
|
82
|
-
}
|
|
83
|
-
const result2 = {
|
|
84
|
-
code: 0,
|
|
85
|
-
message: `remove file: ${removeFiles.join(",")}`,
|
|
86
|
-
removeFiles
|
|
87
|
-
};
|
|
88
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, result2);
|
|
89
|
-
return;
|
|
109
|
+
return (0, _utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({ changeType, changedFilePath }) => {
|
|
110
|
+
emitter.emit(BuildWatchEvent.compiling);
|
|
111
|
+
if (changeType === _utils.WatchChangeType.UNLINK) {
|
|
112
|
+
const removeFiles = [
|
|
113
|
+
_path.normalize(`./${distDir}/${_path.relative(watchDir, changedFilePath)}`)
|
|
114
|
+
];
|
|
115
|
+
if (!quiet) {
|
|
116
|
+
_utils.logger.info(`remove file: ${removeFiles.join(",")}`);
|
|
90
117
|
}
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
const result2 = {
|
|
119
|
+
code: 0,
|
|
120
|
+
message: `remove file: ${removeFiles.join(",")}`,
|
|
121
|
+
removeFiles
|
|
122
|
+
};
|
|
123
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result2);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const result = await (0, _build.build)({
|
|
127
|
+
...option,
|
|
128
|
+
filenames: [
|
|
129
|
+
changedFilePath
|
|
130
|
+
]
|
|
131
|
+
}, babelConfig);
|
|
132
|
+
if (result.code === 1) {
|
|
133
|
+
errorResult.update(result.messageDetails || []);
|
|
134
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
|
|
135
|
+
!quiet && _utils.logger.info(errorResult.value.message);
|
|
136
|
+
} else {
|
|
137
|
+
errorResult.removeByFileName(changedFilePath);
|
|
138
|
+
if (errorResult.checkExistError()) {
|
|
139
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, {
|
|
140
|
+
...errorResult.value,
|
|
141
|
+
virtualDists: result.virtualDists
|
|
142
|
+
});
|
|
143
|
+
!quiet && _utils.logger.info(errorResult.value.message);
|
|
99
144
|
} else {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, {
|
|
103
|
-
...errorResult.value,
|
|
104
|
-
virtualDists: result.virtualDists
|
|
105
|
-
});
|
|
106
|
-
!quiet && import_utils.logger.info(errorResult.value.message);
|
|
107
|
-
} else {
|
|
108
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, result);
|
|
109
|
-
!quiet && import_utils.logger.info(result.message);
|
|
110
|
-
}
|
|
145
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result);
|
|
146
|
+
!quiet && _utils.logger.info(result.message);
|
|
111
147
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
148
|
+
}
|
|
149
|
+
}, [
|
|
150
|
+
`${watchDir}/**/*.d.ts`
|
|
151
|
+
]);
|
|
115
152
|
};
|
|
116
153
|
const buildWatch = (option, babelConfig = {}) => {
|
|
117
154
|
const buildWatchEmitter = new BuildWatchEmitter();
|
|
118
155
|
buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
|
|
119
156
|
return buildWatchEmitter;
|
|
120
157
|
};
|
|
121
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
-
0 && (module.exports = {
|
|
123
|
-
BuildWatchEmitter,
|
|
124
|
-
BuildWatchEvent,
|
|
125
|
-
buildWatch,
|
|
126
|
-
runBuildWatch
|
|
127
|
-
});
|
package/dist/cjs/compiler.js
CHANGED
|
@@ -1,66 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 compiler_exports = {};
|
|
29
|
-
__export(compiler_exports, {
|
|
30
|
-
compiler: () => compiler,
|
|
31
|
-
getDistFilePath: () => getDistFilePath,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
32
13
|
isRes: () => isRes,
|
|
33
|
-
|
|
14
|
+
getDistFilePath: () => getDistFilePath,
|
|
15
|
+
resolveSourceMap: () => resolveSourceMap,
|
|
16
|
+
compiler: () => compiler
|
|
34
17
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
19
|
+
const _core = /* @__PURE__ */ _interop_require_wildcard(require("@babel/core"));
|
|
20
|
+
const _utils = require("@modern-js/utils");
|
|
21
|
+
const _utils1 = /* @__PURE__ */ _interop_require_wildcard(require("./utils"));
|
|
22
|
+
const _constants = require("./constants");
|
|
23
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
24
|
+
if (typeof WeakMap !== "function")
|
|
25
|
+
return null;
|
|
26
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
29
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
30
|
+
})(nodeInterop);
|
|
31
|
+
}
|
|
32
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
33
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
37
|
+
return {
|
|
38
|
+
default: obj
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
42
|
+
if (cache && cache.has(obj)) {
|
|
43
|
+
return cache.get(obj);
|
|
44
|
+
}
|
|
45
|
+
var newObj = {};
|
|
46
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
47
|
+
for (var key in obj) {
|
|
48
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
49
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
50
|
+
if (desc && (desc.get || desc.set)) {
|
|
51
|
+
Object.defineProperty(newObj, key, desc);
|
|
52
|
+
} else {
|
|
53
|
+
newObj[key] = obj[key];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
newObj.default = obj;
|
|
58
|
+
if (cache) {
|
|
59
|
+
cache.set(obj, newObj);
|
|
60
|
+
}
|
|
61
|
+
return newObj;
|
|
62
|
+
}
|
|
41
63
|
const defaultDistDir = "dist";
|
|
42
64
|
const isRes = (r) => Boolean(r);
|
|
43
65
|
const getDistFilePath = (option) => {
|
|
44
66
|
const { filepath, rootDir, distDir, extMap } = option;
|
|
45
|
-
const ext =
|
|
46
|
-
return
|
|
47
|
-
distDir,
|
|
48
|
-
path.relative(rootDir, filepath).replace(ext, extMap[ext])
|
|
49
|
-
);
|
|
67
|
+
const ext = _path.extname(filepath);
|
|
68
|
+
return _path.join(distDir, _path.relative(rootDir, filepath).replace(ext, extMap[ext]));
|
|
50
69
|
};
|
|
51
70
|
const resolveSourceMap = (option) => {
|
|
52
|
-
const {
|
|
53
|
-
babelRes,
|
|
54
|
-
sourceFilePath,
|
|
55
|
-
distFilePath,
|
|
56
|
-
enableVirtualDist = false
|
|
57
|
-
} = option;
|
|
71
|
+
const { babelRes, sourceFilePath, distFilePath, enableVirtualDist = false } = option;
|
|
58
72
|
const mapLoc = `${distFilePath}.map`;
|
|
59
|
-
babelRes.code =
|
|
73
|
+
babelRes.code = _utils1.addSourceMappingUrl(babelRes.code, mapLoc);
|
|
60
74
|
if (babelRes.map) {
|
|
61
|
-
babelRes.map.file =
|
|
75
|
+
babelRes.map.file = _path.basename(distFilePath);
|
|
62
76
|
babelRes.map.sources = [
|
|
63
|
-
|
|
77
|
+
_path.relative(_path.dirname(distFilePath), sourceFilePath)
|
|
64
78
|
];
|
|
65
79
|
}
|
|
66
80
|
const sourceMapVirtualDist = {
|
|
@@ -70,22 +84,13 @@ const resolveSourceMap = (option) => {
|
|
|
70
84
|
if (enableVirtualDist) {
|
|
71
85
|
return sourceMapVirtualDist;
|
|
72
86
|
}
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
_utils.fs.ensureDirSync(_path.dirname(mapLoc));
|
|
88
|
+
_utils.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
75
89
|
return sourceMapVirtualDist;
|
|
76
90
|
};
|
|
77
91
|
const compiler = (option) => {
|
|
78
|
-
const {
|
|
79
|
-
|
|
80
|
-
rootDir,
|
|
81
|
-
enableVirtualDist = false,
|
|
82
|
-
distDir = path.join(path.dirname(rootDir), defaultDistDir),
|
|
83
|
-
verbose = false,
|
|
84
|
-
babelConfig = {},
|
|
85
|
-
distFileExtMap = import_constants.defaultDistFileExtMap,
|
|
86
|
-
quiet = false
|
|
87
|
-
} = option;
|
|
88
|
-
const babelRes = babel.transformFileSync(filepath, babelConfig);
|
|
92
|
+
const { filepath, rootDir, enableVirtualDist = false, distDir = _path.join(_path.dirname(rootDir), defaultDistDir), verbose = false, babelConfig = {}, distFileExtMap = _constants.defaultDistFileExtMap, quiet = false } = option;
|
|
93
|
+
const babelRes = _core.transformFileSync(filepath, babelConfig);
|
|
89
94
|
let virtualDist = null;
|
|
90
95
|
if (!isRes(babelRes)) {
|
|
91
96
|
throw new Error(`${filepath} happen error`);
|
|
@@ -104,7 +109,7 @@ const compiler = (option) => {
|
|
|
104
109
|
sourcemap: ""
|
|
105
110
|
};
|
|
106
111
|
}
|
|
107
|
-
if ((babelRes
|
|
112
|
+
if ((babelRes === null || babelRes === void 0 ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
|
|
108
113
|
if (virtualDist) {
|
|
109
114
|
virtualDist = {
|
|
110
115
|
...virtualDist,
|
|
@@ -131,18 +136,11 @@ const compiler = (option) => {
|
|
|
131
136
|
code: babelRes.code
|
|
132
137
|
};
|
|
133
138
|
} else {
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
_utils.fs.ensureDirSync(_path.dirname(distFilePath));
|
|
140
|
+
_utils.fs.writeFileSync(distFilePath, babelRes.code);
|
|
136
141
|
}
|
|
137
142
|
if (verbose && !quiet) {
|
|
138
|
-
|
|
143
|
+
_utils.logger.info(`${filepath} => ${distFilePath}`);
|
|
139
144
|
}
|
|
140
145
|
return virtualDist;
|
|
141
146
|
};
|
|
142
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
-
0 && (module.exports = {
|
|
144
|
-
compiler,
|
|
145
|
-
getDistFilePath,
|
|
146
|
-
isRes,
|
|
147
|
-
resolveSourceMap
|
|
148
|
-
});
|
|
@@ -1,31 +1,27 @@
|
|
|
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 compilerErrorResult_exports = {};
|
|
19
|
-
__export(compilerErrorResult_exports, {
|
|
20
|
-
CompilerErrorResult: () => CompilerErrorResult
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
Object.defineProperty(exports, "CompilerErrorResult", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => CompilerErrorResult
|
|
8
|
+
});
|
|
9
|
+
function _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
26
19
|
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
class CompilerErrorResult {
|
|
27
23
|
init(initErrorResult) {
|
|
28
|
-
this._messageDetails = (initErrorResult
|
|
24
|
+
this._messageDetails = (initErrorResult === null || initErrorResult === void 0 ? void 0 : initErrorResult.messageDetails) || [];
|
|
29
25
|
}
|
|
30
26
|
update(messageDetails) {
|
|
31
27
|
for (const messageDetail of messageDetails) {
|
|
@@ -42,23 +38,21 @@ class CompilerErrorResult {
|
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
removeByFileName(filename) {
|
|
45
|
-
this._messageDetails = this._messageDetails.filter(
|
|
46
|
-
(detail) => detail.filename !== filename
|
|
47
|
-
);
|
|
41
|
+
this._messageDetails = this._messageDetails.filter((detail) => detail.filename !== filename);
|
|
48
42
|
}
|
|
49
43
|
get value() {
|
|
50
|
-
var
|
|
44
|
+
var _this__messageDetails;
|
|
51
45
|
return {
|
|
52
46
|
code: 1,
|
|
53
|
-
message: `Compilation failure ${(
|
|
47
|
+
message: `Compilation failure ${(_this__messageDetails = this._messageDetails) === null || _this__messageDetails === void 0 ? void 0 : _this__messageDetails.length} files with Babel.`,
|
|
54
48
|
messageDetails: this._messageDetails
|
|
55
49
|
};
|
|
56
50
|
}
|
|
57
51
|
checkExistError() {
|
|
58
52
|
return this._messageDetails.length > 0;
|
|
59
53
|
}
|
|
54
|
+
constructor(initErrorResult) {
|
|
55
|
+
_define_property(this, "_messageDetails", void 0);
|
|
56
|
+
this.init(initErrorResult);
|
|
57
|
+
}
|
|
60
58
|
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
CompilerErrorResult
|
|
64
|
-
});
|
package/dist/cjs/constants.js
CHANGED
|
@@ -1,32 +1,14 @@
|
|
|
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var constants_exports = {};
|
|
19
|
-
__export(constants_exports, {
|
|
20
|
-
defaultDistFileExtMap: () => defaultDistFileExtMap
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "defaultDistFileExtMap", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => defaultDistFileExtMap
|
|
21
8
|
});
|
|
22
|
-
module.exports = __toCommonJS(constants_exports);
|
|
23
9
|
const defaultDistFileExtMap = {
|
|
24
10
|
".js": ".js",
|
|
25
11
|
".jsx": ".js",
|
|
26
12
|
".ts": ".js",
|
|
27
13
|
".tsx": ".js"
|
|
28
14
|
};
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
defaultDistFileExtMap
|
|
32
|
-
});
|