diff --git a/.github/workflows/callable-test-tsc-compliance.yml b/.github/workflows/callable-test-tsc-compliance.yml new file mode 100644 index 00000000000..a81aaf06348 --- /dev/null +++ b/.github/workflows/callable-test-tsc-compliance.yml @@ -0,0 +1,17 @@ +name: Test Github Actions +on: workflow_call + +jobs: + tsc_compliance_test: + name: TSC Compliance Test + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0 https://github.com/actions/checkout/commit/24cb9080177205b6e8c946b17badbe402adc938f + with: + path: amplify-js + - name: Setup node and build the repository + uses: ./amplify-js/.github/actions/node-and-build + - name: Run GithubAction tests + working-directory: ./amplify-js + run: yarn test:tsc-compliance diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index a19885777cb..a9b133e35a6 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -33,6 +33,9 @@ jobs: github-actions-test: needs: prebuild uses: ./.github/workflows/callable-test-github-actions.yml + tsc-compliance-test: + needs: prebuild + uses: ./.github/workflows/callable-test-tsc-compliance.yml all-unit-tests-pass: name: Unit and Bundle tests have passed needs: @@ -40,6 +43,7 @@ jobs: - bundle-size-tests - license-test - github-actions-test + - tsc-compliance-test runs-on: ubuntu-latest # This is a bit of a hack - Branch protections depend upon selected # workflows that run on hardware, not parents of many callable workflows. diff --git a/lerna.json b/lerna.json index 125fde7d69c..fad77adc58b 100644 --- a/lerna.json +++ b/lerna.json @@ -7,7 +7,8 @@ "packages/analytics", "packages/storage", "packages/aws-amplify", - "packages/adapter-nextjs" + "packages/adapter-nextjs", + "scripts/tsc-compliance-test" ], "exact": true, "version": "independent", diff --git a/package.json b/package.json index 3404a7d56da..724f641f47e 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,12 @@ "setup-dev": "yarn && yarn bootstrap && yarn link-all && yarn build", "setup-dev:react-native": "node ./scripts/setup-dev-rn", "bootstrap": "lerna bootstrap", - "test": "lerna run test --stream && yarn test:license && yarn test:github-actions", + "test": "lerna run test --stream && yarn test:license && yarn test:github-actions && test:tsc-compliance", "test:size": "lerna run test:size --no-bail", "test:duplicates": "./scripts/duplicates-yarn.sh", "test:license": "license-check-and-add check -f license_config.json", "test:github-actions": "node ./scripts/test-github-actions.js", + "test:tsc-compliance": "yarn workspace tsc-compliance-test test:compliance:ts4.0", "coverage": "codecov || exit 0", "docs": "typedoc packages/**/src --name amplify-js --hideGenerator --excludePrivate --ignoreCompilerErrors --mode file --out docs/api --theme docs/amplify-theme/typedoc/ --readme README.md", "build": "lerna run build --stream && yarn test:duplicates", @@ -45,7 +46,8 @@ "packages/analytics", "packages/storage", "packages/aws-amplify", - "packages/adapter-nextjs" + "packages/adapter-nextjs", + "scripts/tsc-compliance-test" ], "nohoist": [ "**/@types/react-native", diff --git a/packages/storage/package.json b/packages/storage/package.json index ee062649e50..eb8e3b21d02 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -64,7 +64,7 @@ "s3" ], "dependencies": { - "@smithy/md5-js": "2.0.5", + "@smithy/md5-js": "2.0.7", "@aws-sdk/types": "3.398.0", "fast-xml-parser": "^4.2.5", "buffer": "4.9.2", diff --git a/scripts/tsc-compliance-test/README.md b/scripts/tsc-compliance-test/README.md new file mode 100644 index 00000000000..65c2c78beed --- /dev/null +++ b/scripts/tsc-compliance-test/README.md @@ -0,0 +1,5 @@ +This is an **internal-only** package to make sure all the Amplify JS library public interfaces are always compatible +with TypeScript 4.0 compiler. + +If any additional public APIs are added to the library, you must make sure the new API is included in the `ts4_0.ts` +file. diff --git a/scripts/tsc-compliance-test/package.json b/scripts/tsc-compliance-test/package.json new file mode 100644 index 00000000000..7b3c262ee3f --- /dev/null +++ b/scripts/tsc-compliance-test/package.json @@ -0,0 +1,14 @@ +{ + "name": "tsc-compliance-test", + "version": "0.1.0", + "license": "MIT", + "private": true, + "devDependencies": { + "@types/node": "^16.11.7", + "aws-amplify": "6.0.0", + "typescript": "4.0.x" + }, + "scripts": { + "test:compliance:ts4.0": "tsc -p tsconfig.json" + } +} diff --git a/scripts/tsc-compliance-test/ts4_0.ts b/scripts/tsc-compliance-test/ts4_0.ts new file mode 100644 index 00000000000..dcce2da6051 --- /dev/null +++ b/scripts/tsc-compliance-test/ts4_0.ts @@ -0,0 +1,31 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import * as Amplify from 'aws-amplify'; +import * as analytics from 'aws-amplify/analytics'; + +import * as auth from 'aws-amplify/auth'; +import * as authCognito from 'aws-amplify/auth/cognito'; +import * as authServer from 'aws-amplify/auth/server'; +import * as authCognitoServer from 'aws-amplify/auth/cognito/server'; + +import * as storage from 'aws-amplify/storage'; +import * as storageServer from 'aws-amplify/storage/server'; +import * as storageS3 from 'aws-amplify/storage/s3'; +import * as storageS3Server from 'aws-amplify/storage/s3/server'; + +import * as utils from 'aws-amplify/utils'; + +export const allPublicPaths = [ + Amplify, + analytics, + auth, + authCognito, + authServer, + authCognitoServer, + storage, + storageServer, + storageS3, + storageS3Server, + utils, +]; diff --git a/scripts/tsc-compliance-test/tsconfig.json b/scripts/tsc-compliance-test/tsconfig.json new file mode 100644 index 00000000000..e6533eadd6b --- /dev/null +++ b/scripts/tsc-compliance-test/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "noEmit": true, + "noImplicitAny": true, + "noImplicitReturns": true, + "strict": true, + "target": "ESNext", + "lib": ["DOM", "ESNext.AsyncIterable", "ES2018.AsyncGenerator"], + "moduleResolution": "node", + "types": ["node"] + }, + "include": ["ts4_0.ts"] +} diff --git a/yarn.lock b/yarn.lock index 16f2ff886ad..dc6fbc0d50d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2398,12 +2398,12 @@ dependencies: tslib "^2.5.0" -"@smithy/md5-js@2.0.5": - version "2.0.5" - resolved "https://registry.yarnpkg.com/@smithy/md5-js/-/md5-js-2.0.5.tgz#02173e4e21105819efa8ebaa17eab23d5663f896" - integrity sha512-k5EOte/Ye2r7XBVaXv2rhiehk6l3T4uRiPF+pnxKEc+G9Fwd1xAXBDZrtOq1syFPBKBmVfNszG4nevngST7NKg== +"@smithy/md5-js@2.0.7": + version "2.0.7" + resolved "https://registry.yarnpkg.com/@smithy/md5-js/-/md5-js-2.0.7.tgz#4dea27b20b065857f953c74dbaa050003f48a374" + integrity sha512-2i2BpXF9pI5D1xekqUsgQ/ohv5+H//G9FlawJrkOJskV18PgJ8LiNbLiskMeYt07yAsSTZR7qtlcAaa/GQLWww== dependencies: - "@smithy/types" "^2.2.2" + "@smithy/types" "^2.3.1" "@smithy/util-utf8" "^2.0.0" tslib "^2.5.0" @@ -2774,6 +2774,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-20.6.1.tgz#8b589bba9b2af0128796461a0979764562687e6f" integrity sha512-4LcJvuXQlv4lTHnxwyHQZ3uR9Zw2j7m1C9DfuwoTFQQP4Pmu04O6IfLYgMmHoOCt0nosItLLZAH+sOrRE0Bo8g== +"@types/node@^16.11.7": + version "16.18.52" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.52.tgz#70c56b55d0d7e15fafa875127e95a92605c59c9b" + integrity sha512-sm2aph6cRSsTMFYFgI+RpPLunXO9ClJkpizUVdT7KmGeyfQ14xnjTMT/f3MHcfKqevXqGT6BgVFzW8wcEoDUtA== + "@types/node@^8.9.5": version "8.10.66" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.66.tgz#dd035d409df322acc83dff62a602f12a5783bbb3" @@ -12378,6 +12383,11 @@ typescript-coverage-report@^0.6.4: semantic-ui-react "^0.88.2" type-coverage-core "^2.17.2" +typescript@4.0.x: + version "4.0.8" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.8.tgz#5739105541db80a971fdbd0d56511d1a6f17d37f" + integrity sha512-oz1765PN+imfz1MlZzSZPtC/tqcwsCyIYA8L47EkRnRW97ztRk83SzMiWLrnChC0vqoYxSU1fcFUDA5gV/ZiPg== + typescript@5.0.2: version "5.0.2" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.2.tgz#891e1a90c5189d8506af64b9ef929fca99ba1ee5"