Skip to content

Commit

Permalink
Add UnoCSS plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed May 14, 2024
1 parent c3adf19 commit f8c1475
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 0 deletions.

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.

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

12 changes: 12 additions & 0 deletions packages/knip/fixtures/plugins/unocss/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@fixtures/unocss",
"version": "*",
"scripts": {
"dev": "unocss \"site/{snippets,templates}/**/*.php\" --watch",
"build": "unocss \"site/{snippets,templates}/**/*.php\""
},
"devDependencies": {
"@unocss/cli": "*",
"unocss": "*"
}
}
6 changes: 6 additions & 0 deletions packages/knip/fixtures/plugins/unocss/unocss.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// uno.config.ts
import { defineConfig } from 'unocss'

export default defineConfig({
// ...UnoCSS options
})
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@
"title": "unbuild plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/unbuild/README.md)",
"$ref": "#/definitions/plugin"
},
"unocss": {
"title": "unocss plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/unocss/README.md)",
"$ref": "#/definitions/plugin"
},
"vercel-og": {
"title": "vercel-og plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/vercel-og/README.md)",
"$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 @@ -77,6 +77,7 @@ export const pluginSchema = z.union([
]);

const pluginsSchema = z.object({
unocss: pluginSchema,
astro: pluginSchema,
angular: pluginSchema,
ava: 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 @@ -61,3 +61,4 @@ export { default as wireit } from './wireit/index.js';
export { default as wrangler } from './wrangler/index.js';
export { default as yorkie } from './yorkie/index.js';
export { default as xo } from './xo/index.js';
export { default as unocss } from './unocss/index.js';
33 changes: 33 additions & 0 deletions packages/knip/src/plugins/unocss/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { EnablerPatterns } from '#p/types/config.js';
import type { IsPluginEnabled, Plugin, ResolveConfig } from '#p/types/plugins.js';
import { hasDependency } from '#p/util/plugin.js';
import type { PluginConfig } from './types.js';

// https://unocss.dev/guide/config-file

const title = 'UnoCSS';

const enablers: EnablerPatterns = ['unocss', /^@unocss\//];

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

const config: string[] = ['uno.config.{js,ts,mjs,mts}', 'unocss.config.{js,ts,mjs,mts}'];

const entry: string[] = [];

const production: string[] = [];

const resolveConfig: ResolveConfig<PluginConfig> = async config => {
const dependencies = config?.plugins ?? [];
return [...dependencies];
};

export default {
title,
enablers,
isEnabled,
config,
entry,
production,
resolveConfig,
} satisfies Plugin;
4 changes: 4 additions & 0 deletions packages/knip/src/plugins/unocss/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type PluginConfig = {
plugins?: string[];
entryPathsOrPatterns?: string[];
};
23 changes: 23 additions & 0 deletions packages/knip/test/plugins/unocss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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/unocss');

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

// console.log(issues);

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

0 comments on commit f8c1475

Please sign in to comment.