File tree Expand file tree Collapse file tree 4 files changed +46
-10
lines changed
Expand file tree Collapse file tree 4 files changed +46
-10
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "baseUrl" : " ." ,
4+ "extends" : " ./59-tsconfig.paths.json" ,
5+ "paths" : {
6+ "alias/*" : [ " target/*" ]
7+ }
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "baseUrl" : " ." ,
4+ "paths" : {
5+ "alias-paths/*" : [ " target-paths/*" ]
6+ }
7+ }
8+ }
Original file line number Diff line number Diff line change 11'use strict' ;
2-
3- const reactAppAlias = require ( '../src' ) ;
2+ const path = require ( 'path' )
3+ const { configPathsRaw } = require ( '../src' ) ;
44
55describe ( 'react-app-alias' , ( ) => {
66 test . todo ( 'tested by tests in projects in example folder' ) ;
77} ) ;
8+
9+ describe ( 'extends section of tsconfig on detect config file stage' , ( ) => {
10+ test ( 'read both file and extends' , ( ) => {
11+ const paths = configPathsRaw ( path . resolve ( __dirname , './59-tsconfig.json' ) )
12+ expect ( paths [ 'alias/*' ] [ 0 ] ) . toBe ( 'target/*' ) ;
13+ expect ( paths [ 'alias-paths/*' ] [ 0 ] ) . toBe ( 'target-paths/*' ) ;
14+ } ) ;
15+ } ) ;
16+
Original file line number Diff line number Diff line change @@ -114,17 +114,27 @@ function configPathsRaw(confPath) {
114114 if ( ! confPath )
115115 throw Error ( 'react-app-rewire-alias:configPaths: there is no config file found' )
116116
117+ const confdir = path . dirname ( confPath )
117118 const conf = require ( confPath )
118- const extmsg = ! conf . extends ? '' : `, specify ${ conf . extends } instead of ${ confPath } for configPaths()`
119+ const confPaths = conf . compilerOptions && conf . compilerOptions . paths ?
120+ conf . compilerOptions . paths : { }
119121
120- if ( ! conf . compilerOptions || ! conf . compilerOptions . paths )
121- return { }
122-
123- if ( typeof conf . compilerOptions . paths !== 'object' )
124- throw Error ( `
125- react-app-rewire-alias:configPaths: array expected for paths ${ extmsg } ` )
122+ const extUrl = conf . compilerOptions . extends
123+ const extPath = extUrl ? path . resolve ( confdir , extUrl ) : ''
124+ const ext = extUrl ? require ( extPath ) : { }
125+
126+ const extPaths = ext . compilerOptions && ext . compilerOptions . paths ?
127+ ext . compilerOptions . paths : { }
126128
127- return conf . compilerOptions . paths
129+ if ( typeof confPaths !== 'object' )
130+ throw Error ( `react-app-alias:configPaths: '${ confPath } ' array expected for paths` )
131+ if ( typeof extPaths !== 'object' )
132+ throw Error ( `react-app-alias:configPaths: '${ extPath } ' array expected for paths` )
133+
134+ return {
135+ ...confPaths ,
136+ ...extPaths ,
137+ }
128138}
129139
130140function configPaths ( configPath = '' ) {
You can’t perform that action at this time.
0 commit comments