Skip to content

Commit

Permalink
fix: typedoc 0.27.x changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0t4u committed Dec 4, 2024
1 parent aee9bc4 commit b12ca63
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 935 deletions.
1,129 changes: 231 additions & 898 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@shipgirl/typedoc-plugin-versions",
"version": "0.2.8",
"version": "0.3.0",
"description": "It keeps track of your document builds and provides a select menu for versions",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"lint": "prettier -c .",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
Expand Down Expand Up @@ -38,23 +39,23 @@
"@jest/globals": "^29.7.0",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.14",
"@types/node": "^22.8.2",
"@types/node": "^22.10.1",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^8.12.1",
"@typescript-eslint/parser": "^8.12.1",
"@typescript-eslint/eslint-plugin": "^8.17.0",
"@typescript-eslint/parser": "^8.17.0",
"cpy-cli": "^5.0.0",
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"expect": "^29.7.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typedoc": "~0.26.10",
"typescript": "^5.6.3"
"typedoc": "~0.27.3",
"typescript": "^5.7.2"
},
"peerDependencies": {
"typedoc": "~0.26.0"
"typedoc": "~0.26.0 || ~0.27.0"
}
}
2 changes: 1 addition & 1 deletion src/etc/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Application, JSX, RendererHooks } from 'typedoc';
import { Application, JSX, type RendererHooks } from 'typedoc';

/**
* Injects browser js to control the behaviour of the new `select` DOM element
Expand Down
33 changes: 18 additions & 15 deletions src/etc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import path from 'path';
import fs from 'fs-extra';
import semver from 'semver';
import { version, semanticAlias, metadata } from '../types';
import type { version, semanticAlias, metadata } from '../types.js';
import { Application } from 'typedoc';
const packagePath = path.join(process.cwd(), 'package.json');
const pack = fs.readJSONSync(packagePath);
Expand Down Expand Up @@ -54,10 +54,10 @@ export function refreshMetadata(
const vDev = validate(dev);

const versions = refreshMetadataVersions(
[...(metadata.versions ?? []), metadata.stable, metadata.dev],
[...(metadata.versions ?? []), metadata.stable!, metadata.dev!],
docRoot,
packageFile,
);
) as version[];

return {
versions,
Expand All @@ -75,7 +75,7 @@ export function refreshMetadata(
export function refreshMetadataVersions(
versions: version[],
docRoot: string,
packageFile,
packageFile: string,
) {
return (
[
Expand Down Expand Up @@ -110,7 +110,7 @@ export function refreshMetadataVersions(
// discard undefined && filter to unique values only
.filter((v, i, s) => v !== undefined && s.indexOf(v) === i)
// sort in descending order
.sort(semver.rcompare)
.sort((a, b) => semver.rcompare(a!, b!))
);
}

Expand All @@ -127,7 +127,7 @@ export function refreshMetadataAlias(
versions: version[],
stable: 'auto' | version = 'auto',
dev: 'auto' | version = 'auto',
): version {
): version | undefined {
const option = alias === 'stable' ? stable : dev;
if (
option && // the option is set
Expand All @@ -143,7 +143,7 @@ export function refreshMetadataAlias(
!getLatestVersion('stable', versions, stable, dev) || // or there is no matching latest stable
semver.gte(
latest,
getLatestVersion('stable', versions, stable, dev),
getLatestVersion('stable', versions, stable, dev)!,
true,
))
) {
Expand Down Expand Up @@ -174,7 +174,7 @@ export function getLatestVersion(
versions: version[],
stable: 'auto' | version = 'auto',
dev: 'auto' | version = 'auto',
): version {
): version | undefined {
return [...versions]
.sort(semver.rcompare)
.find((v) => getVersionAlias(v, stable, dev) === alias);
Expand Down Expand Up @@ -225,7 +225,7 @@ export function getSemanticVersion(version: string = pack.version): version {
// ensure prerelease info remains appended
const prerelease = semver.prerelease(version, true);
return prerelease
? `v${semVer.version}-${semver.prerelease(version, true).join('.')}`
? `v${semVer.version}-${semver.prerelease(version, true)!.join('.')}`
: `v${semVer.version}`;
}

Expand All @@ -235,7 +235,7 @@ export function getSemanticVersion(version: string = pack.version): version {
*/
export function getMinorVersion(version?: string): version {
version = getSemanticVersion(version);
const { major, minor } = semver.coerce(version, { loose: true });
const { major, minor } = semver.coerce(version, { loose: true })!;
return `v${major}.${minor}`;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ export function makeJsKeys(metadata: metadata): string {
const alias = metadata.stable ? 'stable' : 'dev';
const keys = [
alias, // add initial key (stable or dev)
...metadata.versions // add the major.minor versions
...metadata.versions! // add the major.minor versions
.map((v) => getMinorVersion(v))
.filter((v, i, s) => s.indexOf(v) === i),
];
Expand Down Expand Up @@ -321,8 +321,11 @@ export function makeAliasLink(

/**
* Creates symlinks for minor versions pointing to the latest patch release
* @param semGroups
* @param versions
* @param docRoot
* @param makeRelativeSymlinks
* @param stable
* @param dev
*/
export function makeMinorVersionLinks(
versions: version[],
Expand Down Expand Up @@ -360,7 +363,7 @@ export function makeMinorVersionLinks(
.filter((v, i, s) => s.indexOf(v) === i)) {
const _docRoot = makeRelativeSymlinks ? './' : docRoot;
const target = path.join(_docRoot, getMinorVersion(version));
const src = path.join(_docRoot, version);
const src = path.join(_docRoot, version!);
if (makeRelativeSymlinks) process.chdir(docRoot);

if (fs.lstatSync(target, { throwIfNoEntry: false })?.isSymbolicLink())
Expand All @@ -375,7 +378,7 @@ export function makeMinorVersionLinks(
* @param docRoot The path to the docs root.
* @returns The version number parsed from the given symlink.
*/
export function getSymlinkVersion(symlink: string, docRoot: string): version {
export function getSymlinkVersion(symlink: string, docRoot: string): version | undefined {
const symlinkPath = path.join(docRoot, symlink);
if (
fs.pathExistsSync(symlinkPath) &&
Expand Down Expand Up @@ -425,7 +428,7 @@ export function handleJeckyll(rootPath: string, targetPath: string): void {
* Copies static assets to the document build folder
* @param targetPath
*/
export function handleAssets(targetPath: string, srcDir: string = __dirname) {
export function handleAssets(targetPath: string, srcDir: string = import.meta.dirname) {
const sourceAsset = path.join(srcDir, '../assets/versionsMenu.js');
fs.ensureDirSync(path.join(targetPath, 'assets'));
fs.copyFileSync(
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { Application, ParameterType, RendererEvent } from 'typedoc';

import path from 'path';
import fs from 'fs-extra';
import * as vUtils from './etc/utils';
import * as vHooks from './etc/hooks';
import { versionsOptions } from './types';
export * from './types';
import * as vUtils from './etc/utils.js';
import * as vHooks from './etc/hooks.js';
import type { versionsOptions } from './types.js';
export * from './types.js';

/**
* The default Typedoc [plugin hook](https://typedoc.org/guides/development/#plugins).
Expand All @@ -34,7 +34,7 @@ export function load(app: Application) {
const vOptions = app.options.getValue("versions") as versionsOptions;

vHooks.injectSelectJs(app);
vHooks.injectSelectHtml(app, vOptions.domLocation);
vHooks.injectSelectHtml(app, vOptions.domLocation!);

const { rootPath, targetPath } = vUtils.getPaths(app);

Expand Down Expand Up @@ -65,17 +65,17 @@ export function load(app: Application) {
vUtils.makeAliasLink(
'stable',
rootPath,
metadata.stable ?? metadata.dev,
metadata.stable! ?? metadata.dev,
vOptions.makeRelativeLinks,
);
vUtils.makeAliasLink(
'dev',
rootPath,
metadata.dev ?? metadata.stable,
metadata.dev! ?? metadata.stable,
vOptions.makeRelativeLinks,
);
vUtils.makeMinorVersionLinks(
metadata.versions,
metadata.versions!,
rootPath,
vOptions.makeRelativeLinks,
);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @module
*/

import { RendererHooks } from 'typedoc';
import type { RendererHooks } from 'typedoc';

/**
* User defined options under the key of `versions` in typedoc.json
Expand Down
10 changes: 7 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
"jsxFragmentFactory": "JSX.Fragment",
"resolveJsonModule": true,
"outDir": "dist",
"module": "commonjs",
"moduleResolution": "node",
"lib": ["ESNext", "DOM"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2020",
"esModuleInterop": true,
"strict": true,
"isolatedModules": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"build": true,
"incremental": true,
"skipLibCheck": true,
"verbatimModuleSyntax": true,
}
}
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"externalPattern": ["**/node_modules/**"],
"excludeExternals": true,
"logLevel": "Verbose",
"plugin": ["./dist"],
"plugin": ["./dist/index.js"],
"versions": { "packageFile": "package.json", "makeRelativeLinks": false },
"skipErrorChecking": true,
"name": "Versions Plugin Docs"
Expand Down

0 comments on commit b12ca63

Please sign in to comment.