override fun execute()

in jetbrains-ultimate/src/software/aws/toolkits/jetbrains/services/lambda/nodejs/NodeJsLambdaBuilder.kt [50:107]


                override fun execute(context: Context, messageEmitter: StepEmitter, ignoreCancellation: Boolean) {
                    // relative to source root so that SAM build can copy it over to the correct place
                    val tsOutput = sourceRoot.resolve(TS_BUILD_DIR).normalize().toAbsolutePath().toString()
                    // relative to existing tsconfig because there is no other option https://github.com/microsoft/TypeScript/issues/25430
                    val tsConfig = sourceRoot.resolve(TS_CONFIG_FILE)
                    if (!tsConfig.exists()) {
                        Files.createFile(tsConfig)
                    }

                    // TODO: if there's an existing tsconfig file, should we use it as a base?
                    tsConfig.writeText(
                        // language=JSON
                        """
                        {
                            "compilerOptions": {
                                "${TypeScriptConfig.TYPE_ROOTS}": [
                                  "${sourceRoot.resolve(TypeScriptConfig.DEFAULT_TYPES_DIRECTORY)}"
                                ],
                                "${TypeScriptConfig.TYPES}": [
                                  "node"
                                ],
                                "${TypeScriptConfig.TARGET_OPTION}": "${TypeScriptConfig.LanguageTarget.ES6.libName}",
                                "${TypeScriptConfig.MODULE}": "${TypeScriptConfig.MODULE_COMMON_JS}",
                                "${TypeScriptConfig.OUT_DIR}": "$tsOutput",
                                "${TypeScriptConfig.ROOT_DIR}": ".",
                                "sourceRoot": "$sourceRoot",
                                "${TypeScriptConfig.SOURCE_MAP}": true
                            }
                        }
                        """.trimIndent()
                    )

                    val tsConfigVirtualFile = VfsUtil.findFile(tsConfig, true) ?: throw RuntimeException("Could not find temporary tsconfig file using VFS")
                    val tsService = TypeScriptCompilerService.getServiceForFile(project, handlerElement.containingFile.virtualFile)

                    messageEmitter.emitMessageLine(message("lambda.build.typescript.compiler.running", tsConfig), false)
                    val compilerFuture = tsService?.compileConfigProjectAndGetErrors(tsConfigVirtualFile)
                    val results = compilerFuture?.get()
                        ?: throw RuntimeException(message("lambda.build.typescript.compiler.ide_error"))

                    messageEmitter.emitMessageLine(message("lambda.build.typescript.compiler.processed_files"), false)
                    results.processedFiles.forEach {
                        messageEmitter.emitMessageLine(it, false)
                    }

                    messageEmitter.emitMessageLine(message("lambda.build.typescript.compiler.emitted_files"), false)
                    results.emittedFiles.forEach {
                        messageEmitter.emitMessageLine(it, false)
                    }

                    // errors, warnings, etc
                    messageEmitter.emitMessageLine(message("lambda.build.typescript.compiler.annotation_results"), false)
                    results.annotationResults.forEach {
                        val isError = it.severity >= HighlightSeverity.WARNING
                        val location = "${it.absoluteFilePath ?: '?'}:${it.line + 1}:"
                        messageEmitter.emitMessageLine(location + it.description, isError)
                    }
                }