Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle aliased symbols in namespaces in api check #1926

Merged
merged 3 commits into from
Aug 28, 2024
Merged

Conversation

sobolk
Copy link
Member

@sobolk sobolk commented Aug 27, 2024

Problem

Sometimes the same symbol name appears under different namespaces.
When this happen API Extractor aliases the type with _<number> suffix to de-duplicate it and presents the type as exported with alias.

This became visible after #1917 got merged.

For example (see https://github.com/aws-amplify/amplify-backend/blob/main/packages/client-config/API.md).

// @public
type AmazonCognitoStandardAttributes = 'address' | 'birthdate' | 'email' | 'family_name' | 'gender' | 'given_name' | 'locale' | 'middle_name' | 'name' | 'nickname' | 'phone_number' | 'picture' | 'preferred_username' | 'profile' | 'sub' | 'updated_at' | 'website' | 'zoneinfo';

// @public
type AmazonCognitoStandardAttributes_2 = 'address' | 'birthdate' | 'email' | 'family_name' | 'gender' | 'given_name' | 'locale' | 'middle_name' | 'name' | 'nickname' | 'phone_number' | 'picture' | 'preferred_username' | 'profile' | 'sub' | 'updated_at' | 'website' | 'zoneinfo';

...

declare namespace clientConfigTypesV1_1 {
    export {
        AmazonCognitoStandardAttributes,

...


declare namespace clientConfigTypesV1 {
    export {
        AmazonCognitoStandardAttributes_2 as AmazonCognitoStandardAttributes,

This has led to the following error:

    Error: Validation of @aws-amplify/client-config failed, compiler output:
    index.ts(6,10): error TS2305: Module '"@aws-amplify/client-config"' has no exported member 'AmazonCognitoStandardAttributes_2'.
    index.ts(7,10): error TS2305: Module '"@aws-amplify/client-config"' has no exported member 'AmazonPinpointChannels_2'.
    index.ts(10,10): error TS2305: Module '"@aws-amplify/client-config"' has no exported member 'AwsAppsyncAuthorizationType_2'.
    index.ts(11,10): error TS2305: Module '"@aws-amplify/client-config"' has no exported member 'AwsRegion_2'.
        at ApiChangesValidator.validate (/home/runner/work/amplify-backend/amplify-backend/scripts/components/api-changes-validator/api_changes_validator.ts:61:13)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at <anonymous> (/home/runner/work/amplify-backend/amplify-backend/scripts/check_api_changes.ts:70:5)
        at async Promise.allSettled (index 10)
        at <anonymous> (/home/runner/work/amplify-backend/amplify-backend/scripts/check_api_changes.ts:50:27)

Changes

This PR adds logic to handle the case where type exported from namespace might be aliased.

Validation

Added content to test project. (so that npm run test:scripts covers it).
This PRs checks.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

changeset-bot bot commented Aug 27, 2024

⚠️ No Changeset found

Latest commit: 3ab9067

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sobolk sobolk marked this pull request as ready for review August 27, 2024 22:15
@sobolk sobolk requested review from a team as code owners August 27, 2024 22:15
awsluja
awsluja previously approved these changes Aug 27, 2024
Amplifiyer
Amplifiyer previously approved these changes Aug 28, 2024
Copy link
Contributor

@Amplifiyer Amplifiyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@sobolk sobolk dismissed stale reviews from Amplifiyer and awsluja via 3ab9067 August 28, 2024 14:07
@sobolk sobolk enabled auto-merge (squash) August 28, 2024 14:17
@sobolk sobolk merged commit 5d6eef2 into main Aug 28, 2024
37 checks passed
@sobolk sobolk deleted the handle-aliased-types branch August 28, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants