-
Notifications
You must be signed in to change notification settings - Fork 822
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: post-process cfn files for minification, consolidating concern of minification a bit #12072
Conversation
dea73f4
to
203a46e
Compare
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/__tests__/utils/minify-utils.test.ts
Fixed
Show fixed
Hide fixed
packages/amplify-provider-awscloudformation/src/utils/minify-utils.ts
Outdated
Show resolved
Hide resolved
203a46e
to
e49880b
Compare
describe('minifyJSONFile', () => { | ||
const writeFileMinifyAndReturnReadContents = (filePath: string, contents: string): string => { | ||
const tmpFilePath = path.join(os.tmpdir(), filePath); | ||
fs.writeFileSync(tmpFilePath, contents); |
Check failure
Code scanning / CodeQL
Insecure temporary file
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.
nit: can this warning be fixed?
fs.mkdirSync(subNestedStacksDirectory); | ||
|
||
// Write files | ||
fs.writeFileSync(path.join(testDirectory, 'file.json'), JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
|
||
// Write files | ||
fs.writeFileSync(path.join(testDirectory, 'file.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(testDirectory, 'config.env'), NON_JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
// Write files | ||
fs.writeFileSync(path.join(testDirectory, 'file.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(testDirectory, 'config.env'), NON_JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_1.json'), JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
fs.writeFileSync(path.join(testDirectory, 'file.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(testDirectory, 'config.env'), NON_JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_1.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_2.json'), JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
fs.writeFileSync(path.join(testDirectory, 'config.env'), NON_JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_1.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_2.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested.env'), NON_JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_1.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_2.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested.env'), NON_JSON_STRING); | ||
fs.writeFileSync(path.join(subNestedStacksDirectory, 'sub_nested.json'), JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested_2.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(nestedStacksDirectory, 'nested.env'), NON_JSON_STRING); | ||
fs.writeFileSync(path.join(subNestedStacksDirectory, 'sub_nested.json'), JSON_STRING); | ||
fs.writeFileSync(path.join(subNestedStacksDirectory, 'sub_nested.env'), NON_JSON_STRING); |
Check failure
Code scanning / CodeQL
Insecure temporary file
if (!jsonFilePath.includes('.json')) return; // Don't convert files not ending in `.json` | ||
const originalJSON = fs.readFileSync(jsonFilePath, 'utf-8'); | ||
const minifiedJSON = JSON.stringify(JSON.parse(originalJSON)); | ||
fs.writeFileSync(jsonFilePath, minifiedJSON); |
Check failure
Code scanning / CodeQL
Insecure temporary file
e49880b
to
0a2b269
Compare
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.
LGTM, let a few nits, mostly concerned about the CodeQL warnings
packages/amplify-e2e-tests/src/__tests__/minify-cloudformation.test.ts
Outdated
Show resolved
Hide resolved
describe('minifyJSONFile', () => { | ||
const writeFileMinifyAndReturnReadContents = (filePath: string, contents: string): string => { | ||
const tmpFilePath = path.join(os.tmpdir(), filePath); | ||
fs.writeFileSync(tmpFilePath, contents); |
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.
nit: can this warning be fixed?
@@ -29,16 +29,21 @@ export type LayerPushSettings = { | |||
usePreviousPermissions?: boolean; | |||
}; | |||
|
|||
export type PushOpts = { |
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.
PushOptions
would be much better.
…f minification a bit (aws-amplify#12072) * fix: post-process cfn files for minification, consolidating concern of minification a bit * chore: applying prettier * fix: update to use amplifyPushUpdate * chore: update param style for push
Description of changes
When the
--minify
flag is passed in, post-process generated CFN files to read them back into memory, and rewrite in a shortened form. This will allow us to remove minify handling from the various places it exists today elsewhere in code, and have a single (or small number) of places where the Amplify CLI handles this.Issue #, if available
#7680
Description of how you validated changes
Added unit tests, and verified manually via
amplify-dev
that that w/ and w/o--minify
flag behaves as expected for both standard and iterative deployment use-cases (previous attempts to resolve this haven't resolved iterative deployments, leaving customers in a state where initial deploy succeeds, and adding/editing relationships will fail).Added an e2e test that verifies that both my nested stack files and top-level stack files will be emitted as
minified
: https://app.circleci.com/pipelines/github/aws-amplify/amplify-cli/16432/workflows/26a70f8c-a154-4ed0-a4f4-5573f5fe67d2Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.