@@ -177,14 +177,13 @@ function getStringifyOptions (
177177
178178 const referenced : ts . Map < boolean > = { }
179179 const dependencies : ts . Map < StringifyOptions > = { }
180- const entry = main == null ? main : resolveFrom ( tree . src , normalizeToDefinition ( main ) )
180+ const entry = main == null ? undefined : normalizeToDefinition ( main )
181181 const prefix = `${ parent ? parent . prefix : '' } ${ DEPENDENCY_SEPARATOR } ${ options . name } `
182182
183183 return extend ( options , {
184184 tree,
185185 entry,
186186 prefix,
187- isTypings,
188187 overrides,
189188 referenced,
190189 dependencies,
@@ -222,20 +221,9 @@ function compileDependencyPath (
222221 parentModule ?: ModuleOptions
223222) : Promise < string > {
224223 const { tree, entry } = options
224+ const dependencyPath = resolveFrom ( tree . src , path || entry || 'index.d.ts' )
225225
226- // Fallback to resolving the entry file.
227- if ( path == null ) {
228- if ( entry == null ) {
229- return Promise . reject ( new TypingsError (
230- `Unable to resolve entry ".d.ts" file for "${ options . name } ", ` +
231- 'please make sure the module has a main or typings field'
232- ) )
233- }
234-
235- return stringifyDependencyPath ( resolveFrom ( tree . src , entry ) , options , parentModule )
236- }
237-
238- return stringifyDependencyPath ( resolveFrom ( tree . src , path ) , options , parentModule )
226+ return stringifyDependencyPath ( dependencyPath , path , options , parentModule )
239227}
240228
241229/**
@@ -244,7 +232,6 @@ function compileDependencyPath (
244232interface StringifyOptions extends CompileOptions {
245233 entry : string
246234 prefix : string
247- isTypings : boolean
248235 overrides : Overrides
249236 referenced : ts . Map < boolean >
250237 dependencies : ts . Map < StringifyOptions >
@@ -321,11 +308,12 @@ interface ModuleOptions {
321308 */
322309function stringifyDependencyPath (
323310 rawPath : string ,
311+ originalPath : string ,
324312 options : StringifyOptions ,
325313 moduleOptions : ModuleOptions
326314) : Promise < string > {
327315 const path = getPath ( rawPath , options )
328- const { tree, global, cwd, resolution, name, readFiles, imported, meta, entry , emitter } = options
316+ const { tree, global, cwd, resolution, name, readFiles, imported, meta, emitter } = options
329317 const importedPath = importPath ( rawPath , pathFromDefinition ( rawPath ) , options )
330318
331319 // Return `null` to skip the dependency writing, could have the same import twice.
@@ -386,12 +374,12 @@ function stringifyDependencyPath (
386374 return loadByModuleName ( path )
387375 }
388376
389- return stringifyDependencyPath ( path , options , childModuleOptions )
377+ return stringifyDependencyPath ( path , importedFile , options , childModuleOptions )
390378 } )
391379
392380 return Promise . all ( imports )
393381 . then < string > ( imports => {
394- const stringified = stringifySourceFile ( sourceFile , options , childModuleOptions )
382+ const stringified = stringifySourceFile ( sourceFile , originalPath , options , childModuleOptions )
395383
396384 for ( const reference of referencedFiles ) {
397385 emitter . emit ( 'reference' , { name, rawPath, reference, tree, resolution } )
@@ -411,7 +399,7 @@ function stringifyDependencyPath (
411399 const relativePath = relativeTo ( tree . src , path )
412400
413401 // Provide better errors for the entry path.
414- if ( rawPath === entry ) {
402+ if ( originalPath == null ) {
415403 return Promise . reject ( new TypingsError (
416404 `Unable to read typings for "${ options . name } ". ` +
417405 `${ authorPhrase } check the entry paths in "${ basename ( tree . src ) } " are up to date` ,
@@ -475,9 +463,14 @@ function importPath (path: string, name: string, options: StringifyOptions) {
475463/**
476464 * Stringify a dependency file contents.
477465 */
478- function stringifySourceFile ( sourceFile : ts . SourceFile , options : StringifyOptions , moduleOptions : ModuleOptions ) {
479- const { isExternal, path, rawPath } = moduleOptions
480- const { tree, name, prefix, parent, isTypings, cwd, global, entry } = options
466+ function stringifySourceFile (
467+ sourceFile : ts . SourceFile ,
468+ originalPath : string ,
469+ options : StringifyOptions ,
470+ moduleOptions : ModuleOptions
471+ ) {
472+ const { isExternal, path } = moduleOptions
473+ const { tree, name, prefix, parent, cwd, global } = options
481474 const parentModule = moduleOptions . parent
482475
483476 // Output information for the original type source.
@@ -601,12 +594,12 @@ function stringifySourceFile (sourceFile: ts.SourceFile, options: StringifyOptio
601594 return declareText ( name , imports . join ( EOL ) )
602595 }
603596
604- const isEntry = rawPath === entry
597+ const isEntry = originalPath == null
605598 const moduleText = normalizeEOL ( processTree ( sourceFile , replacer , read ) , EOL )
606599 const moduleName = parent && parent . global ? name : prefix
607600
608601 // Direct usage of definition/typings. This is *not* a psuedo-module.
609- if ( isEntry && isTypings && ! hasLocalImports ) {
602+ if ( isEntry && ! hasLocalImports ) {
610603 return meta + declareText ( parent ? moduleName : name , moduleText )
611604 }
612605
0 commit comments