Skip to content

Commit 9db7d8d

Browse files
Fix derives base path in typegen (#6107)
* Make derive base path point to the dependency instead of the local file * use node:path * lint * lint
1 parent a1c43fe commit 9db7d8d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/typegen/src/metadataMd.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import type { HexString } from '@polkadot/util/types';
99

1010
import { parse, type Spec } from 'comment-parser';
1111
import fs from 'node:fs';
12-
import path from 'node:path';
12+
import path, { dirname, resolve } from 'node:path';
1313
import process from 'node:process';
14+
import { fileURLToPath } from 'node:url';
1415
import yargs from 'yargs';
1516
import { 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.
569576
const 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

Comments
 (0)