Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ const tests: Record<string, Test> = {
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',
Expand Down