@modern-js/module-tools 2.0.0-beta.0 → 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 (93) hide show
  1. package/CHANGELOG.md +51 -0
  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 +5 -14
  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 +12 -14
  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 +5 -30
  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 +0 -1
  90. package/dist/types/index.d.ts +0 -2
  91. package/dist/types/schema/types.d.ts +1 -3
  92. package/dist/types/types.d.ts +0 -1
  93. package/package.json +19 -19
@@ -4,40 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.runBabelBuild = exports.jsFileSuffix = exports.haveNotAnyJsFile = exports.getWillCompilerCode = exports.buildSourceCode = exports.BabelBuildError = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _error = require("../error");
13
-
14
10
  var _utils2 = require("../utils");
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  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; }
19
-
20
13
  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; }
21
-
22
14
  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; }
23
-
24
15
  class BabelBuildError extends Error {
25
16
  constructor(message, opts) {
26
17
  super(message);
27
-
28
18
  _defineProperty(this, "summary", void 0);
29
-
30
19
  _defineProperty(this, "details", void 0);
31
-
32
20
  Error.captureStackTrace(this, this.constructor);
33
21
  this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
34
22
  this.details = opts === null || opts === void 0 ? void 0 : opts.details;
35
23
  }
36
-
37
24
  toString() {
38
25
  return this.formatError().join('\n');
39
26
  }
40
-
41
27
  formatError() {
42
28
  const msgs = [];
43
29
  const {
@@ -45,64 +31,49 @@ class BabelBuildError extends Error {
45
31
  details = []
46
32
  } = this;
47
33
  msgs.push(_utils.chalk.red.bold(summary));
48
-
49
34
  for (const detail of details) {
50
35
  msgs.push(detail.content);
51
36
  msgs.push('\n');
52
37
  }
53
-
54
38
  return msgs;
55
39
  }
56
-
57
40
  }
58
-
59
41
  exports.BabelBuildError = BabelBuildError;
60
-
61
42
  const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
62
-
63
43
  const bc = _utils.Import.lazy('../../../utils/babel', require);
44
+ const ts = _utils.Import.lazy('../../../utils/tsconfig', require);
64
45
 
65
- const ts = _utils.Import.lazy('../../../utils/tsconfig', require); // const logger: typeof import('../logger') = Import.lazy('../logger', require);
66
-
46
+ // const logger: typeof import('../logger') = Import.lazy('../logger', require);
67
47
 
68
48
  const getExts = (isTs, tsconfig) => {
69
49
  // TODO: 是否受控tsconfig.json 里的jsx配置
70
50
  let exts = [];
71
-
72
51
  if (isTs) {
73
52
  var _tsconfig$compilerOpt;
74
-
75
53
  exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
76
54
  } else {
77
55
  exts = ['.js', '.jsx'];
78
56
  }
79
-
80
57
  return exts;
81
58
  };
82
-
83
59
  const getWillCompilerCode = (srcDirOrFile, option) => {
84
60
  const {
85
61
  tsconfig,
86
62
  isTsProject
87
- } = option; // 如果是一个文件路径,则直接返回
88
-
63
+ } = option;
64
+ // 如果是一个文件路径,则直接返回
89
65
  if (_utils.fs.existsSync(srcDirOrFile) && _utils.fs.lstatSync(srcDirOrFile).isFile()) {
90
66
  return [srcDirOrFile];
91
67
  }
92
-
93
68
  const exts = getExts(isTsProject, tsconfig);
94
69
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
95
-
96
70
  const files = _utils.glob.sync(globPattern, {
97
71
  ignore: [`${srcDirOrFile}/**/*.d.ts`],
98
72
  absolute: true
99
73
  });
100
-
101
74
  return files;
102
75
  };
103
-
104
76
  exports.getWillCompilerCode = getWillCompilerCode;
105
-
106
77
  const buildSourceCode = async config => {
107
78
  const {
108
79
  willCompilerDirOrFile,
@@ -117,7 +88,6 @@ const buildSourceCode = async config => {
117
88
  tsconfig,
118
89
  isTsProject: Boolean(tsconfig)
119
90
  });
120
-
121
91
  if (watch) {
122
92
  const emitter = await babelCompiler.compiler({
123
93
  quiet: true,
@@ -143,9 +113,7 @@ const buildSourceCode = async config => {
143
113
  }, babelConfig);
144
114
  }
145
115
  };
146
-
147
116
  exports.buildSourceCode = buildSourceCode;
148
-
149
117
  const generatorRealFiles = virtualDists => {
150
118
  for (const virtualDist of virtualDists) {
151
119
  const {
@@ -154,14 +122,10 @@ const generatorRealFiles = virtualDists => {
154
122
  sourcemap,
155
123
  sourceMapPath
156
124
  } = virtualDist;
157
-
158
125
  _utils.fs.ensureFileSync(distPath);
159
-
160
126
  _utils.fs.writeFileSync(distPath, code);
161
-
162
127
  if (sourcemap.length > 0) {
163
128
  _utils.fs.ensureFileSync(sourceMapPath);
164
-
165
129
  _utils.fs.writeFileSync(sourceMapPath, sourcemap);
166
130
  }
167
131
  }
@@ -171,8 +135,6 @@ const generatorRealFiles = virtualDists => {
171
135
  * @param outputResults
172
136
  * @param context
173
137
  */
174
-
175
-
176
138
  const outputDist = (outputResults, context) => {
177
139
  const {
178
140
  code,
@@ -180,7 +142,6 @@ const outputDist = (outputResults, context) => {
180
142
  messageDetails,
181
143
  virtualDists = []
182
144
  } = outputResults;
183
-
184
145
  if (code === 0) {
185
146
  generatorRealFiles(virtualDists);
186
147
  } else if (messageDetails && messageDetails.length > 0) {
@@ -193,17 +154,13 @@ const outputDist = (outputResults, context) => {
193
154
  }));
194
155
  }
195
156
  };
196
-
197
157
  const jsFileSuffix = ['js', 'jsx', 'ts', 'tsx'];
198
158
  exports.jsFileSuffix = jsFileSuffix;
199
-
200
159
  const haveNotAnyJsFile = async sourceDir => {
201
160
  const files = await (0, _utils.globby)((0, _utils.slash)(`${sourceDir}/**/*.{${jsFileSuffix.join(',')}}`));
202
161
  return files.length === 0;
203
162
  };
204
-
205
163
  exports.haveNotAnyJsFile = haveNotAnyJsFile;
206
-
207
164
  const runBabelBuild = async (api, config) => {
208
165
  const {
209
166
  bundlelessOptions,
@@ -226,16 +183,13 @@ const runBabelBuild = async (api, config) => {
226
183
  const {
227
184
  sourceDir = './src'
228
185
  } = bundlelessOptions;
229
-
230
186
  const sourceAbsDir = _path.default.join(appDirectory, sourceDir);
231
-
232
187
  const tsconfigPath = _path.default.join(appDirectory, tsconfig);
233
-
234
188
  if (await haveNotAnyJsFile(sourceAbsDir)) {
235
189
  return;
236
- } // TODO: Refactoring based on format and target
237
-
190
+ }
238
191
 
192
+ // TODO: Refactoring based on format and target
239
193
  const syntax = target === 'es5' ? 'es5' : 'es6+';
240
194
  const type = format === 'cjs' ? 'commonjs' : 'module';
241
195
  const titleText = `[Bundleless:Babel: ${format}_${target}]`;
@@ -249,9 +203,7 @@ const runBabelBuild = async (api, config) => {
249
203
  type
250
204
  })
251
205
  };
252
-
253
206
  const distDir = _path.default.join(appDirectory, distPath, outputPath);
254
-
255
207
  const result = await buildSourceCode({
256
208
  appDirectory,
257
209
  distDir,
@@ -261,14 +213,12 @@ const runBabelBuild = async (api, config) => {
261
213
  babelConfig: buildConfig.babelConfig,
262
214
  watch
263
215
  });
264
-
265
216
  if (watch) {
266
217
  const emitter = result;
267
218
  emitter.on(babelCompiler.BuildWatchEvent.firstCompiler, result => {
268
219
  if (result.code === 1) {
269
220
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Fail));
270
221
  console.error(result.message);
271
-
272
222
  for (const detail of result.messageDetails || []) {
273
223
  console.error(detail.content);
274
224
  }
@@ -280,15 +230,12 @@ const runBabelBuild = async (api, config) => {
280
230
  emitter.on(babelCompiler.BuildWatchEvent.watchingCompiler, result => {
281
231
  if (result.code === 1) {
282
232
  var _result$virtualDists;
283
-
284
233
  // console.error(logger.clearFlag);
285
234
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Fail));
286
235
  console.error(result.message);
287
-
288
236
  for (const detail of result.messageDetails || []) {
289
237
  console.error(detail.content);
290
238
  }
291
-
292
239
  if (Array.isArray(result.virtualDists) && ((_result$virtualDists = result.virtualDists) === null || _result$virtualDists === void 0 ? void 0 : _result$virtualDists.length) > 0) {
293
240
  generatorRealFiles(result.virtualDists);
294
241
  }
@@ -305,5 +252,4 @@ const runBabelBuild = async (api, config) => {
305
252
  });
306
253
  }
307
254
  };
308
-
309
255
  exports.runBabelBuild = runBabelBuild;
@@ -4,44 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.styleFileSuffix = exports.runBuild = exports.haveNotAnyStyles = exports.buildStyle = exports.StyleBuildError = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _error = require("../error");
13
-
14
10
  var _utils2 = require("../utils");
15
-
16
11
  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); }
17
-
18
12
  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; }
19
-
20
13
  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; }
21
-
22
14
  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; }
23
-
24
15
  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; }
25
-
26
16
  const compiler = _utils.Import.lazy('@modern-js/style-compiler', require);
27
-
28
17
  class StyleBuildError extends Error {
29
18
  constructor(message, opts) {
30
19
  super(message);
31
-
32
20
  _defineProperty(this, "summary", void 0);
33
-
34
21
  _defineProperty(this, "details", void 0);
35
-
36
22
  Error.captureStackTrace(this, this.constructor);
37
23
  this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
38
24
  this.details = opts === null || opts === void 0 ? void 0 : opts.details;
39
25
  }
40
-
41
26
  toString() {
42
27
  return this.formatError().join('\n');
43
28
  }
44
-
45
29
  formatError() {
46
30
  const msgs = [];
47
31
  const {
@@ -49,32 +33,26 @@ class StyleBuildError extends Error {
49
33
  details = []
50
34
  } = this;
51
35
  msgs.push(_utils.chalk.red.bold(summary));
52
-
53
36
  for (const detail of details) {
54
37
  if (detail.error) {
55
38
  msgs.push(detail.error);
56
39
  msgs.push('\n');
57
40
  }
58
41
  }
59
-
60
42
  return msgs;
61
43
  }
62
-
63
44
  }
45
+
64
46
  /**
65
47
  * when modern build, only throw Error or silent
66
48
  * @param result
67
49
  * @param context
68
50
  */
69
-
70
-
71
51
  exports.StyleBuildError = StyleBuildError;
72
-
73
52
  const generatorFileOrLogError = (result, context) => {
74
53
  if (result.code === 0) {
75
54
  for (const file of result.dists) {
76
55
  _utils.fs.ensureFileSync(file.filename);
77
-
78
56
  _utils.fs.writeFileSync(file.filename, file.content);
79
57
  }
80
58
  } else {
@@ -90,45 +68,35 @@ const generatorFileOrLogError = (result, context) => {
90
68
  }, context));
91
69
  }
92
70
  };
93
-
94
71
  const generatorFileAndLog = (result, titleText) => {
95
72
  if (result.code === 0) {
96
73
  for (const file of result.dists) {
97
74
  _utils.fs.ensureFileSync(file.filename);
98
-
99
75
  _utils.fs.writeFileSync(file.filename, file.content);
100
76
  }
101
-
102
77
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Success));
103
78
  } else {
104
79
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Fail));
105
-
106
80
  for (const file of result.errors) {
107
81
  console.error(file.error);
108
82
  }
109
83
  }
110
84
  };
111
-
112
85
  const copyOriginStyleFiles = ({
113
86
  targetDir,
114
87
  outputDir,
115
88
  ignoreCSS: _ignoreCSS = false
116
89
  }) => {
117
90
  const styleFiles = _utils.glob.sync(`${targetDir}/**/*.{${_ignoreCSS ? '' : 'css,'}sass,scss,less}`);
118
-
119
91
  if (styleFiles.length > 0) {
120
92
  _utils.fs.ensureDirSync(outputDir);
121
93
  }
122
-
123
94
  for (const styleFile of styleFiles) {
124
95
  const file = path.relative(targetDir, styleFile);
125
-
126
96
  _utils.fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
127
-
128
97
  _utils.fs.copyFileSync(styleFile, path.join(outputDir, file));
129
98
  }
130
99
  };
131
-
132
100
  const runBuild = async option => {
133
101
  const {
134
102
  watch,
@@ -139,7 +107,6 @@ const runBuild = async option => {
139
107
  sassOption,
140
108
  postcssOption
141
109
  } = option;
142
-
143
110
  if (watch) {
144
111
  const srcStyleEmitter = compiler.styleCompiler({
145
112
  watch: true,
@@ -169,21 +136,16 @@ const runBuild = async option => {
169
136
  return srcStyleResult;
170
137
  }
171
138
  };
172
-
173
139
  exports.runBuild = runBuild;
174
140
  const styleFileSuffix = ['css', 'less', 'sass', 'scss'];
175
141
  exports.styleFileSuffix = styleFileSuffix;
176
-
177
142
  const haveNotAnyStyles = async sourceDir => {
178
143
  const files = await (0, _utils.globby)((0, _utils.slash)(`${sourceDir}/**/*.{${styleFileSuffix.join(',')}}`));
179
144
  return files.length === 0;
180
145
  };
181
-
182
146
  exports.haveNotAnyStyles = haveNotAnyStyles;
183
-
184
147
  const buildStyle = async (api, config) => {
185
148
  var _style$path;
186
-
187
149
  const modernConfig = api.useResolvedConfigContext();
188
150
  const {
189
151
  appDirectory
@@ -203,11 +165,9 @@ const buildStyle = async (api, config) => {
203
165
  }
204
166
  } = modernConfig;
205
167
  const titleText = `[Bundleless:Style:${sourceDir}]`;
206
-
207
168
  if ((await haveNotAnyStyles(sourceDir)) || style.compileMode === false) {
208
169
  return;
209
170
  }
210
-
211
171
  const runner = api.useHookRunners();
212
172
  const lessOption = await runner.moduleLessConfig({
213
173
  modernConfig
@@ -225,16 +185,12 @@ const buildStyle = async (api, config) => {
225
185
  onLast: async _ => undefined
226
186
  });
227
187
  const postcssOption = (0, _utils2.getPostcssOption)(appDirectory, modernConfig);
228
-
229
188
  if (tailwindPlugin) {
230
189
  var _postcssOption$plugin;
231
-
232
190
  (_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
233
191
  }
234
-
235
192
  const srcDir = path.resolve(appDirectory, sourceDir);
236
193
  const outputDirToSrc = path.join(appDirectory, distPath, outputPath, (_style$path = style.path) !== null && _style$path !== void 0 ? _style$path : './');
237
-
238
194
  if (style.compileMode === 'all' || style.compileMode === 'only-compiled-code') {
239
195
  const result = await runBuild({
240
196
  appDirectory,
@@ -245,7 +201,6 @@ const buildStyle = async (api, config) => {
245
201
  sassOption,
246
202
  postcssOption
247
203
  });
248
-
249
204
  if (watch) {
250
205
  const emitter = result;
251
206
  emitter.on(compiler.BuildWatchEvent.firstCompiler, result => {
@@ -263,7 +218,6 @@ const buildStyle = async (api, config) => {
263
218
  });
264
219
  }
265
220
  }
266
-
267
221
  if (style.compileMode === 'all' || style.compileMode === 'only-source-code') {
268
222
  if (watch) {
269
223
  copyOriginStyleFiles({
@@ -278,7 +232,6 @@ const buildStyle = async (api, config) => {
278
232
  }) => {
279
233
  if (changeType === _utils.WatchChangeType.UNLINK) {
280
234
  const removeFile = path.normalize(`${outputDirToSrc}/${path.relative(srcDir, changedFilePath)}`);
281
-
282
235
  _utils.fs.removeSync(removeFile);
283
236
  } else {
284
237
  copyOriginStyleFiles({
@@ -287,7 +240,6 @@ const buildStyle = async (api, config) => {
287
240
  ignoreCSS: style.compileMode === 'all'
288
241
  });
289
242
  }
290
-
291
243
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Success));
292
244
  });
293
245
  } else {
@@ -299,5 +251,4 @@ const buildStyle = async (api, config) => {
299
251
  }
300
252
  }
301
253
  };
302
-
303
254
  exports.buildStyle = buildStyle;
@@ -4,28 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.unPresets = exports.unPresetWithTargetConfigs = exports.unPresetConfigs = exports.targets = exports.npmLibraryWithUmdPresetConfig = exports.npmLibraryPresetConfig = exports.npmComponentWithUmdPresetConfig = exports.npmComponentPresetConfig = exports.clearFlag = exports.buildingText = exports.buildSuccessText = exports.buildFailText = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
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 clearFlag = '\x1Bc';
17
12
  exports.clearFlag = clearFlag;
18
-
19
13
  const buildingText = _utils.chalk.blue('Building...');
20
-
21
14
  exports.buildingText = buildingText;
22
-
23
15
  const buildSuccessText = _utils.chalk.green('Build succeed');
24
-
25
16
  exports.buildSuccessText = buildSuccessText;
26
-
27
17
  const buildFailText = _utils.chalk.red('Build Failed:');
28
-
29
18
  exports.buildFailText = buildFailText;
30
19
  const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext'];
31
20
  exports.targets = targets;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.padSpaceWith = exports.isInternalError = exports.isExecaError = exports.ModuleBuildError = exports.InternalDTSError = exports.InternalBuildError = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  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; }
11
-
12
9
  const padSpaceWith = (str, targetL, opts = {}) => {
13
10
  const {
14
11
  endStr = '|',
@@ -16,51 +13,40 @@ const padSpaceWith = (str, targetL, opts = {}) => {
16
13
  } = opts;
17
14
  const l = str.length;
18
15
  const endStrL = endStr.length;
19
- const resetL = targetL - l - endStrL; // str is 'aaa', targetL is 4, result is 'aaa|'
16
+ const resetL = targetL - l - endStrL;
20
17
 
18
+ // str is 'aaa', targetL is 4, result is 'aaa|'
21
19
  if (resetL === 0) {
22
20
  return (style ? style(str) : str) + endStr;
23
- } // str is 'aaa', targetL is 5, result is 'aaa |'
24
-
21
+ }
25
22
 
23
+ // str is 'aaa', targetL is 5, result is 'aaa |'
26
24
  if (resetL > 0) {
27
25
  const padStr = str.padEnd(targetL - 1, ' ');
28
-
29
26
  if (style) {
30
27
  return style(str) + padStr.replace(str, '') + endStr;
31
28
  }
32
-
33
29
  return padStr + endStr;
34
30
  }
35
-
36
31
  return str;
37
32
  };
38
-
39
33
  exports.padSpaceWith = padSpaceWith;
40
-
41
34
  class InternalBuildError extends Error {
42
35
  constructor(e, opts) {
43
36
  super(e.message);
44
-
45
37
  _defineProperty(this, "buildType", void 0);
46
-
47
38
  _defineProperty(this, "target", void 0);
48
-
49
39
  _defineProperty(this, "format", void 0);
50
-
51
40
  _defineProperty(this, "e", void 0);
52
-
53
41
  Error.captureStackTrace(this, this.constructor);
54
42
  this.e = e;
55
43
  this.buildType = opts.buildType;
56
44
  this.target = opts.target;
57
45
  this.format = opts.format;
58
46
  }
59
-
60
47
  toString() {
61
48
  return this.formatError().join('\n');
62
49
  }
63
-
64
50
  formatError() {
65
51
  const msgs = [];
66
52
  const {
@@ -91,28 +77,20 @@ class InternalBuildError extends Error {
91
77
  msgs.push(e.stack || '');
92
78
  return msgs;
93
79
  }
94
-
95
80
  }
96
-
97
81
  exports.InternalBuildError = InternalBuildError;
98
-
99
82
  class InternalDTSError extends Error {
100
83
  constructor(e, opts) {
101
84
  super(e.message);
102
-
103
85
  _defineProperty(this, "buildType", void 0);
104
-
105
86
  _defineProperty(this, "e", void 0);
106
-
107
87
  Error.captureStackTrace(this, this.constructor);
108
88
  this.e = e;
109
89
  this.buildType = opts.buildType;
110
90
  }
111
-
112
91
  toString() {
113
92
  return this.formatError().join('\n');
114
93
  }
115
-
116
94
  formatError() {
117
95
  const msgs = [];
118
96
  const {
@@ -120,7 +98,6 @@ class InternalDTSError extends Error {
120
98
  buildType
121
99
  } = this;
122
100
  msgs.push(_utils.chalk.red.bold(`${buildType} DTS failed:`));
123
-
124
101
  if (isExecaError(e)) {
125
102
  /**
126
103
  * `shortMeessage` content like:
@@ -129,47 +106,34 @@ class InternalDTSError extends Error {
129
106
  */
130
107
  if (e.stack) {
131
108
  var _e$stack;
132
-
133
109
  msgs.push((_e$stack = e.stack) === null || _e$stack === void 0 ? void 0 : _e$stack.replace(`${e.name}: ${e.shortMessage}`, ''));
134
110
  }
135
111
  } else {
136
112
  msgs.push(e.stack);
137
113
  }
138
-
139
114
  return msgs;
140
115
  }
141
-
142
116
  }
143
-
144
117
  exports.InternalDTSError = InternalDTSError;
145
-
146
118
  class ModuleBuildError extends Error {
147
119
  constructor(e) {
148
120
  super(`\n\n${e}`);
149
121
  Error.captureStackTrace(this, this.constructor);
150
122
  this.name = 'ModuleBuildError';
151
123
  }
152
-
153
124
  }
154
-
155
125
  exports.ModuleBuildError = ModuleBuildError;
156
-
157
126
  const isInternalError = e => {
158
127
  if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
159
128
  return true;
160
129
  }
161
-
162
130
  return false;
163
131
  };
164
-
165
132
  exports.isInternalError = isInternalError;
166
-
167
133
  const isExecaError = e => {
168
134
  if (e.stdout) {
169
135
  return true;
170
136
  }
171
-
172
137
  return false;
173
138
  };
174
-
175
139
  exports.isExecaError = isExecaError;