From 10ebad53af8d4c5120bb6d6dc8b96c4b1eab28da Mon Sep 17 00:00:00 2001 From: lake2 Date: Mon, 1 Nov 2021 18:53:41 +0800 Subject: [PATCH 1/2] fix: incorrect path when resolve to the same or the sub folder --- src/index.ts | 7 ++++++- test/index.test.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5bf7fb6..ee0c245 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,7 +90,12 @@ function resolveImports( const current = path.relative(base, path.dirname(imported.path)) const target = path.relative(base, resolved) - const relative = path.relative(current, target).replace(/\\/g, '/') + let relative = path.relative(current, target).replace(/\\/g, '/') + if (!relative.startsWith('..')) { + // https://github.com/gulp-plugin/alias/issues/404 + // in the some folder or the sub folder + relative = './' + relative + } lines[imported.index] = line.replace(imported.import, relative) } diff --git a/test/index.test.ts b/test/index.test.ts index f055ca1..e670866 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -50,6 +50,14 @@ const tests: Record = { input: "import module from 'module'\nimport Component from '@/components'", output: "import module from 'module'\nimport Component from '../components'", }, + ['should support wild card aliases : fix incorrect path when resolve to the same or the sub folder']: + // https://github.com/gulp-plugin/alias/issues/404 + { + options: { config: { paths: { '@/*': ['./src/*'] } } }, + path: './src/pages/Page.ts', + input: "import module from 'module'\nimport Component from '@/pages/components'", + output: "import module from 'module'\nimport Component from './components'", + }, ['should skip commented imports']: { options: { config }, path: './src/pages/Page.ts', From 565020891ed63e6dcb28829d2300d58152f7d838 Mon Sep 17 00:00:00 2001 From: lake2 Date: Fri, 28 Jan 2022 21:57:44 +0800 Subject: [PATCH 2/2] update a new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4bd26b9..befb820 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@gulp-plugin/alias", + "name": "gulp-ts-alias-next", "version": "2.2.2", "description": "Use Gulp to resolve Typescript path aliases during compilation.", "main": "./lib/index.js",