@@ -39,30 +39,48 @@ const uploadPathTypes = process.argv[4].split(',')
39
39
runMain ( async ( ) => {
40
40
const awsConfig = AWS_CONFIG [ env ]
41
41
let cloudfrontPathsToInvalidate = [ ]
42
- for ( const { packageName } of packages ) {
43
- const bundleFolder = buildBundleFolder ( packageName )
44
- for ( const uploadPathType of uploadPathTypes ) {
45
- let uploadPath
46
- if ( uploadPathType === 'pull-request' ) {
47
- const pr = await fetchPR ( LOCAL_BRANCH )
48
- if ( ! pr ) {
49
- console . log ( 'No pull requests found for the branch' )
50
- return
51
- }
52
- uploadPath = buildPullRequestUploadPath ( packageName , pr . number )
53
- } else if ( uploadPathType === 'root' ) {
54
- uploadPath = buildRootUploadPath ( packageName , version )
55
- } else {
56
- uploadPath = buildDatacenterUploadPath ( uploadPathType , packageName , version )
57
- }
58
- const bundlePath = `${ bundleFolder } /${ buildBundleFileName ( packageName ) } `
42
+ for ( const { packageName, chunks } of packages ) {
43
+ const pathsToInvalidate = await uploadPackage ( awsConfig , packageName , chunks )
44
+ cloudfrontPathsToInvalidate . push ( ...pathsToInvalidate )
45
+ }
46
+ invalidateCloudfront ( awsConfig , cloudfrontPathsToInvalidate )
47
+ } )
48
+
49
+ async function uploadPackage ( awsConfig , packageName , chunks ) {
50
+ const cloudfrontPathsToInvalidate = [ ]
51
+ const bundleFolder = buildBundleFolder ( packageName )
52
+
53
+ for ( const uploadPathType of uploadPathTypes ) {
54
+ for ( const chunkName of chunks ) {
55
+ const uploadPath = await generateUploadPath ( uploadPathType , chunkName , version )
56
+ const bundlePath = `${ bundleFolder } /${ buildBundleFileName ( chunkName ) } `
59
57
60
58
uploadToS3 ( awsConfig , bundlePath , uploadPath )
61
- cloudfrontPathsToInvalidate . push ( `/ ${ uploadPath } ` )
59
+ cloudfrontPathsToInvalidate . push ( uploadPath )
62
60
}
63
61
}
64
- invalidateCloudfront ( awsConfig , cloudfrontPathsToInvalidate )
65
- } )
62
+
63
+ return cloudfrontPathsToInvalidate
64
+ }
65
+
66
+ async function generateUploadPath ( uploadPathType , chunkName , version ) {
67
+ let uploadPath
68
+
69
+ if ( uploadPathType === 'pull-request' ) {
70
+ const pr = await fetchPR ( LOCAL_BRANCH )
71
+ if ( ! pr ) {
72
+ console . log ( 'No pull requests found for the branch' )
73
+ process . exit ( 0 )
74
+ }
75
+ uploadPath = buildPullRequestUploadPath ( chunkName , pr . number )
76
+ } else if ( uploadPathType === 'root' ) {
77
+ uploadPath = buildRootUploadPath ( chunkName , version )
78
+ } else {
79
+ uploadPath = buildDatacenterUploadPath ( uploadPathType , chunkName , version )
80
+ }
81
+
82
+ return uploadPath
83
+ }
66
84
67
85
function uploadToS3 ( awsConfig , bundlePath , uploadPath ) {
68
86
const accessToS3 = generateEnvironmentForRole ( awsConfig . accountId , 'build-stable-browser-agent-artifacts-s3-write' )
0 commit comments