Skip to content

Commit 9eebc55

Browse files
committed
Entries in rsbuild config are production entries (resolves #1309)
1 parent 2464f37 commit 9eebc55

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

packages/knip/src/plugins/rsbuild/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js';
2-
import { type Input, toEntry } from '../../util/input.js';
2+
import { toProductionEntry } from '../../util/input.js';
33
import { hasDependency } from '../../util/plugin.js';
44
import type { RsbuildConfig } from './types.js';
55

@@ -14,16 +14,16 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
1414
const config = ['rsbuild*.config.{mjs,ts,js,cjs,mts,cts}'];
1515

1616
const resolveConfig: ResolveConfig<RsbuildConfig> = async config => {
17-
const inputs = new Set<Input>();
17+
const entries = new Set<string>();
1818

1919
const checkSource = (source: RsbuildConfig['source']) => {
2020
if (source?.entry) {
2121
for (const entry of Object.values(source.entry)) {
22-
if (typeof entry === 'string') inputs.add(toEntry(entry));
23-
else if (Array.isArray(entry)) for (const e of entry) inputs.add(toEntry(e));
22+
if (typeof entry === 'string') entries.add(entry);
23+
else if (Array.isArray(entry)) for (const e of entry) entries.add(e);
2424
else {
25-
if (typeof entry.import === 'string') inputs.add(toEntry(entry.import));
26-
else if (Array.isArray(entry.import)) for (const e of entry.import) inputs.add(toEntry(e));
25+
if (typeof entry.import === 'string') entries.add(entry.import);
26+
else if (Array.isArray(entry.import)) for (const e of entry.import) entries.add(e);
2727
}
2828
}
2929
}
@@ -37,7 +37,7 @@ const resolveConfig: ResolveConfig<RsbuildConfig> = async config => {
3737
}
3838
}
3939

40-
return Array.from(inputs);
40+
return Array.from(entries).map(input => toProductionEntry(input));
4141
};
4242

4343
export default {

packages/knip/test/plugins/rsbuild.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ test('Find dependencies with the rsbuild plugin', async () => {
1818
total: 9,
1919
});
2020
});
21+
22+
test('Find dependencies with the rsbuild plugin (production)', async () => {
23+
const options = await createOptions({ cwd, isProduction: true });
24+
const { counters } = await main(options);
25+
26+
assert.deepEqual(counters, {
27+
...baseCounters,
28+
processed: 8,
29+
total: 8,
30+
});
31+
});

0 commit comments

Comments
 (0)