@@ -13,13 +13,13 @@ import {
13
13
platformVersion ,
14
14
findModuleFromOptions ,
15
15
insertImport ,
16
- InsertChange ,
17
16
getProjectPath ,
18
17
parseName ,
19
18
addImportToModule ,
20
19
createReplaceChange ,
21
20
ReplaceChange ,
22
- createChangeRecorder ,
21
+ visitTSSourceFiles ,
22
+ commitChanges ,
23
23
} from '@ngrx/data/schematics-core' ;
24
24
import { Schema as EntityDataOptions } from './schema' ;
25
25
@@ -68,13 +68,7 @@ function addEntityDataToNgModule(options: EntityDataOptions): Rule {
68
68
) ;
69
69
70
70
const changes = [ effectsModuleImport , dateEntityNgModuleImport ] ;
71
- const recorder = host . beginUpdate ( modulePath ) ;
72
- for ( const change of changes ) {
73
- if ( change instanceof InsertChange ) {
74
- recorder . insertLeft ( change . pos , change . toAdd ) ;
75
- }
76
- }
77
- host . commitUpdate ( recorder ) ;
71
+ commitChanges ( host , source . fileName , changes ) ;
78
72
79
73
return host ;
80
74
} ;
@@ -103,23 +97,9 @@ function removeAngularNgRxDataFromPackageJson() {
103
97
} ;
104
98
}
105
99
106
- function renameNgrxDataModule ( options : EntityDataOptions ) {
107
- return ( host : Tree , context : SchematicContext ) => {
108
- host . visit ( path => {
109
- if ( ! path . endsWith ( '.ts' ) ) {
110
- return ;
111
- }
112
-
113
- const sourceFile = ts . createSourceFile (
114
- path ,
115
- host . read ( path ) ! . toString ( ) ,
116
- ts . ScriptTarget . Latest
117
- ) ;
118
-
119
- if ( sourceFile . isDeclarationFile ) {
120
- return ;
121
- }
122
-
100
+ function renameNgrxDataModule ( ) {
101
+ return ( host : Tree ) => {
102
+ visitTSSourceFiles ( host , sourceFile => {
123
103
const ngrxDataImports = sourceFile . statements
124
104
. filter ( ts . isImportDeclaration )
125
105
. filter (
@@ -137,12 +117,7 @@ function renameNgrxDataModule(options: EntityDataOptions) {
137
117
...findNgrxDataReplacements ( sourceFile ) ,
138
118
] ;
139
119
140
- if ( changes . length === 0 ) {
141
- return ;
142
- }
143
-
144
- const recorder = createChangeRecorder ( host , path , changes ) ;
145
- host . commitUpdate ( recorder ) ;
120
+ commitChanges ( host , sourceFile . fileName , changes ) ;
146
121
} ) ;
147
122
} ;
148
123
}
@@ -290,7 +265,7 @@ export default function(options: EntityDataOptions): Rule {
290
265
options . migrateNgrxData
291
266
? chain ( [
292
267
removeAngularNgRxDataFromPackageJson ( ) ,
293
- renameNgrxDataModule ( options ) ,
268
+ renameNgrxDataModule ( ) ,
294
269
] )
295
270
: addEntityDataToNgModule ( options ) ,
296
271
] ) ( host , context ) ;
0 commit comments