diff --git a/packages/plugin-code-blocks/src/output/markdown-code-blocks.spec.ts b/packages/plugin-code-blocks/src/output/markdown-code-blocks.spec.ts index 601d5fec..f63a1ece 100644 --- a/packages/plugin-code-blocks/src/output/markdown-code-blocks.spec.ts +++ b/packages/plugin-code-blocks/src/output/markdown-code-blocks.spec.ts @@ -1,7 +1,7 @@ import { resolve } from 'path'; import { noop } from 'lodash'; -import { DeclarationReflection, ReflectionKind, RepositoryType } from 'typedoc'; +import { DeclarationReflection, ReflectionKind, RepositoryType, normalizePath } from 'typedoc'; import { MockPlugin, createMockProjectWithPackage, mockPlugin, restoreFs, setVirtualFs, setupMockMarkdownReplacer, setupMockPageMemo } from '#plugintestbed'; @@ -62,7 +62,7 @@ describe( 'Behavior', () => { expect( markdownReplacerTestbed.runMarkdownReplace( text ) ).toEqual( text ); } ); describe( 'Code block generation', ()=> { - const sourceFile = resolve( rootDir, FILE ); + const sourceFile = normalizePath( resolve( rootDir, FILE ) ); interface IBlockGenerationAssertion{ renderCall: Partial; blocks: Array<[string, {code: string;startLine: number;endLine: number}]>; diff --git a/packages/plugin-pages/src/converter/page-tree/page-tree-builder.spec.ts b/packages/plugin-pages/src/converter/page-tree/page-tree-builder.spec.ts index af689b10..66e8ba73 100644 --- a/packages/plugin-pages/src/converter/page-tree/page-tree-builder.spec.ts +++ b/packages/plugin-pages/src/converter/page-tree/page-tree-builder.spec.ts @@ -2,7 +2,7 @@ import { resolve } from 'path'; import { isString, noop, omit } from 'lodash'; import { Class } from 'type-fest'; -import { Comment, DeclarationReflection, LogLevel, ProjectReflection, Reflection, ReflectionKind, SourceReference } from 'typedoc'; +import { Comment, DeclarationReflection, LogLevel, ProjectReflection, Reflection, ReflectionKind, SourceReference, normalizePath } from 'typedoc'; import { MarkdownToSummary } from '@knodes/typedoc-pluginutils'; @@ -49,7 +49,7 @@ const matchReflection = ( proto: Class, sample: Partial expect( v ).toBeInstanceOf( proto ); const s = sample as any; if( 'sourceFilePath' in s && isString( s.sourceFilePath ) ){ - s.sourceFilePath = resolve( s.sourceFilePath ); + s.sourceFilePath = normalizePath( resolve( s.sourceFilePath ) ); } const cloneValue = Object.keys( omit( sample, 'childrenNodes' ) ).reduce( ( acc, k ) => ( { ...acc, [k]: v[k] } ), {} ); expect( cloneValue ).toMatchObject( omit( sample, 'childrenNodes' ) ); diff --git a/packages/pluginutils/src/markdown-to-summary.ts b/packages/pluginutils/src/markdown-to-summary.ts index 9f0ab16a..1918cbf9 100644 --- a/packages/pluginutils/src/markdown-to-summary.ts +++ b/packages/pluginutils/src/markdown-to-summary.ts @@ -4,7 +4,7 @@ import { writeFileSync } from 'fs'; import { tmpdir } from 'os'; import { join } from 'path'; -import { Application, Context, Converter, DeclarationReflection, ProjectReflection } from 'typedoc'; +import { Application, Context, Converter, DeclarationReflection, ProjectReflection, normalizePath } from 'typedoc'; import { ApplicationAccessor, getApplication } from './base-plugin'; import { miscUtils } from './utils'; @@ -57,8 +57,9 @@ export class MarkdownToSummary { const converter = this._application.converter as any; // const converter: InstanceType<( typeof import( '../../../typedoc/src/lib/converter/converter' ).Converter )> = this._application.converter as any; - const sourceFile = this._context.programs[0].getSourceFiles().find( src => src.fileName.startsWith( miscUtils.rootDir( this._application ) ) ); - assert( sourceFile ); + const rootDir = normalizePath( miscUtils.rootDir( this._application ) ); + const sourceFile = this._context.programs[0].getSourceFiles().find( src => normalizePath( src.fileName ).startsWith( rootDir ) ); + assert( sourceFile, `Failed to lookup for a file in root dir ${rootDir}` ); // eslint-disable-next-line @typescript-eslint/dot-notation -- Access private const ret: Context = converter['convertExports']( fakeContext as any, { program: fakeContext.program, displayName: 'TEMP', sourceFile, readmeFile }, false ); assert( ret.scope instanceof DeclarationReflection ); diff --git a/packages/pluginutils/src/utils/reflection-source.ts b/packages/pluginutils/src/utils/reflection-source.ts index 3aa37c3d..313af350 100644 --- a/packages/pluginutils/src/utils/reflection-source.ts +++ b/packages/pluginutils/src/utils/reflection-source.ts @@ -1,5 +1,5 @@ import { isNumber } from 'lodash'; -import { ProjectReflection, Reflection, SourceReference } from 'typedoc'; +import { ProjectReflection, Reflection, SourceReference, normalizePath } from 'typedoc'; import { PluginAccessor, getApplication, getPlugin } from '../base-plugin'; import { getCoordinates } from './text'; @@ -40,7 +40,7 @@ export const getSourceLocationBestClue = ( reflection?: Reflection, position?: n }; export const createSourceReference = ( pluginAccessor: PluginAccessor, absoluteFilename: string, line?: number, character?: number ) => { - const source = new SourceReference( absoluteFilename, line ?? 1, character ?? 1 ); + const source = new SourceReference( normalizePath( absoluteFilename ), line ?? 1, character ?? 1 ); source.fileName = getPlugin( pluginAccessor ).relativeToRoot( absoluteFilename ); const repo = ( getApplication( pluginAccessor ).converter.getComponent( 'source' ) as any )?.getRepository( source.fullFileName ); source.url = repo?.getURL( source.fullFileName );