From 0420790524495d11e6d22764215a55eafd112433 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Mon, 4 Dec 2023 14:52:41 +0000 Subject: [PATCH] Migrate to AWS-SDK V3 syntax --- bin/upload-to-cdn.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/upload-to-cdn.js b/bin/upload-to-cdn.js index 0abc27e7c4..243ef9dc29 100644 --- a/bin/upload-to-cdn.js +++ b/bin/upload-to-cdn.js @@ -24,7 +24,7 @@ const path = require('node:path') const { pipeline, finished } = require('node:stream/promises') const { readFile } = require('node:fs/promises') -const { S3 } = require('@aws-sdk/client-s3'); +const { S3Client, ListObjectsV2Command, PutObjectCommand } = require('@aws-sdk/client-s3'); const packlist = require('npm-packlist') const tar = require('tar') @@ -109,7 +109,7 @@ async function main (packageName, version) { // where we force push a local build if (version?.startsWith('-')) version = undefined // eslint-disable-line no-param-reassign - const s3 = new S3({ + const s3Client = new S3Client({ credentials: { accessKeyId: process.env.EDGLY_KEY, secretAccessKey: process.env.EDGLY_SECRET, @@ -144,11 +144,12 @@ async function main (packageName, version) { const outputPath = path.posix.join(dirName, `v${version}`) - const { Contents: existing } = await s3.listObjects({ + const { Contents: existing } = await s3Client.send(new ListObjectsV2Command({ Bucket: AWS_BUCKET, Prefix: outputPath, - }) - if (existing.length > 0) { + })) + + if (existing?.length > 0) { if (process.argv.includes('--force')) { console.warn(`WARN Release files for ${dirName} v${version} already exist, overwriting...`) } else { @@ -174,16 +175,16 @@ async function main (packageName, version) { for (const [filename, buffer] of files.entries()) { const key = path.posix.join(outputPath, filename) console.log(`pushing s3://${AWS_BUCKET}/${key}`) - await s3.putObject({ + await s3Client.send(new PutObjectCommand({ Bucket: AWS_BUCKET, Key: key, ContentType: mime.lookup(filename), Body: buffer, - }) + })) } } main(...process.argv.slice(2)).catch((err) => { - console.error(err.stack) + console.error(err) process.exit(1) })