Skip to content

Commit 0bd3c0e

Browse files
committed
msw: Patch @mswjs/data to remove msw dependency
`@mswjs/data` is a TypeScript package that is compiled to CommonJS. `msw` is shipped as a CommonJS + MJS dual build. When `@crates-io/msw` imports `msw` it is using the MJS build, but then when `@crates-io/msw` imports `@mswjs/data` it is transitively using the CommonJS build of `msw`, which leads to webpack issues. Since `msw` in `@mswjs/data` is optional and only used to automatically generate handler functions we can replace the import with `null` since the import will never be executed anyway. This is not a great solution (i.e. I hate it!), but after spending 2-3 hours on this issue it was the only working solution I've found...
1 parent 54eb34b commit 0bd3c0e

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@
157157
"@babel/core",
158158
"postcss"
159159
]
160+
},
161+
"patchedDependencies": {
162+
"@mswjs/data": "patches/@mswjs__data.patch"
160163
}
161164
},
162165
"engines": {

patches/@mswjs__data.patch

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/lib/model/generateGraphQLHandlers.js b/lib/model/generateGraphQLHandlers.js
2+
index d3002bc569125bdfc5c30e4b70869d88ef29457b..7fc10448dad40653a95d194fccf6cd12bcab8442 100644
3+
--- a/lib/model/generateGraphQLHandlers.js
4+
+++ b/lib/model/generateGraphQLHandlers.js
5+
@@ -69,7 +69,7 @@ exports.__esModule = true;
6+
exports.generateGraphQLHandlers = exports.generateGraphQLSchema = exports.definitionToFields = exports.getQueryTypeByValueType = exports.comparatorTypes = exports.getGraphQLType = void 0;
7+
var pluralize_1 = __importDefault(require("pluralize"));
8+
var graphql_1 = require("graphql");
9+
-var msw_1 = require("msw");
10+
+var msw_1 = null;
11+
var primaryKey_1 = require("../primaryKey");
12+
var capitalize_1 = require("../utils/capitalize");
13+
var boolean_1 = require("../comparators/boolean");
14+
diff --git a/lib/model/generateRestHandlers.js b/lib/model/generateRestHandlers.js
15+
index ca08cd1b35d34c1a546ca301b6cce771d58b004d..cc18e2798979f46295bfbb928e9a996f2c68c3eb 100644
16+
--- a/lib/model/generateRestHandlers.js
17+
+++ b/lib/model/generateRestHandlers.js
18+
@@ -88,7 +88,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19+
exports.__esModule = true;
20+
exports.generateRestHandlers = exports.parseQueryParams = exports.withErrors = exports.getResponseStatusByErrorType = exports.createUrlBuilder = void 0;
21+
var pluralize_1 = __importDefault(require("pluralize"));
22+
-var msw_1 = require("msw");
23+
+var msw_1 = null;
24+
var OperationError_1 = require("../errors/OperationError");
25+
var findPrimaryKey_1 = require("../utils/findPrimaryKey");
26+
var HTTPErrorType;

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)