xhs-mp-compiler-cli 2.0.5 → 2.0.6

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.
@@ -31,11 +31,14 @@ export declare abstract class AbstractCompiler extends EventEmitter {
31
31
  protected workerType: IWorkerType;
32
32
  private compilerOpts;
33
33
  protected logger: any;
34
- protected pool: any;
34
+ protected _pool: any;
35
35
  constructor(opts: ICompilerOption, args: ICompilerArgs);
36
+ get pool(): any;
37
+ set pool(val: any);
36
38
  static prepareDevPool(): void;
37
39
  static createPool(workerType: any, poolOpts?: {}, processArgs?: {}): any;
38
40
  static createProcessOps: (processArgs: any) => any;
41
+ abstract makePoolReady(args?: any): any;
39
42
  close(): void;
40
43
  kill(): void;
41
44
  call: (method: any, data: any, options?: any) => any;
@@ -46,6 +49,7 @@ export declare class MPPackDevCompiler extends AbstractCompiler {
46
49
  private readyPkgs;
47
50
  private watching;
48
51
  constructor(props: any, args: any);
52
+ makePoolReady(): void;
49
53
  reset(): void;
50
54
  doCompilePkgs(opts: ICheckOptions): Promise<unknown>;
51
55
  private compilePkgsAndWatch;
@@ -58,12 +62,14 @@ export declare class WebPackDevCompiler extends AbstractCompiler {
58
62
  private watching;
59
63
  private pendingTask?;
60
64
  constructor(props: any, args: any);
65
+ makePoolReady(args: any): void;
61
66
  makePkgsReady(opts: any): Promise<unknown>;
62
67
  reCompilePkgs(opts: any): Promise<void>;
63
68
  }
64
69
  export declare class BuildCompiler extends AbstractCompiler {
65
70
  cps: any;
66
71
  constructor(props: any, args: any);
72
+ makePoolReady(args: any): void;
67
73
  build(option: ICheckOptions): Promise<any>;
68
74
  }
69
75
  export declare function getProjectCompilerClass(compilerType: any): typeof MPPackDevCompiler | typeof WebPackDevCompiler | typeof BuildCompiler;
package/dist/compiler.js CHANGED
@@ -41,6 +41,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
41
41
  this.logger = args.logger || console;
42
42
  this.workerType = args.workerType || 'process';
43
43
  }
44
+ get pool() {
45
+ if (!this._pool) {
46
+ this.makePoolReady();
47
+ }
48
+ return this._pool;
49
+ }
50
+ set pool(val) {
51
+ this._pool = val;
52
+ }
44
53
  static prepareDevPool() {
45
54
  preparedDevPool = AbstractCompiler.createPool('web', {
46
55
  minWorkers: 1,
@@ -134,16 +143,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
134
143
  this.watching = false;
135
144
  this.workerType = (args === null || args === void 0 ? void 0 : args.workerType) || 'web';
136
145
  this.inspectPort = 9227;
146
+ this.makePoolReady();
147
+ }
148
+ makePoolReady() {
137
149
  if (preparedDevPool) {
138
- this.pool = preparedDevPool;
150
+ this._pool = preparedDevPool;
139
151
  }
140
152
  else {
141
- this.pool = AbstractCompiler.createPool(this.workerType, {
153
+ this._pool = AbstractCompiler.createPool(this.workerType, {
142
154
  minWorkers: 1,
143
155
  maxWorkers: 1 // dev最多只有一个,不用多个,不然无法复用首次watch初始化的compiler
144
156
  });
145
157
  }
146
- this.pool.emitWorkerMessage = this.emit.bind(this);
158
+ this._pool.emitWorkerMessage = this.emit.bind(this);
147
159
  }
148
160
  reset() {
149
161
  this.pendingPkgs = {};
@@ -196,7 +208,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
196
208
  catch (error) {
197
209
  todoPkgs.forEach(pkg => {
198
210
  var _a, _b;
199
- (_b = (_a = this.pendingPkgs[pkg].reject) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, fn => fn());
211
+ (_b = (_a = this.pendingPkgs[pkg].reject) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, fn => fn(error));
200
212
  delete this.pendingPkgs[pkg];
201
213
  });
202
214
  }
@@ -217,6 +229,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
217
229
  catch (error) {
218
230
  this.watching = false;
219
231
  this.emit('buildError', { errors: [error.message] });
232
+ throw error;
220
233
  }
221
234
  finally {
222
235
  this.pending = false;
@@ -234,6 +247,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
234
247
  }
235
248
  catch (error) {
236
249
  this.emit('buildError', { errors: [error.message] });
250
+ throw error;
237
251
  }
238
252
  finally {
239
253
  this.pending = false;
@@ -266,6 +280,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
266
280
  this.watching = false;
267
281
  this.workerType = (args === null || args === void 0 ? void 0 : args.workerType) || 'web';
268
282
  this.inspectPort = 9230;
283
+ this.makePoolReady(args);
284
+ }
285
+ makePoolReady(args) {
269
286
  if (preparedDevPool) {
270
287
  this.pool = preparedDevPool;
271
288
  }
@@ -301,9 +318,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
301
318
  }
302
319
  catch (error) {
303
320
  this.watching = false;
304
- (_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach(fn => fn());
305
- this.kill();
321
+ (_d = this.pendingTask.reject) === null || _d === void 0 ? void 0 : _d.forEach(fn => fn(error));
306
322
  this.emit('buildError', { errors: [error.message] });
323
+ throw error;
307
324
  }
308
325
  finally {
309
326
  this.pendingTask = undefined;
@@ -323,6 +340,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
323
340
  }
324
341
  catch (error) {
325
342
  this.emit('buildError', { errors: [error.message] });
343
+ throw error;
326
344
  }
327
345
  });
328
346
  }
@@ -334,6 +352,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
334
352
  this.cps = [];
335
353
  this.workerType = (args === null || args === void 0 ? void 0 : args.workerType) || 'process';
336
354
  this.inspectPort = 9228;
355
+ this.makePoolReady(args);
356
+ }
357
+ makePoolReady(args) {
337
358
  this.pool = AbstractCompiler.createPool(this.workerType, {
338
359
  minWorkers: 1
339
360
  }, args);
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const workerpool = require('xhs-mp-workerpool');
12
- sendBuildInfoMessage('load-packer', '开始加载compiler');
12
+ sendBuildInfoMessage('load-packer', '开始加载编译器');
13
13
  const { createPacker } = require('./packs');
14
- sendBuildInfoMessage('load-packer', '加载compiler完成');
14
+ sendBuildInfoMessage('load-packer', '加载编译器完成');
15
15
  let globalConfig = {};
16
16
  let projectPacker;
17
17
  function formatOutputMessages(err, stats) {
@@ -310,7 +310,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
310
310
  result: 'fail',
311
311
  entryType,
312
312
  config: JSON.stringify(config),
313
- reason: error.message
313
+ reason: error === null || error === void 0 ? void 0 : error.message
314
314
  });
315
315
  throw error;
316
316
  }
@@ -351,7 +351,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
351
351
  result: 'fail',
352
352
  entryType,
353
353
  config: JSON.stringify(config),
354
- reason: error.message
354
+ reason: error === null || error === void 0 ? void 0 : error.message
355
355
  });
356
356
  throw error;
357
357
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xhs-mp-compiler-cli",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "xhs mp command tool.",
5
5
  "preferGlobal": true,
6
6
  "category": "esm",
@@ -88,18 +88,18 @@
88
88
  "webpack-chain": "^6.5.1",
89
89
  "webpack-sources": "^3.2.2",
90
90
  "xhs-mp-workerpool": "^9.1.3",
91
- "xhs-mp-ml-loader": "2.0.5",
92
- "xhs-mp-compiler-utils": "2.0.5",
93
- "xhs-mp-pack": "2.0.5",
94
- "xhs-mp-project": "2.0.5",
95
- "xhs-mp-shared": "2.0.5",
96
- "xhs-mp-shared-fs": "2.0.5",
97
- "xhs-mp-sjs-loader": "2.0.5",
98
- "xhs-mp-sketch-loader": "2.0.5",
91
+ "xhs-mp-ml-loader": "2.0.6",
92
+ "xhs-mp-compiler-utils": "2.0.6",
93
+ "xhs-mp-pack": "2.0.6",
94
+ "xhs-mp-project": "2.0.6",
95
+ "xhs-mp-shared": "2.0.6",
96
+ "xhs-mp-shared-fs": "2.0.6",
97
+ "xhs-mp-sjs-loader": "2.0.6",
98
+ "xhs-mp-sketch-loader": "2.0.6",
99
99
  "yauzl": "^2.10.0"
100
100
  },
101
101
  "peerDependencies": {
102
- "xhs-mp-ml-parser": "2.0.5"
102
+ "xhs-mp-ml-parser": "2.0.6"
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.5"
126
+ "xhs-mp-ml-parser": "2.0.6"
127
127
  },
128
128
  "scripts": {
129
129
  "version": "formula changelog && git add .",