From e1b6881b39188cb3a4e60299bd88d815a2831b16 Mon Sep 17 00:00:00 2001 From: Ming Date: Mon, 13 Mar 2023 19:53:00 +0800 Subject: [PATCH] fix: should not replace to alias when filePath is not in src (#3135) --- .changeset/kind-eagles-breathe.md | 6 ++++++ packages/solutions/app-tools/src/analyze/utils.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/kind-eagles-breathe.md diff --git a/.changeset/kind-eagles-breathe.md b/.changeset/kind-eagles-breathe.md new file mode 100644 index 000000000000..f1b5917f340c --- /dev/null +++ b/.changeset/kind-eagles-breathe.md @@ -0,0 +1,6 @@ +--- +'@modern-js/app-tools': patch +--- + +fix: should not replace to alias when filePath is not in src +fix: 不应该替换为别名,当 filePath 不在 src 目录中时 diff --git a/packages/solutions/app-tools/src/analyze/utils.ts b/packages/solutions/app-tools/src/analyze/utils.ts index 6a73c08015f1..d413f1f88c7b 100644 --- a/packages/solutions/app-tools/src/analyze/utils.ts +++ b/packages/solutions/app-tools/src/analyze/utils.ts @@ -109,7 +109,15 @@ export const replaceWithAlias = ( base: string, filePath: string, alias: string, -) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath))); +) => { + if (filePath.includes(base)) { + return normalizeToPosixPath( + path.join(alias, path.relative(base, filePath)), + ); + } else { + return filePath; + } +}; export const parseModule = async ({ source,