@modern-js/babel-compiler 2.15.0 → 2.16.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.
@@ -1,417 +1,431 @@
1
- function _assertThisInitialized(self) {
2
- if (self === void 0) {
3
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
- }
5
- return self;
1
+ function _assert_this_initialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
5
+ return self;
6
6
  }
7
7
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
- try {
9
- var info = gen[key](arg);
10
- var value = info.value;
11
- } catch (error) {
12
- reject(error);
13
- return;
14
- }
15
- if (info.done) {
16
- resolve(value);
17
- } else {
18
- Promise.resolve(value).then(_next, _throw);
19
- }
8
+ try {
9
+ var info = gen[key](arg);
10
+ var value = info.value;
11
+ } catch (error) {
12
+ reject(error);
13
+ return;
14
+ }
15
+ if (info.done) {
16
+ resolve(value);
17
+ } else {
18
+ Promise.resolve(value).then(_next, _throw);
19
+ }
20
20
  }
21
- function _asyncToGenerator(fn) {
22
- return function() {
23
- var self = this, args = arguments;
24
- return new Promise(function(resolve, reject) {
25
- var gen = fn.apply(self, args);
26
- function _next(value) {
27
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
28
- }
29
- function _throw(err) {
30
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
31
- }
32
- _next(undefined);
33
- });
34
- };
21
+ function _async_to_generator(fn) {
22
+ return function() {
23
+ var self = this, args = arguments;
24
+ return new Promise(function(resolve, reject) {
25
+ var gen = fn.apply(self, args);
26
+ function _next(value) {
27
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
28
+ }
29
+ function _throw(err) {
30
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
31
+ }
32
+ _next(void 0);
33
+ });
34
+ };
35
35
  }
36
- function _classCallCheck(instance, Constructor) {
37
- if (!(instance instanceof Constructor)) {
38
- throw new TypeError("Cannot call a class as a function");
39
- }
36
+ function _class_call_check(instance, Constructor) {
37
+ if (!(instance instanceof Constructor)) {
38
+ throw new TypeError("Cannot call a class as a function");
39
+ }
40
40
  }
41
41
  function _defineProperties(target, props) {
42
- for(var i = 0; i < props.length; i++){
43
- var descriptor = props[i];
44
- descriptor.enumerable = descriptor.enumerable || false;
45
- descriptor.configurable = true;
46
- if ("value" in descriptor) descriptor.writable = true;
47
- Object.defineProperty(target, descriptor.key, descriptor);
48
- }
42
+ for (var i = 0; i < props.length; i++) {
43
+ var descriptor = props[i];
44
+ descriptor.enumerable = descriptor.enumerable || false;
45
+ descriptor.configurable = true;
46
+ if ("value" in descriptor)
47
+ descriptor.writable = true;
48
+ Object.defineProperty(target, descriptor.key, descriptor);
49
+ }
49
50
  }
50
- function _createClass(Constructor, protoProps, staticProps) {
51
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
52
- if (staticProps) _defineProperties(Constructor, staticProps);
53
- return Constructor;
51
+ function _create_class(Constructor, protoProps, staticProps) {
52
+ if (protoProps)
53
+ _defineProperties(Constructor.prototype, protoProps);
54
+ if (staticProps)
55
+ _defineProperties(Constructor, staticProps);
56
+ return Constructor;
54
57
  }
55
- function _defineProperty(obj, key, value) {
56
- if (key in obj) {
57
- Object.defineProperty(obj, key, {
58
- value: value,
59
- enumerable: true,
60
- configurable: true,
61
- writable: true
62
- });
63
- } else {
64
- obj[key] = value;
65
- }
66
- return obj;
58
+ function _define_property(obj, key, value) {
59
+ if (key in obj) {
60
+ Object.defineProperty(obj, key, {
61
+ value,
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true
65
+ });
66
+ } else {
67
+ obj[key] = value;
68
+ }
69
+ return obj;
67
70
  }
68
- function _getPrototypeOf(o) {
69
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
70
- return o.__proto__ || Object.getPrototypeOf(o);
71
- };
72
- return _getPrototypeOf(o);
71
+ function _get_prototype_of(o) {
72
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
73
+ return o2.__proto__ || Object.getPrototypeOf(o2);
74
+ };
75
+ return _get_prototype_of(o);
73
76
  }
74
77
  function _inherits(subClass, superClass) {
75
- if (typeof superClass !== "function" && superClass !== null) {
76
- throw new TypeError("Super expression must either be null or a function");
78
+ if (typeof superClass !== "function" && superClass !== null) {
79
+ throw new TypeError("Super expression must either be null or a function");
80
+ }
81
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
82
+ constructor: {
83
+ value: subClass,
84
+ writable: true,
85
+ configurable: true
77
86
  }
78
- subClass.prototype = Object.create(superClass && superClass.prototype, {
79
- constructor: {
80
- value: subClass,
81
- writable: true,
82
- configurable: true
83
- }
84
- });
85
- if (superClass) _setPrototypeOf(subClass, superClass);
87
+ });
88
+ if (superClass)
89
+ _set_prototype_of(subClass, superClass);
86
90
  }
87
- function _objectSpread(target) {
88
- for(var i = 1; i < arguments.length; i++){
89
- var source = arguments[i] != null ? arguments[i] : {};
90
- var ownKeys = Object.keys(source);
91
- if (typeof Object.getOwnPropertySymbols === "function") {
92
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
93
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
94
- }));
95
- }
96
- ownKeys.forEach(function(key) {
97
- _defineProperty(target, key, source[key]);
98
- });
91
+ function _object_spread(target) {
92
+ for (var i = 1; i < arguments.length; i++) {
93
+ var source = arguments[i] != null ? arguments[i] : {};
94
+ var ownKeys2 = Object.keys(source);
95
+ if (typeof Object.getOwnPropertySymbols === "function") {
96
+ ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
97
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
98
+ }));
99
99
  }
100
- return target;
100
+ ownKeys2.forEach(function(key) {
101
+ _define_property(target, key, source[key]);
102
+ });
103
+ }
104
+ return target;
101
105
  }
102
106
  function ownKeys(object, enumerableOnly) {
103
- var keys = Object.keys(object);
104
- if (Object.getOwnPropertySymbols) {
105
- var symbols = Object.getOwnPropertySymbols(object);
106
- if (enumerableOnly) {
107
- symbols = symbols.filter(function(sym) {
108
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
109
- });
110
- }
111
- keys.push.apply(keys, symbols);
107
+ var keys = Object.keys(object);
108
+ if (Object.getOwnPropertySymbols) {
109
+ var symbols = Object.getOwnPropertySymbols(object);
110
+ if (enumerableOnly) {
111
+ symbols = symbols.filter(function(sym) {
112
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
113
+ });
112
114
  }
113
- return keys;
115
+ keys.push.apply(keys, symbols);
116
+ }
117
+ return keys;
114
118
  }
115
- function _objectSpreadProps(target, source) {
116
- source = source != null ? source : {};
117
- if (Object.getOwnPropertyDescriptors) {
118
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
119
- } else {
120
- ownKeys(Object(source)).forEach(function(key) {
121
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
122
- });
123
- }
124
- return target;
119
+ function _object_spread_props(target, source) {
120
+ source = source != null ? source : {};
121
+ if (Object.getOwnPropertyDescriptors) {
122
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
123
+ } else {
124
+ ownKeys(Object(source)).forEach(function(key) {
125
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
126
+ });
127
+ }
128
+ return target;
125
129
  }
126
- function _possibleConstructorReturn(self, call) {
127
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
128
- return call;
129
- }
130
- return _assertThisInitialized(self);
130
+ function _possible_constructor_return(self, call) {
131
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
132
+ return call;
133
+ }
134
+ return _assert_this_initialized(self);
131
135
  }
132
- function _setPrototypeOf(o, p) {
133
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
134
- o.__proto__ = p;
135
- return o;
136
- };
137
- return _setPrototypeOf(o, p);
136
+ function _set_prototype_of(o, p) {
137
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
138
+ o2.__proto__ = p2;
139
+ return o2;
140
+ };
141
+ return _set_prototype_of(o, p);
138
142
  }
139
- var _typeof = function(obj) {
140
- "@swc/helpers - typeof";
141
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
142
- };
143
- function _isNativeReflectConstruct() {
144
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
145
- if (Reflect.construct.sham) return false;
146
- if (typeof Proxy === "function") return true;
147
- try {
148
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
149
- return true;
150
- } catch (e) {
151
- return false;
152
- }
143
+ function _type_of(obj) {
144
+ "@swc/helpers - typeof";
145
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
153
146
  }
154
- function _createSuper(Derived) {
155
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
156
- return function _createSuperInternal() {
157
- var Super = _getPrototypeOf(Derived), result;
158
- if (hasNativeReflectConstruct) {
159
- var NewTarget = _getPrototypeOf(this).constructor;
160
- result = Reflect.construct(Super, arguments, NewTarget);
161
- } else {
162
- result = Super.apply(this, arguments);
163
- }
164
- return _possibleConstructorReturn(this, result);
165
- };
147
+ function _is_native_reflect_construct() {
148
+ if (typeof Reflect === "undefined" || !Reflect.construct)
149
+ return false;
150
+ if (Reflect.construct.sham)
151
+ return false;
152
+ if (typeof Proxy === "function")
153
+ return true;
154
+ try {
155
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
156
+ }));
157
+ return true;
158
+ } catch (e) {
159
+ return false;
160
+ }
166
161
  }
167
- var __generator = this && this.__generator || function(thisArg, body) {
168
- var f, y, t, g, _ = {
169
- label: 0,
170
- sent: function() {
171
- if (t[0] & 1) throw t[1];
172
- return t[1];
173
- },
174
- trys: [],
175
- ops: []
176
- };
177
- return(g = {
178
- next: verb(0),
179
- "throw": verb(1),
180
- "return": verb(2)
181
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
182
- return this;
183
- }), g);
184
- function verb(n) {
185
- return function(v) {
186
- return step([
187
- n,
188
- v
189
- ]);
190
- };
162
+ function _create_super(Derived) {
163
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
164
+ return function _createSuperInternal() {
165
+ var Super = _get_prototype_of(Derived), result;
166
+ if (hasNativeReflectConstruct) {
167
+ var NewTarget = _get_prototype_of(this).constructor;
168
+ result = Reflect.construct(Super, arguments, NewTarget);
169
+ } else {
170
+ result = Super.apply(this, arguments);
191
171
  }
192
- function step(op) {
193
- if (f) throw new TypeError("Generator is already executing.");
194
- while(_)try {
195
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
196
- if (y = 0, t) op = [
197
- op[0] & 2,
198
- t.value
199
- ];
200
- switch(op[0]){
201
- case 0:
202
- case 1:
203
- t = op;
204
- break;
205
- case 4:
206
- _.label++;
207
- return {
208
- value: op[1],
209
- done: false
210
- };
211
- case 5:
212
- _.label++;
213
- y = op[1];
214
- op = [
215
- 0
216
- ];
217
- continue;
218
- case 7:
219
- op = _.ops.pop();
220
- _.trys.pop();
221
- continue;
222
- default:
223
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
224
- _ = 0;
225
- continue;
226
- }
227
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
228
- _.label = op[1];
229
- break;
230
- }
231
- if (op[0] === 6 && _.label < t[1]) {
232
- _.label = t[1];
233
- t = op;
234
- break;
235
- }
236
- if (t && _.label < t[2]) {
237
- _.label = t[2];
238
- _.ops.push(op);
239
- break;
240
- }
241
- if (t[2]) _.ops.pop();
242
- _.trys.pop();
243
- continue;
244
- }
245
- op = body.call(thisArg, _);
246
- } catch (e) {
172
+ return _possible_constructor_return(this, result);
173
+ };
174
+ }
175
+ var __generator = function(thisArg, body) {
176
+ var f, y, t, g, _ = {
177
+ label: 0,
178
+ sent: function() {
179
+ if (t[0] & 1)
180
+ throw t[1];
181
+ return t[1];
182
+ },
183
+ trys: [],
184
+ ops: []
185
+ };
186
+ return g = {
187
+ next: verb(0),
188
+ "throw": verb(1),
189
+ "return": verb(2)
190
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
191
+ return this;
192
+ }), g;
193
+ function verb(n) {
194
+ return function(v) {
195
+ return step([
196
+ n,
197
+ v
198
+ ]);
199
+ };
200
+ }
201
+ function step(op) {
202
+ if (f)
203
+ throw new TypeError("Generator is already executing.");
204
+ while (_)
205
+ try {
206
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
207
+ return t;
208
+ if (y = 0, t)
209
+ op = [
210
+ op[0] & 2,
211
+ t.value
212
+ ];
213
+ switch (op[0]) {
214
+ case 0:
215
+ case 1:
216
+ t = op;
217
+ break;
218
+ case 4:
219
+ _.label++;
220
+ return {
221
+ value: op[1],
222
+ done: false
223
+ };
224
+ case 5:
225
+ _.label++;
226
+ y = op[1];
247
227
  op = [
248
- 6,
249
- e
228
+ 0
250
229
  ];
251
- y = 0;
252
- } finally{
253
- f = t = 0;
230
+ continue;
231
+ case 7:
232
+ op = _.ops.pop();
233
+ _.trys.pop();
234
+ continue;
235
+ default:
236
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
237
+ _ = 0;
238
+ continue;
239
+ }
240
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
241
+ _.label = op[1];
242
+ break;
243
+ }
244
+ if (op[0] === 6 && _.label < t[1]) {
245
+ _.label = t[1];
246
+ t = op;
247
+ break;
248
+ }
249
+ if (t && _.label < t[2]) {
250
+ _.label = t[2];
251
+ _.ops.push(op);
252
+ break;
253
+ }
254
+ if (t[2])
255
+ _.ops.pop();
256
+ _.trys.pop();
257
+ continue;
254
258
  }
255
- if (op[0] & 5) throw op[1];
256
- return {
257
- value: op[0] ? op[1] : void 0,
258
- done: true
259
- };
260
- }
259
+ op = body.call(thisArg, _);
260
+ } catch (e) {
261
+ op = [
262
+ 6,
263
+ e
264
+ ];
265
+ y = 0;
266
+ } finally {
267
+ f = t = 0;
268
+ }
269
+ if (op[0] & 5)
270
+ throw op[1];
271
+ return {
272
+ value: op[0] ? op[1] : void 0,
273
+ done: true
274
+ };
275
+ }
261
276
  };
262
277
  import * as path from "path";
263
278
  import * as Event from "events";
264
279
  import { logger, watch, WatchChangeType } from "@modern-js/utils";
265
280
  import { build } from "./build";
266
281
  import { CompilerErrorResult } from "./compilerErrorResult";
267
- var BuildWatchEvent = {
268
- firstCompiler: "first-compiler",
269
- compiling: "compiling",
270
- watchingCompiler: "watching-compiler"
282
+ export var BuildWatchEvent = {
283
+ firstCompiler: "first-compiler",
284
+ compiling: "compiling",
285
+ watchingCompiler: "watching-compiler"
271
286
  };
272
- var BuildWatchEmitter = /*#__PURE__*/ function(_Event_EventEmitter) {
273
- "use strict";
274
- _inherits(BuildWatchEmitter, _Event_EventEmitter);
275
- var _super = _createSuper(BuildWatchEmitter);
276
- function BuildWatchEmitter() {
277
- _classCallCheck(this, BuildWatchEmitter);
278
- var _this;
279
- _this = _super.apply(this, arguments);
280
- _defineProperty(_assertThisInitialized(_this), "_initFn", void 0);
281
- return _this;
282
- }
283
- _createClass(BuildWatchEmitter, [
284
- {
285
- key: "setInitFn",
286
- value: function setInitFn(fn) {
287
- this._initFn = fn;
287
+ export var BuildWatchEmitter = /* @__PURE__ */ function(_Event_EventEmitter) {
288
+ "use strict";
289
+ _inherits(BuildWatchEmitter2, _Event_EventEmitter);
290
+ var _super = _create_super(BuildWatchEmitter2);
291
+ function BuildWatchEmitter2() {
292
+ _class_call_check(this, BuildWatchEmitter2);
293
+ var _this;
294
+ _this = _super.apply(this, arguments);
295
+ _define_property(_assert_this_initialized(_this), "_initFn", void 0);
296
+ return _this;
297
+ }
298
+ _create_class(BuildWatchEmitter2, [
299
+ {
300
+ key: "setInitFn",
301
+ value: function setInitFn(fn) {
302
+ this._initFn = fn;
303
+ }
304
+ },
305
+ {
306
+ key: "watch",
307
+ value: function watch2() {
308
+ var _this = this;
309
+ return _async_to_generator(function() {
310
+ return __generator(this, function(_state) {
311
+ if (typeof _this._initFn === "function") {
312
+ return [
313
+ 2,
314
+ _this._initFn(_this)
315
+ ];
288
316
  }
289
- },
290
- {
291
- key: "watch",
292
- value: function watch() {
293
- var _this = this;
294
- return _asyncToGenerator(function() {
295
- return __generator(this, function(_state) {
296
- if (typeof _this._initFn === "function") {
297
- return [
298
- 2,
299
- _this._initFn(_this)
300
- ];
317
+ return [
318
+ 2,
319
+ null
320
+ ];
321
+ });
322
+ })();
323
+ }
324
+ }
325
+ ]);
326
+ return BuildWatchEmitter2;
327
+ }(Event.EventEmitter);
328
+ export var runBuildWatch = function() {
329
+ var _ref = _async_to_generator(function(option) {
330
+ var babelConfig, emitter, errorResult, watchDir, distDir, quiet, firstBuildResult, code;
331
+ var _arguments = arguments;
332
+ return __generator(this, function(_state) {
333
+ switch (_state.label) {
334
+ case 0:
335
+ babelConfig = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, emitter = _arguments.length > 2 ? _arguments[2] : void 0;
336
+ emitter.emit(BuildWatchEvent.compiling);
337
+ errorResult = new CompilerErrorResult();
338
+ watchDir = option.watchDir;
339
+ distDir = option.distDir, quiet = option.quiet;
340
+ return [
341
+ 4,
342
+ build(option, babelConfig)
343
+ ];
344
+ case 1:
345
+ firstBuildResult = _state.sent();
346
+ code = firstBuildResult.code;
347
+ if (code === 1) {
348
+ errorResult.init(firstBuildResult);
349
+ emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
350
+ } else {
351
+ emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
352
+ }
353
+ return [
354
+ 2,
355
+ watch("".concat(watchDir, "/**/*.{js,jsx,ts,tsx}"), function() {
356
+ var _ref2 = _async_to_generator(function(param) {
357
+ var changeType, changedFilePath, removeFiles, result, result1;
358
+ return __generator(this, function(_state2) {
359
+ switch (_state2.label) {
360
+ case 0:
361
+ changeType = param.changeType, changedFilePath = param.changedFilePath;
362
+ emitter.emit(BuildWatchEvent.compiling);
363
+ if (changeType === WatchChangeType.UNLINK) {
364
+ removeFiles = [
365
+ path.normalize("./".concat(distDir, "/").concat(path.relative(watchDir, changedFilePath)))
366
+ ];
367
+ if (!quiet) {
368
+ logger.info("remove file: ".concat(removeFiles.join(",")));
301
369
  }
370
+ result = {
371
+ code: 0,
372
+ message: "remove file: ".concat(removeFiles.join(",")),
373
+ removeFiles
374
+ };
375
+ emitter.emit(BuildWatchEvent.watchingCompiler, result);
302
376
  return [
303
- 2,
304
- null
377
+ 2
305
378
  ];
306
- });
307
- })();
308
- }
309
- }
310
- ]);
311
- return BuildWatchEmitter;
312
- }(Event.EventEmitter);
313
- var runBuildWatch = function() {
314
- var _ref = _asyncToGenerator(function(option) {
315
- var babelConfig, emitter, errorResult, watchDir, distDir, quiet, firstBuildResult, code;
316
- var _arguments = arguments;
317
- return __generator(this, function(_state) {
318
- switch(_state.label){
319
- case 0:
320
- babelConfig = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, emitter = _arguments.length > 2 ? _arguments[2] : void 0;
321
- emitter.emit(BuildWatchEvent.compiling);
322
- errorResult = new CompilerErrorResult();
323
- watchDir = option.watchDir;
324
- distDir = option.distDir, quiet = option.quiet;
325
- return [
379
+ }
380
+ return [
326
381
  4,
327
- build(option, babelConfig)
328
- ];
329
- case 1:
330
- firstBuildResult = _state.sent();
331
- code = firstBuildResult.code;
332
- if (code === 1) {
333
- errorResult.init(firstBuildResult);
334
- emitter.emit(BuildWatchEvent.firstCompiler, errorResult.value);
335
- } else {
336
- emitter.emit(BuildWatchEvent.firstCompiler, firstBuildResult);
337
- }
338
- return [
339
- 2,
340
- watch("".concat(watchDir, "/**/*.{js,jsx,ts,tsx}"), function() {
341
- var _ref = _asyncToGenerator(function(param) {
342
- var changeType, changedFilePath, removeFiles, result2, result;
343
- return __generator(this, function(_state) {
344
- switch(_state.label){
345
- case 0:
346
- changeType = param.changeType, changedFilePath = param.changedFilePath;
347
- emitter.emit(BuildWatchEvent.compiling);
348
- if (changeType === WatchChangeType.UNLINK) {
349
- removeFiles = [
350
- path.normalize("./".concat(distDir, "/").concat(path.relative(watchDir, changedFilePath)))
351
- ];
352
- if (!quiet) {
353
- logger.info("remove file: ".concat(removeFiles.join(",")));
354
- }
355
- result2 = {
356
- code: 0,
357
- message: "remove file: ".concat(removeFiles.join(",")),
358
- removeFiles: removeFiles
359
- };
360
- emitter.emit(BuildWatchEvent.watchingCompiler, result2);
361
- return [
362
- 2
363
- ];
364
- }
365
- return [
366
- 4,
367
- build(_objectSpreadProps(_objectSpread({}, option), {
368
- filenames: [
369
- changedFilePath
370
- ]
371
- }), babelConfig)
372
- ];
373
- case 1:
374
- result = _state.sent();
375
- if (result.code === 1) {
376
- errorResult.update(result.messageDetails || []);
377
- emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
378
- !quiet && logger.info(errorResult.value.message);
379
- } else {
380
- errorResult.removeByFileName(changedFilePath);
381
- if (errorResult.checkExistError()) {
382
- emitter.emit(BuildWatchEvent.watchingCompiler, _objectSpreadProps(_objectSpread({}, errorResult.value), {
383
- virtualDists: result.virtualDists
384
- }));
385
- !quiet && logger.info(errorResult.value.message);
386
- } else {
387
- emitter.emit(BuildWatchEvent.watchingCompiler, result);
388
- !quiet && logger.info(result.message);
389
- }
390
- }
391
- return [
392
- 2
393
- ];
394
- }
395
- });
396
- });
397
- return function(_) {
398
- return _ref.apply(this, arguments);
399
- };
400
- }(), [
401
- "".concat(watchDir, "/**/*.d.ts")
402
- ])
403
- ];
404
- }
405
- });
382
+ build(_object_spread_props(_object_spread({}, option), {
383
+ filenames: [
384
+ changedFilePath
385
+ ]
386
+ }), babelConfig)
387
+ ];
388
+ case 1:
389
+ result1 = _state2.sent();
390
+ if (result1.code === 1) {
391
+ errorResult.update(result1.messageDetails || []);
392
+ emitter.emit(BuildWatchEvent.watchingCompiler, errorResult.value);
393
+ !quiet && logger.info(errorResult.value.message);
394
+ } else {
395
+ errorResult.removeByFileName(changedFilePath);
396
+ if (errorResult.checkExistError()) {
397
+ emitter.emit(BuildWatchEvent.watchingCompiler, _object_spread_props(_object_spread({}, errorResult.value), {
398
+ virtualDists: result1.virtualDists
399
+ }));
400
+ !quiet && logger.info(errorResult.value.message);
401
+ } else {
402
+ emitter.emit(BuildWatchEvent.watchingCompiler, result1);
403
+ !quiet && logger.info(result1.message);
404
+ }
405
+ }
406
+ return [
407
+ 2
408
+ ];
409
+ }
410
+ });
411
+ });
412
+ return function(_) {
413
+ return _ref2.apply(this, arguments);
414
+ };
415
+ }(), [
416
+ "".concat(watchDir, "/**/*.d.ts")
417
+ ])
418
+ ];
419
+ }
406
420
  });
407
- return function runBuildWatch(option) {
408
- return _ref.apply(this, arguments);
409
- };
421
+ });
422
+ return function runBuildWatch2(option) {
423
+ return _ref.apply(this, arguments);
424
+ };
410
425
  }();
411
- var buildWatch = function(option) {
412
- var babelConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
413
- var buildWatchEmitter = new BuildWatchEmitter();
414
- buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
415
- return buildWatchEmitter;
426
+ export var buildWatch = function(option) {
427
+ var babelConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
428
+ var buildWatchEmitter = new BuildWatchEmitter();
429
+ buildWatchEmitter.setInitFn(runBuildWatch.bind(null, option, babelConfig));
430
+ return buildWatchEmitter;
416
431
  };
417
- export { BuildWatchEmitter, BuildWatchEvent, buildWatch, runBuildWatch };