From bf58710078f2991265441d6731164f7875eff513 Mon Sep 17 00:00:00 2001 From: Stephan Bijzitter Date: Tue, 4 Jun 2019 18:39:11 +0200 Subject: [PATCH] Force noEmit compiler option to be false When a developer makes a mistake and has noEmit with a value of true in their tsconfig.json, this plugin errors out with "Typescript compilation failed" message. The message is wrong, as compilation actually did succeed. The real problem is that there simply were no files written to disk and as such there are no files for serverless to deploy. To prevent developers from making this mistake, its value can be forced by the plugin. --- README.md | 3 ++- src/typescript.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c5fdf925..77bcb833 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ The default `tsconfig.json` file used by the plugin looks like this: ```json { "compilerOptions": { + "noEmit": false, "preserveConstEnums": true, "strictNullChecks": true, "sourceMap": true, @@ -47,7 +48,7 @@ The default `tsconfig.json` file used by the plugin looks like this: } ``` -> Note 1: The `outDir` and `rootDir` options cannot be overwritten. +> Note 1: The `outDir`, `rootDir` and `noEmit` options cannot be overwritten. > Note 2: Don't confuse the [`tsconfig.json`](tsconfig.json) in this repository with the one mentioned above. diff --git a/src/typescript.ts b/src/typescript.ts index f18e59b4..e38dad9e 100644 --- a/src/typescript.ts +++ b/src/typescript.ts @@ -6,6 +6,7 @@ import * as path from 'path' export function makeDefaultTypescriptConfig() { const defaultTypescriptConfig: ts.CompilerOptions = { + noEmit: false, preserveConstEnums: true, strictNullChecks: true, sourceMap: true, @@ -120,12 +121,18 @@ export function getTypescriptConfig( logger.log(`Using local tsconfig.json`) } - // disallow overrriding rootDir + // disallow overriding rootDir if (configParseResult.options.rootDir && path.resolve(configParseResult.options.rootDir) !== path.resolve(cwd) && logger) { - logger.log('Warning: "rootDir" from local tsconfig.json is overriden') + logger.log('Warning: "rootDir" from local tsconfig.json is overridden') } configParseResult.options.rootDir = cwd + // disallow overriding noEmit + if (configParseResult.options.noEmit !== false) { + logger.log('Warning: "noEmit" from local tsconfig.json is overridden') + } + configParseResult.options.noEmit = false + return configParseResult.options }