diff --git a/lib/steps/build/compileTypeScript.ts b/lib/steps/build/compileTypeScript.ts index a12cf06a..209b4bfb 100644 --- a/lib/steps/build/compileTypeScript.ts +++ b/lib/steps/build/compileTypeScript.ts @@ -24,7 +24,7 @@ const compileTypeScript = async function ({ const parsedTsConfig = ts.parseJsonSourceFileConfigFileContent(tsConfigSourceFile, ts.sys, applicationRoot, undefined, tsConfigPath); const compilerOptions = parsedTsConfig.options; - if (!compilerOptions.outDir) { + if (!compilerOptions.outDir && !noEmit) { return error(new errors.TypeScriptOutputConfigurationMissing()); } @@ -45,8 +45,8 @@ const compileTypeScript = async function ({ options: compilerOptions }); - if (compilerOptions.incremental !== true) { - await fs.promises.rm(compilerOptions.outDir, { recursive: true, force: true }); + if (compilerOptions.incremental !== true && !noEmit) { + await fs.promises.rm(compilerOptions.outDir!, { recursive: true, force: true }); } let emitResult: EmitResult | undefined; diff --git a/test/integration/analyzeTests.ts b/test/integration/analyzeTests.ts index 78ed751d..8cd4efaa 100644 --- a/test/integration/analyzeTests.ts +++ b/test/integration/analyzeTests.ts @@ -381,4 +381,18 @@ suite('analyze', function (): void { assert.that(stripAnsi(error.stderr)).is.containing('The given license is not a valid SPDX expression.'); } ); + + testWithFixture( + 'does not fail when outDir is not configured in tsconfig', + [ 'analyze', 'without-output-config' ], + async (fixture): Promise => { + const roboterResult = await runCommand('npx roboter analyze', { + cwd: fixture.absoluteTestDirectory, + silent: true + }); + + assert.that(roboterResult).is.aValue(); + assert.that(roboterResult.unwrapOrThrow().exitCode).is.equalTo(0); + } + ); }); diff --git a/test/shared/fixtures/analyze/without-output-config/.eslintrc.json b/test/shared/fixtures/analyze/without-output-config/.eslintrc.json new file mode 100644 index 00000000..0b7481db --- /dev/null +++ b/test/shared/fixtures/analyze/without-output-config/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "es/node" +} diff --git a/test/shared/fixtures/analyze/without-output-config/.npmpackagejsonlintrc.json b/test/shared/fixtures/analyze/without-output-config/.npmpackagejsonlintrc.json new file mode 100644 index 00000000..bce1834e --- /dev/null +++ b/test/shared/fixtures/analyze/without-output-config/.npmpackagejsonlintrc.json @@ -0,0 +1,6 @@ +{ + "extends": "npm-package-json-lint-config-tnw/lib.json", + "rules": { + "prefer-alphabetical-devDependencies": "off" + } +} diff --git a/test/shared/fixtures/analyze/without-output-config/licenseCheck.json b/test/shared/fixtures/analyze/without-output-config/licenseCheck.json new file mode 100644 index 00000000..d5098699 --- /dev/null +++ b/test/shared/fixtures/analyze/without-output-config/licenseCheck.json @@ -0,0 +1,14 @@ +{ + "compatibleLicenses": [ + "0BSD", + "Apache-2.0", + "BSD-2-Clause", + "BSD-3-Clause", + "CC-BY-3.0", + "CC-BY-4.0", + "CC0-1.0", + "MIT", + "ISC", + "Python-2.0" + ] +} diff --git a/test/shared/fixtures/analyze/without-output-config/package.json b/test/shared/fixtures/analyze/without-output-config/package.json new file mode 100644 index 00000000..7b0e5675 --- /dev/null +++ b/test/shared/fixtures/analyze/without-output-config/package.json @@ -0,0 +1,16 @@ +{ + "name": "test-package", + "version": "0.0.1", + "description": "a test-package.", + "contributors": [], + "private": false, + "main": "", + "types": "", + "engines": {}, + "dependencies": {}, + "devDependencies": {}, + "scripts": {}, + "repository": {}, + "keywords": [], + "license": "MIT" +} diff --git a/test/shared/fixtures/analyze/without-output-config/src/index.ts b/test/shared/fixtures/analyze/without-output-config/src/index.ts new file mode 100644 index 00000000..e9265634 --- /dev/null +++ b/test/shared/fixtures/analyze/without-output-config/src/index.ts @@ -0,0 +1,8 @@ +const add = function (left: number, right: number): number { + return left + right; +}; + +const sum = add(23, 42); + +// eslint-disable-next-line no-console +console.log(sum); diff --git a/test/shared/fixtures/analyze/without-output-config/tsconfig.json b/test/shared/fixtures/analyze/without-output-config/tsconfig.json new file mode 100644 index 00000000..341a66c8 --- /dev/null +++ b/test/shared/fixtures/analyze/without-output-config/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "baseUrl": "./", + "declaration": true, + "esModuleInterop": true, + "lib": [ "dom", "esnext" ], + "module": "commonjs", + "resolveJsonModule": true, + "strict": true, + "target": "es2019" + }, + "include": [ + "./**/*.ts" + ] +}