kisstkondoros / gutter-preview

Other
158 stars 37 forks source link

path mapping starting with "/" #97

Open hyrious opened 3 years ago

hyrious commented 3 years ago

maybe related: dividab/tsconfig-paths#128

Me recently work on an vite app which does not support path mapping starting with '@', instead it could use '/@' (vitejs/vite#279). However this extension can not handle these paths like "/@assets/aqua.png". I think it is caused by:

https://github.com/kisstkondoros/gutter-preview/blob/e8c746b66c3c6e7c505c1c575b6d2bc392c9a597/src/mappers/relativetoworkspacerootmapper.ts#L32

Me locally make some dirty works by adding these code and it seems to be working fine:

if (!firstSegment && this.aliases.indexOf('/' + segments[1]) > -1) {
    segments.shift(); // shift ""
    let aliases = this.paths['/' + segments[0]];
    if (!Array.isArray(aliases)) aliases = [aliases];
    aliases.forEach((alias) => {
        if (alias.endsWith('/')) alias = alias.substring(0, alias.length - 1);
        segments[0] = alias;
        const resolvedPath = segments.join('/');
        pathsToTest.push(resolvedPath);
    });
}