@@ -27,6 +27,7 @@ import {
27
27
findModuleFromOptions ,
28
28
addImportToModule ,
29
29
parseName ,
30
+ visitNgModuleImports ,
30
31
} from '@ngrx/schematics/schematics-core' ;
31
32
import { Schema as StoreOptions } from './schema' ;
32
33
@@ -63,25 +64,14 @@ function addImportToNgModule(options: StoreOptions): Rule {
63
64
`${ options . path } /environments/environment`
64
65
) ;
65
66
66
- const runtimeChecks = `
67
- runtimeChecks: {
68
- strictStateImmutability: true,
69
- strictActionImmutability: true,
70
- }
71
- ` ;
72
-
73
67
const rootStoreReducers = options . minimal ? `{}` : `reducers` ;
74
-
75
- const rootStoreConfig = options . minimal
76
- ? `{ ${ runtimeChecks } }`
77
- : `{
78
- metaReducers, ${ runtimeChecks } }` ;
68
+ const rootStoreConfig = options . minimal ? `` : `, { metaReducers }` ;
79
69
80
70
const storeNgModuleImport = addImportToModule (
81
71
source ,
82
72
modulePath ,
83
73
options . root
84
- ? `StoreModule.forRoot(${ rootStoreReducers } , ${ rootStoreConfig } )`
74
+ ? `StoreModule.forRoot(${ rootStoreReducers } ${ rootStoreConfig } )`
85
75
: `StoreModule.forFeature(from${ stringUtils . classify (
86
76
options . name
87
77
) } .${ stringUtils . camelize (
@@ -123,10 +113,20 @@ function addImportToNgModule(options: StoreOptions): Rule {
123
113
let rootImports : ( Change | undefined ) [ ] = [ ] ;
124
114
125
115
if ( options . root ) {
116
+ let hasImports = false ;
117
+ visitNgModuleImports ( source , ( _ , importNodes ) => {
118
+ hasImports = importNodes . length > 0 ;
119
+ } ) ;
120
+
121
+ // `addImportToModule` adds a comma to imports when there are already imports present
122
+ // because at this time the store import hasn't been committed yet, `addImportToModule` wont add a comma
123
+ // so we have to add it here for empty import arrays
124
+ let adjectiveComma = hasImports ? '' : ', ' ;
125
+
126
126
const storeDevtoolsNgModuleImport = addImportToModule (
127
127
source ,
128
128
modulePath ,
129
- `!environment.production ? StoreDevtoolsModule.instrument() : []` ,
129
+ `${ adjectiveComma } !environment.production ? StoreDevtoolsModule.instrument() : []` ,
130
130
relativePath
131
131
) . shift ( ) ;
132
132
0 commit comments