Skip to content
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

fix: top level comment not replacing existing ones #12862

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/amplify-category-function/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const categoryName = 'function';
export const envVarPrintoutPrefix =
'\nYou can access the following resource attributes as environment variables from your Lambda function\n\t';
const topLevelCommentBlockTitle = 'Amplify Params - DO NOT EDIT';
export const topLevelCommentPrefix = `/* ${topLevelCommentBlockTitle}\n\t`;
export const topLevelCommentPrefix = `/* ${topLevelCommentBlockTitle}\n`;
export const topLevelCommentSuffix = `\n${topLevelCommentBlockTitle} */`;

export enum CRUDOperation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const askExecRolePermissionsQuestions = async (

return {
dependsOn,
topLevelComment: `${topLevelCommentPrefix}${envVarStringList}${topLevelCommentSuffix}`,
topLevelComment: `${topLevelCommentPrefix}\t${envVarStringList}${topLevelCommentSuffix}`,
environmentMap,
mutableParametersState: { permissions },
categoryPolicies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const tryUpdateTopLevelComment = (resourceDirPath: string, envVars: strin
updateTopLevelComment(sourceFilePath, newComment);
};

const createTopLevelComment = (envVars: string[]) => `${topLevelCommentPrefix}${envVars.sort().join(`${EOL}\t`)}${topLevelCommentSuffix}`;
const createTopLevelComment = (envVars: string[]) => `${topLevelCommentPrefix}\t${envVars.sort().join(`${EOL}\t`)}${topLevelCommentSuffix}`;

const updateTopLevelComment = (filePath, newComment) => {
const commentRegex = new RegExp(`${_.escapeRegExp(topLevelCommentPrefix)}[a-zA-Z0-9\\-\\s._=]+${_.escapeRegExp(topLevelCommentSuffix)}`);
Expand Down