From 948f909d87f448b06343c95aaa9cc01da67d399a Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Mon, 26 Aug 2024 08:56:44 -0700 Subject: [PATCH 01/16] chore: created param to track inconsistent dependencies --- scripts/check_dependencies.ts | 16 +++++++- scripts/components/dependencies_validator.ts | 43 +++++++++++++------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index 53062b8f28..d936804775 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -1,7 +1,7 @@ import { glob } from 'glob'; import { DependenciesValidator } from './components/dependencies_validator.js'; -await new DependenciesValidator( +await new DependenciesValidator( //**the structure of this comes from dependencies_validator.ts await glob('packages/*'), { 'aws-amplify': { @@ -21,5 +21,17 @@ await new DependenciesValidator( ], }, }, - [['aws-cdk', 'aws-cdk-lib']] + [['aws-cdk', 'aws-cdk-lib']], + [ + { + dependencyName: 'execa', + globalDependencyVersion: '^8.0.1', + exceptions: [ + { + packageName: '@aws-amplify/plugin-types', + dependencyVersion: '^5.1.1', + }, + ], + }, + ] ).validate(); diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index 980bfdde80..a8f115d80b 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -2,15 +2,22 @@ import { execa as _execa } from 'execa'; import { EOL } from 'os'; import { PackageJson, readPackageJson } from './package-json/package_json.js'; -export type DependencyRule = - | { - denyAll: true; - allowList?: never; - } - | { - denyAll?: never; - allowList: Array; - }; +export type DependencyRule = //** going to assume this might not be what I want to refactor... + + | { + denyAll: true; + allowList?: never; + } + | { + denyAll?: never; + allowList: Array; + }; + +export type DependencyWithKnownException = { + dependencyName: string; + globalDependencyVersion: string; + exceptions: Array<{ packageName: string; dependencyVersion: string }>; +}; type NpmListOutputItem = { name?: string; @@ -47,14 +54,17 @@ export class DependenciesValidator { /** * Creates dependency validator * @param packagePaths paths of packages to validate - * @param dependencyRules dependency exclusion and inclusion rules + * @param disallowedDependencies dependency exclusion and inclusion rules * @param linkedDependencies dependencies that should be versioned with the same version + * @param knownInconsistentDependencies dependencies that are known to violate the consistency check * @param execa in order to inject execa mock in tests */ constructor( + //**constructs the dependencies validator -- will want to alter this private packagePaths: Array, - private dependencyRules: Record, - private linkedDependencies: Array>, + private disallowedDependencies: Record, //**consider refactoring dependencyRules and linkedDependencies + private linkedDependencies: Array>, //** I am assuming these are dependencies that should share the same version + private knownInconsistentDependencies: Array, //**previously Record> private execa = _execa ) {} @@ -202,9 +212,9 @@ export class DependenciesValidator { // skip if self referencing continue; } - if (dependencyName in this.dependencyRules) { + if (dependencyName in this.disallowedDependencies) { const dependencyRule: DependencyRule = - this.dependencyRules[dependencyName]; + this.disallowedDependencies[dependencyName]; const isViolating = dependencyRule.denyAll || !dependencyRule.allowList.includes(packageName); @@ -241,12 +251,17 @@ export class DependenciesValidator { } private getPackageVersionDeclarationPredicate = async ( + //**this is where we map packages to dependency versions packageName: string ): Promise => { if (packageName === 'execa') { + //** check if the packageName is a known inconsistent dependency // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 // all other packages must depend on execa@^8.0.1 // this can be removed once execa is patched + //**if the package is a known inconsistent depencency, then we want to make sure every package but the one(s) specified are using the default version + //**so we want to iterate through the array of packageName-DependencyVer pairs, ensure all of them are using the right version + //**in general, the arrays of pairs should be short, so we could do an in operation to find if the package name is in the list if it comes up... return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) => From 7d654af19f1544695d29f232021e90822f53a798 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Mon, 26 Aug 2024 10:35:01 -0700 Subject: [PATCH 02/16] chore: changed knownInconsistentDependencyViolations to record for easier lookup --- scripts/check_dependencies.ts | 7 ++--- scripts/components/dependencies_validator.ts | 32 +++++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index d936804775..45cfb71082 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -22,9 +22,8 @@ await new DependenciesValidator( //**the structure of this comes from dependenci }, }, [['aws-cdk', 'aws-cdk-lib']], - [ - { - dependencyName: 'execa', + { + execa: { globalDependencyVersion: '^8.0.1', exceptions: [ { @@ -33,5 +32,5 @@ await new DependenciesValidator( //**the structure of this comes from dependenci }, ], }, - ] + } ).validate(); diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index a8f115d80b..40b1e5fe1c 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -2,19 +2,17 @@ import { execa as _execa } from 'execa'; import { EOL } from 'os'; import { PackageJson, readPackageJson } from './package-json/package_json.js'; -export type DependencyRule = //** going to assume this might not be what I want to refactor... - - | { - denyAll: true; - allowList?: never; - } - | { - denyAll?: never; - allowList: Array; - }; +export type DependencyRule = + | { + denyAll: true; + allowList?: never; + } + | { + denyAll?: never; + allowList: Array; + }; export type DependencyWithKnownException = { - dependencyName: string; globalDependencyVersion: string; exceptions: Array<{ packageName: string; dependencyVersion: string }>; }; @@ -60,11 +58,13 @@ export class DependenciesValidator { * @param execa in order to inject execa mock in tests */ constructor( - //**constructs the dependencies validator -- will want to alter this private packagePaths: Array, - private disallowedDependencies: Record, //**consider refactoring dependencyRules and linkedDependencies - private linkedDependencies: Array>, //** I am assuming these are dependencies that should share the same version - private knownInconsistentDependencies: Array, //**previously Record> + private disallowedDependencies: Record, + private linkedDependencies: Array>, + private knownInconsistentDependencies: Record< + string, + DependencyWithKnownException + >, private execa = _execa ) {} @@ -260,8 +260,6 @@ export class DependenciesValidator { // all other packages must depend on execa@^8.0.1 // this can be removed once execa is patched //**if the package is a known inconsistent depencency, then we want to make sure every package but the one(s) specified are using the default version - //**so we want to iterate through the array of packageName-DependencyVer pairs, ensure all of them are using the right version - //**in general, the arrays of pairs should be short, so we could do an in operation to find if the package name is in the list if it comes up... return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) => From e02a47da813f7f1bb1fb78993149682b8814a05d Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Mon, 26 Aug 2024 14:10:34 -0700 Subject: [PATCH 03/16] fix: updated dependency validator to be more general in testing for known inconsistent dependencies --- scripts/check_dependencies.ts | 7 +++-- scripts/components/dependencies_validator.ts | 31 ++++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index 45cfb71082..d936804775 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -22,8 +22,9 @@ await new DependenciesValidator( //**the structure of this comes from dependenci }, }, [['aws-cdk', 'aws-cdk-lib']], - { - execa: { + [ + { + dependencyName: 'execa', globalDependencyVersion: '^8.0.1', exceptions: [ { @@ -32,5 +33,5 @@ await new DependenciesValidator( //**the structure of this comes from dependenci }, ], }, - } + ] ).validate(); diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index 40b1e5fe1c..222d8a680d 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -13,6 +13,7 @@ export type DependencyRule = }; export type DependencyWithKnownException = { + dependencyName: string; globalDependencyVersion: string; exceptions: Array<{ packageName: string; dependencyVersion: string }>; }; @@ -61,10 +62,7 @@ export class DependenciesValidator { private packagePaths: Array, private disallowedDependencies: Record, private linkedDependencies: Array>, - private knownInconsistentDependencies: Record< - string, - DependencyWithKnownException - >, + private knownInconsistentDependencies: Array, private execa = _execa ) {} @@ -251,26 +249,33 @@ export class DependenciesValidator { } private getPackageVersionDeclarationPredicate = async ( - //**this is where we map packages to dependency versions packageName: string ): Promise => { - if (packageName === 'execa') { - //** check if the packageName is a known inconsistent dependency + if ( + this.knownInconsistentDependencies.find( + (a) => a.dependencyName === packageName + ) + ) { // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 // all other packages must depend on execa@^8.0.1 // this can be removed once execa is patched - //**if the package is a known inconsistent depencency, then we want to make sure every package but the one(s) specified are using the default version + const inconsistentDependency = this.knownInconsistentDependencies.find( + (x) => x.dependencyName === packageName + ); return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) => - (dependentPackageName === '@aws-amplify/plugin-types' && - version === '^5.1.1') || - version === '^8.0.1' + inconsistentDependency!.exceptions.find( + (a) => a.packageName === dependentPackageName + )?.dependencyVersion || + version === inconsistentDependency!.globalDependencyVersion ); return ( validationResult || - `${packageName} dependency declarations must depend on version ^8.0.1 except in @aws-amplify/plugin-types where it must depend on ^5.1.1.` - ); + `${packageName} dependency declarations must depend on version ${ + inconsistentDependency!.globalDependencyVersion + } except in the following packages,` + ); // ${inconsistentDependency!.exceptions.forEach(exception=>(`${exception.packageName} where it must depend on ${exception.dependencyVersion} `))}`); }; } else if ((await this.getRepoPackageNames()).includes(packageName)) { // repo packages only need consistent major versions From 826327ca363433cc529ee1b7c920c700a7190883 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Mon, 26 Aug 2024 14:27:06 -0700 Subject: [PATCH 04/16] chore: updated error message for incorrect verions --- scripts/components/dependencies_validator.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index 222d8a680d..99f8c8200f 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -274,7 +274,11 @@ export class DependenciesValidator { validationResult || `${packageName} dependency declarations must depend on version ${ inconsistentDependency!.globalDependencyVersion - } except in the following packages,` + } except in the following packages` + + inconsistentDependency!.exceptions.forEach( + (exception) => + `, ${exception.packageName} where it must depend on ${exception.dependencyVersion}` + ) ); // ${inconsistentDependency!.exceptions.forEach(exception=>(`${exception.packageName} where it must depend on ${exception.dependencyVersion} `))}`); }; } else if ((await this.getRepoPackageNames()).includes(packageName)) { From 8c4f2992b558087eb9daf6d8a00d0422456139d6 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Mon, 26 Aug 2024 14:34:15 -0700 Subject: [PATCH 05/16] chore: removed unused code --- scripts/components/dependencies_validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index 99f8c8200f..e4775748b9 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -279,7 +279,7 @@ export class DependenciesValidator { (exception) => `, ${exception.packageName} where it must depend on ${exception.dependencyVersion}` ) - ); // ${inconsistentDependency!.exceptions.forEach(exception=>(`${exception.packageName} where it must depend on ${exception.dependencyVersion} `))}`); + ); }; } else if ((await this.getRepoPackageNames()).includes(packageName)) { // repo packages only need consistent major versions From 3a6b0a56b9338b3eae8041ce237301ce0bb9aed1 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Tue, 27 Aug 2024 11:19:38 -0700 Subject: [PATCH 06/16] fix: updated tests to include array for new parameter in dependendies validator --- .../components/dependencies_validator.test.ts | 18 ++++++++++++++++++ scripts/components/dependencies_validator.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/components/dependencies_validator.test.ts b/scripts/components/dependencies_validator.test.ts index fe93f5488d..25c12c6acc 100644 --- a/scripts/components/dependencies_validator.test.ts +++ b/scripts/components/dependencies_validator.test.ts @@ -41,6 +41,7 @@ void describe('Dependency validator', () => { }, }, [], + [], execaMock as never ).validate(), (err: Error) => { @@ -65,6 +66,7 @@ void describe('Dependency validator', () => { }, }, [], + [], execaMock as never ).validate(), (err: Error) => { @@ -88,6 +90,7 @@ void describe('Dependency validator', () => { }, }, [], + [], execaMock as never ).validate(); }); @@ -106,6 +109,7 @@ void describe('Dependency validator', () => { }, }, [], + [], execaMock as never ).validate(), (err: Error) => { @@ -129,6 +133,7 @@ void describe('Dependency validator', () => { packagePaths, {}, [], + [], execaMock as never ).validate(); }, @@ -156,6 +161,18 @@ void describe('Dependency validator', () => { packagePaths, {}, [], + [ + { + dependencyName: 'yargs', + globalDependencyVersion: '^8.0.1', + exceptions: [ + { + packageName: '@aws-amplify/plugin-types', + dependencyVersion: '^6.2.1', + }, + ], + }, + ], execaMock as never ); @@ -185,6 +202,7 @@ void describe('Dependency validator', () => { packagePaths, {}, [['aws-cdk', 'aws-cdk-lib']], + [], execaMock as never ).validate(); }, diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index e4775748b9..2af33c71f1 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -254,7 +254,7 @@ export class DependenciesValidator { if ( this.knownInconsistentDependencies.find( (a) => a.dependencyName === packageName - ) + ) !== undefined ) { // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 // all other packages must depend on execa@^8.0.1 From a8a1c7786ddda35be984607e76db1b3bf4a0bac5 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Tue, 27 Aug 2024 11:59:13 -0700 Subject: [PATCH 07/16] chore: removed unnecessary comment --- scripts/check_dependencies.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index d936804775..a38953c8ef 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -1,7 +1,7 @@ import { glob } from 'glob'; import { DependenciesValidator } from './components/dependencies_validator.js'; -await new DependenciesValidator( //**the structure of this comes from dependencies_validator.ts +await new DependenciesValidator( await glob('packages/*'), { 'aws-amplify': { From 666e95b06c4777a9fb07e4bea4bc7d8db7d06254 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Wed, 28 Aug 2024 09:48:34 -0700 Subject: [PATCH 08/16] chore: minor adjustment to test --- scripts/components/dependencies_validator.test.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/scripts/components/dependencies_validator.test.ts b/scripts/components/dependencies_validator.test.ts index 25c12c6acc..f095efdb1d 100644 --- a/scripts/components/dependencies_validator.test.ts +++ b/scripts/components/dependencies_validator.test.ts @@ -161,18 +161,7 @@ void describe('Dependency validator', () => { packagePaths, {}, [], - [ - { - dependencyName: 'yargs', - globalDependencyVersion: '^8.0.1', - exceptions: [ - { - packageName: '@aws-amplify/plugin-types', - dependencyVersion: '^6.2.1', - }, - ], - }, - ], + [], execaMock as never ); From 5ff06505ab5d67fa087e057744abee374ea6b545 Mon Sep 17 00:00:00 2001 From: Leena <81589006+ShadowCat567@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:40:16 -0700 Subject: [PATCH 09/16] Update scripts/components/dependencies_validator.ts Co-authored-by: Kamil Sobol --- scripts/components/dependencies_validator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index 2af33c71f1..ef310a525e 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -62,7 +62,7 @@ export class DependenciesValidator { private packagePaths: Array, private disallowedDependencies: Record, private linkedDependencies: Array>, - private knownInconsistentDependencies: Array, + private knownInconsistentDependencyVersions: Array, private execa = _execa ) {} From 628e02c7c8b4c8c0096d1a5daea8ee48a6a59fe8 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Wed, 28 Aug 2024 10:45:44 -0700 Subject: [PATCH 10/16] chore: changed variable name, moved find statement --- scripts/components/dependencies_validator.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index ef310a525e..d0cb5a4c28 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -12,7 +12,7 @@ export type DependencyRule = allowList: Array; }; -export type DependencyWithKnownException = { +export type DependencyWithKnownVersionConsistencyException = { dependencyName: string; globalDependencyVersion: string; exceptions: Array<{ packageName: string; dependencyVersion: string }>; @@ -55,7 +55,7 @@ export class DependenciesValidator { * @param packagePaths paths of packages to validate * @param disallowedDependencies dependency exclusion and inclusion rules * @param linkedDependencies dependencies that should be versioned with the same version - * @param knownInconsistentDependencies dependencies that are known to violate the consistency check + * @param knownInconsistentDependencyVersions dependencies that are known to violate the consistency check * @param execa in order to inject execa mock in tests */ constructor( @@ -251,17 +251,14 @@ export class DependenciesValidator { private getPackageVersionDeclarationPredicate = async ( packageName: string ): Promise => { - if ( - this.knownInconsistentDependencies.find( - (a) => a.dependencyName === packageName - ) !== undefined - ) { + const inconsistentDependency = + this.knownInconsistentDependencyVersions.find( + (x) => x.dependencyName === packageName + ); + if (inconsistentDependency) { // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 // all other packages must depend on execa@^8.0.1 // this can be removed once execa is patched - const inconsistentDependency = this.knownInconsistentDependencies.find( - (x) => x.dependencyName === packageName - ); return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) => From c30106400e0a059198aff2f21b72a54dcdaf468f Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Thu, 29 Aug 2024 11:13:33 -0700 Subject: [PATCH 11/16] chore: added test for inconsistent dependency that has multiple versions in use --- .../components/dependencies_validator.test.ts | 62 +++++++++++++++++++ .../package1/package.json | 12 ++++ .../package2/package.json | 12 ++++ .../package3/package.json | 12 ++++ 4 files changed, 98 insertions(+) create mode 100644 scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json create mode 100644 scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json create mode 100644 scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json diff --git a/scripts/components/dependencies_validator.test.ts b/scripts/components/dependencies_validator.test.ts index f095efdb1d..227b618988 100644 --- a/scripts/components/dependencies_validator.test.ts +++ b/scripts/components/dependencies_validator.test.ts @@ -123,7 +123,9 @@ void describe('Dependency validator', () => { ); }); + //** make a new test or two -- will probably be similar to the one below (requires more thinking than I am able to do right now) void it('can detect inconsistent dependency declarations', async () => { + //** detects whether there are inconsistent dependency declarations and throws an error if true await assert.rejects( async () => { const packagePaths = await glob( @@ -153,6 +155,66 @@ void describe('Dependency validator', () => { ); }); + void it('passes if dependency declaration that is known to be inconsistent uses multiple versions', async () => { + const packagePaths = await glob( + 'scripts/components/test-resources/dependency-version-inconsistent-test-packages/*' + ); + await new DependenciesValidator( + packagePaths, + {}, + [], + [ + { + dependencyName: 'glob', + globalDependencyVersion: '^7.2.0', + exceptions: [ + { + packageName: 'package2', + dependencyVersion: '^3.4.0', + }, + { + packageName: 'package3', + dependencyVersion: '^1.6.0', + }, + ], + }, + ], + execaMock as never + ).validate(); + }); + /* + void it('passes if multiple dependency declarations are known to be inconsistent', async () => { + const packagePaths = await glob(''); + await new DependenciesValidator( + packagePaths, + {}, + [], + [ + { + dependencyName: 'glob', + globalDependencyVersion: '', + exceptions: [ + { + packageName: '', + dependencyVersion: '' + } + ] + }, + { + dependencyName: 'yargs', + globalDependencyVersion: '', + exceptions: [ + { + packageName: '', + dependencyVersion: '' + } + ] + } + ], + execaMock as never + ).validate(); + }); +*/ void it('can detect inconsistent major versions of repo packages', async () => { const packagePaths = await glob( 'scripts/components/test-resources/inter-repo-dependency-version-consistency-test-packages/*' diff --git a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json new file mode 100644 index 0000000000..64ec0f74ce --- /dev/null +++ b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json @@ -0,0 +1,12 @@ +{ + "name": "package1", + "dependencies": { + "glob": "^7.2.0" + }, + "devDependencies": { + "zod": "^3.8.2-alpha.6" + }, + "peerDependencies": { + "yargs": "~14.2.3" + } +} diff --git a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json new file mode 100644 index 0000000000..5918422c23 --- /dev/null +++ b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json @@ -0,0 +1,12 @@ +{ + "name": "package2", + "dependencies": { + "glob": "^3.4.0" + }, + "devDependencies": { + "zod": "^3.8.2-alpha.6" + }, + "peerDependencies": { + "yargs": "~14.2.3" + } +} diff --git a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json new file mode 100644 index 0000000000..cddaa2a3e4 --- /dev/null +++ b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json @@ -0,0 +1,12 @@ +{ + "name": "package2", + "dependencies": { + "glob": "^1.6.0" + }, + "devDependencies": { + "zod": "^3.8.2-alpha.6" + }, + "peerDependencies": { + "yargs": "~14.2.3" + } +} From 62c579e44c293fd271619908def167b62648feed Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Thu, 29 Aug 2024 11:34:02 -0700 Subject: [PATCH 12/16] chore: test added to check multiple dependencies that are marked as inconsistent yield correct results --- .../components/dependencies_validator.test.ts | 28 +++++++++---------- .../package1/package.json | 3 -- .../package2/package.json | 3 -- .../package3/package.json | 3 -- .../package1/package.json | 12 ++++++++ .../package2/package.json | 12 ++++++++ .../package3/package.json | 12 ++++++++ 7 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package1/package.json create mode 100644 scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package2/package.json create mode 100644 scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package3/package.json diff --git a/scripts/components/dependencies_validator.test.ts b/scripts/components/dependencies_validator.test.ts index 227b618988..a3dded6c2e 100644 --- a/scripts/components/dependencies_validator.test.ts +++ b/scripts/components/dependencies_validator.test.ts @@ -182,7 +182,7 @@ void describe('Dependency validator', () => { execaMock as never ).validate(); }); - /* + void it('passes if multiple dependency declarations are known to be inconsistent', async () => { const packagePaths = await glob(''); await new DependenciesValidator( @@ -192,29 +192,29 @@ void describe('Dependency validator', () => { [ { dependencyName: 'glob', - globalDependencyVersion: '', + globalDependencyVersion: '^7.2.0', exceptions: [ { - packageName: '', - dependencyVersion: '' - } - ] + packageName: 'package3', + dependencyVersion: '^5.3.0', + }, + ], }, { - dependencyName: 'yargs', - globalDependencyVersion: '', + dependencyName: 'zod', + globalDependencyVersion: '^3.8.2-alpha.6', exceptions: [ { - packageName: '', - dependencyVersion: '' - } - ] - } + packageName: 'pacakge2', + dependencyVersion: '^2.0.0', + }, + ], + }, ], execaMock as never ).validate(); }); -*/ + void it('can detect inconsistent major versions of repo packages', async () => { const packagePaths = await glob( 'scripts/components/test-resources/inter-repo-dependency-version-consistency-test-packages/*' diff --git a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json index 64ec0f74ce..04c57c8144 100644 --- a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json +++ b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package1/package.json @@ -5,8 +5,5 @@ }, "devDependencies": { "zod": "^3.8.2-alpha.6" - }, - "peerDependencies": { - "yargs": "~14.2.3" } } diff --git a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json index 5918422c23..b8c74c3e16 100644 --- a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json +++ b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package2/package.json @@ -5,8 +5,5 @@ }, "devDependencies": { "zod": "^3.8.2-alpha.6" - }, - "peerDependencies": { - "yargs": "~14.2.3" } } diff --git a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json index cddaa2a3e4..c20dc3d34d 100644 --- a/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json +++ b/scripts/components/test-resources/dependency-version-inconsistent-test-packages/package3/package.json @@ -5,8 +5,5 @@ }, "devDependencies": { "zod": "^3.8.2-alpha.6" - }, - "peerDependencies": { - "yargs": "~14.2.3" } } diff --git a/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package1/package.json b/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package1/package.json new file mode 100644 index 0000000000..64ec0f74ce --- /dev/null +++ b/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package1/package.json @@ -0,0 +1,12 @@ +{ + "name": "package1", + "dependencies": { + "glob": "^7.2.0" + }, + "devDependencies": { + "zod": "^3.8.2-alpha.6" + }, + "peerDependencies": { + "yargs": "~14.2.3" + } +} diff --git a/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package2/package.json b/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package2/package.json new file mode 100644 index 0000000000..0d7f2c8dcc --- /dev/null +++ b/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package2/package.json @@ -0,0 +1,12 @@ +{ + "name": "package2", + "dependencies": { + "glob": "^7.2.0" + }, + "devDependencies": { + "zod": "^2.0.0" + }, + "peerDependencies": { + "yargs": "~14.2.3" + } +} diff --git a/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package3/package.json b/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package3/package.json new file mode 100644 index 0000000000..315990eda0 --- /dev/null +++ b/scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/package3/package.json @@ -0,0 +1,12 @@ +{ + "name": "package3", + "dependencies": { + "glob": "^5.3.0" + }, + "devDependencies": { + "zod": "^3.8.2-alpha.6" + }, + "peerDependencies": { + "yargs": "~14.2.3" + } +} From b43473a99bee1403134f8755aef7f26feeba8cc5 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Thu, 29 Aug 2024 12:01:40 -0700 Subject: [PATCH 13/16] chore: added test for known vs unknown inconsistent dependencies --- .../components/dependencies_validator.test.ts | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/scripts/components/dependencies_validator.test.ts b/scripts/components/dependencies_validator.test.ts index a3dded6c2e..9f2682dbb2 100644 --- a/scripts/components/dependencies_validator.test.ts +++ b/scripts/components/dependencies_validator.test.ts @@ -123,9 +123,7 @@ void describe('Dependency validator', () => { ); }); - //** make a new test or two -- will probably be similar to the one below (requires more thinking than I am able to do right now) void it('can detect inconsistent dependency declarations', async () => { - //** detects whether there are inconsistent dependency declarations and throws an error if true await assert.rejects( async () => { const packagePaths = await glob( @@ -184,7 +182,9 @@ void describe('Dependency validator', () => { }); void it('passes if multiple dependency declarations are known to be inconsistent', async () => { - const packagePaths = await glob(''); + const packagePaths = await glob( + 'scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/*' + ); await new DependenciesValidator( packagePaths, {}, @@ -205,7 +205,7 @@ void describe('Dependency validator', () => { globalDependencyVersion: '^3.8.2-alpha.6', exceptions: [ { - packageName: 'pacakge2', + packageName: 'package2', dependencyVersion: '^2.0.0', }, ], @@ -215,6 +215,46 @@ void describe('Dependency validator', () => { ).validate(); }); + void it('can detect unknown inconsistent dependency delcarations when known inconsistent dependency delcarations are present', async () => { + await assert.rejects( + async () => { + const packagePaths = await glob( + 'scripts/components/test-resources/dependency-version-multiple-inconsistencies-test-packages/*' + ); + await new DependenciesValidator( + packagePaths, + {}, + [], + [ + { + dependencyName: 'glob', + globalDependencyVersion: '^7.2.0', + exceptions: [ + { + packageName: 'package3', + dependencyVersion: '^5.3.0', + }, + ], + }, + ], + execaMock as never + ).validate(); + }, + (err: Error) => { + assert.ok( + err.message.includes( + 'dependency declarations must all the on the same semver range' + ) + ); + assert.ok(err.message.includes('zod')); + assert.ok(err.message.includes('package1')); + assert.ok(err.message.includes('package2')); + assert.ok(err.message.includes('package3')); + return true; + } + ); + }); + void it('can detect inconsistent major versions of repo packages', async () => { const packagePaths = await glob( 'scripts/components/test-resources/inter-repo-dependency-version-consistency-test-packages/*' From 44a9051c305c2ecafde0366b1f65d7807b11add3 Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Thu, 29 Aug 2024 12:29:58 -0700 Subject: [PATCH 14/16] chore: moved execa comment to check_dependencies.ts --- package-lock.json | 18 +++++++++--------- scripts/check_dependencies.ts | 3 +++ scripts/components/dependencies_validator.ts | 3 --- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index c118b8923b..5c7ecf1cc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24682,19 +24682,19 @@ }, "packages/backend": { "name": "@aws-amplify/backend", - "version": "1.1.1", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-auth": "^1.1.2", - "@aws-amplify/backend-data": "^1.1.1", + "@aws-amplify/backend-data": "^1.1.3", "@aws-amplify/backend-function": "^1.3.2", "@aws-amplify/backend-output-schemas": "^1.2.0", "@aws-amplify/backend-output-storage": "^1.1.1", "@aws-amplify/backend-secret": "^1.0.1", "@aws-amplify/backend-storage": "^1.1.1", - "@aws-amplify/client-config": "^1.2.0", + "@aws-amplify/client-config": "^1.3.0", "@aws-amplify/data-schema": "^1.0.0", - "@aws-amplify/platform-core": "^1.0.6", + "@aws-amplify/platform-core": "^1.0.7", "@aws-amplify/plugin-types": "^1.2.1", "@aws-sdk/client-amplify": "^3.624.0", "lodash.snakecase": "^4.1.1" @@ -24729,7 +24729,7 @@ }, "packages/backend-data": { "name": "@aws-amplify/backend-data", - "version": "1.1.2", + "version": "1.1.3", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-output-schemas": "^1.1.0", @@ -24741,7 +24741,7 @@ "devDependencies": { "@aws-amplify/backend-platform-test-stubs": "^0.3.4", "@aws-amplify/data-schema": "^1.0.0", - "@aws-amplify/platform-core": "^1.0.6" + "@aws-amplify/platform-core": "^1.0.7" }, "peerDependencies": { "aws-cdk-lib": "^2.152.0", @@ -25059,13 +25059,13 @@ }, "packages/client-config": { "name": "@aws-amplify/client-config", - "version": "1.2.1", + "version": "1.3.0", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-output-schemas": "^1.2.0", "@aws-amplify/deployed-backend-client": "^1.4.0", "@aws-amplify/model-generator": "^1.0.5", - "@aws-amplify/platform-core": "^1.0.5", + "@aws-amplify/platform-core": "^1.0.7", "zod": "^3.22.2" }, "devDependencies": { @@ -25324,7 +25324,7 @@ }, "packages/platform-core": { "name": "@aws-amplify/platform-core", - "version": "1.0.6", + "version": "1.0.7", "license": "Apache-2.0", "dependencies": { "@aws-amplify/plugin-types": "^1.2.1", diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index a38953c8ef..80d26889d4 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -24,6 +24,9 @@ await new DependenciesValidator( [['aws-cdk', 'aws-cdk-lib']], [ { + // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 + // all other packages must depend on execa@^8.0.1 + // this can be removed once execa is patched dependencyName: 'execa', globalDependencyVersion: '^8.0.1', exceptions: [ diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index d0cb5a4c28..caa9e50bbc 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -256,9 +256,6 @@ export class DependenciesValidator { (x) => x.dependencyName === packageName ); if (inconsistentDependency) { - // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 - // all other packages must depend on execa@^8.0.1 - // this can be removed once execa is patched return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) => From 5d5439ee6a423f1ec4ac12c43f80a72ae1ee926e Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Thu, 29 Aug 2024 12:32:16 -0700 Subject: [PATCH 15/16] Revert "chore: moved execa comment to check_dependencies.ts" This reverts commit 44a9051c305c2ecafde0366b1f65d7807b11add3. --- package-lock.json | 18 +++++++++--------- scripts/check_dependencies.ts | 3 --- scripts/components/dependencies_validator.ts | 3 +++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c7ecf1cc6..c118b8923b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24682,19 +24682,19 @@ }, "packages/backend": { "name": "@aws-amplify/backend", - "version": "1.2.0", + "version": "1.1.1", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-auth": "^1.1.2", - "@aws-amplify/backend-data": "^1.1.3", + "@aws-amplify/backend-data": "^1.1.1", "@aws-amplify/backend-function": "^1.3.2", "@aws-amplify/backend-output-schemas": "^1.2.0", "@aws-amplify/backend-output-storage": "^1.1.1", "@aws-amplify/backend-secret": "^1.0.1", "@aws-amplify/backend-storage": "^1.1.1", - "@aws-amplify/client-config": "^1.3.0", + "@aws-amplify/client-config": "^1.2.0", "@aws-amplify/data-schema": "^1.0.0", - "@aws-amplify/platform-core": "^1.0.7", + "@aws-amplify/platform-core": "^1.0.6", "@aws-amplify/plugin-types": "^1.2.1", "@aws-sdk/client-amplify": "^3.624.0", "lodash.snakecase": "^4.1.1" @@ -24729,7 +24729,7 @@ }, "packages/backend-data": { "name": "@aws-amplify/backend-data", - "version": "1.1.3", + "version": "1.1.2", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-output-schemas": "^1.1.0", @@ -24741,7 +24741,7 @@ "devDependencies": { "@aws-amplify/backend-platform-test-stubs": "^0.3.4", "@aws-amplify/data-schema": "^1.0.0", - "@aws-amplify/platform-core": "^1.0.7" + "@aws-amplify/platform-core": "^1.0.6" }, "peerDependencies": { "aws-cdk-lib": "^2.152.0", @@ -25059,13 +25059,13 @@ }, "packages/client-config": { "name": "@aws-amplify/client-config", - "version": "1.3.0", + "version": "1.2.1", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-output-schemas": "^1.2.0", "@aws-amplify/deployed-backend-client": "^1.4.0", "@aws-amplify/model-generator": "^1.0.5", - "@aws-amplify/platform-core": "^1.0.7", + "@aws-amplify/platform-core": "^1.0.5", "zod": "^3.22.2" }, "devDependencies": { @@ -25324,7 +25324,7 @@ }, "packages/platform-core": { "name": "@aws-amplify/platform-core", - "version": "1.0.7", + "version": "1.0.6", "license": "Apache-2.0", "dependencies": { "@aws-amplify/plugin-types": "^1.2.1", diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index 80d26889d4..a38953c8ef 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -24,9 +24,6 @@ await new DependenciesValidator( [['aws-cdk', 'aws-cdk-lib']], [ { - // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 - // all other packages must depend on execa@^8.0.1 - // this can be removed once execa is patched dependencyName: 'execa', globalDependencyVersion: '^8.0.1', exceptions: [ diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index caa9e50bbc..d0cb5a4c28 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -256,6 +256,9 @@ export class DependenciesValidator { (x) => x.dependencyName === packageName ); if (inconsistentDependency) { + // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 + // all other packages must depend on execa@^8.0.1 + // this can be removed once execa is patched return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) => From 9a0f60b13905f0d058075b562b7dd43e19b7667e Mon Sep 17 00:00:00 2001 From: Vieltojarvi Date: Thu, 29 Aug 2024 12:33:41 -0700 Subject: [PATCH 16/16] chore: moved execa comment to check_dependencies from dependencies_validator --- scripts/check_dependencies.ts | 3 +++ scripts/components/dependencies_validator.ts | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/check_dependencies.ts b/scripts/check_dependencies.ts index a38953c8ef..80d26889d4 100644 --- a/scripts/check_dependencies.ts +++ b/scripts/check_dependencies.ts @@ -24,6 +24,9 @@ await new DependenciesValidator( [['aws-cdk', 'aws-cdk-lib']], [ { + // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 + // all other packages must depend on execa@^8.0.1 + // this can be removed once execa is patched dependencyName: 'execa', globalDependencyVersion: '^8.0.1', exceptions: [ diff --git a/scripts/components/dependencies_validator.ts b/scripts/components/dependencies_validator.ts index d0cb5a4c28..caa9e50bbc 100644 --- a/scripts/components/dependencies_validator.ts +++ b/scripts/components/dependencies_validator.ts @@ -256,9 +256,6 @@ export class DependenciesValidator { (x) => x.dependencyName === packageName ); if (inconsistentDependency) { - // @aws-amplify/plugin-types can depend on execa@^5.1.1 as a workaround for https://github.com/aws-amplify/amplify-backend/issues/962 - // all other packages must depend on execa@^8.0.1 - // this can be removed once execa is patched return (declarations) => { const validationResult = declarations.every( ({ dependentPackageName, version }) =>