Skip to content

Commit

Permalink
fix(ts-helpers): do not resolve relative paths for default alias, #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Marty Mcfly committed Feb 6, 2019
1 parent 90ef23f commit 6f35ba5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/ts-helpers/__tests__/ImportPathsResolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function createResolver(opts?: TSOptions) {
return new ImportPathsResolver({
paths: {
'someRoot/*': ['lib/*/src'],
'*': ['./types/*'],
},
baseUrl: '.',
...opts,
Expand All @@ -27,4 +28,12 @@ describe('ImportPathsResolver', () => {
'../lib/some/src'
])
})

it('should not resolve relative paths to default alias', () => {
const resolver = createResolver()
expect(resolver.getImportSuggestions(
'./some',
'./bla/index.ts',
)).toBeUndefined()
})
})
4 changes: 2 additions & 2 deletions packages/ts-helpers/src/ImportPathsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class ImportPathsResolver {
const paths = opts.paths || {}
const baseUrl = opts.baseUrl ? opts.baseUrl.replace(winSepRegex, '\/') : null

const mapBaseUrl = baseUrl
const mapBaseUrl: ((v: string) => string) | void = baseUrl
? sub => (sub[0] === '/'
? sub
: `${baseUrl}/${sub}`
: `${baseUrl}/${sub.substring(0, 2) === './' ? sub.substring(2) : sub}`
)
: null

Expand Down
2 changes: 1 addition & 1 deletion packages/ts-helpers/src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class Tokenizer {
return '><'
})

this.mask = new RegExp('^' + regExpEscape(mask).replace(/\>\</g, '(.*)') + '$')
this.mask = new RegExp('^' + regExpEscape(mask).replace(/\>\</g, '(?!\\.\\/)(.*)') + '$')
}

parse(str: string): string[] | void {
Expand Down

0 comments on commit 6f35ba5

Please sign in to comment.