Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/knip/fixtures/plugins/hey-api/openapi-ts.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('@hey-api/openapi-ts').UserConfig} */
module.exports = {
input: 'https://get.heyapi.dev/hey-api/backend',
output: {
path: 'src/client2',
},
plugins: ['@hey-api/client-fetch'],
};
6 changes: 6 additions & 0 deletions packages/knip/fixtures/plugins/hey-api/openapi-ts.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('@hey-api/openapi-ts').UserConfig} */
export default {
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: ['@hey-api/client-fetch'],
};
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugins/hey-api/openapi-ts.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
input: 'https://get.heyapi.dev/hey-api/backend',
output: 'src/client',
plugins: ['@hey-api/client-fetch'],
});
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugins/hey-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@plugins/hey-api",
"dependencies": {
"@hey-api/openapi-ts": "*",
"@hey-api/client-fetch": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getData = () => 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getData = () => 0;
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@
"title": "hardhat plugin configuration (https://knip.dev/reference/plugins/hardhat)",
"$ref": "#/definitions/plugin"
},
"hey-api": {
"title": "hey-api plugin configuration (https://knip.dev/reference/plugins/hey-api)",
"$ref": "#/definitions/plugin"
},
"husky": {
"title": "husky plugin configuration (https://knip.dev/reference/plugins/husky)",
"$ref": "#/definitions/plugin"
Expand Down
32 changes: 32 additions & 0 deletions packages/knip/src/plugins/hey-api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js';
import { type Input, toDependency, toEntry } from '../../util/input.js';
import { hasDependency } from '../../util/plugin.js';
import type { PluginConfig } from './types.js';

// https://heyapi.dev/openapi-ts/get-started

const title = 'Hey API';

const enablers = ['@hey-api/openapi-ts'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const config: string[] = ['openapi-ts.config.@(js|ts|cjs|mjs)'];

const resolveConfig: ResolveConfig<PluginConfig> = async (config): Promise<Input[]> => {
const plugins = (config.plugins ?? []).map(plugin => {
const pluginName = typeof plugin === 'string' ? plugin : plugin.name;
return toDependency(pluginName);
});
const outputPath = typeof config.output === 'string' ? config.output : config.output.path;
const entries = outputPath ? [toEntry(`./${outputPath}/**`)] : [];
return [...plugins, ...entries];
};

export default {
title,
enablers,
isEnabled,
config,
resolveConfig,
} satisfies Plugin;
4 changes: 4 additions & 0 deletions packages/knip/src/plugins/hey-api/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type PluginConfig = {
output: string | { path: string };
plugins?: (string | { name: string })[];
};
2 changes: 2 additions & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { default as githubActions } from './github-actions/index.js';
import { default as glob } from './glob/index.js';
import { default as graphqlCodegen } from './graphql-codegen/index.js';
import { default as hardhat } from './hardhat/index.js';
import { default as heyApi } from './hey-api/index.js';
import { default as husky } from './husky/index.js';
import { default as i18nextParser } from './i18next-parser/index.js';
import { default as jest } from './jest/index.js';
Expand Down Expand Up @@ -141,6 +142,7 @@ export const Plugins = {
glob,
'graphql-codegen': graphqlCodegen,
hardhat,
'hey-api': heyApi,
husky,
'i18next-parser': i18nextParser,
jest,
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/schema/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const pluginsSchema = z.object({
glob: pluginSchema,
'graphql-codegen': pluginSchema,
hardhat: pluginSchema,
'hey-api': pluginSchema,
husky: pluginSchema,
'i18next-parser': pluginSchema,
jest: pluginSchema,
Expand Down
2 changes: 2 additions & 0 deletions packages/knip/src/types/PluginNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type PluginName =
| 'glob'
| 'graphql-codegen'
| 'hardhat'
| 'hey-api'
| 'husky'
| 'i18next-parser'
| 'jest'
Expand Down Expand Up @@ -142,6 +143,7 @@ export const pluginNames = [
'glob',
'graphql-codegen',
'hardhat',
'hey-api',
'husky',
'i18next-parser',
'jest',
Expand Down
21 changes: 21 additions & 0 deletions packages/knip/test/plugins/hey-api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/hey-api');

test('Find dependencies with the hey-api plugin', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

assert.deepEqual(counters, {
...baseCounters,
processed: 5,
total: 5,
});
});