|
2 | 2 | // See LICENSE in the project root for license information. |
3 | 3 |
|
4 | 4 | import * as path from 'path'; |
5 | | -import { JsonFile } from '@microsoft/node-core-library'; |
| 5 | +import { |
| 6 | + JsonFile, |
| 7 | + FileSystem |
| 8 | +} from '@microsoft/node-core-library'; |
6 | 9 | import { ApiExtractorRunner } from '@microsoft/rush-stack-compiler'; |
| 10 | +import { IExtractorConfig, IExtractorOptions } from '@microsoft/api-extractor'; |
7 | 11 |
|
8 | 12 | import { RSCTask, IRSCTaskConfig } from './RSCTask'; |
9 | 13 |
|
@@ -134,22 +138,90 @@ export class ApiExtractorTask extends RSCTask<IApiExtractorTaskConfig> { |
134 | 138 | public executeTask(): Promise<void> { |
135 | 139 | this.initializeRushStackCompiler(); |
136 | 140 |
|
137 | | - const apiExtractorRunner: ApiExtractorRunner = new this._rushStackCompiler.ApiExtractorRunner( |
138 | | - { |
139 | | - entry: this.taskConfig.entry, |
| 141 | + if (!this._validateConfiguration()) { |
| 142 | + return Promise.resolve(); |
| 143 | + } |
| 144 | + |
| 145 | + if (!this.taskConfig.entry) { |
| 146 | + return Promise.reject(new Error('entry must be defined')); |
| 147 | + } |
| 148 | + |
| 149 | + if (!this.taskConfig.apiJsonFolder) { |
| 150 | + return Promise.reject(new Error('apiJsonFolder must be defined')); |
| 151 | + } |
| 152 | + |
| 153 | + if (!this.taskConfig.apiReviewFolder) { |
| 154 | + return Promise.reject(new Error('apiReviewFolder must be defined')); |
| 155 | + } |
| 156 | + |
| 157 | + let entryPointFile: string; |
| 158 | + if (this.taskConfig.entry === 'src/index.ts') { |
| 159 | + // backwards compatibility for legacy projects that used *.ts files as their entry point |
| 160 | + entryPointFile = path.join(this.buildConfig.rootPath, 'lib/index.d.ts'); |
| 161 | + } else { |
| 162 | + entryPointFile = path.join(this.buildConfig.rootPath, this.taskConfig.entry); |
| 163 | + } |
| 164 | + |
| 165 | + const extractorConfig: IExtractorConfig = { |
| 166 | + compiler: { |
| 167 | + configType: 'tsconfig', |
| 168 | + rootFolder: this.buildConfig.rootPath |
| 169 | + }, |
| 170 | + project: { |
| 171 | + entryPointSourceFile: entryPointFile |
| 172 | + }, |
| 173 | + apiReviewFile: { |
| 174 | + enabled: true, |
140 | 175 | apiReviewFolder: this.taskConfig.apiReviewFolder, |
141 | | - apiJsonFolder: this.taskConfig.apiJsonFolder, |
142 | | - generateDtsRollup: this.taskConfig.generateDtsRollup, |
143 | | - dtsRollupTrimming: this.taskConfig.dtsRollupTrimming, |
| 176 | + tempFolder: path.join(this.buildConfig.rootPath, this.buildConfig.tempFolder) |
| 177 | + }, |
| 178 | + apiJsonFile: { |
| 179 | + enabled: true, |
| 180 | + outputFolder: this.taskConfig.apiJsonFolder |
| 181 | + } |
| 182 | + }; |
| 183 | + |
| 184 | + if (this.taskConfig.generateDtsRollup) { |
| 185 | + extractorConfig.dtsRollup = { |
| 186 | + enabled: true, |
| 187 | + trimming: !!this.taskConfig.dtsRollupTrimming, |
144 | 188 | publishFolderForInternal: this.taskConfig.publishFolderForInternal, |
145 | 189 | publishFolderForBeta: this.taskConfig.publishFolderForBeta, |
146 | | - publishFolderForPublic: this.taskConfig.publishFolderForPublic, |
147 | | - skipLibCheck: this.taskConfig.skipLibCheck |
148 | | - }, |
| 190 | + publishFolderForPublic: this.taskConfig.publishFolderForPublic |
| 191 | + }; |
| 192 | + } |
| 193 | + |
| 194 | + const extractorOptions: IExtractorOptions = { |
| 195 | + localBuild: !this.buildConfig.production, |
| 196 | + skipLibCheck: this.taskConfig.skipLibCheck |
| 197 | + }; |
| 198 | + |
| 199 | + const apiExtractorRunner: ApiExtractorRunner = new this._rushStackCompiler.ApiExtractorRunner( |
| 200 | + extractorConfig, |
| 201 | + extractorOptions, |
149 | 202 | this.buildFolder, |
150 | 203 | this._terminalProvider |
151 | 204 | ); |
152 | 205 |
|
153 | 206 | return apiExtractorRunner.invoke(); |
154 | 207 | } |
| 208 | + |
| 209 | + private _validateConfiguration(): boolean { |
| 210 | + if (!this.taskConfig.entry) { |
| 211 | + this.logError('Missing or empty "entry" field in api-extractor.json'); |
| 212 | + return false; |
| 213 | + } |
| 214 | + |
| 215 | + if (!this.taskConfig.apiReviewFolder) { |
| 216 | + this.logError('Missing or empty "apiReviewFolder" field in api-extractor.json'); |
| 217 | + return false; |
| 218 | + } |
| 219 | + |
| 220 | + if (!FileSystem.exists(this.taskConfig.entry)) { |
| 221 | + this.logError(`Entry file ${this.taskConfig.entry} does not exist.`); |
| 222 | + return false; |
| 223 | + } |
| 224 | + |
| 225 | + return true; |
| 226 | + } |
155 | 227 | } |
0 commit comments