@@ -266,38 +266,65 @@ async function executeBuildFlow<T extends FolderAsDomainEntry[]>(
266266 const { tag} = PROVIDER_REPO_MAP [ repoType ] ;
267267 const legacyProtonPacking = repoType === "proton-calendar" ;
268268
269- // TODO move block to "folderAsDomainEntry" loop if "node_modules" gets patched
270- if (
271- ! fsExtra . pathExistsSync ( path . join ( repoDir , ".git" ) )
272- ||
273- ! ( await execShell ( [ "git" , [ "tag" ] , { cwd : repoDir } ] , { printStdOut : false } ) ) . stdout . trim ( ) . includes ( tag )
274- ) { // cloning
275- await execShell ( [ "npx" , [ "--no" , "rimraf" , repoDir ] ] ) ;
276- fsExtra . ensureDirSync ( repoDir ) ;
277- await execShell ( [ "git" , [ "clone" , "https://github.com/ProtonMail/WebClients.git" , repoDir ] ] ) ;
278- await execShell ( [ "git" , [ "show" , "--summary" ] , { cwd : repoDir } ] ) ;
279- } else {
280- await execShell ( [ "git" , [ "reset" , "--hard" , "origin/main" ] , { cwd : repoDir } ] ) ;
281- await execShell ( [ "git" , [ "clean" , "-fdx" , "--exclude" , ".yarn/cache" ] , { cwd : repoDir } ] ) ;
282- }
269+ const state : { buildingSetup : ( ) => Promise < void > } = {
270+ async buildingSetup ( ) {
271+ state . buildingSetup = async ( ) => Promise . resolve ( ) ; // one run per "repo type" only needed
272+
273+ // TODO move block to "folderAsDomainEntry" loop if "node_modules" gets patched
274+ if (
275+ ! fsExtra . pathExistsSync ( path . join ( repoDir , ".git" ) )
276+ ||
277+ ! ( await execShell ( [ "git" , [ "tag" ] , { cwd : repoDir } ] , { printStdOut : false } ) ) . stdout . trim ( ) . includes ( tag )
278+ ) { // cloning
279+ await execShell ( [ "npx" , [ "--no" , "rimraf" , repoDir ] ] ) ;
280+ fsExtra . ensureDirSync ( repoDir ) ;
281+ await execShell ( [ "git" , [ "clone" , "https://github.com/ProtonMail/WebClients.git" , repoDir ] ] ) ;
282+ await execShell ( [ "git" , [ "show" , "--summary" ] , { cwd : repoDir } ] ) ;
283+ } else {
284+ await execShell ( [ "git" , [ "reset" , "--hard" , "origin/main" ] , { cwd : repoDir } ] ) ;
285+ await execShell ( [ "git" , [ "clean" , "-fdx" ] , { cwd : repoDir } ] ) ;
286+ }
283287
284- await execShell ( [ "git" , [ "reset" , "--hard" , tag ] , { cwd : repoDir } ] ) ;
285- await execShell ( [ "yarn" , [ "install" ] , { cwd : repoDir } ] , { printStdOut : false } ) ;
288+ await execShell ( [ "git" , [ "reset" , "--hard" , tag ] , { cwd : repoDir } ] ) ;
289+
290+ // TODO "drop yarn install" hacks when executed on CI env
291+ if ( process . env . CI ) {
292+ // hacks applied to avoid the following error:
293+ // eslint-disable-next-line max-len
294+ // YN0018: │ sieve.js@https://github.com/ProtonMail/sieve.js.git#commit=a09ab52092164af74278e77612a091e730e9b7e9: The remote archive doesn't match the expected checksum
295+ // see https://github.com/yarnpkg/berry/issues/1142 and https://github.com/yarnpkg/berry/issues/1989 for details
296+ await execShell ( [ "yarn" , [ "cache" , "clean" , "--all" ] , { cwd : repoDir } ] ) ;
297+ await execShell ( [
298+ "yarn" , [ "install" ] ,
299+ {
300+ cwd : repoDir ,
301+ env : {
302+ ...process . env ,
303+ YARN_CHECKSUM_BEHAVIOR : "update" ,
304+ PUPPETEER_SKIP_CHROMIUM_DOWNLOAD : "1" ,
305+ } ,
306+ } ,
307+ ] ) ;
308+ } else {
309+ await execShell ( [ "yarn" , [ "install" ] , { cwd : repoDir } ] , { printStdOut : false } ) ;
310+ }
286311
287- { // patching
288- const resolvePatchFile = ( file : string ) : string => path . join ( CWD_ABSOLUTE_DIR , `./patches/protonmail/${ file } ` ) ;
289- const repoTypePatchFile = resolvePatchFile ( `${ repoType } .patch` ) ;
312+ { // patching
313+ const resolvePatchFile = ( file : string ) : string => path . join ( CWD_ABSOLUTE_DIR , `./patches/protonmail/${ file } ` ) ;
314+ const repoTypePatchFile = resolvePatchFile ( `${ repoType } .patch` ) ;
290315
291- await applyPatch ( { patchFile : resolvePatchFile ( "common.patch" ) , cwd : repoDir } ) ;
316+ await applyPatch ( { patchFile : resolvePatchFile ( "common.patch" ) , cwd : repoDir } ) ;
292317
293- if ( ! legacyProtonPacking ) {
294- await applyPatch ( { patchFile : resolvePatchFile ( "except-calendar.patch" ) , cwd : repoDir } ) ;
295- }
318+ if ( ! legacyProtonPacking ) {
319+ await applyPatch ( { patchFile : resolvePatchFile ( "except-calendar.patch" ) , cwd : repoDir } ) ;
320+ }
296321
297- if ( fsExtra . pathExistsSync ( repoTypePatchFile ) ) {
298- await applyPatch ( { patchFile : repoTypePatchFile , cwd : repoDir } ) ;
299- }
300- }
322+ if ( fsExtra . pathExistsSync ( repoTypePatchFile ) ) {
323+ await applyPatch ( { patchFile : repoTypePatchFile , cwd : repoDir } ) ;
324+ }
325+ }
326+ } ,
327+ } ;
301328
302329 for ( const folderAsDomainEntry of folderAsDomainEntries ) {
303330 const targetDistDir = path . resolve ( destDir , folderAsDomainEntry . folderNameAsDomain , destSubFolder ) ;
@@ -307,8 +334,8 @@ async function executeBuildFlow<T extends FolderAsDomainEntry[]>(
307334 JSON . stringify ( { ...folderAsDomainEntry , resolvedDistDir : targetDistDir } ) ,
308335 ) ;
309336
310- if ( fsExtra . pathExistsSync ( path . join ( targetDistDir , "index.html" ) ) ) {
311- CONSOLE_LOG ( "Skip building as directory already exists:" , targetDistDir ) ;
337+ if ( fsExtra . pathExistsSync ( path . join ( targetDistDir , WEB_CLIENTS_BLANK_HTML_FILE_NAME ) ) ) {
338+ CONSOLE_LOG ( "Skip building as bundle already exists:" , targetDistDir ) ;
312339 continue ;
313340 }
314341
@@ -324,6 +351,8 @@ async function executeBuildFlow<T extends FolderAsDomainEntry[]>(
324351 if ( shouldFailOnBuild ) {
325352 throw new Error ( `Halting since "${ shouldFailOnBuildEnvVarName } " env var has been enabled` ) ;
326353 } else { // building
354+ await state . buildingSetup ( ) ;
355+
327356 const { configApiParam} = await configure ( { cwd : appDir , repoType} , folderAsDomainEntry ) ;
328357 const publicPath : string | undefined = repoType !== "proton-mail"
329358 ? `/${ PROVIDER_REPO_MAP [ repoType ] . baseDirName } /`
0 commit comments