@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,66 @@
|
|
|
1
1
|
# @modern-js/babel-compiler
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.6
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7879e8f711]
|
|
12
|
+
- Updated dependencies [6aca875011]
|
|
13
|
+
- Updated dependencies [2e6031955e]
|
|
14
|
+
- Updated dependencies [7b7d12cf8f]
|
|
15
|
+
- Updated dependencies [7efeed4]
|
|
16
|
+
- Updated dependencies [92f0eade39]
|
|
17
|
+
- Updated dependencies [edd1cfb1af]
|
|
18
|
+
- Updated dependencies [cc971eabfc]
|
|
19
|
+
- Updated dependencies [5b9049f2e9]
|
|
20
|
+
- Updated dependencies [92004d1906]
|
|
21
|
+
- Updated dependencies [b8bbe036c7]
|
|
22
|
+
- Updated dependencies [d5a31df781]
|
|
23
|
+
- Updated dependencies [dda38c9c3e]
|
|
24
|
+
- Updated dependencies [3bbea92b2a]
|
|
25
|
+
- Updated dependencies [b710adb843]
|
|
26
|
+
- Updated dependencies [ea7cf06257]
|
|
27
|
+
- Updated dependencies [bbe4c4ab64]
|
|
28
|
+
- Updated dependencies [e4558a0bc4]
|
|
29
|
+
- Updated dependencies [abf3421a75]
|
|
30
|
+
- Updated dependencies [543be9558e]
|
|
31
|
+
- Updated dependencies [14b712da84]
|
|
32
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
33
|
+
|
|
34
|
+
## 2.0.0-beta.4
|
|
35
|
+
|
|
36
|
+
### Major Changes
|
|
37
|
+
|
|
38
|
+
- dda38c9c3e: chore: v2
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [7879e8f]
|
|
43
|
+
- Updated dependencies [6aca875]
|
|
44
|
+
- Updated dependencies [2e6031955e]
|
|
45
|
+
- Updated dependencies [7b7d12c]
|
|
46
|
+
- Updated dependencies [92f0eade39]
|
|
47
|
+
- Updated dependencies [edd1cfb1af]
|
|
48
|
+
- Updated dependencies [cc971eabfc]
|
|
49
|
+
- Updated dependencies [5b9049f2e9]
|
|
50
|
+
- Updated dependencies [92004d1906]
|
|
51
|
+
- Updated dependencies [b8bbe036c7]
|
|
52
|
+
- Updated dependencies [d5a31df781]
|
|
53
|
+
- Updated dependencies [dda38c9c3e]
|
|
54
|
+
- Updated dependencies [3bbea92b2a]
|
|
55
|
+
- Updated dependencies [b710adb843]
|
|
56
|
+
- Updated dependencies [ea7cf06]
|
|
57
|
+
- Updated dependencies [bbe4c4a]
|
|
58
|
+
- Updated dependencies [e4558a0]
|
|
59
|
+
- Updated dependencies [abf3421a75]
|
|
60
|
+
- Updated dependencies [543be9558e]
|
|
61
|
+
- Updated dependencies [14b712da84]
|
|
62
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
63
|
+
|
|
3
64
|
## 2.0.0-beta.3
|
|
4
65
|
|
|
5
66
|
### Major Changes
|
package/dist/js/modern/build.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { fs, logger } from "@modern-js/utils";
|
|
2
22
|
import { defaultDistFileExtMap } from "./constants";
|
|
3
23
|
import { compiler } from "./compiler";
|
|
4
|
-
|
|
24
|
+
const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}) {
|
|
5
25
|
const {
|
|
6
26
|
rootDir,
|
|
7
27
|
enableVirtualDist,
|
|
@@ -14,7 +34,7 @@ export const build = async (option, babelConfig = {}) => {
|
|
|
14
34
|
} = option;
|
|
15
35
|
const virtualDists = [];
|
|
16
36
|
if (clean) {
|
|
17
|
-
|
|
37
|
+
yield fs.remove(distDir);
|
|
18
38
|
}
|
|
19
39
|
fs.ensureDir(distDir);
|
|
20
40
|
const messageDetails = [];
|
|
@@ -43,22 +63,28 @@ export const build = async (option, babelConfig = {}) => {
|
|
|
43
63
|
const happenError = messageDetails.length > 0;
|
|
44
64
|
if (!quiet) {
|
|
45
65
|
if (happenError) {
|
|
46
|
-
logger.error(
|
|
47
|
-
|
|
66
|
+
logger.error(
|
|
67
|
+
`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`
|
|
68
|
+
);
|
|
48
69
|
} else {
|
|
49
|
-
logger.info(
|
|
70
|
+
logger.info(
|
|
71
|
+
`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`
|
|
72
|
+
);
|
|
50
73
|
}
|
|
51
74
|
}
|
|
52
75
|
if (happenError) {
|
|
53
76
|
return {
|
|
54
77
|
code: 1,
|
|
55
|
-
message: `Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ?
|
|
78
|
+
message: `Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`,
|
|
56
79
|
messageDetails
|
|
57
80
|
};
|
|
58
81
|
}
|
|
59
82
|
return {
|
|
60
83
|
code: 0,
|
|
61
|
-
message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ?
|
|
84
|
+
message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`,
|
|
62
85
|
virtualDists
|
|
63
86
|
};
|
|
64
|
-
};
|
|
87
|
+
});
|
|
88
|
+
export {
|
|
89
|
+
build
|
|
90
|
+
};
|
|
@@ -1,92 +1,131 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import * as path from "path";
|
|
41
|
+
import * as Event from "events";
|
|
42
|
+
import { logger, watch, WatchChangeType } from "@modern-js/utils";
|
|
7
43
|
import { build } from "./build";
|
|
8
44
|
import { CompilerErrorResult } from "./compilerErrorResult";
|
|
9
|
-
|
|
10
|
-
firstCompiler:
|
|
11
|
-
compiling:
|
|
12
|
-
watchingCompiler:
|
|
45
|
+
const BuildWatchEvent = {
|
|
46
|
+
firstCompiler: "first-compiler",
|
|
47
|
+
compiling: "compiling",
|
|
48
|
+
watchingCompiler: "watching-compiler"
|
|
13
49
|
};
|
|
14
|
-
|
|
15
|
-
constructor(...args) {
|
|
16
|
-
super(...args);
|
|
17
|
-
_defineProperty(this, "_initFn", void 0);
|
|
18
|
-
}
|
|
50
|
+
class BuildWatchEmitter extends Event.EventEmitter {
|
|
19
51
|
setInitFn(fn) {
|
|
20
52
|
this._initFn = fn;
|
|
21
53
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
54
|
+
watch() {
|
|
55
|
+
return __async(this, null, function* () {
|
|
56
|
+
if (typeof this._initFn === "function") {
|
|
57
|
+
return this._initFn(this);
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
});
|
|
27
61
|
}
|
|
28
62
|
}
|
|
29
|
-
|
|
63
|
+
const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}, emitter) {
|
|
30
64
|
emitter.emit(BuildWatchEvent.compiling);
|
|
31
65
|
const errorResult = new CompilerErrorResult();
|
|
32
66
|
const watchDir = option.watchDir;
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} = option;
|
|
37
|
-
// 第一次正常构建
|
|
38
|
-
const firstBuildResult = await build(option, babelConfig);
|
|
39
|
-
const {
|
|
40
|
-
code
|
|
41
|
-
} = firstBuildResult;
|
|
67
|
+
const { distDir, quiet } = option;
|
|
68
|
+
const firstBuildResult = yield build(option, babelConfig);
|
|
69
|
+
const { code } = firstBuildResult;
|
|
42
70
|
if (code === 1) {
|
|
43
71
|
errorResult.init(firstBuildResult);
|
|
44
72
|
emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
|
|
45
73
|
} else {
|
|
46
74
|
emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
47
75
|
}
|
|
48
|
-
return watch(
|
|
49
|
-
|
|
50
|
-
changedFilePath
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
76
|
+
return watch(
|
|
77
|
+
`${watchDir}/**/*.{js,jsx,ts,tsx}`,
|
|
78
|
+
(_02) => __async(void 0, [_02], function* ({ changeType, changedFilePath }) {
|
|
79
|
+
emitter.emit(BuildWatchEvent.compiling);
|
|
80
|
+
if (changeType === WatchChangeType.UNLINK) {
|
|
81
|
+
const removeFiles = [
|
|
82
|
+
path.normalize(
|
|
83
|
+
`./${distDir}/${path.relative(watchDir, changedFilePath)}`
|
|
84
|
+
)
|
|
85
|
+
];
|
|
86
|
+
if (!quiet) {
|
|
87
|
+
logger.info(`remove file: ${removeFiles.join(",")}`);
|
|
88
|
+
}
|
|
89
|
+
const result2 = {
|
|
90
|
+
code: 0,
|
|
91
|
+
message: `remove file: ${removeFiles.join(",")}`,
|
|
92
|
+
removeFiles
|
|
93
|
+
};
|
|
94
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result2);
|
|
95
|
+
return;
|
|
57
96
|
}
|
|
58
|
-
const result =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
const result = await build(_objectSpread(_objectSpread({}, option), {}, {
|
|
67
|
-
filenames: [changedFilePath]
|
|
68
|
-
}), babelConfig);
|
|
69
|
-
if (result.code === 1) {
|
|
70
|
-
errorResult.update(result.messageDetails || []);
|
|
71
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
|
|
72
|
-
!quiet && logger.info(errorResult.value.message);
|
|
73
|
-
} else {
|
|
74
|
-
errorResult.removeByFileName(changedFilePath);
|
|
75
|
-
// 如果该文件没有报错,则更新该文件状态并检查是否还存在其他报错文件
|
|
76
|
-
if (errorResult.checkExistError()) {
|
|
77
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, _objectSpread(_objectSpread({}, errorResult.value), {}, {
|
|
78
|
-
virtualDists: result.virtualDists
|
|
79
|
-
}));
|
|
97
|
+
const result = yield build(
|
|
98
|
+
__spreadProps(__spreadValues({}, option), { filenames: [changedFilePath] }),
|
|
99
|
+
babelConfig
|
|
100
|
+
);
|
|
101
|
+
if (result.code === 1) {
|
|
102
|
+
errorResult.update(result.messageDetails || []);
|
|
103
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
|
|
80
104
|
!quiet && logger.info(errorResult.value.message);
|
|
81
105
|
} else {
|
|
82
|
-
|
|
83
|
-
|
|
106
|
+
errorResult.removeByFileName(changedFilePath);
|
|
107
|
+
if (errorResult.checkExistError()) {
|
|
108
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, __spreadProps(__spreadValues({}, errorResult.value), {
|
|
109
|
+
virtualDists: result.virtualDists
|
|
110
|
+
}));
|
|
111
|
+
!quiet && logger.info(errorResult.value.message);
|
|
112
|
+
} else {
|
|
113
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result);
|
|
114
|
+
!quiet && logger.info(result.message);
|
|
115
|
+
}
|
|
84
116
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
117
|
+
}),
|
|
118
|
+
[`${watchDir}/**/*.d.ts`]
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
const buildWatch = (option, babelConfig = {}) => {
|
|
89
122
|
const buildWatchEmitter = new BuildWatchEmitter();
|
|
90
123
|
buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
|
|
91
124
|
return buildWatchEmitter;
|
|
92
|
-
};
|
|
125
|
+
};
|
|
126
|
+
export {
|
|
127
|
+
BuildWatchEmitter,
|
|
128
|
+
BuildWatchEvent,
|
|
129
|
+
buildWatch,
|
|
130
|
+
runBuildWatch
|
|
131
|
+
};
|
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import * as path from "path";
|
|
21
|
+
import * as babel from "@babel/core";
|
|
22
|
+
import { logger, fs } from "@modern-js/utils";
|
|
7
23
|
import * as utils from "./utils";
|
|
8
24
|
import { defaultDistFileExtMap } from "./constants";
|
|
9
|
-
const defaultDistDir =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const {
|
|
13
|
-
filepath,
|
|
14
|
-
rootDir,
|
|
15
|
-
distDir,
|
|
16
|
-
extMap
|
|
17
|
-
} = option;
|
|
25
|
+
const defaultDistDir = "dist";
|
|
26
|
+
const isRes = (r) => Boolean(r);
|
|
27
|
+
const getDistFilePath = (option) => {
|
|
28
|
+
const { filepath, rootDir, distDir, extMap } = option;
|
|
18
29
|
const ext = path.extname(filepath);
|
|
19
|
-
return path.join(
|
|
30
|
+
return path.join(
|
|
31
|
+
distDir,
|
|
32
|
+
path.relative(rootDir, filepath).replace(ext, extMap[ext])
|
|
33
|
+
);
|
|
20
34
|
};
|
|
21
|
-
|
|
35
|
+
const resolveSourceMap = (option) => {
|
|
22
36
|
const {
|
|
23
37
|
babelRes,
|
|
24
38
|
sourceFilePath,
|
|
@@ -29,7 +43,9 @@ export const resolveSourceMap = option => {
|
|
|
29
43
|
babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
|
|
30
44
|
if (babelRes.map) {
|
|
31
45
|
babelRes.map.file = path.basename(distFilePath);
|
|
32
|
-
babelRes.map.sources = [
|
|
46
|
+
babelRes.map.sources = [
|
|
47
|
+
path.relative(path.dirname(distFilePath), sourceFilePath)
|
|
48
|
+
];
|
|
33
49
|
}
|
|
34
50
|
const sourceMapVirtualDist = {
|
|
35
51
|
sourcemap: JSON.stringify(babelRes.map),
|
|
@@ -42,7 +58,7 @@ export const resolveSourceMap = option => {
|
|
|
42
58
|
fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
43
59
|
return sourceMapVirtualDist;
|
|
44
60
|
};
|
|
45
|
-
|
|
61
|
+
const compiler = (option) => {
|
|
46
62
|
const {
|
|
47
63
|
filepath,
|
|
48
64
|
rootDir,
|
|
@@ -67,14 +83,14 @@ export const compiler = option => {
|
|
|
67
83
|
if (enableVirtualDist) {
|
|
68
84
|
virtualDist = {
|
|
69
85
|
distPath: distFilePath,
|
|
70
|
-
sourceMapPath:
|
|
71
|
-
code:
|
|
72
|
-
sourcemap:
|
|
86
|
+
sourceMapPath: "",
|
|
87
|
+
code: "",
|
|
88
|
+
sourcemap: ""
|
|
73
89
|
};
|
|
74
90
|
}
|
|
75
|
-
if (babelRes
|
|
91
|
+
if ((babelRes == null ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
|
|
76
92
|
if (virtualDist) {
|
|
77
|
-
virtualDist =
|
|
93
|
+
virtualDist = __spreadValues(__spreadValues({}, virtualDist), resolveSourceMap({
|
|
78
94
|
babelRes,
|
|
79
95
|
sourceFilePath: filepath,
|
|
80
96
|
distFilePath,
|
|
@@ -90,7 +106,7 @@ export const compiler = option => {
|
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
108
|
if (virtualDist) {
|
|
93
|
-
virtualDist =
|
|
109
|
+
virtualDist = __spreadProps(__spreadValues({}, virtualDist), {
|
|
94
110
|
distPath: distFilePath,
|
|
95
111
|
code: babelRes.code
|
|
96
112
|
});
|
|
@@ -102,4 +118,10 @@ export const compiler = option => {
|
|
|
102
118
|
logger.info(`${filepath} => ${distFilePath}`);
|
|
103
119
|
}
|
|
104
120
|
return virtualDist;
|
|
105
|
-
};
|
|
121
|
+
};
|
|
122
|
+
export {
|
|
123
|
+
compiler,
|
|
124
|
+
getDistFilePath,
|
|
125
|
+
isRes,
|
|
126
|
+
resolveSourceMap
|
|
127
|
+
};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
export class CompilerErrorResult {
|
|
1
|
+
class CompilerErrorResult {
|
|
3
2
|
constructor(initErrorResult) {
|
|
4
|
-
_defineProperty(this, "_messageDetails", void 0);
|
|
5
3
|
this.init(initErrorResult);
|
|
6
4
|
}
|
|
7
5
|
init(initErrorResult) {
|
|
8
|
-
this._messageDetails = (initErrorResult
|
|
6
|
+
this._messageDetails = (initErrorResult == null ? void 0 : initErrorResult.messageDetails) || [];
|
|
9
7
|
}
|
|
10
8
|
update(messageDetails) {
|
|
11
9
|
for (const messageDetail of messageDetails) {
|
|
12
|
-
|
|
13
|
-
const addError = !this._messageDetails.some(detail => {
|
|
10
|
+
const addError = !this._messageDetails.some((detail) => {
|
|
14
11
|
if (detail.filename === messageDetail.filename) {
|
|
15
|
-
// 如果错误栈里存在该文件报错信息,则更新内容
|
|
16
12
|
detail.content = messageDetail.content;
|
|
17
13
|
return true;
|
|
18
14
|
}
|
|
@@ -24,17 +20,22 @@ export class CompilerErrorResult {
|
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
22
|
removeByFileName(filename) {
|
|
27
|
-
this._messageDetails = this._messageDetails.filter(
|
|
23
|
+
this._messageDetails = this._messageDetails.filter(
|
|
24
|
+
(detail) => detail.filename !== filename
|
|
25
|
+
);
|
|
28
26
|
}
|
|
29
27
|
get value() {
|
|
30
|
-
var
|
|
28
|
+
var _a;
|
|
31
29
|
return {
|
|
32
30
|
code: 1,
|
|
33
|
-
message: `Compilation failure ${(
|
|
31
|
+
message: `Compilation failure ${(_a = this._messageDetails) == null ? void 0 : _a.length} files with Babel.`,
|
|
34
32
|
messageDetails: this._messageDetails
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
35
|
checkExistError() {
|
|
38
36
|
return this._messageDetails.length > 0;
|
|
39
37
|
}
|
|
40
|
-
}
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
CompilerErrorResult
|
|
41
|
+
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
const defaultDistFileExtMap = {
|
|
2
|
+
".js": ".js",
|
|
3
|
+
".jsx": ".js",
|
|
4
|
+
".ts": ".js",
|
|
5
|
+
".tsx": ".js"
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
defaultDistFileExtMap
|
|
9
|
+
};
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
4
17
|
import { defaultDistFileExtMap } from "./constants";
|
|
5
18
|
const defaultOptions = {
|
|
6
19
|
enableWatch: false,
|
|
@@ -13,4 +26,7 @@ const defaultOptions = {
|
|
|
13
26
|
verbose: false,
|
|
14
27
|
clean: false
|
|
15
28
|
};
|
|
16
|
-
|
|
29
|
+
const mergeDefaultOption = (compilerOptions) => __spreadValues(__spreadValues({}, defaultOptions), compilerOptions);
|
|
30
|
+
export {
|
|
31
|
+
mergeDefaultOption
|
|
32
|
+
};
|
|
@@ -1,21 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { glob } from "@modern-js/utils";
|
|
21
|
+
import { DEFAULT_EXTENSIONS } from "@babel/core";
|
|
6
22
|
import { mergeDefaultOption } from "./defaults";
|
|
7
|
-
|
|
23
|
+
const getGlobPattern = (dir, extensions) => {
|
|
8
24
|
if (extensions.length > 1) {
|
|
9
|
-
return `${dir}/**/*{${extensions.join(
|
|
25
|
+
return `${dir}/**/*{${extensions.join(",")}}`;
|
|
10
26
|
} else if (extensions.length === 1) {
|
|
11
27
|
return `${dir}/**/*${extensions[0]}`;
|
|
12
28
|
} else {
|
|
13
29
|
return `${dir}/**/*`;
|
|
14
30
|
}
|
|
15
31
|
};
|
|
16
|
-
|
|
17
|
-
const isExtensions = ext => Array.isArray(ext);
|
|
18
|
-
const isExtensionsFunc = ext => typeof ext ===
|
|
32
|
+
const getFinalExtensions = (extensions) => {
|
|
33
|
+
const isExtensions = (ext) => Array.isArray(ext);
|
|
34
|
+
const isExtensionsFunc = (ext) => typeof ext === "function";
|
|
19
35
|
if (isExtensions(extensions)) {
|
|
20
36
|
return [...extensions, ...DEFAULT_EXTENSIONS];
|
|
21
37
|
} else if (isExtensionsFunc(extensions)) {
|
|
@@ -24,19 +40,17 @@ export const getFinalExtensions = extensions => {
|
|
|
24
40
|
return DEFAULT_EXTENSIONS;
|
|
25
41
|
}
|
|
26
42
|
};
|
|
27
|
-
|
|
43
|
+
const getFilesFromDir = ({
|
|
28
44
|
dir,
|
|
29
|
-
finalExt
|
|
30
|
-
ignore
|
|
45
|
+
finalExt = [],
|
|
46
|
+
ignore = []
|
|
31
47
|
}) => {
|
|
32
48
|
let globFindFilenames = [];
|
|
33
|
-
const globPattern = getGlobPattern(dir,
|
|
34
|
-
globFindFilenames = glob.sync(globPattern, {
|
|
35
|
-
ignore: _ignore
|
|
36
|
-
});
|
|
49
|
+
const globPattern = getGlobPattern(dir, finalExt);
|
|
50
|
+
globFindFilenames = glob.sync(globPattern, { ignore });
|
|
37
51
|
return globFindFilenames;
|
|
38
52
|
};
|
|
39
|
-
|
|
53
|
+
const getFinalCompilerOption = (option) => {
|
|
40
54
|
const optionWithDefault = mergeDefaultOption(option);
|
|
41
55
|
const {
|
|
42
56
|
sourceDir,
|
|
@@ -55,14 +69,19 @@ export const getFinalCompilerOption = option => {
|
|
|
55
69
|
});
|
|
56
70
|
}
|
|
57
71
|
if (enableWatch) {
|
|
58
|
-
// 开启watch模式,清空通过 sourceDir 找到的文件,而改为使用watchDirs
|
|
59
72
|
globFindFilenames = getFilesFromDir({
|
|
60
73
|
dir: watchDir,
|
|
61
74
|
ignore,
|
|
62
75
|
finalExt
|
|
63
76
|
});
|
|
64
77
|
}
|
|
65
|
-
return
|
|
78
|
+
return __spreadProps(__spreadValues({}, optionWithDefault), {
|
|
66
79
|
filenames: [...optionWithDefault.filenames, ...globFindFilenames]
|
|
67
80
|
});
|
|
68
|
-
};
|
|
81
|
+
};
|
|
82
|
+
export {
|
|
83
|
+
getFilesFromDir,
|
|
84
|
+
getFinalCompilerOption,
|
|
85
|
+
getFinalExtensions,
|
|
86
|
+
getGlobPattern
|
|
87
|
+
};
|