@modern-js/babel-compiler 2.4.1-beta.0 → 2.6.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 (37) hide show
  1. package/CHANGELOG.md +19 -2
  2. package/dist/{js/node → cjs}/build.js +3 -23
  3. package/dist/{js/node → cjs}/buildWatch.js +19 -53
  4. package/dist/{js/node → cjs}/compiler.js +16 -25
  5. package/dist/{js/node → cjs}/defaults.js +4 -15
  6. package/dist/{js/node → cjs}/getFinalOption.js +3 -19
  7. package/dist/{js/node → cjs}/index.js +11 -33
  8. package/dist/{js/node → cjs}/utils.js +4 -0
  9. package/dist/{js/modern → esm-node}/build.js +3 -23
  10. package/dist/{js/modern → esm-node}/buildWatch.js +15 -55
  11. package/dist/{js/modern → esm-node}/compiler.js +12 -27
  12. package/dist/esm-node/defaults.js +19 -0
  13. package/dist/{js/modern → esm-node}/getFinalOption.js +3 -21
  14. package/dist/esm-node/index.js +21 -0
  15. package/package.json +9 -10
  16. package/dist/js/modern/defaults.js +0 -32
  17. package/dist/js/modern/index.js +0 -43
  18. /package/dist/{js/node → cjs}/compilerErrorResult.js +0 -0
  19. /package/dist/{js/node → cjs}/constants.js +0 -0
  20. /package/dist/{js/node → cjs}/type.js +0 -0
  21. /package/dist/{js/node → cjs}/validate.js +0 -0
  22. /package/dist/{js/treeshaking → esm}/build.js +0 -0
  23. /package/dist/{js/treeshaking → esm}/buildWatch.js +0 -0
  24. /package/dist/{js/treeshaking → esm}/compiler.js +0 -0
  25. /package/dist/{js/treeshaking → esm}/compilerErrorResult.js +0 -0
  26. /package/dist/{js/treeshaking → esm}/constants.js +0 -0
  27. /package/dist/{js/treeshaking → esm}/defaults.js +0 -0
  28. /package/dist/{js/treeshaking → esm}/getFinalOption.js +0 -0
  29. /package/dist/{js/treeshaking → esm}/index.js +0 -0
  30. /package/dist/{js/treeshaking → esm}/type.js +0 -0
  31. /package/dist/{js/treeshaking → esm}/utils.js +0 -0
  32. /package/dist/{js/treeshaking → esm}/validate.js +0 -0
  33. /package/dist/{js/modern → esm-node}/compilerErrorResult.js +0 -0
  34. /package/dist/{js/modern → esm-node}/constants.js +0 -0
  35. /package/dist/{js/modern → esm-node}/type.js +0 -0
  36. /package/dist/{js/modern → esm-node}/utils.js +0 -0
  37. /package/dist/{js/modern → esm-node}/validate.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,11 +1,28 @@
1
1
  # @modern-js/babel-compiler
2
2
 
3
- ## 2.4.1-beta.0
3
+ ## 2.6.0
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - Updated dependencies [e1f799e]
8
+ - Updated dependencies [7915ab3]
9
+ - Updated dependencies [0fe658a]
10
+ - @modern-js/utils@2.6.0
11
+
12
+ ## 2.5.0
13
+
14
+ ### Patch Changes
15
+
16
+ - 89ca6cc: refactor: merge build-config into scripts/build
17
+
18
+ refactor: 把 build-config 合并进 scripts/build
19
+
20
+ - 30614fa: chore: modify package.json entry fields and build config
21
+ chore: 更改 package.json entry 字段以及构建配置
22
+ - Updated dependencies [30614fa]
23
+ - Updated dependencies [1b0ce87]
7
24
  - Updated dependencies [11c053b]
8
- - @modern-js/utils@2.4.1-beta.0
25
+ - @modern-js/utils@2.5.0
9
26
 
10
27
  ## 2.4.0
11
28
 
@@ -15,26 +15,6 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var __async = (__this, __arguments, generator) => {
19
- return new Promise((resolve, reject) => {
20
- var fulfilled = (value) => {
21
- try {
22
- step(generator.next(value));
23
- } catch (e) {
24
- reject(e);
25
- }
26
- };
27
- var rejected = (value) => {
28
- try {
29
- step(generator.throw(value));
30
- } catch (e) {
31
- reject(e);
32
- }
33
- };
34
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
- step((generator = generator.apply(__this, __arguments)).next());
36
- });
37
- };
38
18
  var build_exports = {};
39
19
  __export(build_exports, {
40
20
  build: () => build
@@ -43,7 +23,7 @@ module.exports = __toCommonJS(build_exports);
43
23
  var import_utils = require("@modern-js/utils");
44
24
  var import_constants = require("./constants");
45
25
  var import_compiler = require("./compiler");
46
- const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}) {
26
+ const build = async (option, babelConfig = {}) => {
47
27
  const {
48
28
  rootDir,
49
29
  enableVirtualDist,
@@ -56,7 +36,7 @@ const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, bab
56
36
  } = option;
57
37
  const virtualDists = [];
58
38
  if (clean) {
59
- yield import_utils.fs.remove(distDir);
39
+ await import_utils.fs.remove(distDir);
60
40
  }
61
41
  import_utils.fs.ensureDir(distDir);
62
42
  const messageDetails = [];
@@ -106,7 +86,7 @@ const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, bab
106
86
  message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`,
107
87
  virtualDists
108
88
  };
109
- });
89
+ };
110
90
  // Annotate the CommonJS export names for ESM import in node:
111
91
  0 && (module.exports = {
112
92
  build
@@ -1,26 +1,9 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
7
  var __export = (target, all) => {
25
8
  for (var name in all)
26
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -34,30 +17,14 @@ var __copyProps = (to, from, except, desc) => {
34
17
  return to;
35
18
  };
36
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
37
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
25
  mod
39
26
  ));
40
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
- var __async = (__this, __arguments, generator) => {
42
- return new Promise((resolve, reject) => {
43
- var fulfilled = (value) => {
44
- try {
45
- step(generator.next(value));
46
- } catch (e) {
47
- reject(e);
48
- }
49
- };
50
- var rejected = (value) => {
51
- try {
52
- step(generator.throw(value));
53
- } catch (e) {
54
- reject(e);
55
- }
56
- };
57
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
58
- step((generator = generator.apply(__this, __arguments)).next());
59
- });
60
- };
61
28
  var buildWatch_exports = {};
62
29
  __export(buildWatch_exports, {
63
30
  BuildWatchEmitter: () => BuildWatchEmitter,
@@ -80,21 +47,19 @@ class BuildWatchEmitter extends Event.EventEmitter {
80
47
  setInitFn(fn) {
81
48
  this._initFn = fn;
82
49
  }
83
- watch() {
84
- return __async(this, null, function* () {
85
- if (typeof this._initFn === "function") {
86
- return this._initFn(this);
87
- }
88
- return null;
89
- });
50
+ async watch() {
51
+ if (typeof this._initFn === "function") {
52
+ return this._initFn(this);
53
+ }
54
+ return null;
90
55
  }
91
56
  }
92
- const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}, emitter) {
57
+ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
93
58
  emitter.emit(BuildWatchEvent.compiling);
94
59
  const errorResult = new import_compilerErrorResult.CompilerErrorResult();
95
60
  const watchDir = option.watchDir;
96
61
  const { distDir, quiet } = option;
97
- const firstBuildResult = yield (0, import_build.build)(option, babelConfig);
62
+ const firstBuildResult = await (0, import_build.build)(option, babelConfig);
98
63
  const { code } = firstBuildResult;
99
64
  if (code === 1) {
100
65
  errorResult.init(firstBuildResult);
@@ -104,7 +69,7 @@ const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (opt
104
69
  }
105
70
  return (0, import_utils.watch)(
106
71
  `${watchDir}/**/*.{js,jsx,ts,tsx}`,
107
- (_02) => __async(void 0, [_02], function* ({ changeType, changedFilePath }) {
72
+ async ({ changeType, changedFilePath }) => {
108
73
  emitter.emit(BuildWatchEvent.compiling);
109
74
  if (changeType === import_utils.WatchChangeType.UNLINK) {
110
75
  const removeFiles = [
@@ -123,8 +88,8 @@ const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (opt
123
88
  emitter.emit(BuildWatchEvent.watchingCompiler, result2);
124
89
  return;
125
90
  }
126
- const result = yield (0, import_build.build)(
127
- __spreadProps(__spreadValues({}, option), { filenames: [changedFilePath] }),
91
+ const result = await (0, import_build.build)(
92
+ { ...option, filenames: [changedFilePath] },
128
93
  babelConfig
129
94
  );
130
95
  if (result.code === 1) {
@@ -134,19 +99,20 @@ const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (opt
134
99
  } else {
135
100
  errorResult.removeByFileName(changedFilePath);
136
101
  if (errorResult.checkExistError()) {
137
- emitter.emit(BuildWatchEvent.watchingCompiler, __spreadProps(__spreadValues({}, errorResult.value), {
102
+ emitter.emit(BuildWatchEvent.watchingCompiler, {
103
+ ...errorResult.value,
138
104
  virtualDists: result.virtualDists
139
- }));
105
+ });
140
106
  !quiet && import_utils.logger.info(errorResult.value.message);
141
107
  } else {
142
108
  emitter.emit(BuildWatchEvent.watchingCompiler, result);
143
109
  !quiet && import_utils.logger.info(result.message);
144
110
  }
145
111
  }
146
- }),
112
+ },
147
113
  [`${watchDir}/**/*.d.ts`]
148
114
  );
149
- });
115
+ };
150
116
  const buildWatch = (option, babelConfig = {}) => {
151
117
  const buildWatchEmitter = new BuildWatchEmitter();
152
118
  buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
@@ -1,26 +1,9 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
7
  var __export = (target, all) => {
25
8
  for (var name in all)
26
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -34,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
34
17
  return to;
35
18
  };
36
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
37
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
25
  mod
39
26
  ));
@@ -119,12 +106,15 @@ const compiler = (option) => {
119
106
  }
120
107
  if ((babelRes == null ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
121
108
  if (virtualDist) {
122
- virtualDist = __spreadValues(__spreadValues({}, virtualDist), resolveSourceMap({
123
- babelRes,
124
- sourceFilePath: filepath,
125
- distFilePath,
126
- enableVirtualDist
127
- }));
109
+ virtualDist = {
110
+ ...virtualDist,
111
+ ...resolveSourceMap({
112
+ babelRes,
113
+ sourceFilePath: filepath,
114
+ distFilePath,
115
+ enableVirtualDist
116
+ })
117
+ };
128
118
  } else {
129
119
  resolveSourceMap({
130
120
  babelRes,
@@ -135,10 +125,11 @@ const compiler = (option) => {
135
125
  }
136
126
  }
137
127
  if (virtualDist) {
138
- virtualDist = __spreadProps(__spreadValues({}, virtualDist), {
128
+ virtualDist = {
129
+ ...virtualDist,
139
130
  distPath: distFilePath,
140
131
  code: babelRes.code
141
- });
132
+ };
142
133
  } else {
143
134
  import_utils.fs.ensureDirSync(path.dirname(distFilePath));
144
135
  import_utils.fs.writeFileSync(distFilePath, babelRes.code);
@@ -1,21 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
5
  var __export = (target, all) => {
20
6
  for (var name in all)
21
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -46,7 +32,10 @@ const defaultOptions = {
46
32
  verbose: false,
47
33
  clean: false
48
34
  };
49
- const mergeDefaultOption = (compilerOptions) => __spreadValues(__spreadValues({}, defaultOptions), compilerOptions);
35
+ const mergeDefaultOption = (compilerOptions) => ({
36
+ ...defaultOptions,
37
+ ...compilerOptions
38
+ });
50
39
  // Annotate the CommonJS export names for ESM import in node:
51
40
  0 && (module.exports = {
52
41
  mergeDefaultOption
@@ -1,24 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
5
  var __export = (target, all) => {
23
6
  for (var name in all)
24
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -98,9 +81,10 @@ const getFinalCompilerOption = (option) => {
98
81
  finalExt
99
82
  });
100
83
  }
101
- return __spreadProps(__spreadValues({}, optionWithDefault), {
84
+ return {
85
+ ...optionWithDefault,
102
86
  filenames: [...optionWithDefault.filenames, ...globFindFilenames]
103
- });
87
+ };
104
88
  };
105
89
  // Annotate the CommonJS export names for ESM import in node:
106
90
  0 && (module.exports = {
@@ -16,26 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __async = (__this, __arguments, generator) => {
20
- return new Promise((resolve, reject) => {
21
- var fulfilled = (value) => {
22
- try {
23
- step(generator.next(value));
24
- } catch (e) {
25
- reject(e);
26
- }
27
- };
28
- var rejected = (value) => {
29
- try {
30
- step(generator.throw(value));
31
- } catch (e) {
32
- reject(e);
33
- }
34
- };
35
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
36
- step((generator = generator.apply(__this, __arguments)).next());
37
- });
38
- };
39
19
  var src_exports = {};
40
20
  __export(src_exports, {
41
21
  compiler: () => compiler
@@ -47,19 +27,17 @@ var import_buildWatch = require("./buildWatch");
47
27
  var import_validate = require("./validate");
48
28
  __reExport(src_exports, require("./buildWatch"), module.exports);
49
29
  __reExport(src_exports, require("./type"), module.exports);
50
- function compiler(_0) {
51
- return __async(this, arguments, function* (compilerOptions, babelOptions = {}) {
52
- const validRet = (0, import_validate.validate)(compilerOptions);
53
- if (validRet) {
54
- return validRet;
55
- }
56
- const finalCompilerOption = (0, import_getFinalOption.getFinalCompilerOption)(compilerOptions);
57
- if (compilerOptions.enableWatch) {
58
- return (0, import_buildWatch.buildWatch)(finalCompilerOption, babelOptions);
59
- } else {
60
- return (0, import_build.build)(finalCompilerOption, babelOptions);
61
- }
62
- });
30
+ async function compiler(compilerOptions, babelOptions = {}) {
31
+ const validRet = (0, import_validate.validate)(compilerOptions);
32
+ if (validRet) {
33
+ return validRet;
34
+ }
35
+ const finalCompilerOption = (0, import_getFinalOption.getFinalCompilerOption)(compilerOptions);
36
+ if (compilerOptions.enableWatch) {
37
+ return (0, import_buildWatch.buildWatch)(finalCompilerOption, babelOptions);
38
+ } else {
39
+ return (0, import_build.build)(finalCompilerOption, babelOptions);
40
+ }
63
41
  }
64
42
  // Annotate the CommonJS export names for ESM import in node:
65
43
  0 && (module.exports = {
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -1,27 +1,7 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
1
  import { fs, logger } from "@modern-js/utils";
22
2
  import { defaultDistFileExtMap } from "./constants";
23
3
  import { compiler } from "./compiler";
24
- const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}) {
4
+ const build = async (option, babelConfig = {}) => {
25
5
  const {
26
6
  rootDir,
27
7
  enableVirtualDist,
@@ -34,7 +14,7 @@ const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, bab
34
14
  } = option;
35
15
  const virtualDists = [];
36
16
  if (clean) {
37
- yield fs.remove(distDir);
17
+ await fs.remove(distDir);
38
18
  }
39
19
  fs.ensureDir(distDir);
40
20
  const messageDetails = [];
@@ -84,7 +64,7 @@ const build = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, bab
84
64
  message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? "files" : "file"} with Babel.`,
85
65
  virtualDists
86
66
  };
87
- });
67
+ };
88
68
  export {
89
69
  build
90
70
  };
@@ -1,42 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
1
  import * as path from "path";
41
2
  import * as Event from "events";
42
3
  import { logger, watch, WatchChangeType } from "@modern-js/utils";
@@ -51,21 +12,19 @@ class BuildWatchEmitter extends Event.EventEmitter {
51
12
  setInitFn(fn) {
52
13
  this._initFn = fn;
53
14
  }
54
- watch() {
55
- return __async(this, null, function* () {
56
- if (typeof this._initFn === "function") {
57
- return this._initFn(this);
58
- }
59
- return null;
60
- });
15
+ async watch() {
16
+ if (typeof this._initFn === "function") {
17
+ return this._initFn(this);
18
+ }
19
+ return null;
61
20
  }
62
21
  }
63
- const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (option, babelConfig = {}, emitter) {
22
+ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
64
23
  emitter.emit(BuildWatchEvent.compiling);
65
24
  const errorResult = new CompilerErrorResult();
66
25
  const watchDir = option.watchDir;
67
26
  const { distDir, quiet } = option;
68
- const firstBuildResult = yield build(option, babelConfig);
27
+ const firstBuildResult = await build(option, babelConfig);
69
28
  const { code } = firstBuildResult;
70
29
  if (code === 1) {
71
30
  errorResult.init(firstBuildResult);
@@ -75,7 +34,7 @@ const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (opt
75
34
  }
76
35
  return watch(
77
36
  `${watchDir}/**/*.{js,jsx,ts,tsx}`,
78
- (_02) => __async(void 0, [_02], function* ({ changeType, changedFilePath }) {
37
+ async ({ changeType, changedFilePath }) => {
79
38
  emitter.emit(BuildWatchEvent.compiling);
80
39
  if (changeType === WatchChangeType.UNLINK) {
81
40
  const removeFiles = [
@@ -94,8 +53,8 @@ const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (opt
94
53
  emitter.emit(BuildWatchEvent.watchingCompiler, result2);
95
54
  return;
96
55
  }
97
- const result = yield build(
98
- __spreadProps(__spreadValues({}, option), { filenames: [changedFilePath] }),
56
+ const result = await build(
57
+ { ...option, filenames: [changedFilePath] },
99
58
  babelConfig
100
59
  );
101
60
  if (result.code === 1) {
@@ -105,19 +64,20 @@ const runBuildWatch = (_0, ..._1) => __async(void 0, [_0, ..._1], function* (opt
105
64
  } else {
106
65
  errorResult.removeByFileName(changedFilePath);
107
66
  if (errorResult.checkExistError()) {
108
- emitter.emit(BuildWatchEvent.watchingCompiler, __spreadProps(__spreadValues({}, errorResult.value), {
67
+ emitter.emit(BuildWatchEvent.watchingCompiler, {
68
+ ...errorResult.value,
109
69
  virtualDists: result.virtualDists
110
- }));
70
+ });
111
71
  !quiet && logger.info(errorResult.value.message);
112
72
  } else {
113
73
  emitter.emit(BuildWatchEvent.watchingCompiler, result);
114
74
  !quiet && logger.info(result.message);
115
75
  }
116
76
  }
117
- }),
77
+ },
118
78
  [`${watchDir}/**/*.d.ts`]
119
79
  );
120
- });
80
+ };
121
81
  const buildWatch = (option, babelConfig = {}) => {
122
82
  const buildWatchEmitter = new BuildWatchEmitter();
123
83
  buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  import * as path from "path";
21
2
  import * as babel from "@babel/core";
22
3
  import { logger, fs } from "@modern-js/utils";
@@ -90,12 +71,15 @@ const compiler = (option) => {
90
71
  }
91
72
  if ((babelRes == null ? void 0 : babelRes.map) && babelConfig.sourceMaps && babelConfig.sourceMaps !== "inline") {
92
73
  if (virtualDist) {
93
- virtualDist = __spreadValues(__spreadValues({}, virtualDist), resolveSourceMap({
94
- babelRes,
95
- sourceFilePath: filepath,
96
- distFilePath,
97
- enableVirtualDist
98
- }));
74
+ virtualDist = {
75
+ ...virtualDist,
76
+ ...resolveSourceMap({
77
+ babelRes,
78
+ sourceFilePath: filepath,
79
+ distFilePath,
80
+ enableVirtualDist
81
+ })
82
+ };
99
83
  } else {
100
84
  resolveSourceMap({
101
85
  babelRes,
@@ -106,10 +90,11 @@ const compiler = (option) => {
106
90
  }
107
91
  }
108
92
  if (virtualDist) {
109
- virtualDist = __spreadProps(__spreadValues({}, virtualDist), {
93
+ virtualDist = {
94
+ ...virtualDist,
110
95
  distPath: distFilePath,
111
96
  code: babelRes.code
112
- });
97
+ };
113
98
  } else {
114
99
  fs.ensureDirSync(path.dirname(distFilePath));
115
100
  fs.writeFileSync(distFilePath, babelRes.code);
@@ -0,0 +1,19 @@
1
+ import { defaultDistFileExtMap } from "./constants";
2
+ const defaultOptions = {
3
+ enableWatch: false,
4
+ enableVirtualDist: false,
5
+ extensions: [],
6
+ filenames: [],
7
+ distFileExtMap: defaultDistFileExtMap,
8
+ ignore: [],
9
+ quiet: false,
10
+ verbose: false,
11
+ clean: false
12
+ };
13
+ const mergeDefaultOption = (compilerOptions) => ({
14
+ ...defaultOptions,
15
+ ...compilerOptions
16
+ });
17
+ export {
18
+ mergeDefaultOption
19
+ };
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  import { glob } from "@modern-js/utils";
21
2
  import { DEFAULT_EXTENSIONS } from "@babel/core";
22
3
  import { mergeDefaultOption } from "./defaults";
@@ -75,9 +56,10 @@ const getFinalCompilerOption = (option) => {
75
56
  finalExt
76
57
  });
77
58
  }
78
- return __spreadProps(__spreadValues({}, optionWithDefault), {
59
+ return {
60
+ ...optionWithDefault,
79
61
  filenames: [...optionWithDefault.filenames, ...globFindFilenames]
80
- });
62
+ };
81
63
  };
82
64
  export {
83
65
  getFilesFromDir,
@@ -0,0 +1,21 @@
1
+ import { getFinalCompilerOption } from "./getFinalOption";
2
+ import { build } from "./build";
3
+ import { buildWatch } from "./buildWatch";
4
+ import { validate } from "./validate";
5
+ 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
+ }
16
+ }
17
+ export * from "./buildWatch";
18
+ export * from "./type";
19
+ export {
20
+ compiler
21
+ };
package/package.json CHANGED
@@ -11,26 +11,25 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.4.1-beta.0",
14
+ "version": "2.6.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
- "main": "./dist/js/node/index.js",
18
- "module": "./dist/js/treeshaking/index.js",
19
- "jsnext:modern": "./dist/js/modern/index.js",
17
+ "main": "./dist/cjs/index.js",
18
+ "module": "./dist/esm/index.js",
20
19
  "exports": {
21
20
  ".": {
22
21
  "node": {
23
22
  "jsnext:source": "./src/index.ts",
24
- "import": "./dist/js/modern/index.js",
25
- "require": "./dist/js/node/index.js"
23
+ "import": "./dist/esm-node/index.js",
24
+ "require": "./dist/cjs/index.js"
26
25
  },
27
- "default": "./dist/js/treeshaking/index.js"
26
+ "default": "./dist/esm/index.js"
28
27
  }
29
28
  },
30
29
  "dependencies": {
31
30
  "@babel/core": "^7.18.0",
32
31
  "@babel/runtime": "^7.18.0",
33
- "@modern-js/utils": "2.4.1-beta.0"
32
+ "@modern-js/utils": "2.6.0"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@babel/plugin-transform-classes": "^7.18.0",
@@ -41,8 +40,8 @@
41
40
  "@types/node": "^14",
42
41
  "typescript": "^4",
43
42
  "jest": "^27",
44
- "@scripts/build": "2.4.0",
45
- "@scripts/jest-config": "2.4.0"
43
+ "@scripts/build": "2.6.0",
44
+ "@scripts/jest-config": "2.6.0"
46
45
  },
47
46
  "sideEffects": false,
48
47
  "modernConfig": {
@@ -1,32 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- import { defaultDistFileExtMap } from "./constants";
18
- const defaultOptions = {
19
- enableWatch: false,
20
- enableVirtualDist: false,
21
- extensions: [],
22
- filenames: [],
23
- distFileExtMap: defaultDistFileExtMap,
24
- ignore: [],
25
- quiet: false,
26
- verbose: false,
27
- clean: false
28
- };
29
- const mergeDefaultOption = (compilerOptions) => __spreadValues(__spreadValues({}, defaultOptions), compilerOptions);
30
- export {
31
- mergeDefaultOption
32
- };
@@ -1,43 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { getFinalCompilerOption } from "./getFinalOption";
22
- import { build } from "./build";
23
- import { buildWatch } from "./buildWatch";
24
- import { validate } from "./validate";
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
- });
38
- }
39
- export * from "./buildWatch";
40
- export * from "./type";
41
- export {
42
- compiler
43
- };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes