@@ -2,7 +2,7 @@ import type { Compiler, Compilation } from 'webpack'
2
2
import type webpack from 'webpack'
3
3
import type { EventEmitter } from 'events'
4
4
import _ from 'lodash'
5
- import fs , { PathLike } from 'fs'
5
+ import fs , { PathLike } from 'fs-extra '
6
6
import path from 'path'
7
7
8
8
type UtimesSync = ( path : PathLike , atime : string | number | Date , mtime : string | number | Date ) => void
@@ -68,6 +68,31 @@ export class CypressCTWebpackPlugin {
68
68
}
69
69
} ;
70
70
71
+ private beforeCompile = async ( compilationParams : object , callback : Function ) => {
72
+ if ( ! this . compilation ) {
73
+ callback ( )
74
+
75
+ return
76
+ }
77
+
78
+ // Ensure we don't try to load files that have been removed from the file system
79
+ // but have not yet been detected by the onSpecsChange handler
80
+
81
+ const foundFiles = ( await Promise . all ( this . files . map ( async ( file ) => {
82
+ try {
83
+ const exists = await fs . pathExists ( file . absolute )
84
+
85
+ return exists ? file : null
86
+ } catch ( e ) {
87
+ return null
88
+ }
89
+ } ) ) )
90
+
91
+ this . files = foundFiles . filter ( ( file ) => file !== null ) as Cypress . Spec [ ]
92
+
93
+ callback ( )
94
+ }
95
+
71
96
/*
72
97
* After compiling, we check for errors and inform the server of them.
73
98
*/
@@ -96,7 +121,7 @@ export class CypressCTWebpackPlugin {
96
121
}
97
122
}
98
123
99
- // After emitting assets, we tell the server complitation was successful
124
+ // After emitting assets, we tell the server compilation was successful
100
125
// so it can trigger a reload the AUT iframe.
101
126
private afterEmit = ( ) => {
102
127
if ( ! this . compilation ?. getStats ( ) . hasErrors ( ) ) {
@@ -152,6 +177,7 @@ export class CypressCTWebpackPlugin {
152
177
const _compiler = compiler as Compiler
153
178
154
179
this . devServerEvents . on ( 'dev-server:specs:changed' , this . onSpecsChange )
180
+ _compiler . hooks . beforeCompile . tapAsync ( 'CypressCTPlugin' , this . beforeCompile )
155
181
_compiler . hooks . afterCompile . tap ( 'CypressCTPlugin' , this . afterCompile )
156
182
_compiler . hooks . afterEmit . tap ( 'CypressCTPlugin' , this . afterEmit )
157
183
_compiler . hooks . compilation . tap ( 'CypressCTPlugin' , ( compilation ) => this . addCompilationHooks ( compilation as Webpack45Compilation ) )
0 commit comments