@@ -83,8 +83,43 @@ const flipFuses = async (context) => {
8383 await context . packager . addElectronFuses ( context , newFuses ) ;
8484} ;
8585
86+ /**
87+ * @param {string } directory
88+ * @param {Date } date
89+ */
90+ const recursivelySetFileTimes = ( directory , date ) => {
91+ const files = fs . readdirSync ( directory ) ;
92+ for ( const file of files ) {
93+ const filePath = pathUtil . join ( directory , file ) ;
94+ const stat = fs . statSync ( filePath ) ;
95+ if ( stat . isDirectory ( ) ) {
96+ recursivelySetFileTimes ( filePath , date ) ;
97+ } else {
98+ fs . utimesSync ( filePath , date , date ) ;
99+ }
100+ }
101+ fs . utimesSync ( directory , date , date ) ;
102+ } ;
103+
104+ /**
105+ * @returns {Date }
106+ */
107+ const getSourceDateEpoch = ( ) => {
108+ // Standard variable for defining the time for a build
109+ // https://reproducible-builds.org/docs/source-date-epoch/
110+ if ( process . env . SOURCE_DATE_EPOCH ) {
111+ return new Date ( ( + process . env . SOURCE_DATE_EPOCH ) * 1000 ) ;
112+ }
113+
114+ // Otherwise, use an arbitrary constant date to ensure builds are still
115+ // reproducible even without SOURCE_DATE_EPOCH being set. This constant is
116+ // from commit 35045e7c0fa4e4e14b2747e967adb4029cedb945.
117+ return new Date ( 1609809111000 ) ;
118+ } ;
119+
86120const afterPack = async ( context ) => {
87121 await flipFuses ( context ) ;
122+ recursivelySetFileTimes ( context . appOutDir , getSourceDateEpoch ( ) ) ;
88123} ;
89124
90125const build = async ( {
0 commit comments