From f4ef2e9e33202faf04d2a700b0fcac314914cb6e Mon Sep 17 00:00:00 2001 From: michaelrambeau Date: Wed, 2 Aug 2023 17:10:43 +0900 Subject: [PATCH 1/4] Handle `React.ReactChild` correctly --- packages/uxpin-merge-cli/package.json | 2 +- .../typescript/property/type/checker.ts | 57 +++++++++++++++++++ .../property/type/checker/isBooleanLike.ts | 6 -- .../property/type/checker/isCallable.ts | 6 -- .../property/type/checker/isEnum.ts | 9 --- .../property/type/checker/isIntersection.ts | 5 -- .../type/checker/isIntersectionOfObjects.ts | 7 --- .../type/checker/isKnownPropertyType.ts | 10 ---- .../property/type/checker/isLiteral.ts | 5 -- .../property/type/checker/isObject.ts | 6 -- .../property/type/checker/isObjectLike.ts | 7 --- .../property/type/checker/isUnion.ts | 5 -- .../type/node/convertTypeToPropertyType.ts | 14 ++--- .../type/node/serializeKnownPropertyType.ts | 1 + packages/uxpin-merge-cli/yarn.lock | 8 +-- 15 files changed, 67 insertions(+), 81 deletions(-) create mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isBooleanLike.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isCallable.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isEnum.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersection.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersectionOfObjects.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isKnownPropertyType.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isLiteral.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObject.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObjectLike.ts delete mode 100644 packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isUnion.ts diff --git a/packages/uxpin-merge-cli/package.json b/packages/uxpin-merge-cli/package.json index e55a8efdf..bd761e663 100644 --- a/packages/uxpin-merge-cli/package.json +++ b/packages/uxpin-merge-cli/package.json @@ -133,7 +133,7 @@ "sortobject": "^1.1.1", "source-map-support": "^0.4.18", "tslib": "^1.9.0", - "typescript": "4.4.2", + "typescript": "4.8.4", "uuid": "^3.3.2", "webpack-merge": "^4.1.2", "webpack-virtual-modules": "^0.5.0" diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker.ts new file mode 100644 index 000000000..1ab665866 --- /dev/null +++ b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker.ts @@ -0,0 +1,57 @@ +import * as ts from 'typescript'; + +import { KNOWN_TYPES_MAP } from './node/serializeKnownPropertyType'; + +export function isAny(type: ts.Type): boolean { + return Boolean(type.flags & ts.TypeFlags.Any); +} + +export function isBooleanLike(type: ts.Type): boolean { + return Boolean(type.flags & ts.TypeFlags.BooleanLike); +} + +export function isCallable(type: ts.Type): boolean { + return isObjectLike(type) && !!type.getCallSignatures().length; +} + +export function isEnum(type: ts.Type): type is ts.LiteralType { + if (type.symbol?.valueDeclaration) { + return ts.isEnumMember(type.symbol.valueDeclaration); + } + + return false; +} + +export function isKnownPropertyType(type: ts.Type): boolean { + const typeSymbol: ts.Symbol = type.symbol || type.aliasSymbol; + + return ( + (isAny(type) || isObjectLike(type) || isUnion(type)) && + typeSymbol && + typeSymbol.escapedName.toString() in KNOWN_TYPES_MAP + ); +} + +export function isIntersection(type: ts.Type): type is ts.IntersectionType { + return type.isIntersection(); +} + +export function isIntersectionOfObjects(type: ts.Type): boolean { + return isIntersection(type) && type.types.every(isObjectLike); +} + +export function isLiteral(type: ts.Type): type is ts.LiteralType { + return type.isLiteral(); +} + +export function isObject(type: ts.Type): boolean { + return Boolean(type.flags & ts.TypeFlags.Object || type.flags & ts.TypeFlags.NonPrimitive); +} + +export function isObjectLike(type: ts.Type): boolean { + return isObject(type) || isIntersectionOfObjects(type); +} + +export function isUnion(type: ts.Type): type is ts.UnionType { + return type.isUnion(); +} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isBooleanLike.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isBooleanLike.ts deleted file mode 100644 index 45e8d8a02..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isBooleanLike.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as ts from 'typescript'; - -export function isBooleanLike(type: ts.Type): boolean { - // tslint:disable-next-line no-bitwise - return Boolean(type.flags & ts.TypeFlags.BooleanLike); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isCallable.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isCallable.ts deleted file mode 100644 index 65ec8f1c8..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isCallable.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as ts from 'typescript'; -import { isObjectLike } from './isObjectLike'; - -export function isCallable(type: ts.Type): boolean { - return isObjectLike(type) && !!type.getCallSignatures().length; -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isEnum.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isEnum.ts deleted file mode 100644 index e9e5111ae..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isEnum.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as ts from 'typescript'; - -export function isEnum(type: ts.Type): type is ts.LiteralType { - if (type.symbol?.valueDeclaration) { - return ts.isEnumMember(type.symbol.valueDeclaration); - } - - return false; -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersection.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersection.ts deleted file mode 100644 index ba5e8ccb2..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersection.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as ts from 'typescript'; - -export function isIntersection(type: ts.Type): type is ts.IntersectionType { - return type.isIntersection(); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersectionOfObjects.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersectionOfObjects.ts deleted file mode 100644 index affc16d82..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isIntersectionOfObjects.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as ts from 'typescript'; -import { isIntersection } from './isIntersection'; -import { isObjectLike } from './isObjectLike'; - -export function isIntersectionOfObjects(type: ts.Type): boolean { - return isIntersection(type) && type.types.every(isObjectLike); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isKnownPropertyType.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isKnownPropertyType.ts deleted file mode 100644 index c6c339437..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isKnownPropertyType.ts +++ /dev/null @@ -1,10 +0,0 @@ -import * as ts from 'typescript'; -import { KNOWN_TYPES_MAP } from '../node/serializeKnownPropertyType'; -import { isObjectLike } from './isObjectLike'; -import { isUnion } from './isUnion'; - -export function isKnownPropertyType(type: ts.Type): boolean { - const typeSymbol: ts.Symbol = type.symbol || type.aliasSymbol; - - return (isObjectLike(type) || isUnion(type)) && typeSymbol && typeSymbol.escapedName.toString() in KNOWN_TYPES_MAP; -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isLiteral.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isLiteral.ts deleted file mode 100644 index 7519d9365..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isLiteral.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as ts from 'typescript'; - -export function isLiteral(type: ts.Type): type is ts.LiteralType { - return type.isLiteral(); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObject.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObject.ts deleted file mode 100644 index 4b1b36e60..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObject.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as ts from 'typescript'; - -export function isObject(type: ts.Type): boolean { - // tslint:disable-next-line no-bitwise - return Boolean(type.flags & ts.TypeFlags.Object || type.flags & ts.TypeFlags.NonPrimitive); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObjectLike.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObjectLike.ts deleted file mode 100644 index a69e8697d..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isObjectLike.ts +++ /dev/null @@ -1,7 +0,0 @@ -import * as ts from 'typescript'; -import { isIntersectionOfObjects } from './isIntersectionOfObjects'; -import { isObject } from './isObject'; - -export function isObjectLike(type: ts.Type): boolean { - return isObject(type) || isIntersectionOfObjects(type); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isUnion.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isUnion.ts deleted file mode 100644 index 48db4c2af..000000000 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/checker/isUnion.ts +++ /dev/null @@ -1,5 +0,0 @@ -import * as ts from 'typescript'; - -export function isUnion(type: ts.Type): type is ts.UnionType { - return type.isUnion(); -} diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts index bd910464a..61dadd597 100644 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts +++ b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts @@ -1,13 +1,7 @@ import * as ts from 'typescript'; import { PropertyType } from '../../../../ComponentPropertyDefinition'; import { TSSerializationContext } from '../../../context/getSerializationContext'; -import { isBooleanLike } from '../checker/isBooleanLike'; -import { isCallable } from '../checker/isCallable'; -import { isEnum } from '../checker/isEnum'; -import { isKnownPropertyType } from '../checker/isKnownPropertyType'; -import { isLiteral } from '../checker/isLiteral'; -import { isObjectLike } from '../checker/isObjectLike'; -import { isUnion } from '../checker/isUnion'; +import { isBooleanLike, isCallable, isEnum, isKnownPropertyType, isLiteral, isObjectLike, isUnion } from '../checker'; import { serializeAsUnsupportedType } from './serializeAsUnsupportedType'; import { serializeEnumType } from './serializeEnumType'; import { serializeKnownPropertyType } from './serializeKnownPropertyType'; @@ -28,12 +22,12 @@ export function convertTypeToPropertyType( if (isBooleanLike(type)) { return { name: 'boolean', structure: {} }; } - if (type.flags & ts.TypeFlags.Any) { - return { name: 'any', structure: {} }; - } if (isKnownPropertyType(type)) { return serializeKnownPropertyType(type); } + if (type.flags & ts.TypeFlags.Any) { + return { name: 'any', structure: {} }; + } if (isCallable(type)) { return { name: 'func', structure: {} }; } diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts index e7796136a..41aa38e3a 100644 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts +++ b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts @@ -6,6 +6,7 @@ export const KNOWN_TYPES_MAP: { [typeName: string]: PropertyType } = { Date: { name: 'date', structure: {} }, ReactElement: { name: 'element', structure: {} }, ReactNode: { name: 'node', structure: {} }, + ReactChild: { name: 'node', structure: {} }, }; export function serializeKnownPropertyType(type: ts.Type): PropertyType { diff --git a/packages/uxpin-merge-cli/yarn.lock b/packages/uxpin-merge-cli/yarn.lock index 2f343c41c..9592c153d 100644 --- a/packages/uxpin-merge-cli/yarn.lock +++ b/packages/uxpin-merge-cli/yarn.lock @@ -7290,10 +7290,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@4.4.2: - version "4.4.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86" - integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ== +typescript@4.8.4: + version "4.8.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6" + integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ== typescript@>=5.0.2: version "5.0.4" From 3abc06d43dfedf8c2e6f4cb831b3bb650fe68b22 Mon Sep 17 00:00:00 2001 From: michaelrambeau Date: Wed, 2 Aug 2023 17:32:42 +0900 Subject: [PATCH 2/4] Use more the new `isAny` function --- .../property/type/node/convertTypeToPropertyType.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts index 61dadd597..d93a1a39f 100644 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts +++ b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/convertTypeToPropertyType.ts @@ -1,7 +1,16 @@ import * as ts from 'typescript'; import { PropertyType } from '../../../../ComponentPropertyDefinition'; import { TSSerializationContext } from '../../../context/getSerializationContext'; -import { isBooleanLike, isCallable, isEnum, isKnownPropertyType, isLiteral, isObjectLike, isUnion } from '../checker'; +import { + isAny, + isBooleanLike, + isCallable, + isEnum, + isKnownPropertyType, + isLiteral, + isObjectLike, + isUnion, +} from '../checker'; import { serializeAsUnsupportedType } from './serializeAsUnsupportedType'; import { serializeEnumType } from './serializeEnumType'; import { serializeKnownPropertyType } from './serializeKnownPropertyType'; @@ -25,7 +34,7 @@ export function convertTypeToPropertyType( if (isKnownPropertyType(type)) { return serializeKnownPropertyType(type); } - if (type.flags & ts.TypeFlags.Any) { + if (isAny(type)) { return { name: 'any', structure: {} }; } if (isCallable(type)) { From 04f133de1c5e2295c867346d6bc8f93add287493 Mon Sep 17 00:00:00 2001 From: michaelrambeau Date: Wed, 2 Aug 2023 17:39:24 +0900 Subject: [PATCH 3/4] Set temporary package name for `dev` release --- packages/uxpin-merge-cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/uxpin-merge-cli/package.json b/packages/uxpin-merge-cli/package.json index bd761e663..db184ce4e 100644 --- a/packages/uxpin-merge-cli/package.json +++ b/packages/uxpin-merge-cli/package.json @@ -1,6 +1,6 @@ { "name": "@uxpin/merge-cli", - "version": "3.3.0", + "version": "3.3.0-atlas", "description": "The Command-line tool integrates the Design System repository with: https://www.uxpin.com/merge", "repository": { "type": "git", From cd56abc1d328640cbe0bcbb859118b44ac58c3c3 Mon Sep 17 00:00:00 2001 From: michaelrambeau Date: Thu, 3 Aug 2023 18:34:19 +0900 Subject: [PATCH 4/4] Handle more types coming from Altassian DS --- .../property/type/node/serializeKnownPropertyType.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts index 41aa38e3a..7bce998ae 100644 --- a/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts +++ b/packages/uxpin-merge-cli/src/steps/serialization/component/implementation/typescript/property/type/node/serializeKnownPropertyType.ts @@ -7,6 +7,11 @@ export const KNOWN_TYPES_MAP: { [typeName: string]: PropertyType } = { ReactElement: { name: 'element', structure: {} }, ReactNode: { name: 'node', structure: {} }, ReactChild: { name: 'node', structure: {} }, + ReactNodeArray: { name: 'node', structure: {} }, + // TODO Following types are very specific and should be handled in a different way + // Maybe defaulting unknown types to `string` instead of `any` would be better? + AnchorHTMLAttributes: { name: 'string', structure: {} }, + ButtonHTMLAttributes: { name: 'string', structure: {} }, }; export function serializeKnownPropertyType(type: ts.Type): PropertyType {