@@ -91,14 +91,16 @@ function cleanupGeneratedFiles (manifest, { keep = false } = {}) {
9191 filesRemoved : 0 ,
9292 filesRetained : 0 ,
9393 }
94- for ( const framework of manifest . frameworks || [ ] ) {
95- const strategy = framework . generatedTestStrategy
96- addCleanupOutcome (
97- outcome ,
98- cleanupPaths ( getSafeCleanupPaths ( framework , strategy , { includeGeneratedFiles : true } ) ) ,
99- 'files'
100- )
101- addCleanupOutcome ( outcome , cleanupCreatedDirectories ( framework . project . root ) , 'directories' )
94+ if ( manifest . frameworks ) {
95+ for ( const framework of manifest . frameworks ) {
96+ const strategy = framework . generatedTestStrategy
97+ addCleanupOutcome (
98+ outcome ,
99+ cleanupPaths ( getSafeCleanupPaths ( framework , strategy , { includeGeneratedFiles : true } ) ) ,
100+ 'files'
101+ )
102+ addCleanupOutcome ( outcome , cleanupCreatedDirectories ( framework . project . root ) , 'directories' )
103+ }
102104 }
103105 outcome . status = outcome . filesRetained > 0 || outcome . directoriesRetained > 0
104106 ? 'incomplete'
@@ -168,13 +170,15 @@ function initializeRuntimeCleanupFiles (framework, strategy) {
168170 if ( initializedCleanupStrategies . has ( strategy ) ) return
169171
170172 const generatedFiles = new Set ( ( strategy . files || [ ] ) . map ( file => validateGeneratedFilePath ( framework , file . path ) ) )
171- for ( const cleanupPath of strategy . cleanupPaths || [ ] ) {
172- const filename = validateCleanupPath ( framework , cleanupPath )
173- if ( generatedFiles . has ( filename ) || isDirectory ( filename ) || ! isNamespacedRuntimeFile ( filename ) ) continue
174- if ( fs . existsSync ( filename ) ) {
175- throw new Error ( `Refusing to delete pre-existing generated validation runtime file: ${ filename } ` )
173+ if ( strategy . cleanupPaths ) {
174+ for ( const cleanupPath of strategy . cleanupPaths ) {
175+ const filename = validateCleanupPath ( framework , cleanupPath )
176+ if ( generatedFiles . has ( filename ) || isDirectory ( filename ) || ! isNamespacedRuntimeFile ( filename ) ) continue
177+ if ( fs . existsSync ( filename ) ) {
178+ throw new Error ( `Refusing to delete pre-existing generated validation runtime file: ${ filename } ` )
179+ }
180+ authorizedRuntimeCleanupFiles . set ( filename , authorizePathForCleanup ( framework . project . root , filename ) )
176181 }
177- authorizedRuntimeCleanupFiles . set ( filename , authorizePathForCleanup ( framework . project . root , filename ) )
178182 }
179183 initializedCleanupStrategies . add ( strategy )
180184}
@@ -183,20 +187,24 @@ function getSafeCleanupPaths (framework, strategy, { includeGeneratedFiles }) {
183187 if ( ! strategy ) return [ ]
184188
185189 const generatedFiles = new Set ( )
186- for ( const file of strategy . files || [ ] ) {
187- generatedFiles . add ( validateGeneratedFilePath ( framework , file . path ) )
190+ if ( strategy . files ) {
191+ for ( const file of strategy . files ) {
192+ generatedFiles . add ( validateGeneratedFilePath ( framework , file . path ) )
193+ }
188194 }
189195
190196 const cleanupPaths = [ ]
191- for ( const cleanupPath of strategy . cleanupPaths || [ ] ) {
192- const filename = validateCleanupPath ( framework , cleanupPath )
193- if ( generatedFiles . has ( filename ) ) {
194- if ( includeGeneratedFiles && writtenGeneratedFiles . has ( filename ) ) cleanupPaths . push ( filename )
195- continue
196- }
197+ if ( strategy . cleanupPaths ) {
198+ for ( const cleanupPath of strategy . cleanupPaths ) {
199+ const filename = validateCleanupPath ( framework , cleanupPath )
200+ if ( generatedFiles . has ( filename ) ) {
201+ if ( includeGeneratedFiles && writtenGeneratedFiles . has ( filename ) ) cleanupPaths . push ( filename )
202+ continue
203+ }
197204
198- if ( authorizedRuntimeCleanupFiles . has ( filename ) ) {
199- cleanupPaths . push ( filename )
205+ if ( authorizedRuntimeCleanupFiles . has ( filename ) ) {
206+ cleanupPaths . push ( filename )
207+ }
200208 }
201209 }
202210
@@ -264,10 +272,12 @@ function authorizePathForCleanup (root, filename) {
264272}
265273
266274function pinRuntimeCleanupParents ( strategy ) {
267- for ( const cleanupPath of strategy . cleanupPaths || [ ] ) {
268- const authorization = authorizedRuntimeCleanupFiles . get ( path . resolve ( cleanupPath ) )
269- if ( authorization && authorization . physicalParent === undefined ) {
270- pinCleanupParent ( authorization , cleanupPath )
275+ if ( strategy . cleanupPaths ) {
276+ for ( const cleanupPath of strategy . cleanupPaths ) {
277+ const authorization = authorizedRuntimeCleanupFiles . get ( path . resolve ( cleanupPath ) )
278+ if ( authorization && authorization . physicalParent === undefined ) {
279+ pinCleanupParent ( authorization , cleanupPath )
280+ }
271281 }
272282 }
273283}
0 commit comments