Skip to content

Commit

Permalink
Add travis CI plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 5, 2024
1 parent e6fa86a commit 4821b52
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 1 deletion.
9 changes: 9 additions & 0 deletions packages/knip/fixtures/plugins/travis/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo: false

language: node_js

node_js:
- 12

before_deploy:
- ./node_modules/.bin/patch-version
4 changes: 4 additions & 0 deletions packages/knip/fixtures/plugins/travis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@fixtures/travis",
"version": "*"
}
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@
"title": "tailwind plugin configuration (https://knip.dev/reference/plugins/tailwind)",
"$ref": "#/definitions/plugin"
},
"travis": {
"title": "travis plugin configuration (https://knip.dev/reference/plugins/travis)",
"$ref": "#/definitions/plugin"
},
"tsup": {
"title": "tsup plugin configuration (https://knip.dev/reference/plugins/tsup)",
"$ref": "#/definitions/plugin"
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/ConfigurationValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const pluginsSchema = z.object({
svelte: pluginSchema,
syncpack: pluginSchema,
tailwind: pluginSchema,
travis: pluginSchema,
tsup: pluginSchema,
typedoc: pluginSchema,
typescript: pluginSchema,
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export { default as stylelint } from './stylelint/index.js';
export { default as svelte } from './svelte/index.js';
export { default as syncpack } from './syncpack/index.js';
export { default as tailwind } from './tailwind/index.js';
export { default as travis } from './travis/index.js';
export { default as tsup } from './tsup/index.js';
export { default as typedoc } from './typedoc/index.js';
export { default as typescript } from './typescript/index.js';
Expand Down
33 changes: 33 additions & 0 deletions packages/knip/src/plugins/travis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { IsPluginEnabled, Plugin, ResolveConfig } from '#p/types/plugins.js';
import { _glob } from '#p/util/glob.js';
import { getDependenciesFromScripts } from '../../util/plugin.js';

// https://docs.travis-ci.com/user/customizing-the-build/

const title = 'Travis CI';

const enablers = 'This plugin is enabled when a `.travis.yml` file is found in the root folder.';

const isEnabled: IsPluginEnabled = async ({ cwd }) => Boolean(await _glob({ cwd, patterns: ['.travis.yml'] }));

const config = ['.travis.yml'];

const resolveConfig: ResolveConfig = async (config, options) => {
if (!config) return [];

const beforeDeploy = [config.before_deploy ?? []].flat();
const beforeInstall = [config.before_install ?? []].flat();
const beforeScript = [config.before_script ?? []].flat();

const scripts = [...beforeDeploy, ...beforeInstall, ...beforeScript];

return getDependenciesFromScripts(scripts, { ...options, knownGlobalsOnly: true });
};

export default {
title,
enablers,
isEnabled,
config,
resolveConfig,
} satisfies Plugin;
2 changes: 1 addition & 1 deletion packages/knip/src/typescript/ast-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const isExported = (node: ts.Node): boolean => {
return node.parent ? isExported(node.parent) : false;
};

const isTypeDeclaration = (node: ts.Node) =>
export const isTypeDeclaration = (node: ts.Node) =>
ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node) || ts.isEnumDeclaration(node);

const getAncestorTypeDeclaration = (node: ts.Node) => {
Expand Down
24 changes: 24 additions & 0 deletions packages/knip/test/plugins/travis.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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/travis');

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

assert(issues.binaries['.travis.yml']['patch-version']);

assert.deepEqual(counters, {
...baseCounters,
binaries: 1,
processed: 0,
total: 0,
});
});

0 comments on commit 4821b52

Please sign in to comment.