@modern-js/module-tools 1.5.5 → 1.6.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/js/modern/cli/build.js +5 -4
  3. package/dist/js/modern/commands/build.js +40 -27
  4. package/dist/js/modern/features/build/bundle/index.js +6 -0
  5. package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
  6. package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
  7. package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -55
  8. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
  9. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
  10. package/dist/js/modern/features/build/bundleless/index.js +13 -0
  11. package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
  12. package/dist/js/modern/features/build/bundleless/style.js +266 -0
  13. package/dist/js/modern/features/build/constants.js +94 -59
  14. package/dist/js/modern/features/build/error.js +150 -0
  15. package/dist/js/modern/features/build/index.js +84 -19
  16. package/dist/js/modern/features/build/legacy-constants.js +99 -0
  17. package/dist/js/modern/features/build/normalize.js +293 -0
  18. package/dist/js/modern/features/build/types.js +0 -0
  19. package/dist/js/modern/features/build/utils.js +29 -137
  20. package/dist/js/modern/index.js +3 -1
  21. package/dist/js/modern/locale/en.js +5 -3
  22. package/dist/js/modern/locale/zh.js +5 -3
  23. package/dist/js/modern/schema/build-config.js +104 -0
  24. package/dist/js/modern/schema/index.js +2 -1
  25. package/dist/js/modern/schema/output.js +18 -9
  26. package/dist/js/modern/schema/source.js +2 -10
  27. package/dist/js/modern/schema/tools.js +6 -0
  28. package/dist/js/modern/schema/types.js +0 -0
  29. package/dist/js/modern/utils/babel.js +6 -3
  30. package/dist/js/modern/utils/constants.js +3 -0
  31. package/dist/js/node/cli/build.js +5 -4
  32. package/dist/js/node/commands/build.js +50 -29
  33. package/dist/js/node/features/build/bundle/index.js +17 -0
  34. package/dist/js/node/features/build/bundle/runRollup.js +174 -0
  35. package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
  36. package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
  37. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
  38. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
  39. package/dist/js/node/features/build/bundleless/index.js +26 -0
  40. package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
  41. package/dist/js/node/features/build/bundleless/style.js +299 -0
  42. package/dist/js/node/features/build/constants.js +115 -67
  43. package/dist/js/node/features/build/error.js +175 -0
  44. package/dist/js/node/features/build/index.js +92 -19
  45. package/dist/js/node/features/build/legacy-constants.js +107 -0
  46. package/dist/js/node/features/build/normalize.js +322 -0
  47. package/dist/js/node/features/build/types.js +0 -0
  48. package/dist/js/node/features/build/utils.js +31 -145
  49. package/dist/js/node/index.js +5 -1
  50. package/dist/js/node/locale/en.js +5 -3
  51. package/dist/js/node/locale/zh.js +5 -3
  52. package/dist/js/node/schema/build-config.js +113 -0
  53. package/dist/js/node/schema/index.js +3 -1
  54. package/dist/js/node/schema/output.js +20 -9
  55. package/dist/js/node/schema/source.js +2 -10
  56. package/dist/js/node/schema/tools.js +13 -0
  57. package/dist/js/node/schema/types.js +0 -0
  58. package/dist/js/node/utils/babel.js +5 -2
  59. package/dist/js/node/utils/constants.js +11 -0
  60. package/dist/types/cli/build.d.ts +1 -1
  61. package/dist/types/cli/new.d.ts +1 -1
  62. package/dist/types/commands/build.d.ts +12 -12
  63. package/dist/types/features/build/bundle/index.d.ts +3 -0
  64. package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
  65. package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
  66. package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
  67. package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
  68. package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
  69. package/dist/types/features/build/bundleless/index.d.ts +4 -0
  70. package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
  71. package/dist/types/features/build/bundleless/style.d.ts +25 -0
  72. package/dist/types/features/build/constants.d.ts +17 -13
  73. package/dist/types/features/build/error.d.ts +33 -0
  74. package/dist/types/features/build/index.d.ts +4 -3
  75. package/dist/types/features/build/legacy-constants.d.ts +8 -0
  76. package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
  77. package/dist/types/features/build/normalize.d.ts +18 -0
  78. package/dist/types/features/build/types.d.ts +15 -0
  79. package/dist/types/features/build/utils.d.ts +9 -31
  80. package/dist/types/locale/en.d.ts +2 -0
  81. package/dist/types/locale/index.d.ts +4 -0
  82. package/dist/types/locale/zh.d.ts +2 -0
  83. package/dist/types/schema/build-config.d.ts +179 -0
  84. package/dist/types/schema/index.d.ts +166 -18
  85. package/dist/types/schema/output.d.ts +170 -10
  86. package/dist/types/schema/source.d.ts +2 -11
  87. package/dist/types/schema/tools.d.ts +6 -0
  88. package/dist/types/schema/types.d.ts +45 -0
  89. package/dist/types/types.d.ts +29 -28
  90. package/dist/types/utils/babel.d.ts +3 -2
  91. package/dist/types/utils/constants.d.ts +2 -0
  92. package/dist/types/utils/logger.d.ts +2 -0
  93. package/package.json +29 -16
  94. package/dist/js/modern/features/build/build-watch.js +0 -101
  95. package/dist/js/modern/features/build/build.js +0 -123
  96. package/dist/js/modern/tasks/build-source-code.js +0 -207
  97. package/dist/js/modern/tasks/build-style.js +0 -168
  98. package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
  99. package/dist/js/modern/tasks/build-watch-style.js +0 -215
  100. package/dist/js/modern/tasks/constants.js +0 -1
  101. package/dist/js/node/features/build/build-watch.js +0 -121
  102. package/dist/js/node/features/build/build.js +0 -143
  103. package/dist/js/node/tasks/build-source-code.js +0 -233
  104. package/dist/js/node/tasks/build-style.js +0 -183
  105. package/dist/js/node/tasks/build-watch-source-code.js +0 -173
  106. package/dist/js/node/tasks/build-watch-style.js +0 -232
  107. package/dist/js/node/tasks/constants.js +0 -8
  108. package/dist/types/features/build/build-watch.d.ts +0 -3
  109. package/dist/types/features/build/build.d.ts +0 -3
  110. package/dist/types/tasks/build-source-code.d.ts +0 -25
  111. package/dist/types/tasks/build-style.d.ts +0 -1
  112. package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
  113. package/dist/types/tasks/build-watch-style.d.ts +0 -1
  114. package/dist/types/tasks/constants.d.ts +0 -1
  115. package/dist/types/tasks/copy-assets.d.ts +0 -1
  116. package/dist/types/tasks/generator-dts/index.d.ts +0 -1
@@ -1,9 +1,9 @@
1
- import { Import, execa, fs, json5, isObject } from '@modern-js/utils';
1
+ import path from 'path';
2
+ import { Import, execa, fs, json5 } from '@modern-js/utils';
3
+ import { InternalDTSError } from "../../error";
4
+ import { SectionTitleStatus, watchSectionTitle } from "../../utils";
2
5
  import { getTscBinPath } from "./utils";
3
- const core = Import.lazy('@modern-js/core', require);
4
- const argv = Import.lazy('process.argv', require);
5
6
  const utils = Import.lazy('./utils', require);
6
- let removeTsconfigPath = '';
7
7
 
8
8
  const getProjectTsconfig = tsconfigPath => {
9
9
  if (!tsconfigPath || !fs.existsSync(tsconfigPath)) {
@@ -14,7 +14,6 @@ const getProjectTsconfig = tsconfigPath => {
14
14
  };
15
15
 
16
16
  const resolveLog = (childProgress, {
17
- tsCheck: _tsCheck = false,
18
17
  watch: _watch = false
19
18
  } = {}) => {
20
19
  var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
@@ -25,11 +24,8 @@ const resolveLog = (childProgress, {
25
24
  * watch 模式下,则使用这里的信息
26
25
  */
27
26
  (_childProgress$stdout = childProgress.stdout) === null || _childProgress$stdout === void 0 ? void 0 : _childProgress$stdout.on('data', data => {
28
- if (!_tsCheck) {
29
- return;
30
- }
31
-
32
27
  if (_watch) {
28
+ console.info(watchSectionTitle('[Bundleless:DTS]', SectionTitleStatus.Log));
33
29
  console.info(data.toString());
34
30
  }
35
31
  }); // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
@@ -46,95 +42,75 @@ const generatorDts = async (_, config) => {
46
42
  const {
47
43
  tsconfigPath,
48
44
  distDir,
49
- sourceDirName = 'src',
50
- projectData: {
51
- appDirectory
52
- },
53
- tsCheck = false,
45
+ sourceDir = 'src',
46
+ appDirectory,
54
47
  watch = false
55
48
  } = config;
56
49
  const userTsconfig = getProjectTsconfig(tsconfigPath);
57
50
  const willDeleteTsconfigPath = utils.generatorTsConfig(userTsconfig, {
58
51
  appDirectory,
59
52
  distDir,
60
- sourceDir: sourceDirName
53
+ sourceDir
61
54
  });
62
- removeTsconfigPath = willDeleteTsconfigPath;
63
55
  const tscBinFile = getTscBinPath(appDirectory);
64
56
  const watchParams = watch ? ['-w'] : [];
65
- const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
57
+ const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath,
58
+ /* Required parameter, use it stdout have color */
59
+ '--pretty', // https://github.com/microsoft/TypeScript/issues/21824
60
+ '--preserveWatchOutput', ...watchParams], {
66
61
  stdio: 'pipe',
67
62
  cwd: appDirectory
68
63
  });
69
64
  resolveLog(childProgress, {
70
- tsCheck,
71
65
  watch
72
66
  });
73
67
 
74
68
  try {
75
69
  await childProgress;
76
- console.info('[TSC Compiler]: Successfully');
77
70
  } catch (e) {
78
- if (!tsCheck) {
79
- console.info(`There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'`);
80
- } // 通过使用 execa,可以将 tsc 的 data 类型的报错信息变为异常错误信息
81
- else if (isObject(e) && e.stdout) {
82
- console.error(e.stdout);
83
- } else {
84
- console.error(e);
71
+ if (e instanceof Error) {
72
+ throw new InternalDTSError(e, {
73
+ buildType: 'bundleless'
74
+ });
85
75
  }
86
76
  }
87
77
 
88
78
  fs.removeSync(willDeleteTsconfigPath);
89
79
  };
90
80
 
91
- const taskMain = async ({
92
- modernConfig
93
- }) => {
94
- const processArgv = argv(process.argv.slice(2));
95
- const config = processArgv({
96
- appDirectory: process.cwd(),
97
- srcDir: 'src',
98
- distDir: 'dist/types',
99
- tsconfigPath: './tsconfig.json',
100
- sourceDirName: 'src'
101
- });
102
- const option = {
103
- srcDir: config.srcDir,
104
- distDir: config.distDir,
105
- projectData: {
106
- appDirectory: config.appDirectory
81
+ export const genDts = async (api, config) => {
82
+ const {
83
+ outputPath,
84
+ tsconfig: tsconfigPath,
85
+ watch,
86
+ bundlelessOptions: {
87
+ sourceDir
107
88
  },
108
- tsconfigPath: config.tsconfigPath,
109
- watch: config.watch,
110
- tsCheck: config.tsCheck,
111
- sourceDirName: config.sourceDirName
112
- };
113
- await generatorDts(modernConfig, option); // // TODO: watch 模式下无法转换
114
-
115
- utils.resolveAlias(modernConfig, option);
116
- };
117
-
118
- (async () => {
119
- let options;
89
+ enableDts
90
+ } = config;
120
91
 
121
- if (process.env.CORE_INIT_OPTION_FILE) {
122
- ({
123
- options
124
- } = require(process.env.CORE_INIT_OPTION_FILE));
92
+ if (!enableDts) {
93
+ return;
125
94
  }
126
95
 
127
96
  const {
128
- resolved
129
- } = await core.cli.init([], options);
130
- await core.manager.run(async () => {
131
- try {
132
- await taskMain({
133
- modernConfig: resolved
134
- });
135
- } catch (e) {
136
- console.error(e.message);
137
- fs.removeSync(removeTsconfigPath);
97
+ appDirectory
98
+ } = api.useAppContext();
99
+ const modernConfig = api.useResolvedConfigContext();
100
+ const {
101
+ output: {
102
+ path: distPath = 'dist'
138
103
  }
139
- });
140
- })();
104
+ } = modernConfig;
105
+ const distDir = path.join(appDirectory, distPath, outputPath);
106
+ const option = {
107
+ appDirectory,
108
+ distDir,
109
+ tsconfigPath,
110
+ watch,
111
+ sourceDir
112
+ };
113
+ await generatorDts(modernConfig, option); // TODO: watch 模式下无法转换
114
+
115
+ utils.resolveAlias(modernConfig, option);
116
+ };
@@ -7,9 +7,9 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
7
7
  import * as path from 'path';
8
8
  import { Import, glob, fs } from '@modern-js/utils';
9
9
  import { merge as deepMerge } from '@modern-js/utils/lodash';
10
- const babel = Import.lazy('../../utils/babel', require);
11
- const tsPathsTransform = Import.lazy('../../utils/tspaths-transform', require);
12
- const constants = Import.lazy('../constants', require);
10
+ const babel = Import.lazy('../../../../utils/babel', require);
11
+ const tsPathsTransform = Import.lazy('../../../../utils/tspaths-transform', require);
12
+ const constants = Import.lazy('../../../../utils/constants', require);
13
13
  export const generatorTsConfig = (projectTsconfig, {
14
14
  appDirectory,
15
15
  distDir,
@@ -64,14 +64,14 @@ export const resolveAlias = (modernConfig, config, watchFilenames = []) => {
64
64
  absolute: true
65
65
  });
66
66
  const alias = babel.getFinalAlias(modernConfig, {
67
- appDirectory: config.projectData.appDirectory,
68
- tsconfigPath: config.tsconfigPath || path.join(config.projectData.appDirectory, './tsconfig.json'),
67
+ appDirectory: config.appDirectory,
68
+ tsconfigPath: config.tsconfigPath || path.join(config.appDirectory, './tsconfig.json'),
69
69
  sourceAbsDir: config.distDir
70
70
  });
71
71
  const mergedPaths = alias.isTsPath ? alias.paths || {} : _objectSpread(_objectSpread({}, defaultPaths), alias.paths || {});
72
72
  const result = tsPathsTransform.transformDtsAlias({
73
73
  filenames: dtsFilenames,
74
- baseUrl: path.join(config.projectData.appDirectory, output.path || 'dist'),
74
+ baseUrl: path.join(config.appDirectory, output.path || 'dist'),
75
75
  paths: mergedPaths
76
76
  });
77
77
 
@@ -0,0 +1,13 @@
1
+ import { runBabelBuild } from "./runBabel";
2
+ import { buildStyle } from "./style";
3
+ import { genDts } from "./generator-dts";
4
+ import { copyStaticAssets } from "./copy-assets";
5
+ export const build = async (api, config, legacyOptions) => {
6
+ if (legacyOptions !== null && legacyOptions !== void 0 && legacyOptions.styleOnly) {
7
+ await buildStyle(api, config);
8
+ return;
9
+ }
10
+
11
+ const tasks = config.dtsOnly ? [genDts(api, config)] : [runBabelBuild(api, config), genDts(api, config), buildStyle(api, config), copyStaticAssets(api, config)];
12
+ await Promise.all(tasks);
13
+ };
@@ -0,0 +1,269 @@
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
+ 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
+ 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
+ import path from 'path';
8
+ import { Import, glob, fs, chalk, globby } from '@modern-js/utils';
9
+ import { InternalBuildError } from "../error";
10
+ import { SectionTitleStatus, watchSectionTitle } from "../utils";
11
+ export class BabelBuildError extends Error {
12
+ constructor(message, opts) {
13
+ super(message);
14
+
15
+ _defineProperty(this, "summary", void 0);
16
+
17
+ _defineProperty(this, "details", void 0);
18
+
19
+ Error.captureStackTrace(this, this.constructor);
20
+ this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
21
+ this.details = opts === null || opts === void 0 ? void 0 : opts.details;
22
+ }
23
+
24
+ toString() {
25
+ return this.formatError().join('\n');
26
+ }
27
+
28
+ formatError() {
29
+ const msgs = [];
30
+ const {
31
+ summary,
32
+ details = []
33
+ } = this;
34
+ msgs.push(chalk.red.bold(summary));
35
+
36
+ for (const detail of details) {
37
+ msgs.push(detail.content);
38
+ msgs.push('\n');
39
+ }
40
+
41
+ return msgs;
42
+ }
43
+
44
+ }
45
+ const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
46
+ const bc = Import.lazy('../../../utils/babel', require);
47
+ const ts = Import.lazy('../../../utils/tsconfig', require); // const logger: typeof import('../logger') = Import.lazy('../logger', require);
48
+
49
+ const getExts = (isTs, tsconfig) => {
50
+ // TODO: 是否受控tsconfig.json 里的jsx配置
51
+ let exts = [];
52
+
53
+ if (isTs) {
54
+ var _tsconfig$compilerOpt;
55
+
56
+ exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
57
+ } else {
58
+ exts = ['.js', '.jsx'];
59
+ }
60
+
61
+ return exts;
62
+ };
63
+
64
+ export const getWillCompilerCode = (srcDirOrFile, option) => {
65
+ const {
66
+ tsconfig,
67
+ isTsProject
68
+ } = option; // 如果是一个文件路径,则直接返回
69
+
70
+ if (fs.existsSync(srcDirOrFile) && fs.lstatSync(srcDirOrFile).isFile()) {
71
+ return [srcDirOrFile];
72
+ }
73
+
74
+ const exts = getExts(isTsProject, tsconfig);
75
+ const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
76
+ const files = glob.sync(globPattern, {
77
+ ignore: [`${srcDirOrFile}/**/*.d.ts`],
78
+ absolute: true
79
+ });
80
+ return files;
81
+ };
82
+ export const buildSourceCode = async config => {
83
+ const {
84
+ willCompilerDirOrFile,
85
+ tsconfigPath,
86
+ babelConfig,
87
+ srcRootDir,
88
+ distDir,
89
+ watch
90
+ } = config;
91
+ const tsconfig = ts.readTsConfig(tsconfigPath);
92
+ const willCompilerFiles = getWillCompilerCode(willCompilerDirOrFile, {
93
+ tsconfig,
94
+ isTsProject: Boolean(tsconfig)
95
+ });
96
+
97
+ if (watch) {
98
+ const emitter = await babelCompiler.compiler({
99
+ quiet: true,
100
+ enableVirtualDist: true,
101
+ enableWatch: true,
102
+ rootDir: srcRootDir,
103
+ filenames: willCompilerFiles,
104
+ distDir,
105
+ watchDir: srcRootDir,
106
+ extensions: getExts(Boolean(tsconfig), tsconfig),
107
+ ignore: ['*.d.ts']
108
+ }, babelConfig);
109
+ return emitter;
110
+ } else {
111
+ return babelCompiler.compiler({
112
+ quiet: true,
113
+ enableVirtualDist: true,
114
+ rootDir: srcRootDir,
115
+ filenames: willCompilerFiles,
116
+ distDir,
117
+ // enableWatch: watch,
118
+ ignore: ['*.d.ts']
119
+ }, babelConfig);
120
+ }
121
+ };
122
+
123
+ const generatorRealFiles = virtualDists => {
124
+ for (const virtualDist of virtualDists) {
125
+ const {
126
+ distPath,
127
+ code,
128
+ sourcemap,
129
+ sourceMapPath
130
+ } = virtualDist;
131
+ fs.ensureFileSync(distPath);
132
+ fs.writeFileSync(distPath, code);
133
+
134
+ if (sourcemap.length > 0) {
135
+ fs.ensureFileSync(sourceMapPath);
136
+ fs.writeFileSync(sourceMapPath, sourcemap);
137
+ }
138
+ }
139
+ };
140
+ /**
141
+ * when modern build, only throw Error or silent
142
+ * @param outputResults
143
+ * @param context
144
+ */
145
+
146
+
147
+ const outputDist = (outputResults, context) => {
148
+ const {
149
+ code,
150
+ message,
151
+ messageDetails,
152
+ virtualDists = []
153
+ } = outputResults;
154
+
155
+ if (code === 0) {
156
+ generatorRealFiles(virtualDists);
157
+ } else if (messageDetails && messageDetails.length > 0) {
158
+ const babelError = new BabelBuildError('bundleless failed', {
159
+ summary: message,
160
+ details: messageDetails
161
+ });
162
+ throw new InternalBuildError(babelError, _objectSpread(_objectSpread({}, context), {}, {
163
+ buildType: 'bundleless'
164
+ }));
165
+ }
166
+ };
167
+
168
+ export const jsFileSuffix = ['js', 'jsx', 'ts', 'tsx'];
169
+ export const haveNotAnyJsFile = async sourceDir => {
170
+ const files = await globby(`${sourceDir}/**/*.{${jsFileSuffix.join(',')}}`);
171
+ return files.length === 0;
172
+ };
173
+ export const runBabelBuild = async (api, config) => {
174
+ const {
175
+ bundlelessOptions,
176
+ tsconfig,
177
+ target,
178
+ format,
179
+ outputPath,
180
+ watch,
181
+ sourceMap
182
+ } = config;
183
+ const {
184
+ appDirectory
185
+ } = api.useAppContext();
186
+ const modernConfig = api.useResolvedConfigContext();
187
+ const {
188
+ output: {
189
+ path: distPath = 'dist'
190
+ }
191
+ } = modernConfig;
192
+ const {
193
+ sourceDir = './src'
194
+ } = bundlelessOptions;
195
+ const sourceAbsDir = path.join(appDirectory, sourceDir);
196
+ const tsconfigPath = path.join(appDirectory, tsconfig);
197
+
198
+ if (await haveNotAnyJsFile(sourceAbsDir)) {
199
+ return;
200
+ } // TODO: Refactoring based on format and target
201
+
202
+
203
+ const syntax = target === 'es5' ? 'es5' : 'es6+';
204
+ const type = format === 'cjs' ? 'commonjs' : 'module';
205
+ const titleText = `[Bundleless:Babel: ${format}_${target}]`;
206
+ const buildConfig = {
207
+ format,
208
+ target,
209
+ babelConfig: bc.resolveBabelConfig(appDirectory, modernConfig, sourceMap, bundlelessOptions, {
210
+ sourceAbsDir,
211
+ tsconfigPath,
212
+ syntax,
213
+ type
214
+ })
215
+ };
216
+ const distDir = path.join(appDirectory, distPath, outputPath);
217
+ const result = await buildSourceCode({
218
+ appDirectory,
219
+ distDir,
220
+ srcRootDir: sourceAbsDir,
221
+ willCompilerDirOrFile: sourceAbsDir,
222
+ tsconfigPath,
223
+ babelConfig: buildConfig.babelConfig,
224
+ watch
225
+ });
226
+
227
+ if (watch) {
228
+ const emitter = result;
229
+ emitter.on(babelCompiler.BuildWatchEvent.firstCompiler, result => {
230
+ if (result.code === 1) {
231
+ console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
232
+ console.error(result.message);
233
+
234
+ for (const detail of result.messageDetails || []) {
235
+ console.error(detail.content);
236
+ }
237
+ } else {
238
+ generatorRealFiles(result.virtualDists);
239
+ console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
240
+ }
241
+ });
242
+ emitter.on(babelCompiler.BuildWatchEvent.watchingCompiler, result => {
243
+ if (result.code === 1) {
244
+ var _result$virtualDists;
245
+
246
+ // console.error(logger.clearFlag);
247
+ console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
248
+ console.error(result.message);
249
+
250
+ for (const detail of result.messageDetails || []) {
251
+ console.error(detail.content);
252
+ }
253
+
254
+ if (Array.isArray(result.virtualDists) && ((_result$virtualDists = result.virtualDists) === null || _result$virtualDists === void 0 ? void 0 : _result$virtualDists.length) > 0) {
255
+ generatorRealFiles(result.virtualDists);
256
+ }
257
+ } else {
258
+ generatorRealFiles(result.virtualDists);
259
+ console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
260
+ }
261
+ });
262
+ await emitter.watch();
263
+ } else {
264
+ outputDist(result, {
265
+ target,
266
+ format
267
+ });
268
+ }
269
+ };