Skip to content

Commit

Permalink
Add preconstruct plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 31, 2024
1 parent 4ea83f2 commit af61c96
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 0 deletions.
Empty file.
Empty file.

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

Empty file.
13 changes: 13 additions & 0 deletions packages/knip/fixtures/plugins/preconstruct/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@fixtures/preconstruct",
"version": "*",
"scripts": {
"build": "preconstruct build"
},
"devDependencies": {
"@preconstruct/cli": "*"
},
"preconstruct": {
"entrypoints": ["index.js", "other.js"]
}
}
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@
"title": "PostCSS plugin configuration (https://knip.dev/reference/plugins/postcss)",
"$ref": "#/definitions/plugin"
},
"preconstruct": {
"title": "preconstruct plugin configuration (https://knip.dev/reference/plugins/preconstruct)",
"$ref": "#/definitions/plugin"
},
"prettier": {
"title": "Prettier plugin configuration (https://knip.dev/reference/plugins/prettier)",
"$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 @@ -118,6 +118,7 @@ const pluginsSchema = z.object({
playwright: pluginSchema,
'playwright-ct': pluginSchema,
postcss: pluginSchema,
preconstruct: pluginSchema,
prettier: pluginSchema,
'react-cosmos': pluginSchema,
'release-it': 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 @@ -39,6 +39,7 @@ export { default as oclif } from './oclif/index.js';
export { default as playwright } from './playwright/index.js';
export { default as playwrightCt } from './playwright-ct/index.js';
export { default as postcss } from './postcss/index.js';
export { default as preconstruct } from './preconstruct/index.js';
export { default as prettier } from './prettier/index.js';
export { default as reactCosmos } from './react-cosmos/index.js';
export { default as releaseIt } from './release-it/index.js';
Expand Down
26 changes: 26 additions & 0 deletions packages/knip/src/plugins/preconstruct/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { IsPluginEnabled, Plugin, ResolveConfig } from '#p/types/plugins.js';
import { hasDependency } from '#p/util/plugin.js';
import { toEntryPattern } from '../../util/protocols.js';
import type { PreconstructConfig } from './types.js';

// https://preconstruct.tools/configuration

const title = 'Preconstruct';

const enablers = ['@preconstruct/cli'];

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

const config = ['package.json'];

const resolveEntryPaths: ResolveConfig<PreconstructConfig> = async config => {
return (config.entrypoints ?? []).map(toEntryPattern);
};

export default {
title,
enablers,
isEnabled,
config,
resolveEntryPaths,
} satisfies Plugin;
3 changes: 3 additions & 0 deletions packages/knip/src/plugins/preconstruct/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type PreconstructConfig = {
entrypoints?: string[];
};
21 changes: 21 additions & 0 deletions packages/knip/test/plugins/preconstruct.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/preconstruct');

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

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

0 comments on commit af61c96

Please sign in to comment.