Skip to content

Commit 34eb820

Browse files
committed
fix: Clear generated env directory before shim generation
1 parent 5d0d04a commit 34eb820

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

packages/backend-function/src/function_env_type_generator.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,12 @@ void describe('FunctionEnvironmentTypeGenerator', () => {
7777
const fsExistsSyncMock = mock.method(fs, 'existsSync', () => true);
7878
const fsRmSyncMock = mock.method(fs, 'rmSync', () => {});
7979

80-
const functionEnvironmentTypeGenerator =
81-
new FunctionEnvironmentTypeGenerator('testFunction');
80+
new FunctionEnvironmentTypeGenerator('testFunction1');
8281

8382
assert.equal(fsExistsSyncMock.mock.calls.length, 1);
8483
assert.equal(fsRmSyncMock.mock.calls.length, 1);
8584

86-
const functionEnvironmentTypeGenerator2 =
87-
new FunctionEnvironmentTypeGenerator('testFunction2');
88-
89-
functionEnvironmentTypeGenerator.clearGeneratedEnvDirectory();
90-
functionEnvironmentTypeGenerator2.clearGeneratedEnvDirectory();
85+
new FunctionEnvironmentTypeGenerator('testFunction2');
9186

9287
assert.equal(fsExistsSyncMock.mock.calls.length, 1);
9388
assert.equal(fsRmSyncMock.mock.calls.length, 1);

packages/backend-function/src/function_env_type_generator.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@ export class FunctionEnvironmentTypeGenerator {
3131
);
3232
this.clearGeneratedEnvDirectory();
3333
}
34-
/**
35-
* Clear existing files and subdirectories in the generated env directory
36-
*/
37-
public clearGeneratedEnvDirectory = (): void => {
38-
if (FunctionEnvironmentTypeGenerator.isEnvDirectoryInitialized) {
39-
return;
40-
}
41-
const pathToDelete = path.join(
42-
process.cwd(),
43-
'.amplify',
44-
'generated',
45-
'env'
46-
);
47-
if (fs.existsSync(pathToDelete)) {
48-
fs.rmSync(pathToDelete, { recursive: true, force: true });
49-
FunctionEnvironmentTypeGenerator.isEnvDirectoryInitialized = true;
50-
}
51-
};
5234

5335
/**
5436
* Generate a typed process.env shim
@@ -117,4 +99,22 @@ export class FunctionEnvironmentTypeGenerator {
11799

118100
fs.writeFileSync(this.typeDefFilePath, content);
119101
};
102+
/**
103+
* Clear existing files and subdirectories in the generated env directory
104+
*/
105+
private clearGeneratedEnvDirectory = (): void => {
106+
if (FunctionEnvironmentTypeGenerator.isEnvDirectoryInitialized) {
107+
return;
108+
}
109+
const pathToDelete = path.join(
110+
process.cwd(),
111+
'.amplify',
112+
'generated',
113+
'env'
114+
);
115+
if (fs.existsSync(pathToDelete)) {
116+
fs.rmSync(pathToDelete, { recursive: true, force: true });
117+
FunctionEnvironmentTypeGenerator.isEnvDirectoryInitialized = true;
118+
}
119+
};
120120
}

0 commit comments

Comments
 (0)