Skip to content

Commit

Permalink
Fix dynamically added config files for disabled plugins (resolve #947)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Feb 18, 2025
1 parent 0b7f05f commit 8209917
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugin-disable/knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workspaces": {
"ws": {}
}
}
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugin-disable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@fixtures/plugin-disable",
"workspaces": ["ws"],
"scripts": {
"test": "vitest -c vite.config.ts"
}
}
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugin-disable/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getValues = () => {
throw new Error("This plugin should've been ignored");
};

export default {
someValue: getValues(),
};
6 changes: 6 additions & 0 deletions packages/knip/fixtures/plugin-disable/ws/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@fixtures/plugin-disable-workspace",
"scripts": {
"playwright-test": "playwright test --config playwright.config.ts"
}
}
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugin-disable/ws/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const getValues = () => {
throw new Error("This plugin should've been ignored");
};

export default {
someValue: getValues(),
};
3 changes: 2 additions & 1 deletion packages/knip/src/WorkspaceWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ export class WorkspaceWorker {
do {
for (const [pluginName, dependencies] of configFiles.entries()) {
configFiles.delete(pluginName);
await runPlugin(pluginName, Array.from(dependencies));
if (this.enabledPlugins.includes(pluginName)) await runPlugin(pluginName, Array.from(dependencies));
else for (const id of dependencies) addInput(toEntry(id));
}
} while (remainingPlugins.size > 0 && configFiles.size > 0);

Expand Down
22 changes: 22 additions & 0 deletions packages/knip/test/plugin-disable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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/plugin-disable');

test('Disable plugin from dynamically added config file', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

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

0 comments on commit 8209917

Please sign in to comment.