Comparing version 0.25.2 to 0.25.3
@@ -99,2 +99,3 @@ "use strict"; | ||
const abstract_1 = require("./models/reflections/abstract"); | ||
const ReflectionSymbolId_1 = require("./models/reflections/ReflectionSymbolId"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -455,5 +456,6 @@ const packageInfo = require("../../package.json"); | ||
const projects = []; | ||
const projectsToConvert = []; | ||
// Generate a json file for each package | ||
for (const dir of packageDirs) { | ||
this.logger.info(`Converting project at ${(0, paths_1.nicePath)(dir)}`); | ||
this.logger.verbose(`Reading project at ${(0, paths_1.nicePath)(dir)}`); | ||
const opts = origOptions.copyForPackage(dir); | ||
@@ -468,3 +470,8 @@ await opts.read(this.logger, dir); | ||
} | ||
this.options = opts; | ||
(0, ReflectionSymbolId_1.addInferredDeclarationMapPaths)(opts.getCompilerOptions(), opts.getFileNames()); | ||
projectsToConvert.push({ dir, options: opts }); | ||
} | ||
for (const { dir, options } of projectsToConvert) { | ||
this.logger.info(`Converting project at ${(0, paths_1.nicePath)(dir)}`); | ||
this.options = options; | ||
const project = await this.convert(); | ||
@@ -471,0 +478,0 @@ if (project) { |
@@ -24,2 +24,3 @@ "use strict"; | ||
const index = new models_1.SignatureReflection("__index", models_1.ReflectionKind.IndexSignature, context.scope); | ||
index.comment = context.getComment(indexSymbol, index.kind); | ||
index.parameters = [ | ||
@@ -26,0 +27,0 @@ new models_1.ParameterReflection(param.name.getText(), models_1.ReflectionKind.Parameter, index), |
@@ -575,3 +575,6 @@ "use strict"; | ||
const parentSymbol = context.project.getSymbolFromReflection(context.scope); | ||
(0, assert_1.default)(parentSymbol, `No parent symbol found for ${symbol.name} in ${context.scope.name}`); | ||
// It'd be nice to be able to assert that this is true, but sometimes object | ||
// types don't get symbols if they are inferred. | ||
if (!parentSymbol) | ||
return false; | ||
const parents = parentSymbol.declarations?.slice() || []; | ||
@@ -578,0 +581,0 @@ const constructorDecls = parents.flatMap((parent) => typescript_1.default.isClassDeclaration(parent) |
@@ -167,9 +167,10 @@ "use strict"; | ||
convertType(context, type) { | ||
if (!type.symbol) { | ||
const symbol = type.getSymbol(); | ||
if (!symbol) { | ||
return new models_1.IntrinsicType("Function"); | ||
} | ||
const reflection = new models_1.DeclarationReflection("__type", models_1.ReflectionKind.Constructor, context.scope); | ||
context.registerReflection(reflection, type.symbol); | ||
context.registerReflection(reflection, symbol); | ||
context.trigger(converter_events_1.ConverterEvents.CREATE_DECLARATION, reflection); | ||
(0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, type.getConstructSignatures()[0], type.symbol); | ||
(0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, type.getConstructSignatures()[0], symbol); | ||
return new models_1.ReflectionType(reflection); | ||
@@ -216,7 +217,8 @@ }, | ||
convertType(context, type) { | ||
if (!type.symbol) { | ||
const symbol = type.getSymbol(); | ||
if (!symbol) { | ||
return new models_1.IntrinsicType("Function"); | ||
} | ||
const reflection = new models_1.DeclarationReflection("__type", models_1.ReflectionKind.TypeLiteral, context.scope); | ||
context.registerReflection(reflection, type.symbol); | ||
context.registerReflection(reflection, symbol); | ||
context.trigger(converter_events_1.ConverterEvents.CREATE_DECLARATION, reflection); | ||
@@ -256,3 +258,3 @@ (0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.CallSignature, type.getCallSignatures()[0], type.getSymbol()); | ||
convertType(context, type) { | ||
return new models_1.InferredType(type.symbol.name, maybeConvertType(context, type.getConstraint())); | ||
return new models_1.InferredType(type.getSymbol().name, maybeConvertType(context, type.getConstraint())); | ||
}, | ||
@@ -378,7 +380,5 @@ }; | ||
convertType(context, type) { | ||
if (!type.symbol) { | ||
return new models_1.IntrinsicType("Object"); | ||
} | ||
const symbol = type.getSymbol(); | ||
const reflection = new models_1.DeclarationReflection("__type", models_1.ReflectionKind.TypeLiteral, context.scope); | ||
context.registerReflection(reflection, type.symbol); | ||
context.registerReflection(reflection, symbol); | ||
context.trigger(converter_events_1.ConverterEvents.CREATE_DECLARATION, reflection); | ||
@@ -389,8 +389,10 @@ for (const prop of context.checker.getPropertiesOfType(type)) { | ||
for (const signature of type.getCallSignatures()) { | ||
(0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.CallSignature, signature, type.symbol); | ||
(0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.CallSignature, signature, symbol); | ||
} | ||
for (const signature of type.getConstructSignatures()) { | ||
(0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, signature, type.symbol); | ||
(0, signature_1.createSignature)(context.withScope(reflection), models_1.ReflectionKind.ConstructorSignature, signature, symbol); | ||
} | ||
(0, index_signature_1.convertIndexSignature)(context.withScope(reflection), type.symbol); | ||
if (symbol) { | ||
(0, index_signature_1.convertIndexSignature)(context.withScope(reflection), symbol); | ||
} | ||
return new models_1.ReflectionType(reflection); | ||
@@ -397,0 +399,0 @@ }, |
"use strict"; | ||
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { | ||
var useValue = arguments.length > 2; | ||
for (var i = 0; i < initializers.length; i++) { | ||
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); | ||
} | ||
return useValue ? value : void 0; | ||
}; | ||
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { | ||
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } | ||
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; | ||
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; | ||
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); | ||
var _, done = false; | ||
for (var i = decorators.length - 1; i >= 0; i--) { | ||
var context = {}; | ||
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; | ||
for (var p in contextIn.access) context.access[p] = contextIn.access[p]; | ||
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; | ||
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); | ||
if (kind === "accessor") { | ||
if (result === void 0) continue; | ||
if (result === null || typeof result !== "object") throw new TypeError("Object expected"); | ||
if (_ = accept(result.get)) descriptor.get = _; | ||
if (_ = accept(result.set)) descriptor.set = _; | ||
if (_ = accept(result.init)) initializers.unshift(_); | ||
} | ||
else if (_ = accept(result)) { | ||
if (kind === "field") initializers.unshift(_); | ||
else descriptor[key] = _; | ||
} | ||
} | ||
if (target) Object.defineProperty(target, contextIn.name, descriptor); | ||
done = true; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,2 +42,3 @@ exports.Reflection = exports.TraverseProperty = exports.ReflectionFlags = exports.ReflectionFlag = exports.resetReflectionID = void 0; | ||
const kind_1 = require("./kind"); | ||
const general_1 = require("../../utils/general"); | ||
/** | ||
@@ -211,212 +246,234 @@ * Current reflection id. | ||
*/ | ||
class Reflection { | ||
get project() { | ||
if (this.isProject()) | ||
return this; | ||
(0, assert_1.ok)(this.parent, "Tried to get the project on a reflection not in a project"); | ||
return this.parent.project; | ||
} | ||
constructor(name, kind, parent) { | ||
this.flags = new ReflectionFlags(); | ||
this.id = REFLECTION_ID++; | ||
this.parent = parent; | ||
this.name = name; | ||
this.kind = kind; | ||
// If our parent is external, we are too. | ||
if (parent?.flags.isExternal) { | ||
this.setFlag(ReflectionFlag.External); | ||
} | ||
} | ||
/** | ||
* Test whether this reflection is of the given kind. | ||
*/ | ||
kindOf(kind) { | ||
const kindArray = Array.isArray(kind) ? kind : [kind]; | ||
return kindArray.some((kind) => (this.kind & kind) !== 0); | ||
} | ||
/** | ||
* Return the full name of this reflection. Intended for use in debugging. For log messages | ||
* intended to be displayed to the user for them to fix, prefer {@link getFriendlyFullName} instead. | ||
* | ||
* The full name contains the name of this reflection and the names of all parent reflections. | ||
* | ||
* @param separator Separator used to join the names of the reflections. | ||
* @returns The full name of this reflection. | ||
*/ | ||
getFullName(separator = ".") { | ||
if (this.parent && !this.parent.isProject()) { | ||
return this.parent.getFullName(separator) + separator + this.name; | ||
} | ||
else { | ||
return this.name; | ||
} | ||
} | ||
/** | ||
* Return the full name of this reflection, with signature names dropped if possible without | ||
* introducing ambiguity in the name. | ||
*/ | ||
getFriendlyFullName() { | ||
if (this.parent && !this.parent.isProject()) { | ||
if (this.kindOf(kind_1.ReflectionKind.ConstructorSignature | | ||
kind_1.ReflectionKind.CallSignature | | ||
kind_1.ReflectionKind.GetSignature | | ||
kind_1.ReflectionKind.SetSignature)) { | ||
return this.parent.getFriendlyFullName(); | ||
let Reflection = (() => { | ||
var _a; | ||
let _instanceExtraInitializers = []; | ||
let _parent_decorators; | ||
let _parent_initializers = []; | ||
return _a = class Reflection { | ||
get project() { | ||
if (this.isProject()) | ||
return this; | ||
(0, assert_1.ok)(this.parent, "Tried to get the project on a reflection not in a project"); | ||
return this.parent.project; | ||
} | ||
return this.parent.getFriendlyFullName() + "." + this.name; | ||
} | ||
else { | ||
return this.name; | ||
} | ||
} | ||
/** | ||
* Set a flag on this reflection. | ||
*/ | ||
setFlag(flag, value = true) { | ||
this.flags.setFlag(flag, value); | ||
} | ||
/** | ||
* Return an url safe alias for this reflection. | ||
*/ | ||
getAlias() { | ||
if (!this._alias) { | ||
let alias = this.name.replace(/\W/g, "_"); | ||
if (alias === "") { | ||
alias = "reflection-" + this.id; | ||
constructor(name, kind, parent) { | ||
/** | ||
* Unique id of this reflection. | ||
*/ | ||
this.id = (__runInitializers(this, _instanceExtraInitializers), void 0); | ||
this.flags = new ReflectionFlags(); | ||
/** | ||
* The reflection this reflection is a child of. | ||
*/ | ||
this.parent = __runInitializers(this, _parent_initializers, void 0); | ||
this.id = REFLECTION_ID++; | ||
this.parent = parent; | ||
this.name = name; | ||
this.kind = kind; | ||
// If our parent is external, we are too. | ||
if (parent?.flags.isExternal) { | ||
this.setFlag(ReflectionFlag.External); | ||
} | ||
} | ||
// NTFS/ExFAT use uppercase, so we will too. It probably won't matter | ||
// in this case since names will generally be valid identifiers, but to be safe... | ||
const upperAlias = alias.toUpperCase(); | ||
let target = this; | ||
while (target.parent && !target.hasOwnDocument) { | ||
target = target.parent; | ||
/** | ||
* Test whether this reflection is of the given kind. | ||
*/ | ||
kindOf(kind) { | ||
const kindArray = Array.isArray(kind) ? kind : [kind]; | ||
return kindArray.some((kind) => (this.kind & kind) !== 0); | ||
} | ||
target._aliases ||= new Map(); | ||
let suffix = ""; | ||
if (!target._aliases.has(upperAlias)) { | ||
target._aliases.set(upperAlias, 1); | ||
/** | ||
* Return the full name of this reflection. Intended for use in debugging. For log messages | ||
* intended to be displayed to the user for them to fix, prefer {@link getFriendlyFullName} instead. | ||
* | ||
* The full name contains the name of this reflection and the names of all parent reflections. | ||
* | ||
* @param separator Separator used to join the names of the reflections. | ||
* @returns The full name of this reflection. | ||
*/ | ||
getFullName(separator = ".") { | ||
if (this.parent && !this.parent.isProject()) { | ||
return this.parent.getFullName(separator) + separator + this.name; | ||
} | ||
else { | ||
return this.name; | ||
} | ||
} | ||
else { | ||
const count = target._aliases.get(upperAlias); | ||
suffix = "-" + count.toString(); | ||
target._aliases.set(upperAlias, count + 1); | ||
} | ||
alias += suffix; | ||
this._alias = alias; | ||
} | ||
return this._alias; | ||
} | ||
/** | ||
* Has this reflection a visible comment? | ||
* | ||
* @returns TRUE when this reflection has a visible comment. | ||
*/ | ||
hasComment() { | ||
return this.comment ? this.comment.hasVisibleComponent() : false; | ||
} | ||
hasGetterOrSetter() { | ||
return false; | ||
} | ||
/** | ||
* Return a child by its name. | ||
* | ||
* @param names The name hierarchy of the child to look for. | ||
* @returns The found child or undefined. | ||
*/ | ||
getChildByName(arg) { | ||
const names = Array.isArray(arg) | ||
? arg | ||
: (0, utils_1.splitUnquotedString)(arg, "."); | ||
const name = names[0]; | ||
let result; | ||
this.traverse((child) => { | ||
if (child.name === name) { | ||
if (names.length <= 1) { | ||
result = child; | ||
/** | ||
* Return the full name of this reflection, with signature names dropped if possible without | ||
* introducing ambiguity in the name. | ||
*/ | ||
getFriendlyFullName() { | ||
if (this.parent && !this.parent.isProject()) { | ||
if (this.kindOf(kind_1.ReflectionKind.ConstructorSignature | | ||
kind_1.ReflectionKind.CallSignature | | ||
kind_1.ReflectionKind.GetSignature | | ||
kind_1.ReflectionKind.SetSignature)) { | ||
return this.parent.getFriendlyFullName(); | ||
} | ||
return this.parent.getFriendlyFullName() + "." + this.name; | ||
} | ||
else { | ||
result = child.getChildByName(names.slice(1)); | ||
return this.name; | ||
} | ||
} | ||
/** | ||
* Set a flag on this reflection. | ||
*/ | ||
setFlag(flag, value = true) { | ||
this.flags.setFlag(flag, value); | ||
} | ||
/** | ||
* Return an url safe alias for this reflection. | ||
*/ | ||
getAlias() { | ||
if (!this._alias) { | ||
let alias = this.name.replace(/\W/g, "_"); | ||
if (alias === "") { | ||
alias = "reflection-" + this.id; | ||
} | ||
// NTFS/ExFAT use uppercase, so we will too. It probably won't matter | ||
// in this case since names will generally be valid identifiers, but to be safe... | ||
const upperAlias = alias.toUpperCase(); | ||
let target = this; | ||
while (target.parent && !target.hasOwnDocument) { | ||
target = target.parent; | ||
} | ||
target._aliases ||= new Map(); | ||
let suffix = ""; | ||
if (!target._aliases.has(upperAlias)) { | ||
target._aliases.set(upperAlias, 1); | ||
} | ||
else { | ||
const count = target._aliases.get(upperAlias); | ||
suffix = "-" + count.toString(); | ||
target._aliases.set(upperAlias, count + 1); | ||
} | ||
alias += suffix; | ||
this._alias = alias; | ||
} | ||
return this._alias; | ||
} | ||
/** | ||
* Has this reflection a visible comment? | ||
* | ||
* @returns TRUE when this reflection has a visible comment. | ||
*/ | ||
hasComment() { | ||
return this.comment ? this.comment.hasVisibleComponent() : false; | ||
} | ||
hasGetterOrSetter() { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
return result; | ||
} | ||
/** | ||
* Return whether this reflection is the root / project reflection. | ||
*/ | ||
isProject() { | ||
return false; | ||
} | ||
isDeclaration() { | ||
return false; | ||
} | ||
/** | ||
* Check if this reflection or any of its parents have been marked with the `@deprecated` tag. | ||
*/ | ||
isDeprecated() { | ||
let signaturesDeprecated = false; | ||
this.visit({ | ||
declaration(decl) { | ||
if (decl.signatures && | ||
decl.signatures.every((sig) => sig.comment?.getTag("@deprecated"))) { | ||
signaturesDeprecated = true; | ||
/** | ||
* Return a child by its name. | ||
* | ||
* @param names The name hierarchy of the child to look for. | ||
* @returns The found child or undefined. | ||
*/ | ||
getChildByName(arg) { | ||
const names = Array.isArray(arg) | ||
? arg | ||
: (0, utils_1.splitUnquotedString)(arg, "."); | ||
const name = names[0]; | ||
let result; | ||
this.traverse((child) => { | ||
if (child.name === name) { | ||
if (names.length <= 1) { | ||
result = child; | ||
} | ||
else { | ||
result = child.getChildByName(names.slice(1)); | ||
} | ||
return false; | ||
} | ||
return true; | ||
}); | ||
return result; | ||
} | ||
/** | ||
* Return whether this reflection is the root / project reflection. | ||
*/ | ||
isProject() { | ||
return false; | ||
} | ||
isDeclaration() { | ||
return false; | ||
} | ||
/** | ||
* Check if this reflection or any of its parents have been marked with the `@deprecated` tag. | ||
*/ | ||
isDeprecated() { | ||
let signaturesDeprecated = false; | ||
this.visit({ | ||
declaration(decl) { | ||
if (decl.signatures && | ||
decl.signatures.every((sig) => sig.comment?.getTag("@deprecated"))) { | ||
signaturesDeprecated = true; | ||
} | ||
}, | ||
}); | ||
if (signaturesDeprecated || this.comment?.getTag("@deprecated")) { | ||
return true; | ||
} | ||
}, | ||
}); | ||
if (signaturesDeprecated || this.comment?.getTag("@deprecated")) { | ||
return true; | ||
} | ||
return this.parent?.isDeprecated() ?? false; | ||
} | ||
visit(visitor) { | ||
visitor[this.variant]?.(this); | ||
} | ||
/** | ||
* Return a string representation of this reflection. | ||
*/ | ||
toString() { | ||
return kind_1.ReflectionKind[this.kind] + " " + this.name; | ||
} | ||
/** | ||
* Return a string representation of this reflection and all of its children. | ||
* | ||
* @param indent Used internally to indent child reflections. | ||
*/ | ||
toStringHierarchy(indent = "") { | ||
const lines = [indent + this.toString()]; | ||
indent += " "; | ||
this.traverse((child) => { | ||
lines.push(child.toStringHierarchy(indent)); | ||
return true; | ||
}); | ||
return lines.join("\n"); | ||
} | ||
toObject(serializer) { | ||
return { | ||
id: this.id, | ||
name: this.name, | ||
variant: this.variant, | ||
kind: this.kind, | ||
flags: this.flags.toObject(), | ||
comment: this.comment && !this.comment.isEmpty() | ||
? serializer.toObject(this.comment) | ||
: undefined, | ||
}; | ||
} | ||
fromObject(de, obj) { | ||
// DO NOT copy id from obj. When deserializing reflections | ||
// they should be given new ids since they belong to a different project. | ||
this.name = obj.name; | ||
// Skip copying variant, we know it's already the correct value because the deserializer | ||
// will construct the correct class type. | ||
this.kind = obj.kind; | ||
this.flags.fromObject(obj.flags); | ||
// Parent is set during construction, so we don't need to do it here. | ||
this.comment = de.revive(obj.comment, () => new comment_1.Comment()); | ||
// url, anchor, hasOwnDocument, _alias, _aliases are set during rendering and only relevant during render. | ||
// It doesn't make sense to serialize them to json, or restore them. | ||
} | ||
} | ||
return this.parent?.isDeprecated() ?? false; | ||
} | ||
visit(visitor) { | ||
visitor[this.variant]?.(this); | ||
} | ||
/** | ||
* Return a string representation of this reflection. | ||
*/ | ||
toString() { | ||
return kind_1.ReflectionKind[this.kind] + " " + this.name; | ||
} | ||
/** | ||
* Return a string representation of this reflection and all of its children. | ||
* | ||
* @param indent Used internally to indent child reflections. | ||
*/ | ||
toStringHierarchy(indent = "") { | ||
const lines = [indent + this.toString()]; | ||
indent += " "; | ||
this.traverse((child) => { | ||
lines.push(child.toStringHierarchy(indent)); | ||
return true; | ||
}); | ||
return lines.join("\n"); | ||
} | ||
toObject(serializer) { | ||
return { | ||
id: this.id, | ||
name: this.name, | ||
variant: this.variant, | ||
kind: this.kind, | ||
flags: this.flags.toObject(), | ||
comment: this.comment && !this.comment.isEmpty() | ||
? serializer.toObject(this.comment) | ||
: undefined, | ||
}; | ||
} | ||
fromObject(de, obj) { | ||
// DO NOT copy id from obj. When deserializing reflections | ||
// they should be given new ids since they belong to a different project. | ||
this.name = obj.name; | ||
// Skip copying variant, we know it's already the correct value because the deserializer | ||
// will construct the correct class type. | ||
this.kind = obj.kind; | ||
this.flags.fromObject(obj.flags); | ||
// Parent is set during construction, so we don't need to do it here. | ||
this.comment = de.revive(obj.comment, () => new comment_1.Comment()); | ||
// url, anchor, hasOwnDocument, _alias, _aliases are set during rendering and only relevant during render. | ||
// It doesn't make sense to serialize them to json, or restore them. | ||
} | ||
}, | ||
(() => { | ||
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; | ||
_parent_decorators = [general_1.NonEnumerable // So that it doesn't show up in console.log | ||
]; | ||
__esDecorate(null, null, _parent_decorators, { kind: "field", name: "parent", static: false, private: false, access: { has: obj => "parent" in obj, get: obj => obj.parent, set: (obj, value) => { obj.parent = value; } }, metadata: _metadata }, _parent_initializers, _instanceExtraInitializers); | ||
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); | ||
})(), | ||
_a; | ||
})(); | ||
exports.Reflection = Reflection; |
@@ -30,1 +30,2 @@ import ts from "typescript"; | ||
} | ||
export declare function addInferredDeclarationMapPaths(opts: ts.CompilerOptions, files: readonly string[]): void; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ReflectionSymbolId = void 0; | ||
exports.addInferredDeclarationMapPaths = exports.ReflectionSymbolId = void 0; | ||
const fs_1 = require("fs"); | ||
@@ -24,3 +24,3 @@ const path_1 = require("path"); | ||
declaration ??= symbol?.declarations?.[0]; | ||
this.fileName = (0, paths_1.normalizePath)(declaration?.getSourceFile().fileName ?? "\0"); | ||
this.fileName = (0, paths_1.normalizePath)(declaration?.getSourceFile().fileName ?? ""); | ||
if (symbol.declarations?.some(typescript_1.default.isSourceFile)) { | ||
@@ -49,6 +49,7 @@ this.qualifiedName = ""; | ||
toObject(serializer) { | ||
const sourceFileName = (0, path_1.isAbsolute)(this.fileName) | ||
? (0, paths_1.normalizePath)((0, path_1.relative)(serializer.projectRoot, resolveDeclarationMaps(this.fileName))) | ||
: this.fileName; | ||
return { | ||
sourceFileName: (0, path_1.isAbsolute)(this.fileName) | ||
? (0, paths_1.normalizePath)((0, path_1.relative)(serializer.projectRoot, resolveDeclarationMaps(this.fileName))) | ||
: this.fileName, | ||
sourceFileName, | ||
qualifiedName: this.qualifiedName, | ||
@@ -60,7 +61,4 @@ }; | ||
const declarationMapCache = new Map(); | ||
/** | ||
* See also getTsSourceFromJsSource in package-manifest.ts. | ||
*/ | ||
function resolveDeclarationMaps(file) { | ||
if (!file.endsWith(".d.ts")) | ||
if (!/\.d\.[cm]?ts$/.test(file)) | ||
return file; | ||
@@ -100,1 +98,10 @@ if (declarationMapCache.has(file)) | ||
} | ||
function addInferredDeclarationMapPaths(opts, files) { | ||
const rootDir = opts.rootDir || (0, fs_2.getCommonDirectory)(files); | ||
const declDir = opts.declarationDir || opts.outDir || rootDir; | ||
for (const file of files) { | ||
const mapFile = (0, path_1.resolve)(declDir, (0, path_1.relative)(rootDir, file)).replace(/\.([cm]?[tj]s)x?$/, ".d.$1"); | ||
declarationMapCache.set(mapFile, file); | ||
} | ||
} | ||
exports.addInferredDeclarationMapPaths = addInferredDeclarationMapPaths; |
@@ -11,4 +11,4 @@ "use strict"; | ||
"Generated using ", | ||
utils_1.JSX.createElement("a", { href: "https://typedoc.org/", rel: "noopener", target: "_blank" }, "TypeDoc")))); | ||
utils_1.JSX.createElement("a", { href: "https://typedoc.org/", target: "_blank" }, "TypeDoc")))); | ||
} | ||
exports.footer = footer; |
@@ -5,2 +5,25 @@ "use strict"; | ||
const utils_1 = require("../../../../utils"); | ||
function sourceLink(context, item) { | ||
if (!item.url) { | ||
return (utils_1.JSX.createElement("li", null, | ||
"Defined in ", | ||
item.fileName, | ||
":", | ||
item.line)); | ||
} | ||
if (context.options.getValue("sourceLinkExternal")) { | ||
return (utils_1.JSX.createElement("li", null, | ||
"Defined in ", | ||
utils_1.JSX.createElement("a", { href: item.url, class: "external", target: "_blank" }, | ||
item.fileName, | ||
":", | ||
item.line))); | ||
} | ||
return (utils_1.JSX.createElement("li", null, | ||
"Defined in ", | ||
utils_1.JSX.createElement("a", { href: item.url }, | ||
item.fileName, | ||
":", | ||
item.line))); | ||
} | ||
const memberSources = (context, props) => { | ||
@@ -23,13 +46,4 @@ const sources = []; | ||
} | ||
if (props.sources) { | ||
sources.push(utils_1.JSX.createElement("ul", null, props.sources.map((item) => item.url ? (utils_1.JSX.createElement("li", null, | ||
"Defined in ", | ||
utils_1.JSX.createElement("a", { href: item.url }, | ||
item.fileName, | ||
":", | ||
item.line))) : (utils_1.JSX.createElement("li", null, | ||
"Defined in ", | ||
item.fileName, | ||
":", | ||
item.line))))); | ||
if (props.sources?.length) { | ||
sources.push(utils_1.JSX.createElement("ul", null, props.sources.map((item) => sourceLink(context, item)))); | ||
} | ||
@@ -36,0 +50,0 @@ if (sources.length === 0) { |
@@ -206,14 +206,11 @@ "use strict"; | ||
if (this.includeSource) { | ||
if (fs.existsSync(this.includeSource) && | ||
fs.statSync(this.includeSource).isDirectory()) { | ||
if (fs.existsSync(this.includeSource) && fs.statSync(this.includeSource).isDirectory()) { | ||
this.includes = this.includeSource; | ||
} | ||
else { | ||
this.application.logger.warn("Could not find provided includes directory: " + | ||
this.includeSource); | ||
this.application.logger.warn("Could not find provided includes directory: " + this.includeSource); | ||
} | ||
} | ||
if (this.mediaSource) { | ||
if (fs.existsSync(this.mediaSource) && | ||
fs.statSync(this.mediaSource).isDirectory()) { | ||
if (fs.existsSync(this.mediaSource) && fs.statSync(this.mediaSource).isDirectory()) { | ||
this.mediaDirectory = Path.join(event.outputDirectory, "media"); | ||
@@ -224,4 +221,3 @@ (0, utils_1.copySync)(this.mediaSource, this.mediaDirectory); | ||
this.mediaDirectory = undefined; | ||
this.application.logger.warn("Could not find provided media directory: " + | ||
this.mediaSource); | ||
this.application.logger.warn("Could not find provided media directory: " + this.mediaSource); | ||
} | ||
@@ -241,2 +237,8 @@ } | ||
markedOptions.renderer = new Marked.Renderer(); | ||
markedOptions.renderer.link = (href, title, text) => { | ||
// Prefix the #anchor links `#md:`. | ||
const target = href?.replace(/^#(?:md:)?(.+)/, "#md:$1") || undefined; | ||
return (0, utils_1.renderElement)(utils_1.JSX.createElement("a", { href: target, title: title || undefined }, | ||
utils_1.JSX.createElement(utils_1.JSX.Raw, { html: text }))); | ||
}; | ||
markedOptions.renderer.heading = (text, level, _, slugger) => { | ||
@@ -250,3 +252,8 @@ const slug = slugger.slug(text); | ||
}); | ||
return `<a id="md:${slug}" class="tsd-anchor"></a><h${level}><a href="#md:${slug}">${text}</a></h${level}>`; | ||
const H = `h${level}`; | ||
return (0, utils_1.renderElement)(utils_1.JSX.createElement(utils_1.JSX.Fragment, null, | ||
utils_1.JSX.createElement("a", { id: `md:${slug}`, class: "tsd-anchor" }), | ||
utils_1.JSX.createElement(H, null, | ||
utils_1.JSX.createElement("a", { href: `#md:${slug}` }, | ||
utils_1.JSX.createElement(utils_1.JSX.Raw, { html: text }))))); | ||
}; | ||
@@ -253,0 +260,0 @@ markedOptions.renderer.code = renderCode; |
@@ -41,4 +41,5 @@ /** | ||
export declare function assertNever(x: never): never; | ||
export declare function NonEnumerable(_cls: unknown, context: ClassFieldDecoratorContext): void; | ||
export declare function hasBeenLoadedMultipleTimes(): boolean; | ||
export declare function getLoadedPaths(): string[]; | ||
export {}; |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getLoadedPaths = exports.hasBeenLoadedMultipleTimes = exports.assertNever = void 0; | ||
exports.getLoadedPaths = exports.hasBeenLoadedMultipleTimes = exports.NonEnumerable = exports.assertNever = void 0; | ||
const path_1 = require("path"); | ||
@@ -37,2 +37,12 @@ const Util = __importStar(require("util")); | ||
exports.assertNever = assertNever; | ||
function NonEnumerable(_cls, context) { | ||
context.addInitializer(function () { | ||
Object.defineProperty(this, context.name, { | ||
enumerable: false, | ||
configurable: true, | ||
writable: true, | ||
}); | ||
}); | ||
} | ||
exports.NonEnumerable = NonEnumerable; | ||
/** | ||
@@ -39,0 +49,0 @@ * This is a hack to make it possible to detect and warn about installation setups |
@@ -92,3 +92,3 @@ "use strict"; | ||
if (tag !== jsx_elements_1.JsxFragment) { | ||
if (blockElements.has(tag) && renderPretty) { | ||
if (blockElements.has(tag) && renderPretty && html) { | ||
html += "\n"; | ||
@@ -110,4 +110,5 @@ } | ||
html += key; | ||
html += "="; | ||
html += JSON.stringify(val); | ||
html += '="'; | ||
html += (typeof val === "string" ? val : JSON.stringify(val)).replaceAll('"', """); | ||
html += '"'; | ||
} | ||
@@ -114,0 +115,0 @@ } |
@@ -79,2 +79,3 @@ import type { Theme as ShikiTheme } from "shiki"; | ||
sourceLinkTemplate: string; | ||
sourceLinkExternal: boolean; | ||
disableGit: boolean; | ||
@@ -81,0 +82,0 @@ gitRevision: string; |
@@ -296,2 +296,20 @@ "use strict"; | ||
options.addDeclaration({ | ||
name: "sourceLinkTemplate", | ||
help: "Specify a link template to be used when generating source urls. If not set, will be automatically created using the git remote. Supports {path}, {line}, {gitRevision} placeholders.", | ||
}); | ||
options.addDeclaration({ | ||
name: "gitRevision", | ||
help: "Use specified revision instead of the last revision for linking to GitHub/Bitbucket source files. Has no effect if disableSources is set.", | ||
}); | ||
options.addDeclaration({ | ||
name: "gitRemote", | ||
help: "Use the specified remote for linking to GitHub/Bitbucket source files. Has no effect if disableGit or disableSources is set.", | ||
defaultValue: "origin", | ||
}); | ||
options.addDeclaration({ | ||
name: "disableGit", | ||
help: "Assume that all can be linked to with the sourceLinkTemplate, sourceLinkTemplate must be set if this is enabled. {path} will be rooted at basePath", | ||
type: declaration_1.ParameterType.Boolean, | ||
}); | ||
options.addDeclaration({ | ||
name: "basePath", | ||
@@ -333,20 +351,7 @@ help: "Specifies the base path to be used when displaying file paths.", | ||
options.addDeclaration({ | ||
name: "sourceLinkTemplate", | ||
help: "Specify a link template to be used when generating source urls. If not set, will be automatically created using the git remote. Supports {path}, {line}, {gitRevision} placeholders.", | ||
}); | ||
options.addDeclaration({ | ||
name: "disableGit", | ||
help: "Assume that all can be linked to with the sourceLinkTemplate, sourceLinkTemplate must be set if this is enabled. {path} will be rooted at basePath", | ||
name: "sourceLinkExternal", | ||
help: "Specifies that source links should be treated as external links to be opened in a new tab.", | ||
type: declaration_1.ParameterType.Boolean, | ||
}); | ||
options.addDeclaration({ | ||
name: "gitRevision", | ||
help: "Use specified revision instead of the last revision for linking to GitHub/Bitbucket source files. Has no effect if disableSources is set.", | ||
}); | ||
options.addDeclaration({ | ||
name: "gitRemote", | ||
help: "Use the specified remote for linking to GitHub/Bitbucket source files. Has no effect if disableGit or disableSources is set.", | ||
defaultValue: "origin", | ||
}); | ||
options.addDeclaration({ | ||
name: "githubPages", | ||
@@ -353,0 +358,0 @@ help: "Generate a .nojekyll file to prevent 404 errors in GitHub Pages. Defaults to `true`.", |
@@ -7,4 +7,4 @@ /** | ||
import type { Options } from "./options"; | ||
export declare const SORT_STRATEGIES: readonly ["source-order", "alphabetical", "enum-value-ascending", "enum-value-descending", "enum-member-source-order", "static-first", "instance-first", "visibility", "required-first", "kind"]; | ||
export declare const SORT_STRATEGIES: readonly ["source-order", "alphabetical", "enum-value-ascending", "enum-value-descending", "enum-member-source-order", "static-first", "instance-first", "visibility", "required-first", "kind", "external-last"]; | ||
export type SortStrategy = (typeof SORT_STRATEGIES)[number]; | ||
export declare function getSortFunction(opts: Options): (reflections: DeclarationReflection[]) => void; |
@@ -21,2 +21,3 @@ "use strict"; | ||
"kind", | ||
"external-last", | ||
]; | ||
@@ -124,2 +125,5 @@ const defaultKindSortOrder = [ | ||
}, | ||
"external-last"(a, b) { | ||
return !a.flags.isExternal && b.flags.isExternal; | ||
}, | ||
}; | ||
@@ -126,0 +130,0 @@ function getSortFunction(opts) { |
{ | ||
"name": "typedoc", | ||
"description": "Create api documentation for TypeScript projects.", | ||
"version": "0.25.2", | ||
"version": "0.25.3", | ||
"homepage": "https://typedoc.org", | ||
@@ -6,0 +6,0 @@ "exports": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1366292
31331