@modern-js/module-tools 1.21.5 → 2.0.0-beta.1

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 (94) hide show
  1. package/CHANGELOG.md +83 -46
  2. package/dist/js/modern/cli/build.js +2 -1
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/cli/new.js +0 -3
  5. package/dist/js/modern/commands/build.js +0 -4
  6. package/dist/js/modern/commands/dev.js +2 -5
  7. package/dist/js/modern/features/build/build-platform.js +11 -14
  8. package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
  9. package/dist/js/modern/features/build/bundle/runSpeedy.js +4 -18
  10. package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
  11. package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
  12. package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
  13. package/dist/js/modern/features/build/bundleless/index.js +0 -2
  14. package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
  15. package/dist/js/modern/features/build/bundleless/style.js +1 -30
  16. package/dist/js/modern/features/build/constants.js +0 -3
  17. package/dist/js/modern/features/build/error.js +4 -27
  18. package/dist/js/modern/features/build/index.js +6 -15
  19. package/dist/js/modern/features/build/legacy-constants.js +8 -4
  20. package/dist/js/modern/features/build/logger/logText.js +0 -12
  21. package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
  22. package/dist/js/modern/features/build/normalize.js +18 -43
  23. package/dist/js/modern/features/build/utils.js +14 -19
  24. package/dist/js/modern/features/dev/index.js +4 -9
  25. package/dist/js/modern/hooks/index.js +0 -3
  26. package/dist/js/modern/index.js +5 -9
  27. package/dist/js/modern/schema/build-config.js +2 -1
  28. package/dist/js/modern/schema/output.js +5 -10
  29. package/dist/js/modern/utils/babel.js +13 -15
  30. package/dist/js/modern/utils/copy.js +6 -15
  31. package/dist/js/modern/utils/init-env.js +0 -1
  32. package/dist/js/modern/utils/logger.js +1 -16
  33. package/dist/js/modern/utils/readline.js +2 -4
  34. package/dist/js/modern/utils/tsconfig.js +0 -1
  35. package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
  36. package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
  37. package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
  38. package/dist/js/modern/utils/valide.js +2 -6
  39. package/dist/js/node/cli/build.js +2 -6
  40. package/dist/js/node/cli/dev.js +2 -7
  41. package/dist/js/node/cli/index.js +0 -6
  42. package/dist/js/node/cli/new.js +0 -8
  43. package/dist/js/node/commands/build.js +0 -19
  44. package/dist/js/node/commands/dev.js +2 -15
  45. package/dist/js/node/commands/index.js +0 -2
  46. package/dist/js/node/features/build/build-platform.js +11 -20
  47. package/dist/js/node/features/build/bundle/index.js +0 -6
  48. package/dist/js/node/features/build/bundle/runRollup.js +3 -32
  49. package/dist/js/node/features/build/bundle/runSpeedy.js +4 -32
  50. package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
  51. package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
  52. package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
  53. package/dist/js/node/features/build/bundleless/index.js +0 -11
  54. package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
  55. package/dist/js/node/features/build/bundleless/style.js +1 -50
  56. package/dist/js/node/features/build/constants.js +0 -11
  57. package/dist/js/node/features/build/error.js +4 -40
  58. package/dist/js/node/features/build/index.js +6 -38
  59. package/dist/js/node/features/build/legacy-constants.js +8 -4
  60. package/dist/js/node/features/build/logger/index.js +0 -4
  61. package/dist/js/node/features/build/logger/logText.js +0 -18
  62. package/dist/js/node/features/build/logger/loggerManager.js +5 -26
  63. package/dist/js/node/features/build/normalize.js +18 -61
  64. package/dist/js/node/features/build/utils.js +13 -35
  65. package/dist/js/node/features/dev/index.js +4 -17
  66. package/dist/js/node/hooks/build.js +0 -5
  67. package/dist/js/node/hooks/dev.js +0 -5
  68. package/dist/js/node/hooks/index.js +0 -10
  69. package/dist/js/node/index.js +6 -26
  70. package/dist/js/node/locale/index.js +0 -5
  71. package/dist/js/node/schema/build-config.js +2 -1
  72. package/dist/js/node/schema/index.js +0 -5
  73. package/dist/js/node/schema/output.js +5 -12
  74. package/dist/js/node/utils/babel.js +12 -22
  75. package/dist/js/node/utils/color.js +0 -3
  76. package/dist/js/node/utils/copy.js +6 -23
  77. package/dist/js/node/utils/init-env.js +0 -3
  78. package/dist/js/node/utils/json.js +0 -2
  79. package/dist/js/node/utils/language.js +0 -3
  80. package/dist/js/node/utils/logger.js +1 -26
  81. package/dist/js/node/utils/readline.js +0 -8
  82. package/dist/js/node/utils/tsconfig.js +0 -7
  83. package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
  84. package/dist/js/node/utils/tspaths-transform/index.js +2 -34
  85. package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
  86. package/dist/js/node/utils/valide.js +2 -11
  87. package/dist/types/commands/build.d.ts +0 -1
  88. package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
  89. package/dist/types/features/build/utils.d.ts +1 -3
  90. package/dist/types/hooks/index.d.ts +2 -1
  91. package/dist/types/index.d.ts +2 -2
  92. package/dist/types/schema/types.d.ts +1 -3
  93. package/dist/types/types.d.ts +0 -1
  94. package/package.json +20 -44
@@ -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 { Import, glob, fs, nanoid } from '@modern-js/utils';
9
6
  import { merge as deepMerge } from '@modern-js/utils/lodash';
@@ -15,17 +12,16 @@ export const generatorTsConfig = (projectTsconfig, {
15
12
  sourceDir: _sourceDir = 'src'
16
13
  }) => {
17
14
  var _projectTsconfig$comp, _projectTsconfig$comp2, _ref, _projectTsconfig$excl;
18
-
19
15
  const tempPath = path.resolve(appDirectory, './node_modules');
20
- const resolvePath = path.relative(tempPath, appDirectory); // const rootDir = projectTsconfig.compilerOptions?.rootDir
16
+ const resolvePath = path.relative(tempPath, appDirectory);
17
+ // const rootDir = projectTsconfig.compilerOptions?.rootDir
21
18
  // ? path.join(resolvePath, projectTsconfig.compilerOptions?.rootDir)
22
19
  // : resolvePath;
23
20
  // 目前限制 rootDir 的路径为 sourceDir
24
-
25
21
  const rootDir = path.join(resolvePath, _sourceDir);
26
- const baseUrl = (_projectTsconfig$comp = projectTsconfig.compilerOptions) !== null && _projectTsconfig$comp !== void 0 && _projectTsconfig$comp.baseUrl ? path.join(appDirectory, (_projectTsconfig$comp2 = projectTsconfig.compilerOptions) === null || _projectTsconfig$comp2 === void 0 ? void 0 : _projectTsconfig$comp2.baseUrl) : appDirectory; // if include = ['src'], final include should be ['../src']
22
+ const baseUrl = (_projectTsconfig$comp = projectTsconfig.compilerOptions) !== null && _projectTsconfig$comp !== void 0 && _projectTsconfig$comp.baseUrl ? path.join(appDirectory, (_projectTsconfig$comp2 = projectTsconfig.compilerOptions) === null || _projectTsconfig$comp2 === void 0 ? void 0 : _projectTsconfig$comp2.baseUrl) : appDirectory;
23
+ // if include = ['src'], final include should be ['../src']
27
24
  // const include = projectTsconfig.include?.map(includePath =>
28
-
29
25
  const include = (_ref = [_sourceDir]) === null || _ref === void 0 ? void 0 : _ref.map(includePath => path.join(resolvePath, includePath));
30
26
  const exclude = (_projectTsconfig$excl = projectTsconfig.exclude) === null || _projectTsconfig$excl === void 0 ? void 0 : _projectTsconfig$excl.map(excludePath => path.join(resolvePath, excludePath));
31
27
  const resetConfig = {
@@ -40,11 +36,9 @@ export const generatorTsConfig = (projectTsconfig, {
40
36
  include,
41
37
  exclude
42
38
  };
43
-
44
39
  if (projectTsconfig.extends) {
45
40
  resetConfig.extends = projectTsconfig.extends.startsWith('.') ? path.join(resolvePath, projectTsconfig.extends) : projectTsconfig.extends;
46
41
  }
47
-
48
42
  const recommendOption = {
49
43
  // Ensure that Babel can safely transpile files in the TypeScript project
50
44
  compilerOptions: {
@@ -53,7 +47,8 @@ export const generatorTsConfig = (projectTsconfig, {
53
47
  };
54
48
  const tempTsconfigPath = path.join(tempPath, `tsconfig.${Date.now()}.${nanoid()}.json`);
55
49
  fs.ensureFileSync(tempTsconfigPath);
56
- fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig, // 此处是必须要覆盖用户默认配置
50
+ fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig,
51
+ // 此处是必须要覆盖用户默认配置
57
52
  resetConfig));
58
53
  return tempTsconfigPath;
59
54
  };
@@ -79,7 +74,6 @@ export const resolveAlias = (modernConfig, config, watchFilenames = []) => {
79
74
  baseUrl: path.join(config.appDirectory, output.path || 'dist'),
80
75
  paths: mergedPaths
81
76
  });
82
-
83
77
  for (const r of result) {
84
78
  fs.writeFileSync(r.path, r.content);
85
79
  }
@@ -89,16 +83,12 @@ export const getTscBinPath = appDirectory => {
89
83
  root
90
84
  } = path.parse(appDirectory);
91
85
  let currentDirectory = appDirectory;
92
-
93
86
  while (currentDirectory !== root) {
94
87
  const tscBinFile = path.join(currentDirectory, './node_modules/.bin/tsc');
95
-
96
88
  if (fs.existsSync(tscBinFile)) {
97
89
  return tscBinFile;
98
90
  }
99
-
100
91
  currentDirectory = path.dirname(currentDirectory);
101
92
  }
102
-
103
93
  throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
104
94
  };
@@ -10,12 +10,10 @@ export const build = async (api, config, legacyOptions) => {
10
10
  console.info(chalk.yellowBright('bundleless 构建暂时不支持 umd 格式'));
11
11
  return;
12
12
  }
13
-
14
13
  if (legacyOptions !== null && legacyOptions !== void 0 && legacyOptions.styleOnly) {
15
14
  await buildStyle(api, config);
16
15
  return;
17
16
  }
18
-
19
17
  const tasks = config.dtsOnly ? [genDts] : [runBabelBuild, genDts, buildStyle, copyStaticAssets];
20
18
  await pMap(tasks, async task => {
21
19
  await task(api, config);
@@ -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 path from 'path';
8
5
  import { Import, glob, fs, chalk, globby, slash } from '@modern-js/utils';
9
6
  import { InternalBuildError } from "../error";
@@ -11,20 +8,15 @@ import { SectionTitleStatus, watchSectionTitle } from "../utils";
11
8
  export class BabelBuildError extends Error {
12
9
  constructor(message, opts) {
13
10
  super(message);
14
-
15
11
  _defineProperty(this, "summary", void 0);
16
-
17
12
  _defineProperty(this, "details", void 0);
18
-
19
13
  Error.captureStackTrace(this, this.constructor);
20
14
  this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
21
15
  this.details = opts === null || opts === void 0 ? void 0 : opts.details;
22
16
  }
23
-
24
17
  toString() {
25
18
  return this.formatError().join('\n');
26
19
  }
27
-
28
20
  formatError() {
29
21
  const msgs = [];
30
22
  const {
@@ -32,45 +24,39 @@ export class BabelBuildError extends Error {
32
24
  details = []
33
25
  } = this;
34
26
  msgs.push(chalk.red.bold(summary));
35
-
36
27
  for (const detail of details) {
37
28
  msgs.push(detail.content);
38
29
  msgs.push('\n');
39
30
  }
40
-
41
31
  return msgs;
42
32
  }
43
-
44
33
  }
45
34
  const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
46
35
  const bc = Import.lazy('../../../utils/babel', require);
47
- const ts = Import.lazy('../../../utils/tsconfig', require); // const logger: typeof import('../logger') = Import.lazy('../logger', require);
36
+ const ts = Import.lazy('../../../utils/tsconfig', require);
37
+
38
+ // const logger: typeof import('../logger') = Import.lazy('../logger', require);
48
39
 
49
40
  const getExts = (isTs, tsconfig) => {
50
41
  // TODO: 是否受控tsconfig.json 里的jsx配置
51
42
  let exts = [];
52
-
53
43
  if (isTs) {
54
44
  var _tsconfig$compilerOpt;
55
-
56
45
  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
46
  } else {
58
47
  exts = ['.js', '.jsx'];
59
48
  }
60
-
61
49
  return exts;
62
50
  };
63
-
64
51
  export const getWillCompilerCode = (srcDirOrFile, option) => {
65
52
  const {
66
53
  tsconfig,
67
54
  isTsProject
68
- } = option; // 如果是一个文件路径,则直接返回
69
-
55
+ } = option;
56
+ // 如果是一个文件路径,则直接返回
70
57
  if (fs.existsSync(srcDirOrFile) && fs.lstatSync(srcDirOrFile).isFile()) {
71
58
  return [srcDirOrFile];
72
59
  }
73
-
74
60
  const exts = getExts(isTsProject, tsconfig);
75
61
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
76
62
  const files = glob.sync(globPattern, {
@@ -93,7 +79,6 @@ export const buildSourceCode = async config => {
93
79
  tsconfig,
94
80
  isTsProject: Boolean(tsconfig)
95
81
  });
96
-
97
82
  if (watch) {
98
83
  const emitter = await babelCompiler.compiler({
99
84
  quiet: true,
@@ -119,7 +104,6 @@ export const buildSourceCode = async config => {
119
104
  }, babelConfig);
120
105
  }
121
106
  };
122
-
123
107
  const generatorRealFiles = virtualDists => {
124
108
  for (const virtualDist of virtualDists) {
125
109
  const {
@@ -130,7 +114,6 @@ const generatorRealFiles = virtualDists => {
130
114
  } = virtualDist;
131
115
  fs.ensureFileSync(distPath);
132
116
  fs.writeFileSync(distPath, code);
133
-
134
117
  if (sourcemap.length > 0) {
135
118
  fs.ensureFileSync(sourceMapPath);
136
119
  fs.writeFileSync(sourceMapPath, sourcemap);
@@ -142,8 +125,6 @@ const generatorRealFiles = virtualDists => {
142
125
  * @param outputResults
143
126
  * @param context
144
127
  */
145
-
146
-
147
128
  const outputDist = (outputResults, context) => {
148
129
  const {
149
130
  code,
@@ -151,7 +132,6 @@ const outputDist = (outputResults, context) => {
151
132
  messageDetails,
152
133
  virtualDists = []
153
134
  } = outputResults;
154
-
155
135
  if (code === 0) {
156
136
  generatorRealFiles(virtualDists);
157
137
  } else if (messageDetails && messageDetails.length > 0) {
@@ -164,7 +144,6 @@ const outputDist = (outputResults, context) => {
164
144
  }));
165
145
  }
166
146
  };
167
-
168
147
  export const jsFileSuffix = ['js', 'jsx', 'ts', 'tsx'];
169
148
  export const haveNotAnyJsFile = async sourceDir => {
170
149
  const files = await globby(slash(`${sourceDir}/**/*.{${jsFileSuffix.join(',')}}`));
@@ -194,12 +173,11 @@ export const runBabelBuild = async (api, config) => {
194
173
  } = bundlelessOptions;
195
174
  const sourceAbsDir = path.join(appDirectory, sourceDir);
196
175
  const tsconfigPath = path.join(appDirectory, tsconfig);
197
-
198
176
  if (await haveNotAnyJsFile(sourceAbsDir)) {
199
177
  return;
200
- } // TODO: Refactoring based on format and target
201
-
178
+ }
202
179
 
180
+ // TODO: Refactoring based on format and target
203
181
  const syntax = target === 'es5' ? 'es5' : 'es6+';
204
182
  const type = format === 'cjs' ? 'commonjs' : 'module';
205
183
  const titleText = `[Bundleless:Babel: ${format}_${target}]`;
@@ -223,14 +201,12 @@ export const runBabelBuild = async (api, config) => {
223
201
  babelConfig: buildConfig.babelConfig,
224
202
  watch
225
203
  });
226
-
227
204
  if (watch) {
228
205
  const emitter = result;
229
206
  emitter.on(babelCompiler.BuildWatchEvent.firstCompiler, result => {
230
207
  if (result.code === 1) {
231
208
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
232
209
  console.error(result.message);
233
-
234
210
  for (const detail of result.messageDetails || []) {
235
211
  console.error(detail.content);
236
212
  }
@@ -242,15 +218,12 @@ export const runBabelBuild = async (api, config) => {
242
218
  emitter.on(babelCompiler.BuildWatchEvent.watchingCompiler, result => {
243
219
  if (result.code === 1) {
244
220
  var _result$virtualDists;
245
-
246
221
  // console.error(logger.clearFlag);
247
222
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
248
223
  console.error(result.message);
249
-
250
224
  for (const detail of result.messageDetails || []) {
251
225
  console.error(detail.content);
252
226
  }
253
-
254
227
  if (Array.isArray(result.virtualDists) && ((_result$virtualDists = result.virtualDists) === null || _result$virtualDists === void 0 ? void 0 : _result$virtualDists.length) > 0) {
255
228
  generatorRealFiles(result.virtualDists);
256
229
  }
@@ -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 { fs, glob, Import, watch as watcher, WatchChangeType, chalk, globby, slash } from '@modern-js/utils';
9
6
  import { InternalBuildError } from "../error";
@@ -12,20 +9,15 @@ const compiler = Import.lazy('@modern-js/style-compiler', require);
12
9
  export class StyleBuildError extends Error {
13
10
  constructor(message, opts) {
14
11
  super(message);
15
-
16
12
  _defineProperty(this, "summary", void 0);
17
-
18
13
  _defineProperty(this, "details", void 0);
19
-
20
14
  Error.captureStackTrace(this, this.constructor);
21
15
  this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
22
16
  this.details = opts === null || opts === void 0 ? void 0 : opts.details;
23
17
  }
24
-
25
18
  toString() {
26
19
  return this.formatError().join('\n');
27
20
  }
28
-
29
21
  formatError() {
30
22
  const msgs = [];
31
23
  const {
@@ -33,24 +25,21 @@ export class StyleBuildError extends Error {
33
25
  details = []
34
26
  } = this;
35
27
  msgs.push(chalk.red.bold(summary));
36
-
37
28
  for (const detail of details) {
38
29
  if (detail.error) {
39
30
  msgs.push(detail.error);
40
31
  msgs.push('\n');
41
32
  }
42
33
  }
43
-
44
34
  return msgs;
45
35
  }
46
-
47
36
  }
37
+
48
38
  /**
49
39
  * when modern build, only throw Error or silent
50
40
  * @param result
51
41
  * @param context
52
42
  */
53
-
54
43
  const generatorFileOrLogError = (result, context) => {
55
44
  if (result.code === 0) {
56
45
  for (const file of result.dists) {
@@ -70,42 +59,35 @@ const generatorFileOrLogError = (result, context) => {
70
59
  }, context));
71
60
  }
72
61
  };
73
-
74
62
  const generatorFileAndLog = (result, titleText) => {
75
63
  if (result.code === 0) {
76
64
  for (const file of result.dists) {
77
65
  fs.ensureFileSync(file.filename);
78
66
  fs.writeFileSync(file.filename, file.content);
79
67
  }
80
-
81
68
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
82
69
  } else {
83
70
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
84
-
85
71
  for (const file of result.errors) {
86
72
  console.error(file.error);
87
73
  }
88
74
  }
89
75
  };
90
-
91
76
  const copyOriginStyleFiles = ({
92
77
  targetDir,
93
78
  outputDir,
94
79
  ignoreCSS: _ignoreCSS = false
95
80
  }) => {
96
81
  const styleFiles = glob.sync(`${targetDir}/**/*.{${_ignoreCSS ? '' : 'css,'}sass,scss,less}`);
97
-
98
82
  if (styleFiles.length > 0) {
99
83
  fs.ensureDirSync(outputDir);
100
84
  }
101
-
102
85
  for (const styleFile of styleFiles) {
103
86
  const file = path.relative(targetDir, styleFile);
104
87
  fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
105
88
  fs.copyFileSync(styleFile, path.join(outputDir, file));
106
89
  }
107
90
  };
108
-
109
91
  export const runBuild = async option => {
110
92
  const {
111
93
  watch,
@@ -116,7 +98,6 @@ export const runBuild = async option => {
116
98
  sassOption,
117
99
  postcssOption
118
100
  } = option;
119
-
120
101
  if (watch) {
121
102
  const srcStyleEmitter = compiler.styleCompiler({
122
103
  watch: true,
@@ -153,7 +134,6 @@ export const haveNotAnyStyles = async sourceDir => {
153
134
  };
154
135
  export const buildStyle = async (api, config) => {
155
136
  var _style$path;
156
-
157
137
  const modernConfig = api.useResolvedConfigContext();
158
138
  const {
159
139
  appDirectory
@@ -173,11 +153,9 @@ export const buildStyle = async (api, config) => {
173
153
  }
174
154
  } = modernConfig;
175
155
  const titleText = `[Bundleless:Style:${sourceDir}]`;
176
-
177
156
  if ((await haveNotAnyStyles(sourceDir)) || style.compileMode === false) {
178
157
  return;
179
158
  }
180
-
181
159
  const runner = api.useHookRunners();
182
160
  const lessOption = await runner.moduleLessConfig({
183
161
  modernConfig
@@ -195,16 +173,12 @@ export const buildStyle = async (api, config) => {
195
173
  onLast: async _ => undefined
196
174
  });
197
175
  const postcssOption = getPostcssOption(appDirectory, modernConfig);
198
-
199
176
  if (tailwindPlugin) {
200
177
  var _postcssOption$plugin;
201
-
202
178
  (_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
203
179
  }
204
-
205
180
  const srcDir = path.resolve(appDirectory, sourceDir);
206
181
  const outputDirToSrc = path.join(appDirectory, distPath, outputPath, (_style$path = style.path) !== null && _style$path !== void 0 ? _style$path : './');
207
-
208
182
  if (style.compileMode === 'all' || style.compileMode === 'only-compiled-code') {
209
183
  const result = await runBuild({
210
184
  appDirectory,
@@ -215,7 +189,6 @@ export const buildStyle = async (api, config) => {
215
189
  sassOption,
216
190
  postcssOption
217
191
  });
218
-
219
192
  if (watch) {
220
193
  const emitter = result;
221
194
  emitter.on(compiler.BuildWatchEvent.firstCompiler, result => {
@@ -233,7 +206,6 @@ export const buildStyle = async (api, config) => {
233
206
  });
234
207
  }
235
208
  }
236
-
237
209
  if (style.compileMode === 'all' || style.compileMode === 'only-source-code') {
238
210
  if (watch) {
239
211
  copyOriginStyleFiles({
@@ -256,7 +228,6 @@ export const buildStyle = async (api, config) => {
256
228
  ignoreCSS: style.compileMode === 'all'
257
229
  });
258
230
  }
259
-
260
231
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
261
232
  });
262
233
  } else {
@@ -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 { chalk } from '@modern-js/utils';
8
5
  export const clearFlag = '\x1Bc';
9
6
  export const buildingText = chalk.blue('Building...');
@@ -1,5 +1,4 @@
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
  import { chalk } from '@modern-js/utils';
4
3
  export const padSpaceWith = (str, targetL, opts = {}) => {
5
4
  const {
@@ -8,48 +7,39 @@ export const padSpaceWith = (str, targetL, opts = {}) => {
8
7
  } = opts;
9
8
  const l = str.length;
10
9
  const endStrL = endStr.length;
11
- const resetL = targetL - l - endStrL; // str is 'aaa', targetL is 4, result is 'aaa|'
10
+ const resetL = targetL - l - endStrL;
12
11
 
12
+ // str is 'aaa', targetL is 4, result is 'aaa|'
13
13
  if (resetL === 0) {
14
14
  return (style ? style(str) : str) + endStr;
15
- } // str is 'aaa', targetL is 5, result is 'aaa |'
16
-
15
+ }
17
16
 
17
+ // str is 'aaa', targetL is 5, result is 'aaa |'
18
18
  if (resetL > 0) {
19
19
  const padStr = str.padEnd(targetL - 1, ' ');
20
-
21
20
  if (style) {
22
21
  return style(str) + padStr.replace(str, '') + endStr;
23
22
  }
24
-
25
23
  return padStr + endStr;
26
24
  }
27
-
28
25
  return str;
29
26
  };
30
27
  export class InternalBuildError extends Error {
31
28
  constructor(e, opts) {
32
29
  super(e.message);
33
-
34
30
  _defineProperty(this, "buildType", void 0);
35
-
36
31
  _defineProperty(this, "target", void 0);
37
-
38
32
  _defineProperty(this, "format", void 0);
39
-
40
33
  _defineProperty(this, "e", void 0);
41
-
42
34
  Error.captureStackTrace(this, this.constructor);
43
35
  this.e = e;
44
36
  this.buildType = opts.buildType;
45
37
  this.target = opts.target;
46
38
  this.format = opts.format;
47
39
  }
48
-
49
40
  toString() {
50
41
  return this.formatError().join('\n');
51
42
  }
52
-
53
43
  formatError() {
54
44
  const msgs = [];
55
45
  const {
@@ -80,25 +70,19 @@ export class InternalBuildError extends Error {
80
70
  msgs.push(e.stack || '');
81
71
  return msgs;
82
72
  }
83
-
84
73
  }
85
74
  export class InternalDTSError extends Error {
86
75
  constructor(e, opts) {
87
76
  super(e.message);
88
-
89
77
  _defineProperty(this, "buildType", void 0);
90
-
91
78
  _defineProperty(this, "e", void 0);
92
-
93
79
  Error.captureStackTrace(this, this.constructor);
94
80
  this.e = e;
95
81
  this.buildType = opts.buildType;
96
82
  }
97
-
98
83
  toString() {
99
84
  return this.formatError().join('\n');
100
85
  }
101
-
102
86
  formatError() {
103
87
  const msgs = [];
104
88
  const {
@@ -106,7 +90,6 @@ export class InternalDTSError extends Error {
106
90
  buildType
107
91
  } = this;
108
92
  msgs.push(chalk.red.bold(`${buildType} DTS failed:`));
109
-
110
93
  if (isExecaError(e)) {
111
94
  /**
112
95
  * `shortMeessage` content like:
@@ -115,16 +98,13 @@ export class InternalDTSError extends Error {
115
98
  */
116
99
  if (e.stack) {
117
100
  var _e$stack;
118
-
119
101
  msgs.push((_e$stack = e.stack) === null || _e$stack === void 0 ? void 0 : _e$stack.replace(`${e.name}: ${e.shortMessage}`, ''));
120
102
  }
121
103
  } else {
122
104
  msgs.push(e.stack);
123
105
  }
124
-
125
106
  return msgs;
126
107
  }
127
-
128
108
  }
129
109
  export class ModuleBuildError extends Error {
130
110
  constructor(e) {
@@ -132,19 +112,16 @@ export class ModuleBuildError extends Error {
132
112
  Error.captureStackTrace(this, this.constructor);
133
113
  this.name = 'ModuleBuildError';
134
114
  }
135
-
136
115
  }
137
116
  export const isInternalError = e => {
138
117
  if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
139
118
  return true;
140
119
  }
141
-
142
120
  return false;
143
121
  };
144
122
  export const isExecaError = e => {
145
123
  if (e.stdout) {
146
124
  return true;
147
125
  }
148
-
149
126
  return false;
150
127
  };
@@ -15,7 +15,6 @@ export const checkPlatformAndRunBuild = async (platform, options) => {
15
15
  api,
16
16
  isTsProject
17
17
  } = options;
18
-
19
18
  if (typeof platform === 'boolean' && platform) {
20
19
  if (process.env.RUN_PLATFORM) {
21
20
  await bp.buildPlatform(api, {
@@ -23,12 +22,10 @@ export const checkPlatformAndRunBuild = async (platform, options) => {
23
22
  isTsProject
24
23
  });
25
24
  }
26
-
27
25
  return {
28
26
  exit: true
29
27
  };
30
28
  }
31
-
32
29
  if (typeof platform === 'string') {
33
30
  if (process.env.RUN_PLATFORM) {
34
31
  await bp.buildPlatform(api, {
@@ -36,12 +33,10 @@ export const checkPlatformAndRunBuild = async (platform, options) => {
36
33
  isTsProject
37
34
  });
38
35
  }
39
-
40
36
  return {
41
37
  exit: true
42
38
  };
43
39
  }
44
-
45
40
  return {
46
41
  exit: false
47
42
  };
@@ -57,17 +52,15 @@ export const runBuild = async (api, normalizedModuleConfig, config) => {
57
52
  };
58
53
  export const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
59
54
  console.info(chalk.blue.bold(buildingText));
60
-
61
55
  try {
62
56
  // eslint-disable-next-line no-console
63
57
  console.time(buildSuccessText);
64
58
  await runBuild(api, normalizedModuleConfig, config);
65
- ReadlineUtils.clearPrevLine(process.stdout); // eslint-disable-next-line no-console
66
-
59
+ ReadlineUtils.clearPrevLine(process.stdout);
60
+ // eslint-disable-next-line no-console
67
61
  console.timeEnd(buildSuccessText);
68
62
  } catch (e) {
69
63
  ReadlineUtils.clearPrevLine(process.stdout);
70
-
71
64
  if (isInternalError(e)) {
72
65
  throw new ModuleBuildError(e);
73
66
  } else {
@@ -90,23 +83,22 @@ export const build = async (api, config) => {
90
83
  output: {
91
84
  path: outputPath = 'dist'
92
85
  }
93
- } = modernConfig; // build platform
86
+ } = modernConfig;
94
87
 
88
+ // build platform
95
89
  const platformBuildRet = await checkPlatformAndRunBuild(platform, {
96
90
  api,
97
91
  isTsProject
98
92
  });
99
-
100
93
  if (platformBuildRet.exit) {
101
94
  return;
102
95
  }
103
-
104
96
  if (clear) {
105
97
  fs.removeSync(path.join(appDirectory, outputPath));
106
98
  }
99
+ const deps = getAllDeps(appDirectory);
107
100
 
108
- const deps = getAllDeps(appDirectory); // should normalize module tool config here, ensure the same config for build
109
-
101
+ // should normalize module tool config here, ensure the same config for build
110
102
  const normalizedModuleConfig = normalizeModuleConfig({
111
103
  buildFeatOption: config,
112
104
  api,
@@ -116,7 +108,6 @@ export const build = async (api, config) => {
116
108
  modernConfig,
117
109
  appContext
118
110
  });
119
-
120
111
  if (config.enableWatchMode) {
121
112
  console.info(chalk.blue.underline('start build in watch mode...\n'));
122
113
  await runBuild(api, normalizedModuleConfig, config);