@dotcom-tool-kit/upload-assets-to-s3 2.0.13 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.toolkitrc.yml CHANGED
@@ -1,10 +1,2 @@
1
1
  hooks:
2
2
  'release:remote': UploadAssetsToS3
3
-
4
- options:
5
- '@dotcom-tool-kit/upload-static-assets':
6
- directory: 'public'
7
- bucket: 'ft-next-hashed-assets-prod'
8
- destination: 'hashed-assets/uploaded'
9
- extensions: 'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json'
10
- cacheControl: 'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600'
package/README.md CHANGED
@@ -21,13 +21,14 @@ plugins:
21
21
  ## Options
22
22
  | Key | Description | Default value |
23
23
  |-|-|-|
24
- | `accessKeyIdEnvVar` | variable name of the project's aws access key id | no default value - for backwards compatability the plugin falls back to the default value for `accessKeyId` |
24
+ | `accessKeyIdEnvVar` | variable name of the project's aws access key id. If uploading to multiple buckets the same credentials will need to work for all. | no default value - for backwards compatability the plugin falls back to the default value for `accessKeyId` |
25
25
  | `secretAccessKeyEnvVar` | variable name of the project's aws secret access key | no default value - for backwards compatability the plugin falls back to the default value for `secretAccessKey` |
26
26
  | `accessKeyId` | **DEPRECATED** variable name of the project's aws access key id | 'aws_access_hashed_assets' |
27
27
  | `secretAccessKey` | **DEPRECATED** variable name of the project's aws secret access key | 'aws_secret_hashed_assets' |
28
28
  | `directory` | the folder in the project whose contents will be uploaded to S3 | 'public' |
29
- | `reviewBucket` | the development or test S3 bucket | ['ft-next-hashed-assets-preview'] |
30
- | `prodBucket` | production S3 bucket/s; an array of strings. The same files will be uploaded to each | ['ft-next-hashed-assets-prod', 'ft-next-hashed-assets-prod-us'] |
29
+ | `reviewBucket` | the development or test S3 bucket | `['ft-next-hashed-assets-preview']` |
30
+ | `prodBucket` | production S3 bucket/s; an array of strings. The same files will be uploaded to each. _Note: most Customer Products buckets that have a `prod` and `prod-us` version are already configured in AWS to replicate file changes from one to the other so you don't need to specify both here. Also, if multiple buckets are specified the same credentials will need to be valid for both for the upload to be successful_ | `['ft-next-hashed-assets-prod']` |
31
+ | `region` | the AWS region your buckets are stored in (let the Platforms team know if you need to upload to multiple buckets in multiple regions) | eu-west-1 |
31
32
  | `destination` | the destination folder for uploaded assets. Set to `''` to upload assets to the top level of the bucket | 'hashed-assets/page-kit' |
32
33
  | `extensions` | file extensions to be uploaded to S3 | 'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json' |
33
34
  | `cacheControl` | header that controls how long your files stay in a CloudFront cache before CloudFront forwards another request to your origin | 'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600' |
@@ -38,7 +39,7 @@ Example:
38
39
  '@dotcom-tool-kit/upload-assets-to-s3':
39
40
  accessKeyId: AWS_ACCESS
40
41
  secretAccessKey: AWS_KEY
41
- prodBucket: ['ft-next-service-registry-prod', 'ft-next-service-registry-prod-us']
42
+ prodBucket: ['ft-next-service-registry-prod']
42
43
  reviewBucket: ['ft-next-service-registry-dev']
43
44
  destination: ''
44
45
  ```
package/lib/index.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tasks = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const upload_assets_to_s3_1 = (0, tslib_1.__importDefault)(require("./tasks/upload-assets-to-s3"));
5
+ const upload_assets_to_s3_1 = tslib_1.__importDefault(require("./tasks/upload-assets-to-s3"));
6
6
  exports.tasks = [upload_assets_to_s3_1.default];
@@ -1,11 +1,10 @@
1
1
  import { Task } from '@dotcom-tool-kit/types';
2
- import aws from 'aws-sdk';
2
+ import { S3Client } from '@aws-sdk/client-s3';
3
3
  import { UploadAssetsToS3Options, UploadAssetsToS3Schema } from '@dotcom-tool-kit/types/lib/schema/upload-assets-to-s3';
4
4
  export default class UploadAssetsToS3 extends Task<typeof UploadAssetsToS3Schema> {
5
5
  static description: string;
6
- static defaultOptions: UploadAssetsToS3Options;
7
6
  run(): Promise<void>;
8
- uploadFile(file: string, options: UploadAssetsToS3Options, s3: aws.S3): Promise<void>;
7
+ uploadFile(file: string, options: UploadAssetsToS3Options, s3: S3Client): Promise<void>;
9
8
  uploadAssetsToS3(options: UploadAssetsToS3Options): Promise<void>;
10
9
  }
11
10
  //# sourceMappingURL=upload-assets-to-s3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"upload-assets-to-s3.d.ts","sourceRoot":"","sources":["../../src/tasks/upload-assets-to-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAE7C,OAAO,GAAG,MAAM,SAAS,CAAA;AAMzB,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uDAAuD,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC,OAAO,sBAAsB,CAAC;IAC/E,MAAM,CAAC,WAAW,SAAK;IAEvB,MAAM,CAAC,cAAc,EAAE,uBAAuB,CAS7C;IAEK,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAGpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDrF,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBxE"}
1
+ {"version":3,"file":"upload-assets-to-s3.d.ts","sourceRoot":"","sources":["../../src/tasks/upload-assets-to-s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAE7C,OAAO,EAAE,QAAQ,EAAoB,MAAM,oBAAoB,CAAA;AAM/D,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uDAAuD,CAAA;AAE9D,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,IAAI,CAAC,OAAO,sBAAsB,CAAC;IAC/E,MAAM,CAAC,WAAW,SAAK;IAEjB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAGpB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,EAAE,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAiDvF,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;CAyBxE"}
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const types_1 = require("@dotcom-tool-kit/types");
5
- const fs = (0, tslib_1.__importStar)(require("fs"));
6
- const aws_sdk_1 = (0, tslib_1.__importDefault)(require("aws-sdk"));
7
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
8
- const mime_1 = (0, tslib_1.__importDefault)(require("mime"));
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const client_s3_1 = require("@aws-sdk/client-s3");
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ const mime_1 = tslib_1.__importDefault(require("mime"));
9
9
  const glob_1 = require("glob");
10
10
  const error_1 = require("@dotcom-tool-kit/error");
11
11
  const logger_1 = require("@dotcom-tool-kit/logger");
@@ -33,8 +33,8 @@ class UploadAssetsToS3 extends types_1.Task {
33
33
  CacheControl: options.cacheControl
34
34
  };
35
35
  currentBucket = params.Bucket;
36
- const data = await s3.upload(params).promise();
37
- this.logger.info(`Uploaded ${logger_1.styles.filepath(filepath)} to ${logger_1.styles.URL(data.Location)}`);
36
+ await s3.send(new client_s3_1.PutObjectCommand(params));
37
+ this.logger.info(`Uploaded ${logger_1.styles.filepath(filepath)} to ${logger_1.styles.URL(currentBucket)}`);
38
38
  }
39
39
  else {
40
40
  for (const bucket of bucketByEnv) {
@@ -48,8 +48,8 @@ class UploadAssetsToS3 extends types_1.Task {
48
48
  CacheControl: options.cacheControl
49
49
  };
50
50
  currentBucket = params.Bucket;
51
- const data = await s3.upload(params).promise();
52
- this.logger.info(`Uploaded ${logger_1.styles.filepath(filepath)} to ${logger_1.styles.URL(data.Location)}`);
51
+ await s3.send(new client_s3_1.PutObjectCommand(params));
52
+ this.logger.info(`Uploaded ${logger_1.styles.filepath(filepath)} to ${logger_1.styles.URL(currentBucket)}`);
53
53
  }
54
54
  }
55
55
  }
@@ -67,30 +67,26 @@ class UploadAssetsToS3 extends types_1.Task {
67
67
  const extensions = options.extensions.includes(',') ? `{${options.extensions}}` : options.extensions;
68
68
  const globFile = `**/*${extensions}`;
69
69
  const files = glob_1.glob.sync(globFile, { cwd: options.directory, nodir: true });
70
- const s3 = new aws_sdk_1.default.S3({
70
+ if (files.length === 0) {
71
+ throw new error_1.ToolKitError(`no files found at the provided directory: ${options.directory}`);
72
+ }
73
+ const s3 = new client_s3_1.S3Client({
74
+ region: options.region,
71
75
  // fallback to default value for accessKeyId if neither accessKeyIdEnvVar or accessKeyId have been provided as options
72
- accessKeyId:
73
- /* eslint-disable-next-line */
74
- process.env[(_a = options.accessKeyIdEnvVar) !== null && _a !== void 0 ? _a : options.accessKeyId],
75
- secretAccessKey:
76
- /* eslint-disable-next-line */
77
- process.env[(_b = options.secretAccessKeyEnvVar) !== null && _b !== void 0 ? _b : options.secretAccessKey]
76
+ credentials: {
77
+ accessKeyId:
78
+ /* eslint-disable-next-line */
79
+ process.env[(_a = options.accessKeyIdEnvVar) !== null && _a !== void 0 ? _a : options.accessKeyId],
80
+ secretAccessKey:
81
+ /* eslint-disable-next-line */
82
+ process.env[(_b = options.secretAccessKeyEnvVar) !== null && _b !== void 0 ? _b : options.secretAccessKey]
83
+ }
78
84
  });
79
85
  await Promise.all(files.map((file) => this.uploadFile(file, options, s3)));
80
86
  }
81
87
  }
82
88
  exports.default = UploadAssetsToS3;
83
89
  UploadAssetsToS3.description = '';
84
- UploadAssetsToS3.defaultOptions = {
85
- accessKeyId: 'aws_access_hashed_assets',
86
- secretAccessKey: 'aws_secret_hashed_assets',
87
- directory: 'public',
88
- reviewBucket: ['ft-next-hashed-assets-preview'],
89
- prodBucket: ['ft-next-hashed-assets-prod', 'ft-next-hashed-assets-prod-us'],
90
- destination: 'hashed-assets/page-kit',
91
- extensions: 'js,css,map,gz,br,png,jpg,jpeg,gif,webp,svg,ico,json',
92
- cacheControl: 'public, max-age=31536000, stale-while-revalidate=60, stale-if-error=3600'
93
- };
94
90
  const getFileType = (filename) => {
95
91
  // We need to know the original file type so ignore any compression
96
92
  const originalFile = filename.replace(/\.(br|gz)$/, '');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcom-tool-kit/upload-assets-to-s3",
3
- "version": "2.0.13",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -10,10 +10,10 @@
10
10
  "author": "FT.com Platforms Team <platforms-team.customer-products@ft.com>",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
+ "@aws-sdk/client-s3": "^3.256.0",
13
14
  "@dotcom-tool-kit/error": "^2.0.1",
14
- "@dotcom-tool-kit/logger": "^2.2.0",
15
- "@dotcom-tool-kit/types": "^2.8.0",
16
- "aws-sdk": "^2.901.0",
15
+ "@dotcom-tool-kit/logger": "^2.2.1",
16
+ "@dotcom-tool-kit/types": "^2.9.0",
17
17
  "glob": "^7.1.6",
18
18
  "mime": "^2.5.2",
19
19
  "tslib": "^2.3.1"
@@ -41,6 +41,6 @@
41
41
  "extends": "../../package.json"
42
42
  },
43
43
  "peerDependencies": {
44
- "dotcom-tool-kit": "2.x"
44
+ "dotcom-tool-kit": "^2.6.0"
45
45
  }
46
46
  }