Skip to content

Improve api-extractor invocation so it's easier to determine failure - #451

Merged
Pete Gonzalez (octogonz) merged 6 commits into
masterfrom
pgonzal/extractor-error-detection
Nov 28, 2017
Merged

Pete Gonzalez (octogonz) merged 6 commits into
masterfrom
pgonzal/extractor-error-detection

Conversation

@octogonz

Copy link
Copy Markdown
Collaborator

If API Extractor reports warnings or errors, the build should fail. However, since Extractor.analyzeProject() doesn't return a value, the only way to determine failure is by providing a customLogger. (This is what gulp-core-build does.) This PR adds a boolean return value to avoid this limitation.

Based on feedback, we're also renaming Extractor.analyzeProject() to Extractor.processProject().

This PR also updates the api-extractor command-line tool to return a nonzero exit code if an error occurs.


extractor.analyzeProject();
if (!extractor.processProject()) {
console.log('processProject() failed the build');

@qz2017 QZ (qz2017) Nov 23, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.error #WontFix

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is only used for easier debugging during development; it's not part of the shipping code


In reply to: 152713831 [](ancestors = 152713831)


// If there were any errors or warnings, then fail the build
return (this._monitoredLogger.errorCount + this._monitoredLogger.warningCount) === 0;
}

@qz2017 QZ (qz2017) Nov 23, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about return the sum of error and warning? so that we know how many errors there are. #WontFix

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the caller needs to report statistics, then I would prefer to return an actual statistics object with counts based on whatever reporting scenario there is.

However, currently I don't believe anyone has that requirement. Either they provide a custom logger (which gives them detailed access to everything) or else they just want to know whether the build should pass or fail.


In reply to: 152714377 [](ancestors = 152714377)


// NOTE: processProject() returns false if errors or warnings occurred, however we
// already handle this above via our customLogger
extractor.processProject();

@qz2017 QZ (qz2017) Nov 23, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about adding if (resultHasError) { completeCallback('extractor failed with n errors'); }? #WontFix

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCB already counts the number of errors and warnings that were passed to its custom logger and reports them like this:

Warning - tslint - src/Text.ts(41,12): error no-any: Type declaration of 'any' loses type-safety. Consider replacing it with a more precise type, the empty type ('{}'), or suppress this occurrence.
Warning - tslint - src/Text.ts(41,9): error no-unused-variable: 'x' is declared but never used.
Warning - tslint - src/Text.ts(41,9): error prefer-const: Identifier 'x' is never reassigned; use 'const' instead of 'let'.
Warning - [api-extractor] You have changed the public API signature for this project. Updating ../../common/reviews/api/sp-core-library.api.ts
Error - [api-extractor] src/Text.ts(10,1): A release tag (@alpha, @beta, @public, @internal) must be specified for Text
[15:23:14] Project @microsoft/sp-core-library version: 1.4.0-dev.14
[15:23:14] Build tools version: 3.2.7
[15:23:14] Node version: v6.10.2
[15:23:14] Total duration: 12 s
[15:23:14] Task warnings: 4
[15:23:14] Task errors: 1

Thus, the api-extractor task doesn't need to maintain its own statistics.


In reply to: 152714393 [](ancestors = 152714393)

@qz2017 QZ (qz2017) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with suggestions.

@octogonz
Pete Gonzalez (octogonz) merged commit 894bf71 into master Nov 28, 2017
javier-garcia-meteologica pushed a commit to javier-garcia-meteologica/rushstack that referenced this pull request Jun 26, 2020
…or-detection

Improve api-extractor invocation so it's easier to determine failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants