@@ -9,8 +9,9 @@ import type { HexString } from '@polkadot/util/types';
99
1010import { parse , type Spec } from 'comment-parser' ;
1111import fs from 'node:fs' ;
12- import path from 'node:path' ;
12+ import path , { dirname , resolve } from 'node:path' ;
1313import process from 'node:process' ;
14+ import { fileURLToPath } from 'node:url' ;
1415import yargs from 'yargs' ;
1516import { hideBin } from 'yargs/helpers' ;
1617
@@ -563,15 +564,21 @@ function addErrors (runtimeDesc: string, { lookup, pallets }: MetadataLatest): s
563564 } ) ;
564565}
565566
566- const BASE_DERIVE_PATH = '../api/packages/api-derive/src/' ;
567+ function getDependencyBasePath ( moduleName : string ) : string {
568+ const modulePath = import . meta. resolve ( moduleName ) ;
569+
570+ return resolve ( dirname ( fileURLToPath ( modulePath ) ) ) ;
571+ }
572+
573+ const BASE_DERIVE_PATH = getDependencyBasePath ( '@polkadot/api-derive' ) ;
567574
568575// It finds all typescript file paths withing a given derive module.
569576const obtainDeriveFiles = ( deriveModule : string ) => {
570- const filePath = `${ BASE_DERIVE_PATH } ${ deriveModule } ` ;
577+ const filePath = `${ BASE_DERIVE_PATH } / ${ deriveModule } ` ;
571578 const files = fs . readdirSync ( filePath ) ;
572579
573580 return files
574- . filter ( ( file ) => file . endsWith ( '.ts' ) && ! file . endsWith ( '.d.ts ') )
581+ . filter ( ( file ) => file . endsWith ( '.js ' ) )
575582 . map ( ( file ) => `${ deriveModule } /${ file } ` ) ;
576583} ;
577584
@@ -639,7 +646,7 @@ const getDeriveDocs = (
639646 metadata : Record < string , Derive [ ] > ,
640647 file : string
641648) => {
642- const filePath = `${ BASE_DERIVE_PATH } ${ file } ` ;
649+ const filePath = `${ BASE_DERIVE_PATH } / ${ file } ` ;
643650 const deriveModule = file . split ( '/' ) [ 0 ] ;
644651 const fileContent = fs . readFileSync ( filePath , 'utf8' ) ;
645652 const comments = parse ( fileContent ) ;
0 commit comments