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", 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',