@@ -50,13 +50,17 @@ export class UpdateProject<Context> {
50
50
* @param data Upgrade data that is passed to all migration rules.
51
51
* @param additionalStylesheetPaths Additional stylesheets that should be migrated, if not
52
52
* referenced in an Angular component. This is helpful for global stylesheets in a project.
53
+ * @param limitToDirectory If specified, changes will be limited to the given directory.
53
54
*/
54
55
migrate < Data > (
55
56
migrationTypes : MigrationCtor < Data , Context > [ ] ,
56
57
target : TargetVersion | null ,
57
58
data : Data ,
58
59
additionalStylesheetPaths ?: string [ ] ,
60
+ limitToDirectory ?: string ,
59
61
) : { hasFailures : boolean } {
62
+ limitToDirectory &&= this . _fileSystem . resolve ( limitToDirectory ) ;
63
+
60
64
// Create instances of the specified migrations.
61
65
const migrations = this . _createMigrations ( migrationTypes , target , data ) ;
62
66
// Creates the component resource collector. The collector can visit arbitrary
@@ -65,9 +69,14 @@ export class UpdateProject<Context> {
65
69
const resourceCollector = new ComponentResourceCollector ( this . _typeChecker , this . _fileSystem ) ;
66
70
// Collect all of the TypeScript source files we want to migrate. We don't
67
71
// migrate type definition files, or source files from external libraries.
68
- const sourceFiles = this . _program
69
- . getSourceFiles ( )
70
- . filter ( f => ! f . isDeclarationFile && ! this . _program . isSourceFileFromExternalLibrary ( f ) ) ;
72
+ const sourceFiles = this . _program . getSourceFiles ( ) . filter ( f => {
73
+ return (
74
+ ! f . isDeclarationFile &&
75
+ ( limitToDirectory == null ||
76
+ this . _fileSystem . resolve ( f . fileName ) . startsWith ( limitToDirectory ) ) &&
77
+ ! this . _program . isSourceFileFromExternalLibrary ( f )
78
+ ) ;
79
+ } ) ;
71
80
72
81
// Helper function that visits a given TypeScript node and collects all referenced
73
82
// component resources (i.e. stylesheets or templates). Additionally, the helper
@@ -121,11 +130,13 @@ export class UpdateProject<Context> {
121
130
if ( additionalStylesheetPaths ) {
122
131
additionalStylesheetPaths . forEach ( filePath => {
123
132
const resolvedPath = this . _fileSystem . resolve ( filePath ) ;
124
- const stylesheet = resourceCollector . resolveExternalStylesheet ( resolvedPath , null ) ;
125
- // Do not visit stylesheets which have been referenced from a component.
126
- if ( ! this . _analyzedFiles . has ( resolvedPath ) && stylesheet ) {
127
- migrations . forEach ( r => r . visitStylesheet ( stylesheet ) ) ;
128
- this . _analyzedFiles . add ( resolvedPath ) ;
133
+ if ( limitToDirectory == null || resolvedPath . startsWith ( limitToDirectory ) ) {
134
+ const stylesheet = resourceCollector . resolveExternalStylesheet ( resolvedPath , null ) ;
135
+ // Do not visit stylesheets which have been referenced from a component.
136
+ if ( ! this . _analyzedFiles . has ( resolvedPath ) && stylesheet ) {
137
+ migrations . forEach ( r => r . visitStylesheet ( stylesheet ) ) ;
138
+ this . _analyzedFiles . add ( resolvedPath ) ;
139
+ }
129
140
}
130
141
} ) ;
131
142
}
0 commit comments