@@ -29,27 +29,30 @@ import stringReplacer from "../processors/stringReplacer.js";
2929 * @param {string } parameters.options.pattern Pattern to locate the files to be processed
3030 * @returns {Promise<undefined> } Promise resolving with <code>undefined</code> once data has been written
3131 */
32- export default function ( { workspace, options : { copyright, pattern} } ) {
32+ export default async function ( { workspace, buildCache , options : { copyright, pattern} } ) {
3333 if ( ! copyright ) {
34- return Promise . resolve ( ) ;
34+ return ;
3535 }
3636
3737 // Replace optional placeholder ${currentYear} with the current year
3838 copyright = copyright . replace ( / (?: \$ \{ c u r r e n t Y e a r \} ) / , new Date ( ) . getFullYear ( ) ) ;
3939
40- return workspace . byGlob ( pattern )
41- . then ( ( processedResources ) => {
42- return stringReplacer ( {
43- resources : processedResources ,
44- options : {
45- pattern : / (?: \$ \{ c o p y r i g h t \} | @ c o p y r i g h t @ ) / g,
46- replacement : copyright
47- }
48- } ) ;
49- } )
50- . then ( ( processedResources ) => {
51- return Promise . all ( processedResources . map ( ( resource ) => {
52- return workspace . write ( resource ) ;
53- } ) ) ;
54- } ) ;
40+ let resources = await workspace . byGlob ( pattern ) ;
41+ if ( buildCache . hasCache ( ) ) {
42+ const changedPaths = buildCache . getChangedProjectResourcePaths ( ) ;
43+ resources = resources . filter ( ( resource ) => changedPaths . has ( resource . getPath ( ) ) ) ;
44+ }
45+
46+ const processedResources = await stringReplacer ( {
47+ resources,
48+ options : {
49+ pattern : / (?: \$ \{ c o p y r i g h t \} | @ c o p y r i g h t @ ) / g,
50+ replacement : copyright
51+ }
52+ } ) ;
53+ return Promise . all ( processedResources . map ( ( resource ) => {
54+ if ( resource ) {
55+ return workspace . write ( resource ) ;
56+ }
57+ } ) ) ;
5558}
0 commit comments