Skip to content

Commit b82cc07

Browse files
committed
fix: detect possible glob pattern in bundle more
1 parent d637e02 commit b82cc07

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

packages/core/src/config.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path, { dirname, extname, isAbsolute, join } from 'node:path';
33
import {
44
type EnvironmentConfig,
55
type RsbuildConfig,
6+
type RsbuildEntry,
67
type RsbuildPlugin,
78
type RsbuildPlugins,
89
type Rspack,
@@ -844,25 +845,26 @@ const composeSyntaxConfig = (
844845
};
845846
};
846847

847-
export const appendEntryQuery = (
848+
const traverseEntryQuery = (
848849
entry: RsbuildConfigEntry,
850+
callback: (entry: string) => string,
849851
): RsbuildConfigEntry => {
850852
const newEntry: Record<string, RsbuildConfigEntryItem> = {};
851853

852854
for (const [key, value] of Object.entries(entry)) {
853855
let result: RsbuildConfigEntryItem = value;
854856

855857
if (typeof value === 'string') {
856-
result = `${value}?${RSLIB_ENTRY_QUERY}`;
858+
result = callback(value);
857859
} else if (Array.isArray(value)) {
858-
result = value.map((item) => `${item}?${RSLIB_ENTRY_QUERY}`);
860+
result = value.map(callback);
859861
} else {
860862
result = {
861863
...value,
862864
import:
863865
typeof value.import === 'string'
864-
? `${value.import}?${RSLIB_ENTRY_QUERY}`
865-
: value.import.map((item) => `${item}?${RSLIB_ENTRY_QUERY}`),
866+
? callback(value.import)
867+
: value.import.map(callback),
866868
};
867869
}
868870

@@ -872,6 +874,9 @@ export const appendEntryQuery = (
872874
return newEntry;
873875
};
874876

877+
export const appendEntryQuery = (entries: RsbuildConfigEntry): RsbuildEntry =>
878+
traverseEntryQuery(entries, (item) => `${item}?${RSLIB_ENTRY_QUERY}`);
879+
875880
const composeEntryConfig = async (
876881
entries: RsbuildConfigEntry,
877882
bundle: LibConfig['bundle'],
@@ -883,6 +888,20 @@ const composeEntryConfig = async (
883888
}
884889

885890
if (bundle !== false) {
891+
let hasGlobPattern = false;
892+
traverseEntryQuery(entries, (entry) => {
893+
if (entry.includes('*')) {
894+
hasGlobPattern = true;
895+
}
896+
return entry;
897+
});
898+
899+
if (hasGlobPattern) {
900+
throw new Error(
901+
`glob pattern is not supported when "bundle" is "true", considering ${color.green('set "bundle" to "false"')} to use bundleless mode. See ${color.green('https://lib.rsbuild.dev/guide/basic/output-structure')} for more details.`,
902+
);
903+
}
904+
886905
return {
887906
entryConfig: {
888907
source: {

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-glob-bundle-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig({})],
6+
source: {
7+
entry: {
8+
index: ['./src/**'],
9+
},
10+
},
11+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const bar = 'bar';
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,11 @@ test('glob entry bundleless', async () => {
9898
}
9999
`);
100100
});
101+
102+
test('glob entry bundle', async () => {
103+
const fixturePath = join(__dirname, 'glob-bundle');
104+
const build = buildAndGetResults({ fixturePath });
105+
expect(build).rejects.toThrowErrorMatchingInlineSnapshot(
106+
`[Error: glob pattern is not supported when "bundle" is "true", considering set "bundle" to "false" to use bundleless mode. See https://lib.rsbuild.dev/guide/basic/output-structure for more details.]`,
107+
);
108+
});

0 commit comments

Comments
 (0)