@@ -52,9 +52,10 @@ const createFiles = () => {
5252} ;
5353
5454/**
55+ * @param {{ from: string, to: string } } pattern what the build copies
5556 * @returns {Promise<import("../../").Compilation> } the compilation of one build
5657 */
57- const compile = ( ) => {
58+ const compile = ( pattern ) => {
5859 const webpack = require ( "../.." ) ;
5960 const compiler = webpack ( {
6061 mode : "development" ,
@@ -63,7 +64,7 @@ const compile = () => {
6364 output : {
6465 path : outputPath ,
6566 filename : "bundle.js" ,
66- copy : [ { from : "static" , to : "." } ]
67+ copy : [ pattern ]
6768 }
6869 } ) ;
6970
@@ -87,6 +88,8 @@ const compile = () => {
8788describe ( "CopyPlugin" , ( ) => {
8889 /** @type {import("../../").Compilation } */
8990 let compilation ;
91+ /** @type {import("../../").Compilation | undefined } */
92+ let fromAliasCompilation ;
9093 /** @type {boolean } */
9194 let aliased ;
9295
@@ -95,7 +98,13 @@ describe("CopyPlugin", () => {
9598 rimraf ( tempFolderPath , resolve ) ;
9699 } ) ;
97100 aliased = createFiles ( ) ;
98- compilation = await compile ( ) ;
101+ compilation = await compile ( { from : "static" , to : "." } ) ;
102+ if ( aliased ) {
103+ fromAliasCompilation = await compile ( {
104+ from : "static/alias" ,
105+ to : "aliased"
106+ } ) ;
107+ }
99108 } ) ;
100109
101110 afterAll ( ( done ) => {
@@ -120,6 +129,21 @@ describe("CopyPlugin", () => {
120129 expect ( compilation . getAsset ( "alias/stale.txt" ) ) . toBeUndefined ( ) ;
121130 } ) ;
122131
132+ it ( "should copy nothing when the pattern itself names such a symlink" , ( ) => {
133+ if ( ! fromAliasCompilation ) return ;
134+ // the base resolves into the output directory, so the pattern reaches no
135+ // file and says so rather than copying the build's own output
136+ expect (
137+ [ ...fromAliasCompilation . getAssets ( ) ] . filter ( ( asset ) =>
138+ asset . name . startsWith ( "aliased/" )
139+ )
140+ ) . toHaveLength ( 0 ) ;
141+ expect ( fromAliasCompilation . warnings ) . toHaveLength ( 1 ) ;
142+ expect ( fromAliasCompilation . warnings [ 0 ] . name ) . toBe (
143+ "EmptyCopyPatternWarning"
144+ ) ;
145+ } ) ;
146+
123147 it ( "should not make a file inside the output path a dependency" , ( ) => {
124148 expect ( [ ...compilation . fileDependencies ] ) . not . toContain ( stalePath ) ;
125149 } ) ;
0 commit comments