Skip to content

Commit d010539

Browse files
authored
fix: turn off type checking if amplify/tsconfig.json is not found (#706)
1 parent 8258926 commit d010539

File tree

3 files changed

+75
-10
lines changed

3 files changed

+75
-10
lines changed

.changeset/few-readers-brush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
---
4+
5+
turn off type checking if amplify/tsconfig.json is not found

packages/backend-deployer/src/cdk_deployer.test.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,24 @@ void describe('invokeCDKCommand', () => {
155155
deploymentType: 'branch',
156156
validateAppSources: true,
157157
});
158-
assert.strictEqual(execaMock.mock.callCount(), 2);
159-
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 5);
158+
assert.strictEqual(execaMock.mock.callCount(), 3);
159+
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 4);
160160
assert.deepStrictEqual(execaMock.mock.calls[0].arguments[1], [
161+
'tsc',
162+
'--showConfig',
163+
'--project',
164+
'amplify',
165+
]);
166+
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 5);
167+
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
161168
'tsc',
162169
'--noEmit',
163170
'--skipLibCheck',
164171
'--project',
165172
'amplify',
166173
]);
167-
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 16);
168-
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
174+
assert.equal(execaMock.mock.calls[2].arguments[1]?.length, 16);
175+
assert.deepStrictEqual(execaMock.mock.calls[2].arguments[1], [
169176
'cdk',
170177
'deploy',
171178
'--ci',
@@ -190,15 +197,56 @@ void describe('invokeCDKCommand', () => {
190197
deploymentType: 'sandbox',
191198
validateAppSources: true,
192199
});
193-
assert.strictEqual(execaMock.mock.callCount(), 2);
194-
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 5);
200+
assert.strictEqual(execaMock.mock.callCount(), 3);
201+
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 4);
195202
assert.deepStrictEqual(execaMock.mock.calls[0].arguments[1], [
203+
'tsc',
204+
'--showConfig',
205+
'--project',
206+
'amplify',
207+
]);
208+
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 5);
209+
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
196210
'tsc',
197211
'--noEmit',
198212
'--skipLibCheck',
199213
'--project',
200214
'amplify',
201215
]);
216+
assert.equal(execaMock.mock.calls[2].arguments[1]?.length, 12);
217+
assert.deepStrictEqual(execaMock.mock.calls[2].arguments[1], [
218+
'cdk',
219+
'deploy',
220+
'--ci',
221+
'--app',
222+
"'npx tsx amplify/backend.ts'",
223+
'--all',
224+
'--output',
225+
'.amplify/artifacts/cdk.out',
226+
'--context',
227+
`amplify-backend-type=sandbox`,
228+
'--hotswap-fallback',
229+
'--method=direct',
230+
]);
231+
});
232+
233+
void it('disables type checking when tsconfig is not present', async () => {
234+
// simulate first execa call as throwing error when checking for tsconfig.json
235+
execaMock.mock.mockImplementationOnce(() =>
236+
Promise.reject(new Error('some error'))
237+
);
238+
await invoker.deploy(undefined, {
239+
deploymentType: 'sandbox',
240+
validateAppSources: true,
241+
});
242+
assert.strictEqual(execaMock.mock.callCount(), 2);
243+
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 4);
244+
assert.deepStrictEqual(execaMock.mock.calls[0].arguments[1], [
245+
'tsc',
246+
'--showConfig',
247+
'--project',
248+
'amplify',
249+
]);
202250
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 12);
203251
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
204252
'cdk',

packages/backend-deployer/src/cdk_deployer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,28 @@ export class CDKDeployer implements BackendDeployer {
7474
};
7575

7676
private invokeTsc = async (deployProps?: DeployProps) => {
77-
if (deployProps?.validateAppSources) {
77+
if (!deployProps?.validateAppSources) {
78+
return;
79+
}
80+
try {
7881
await this.executeChildProcess('npx', [
7982
'tsc',
80-
'--noEmit',
81-
'--skipLibCheck',
82-
// pointing the project arg to the amplify backend directory will use the tsconfig present in that directory
83+
'--showConfig',
8384
'--project',
8485
dirname(this.backendLocator.locate()),
8586
]);
87+
} catch (error) {
88+
// If we cannot load ts config, turn off type checking
89+
return;
8690
}
91+
await this.executeChildProcess('npx', [
92+
'tsc',
93+
'--noEmit',
94+
'--skipLibCheck',
95+
// pointing the project arg to the amplify backend directory will use the tsconfig present in that directory
96+
'--project',
97+
dirname(this.backendLocator.locate()),
98+
]);
8799
};
88100

89101
/**

0 commit comments

Comments
 (0)