@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.
Files changed (55) hide show
  1. package/dist/cjs/build.js +68 -73
  2. package/dist/cjs/buildWatch.js +111 -116
  3. package/dist/cjs/compiler.js +103 -116
  4. package/dist/cjs/compilerErrorResult.js +61 -56
  5. package/dist/cjs/constants.js +36 -28
  6. package/dist/cjs/defaults.js +46 -38
  7. package/dist/cjs/getFinalOption.js +82 -83
  8. package/dist/cjs/index.js +92 -44
  9. package/dist/cjs/type.js +17 -15
  10. package/dist/cjs/utils.js +34 -37
  11. package/dist/cjs/validate.js +70 -64
  12. package/dist/esm/build.mjs +42 -0
  13. package/dist/esm/buildWatch.mjs +78 -0
  14. package/dist/esm/compiler.mjs +76 -0
  15. package/dist/esm/compilerErrorResult.mjs +34 -0
  16. package/dist/esm/constants.mjs +7 -0
  17. package/dist/esm/defaults.mjs +17 -0
  18. package/dist/esm/getFinalOption.mjs +50 -0
  19. package/dist/{esm-node/index.js → esm/index.mjs} +7 -14
  20. package/dist/esm/utils.mjs +5 -0
  21. package/dist/esm/validate.mjs +32 -0
  22. package/dist/esm-node/build.mjs +42 -0
  23. package/dist/esm-node/buildWatch.mjs +78 -0
  24. package/dist/esm-node/compiler.mjs +76 -0
  25. package/dist/esm-node/compilerErrorResult.mjs +34 -0
  26. package/dist/esm-node/constants.mjs +7 -0
  27. package/dist/esm-node/defaults.mjs +17 -0
  28. package/dist/esm-node/getFinalOption.mjs +50 -0
  29. package/dist/esm-node/index.mjs +14 -0
  30. package/dist/esm-node/utils.mjs +5 -0
  31. package/dist/esm-node/validate.mjs +32 -0
  32. package/package.json +24 -17
  33. package/rslib.config.mts +4 -0
  34. package/rstest.config.ts +7 -0
  35. package/dist/esm/build.js +0 -105
  36. package/dist/esm/buildWatch.js +0 -157
  37. package/dist/esm/compiler.js +0 -95
  38. package/dist/esm/compilerErrorResult.js +0 -71
  39. package/dist/esm/constants.js +0 -9
  40. package/dist/esm/defaults.js +0 -19
  41. package/dist/esm/getFinalOption.js +0 -68
  42. package/dist/esm/index.js +0 -46
  43. package/dist/esm/utils.js +0 -7
  44. package/dist/esm/validate.js +0 -44
  45. package/dist/esm-node/build.js +0 -57
  46. package/dist/esm-node/buildWatch.js +0 -89
  47. package/dist/esm-node/compiler.js +0 -95
  48. package/dist/esm-node/compilerErrorResult.js +0 -39
  49. package/dist/esm-node/constants.js +0 -9
  50. package/dist/esm-node/defaults.js +0 -19
  51. package/dist/esm-node/getFinalOption.js +0 -67
  52. package/dist/esm-node/utils.js +0 -8
  53. package/dist/esm-node/validate.js +0 -44
  54. /package/dist/esm/{type.js → type.mjs} +0 -0
  55. /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 __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var build_exports = {};
20
- __export(build_exports, {
21
- build: () => build
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
- module.exports = __toCommonJS(build_exports);
24
- var import_utils = require("@modern-js/utils");
25
- var import_compiler = require("./compiler");
26
- var import_constants = require("./constants");
27
- const build = async (option, babelConfig = {}) => {
28
- const { rootDir, enableVirtualDist, filenames, clean, distDir, distFileExtMap = import_constants.defaultDistFileExtMap, verbose = false, quiet = false } = option;
29
- const virtualDists = [];
30
- if (clean) {
31
- await import_utils.fs.remove(distDir);
32
- }
33
- import_utils.fs.ensureDir(distDir);
34
- const messageDetails = [];
35
- for (const filename of filenames) {
36
- try {
37
- const dist = (0, import_compiler.compiler)({
38
- rootDir,
39
- enableVirtualDist,
40
- filepath: filename,
41
- distDir,
42
- verbose,
43
- quiet,
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
- messageDetails.push({
52
- filename,
53
- content: e.toString()
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
- if (happenError) {
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
- code: 1,
68
- message: `Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`,
69
- messageDetails
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
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {
80
- build
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
  });
@@ -1,126 +1,121 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var buildWatch_exports = {};
30
- __export(buildWatch_exports, {
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
- module.exports = __toCommonJS(buildWatch_exports);
37
- var Event = __toESM(require("events"));
38
- var path = __toESM(require("path"));
39
- var import_utils = require("@modern-js/utils");
40
- var import_build = require("./build");
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
- firstCompiler: "first-compiler",
44
- compiling: "compiling",
45
- watchingCompiler: "watching-compiler"
38
+ firstCompiler: 'first-compiler',
39
+ compiling: 'compiling',
40
+ watchingCompiler: 'watching-compiler'
46
41
  };
47
- class BuildWatchEmitter extends Event.EventEmitter {
48
- setInitFn(fn) {
49
- this._initFn = fn;
50
- }
51
- async watch() {
52
- if (typeof this._initFn === "function") {
53
- return this._initFn(this);
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
- if (changeType === import_utils.WatchChangeType.UNLINK) {
74
- const removeFiles = [
75
- path.normalize(`./${distDir}/${path.relative(watchDir, changedFilePath)}`)
76
- ];
77
- if (!quiet) {
78
- import_utils.logger.info(`remove file: ${removeFiles.join(",")}`);
79
- }
80
- const result2 = {
81
- code: 0,
82
- message: `remove file: ${removeFiles.join(",")}`,
83
- removeFiles
84
- };
85
- emitter.emit(BuildWatchEvent.watchingCompiler, result2);
86
- return;
87
- }
88
- const result = await (0, import_build.build)({
89
- ...option,
90
- filenames: [
91
- changedFilePath
92
- ]
93
- }, babelConfig);
94
- if (result.code === 1) {
95
- errorResult.update(result.messageDetails || []);
96
- emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
97
- !quiet && import_utils.logger.info(errorResult.value.message);
98
- } else {
99
- errorResult.removeByFileName(changedFilePath);
100
- if (errorResult.checkExistError()) {
101
- emitter.emit(BuildWatchEvent.watchingCompiler, {
102
- ...errorResult.value,
103
- virtualDists: result.virtualDists
104
- });
105
- !quiet && import_utils.logger.info(errorResult.value.message);
106
- } else {
107
- emitter.emit(BuildWatchEvent.watchingCompiler, result);
108
- !quiet && import_utils.logger.info(result.message);
109
- }
110
- }
111
- }, [
112
- `${watchDir}/**/*.d.ts`
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
- const buildWatchEmitter = new BuildWatchEmitter();
117
- buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
118
- return buildWatchEmitter;
104
+ const buildWatch = (option, babelConfig = {})=>{
105
+ const buildWatchEmitter = new BuildWatchEmitter();
106
+ buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
107
+ return buildWatchEmitter;
119
108
  };
120
- // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {
122
- BuildWatchEmitter,
123
- BuildWatchEvent,
124
- buildWatch,
125
- runBuildWatch
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
  });
@@ -1,132 +1,119 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var compiler_exports = {};
30
- __export(compiler_exports, {
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
- module.exports = __toCommonJS(compiler_exports);
37
- var path = __toESM(require("path"));
38
- var babel = __toESM(require("@babel/core"));
39
- var import_utils = require("@modern-js/utils");
40
- var import_constants = require("./constants");
41
- var utils = __toESM(require("./utils"));
42
- const defaultDistDir = "dist";
43
- const isRes = (r) => Boolean(r);
44
- const getDistFilePath = (option) => {
45
- const { filepath, rootDir, distDir, extMap } = option;
46
- const ext = path.extname(filepath);
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
- const { babelRes, sourceFilePath, distFilePath, enableVirtualDist = false } = option;
51
- const mapLoc = `${distFilePath}.map`;
52
- babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
53
- if (babelRes.map) {
54
- babelRes.map.file = path.basename(distFilePath);
55
- babelRes.map.sources = [
56
- path.relative(path.dirname(distFilePath), sourceFilePath)
57
- ];
58
- }
59
- const sourceMapVirtualDist = {
60
- sourcemap: JSON.stringify(babelRes.map),
61
- sourceMapPath: mapLoc
62
- };
63
- if (enableVirtualDist) {
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
- const { filepath, rootDir, enableVirtualDist = false, distDir = path.join(path.dirname(rootDir), defaultDistDir), verbose = false, babelConfig = {}, distFileExtMap = import_constants.defaultDistFileExtMap, quiet = false } = option;
72
- const babelRes = babel.transformFileSync(filepath, babelConfig);
73
- let virtualDist = null;
74
- if (!isRes(babelRes)) {
75
- throw new Error(`${filepath} happen error`);
76
- }
77
- const distFilePath = getDistFilePath({
78
- filepath,
79
- rootDir,
80
- distDir,
81
- extMap: distFileExtMap
82
- });
83
- if (enableVirtualDist) {
84
- virtualDist = {
85
- distPath: distFilePath,
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
- babelRes,
97
- sourceFilePath: filepath,
98
- distFilePath,
99
- enableVirtualDist
83
+ babelRes,
84
+ sourceFilePath: filepath,
85
+ distFilePath,
86
+ enableVirtualDist
100
87
  })
101
- };
102
- } else {
103
- resolveSourceMap({
88
+ };
89
+ else resolveSourceMap({
104
90
  babelRes,
105
91
  sourceFilePath: filepath,
106
92
  distFilePath,
107
93
  enableVirtualDist
108
- });
109
- }
110
- }
111
- if (virtualDist) {
112
- virtualDist = {
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
- } else {
118
- import_utils.fs.ensureDirSync(path.dirname(distFilePath));
119
- import_utils.fs.writeFileSync(distFilePath, babelRes.code);
120
- }
121
- if (verbose && !quiet) {
122
- import_utils.logger.info(`${filepath} => ${distFilePath}`);
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
- // Annotate the CommonJS export names for ESM import in node:
127
- 0 && (module.exports = {
128
- compiler,
129
- getDistFilePath,
130
- isRes,
131
- resolveSourceMap
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
  });