-
Notifications
You must be signed in to change notification settings - Fork 67
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: added static context to clear the .amplify/generated/env Directory before synthesis #2044
base: main
Are you sure you want to change the base?
Conversation
…ry before synthesis
…ry before synthesis
…ry before synthesis
🦋 Changeset detectedLatest commit: cfd19f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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. I like the approach.
Couple of naming comments.
@@ -7,10 +7,11 @@ import { EOL } from 'os'; | |||
* Generates a typed process.env shim for environment variables | |||
*/ | |||
export class FunctionEnvironmentTypeGenerator { | |||
// Using this to ensure directory is cleared once |
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.
// Using this to ensure directory is cleared once | |
// Using this to ensure directory is cleared once per synthesis |
/** | ||
* Clear existing files and subdirectories in the generated env directory | ||
*/ | ||
public clearGeneratedEnvDirectory = (): void => { |
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.
can this be private ?
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.
Can't be private since we're using this in test class
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.
fsExistsSyncMock.mock.restore(); | ||
fsRmSyncMock.mock.restore(); | ||
}); | ||
const resetFactoryCount = () => { |
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.
const resetFactoryCount = () => { | |
const resetFactoryGlobalState = () => { |
/** | ||
* Clear existing files and subdirectories in the generated env directory | ||
*/ | ||
public clearGeneratedEnvDirectory = (): void => { |
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.
assert.equal(fsExistsSyncMock.mock.calls.length, 1); | ||
assert.equal(fsRmSyncMock.mock.calls.length, 1); | ||
|
||
const functionEnvironmentTypeGenerator2 = | ||
new FunctionEnvironmentTypeGenerator('testFunction2'); | ||
|
||
functionEnvironmentTypeGenerator.clearGeneratedEnvDirectory(); | ||
functionEnvironmentTypeGenerator2.clearGeneratedEnvDirectory(); | ||
|
||
assert.equal(fsExistsSyncMock.mock.calls.length, 1); | ||
assert.equal(fsRmSyncMock.mock.calls.length, 1); |
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.
assert.equal(fsExistsSyncMock.mock.calls.length, 1); | |
assert.equal(fsRmSyncMock.mock.calls.length, 1); | |
const functionEnvironmentTypeGenerator2 = | |
new FunctionEnvironmentTypeGenerator('testFunction2'); | |
functionEnvironmentTypeGenerator.clearGeneratedEnvDirectory(); | |
functionEnvironmentTypeGenerator2.clearGeneratedEnvDirectory(); | |
assert.equal(fsExistsSyncMock.mock.calls.length, 1); | |
assert.equal(fsRmSyncMock.mock.calls.length, 1); | |
assert.equal(fsExistsSyncMock.mock.calls.length, 1); | |
assert.equal(fsRmSyncMock.mock.calls.length, 1); | |
const functionEnvironmentTypeGenerator2 = | |
new FunctionEnvironmentTypeGenerator('testFunction2'); | |
assert.equal(fsExistsSyncMock.mock.calls.length, 1); | |
assert.equal(fsRmSyncMock.mock.calls.length, 1); |
calling ctor multiple times should be good enough.
.changeset/rare-seas-eat.md
Outdated
--- | ||
'@aws-amplify/backend-function': patch | ||
--- |
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.
--- | |
'@aws-amplify/backend-function': patch | |
--- | |
--- | |
'@aws-amplify/backend': patch | |
'@aws-amplify/backend-function': patch | |
--- |
Looks like new check is working (#2042)
Problem
The
.amplify/generated/env/
directory is not cleared before deployments, causing outdated/renamed environment files to remain. This can lead to confusion and potential errors when the function's handler code does not match the current environment settings.