@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.
@@ -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
- export async function compiler(compilerOptions, babelOptions = {}) {
6
- const validRet = validate(compilerOptions);
7
- if (validRet) {
8
- return validRet;
9
- }
10
- const finalCompilerOption = getFinalCompilerOption(compilerOptions);
11
- if (compilerOptions.enableWatch) {
12
- return buildWatch(finalCompilerOption, babelOptions);
13
- } else {
14
- return build(finalCompilerOption, babelOptions);
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
+ };
@@ -1,4 +1,8 @@
1
- import * as path from 'path';
2
- export function addSourceMappingUrl(code, loc) {
3
- return `${code}\n//# sourceMappingURL=${path.normalize(path.basename(loc))}`;
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 '@modern-js/utils';
2
- export const sourceDirAndFileNamesValidMessage = 'At least one of the sourceDir and filenames configurations must be configured';
3
- export const watchDirValidMessage = 'should set watchDir when enableWatch is true';
4
- export const validateSourceDirAndFileNames = compilerOptions => {
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
- export const validateWatchDir = compilerOptions => {
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
- export const validate = compilerOptions => {
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
+ };
@@ -1,32 +1,68 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.build = void 0;
7
- var _utils = require("@modern-js/utils");
8
- var _constants = require("./constants");
9
- var _compiler = require("./compiler");
10
- const build = async (option, babelConfig = {}) => {
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 = _constants.defaultDistFileExtMap,
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
- await _utils.fs.remove(distDir);
59
+ yield import_utils.fs.remove(distDir);
24
60
  }
25
- _utils.fs.ensureDir(distDir);
61
+ import_utils.fs.ensureDir(distDir);
26
62
  const messageDetails = [];
27
63
  for (const filename of filenames) {
28
64
  try {
29
- const dist = (0, _compiler.compiler)({
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
- _utils.logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? 'files' : 'file'} with Babel.`);
53
- // TODO: 具体的报错信息打印
88
+ import_utils.logger.error(
89
+ `Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? "files" : "file"} with Babel.`
90
+ );
54
91
  } else {
55
- _utils.logger.info(`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? 'files' : 'file'} with Babel.`);
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 ? 'files' : 'file'} with Babel.`,
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 ? 'files' : 'file'} with Babel.`,
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- exports.runBuildWatch = exports.buildWatch = exports.BuildWatchEvent = exports.BuildWatchEmitter = void 0;
7
- var path = _interopRequireWildcard(require("path"));
8
- var Event = _interopRequireWildcard(require("events"));
9
- var _utils = require("@modern-js/utils");
10
- var _build = require("./build");
11
- var _compilerErrorResult = require("./compilerErrorResult");
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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: 'first-compiler',
19
- compiling: 'compiling',
20
- watchingCompiler: 'watching-compiler'
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
- async watch() {
32
- if (typeof this._initFn === 'function') {
33
- return this._initFn(this);
34
- }
35
- return null;
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
- exports.BuildWatchEmitter = BuildWatchEmitter;
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 _compilerErrorResult.CompilerErrorResult();
96
+ const errorResult = new import_compilerErrorResult.CompilerErrorResult();
42
97
  const watchDir = option.watchDir;
43
- const {
44
- distDir,
45
- quiet
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, _utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
59
- changeType,
60
- changedFilePath
61
- }) => {
62
- emitter.emit(BuildWatchEvent.compiling);
63
- if (changeType === _utils.WatchChangeType.UNLINK) {
64
- const removeFiles = [path.normalize(`./${distDir}/${path.relative(watchDir, changedFilePath)}`)];
65
- if (!quiet) {
66
- _utils.logger.info(`remove file: ${removeFiles.join(',')}`);
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
- code: 0,
70
- message: `remove file: ${removeFiles.join(',')}`,
71
- removeFiles
72
- };
73
- emitter.emit(BuildWatchEvent.watchingCompiler, result);
74
- return;
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
- emitter.emit(BuildWatchEvent.watchingCompiler, result);
93
- !quiet && _utils.logger.info(result.message);
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
- }, [`${watchDir}/**/*.d.ts`]);
97
- };
98
- exports.runBuildWatch = runBuildWatch;
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;
@@ -1,34 +1,69 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- exports.resolveSourceMap = exports.isRes = exports.getDistFilePath = exports.compiler = void 0;
7
- var path = _interopRequireWildcard(require("path"));
8
- var babel = _interopRequireWildcard(require("@babel/core"));
9
- var _utils = require("@modern-js/utils");
10
- var utils = _interopRequireWildcard(require("./utils"));
11
- var _constants = require("./constants");
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
- const defaultDistDir = 'dist';
18
- const isRes = r => Boolean(r);
19
- exports.isRes = isRes;
20
- const getDistFilePath = option => {
21
- const {
22
- filepath,
23
- rootDir,
24
- distDir,
25
- extMap
26
- } = option;
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(distDir, path.relative(rootDir, filepath).replace(ext, extMap[ext]));
61
+ return path.join(
62
+ distDir,
63
+ path.relative(rootDir, filepath).replace(ext, extMap[ext])
64
+ );
29
65
  };
30
- exports.getDistFilePath = getDistFilePath;
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 = [path.relative(path.dirname(distFilePath), sourceFilePath)];
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
- _utils.fs.ensureDirSync(path.dirname(mapLoc));
52
- _utils.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
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
- exports.resolveSourceMap = resolveSourceMap;
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 = _constants.defaultDistFileExtMap,
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 !== null && babelRes !== void 0 && babelRes.map && babelConfig.sourceMaps && babelConfig.sourceMaps !== 'inline') {
122
+ if ((babelRes == null ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
87
123
  if (virtualDist) {
88
- virtualDist = _objectSpread(_objectSpread({}, virtualDist), resolveSourceMap({
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 = _objectSpread(_objectSpread({}, virtualDist), {}, {
140
+ virtualDist = __spreadProps(__spreadValues({}, virtualDist), {
105
141
  distPath: distFilePath,
106
142
  code: babelRes.code
107
143
  });
108
144
  } else {
109
- _utils.fs.ensureDirSync(path.dirname(distFilePath));
110
- _utils.fs.writeFileSync(distFilePath, babelRes.code);
145
+ import_utils.fs.ensureDirSync(path.dirname(distFilePath));
146
+ import_utils.fs.writeFileSync(distFilePath, babelRes.code);
111
147
  }
112
148
  if (verbose && !quiet) {
113
- _utils.logger.info(`${filepath} => ${distFilePath}`);
149
+ import_utils.logger.info(`${filepath} => ${distFilePath}`);
114
150
  }
115
151
  return virtualDist;
116
152
  };
117
- exports.compiler = compiler;