From fc9ba04eeae22b46be64045beba4c9a7aa013af4 Mon Sep 17 00:00:00 2001 From: Mark McCulloh Date: Wed, 18 Oct 2023 17:47:41 -0400 Subject: [PATCH] chore(sdk): force usage of mime v3 throughout repo (#4590) We were already depending on `mime`, so this does not increase our dependency closure. The version of `mime` that `express` depends on (via the `send` package) is very old and can easily conflict with other dependencies we may want to add. This forces our packages to always use v3 of `mime`, and patches `mime` v3 to expose the previously removed functions. *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- libs/wingsdk/.projen/deps.json | 5 +++++ libs/wingsdk/.projen/tasks.json | 2 +- libs/wingsdk/.projenrc.ts | 1 + libs/wingsdk/package.json | 2 ++ package.json | 6 +++++- patches/mime@3.0.0.patch | 32 +++++++++++++++++++++++++++++++ pnpm-lock.yaml | 34 ++++++++++++++++++--------------- 7 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 patches/mime@3.0.0.patch diff --git a/libs/wingsdk/.projen/deps.json b/libs/wingsdk/.projen/deps.json index 5c7159ccc78..3a4fc133175 100644 --- a/libs/wingsdk/.projen/deps.json +++ b/libs/wingsdk/.projen/deps.json @@ -286,6 +286,11 @@ "name": "mime-types", "type": "bundled" }, + { + "name": "mime", + "version": "^3.0.0", + "type": "bundled" + }, { "name": "nanoid", "version": "^3.3.6", diff --git a/libs/wingsdk/.projen/tasks.json b/libs/wingsdk/.projen/tasks.json index 18c923b6ed2..8f94ecd0680 100644 --- a/libs/wingsdk/.projen/tasks.json +++ b/libs/wingsdk/.projen/tasks.json @@ -492,7 +492,7 @@ "exec": "pnpm i --no-frozen-lockfile" }, { - "exec": "pnpm update @cdktf/provider-aws @types/aws-lambda @types/express @types/fs-extra @types/mime-types @types/node @types/uuid @typescript-eslint/eslint-plugin @typescript-eslint/parser @vitest/coverage-v8 @winglang/jsii-docgen aws-sdk-client-mock aws-sdk-client-mock-jest bump-pack cdktf-cli constructs eslint-config-prettier eslint-import-resolver-node eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint-plugin-sort-exports eslint fs-extra jsii-diff jsii-pacmak jsii-rosetta jsii nanoid npm-check-updates prettier projen standard-version ts-node typescript vitest wing-api-checker @aws-sdk/client-cloudwatch-logs @aws-sdk/client-dynamodb @aws-sdk/client-elasticache @aws-sdk/client-lambda @aws-sdk/client-s3 @aws-sdk/client-secrets-manager @aws-sdk/client-sns @aws-sdk/client-sqs @aws-sdk/is-array-buffer @aws-sdk/s3-request-presigner @aws-sdk/types @aws-sdk/util-buffer-from @aws-sdk/util-dynamodb @aws-sdk/util-stream-node @aws-sdk/util-utf8-node @azure/core-paging @azure/identity @azure/storage-blob @types/aws-lambda aws-cdk-lib cdktf cron-parser esbuild-wasm express ioredis jsonschema mime-types nanoid safe-stable-stringify uuid yaml constructs constructs" + "exec": "pnpm update @cdktf/provider-aws @types/aws-lambda @types/express @types/fs-extra @types/mime-types @types/node @types/uuid @typescript-eslint/eslint-plugin @typescript-eslint/parser @vitest/coverage-v8 @winglang/jsii-docgen aws-sdk-client-mock aws-sdk-client-mock-jest bump-pack cdktf-cli constructs eslint-config-prettier eslint-import-resolver-node eslint-import-resolver-typescript eslint-plugin-import eslint-plugin-prettier eslint-plugin-sort-exports eslint fs-extra jsii-diff jsii-pacmak jsii-rosetta jsii nanoid npm-check-updates prettier projen standard-version ts-node typescript vitest wing-api-checker @aws-sdk/client-cloudwatch-logs @aws-sdk/client-dynamodb @aws-sdk/client-elasticache @aws-sdk/client-lambda @aws-sdk/client-s3 @aws-sdk/client-secrets-manager @aws-sdk/client-sns @aws-sdk/client-sqs @aws-sdk/is-array-buffer @aws-sdk/s3-request-presigner @aws-sdk/types @aws-sdk/util-buffer-from @aws-sdk/util-dynamodb @aws-sdk/util-stream-node @aws-sdk/util-utf8-node @azure/core-paging @azure/identity @azure/storage-blob @types/aws-lambda aws-cdk-lib cdktf cron-parser esbuild-wasm express ioredis jsonschema mime-types mime nanoid safe-stable-stringify uuid yaml constructs constructs" }, { "exec": "pnpm exec projen" diff --git a/libs/wingsdk/.projenrc.ts b/libs/wingsdk/.projenrc.ts index e417a74abd0..d4910c0dff7 100644 --- a/libs/wingsdk/.projenrc.ts +++ b/libs/wingsdk/.projenrc.ts @@ -71,6 +71,7 @@ const project = new cdk.JsiiProject({ "@aws-sdk/util-buffer-from@3.208.0", "@aws-sdk/is-array-buffer@3.201.0", "mime-types", + "mime@^3.0.0", // azure client dependencies "@azure/storage-blob@12.14.0", "@azure/identity@3.1.3", diff --git a/libs/wingsdk/package.json b/libs/wingsdk/package.json index 8af63262534..c3f5e15614e 100644 --- a/libs/wingsdk/package.json +++ b/libs/wingsdk/package.json @@ -106,6 +106,7 @@ "express": "^4.18.2", "ioredis": "^5.3.2", "jsonschema": "^1.4.1", + "mime": "^3.0.0", "mime-types": "^2.1.35", "nanoid": "^3.3.6", "safe-stable-stringify": "^2.4.3", @@ -139,6 +140,7 @@ "express", "ioredis", "jsonschema", + "mime", "mime-types", "nanoid", "safe-stable-stringify", diff --git a/package.json b/package.json index 9111c44f799..3546aef4e62 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,9 @@ "pnpm": "8.6.5" }, "pnpm": { + "overrides": { + "mime": "^3.0.0" + }, "patchedDependencies": { "wasi-js@1.7.3": "patches/wasi-js@1.7.3.patch", "@aws-sdk/is-array-buffer@3.201.0": "patches/@aws-sdk__is-array-buffer@3.201.0.patch", @@ -30,7 +33,8 @@ "jsii@5.0.11": "patches/jsii@5.0.11.patch", "@aws-sdk/util-utf8-node@3.259.0": "patches/@aws-sdk__util-utf8-node@3.259.0.patch", "@aws-sdk/util-utf8-browser@3.259.0": "patches/@aws-sdk__util-utf8-browser@3.259.0.patch", - "esbuild-wasm@0.18.20": "patches/esbuild-wasm@0.18.20.patch" + "esbuild-wasm@0.18.20": "patches/esbuild-wasm@0.18.20.patch", + "mime@3.0.0": "patches/mime@3.0.0.patch" } } } diff --git a/patches/mime@3.0.0.patch b/patches/mime@3.0.0.patch new file mode 100644 index 00000000000..a365e77e274 --- /dev/null +++ b/patches/mime@3.0.0.patch @@ -0,0 +1,32 @@ +diff --git a/CHANGELOG.md b/CHANGELOG.md +deleted file mode 100644 +index cdf9be581e413715fefc1d72d146e35b98cd10ef..0000000000000000000000000000000000000000 +diff --git a/Mime.js b/Mime.js +index 969a66e41fbb6d7265562a657cb24b4e761969ee..63a8891041f07745af0f74d64941c3225f12951b 100644 +--- a/Mime.js ++++ b/Mime.js +@@ -15,6 +15,8 @@ function Mime() { + this.define = this.define.bind(this); + this.getType = this.getType.bind(this); + this.getExtension = this.getExtension.bind(this); ++ this.lookup = this.lookup.bind(this); ++ this.charsets.lookup = this.charsets.lookup.bind(this); + } + + /** +@@ -86,6 +88,15 @@ Mime.prototype.getType = function(path) { + return (hasDot || !hasPath) && this._types[ext] || null; + }; + ++ ++Mime.prototype.lookup = Mime.prototype.getType; ++Mime.prototype.charsets = { ++ lookup: function(mimeType, fallback) { ++ // Assume text types are utf8 ++ return (/^text\/|^application\/(javascript|json)/).test(mimeType) ? 'UTF-8' : fallback; ++ } ++}; ++ + /** + * Return file extension associated with a mime type + */ \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 82d781bccc6..c5e0428ac68 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + mime: ^3.0.0 + patchedDependencies: '@aws-sdk/is-array-buffer@3.201.0': hash: lcduyc25etdvbxthpjpldc7hvu @@ -23,6 +26,9 @@ patchedDependencies: jsii@5.0.11: hash: zhi5puwzi5jiulxnmqgkd4wl2a path: patches/jsii@5.0.11.patch + mime@3.0.0: + hash: 2he2uszztbibyal6zfzmv2a2oa + path: patches/mime@3.0.0.patch wasi-js@1.7.3: hash: rmwvp46j2ligfusbdx5dzh4a3q path: patches/wasi-js@1.7.3.patch @@ -1229,6 +1235,9 @@ importers: jsonschema: specifier: ^1.4.1 version: 1.4.1 + mime: + specifier: ^3.0.0 + version: 3.0.0(patch_hash=2he2uszztbibyal6zfzmv2a2oa) mime-types: specifier: ^2.1.35 version: 2.1.35 @@ -10448,7 +10457,7 @@ packages: jsonc-parser: 3.2.0 leven: 3.1.0 markdown-it: 12.3.2 - mime: 1.6.0 + mime: 3.0.0(patch_hash=2he2uszztbibyal6zfzmv2a2oa) minimatch: 3.1.2 parse-semver: 1.1.1 read: 1.0.7 @@ -13275,7 +13284,7 @@ packages: dependencies: semver: 7.5.4 shelljs: 0.8.5 - typescript: 5.3.0-dev.20231016 + typescript: 5.3.0-dev.20231018 dev: true /dset@3.1.2: @@ -18446,16 +18455,11 @@ packages: dependencies: mime-db: 1.52.0 - /mime@1.6.0: - resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==} - engines: {node: '>=4'} - hasBin: true - - /mime@2.6.0: - resolution: {integrity: sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==} - engines: {node: '>=4.0.0'} + /mime@3.0.0(patch_hash=2he2uszztbibyal6zfzmv2a2oa): + resolution: {integrity: sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==} + engines: {node: '>=10.0.0'} hasBin: true - dev: true + patched: true /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} @@ -20130,7 +20134,7 @@ packages: debug: 4.3.4 extract-zip: 1.7.0 https-proxy-agent: 4.0.0 - mime: 2.6.0 + mime: 3.0.0(patch_hash=2he2uszztbibyal6zfzmv2a2oa) mime-types: 2.1.35 progress: 2.0.3 proxy-from-env: 1.1.0 @@ -21102,7 +21106,7 @@ packages: etag: 1.8.1 fresh: 0.5.2 http-errors: 2.0.0 - mime: 1.6.0 + mime: 3.0.0(patch_hash=2he2uszztbibyal6zfzmv2a2oa) ms: 2.1.3 on-finished: 2.4.1 range-parser: 1.2.1 @@ -22712,8 +22716,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - /typescript@5.3.0-dev.20231016: - resolution: {integrity: sha512-1NaopFFSKTDFUHEkuN7xJfPMwXZFd1g+wKuMu2eh3rDHN7lhQMGDU08D2CnlLYK2xfNjgeb5qAWXQAdMbRLn3A==} + /typescript@5.3.0-dev.20231018: + resolution: {integrity: sha512-qBPaVi+ntB9Ys4T3uP1ZYCtxFWIV/1ieooBDhFEd8nw4IqAoB/Us7XobF3xb756bnX8cS/zIt9fgukde4MG4bA==} engines: {node: '>=14.17'} hasBin: true dev: true