@doracli/rollup 0.0.1 → 0.0.2

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/lib/cjs/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var rollup = require('rollup');
3
4
  var lang = require('@cclr/lang');
4
- var filePro = require('@dorabag/file-pro');
5
5
  var helper = require('@doracli/helper');
6
+ var filePro = require('@dorabag/file-pro');
6
7
  var path = require('path');
7
8
  var alias = require('@rollup/plugin-alias');
8
9
  var babel = require('@rollup/plugin-babel');
@@ -18,7 +19,6 @@ var promises = require('fs/promises');
18
19
  var postcss = require('rollup-plugin-postcss');
19
20
  var resolve = require('@rollup/plugin-node-resolve');
20
21
  var presetBabel = require('@doracli/preset-babel');
21
- var rollup = require('rollup');
22
22
 
23
23
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
24
24
  function _arrayLikeToArray(r, a) {
@@ -26,9 +26,16 @@ function _arrayLikeToArray(r, a) {
26
26
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
27
27
  return n;
28
28
  }
29
+ function _arrayWithHoles(r) {
30
+ if (Array.isArray(r)) return r;
31
+ }
29
32
  function _arrayWithoutHoles(r) {
30
33
  if (Array.isArray(r)) return _arrayLikeToArray(r);
31
34
  }
35
+ function _assertThisInitialized(e) {
36
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
37
+ return e;
38
+ }
32
39
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
33
40
  try {
34
41
  var i = n[a](c),
@@ -54,6 +61,9 @@ function _asyncToGenerator(n) {
54
61
  });
55
62
  };
56
63
  }
64
+ function _callSuper(t, o, e) {
65
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
66
+ }
57
67
  function _classCallCheck(a, n) {
58
68
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
59
69
  }
@@ -76,9 +86,61 @@ function _defineProperty(e, r, t) {
76
86
  writable: true
77
87
  }) : e[r] = t, e;
78
88
  }
89
+ function _getPrototypeOf(t) {
90
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
91
+ return t.__proto__ || Object.getPrototypeOf(t);
92
+ }, _getPrototypeOf(t);
93
+ }
94
+ function _inherits(t, e) {
95
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
96
+ t.prototype = Object.create(e && e.prototype, {
97
+ constructor: {
98
+ value: t,
99
+ writable: true,
100
+ configurable: true
101
+ }
102
+ }), Object.defineProperty(t, "prototype", {
103
+ writable: false
104
+ }), e && _setPrototypeOf(t, e);
105
+ }
106
+ function _isNativeReflectConstruct() {
107
+ try {
108
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
109
+ } catch (t) {}
110
+ return (_isNativeReflectConstruct = function () {
111
+ return !!t;
112
+ })();
113
+ }
79
114
  function _iterableToArray(r) {
80
115
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
81
116
  }
117
+ function _iterableToArrayLimit(r, l) {
118
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
119
+ if (null != t) {
120
+ var e,
121
+ n,
122
+ i,
123
+ u,
124
+ a = [],
125
+ f = true,
126
+ o = false;
127
+ try {
128
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
129
+ } catch (r) {
130
+ o = true, n = r;
131
+ } finally {
132
+ try {
133
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
134
+ } finally {
135
+ if (o) throw n;
136
+ }
137
+ }
138
+ return a;
139
+ }
140
+ }
141
+ function _nonIterableRest() {
142
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
143
+ }
82
144
  function _nonIterableSpread() {
83
145
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
84
146
  }
@@ -123,6 +185,11 @@ function _objectWithoutPropertiesLoose(r, e) {
123
185
  }
124
186
  return t;
125
187
  }
188
+ function _possibleConstructorReturn(t, e) {
189
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
190
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
191
+ return _assertThisInitialized(t);
192
+ }
126
193
  function _regenerator() {
127
194
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
128
195
  var e,
@@ -231,6 +298,14 @@ function _regeneratorDefine(e, r, n, t) {
231
298
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
232
299
  }, _regeneratorDefine(e, r, n, t);
233
300
  }
301
+ function _setPrototypeOf(t, e) {
302
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
303
+ return t.__proto__ = e, t;
304
+ }, _setPrototypeOf(t, e);
305
+ }
306
+ function _slicedToArray(r, e) {
307
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
308
+ }
234
309
  function _toConsumableArray(r) {
235
310
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
236
311
  }
@@ -256,6 +331,223 @@ function _unsupportedIterableToArray(r, a) {
256
331
  }
257
332
  }
258
333
 
334
+ var mergeRollupOptions = function mergeRollupOptions(first, second) {
335
+ if (!first) return second;
336
+ if (!second) return first;
337
+ return _objectSpread2(_objectSpread2({}, first), second);
338
+ };
339
+
340
+ var Compiler = /*#__PURE__*/function (_CompilerBase) {
341
+ function Compiler() {
342
+ var _this;
343
+ _classCallCheck(this, Compiler);
344
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
345
+ args[_key] = arguments[_key];
346
+ }
347
+ _this = _callSuper(this, Compiler, [].concat(args));
348
+ _defineProperty(_this, "context", /*#__PURE__*/function () {
349
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
350
+ var rollupBuild, outputList;
351
+ return _regenerator().w(function (_context3) {
352
+ while (1) switch (_context3.n) {
353
+ case 0:
354
+ _context3.n = 1;
355
+ return rollup.rollup(mergeRollupOptions(_this.initOptions, options));
356
+ case 1:
357
+ rollupBuild = _context3.v;
358
+ outputList = [];
359
+ if (options.output) {
360
+ outputList = lang.isArray(options.output) ? options.output : [options.output];
361
+ }
362
+ return _context3.a(2, Promise.resolve({
363
+ rebuild: function () {
364
+ var _rebuild = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
365
+ var outputOptions, i, output, writeRes;
366
+ return _regenerator().w(function (_context) {
367
+ while (1) switch (_context.n) {
368
+ case 0:
369
+ outputOptions = [];
370
+ i = 0;
371
+ case 1:
372
+ if (!(i < outputList.length)) {
373
+ _context.n = 4;
374
+ break;
375
+ }
376
+ output = outputList[i];
377
+ _context.n = 2;
378
+ return rollupBuild.write(output);
379
+ case 2:
380
+ writeRes = _context.v;
381
+ outputOptions.push(writeRes);
382
+ case 3:
383
+ i++;
384
+ _context.n = 1;
385
+ break;
386
+ case 4:
387
+ return _context.a(2, Promise.resolve({
388
+ rollupBuild: rollupBuild,
389
+ outputOptions: outputOptions
390
+ }));
391
+ }
392
+ }, _callee);
393
+ }));
394
+ function rebuild() {
395
+ return _rebuild.apply(this, arguments);
396
+ }
397
+ return rebuild;
398
+ }(),
399
+ cancel: function () {
400
+ var _cancel = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
401
+ return _regenerator().w(function (_context2) {
402
+ while (1) switch (_context2.n) {
403
+ case 0:
404
+ helper.cLog.warn('build', 'empty', 'Rollup does not need to be canceled.');
405
+ case 1:
406
+ return _context2.a(2);
407
+ }
408
+ }, _callee2);
409
+ }));
410
+ function cancel() {
411
+ return _cancel.apply(this, arguments);
412
+ }
413
+ return cancel;
414
+ }()
415
+ }));
416
+ }
417
+ }, _callee3);
418
+ }));
419
+ return function (_x) {
420
+ return _ref.apply(this, arguments);
421
+ };
422
+ }());
423
+ _defineProperty(_this, "inOutMap", /*#__PURE__*/function () {
424
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(inputOutputMap) {
425
+ var input;
426
+ return _regenerator().w(function (_context4) {
427
+ while (1) switch (_context4.n) {
428
+ case 0:
429
+ input = {};
430
+ Object.entries(inputOutputMap).forEach(function (_ref3) {
431
+ var _ref4 = _slicedToArray(_ref3, 2),
432
+ input = _ref4[0],
433
+ output = _ref4[1];
434
+ input[output] = input;
435
+ });
436
+ return _context4.a(2, _this.build({
437
+ input: input
438
+ }));
439
+ }
440
+ }, _callee4);
441
+ }));
442
+ return function (_x2) {
443
+ return _ref2.apply(this, arguments);
444
+ };
445
+ }());
446
+ _defineProperty(_this, "input", /*#__PURE__*/function () {
447
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(input) {
448
+ var rollupBuild;
449
+ return _regenerator().w(function (_context6) {
450
+ while (1) switch (_context6.n) {
451
+ case 0:
452
+ _context6.n = 1;
453
+ return rollup.rollup(mergeRollupOptions(_this.initOptions, {
454
+ input: input
455
+ }));
456
+ case 1:
457
+ rollupBuild = _context6.v;
458
+ return _context6.a(2, {
459
+ output: function () {
460
+ var _output2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_output) {
461
+ var writeRes;
462
+ return _regenerator().w(function (_context5) {
463
+ while (1) switch (_context5.n) {
464
+ case 0:
465
+ _context5.n = 1;
466
+ return rollupBuild.write(_output);
467
+ case 1:
468
+ writeRes = _context5.v;
469
+ return _context5.a(2, {
470
+ rollupBuild: rollupBuild,
471
+ outputOptions: [writeRes]
472
+ });
473
+ }
474
+ }, _callee5);
475
+ }));
476
+ function output(_x4) {
477
+ return _output2.apply(this, arguments);
478
+ }
479
+ return output;
480
+ }()
481
+ });
482
+ }
483
+ }, _callee6);
484
+ }));
485
+ return function (_x3) {
486
+ return _ref5.apply(this, arguments);
487
+ };
488
+ }());
489
+ _defineProperty(_this, "build", /*#__PURE__*/function () {
490
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(options) {
491
+ var rollupBuild, outputList, outputOptions, i, output, writeRes;
492
+ return _regenerator().w(function (_context7) {
493
+ while (1) switch (_context7.n) {
494
+ case 0:
495
+ _context7.n = 1;
496
+ return rollup.rollup(mergeRollupOptions(_this.initOptions, options));
497
+ case 1:
498
+ rollupBuild = _context7.v;
499
+ outputList = [];
500
+ if (options.output) {
501
+ outputList = lang.isArray(options.output) ? options.output : [options.output];
502
+ }
503
+ outputOptions = [];
504
+ i = 0;
505
+ case 2:
506
+ if (!(i < outputList.length)) {
507
+ _context7.n = 5;
508
+ break;
509
+ }
510
+ output = outputList[i];
511
+ _context7.n = 3;
512
+ return rollupBuild.write(output);
513
+ case 3:
514
+ writeRes = _context7.v;
515
+ outputOptions.push(writeRes);
516
+ case 4:
517
+ i++;
518
+ _context7.n = 2;
519
+ break;
520
+ case 5:
521
+ return _context7.a(2, {
522
+ rollupBuild: rollupBuild,
523
+ outputOptions: outputOptions
524
+ });
525
+ }
526
+ }, _callee7);
527
+ }));
528
+ return function (_x5) {
529
+ return _ref6.apply(this, arguments);
530
+ };
531
+ }());
532
+ _defineProperty(_this, "watch", function (options) {
533
+ var watchOptions = mergeRollupOptions(_this.initOptions, options);
534
+ return rollup.watch(watchOptions);
535
+ });
536
+ _defineProperty(_this, "server", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
537
+ return _regenerator().w(function (_context8) {
538
+ while (1) switch (_context8.n) {
539
+ case 0:
540
+ helper.cLog.warn('serve', 'empty', 'Rollup does not support serve functionality.');
541
+ return _context8.a(2);
542
+ }
543
+ }, _callee8);
544
+ })));
545
+ return _this;
546
+ }
547
+ _inherits(Compiler, _CompilerBase);
548
+ return _createClass(Compiler);
549
+ }(helper.CompilerBase);
550
+
259
551
  /**
260
552
  * 获取external配置
261
553
  * @param envParams 环境参数
@@ -909,6 +1201,7 @@ var rollupWatch = function rollupWatch(config) {
909
1201
  return rollup.watch(config);
910
1202
  };
911
1203
 
1204
+ exports.Compiler = Compiler;
912
1205
  exports.Ctx = Ctx;
913
1206
  exports.createRollupBuild = createRollupBuild;
914
1207
  exports.dealDts = dealDts;
@@ -930,5 +1223,6 @@ exports.getResolvePlugin = getResolvePlugin;
930
1223
  exports.getRollupWrite = getRollupWrite;
931
1224
  exports.getWatch = getWatch;
932
1225
  exports.handleError = handleError;
1226
+ exports.mergeRollupOptions = mergeRollupOptions;
933
1227
  exports.rollupWatch = rollupWatch;
934
1228
  exports.rollupWatchLog = rollupWatchLog;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { rollup, watch } from 'rollup';
1
2
  import { isArray, isString, isObject } from '@cclr/lang';
3
+ import { CompilerBase, cLog, findInput, getTsPathAlias, picocolors } from '@doracli/helper';
2
4
  import { isValidDir, getNodeModulesDir, getDirname, getCwd, isValidFilePathSync, mkdirRecursive, getFilename } from '@dorabag/file-pro';
3
- import { findInput, cLog, getTsPathAlias, picocolors } from '@doracli/helper';
4
5
  import { join, isAbsolute, resolve, relative, dirname } from 'path';
5
6
  import alias from '@rollup/plugin-alias';
6
7
  import babel from '@rollup/plugin-babel';
@@ -16,16 +17,22 @@ import { writeFile } from 'fs/promises';
16
17
  import postcss from 'rollup-plugin-postcss';
17
18
  import resolve$1 from '@rollup/plugin-node-resolve';
18
19
  import { nodeBabelPreset, reactBabelPreset } from '@doracli/preset-babel';
19
- import { rollup, watch } from 'rollup';
20
20
 
21
21
  function _arrayLikeToArray(r, a) {
22
22
  (null == a || a > r.length) && (a = r.length);
23
23
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
24
24
  return n;
25
25
  }
26
+ function _arrayWithHoles(r) {
27
+ if (Array.isArray(r)) return r;
28
+ }
26
29
  function _arrayWithoutHoles(r) {
27
30
  if (Array.isArray(r)) return _arrayLikeToArray(r);
28
31
  }
32
+ function _assertThisInitialized(e) {
33
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
34
+ return e;
35
+ }
29
36
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
30
37
  try {
31
38
  var i = n[a](c),
@@ -51,6 +58,9 @@ function _asyncToGenerator(n) {
51
58
  });
52
59
  };
53
60
  }
61
+ function _callSuper(t, o, e) {
62
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
63
+ }
54
64
  function _classCallCheck(a, n) {
55
65
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
56
66
  }
@@ -73,9 +83,61 @@ function _defineProperty(e, r, t) {
73
83
  writable: true
74
84
  }) : e[r] = t, e;
75
85
  }
86
+ function _getPrototypeOf(t) {
87
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
88
+ return t.__proto__ || Object.getPrototypeOf(t);
89
+ }, _getPrototypeOf(t);
90
+ }
91
+ function _inherits(t, e) {
92
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
93
+ t.prototype = Object.create(e && e.prototype, {
94
+ constructor: {
95
+ value: t,
96
+ writable: true,
97
+ configurable: true
98
+ }
99
+ }), Object.defineProperty(t, "prototype", {
100
+ writable: false
101
+ }), e && _setPrototypeOf(t, e);
102
+ }
103
+ function _isNativeReflectConstruct() {
104
+ try {
105
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
106
+ } catch (t) {}
107
+ return (_isNativeReflectConstruct = function () {
108
+ return !!t;
109
+ })();
110
+ }
76
111
  function _iterableToArray(r) {
77
112
  if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
78
113
  }
114
+ function _iterableToArrayLimit(r, l) {
115
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
116
+ if (null != t) {
117
+ var e,
118
+ n,
119
+ i,
120
+ u,
121
+ a = [],
122
+ f = true,
123
+ o = false;
124
+ try {
125
+ if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
126
+ } catch (r) {
127
+ o = true, n = r;
128
+ } finally {
129
+ try {
130
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
131
+ } finally {
132
+ if (o) throw n;
133
+ }
134
+ }
135
+ return a;
136
+ }
137
+ }
138
+ function _nonIterableRest() {
139
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
140
+ }
79
141
  function _nonIterableSpread() {
80
142
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
81
143
  }
@@ -120,6 +182,11 @@ function _objectWithoutPropertiesLoose(r, e) {
120
182
  }
121
183
  return t;
122
184
  }
185
+ function _possibleConstructorReturn(t, e) {
186
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
187
+ if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
188
+ return _assertThisInitialized(t);
189
+ }
123
190
  function _regenerator() {
124
191
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
125
192
  var e,
@@ -228,6 +295,14 @@ function _regeneratorDefine(e, r, n, t) {
228
295
  }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
229
296
  }, _regeneratorDefine(e, r, n, t);
230
297
  }
298
+ function _setPrototypeOf(t, e) {
299
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
300
+ return t.__proto__ = e, t;
301
+ }, _setPrototypeOf(t, e);
302
+ }
303
+ function _slicedToArray(r, e) {
304
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
305
+ }
231
306
  function _toConsumableArray(r) {
232
307
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
233
308
  }
@@ -253,6 +328,223 @@ function _unsupportedIterableToArray(r, a) {
253
328
  }
254
329
  }
255
330
 
331
+ var mergeRollupOptions = function mergeRollupOptions(first, second) {
332
+ if (!first) return second;
333
+ if (!second) return first;
334
+ return _objectSpread2(_objectSpread2({}, first), second);
335
+ };
336
+
337
+ var Compiler = /*#__PURE__*/function (_CompilerBase) {
338
+ function Compiler() {
339
+ var _this;
340
+ _classCallCheck(this, Compiler);
341
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
342
+ args[_key] = arguments[_key];
343
+ }
344
+ _this = _callSuper(this, Compiler, [].concat(args));
345
+ _defineProperty(_this, "context", /*#__PURE__*/function () {
346
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(options) {
347
+ var rollupBuild, outputList;
348
+ return _regenerator().w(function (_context3) {
349
+ while (1) switch (_context3.n) {
350
+ case 0:
351
+ _context3.n = 1;
352
+ return rollup(mergeRollupOptions(_this.initOptions, options));
353
+ case 1:
354
+ rollupBuild = _context3.v;
355
+ outputList = [];
356
+ if (options.output) {
357
+ outputList = isArray(options.output) ? options.output : [options.output];
358
+ }
359
+ return _context3.a(2, Promise.resolve({
360
+ rebuild: function () {
361
+ var _rebuild = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
362
+ var outputOptions, i, output, writeRes;
363
+ return _regenerator().w(function (_context) {
364
+ while (1) switch (_context.n) {
365
+ case 0:
366
+ outputOptions = [];
367
+ i = 0;
368
+ case 1:
369
+ if (!(i < outputList.length)) {
370
+ _context.n = 4;
371
+ break;
372
+ }
373
+ output = outputList[i];
374
+ _context.n = 2;
375
+ return rollupBuild.write(output);
376
+ case 2:
377
+ writeRes = _context.v;
378
+ outputOptions.push(writeRes);
379
+ case 3:
380
+ i++;
381
+ _context.n = 1;
382
+ break;
383
+ case 4:
384
+ return _context.a(2, Promise.resolve({
385
+ rollupBuild: rollupBuild,
386
+ outputOptions: outputOptions
387
+ }));
388
+ }
389
+ }, _callee);
390
+ }));
391
+ function rebuild() {
392
+ return _rebuild.apply(this, arguments);
393
+ }
394
+ return rebuild;
395
+ }(),
396
+ cancel: function () {
397
+ var _cancel = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
398
+ return _regenerator().w(function (_context2) {
399
+ while (1) switch (_context2.n) {
400
+ case 0:
401
+ cLog.warn('build', 'empty', 'Rollup does not need to be canceled.');
402
+ case 1:
403
+ return _context2.a(2);
404
+ }
405
+ }, _callee2);
406
+ }));
407
+ function cancel() {
408
+ return _cancel.apply(this, arguments);
409
+ }
410
+ return cancel;
411
+ }()
412
+ }));
413
+ }
414
+ }, _callee3);
415
+ }));
416
+ return function (_x) {
417
+ return _ref.apply(this, arguments);
418
+ };
419
+ }());
420
+ _defineProperty(_this, "inOutMap", /*#__PURE__*/function () {
421
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(inputOutputMap) {
422
+ var input;
423
+ return _regenerator().w(function (_context4) {
424
+ while (1) switch (_context4.n) {
425
+ case 0:
426
+ input = {};
427
+ Object.entries(inputOutputMap).forEach(function (_ref3) {
428
+ var _ref4 = _slicedToArray(_ref3, 2),
429
+ input = _ref4[0],
430
+ output = _ref4[1];
431
+ input[output] = input;
432
+ });
433
+ return _context4.a(2, _this.build({
434
+ input: input
435
+ }));
436
+ }
437
+ }, _callee4);
438
+ }));
439
+ return function (_x2) {
440
+ return _ref2.apply(this, arguments);
441
+ };
442
+ }());
443
+ _defineProperty(_this, "input", /*#__PURE__*/function () {
444
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(input) {
445
+ var rollupBuild;
446
+ return _regenerator().w(function (_context6) {
447
+ while (1) switch (_context6.n) {
448
+ case 0:
449
+ _context6.n = 1;
450
+ return rollup(mergeRollupOptions(_this.initOptions, {
451
+ input: input
452
+ }));
453
+ case 1:
454
+ rollupBuild = _context6.v;
455
+ return _context6.a(2, {
456
+ output: function () {
457
+ var _output2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_output) {
458
+ var writeRes;
459
+ return _regenerator().w(function (_context5) {
460
+ while (1) switch (_context5.n) {
461
+ case 0:
462
+ _context5.n = 1;
463
+ return rollupBuild.write(_output);
464
+ case 1:
465
+ writeRes = _context5.v;
466
+ return _context5.a(2, {
467
+ rollupBuild: rollupBuild,
468
+ outputOptions: [writeRes]
469
+ });
470
+ }
471
+ }, _callee5);
472
+ }));
473
+ function output(_x4) {
474
+ return _output2.apply(this, arguments);
475
+ }
476
+ return output;
477
+ }()
478
+ });
479
+ }
480
+ }, _callee6);
481
+ }));
482
+ return function (_x3) {
483
+ return _ref5.apply(this, arguments);
484
+ };
485
+ }());
486
+ _defineProperty(_this, "build", /*#__PURE__*/function () {
487
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(options) {
488
+ var rollupBuild, outputList, outputOptions, i, output, writeRes;
489
+ return _regenerator().w(function (_context7) {
490
+ while (1) switch (_context7.n) {
491
+ case 0:
492
+ _context7.n = 1;
493
+ return rollup(mergeRollupOptions(_this.initOptions, options));
494
+ case 1:
495
+ rollupBuild = _context7.v;
496
+ outputList = [];
497
+ if (options.output) {
498
+ outputList = isArray(options.output) ? options.output : [options.output];
499
+ }
500
+ outputOptions = [];
501
+ i = 0;
502
+ case 2:
503
+ if (!(i < outputList.length)) {
504
+ _context7.n = 5;
505
+ break;
506
+ }
507
+ output = outputList[i];
508
+ _context7.n = 3;
509
+ return rollupBuild.write(output);
510
+ case 3:
511
+ writeRes = _context7.v;
512
+ outputOptions.push(writeRes);
513
+ case 4:
514
+ i++;
515
+ _context7.n = 2;
516
+ break;
517
+ case 5:
518
+ return _context7.a(2, {
519
+ rollupBuild: rollupBuild,
520
+ outputOptions: outputOptions
521
+ });
522
+ }
523
+ }, _callee7);
524
+ }));
525
+ return function (_x5) {
526
+ return _ref6.apply(this, arguments);
527
+ };
528
+ }());
529
+ _defineProperty(_this, "watch", function (options) {
530
+ var watchOptions = mergeRollupOptions(_this.initOptions, options);
531
+ return watch(watchOptions);
532
+ });
533
+ _defineProperty(_this, "server", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
534
+ return _regenerator().w(function (_context8) {
535
+ while (1) switch (_context8.n) {
536
+ case 0:
537
+ cLog.warn('serve', 'empty', 'Rollup does not support serve functionality.');
538
+ return _context8.a(2);
539
+ }
540
+ }, _callee8);
541
+ })));
542
+ return _this;
543
+ }
544
+ _inherits(Compiler, _CompilerBase);
545
+ return _createClass(Compiler);
546
+ }(CompilerBase);
547
+
256
548
  /**
257
549
  * 获取external配置
258
550
  * @param envParams 环境参数
@@ -906,4 +1198,4 @@ var rollupWatch = function rollupWatch(config) {
906
1198
  return watch(config);
907
1199
  };
908
1200
 
909
- export { Ctx, createRollupBuild, dealDts, getAliasPlugin, getBabelPlugin, getCommonjsPlugin, getCopyPlugin, getDtsPlugin, getExternal, getFirstInput, getInput, getJsonPlugin, getMinimizePlugin, getNodePlugins, getOutput, getPostcssPlugin, getReactPlugins, getResolvePlugin, getRollupWrite, getWatch, handleError, rollupWatch, rollupWatchLog };
1201
+ export { Compiler, Ctx, createRollupBuild, dealDts, getAliasPlugin, getBabelPlugin, getCommonjsPlugin, getCopyPlugin, getDtsPlugin, getExternal, getFirstInput, getInput, getJsonPlugin, getMinimizePlugin, getNodePlugins, getOutput, getPostcssPlugin, getReactPlugins, getResolvePlugin, getRollupWrite, getWatch, handleError, mergeRollupOptions, rollupWatch, rollupWatchLog };
@@ -1,6 +1,7 @@
1
1
  import * as rollup from 'rollup';
2
- import { ExternalOption, InputOption, OutputOptions, WatcherOptions, Plugin, RollupOptions, RollupWatcher, RollupWatchOptions, RollupBuild } from 'rollup';
2
+ import { RollupBuild, RollupOutput, RollupOptions, RollupWatcher, OutputOptions, RollupWatchOptions, ExternalOption, InputOption, WatcherOptions, Plugin } from 'rollup';
3
3
  export { RollupBuild } from 'rollup';
4
+ import { CompilerBase, ConfigCtx } from '@doracli/helper';
4
5
  import { TPlainObject } from '@cclr/lang';
5
6
  import { RollupAliasOptions } from '@rollup/plugin-alias';
6
7
  import { RollupBabelInputPluginOptions } from '@rollup/plugin-babel';
@@ -12,7 +13,40 @@ import { Options } from 'rollup-plugin-dts';
12
13
  import { RollupJsonOptions } from '@rollup/plugin-json';
13
14
  import { PostCSSPluginConf } from 'rollup-plugin-postcss';
14
15
  import { RollupNodeResolveOptions } from '@rollup/plugin-node-resolve';
15
- import { ConfigCtx } from '@doracli/helper';
16
+
17
+ type TBuildResult = {
18
+ rollupBuild: RollupBuild;
19
+ outputOptions: RollupOutput[];
20
+ };
21
+ declare class Compiler extends CompilerBase<RollupOptions, {
22
+ build: Promise<TBuildResult>;
23
+ watch: RollupWatcher;
24
+ server: Promise<void>;
25
+ }> {
26
+ context: (options: RollupOptions) => Promise<{
27
+ rebuild: () => Promise<{
28
+ rollupBuild: RollupBuild;
29
+ outputOptions: RollupOutput[];
30
+ }>;
31
+ cancel: () => Promise<void>;
32
+ }>;
33
+ inOutMap: (inputOutputMap: Record<string, string>) => Promise<{
34
+ rollupBuild: RollupBuild;
35
+ outputOptions: RollupOutput[];
36
+ }>;
37
+ input: (input: string) => Promise<{
38
+ output: (output: OutputOptions) => Promise<{
39
+ rollupBuild: RollupBuild;
40
+ outputOptions: RollupOutput[];
41
+ }>;
42
+ }>;
43
+ build: (options: RollupOptions) => Promise<{
44
+ rollupBuild: RollupBuild;
45
+ outputOptions: RollupOutput[];
46
+ }>;
47
+ watch: (options: RollupWatchOptions) => RollupWatcher;
48
+ server: () => Promise<void>;
49
+ }
16
50
 
17
51
  /** 动作 */
18
52
  type TAction = 'build' | 'dev' | 'watch';
@@ -222,6 +256,8 @@ declare const getFirstInput: (inputOrigin: TInputOption) => {
222
256
  declare const rollupWatchLog: (watcher: RollupWatcher) => void;
223
257
  declare function handleError(error: any, recover?: boolean): void;
224
258
 
259
+ declare const mergeRollupOptions: <T extends Partial<RollupOptions>>(first: T, second: T) => T;
260
+
225
261
  declare const rollupWatch: (config: RollupWatchOptions | RollupWatchOptions[]) => rollup.RollupWatcher;
226
262
 
227
263
  /**
@@ -231,5 +267,5 @@ declare const rollupWatch: (config: RollupWatchOptions | RollupWatchOptions[]) =
231
267
  */
232
268
  declare const getRollupWrite: (rollupBuild: RollupBuild) => (output: TOutputOptions) => Promise<rollup.RollupOutput>;
233
269
 
234
- export { Ctx, createRollupBuild, dealDts, getAliasPlugin, getBabelPlugin, getCommonjsPlugin, getCopyPlugin, getDtsPlugin, getExternal, getFirstInput, getInput, getJsonPlugin, getMinimizePlugin, getNodePlugins, getOutput, getPostcssPlugin, getReactPlugins, getResolvePlugin, getRollupWrite, getWatch, handleError, rollupWatch, rollupWatchLog };
235
- export type { TAction, TEnvParams, TExternalOption, TInputOption, TOutputOptions, TUserExternalOption, TWatcherOptions };
270
+ export { Compiler, Ctx, createRollupBuild, dealDts, getAliasPlugin, getBabelPlugin, getCommonjsPlugin, getCopyPlugin, getDtsPlugin, getExternal, getFirstInput, getInput, getJsonPlugin, getMinimizePlugin, getNodePlugins, getOutput, getPostcssPlugin, getReactPlugins, getResolvePlugin, getRollupWrite, getWatch, handleError, mergeRollupOptions, rollupWatch, rollupWatchLog };
271
+ export type { TAction, TBuildResult, TEnvParams, TExternalOption, TInputOption, TOutputOptions, TUserExternalOption, TWatcherOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doracli/rollup",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "use rollup",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -32,23 +32,23 @@
32
32
  "@cclr/utils": "^0.1.28",
33
33
  "@dorabag/file-pro": "^1.0.10",
34
34
  "@dorabag/srv-tool": "^1.0.10",
35
- "@doracli/helper": "^0.0.1",
36
- "@doracli/preset-babel": "^0.0.1",
37
- "@doracli/type": "^0.0.1",
35
+ "@doracli/helper": "^0.0.2",
36
+ "@doracli/preset-babel": "^0.0.2",
37
+ "@doracli/type": "^0.0.2",
38
38
  "@rollup/plugin-alias": "^5.1.1",
39
39
  "@rollup/plugin-babel": "^6.1.0",
40
40
  "@rollup/plugin-commonjs": "^28.0.8",
41
41
  "@rollup/plugin-json": "^6.1.0",
42
42
  "@rollup/plugin-node-resolve": "^16.0.3",
43
43
  "@rollup/plugin-terser": "^0.4.4",
44
- "@rollup/plugin-typescript": "^12.1.4",
44
+ "@rollup/plugin-typescript": "^12.3.0",
45
45
  "autoprefixer": "^10.4.21",
46
46
  "cssnano": "^7.1.1",
47
47
  "postcss": "^8.5.6",
48
- "rollup": "^4.52.4",
48
+ "rollup": "^4.52.5",
49
49
  "rollup-plugin-copy": "^3.5.0",
50
50
  "rollup-plugin-dts": "^6.2.3",
51
51
  "rollup-plugin-postcss": "^4.0.2"
52
52
  },
53
- "gitHead": "40ab496f25042487a671979074515f3345c96453"
53
+ "gitHead": "912cb44292b64679630a799974d18c22b2e69738"
54
54
  }