@modern-js/babel-compiler 2.0.0-beta.2 → 2.0.0-beta.4
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 +58 -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 +58 -20
- package/dist/js/node/buildWatch.js +131 -79
- package/dist/js/node/compiler.js +79 -44
- package/dist/js/node/compilerErrorResult.js +28 -15
- package/dist/js/node/constants.js +25 -10
- package/dist/js/node/defaults.js +40 -12
- package/dist/js/node/getFinalOption.js +61 -33
- package/dist/js/node/index.js +58 -43
- package/dist/js/node/utils.js +31 -10
- package/dist/js/node/validate.js +36 -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/modern/index.js
CHANGED
|
@@ -1,18 +1,43 @@
|
|
|
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
|
+
};
|
|
1
21
|
import { getFinalCompilerOption } from "./getFinalOption";
|
|
2
22
|
import { build } from "./build";
|
|
3
23
|
import { buildWatch } from "./buildWatch";
|
|
4
24
|
import { validate } from "./validate";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
function compiler(_0) {
|
|
26
|
+
return __async(this, arguments, function* (compilerOptions, babelOptions = {}) {
|
|
27
|
+
const validRet = validate(compilerOptions);
|
|
28
|
+
if (validRet) {
|
|
29
|
+
return validRet;
|
|
30
|
+
}
|
|
31
|
+
const finalCompilerOption = getFinalCompilerOption(compilerOptions);
|
|
32
|
+
if (compilerOptions.enableWatch) {
|
|
33
|
+
return buildWatch(finalCompilerOption, babelOptions);
|
|
34
|
+
} else {
|
|
35
|
+
return build(finalCompilerOption, babelOptions);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
16
38
|
}
|
|
17
39
|
export * from "./buildWatch";
|
|
18
|
-
export * from "./type";
|
|
40
|
+
export * from "./type";
|
|
41
|
+
export {
|
|
42
|
+
compiler
|
|
43
|
+
};
|
package/dist/js/modern/utils.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import * as path from
|
|
2
|
-
|
|
3
|
-
return `${code}
|
|
4
|
-
}
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
function addSourceMappingUrl(code, loc) {
|
|
3
|
+
return `${code}
|
|
4
|
+
//# sourceMappingURL=${path.normalize(path.basename(loc))}`;
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
addSourceMappingUrl
|
|
8
|
+
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { logger } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
sourceDir,
|
|
7
|
-
filenames,
|
|
8
|
-
quiet
|
|
9
|
-
} = compilerOptions;
|
|
1
|
+
import { logger } from "@modern-js/utils";
|
|
2
|
+
const sourceDirAndFileNamesValidMessage = "At least one of the sourceDir and filenames configurations must be configured";
|
|
3
|
+
const watchDirValidMessage = "should set watchDir when enableWatch is true";
|
|
4
|
+
const validateSourceDirAndFileNames = (compilerOptions) => {
|
|
5
|
+
const { sourceDir, filenames, quiet } = compilerOptions;
|
|
10
6
|
if (!sourceDir && !filenames) {
|
|
11
7
|
if (!quiet) {
|
|
12
8
|
logger.error(sourceDirAndFileNamesValidMessage);
|
|
@@ -19,27 +15,26 @@ export const validateSourceDirAndFileNames = compilerOptions => {
|
|
|
19
15
|
}
|
|
20
16
|
return null;
|
|
21
17
|
};
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
watchDir,
|
|
25
|
-
enableWatch,
|
|
26
|
-
quiet
|
|
27
|
-
} = compilerOptions;
|
|
18
|
+
const validateWatchDir = (compilerOptions) => {
|
|
19
|
+
const { watchDir, enableWatch, quiet } = compilerOptions;
|
|
28
20
|
if (enableWatch && !watchDir) {
|
|
29
21
|
if (!quiet) {
|
|
30
22
|
logger.error(watchDirValidMessage);
|
|
31
23
|
}
|
|
32
|
-
return {
|
|
33
|
-
code: 1,
|
|
34
|
-
message: watchDirValidMessage,
|
|
35
|
-
virtualDists: []
|
|
36
|
-
};
|
|
24
|
+
return { code: 1, message: watchDirValidMessage, virtualDists: [] };
|
|
37
25
|
}
|
|
38
26
|
return null;
|
|
39
27
|
};
|
|
40
|
-
|
|
28
|
+
const validate = (compilerOptions) => {
|
|
41
29
|
if (compilerOptions.enableWatch) {
|
|
42
30
|
return validateWatchDir(compilerOptions);
|
|
43
31
|
}
|
|
44
32
|
return validateSourceDirAndFileNames(compilerOptions);
|
|
45
|
-
};
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
sourceDirAndFileNamesValidMessage,
|
|
36
|
+
validate,
|
|
37
|
+
validateSourceDirAndFileNames,
|
|
38
|
+
validateWatchDir,
|
|
39
|
+
watchDirValidMessage
|
|
40
|
+
};
|
package/dist/js/node/build.js
CHANGED
|
@@ -1,32 +1,68 @@
|
|
|
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 stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
build: () => build
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
var import_utils = require("@modern-js/utils");
|
|
24
|
+
var import_constants = require("./constants");
|
|
25
|
+
var import_compiler = require("./compiler");
|
|
26
|
+
var __async = (__this, __arguments, generator) => {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
var fulfilled = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.next(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var rejected = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.throw(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
43
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}) {
|
|
11
47
|
const {
|
|
12
48
|
rootDir,
|
|
13
49
|
enableVirtualDist,
|
|
14
50
|
filenames,
|
|
15
51
|
clean,
|
|
16
52
|
distDir,
|
|
17
|
-
distFileExtMap =
|
|
53
|
+
distFileExtMap = import_constants.defaultDistFileExtMap,
|
|
18
54
|
verbose = false,
|
|
19
55
|
quiet = false
|
|
20
56
|
} = option;
|
|
21
57
|
const virtualDists = [];
|
|
22
58
|
if (clean) {
|
|
23
|
-
|
|
59
|
+
yield import_utils.fs.remove(distDir);
|
|
24
60
|
}
|
|
25
|
-
|
|
61
|
+
import_utils.fs.ensureDir(distDir);
|
|
26
62
|
const messageDetails = [];
|
|
27
63
|
for (const filename of filenames) {
|
|
28
64
|
try {
|
|
29
|
-
const dist = (0,
|
|
65
|
+
const dist = (0, import_compiler.compiler)({
|
|
30
66
|
rootDir,
|
|
31
67
|
enableVirtualDist,
|
|
32
68
|
filepath: filename,
|
|
@@ -49,23 +85,25 @@ const build = async (option, babelConfig = {}) => {
|
|
|
49
85
|
const happenError = messageDetails.length > 0;
|
|
50
86
|
if (!quiet) {
|
|
51
87
|
if (happenError) {
|
|
52
|
-
|
|
53
|
-
|
|
88
|
+
import_utils.logger.error(
|
|
89
|
+
`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`
|
|
90
|
+
);
|
|
54
91
|
} else {
|
|
55
|
-
|
|
92
|
+
import_utils.logger.info(
|
|
93
|
+
`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`
|
|
94
|
+
);
|
|
56
95
|
}
|
|
57
96
|
}
|
|
58
97
|
if (happenError) {
|
|
59
98
|
return {
|
|
60
99
|
code: 1,
|
|
61
|
-
message: `Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ?
|
|
100
|
+
message: `Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`,
|
|
62
101
|
messageDetails
|
|
63
102
|
};
|
|
64
103
|
}
|
|
65
104
|
return {
|
|
66
105
|
code: 0,
|
|
67
|
-
message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ?
|
|
106
|
+
message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`,
|
|
68
107
|
virtualDists
|
|
69
108
|
};
|
|
70
|
-
};
|
|
71
|
-
exports.build = build;
|
|
109
|
+
});
|
|
@@ -1,104 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
BuildWatchEmitter: () => BuildWatchEmitter,
|
|
27
|
+
BuildWatchEvent: () => BuildWatchEvent,
|
|
28
|
+
buildWatch: () => buildWatch,
|
|
29
|
+
runBuildWatch: () => runBuildWatch
|
|
5
30
|
});
|
|
6
|
-
|
|
7
|
-
var path =
|
|
8
|
-
var Event =
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
32
|
+
var path = __toESM(require("path"));
|
|
33
|
+
var Event = __toESM(require("events"));
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_build = require("./build");
|
|
36
|
+
var import_compilerErrorResult = require("./compilerErrorResult");
|
|
37
|
+
var __defProp2 = Object.defineProperty;
|
|
38
|
+
var __defProps = Object.defineProperties;
|
|
39
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
40
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
41
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
42
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
43
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
44
|
+
var __spreadValues = (a, b) => {
|
|
45
|
+
for (var prop in b || (b = {}))
|
|
46
|
+
if (__hasOwnProp2.call(b, prop))
|
|
47
|
+
__defNormalProp(a, prop, b[prop]);
|
|
48
|
+
if (__getOwnPropSymbols)
|
|
49
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
50
|
+
if (__propIsEnum.call(b, prop))
|
|
51
|
+
__defNormalProp(a, prop, b[prop]);
|
|
52
|
+
}
|
|
53
|
+
return a;
|
|
54
|
+
};
|
|
55
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
56
|
+
var __async = (__this, __arguments, generator) => {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
var fulfilled = (value) => {
|
|
59
|
+
try {
|
|
60
|
+
step(generator.next(value));
|
|
61
|
+
} catch (e) {
|
|
62
|
+
reject(e);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var rejected = (value) => {
|
|
66
|
+
try {
|
|
67
|
+
step(generator.throw(value));
|
|
68
|
+
} catch (e) {
|
|
69
|
+
reject(e);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
73
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
74
|
+
});
|
|
75
|
+
};
|
|
17
76
|
const BuildWatchEvent = {
|
|
18
|
-
firstCompiler:
|
|
19
|
-
compiling:
|
|
20
|
-
watchingCompiler:
|
|
77
|
+
firstCompiler: "first-compiler",
|
|
78
|
+
compiling: "compiling",
|
|
79
|
+
watchingCompiler: "watching-compiler"
|
|
21
80
|
};
|
|
22
|
-
exports.BuildWatchEvent = BuildWatchEvent;
|
|
23
81
|
class BuildWatchEmitter extends Event.EventEmitter {
|
|
24
|
-
constructor(...args) {
|
|
25
|
-
super(...args);
|
|
26
|
-
_defineProperty(this, "_initFn", void 0);
|
|
27
|
-
}
|
|
28
82
|
setInitFn(fn) {
|
|
29
83
|
this._initFn = fn;
|
|
30
84
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
85
|
+
watch() {
|
|
86
|
+
return __async(this, null, function* () {
|
|
87
|
+
if (typeof this._initFn === "function") {
|
|
88
|
+
return this._initFn(this);
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
});
|
|
36
92
|
}
|
|
37
93
|
}
|
|
38
|
-
|
|
39
|
-
const runBuildWatch = async (option, babelConfig = {}, emitter) => {
|
|
94
|
+
const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}, emitter) {
|
|
40
95
|
emitter.emit(BuildWatchEvent.compiling);
|
|
41
|
-
const errorResult = new
|
|
96
|
+
const errorResult = new import_compilerErrorResult.CompilerErrorResult();
|
|
42
97
|
const watchDir = option.watchDir;
|
|
43
|
-
const {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} = option;
|
|
47
|
-
// 第一次正常构建
|
|
48
|
-
const firstBuildResult = await (0, _build.build)(option, babelConfig);
|
|
49
|
-
const {
|
|
50
|
-
code
|
|
51
|
-
} = firstBuildResult;
|
|
98
|
+
const { distDir, quiet } = option;
|
|
99
|
+
const firstBuildResult = yield (0, import_build.build)(option, babelConfig);
|
|
100
|
+
const { code } = firstBuildResult;
|
|
52
101
|
if (code === 1) {
|
|
53
102
|
errorResult.init(firstBuildResult);
|
|
54
103
|
emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
|
|
55
104
|
} else {
|
|
56
105
|
emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
57
106
|
}
|
|
58
|
-
return (0,
|
|
59
|
-
|
|
60
|
-
changedFilePath
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
107
|
+
return (0, import_utils.watch)(
|
|
108
|
+
`${watchDir}/**/*.{js,jsx,ts,tsx}`,
|
|
109
|
+
(_02) => __async(void 0, [_02], function* ({ changeType, changedFilePath }) {
|
|
110
|
+
emitter.emit(BuildWatchEvent.compiling);
|
|
111
|
+
if (changeType === import_utils.WatchChangeType.UNLINK) {
|
|
112
|
+
const removeFiles = [
|
|
113
|
+
path.normalize(
|
|
114
|
+
`./${distDir}/${path.relative(watchDir, changedFilePath)}`
|
|
115
|
+
)
|
|
116
|
+
];
|
|
117
|
+
if (!quiet) {
|
|
118
|
+
import_utils.logger.info(`remove file: ${removeFiles.join(",")}`);
|
|
119
|
+
}
|
|
120
|
+
const result2 = {
|
|
121
|
+
code: 0,
|
|
122
|
+
message: `remove file: ${removeFiles.join(",")}`,
|
|
123
|
+
removeFiles
|
|
124
|
+
};
|
|
125
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result2);
|
|
126
|
+
return;
|
|
67
127
|
}
|
|
68
|
-
const result =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const result = await (0, _build.build)(_objectSpread(_objectSpread({}, option), {}, {
|
|
77
|
-
filenames: [changedFilePath]
|
|
78
|
-
}), babelConfig);
|
|
79
|
-
if (result.code === 1) {
|
|
80
|
-
errorResult.update(result.messageDetails || []);
|
|
81
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
|
|
82
|
-
!quiet && _utils.logger.info(errorResult.value.message);
|
|
83
|
-
} else {
|
|
84
|
-
errorResult.removeByFileName(changedFilePath);
|
|
85
|
-
// 如果该文件没有报错,则更新该文件状态并检查是否还存在其他报错文件
|
|
86
|
-
if (errorResult.checkExistError()) {
|
|
87
|
-
emitter.emit(BuildWatchEvent.watchingCompiler, _objectSpread(_objectSpread({}, errorResult.value), {}, {
|
|
88
|
-
virtualDists: result.virtualDists
|
|
89
|
-
}));
|
|
90
|
-
!quiet && _utils.logger.info(errorResult.value.message);
|
|
128
|
+
const result = yield (0, import_build.build)(
|
|
129
|
+
__spreadProps(__spreadValues({}, option), { filenames: [changedFilePath] }),
|
|
130
|
+
babelConfig
|
|
131
|
+
);
|
|
132
|
+
if (result.code === 1) {
|
|
133
|
+
errorResult.update(result.messageDetails || []);
|
|
134
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
|
|
135
|
+
!quiet && import_utils.logger.info(errorResult.value.message);
|
|
91
136
|
} else {
|
|
92
|
-
|
|
93
|
-
|
|
137
|
+
errorResult.removeByFileName(changedFilePath);
|
|
138
|
+
if (errorResult.checkExistError()) {
|
|
139
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, __spreadProps(__spreadValues({}, errorResult.value), {
|
|
140
|
+
virtualDists: result.virtualDists
|
|
141
|
+
}));
|
|
142
|
+
!quiet && import_utils.logger.info(errorResult.value.message);
|
|
143
|
+
} else {
|
|
144
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result);
|
|
145
|
+
!quiet && import_utils.logger.info(result.message);
|
|
146
|
+
}
|
|
94
147
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
148
|
+
}),
|
|
149
|
+
[`${watchDir}/**/*.d.ts`]
|
|
150
|
+
);
|
|
151
|
+
});
|
|
99
152
|
const buildWatch = (option, babelConfig = {}) => {
|
|
100
153
|
const buildWatchEmitter = new BuildWatchEmitter();
|
|
101
154
|
buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
|
|
102
155
|
return buildWatchEmitter;
|
|
103
156
|
};
|
|
104
|
-
exports.buildWatch = buildWatch;
|
package/dist/js/node/compiler.js
CHANGED
|
@@ -1,34 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
compiler: () => compiler,
|
|
27
|
+
getDistFilePath: () => getDistFilePath,
|
|
28
|
+
isRes: () => isRes,
|
|
29
|
+
resolveSourceMap: () => resolveSourceMap
|
|
5
30
|
});
|
|
6
|
-
|
|
7
|
-
var path =
|
|
8
|
-
var babel =
|
|
9
|
-
var
|
|
10
|
-
var utils =
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
32
|
+
var path = __toESM(require("path"));
|
|
33
|
+
var babel = __toESM(require("@babel/core"));
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var utils = __toESM(require("./utils"));
|
|
36
|
+
var import_constants = require("./constants");
|
|
37
|
+
var __defProp2 = Object.defineProperty;
|
|
38
|
+
var __defProps = Object.defineProperties;
|
|
39
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
40
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
41
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
42
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
43
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
44
|
+
var __spreadValues = (a, b) => {
|
|
45
|
+
for (var prop in b || (b = {}))
|
|
46
|
+
if (__hasOwnProp2.call(b, prop))
|
|
47
|
+
__defNormalProp(a, prop, b[prop]);
|
|
48
|
+
if (__getOwnPropSymbols)
|
|
49
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
50
|
+
if (__propIsEnum.call(b, prop))
|
|
51
|
+
__defNormalProp(a, prop, b[prop]);
|
|
52
|
+
}
|
|
53
|
+
return a;
|
|
54
|
+
};
|
|
55
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
56
|
+
const defaultDistDir = "dist";
|
|
57
|
+
const isRes = (r) => Boolean(r);
|
|
58
|
+
const getDistFilePath = (option) => {
|
|
59
|
+
const { filepath, rootDir, distDir, extMap } = option;
|
|
27
60
|
const ext = path.extname(filepath);
|
|
28
|
-
return path.join(
|
|
61
|
+
return path.join(
|
|
62
|
+
distDir,
|
|
63
|
+
path.relative(rootDir, filepath).replace(ext, extMap[ext])
|
|
64
|
+
);
|
|
29
65
|
};
|
|
30
|
-
|
|
31
|
-
const resolveSourceMap = option => {
|
|
66
|
+
const resolveSourceMap = (option) => {
|
|
32
67
|
const {
|
|
33
68
|
babelRes,
|
|
34
69
|
sourceFilePath,
|
|
@@ -39,7 +74,9 @@ const resolveSourceMap = option => {
|
|
|
39
74
|
babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
|
|
40
75
|
if (babelRes.map) {
|
|
41
76
|
babelRes.map.file = path.basename(distFilePath);
|
|
42
|
-
babelRes.map.sources = [
|
|
77
|
+
babelRes.map.sources = [
|
|
78
|
+
path.relative(path.dirname(distFilePath), sourceFilePath)
|
|
79
|
+
];
|
|
43
80
|
}
|
|
44
81
|
const sourceMapVirtualDist = {
|
|
45
82
|
sourcemap: JSON.stringify(babelRes.map),
|
|
@@ -48,12 +85,11 @@ const resolveSourceMap = option => {
|
|
|
48
85
|
if (enableVirtualDist) {
|
|
49
86
|
return sourceMapVirtualDist;
|
|
50
87
|
}
|
|
51
|
-
|
|
52
|
-
|
|
88
|
+
import_utils.fs.ensureDirSync(path.dirname(mapLoc));
|
|
89
|
+
import_utils.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
53
90
|
return sourceMapVirtualDist;
|
|
54
91
|
};
|
|
55
|
-
|
|
56
|
-
const compiler = option => {
|
|
92
|
+
const compiler = (option) => {
|
|
57
93
|
const {
|
|
58
94
|
filepath,
|
|
59
95
|
rootDir,
|
|
@@ -61,7 +97,7 @@ const compiler = option => {
|
|
|
61
97
|
distDir = path.join(path.dirname(rootDir), defaultDistDir),
|
|
62
98
|
verbose = false,
|
|
63
99
|
babelConfig = {},
|
|
64
|
-
distFileExtMap =
|
|
100
|
+
distFileExtMap = import_constants.defaultDistFileExtMap,
|
|
65
101
|
quiet = false
|
|
66
102
|
} = option;
|
|
67
103
|
const babelRes = babel.transformFileSync(filepath, babelConfig);
|
|
@@ -78,14 +114,14 @@ const compiler = option => {
|
|
|
78
114
|
if (enableVirtualDist) {
|
|
79
115
|
virtualDist = {
|
|
80
116
|
distPath: distFilePath,
|
|
81
|
-
sourceMapPath:
|
|
82
|
-
code:
|
|
83
|
-
sourcemap:
|
|
117
|
+
sourceMapPath: "",
|
|
118
|
+
code: "",
|
|
119
|
+
sourcemap: ""
|
|
84
120
|
};
|
|
85
121
|
}
|
|
86
|
-
if (babelRes
|
|
122
|
+
if ((babelRes == null ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
|
|
87
123
|
if (virtualDist) {
|
|
88
|
-
virtualDist =
|
|
124
|
+
virtualDist = __spreadValues(__spreadValues({}, virtualDist), resolveSourceMap({
|
|
89
125
|
babelRes,
|
|
90
126
|
sourceFilePath: filepath,
|
|
91
127
|
distFilePath,
|
|
@@ -101,17 +137,16 @@ const compiler = option => {
|
|
|
101
137
|
}
|
|
102
138
|
}
|
|
103
139
|
if (virtualDist) {
|
|
104
|
-
virtualDist =
|
|
140
|
+
virtualDist = __spreadProps(__spreadValues({}, virtualDist), {
|
|
105
141
|
distPath: distFilePath,
|
|
106
142
|
code: babelRes.code
|
|
107
143
|
});
|
|
108
144
|
} else {
|
|
109
|
-
|
|
110
|
-
|
|
145
|
+
import_utils.fs.ensureDirSync(path.dirname(distFilePath));
|
|
146
|
+
import_utils.fs.writeFileSync(distFilePath, babelRes.code);
|
|
111
147
|
}
|
|
112
148
|
if (verbose && !quiet) {
|
|
113
|
-
|
|
149
|
+
import_utils.logger.info(`${filepath} => ${distFilePath}`);
|
|
114
150
|
}
|
|
115
151
|
return virtualDist;
|
|
116
152
|
};
|
|
117
|
-
exports.compiler = compiler;
|