Skip to content

Commit

Permalink
fix: turn off type checking if amplify/tsconfig.json is not found (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer authored Nov 20, 2023
1 parent 8258926 commit d010539
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-readers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-deployer': patch
---

turn off type checking if amplify/tsconfig.json is not found
60 changes: 54 additions & 6 deletions packages/backend-deployer/src/cdk_deployer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,24 @@ void describe('invokeCDKCommand', () => {
deploymentType: 'branch',
validateAppSources: true,
});
assert.strictEqual(execaMock.mock.callCount(), 2);
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 5);
assert.strictEqual(execaMock.mock.callCount(), 3);
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 4);
assert.deepStrictEqual(execaMock.mock.calls[0].arguments[1], [
'tsc',
'--showConfig',
'--project',
'amplify',
]);
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 5);
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
'tsc',
'--noEmit',
'--skipLibCheck',
'--project',
'amplify',
]);
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 16);
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
assert.equal(execaMock.mock.calls[2].arguments[1]?.length, 16);
assert.deepStrictEqual(execaMock.mock.calls[2].arguments[1], [
'cdk',
'deploy',
'--ci',
Expand All @@ -190,15 +197,56 @@ void describe('invokeCDKCommand', () => {
deploymentType: 'sandbox',
validateAppSources: true,
});
assert.strictEqual(execaMock.mock.callCount(), 2);
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 5);
assert.strictEqual(execaMock.mock.callCount(), 3);
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 4);
assert.deepStrictEqual(execaMock.mock.calls[0].arguments[1], [
'tsc',
'--showConfig',
'--project',
'amplify',
]);
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 5);
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
'tsc',
'--noEmit',
'--skipLibCheck',
'--project',
'amplify',
]);
assert.equal(execaMock.mock.calls[2].arguments[1]?.length, 12);
assert.deepStrictEqual(execaMock.mock.calls[2].arguments[1], [
'cdk',
'deploy',
'--ci',
'--app',
"'npx tsx amplify/backend.ts'",
'--all',
'--output',
'.amplify/artifacts/cdk.out',
'--context',
`amplify-backend-type=sandbox`,
'--hotswap-fallback',
'--method=direct',
]);
});

void it('disables type checking when tsconfig is not present', async () => {
// simulate first execa call as throwing error when checking for tsconfig.json
execaMock.mock.mockImplementationOnce(() =>
Promise.reject(new Error('some error'))
);
await invoker.deploy(undefined, {
deploymentType: 'sandbox',
validateAppSources: true,
});
assert.strictEqual(execaMock.mock.callCount(), 2);
assert.equal(execaMock.mock.calls[0].arguments[1]?.length, 4);
assert.deepStrictEqual(execaMock.mock.calls[0].arguments[1], [
'tsc',
'--showConfig',
'--project',
'amplify',
]);
assert.equal(execaMock.mock.calls[1].arguments[1]?.length, 12);
assert.deepStrictEqual(execaMock.mock.calls[1].arguments[1], [
'cdk',
Expand Down
20 changes: 16 additions & 4 deletions packages/backend-deployer/src/cdk_deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,28 @@ export class CDKDeployer implements BackendDeployer {
};

private invokeTsc = async (deployProps?: DeployProps) => {
if (deployProps?.validateAppSources) {
if (!deployProps?.validateAppSources) {
return;
}
try {
await this.executeChildProcess('npx', [
'tsc',
'--noEmit',
'--skipLibCheck',
// pointing the project arg to the amplify backend directory will use the tsconfig present in that directory
'--showConfig',
'--project',
dirname(this.backendLocator.locate()),
]);
} catch (error) {
// If we cannot load ts config, turn off type checking
return;
}
await this.executeChildProcess('npx', [
'tsc',
'--noEmit',
'--skipLibCheck',
// pointing the project arg to the amplify backend directory will use the tsconfig present in that directory
'--project',
dirname(this.backendLocator.locate()),
]);
};

/**
Expand Down

0 comments on commit d010539

Please sign in to comment.