Skip to content

Commit 8209917

Browse files
committedFeb 18, 2025
Fix dynamically added config files for disabled plugins (resolve #947)
1 parent 0b7f05f commit 8209917

File tree

7 files changed

+56
-1
lines changed

7 files changed

+56
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workspaces": {
3+
"ws": {}
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@fixtures/plugin-disable",
3+
"workspaces": ["ws"],
4+
"scripts": {
5+
"test": "vitest -c vite.config.ts"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const getValues = () => {
2+
throw new Error("This plugin should've been ignored");
3+
};
4+
5+
export default {
6+
someValue: getValues(),
7+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@fixtures/plugin-disable-workspace",
3+
"scripts": {
4+
"playwright-test": "playwright test --config playwright.config.ts"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const getValues = () => {
2+
throw new Error("This plugin should've been ignored");
3+
};
4+
5+
export default {
6+
someValue: getValues(),
7+
};

‎packages/knip/src/WorkspaceWorker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ export class WorkspaceWorker {
376376
do {
377377
for (const [pluginName, dependencies] of configFiles.entries()) {
378378
configFiles.delete(pluginName);
379-
await runPlugin(pluginName, Array.from(dependencies));
379+
if (this.enabledPlugins.includes(pluginName)) await runPlugin(pluginName, Array.from(dependencies));
380+
else for (const id of dependencies) addInput(toEntry(id));
380381
}
381382
} while (remainingPlugins.size > 0 && configFiles.size > 0);
382383

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test } from 'bun:test';
2+
import assert from 'node:assert/strict';
3+
import { main } from '../src/index.js';
4+
import { resolve } from '../src/util/path.js';
5+
import baseArguments from './helpers/baseArguments.js';
6+
import baseCounters from './helpers/baseCounters.js';
7+
8+
const cwd = resolve('fixtures/plugin-disable');
9+
10+
test('Disable plugin from dynamically added config file', async () => {
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
assert.deepEqual(counters, {
17+
...baseCounters,
18+
binaries: 2,
19+
total: 2,
20+
processed: 2,
21+
});
22+
});

0 commit comments

Comments
 (0)
Please sign in to comment.