diff --git a/.circleci/config.yml b/.circleci/config.yml index 25e14c85..67bb7a83 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,18 +21,22 @@ executors: TZ: "/usr/share/zoneinfo/America/Los_Angeles" commands: + setup_auth: + description: Configure authentication for deployments + steps: + - add_ssh_keys: + fingerprints: + - "SHA256:hUAWVYdfSW5ml6ufbfyEHUcuPwUJ88xVhsZc21b2lA8" + - run: mkdir -p ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config + - run: git config --global user.name "Intuit Service" + - run: git config --global user.email "opensource-svc@intuit.com" + auto_shipit: description: Perform Auto shipit steps: - attach_workspace: at: ~/tools - - - restore_cache: - keys: - - v1-bazel-cache-core-{{ .Branch }}-{{ .Revision }} - - v1-bazel-cache-core-{{ .Branch }} - - v1-bazel-cache-core-main - + - setup_auth - run: echo "//registry.npmjs.com/:_authToken=$NPM_TOKEN" >> ~/.npmrc - run: echo -e $GPG_KEY | gpg --import --batch - run: | @@ -70,7 +74,7 @@ jobs: executor: base steps: - attach_workspace: - at: ~/player + at: ~/tools - run: | echo "build --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local echo "test --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local @@ -87,12 +91,6 @@ jobs: at: ~/tools # Python files don't have a build step so we only need to actually build the JS files - run: bazel build -- $(bazel query "kind(npm_package, //...)" --output label 2>/dev/null | tr '\n' ' ') - - - save_cache: - paths: - - node_modules - key: v1-dependencies-{ { checksum "package.json" }} - - persist_to_workspace: root: . paths: @@ -105,12 +103,6 @@ jobs: - attach_workspace: at: ~/tools - - restore_cache: - keys: - - v1-bazel-cache-core-{{ .Branch }}-{{ .Revision }} - - v1-bazel-cache-core-{{ .Branch }} - - v1-bazel-cache-core-main - - run: | bazel coverage --config=ci -- $(bazel query "kind(js_test, //...) + kind(py_test, //...)" --output label 2>/dev/null | tr '\n' ' ') diff --git a/language/generators/fluent/BUILD b/language/generators/fluent/BUILD index 28acdfd3..c6866cc1 100644 --- a/language/generators/fluent/BUILD +++ b/language/generators/fluent/BUILD @@ -11,8 +11,6 @@ vitest_config(name = "vitest_config") js_pipeline( package_name = "@player-tools/fluent-generator", test_deps = [ - "//:node_modules", - "//:vitest_config", ":node_modules/@player-tools/test-utils", ":node_modules/@player-tools/xlr-converters", ":node_modules/@player-tools/fluent", @@ -20,6 +18,10 @@ js_pipeline( deps = [ ":node_modules/@player-tools/xlr", ":node_modules/@player-tools/xlr-utils", - ":node_modules/ts-morph", + "//:node_modules/ts-morph", + "//:node_modules/typescript" ], + peer_deps = [ + "//:node_modules/@player-ui/types" + ] ) diff --git a/language/generators/fluent/package.json b/language/generators/fluent/package.json index f24343db..e345b07e 100644 --- a/language/generators/fluent/package.json +++ b/language/generators/fluent/package.json @@ -7,15 +7,11 @@ }, "dependencies": { "@player-tools/xlr": "workspace:*", - "@player-tools/xlr-utils": "workspace:*", - "ts-morph": "^24.0.0" + "@player-tools/xlr-utils": "workspace:*" }, "devDependencies": { "@player-tools/fluent": "workspace:*", "@player-tools/test-utils": "workspace:*", "@player-tools/xlr-converters": "workspace:*" - }, - "peerDependencies": { - "@player-ui/types": ">=0.12.0" } } diff --git a/package.json b/package.json index 71848cbd..d6669430 100644 --- a/package.json +++ b/package.json @@ -156,6 +156,7 @@ "tiny-uid": "^1.1.2", "ts-deepmerge": "^7.0.2", "ts-loader": "^5.3.3", + "ts-morph": "^24.0.0", "ts-node": "^10.4.0", "tsconfig-to-swcconfig": "^2.7.0", "tslib": "^2.6.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0b5c1a96..051b0cc5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -414,6 +414,9 @@ importers: ts-loader: specifier: ^5.3.3 version: 5.4.5(typescript@5.5.4) + ts-morph: + specifier: ^24.0.0 + version: 24.0.0 ts-node: specifier: ^10.4.0 version: 10.9.2(@types/node@18.19.34)(typescript@5.5.4) @@ -586,12 +589,6 @@ importers: '@player-tools/xlr-utils': specifier: workspace:* version: link:../../../xlr/utils - '@player-ui/types': - specifier: '>=0.12.0' - version: 0.14.1 - ts-morph: - specifier: ^24.0.0 - version: 24.0.0 devDependencies: '@player-tools/fluent': specifier: workspace:* @@ -3144,9 +3141,6 @@ packages: '@player-ui/types@0.12.0-next.1': resolution: {integrity: sha512-9rILZKIvu6lSGQZ7oVIqzwk7ap6clo7E4iutS0PUJoGkjlwsDEpGIDu1O7wiKRJNmYmY0GCL4JOJdglCFEJnRA==, tarball: https://registry.npmjs.org/@player-ui/types/-/types-0.12.0-next.1.tgz} - '@player-ui/types@0.14.1': - resolution: {integrity: sha512-AXBKPMLm+vhEvQeaevKiOSYXo5B6H0qga1iwEZhXAaZ0zOWqAv+bxEHVK87RVQpJAxRAqO64bsJ7G9LD9XGr3g==, tarball: https://registry.npmjs.org/@player-ui/types/-/types-0.14.1.tgz} - '@player-ui/types@0.7.2-next.4': resolution: {integrity: sha512-wvKlmu+ZJSVT5fs/vHHwpv4KhgZmqinJBvHhttU4LHzqrEauaRcS/DVCItABXt6ABxhIakPInnxQtH1xCwdDyQ==, tarball: https://registry.npmjs.org/@player-ui/types/-/types-0.7.2-next.4.tgz} @@ -15282,10 +15276,6 @@ snapshots: dependencies: tslib: 2.6.3 - '@player-ui/types@0.14.1': - dependencies: - tslib: 2.6.3 - '@player-ui/types@0.7.2-next.4': dependencies: '@babel/runtime': 7.15.4 diff --git a/xlr/converters/src/ts-to-xlr.ts b/xlr/converters/src/ts-to-xlr.ts index 47cfb9ea..7c7195b9 100644 --- a/xlr/converters/src/ts-to-xlr.ts +++ b/xlr/converters/src/ts-to-xlr.ts @@ -122,7 +122,13 @@ export class TsConverter { } /** Converts all exported objects to a XLR representation */ - public convertSourceFile(sourceFile: ts.SourceFile) { + public convertSourceFile(sourceFile: ts.SourceFile): { + data: { + version: number; + types: NonNullable[]; + }; + convertedTypes: string[]; + } { const declarations = sourceFile.statements.filter(isTopLevelNode); const types = declarations diff --git a/xlr/sdk/BUILD b/xlr/sdk/BUILD index 4c32c579..0f25f4aa 100644 --- a/xlr/sdk/BUILD +++ b/xlr/sdk/BUILD @@ -14,8 +14,6 @@ js_pipeline( "//:node_modules/typescript", ], test_deps = [ - ":node_modules", - "//:vitest_config", ":node_modules/@player-tools/static-xlrs", ], deps = [ diff --git a/xlr/sdk/src/__tests__/sdk.test.ts b/xlr/sdk/src/__tests__/sdk.test.ts index 4b7d1307..6f4ac504 100644 --- a/xlr/sdk/src/__tests__/sdk.test.ts +++ b/xlr/sdk/src/__tests__/sdk.test.ts @@ -264,6 +264,29 @@ describe("Or Type Validation", () => { "Expected: apple | banana | carrot | deli-meat", ); }); + + test("Uses primitive type names over titles", () => { + const sdk = new XLRSDK(); + sdk.loadDefinitionsFromModule(Types); + sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest); + const validator = new XLRValidator(sdk.getType.bind(sdk)); + + const orType: OrType = { + type: "or", + or: [{ type: "string", title: "TextAsset.value" }, { type: "boolean" }], + }; + + const rootNode = parseTree(`1`); + if (!rootNode) { + throw new Error("Expected root node to be parsed"); + } + + const validationResult = validator.validateType(rootNode, orType); + + expect(validationResult[0].message).toBe( + "Does not match any of the types: string | boolean", + ); + }); }); describe("generateNestedTypesInfo Test", () => { diff --git a/xlr/sdk/src/__tests__/utils.test.ts b/xlr/sdk/src/__tests__/utils.test.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/xlr/sdk/src/validator.ts b/xlr/sdk/src/validator.ts index 11121d86..02f3b670 100644 --- a/xlr/sdk/src/validator.ts +++ b/xlr/sdk/src/validator.ts @@ -97,7 +97,11 @@ export class XLRValidator { let message: string; const expectedTypes = xlrNode.or - .map((node) => node.name ?? node.title ?? node.type ?? "") + .map((node) => + isPrimitiveTypeNode(node) + ? node.type + : (node.name ?? node.title ?? node.type ?? ""), + ) .join(" | "); if (xlrNode.name) { diff --git a/xlr/utils/BUILD b/xlr/utils/BUILD index b9f15842..2e7760f8 100644 --- a/xlr/utils/BUILD +++ b/xlr/utils/BUILD @@ -15,8 +15,6 @@ js_pipeline( "//:node_modules/jsonc-parser", ], test_deps = [ - "//:node_modules", - "//:vitest_config", ":node_modules/@player-tools/test-utils", ], deps = [ diff --git a/xlr/utils/src/ts-helpers.ts b/xlr/utils/src/ts-helpers.ts index 793032a2..e21fb251 100644 --- a/xlr/utils/src/ts-helpers.ts +++ b/xlr/utils/src/ts-helpers.ts @@ -49,7 +49,12 @@ export function isNodeExported(node: ts.Node): boolean { export function getReferencedType( node: ts.TypeReferenceNode, typeChecker: ts.TypeChecker, -) { +): + | { + declaration: ts.TypeAliasDeclaration | ts.InterfaceDeclaration; + exported: boolean; + } + | undefined { let symbol = typeChecker.getSymbolAtLocation(node.typeName); if (