typedoc-plugin-resolve-crossmodule-references
Advanced tools
Comparing version 0.1.1 to 0.2.0
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.load = void 0; | ||
const convert_source_map_1 = require("convert-source-map"); | ||
const path_1 = __importDefault(require("path")); | ||
const typedoc_1 = require("typedoc"); | ||
@@ -91,37 +86,10 @@ function load(app) { | ||
return type; | ||
return getSourcesReferenceType(type, context.project) ?? type; | ||
return findReferenceType(type, context.project) ?? type; | ||
} | ||
function getSourcesReferenceType(type, project) { | ||
const srcFile = findSymbolSourceFile(type.getSymbol(), project); | ||
if (!srcFile) | ||
return null; | ||
const newTargetReflection = srcFile.reflections.find(({ name }) => name === type.name); | ||
function findReferenceType(type, project) { | ||
const newTargetReflection = project.getReflectionsByKind(typedoc_1.ReflectionKind.All).find(({ name }) => name === type.name); | ||
if (!newTargetReflection) | ||
return null; | ||
const newTargetSymbol = project.getSymbolFromReflection(newTargetReflection); | ||
if (!newTargetSymbol) | ||
return null; | ||
return new typedoc_1.ReferenceType(type.name, newTargetSymbol, project); | ||
return typedoc_1.ReferenceType.createResolvedReference(type.name, newTargetReflection, project); | ||
} | ||
function findSymbolSourceFile(symbol, project) { | ||
const declarations = symbol.getDeclarations(); | ||
if (!declarations) | ||
return undefined; | ||
for (const declaration of declarations) { | ||
const declSrcFile = declaration.getSourceFile(); | ||
const srcDirPath = path_1.default.dirname(declSrcFile.fileName); | ||
const srcMapConverter = (0, convert_source_map_1.fromSource)(declSrcFile.text) ?? (0, convert_source_map_1.fromMapFileSource)(declSrcFile.text, srcDirPath); | ||
if (!srcMapConverter) | ||
continue; | ||
const sources = srcMapConverter.toObject().sources; | ||
for (const source of sources) { | ||
const srcFileName = path_1.default.resolve(srcDirPath, source); | ||
const srcFile = project.files.find(({ fullFileName }) => fullFileName === srcFileName); | ||
if (!srcFile) | ||
continue; | ||
return srcFile; | ||
} | ||
} | ||
return undefined; | ||
} | ||
function isReferenceType(type) { | ||
@@ -128,0 +96,0 @@ return type?.type === 'reference'; |
{ | ||
"name": "typedoc-plugin-resolve-crossmodule-references", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "TypeDoc plugin for resolving cross module reference in a mono-repository", | ||
@@ -15,2 +15,5 @@ "main": "dist", | ||
], | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"files": [ | ||
@@ -24,20 +27,17 @@ "dist" | ||
"peerDependencies": { | ||
"typedoc": "*" | ||
"typedoc": ">=0.22 <=0.23" | ||
}, | ||
"dependencies": { | ||
"convert-source-map": "^1.8.0" | ||
}, | ||
"devDependencies": { | ||
"@ava/typescript": "^3.0.1", | ||
"@tsconfig/node14": "^1.0.1", | ||
"@types/convert-source-map": "^1.5.2", | ||
"@types/node": "^17.0.8", | ||
"ava": "^4.0.1", | ||
"prettier": "^2.5.1", | ||
"ts-node": "^10.4.0", | ||
"@tsconfig/node16": "^1.0.3", | ||
"@types/node": "^18.0.6", | ||
"ava": "^4.3.1", | ||
"prettier": "^2.7.1", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^10.9.1", | ||
"tslint": "^6.1.3", | ||
"tslint-config-prettier": "^1.18.0", | ||
"tslint-plugin-prettier": "^2.3.0", | ||
"typedoc": "^0.22.10", | ||
"typescript": "^4.5.4" | ||
"typedoc": "^0.23.8", | ||
"typescript": "^4.7.4" | ||
}, | ||
@@ -47,7 +47,7 @@ "scripts": { | ||
"ci": "yarn build && yarn lint && yarn test", | ||
"clean": "rm -rf dist", | ||
"clean": "rimraf dist", | ||
"lint": "tslint -p .", | ||
"test": "yarn test:clean && yarn test:build && yarn test:generate && ava", | ||
"test:build": "yarn workspaces foreach -t --from '{@typedoc-plugin-resolve-crossmodule-references/a,@typedoc-plugin-resolve-crossmodule-references/b}' run build", | ||
"test:clean": "rm -rf test/docs.json test/packages/a/dist test/packages/b/dist", | ||
"test:clean": "rimraf test/docs.json test/packages/a/dist test/packages/b/dist", | ||
"test:generate": "cd test && yarn typedoc" | ||
@@ -54,0 +54,0 @@ }, |
1
17060
105
+ Addedansi-sequence-parser@1.1.1(transitive)
+ Addedjsonc-parser@3.3.1(transitive)
+ Addedmarked@4.3.0(transitive)
+ Addedminimatch@7.4.6(transitive)
+ Addedshiki@0.14.7(transitive)
+ Addedtypedoc@0.23.28(transitive)
+ Addedtypescript@5.0.4(transitive)
+ Addedvscode-oniguruma@1.7.0(transitive)
+ Addedvscode-textmate@8.0.0(transitive)
- Removedconvert-source-map@^1.8.0
- Removed@gerrit0/mini-shiki@1.27.2(transitive)
- Removed@shikijs/engine-oniguruma@1.27.2(transitive)
- Removed@shikijs/types@1.27.2(transitive)
- Removed@shikijs/vscode-textmate@10.0.1(transitive)
- Removed@types/hast@3.0.4(transitive)
- Removed@types/unist@3.0.3(transitive)
- Removedargparse@2.0.1(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedentities@4.5.0(transitive)
- Removedlinkify-it@5.0.0(transitive)
- Removedmarkdown-it@14.1.0(transitive)
- Removedmdurl@2.0.0(transitive)
- Removedminimatch@9.0.5(transitive)
- Removedpunycode.js@2.3.1(transitive)
- Removedtypedoc@0.27.6(transitive)
- Removedtypescript@5.7.3(transitive)
- Removeduc.micro@2.1.0(transitive)
- Removedyaml@2.7.0(transitive)