Skip to content

Commit

Permalink
Look for typedoc config in package.json and tsconfig.json (closes #129)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 17, 2023
1 parent 3655301 commit 66e9840
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/plugins/typedoc/README.md
Expand Up @@ -16,7 +16,9 @@ or `devDependencies`:
"typedoc.{js,cjs,json,jsonc}",
"typedoc.config.{js,cjs}",
".config/typedoc.{js,cjs,json,jsonc}",
".config/typedoc.config.{js,cjs}"
".config/typedoc.config.{js,cjs}",
"package.json",
"tsconfig.json"
]
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/typedoc/index.ts
Expand Up @@ -17,10 +17,16 @@ export const CONFIG_FILE_PATTERNS = [
'typedoc.config.{js,cjs}',
'.config/typedoc.{js,cjs,json,jsonc}',
'.config/typedoc.config.{js,cjs}',
'package.json',
'tsconfig.json',
];

const findTypeDocDependencies: GenericPluginCallback = async configFilePath => {
const config: PluginConfig = await load(configFilePath);
const findTypeDocDependencies: GenericPluginCallback = async (configFilePath, { manifest }) => {
const config: PluginConfig = configFilePath.endsWith('package.json')
? manifest.typedocOptions
: configFilePath.endsWith('tsconfig.json')
? (await load(configFilePath)).typedocOptions
: await load(configFilePath);
return config?.plugin ?? [];
};

Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/plugins/typedoc/package.json
@@ -0,0 +1,8 @@
{
"name": "typedoc",
"typedocOptions": {
"plugin": [
"typedoc-plugin-umami"
]
}
}
5 changes: 5 additions & 0 deletions tests/fixtures/plugins/typedoc/tsconfig.json
@@ -0,0 +1,5 @@
{
"typedocOptions": {
"plugin": ["typedoc-plugin-zod"]
}
}
16 changes: 15 additions & 1 deletion tests/plugins/typedoc.test.ts
Expand Up @@ -2,15 +2,29 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import * as typedoc from '../../src/plugins/typedoc/index.js';
import { resolve, join } from '../../src/util/path.js';
import { getManifest } from '../helpers/index.js';

const cwd = resolve('tests/fixtures/plugins/typedoc');
const manifest = getManifest(cwd);

test('Find dependencies in typedoc configuration (json)', async () => {
const configFilePath = join(cwd, 'typedoc.json');
const dependencies = await typedoc.findDependencies(configFilePath);
const dependencies = await typedoc.findDependencies(configFilePath, { manifest });
assert.deepEqual(dependencies, [
'@appium/typedoc-plugin-appium',
'typedoc-plugin-expand-object-like-types',
'./dist/index.cjs',
]);
});

test('Find dependencies in typedoc configuration (package.json)', async () => {
const configFilePath = join(cwd, 'tsconfig.json');
const dependencies = await typedoc.findDependencies(configFilePath, { manifest });
assert.deepEqual(dependencies, ['typedoc-plugin-zod']);
});

test('Find dependencies in typedoc configuration (tsconfig.json)', async () => {
const configFilePath = join(cwd, 'package.json');
const dependencies = await typedoc.findDependencies(configFilePath, { manifest });
assert.deepEqual(dependencies, ['typedoc-plugin-umami']);
});

0 comments on commit 66e9840

Please sign in to comment.