Skip to content

Commit d106f20

Browse files
authored
fix: warn duplicate entries in bundleless mode (#715)
1 parent 3760277 commit d106f20

File tree

9 files changed

+57
-5
lines changed

9 files changed

+57
-5
lines changed

packages/core/src/config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,18 @@ const composeEntryConfig = async (
10191019

10201020
for (const file of resolvedEntryFiles) {
10211021
const entryName = getEntryName(file);
1022+
10221023
if (resolvedEntries[entryName]) {
1023-
logger.warn(
1024-
`duplicate entry: ${entryName}, this may lead to the incorrect output, please rename the file`,
1025-
);
1024+
calcLcp &&
1025+
logger.warn(
1026+
`Duplicate entry ${color.cyan(entryName)} from ${color.cyan(
1027+
path.relative(root, file),
1028+
)} and ${color.cyan(
1029+
path.relative(root, resolvedEntries[entryName]),
1030+
)}, which may lead to the incorrect output, please rename the file.`,
1031+
);
10261032
}
1033+
10271034
resolvedEntries[entryName] = file;
10281035
}
10291036
}

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "entry-duplicate-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({
7+
bundle: false,
8+
}),
9+
],
10+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.red {
2+
color: red;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.counter-text {
2+
font-size: 50px;
3+
}

tests/integration/entry/duplicate/src/index.svg

Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';

tests/integration/entry/index.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { join } from 'node:path';
1+
import path, { join } from 'node:path';
22
import stripAnsi from 'strip-ansi';
3-
import { buildAndGetResults, queryContent } from 'test-helper';
3+
import { buildAndGetResults, proxyConsole, queryContent } from 'test-helper';
44
import { expect, test } from 'vitest';
55

66
test('default entry', async () => {
@@ -168,3 +168,23 @@ test('validate entry and throw errors', async () => {
168168
`"The source.entry configuration should be an object, but received string: ./src/**. Checkout https://lib.rsbuild.dev/config/rsbuild/source#sourceentry for more details."`,
169169
);
170170
});
171+
172+
test('duplicate entry in bundleless mode', async () => {
173+
const { logs, restore } = proxyConsole();
174+
const fixturePath = join(__dirname, 'duplicate');
175+
await buildAndGetResults({ fixturePath });
176+
177+
const logStrings = logs.map((log) => stripAnsi(log));
178+
179+
expect(
180+
logStrings.some((log) =>
181+
log.includes(
182+
`Duplicate entry index from ${path.normalize(
183+
'src/index.ts',
184+
)} and ${path.normalize('src/index.svg')}, which may lead to the incorrect output, please rename the file.`,
185+
),
186+
),
187+
).toBe(true);
188+
189+
restore();
190+
});

0 commit comments

Comments
 (0)