@modern-js/babel-compiler 2.0.0-beta.0 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @modern-js/babel-compiler
2
2
 
3
+ ## 2.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [92f0ead]
12
+ - Updated dependencies [edd1cfb1af]
13
+ - Updated dependencies [cc971eabfc]
14
+ - Updated dependencies [5b9049f2e9]
15
+ - Updated dependencies [92004d1]
16
+ - Updated dependencies [b8bbe036c7]
17
+ - Updated dependencies [d5a31df781]
18
+ - Updated dependencies [dda38c9c3e]
19
+ - Updated dependencies [3bbea92b2a]
20
+ - Updated dependencies [abf3421a75]
21
+ - Updated dependencies [543be9558e]
22
+ - Updated dependencies [14b712da84]
23
+ - @modern-js/utils@2.0.0-beta.2
24
+
25
+ ## 2.0.0-beta.1
26
+
27
+ ### Major Changes
28
+
29
+ - dda38c9: chore: v2
30
+
31
+ ### Patch Changes
32
+
33
+ - Updated dependencies [92f0ead]
34
+ - Updated dependencies [edd1cfb1af]
35
+ - Updated dependencies [cc971eabfc]
36
+ - Updated dependencies [5b9049f]
37
+ - Updated dependencies [92004d1]
38
+ - Updated dependencies [b8bbe036c7]
39
+ - Updated dependencies [d5a31df781]
40
+ - Updated dependencies [dda38c9]
41
+ - Updated dependencies [3bbea92b2a]
42
+ - Updated dependencies [abf3421]
43
+ - Updated dependencies [543be9558e]
44
+ - Updated dependencies [14b712d]
45
+ - @modern-js/utils@2.0.0-beta.1
46
+
3
47
  ## 2.0.0-beta.0
4
48
 
5
49
  ### Major Changes
@@ -13,14 +13,11 @@ export const build = async (option, babelConfig = {}) => {
13
13
  quiet = false
14
14
  } = option;
15
15
  const virtualDists = [];
16
-
17
16
  if (clean) {
18
17
  await fs.remove(distDir);
19
18
  }
20
-
21
19
  fs.ensureDir(distDir);
22
20
  const messageDetails = [];
23
-
24
21
  for (const filename of filenames) {
25
22
  try {
26
23
  const dist = compiler({
@@ -33,7 +30,6 @@ export const build = async (option, babelConfig = {}) => {
33
30
  babelConfig,
34
31
  distFileExtMap
35
32
  });
36
-
37
33
  if (enableVirtualDist && dist) {
38
34
  virtualDists.push(dist);
39
35
  }
@@ -44,17 +40,15 @@ export const build = async (option, babelConfig = {}) => {
44
40
  });
45
41
  }
46
42
  }
47
-
48
43
  const happenError = messageDetails.length > 0;
49
-
50
44
  if (!quiet) {
51
45
  if (happenError) {
52
- logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? 'files' : 'file'} with Babel.`); // TODO: 具体的报错信息打印
46
+ logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? 'files' : 'file'} with Babel.`);
47
+ // TODO: 具体的报错信息打印
53
48
  } else {
54
49
  logger.info(`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? 'files' : 'file'} with Babel.`);
55
50
  }
56
51
  }
57
-
58
52
  if (happenError) {
59
53
  return {
60
54
  code: 1,
@@ -62,7 +56,6 @@ export const build = async (option, babelConfig = {}) => {
62
56
  messageDetails
63
57
  };
64
58
  }
65
-
66
59
  return {
67
60
  code: 0,
68
61
  message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? 'files' : 'file'} with Babel.`,
@@ -1,9 +1,6 @@
1
1
  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; }
2
-
3
2
  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; }
4
-
5
3
  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; }
6
-
7
4
  import * as path from 'path';
8
5
  import * as Event from 'events';
9
6
  import { logger, watch, WatchChangeType } from '@modern-js/utils';
@@ -17,22 +14,17 @@ export const BuildWatchEvent = {
17
14
  export class BuildWatchEmitter extends Event.EventEmitter {
18
15
  constructor(...args) {
19
16
  super(...args);
20
-
21
17
  _defineProperty(this, "_initFn", void 0);
22
18
  }
23
-
24
19
  setInitFn(fn) {
25
20
  this._initFn = fn;
26
21
  }
27
-
28
22
  async watch() {
29
23
  if (typeof this._initFn === 'function') {
30
24
  return this._initFn(this);
31
25
  }
32
-
33
26
  return null;
34
27
  }
35
-
36
28
  }
37
29
  export const runBuildWatch = async (option, babelConfig = {}, emitter) => {
38
30
  emitter.emit(BuildWatchEvent.compiling);
@@ -41,33 +33,28 @@ export const runBuildWatch = async (option, babelConfig = {}, emitter) => {
41
33
  const {
42
34
  distDir,
43
35
  quiet
44
- } = option; // 第一次正常构建
45
-
36
+ } = option;
37
+ // 第一次正常构建
46
38
  const firstBuildResult = await build(option, babelConfig);
47
39
  const {
48
40
  code
49
41
  } = firstBuildResult;
50
-
51
42
  if (code === 1) {
52
43
  errorResult.init(firstBuildResult);
53
44
  emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
54
45
  } else {
55
46
  emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
56
47
  }
57
-
58
48
  return watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
59
49
  changeType,
60
50
  changedFilePath
61
51
  }) => {
62
52
  emitter.emit(BuildWatchEvent.compiling);
63
-
64
53
  if (changeType === WatchChangeType.UNLINK) {
65
54
  const removeFiles = [path.normalize(`./${distDir}/${path.relative(watchDir, changedFilePath)}`)];
66
-
67
55
  if (!quiet) {
68
56
  logger.info(`remove file: ${removeFiles.join(',')}`);
69
57
  }
70
-
71
58
  const result = {
72
59
  code: 0,
73
60
  message: `remove file: ${removeFiles.join(',')}`,
@@ -76,18 +63,16 @@ export const runBuildWatch = async (option, babelConfig = {}, emitter) => {
76
63
  emitter.emit(BuildWatchEvent.watchingCompiler, result);
77
64
  return;
78
65
  }
79
-
80
66
  const result = await build(_objectSpread(_objectSpread({}, option), {}, {
81
67
  filenames: [changedFilePath]
82
68
  }), babelConfig);
83
-
84
69
  if (result.code === 1) {
85
70
  errorResult.update(result.messageDetails || []);
86
71
  emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
87
72
  !quiet && logger.info(errorResult.value.message);
88
73
  } else {
89
- errorResult.removeByFileName(changedFilePath); // 如果该文件没有报错,则更新该文件状态并检查是否还存在其他报错文件
90
-
74
+ errorResult.removeByFileName(changedFilePath);
75
+ // 如果该文件没有报错,则更新该文件状态并检查是否还存在其他报错文件
91
76
  if (errorResult.checkExistError()) {
92
77
  emitter.emit(BuildWatchEvent.watchingCompiler, _objectSpread(_objectSpread({}, errorResult.value), {}, {
93
78
  virtualDists: result.virtualDists
@@ -1,9 +1,6 @@
1
1
  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; }
2
-
3
2
  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; }
4
-
5
3
  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; }
6
-
7
4
  import * as path from 'path';
8
5
  import * as babel from '@babel/core';
9
6
  import { logger, fs } from '@modern-js/utils';
@@ -30,21 +27,17 @@ export const resolveSourceMap = option => {
30
27
  } = option;
31
28
  const mapLoc = `${distFilePath}.map`;
32
29
  babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
33
-
34
30
  if (babelRes.map) {
35
31
  babelRes.map.file = path.basename(distFilePath);
36
32
  babelRes.map.sources = [path.relative(path.dirname(distFilePath), sourceFilePath)];
37
33
  }
38
-
39
34
  const sourceMapVirtualDist = {
40
35
  sourcemap: JSON.stringify(babelRes.map),
41
36
  sourceMapPath: mapLoc
42
37
  };
43
-
44
38
  if (enableVirtualDist) {
45
39
  return sourceMapVirtualDist;
46
40
  }
47
-
48
41
  fs.ensureDirSync(path.dirname(mapLoc));
49
42
  fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
50
43
  return sourceMapVirtualDist;
@@ -62,18 +55,15 @@ export const compiler = option => {
62
55
  } = option;
63
56
  const babelRes = babel.transformFileSync(filepath, babelConfig);
64
57
  let virtualDist = null;
65
-
66
58
  if (!isRes(babelRes)) {
67
59
  throw new Error(`${filepath} happen error`);
68
60
  }
69
-
70
61
  const distFilePath = getDistFilePath({
71
62
  filepath,
72
63
  rootDir,
73
64
  distDir,
74
65
  extMap: distFileExtMap
75
66
  });
76
-
77
67
  if (enableVirtualDist) {
78
68
  virtualDist = {
79
69
  distPath: distFilePath,
@@ -82,7 +72,6 @@ export const compiler = option => {
82
72
  sourcemap: ''
83
73
  };
84
74
  }
85
-
86
75
  if (babelRes !== null && babelRes !== void 0 && babelRes.map && babelConfig.sourceMaps && babelConfig.sourceMaps !== 'inline') {
87
76
  if (virtualDist) {
88
77
  virtualDist = _objectSpread(_objectSpread({}, virtualDist), resolveSourceMap({
@@ -100,7 +89,6 @@ export const compiler = option => {
100
89
  });
101
90
  }
102
91
  }
103
-
104
92
  if (virtualDist) {
105
93
  virtualDist = _objectSpread(_objectSpread({}, virtualDist), {}, {
106
94
  distPath: distFilePath,
@@ -110,10 +98,8 @@ export const compiler = option => {
110
98
  fs.ensureDirSync(path.dirname(distFilePath));
111
99
  fs.writeFileSync(distFilePath, babelRes.code);
112
100
  }
113
-
114
101
  if (verbose && !quiet) {
115
102
  logger.info(`${filepath} => ${distFilePath}`);
116
103
  }
117
-
118
104
  return virtualDist;
119
105
  };
@@ -1,16 +1,12 @@
1
1
  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; }
2
-
3
2
  export class CompilerErrorResult {
4
3
  constructor(initErrorResult) {
5
4
  _defineProperty(this, "_messageDetails", void 0);
6
-
7
5
  this.init(initErrorResult);
8
6
  }
9
-
10
7
  init(initErrorResult) {
11
8
  this._messageDetails = (initErrorResult === null || initErrorResult === void 0 ? void 0 : initErrorResult.messageDetails) || [];
12
9
  }
13
-
14
10
  update(messageDetails) {
15
11
  for (const messageDetail of messageDetails) {
16
12
  // 遍历存不存在该文件报错信息,不存在则增加,否则更新内容
@@ -20,32 +16,25 @@ export class CompilerErrorResult {
20
16
  detail.content = messageDetail.content;
21
17
  return true;
22
18
  }
23
-
24
19
  return false;
25
20
  });
26
-
27
21
  if (addError) {
28
22
  this._messageDetails.push(messageDetail);
29
23
  }
30
24
  }
31
25
  }
32
-
33
26
  removeByFileName(filename) {
34
27
  this._messageDetails = this._messageDetails.filter(detail => detail.filename !== filename);
35
28
  }
36
-
37
29
  get value() {
38
30
  var _this$_messageDetails;
39
-
40
31
  return {
41
32
  code: 1,
42
33
  message: `Compilation failure ${(_this$_messageDetails = this._messageDetails) === null || _this$_messageDetails === void 0 ? void 0 : _this$_messageDetails.length} files with Babel.`,
43
34
  messageDetails: this._messageDetails
44
35
  };
45
36
  }
46
-
47
37
  checkExistError() {
48
38
  return this._messageDetails.length > 0;
49
39
  }
50
-
51
40
  }
@@ -1,9 +1,6 @@
1
1
  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; }
2
-
3
2
  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; }
4
-
5
3
  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; }
6
-
7
4
  import { defaultDistFileExtMap } from "./constants";
8
5
  const defaultOptions = {
9
6
  enableWatch: false,
@@ -1,9 +1,6 @@
1
1
  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; }
2
-
3
2
  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; }
4
-
5
3
  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; }
6
-
7
4
  import { glob } from '@modern-js/utils';
8
5
  import { DEFAULT_EXTENSIONS } from '@babel/core';
9
6
  import { mergeDefaultOption } from "./defaults";
@@ -18,9 +15,7 @@ export const getGlobPattern = (dir, extensions) => {
18
15
  };
19
16
  export const getFinalExtensions = extensions => {
20
17
  const isExtensions = ext => Array.isArray(ext);
21
-
22
18
  const isExtensionsFunc = ext => typeof ext === 'function';
23
-
24
19
  if (isExtensions(extensions)) {
25
20
  return [...extensions, ...DEFAULT_EXTENSIONS];
26
21
  } else if (isExtensionsFunc(extensions)) {
@@ -52,7 +47,6 @@ export const getFinalCompilerOption = option => {
52
47
  } = option;
53
48
  let globFindFilenames = [];
54
49
  const finalExt = getFinalExtensions(extensions);
55
-
56
50
  if (sourceDir) {
57
51
  globFindFilenames = getFilesFromDir({
58
52
  dir: sourceDir,
@@ -60,7 +54,6 @@ export const getFinalCompilerOption = option => {
60
54
  finalExt
61
55
  });
62
56
  }
63
-
64
57
  if (enableWatch) {
65
58
  // 开启watch模式,清空通过 sourceDir 找到的文件,而改为使用watchDirs
66
59
  globFindFilenames = getFilesFromDir({
@@ -69,7 +62,6 @@ export const getFinalCompilerOption = option => {
69
62
  finalExt
70
63
  });
71
64
  }
72
-
73
65
  return _objectSpread(_objectSpread({}, optionWithDefault), {}, {
74
66
  filenames: [...optionWithDefault.filenames, ...globFindFilenames]
75
67
  });
@@ -4,13 +4,10 @@ import { buildWatch } from "./buildWatch";
4
4
  import { validate } from "./validate";
5
5
  export async function compiler(compilerOptions, babelOptions = {}) {
6
6
  const validRet = validate(compilerOptions);
7
-
8
7
  if (validRet) {
9
8
  return validRet;
10
9
  }
11
-
12
10
  const finalCompilerOption = getFinalCompilerOption(compilerOptions);
13
-
14
11
  if (compilerOptions.enableWatch) {
15
12
  return buildWatch(finalCompilerOption, babelOptions);
16
13
  } else {
@@ -7,19 +7,16 @@ export const validateSourceDirAndFileNames = compilerOptions => {
7
7
  filenames,
8
8
  quiet
9
9
  } = compilerOptions;
10
-
11
10
  if (!sourceDir && !filenames) {
12
11
  if (!quiet) {
13
12
  logger.error(sourceDirAndFileNamesValidMessage);
14
13
  }
15
-
16
14
  return {
17
15
  code: 1,
18
16
  message: sourceDirAndFileNamesValidMessage,
19
17
  virtualDists: []
20
18
  };
21
19
  }
22
-
23
20
  return null;
24
21
  };
25
22
  export const validateWatchDir = compilerOptions => {
@@ -28,25 +25,21 @@ export const validateWatchDir = compilerOptions => {
28
25
  enableWatch,
29
26
  quiet
30
27
  } = compilerOptions;
31
-
32
28
  if (enableWatch && !watchDir) {
33
29
  if (!quiet) {
34
30
  logger.error(watchDirValidMessage);
35
31
  }
36
-
37
32
  return {
38
33
  code: 1,
39
34
  message: watchDirValidMessage,
40
35
  virtualDists: []
41
36
  };
42
37
  }
43
-
44
38
  return null;
45
39
  };
46
40
  export const validate = compilerOptions => {
47
41
  if (compilerOptions.enableWatch) {
48
42
  return validateWatchDir(compilerOptions);
49
43
  }
50
-
51
44
  return validateSourceDirAndFileNames(compilerOptions);
52
45
  };
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.build = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  var _constants = require("./constants");
11
-
12
9
  var _compiler = require("./compiler");
13
-
14
10
  const build = async (option, babelConfig = {}) => {
15
11
  const {
16
12
  rootDir,
@@ -23,15 +19,11 @@ const build = async (option, babelConfig = {}) => {
23
19
  quiet = false
24
20
  } = option;
25
21
  const virtualDists = [];
26
-
27
22
  if (clean) {
28
23
  await _utils.fs.remove(distDir);
29
24
  }
30
-
31
25
  _utils.fs.ensureDir(distDir);
32
-
33
26
  const messageDetails = [];
34
-
35
27
  for (const filename of filenames) {
36
28
  try {
37
29
  const dist = (0, _compiler.compiler)({
@@ -44,7 +36,6 @@ const build = async (option, babelConfig = {}) => {
44
36
  babelConfig,
45
37
  distFileExtMap
46
38
  });
47
-
48
39
  if (enableVirtualDist && dist) {
49
40
  virtualDists.push(dist);
50
41
  }
@@ -55,18 +46,15 @@ const build = async (option, babelConfig = {}) => {
55
46
  });
56
47
  }
57
48
  }
58
-
59
49
  const happenError = messageDetails.length > 0;
60
-
61
50
  if (!quiet) {
62
51
  if (happenError) {
63
- _utils.logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? 'files' : 'file'} with Babel.`); // TODO: 具体的报错信息打印
64
-
52
+ _utils.logger.error(`Compilation failure ${messageDetails.length} ${messageDetails.length !== 1 ? 'files' : 'file'} with Babel.`);
53
+ // TODO: 具体的报错信息打印
65
54
  } else {
66
55
  _utils.logger.info(`Successfully compiled ${filenames.length} ${filenames.length !== 1 ? 'files' : 'file'} with Babel.`);
67
56
  }
68
57
  }
69
-
70
58
  if (happenError) {
71
59
  return {
72
60
  code: 1,
@@ -74,12 +62,10 @@ const build = async (option, babelConfig = {}) => {
74
62
  messageDetails
75
63
  };
76
64
  }
77
-
78
65
  return {
79
66
  code: 0,
80
67
  message: `Successfully compiled ${filenames.length} ${filenames.length !== 1 ? 'files' : 'file'} with Babel.`,
81
68
  virtualDists
82
69
  };
83
70
  };
84
-
85
71
  exports.build = build;
@@ -4,57 +4,38 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.runBuildWatch = exports.buildWatch = exports.BuildWatchEvent = exports.BuildWatchEmitter = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var Event = _interopRequireWildcard(require("events"));
11
-
12
9
  var _utils = require("@modern-js/utils");
13
-
14
10
  var _build = require("./build");
15
-
16
11
  var _compilerErrorResult = require("./compilerErrorResult");
17
-
18
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); }
19
-
20
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; }
21
-
22
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; }
23
-
24
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; }
25
-
26
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; }
27
-
28
17
  const BuildWatchEvent = {
29
18
  firstCompiler: 'first-compiler',
30
19
  compiling: 'compiling',
31
20
  watchingCompiler: 'watching-compiler'
32
21
  };
33
22
  exports.BuildWatchEvent = BuildWatchEvent;
34
-
35
23
  class BuildWatchEmitter extends Event.EventEmitter {
36
24
  constructor(...args) {
37
25
  super(...args);
38
-
39
26
  _defineProperty(this, "_initFn", void 0);
40
27
  }
41
-
42
28
  setInitFn(fn) {
43
29
  this._initFn = fn;
44
30
  }
45
-
46
31
  async watch() {
47
32
  if (typeof this._initFn === 'function') {
48
33
  return this._initFn(this);
49
34
  }
50
-
51
35
  return null;
52
36
  }
53
-
54
37
  }
55
-
56
38
  exports.BuildWatchEmitter = BuildWatchEmitter;
57
-
58
39
  const runBuildWatch = async (option, babelConfig = {}, emitter) => {
59
40
  emitter.emit(BuildWatchEvent.compiling);
60
41
  const errorResult = new _compilerErrorResult.CompilerErrorResult();
@@ -62,33 +43,28 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
62
43
  const {
63
44
  distDir,
64
45
  quiet
65
- } = option; // 第一次正常构建
66
-
46
+ } = option;
47
+ // 第一次正常构建
67
48
  const firstBuildResult = await (0, _build.build)(option, babelConfig);
68
49
  const {
69
50
  code
70
51
  } = firstBuildResult;
71
-
72
52
  if (code === 1) {
73
53
  errorResult.init(firstBuildResult);
74
54
  emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
75
55
  } else {
76
56
  emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
77
57
  }
78
-
79
58
  return (0, _utils.watch)(`${watchDir}/**/*.{js,jsx,ts,tsx}`, async ({
80
59
  changeType,
81
60
  changedFilePath
82
61
  }) => {
83
62
  emitter.emit(BuildWatchEvent.compiling);
84
-
85
63
  if (changeType === _utils.WatchChangeType.UNLINK) {
86
64
  const removeFiles = [path.normalize(`./${distDir}/${path.relative(watchDir, changedFilePath)}`)];
87
-
88
65
  if (!quiet) {
89
66
  _utils.logger.info(`remove file: ${removeFiles.join(',')}`);
90
67
  }
91
-
92
68
  const result = {
93
69
  code: 0,
94
70
  message: `remove file: ${removeFiles.join(',')}`,
@@ -97,18 +73,16 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
97
73
  emitter.emit(BuildWatchEvent.watchingCompiler, result);
98
74
  return;
99
75
  }
100
-
101
76
  const result = await (0, _build.build)(_objectSpread(_objectSpread({}, option), {}, {
102
77
  filenames: [changedFilePath]
103
78
  }), babelConfig);
104
-
105
79
  if (result.code === 1) {
106
80
  errorResult.update(result.messageDetails || []);
107
81
  emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
108
82
  !quiet && _utils.logger.info(errorResult.value.message);
109
83
  } else {
110
- errorResult.removeByFileName(changedFilePath); // 如果该文件没有报错,则更新该文件状态并检查是否还存在其他报错文件
111
-
84
+ errorResult.removeByFileName(changedFilePath);
85
+ // 如果该文件没有报错,则更新该文件状态并检查是否还存在其他报错文件
112
86
  if (errorResult.checkExistError()) {
113
87
  emitter.emit(BuildWatchEvent.watchingCompiler, _objectSpread(_objectSpread({}, errorResult.value), {}, {
114
88
  virtualDists: result.virtualDists
@@ -121,13 +95,10 @@ const runBuildWatch = async (option, babelConfig = {}, emitter) => {
121
95
  }
122
96
  }, [`${watchDir}/**/*.d.ts`]);
123
97
  };
124
-
125
98
  exports.runBuildWatch = runBuildWatch;
126
-
127
99
  const buildWatch = (option, babelConfig = {}) => {
128
100
  const buildWatchEmitter = new BuildWatchEmitter();
129
101
  buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
130
102
  return buildWatchEmitter;
131
103
  };
132
-
133
104
  exports.buildWatch = buildWatch;
@@ -4,33 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resolveSourceMap = exports.isRes = exports.getDistFilePath = exports.compiler = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var babel = _interopRequireWildcard(require("@babel/core"));
11
-
12
9
  var _utils = require("@modern-js/utils");
13
-
14
10
  var utils = _interopRequireWildcard(require("./utils"));
15
-
16
11
  var _constants = require("./constants");
17
-
18
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); }
19
-
20
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; }
21
-
22
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; }
23
-
24
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; }
25
-
26
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; }
27
-
28
17
  const defaultDistDir = 'dist';
29
-
30
18
  const isRes = r => Boolean(r);
31
-
32
19
  exports.isRes = isRes;
33
-
34
20
  const getDistFilePath = option => {
35
21
  const {
36
22
  filepath,
@@ -41,9 +27,7 @@ const getDistFilePath = option => {
41
27
  const ext = path.extname(filepath);
42
28
  return path.join(distDir, path.relative(rootDir, filepath).replace(ext, extMap[ext]));
43
29
  };
44
-
45
30
  exports.getDistFilePath = getDistFilePath;
46
-
47
31
  const resolveSourceMap = option => {
48
32
  const {
49
33
  babelRes,
@@ -53,30 +37,22 @@ const resolveSourceMap = option => {
53
37
  } = option;
54
38
  const mapLoc = `${distFilePath}.map`;
55
39
  babelRes.code = utils.addSourceMappingUrl(babelRes.code, mapLoc);
56
-
57
40
  if (babelRes.map) {
58
41
  babelRes.map.file = path.basename(distFilePath);
59
42
  babelRes.map.sources = [path.relative(path.dirname(distFilePath), sourceFilePath)];
60
43
  }
61
-
62
44
  const sourceMapVirtualDist = {
63
45
  sourcemap: JSON.stringify(babelRes.map),
64
46
  sourceMapPath: mapLoc
65
47
  };
66
-
67
48
  if (enableVirtualDist) {
68
49
  return sourceMapVirtualDist;
69
50
  }
70
-
71
51
  _utils.fs.ensureDirSync(path.dirname(mapLoc));
72
-
73
52
  _utils.fs.writeFileSync(mapLoc, JSON.stringify(babelRes.map));
74
-
75
53
  return sourceMapVirtualDist;
76
54
  };
77
-
78
55
  exports.resolveSourceMap = resolveSourceMap;
79
-
80
56
  const compiler = option => {
81
57
  const {
82
58
  filepath,
@@ -90,18 +66,15 @@ const compiler = option => {
90
66
  } = option;
91
67
  const babelRes = babel.transformFileSync(filepath, babelConfig);
92
68
  let virtualDist = null;
93
-
94
69
  if (!isRes(babelRes)) {
95
70
  throw new Error(`${filepath} happen error`);
96
71
  }
97
-
98
72
  const distFilePath = getDistFilePath({
99
73
  filepath,
100
74
  rootDir,
101
75
  distDir,
102
76
  extMap: distFileExtMap
103
77
  });
104
-
105
78
  if (enableVirtualDist) {
106
79
  virtualDist = {
107
80
  distPath: distFilePath,
@@ -110,7 +83,6 @@ const compiler = option => {
110
83
  sourcemap: ''
111
84
  };
112
85
  }
113
-
114
86
  if (babelRes !== null && babelRes !== void 0 && babelRes.map && babelConfig.sourceMaps && babelConfig.sourceMaps !== 'inline') {
115
87
  if (virtualDist) {
116
88
  virtualDist = _objectSpread(_objectSpread({}, virtualDist), resolveSourceMap({
@@ -128,7 +100,6 @@ const compiler = option => {
128
100
  });
129
101
  }
130
102
  }
131
-
132
103
  if (virtualDist) {
133
104
  virtualDist = _objectSpread(_objectSpread({}, virtualDist), {}, {
134
105
  distPath: distFilePath,
@@ -136,15 +107,11 @@ const compiler = option => {
136
107
  });
137
108
  } else {
138
109
  _utils.fs.ensureDirSync(path.dirname(distFilePath));
139
-
140
110
  _utils.fs.writeFileSync(distFilePath, babelRes.code);
141
111
  }
142
-
143
112
  if (verbose && !quiet) {
144
113
  _utils.logger.info(`${filepath} => ${distFilePath}`);
145
114
  }
146
-
147
115
  return virtualDist;
148
116
  };
149
-
150
117
  exports.compiler = compiler;
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CompilerErrorResult = void 0;
7
-
8
7
  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; }
9
-
10
8
  class CompilerErrorResult {
11
9
  constructor(initErrorResult) {
12
10
  _defineProperty(this, "_messageDetails", void 0);
13
-
14
11
  this.init(initErrorResult);
15
12
  }
16
-
17
13
  init(initErrorResult) {
18
14
  this._messageDetails = (initErrorResult === null || initErrorResult === void 0 ? void 0 : initErrorResult.messageDetails) || [];
19
15
  }
20
-
21
16
  update(messageDetails) {
22
17
  for (const messageDetail of messageDetails) {
23
18
  // 遍历存不存在该文件报错信息,不存在则增加,否则更新内容
@@ -27,34 +22,26 @@ class CompilerErrorResult {
27
22
  detail.content = messageDetail.content;
28
23
  return true;
29
24
  }
30
-
31
25
  return false;
32
26
  });
33
-
34
27
  if (addError) {
35
28
  this._messageDetails.push(messageDetail);
36
29
  }
37
30
  }
38
31
  }
39
-
40
32
  removeByFileName(filename) {
41
33
  this._messageDetails = this._messageDetails.filter(detail => detail.filename !== filename);
42
34
  }
43
-
44
35
  get value() {
45
36
  var _this$_messageDetails;
46
-
47
37
  return {
48
38
  code: 1,
49
39
  message: `Compilation failure ${(_this$_messageDetails = this._messageDetails) === null || _this$_messageDetails === void 0 ? void 0 : _this$_messageDetails.length} files with Babel.`,
50
40
  messageDetails: this._messageDetails
51
41
  };
52
42
  }
53
-
54
43
  checkExistError() {
55
44
  return this._messageDetails.length > 0;
56
45
  }
57
-
58
46
  }
59
-
60
47
  exports.CompilerErrorResult = CompilerErrorResult;
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.mergeDefaultOption = void 0;
7
-
8
7
  var _constants = require("./constants");
9
-
10
8
  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; }
11
-
12
9
  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; }
13
-
14
10
  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; }
15
-
16
11
  const defaultOptions = {
17
12
  enableWatch: false,
18
13
  enableVirtualDist: false,
@@ -24,7 +19,5 @@ const defaultOptions = {
24
19
  verbose: false,
25
20
  clean: false
26
21
  };
27
-
28
22
  const mergeDefaultOption = compilerOptions => _objectSpread(_objectSpread({}, defaultOptions), compilerOptions);
29
-
30
23
  exports.mergeDefaultOption = mergeDefaultOption;
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getGlobPattern = exports.getFinalExtensions = exports.getFinalCompilerOption = exports.getFilesFromDir = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  var _core = require("@babel/core");
11
-
12
9
  var _defaults = require("./defaults");
13
-
14
10
  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
-
16
11
  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; }
17
-
18
12
  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; }
19
-
20
13
  const getGlobPattern = (dir, extensions) => {
21
14
  if (extensions.length > 1) {
22
15
  return `${dir}/**/*{${extensions.join(',')}}`;
@@ -26,14 +19,10 @@ const getGlobPattern = (dir, extensions) => {
26
19
  return `${dir}/**/*`;
27
20
  }
28
21
  };
29
-
30
22
  exports.getGlobPattern = getGlobPattern;
31
-
32
23
  const getFinalExtensions = extensions => {
33
24
  const isExtensions = ext => Array.isArray(ext);
34
-
35
25
  const isExtensionsFunc = ext => typeof ext === 'function';
36
-
37
26
  if (isExtensions(extensions)) {
38
27
  return [...extensions, ..._core.DEFAULT_EXTENSIONS];
39
28
  } else if (isExtensionsFunc(extensions)) {
@@ -42,9 +31,7 @@ const getFinalExtensions = extensions => {
42
31
  return _core.DEFAULT_EXTENSIONS;
43
32
  }
44
33
  };
45
-
46
34
  exports.getFinalExtensions = getFinalExtensions;
47
-
48
35
  const getFilesFromDir = ({
49
36
  dir,
50
37
  finalExt: _finalExt = [],
@@ -57,9 +44,7 @@ const getFilesFromDir = ({
57
44
  });
58
45
  return globFindFilenames;
59
46
  };
60
-
61
47
  exports.getFilesFromDir = getFilesFromDir;
62
-
63
48
  const getFinalCompilerOption = option => {
64
49
  const optionWithDefault = (0, _defaults.mergeDefaultOption)(option);
65
50
  const {
@@ -71,7 +56,6 @@ const getFinalCompilerOption = option => {
71
56
  } = option;
72
57
  let globFindFilenames = [];
73
58
  const finalExt = getFinalExtensions(extensions);
74
-
75
59
  if (sourceDir) {
76
60
  globFindFilenames = getFilesFromDir({
77
61
  dir: sourceDir,
@@ -79,7 +63,6 @@ const getFinalCompilerOption = option => {
79
63
  finalExt
80
64
  });
81
65
  }
82
-
83
66
  if (enableWatch) {
84
67
  // 开启watch模式,清空通过 sourceDir 找到的文件,而改为使用watchDirs
85
68
  globFindFilenames = getFilesFromDir({
@@ -88,10 +71,8 @@ const getFinalCompilerOption = option => {
88
71
  finalExt
89
72
  });
90
73
  }
91
-
92
74
  return _objectSpread(_objectSpread({}, optionWithDefault), {}, {
93
75
  filenames: [...optionWithDefault.filenames, ...globFindFilenames]
94
76
  });
95
77
  };
96
-
97
78
  exports.getFinalCompilerOption = getFinalCompilerOption;
@@ -7,13 +7,9 @@ var _exportNames = {
7
7
  compiler: true
8
8
  };
9
9
  exports.compiler = compiler;
10
-
11
10
  var _getFinalOption = require("./getFinalOption");
12
-
13
11
  var _build = require("./build");
14
-
15
12
  var _buildWatch = require("./buildWatch");
16
-
17
13
  Object.keys(_buildWatch).forEach(function (key) {
18
14
  if (key === "default" || key === "__esModule") return;
19
15
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -25,11 +21,8 @@ Object.keys(_buildWatch).forEach(function (key) {
25
21
  }
26
22
  });
27
23
  });
28
-
29
24
  var _validate = require("./validate");
30
-
31
25
  var _type = require("./type");
32
-
33
26
  Object.keys(_type).forEach(function (key) {
34
27
  if (key === "default" || key === "__esModule") return;
35
28
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -41,16 +34,12 @@ Object.keys(_type).forEach(function (key) {
41
34
  }
42
35
  });
43
36
  });
44
-
45
37
  async function compiler(compilerOptions, babelOptions = {}) {
46
38
  const validRet = (0, _validate.validate)(compilerOptions);
47
-
48
39
  if (validRet) {
49
40
  return validRet;
50
41
  }
51
-
52
42
  const finalCompilerOption = (0, _getFinalOption.getFinalCompilerOption)(compilerOptions);
53
-
54
43
  if (compilerOptions.enableWatch) {
55
44
  return (0, _buildWatch.buildWatch)(finalCompilerOption, babelOptions);
56
45
  } else {
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addSourceMappingUrl = addSourceMappingUrl;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  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); }
11
-
12
9
  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; }
13
-
14
10
  function addSourceMappingUrl(code, loc) {
15
11
  return `${code}\n//# sourceMappingURL=${path.normalize(path.basename(loc))}`;
16
12
  }
@@ -4,68 +4,53 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.watchDirValidMessage = exports.validateWatchDir = exports.validateSourceDirAndFileNames = exports.validate = exports.sourceDirAndFileNamesValidMessage = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  const sourceDirAndFileNamesValidMessage = 'At least one of the sourceDir and filenames configurations must be configured';
11
9
  exports.sourceDirAndFileNamesValidMessage = sourceDirAndFileNamesValidMessage;
12
10
  const watchDirValidMessage = 'should set watchDir when enableWatch is true';
13
11
  exports.watchDirValidMessage = watchDirValidMessage;
14
-
15
12
  const validateSourceDirAndFileNames = compilerOptions => {
16
13
  const {
17
14
  sourceDir,
18
15
  filenames,
19
16
  quiet
20
17
  } = compilerOptions;
21
-
22
18
  if (!sourceDir && !filenames) {
23
19
  if (!quiet) {
24
20
  _utils.logger.error(sourceDirAndFileNamesValidMessage);
25
21
  }
26
-
27
22
  return {
28
23
  code: 1,
29
24
  message: sourceDirAndFileNamesValidMessage,
30
25
  virtualDists: []
31
26
  };
32
27
  }
33
-
34
28
  return null;
35
29
  };
36
-
37
30
  exports.validateSourceDirAndFileNames = validateSourceDirAndFileNames;
38
-
39
31
  const validateWatchDir = compilerOptions => {
40
32
  const {
41
33
  watchDir,
42
34
  enableWatch,
43
35
  quiet
44
36
  } = compilerOptions;
45
-
46
37
  if (enableWatch && !watchDir) {
47
38
  if (!quiet) {
48
39
  _utils.logger.error(watchDirValidMessage);
49
40
  }
50
-
51
41
  return {
52
42
  code: 1,
53
43
  message: watchDirValidMessage,
54
44
  virtualDists: []
55
45
  };
56
46
  }
57
-
58
47
  return null;
59
48
  };
60
-
61
49
  exports.validateWatchDir = validateWatchDir;
62
-
63
50
  const validate = compilerOptions => {
64
51
  if (compilerOptions.enableWatch) {
65
52
  return validateWatchDir(compilerOptions);
66
53
  }
67
-
68
54
  return validateSourceDirAndFileNames(compilerOptions);
69
55
  };
70
-
71
56
  exports.validate = validate;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.0",
14
+ "version": "2.0.0-beta.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@babel/core": "^7.18.0",
32
32
  "@babel/runtime": "^7.18.0",
33
- "@modern-js/utils": "2.0.0-beta.0"
33
+ "@modern-js/utils": "2.0.0-beta.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@babel/plugin-transform-classes": "^7.18.0",
@@ -40,9 +40,9 @@
40
40
  "@types/jest": "^27",
41
41
  "@types/node": "^14",
42
42
  "typescript": "^4",
43
- "@scripts/build": "2.0.0-beta.0",
44
43
  "jest": "^27",
45
- "@scripts/jest-config": "2.0.0-beta.0"
44
+ "@scripts/build": "2.0.0-beta.2",
45
+ "@scripts/jest-config": "2.0.0-beta.2"
46
46
  },
47
47
  "sideEffects": false,
48
48
  "modernConfig": {
@@ -55,8 +55,8 @@
55
55
  "access": "public"
56
56
  },
57
57
  "scripts": {
58
- "new": "modern new",
59
- "build": "modern build",
58
+ "new": "modern-lib new",
59
+ "build": "modern-lib build",
60
60
  "test": "jest --passWithNoTests"
61
61
  }
62
62
  }