@luna-park/plugin 1.8.0 → 2.0.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/dist/dist-CZjmIqBC.mjs +894 -0
- package/dist/eslint.d.mts +1 -2
- package/dist/eslint.mjs +11 -4
- package/dist/extractor.d.mts +3 -13
- package/dist/extractor.mjs +31 -40
- package/dist/{index-76yMHag4.d.mts → index-B4kxQtaL.d.mts} +163 -145
- package/dist/index.d.mts +538 -459
- package/dist/index.mjs +1349 -212
- package/dist/preview.d.mts +1 -3
- package/dist/preview.mjs +2 -4
- package/package.json +30 -23
- package/dist/dist-BoFOku7q.mjs +0 -608
package/dist/eslint.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//#region src/eslint/index.d.ts
|
|
2
1
|
export declare const objectKeysOptions: {
|
|
3
2
|
orderedKeys: string[];
|
|
4
3
|
selectors: {
|
|
5
4
|
target: {
|
|
6
5
|
name: string;
|
|
7
6
|
type: "function" | "property";
|
|
7
|
+
argument?: number | undefined;
|
|
8
8
|
};
|
|
9
9
|
mode: "direct" | "recursive";
|
|
10
10
|
orderedKeys?: Array<string>;
|
|
@@ -17,5 +17,4 @@ declare const _default: {
|
|
|
17
17
|
"sort-keys-custom-order/object-keys": ["error", typeof objectKeysOptions];
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
//#endregion
|
|
21
20
|
export { _default as default };
|
package/dist/eslint.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
// src/eslint/index.ts
|
|
2
2
|
function selector(name, type, options) {
|
|
3
|
+
const { argument, ...sorting } = options;
|
|
3
4
|
return {
|
|
4
5
|
mode: "direct",
|
|
5
|
-
...
|
|
6
|
+
...sorting,
|
|
6
7
|
target: {
|
|
8
|
+
...argument !== void 0 && { argument },
|
|
7
9
|
name,
|
|
8
10
|
type
|
|
9
11
|
}
|
|
@@ -62,12 +64,17 @@ const objectKeysOptions = {
|
|
|
62
64
|
] }),
|
|
63
65
|
selector("inputs", "property", { sorting: "none" }),
|
|
64
66
|
selector("outputs", "property", { sorting: "none" }),
|
|
65
|
-
selector("
|
|
67
|
+
selector("config", "property", { sorting: "none" }),
|
|
68
|
+
selector("methods", "property", { sorting: "none" }),
|
|
69
|
+
selector("LogicType.object", "function", {
|
|
70
|
+
argument: 0,
|
|
71
|
+
sorting: "none"
|
|
72
|
+
}),
|
|
73
|
+
selector("enum", "property", { sorting: "none" })
|
|
66
74
|
]
|
|
67
75
|
};
|
|
68
76
|
var eslint_default = {
|
|
69
77
|
name: "@luna-park/plugin/eslint",
|
|
70
78
|
rules: { "sort-keys-custom-order/object-keys": ["error", objectKeysOptions] }
|
|
71
79
|
};
|
|
72
|
-
//#endregion
|
|
73
80
|
export { eslint_default as default, objectKeysOptions };
|
package/dist/extractor.d.mts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { d as TSchema } from "./index-
|
|
1
|
+
import { d as TSchema } from "./index-B4kxQtaL.mjs";
|
|
2
2
|
import * as ts$1 from "typescript";
|
|
3
3
|
import ts from "typescript";
|
|
4
|
-
//#region src/extractor/export/type.d.ts
|
|
5
4
|
type TExportResult = {
|
|
6
5
|
components: Record<string, TExportComponent>;
|
|
7
6
|
functions: Record<string, TExportFunction>;
|
|
8
7
|
types: Record<string, TExportType>;
|
|
9
8
|
};
|
|
10
9
|
type TExportComponent = {
|
|
11
|
-
emits?: Record<string,
|
|
10
|
+
emits?: Record<string, TExportType>;
|
|
12
11
|
models?: Record<string, TExportType>;
|
|
13
12
|
properties?: Record<string, TExportType>;
|
|
14
13
|
slots?: Record<string, TExportType>;
|
|
@@ -26,7 +25,6 @@ type TExportFunction = {
|
|
|
26
25
|
description?: string;
|
|
27
26
|
type: string;
|
|
28
27
|
};
|
|
29
|
-
type: string;
|
|
30
28
|
};
|
|
31
29
|
type TExportType = {
|
|
32
30
|
default?: string;
|
|
@@ -35,8 +33,6 @@ type TExportType = {
|
|
|
35
33
|
properties?: Record<string, TExportType>;
|
|
36
34
|
type: string | Record<string, TExportType>;
|
|
37
35
|
};
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/extractor/export/index.d.ts
|
|
40
36
|
export declare class CTypeExport {
|
|
41
37
|
program: ts.Program;
|
|
42
38
|
checker: ts.TypeChecker;
|
|
@@ -51,8 +47,6 @@ export declare class CTypeExport {
|
|
|
51
47
|
extractType(type: ts.Type, ctxNode?: ts.Node): void;
|
|
52
48
|
typeToString(type: ts.Type, flags?: number): string;
|
|
53
49
|
}
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region src/extractor/generator.d.ts
|
|
56
50
|
type TExportNodeFunction = {
|
|
57
51
|
description?: string;
|
|
58
52
|
name?: string;
|
|
@@ -71,13 +65,9 @@ type TExportLogicResult = {
|
|
|
71
65
|
types: Record<string, TSchema>;
|
|
72
66
|
};
|
|
73
67
|
export declare function generateNodes(exportResult: TExportResult, packageName?: string): TExportLogicResult;
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/extractor/source.d.ts
|
|
76
68
|
export declare function getSourceFile(moduleName: string): {
|
|
77
69
|
program: ts$1.Program;
|
|
78
70
|
sourceFile: ts$1.SourceFile;
|
|
79
71
|
};
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/extractor/index.d.ts
|
|
82
72
|
export declare function extractFile(filePath: string, target: string): Promise<void>;
|
|
83
|
-
|
|
73
|
+
export {};
|
package/dist/extractor.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as assertType, f as cleanObject, i as LogicType, l as schemaLoop, m as objectMap, r as EVarType, u as typeToSchema } from "./dist-CZjmIqBC.mjs";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import * as ts$1 from "typescript";
|
|
4
|
-
import ts from "typescript";
|
|
3
|
+
import ts, * as ts$1 from "typescript";
|
|
5
4
|
import * as path from "path";
|
|
6
5
|
import * as fs$1 from "fs";
|
|
7
|
-
|
|
6
|
+
// src/extractor/code/lib.ts
|
|
8
7
|
function generateCode(schema, options = {}) {
|
|
9
8
|
if (typeof schema !== "object" || schema === null) return JSON.stringify(schema);
|
|
10
9
|
const properties = {};
|
|
10
|
+
const values = { ...schema };
|
|
11
11
|
for (const props of [
|
|
12
12
|
"default",
|
|
13
13
|
"description",
|
|
@@ -17,10 +17,13 @@ function generateCode(schema, options = {}) {
|
|
|
17
17
|
"optional",
|
|
18
18
|
"example",
|
|
19
19
|
"enum"
|
|
20
|
-
]) if (
|
|
20
|
+
]) if (values[props]) properties[props] = values[props];
|
|
21
21
|
if (schema.type === EVarType.array) return buildFunctionCall(`LogicType.${schema.type}`, [generateCode(schema.items, options), getCodeFromObject(properties)]);
|
|
22
22
|
if (schema.type === EVarType.interface) return buildFunctionCall(`LogicType.${schema.type}`, [JSON.stringify(schema.className), getCodeFromObject(properties)]);
|
|
23
|
-
if (
|
|
23
|
+
if ([EVarType.union, EVarType.intersection].includes(schema.type)) {
|
|
24
|
+
assertType(schema);
|
|
25
|
+
return buildFunctionCall(`LogicType.${schema.type}`, [`[${schema.elements.map((element) => generateCode(element, options)).join(", ")}]`, getCodeFromObject(properties)]);
|
|
26
|
+
}
|
|
24
27
|
if (schema.type === EVarType.function) return buildFunctionCall(`LogicType.${schema.type}`, [
|
|
25
28
|
generateCode(schema.inputs, options),
|
|
26
29
|
generateCode(schema.output, options),
|
|
@@ -45,8 +48,7 @@ function getCodeFromObject(object, raw) {
|
|
|
45
48
|
function getSafeKey(key) {
|
|
46
49
|
return /^[a-zA-Z]+$/.test(key) ? key : JSON.stringify(key);
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
//#region src/extractor/code/component.ts
|
|
51
|
+
// src/extractor/code/component.ts
|
|
50
52
|
function getComponentCode(logicResult, file) {
|
|
51
53
|
const content = [];
|
|
52
54
|
const component = logicResult.components["default"];
|
|
@@ -72,8 +74,7 @@ export const ${file.name.toLocaleLowerCase()}: TComponent = {
|
|
|
72
74
|
${content.map(({ key, value }) => `${key}: {\n ${value}\n }`).join(",\n ")}
|
|
73
75
|
}`;
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/extractor/documentation.ts
|
|
77
|
+
// src/extractor/documentation.ts
|
|
77
78
|
function getDocumentationFromSymbol(symbol, checker) {
|
|
78
79
|
const documentation = { description: mergeSymbolDisplayParts(symbol.getDocumentationComment(checker)) || void 0 };
|
|
79
80
|
for (const tag of symbol.getJsDocTags()) {
|
|
@@ -81,8 +82,8 @@ function getDocumentationFromSymbol(symbol, checker) {
|
|
|
81
82
|
if (!documentation.params) documentation.params = {};
|
|
82
83
|
let paramDescription = mergeSymbolDisplayParts(tag.text?.slice(1)).trim();
|
|
83
84
|
if (paramDescription.startsWith("- ")) paramDescription = paramDescription.slice(2);
|
|
84
|
-
const paramName = tag.text[0]?.text;
|
|
85
|
-
documentation.params[paramName] = paramDescription;
|
|
85
|
+
const paramName = tag.text?.[0]?.text;
|
|
86
|
+
if (paramName) documentation.params[paramName] = paramDescription;
|
|
86
87
|
continue;
|
|
87
88
|
}
|
|
88
89
|
documentation[tag.name] = mergeSymbolDisplayParts(tag.text);
|
|
@@ -92,8 +93,7 @@ function getDocumentationFromSymbol(symbol, checker) {
|
|
|
92
93
|
function mergeSymbolDisplayParts(symbolDisplayParts = []) {
|
|
93
94
|
return symbolDisplayParts.map((part) => part.text).join("");
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
-
//#region src/extractor/export/component.ts
|
|
96
|
+
// src/extractor/export/component.ts
|
|
97
97
|
function getSlots(type, typeExport) {
|
|
98
98
|
const properties = typeExport.checker.getPropertiesOfType(type);
|
|
99
99
|
const slots = {};
|
|
@@ -168,8 +168,7 @@ function emitName(name) {
|
|
|
168
168
|
name = name.slice(2);
|
|
169
169
|
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
170
170
|
}
|
|
171
|
-
|
|
172
|
-
//#region src/extractor/export/template.ts
|
|
171
|
+
// src/extractor/export/template.ts
|
|
173
172
|
function getTemplateTypeParameters(signature, typeExport) {
|
|
174
173
|
return Object.fromEntries((signature.getTypeParameters() ?? []).map((typeParameter) => {
|
|
175
174
|
let type = "unknown";
|
|
@@ -180,8 +179,7 @@ function getTemplateTypeParameters(signature, typeExport) {
|
|
|
180
179
|
return [typeParameter.symbol.name, type];
|
|
181
180
|
}));
|
|
182
181
|
}
|
|
183
|
-
|
|
184
|
-
//#region src/extractor/export/utils.ts
|
|
182
|
+
// src/extractor/export/utils.ts
|
|
185
183
|
function getResolvedExports(checker, module) {
|
|
186
184
|
const resolvedExports = /* @__PURE__ */ new Map();
|
|
187
185
|
const exports = checker.getExportsOfModule(module);
|
|
@@ -216,8 +214,7 @@ function extractEnumDefinition(enumDeclaration) {
|
|
|
216
214
|
});
|
|
217
215
|
return `{ ${members.join(", ")} }`;
|
|
218
216
|
}
|
|
219
|
-
|
|
220
|
-
//#region src/extractor/lib.ts
|
|
217
|
+
// src/extractor/lib.ts
|
|
221
218
|
function isUserType(type) {
|
|
222
219
|
if (type.getFlags() & (ts.TypeFlags.StringLike | ts.TypeFlags.NumberLike | ts.TypeFlags.BooleanLike | ts.TypeFlags.ESSymbolLike | ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.Never)) return false;
|
|
223
220
|
const symbol = type.getSymbol();
|
|
@@ -229,8 +226,7 @@ function isUserType(type) {
|
|
|
229
226
|
if (srcFile.fileName.startsWith("/@vue/")) return false;
|
|
230
227
|
return true;
|
|
231
228
|
}
|
|
232
|
-
|
|
233
|
-
//#region src/extractor/export/index.ts
|
|
229
|
+
// src/extractor/export/index.ts
|
|
234
230
|
const FLAGS = ts.TypeFormatFlags.WriteArrowStyleSignature | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope | ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.UseFullyQualifiedType;
|
|
235
231
|
var CTypeExport = class {
|
|
236
232
|
program;
|
|
@@ -303,15 +299,15 @@ var CTypeExport = class {
|
|
|
303
299
|
const documentation = getDocumentationFromSymbol(signature, this.checker);
|
|
304
300
|
const typeParameters = getTemplateTypeParameters(signature, this);
|
|
305
301
|
const parameters = signature.getParameters().map((symbol) => {
|
|
306
|
-
const
|
|
302
|
+
const parameterDeclaration = symbol.valueDeclaration;
|
|
307
303
|
const pType = this.checker.getTypeOfSymbol(symbol);
|
|
308
|
-
this.extractType(pType,
|
|
309
|
-
const defaultValue =
|
|
304
|
+
this.extractType(pType, parameterDeclaration ?? this.index);
|
|
305
|
+
const defaultValue = parameterDeclaration?.initializer?.getText();
|
|
310
306
|
return cleanObject({
|
|
311
307
|
default: defaultValue,
|
|
312
308
|
description: documentation.params?.[symbol.name],
|
|
313
309
|
name: symbol.name,
|
|
314
|
-
optional: !!
|
|
310
|
+
optional: !!parameterDeclaration?.questionToken || defaultValue !== void 0 || void 0,
|
|
315
311
|
type: swapType(this.typeToString(pType), typeParameters)
|
|
316
312
|
});
|
|
317
313
|
});
|
|
@@ -324,7 +320,7 @@ var CTypeExport = class {
|
|
|
324
320
|
component.properties = props.props;
|
|
325
321
|
component.emits = props.emits;
|
|
326
322
|
Object.values(component.properties).forEach((prop) => {
|
|
327
|
-
prop.type = swapType(prop.type, typeParameters);
|
|
323
|
+
if (typeof prop.type === "string") prop.type = swapType(prop.type, typeParameters);
|
|
328
324
|
});
|
|
329
325
|
}
|
|
330
326
|
const slotsIndex = parameters.findIndex((parameter) => parameter.name === "__VLS_slots");
|
|
@@ -332,7 +328,7 @@ var CTypeExport = class {
|
|
|
332
328
|
if (slotsSymbol) {
|
|
333
329
|
component.slots = getSlots(this.checker.getTypeOfSymbol(slotsSymbol), this);
|
|
334
330
|
Object.values(component.slots).forEach((slot) => {
|
|
335
|
-
slot.type = swapType(slot.type, typeParameters);
|
|
331
|
+
if (typeof slot.type === "string") slot.type = swapType(slot.type, typeParameters);
|
|
336
332
|
});
|
|
337
333
|
}
|
|
338
334
|
this.result.components[name] = computeModels(component);
|
|
@@ -389,7 +385,7 @@ var CTypeExport = class {
|
|
|
389
385
|
const constraintTypeObj = this.checker.getTypeFromTypeNode(constraintType);
|
|
390
386
|
type = this.typeToString(constraintTypeObj);
|
|
391
387
|
}
|
|
392
|
-
return [typeParameter.
|
|
388
|
+
return [typeParameter.name.text, type];
|
|
393
389
|
}));
|
|
394
390
|
this.result.types[fullName] = {
|
|
395
391
|
...getDocumentationFromSymbol(symbol, this.checker),
|
|
@@ -397,7 +393,7 @@ var CTypeExport = class {
|
|
|
397
393
|
};
|
|
398
394
|
}
|
|
399
395
|
if (symbol.flags & ts.SymbolFlags.Interface && isUserType(type)) {
|
|
400
|
-
const declaration = symbol.getDeclarations()[0];
|
|
396
|
+
const declaration = symbol.getDeclarations()?.[0];
|
|
401
397
|
if (declaration) {
|
|
402
398
|
const properties = this.checker.getPropertiesOfType(type);
|
|
403
399
|
const exportProperties = {};
|
|
@@ -428,7 +424,7 @@ var CTypeExport = class {
|
|
|
428
424
|
"Required"
|
|
429
425
|
].includes(fullName)) {
|
|
430
426
|
this.cache.delete(type);
|
|
431
|
-
this.extractType(type.aliasTypeArguments[0]);
|
|
427
|
+
if (type.aliasTypeArguments?.[0]) this.extractType(type.aliasTypeArguments[0]);
|
|
432
428
|
return;
|
|
433
429
|
}
|
|
434
430
|
if (type.aliasTypeArguments?.some((typeArgument) => !isUserType(typeArgument))) return;
|
|
@@ -464,8 +460,7 @@ var CTypeExport = class {
|
|
|
464
460
|
return this.checker.typeToString(type, void 0, flags);
|
|
465
461
|
}
|
|
466
462
|
};
|
|
467
|
-
|
|
468
|
-
//#region src/extractor/generator.ts
|
|
463
|
+
// src/extractor/generator.ts
|
|
469
464
|
function generateNodes(exportResult, packageName = "unknown") {
|
|
470
465
|
const nodeResult = {
|
|
471
466
|
components: {},
|
|
@@ -547,8 +542,7 @@ function generateNodes(exportResult, packageName = "unknown") {
|
|
|
547
542
|
}
|
|
548
543
|
}
|
|
549
544
|
}
|
|
550
|
-
|
|
551
|
-
//#region src/extractor/config.ts
|
|
545
|
+
// src/extractor/config.ts
|
|
552
546
|
function findNearestTsConfig(configPath) {
|
|
553
547
|
while (true) {
|
|
554
548
|
const tsconfigPath = path.join(configPath, "tsconfig.json");
|
|
@@ -563,8 +557,7 @@ function getTsConfig(configPath) {
|
|
|
563
557
|
if (configFile.error) throw new Error(`Failed to read tsconfig.json: ${configFile.error.messageText}`);
|
|
564
558
|
return ts$1.parseJsonConfigFileContent(configFile.config, ts$1.sys, path.dirname(configPath));
|
|
565
559
|
}
|
|
566
|
-
|
|
567
|
-
//#region src/extractor/source.ts
|
|
560
|
+
// src/extractor/source.ts
|
|
568
561
|
function resolveModulePath(moduleName, compilerOptions) {
|
|
569
562
|
const tempFileName = path.join(process.cwd(), "__temp__.ts");
|
|
570
563
|
const tempHost = ts$1.createCompilerHost(compilerOptions);
|
|
@@ -590,8 +583,7 @@ function getSourceFile(moduleName) {
|
|
|
590
583
|
sourceFile
|
|
591
584
|
};
|
|
592
585
|
}
|
|
593
|
-
|
|
594
|
-
//#region src/extractor/index.ts
|
|
586
|
+
// src/extractor/index.ts
|
|
595
587
|
const fsp = fs.promises;
|
|
596
588
|
async function extractFile(filePath, target) {
|
|
597
589
|
const fileName = filePath.split("/").pop().split(".")[0];
|
|
@@ -606,5 +598,4 @@ async function extractFile(filePath, target) {
|
|
|
606
598
|
await fsp.writeFile(target, content);
|
|
607
599
|
}
|
|
608
600
|
}
|
|
609
|
-
//#endregion
|
|
610
601
|
export { CTypeExport, extractFile, generateNodes, getSourceFile };
|