@@ -23,6 +23,11 @@ export type Options = {
2323 * that contains the external libraries, i.e. node_modules.
2424 */
2525 includeExternalLibraries ?: boolean ;
26+ /**
27+ * Adds a property `projectName` to each entry
28+ * that contains the name of the project.
29+ */
30+ projectName ?: string ;
2631} ;
2732export type ProjectData = Record < string , ProjectDataEntry > ;
2833
@@ -78,7 +83,6 @@ function calcOrGetTags(
7883 */
7984export function getProjectData (
8085 entryFileAbsolute : string ,
81- projectName : string ,
8286 options ?: Options ,
8387) : ProjectData ;
8488/**
@@ -114,43 +118,28 @@ export function getProjectData(
114118export function getProjectData (
115119 entryFileRelative : string ,
116120 cwd : string ,
117- projectName : string ,
118121 options ?: Options ,
119122) : ProjectData ;
120123
121124export function getProjectData (
122125 entryFile : string ,
123- cwdOrProjectName : string ,
124- projectNameOrOptions ?: string | Options ,
126+ cwdOrOptions ?: string | Options ,
125127 optionalOptions ?: Options ,
126128) : ProjectData {
127129 const fs = getFs ( ) ;
128- let absoluteEntryFile : string ;
129- let cwd : string | undefined ;
130- let projectName : string ;
131- let options : Options ;
132-
133- if (
134- typeof cwdOrProjectName === 'string' &&
135- typeof projectNameOrOptions === 'string'
136- ) {
137- // Called with: (entryFile, cwd, projectName, options?)
138- absoluteEntryFile = fs . join ( entryFile ) ;
139- cwd = cwdOrProjectName ;
140- projectName = projectNameOrOptions ;
141- options = optionalOptions || { } ;
142- } else if (
143- typeof cwdOrProjectName === 'string' &&
144- typeof projectNameOrOptions === 'object'
145- ) {
146- // Called with: (entryFile, projectName, options)
147- absoluteEntryFile = entryFile ;
148- cwd = undefined ;
149- projectName = cwdOrProjectName ;
150- options = projectNameOrOptions || { } ;
151- } else {
152- throw new Error ( 'Invalid arguments to getProjectData' ) ;
153- }
130+ const absoluteEntryFile =
131+ cwdOrOptions === undefined
132+ ? entryFile
133+ : typeof cwdOrOptions === 'string'
134+ ? fs . join ( entryFile )
135+ : entryFile ;
136+
137+ const cwd = typeof cwdOrOptions === 'string' ? cwdOrOptions : undefined ;
138+ const options = optionalOptions
139+ ? optionalOptions
140+ : typeof cwdOrOptions === 'object'
141+ ? cwdOrOptions
142+ : { } ;
154143
155144 const projectInfo = init ( toFsPath ( absoluteEntryFile ) ) ;
156145
@@ -164,7 +153,7 @@ export function getProjectData(
164153 tags : calcOrGetTags ( fileInfo . moduleInfo . path , projectInfo , tagsCache ) ,
165154 imports : fileInfo . imports . map ( ( fileInfo ) => fileInfo . path ) ,
166155 unresolvedImports : fileInfo . unresolvableImports ,
167- projectName : projectName ,
156+ projectName : options . projectName ?? '' ,
168157 } ;
169158
170159 if ( options . includeExternalLibraries ) {
0 commit comments