@kubb/core 0.37.6 → 0.37.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.d.ts +383 -0
- package/dist/browser/index.global.js +169055 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/browser/index.js +1136 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/index.mjs +1112 -0
- package/dist/browser/index.mjs.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -5
|
@@ -0,0 +1,1136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var fse = require('fs-extra');
|
|
6
|
+
var prettier = require('prettier');
|
|
7
|
+
var EventEmitter = require('events');
|
|
8
|
+
var uuid = require('uuid');
|
|
9
|
+
var dirTree = require('directory-tree');
|
|
10
|
+
|
|
11
|
+
var __create = Object.create;
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
14
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __esm = (fn, res) => function __init() {
|
|
18
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
19
|
+
};
|
|
20
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
21
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.pnpm/tsup@6.5.0_typescript@4.9.4/node_modules/tsup/assets/cjs_shims.js
|
|
37
|
+
var init_cjs_shims = __esm({
|
|
38
|
+
"../../node_modules/.pnpm/tsup@6.5.0_typescript@4.9.4/node_modules/tsup/assets/cjs_shims.js"() {
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// ../../node_modules/.pnpm/path-browserify@1.0.1/node_modules/path-browserify/index.js
|
|
43
|
+
var require_path_browserify = __commonJS({
|
|
44
|
+
"../../node_modules/.pnpm/path-browserify@1.0.1/node_modules/path-browserify/index.js"(exports, module) {
|
|
45
|
+
init_cjs_shims();
|
|
46
|
+
function assertPath(path) {
|
|
47
|
+
if (typeof path !== "string") {
|
|
48
|
+
throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function normalizeStringPosix(path, allowAboveRoot) {
|
|
52
|
+
var res = "";
|
|
53
|
+
var lastSegmentLength = 0;
|
|
54
|
+
var lastSlash = -1;
|
|
55
|
+
var dots = 0;
|
|
56
|
+
var code;
|
|
57
|
+
for (var i = 0; i <= path.length; ++i) {
|
|
58
|
+
if (i < path.length)
|
|
59
|
+
code = path.charCodeAt(i);
|
|
60
|
+
else if (code === 47)
|
|
61
|
+
break;
|
|
62
|
+
else
|
|
63
|
+
code = 47;
|
|
64
|
+
if (code === 47) {
|
|
65
|
+
if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) {
|
|
66
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
67
|
+
if (res.length > 2) {
|
|
68
|
+
var lastSlashIndex = res.lastIndexOf("/");
|
|
69
|
+
if (lastSlashIndex !== res.length - 1) {
|
|
70
|
+
if (lastSlashIndex === -1) {
|
|
71
|
+
res = "";
|
|
72
|
+
lastSegmentLength = 0;
|
|
73
|
+
} else {
|
|
74
|
+
res = res.slice(0, lastSlashIndex);
|
|
75
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
76
|
+
}
|
|
77
|
+
lastSlash = i;
|
|
78
|
+
dots = 0;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
} else if (res.length === 2 || res.length === 1) {
|
|
82
|
+
res = "";
|
|
83
|
+
lastSegmentLength = 0;
|
|
84
|
+
lastSlash = i;
|
|
85
|
+
dots = 0;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (allowAboveRoot) {
|
|
90
|
+
if (res.length > 0)
|
|
91
|
+
res += "/..";
|
|
92
|
+
else
|
|
93
|
+
res = "..";
|
|
94
|
+
lastSegmentLength = 2;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
if (res.length > 0)
|
|
98
|
+
res += "/" + path.slice(lastSlash + 1, i);
|
|
99
|
+
else
|
|
100
|
+
res = path.slice(lastSlash + 1, i);
|
|
101
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
102
|
+
}
|
|
103
|
+
lastSlash = i;
|
|
104
|
+
dots = 0;
|
|
105
|
+
} else if (code === 46 && dots !== -1) {
|
|
106
|
+
++dots;
|
|
107
|
+
} else {
|
|
108
|
+
dots = -1;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return res;
|
|
112
|
+
}
|
|
113
|
+
function _format(sep, pathObject) {
|
|
114
|
+
var dir = pathObject.dir || pathObject.root;
|
|
115
|
+
var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
116
|
+
if (!dir) {
|
|
117
|
+
return base;
|
|
118
|
+
}
|
|
119
|
+
if (dir === pathObject.root) {
|
|
120
|
+
return dir + base;
|
|
121
|
+
}
|
|
122
|
+
return dir + sep + base;
|
|
123
|
+
}
|
|
124
|
+
var posix = {
|
|
125
|
+
resolve: function resolve() {
|
|
126
|
+
var resolvedPath = "";
|
|
127
|
+
var resolvedAbsolute = false;
|
|
128
|
+
var cwd;
|
|
129
|
+
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
130
|
+
var path;
|
|
131
|
+
if (i >= 0)
|
|
132
|
+
path = arguments[i];
|
|
133
|
+
else {
|
|
134
|
+
if (cwd === void 0)
|
|
135
|
+
cwd = process.cwd();
|
|
136
|
+
path = cwd;
|
|
137
|
+
}
|
|
138
|
+
assertPath(path);
|
|
139
|
+
if (path.length === 0) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
resolvedPath = path + "/" + resolvedPath;
|
|
143
|
+
resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
144
|
+
}
|
|
145
|
+
resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
|
|
146
|
+
if (resolvedAbsolute) {
|
|
147
|
+
if (resolvedPath.length > 0)
|
|
148
|
+
return "/" + resolvedPath;
|
|
149
|
+
else
|
|
150
|
+
return "/";
|
|
151
|
+
} else if (resolvedPath.length > 0) {
|
|
152
|
+
return resolvedPath;
|
|
153
|
+
} else {
|
|
154
|
+
return ".";
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
normalize: function normalize(path) {
|
|
158
|
+
assertPath(path);
|
|
159
|
+
if (path.length === 0)
|
|
160
|
+
return ".";
|
|
161
|
+
var isAbsolute = path.charCodeAt(0) === 47;
|
|
162
|
+
var trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
163
|
+
path = normalizeStringPosix(path, !isAbsolute);
|
|
164
|
+
if (path.length === 0 && !isAbsolute)
|
|
165
|
+
path = ".";
|
|
166
|
+
if (path.length > 0 && trailingSeparator)
|
|
167
|
+
path += "/";
|
|
168
|
+
if (isAbsolute)
|
|
169
|
+
return "/" + path;
|
|
170
|
+
return path;
|
|
171
|
+
},
|
|
172
|
+
isAbsolute: function isAbsolute(path) {
|
|
173
|
+
assertPath(path);
|
|
174
|
+
return path.length > 0 && path.charCodeAt(0) === 47;
|
|
175
|
+
},
|
|
176
|
+
join: function join() {
|
|
177
|
+
if (arguments.length === 0)
|
|
178
|
+
return ".";
|
|
179
|
+
var joined;
|
|
180
|
+
for (var i = 0; i < arguments.length; ++i) {
|
|
181
|
+
var arg = arguments[i];
|
|
182
|
+
assertPath(arg);
|
|
183
|
+
if (arg.length > 0) {
|
|
184
|
+
if (joined === void 0)
|
|
185
|
+
joined = arg;
|
|
186
|
+
else
|
|
187
|
+
joined += "/" + arg;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (joined === void 0)
|
|
191
|
+
return ".";
|
|
192
|
+
return posix.normalize(joined);
|
|
193
|
+
},
|
|
194
|
+
relative: function relative(from, to) {
|
|
195
|
+
assertPath(from);
|
|
196
|
+
assertPath(to);
|
|
197
|
+
if (from === to)
|
|
198
|
+
return "";
|
|
199
|
+
from = posix.resolve(from);
|
|
200
|
+
to = posix.resolve(to);
|
|
201
|
+
if (from === to)
|
|
202
|
+
return "";
|
|
203
|
+
var fromStart = 1;
|
|
204
|
+
for (; fromStart < from.length; ++fromStart) {
|
|
205
|
+
if (from.charCodeAt(fromStart) !== 47)
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
var fromEnd = from.length;
|
|
209
|
+
var fromLen = fromEnd - fromStart;
|
|
210
|
+
var toStart = 1;
|
|
211
|
+
for (; toStart < to.length; ++toStart) {
|
|
212
|
+
if (to.charCodeAt(toStart) !== 47)
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
var toEnd = to.length;
|
|
216
|
+
var toLen = toEnd - toStart;
|
|
217
|
+
var length = fromLen < toLen ? fromLen : toLen;
|
|
218
|
+
var lastCommonSep = -1;
|
|
219
|
+
var i = 0;
|
|
220
|
+
for (; i <= length; ++i) {
|
|
221
|
+
if (i === length) {
|
|
222
|
+
if (toLen > length) {
|
|
223
|
+
if (to.charCodeAt(toStart + i) === 47) {
|
|
224
|
+
return to.slice(toStart + i + 1);
|
|
225
|
+
} else if (i === 0) {
|
|
226
|
+
return to.slice(toStart + i);
|
|
227
|
+
}
|
|
228
|
+
} else if (fromLen > length) {
|
|
229
|
+
if (from.charCodeAt(fromStart + i) === 47) {
|
|
230
|
+
lastCommonSep = i;
|
|
231
|
+
} else if (i === 0) {
|
|
232
|
+
lastCommonSep = 0;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
var fromCode = from.charCodeAt(fromStart + i);
|
|
238
|
+
var toCode = to.charCodeAt(toStart + i);
|
|
239
|
+
if (fromCode !== toCode)
|
|
240
|
+
break;
|
|
241
|
+
else if (fromCode === 47)
|
|
242
|
+
lastCommonSep = i;
|
|
243
|
+
}
|
|
244
|
+
var out = "";
|
|
245
|
+
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
246
|
+
if (i === fromEnd || from.charCodeAt(i) === 47) {
|
|
247
|
+
if (out.length === 0)
|
|
248
|
+
out += "..";
|
|
249
|
+
else
|
|
250
|
+
out += "/..";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (out.length > 0)
|
|
254
|
+
return out + to.slice(toStart + lastCommonSep);
|
|
255
|
+
else {
|
|
256
|
+
toStart += lastCommonSep;
|
|
257
|
+
if (to.charCodeAt(toStart) === 47)
|
|
258
|
+
++toStart;
|
|
259
|
+
return to.slice(toStart);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
_makeLong: function _makeLong(path) {
|
|
263
|
+
return path;
|
|
264
|
+
},
|
|
265
|
+
dirname: function dirname(path) {
|
|
266
|
+
assertPath(path);
|
|
267
|
+
if (path.length === 0)
|
|
268
|
+
return ".";
|
|
269
|
+
var code = path.charCodeAt(0);
|
|
270
|
+
var hasRoot = code === 47;
|
|
271
|
+
var end = -1;
|
|
272
|
+
var matchedSlash = true;
|
|
273
|
+
for (var i = path.length - 1; i >= 1; --i) {
|
|
274
|
+
code = path.charCodeAt(i);
|
|
275
|
+
if (code === 47) {
|
|
276
|
+
if (!matchedSlash) {
|
|
277
|
+
end = i;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
matchedSlash = false;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (end === -1)
|
|
285
|
+
return hasRoot ? "/" : ".";
|
|
286
|
+
if (hasRoot && end === 1)
|
|
287
|
+
return "//";
|
|
288
|
+
return path.slice(0, end);
|
|
289
|
+
},
|
|
290
|
+
basename: function basename(path, ext) {
|
|
291
|
+
if (ext !== void 0 && typeof ext !== "string")
|
|
292
|
+
throw new TypeError('"ext" argument must be a string');
|
|
293
|
+
assertPath(path);
|
|
294
|
+
var start = 0;
|
|
295
|
+
var end = -1;
|
|
296
|
+
var matchedSlash = true;
|
|
297
|
+
var i;
|
|
298
|
+
if (ext !== void 0 && ext.length > 0 && ext.length <= path.length) {
|
|
299
|
+
if (ext.length === path.length && ext === path)
|
|
300
|
+
return "";
|
|
301
|
+
var extIdx = ext.length - 1;
|
|
302
|
+
var firstNonSlashEnd = -1;
|
|
303
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
304
|
+
var code = path.charCodeAt(i);
|
|
305
|
+
if (code === 47) {
|
|
306
|
+
if (!matchedSlash) {
|
|
307
|
+
start = i + 1;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
if (firstNonSlashEnd === -1) {
|
|
312
|
+
matchedSlash = false;
|
|
313
|
+
firstNonSlashEnd = i + 1;
|
|
314
|
+
}
|
|
315
|
+
if (extIdx >= 0) {
|
|
316
|
+
if (code === ext.charCodeAt(extIdx)) {
|
|
317
|
+
if (--extIdx === -1) {
|
|
318
|
+
end = i;
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
extIdx = -1;
|
|
322
|
+
end = firstNonSlashEnd;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (start === end)
|
|
328
|
+
end = firstNonSlashEnd;
|
|
329
|
+
else if (end === -1)
|
|
330
|
+
end = path.length;
|
|
331
|
+
return path.slice(start, end);
|
|
332
|
+
} else {
|
|
333
|
+
for (i = path.length - 1; i >= 0; --i) {
|
|
334
|
+
if (path.charCodeAt(i) === 47) {
|
|
335
|
+
if (!matchedSlash) {
|
|
336
|
+
start = i + 1;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
} else if (end === -1) {
|
|
340
|
+
matchedSlash = false;
|
|
341
|
+
end = i + 1;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (end === -1)
|
|
345
|
+
return "";
|
|
346
|
+
return path.slice(start, end);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
extname: function extname(path) {
|
|
350
|
+
assertPath(path);
|
|
351
|
+
var startDot = -1;
|
|
352
|
+
var startPart = 0;
|
|
353
|
+
var end = -1;
|
|
354
|
+
var matchedSlash = true;
|
|
355
|
+
var preDotState = 0;
|
|
356
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
357
|
+
var code = path.charCodeAt(i);
|
|
358
|
+
if (code === 47) {
|
|
359
|
+
if (!matchedSlash) {
|
|
360
|
+
startPart = i + 1;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (end === -1) {
|
|
366
|
+
matchedSlash = false;
|
|
367
|
+
end = i + 1;
|
|
368
|
+
}
|
|
369
|
+
if (code === 46) {
|
|
370
|
+
if (startDot === -1)
|
|
371
|
+
startDot = i;
|
|
372
|
+
else if (preDotState !== 1)
|
|
373
|
+
preDotState = 1;
|
|
374
|
+
} else if (startDot !== -1) {
|
|
375
|
+
preDotState = -1;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
379
|
+
return "";
|
|
380
|
+
}
|
|
381
|
+
return path.slice(startDot, end);
|
|
382
|
+
},
|
|
383
|
+
format: function format2(pathObject) {
|
|
384
|
+
if (pathObject === null || typeof pathObject !== "object") {
|
|
385
|
+
throw new TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
386
|
+
}
|
|
387
|
+
return _format("/", pathObject);
|
|
388
|
+
},
|
|
389
|
+
parse: function parse(path) {
|
|
390
|
+
assertPath(path);
|
|
391
|
+
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
392
|
+
if (path.length === 0)
|
|
393
|
+
return ret;
|
|
394
|
+
var code = path.charCodeAt(0);
|
|
395
|
+
var isAbsolute = code === 47;
|
|
396
|
+
var start;
|
|
397
|
+
if (isAbsolute) {
|
|
398
|
+
ret.root = "/";
|
|
399
|
+
start = 1;
|
|
400
|
+
} else {
|
|
401
|
+
start = 0;
|
|
402
|
+
}
|
|
403
|
+
var startDot = -1;
|
|
404
|
+
var startPart = 0;
|
|
405
|
+
var end = -1;
|
|
406
|
+
var matchedSlash = true;
|
|
407
|
+
var i = path.length - 1;
|
|
408
|
+
var preDotState = 0;
|
|
409
|
+
for (; i >= start; --i) {
|
|
410
|
+
code = path.charCodeAt(i);
|
|
411
|
+
if (code === 47) {
|
|
412
|
+
if (!matchedSlash) {
|
|
413
|
+
startPart = i + 1;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (end === -1) {
|
|
419
|
+
matchedSlash = false;
|
|
420
|
+
end = i + 1;
|
|
421
|
+
}
|
|
422
|
+
if (code === 46) {
|
|
423
|
+
if (startDot === -1)
|
|
424
|
+
startDot = i;
|
|
425
|
+
else if (preDotState !== 1)
|
|
426
|
+
preDotState = 1;
|
|
427
|
+
} else if (startDot !== -1) {
|
|
428
|
+
preDotState = -1;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
432
|
+
if (end !== -1) {
|
|
433
|
+
if (startPart === 0 && isAbsolute)
|
|
434
|
+
ret.base = ret.name = path.slice(1, end);
|
|
435
|
+
else
|
|
436
|
+
ret.base = ret.name = path.slice(startPart, end);
|
|
437
|
+
}
|
|
438
|
+
} else {
|
|
439
|
+
if (startPart === 0 && isAbsolute) {
|
|
440
|
+
ret.name = path.slice(1, startDot);
|
|
441
|
+
ret.base = path.slice(1, end);
|
|
442
|
+
} else {
|
|
443
|
+
ret.name = path.slice(startPart, startDot);
|
|
444
|
+
ret.base = path.slice(startPart, end);
|
|
445
|
+
}
|
|
446
|
+
ret.ext = path.slice(startDot, end);
|
|
447
|
+
}
|
|
448
|
+
if (startPart > 0)
|
|
449
|
+
ret.dir = path.slice(0, startPart - 1);
|
|
450
|
+
else if (isAbsolute)
|
|
451
|
+
ret.dir = "/";
|
|
452
|
+
return ret;
|
|
453
|
+
},
|
|
454
|
+
sep: "/",
|
|
455
|
+
delimiter: ":",
|
|
456
|
+
win32: null,
|
|
457
|
+
posix: null
|
|
458
|
+
};
|
|
459
|
+
posix.posix = posix;
|
|
460
|
+
module.exports = posix;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// src/index.ts
|
|
465
|
+
init_cjs_shims();
|
|
466
|
+
|
|
467
|
+
// src/build.ts
|
|
468
|
+
init_cjs_shims();
|
|
469
|
+
|
|
470
|
+
// src/managers/pluginManager/PluginManager.ts
|
|
471
|
+
init_cjs_shims();
|
|
472
|
+
|
|
473
|
+
// src/plugin.ts
|
|
474
|
+
init_cjs_shims();
|
|
475
|
+
var import_path2 = __toESM(require_path_browserify());
|
|
476
|
+
|
|
477
|
+
// src/utils/isPromise.ts
|
|
478
|
+
init_cjs_shims();
|
|
479
|
+
var isPromise = (result) => {
|
|
480
|
+
return typeof result?.then === "function";
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// src/utils/write.ts
|
|
484
|
+
init_cjs_shims();
|
|
485
|
+
|
|
486
|
+
// src/utils/format.ts
|
|
487
|
+
init_cjs_shims();
|
|
488
|
+
var formatOptions = {
|
|
489
|
+
tabWidth: 2,
|
|
490
|
+
printWidth: 160,
|
|
491
|
+
parser: "typescript",
|
|
492
|
+
singleQuote: true,
|
|
493
|
+
semi: false,
|
|
494
|
+
bracketSameLine: false,
|
|
495
|
+
endOfLine: "auto"
|
|
496
|
+
};
|
|
497
|
+
var format = (text) => {
|
|
498
|
+
return prettier.format(text, formatOptions);
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/utils/write.ts
|
|
502
|
+
var write = async (data, path, options = { format: false }) => {
|
|
503
|
+
const formattedData = options.format ? format(data) : data;
|
|
504
|
+
try {
|
|
505
|
+
await fse.stat(path);
|
|
506
|
+
const oldContent = await fse.readFile(path, { encoding: "utf-8" });
|
|
507
|
+
if (oldContent?.toString() === formattedData) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
} catch (_err) {
|
|
511
|
+
return fse.outputFile(path, formattedData, { encoding: "utf-8" });
|
|
512
|
+
}
|
|
513
|
+
return fse.outputFile(path, formattedData, { encoding: "utf-8" });
|
|
514
|
+
};
|
|
515
|
+
var clean = async (path) => {
|
|
516
|
+
return fse.remove(path);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
// src/utils/cache.ts
|
|
520
|
+
init_cjs_shims();
|
|
521
|
+
function createPluginCache(cache) {
|
|
522
|
+
return {
|
|
523
|
+
delete(id) {
|
|
524
|
+
return delete cache[id];
|
|
525
|
+
},
|
|
526
|
+
get(id) {
|
|
527
|
+
const item = cache[id];
|
|
528
|
+
if (!item)
|
|
529
|
+
return;
|
|
530
|
+
item[0] = 0;
|
|
531
|
+
return item[1];
|
|
532
|
+
},
|
|
533
|
+
has(id) {
|
|
534
|
+
const item = cache[id];
|
|
535
|
+
if (!item)
|
|
536
|
+
return false;
|
|
537
|
+
item[0] = 0;
|
|
538
|
+
return true;
|
|
539
|
+
},
|
|
540
|
+
set(id, value) {
|
|
541
|
+
cache[id] = [0, value];
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/utils/read.ts
|
|
547
|
+
init_cjs_shims();
|
|
548
|
+
var import_path = __toESM(require_path_browserify());
|
|
549
|
+
var getRelativePath = (root, file) => {
|
|
550
|
+
if (!root || !file) {
|
|
551
|
+
throw new Error("Root and file should be filled in when retrieving the relativePath");
|
|
552
|
+
}
|
|
553
|
+
const newPath = import_path.default.relative(root, file).replace("../", "").replace(".ts", "").trimEnd();
|
|
554
|
+
return `./${newPath}`;
|
|
555
|
+
};
|
|
556
|
+
var getPathMode = (path) => {
|
|
557
|
+
if (!path) {
|
|
558
|
+
return void 0;
|
|
559
|
+
}
|
|
560
|
+
return import_path.default.extname(path) ? "file" : "directory";
|
|
561
|
+
};
|
|
562
|
+
var read = async (path, encoding = "utf8") => {
|
|
563
|
+
try {
|
|
564
|
+
return fse.readFile(path, encoding);
|
|
565
|
+
} catch (err) {
|
|
566
|
+
console.error(err);
|
|
567
|
+
throw err;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
// src/plugin.ts
|
|
572
|
+
function createPlugin(factory) {
|
|
573
|
+
return (options) => {
|
|
574
|
+
const plugin = factory(options);
|
|
575
|
+
if (Array.isArray(plugin)) {
|
|
576
|
+
throw new Error("Not implemented");
|
|
577
|
+
}
|
|
578
|
+
if (!plugin.transform) {
|
|
579
|
+
plugin.transform = function transform(code) {
|
|
580
|
+
return code;
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
return plugin;
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
var name = "core";
|
|
587
|
+
var isEmittedFile = (result) => {
|
|
588
|
+
return !!result.id;
|
|
589
|
+
};
|
|
590
|
+
var definePlugin = createPlugin((options) => {
|
|
591
|
+
const { fileManager, resolveId, load } = options;
|
|
592
|
+
const api = {
|
|
593
|
+
get config() {
|
|
594
|
+
return options.config;
|
|
595
|
+
},
|
|
596
|
+
fileManager,
|
|
597
|
+
async addFile(file, options2) {
|
|
598
|
+
if (isEmittedFile(file)) {
|
|
599
|
+
const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
|
|
600
|
+
const path = resolvedId || file.importer || file.id;
|
|
601
|
+
return fileManager.add({
|
|
602
|
+
path,
|
|
603
|
+
fileName: file.name || file.id,
|
|
604
|
+
source: file.source || ""
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
if (options2?.root) ;
|
|
608
|
+
return fileManager.addOrAppend(file);
|
|
609
|
+
},
|
|
610
|
+
resolveId,
|
|
611
|
+
load,
|
|
612
|
+
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
613
|
+
};
|
|
614
|
+
return {
|
|
615
|
+
name,
|
|
616
|
+
api,
|
|
617
|
+
resolveId(fileName, directory) {
|
|
618
|
+
if (!directory) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
return import_path2.default.resolve(directory, fileName);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// src/managers/fileManager/FileManager.ts
|
|
627
|
+
init_cjs_shims();
|
|
628
|
+
|
|
629
|
+
// src/managers/fileManager/events.ts
|
|
630
|
+
init_cjs_shims();
|
|
631
|
+
var keys = {
|
|
632
|
+
getFileKey: () => `file`,
|
|
633
|
+
getStatusChangeKey: () => `status-change`,
|
|
634
|
+
getStatusChangeByIdKey: (id) => `${id}-status-change`,
|
|
635
|
+
getSuccessKey: () => `success`,
|
|
636
|
+
getRemoveKey: (id) => `${id}remove`
|
|
637
|
+
};
|
|
638
|
+
var getFileManagerEvents = (emitter) => {
|
|
639
|
+
return {
|
|
640
|
+
emitFile: (id, file) => {
|
|
641
|
+
emitter.emit(keys.getFileKey(), id, file);
|
|
642
|
+
},
|
|
643
|
+
emitStatusChange: (file) => {
|
|
644
|
+
emitter.emit(keys.getStatusChangeKey(), file);
|
|
645
|
+
},
|
|
646
|
+
emitStatusChangeById: (id, status) => {
|
|
647
|
+
emitter.emit(keys.getStatusChangeByIdKey(id), status);
|
|
648
|
+
},
|
|
649
|
+
emitSuccess: () => {
|
|
650
|
+
emitter.emit(keys.getSuccessKey());
|
|
651
|
+
},
|
|
652
|
+
emitRemove: (id, file) => {
|
|
653
|
+
emitter.emit(keys.getRemoveKey(id), file);
|
|
654
|
+
},
|
|
655
|
+
onAdd: (callback) => {
|
|
656
|
+
emitter.on(keys.getFileKey(), callback);
|
|
657
|
+
return () => emitter.removeListener(keys.getFileKey(), callback);
|
|
658
|
+
},
|
|
659
|
+
onStatusChange: (callback) => {
|
|
660
|
+
emitter.on(keys.getStatusChangeKey(), callback);
|
|
661
|
+
return () => emitter.removeListener(keys.getStatusChangeKey(), callback);
|
|
662
|
+
},
|
|
663
|
+
onStatusChangeById: (id, callback) => {
|
|
664
|
+
emitter.on(keys.getStatusChangeByIdKey(id), callback);
|
|
665
|
+
return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback);
|
|
666
|
+
},
|
|
667
|
+
onSuccess: (callback) => {
|
|
668
|
+
emitter.on(keys.getSuccessKey(), callback);
|
|
669
|
+
return () => emitter.removeListener(keys.getSuccessKey(), callback);
|
|
670
|
+
},
|
|
671
|
+
onRemove: (id, callback) => {
|
|
672
|
+
emitter.on(keys.getRemoveKey(id), callback);
|
|
673
|
+
return () => emitter.removeListener(keys.getRemoveKey(id), callback);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
// src/managers/fileManager/FileManager.ts
|
|
679
|
+
var FileManager = class {
|
|
680
|
+
cache = /* @__PURE__ */ new Map();
|
|
681
|
+
emitter = new EventEmitter();
|
|
682
|
+
events = getFileManagerEvents(this.emitter);
|
|
683
|
+
constructor() {
|
|
684
|
+
this.events.onStatusChange(() => {
|
|
685
|
+
if (this.getCountByStatus("removed") === this.cache.size) {
|
|
686
|
+
this.events.emitSuccess();
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
getCache(id) {
|
|
691
|
+
return this.cache.get(id);
|
|
692
|
+
}
|
|
693
|
+
getCacheByPath(path) {
|
|
694
|
+
let cache;
|
|
695
|
+
this.cache.forEach((item) => {
|
|
696
|
+
if (item.file.path === path) {
|
|
697
|
+
cache = item;
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
return cache;
|
|
701
|
+
}
|
|
702
|
+
getCountByStatus(status) {
|
|
703
|
+
let count = 0;
|
|
704
|
+
this.cache.forEach((item) => {
|
|
705
|
+
if (item.status === status) {
|
|
706
|
+
count++;
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
return count;
|
|
710
|
+
}
|
|
711
|
+
get files() {
|
|
712
|
+
const files = [];
|
|
713
|
+
this.cache.forEach((item) => {
|
|
714
|
+
files.push(item.file);
|
|
715
|
+
});
|
|
716
|
+
return files;
|
|
717
|
+
}
|
|
718
|
+
add(file) {
|
|
719
|
+
const cacheItem = { id: uuid.v4(), file, status: "new" };
|
|
720
|
+
this.cache.set(cacheItem.id, cacheItem);
|
|
721
|
+
this.events.emitFile(cacheItem.id, file);
|
|
722
|
+
return new Promise((resolve) => {
|
|
723
|
+
const unsubscribe = this.events.onRemove(cacheItem.id, (file2) => {
|
|
724
|
+
resolve(file2);
|
|
725
|
+
unsubscribe();
|
|
726
|
+
});
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
addOrAppend(file) {
|
|
730
|
+
const previousCache = this.getCacheByPath(file.path);
|
|
731
|
+
if (previousCache) {
|
|
732
|
+
this.remove(previousCache.id);
|
|
733
|
+
return this.add({
|
|
734
|
+
...file,
|
|
735
|
+
source: `${previousCache.file.source}
|
|
736
|
+
${file.source}`
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
return this.add(file);
|
|
740
|
+
}
|
|
741
|
+
setStatus(id, status) {
|
|
742
|
+
const cacheItem = this.getCache(id);
|
|
743
|
+
if (!cacheItem) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
cacheItem.status = status;
|
|
747
|
+
this.cache.set(id, cacheItem);
|
|
748
|
+
this.events.emitStatusChange(cacheItem.file);
|
|
749
|
+
this.events.emitStatusChangeById(id, status);
|
|
750
|
+
}
|
|
751
|
+
get(id) {
|
|
752
|
+
const cacheItem = this.getCache(id);
|
|
753
|
+
return cacheItem?.file;
|
|
754
|
+
}
|
|
755
|
+
remove(id) {
|
|
756
|
+
const cacheItem = this.getCache(id);
|
|
757
|
+
if (!cacheItem) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
this.setStatus(id, "removed");
|
|
761
|
+
this.events.emitRemove(id, cacheItem.file);
|
|
762
|
+
}
|
|
763
|
+
async write(...params) {
|
|
764
|
+
return write(...params);
|
|
765
|
+
}
|
|
766
|
+
async read(...params) {
|
|
767
|
+
return read(...params);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// src/managers/fileManager/TreeNode.ts
|
|
772
|
+
init_cjs_shims();
|
|
773
|
+
var TreeNode = class {
|
|
774
|
+
data;
|
|
775
|
+
parent;
|
|
776
|
+
children;
|
|
777
|
+
constructor(data, parent) {
|
|
778
|
+
this.data = data;
|
|
779
|
+
this.parent = parent;
|
|
780
|
+
return this;
|
|
781
|
+
}
|
|
782
|
+
addChild(data) {
|
|
783
|
+
const child = new TreeNode(data, this);
|
|
784
|
+
if (!this.children) {
|
|
785
|
+
this.children = [];
|
|
786
|
+
}
|
|
787
|
+
this.children.push(child);
|
|
788
|
+
return child;
|
|
789
|
+
}
|
|
790
|
+
find(data) {
|
|
791
|
+
if (data === this.data) {
|
|
792
|
+
return this;
|
|
793
|
+
}
|
|
794
|
+
if (this.children) {
|
|
795
|
+
for (let i = 0, { length } = this.children, target = null; i < length; i++) {
|
|
796
|
+
target = this.children[i].find(data);
|
|
797
|
+
if (target) {
|
|
798
|
+
return target;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
leaves() {
|
|
805
|
+
if (!this.children || this.children.length === 0) {
|
|
806
|
+
return [this];
|
|
807
|
+
}
|
|
808
|
+
const leaves = [];
|
|
809
|
+
if (this.children) {
|
|
810
|
+
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
811
|
+
leaves.push.apply(leaves, this.children[i].leaves());
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
return leaves;
|
|
815
|
+
}
|
|
816
|
+
root() {
|
|
817
|
+
if (!this.parent) {
|
|
818
|
+
return this;
|
|
819
|
+
}
|
|
820
|
+
return this.parent.root();
|
|
821
|
+
}
|
|
822
|
+
forEach(callback) {
|
|
823
|
+
if (typeof callback !== "function") {
|
|
824
|
+
throw new TypeError("forEach() callback must be a function");
|
|
825
|
+
}
|
|
826
|
+
callback(this);
|
|
827
|
+
if (this.children) {
|
|
828
|
+
for (let i = 0, { length } = this.children; i < length; i++) {
|
|
829
|
+
this.children[i].forEach(callback);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
return this;
|
|
833
|
+
}
|
|
834
|
+
static build(path, options = {}) {
|
|
835
|
+
const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
|
|
836
|
+
if (!filteredTree) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
|
|
840
|
+
const recurse = (node, item) => {
|
|
841
|
+
const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
|
|
842
|
+
if (item.children?.length) {
|
|
843
|
+
item.children?.forEach((child) => {
|
|
844
|
+
recurse(subNode, child);
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
filteredTree.children?.forEach((child) => recurse(treeNode, child));
|
|
849
|
+
return treeNode;
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
// src/managers/pluginManager/PluginManager.ts
|
|
854
|
+
var hookNames = {
|
|
855
|
+
validate: 1,
|
|
856
|
+
buildStart: 1,
|
|
857
|
+
resolveId: 1,
|
|
858
|
+
load: 1,
|
|
859
|
+
transform: 1,
|
|
860
|
+
writeFile: 1,
|
|
861
|
+
buildEnd: 1
|
|
862
|
+
};
|
|
863
|
+
var hooks = Object.keys(hookNames);
|
|
864
|
+
var PluginManager = class {
|
|
865
|
+
plugins;
|
|
866
|
+
fileManager;
|
|
867
|
+
logger;
|
|
868
|
+
config;
|
|
869
|
+
core;
|
|
870
|
+
constructor(config, options) {
|
|
871
|
+
this.logger = options.logger;
|
|
872
|
+
this.config = config;
|
|
873
|
+
this.fileManager = new FileManager();
|
|
874
|
+
this.core = definePlugin({
|
|
875
|
+
config,
|
|
876
|
+
fileManager: this.fileManager,
|
|
877
|
+
load: this.load,
|
|
878
|
+
resolveId: this.resolveId
|
|
879
|
+
});
|
|
880
|
+
this.plugins = [this.core, ...config.plugins || []];
|
|
881
|
+
}
|
|
882
|
+
resolveId = (params) => {
|
|
883
|
+
if (params.pluginName) {
|
|
884
|
+
return this.hookForPlugin(params.pluginName, "resolveId", [params.fileName, params.directory, params.options]);
|
|
885
|
+
}
|
|
886
|
+
return this.hookFirst("resolveId", [params.fileName, params.directory, params.options]);
|
|
887
|
+
};
|
|
888
|
+
load = async (id) => {
|
|
889
|
+
return this.hookFirst("load", [id]);
|
|
890
|
+
};
|
|
891
|
+
hookForPlugin(pluginName, hookName, parameters, skipped) {
|
|
892
|
+
let promise = Promise.resolve(null);
|
|
893
|
+
for (const plugin of this.getSortedPlugins(hookName, pluginName)) {
|
|
894
|
+
if (skipped && skipped.has(plugin))
|
|
895
|
+
continue;
|
|
896
|
+
promise = promise.then((result) => {
|
|
897
|
+
if (result != null)
|
|
898
|
+
return result;
|
|
899
|
+
return this.run("hookFirst", hookName, parameters, plugin);
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
return promise;
|
|
903
|
+
}
|
|
904
|
+
hookFirst(hookName, parameters, skipped) {
|
|
905
|
+
let promise = Promise.resolve(null);
|
|
906
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
907
|
+
if (skipped && skipped.has(plugin))
|
|
908
|
+
continue;
|
|
909
|
+
promise = promise.then((result) => {
|
|
910
|
+
if (result != null)
|
|
911
|
+
return result;
|
|
912
|
+
return this.run("hookFirst", hookName, parameters, plugin);
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
return promise;
|
|
916
|
+
}
|
|
917
|
+
async hookParallel(hookName, parameters) {
|
|
918
|
+
const parallelPromises = [];
|
|
919
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
920
|
+
if (plugin[hookName]?.sequential) {
|
|
921
|
+
await Promise.all(parallelPromises);
|
|
922
|
+
parallelPromises.length = 0;
|
|
923
|
+
await this.run("hookParallel", hookName, parameters, plugin);
|
|
924
|
+
} else {
|
|
925
|
+
const promise = this.run("hookParallel", hookName, parameters, plugin);
|
|
926
|
+
parallelPromises.push(promise);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return Promise.all(parallelPromises);
|
|
930
|
+
}
|
|
931
|
+
hookReduceArg0(hookName, [argument0, ...rest], reduce) {
|
|
932
|
+
let promise = Promise.resolve(argument0);
|
|
933
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
934
|
+
promise = promise.then(
|
|
935
|
+
(argument02) => this.run("hookReduceArg0", hookName, [argument02, ...rest], plugin).then(
|
|
936
|
+
(result) => reduce.call(this.core.api, argument02, result, plugin)
|
|
937
|
+
)
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
return promise;
|
|
941
|
+
}
|
|
942
|
+
hookSeq(hookName, parameters) {
|
|
943
|
+
let promise = Promise.resolve();
|
|
944
|
+
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
945
|
+
promise = promise.then(() => this.run("hookSeq", hookName, parameters, plugin));
|
|
946
|
+
}
|
|
947
|
+
return promise.then(noReturn);
|
|
948
|
+
}
|
|
949
|
+
getSortedPlugins(hookName, pluginName) {
|
|
950
|
+
const plugins = [...this.plugins];
|
|
951
|
+
if (pluginName) {
|
|
952
|
+
const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName]);
|
|
953
|
+
if (pluginsByPluginName.length === 0) {
|
|
954
|
+
if (this.config.logLevel === "warn" && this.logger?.spinner) {
|
|
955
|
+
this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`);
|
|
956
|
+
}
|
|
957
|
+
return [this.core];
|
|
958
|
+
}
|
|
959
|
+
return pluginsByPluginName;
|
|
960
|
+
}
|
|
961
|
+
return plugins;
|
|
962
|
+
}
|
|
963
|
+
run(strategy, hookName, parameters, plugin) {
|
|
964
|
+
const hook = plugin[hookName];
|
|
965
|
+
return Promise.resolve().then(() => {
|
|
966
|
+
if (typeof hook !== "function") {
|
|
967
|
+
return hook;
|
|
968
|
+
}
|
|
969
|
+
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
970
|
+
this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
971
|
+
`;
|
|
972
|
+
}
|
|
973
|
+
const hookResult = hook.apply(this.core.api, parameters);
|
|
974
|
+
if (!hookResult?.then) {
|
|
975
|
+
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
976
|
+
this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
977
|
+
`);
|
|
978
|
+
}
|
|
979
|
+
return hookResult;
|
|
980
|
+
}
|
|
981
|
+
return Promise.resolve(hookResult).then((result) => {
|
|
982
|
+
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
983
|
+
this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
984
|
+
`);
|
|
985
|
+
}
|
|
986
|
+
return result;
|
|
987
|
+
});
|
|
988
|
+
}).catch((e) => this.catcher(e, plugin, hookName));
|
|
989
|
+
}
|
|
990
|
+
runSync(hookName, parameters, plugin) {
|
|
991
|
+
const hook = plugin[hookName];
|
|
992
|
+
try {
|
|
993
|
+
return hook.apply(this.core.api, parameters);
|
|
994
|
+
} catch (error) {
|
|
995
|
+
return error;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
catcher(e, plugin, hookName) {
|
|
999
|
+
const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})
|
|
1000
|
+
`;
|
|
1001
|
+
if (this.logger?.spinner) {
|
|
1002
|
+
this.logger.spinner.fail(text);
|
|
1003
|
+
throw e;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
function noReturn() {
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// src/managers/pluginManager/validate.ts
|
|
1011
|
+
init_cjs_shims();
|
|
1012
|
+
var ValidationPluginError = class extends Error {
|
|
1013
|
+
};
|
|
1014
|
+
var validatePlugins = (plugins, dependedPluginNames) => {
|
|
1015
|
+
let pluginNames = [];
|
|
1016
|
+
if (typeof dependedPluginNames === "string") {
|
|
1017
|
+
pluginNames = [dependedPluginNames];
|
|
1018
|
+
} else {
|
|
1019
|
+
pluginNames = dependedPluginNames;
|
|
1020
|
+
}
|
|
1021
|
+
pluginNames.forEach((pluginName) => {
|
|
1022
|
+
const exists = plugins.some((plugin) => plugin.name === pluginName);
|
|
1023
|
+
if (!exists) {
|
|
1024
|
+
throw new ValidationPluginError(`This plugin depends on the ${pluginName} plugin.`);
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
return true;
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// src/build.ts
|
|
1031
|
+
async function transformReducer(_previousCode, result, _plugin) {
|
|
1032
|
+
if (result === null) {
|
|
1033
|
+
return null;
|
|
1034
|
+
}
|
|
1035
|
+
return result;
|
|
1036
|
+
}
|
|
1037
|
+
async function buildImplementation(options, done) {
|
|
1038
|
+
const { config, logger } = options;
|
|
1039
|
+
if (config.output.clean) {
|
|
1040
|
+
await clean(config.output.path);
|
|
1041
|
+
}
|
|
1042
|
+
const pluginManager = new PluginManager(config, { logger });
|
|
1043
|
+
const { plugins, fileManager } = pluginManager;
|
|
1044
|
+
try {
|
|
1045
|
+
await pluginManager.hookParallel("validate", [plugins]);
|
|
1046
|
+
} catch (e) {
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
fileManager.events.onSuccess(async () => {
|
|
1050
|
+
await pluginManager.hookParallel("buildEnd");
|
|
1051
|
+
setTimeout(() => {
|
|
1052
|
+
done({ fileManager });
|
|
1053
|
+
}, 1e3);
|
|
1054
|
+
});
|
|
1055
|
+
fileManager.events.onAdd(async (id, file) => {
|
|
1056
|
+
const { path } = file;
|
|
1057
|
+
let { source: code } = file;
|
|
1058
|
+
const loadedResult = await pluginManager.hookFirst("load", [path]);
|
|
1059
|
+
if (loadedResult) {
|
|
1060
|
+
code = loadedResult;
|
|
1061
|
+
}
|
|
1062
|
+
if (code) {
|
|
1063
|
+
const transformedCode = await pluginManager.hookReduceArg0("transform", [code, path], transformReducer);
|
|
1064
|
+
if (typeof config.input === "object") {
|
|
1065
|
+
await pluginManager.hookParallel("writeFile", [transformedCode, path]);
|
|
1066
|
+
}
|
|
1067
|
+
fileManager.setStatus(id, "success");
|
|
1068
|
+
fileManager.remove(id);
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
await pluginManager.hookParallel("buildStart", [config]);
|
|
1072
|
+
}
|
|
1073
|
+
function build(options) {
|
|
1074
|
+
return new Promise((resolve, reject) => {
|
|
1075
|
+
try {
|
|
1076
|
+
buildImplementation(options, resolve);
|
|
1077
|
+
} catch (e) {
|
|
1078
|
+
reject(e);
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// src/config.ts
|
|
1084
|
+
init_cjs_shims();
|
|
1085
|
+
var defineConfig = (options) => options;
|
|
1086
|
+
|
|
1087
|
+
// src/generators/SchemaGenerator.ts
|
|
1088
|
+
init_cjs_shims();
|
|
1089
|
+
|
|
1090
|
+
// src/generators/Generator.ts
|
|
1091
|
+
init_cjs_shims();
|
|
1092
|
+
var Generator = class {
|
|
1093
|
+
_options = {};
|
|
1094
|
+
constructor(options = {}) {
|
|
1095
|
+
if (options) {
|
|
1096
|
+
this._options = {
|
|
1097
|
+
...this._options,
|
|
1098
|
+
...options
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
return this;
|
|
1102
|
+
}
|
|
1103
|
+
get options() {
|
|
1104
|
+
return this._options;
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
|
|
1108
|
+
// src/generators/SchemaGenerator.ts
|
|
1109
|
+
var SchemaGenerator = class extends Generator {
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
// src/index.ts
|
|
1113
|
+
var src_default = build;
|
|
1114
|
+
|
|
1115
|
+
exports.FileManager = FileManager;
|
|
1116
|
+
exports.Generator = Generator;
|
|
1117
|
+
exports.PluginManager = PluginManager;
|
|
1118
|
+
exports.SchemaGenerator = SchemaGenerator;
|
|
1119
|
+
exports.TreeNode = TreeNode;
|
|
1120
|
+
exports.ValidationPluginError = ValidationPluginError;
|
|
1121
|
+
exports.build = build;
|
|
1122
|
+
exports.clean = clean;
|
|
1123
|
+
exports.createPlugin = createPlugin;
|
|
1124
|
+
exports.createPluginCache = createPluginCache;
|
|
1125
|
+
exports.default = src_default;
|
|
1126
|
+
exports.defineConfig = defineConfig;
|
|
1127
|
+
exports.format = format;
|
|
1128
|
+
exports.getPathMode = getPathMode;
|
|
1129
|
+
exports.getRelativePath = getRelativePath;
|
|
1130
|
+
exports.hooks = hooks;
|
|
1131
|
+
exports.isPromise = isPromise;
|
|
1132
|
+
exports.read = read;
|
|
1133
|
+
exports.validatePlugins = validatePlugins;
|
|
1134
|
+
exports.write = write;
|
|
1135
|
+
//# sourceMappingURL=out.js.map
|
|
1136
|
+
//# sourceMappingURL=index.js.map
|