@next-core/build-next-bricks 1.9.0 → 1.10.0
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/package.json +3 -3
- package/src/makeBrickManifest.js +40 -2
- package/src/scanBricks.js +51 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/build-next-bricks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Build next bricks",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/v3/packages/build-next-bricks",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"webpack": "^5.84.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@next-core/brick-manifest": "^0.
|
|
52
|
+
"@next-core/brick-manifest": "^0.3.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "14b533269133db07014b416199d988b0025f2b3c"
|
|
55
55
|
}
|
package/src/makeBrickManifest.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parse } from "doctrine";
|
|
2
|
+
import { getTypeAnnotation } from "./utils.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @typedef {import("@next-core/brick-manifest").BrickManifest} BrickManifest
|
|
@@ -15,7 +16,8 @@ import { parse } from "doctrine";
|
|
|
15
16
|
/**
|
|
16
17
|
* @param {string} name
|
|
17
18
|
* @param {NodePath} nodePath
|
|
18
|
-
* @param {string} source
|
|
19
|
+
* @param {string} source'
|
|
20
|
+
* @param {Set<string>} referenceSet
|
|
19
21
|
* @returns {BrickManifest}
|
|
20
22
|
*/
|
|
21
23
|
export default function makeBrickManifest(name, nodePath, source) {
|
|
@@ -94,8 +96,9 @@ function findDocComment({ node, parentPath }, source) {
|
|
|
94
96
|
* @param {BrickManifest} manifest
|
|
95
97
|
* @param {Node[]} nodes
|
|
96
98
|
* @param {string} source
|
|
99
|
+
* @param {Set<string>} referenceSet
|
|
97
100
|
*/
|
|
98
|
-
function scanFields(manifest, nodes, source) {
|
|
101
|
+
function scanFields(manifest, nodes, source, referenceSet = new Set()) {
|
|
99
102
|
for (const node of nodes) {
|
|
100
103
|
if (node.type === "ClassAccessorProperty" && node.decorators?.length) {
|
|
101
104
|
for (const { expression } of node.decorators) {
|
|
@@ -145,6 +148,12 @@ function scanFields(manifest, nodes, source) {
|
|
|
145
148
|
) {
|
|
146
149
|
const { typeAnnotation } = node.typeAnnotation;
|
|
147
150
|
prop.type = getTypeWithoutUndefined(typeAnnotation, source);
|
|
151
|
+
prop.types = getTypesWithoutUndefined(
|
|
152
|
+
typeAnnotation,
|
|
153
|
+
source,
|
|
154
|
+
referenceSet
|
|
155
|
+
);
|
|
156
|
+
prop.reference = [...referenceSet];
|
|
148
157
|
}
|
|
149
158
|
if (node.value && !prop.default) {
|
|
150
159
|
prop.default = source.substring(
|
|
@@ -209,6 +218,12 @@ function scanFields(manifest, nodes, source) {
|
|
|
209
218
|
const param = typeAnnotation.typeParameters.params[0];
|
|
210
219
|
event.detail ??= {};
|
|
211
220
|
event.detail.type = source.substring(param.start, param.end);
|
|
221
|
+
event.detail.types = getTypeAnnotation(
|
|
222
|
+
param,
|
|
223
|
+
source,
|
|
224
|
+
referenceSet
|
|
225
|
+
);
|
|
226
|
+
event.detail.reference = [...referenceSet];
|
|
212
227
|
}
|
|
213
228
|
}
|
|
214
229
|
manifest.events.push(event);
|
|
@@ -244,6 +259,12 @@ function scanFields(manifest, nodes, source) {
|
|
|
244
259
|
typeAnnotation.start,
|
|
245
260
|
typeAnnotation.end
|
|
246
261
|
);
|
|
262
|
+
method.return.types = getTypeAnnotation(
|
|
263
|
+
typeAnnotation,
|
|
264
|
+
source,
|
|
265
|
+
referenceSet
|
|
266
|
+
);
|
|
267
|
+
method.return.reference = [...referenceSet];
|
|
247
268
|
}
|
|
248
269
|
manifest.methods.push(method);
|
|
249
270
|
}
|
|
@@ -287,6 +308,23 @@ function getTypeWithoutUndefined(node, source) {
|
|
|
287
308
|
return source.substring(node.start, node.end);
|
|
288
309
|
}
|
|
289
310
|
|
|
311
|
+
/**
|
|
312
|
+
* @param {import("@babel/types")/.typeAnnotation} typeAnnotation
|
|
313
|
+
* @param {string} source
|
|
314
|
+
* @param {Set<string} set
|
|
315
|
+
*/
|
|
316
|
+
function getTypesWithoutUndefined(typeAnnotation, source, set) {
|
|
317
|
+
if (typeAnnotation.type === "TSUnionType" && typeAnnotation.types) {
|
|
318
|
+
return {
|
|
319
|
+
type: "union",
|
|
320
|
+
types: typeAnnotation.types
|
|
321
|
+
.filter((type) => type.type !== "TSUndefinedKeyword")
|
|
322
|
+
.map((item) => getTypeAnnotation(item, source, set)),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return getTypeAnnotation(typeAnnotation, source, set);
|
|
326
|
+
}
|
|
327
|
+
|
|
290
328
|
/**
|
|
291
329
|
* @param {Tag[]} tags
|
|
292
330
|
* @param {string} title
|
package/src/scanBricks.js
CHANGED
|
@@ -700,26 +700,51 @@ export default async function scanBricks(packageDir) {
|
|
|
700
700
|
|
|
701
701
|
if (manifest && manifest.bricks.length) {
|
|
702
702
|
manifest.bricks.forEach((brickDoc) => {
|
|
703
|
-
const { name, properties } = brickDoc;
|
|
703
|
+
const { name, properties = [], events = [], methods = [] } = brickDoc;
|
|
704
704
|
const importInfo = bricksImportsInfo[name];
|
|
705
|
-
const fieldTypes =
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
.
|
|
705
|
+
const fieldTypes = new Set();
|
|
706
|
+
|
|
707
|
+
properties.forEach((item) => {
|
|
708
|
+
importInfo.properties = (importInfo.properties || []).concat({
|
|
709
|
+
name: item.name,
|
|
710
|
+
types: item.types,
|
|
711
|
+
});
|
|
712
|
+
(item.reference || []).forEach((item) => fieldTypes.add(item));
|
|
713
|
+
|
|
714
|
+
delete item.types;
|
|
715
|
+
delete item.reference;
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
events.forEach((item) => {
|
|
719
|
+
if (item.detail) {
|
|
720
|
+
importInfo.events = (importInfo.events || []).concat({
|
|
721
|
+
name: item.name,
|
|
722
|
+
types: item.detail.types,
|
|
723
|
+
});
|
|
724
|
+
(item.detail.reference || []).forEach((item) => fieldTypes.add(item));
|
|
725
|
+
|
|
726
|
+
delete item.detail.types;
|
|
727
|
+
delete item.detail.reference;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
methods.forEach((item) => {
|
|
732
|
+
if (item.return) {
|
|
733
|
+
importInfo.methods = (importInfo.methods || []).concat({
|
|
734
|
+
name: item.name,
|
|
735
|
+
types: item.return.types,
|
|
736
|
+
});
|
|
737
|
+
(item.return.reference || []).forEach((item) => fieldTypes.add(item));
|
|
738
|
+
|
|
739
|
+
delete item.return.types;
|
|
740
|
+
delete item.return.reference;
|
|
741
|
+
}
|
|
742
|
+
});
|
|
716
743
|
|
|
717
744
|
const importKeysSet = new Set();
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
);
|
|
722
|
-
}
|
|
745
|
+
[...fieldTypes].forEach((type) =>
|
|
746
|
+
findType(type, importInfo, importKeysSet)
|
|
747
|
+
);
|
|
723
748
|
});
|
|
724
749
|
}
|
|
725
750
|
|
|
@@ -734,7 +759,15 @@ export default async function scanBricks(packageDir) {
|
|
|
734
759
|
manifest,
|
|
735
760
|
types: Object.fromEntries(
|
|
736
761
|
Object.entries(bricksImportsInfo).map(([k, v]) => {
|
|
737
|
-
return [
|
|
762
|
+
return [
|
|
763
|
+
k,
|
|
764
|
+
{
|
|
765
|
+
properties: v.properties,
|
|
766
|
+
events: v.events,
|
|
767
|
+
methods: v.methods,
|
|
768
|
+
types: v.types,
|
|
769
|
+
},
|
|
770
|
+
];
|
|
738
771
|
})
|
|
739
772
|
),
|
|
740
773
|
};
|