@aeriajs/entrypoint 0.0.24 → 0.0.25
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/index.js +3 -0
- package/dist/index.mjs +48 -312
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -10,6 +10,9 @@ const promises_1 = __importDefault(require("fs/promises"));
|
|
|
10
10
|
let collectionsMemo;
|
|
11
11
|
const collectionMemo = {};
|
|
12
12
|
const getEntrypointPath = async () => {
|
|
13
|
+
if (process.env.AERIA_MAIN) {
|
|
14
|
+
return path_1.default.join(process.cwd(), process.env.AERIA_MAIN);
|
|
15
|
+
}
|
|
13
16
|
const { main, aeriaMain } = JSON.parse(await promises_1.default.readFile(path_1.default.join(process.cwd(), 'package.json'), {
|
|
14
17
|
encoding: 'utf8',
|
|
15
18
|
}));
|
package/dist/index.mjs
CHANGED
|
@@ -1,315 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, g, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
};
|
|
40
|
-
return g = {
|
|
41
|
-
next: verb(0),
|
|
42
|
-
"throw": verb(1),
|
|
43
|
-
"return": verb(2)
|
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
-
return this;
|
|
46
|
-
}), g;
|
|
47
|
-
function verb(n) {
|
|
48
|
-
return function(v) {
|
|
49
|
-
return step([
|
|
50
|
-
n,
|
|
51
|
-
v
|
|
52
|
-
]);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function step(op) {
|
|
56
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
-
while(_)try {
|
|
58
|
-
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;
|
|
59
|
-
if (y = 0, t) op = [
|
|
60
|
-
op[0] & 2,
|
|
61
|
-
t.value
|
|
62
|
-
];
|
|
63
|
-
switch(op[0]){
|
|
64
|
-
case 0:
|
|
65
|
-
case 1:
|
|
66
|
-
t = op;
|
|
67
|
-
break;
|
|
68
|
-
case 4:
|
|
69
|
-
_.label++;
|
|
70
|
-
return {
|
|
71
|
-
value: op[1],
|
|
72
|
-
done: false
|
|
73
|
-
};
|
|
74
|
-
case 5:
|
|
75
|
-
_.label++;
|
|
76
|
-
y = op[1];
|
|
77
|
-
op = [
|
|
78
|
-
0
|
|
79
|
-
];
|
|
80
|
-
continue;
|
|
81
|
-
case 7:
|
|
82
|
-
op = _.ops.pop();
|
|
83
|
-
_.trys.pop();
|
|
84
|
-
continue;
|
|
85
|
-
default:
|
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
-
_ = 0;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
-
_.label = op[1];
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
-
_.label = t[1];
|
|
96
|
-
t = op;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
if (t && _.label < t[2]) {
|
|
100
|
-
_.label = t[2];
|
|
101
|
-
_.ops.push(op);
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
if (t[2]) _.ops.pop();
|
|
105
|
-
_.trys.pop();
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
op = body.call(thisArg, _);
|
|
109
|
-
} catch (e) {
|
|
110
|
-
op = [
|
|
111
|
-
6,
|
|
112
|
-
e
|
|
113
|
-
];
|
|
114
|
-
y = 0;
|
|
115
|
-
} finally{
|
|
116
|
-
f = t = 0;
|
|
117
|
-
}
|
|
118
|
-
if (op[0] & 5) throw op[1];
|
|
119
|
-
return {
|
|
120
|
-
value: op[0] ? op[1] : void 0,
|
|
121
|
-
done: true
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
"use strict";
|
|
125
2
|
import { dynamicImport } from "@aeriajs/common";
|
|
126
3
|
import path from "path";
|
|
127
4
|
import fs from "fs/promises";
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
export
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
return function getEntrypoint() {
|
|
178
|
-
return _ref.apply(this, arguments);
|
|
179
|
-
};
|
|
180
|
-
}();
|
|
181
|
-
var internalGetCollections = function() {
|
|
182
|
-
var _ref = _async_to_generator(function() {
|
|
183
|
-
var entrypoint, collections;
|
|
184
|
-
return _ts_generator(this, function(_state) {
|
|
185
|
-
switch(_state.label){
|
|
186
|
-
case 0:
|
|
187
|
-
return [
|
|
188
|
-
4,
|
|
189
|
-
getEntrypoint()
|
|
190
|
-
];
|
|
191
|
-
case 1:
|
|
192
|
-
entrypoint = _state.sent();
|
|
193
|
-
collections = entrypoint.collections ? entrypoint.collections : entrypoint.default.options.collections;
|
|
194
|
-
return [
|
|
195
|
-
2,
|
|
196
|
-
Object.assign({}, collections)
|
|
197
|
-
];
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
return function internalGetCollections() {
|
|
202
|
-
return _ref.apply(this, arguments);
|
|
203
|
-
};
|
|
204
|
-
}();
|
|
205
|
-
export var getCollections = function() {
|
|
206
|
-
var _ref = _async_to_generator(function() {
|
|
207
|
-
return _ts_generator(this, function(_state) {
|
|
208
|
-
switch(_state.label){
|
|
209
|
-
case 0:
|
|
210
|
-
if (collectionsMemo) {
|
|
211
|
-
return [
|
|
212
|
-
2,
|
|
213
|
-
Object.assign({}, collectionsMemo)
|
|
214
|
-
];
|
|
215
|
-
}
|
|
216
|
-
return [
|
|
217
|
-
4,
|
|
218
|
-
internalGetCollections()
|
|
219
|
-
];
|
|
220
|
-
case 1:
|
|
221
|
-
collectionsMemo = _state.sent();
|
|
222
|
-
return [
|
|
223
|
-
2,
|
|
224
|
-
collectionsMemo
|
|
225
|
-
];
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
return function getCollections() {
|
|
230
|
-
return _ref.apply(this, arguments);
|
|
231
|
-
};
|
|
232
|
-
}();
|
|
233
|
-
export var getCollection = function() {
|
|
234
|
-
var _ref = _async_to_generator(function(collectionName) {
|
|
235
|
-
var collections, candidate, collection;
|
|
236
|
-
return _ts_generator(this, function(_state) {
|
|
237
|
-
switch(_state.label){
|
|
238
|
-
case 0:
|
|
239
|
-
if (collectionMemo[collectionName]) {
|
|
240
|
-
return [
|
|
241
|
-
2,
|
|
242
|
-
collectionMemo[collectionName]
|
|
243
|
-
];
|
|
244
|
-
}
|
|
245
|
-
return [
|
|
246
|
-
4,
|
|
247
|
-
getCollections()
|
|
248
|
-
];
|
|
249
|
-
case 1:
|
|
250
|
-
collections = _state.sent();
|
|
251
|
-
candidate = collections[collectionName];
|
|
252
|
-
if (!candidate) {
|
|
253
|
-
return [
|
|
254
|
-
2
|
|
255
|
-
];
|
|
256
|
-
}
|
|
257
|
-
collection = typeof candidate === "function" ? candidate() : candidate;
|
|
258
|
-
collectionsMemo[collectionName] = candidate;
|
|
259
|
-
return [
|
|
260
|
-
2,
|
|
261
|
-
collection
|
|
262
|
-
];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
return function getCollection(collectionName) {
|
|
267
|
-
return _ref.apply(this, arguments);
|
|
268
|
-
};
|
|
269
|
-
}();
|
|
270
|
-
export var getRouter = function() {
|
|
271
|
-
var _ref = _async_to_generator(function() {
|
|
272
|
-
var entrypoint;
|
|
273
|
-
return _ts_generator(this, function(_state) {
|
|
274
|
-
switch(_state.label){
|
|
275
|
-
case 0:
|
|
276
|
-
return [
|
|
277
|
-
4,
|
|
278
|
-
getEntrypoint()
|
|
279
|
-
];
|
|
280
|
-
case 1:
|
|
281
|
-
entrypoint = _state.sent();
|
|
282
|
-
return [
|
|
283
|
-
2,
|
|
284
|
-
entrypoint.router
|
|
285
|
-
];
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
return function getRouter() {
|
|
290
|
-
return _ref.apply(this, arguments);
|
|
291
|
-
};
|
|
292
|
-
}();
|
|
293
|
-
export var getConfig = function() {
|
|
294
|
-
var _ref = _async_to_generator(function() {
|
|
295
|
-
var entrypoint;
|
|
296
|
-
return _ts_generator(this, function(_state) {
|
|
297
|
-
switch(_state.label){
|
|
298
|
-
case 0:
|
|
299
|
-
return [
|
|
300
|
-
4,
|
|
301
|
-
getEntrypoint()
|
|
302
|
-
];
|
|
303
|
-
case 1:
|
|
304
|
-
entrypoint = _state.sent();
|
|
305
|
-
return [
|
|
306
|
-
2,
|
|
307
|
-
entrypoint.default ? entrypoint.default.options.config : {}
|
|
308
|
-
];
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
return function getConfig() {
|
|
313
|
-
return _ref.apply(this, arguments);
|
|
314
|
-
};
|
|
315
|
-
}();
|
|
5
|
+
let collectionsMemo;
|
|
6
|
+
const collectionMemo = {};
|
|
7
|
+
export const getEntrypointPath = async () => {
|
|
8
|
+
if (process.env.AERIA_MAIN) {
|
|
9
|
+
return path.join(process.cwd(), process.env.AERIA_MAIN);
|
|
10
|
+
}
|
|
11
|
+
const { main, aeriaMain } = JSON.parse(await fs.readFile(path.join(process.cwd(), "package.json"), {
|
|
12
|
+
encoding: "utf8"
|
|
13
|
+
}));
|
|
14
|
+
return path.join(process.cwd(), aeriaMain || main);
|
|
15
|
+
};
|
|
16
|
+
export const getEntrypoint = async () => {
|
|
17
|
+
return dynamicImport(await getEntrypointPath());
|
|
18
|
+
};
|
|
19
|
+
const internalGetCollections = async () => {
|
|
20
|
+
const entrypoint = await getEntrypoint();
|
|
21
|
+
const collections = entrypoint.collections ? entrypoint.collections : entrypoint.default.options.collections;
|
|
22
|
+
return Object.assign({}, collections);
|
|
23
|
+
};
|
|
24
|
+
export const getCollections = async () => {
|
|
25
|
+
if (collectionsMemo) {
|
|
26
|
+
return Object.assign({}, collectionsMemo);
|
|
27
|
+
}
|
|
28
|
+
collectionsMemo = await internalGetCollections();
|
|
29
|
+
return collectionsMemo;
|
|
30
|
+
};
|
|
31
|
+
export const getCollection = async (collectionName) => {
|
|
32
|
+
if (collectionMemo[collectionName]) {
|
|
33
|
+
return collectionMemo[collectionName];
|
|
34
|
+
}
|
|
35
|
+
const collections = await getCollections();
|
|
36
|
+
const candidate = collections[collectionName];
|
|
37
|
+
if (!candidate) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const collection = typeof candidate === "function" ? candidate() : candidate;
|
|
41
|
+
collectionsMemo[collectionName] = candidate;
|
|
42
|
+
return collection;
|
|
43
|
+
};
|
|
44
|
+
export const getRouter = async () => {
|
|
45
|
+
const entrypoint = await getEntrypoint();
|
|
46
|
+
return entrypoint.router;
|
|
47
|
+
};
|
|
48
|
+
export const getConfig = async () => {
|
|
49
|
+
const entrypoint = await getEntrypoint();
|
|
50
|
+
return entrypoint.default ? entrypoint.default.options.config : {};
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/entrypoint",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"lint:fix": "eslint src --fix",
|
|
32
32
|
"build": "pnpm build:cjs && pnpm build:esm",
|
|
33
33
|
"build:cjs": "tsc",
|
|
34
|
-
"build:esm": "
|
|
34
|
+
"build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
|
|
35
35
|
"build:esm-transform": "pnpm -w esm-transform $PWD/dist"
|
|
36
36
|
}
|
|
37
37
|
}
|