diff --git a/src/builder/bundless/dts/index.ts b/src/builder/bundless/dts/index.ts index df539d69..319d237f 100644 --- a/src/builder/bundless/dts/index.ts +++ b/src/builder/bundless/dts/index.ts @@ -188,19 +188,37 @@ export default async function getDeclarations( }); // check compile error - // istanbul-ignore-if - if (result.diagnostics.length) { - result.diagnostics.forEach((d) => { - const loc = ts.getLineAndCharacterOfPosition(d.file!, d.start!); - const rltPath = winPath(path.relative(opts.cwd, d.file!.fileName)); - const errMsg = ts.flattenDiagnosticMessageText(d.messageText, '\n'); - - logger.error( - `${chalk.blueBright(rltPath)}:${ - // correct line number & column number, ref: https://github.com/microsoft/TypeScript/blob/93f2d2b9a1b2f8861b49d76bb5e58f6e9f2b56ee/src/compiler/tracing.ts#L185 - `${chalk.yellow(loc.line + 1)}:${chalk.yellow(loc.character + 1)}` - } - ${chalk.gray(`TS${d.code}:`)} ${errMsg}`, - ); + // ref: https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#a-minimal-compiler + const diagnostics = ts + .getPreEmitDiagnostics(incrProgram.getProgram()) + .concat(result.diagnostics); + + /* istanbul ignore if -- @preserve */ + if (diagnostics.length) { + diagnostics.forEach((d) => { + const fragments: string[] = []; + + // show file path & line number + if (d.file && d.start) { + const rltPath = winPath(path.relative(opts.cwd, d.file!.fileName)); + const loc = ts.getLineAndCharacterOfPosition(d.file!, d.start!); + + fragments.push( + `${chalk.blueBright(rltPath)}:${ + // correct line number & column number, ref: https://github.com/microsoft/TypeScript/blob/93f2d2b9a1b2f8861b49d76bb5e58f6e9f2b56ee/src/compiler/tracing.ts#L185 + `${chalk.yellow(loc.line + 1)}:${chalk.yellow( + loc.character + 1, + )} -` + }`, + ); + } + + // show error code + fragments.push(chalk.gray(`TS${d.code}:`)); + // show error message + fragments.push(ts.flattenDiagnosticMessageText(d.messageText, '\n')); + + logger.error(fragments.join(' ')); }); throw new Error('Declaration generation failed.'); } diff --git a/tests/fixtures/build/bundle-targets/tsconfig.json b/tests/fixtures/build/bundle-targets/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundle-targets/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-babel-config/tsconfig.json b/tests/fixtures/build/bundless-babel-config/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-babel-config/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-babel-targets/tsconfig.json b/tests/fixtures/build/bundless-babel-targets/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-babel-targets/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-define/tsconfig.json b/tests/fixtures/build/bundless-define/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-define/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-esbuild-targets/tsconfig.json b/tests/fixtures/build/bundless-esbuild-targets/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-esbuild-targets/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-ignores/tsconfig.json b/tests/fixtures/build/bundless-ignores/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-ignores/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-overrides/tsconfig.json b/tests/fixtures/build/bundless-overrides/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-overrides/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-swc-targets/tsconfig.json b/tests/fixtures/build/bundless-swc-targets/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-swc-targets/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/bundless-transformer/tsconfig.json b/tests/fixtures/build/bundless-transformer/tsconfig.json deleted file mode 100644 index 0967ef42..00000000 --- a/tests/fixtures/build/bundless-transformer/tsconfig.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/build/donocopy-public/tsconfig.json b/tests/fixtures/build/donocopy-public/tsconfig.json deleted file mode 100644 index a224293f..00000000 --- a/tests/fixtures/build/donocopy-public/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "jsx": "react-jsx" - } -} diff --git a/tests/fixtures/build/tsconfig.json b/tests/fixtures/build/tsconfig.json new file mode 100644 index 00000000..57c4da7c --- /dev/null +++ b/tests/fixtures/build/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "rootDir": ".", + "jsx": "react" + }, + "include": ["**/*.ts", "**/*.tsx"] +}