From e5d6bc1781abe7d79e06f5a280ce5f39668709a2 Mon Sep 17 00:00:00 2001 From: Robert Lucian Chiriac Date: Fri, 20 Dec 2024 15:14:54 +0200 Subject: [PATCH] Address PR comments --- bin/cdklocal | 19 +++++++++++-------- package-lock.json | 28 ++++++++++++++-------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/bin/cdklocal b/bin/cdklocal index 6925889..819a6e1 100755 --- a/bin/cdklocal +++ b/bin/cdklocal @@ -18,7 +18,6 @@ const EDGE_PORT = process.env.EDGE_PORT || DEFAULT_EDGE_PORT; const DEFAULT_HOSTNAME = "localhost"; const LAMBDA_MOUNT_CODE = isEnvTrue("LAMBDA_MOUNT_CODE"); const PROTOCOL = isEnvTrue("USE_SSL") ? "https" : "http"; -const DEBUG_ON = process.env.DEBUG === "1"; //---------------- @@ -29,6 +28,14 @@ const getLocalEndpoint = async () => process.env.AWS_ENDPOINT_URL || `${PROTOCOL var resolvedHostname = undefined; +const runAsyncFunctionAsSync = (asyncFn) => { + return (...args) => { + asyncFn(...args).catch((e) => { + console.error(e); + }); + }; +}; + const getLocalHost = async () => { if (resolvedHostname) { // early exit to not resolve again @@ -207,10 +214,6 @@ const patchCurrentAccount = (SDK) => { const patchToolkitInfo = (ToolkitInfo) => { const setBucketUrl = function setBucketUrl(object, bucket, domain) { const newBucketUrl = `https://${domain.replace(`${bucket}.`, "")}:${EDGE_PORT}/${bucket}`; - if (DEBUG_ON) { - console.debug("Old bucketUrl:", object.bucketUrl); - console.debug("New bucketUrl:", newBucketUrl); - } Object.defineProperty(object, "bucketUrl", { get() { return newBucketUrl; @@ -221,7 +224,7 @@ const patchToolkitInfo = (ToolkitInfo) => { // Pre-fetch the necessary values for the bucket URL const prefetchBucketUrl = async (object) => { // Has been observed that the object is not always an instance of ToolkitInfo - if (object != {}) { + if (object && Object.prototype.hasOwnProperty.call(object, "bucketName") && Object.prototype.hasOwnProperty.call(object, "bucketUrl")) { try { const bucket = object.bucketName; const domain = object.bucketUrl.replace("https://", "") || await getLocalHost(); @@ -241,7 +244,7 @@ const patchToolkitInfo = (ToolkitInfo) => { }; // for compatibility with with older versions of CDK - prefetchBucketUrl(ToolkitInfo.prototype); + runAsyncFunctionAsSync(prefetchBucketUrl(ToolkitInfo.prototype)); const cdkLookupFn = ToolkitInfo.lookup; ToolkitInfo.lookup = async (...args) => { @@ -253,7 +256,7 @@ const patchToolkitInfo = (ToolkitInfo) => { const fromStackFn = ToolkitInfo.fromStack; ToolkitInfo.fromStack = (...args) => { const toolkitInfoObject = fromStackFn(...args); - prefetchBucketUrl(toolkitInfoObject); + runAsyncFunctionAsSync(prefetchBucketUrl(toolkitInfoObject)); return toolkitInfoObject; }; }; diff --git a/package-lock.json b/package-lock.json index 629c960..6dfd444 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "aws-cdk-local", - "version": "2.19.0", + "version": "2.18.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "aws-cdk-local", - "version": "2.19.0", + "version": "2.18.1", "license": "Apache-2.0", "dependencies": { "diff": "^5.0.0" @@ -191,9 +191,9 @@ "dev": true }, "node_modules/cross-spawn": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", - "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, "dependencies": { "path-key": "^3.1.0", @@ -905,9 +905,9 @@ } }, "node_modules/word-wrap": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", - "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true, "engines": { "node": ">=0.10.0" @@ -1055,9 +1055,9 @@ "dev": true }, "cross-spawn": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", - "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "dev": true, "requires": { "path-key": "^3.1.0", @@ -1589,9 +1589,9 @@ } }, "word-wrap": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", - "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", "dev": true }, "wrappy": {