Skip to content

Commit 4e2a421

Browse files
committed
Force upgrade all dependencies
Includes fixes for newer TS versions and ESLint rules
1 parent a2180fb commit 4e2a421

File tree

12 files changed

+2006
-2907
lines changed

12 files changed

+2006
-2907
lines changed

.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
{
1818
"argsIgnorePattern": "^_"
1919
}
20+
],
21+
"@typescript-eslint/restrict-template-expressions": [
22+
"error",
23+
{
24+
"allowNullish": true
25+
}
2026
]
2127
},
2228
"reportUnusedDisableDirectives": true,

package-lock.json

Lines changed: 1957 additions & 2869 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
"@types/jest": "^26.0.19",
2828
"@types/minimatch": "^3.0.3",
2929
"@types/node": "^14.14.16",
30-
"@typescript-eslint/eslint-plugin": "^2.34.0",
31-
"@typescript-eslint/parser": "^2.34.0",
32-
"eslint": "^6.8.0",
33-
"jest": "^25.5.4",
30+
"@typescript-eslint/eslint-plugin": "^4.11.0",
31+
"@typescript-eslint/parser": "^4.11.0",
32+
"eslint": "^7.16.0",
33+
"jest": "^26.6.3",
3434
"prettier": "^2.2.1",
35-
"ts-jest": "^25.5.1",
35+
"ts-jest": "^26.4.4",
3636
"ts-loader": "^8.0.12",
37-
"typescript": "^3.9.7",
37+
"typescript": "^4.1.3",
3838
"webpack": "^5.11.0",
39-
"webpack-cli": "^4.2.0"
39+
"webpack-cli": "^4.3.0"
4040
},
4141
"dependencies": {
4242
"aws-sdk": "^2.817.0",

src/__tests__/s3-upload-config-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { S3UploadConfig } from "../s3-upload-config";
44
* Helper function to build an S3UploadConfig while maintaining basic JSON type safety
55
* @param config The config to serialize and construct an S3UploadConfig from
66
*/
7-
function newS3UploadConfig(config: object): S3UploadConfig {
7+
function newS3UploadConfig(config: Record<string, unknown>): S3UploadConfig {
88
return new S3UploadConfig(JSON.stringify(config));
99
}
1010

src/__tests__/simple-fs-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("SimpleFs", () => {
77
let tempDir: string;
88

99
beforeEach(() => {
10-
tempDir = path.join(os.tmpdir(), "__simple-fs-test-dir__" + Math.random());
10+
tempDir = path.join(os.tmpdir(), `__simple-fs-test-dir__${Math.random()}`);
1111
simpleFs.deleteFolder(tempDir);
1212
simpleFs.createFolder(tempDir);
1313
});
@@ -33,7 +33,7 @@ describe("SimpleFs", () => {
3333
test("real file", () => {
3434
const contentsString = simpleFs.readFile("package.json").toString();
3535

36-
const contents: object = JSON.parse(contentsString);
36+
const contents = JSON.parse(contentsString) as Record<string, unknown>;
3737

3838
// Make sure it's a non-trivial object so we're not just lucky that it read some file
3939
expect(Object.keys(contents).length).toBeGreaterThan(1);

src/handler/handle-create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class CreateHandler extends EventHandler {
1919
} catch (e) {
2020
return {
2121
status: ResponseStatus.FAILED,
22-
reason: `Unable to list objects in bucket. (${e})`,
22+
reason: `Unable to list objects in bucket. (${(e as Error).toString()})`,
2323
};
2424
}
2525

@@ -51,7 +51,7 @@ export class CreateHandler extends EventHandler {
5151
} catch (e) {
5252
return {
5353
status: ResponseStatus.FAILED,
54-
reason: `Unable to upload files to S3. (${e})`,
54+
reason: `Unable to upload files to S3. (${(e as Error).toString()})`,
5555
};
5656
}
5757

src/handler/handle-delete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ export class DeleteHandler extends EventHandler {
1717
} catch (e) {
1818
return {
1919
status: ResponseStatus.FAILED,
20-
reason: `Unable to list objects in ${bucketName}. (${e})`,
20+
reason: `Unable to list objects in ${bucketName}. (${(e as Error).toString()})`,
2121
};
2222
}
2323
try {
2424
await Promise.all(keys.map((key) => simpleS3.deleteObject(bucketName, key)));
2525
} catch (e) {
2626
return {
2727
status: ResponseStatus.FAILED,
28-
reason: `Unable to delete objects in ${bucketName}. (${e})`,
28+
reason: `Unable to delete objects in ${bucketName}. (${(e as Error).toString()})`,
2929
};
3030
}
3131

src/handler/handle-update.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class UpdateHandler extends EventHandler {
2020
} catch (e) {
2121
return {
2222
status: ResponseStatus.FAILED,
23-
reason: `Unable to list objects in bucket. (${e})`,
23+
reason: `Unable to list objects in bucket. (${(e as Error).toString()})`,
2424
};
2525
}
2626

@@ -29,7 +29,7 @@ export class UpdateHandler extends EventHandler {
2929
} catch (e) {
3030
return {
3131
status: ResponseStatus.FAILED,
32-
reason: `Unable to delete objects in ${bucketName}. (${e})`,
32+
reason: `Unable to delete objects in ${bucketName}. (${(e as Error).toString()})`,
3333
};
3434
}
3535

@@ -54,7 +54,7 @@ export class UpdateHandler extends EventHandler {
5454
} catch (e) {
5555
return {
5656
status: ResponseStatus.FAILED,
57-
reason: `Unable to upload files to S3. (${e})`,
57+
reason: `Unable to upload files to S3. (${(e as Error).toString()})`,
5858
};
5959
}
6060

src/handler/handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export abstract class EventHandler {
4747
} catch (e) {
4848
await callback({
4949
status: ResponseStatus.FAILED,
50-
reason: `Unable to read or parse ${S3_UPLOAD_CONFIG_FILE}: ${e}`,
50+
reason: `Unable to read or parse ${S3_UPLOAD_CONFIG_FILE}: ${(e as Error).toString()}`,
5151
});
5252
return;
5353
}
@@ -59,14 +59,14 @@ export abstract class EventHandler {
5959
} catch (e) {
6060
result = {
6161
status: ResponseStatus.FAILED,
62-
reason: `Failure when handling event. (${e})`,
62+
reason: `Failure when handling event. (${(e as Error).toString()})`,
6363
};
6464
}
6565

6666
await callback(result);
6767
}
6868

69-
protected abstract async handleEvent(
69+
protected abstract handleEvent(
7070
parameters: RequestParameters,
7171
simpleS3: SimpleS3,
7272
simpleFs: SimpleFs,

src/index.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function getObjectPrefix(event: CloudformationEvent): string | undefined {
2121
function validateArguments(event: CloudformationEvent): void {
2222
const bucketName = getNewBucketName(event);
2323
if (!bucketName) {
24-
throw `${CustomParameters.BUCKET_NAME} must be specified.`;
24+
throw new Error(`${CustomParameters.BUCKET_NAME} must be specified.`);
2525
}
2626
}
2727

2828
function computePhysicalId(event: CloudformationEvent): string {
29-
return `Bucket:${getNewBucketName(event)} ObjectPrefix: ${getObjectPrefix(event)}`;
29+
return `Bucket: ${getNewBucketName(event)} ObjectPrefix: ${getObjectPrefix(event)}`;
3030
}
3131

3232
// Send response to the pre-signed S3 URL
@@ -35,7 +35,7 @@ async function sendResponse(
3535
context: CloudformationContext,
3636
responseStatus: ResponseStatus,
3737
responseReason?: string,
38-
responseData?: object
38+
responseData?: Record<string, unknown>
3939
): Promise<void> {
4040
const responseBody = JSON.stringify({
4141
Status: responseStatus,
@@ -63,16 +63,16 @@ async function sendResponse(
6363

6464
console.log("SENDING RESPONSE...\n");
6565

66-
await new Promise((resolve, reject) => {
66+
await new Promise<void>((resolve, reject) => {
6767
const request = https.request(options, function (response) {
68-
console.log("STATUS: " + response.statusCode);
69-
console.log("HEADERS: " + JSON.stringify(response.headers));
68+
console.log(`STATUS: ${response.statusCode}`);
69+
console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
7070
// Tell AWS Lambda that the function execution is done
7171
resolve();
7272
});
7373

7474
request.on("error", function (error) {
75-
console.log("sendResponse Error:" + error);
75+
console.log("sendResponse Error: ", error);
7676
// Tell AWS Lambda that the function execution is done
7777
reject();
7878
});
@@ -84,10 +84,7 @@ async function sendResponse(
8484
});
8585
}
8686

87-
exports.handler = async function (
88-
event: CloudformationEvent,
89-
context: CloudformationContext
90-
): Promise<void> {
87+
async function handler(event: CloudformationEvent, context: CloudformationContext): Promise<void> {
9188
console.log("REQUEST RECEIVED:\n" + JSON.stringify(event));
9289

9390
const callback: ResultCallback = async (result: ResultType) => {
@@ -96,10 +93,10 @@ exports.handler = async function (
9693

9794
try {
9895
validateArguments(event);
99-
} catch (errorMessage) {
96+
} catch (e) {
10097
return await callback({
10198
status: ResponseStatus.FAILED,
102-
reason: errorMessage,
99+
reason: (e as Error).toString(),
103100
});
104101
}
105102

@@ -113,7 +110,10 @@ exports.handler = async function (
113110
default:
114111
return await callback({
115112
status: ResponseStatus.FAILED,
116-
reason: `Unknown request type ${event.RequestType}`,
113+
reason: `Unknown request type ${event.RequestType as string}`,
117114
});
118115
}
119-
};
116+
}
117+
118+
declare const exports: Record<string, unknown>;
119+
exports.handler = handler;

0 commit comments

Comments
 (0)