From 08a3a7003b045259b4707ae9fefc52199e33cb5f Mon Sep 17 00:00:00 2001 From: Alex Ivasyuv Date: Fri, 7 Jun 2019 10:33:51 +0300 Subject: [PATCH] handle node_modules paths, and use module name instead of relative path --- src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.ts b/src/index.ts index dcb0d46..24033bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,6 +90,10 @@ verboseLog(`aliases: ${JSON.stringify(aliases, null, 2)}`); const toRelative = (from: string, x: string): string => { const rel = relative(from, x); + + const matchNodeModules = x.match(/.*\/node_modules\//); + if (matchNodeModules) return relative(matchNodeModules[0], x); + return (rel.startsWith('.') ? rel : `./${rel}`).replace(/\\/g, '/'); };