Skip to content

Commit

Permalink
chore: align-version script drops caret from dependencies it rewrites (
Browse files Browse the repository at this point in the history
…#27376)

The `align-version` script is supposed to rewrite `0.0.0` -> `2.99.0`, and also to rewrite `^0.0.0` -> `^2.99.0`. It didn't do the latter, because of a variable shadowing mistake. That mistake happened to come out correctly often enough that we didn't notice it.

Fix that bug.

Also add a linting rule that says that all peerDependencies should have a `^` dependency on `aws-cdk-lib`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr committed Oct 2, 2023
1 parent a367d91 commit 1162746
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"@aws-cdk/pkglint": "0.0.0"
},
"peerDependencies": {
"aws-cdk-lib": "0.0.0",
"aws-cdk-lib": "^0.0.0",
"constructs": "^10.0.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-appconfig-alpha/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
},
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"aws-cdk-lib": "0.0.0",
"aws-cdk-lib": "^0.0.0",
"constructs": "^10.0.0"
},
"separate-module": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"repository": {
"url": "https://github.com/aws/aws-cdk.git",
"type": "git",
"directory": "packages/custom-resource-handlers"
"directory": "packages/@aws-cdk/custom-resource-handlers"
},
"keywords": [
"aws",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/example-construct-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
},
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"aws-cdk-lib": "0.0.0",
"aws-cdk-lib": "^0.0.0",
"constructs": "^10.0.0"
},
"separate-module": false,
Expand Down
8 changes: 3 additions & 5 deletions scripts/align-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ for (const file of files) {
}

const version = packageVersionMap[pkg.name]
console.log(version);
pkg.version = version;

processSection(pkg.dependencies || { }, file);
Expand All @@ -41,13 +40,12 @@ for (const file of files) {
function processSection(section, file) {
for (const [ name, version ] of Object.entries(section)) {
if (version === marker || version === '^' + marker) {
const version = packageVersionMap[name];

if (!version) {
const newVersion = packageVersionMap[name];
if (!newVersion) {
throw new Error(`No package found ${name} within repository, which has version 0.0.0`);
}

section[name] = version.replace(marker, version);
section[name] = version.replace(marker, newVersion);
}
}
}
22 changes: 22 additions & 0 deletions tools/@aws-cdk/pkglint/lib/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,28 @@ export class ConstructsDependency extends ValidationRule {
}
}

/**
* Peer dependencies should be a range, not a point version, to maximize compatibility
*/
export class PeerDependencyRange extends ValidationRule {
public readonly name = 'peerdependency/range';

public validate(pkg: PackageJson) {
const packages = ['aws-cdk-lib'];
for (const [name, version] of Object.entries(pkg.peerDependencies)) {
if (packages.includes(name) && version.match(/^[0-9]/)) {
pkg.report({
ruleName: this.name,
message: `peerDependency on" ${name}" should be a range, not a point version: "${version}"`,
fix: () => {
pkg.addPeerDependency(name, '^' + version);
},
});
}
}
}
}

/**
* Do not announce new versions of AWS CDK modules in awscdk.io because it is very very spammy
* and actually causes the @awscdkio twitter account to be blocked.
Expand Down

0 comments on commit 1162746

Please sign in to comment.