diff --git a/.changeset/few-readers-brush.md b/.changeset/few-readers-brush.md new file mode 100644 index 0000000000..6347887f1d --- /dev/null +++ b/.changeset/few-readers-brush.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-deployer': patch +--- + +turn off type checking if amplify/tsconfig.json is not found diff --git a/packages/backend-deployer/src/cdk_deployer.test.ts b/packages/backend-deployer/src/cdk_deployer.test.ts index 3267b38665..4d41b1546a 100644 --- a/packages/backend-deployer/src/cdk_deployer.test.ts +++ b/packages/backend-deployer/src/cdk_deployer.test.ts @@ -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', @@ -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', diff --git a/packages/backend-deployer/src/cdk_deployer.ts b/packages/backend-deployer/src/cdk_deployer.ts index b8460ff06f..4cd1fc4370 100644 --- a/packages/backend-deployer/src/cdk_deployer.ts +++ b/packages/backend-deployer/src/cdk_deployer.ts @@ -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()), + ]); }; /**