File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,10 @@ export default {
7575 const hasAlias =
7676 options . alias
7777 | > keys
78- | > some ( alias => sourcePath | > startsWith ( `${ alias } /` ) )
78+ | > some (
79+ alias =>
80+ ( sourcePath | > startsWith ( `${ alias } /` ) ) || sourcePath === alias ,
81+ )
7982
8083 const importWithoutAlias = resolvePath ( sourcePath , currentFile , options )
8184
@@ -96,10 +99,11 @@ export default {
9699
97100 const absoluteImportPath = P . resolve ( folder , sourcePath )
98101
99- const rewrittenImport = `${ matchingAlias . name } /${
100- P . relative ( matchingAlias . path , absoluteImportPath )
101- | > replace ( / \\ / g, '/' )
102- } `
102+ const rewrittenImport =
103+ `${ matchingAlias . name } /${
104+ P . relative ( matchingAlias . path , absoluteImportPath )
105+ | > replace ( / \\ / g, '/' )
106+ } ` | > replace ( / \/ $ / , '' )
103107
104108 const importType = getImportType ( importWithoutAlias )
105109
Original file line number Diff line number Diff line change @@ -245,6 +245,26 @@ export default tester(
245245 output : "import foo from '@/foo'" ,
246246 } )
247247 } ,
248+ 'direct import of an alias from another one' : async ( ) => {
249+ await outputFiles ( {
250+ '.babelrc.json' : JSON . stringify ( {
251+ plugins : [
252+ [
253+ packageName `babel-plugin-module-resolver` ,
254+ { alias : { '@components' : './components' , '@hooks' : './hooks' } } ,
255+ ] ,
256+ ] ,
257+ } ) ,
258+ } )
259+ expect (
260+ lint ( "import { foo } from '../hooks'" , {
261+ filename : 'components/bar.js' ,
262+ } ) ,
263+ ) . toEqual ( {
264+ messages : [ "Unexpected parent import '../hooks'. Use '@hooks' instead" ] ,
265+ output : "import { foo } from '@hooks'" ,
266+ } )
267+ } ,
248268 external : async ( ) => {
249269 await fs . outputFile (
250270 '.babelrc.json' ,
You can’t perform that action at this time.
0 commit comments