@@ -64,9 +64,10 @@ const createFiles = () => {
6464/**
6565 * @param {{ from: string, to: string, globOptions?: { followSymlinks?: boolean, ignore?: string[] } } } pattern what the build copies
6666 * @param {((copiedPath: string) => boolean | void)= } ignore what to tap the `ignore` hook with
67+ * @param {Record<string, EXPECTED_ANY>= } inputFileSystemOverrides members to replace on the input file system
6768 * @returns {Promise<import("../../").Compilation> } the compilation of one build
6869 */
69- const compile = ( pattern , ignore ) => {
70+ const compile = ( pattern , ignore , inputFileSystemOverrides ) => {
7071 const webpack = require ( "../.." ) ;
7172 const compiler = webpack ( {
7273 mode : "development" ,
@@ -91,6 +92,12 @@ const compile = (pattern, ignore) => {
9192 compiler . outputFileSystem = /** @type {EXPECTED_ANY } */ (
9293 createFsFromVolume ( new Volume ( ) )
9394 ) ;
95+ if ( inputFileSystemOverrides ) {
96+ compiler . inputFileSystem = Object . assign (
97+ Object . create ( compiler . inputFileSystem ) ,
98+ inputFileSystemOverrides
99+ ) ;
100+ }
94101
95102 return new Promise ( ( resolve , reject ) => {
96103 compiler . run ( ( err , stats ) => {
@@ -207,6 +214,62 @@ describe("CopyPlugin", () => {
207214 ) . toBeUndefined ( ) ;
208215 } ) ;
209216
217+ it ( "should skip a link globOptions.ignore names when not following" , async ( ) => {
218+ if ( ! fileAliased ) return ;
219+ const ignored = await compile ( {
220+ from : "static" ,
221+ to : "." ,
222+ globOptions : { followSymlinks : false , ignore : [ "**/stale-link.txt" ] }
223+ } ) ;
224+ expect ( ignored . getAsset ( "stale-link.txt" ) ) . toBeUndefined ( ) ;
225+ expect ( ignored . getAsset ( "keep.txt" ) ) . toBeDefined ( ) ;
226+ } ) ;
227+
228+ it ( "should treat a glob from as a glob when not following" , async ( ) => {
229+ // `lstat` reports the glob missing, which says it is no link either
230+ const globbed = await compile ( {
231+ from : "static/*.txt" ,
232+ to : "globbed" ,
233+ globOptions : { followSymlinks : false }
234+ } ) ;
235+ expect ( globbed . getAsset ( "globbed/keep.txt" ) ) . toBeDefined ( ) ;
236+ expect ( globbed . errors ) . toHaveLength ( 0 ) ;
237+ } ) ;
238+
239+ it ( "should copy a file from as a file on a file system without lstat" , async ( ) => {
240+ const withoutLstat = await compile (
241+ {
242+ from : "static/keep.txt" ,
243+ to : "plain" ,
244+ globOptions : { followSymlinks : false }
245+ } ,
246+ undefined ,
247+ { lstat : undefined }
248+ ) ;
249+ expect ( withoutLstat . getAsset ( "plain/keep.txt" ) ) . toBeDefined ( ) ;
250+ expect ( withoutLstat . errors ) . toHaveLength ( 0 ) ;
251+ } ) ;
252+
253+ it ( "should report an lstat failure other than a missing path" , async ( ) => {
254+ const failing = await compile (
255+ {
256+ from : "static/keep.txt" ,
257+ to : "failing" ,
258+ globOptions : { followSymlinks : false }
259+ } ,
260+ undefined ,
261+ {
262+ lstat : (
263+ /** @type {string } */ _path ,
264+ /** @type {(err: NodeJS.ErrnoException) => void } */ callback
265+ ) => callback ( Object . assign ( new Error ( "lstat failed" ) , { code : "EIO" } ) )
266+ }
267+ ) ;
268+ expect ( failing . getAsset ( "failing/keep.txt" ) ) . toBeUndefined ( ) ;
269+ expect ( failing . errors . length ) . toBeGreaterThan ( 0 ) ;
270+ expect ( String ( failing . errors [ 0 ] . message ) ) . toContain ( "lstat failed" ) ;
271+ } ) ;
272+
210273 it ( "should report no error or warning" , ( ) => {
211274 expect ( compilation . errors ) . toHaveLength ( 0 ) ;
212275 expect ( compilation . warnings ) . toHaveLength ( 0 ) ;
0 commit comments