Skip to content

Commit

Permalink
chore(sdk): force usage of mime v3 throughout repo (#4590)
Browse files Browse the repository at this point in the history
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)*.
  • Loading branch information
MarkMcCulloh authored Oct 18, 2023
1 parent 0b3ece4 commit fc9ba04
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 17 deletions.
5 changes: 5 additions & 0 deletions libs/wingsdk/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/wingsdk/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/wingsdk/.projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const project = new cdk.JsiiProject({
"@aws-sdk/[email protected]",
"@aws-sdk/[email protected]",
"mime-types",
"mime@^3.0.0",
// azure client dependencies
"@azure/[email protected]",
"@azure/[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions libs/wingsdk/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@
"pnpm": "8.6.5"
},
"pnpm": {
"overrides": {
"mime": "^3.0.0"
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]",
"@aws-sdk/[email protected]": "patches/@[email protected]",
"@aws-sdk/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]",
"@aws-sdk/[email protected]": "patches/@[email protected]",
"@aws-sdk/[email protected]": "patches/@[email protected]",
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
}
}
32 changes: 32 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -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
*/
34 changes: 19 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc9ba04

Please sign in to comment.