Skip to content

Commit bfb62e0

Browse files
authored
fix: only treat files within context as source file (#677)
1 parent 22efc8d commit bfb62e0

File tree

34 files changed

+204
-55
lines changed

34 files changed

+204
-55
lines changed

packages/core/src/config.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,12 @@ const traverseEntryQuery = (
878878
export const appendEntryQuery = (entries: RsbuildConfigEntry): RsbuildEntry =>
879879
traverseEntryQuery(entries, (item) => `${item}?${RSLIB_ENTRY_QUERY}`);
880880

881+
export const resolveEntryPath = (
882+
entries: RsbuildConfigEntry,
883+
root: string,
884+
): RsbuildEntry =>
885+
traverseEntryQuery(entries, (item) => path.resolve(root, item));
886+
881887
const composeEntryConfig = async (
882888
rawEntry: RsbuildConfigEntry,
883889
bundle: LibConfig['bundle'],
@@ -939,7 +945,7 @@ const composeEntryConfig = async (
939945
return {
940946
entryConfig: {
941947
source: {
942-
entry: appendEntryQuery(entries),
948+
entry: appendEntryQuery(resolveEntryPath(entries, root)),
943949
},
944950
},
945951
lcp: null,
@@ -1044,6 +1050,7 @@ const composeBundlelessExternalConfig = (
10441050
redirect: Redirect,
10451051
cssModulesAuto: CssLoaderOptionsAuto,
10461052
bundle: boolean,
1053+
rootPath: string,
10471054
): {
10481055
config: EnvironmentConfig;
10491056
resolvedJsRedirect?: DeepRequired<JsRedirect>;
@@ -1083,9 +1090,12 @@ const composeBundlelessExternalConfig = (
10831090
let resolvedRequest = request;
10841091
// use resolver to resolve the request
10851092
resolvedRequest = await resolver!(context!, resolvedRequest);
1093+
const isSubpath = resolvedRequest.startsWith(
1094+
rootPath + path.sep,
1095+
);
10861096

1087-
// only handle the request that is not in node_modules
1088-
if (!resolvedRequest.includes('node_modules')) {
1097+
// only handle the request that within the root path
1098+
if (isSubpath) {
10891099
resolvedRequest = normalizeSlash(
10901100
path.relative(path.dirname(issuer), resolvedRequest),
10911101
);
@@ -1359,6 +1369,7 @@ async function composeLibRsbuildConfig(
13591369
redirect,
13601370
cssModulesAuto,
13611371
bundle,
1372+
rootPath,
13621373
);
13631374
const {
13641375
config: targetConfig,

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ icss
4747
idents
4848
iife
4949
imagex
50+
importee
5051
jfif
5152
jiti
5253
jscpuprofile
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import logo from '../../../../assets/logo.svg';
1+
import logo from '../assets/logo.svg';
22

33
export default logo;

tests/integration/asset/name/src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import a from '../../../../assets/image.png';
1+
import a from '../assets/image.png';
22

33
export default () => {
44
return <img src={a} alt="" />;
174 KB
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import a from '../../../../assets/image.png';
1+
import a from '../assets/image.png';
22

33
export default a;
Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)