@modern-js/babel-compiler 2.69.4 → 3.0.0-alpha.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/dist/cjs/build.js +68 -73
- package/dist/cjs/buildWatch.js +111 -116
- package/dist/cjs/compiler.js +103 -116
- package/dist/cjs/compilerErrorResult.js +61 -56
- package/dist/cjs/constants.js +36 -28
- package/dist/cjs/defaults.js +46 -38
- package/dist/cjs/getFinalOption.js +82 -83
- package/dist/cjs/index.js +92 -44
- package/dist/cjs/type.js +17 -15
- package/dist/cjs/utils.js +34 -37
- package/dist/cjs/validate.js +70 -64
- package/dist/esm/build.mjs +42 -0
- package/dist/esm/buildWatch.mjs +78 -0
- package/dist/esm/compiler.mjs +76 -0
- package/dist/esm/compilerErrorResult.mjs +34 -0
- package/dist/esm/constants.mjs +7 -0
- package/dist/esm/defaults.mjs +17 -0
- package/dist/esm/getFinalOption.mjs +50 -0
- package/dist/{esm-node/index.js → esm/index.mjs} +7 -14
- package/dist/esm/utils.mjs +5 -0
- package/dist/esm/validate.mjs +32 -0
- package/dist/esm-node/build.mjs +42 -0
- package/dist/esm-node/buildWatch.mjs +78 -0
- package/dist/esm-node/compiler.mjs +76 -0
- package/dist/esm-node/compilerErrorResult.mjs +34 -0
- package/dist/esm-node/constants.mjs +7 -0
- package/dist/esm-node/defaults.mjs +17 -0
- package/dist/esm-node/getFinalOption.mjs +50 -0
- package/dist/esm-node/index.mjs +14 -0
- package/dist/esm-node/utils.mjs +5 -0
- package/dist/esm-node/validate.mjs +32 -0
- package/package.json +24 -17
- package/rslib.config.mts +4 -0
- package/rstest.config.ts +7 -0
- package/dist/esm/build.js +0 -105
- package/dist/esm/buildWatch.js +0 -157
- package/dist/esm/compiler.js +0 -95
- package/dist/esm/compilerErrorResult.js +0 -71
- package/dist/esm/constants.js +0 -9
- package/dist/esm/defaults.js +0 -19
- package/dist/esm/getFinalOption.js +0 -68
- package/dist/esm/index.js +0 -46
- package/dist/esm/utils.js +0 -7
- package/dist/esm/validate.js +0 -44
- package/dist/esm-node/build.js +0 -57
- package/dist/esm-node/buildWatch.js +0 -89
- package/dist/esm-node/compiler.js +0 -95
- package/dist/esm-node/compilerErrorResult.js +0 -39
- package/dist/esm-node/constants.js +0 -9
- package/dist/esm-node/defaults.js +0 -19
- package/dist/esm-node/getFinalOption.js +0 -67
- package/dist/esm-node/utils.js +0 -8
- package/dist/esm-node/validate.js +0 -44
- /package/dist/esm/{type.js → type.mjs} +0 -0
- /package/dist/esm-node/{type.js → type.mjs} +0 -0
package/dist/cjs/build.js
CHANGED
|
@@ -1,81 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
build: ()=>build
|
|
22
28
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
babelConfig,
|
|
45
|
-
distFileExtMap
|
|
46
|
-
});
|
|
47
|
-
if (enableVirtualDist && dist) {
|
|
48
|
-
virtualDists.push(dist);
|
|
49
|
-
}
|
|
29
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
30
|
+
const external_compiler_js_namespaceObject = require("./compiler.js");
|
|
31
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
32
|
+
const build = async (option, babelConfig = {})=>{
|
|
33
|
+
const { rootDir, enableVirtualDist, filenames, clean, distDir, distFileExtMap = external_constants_js_namespaceObject.defaultDistFileExtMap, verbose = false, quiet = false } = option;
|
|
34
|
+
const virtualDists = [];
|
|
35
|
+
if (clean) await utils_namespaceObject.fs.remove(distDir);
|
|
36
|
+
utils_namespaceObject.fs.ensureDir(distDir);
|
|
37
|
+
const messageDetails = [];
|
|
38
|
+
for (const filename of filenames)try {
|
|
39
|
+
const dist = (0, external_compiler_js_namespaceObject.compiler)({
|
|
40
|
+
rootDir,
|
|
41
|
+
enableVirtualDist,
|
|
42
|
+
filepath: filename,
|
|
43
|
+
distDir,
|
|
44
|
+
verbose,
|
|
45
|
+
quiet,
|
|
46
|
+
babelConfig,
|
|
47
|
+
distFileExtMap
|
|
48
|
+
});
|
|
49
|
+
if (enableVirtualDist && dist) virtualDists.push(dist);
|
|
50
50
|
} catch (e) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const happenError = messageDetails.length > 0;
|
|
58
|
-
if (!quiet) {
|
|
59
|
-
if (happenError) {
|
|
60
|
-
import_utils.logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`);
|
|
61
|
-
} else {
|
|
62
|
-
import_utils.logger.info(`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`);
|
|
51
|
+
messageDetails.push({
|
|
52
|
+
filename,
|
|
53
|
+
content: e.toString()
|
|
54
|
+
});
|
|
63
55
|
}
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const happenError = messageDetails.length > 0;
|
|
57
|
+
if (!quiet) if (happenError) utils_namespaceObject.logger.error(`Compilation failure ${messageDetails.length} ${1 !== messageDetails.length ? 'files' : 'file'} with Babel.`);
|
|
58
|
+
else utils_namespaceObject.logger.info(`Successfully compiled ${filenames.length} ${1 !== filenames.length ? 'files' : 'file'} with Babel.`);
|
|
59
|
+
if (happenError) return {
|
|
60
|
+
code: 1,
|
|
61
|
+
message: `Compilation failure ${messageDetails.length} ${1 !== messageDetails.length ? 'files' : 'file'} with Babel.`,
|
|
62
|
+
messageDetails
|
|
63
|
+
};
|
|
66
64
|
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
code: 0,
|
|
66
|
+
message: `Successfully compiled ${filenames.length} ${1 !== filenames.length ? 'files' : 'file'} with Babel.`,
|
|
67
|
+
virtualDists
|
|
70
68
|
};
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
code: 0,
|
|
74
|
-
message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`,
|
|
75
|
-
virtualDists
|
|
76
|
-
};
|
|
77
69
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
exports.build = __webpack_exports__.build;
|
|
71
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
72
|
+
"build"
|
|
73
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
74
|
+
Object.defineProperty(exports, '__esModule', {
|
|
75
|
+
value: true
|
|
81
76
|
});
|
package/dist/cjs/buildWatch.js
CHANGED
|
@@ -1,126 +1,121 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
BuildWatchEmitter: () => BuildWatchEmitter,
|
|
32
|
-
BuildWatchEvent: () => BuildWatchEvent,
|
|
33
|
-
buildWatch: () => buildWatch,
|
|
34
|
-
runBuildWatch: () => runBuildWatch
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
BuildWatchEvent: ()=>BuildWatchEvent,
|
|
28
|
+
buildWatch: ()=>buildWatch,
|
|
29
|
+
runBuildWatch: ()=>runBuildWatch,
|
|
30
|
+
BuildWatchEmitter: ()=>BuildWatchEmitter
|
|
35
31
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var import_compilerErrorResult = require("./compilerErrorResult");
|
|
32
|
+
const external_events_namespaceObject = require("events");
|
|
33
|
+
const external_path_namespaceObject = require("path");
|
|
34
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
35
|
+
const external_build_js_namespaceObject = require("./build.js");
|
|
36
|
+
const external_compilerErrorResult_js_namespaceObject = require("./compilerErrorResult.js");
|
|
42
37
|
const BuildWatchEvent = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
firstCompiler: 'first-compiler',
|
|
39
|
+
compiling: 'compiling',
|
|
40
|
+
watchingCompiler: 'watching-compiler'
|
|
46
41
|
};
|
|
47
|
-
class BuildWatchEmitter extends
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
42
|
+
class BuildWatchEmitter extends external_events_namespaceObject.EventEmitter {
|
|
43
|
+
setInitFn(fn) {
|
|
44
|
+
this._initFn = fn;
|
|
45
|
+
}
|
|
46
|
+
async watch() {
|
|
47
|
+
if ('function' == typeof this._initFn) return this._initFn(this);
|
|
48
|
+
return null;
|
|
54
49
|
}
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
50
|
}
|
|
58
|
-
const runBuildWatch = async (option, babelConfig = {}, emitter)
|
|
59
|
-
emitter.emit(BuildWatchEvent.compiling);
|
|
60
|
-
const errorResult = new import_compilerErrorResult.CompilerErrorResult();
|
|
61
|
-
const watchDir = option.watchDir;
|
|
62
|
-
const { distDir, quiet } = option;
|
|
63
|
-
const firstBuildResult = await (0, import_build.build)(option, babelConfig);
|
|
64
|
-
const { code } = firstBuildResult;
|
|
65
|
-
if (code === 1) {
|
|
66
|
-
errorResult.init(firstBuildResult);
|
|
67
|
-
emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
|
|
68
|
-
} else {
|
|
69
|
-
emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
70
|
-
}
|
|
71
|
-
return (0, import_utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({ changeType, changedFilePath }) => {
|
|
51
|
+
const runBuildWatch = async (option, babelConfig = {}, emitter)=>{
|
|
72
52
|
emitter.emit(BuildWatchEvent.compiling);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
53
|
+
const errorResult = new external_compilerErrorResult_js_namespaceObject.CompilerErrorResult();
|
|
54
|
+
const watchDir = option.watchDir;
|
|
55
|
+
const { distDir, quiet } = option;
|
|
56
|
+
const firstBuildResult = await (0, external_build_js_namespaceObject.build)(option, babelConfig);
|
|
57
|
+
const { code } = firstBuildResult;
|
|
58
|
+
if (1 === code) {
|
|
59
|
+
errorResult.init(firstBuildResult);
|
|
60
|
+
emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
|
|
61
|
+
} else emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
|
|
62
|
+
return (0, utils_namespaceObject.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({ changeType, changedFilePath })=>{
|
|
63
|
+
emitter.emit(BuildWatchEvent.compiling);
|
|
64
|
+
if (changeType === utils_namespaceObject.WatchChangeType.UNLINK) {
|
|
65
|
+
const removeFiles = [
|
|
66
|
+
external_path_namespaceObject.normalize(`./${distDir}/${external_path_namespaceObject.relative(watchDir, changedFilePath)}`)
|
|
67
|
+
];
|
|
68
|
+
if (!quiet) utils_namespaceObject.logger.info(`remove file: ${removeFiles.join(',')}`);
|
|
69
|
+
const result = {
|
|
70
|
+
code: 0,
|
|
71
|
+
message: `remove file: ${removeFiles.join(',')}`,
|
|
72
|
+
removeFiles
|
|
73
|
+
};
|
|
74
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const result = await (0, external_build_js_namespaceObject.build)({
|
|
78
|
+
...option,
|
|
79
|
+
filenames: [
|
|
80
|
+
changedFilePath
|
|
81
|
+
]
|
|
82
|
+
}, babelConfig);
|
|
83
|
+
if (1 === result.code) {
|
|
84
|
+
errorResult.update(result.messageDetails || []);
|
|
85
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
|
|
86
|
+
quiet || utils_namespaceObject.logger.info(errorResult.value.message);
|
|
87
|
+
} else {
|
|
88
|
+
errorResult.removeByFileName(changedFilePath);
|
|
89
|
+
if (errorResult.checkExistError()) {
|
|
90
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, {
|
|
91
|
+
...errorResult.value,
|
|
92
|
+
virtualDists: result.virtualDists
|
|
93
|
+
});
|
|
94
|
+
quiet || utils_namespaceObject.logger.info(errorResult.value.message);
|
|
95
|
+
} else {
|
|
96
|
+
emitter.emit(BuildWatchEvent.watchingCompiler, result);
|
|
97
|
+
quiet || utils_namespaceObject.logger.info(result.message);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [
|
|
101
|
+
`${watchDir}/**/*.d.ts`
|
|
102
|
+
]);
|
|
114
103
|
};
|
|
115
|
-
const buildWatch = (option, babelConfig = {})
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
104
|
+
const buildWatch = (option, babelConfig = {})=>{
|
|
105
|
+
const buildWatchEmitter = new BuildWatchEmitter();
|
|
106
|
+
buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
|
|
107
|
+
return buildWatchEmitter;
|
|
119
108
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
109
|
+
exports.BuildWatchEmitter = __webpack_exports__.BuildWatchEmitter;
|
|
110
|
+
exports.BuildWatchEvent = __webpack_exports__.BuildWatchEvent;
|
|
111
|
+
exports.buildWatch = __webpack_exports__.buildWatch;
|
|
112
|
+
exports.runBuildWatch = __webpack_exports__.runBuildWatch;
|
|
113
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
114
|
+
"BuildWatchEmitter",
|
|
115
|
+
"BuildWatchEvent",
|
|
116
|
+
"buildWatch",
|
|
117
|
+
"runBuildWatch"
|
|
118
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
119
|
+
Object.defineProperty(exports, '__esModule', {
|
|
120
|
+
value: true
|
|
126
121
|
});
|
package/dist/cjs/compiler.js
CHANGED
|
@@ -1,132 +1,119 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
compiler: () => compiler,
|
|
32
|
-
getDistFilePath: () => getDistFilePath,
|
|
33
|
-
isRes: () => isRes,
|
|
34
|
-
resolveSourceMap: () => resolveSourceMap
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
getDistFilePath: ()=>getDistFilePath,
|
|
28
|
+
compiler: ()=>compiler,
|
|
29
|
+
resolveSourceMap: ()=>resolveSourceMap,
|
|
30
|
+
isRes: ()=>isRes
|
|
35
31
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return path.join(distDir, path.relative(rootDir, filepath).replace(ext, extMap[ext]));
|
|
32
|
+
const external_path_namespaceObject = require("path");
|
|
33
|
+
const core_namespaceObject = require("@babel/core");
|
|
34
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
35
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
36
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
37
|
+
const defaultDistDir = 'dist';
|
|
38
|
+
const isRes = (r)=>Boolean(r);
|
|
39
|
+
const getDistFilePath = (option)=>{
|
|
40
|
+
const { filepath, rootDir, distDir, extMap } = option;
|
|
41
|
+
const ext = external_path_namespaceObject.extname(filepath);
|
|
42
|
+
return external_path_namespaceObject.join(distDir, external_path_namespaceObject.relative(rootDir, filepath).replace(ext, extMap[ext]));
|
|
48
43
|
};
|
|
49
|
-
const resolveSourceMap = (option)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
const resolveSourceMap = (option)=>{
|
|
45
|
+
const { babelRes, sourceFilePath, distFilePath, enableVirtualDist = false } = option;
|
|
46
|
+
const mapLoc = `${distFilePath}.map`;
|
|
47
|
+
babelRes.code = external_utils_js_namespaceObject.addSourceMappingUrl(babelRes.code, mapLoc);
|
|
48
|
+
if (babelRes.map) {
|
|
49
|
+
babelRes.map.file = external_path_namespaceObject.basename(distFilePath);
|
|
50
|
+
babelRes.map.sources = [
|
|
51
|
+
external_path_namespaceObject.relative(external_path_namespaceObject.dirname(distFilePath), sourceFilePath)
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
const sourceMapVirtualDist = {
|
|
55
|
+
sourcemap: JSON.stringify(babelRes.map),
|
|
56
|
+
sourceMapPath: mapLoc
|
|
57
|
+
};
|
|
58
|
+
if (enableVirtualDist) return sourceMapVirtualDist;
|
|
59
|
+
utils_namespaceObject.fs.ensureDirSync(external_path_namespaceObject.dirname(mapLoc));
|
|
60
|
+
utils_namespaceObject.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
64
61
|
return sourceMapVirtualDist;
|
|
65
|
-
}
|
|
66
|
-
import_utils.fs.ensureDirSync(path.dirname(mapLoc));
|
|
67
|
-
import_utils.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
|
|
68
|
-
return sourceMapVirtualDist;
|
|
69
62
|
};
|
|
70
|
-
const compiler = (option)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
sourceMapPath: "",
|
|
87
|
-
code: "",
|
|
88
|
-
sourcemap: ""
|
|
63
|
+
const compiler = (option)=>{
|
|
64
|
+
const { filepath, rootDir, enableVirtualDist = false, distDir = external_path_namespaceObject.join(external_path_namespaceObject.dirname(rootDir), defaultDistDir), verbose = false, babelConfig = {}, distFileExtMap = external_constants_js_namespaceObject.defaultDistFileExtMap, quiet = false } = option;
|
|
65
|
+
const babelRes = core_namespaceObject.transformFileSync(filepath, babelConfig);
|
|
66
|
+
let virtualDist = null;
|
|
67
|
+
if (!isRes(babelRes)) throw new Error(`${filepath} happen error`);
|
|
68
|
+
const distFilePath = getDistFilePath({
|
|
69
|
+
filepath,
|
|
70
|
+
rootDir,
|
|
71
|
+
distDir,
|
|
72
|
+
extMap: distFileExtMap
|
|
73
|
+
});
|
|
74
|
+
if (enableVirtualDist) virtualDist = {
|
|
75
|
+
distPath: distFilePath,
|
|
76
|
+
sourceMapPath: '',
|
|
77
|
+
code: '',
|
|
78
|
+
sourcemap: ''
|
|
89
79
|
};
|
|
90
|
-
|
|
91
|
-
if ((babelRes === null || babelRes === void 0 ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
|
|
92
|
-
if (virtualDist) {
|
|
93
|
-
virtualDist = {
|
|
80
|
+
if (babelRes?.map && babelConfig.sourceMaps && 'inline' !== babelConfig.sourceMaps) if (virtualDist) virtualDist = {
|
|
94
81
|
...virtualDist,
|
|
95
82
|
...resolveSourceMap({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
babelRes,
|
|
84
|
+
sourceFilePath: filepath,
|
|
85
|
+
distFilePath,
|
|
86
|
+
enableVirtualDist
|
|
100
87
|
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
resolveSourceMap({
|
|
88
|
+
};
|
|
89
|
+
else resolveSourceMap({
|
|
104
90
|
babelRes,
|
|
105
91
|
sourceFilePath: filepath,
|
|
106
92
|
distFilePath,
|
|
107
93
|
enableVirtualDist
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
...virtualDist,
|
|
114
|
-
distPath: distFilePath,
|
|
115
|
-
code: babelRes.code
|
|
94
|
+
});
|
|
95
|
+
if (virtualDist) virtualDist = {
|
|
96
|
+
...virtualDist,
|
|
97
|
+
distPath: distFilePath,
|
|
98
|
+
code: babelRes.code
|
|
116
99
|
};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
return virtualDist;
|
|
100
|
+
else {
|
|
101
|
+
utils_namespaceObject.fs.ensureDirSync(external_path_namespaceObject.dirname(distFilePath));
|
|
102
|
+
utils_namespaceObject.fs.writeFileSync(distFilePath, babelRes.code);
|
|
103
|
+
}
|
|
104
|
+
if (verbose && !quiet) utils_namespaceObject.logger.info(`${filepath} => ${distFilePath}`);
|
|
105
|
+
return virtualDist;
|
|
125
106
|
};
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
107
|
+
exports.compiler = __webpack_exports__.compiler;
|
|
108
|
+
exports.getDistFilePath = __webpack_exports__.getDistFilePath;
|
|
109
|
+
exports.isRes = __webpack_exports__.isRes;
|
|
110
|
+
exports.resolveSourceMap = __webpack_exports__.resolveSourceMap;
|
|
111
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
112
|
+
"compiler",
|
|
113
|
+
"getDistFilePath",
|
|
114
|
+
"isRes",
|
|
115
|
+
"resolveSourceMap"
|
|
116
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
117
|
+
Object.defineProperty(exports, '__esModule', {
|
|
118
|
+
value: true
|
|
132
119
|
});
|