xhs-mp-compiler-cli 2.0.9 → 2.0.10

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/dist/compiler.js CHANGED
@@ -83,6 +83,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
83
83
  pool === null || pool === void 0 ? void 0 : pool.emitWorkerMessage(payload.event, payload.data);
84
84
  }
85
85
  });
86
+ workerIns.worker.on('error', (err) => {
87
+ pool === null || pool === void 0 ? void 0 : pool.emitWorkerMessage('uncaughtException', err);
88
+ });
86
89
  };
87
90
  pool.workers.forEach(workerIns => {
88
91
  handlerWorker(workerIns);
@@ -224,11 +227,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
224
227
  this.emit('buildStart');
225
228
  yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
226
229
  this.watching = true;
227
- this.emit('buildSuccess');
230
+ this.emit('buildEnd');
228
231
  }
229
232
  catch (error) {
230
233
  this.watching = false;
231
- this.emit('buildError', { errors: [error.message] });
232
234
  throw error;
233
235
  }
234
236
  finally {
@@ -243,10 +245,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
243
245
  this.pending = true;
244
246
  this.emit('buildStart');
245
247
  yield this.call('activatePkgs', { compilePkgs });
246
- this.emit('buildSuccess');
248
+ this.emit('buildEnd');
247
249
  }
248
250
  catch (error) {
249
- this.emit('buildError', { errors: [error.message] });
250
251
  throw error;
251
252
  }
252
253
  finally {
@@ -314,12 +315,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
314
315
  yield this.call('runTask', Object.assign({ action: 'dev' }, opts));
315
316
  this.watching = true;
316
317
  (_c = this.pendingTask.resolve) === null || _c === void 0 ? void 0 : _c.forEach(fn => fn());
317
- this.emit('buildSuccess');
318
+ this.emit('buildEnd');
318
319
  }
319
320
  catch (error) {
320
321
  this.watching = false;
321
322
  (_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach(fn => fn(error));
322
- this.emit('buildError', { errors: [error.message] });
323
323
  throw error;
324
324
  }
325
325
  finally {
@@ -1,16 +1,13 @@
1
- declare const workerpool: any;
1
+ declare const workerPool: any;
2
2
  declare const createPacker: any;
3
3
  declare let globalConfig: any;
4
4
  declare let projectPacker: any;
5
- declare function formatOutputMessages(err: any, stats: any): {
6
- errors: any;
7
- warnings: any;
8
- };
5
+ declare function formatOutputError(err: any, stats: any): any;
9
6
  declare function sendMessage(data: any): void;
10
7
  declare function sendBuildInfoMessage(type: any, message: any): void;
11
8
  declare function createProjectPacker(data: any): any;
12
9
  declare const handlers: {
13
- runWatch: (data: any) => Promise<any>;
10
+ runWatch: (data: any) => Promise<void>;
14
11
  changeCompileOptions(data: any): void;
15
12
  activatePkgs: (data: any) => Promise<void>;
16
13
  runBuild: (data: any) => Promise<unknown>;
@@ -8,23 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const workerpool = require('xhs-mp-workerpool');
11
+ const workerPool = require('xhs-mp-workerpool');
12
12
  sendBuildInfoMessage('load-packer', '开始加载编译器');
13
13
  const { createPacker } = require('./packs');
14
14
  sendBuildInfoMessage('load-packer', '加载编译器完成');
15
15
  let globalConfig = {};
16
16
  let projectPacker;
17
- function formatOutputMessages(err, stats) {
17
+ function formatOutputError(err, stats) {
18
18
  if (err) {
19
- return { errors: [err.message], warnings: [] };
19
+ return err;
20
20
  }
21
21
  const json = stats.toJson({ warnings: true, errors: true, all: false });
22
- const formattedErrors = json.errors.map(item => item.message);
23
- const formattedWarnings = json.warnings.map(item => item.message);
24
- const result = { errors: formattedErrors, warnings: formattedWarnings };
25
- return result;
22
+ const formattedErrors = json.errors.map(item => `message: ${item.message}\n`);
23
+ return new Error(formattedErrors.join('\n'));
26
24
  }
27
- // workerpool 只支持在exec期间发送event
25
+ // workerPool 只支持在exec期间发送event
28
26
  // 这里自己实现sendMessage
29
27
  function sendMessage(data) {
30
28
  const msg = Object.assign(Object.assign({}, data), { customMessage: true });
@@ -100,13 +98,12 @@ const handlers = {
100
98
  // 修改文件时构建
101
99
  const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
102
100
  if (hasError) {
103
- sendMessage({
104
- event: 'emitCompileStats',
105
- data: {
106
- stats: formatOutputMessages(err, stats)
107
- }
108
- });
109
- return;
101
+ throw formatOutputError(err, stats);
102
+ // sendMessage({
103
+ // event: 'compileErrorWhenFileChange',
104
+ // data: formatOutputError(err, stats)
105
+ // })
106
+ // return
110
107
  }
111
108
  sendMessage({
112
109
  event: 'compileFinishWhenFileChange'
@@ -115,10 +112,8 @@ const handlers = {
115
112
  console.log('[compiler] it is watching...', err, stats);
116
113
  const hasError = err || stats.hasErrors();
117
114
  if (hasError) {
118
- const error = formatOutputMessages(err, stats);
119
- throw error;
115
+ throw formatOutputError(err, stats);
120
116
  }
121
- return stats;
122
117
  }),
123
118
  changeCompileOptions(data) {
124
119
  projectPacker === null || projectPacker === void 0 ? void 0 : projectPacker.changeCompileOptions(data);
@@ -132,7 +127,7 @@ const handlers = {
132
127
  console.log('run activate finish', err, stats);
133
128
  const hasError = err || ((_c = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _c === void 0 ? void 0 : _c.call(stats));
134
129
  if (hasError) {
135
- throw stats;
130
+ throw formatOutputError(err, stats);
136
131
  }
137
132
  }),
138
133
  runBuild: data => {
@@ -143,9 +138,8 @@ const handlers = {
143
138
  var _a;
144
139
  const hasError = err || ((_a = stats === null || stats === void 0 ? void 0 : stats.hasErrors) === null || _a === void 0 ? void 0 : _a.call(stats));
145
140
  if (hasError) {
146
- const statsInfo = formatOutputMessages(err, stats);
147
- reject(statsInfo);
148
- return;
141
+ const error = formatOutputError(err, stats);
142
+ return reject(error);
149
143
  }
150
144
  resolve(null);
151
145
  });
@@ -169,4 +163,4 @@ const handlers = {
169
163
  globalConfig = null;
170
164
  }
171
165
  };
172
- workerpool.worker(handlers);
166
+ workerPool.worker(handlers);
@@ -54,26 +54,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
54
54
  compiler.on('buildStart', data => {
55
55
  this.emit('simulator-compile-start', data);
56
56
  });
57
+ compiler.on('buildEnd', data => {
58
+ this.emit('simulator-compile-end', data);
59
+ });
57
60
  compiler.on('compileInfo', data => {
58
61
  this.emit('simulator-compile-info', data);
59
62
  });
60
- compiler.on('buildSuccess', data => {
61
- this.emit('simulator-compile-success', data);
63
+ compiler.on('compilePercent', data => {
64
+ this.emit('simulator-compile-percent', data);
62
65
  });
63
- compiler.on('buildError', data => {
64
- this.emit('simulator-compile-error', data);
66
+ compiler.on('compileErrorWhenFileChange', error => {
67
+ this.emit('simulator-file-change-compile-error', error);
65
68
  });
66
69
  compiler.on('compileFinishWhenFileChange', data => {
67
70
  this.emit('simulator-file-change-compile-finish', data);
68
71
  });
69
- compiler.on('compilePercent', data => {
70
- this.emit('simulator-compile-percent', data);
71
- });
72
- compiler.on('emitCompileStats', data => {
73
- this.emit('simulator-compile-stats', data);
74
- });
75
- compiler.on('unexpectedExit', data => {
76
- this.emit('simulator-compile-unexpectedExit', data);
72
+ compiler.on('uncaughtException', err => {
73
+ this.emit('simulator-uncaught-exception', err);
77
74
  });
78
75
  };
79
76
  this.initBuildCompiler = compiler => {
@@ -83,8 +80,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
83
80
  compiler.on('compileInfo', data => {
84
81
  this.emit('full-compiler-info', data);
85
82
  });
86
- compiler.on('emitCompileStats', data => {
87
- this.emit('full-compile-stats', data);
83
+ compiler.on('uncaughtException', err => {
84
+ this.emit('full-compile-uncaught-exception', err);
88
85
  });
89
86
  };
90
87
  const { logger, report, projectPath, project } = props;
@@ -253,11 +250,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
253
250
  }
254
251
  }
255
252
  const config = Object.assign(Object.assign({ compilePkgs, compressCss: false, compressJs: true, enableSourcemap: true, appendSourcemapComment: true, runInServiceSandbox: true, devWriteToDisk: true }, defaultOptions), opts);
256
- console.log('[compiler]makePkgsReady', config);
257
253
  try {
258
- this.emit('makePkgsReady-start', { config });
259
254
  yield compiler.makePkgsReady(config);
260
- this.emit('makePkgsReady-end', { config });
261
255
  (_a = this.report) === null || _a === void 0 ? void 0 : _a.call(this, 'compile', {
262
256
  result: 'success',
263
257
  entryType,
@@ -266,7 +260,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
266
260
  });
267
261
  }
268
262
  catch (error) {
269
- this.emit('makePkgsReady-error', { config, error });
270
263
  (_b = this.report) === null || _b === void 0 ? void 0 : _b.call(this, 'compile', {
271
264
  result: 'fail',
272
265
  entryType,
@@ -286,14 +279,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
286
279
  const defaultOptions = yield this.getUsingPackageType(entryType);
287
280
  const startTime = Date.now();
288
281
  const config = Object.assign(Object.assign({ compilePkgs, compressCss: false, compressJs: true, enableSourcemap: true, appendSourcemapComment: true, runInServiceSandbox: true, devWriteToDisk: true }, defaultOptions), opts);
289
- console.log('[compiler]reCompilePkgs', config);
290
282
  try {
291
- this.emit('recompile-pkgs-start', { config });
292
283
  this.removeCacheDir();
293
284
  this.removeDistDir();
294
285
  (_a = (0, sharedFs_1.default)(true)) === null || _a === void 0 ? void 0 : _a.clear();
295
286
  yield compiler.reCompilePkgs(config);
296
- this.emit('recompile-pkgs-end', { config });
297
287
  (_b = this.report) === null || _b === void 0 ? void 0 : _b.call(this, 'compile', {
298
288
  result: 'success',
299
289
  entryType,
@@ -302,7 +292,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
302
292
  });
303
293
  }
304
294
  catch (error) {
305
- this.emit('recompile-pkgs-error', { config, error });
306
295
  (_c = this.report) === null || _c === void 0 ? void 0 : _c.call(this, 'compile', {
307
296
  result: 'fail',
308
297
  entryType,
@@ -315,40 +304,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
315
304
  }
316
305
  compileProject(config) {
317
306
  return __awaiter(this, void 0, void 0, function* () {
318
- var _a, _b, _c, _d, _e;
307
+ var _a, _b, _c, _d;
319
308
  const { entryType } = config;
320
309
  try {
321
- this.emit('compile-project-start');
310
+ this.emit('full-compile-project-start');
311
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.log('Compile project...');
322
312
  const startTime = Date.now();
323
313
  const compiler = this.getCompiler(entryType);
324
314
  this.removeDistDir(entryType);
325
- (_a = (0, sharedFs_1.default)(true)) === null || _a === void 0 ? void 0 : _a.clear();
326
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project...');
327
315
  yield compiler.build(config);
328
- (_c = this.logger) === null || _c === void 0 ? void 0 : _c.log('Compile project done...');
329
- this.emit('compile-project-end');
330
- (_d = this.report) === null || _d === void 0 ? void 0 : _d.call(this, 'compile', {
316
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.log('Compile project done...');
317
+ this.emit('full-compile-project-end');
318
+ (_c = this.report) === null || _c === void 0 ? void 0 : _c.call(this, 'compile', {
331
319
  result: 'success',
332
320
  entryType,
333
321
  config: JSON.stringify(config),
334
322
  duration: Date.now() - startTime
335
323
  });
336
324
  }
337
- catch (stats) {
338
- let errors = [];
339
- if (stats.errors) {
340
- errors = stats.errors;
341
- }
342
- else if (stats instanceof Error) {
343
- errors = [stats.message];
344
- }
345
- this.emit('compile-project-error', { config, errors });
346
- const error = new Error(errors.join('\n\n'));
347
- (_e = this.report) === null || _e === void 0 ? void 0 : _e.call(this, 'compile', {
325
+ catch (error) {
326
+ (_d = this.report) === null || _d === void 0 ? void 0 : _d.call(this, 'compile', {
348
327
  result: 'fail',
349
328
  entryType,
350
329
  config: JSON.stringify(config),
351
- reason: error === null || error === void 0 ? void 0 : error.message
330
+ reason: error.message
352
331
  });
353
332
  throw error;
354
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -87,19 +87,19 @@
87
87
  "webpack-bundle-analyzer": "^4.4.0",
88
88
  "webpack-chain": "^6.5.1",
89
89
  "webpack-sources": "^3.2.2",
90
- "xhs-mp-workerpool": "^9.1.3",
91
- "xhs-mp-ml-loader": "2.0.9",
92
- "xhs-mp-compiler-utils": "2.0.9",
93
- "xhs-mp-pack": "2.0.9",
94
- "xhs-mp-project": "2.0.9",
95
- "xhs-mp-shared": "2.0.9",
96
- "xhs-mp-shared-fs": "2.0.9",
97
- "xhs-mp-sjs-loader": "2.0.9",
98
- "xhs-mp-sketch-loader": "2.0.9",
90
+ "xhs-mp-workerpool": "^9.2.0",
91
+ "xhs-mp-ml-loader": "2.0.10",
92
+ "xhs-mp-compiler-utils": "2.0.10",
93
+ "xhs-mp-pack": "2.0.10",
94
+ "xhs-mp-project": "2.0.10",
95
+ "xhs-mp-shared": "2.0.10",
96
+ "xhs-mp-shared-fs": "2.0.10",
97
+ "xhs-mp-sjs-loader": "2.0.10",
98
+ "xhs-mp-sketch-loader": "2.0.10",
99
99
  "yauzl": "^2.10.0"
100
100
  },
101
101
  "peerDependencies": {
102
- "xhs-mp-ml-parser": "2.0.9"
102
+ "xhs-mp-ml-parser": "2.0.10"
103
103
  },
104
104
  "devDependencies": {
105
105
  "@types/babel__generator": "7.6.3",
@@ -123,7 +123,7 @@
123
123
  "typescript": "5.1.6",
124
124
  "vue3-jest": "27.0.0-alpha.2",
125
125
  "webpack-dev-server": "4.0.0-beta.3",
126
- "xhs-mp-ml-parser": "2.0.9"
126
+ "xhs-mp-ml-parser": "2.0.10"
127
127
  },
128
128
  "scripts": {
129
129
  "version": "formula changelog && git add .",