Skip to content
This repository was archived by the owner on Mar 31, 2025. It is now read-only.
This repository was archived by the owner on Mar 31, 2025. It is now read-only.

relativePath returned by tsParser getFileInfo() is sometimes absolute #179

@mikejpeters

Description

@mikejpeters

The dgeni TypeScript package sometimes generates docs where doc.fileInfo.relativePath is an absolute path instead of relative. This also affects the doc.id, which I think is resolved from this property.

It seems that if readTypeScriptModules.sourceFiles is configured so that the TypeScript parser parses a file before it parses a second file that is imported by the first, it affects how the parser resolves the second file's fileName property, causing it to be an absolute path instead of relative. Based on this I don't think you can trust fileName to be relative at typescript/services/tsParser/getFileInfo.js#L7.

Example

Assuming basePath is /absolute/path/to/src and sourcePath includes:

  • File A: /absolute/path/to/src/a.ts (imports ./b.ts)
  • File B: /absolute/path/to/src/b.ts

If the TypeScript parser parses File A before File B, the doc for File A will have fileInfo.relativePath: "a.ts", but the doc for File B will have fileInfo.relativePath: "/absolute/path/to/src/b.ts"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions