X Tutup
Skip to content

Commit 774e16d

Browse files
committed
Add a new api-extractor.json config file setting for "bundledPackages"
1 parent 0c285cd commit 774e16d

File tree

6 files changed

+60
-1
lines changed

6 files changed

+60
-1
lines changed

apps/api-extractor/src/api/ExtractorConfig.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ interface IExtractorConfigParameters {
9595
packageJson: INodePackageJson | undefined;
9696
packageFolder: string | undefined;
9797
mainEntryPointFilePath: string;
98+
bundledPackages: string[];
9899
tsconfigFilePath: string;
99100
overrideTsconfig: { } | undefined;
100101
skipLibCheck: boolean;
@@ -153,6 +154,9 @@ export class ExtractorConfig {
153154
/** {@inheritDoc IConfigFile.mainEntryPointFilePath} */
154155
public readonly mainEntryPointFilePath: string;
155156

157+
/** {@inheritDoc IConfigFile.bundledPackages} */
158+
public readonly bundledPackages: string[];
159+
156160
/** {@inheritDoc IConfigCompiler.tsconfigFilePath} */
157161
public readonly tsconfigFilePath: string;
158162

@@ -202,6 +206,7 @@ export class ExtractorConfig {
202206
this.packageJson = parameters.packageJson;
203207
this.packageFolder = parameters.packageFolder;
204208
this.mainEntryPointFilePath = parameters.mainEntryPointFilePath;
209+
this.bundledPackages = parameters.bundledPackages;
205210
this.tsconfigFilePath = parameters.tsconfigFilePath;
206211
this.overrideTsconfig = parameters.overrideTsconfig;
207212
this.skipLibCheck = parameters.skipLibCheck;
@@ -543,6 +548,13 @@ export class ExtractorConfig {
543548
throw new Error('The "mainEntryPointFilePath" path does not exist: ' + mainEntryPointFilePath);
544549
}
545550

551+
const bundledPackages: string[] = configObject.bundledPackages || [];
552+
for (const bundledPackage of bundledPackages) {
553+
if (!PackageName.isValidName(bundledPackage)) {
554+
throw new Error(`The "bundledPackages" list contains an invalid package name: "${bundledPackage}"`);
555+
}
556+
}
557+
546558
const tsconfigFilePath: string = ExtractorConfig._resolvePathWithTokens('tsconfigFilePath',
547559
configObject.compiler.tsconfigFilePath, tokenContext);
548560

@@ -645,6 +657,7 @@ export class ExtractorConfig {
645657
packageJson,
646658
packageFolder,
647659
mainEntryPointFilePath,
660+
bundledPackages,
648661
tsconfigFilePath,
649662
overrideTsconfig: configObject.compiler.overrideTsconfig,
650663
skipLibCheck: !!configObject.compiler.skipLibCheck,

apps/api-extractor/src/api/IConfigFile.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ export interface IConfigFile {
321321
*/
322322
mainEntryPointFilePath: string;
323323

324+
/**
325+
* A list of NPM package names whose exports should be treated as part of this package.
326+
*
327+
* @remarks
328+
*
329+
* For example, suppose that Webpack is used to generate a distributed bundle for the project `library1`,
330+
* and another NPM package `library2` is embedded in this bundle. Some types from `library2` may become part
331+
* of the exported API for `library1`, but by default API Extractor would generate a .d.ts rollup that explicitly
332+
* imports `library2`. To avoid this, we can specify:
333+
*
334+
* ```js
335+
* "bundledPackages": [ "library2" ],
336+
* ```
337+
*
338+
* This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
339+
* local files for `library1`.
340+
*/
341+
bundledPackages?: string[];
342+
324343
/**
325344
* {@inheritDoc IConfigCompiler}
326345
*/

apps/api-extractor/src/schemas/api-extractor-defaults.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
2+
"projectFolder": "<lookup>",
3+
24
// ("mainEntryPointFilePath" is required)
35

4-
"projectFolder": "<lookup>",
6+
"bundledPackages": [ ],
57

68
"compiler": {
79
"tsconfigFilePath": "<projectFolder>/tsconfig.json",

apps/api-extractor/src/schemas/api-extractor-template.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
*/
4848
"mainEntryPointFilePath": "<projectFolder>/lib/index.d.ts",
4949

50+
/**
51+
* A list of NPM package names whose exports should be treated as part of this package.
52+
*
53+
* For example, suppose that Webpack is used to generate a distributed bundle for the project "library1",
54+
* and another NPM package "library2" is embedded in this bundle. Some types from library2 may become part
55+
* of the exported API for library1, but by default API Extractor would generate a .d.ts rollup that explicitly
56+
* imports library2. To avoid this, we can specify:
57+
*
58+
* "bundledPackages": [ "library2" ],
59+
*
60+
* This would direct API Extractor to embed those types directly in the .d.ts rollup, as if they had been
61+
* local files for library1.
62+
*/
63+
"bundledPackages": [ ],
64+
5065
/**
5166
* Determines how the TypeScript compiler engine will be invoked by API Extractor.
5267
*/

apps/api-extractor/src/schemas/api-extractor.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
"type": "string"
2424
},
2525

26+
"bundledPackages": {
27+
"description": "A list of NPM package names whose exports should be treated as part of this package.",
28+
"type": "array",
29+
"items": {
30+
"type": "string"
31+
}
32+
},
33+
2634
"compiler": {
2735
"description": "Determines how the TypeScript compiler engine will be invoked by API Extractor.",
2836
"type": "object",

common/reviews/api/api-extractor.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class ExtractorConfig {
4141
readonly apiJsonFilePath: string;
4242
readonly apiReportEnabled: boolean;
4343
readonly betaTrimmedFilePath: string;
44+
readonly bundledPackages: string[];
4445
readonly docModelEnabled: boolean;
4546
static readonly FILENAME: string;
4647
getDiagnosticDump(): string;
@@ -175,6 +176,7 @@ export interface IConfigDtsRollup {
175176
// @public
176177
export interface IConfigFile {
177178
apiReport?: IConfigApiReport;
179+
bundledPackages?: string[];
178180
compiler?: IConfigCompiler;
179181
docModel?: IConfigDocModel;
180182
// @beta

0 commit comments

Comments
 (0)
X Tutup