@doracli/esbuild-react 0.0.3 → 0.0.4

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,187 +1,285 @@
1
1
  'use strict';
2
2
 
3
- var esbuild = require('@doracli/esbuild');
4
3
  var helper = require('@doracli/helper');
5
- var filePro = require('@dorabag/file-pro');
6
- var path = require('path');
4
+ var esbuild = require('@doracli/esbuild');
7
5
 
8
- var clear = function clear(ctx) {
9
- return new Promise(function ($return, $error) {
10
- var _ctx$getDoraConfig, clear, output, _ref, path;
11
- _ctx$getDoraConfig = ctx.getDoraConfig(), clear = _ctx$getDoraConfig.clear, output = _ctx$getDoraConfig.output;
12
- _ref = output || {}, path = _ref.path;
13
- var $Try_1_Post = function () {
14
- try {
15
- return $return();
16
- } catch ($boundEx) {
17
- return $error($boundEx);
6
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
7
+ try {
8
+ var i = n[a](c),
9
+ u = i.value;
10
+ } catch (n) {
11
+ return void e(n);
12
+ }
13
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
14
+ }
15
+ function _asyncToGenerator(n) {
16
+ return function () {
17
+ var t = this,
18
+ e = arguments;
19
+ return new Promise(function (r, o) {
20
+ var a = n.apply(t, e);
21
+ function _next(n) {
22
+ asyncGeneratorStep(a, r, o, _next, _throw, 'next', n);
18
23
  }
19
- };
20
- var $Try_1_Catch = function (_error) {
21
- try {
22
- helper.cLog.warn('clear', 'warn', "\u6E05\u7A7A\u76EE\u6807\u6587\u4EF6\u5939\u5931\u8D25: ".concat(path));
23
- return $Try_1_Post();
24
- } catch ($boundEx) {
25
- return $error($boundEx);
24
+ function _throw(n) {
25
+ asyncGeneratorStep(a, r, o, _next, _throw, 'throw', n);
26
26
  }
27
- };
28
- try {
29
- if (!clear) return $return();
30
- if (!path) return $return();
31
- return Promise.resolve(filePro.isValidDir(path)).then(function ($await_2) {
32
- try {
33
- if (!$await_2) return $return();
34
- return Promise.resolve(filePro.cleanTargets(path)).then(function ($await_3) {
35
- try {
36
- return $Try_1_Post();
37
- } catch ($boundEx) {
38
- return $Try_1_Catch($boundEx);
27
+ _next(void 0);
28
+ });
29
+ };
30
+ }
31
+ function _regenerator() {
32
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
33
+ var e,
34
+ t,
35
+ r = 'function' == typeof Symbol ? Symbol : {},
36
+ n = r.iterator || '@@iterator',
37
+ o = r.toStringTag || '@@toStringTag';
38
+ function i(r, n, o, i) {
39
+ var c = n && n.prototype instanceof Generator ? n : Generator,
40
+ u = Object.create(c.prototype);
41
+ return (
42
+ _regeneratorDefine(
43
+ u,
44
+ '_invoke',
45
+ (function (r, n, o) {
46
+ var i,
47
+ c,
48
+ u,
49
+ f = 0,
50
+ p = o || [],
51
+ y = false,
52
+ G = {
53
+ p: 0,
54
+ n: 0,
55
+ v: e,
56
+ a: d,
57
+ f: d.bind(e, 4),
58
+ d: function (t, r) {
59
+ return ((i = t), (c = 0), (u = e), (G.n = r), a);
60
+ },
61
+ };
62
+ function d(r, n) {
63
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
64
+ var o,
65
+ i = p[t],
66
+ d = G.p,
67
+ l = i[2];
68
+ r > 3
69
+ ? (o = l === n) &&
70
+ ((u = i[(c = i[4]) ? 5 : ((c = 3), 3)]), (i[4] = i[5] = e))
71
+ : i[0] <= d &&
72
+ ((o = r < 2 && d < i[1])
73
+ ? ((c = 0), (G.v = n), (G.n = i[1]))
74
+ : d < l &&
75
+ (o = r < 3 || i[0] > n || n > l) &&
76
+ ((i[4] = r), (i[5] = n), (G.n = l), (c = 0)));
39
77
  }
40
- }, $Try_1_Catch);
41
- } catch ($boundEx) {
42
- return $Try_1_Catch($boundEx);
43
- }
44
- }, $Try_1_Catch);
45
- } catch (_error) {
46
- $Try_1_Catch();
47
- }
48
- });
49
- };
50
-
51
- var ActionMap = {
52
- build: helper.EnvEnum.prod
53
- };
54
-
55
- var updateDefine = function updateDefine(ctx) {
56
- var action = ctx.envParams.action;
57
- ctx.updateEsbuildConfig({
58
- define: esbuild.getDefine({
59
- NODE_ENV: ActionMap[action] || helper.EnvEnum.prod
60
- })
61
- });
62
- };
78
+ if (o || r > 1) return a;
79
+ throw ((y = true), n);
80
+ }
81
+ return function (o, p, l) {
82
+ if (f > 1) throw TypeError('Generator is already running');
83
+ for (
84
+ y && 1 === p && d(p, l), c = p, u = l;
85
+ (t = c < 2 ? e : u) || !y;
63
86
 
64
- var updateEntryPoints = function updateEntryPoints(ctx) {
65
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
66
- input = _ctx$getDoraConfig.input;
67
- if (input) {
68
- ctx.updateEsbuildConfig({
69
- entryPoints: [input]
70
- });
71
- return;
87
+ ) {
88
+ i ||
89
+ (c
90
+ ? c < 3
91
+ ? (c > 1 && (G.n = -1), d(c, u))
92
+ : (G.n = u)
93
+ : (G.v = u));
94
+ try {
95
+ if (((f = 2), i)) {
96
+ if ((c || (o = 'next'), (t = i[o]))) {
97
+ if (!(t = t.call(i, u)))
98
+ throw TypeError('iterator result is not an object');
99
+ if (!t.done) return t;
100
+ ((u = t.value), c < 2 && (c = 0));
101
+ } else
102
+ (1 === c && (t = i.return) && t.call(i),
103
+ c < 2 &&
104
+ ((u = TypeError(
105
+ "The iterator does not provide a '" + o + "' method"
106
+ )),
107
+ (c = 1)));
108
+ i = e;
109
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
110
+ } catch (t) {
111
+ ((i = e), (c = 1), (u = t));
112
+ } finally {
113
+ f = 1;
114
+ }
115
+ }
116
+ return {
117
+ value: t,
118
+ done: y,
119
+ };
120
+ };
121
+ })(r, o, i),
122
+ true
123
+ ),
124
+ u
125
+ );
72
126
  }
73
- ctx.updateEsbuildConfig({
74
- entryPoints: esbuild.getEntryPoints(ctx.envParams)
75
- });
76
- };
77
-
78
- var updateLoader = function updateLoader(ctx) {
79
- ctx.updateEsbuildConfig({
80
- loader: esbuild.getReactLoaderPreset()
81
- });
82
- };
83
-
84
- var updateOutput = function updateOutput(ctx) {
85
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
86
- output = _ctx$getDoraConfig.output;
87
- var workRootDir = ctx.envParams.workRootDir;
88
- var path$1 = output.path,
89
- file = output.file;
90
- ctx.updateEsbuildConfig({
91
- outfile: path.join(workRootDir, path$1, file || 'index.js')
92
- });
93
- };
94
-
95
- var updatePlugin = function updatePlugin(ctx) {
96
- var plugins = [];
97
- plugins.push(esbuild.getLessPlugin(), esbuild.getPostCssPlugin());
98
- ctx.updateEsbuildConfig({
99
- plugins: plugins
100
- });
101
- };
102
-
103
- var updateTrivial = function updateTrivial(ctx) {
104
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
105
- minimize = _ctx$getDoraConfig.minimize;
106
- ctx.updateEsbuildConfig({
107
- minify: minimize,
108
- bundle: true,
109
- platform: 'browser',
110
- target: ['es2020'],
111
- resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
112
- logLevel: 'info'
113
- });
114
- };
127
+ var a = {};
128
+ function Generator() {}
129
+ function GeneratorFunction() {}
130
+ function GeneratorFunctionPrototype() {}
131
+ t = Object.getPrototypeOf;
132
+ var c = [][n]
133
+ ? t(t([][n]()))
134
+ : (_regeneratorDefine((t = {}), n, function () {
135
+ return this;
136
+ }),
137
+ t),
138
+ u =
139
+ (GeneratorFunctionPrototype.prototype =
140
+ Generator.prototype =
141
+ Object.create(c));
142
+ function f(e) {
143
+ return (
144
+ Object.setPrototypeOf
145
+ ? Object.setPrototypeOf(e, GeneratorFunctionPrototype)
146
+ : ((e.__proto__ = GeneratorFunctionPrototype),
147
+ _regeneratorDefine(e, o, 'GeneratorFunction')),
148
+ (e.prototype = Object.create(u)),
149
+ e
150
+ );
151
+ }
152
+ return (
153
+ (GeneratorFunction.prototype = GeneratorFunctionPrototype),
154
+ _regeneratorDefine(u, 'constructor', GeneratorFunctionPrototype),
155
+ _regeneratorDefine(
156
+ GeneratorFunctionPrototype,
157
+ 'constructor',
158
+ GeneratorFunction
159
+ ),
160
+ (GeneratorFunction.displayName = 'GeneratorFunction'),
161
+ _regeneratorDefine(GeneratorFunctionPrototype, o, 'GeneratorFunction'),
162
+ _regeneratorDefine(u),
163
+ _regeneratorDefine(u, o, 'Generator'),
164
+ _regeneratorDefine(u, n, function () {
165
+ return this;
166
+ }),
167
+ _regeneratorDefine(u, 'toString', function () {
168
+ return '[object Generator]';
169
+ }),
170
+ (_regenerator = function () {
171
+ return {
172
+ w: i,
173
+ m: f,
174
+ };
175
+ })()
176
+ );
177
+ }
178
+ function _regeneratorDefine(e, r, n, t) {
179
+ var i = Object.defineProperty;
180
+ try {
181
+ i({}, '', {});
182
+ } catch (e) {
183
+ i = 0;
184
+ }
185
+ ((_regeneratorDefine = function (e, r, n, t) {
186
+ function o(r, n) {
187
+ _regeneratorDefine(e, r, function (e) {
188
+ return this._invoke(r, n, e);
189
+ });
190
+ }
191
+ r
192
+ ? i
193
+ ? i(e, r, {
194
+ value: n,
195
+ enumerable: !t,
196
+ configurable: !t,
197
+ writable: !t,
198
+ })
199
+ : (e[r] = n)
200
+ : (o('next', 0), o('throw', 1), o('return', 2));
201
+ }),
202
+ _regeneratorDefine(e, r, n, t));
203
+ }
115
204
 
116
- var initEsbuildConfig = function initEsbuildConfig(ctx) {
117
- return new Promise(function ($return, $error) {
118
- updateEntryPoints(ctx);
119
- updateOutput(ctx);
120
- updateDefine(ctx);
121
- updateLoader(ctx);
122
- updatePlugin(ctx);
123
- updateTrivial(ctx);
124
- return $return();
125
- });
205
+ var getBuildCtx = function getBuildCtx(configCtx, envParams) {
206
+ var workflow = helper.configCtxWorkflow(new esbuild.Ctx(configCtx));
207
+ workflow.use(esbuild.envParamsMw(envParams));
208
+ workflow.use(esbuild.esbuildPlainMw());
209
+ workflow.use(esbuild.esbuildEntryPointsMw());
210
+ workflow.use(esbuild.esbuildOutputMw());
211
+ workflow.use(esbuild.esbuildReactLoaderMw());
212
+ workflow.use(esbuild.esbuildStylePluginMw());
213
+ return workflow.getResult();
126
214
  };
215
+ var buildBase = /*#__PURE__*/ (function () {
216
+ var _ref = _asyncToGenerator(
217
+ /*#__PURE__*/ _regenerator().m(function _callee(ctx) {
218
+ var compiler, timeEnd, res;
219
+ return _regenerator().w(function (_context) {
220
+ while (1)
221
+ switch (_context.n) {
222
+ case 0:
223
+ compiler = new esbuild.Compiler(ctx.esbuildConfig);
224
+ timeEnd = helper.cLog.time('build');
225
+ _context.n = 1;
226
+ return compiler.build({});
227
+ case 1:
228
+ res = _context.v;
229
+ timeEnd();
230
+ return _context.a(2, res);
231
+ }
232
+ }, _callee);
233
+ })
234
+ );
235
+ return function buildBase(_x) {
236
+ return _ref.apply(this, arguments);
237
+ };
238
+ })();
127
239
 
128
- var buildBase = function buildBase(ctx) {
129
- return new Promise(function ($return, $error) {
130
- var timeEnd, res;
131
- return Promise.resolve(initEsbuildConfig(ctx)).then(function ($await_1) {
132
- try {
133
- return Promise.resolve(clear(ctx)).then(function ($await_2) {
134
- try {
135
- timeEnd = helper.cLog.time('build');
136
- return Promise.resolve(esbuild.builder(ctx.esbuildConfig)).then(function ($await_3) {
137
- try {
138
- res = $await_3;
139
- timeEnd();
140
- return $return(res);
141
- } catch ($boundEx) {
142
- return $error($boundEx);
240
+ var buildSingle = /*#__PURE__*/ (function () {
241
+ var _ref = _asyncToGenerator(
242
+ /*#__PURE__*/ _regenerator().m(function _callee(configCtx, envParams) {
243
+ var ctx, res, _ref2, errors;
244
+ return _regenerator().w(function (_context) {
245
+ while (1)
246
+ switch (_context.n) {
247
+ case 0:
248
+ _context.n = 1;
249
+ return getBuildCtx(configCtx, envParams);
250
+ case 1:
251
+ ctx = _context.v;
252
+ _context.n = 2;
253
+ return buildBase(ctx);
254
+ case 2:
255
+ res = _context.v;
256
+ ((_ref2 = res || {}), (errors = _ref2.errors));
257
+ if (!(errors !== null && errors !== void 0 && errors.length)) {
258
+ _context.n = 3;
259
+ break;
143
260
  }
144
- }, $error);
145
- } catch ($boundEx) {
146
- return $error($boundEx);
261
+ helper.cLog.error('build', 'error', 'esbuld构建失败,捕获到错误');
262
+ errors.forEach(function (message) {
263
+ var detail = message.detail,
264
+ id = message.id,
265
+ location = message.location,
266
+ notes = message.notes,
267
+ pluginName = message.pluginName,
268
+ text = message.text;
269
+ console.log(id, location, pluginName, detail, notes, text);
270
+ });
271
+ return _context.a(2);
272
+ case 3:
273
+ helper.cLog.info('build', 'success', 'esbuld构建成功');
274
+ case 4:
275
+ return _context.a(2);
147
276
  }
148
- }, $error);
149
- } catch ($boundEx) {
150
- return $error($boundEx);
151
- }
152
- }, $error);
153
- });
154
- };
155
-
156
- var buildSingle = function buildSingle(configCtx, envParams) {
157
- return new Promise(function ($return, $error) {
158
- var ctx, res, _ref, errors;
159
- ctx = new esbuild.Ctx(configCtx);
160
- ctx.updateEnvParams(envParams);
161
- return Promise.resolve(buildBase(ctx)).then(function ($await_1) {
162
- try {
163
- res = $await_1;
164
- _ref = res || {}, errors = _ref.errors;
165
- if (errors !== null && errors !== void 0 && errors.length) {
166
- helper.cLog.error('build', 'error', 'esbuld构建失败,捕获到错误');
167
- errors.forEach(function (message) {
168
- var detail = message.detail,
169
- id = message.id,
170
- location = message.location,
171
- notes = message.notes,
172
- pluginName = message.pluginName,
173
- text = message.text;
174
- console.log(id, location, pluginName, detail, notes, text);
175
- });
176
- return $return();
177
- }
178
- helper.cLog.info('build', 'success', 'esbuld构建成功');
179
- return $return();
180
- } catch ($boundEx) {
181
- return $error($boundEx);
182
- }
183
- }, $error);
184
- });
185
- };
277
+ }, _callee);
278
+ })
279
+ );
280
+ return function buildSingle(_x, _x2) {
281
+ return _ref.apply(this, arguments);
282
+ };
283
+ })();
186
284
 
187
285
  exports.buildSingle = buildSingle;
package/lib/esm/index.js CHANGED
@@ -1,185 +1,292 @@
1
- import { getDefine, getEntryPoints, getReactLoaderPreset, getLessPlugin, getPostCssPlugin, builder, Ctx } from '@doracli/esbuild';
2
- import { cLog, EnvEnum } from '@doracli/helper';
3
- import { isValidDir, cleanTargets } from '@dorabag/file-pro';
4
- import { join } from 'path';
1
+ import {
2
+ Compiler,
3
+ Ctx,
4
+ envParamsMw,
5
+ esbuildEntryPointsMw,
6
+ esbuildOutputMw,
7
+ esbuildPlainMw,
8
+ esbuildReactLoaderMw,
9
+ esbuildStylePluginMw,
10
+ } from '@doracli/esbuild';
11
+ import { cLog, configCtxWorkflow } from '@doracli/helper';
5
12
 
6
- var clear = function clear(ctx) {
7
- return new Promise(function ($return, $error) {
8
- var _ctx$getDoraConfig, clear, output, _ref, path;
9
- _ctx$getDoraConfig = ctx.getDoraConfig(), clear = _ctx$getDoraConfig.clear, output = _ctx$getDoraConfig.output;
10
- _ref = output || {}, path = _ref.path;
11
- var $Try_1_Post = function () {
12
- try {
13
- return $return();
14
- } catch ($boundEx) {
15
- return $error($boundEx);
13
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
14
+ try {
15
+ var i = n[a](c),
16
+ u = i.value;
17
+ } catch (n) {
18
+ return void e(n);
19
+ }
20
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
21
+ }
22
+ function _asyncToGenerator(n) {
23
+ return function () {
24
+ var t = this,
25
+ e = arguments;
26
+ return new Promise(function (r, o) {
27
+ var a = n.apply(t, e);
28
+ function _next(n) {
29
+ asyncGeneratorStep(a, r, o, _next, _throw, 'next', n);
16
30
  }
17
- };
18
- var $Try_1_Catch = function (_error) {
19
- try {
20
- cLog.warn('clear', 'warn', "\u6E05\u7A7A\u76EE\u6807\u6587\u4EF6\u5939\u5931\u8D25: ".concat(path));
21
- return $Try_1_Post();
22
- } catch ($boundEx) {
23
- return $error($boundEx);
31
+ function _throw(n) {
32
+ asyncGeneratorStep(a, r, o, _next, _throw, 'throw', n);
24
33
  }
25
- };
26
- try {
27
- if (!clear) return $return();
28
- if (!path) return $return();
29
- return Promise.resolve(isValidDir(path)).then(function ($await_2) {
30
- try {
31
- if (!$await_2) return $return();
32
- return Promise.resolve(cleanTargets(path)).then(function ($await_3) {
33
- try {
34
- return $Try_1_Post();
35
- } catch ($boundEx) {
36
- return $Try_1_Catch($boundEx);
34
+ _next(void 0);
35
+ });
36
+ };
37
+ }
38
+ function _regenerator() {
39
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
40
+ var e,
41
+ t,
42
+ r = 'function' == typeof Symbol ? Symbol : {},
43
+ n = r.iterator || '@@iterator',
44
+ o = r.toStringTag || '@@toStringTag';
45
+ function i(r, n, o, i) {
46
+ var c = n && n.prototype instanceof Generator ? n : Generator,
47
+ u = Object.create(c.prototype);
48
+ return (
49
+ _regeneratorDefine(
50
+ u,
51
+ '_invoke',
52
+ (function (r, n, o) {
53
+ var i,
54
+ c,
55
+ u,
56
+ f = 0,
57
+ p = o || [],
58
+ y = false,
59
+ G = {
60
+ p: 0,
61
+ n: 0,
62
+ v: e,
63
+ a: d,
64
+ f: d.bind(e, 4),
65
+ d: function (t, r) {
66
+ return ((i = t), (c = 0), (u = e), (G.n = r), a);
67
+ },
68
+ };
69
+ function d(r, n) {
70
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
71
+ var o,
72
+ i = p[t],
73
+ d = G.p,
74
+ l = i[2];
75
+ r > 3
76
+ ? (o = l === n) &&
77
+ ((u = i[(c = i[4]) ? 5 : ((c = 3), 3)]), (i[4] = i[5] = e))
78
+ : i[0] <= d &&
79
+ ((o = r < 2 && d < i[1])
80
+ ? ((c = 0), (G.v = n), (G.n = i[1]))
81
+ : d < l &&
82
+ (o = r < 3 || i[0] > n || n > l) &&
83
+ ((i[4] = r), (i[5] = n), (G.n = l), (c = 0)));
37
84
  }
38
- }, $Try_1_Catch);
39
- } catch ($boundEx) {
40
- return $Try_1_Catch($boundEx);
41
- }
42
- }, $Try_1_Catch);
43
- } catch (_error) {
44
- $Try_1_Catch();
45
- }
46
- });
47
- };
48
-
49
- var ActionMap = {
50
- build: EnvEnum.prod
51
- };
52
-
53
- var updateDefine = function updateDefine(ctx) {
54
- var action = ctx.envParams.action;
55
- ctx.updateEsbuildConfig({
56
- define: getDefine({
57
- NODE_ENV: ActionMap[action] || EnvEnum.prod
58
- })
59
- });
60
- };
85
+ if (o || r > 1) return a;
86
+ throw ((y = true), n);
87
+ }
88
+ return function (o, p, l) {
89
+ if (f > 1) throw TypeError('Generator is already running');
90
+ for (
91
+ y && 1 === p && d(p, l), c = p, u = l;
92
+ (t = c < 2 ? e : u) || !y;
61
93
 
62
- var updateEntryPoints = function updateEntryPoints(ctx) {
63
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
64
- input = _ctx$getDoraConfig.input;
65
- if (input) {
66
- ctx.updateEsbuildConfig({
67
- entryPoints: [input]
68
- });
69
- return;
94
+ ) {
95
+ i ||
96
+ (c
97
+ ? c < 3
98
+ ? (c > 1 && (G.n = -1), d(c, u))
99
+ : (G.n = u)
100
+ : (G.v = u));
101
+ try {
102
+ if (((f = 2), i)) {
103
+ if ((c || (o = 'next'), (t = i[o]))) {
104
+ if (!(t = t.call(i, u)))
105
+ throw TypeError('iterator result is not an object');
106
+ if (!t.done) return t;
107
+ ((u = t.value), c < 2 && (c = 0));
108
+ } else
109
+ (1 === c && (t = i.return) && t.call(i),
110
+ c < 2 &&
111
+ ((u = TypeError(
112
+ "The iterator does not provide a '" + o + "' method"
113
+ )),
114
+ (c = 1)));
115
+ i = e;
116
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
117
+ } catch (t) {
118
+ ((i = e), (c = 1), (u = t));
119
+ } finally {
120
+ f = 1;
121
+ }
122
+ }
123
+ return {
124
+ value: t,
125
+ done: y,
126
+ };
127
+ };
128
+ })(r, o, i),
129
+ true
130
+ ),
131
+ u
132
+ );
70
133
  }
71
- ctx.updateEsbuildConfig({
72
- entryPoints: getEntryPoints(ctx.envParams)
73
- });
74
- };
75
-
76
- var updateLoader = function updateLoader(ctx) {
77
- ctx.updateEsbuildConfig({
78
- loader: getReactLoaderPreset()
79
- });
80
- };
81
-
82
- var updateOutput = function updateOutput(ctx) {
83
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
84
- output = _ctx$getDoraConfig.output;
85
- var workRootDir = ctx.envParams.workRootDir;
86
- var path = output.path,
87
- file = output.file;
88
- ctx.updateEsbuildConfig({
89
- outfile: join(workRootDir, path, file || 'index.js')
90
- });
91
- };
92
-
93
- var updatePlugin = function updatePlugin(ctx) {
94
- var plugins = [];
95
- plugins.push(getLessPlugin(), getPostCssPlugin());
96
- ctx.updateEsbuildConfig({
97
- plugins: plugins
98
- });
99
- };
100
-
101
- var updateTrivial = function updateTrivial(ctx) {
102
- var _ctx$getDoraConfig = ctx.getDoraConfig(),
103
- minimize = _ctx$getDoraConfig.minimize;
104
- ctx.updateEsbuildConfig({
105
- minify: minimize,
106
- bundle: true,
107
- platform: 'browser',
108
- target: ['es2020'],
109
- resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
110
- logLevel: 'info'
111
- });
112
- };
134
+ var a = {};
135
+ function Generator() {}
136
+ function GeneratorFunction() {}
137
+ function GeneratorFunctionPrototype() {}
138
+ t = Object.getPrototypeOf;
139
+ var c = [][n]
140
+ ? t(t([][n]()))
141
+ : (_regeneratorDefine((t = {}), n, function () {
142
+ return this;
143
+ }),
144
+ t),
145
+ u =
146
+ (GeneratorFunctionPrototype.prototype =
147
+ Generator.prototype =
148
+ Object.create(c));
149
+ function f(e) {
150
+ return (
151
+ Object.setPrototypeOf
152
+ ? Object.setPrototypeOf(e, GeneratorFunctionPrototype)
153
+ : ((e.__proto__ = GeneratorFunctionPrototype),
154
+ _regeneratorDefine(e, o, 'GeneratorFunction')),
155
+ (e.prototype = Object.create(u)),
156
+ e
157
+ );
158
+ }
159
+ return (
160
+ (GeneratorFunction.prototype = GeneratorFunctionPrototype),
161
+ _regeneratorDefine(u, 'constructor', GeneratorFunctionPrototype),
162
+ _regeneratorDefine(
163
+ GeneratorFunctionPrototype,
164
+ 'constructor',
165
+ GeneratorFunction
166
+ ),
167
+ (GeneratorFunction.displayName = 'GeneratorFunction'),
168
+ _regeneratorDefine(GeneratorFunctionPrototype, o, 'GeneratorFunction'),
169
+ _regeneratorDefine(u),
170
+ _regeneratorDefine(u, o, 'Generator'),
171
+ _regeneratorDefine(u, n, function () {
172
+ return this;
173
+ }),
174
+ _regeneratorDefine(u, 'toString', function () {
175
+ return '[object Generator]';
176
+ }),
177
+ (_regenerator = function () {
178
+ return {
179
+ w: i,
180
+ m: f,
181
+ };
182
+ })()
183
+ );
184
+ }
185
+ function _regeneratorDefine(e, r, n, t) {
186
+ var i = Object.defineProperty;
187
+ try {
188
+ i({}, '', {});
189
+ } catch (e) {
190
+ i = 0;
191
+ }
192
+ ((_regeneratorDefine = function (e, r, n, t) {
193
+ function o(r, n) {
194
+ _regeneratorDefine(e, r, function (e) {
195
+ return this._invoke(r, n, e);
196
+ });
197
+ }
198
+ r
199
+ ? i
200
+ ? i(e, r, {
201
+ value: n,
202
+ enumerable: !t,
203
+ configurable: !t,
204
+ writable: !t,
205
+ })
206
+ : (e[r] = n)
207
+ : (o('next', 0), o('throw', 1), o('return', 2));
208
+ }),
209
+ _regeneratorDefine(e, r, n, t));
210
+ }
113
211
 
114
- var initEsbuildConfig = function initEsbuildConfig(ctx) {
115
- return new Promise(function ($return, $error) {
116
- updateEntryPoints(ctx);
117
- updateOutput(ctx);
118
- updateDefine(ctx);
119
- updateLoader(ctx);
120
- updatePlugin(ctx);
121
- updateTrivial(ctx);
122
- return $return();
123
- });
212
+ var getBuildCtx = function getBuildCtx(configCtx, envParams) {
213
+ var workflow = configCtxWorkflow(new Ctx(configCtx));
214
+ workflow.use(envParamsMw(envParams));
215
+ workflow.use(esbuildPlainMw());
216
+ workflow.use(esbuildEntryPointsMw());
217
+ workflow.use(esbuildOutputMw());
218
+ workflow.use(esbuildReactLoaderMw());
219
+ workflow.use(esbuildStylePluginMw());
220
+ return workflow.getResult();
124
221
  };
222
+ var buildBase = /*#__PURE__*/ (function () {
223
+ var _ref = _asyncToGenerator(
224
+ /*#__PURE__*/ _regenerator().m(function _callee(ctx) {
225
+ var compiler, timeEnd, res;
226
+ return _regenerator().w(function (_context) {
227
+ while (1)
228
+ switch (_context.n) {
229
+ case 0:
230
+ compiler = new Compiler(ctx.esbuildConfig);
231
+ timeEnd = cLog.time('build');
232
+ _context.n = 1;
233
+ return compiler.build({});
234
+ case 1:
235
+ res = _context.v;
236
+ timeEnd();
237
+ return _context.a(2, res);
238
+ }
239
+ }, _callee);
240
+ })
241
+ );
242
+ return function buildBase(_x) {
243
+ return _ref.apply(this, arguments);
244
+ };
245
+ })();
125
246
 
126
- var buildBase = function buildBase(ctx) {
127
- return new Promise(function ($return, $error) {
128
- var timeEnd, res;
129
- return Promise.resolve(initEsbuildConfig(ctx)).then(function ($await_1) {
130
- try {
131
- return Promise.resolve(clear(ctx)).then(function ($await_2) {
132
- try {
133
- timeEnd = cLog.time('build');
134
- return Promise.resolve(builder(ctx.esbuildConfig)).then(function ($await_3) {
135
- try {
136
- res = $await_3;
137
- timeEnd();
138
- return $return(res);
139
- } catch ($boundEx) {
140
- return $error($boundEx);
247
+ var buildSingle = /*#__PURE__*/ (function () {
248
+ var _ref = _asyncToGenerator(
249
+ /*#__PURE__*/ _regenerator().m(function _callee(configCtx, envParams) {
250
+ var ctx, res, _ref2, errors;
251
+ return _regenerator().w(function (_context) {
252
+ while (1)
253
+ switch (_context.n) {
254
+ case 0:
255
+ _context.n = 1;
256
+ return getBuildCtx(configCtx, envParams);
257
+ case 1:
258
+ ctx = _context.v;
259
+ _context.n = 2;
260
+ return buildBase(ctx);
261
+ case 2:
262
+ res = _context.v;
263
+ ((_ref2 = res || {}), (errors = _ref2.errors));
264
+ if (!(errors !== null && errors !== void 0 && errors.length)) {
265
+ _context.n = 3;
266
+ break;
141
267
  }
142
- }, $error);
143
- } catch ($boundEx) {
144
- return $error($boundEx);
268
+ cLog.error('build', 'error', 'esbuld构建失败,捕获到错误');
269
+ errors.forEach(function (message) {
270
+ var detail = message.detail,
271
+ id = message.id,
272
+ location = message.location,
273
+ notes = message.notes,
274
+ pluginName = message.pluginName,
275
+ text = message.text;
276
+ console.log(id, location, pluginName, detail, notes, text);
277
+ });
278
+ return _context.a(2);
279
+ case 3:
280
+ cLog.info('build', 'success', 'esbuld构建成功');
281
+ case 4:
282
+ return _context.a(2);
145
283
  }
146
- }, $error);
147
- } catch ($boundEx) {
148
- return $error($boundEx);
149
- }
150
- }, $error);
151
- });
152
- };
153
-
154
- var buildSingle = function buildSingle(configCtx, envParams) {
155
- return new Promise(function ($return, $error) {
156
- var ctx, res, _ref, errors;
157
- ctx = new Ctx(configCtx);
158
- ctx.updateEnvParams(envParams);
159
- return Promise.resolve(buildBase(ctx)).then(function ($await_1) {
160
- try {
161
- res = $await_1;
162
- _ref = res || {}, errors = _ref.errors;
163
- if (errors !== null && errors !== void 0 && errors.length) {
164
- cLog.error('build', 'error', 'esbuld构建失败,捕获到错误');
165
- errors.forEach(function (message) {
166
- var detail = message.detail,
167
- id = message.id,
168
- location = message.location,
169
- notes = message.notes,
170
- pluginName = message.pluginName,
171
- text = message.text;
172
- console.log(id, location, pluginName, detail, notes, text);
173
- });
174
- return $return();
175
- }
176
- cLog.info('build', 'success', 'esbuld构建成功');
177
- return $return();
178
- } catch ($boundEx) {
179
- return $error($boundEx);
180
- }
181
- }, $error);
182
- });
183
- };
284
+ }, _callee);
285
+ })
286
+ );
287
+ return function buildSingle(_x, _x2) {
288
+ return _ref.apply(this, arguments);
289
+ };
290
+ })();
184
291
 
185
292
  export { buildSingle };
@@ -1,6 +1,9 @@
1
- import { TEnvParams } from '@doracli/esbuild';
2
- import { ConfigCtx } from '@doracli/helper';
1
+ import type { TEnvParams } from '@doracli/esbuild';
2
+ import type { ConfigCtx } from '@doracli/helper';
3
3
 
4
- declare const buildSingle: (configCtx: ConfigCtx, envParams: TEnvParams) => Promise<void>;
4
+ declare const buildSingle: (
5
+ configCtx: ConfigCtx,
6
+ envParams: TEnvParams
7
+ ) => Promise<void>;
5
8
 
6
9
  export { buildSingle };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doracli/esbuild-react",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "package by esbuild-react",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -31,13 +31,13 @@
31
31
  "build": "ccf build"
32
32
  },
33
33
  "dependencies": {
34
- "@cclr/lang": "^0.1.28",
35
- "@cclr/utils": "^0.1.28",
34
+ "@cclr/lang": "^0.1.44",
35
+ "@cclr/utils": "^0.1.44",
36
36
  "@dorabag/file-pro": "^1.0.10",
37
- "@doracli/commander": "0.0.3",
38
- "@doracli/esbuild": "0.0.3",
39
- "@doracli/helper": "0.0.3",
40
- "@doracli/type": "0.0.3"
37
+ "@doracli/commander": "0.0.4",
38
+ "@doracli/esbuild": "0.0.4",
39
+ "@doracli/helper": "0.0.4",
40
+ "@doracli/type": "0.0.4"
41
41
  },
42
- "gitHead": "c89b02be8c385738ad80749447133d30e00b1f75"
42
+ "gitHead": "a978bb7e7b32c192b1eb527dae5f25bbe1a2af86"
43
43
  }