22// See LICENSE in the project root for license information.
33
44import * as ts from 'typescript' ;
5- import { InternalError } from '@microsoft/node-core-library' ;
5+ import { InternalError , PackageName } from '@microsoft/node-core-library' ;
66
77import { TypeScriptHelpers } from './TypeScriptHelpers' ;
88import { AstSymbol } from './AstSymbol' ;
@@ -55,6 +55,7 @@ interface IAstModuleReference {
5555export class ExportAnalyzer {
5656 private readonly _program : ts . Program ;
5757 private readonly _typeChecker : ts . TypeChecker ;
58+ private readonly _bundledPackageNames : Set < string > ;
5859 private readonly _astSymbolTable : IAstSymbolTable ;
5960
6061 private readonly _astModulesByModuleSymbol : Map < ts . Symbol , AstModule >
@@ -65,9 +66,11 @@ export class ExportAnalyzer {
6566
6667 private readonly _astImportsByKey : Map < string , AstImport > = new Map < string , AstImport > ( ) ;
6768
68- public constructor ( program : ts . Program , typeChecker : ts . TypeChecker , astSymbolTable : IAstSymbolTable ) {
69+ public constructor ( program : ts . Program , typeChecker : ts . TypeChecker , bundledPackageNames : Set < string > ,
70+ astSymbolTable : IAstSymbolTable ) {
6971 this . _program = program ;
7072 this . _typeChecker = typeChecker ;
73+ this . _bundledPackageNames = bundledPackageNames ;
7174 this . _astSymbolTable = astSymbolTable ;
7275 }
7376
@@ -93,7 +96,7 @@ export class ExportAnalyzer {
9396 if ( moduleReference !== undefined ) {
9497 // Match: "@microsoft/sp-lodash-subset" or "lodash/has"
9598 // but ignore: "../folder/LocalFile"
96- if ( ! ts . isExternalModuleNameRelative ( moduleReference . moduleSpecifier ) ) {
99+ if ( this . _isExternalModulePath ( moduleReference . moduleSpecifier ) ) {
97100 externalModulePath = moduleReference . moduleSpecifier ;
98101 }
99102 }
@@ -231,6 +234,30 @@ export class ExportAnalyzer {
231234 return entryPointAstModule . astModuleExportInfo ;
232235 }
233236
237+ /**
238+ * Returns true if the module specifier refers to an external package. Ignores packages listed in the
239+ * "bundledPackages" setting from the api-extractor.json config file.
240+ *
241+ * @remarks
242+ * Examples:
243+ *
244+ * - NO: `./file1`
245+ * - YES: `library1`
246+ * - YES: `@my-scope/my-package`
247+ */
248+ private _isExternalModulePath ( moduleSpecifier : string ) : boolean {
249+ if ( ts . isExternalModuleNameRelative ( moduleSpecifier ) ) {
250+ return false ;
251+ }
252+
253+ // TODO: The moduleSpecifier may include a path like "@my-scope/my-package/path1/path2".
254+
255+ if ( this . _bundledPackageNames . has ( moduleSpecifier ) ) {
256+ return false ;
257+ }
258+ return true ;
259+ }
260+
234261 /**
235262 * Returns true if when we analyzed sourceFile, we found that it contains an "export=" statement that allows
236263 * it to behave /either/ as an ambient module /or/ as a regular importable module. In this case,
@@ -617,7 +644,7 @@ export class ExportAnalyzer {
617644
618645 // Match: "@microsoft/sp-lodash-subset" or "lodash/has"
619646 // but ignore: "../folder/LocalFile"
620- if ( ! ts . isExternalModuleNameRelative ( moduleSpecifier ) ) {
647+ if ( this . _isExternalModulePath ( moduleSpecifier ) ) {
621648 return moduleSpecifier ;
622649 }
623650
0 commit comments