Skip to content

chore(individual-pkg-gen): remove L1s from alpha modules, and rewrite…#16483

Closed
madeline-k wants to merge 1 commit intoaws:masterfrom
madeline-k:v2/remove-l1s-and-rewrite-imports-2
Closed

chore(individual-pkg-gen): remove L1s from alpha modules, and rewrite…#16483
madeline-k wants to merge 1 commit intoaws:masterfrom
madeline-k:v2/remove-l1s-and-rewrite-imports-2

Conversation

@madeline-k
Copy link
Copy Markdown
Contributor

… imports using ts.updateXX() APIs

This change includes a significant rewrite of rewrite.ts to use ts AST node manipulation to update the import statments, rather than text manipulation. The reason to try this approach is it allows us to manipulate the AST directly, and insert two nodes where there formerly was one. The driving use case to do it this way was rewriting this:

import { CfnCluster, Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType } from '../lib';

into this:

import { CfnCluster } from '../lib/redshift.generated';
import { Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType } from '../lib';

The current approach still has some flaws, and it is really challenging to maintain the whitespace and comments of the original file. In the current state, a lot of whitespace and comments are removed.

Another approach that I tried and did not work in some cases unfortunately was to get the unchanged lines with :

// where s is a ts.Statement for the unchanged line
sourceFile.text.substr(s.getFullStart(), s.getFullStart() + s.getFullWidth());

this will most of the time get the full text of a statement, including leading whitespace and comments. But sometimes it gets entire lines or parts of lines preceding or following the line in question. This would even occur when just iterating through sourceFile.statements with the above logic. Before ever manipulating any of the nodes.

And printing the updated lines with:

const printer = ts.createPrinter({
    // Using the ts.updateXX() api maintains the leading comment, but not leading whitespace.
    // Remove the comments when printing and add back the full leading trivia later.
    removeComments: true,
});
const originalLeadingTriva = sourceFile.text.substr(s.getFullStart(), s.getStart(sourceFile));
return`${originalLeadingTriva}${printer.printNode(ts.EmitHint.Unspecified, s, sourceFile)}`;

this worked for the updated lines for the most part, but the real blocker for using this was re-printing out the unchanged statements.


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

@madeline-k madeline-k added the pr/do-not-merge This PR should not be merged at this time. label Sep 14, 2021
@gitpod-io
Copy link
Copy Markdown

gitpod-io bot commented Sep 14, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 14, 2021
@madeline-k madeline-k requested a review from rix0rrr September 14, 2021 04:53
@madeline-k
Copy link
Copy Markdown
Contributor Author

Alternative option: #16481

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 6f0be11
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@rix0rrr rix0rrr closed this Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS. pr/do-not-merge This PR should not be merged at this time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants