fix error when project path contains "src" (#1185) (#1194)

fix error when project path contains src (#1185)

Co-authored-by: Tim Havlicek <t.havlicek@s-v.de>
This commit is contained in:
Tim 2023-08-10 11:07:35 +02:00 committed by GitHub
parent cc1bd64a56
commit baf032883f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ import fs from 'fs/promises';
import path from 'path';
import { Alias } from 'vite';
const projectPath = path.resolve(__dirname, '../../../');
const pkgJsonCache = new Map();
const resolver: Alias = {
@ -12,10 +13,12 @@ const resolver: Alias = {
const [_, sourcePath] = source.split('~/');
if (importer!.includes('/src/')) {
const [pkg] = importer!.split('/src/');
const relativeImporter = importer!.replace(projectPath, '');
root = `${pkg!}/src`;
if (relativeImporter.includes('/src/')) {
const [pkg] = relativeImporter.split('/src/');
root = `${projectPath}${pkg}/src`;
} else {
let parent = importer!;