@driveflux/fab 1.0.0-next.0 → 1.0.0-next.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/.turbo/turbo-build.log +14 -13
- package/CHANGELOG.md +12 -0
- package/bin/fab.js +7 -6
- package/dist/build.d.ts +7 -5
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +112 -29
- package/dist/clean.js +2 -2
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -1
- package/dist/src/build.js +737 -0
- package/dist/src/clean.js +258 -0
- package/dist/src/config.js +279 -0
- package/dist/src/create.js +270 -0
- package/dist/src/index.js +5 -0
- package/dist/src/types.js +1 -0
- package/dist/src/utils.js +308 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/package.json +13 -10
- package/src/build.ts +46 -11
- package/src/clean.ts +1 -1
- package/src/config.ts +2 -0
- package/src/utils.ts +4 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _iterable_to_array_limit(arr, i) {
|
|
39
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
|
+
if (_i == null) return;
|
|
41
|
+
var _arr = [];
|
|
42
|
+
var _n = true;
|
|
43
|
+
var _d = false;
|
|
44
|
+
var _s, _e;
|
|
45
|
+
try {
|
|
46
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
47
|
+
_arr.push(_s.value);
|
|
48
|
+
if (i && _arr.length === i) break;
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_d = true;
|
|
52
|
+
_e = err;
|
|
53
|
+
} finally{
|
|
54
|
+
try {
|
|
55
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
56
|
+
} finally{
|
|
57
|
+
if (_d) throw _e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return _arr;
|
|
61
|
+
}
|
|
62
|
+
function _non_iterable_rest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
function _sliced_to_array(arr, i) {
|
|
66
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
67
|
+
}
|
|
68
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
69
|
+
if (!o) return;
|
|
70
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
71
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
72
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
73
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
74
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
75
|
+
}
|
|
76
|
+
function _ts_generator(thisArg, body) {
|
|
77
|
+
var f, y, t, g, _ = {
|
|
78
|
+
label: 0,
|
|
79
|
+
sent: function() {
|
|
80
|
+
if (t[0] & 1) throw t[1];
|
|
81
|
+
return t[1];
|
|
82
|
+
},
|
|
83
|
+
trys: [],
|
|
84
|
+
ops: []
|
|
85
|
+
};
|
|
86
|
+
return g = {
|
|
87
|
+
next: verb(0),
|
|
88
|
+
"throw": verb(1),
|
|
89
|
+
"return": verb(2)
|
|
90
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
91
|
+
return this;
|
|
92
|
+
}), g;
|
|
93
|
+
function verb(n) {
|
|
94
|
+
return function(v) {
|
|
95
|
+
return step([
|
|
96
|
+
n,
|
|
97
|
+
v
|
|
98
|
+
]);
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function step(op) {
|
|
102
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
103
|
+
while(_)try {
|
|
104
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
105
|
+
if (y = 0, t) op = [
|
|
106
|
+
op[0] & 2,
|
|
107
|
+
t.value
|
|
108
|
+
];
|
|
109
|
+
switch(op[0]){
|
|
110
|
+
case 0:
|
|
111
|
+
case 1:
|
|
112
|
+
t = op;
|
|
113
|
+
break;
|
|
114
|
+
case 4:
|
|
115
|
+
_.label++;
|
|
116
|
+
return {
|
|
117
|
+
value: op[1],
|
|
118
|
+
done: false
|
|
119
|
+
};
|
|
120
|
+
case 5:
|
|
121
|
+
_.label++;
|
|
122
|
+
y = op[1];
|
|
123
|
+
op = [
|
|
124
|
+
0
|
|
125
|
+
];
|
|
126
|
+
continue;
|
|
127
|
+
case 7:
|
|
128
|
+
op = _.ops.pop();
|
|
129
|
+
_.trys.pop();
|
|
130
|
+
continue;
|
|
131
|
+
default:
|
|
132
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
133
|
+
_ = 0;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
137
|
+
_.label = op[1];
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
141
|
+
_.label = t[1];
|
|
142
|
+
t = op;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
if (t && _.label < t[2]) {
|
|
146
|
+
_.label = t[2];
|
|
147
|
+
_.ops.push(op);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
if (t[2]) _.ops.pop();
|
|
151
|
+
_.trys.pop();
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
op = body.call(thisArg, _);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
op = [
|
|
157
|
+
6,
|
|
158
|
+
e
|
|
159
|
+
];
|
|
160
|
+
y = 0;
|
|
161
|
+
} finally{
|
|
162
|
+
f = t = 0;
|
|
163
|
+
}
|
|
164
|
+
if (op[0] & 5) throw op[1];
|
|
165
|
+
return {
|
|
166
|
+
value: op[0] ? op[1] : void 0,
|
|
167
|
+
done: true
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
import fg from "fast-glob";
|
|
172
|
+
import assert from "node:assert";
|
|
173
|
+
import fs from "node:fs/promises";
|
|
174
|
+
import path from "node:path";
|
|
175
|
+
import { clean } from "./clean.js";
|
|
176
|
+
import { ensureDir, getDefaultOptions, runCommand, validatePackageJson } from "./utils.js";
|
|
177
|
+
var glob = fg.glob;
|
|
178
|
+
export var build = function() {
|
|
179
|
+
var _ref = _async_to_generator(function() {
|
|
180
|
+
var options, promises;
|
|
181
|
+
var _arguments = arguments;
|
|
182
|
+
return _ts_generator(this, function(_state) {
|
|
183
|
+
switch(_state.label){
|
|
184
|
+
case 0:
|
|
185
|
+
options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : getDefaultOptions();
|
|
186
|
+
// Cleanup first
|
|
187
|
+
return [
|
|
188
|
+
4,
|
|
189
|
+
clean(options)
|
|
190
|
+
];
|
|
191
|
+
case 1:
|
|
192
|
+
_state.sent();
|
|
193
|
+
promises = [];
|
|
194
|
+
if (!options.noESM) {
|
|
195
|
+
promises.push(buildEsm(options));
|
|
196
|
+
}
|
|
197
|
+
if (!options.noTypes) {
|
|
198
|
+
promises.push(buildTypes(options));
|
|
199
|
+
}
|
|
200
|
+
if (!options.noCJS) {
|
|
201
|
+
promises.push(buildCjs(options));
|
|
202
|
+
}
|
|
203
|
+
// Build necessary files
|
|
204
|
+
return [
|
|
205
|
+
4,
|
|
206
|
+
Promise.all(promises)
|
|
207
|
+
];
|
|
208
|
+
case 2:
|
|
209
|
+
_state.sent();
|
|
210
|
+
// Make exports for CJS
|
|
211
|
+
return [
|
|
212
|
+
4,
|
|
213
|
+
makeBaseExports(options)
|
|
214
|
+
];
|
|
215
|
+
case 3:
|
|
216
|
+
_state.sent();
|
|
217
|
+
return [
|
|
218
|
+
2
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
return function build() {
|
|
224
|
+
return _ref.apply(this, arguments);
|
|
225
|
+
};
|
|
226
|
+
}();
|
|
227
|
+
export var buildTypes = function() {
|
|
228
|
+
var _ref = _async_to_generator(function() {
|
|
229
|
+
var options;
|
|
230
|
+
var _arguments = arguments;
|
|
231
|
+
return _ts_generator(this, function(_state) {
|
|
232
|
+
switch(_state.label){
|
|
233
|
+
case 0:
|
|
234
|
+
options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : getDefaultOptions();
|
|
235
|
+
return [
|
|
236
|
+
4,
|
|
237
|
+
validatePackageJson({
|
|
238
|
+
command: "tsc",
|
|
239
|
+
cwd: options.cwd
|
|
240
|
+
})
|
|
241
|
+
];
|
|
242
|
+
case 1:
|
|
243
|
+
_state.sent();
|
|
244
|
+
return [
|
|
245
|
+
4,
|
|
246
|
+
runCommand("pnpm", [
|
|
247
|
+
"tsc",
|
|
248
|
+
"--emitDeclarationOnly",
|
|
249
|
+
"--declarationMap"
|
|
250
|
+
], {
|
|
251
|
+
cwd: options.cwd
|
|
252
|
+
})
|
|
253
|
+
];
|
|
254
|
+
case 2:
|
|
255
|
+
_state.sent();
|
|
256
|
+
return [
|
|
257
|
+
2
|
|
258
|
+
];
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
return function buildTypes() {
|
|
263
|
+
return _ref.apply(this, arguments);
|
|
264
|
+
};
|
|
265
|
+
}();
|
|
266
|
+
export var buildCjs = function() {
|
|
267
|
+
var _ref = _async_to_generator(function() {
|
|
268
|
+
var options, _options_cwd, cwd, _options_destination, destination, cjsPath, targetPath;
|
|
269
|
+
var _arguments = arguments;
|
|
270
|
+
return _ts_generator(this, function(_state) {
|
|
271
|
+
switch(_state.label){
|
|
272
|
+
case 0:
|
|
273
|
+
options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : getDefaultOptions();
|
|
274
|
+
cwd = (_options_cwd = options.cwd) !== null && _options_cwd !== void 0 ? _options_cwd : process.cwd();
|
|
275
|
+
destination = (_options_destination = options.destination) !== null && _options_destination !== void 0 ? _options_destination : getDefaultOptions().destination;
|
|
276
|
+
cjsPath = path.resolve(destination, "cjs");
|
|
277
|
+
return [
|
|
278
|
+
4,
|
|
279
|
+
validatePackageJson({
|
|
280
|
+
command: "swc",
|
|
281
|
+
cwd: cwd
|
|
282
|
+
})
|
|
283
|
+
];
|
|
284
|
+
case 1:
|
|
285
|
+
_state.sent();
|
|
286
|
+
// We start by emitting the CJS files
|
|
287
|
+
return [
|
|
288
|
+
4,
|
|
289
|
+
runCommand("pnpm", [
|
|
290
|
+
"swc",
|
|
291
|
+
"src",
|
|
292
|
+
"-C",
|
|
293
|
+
"module.type=commonjs",
|
|
294
|
+
"-d",
|
|
295
|
+
cjsPath
|
|
296
|
+
], {
|
|
297
|
+
cwd: cwd
|
|
298
|
+
})
|
|
299
|
+
];
|
|
300
|
+
case 2:
|
|
301
|
+
_state.sent();
|
|
302
|
+
targetPath = path.resolve(cwd, cjsPath, "package.json");
|
|
303
|
+
return [
|
|
304
|
+
4,
|
|
305
|
+
ensureDir(path.dirname(targetPath))
|
|
306
|
+
];
|
|
307
|
+
case 3:
|
|
308
|
+
_state.sent();
|
|
309
|
+
return [
|
|
310
|
+
4,
|
|
311
|
+
fs.writeFile(targetPath, '{\n "type": "commonjs"\n}')
|
|
312
|
+
];
|
|
313
|
+
case 4:
|
|
314
|
+
_state.sent();
|
|
315
|
+
return [
|
|
316
|
+
2
|
|
317
|
+
];
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
return function buildCjs() {
|
|
322
|
+
return _ref.apply(this, arguments);
|
|
323
|
+
};
|
|
324
|
+
}();
|
|
325
|
+
export var makeBaseExports = function() {
|
|
326
|
+
var _ref = _async_to_generator(function() {
|
|
327
|
+
var options, _options_cwd, cwd, exp, _tmp, baseMap;
|
|
328
|
+
var _arguments = arguments;
|
|
329
|
+
return _ts_generator(this, function(_state) {
|
|
330
|
+
switch(_state.label){
|
|
331
|
+
case 0:
|
|
332
|
+
options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : getDefaultOptions();
|
|
333
|
+
cwd = (_options_cwd = options.cwd) !== null && _options_cwd !== void 0 ? _options_cwd : process.cwd();
|
|
334
|
+
_tmp = options.exports;
|
|
335
|
+
if (_tmp) return [
|
|
336
|
+
3,
|
|
337
|
+
2
|
|
338
|
+
];
|
|
339
|
+
return [
|
|
340
|
+
4,
|
|
341
|
+
parseExports(cwd)
|
|
342
|
+
];
|
|
343
|
+
case 1:
|
|
344
|
+
_tmp = _state.sent();
|
|
345
|
+
_state.label = 2;
|
|
346
|
+
case 2:
|
|
347
|
+
exp = _tmp;
|
|
348
|
+
// Let's validate the exports
|
|
349
|
+
if (!exp) {
|
|
350
|
+
throw new Error("No exports found");
|
|
351
|
+
}
|
|
352
|
+
if (typeof exp !== "object" && Array.isArray(exp)) {
|
|
353
|
+
throw new Error("Exports must be an object");
|
|
354
|
+
}
|
|
355
|
+
return [
|
|
356
|
+
4,
|
|
357
|
+
Promise.all(Object.entries(exp).map(function(entry) {
|
|
358
|
+
return processEntry(entry, options);
|
|
359
|
+
}))
|
|
360
|
+
];
|
|
361
|
+
case 3:
|
|
362
|
+
baseMap = _state.sent().flat();
|
|
363
|
+
return [
|
|
364
|
+
4,
|
|
365
|
+
Promise.all(baseMap.map(function(param) {
|
|
366
|
+
var targetFile = param.targetFile, content = param.content;
|
|
367
|
+
return createBaseExportFile(targetFile, content, cwd);
|
|
368
|
+
}))
|
|
369
|
+
];
|
|
370
|
+
case 4:
|
|
371
|
+
return [
|
|
372
|
+
2,
|
|
373
|
+
_state.sent()
|
|
374
|
+
];
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
return function makeBaseExports() {
|
|
379
|
+
return _ref.apply(this, arguments);
|
|
380
|
+
};
|
|
381
|
+
}();
|
|
382
|
+
var createBaseExportFile = function() {
|
|
383
|
+
var _ref = _async_to_generator(function(targetFile, content, cwd) {
|
|
384
|
+
var targetPath;
|
|
385
|
+
return _ts_generator(this, function(_state) {
|
|
386
|
+
switch(_state.label){
|
|
387
|
+
case 0:
|
|
388
|
+
targetPath = path.resolve(cwd, targetFile);
|
|
389
|
+
return [
|
|
390
|
+
4,
|
|
391
|
+
ensureDir(path.dirname(targetPath))
|
|
392
|
+
];
|
|
393
|
+
case 1:
|
|
394
|
+
_state.sent();
|
|
395
|
+
return [
|
|
396
|
+
4,
|
|
397
|
+
fs.writeFile(targetPath, content)
|
|
398
|
+
];
|
|
399
|
+
case 2:
|
|
400
|
+
_state.sent();
|
|
401
|
+
return [
|
|
402
|
+
2,
|
|
403
|
+
targetPath
|
|
404
|
+
];
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
return function createBaseExportFile(targetFile, content, cwd) {
|
|
409
|
+
return _ref.apply(this, arguments);
|
|
410
|
+
};
|
|
411
|
+
}();
|
|
412
|
+
var processEntry = function() {
|
|
413
|
+
var _ref = _async_to_generator(function(entry, options) {
|
|
414
|
+
var cjsExportsPromise, typesExportsPromise;
|
|
415
|
+
return _ts_generator(this, function(_state) {
|
|
416
|
+
switch(_state.label){
|
|
417
|
+
case 0:
|
|
418
|
+
cjsExportsPromise = Promise.resolve([]);
|
|
419
|
+
if (!options.noCJS) {
|
|
420
|
+
cjsExportsPromise = extractBaseExportsFromEntry(entry, "cjs", options);
|
|
421
|
+
}
|
|
422
|
+
typesExportsPromise = Promise.resolve([]);
|
|
423
|
+
if (!options.noTypes) {
|
|
424
|
+
typesExportsPromise = extractBaseExportsFromEntry(entry, "types", options);
|
|
425
|
+
}
|
|
426
|
+
return [
|
|
427
|
+
4,
|
|
428
|
+
Promise.all([
|
|
429
|
+
cjsExportsPromise,
|
|
430
|
+
typesExportsPromise
|
|
431
|
+
])
|
|
432
|
+
];
|
|
433
|
+
case 1:
|
|
434
|
+
return [
|
|
435
|
+
2,
|
|
436
|
+
_state.sent().flat()
|
|
437
|
+
];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
return function processEntry(entry, options) {
|
|
442
|
+
return _ref.apply(this, arguments);
|
|
443
|
+
};
|
|
444
|
+
}();
|
|
445
|
+
var extractBaseExportsFromEntry = function() {
|
|
446
|
+
var _ref = _async_to_generator(function(param, type, options) {
|
|
447
|
+
var _param, key, value, _options_cwd, cwd, hasWildcard, exportTypeKey, exportKeyValue, asteriskPosition, paths, targetFiles;
|
|
448
|
+
return _ts_generator(this, function(_state) {
|
|
449
|
+
switch(_state.label){
|
|
450
|
+
case 0:
|
|
451
|
+
_param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
|
452
|
+
cwd = (_options_cwd = options.cwd) !== null && _options_cwd !== void 0 ? _options_cwd : process.cwd();
|
|
453
|
+
assert([
|
|
454
|
+
"cjs",
|
|
455
|
+
"types"
|
|
456
|
+
].includes(type), "The type of the entry ".concat(key, ' must be "cjs" | "types". ').concat(type, " given"));
|
|
457
|
+
// We need to make sure the * is ONLY once at most and is at the end of the key
|
|
458
|
+
hasWildcard = /^[^*]*\*$/.test(key);
|
|
459
|
+
if (key.includes("*") && !hasWildcard) {
|
|
460
|
+
throw new Error("Only 1 wildcard at the end of the export path is allowed. Provided ".concat(key));
|
|
461
|
+
}
|
|
462
|
+
exportTypeKey = type === "cjs" ? "require" : "types";
|
|
463
|
+
if (typeof value !== "object" || !value || Array.isArray(value) || !(exportTypeKey in value) || typeof value[exportTypeKey] === "undefined") {
|
|
464
|
+
throw new Error("Missing key ".concat(exportTypeKey, " from the exports map of ").concat(key, ". If this is desired, then set it to null."));
|
|
465
|
+
}
|
|
466
|
+
exportKeyValue = value[exportTypeKey];
|
|
467
|
+
if (exportKeyValue === null) {
|
|
468
|
+
return [
|
|
469
|
+
2,
|
|
470
|
+
[]
|
|
471
|
+
];
|
|
472
|
+
}
|
|
473
|
+
if (typeof exportKeyValue !== "string") {
|
|
474
|
+
throw new Error('Only strings are allowed in the "'.concat(exportTypeKey, '" field'));
|
|
475
|
+
}
|
|
476
|
+
asteriskPosition = exportKeyValue.replace("./", "").split("/").findIndex(function(p) {
|
|
477
|
+
return p.startsWith("*");
|
|
478
|
+
});
|
|
479
|
+
return [
|
|
480
|
+
4,
|
|
481
|
+
parseExportPath(exportKeyValue, cwd)
|
|
482
|
+
];
|
|
483
|
+
case 1:
|
|
484
|
+
paths = _state.sent();
|
|
485
|
+
targetFiles = Promise.all(paths.map(function() {
|
|
486
|
+
var _ref = _async_to_generator(function(p) {
|
|
487
|
+
var finalKey, content, targetFile, geImportPaths, importPaths, relativeImportPath, importPaths1, relativeImportPath1, fileContent, exportObj;
|
|
488
|
+
return _ts_generator(this, function(_state) {
|
|
489
|
+
switch(_state.label){
|
|
490
|
+
case 0:
|
|
491
|
+
finalKey = key;
|
|
492
|
+
if (hasWildcard) {
|
|
493
|
+
finalKey = key.replace("*", p.split("/").slice(asteriskPosition, asteriskPosition + 1).join("/"));
|
|
494
|
+
}
|
|
495
|
+
if (finalKey === "." || finalKey === "./") {
|
|
496
|
+
finalKey = "index";
|
|
497
|
+
}
|
|
498
|
+
content = "";
|
|
499
|
+
targetFile = "";
|
|
500
|
+
geImportPaths = function(importPath) {
|
|
501
|
+
var targetFile = path.resolve(cwd, importPath);
|
|
502
|
+
var importFromPath = path.dirname(targetFile);
|
|
503
|
+
var fullImportPath = path.resolve(cwd, p);
|
|
504
|
+
var relativeImportPath = path.relative(importFromPath, fullImportPath);
|
|
505
|
+
return {
|
|
506
|
+
relativeImportPath: relativeImportPath,
|
|
507
|
+
fullImportPath: fullImportPath,
|
|
508
|
+
targetFile: targetFile
|
|
509
|
+
};
|
|
510
|
+
};
|
|
511
|
+
if (!(type === "cjs")) return [
|
|
512
|
+
3,
|
|
513
|
+
2
|
|
514
|
+
];
|
|
515
|
+
return [
|
|
516
|
+
4,
|
|
517
|
+
resolvePathWithExtension(finalKey, "cjs")
|
|
518
|
+
];
|
|
519
|
+
case 1:
|
|
520
|
+
finalKey = _state.sent();
|
|
521
|
+
importPaths = geImportPaths(finalKey);
|
|
522
|
+
relativeImportPath = importPaths.relativeImportPath;
|
|
523
|
+
targetFile = importPaths.targetFile;
|
|
524
|
+
content = "module.exports = require('".concat(formatImportPath(relativeImportPath), "')");
|
|
525
|
+
_state.label = 2;
|
|
526
|
+
case 2:
|
|
527
|
+
if (!(type === "types")) return [
|
|
528
|
+
3,
|
|
529
|
+
5
|
|
530
|
+
];
|
|
531
|
+
return [
|
|
532
|
+
4,
|
|
533
|
+
resolvePathWithExtension(finalKey, "d.ts")
|
|
534
|
+
];
|
|
535
|
+
case 3:
|
|
536
|
+
finalKey = _state.sent();
|
|
537
|
+
importPaths1 = geImportPaths(finalKey);
|
|
538
|
+
relativeImportPath1 = importPaths1.relativeImportPath;
|
|
539
|
+
targetFile = importPaths1.targetFile;
|
|
540
|
+
// Typescript will complain about exprting .d.ts, so we just omt that
|
|
541
|
+
content = "export * from '".concat(formatImportPath(relativeImportPath1).replace(".d.ts", ""), "'");
|
|
542
|
+
return [
|
|
543
|
+
4,
|
|
544
|
+
fs.readFile(importPaths1.fullImportPath, "utf-8")
|
|
545
|
+
];
|
|
546
|
+
case 4:
|
|
547
|
+
fileContent = _state.sent();
|
|
548
|
+
if (/export default/.test(fileContent)) {
|
|
549
|
+
content += "\nexport { default } from '".concat(formatImportPath(relativeImportPath1), "'");
|
|
550
|
+
}
|
|
551
|
+
_state.label = 5;
|
|
552
|
+
case 5:
|
|
553
|
+
if (!content) {
|
|
554
|
+
throw new Error("No content found for ".concat(exportKeyValue));
|
|
555
|
+
}
|
|
556
|
+
exportObj = {
|
|
557
|
+
type: type,
|
|
558
|
+
targetFile: targetFile,
|
|
559
|
+
content: content
|
|
560
|
+
};
|
|
561
|
+
return [
|
|
562
|
+
2,
|
|
563
|
+
exportObj
|
|
564
|
+
];
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
return function(p) {
|
|
569
|
+
return _ref.apply(this, arguments);
|
|
570
|
+
};
|
|
571
|
+
}()));
|
|
572
|
+
if (!targetFiles) {
|
|
573
|
+
console.log("⚠️ No CJS target files for ".concat(key));
|
|
574
|
+
}
|
|
575
|
+
return [
|
|
576
|
+
2,
|
|
577
|
+
targetFiles
|
|
578
|
+
];
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
return function extractBaseExportsFromEntry(_, type, options) {
|
|
583
|
+
return _ref.apply(this, arguments);
|
|
584
|
+
};
|
|
585
|
+
}();
|
|
586
|
+
var resolvePathWithExtension = function() {
|
|
587
|
+
var _ref = _async_to_generator(function(targetFile, extension) {
|
|
588
|
+
var e;
|
|
589
|
+
return _ts_generator(this, function(_state) {
|
|
590
|
+
switch(_state.label){
|
|
591
|
+
case 0:
|
|
592
|
+
_state.trys.push([
|
|
593
|
+
0,
|
|
594
|
+
2,
|
|
595
|
+
,
|
|
596
|
+
3
|
|
597
|
+
]);
|
|
598
|
+
return [
|
|
599
|
+
4,
|
|
600
|
+
fs.stat(targetFile)
|
|
601
|
+
];
|
|
602
|
+
case 1:
|
|
603
|
+
if (_state.sent().isDirectory()) {
|
|
604
|
+
return [
|
|
605
|
+
2,
|
|
606
|
+
"".concat(targetFile, "/index.").concat(extension)
|
|
607
|
+
];
|
|
608
|
+
} else {
|
|
609
|
+
return [
|
|
610
|
+
2,
|
|
611
|
+
"".concat(targetFile, ".").concat(extension)
|
|
612
|
+
];
|
|
613
|
+
}
|
|
614
|
+
return [
|
|
615
|
+
3,
|
|
616
|
+
3
|
|
617
|
+
];
|
|
618
|
+
case 2:
|
|
619
|
+
e = _state.sent();
|
|
620
|
+
return [
|
|
621
|
+
2,
|
|
622
|
+
"".concat(targetFile, ".").concat(extension)
|
|
623
|
+
];
|
|
624
|
+
case 3:
|
|
625
|
+
return [
|
|
626
|
+
2
|
|
627
|
+
];
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
return function resolvePathWithExtension(targetFile, extension) {
|
|
632
|
+
return _ref.apply(this, arguments);
|
|
633
|
+
};
|
|
634
|
+
}();
|
|
635
|
+
var formatImportPath = function(exportPath) {
|
|
636
|
+
return exportPath.startsWith(".") ? exportPath : "./".concat(exportPath);
|
|
637
|
+
};
|
|
638
|
+
var parseExportPath = function() {
|
|
639
|
+
var _ref = _async_to_generator(function(exportPath) {
|
|
640
|
+
var cwd, split, files;
|
|
641
|
+
var _arguments = arguments;
|
|
642
|
+
return _ts_generator(this, function(_state) {
|
|
643
|
+
switch(_state.label){
|
|
644
|
+
case 0:
|
|
645
|
+
cwd = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : process.cwd();
|
|
646
|
+
split = exportPath.split("*");
|
|
647
|
+
if (split.length === 1) {
|
|
648
|
+
return [
|
|
649
|
+
2,
|
|
650
|
+
[
|
|
651
|
+
exportPath
|
|
652
|
+
]
|
|
653
|
+
];
|
|
654
|
+
}
|
|
655
|
+
// Allow only 1 * in the path
|
|
656
|
+
if (split.length > 2) {
|
|
657
|
+
throw new Error("Invalid export path. Only one * is allowed");
|
|
658
|
+
}
|
|
659
|
+
return [
|
|
660
|
+
4,
|
|
661
|
+
glob(exportPath)
|
|
662
|
+
];
|
|
663
|
+
case 1:
|
|
664
|
+
files = _state.sent();
|
|
665
|
+
return [
|
|
666
|
+
2,
|
|
667
|
+
files.map(function(f) {
|
|
668
|
+
return path.relative(cwd, f);
|
|
669
|
+
})
|
|
670
|
+
];
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
});
|
|
674
|
+
return function parseExportPath(exportPath) {
|
|
675
|
+
return _ref.apply(this, arguments);
|
|
676
|
+
};
|
|
677
|
+
}();
|
|
678
|
+
export var buildEsm = function() {
|
|
679
|
+
var _ref = _async_to_generator(function() {
|
|
680
|
+
var options, _options_destination;
|
|
681
|
+
var _arguments = arguments;
|
|
682
|
+
return _ts_generator(this, function(_state) {
|
|
683
|
+
switch(_state.label){
|
|
684
|
+
case 0:
|
|
685
|
+
options = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : getDefaultOptions();
|
|
686
|
+
console.log("DESTINATION", options.destination, getDefaultOptions().destination);
|
|
687
|
+
return [
|
|
688
|
+
4,
|
|
689
|
+
runCommand("pnpm", [
|
|
690
|
+
"swc",
|
|
691
|
+
"src",
|
|
692
|
+
"-d",
|
|
693
|
+
(_options_destination = options.destination) !== null && _options_destination !== void 0 ? _options_destination : getDefaultOptions().destination
|
|
694
|
+
], {
|
|
695
|
+
cwd: options.cwd
|
|
696
|
+
})
|
|
697
|
+
];
|
|
698
|
+
case 1:
|
|
699
|
+
_state.sent();
|
|
700
|
+
return [
|
|
701
|
+
2
|
|
702
|
+
];
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
return function buildEsm() {
|
|
707
|
+
return _ref.apply(this, arguments);
|
|
708
|
+
};
|
|
709
|
+
}();
|
|
710
|
+
var parseExports = function() {
|
|
711
|
+
var _ref = _async_to_generator(function() {
|
|
712
|
+
var cwd, pkg, _;
|
|
713
|
+
var _arguments = arguments;
|
|
714
|
+
return _ts_generator(this, function(_state) {
|
|
715
|
+
switch(_state.label){
|
|
716
|
+
case 0:
|
|
717
|
+
cwd = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : process.cwd();
|
|
718
|
+
_ = JSON.parse;
|
|
719
|
+
return [
|
|
720
|
+
4,
|
|
721
|
+
fs.readFile(path.join(cwd, "package.json"), "utf-8")
|
|
722
|
+
];
|
|
723
|
+
case 1:
|
|
724
|
+
pkg = _.apply(JSON, [
|
|
725
|
+
_state.sent()
|
|
726
|
+
]);
|
|
727
|
+
return [
|
|
728
|
+
2,
|
|
729
|
+
pkg.exports
|
|
730
|
+
];
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
});
|
|
734
|
+
return function parseExports() {
|
|
735
|
+
return _ref.apply(this, arguments);
|
|
736
|
+
};
|
|
737
|
+
}();
|