Skip to content

Commit

Permalink
fix: windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
GerkinDev committed Jul 19, 2022
1 parent ee4a8af commit 47bf765
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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<ICodeBlock>;
blocks: Array<[string, {code: string;startLine: number;endLine: number}]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -49,7 +49,7 @@ const matchReflection = <T extends Reflection>( proto: Class<T>, 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' ) );
Expand Down
7 changes: 4 additions & 3 deletions packages/pluginutils/src/markdown-to-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions packages/pluginutils/src/utils/reflection-source.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 47bf765

Please sign in to comment.