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
feat(cli): support for matching notices with arbitrary module names #19088
Changes from 29 commits
abb4a05
7c873c3
e280527
236f3a9
f5c2962
5175a13
4c32d0f
e402447
4274283
9b68e6f
8a245d2
8546c00
2642b3a
bcf9c13
527eb2b
0657b9f
e026e55
977c061
303b953
f307cc0
d9ba71f
17cbce3
a74eadc
10979a9
6b89ea1
fc4a56e
1020b99
e7afe1d
0bb05ae
f76d5c8
4b6ded6
6325423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import * as path from 'path'; | |
import * as fs from 'fs-extra'; | ||
import * as semver from 'semver'; | ||
import { debug, print } from './logging'; | ||
import { flatMap } from './util'; | ||
import { cdkCacheDir } from './util/directories'; | ||
import { versionNumber } from './version'; | ||
|
||
|
@@ -75,8 +76,8 @@ export interface FilterNoticeOptions { | |
export function filterNotices(data: Notice[], options: FilterNoticeOptions): Notice[] { | ||
const filter = new NoticeFilter({ | ||
cliVersion: options.cliVersion ?? versionNumber(), | ||
frameworkVersion: options.frameworkVersion ?? frameworkVersion(options.outdir ?? 'cdk.out'), | ||
acknowledgedIssueNumbers: options.acknowledgedIssueNumbers ?? new Set(), | ||
tree: loadTree(options.outdir ?? 'cdk.out').tree, | ||
}); | ||
return data.filter(notice => filter.apply(notice)); | ||
} | ||
|
@@ -188,8 +189,8 @@ export class CachedDataSource implements NoticeDataSource { | |
|
||
export interface NoticeFilterProps { | ||
cliVersion: string, | ||
frameworkVersion: string | undefined, | ||
acknowledgedIssueNumbers: Set<number>, | ||
tree: Node, | ||
} | ||
|
||
export class NoticeFilter { | ||
|
@@ -206,8 +207,23 @@ export class NoticeFilter { | |
if (this.acknowledgedIssueNumbers.has(notice.issueNumber)) { | ||
return false; | ||
} | ||
|
||
const components = flatMap(notice.components, component => { | ||
if (component.name === 'framework') { | ||
return [{ | ||
name: '@aws-cdk/core', | ||
version: component.version, | ||
}, { | ||
name: 'aws-cdk-lib', | ||
version: component.version, | ||
}]; | ||
} else { | ||
return [component]; | ||
} | ||
}); | ||
|
||
return this.applyVersion(notice, 'cli', this.props.cliVersion) || | ||
this.applyVersion(notice, 'framework', this.props.frameworkVersion); | ||
match(components, this.props.tree); | ||
} | ||
|
||
/** | ||
|
@@ -244,21 +260,61 @@ function formatOverview(text: string) { | |
return '\t' + heading + content; | ||
} | ||
|
||
function frameworkVersion(outdir: string): string | undefined { | ||
const tree = loadTree().tree; | ||
/** | ||
* Whether any component in the tree matches any component in the query. | ||
*/ | ||
function match(query: Component[], tree: Node): boolean { | ||
return some(tree, node => { | ||
return query.some(component => | ||
node.constructInfo?.fqn.startsWith(component.name) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but we should also check that the We don't want:
To match
|
||
semver.satisfies(node.constructInfo?.version ?? '', component.version)); | ||
}); | ||
} | ||
|
||
if (tree?.constructInfo?.fqn.startsWith('aws-cdk-lib') | ||
|| tree?.constructInfo?.fqn.startsWith('@aws-cdk/core')) { | ||
return tree.constructInfo.version; | ||
function loadTree(outdir: string) { | ||
try { | ||
return fs.readJSONSync(path.join(outdir, 'tree.json')); | ||
} catch (e) { | ||
debug(`Failed to get tree.json file: ${e}`); | ||
return {}; | ||
} | ||
return undefined; | ||
} | ||
|
||
function loadTree() { | ||
try { | ||
return fs.readJSONSync(path.join(outdir, 'tree.json')); | ||
} catch (e) { | ||
debug(`Failed to get tree.json file: ${e}`); | ||
return {}; | ||
/** | ||
* Source information on a construct (class fqn and version) | ||
*/ | ||
interface ConstructInfo { | ||
readonly fqn: string; | ||
readonly version: string; | ||
} | ||
|
||
/** | ||
* A node in the construct tree. | ||
* @internal | ||
*/ | ||
interface Node { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
readonly id: string; | ||
readonly path: string; | ||
readonly children?: { [key: string]: Node }; | ||
readonly attributes?: { [key: string]: any }; | ||
|
||
/** | ||
* Information on the construct class that led to this node, if available | ||
*/ | ||
readonly constructInfo?: ConstructInfo; | ||
} | ||
|
||
function some(node: Node, predicate: (n: Node) => boolean): boolean { | ||
return node != null && (predicate(node) || findInChildren()); | ||
|
||
function findInChildren(): boolean { | ||
if (node.children == null) { return false; } | ||
|
||
for (const name in node.children) { | ||
if (some(node.children[name], predicate)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
"version": "tree-0.1", | ||
"tree": { | ||
"id": "App", | ||
"path": "", | ||
"children": { | ||
"Tree": { | ||
"id": "Tree", | ||
"path": "Tree", | ||
"constructInfo": { | ||
"fqn": "constructs.Construct", | ||
"version": "10.0.66" | ||
} | ||
}, | ||
"SimulationStack": { | ||
"id": "SimulationStack", | ||
"path": "SimulationStack", | ||
"children": { | ||
"HttpApi": { | ||
"id": "HttpApi", | ||
"path": "SimulationStack/HttpApi", | ||
"children": { | ||
"Resource": { | ||
"id": "Resource", | ||
"path": "SimulationStack/HttpApi/Resource", | ||
"attributes": { | ||
"aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Api", | ||
"aws:cdk:cloudformation:props": { | ||
"name": "HttpApi", | ||
"protocolType": "HTTP" | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "aws-cdk-lib.aws_apigatewayv2.CfnApi", | ||
"version": "2.8.0" | ||
} | ||
}, | ||
"DefaultStage": { | ||
"id": "DefaultStage", | ||
"path": "SimulationStack/HttpApi/DefaultStage", | ||
"children": { | ||
"Resource": { | ||
"id": "Resource", | ||
"path": "SimulationStack/HttpApi/DefaultStage/Resource", | ||
"attributes": { | ||
"aws:cdk:cloudformation:type": "AWS::ApiGatewayV2::Stage", | ||
"aws:cdk:cloudformation:props": { | ||
"apiId": { | ||
"Ref": "HttpApiF5A9A8A7" | ||
}, | ||
"stageName": "$default", | ||
"autoDeploy": true | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "aws-cdk-lib.aws_apigatewayv2.CfnStage", | ||
"version": "2.8.0" | ||
} | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "@aws-cdk/aws-apigatewayv2-alpha.HttpStage", | ||
"version": "2.13.0-alpha.0" | ||
} | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "@aws-cdk/aws-apigatewayv2-alpha.HttpApi", | ||
"version": "2.13.0-alpha.0" | ||
} | ||
}, | ||
"CDKMetadata": { | ||
"id": "CDKMetadata", | ||
"path": "SimulationStack/CDKMetadata", | ||
"children": { | ||
"Default": { | ||
"id": "Default", | ||
"path": "SimulationStack/CDKMetadata/Default", | ||
"constructInfo": { | ||
"fqn": "aws-cdk-lib.CfnResource", | ||
"version": "2.8.0" | ||
} | ||
}, | ||
"Condition": { | ||
"id": "Condition", | ||
"path": "SimulationStack/CDKMetadata/Condition", | ||
"constructInfo": { | ||
"fqn": "aws-cdk-lib.CfnCondition", | ||
"version": "2.8.0" | ||
} | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "constructs.Construct", | ||
"version": "10.0.66" | ||
} | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "aws-cdk-lib.Stack", | ||
"version": "2.8.0" | ||
} | ||
} | ||
}, | ||
"constructInfo": { | ||
"fqn": "aws-cdk-lib.App", | ||
"version": "2.8.0" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could do with a comment