@@ -20,28 +20,41 @@ const base = baseConfig.compilerOptions.paths;
2020/** Get existing paths in our second config file */
2121const toExtend = extendedConfig . compilerOptions . paths ;
2222
23+ /**
24+ * Extract any keys that aren't from our lib (i.e. will have polyfills)
25+ */
26+ const saveThese = { } ;
27+
28+ /** Get all paths in the file to merge */
29+ const existingPaths = Object . keys ( toExtend ) ;
30+
31+ // delete any changed libraries
32+ for ( let i = 0 ; i < existingPaths . length ; i ++ ) {
33+ // check for polyfill and not local library
34+ if ( ! existingPaths [ i ] . startsWith ( '@idl' ) ) {
35+ saveThese [ existingPaths [ i ] ] = toExtend [ existingPaths [ i ] ] ;
36+ delete toExtend [ existingPaths [ i ] ] ;
37+ continue ;
38+ }
39+
40+ // remove if lib is not in existing source
41+ if ( ! ( existingPaths [ i ] in base ) && existingPaths [ i ] in toExtend ) {
42+ delete toExtend [ existingPaths [ i ] ] ;
43+ changes = true ;
44+ }
45+ }
46+
2347/** Get all paths that should be shared */
2448const sharedPaths = Object . keys ( base ) ;
2549
2650/** Track if there are changes */
2751let changes = false ;
2852
29- // check for changes - so we dont always break formatting
53+ // add any missing libraries
3054for ( let i = 0 ; i < sharedPaths . length ; i ++ ) {
3155 if ( ! ( sharedPaths [ i ] in toExtend ) ) {
56+ toExtend [ sharedPaths [ i ] ] = base [ sharedPaths [ i ] ] ;
3257 changes = true ;
33- break ;
34- }
35- }
36-
37- /** Get all paths in the file to merge */
38- const existingPaths = Object . keys ( toExtend ) ;
39-
40- // check for changes - so we dont always break formatting
41- for ( let i = 0 ; i < existingPaths . length ; i ++ ) {
42- if ( ! ( existingPaths [ i ] in base ) ) {
43- changes = true ;
44- break ;
4558 }
4659}
4760
@@ -50,21 +63,8 @@ if (!changes) {
5063 process . exit ( ) ;
5164}
5265
53- // check for changes - so we dont always break formatting
54- for ( let i = 0 ; i < existingPaths . length ; i ++ ) {
55- if ( existingPaths [ i ] . startsWith ( '@idl' ) ) {
56- delete toExtend [ existingPaths [ i ] ] ;
57- }
58- }
59-
60- // Merge paths
61- const mergedPaths = {
62- ...baseConfig . compilerOptions . paths ,
63- ...extendedConfig . compilerOptions . paths ,
64- } ;
65-
6666// Update extended config
67- extendedConfig . compilerOptions . paths = mergedPaths ;
67+ extendedConfig . compilerOptions . paths = { ... toExtend , ... saveThese } ;
6868
6969// Write updated config
7070fs . writeFileSync ( extendedConfigPath , JSON . stringify ( extendedConfig , null , 2 ) ) ;
0 commit comments