Skip to content

Commit cda08fe

Browse files
committed
Moving API extractor options out of RSC.
1 parent 52ef861 commit cda08fe

6 files changed

Lines changed: 107 additions & 222 deletions

File tree

common/reviews/api/rush-stack-compiler.api.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
// @beta
2-
class ApiExtractorRunner extends RushStackCompilerBase<IApiExtractorTaskConfig> {
3-
constructor(taskOptions: IApiExtractorTaskConfig, rootPath: string, terminalProvider: ITerminalProvider);
2+
class ApiExtractorRunner extends RushStackCompilerBase {
3+
constructor(extractorConfig: IExtractorConfig, extractorOptions: IExtractorOptions, rootPath: string, terminalProvider: ITerminalProvider);
44
// (undocumented)
55
invoke(): Promise<void>;
66
}
77

8-
// @public (undocumented)
9-
interface IApiExtractorTaskConfig {
10-
apiJsonFolder?: string;
11-
apiReviewFolder?: string;
12-
// @beta
13-
dtsRollupTrimming: boolean;
14-
entry?: string;
15-
// @beta
16-
generateDtsRollup?: boolean;
17-
localBuild?: boolean;
18-
// @beta
19-
publishFolderForBeta?: string;
20-
// @beta
21-
publishFolderForInternal?: string;
22-
// @beta
23-
publishFolderForPublic?: string;
24-
skipLibCheck?: boolean;
25-
}
26-
278
// @public (undocumented)
289
interface ITslintRunnerConfig {
2910
displayAsError?: boolean;
@@ -34,7 +15,7 @@ interface ITslintRunnerConfig {
3415
}
3516

3617
// @beta (undocumented)
37-
class RushStackCompilerBase<TOptions> {
18+
class RushStackCompilerBase<TOptions = {}> {
3819
constructor(taskOptions: TOptions, rootPath: string, terminalProvider: ITerminalProvider);
3920
// WARNING: The type "StandardBuildFolders" needs to be exported by the package (e.g. added to index.ts)
4021
// (undocumented)
@@ -53,7 +34,7 @@ class TslintRunner extends RushStackCompilerBase<ITslintRunnerConfig> {
5334
}
5435

5536
// @beta (undocumented)
56-
class TypescriptCompiler extends RushStackCompilerBase<{}> {
37+
class TypescriptCompiler extends RushStackCompilerBase {
5738
constructor(rootPath: string, terminalProvider: ITerminalProvider);
5839
// (undocumented)
5940
invoke(): Promise<void>;

core-build/gulp-core-build-typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"resolve": "~1.8.1"
2323
},
2424
"devDependencies": {
25+
"@microsoft/api-extractor": "6.0.9",
2526
"@microsoft/rush-stack-compiler": "0.1.20",
2627
"@microsoft/node-library-build": "5.0.16",
2728
"@types/glob": "5.0.30",

core-build/gulp-core-build-typescript/src/ApiExtractorTask.ts

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
// See LICENSE in the project root for license information.
33

44
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';
69
import { ApiExtractorRunner } from '@microsoft/rush-stack-compiler';
10+
import { IExtractorConfig, IExtractorOptions } from '@microsoft/api-extractor';
711

812
import { RSCTask, IRSCTaskConfig } from './RSCTask';
913

@@ -134,22 +138,90 @@ export class ApiExtractorTask extends RSCTask<IApiExtractorTaskConfig> {
134138
public executeTask(): Promise<void> {
135139
this.initializeRushStackCompiler();
136140

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,
140175
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,
144188
publishFolderForInternal: this.taskConfig.publishFolderForInternal,
145189
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,
149202
this.buildFolder,
150203
this._terminalProvider
151204
);
152205

153206
return apiExtractorRunner.invoke();
154207
}
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+
}
155227
}

0 commit comments

Comments
 (0)