Skip to content

Commit 00fe4e0

Browse files
authored
feat!: msw/graphql, graphql as an optional peer dependency (#2691)
1 parent 013012b commit 00fe4e0

71 files changed

Lines changed: 290 additions & 216 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.oxlintrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
"env": {
88
"builtin": true
99
},
10-
"ignorePatterns": ["/lib", "/node", "/native", "/config"],
10+
"ignorePatterns": [
11+
"/lib",
12+
"/node",
13+
"/browser",
14+
"/graphql",
15+
"/native",
16+
"/config"
17+
],
1118
"rules": {
1219
"constructor-super": "error",
1320
"for-direction": "error",

config/plugins/rolldown/forceFileExtensionsPlugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export function forceFileExtensionsPlugin(): TsdownPlugin {
88
name: 'forceFileExtensionsPlugin',
99
renderChunk(code, chunk, outputOptions) {
1010
const isEsm =
11-
outputOptions.format === 'es' ||
12-
chunk.fileName.endsWith(ESM_EXTENSION)
11+
outputOptions.format === 'es' || chunk.fileName.endsWith(ESM_EXTENSION)
1312

1413
if (!isEsm) {
1514
return

config/plugins/rolldown/graphQLImportPlugin.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

config/replaceCoreImports.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
const CORE_ESM_IMPORT_PATTERN = /from ["'](#core(.*))["'](;)?/gm
2-
const CORE_CJS_IMPORT_PATTERN = /require\(["'](#core(.*))["']\)(;)?/gm
1+
const CORE_ESM_IMPORT_PATTERN = /(from|import)\s+["'](#core(.*?))["'](;)?/gm
2+
const CORE_CJS_IMPORT_PATTERN = /require\(["'](#core(.*?))["']\)(;)?/gm
33

44
function getCoreImportPattern(isEsm) {
55
return isEsm ? CORE_ESM_IMPORT_PATTERN : CORE_CJS_IMPORT_PATTERN
66
}
77

88
export function hasCoreImports(fileContents, isEsm) {
9-
return getCoreImportPattern(isEsm).test(fileContents)
9+
return fileContents.search(getCoreImportPattern(isEsm)) !== -1
1010
}
1111

1212
export function replaceCoreImports(moduleFilePath, fileContents, isEsm) {
13+
if (isEsm) {
14+
return fileContents.replace(
15+
CORE_ESM_IMPORT_PATTERN,
16+
(_, keyword, __, maybeSubmodulePath, maybeSemicolon) => {
17+
const submodulePath = maybeSubmodulePath || '/index'
18+
/**
19+
* @note Although all .d.ts are considered ESM, append different
20+
* file extension for d.mts files.
21+
*/
22+
const extension = moduleFilePath.endsWith('.d.mts') ? '.mjs' : ''
23+
const semicolon = maybeSemicolon || ''
24+
25+
return `${keyword} "../core${submodulePath}${extension}"${semicolon}`
26+
},
27+
)
28+
}
29+
1330
return fileContents.replace(
14-
getCoreImportPattern(isEsm),
31+
CORE_CJS_IMPORT_PATTERN,
1532
(_, __, maybeSubmodulePath, maybeSemicolon) => {
1633
const submodulePath = maybeSubmodulePath || '/index'
17-
/**
18-
* @note Although all .d.ts are considered ESM, append different
19-
* file extension for d.mts files.
20-
*/
21-
const extension = moduleFilePath.endsWith('.d.mts') ? '.mjs' : ''
2234
const semicolon = maybeSemicolon || ''
2335

24-
return isEsm
25-
? `from "../core${submodulePath}${extension}"${semicolon}`
26-
: `require("../core${submodulePath}")${semicolon}`
36+
return `require("../core${submodulePath}")${semicolon}`
2737
},
2838
)
2939
}

graphql/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"type": "commonjs",
3+
"main": "../lib/graphql/index.js",
4+
"module": "../lib/graphql/index.mjs",
5+
"types": "../lib/graphql/index.d.ts",
6+
"exports": {
7+
".": {
8+
"module-sync": {
9+
"types": "./../lib/graphql/index.d.mts",
10+
"default": "./../lib/graphql/index.mjs"
11+
},
12+
"module": {
13+
"types": "./../lib/graphql/index.d.mts",
14+
"default": "./../lib/graphql/index.mjs"
15+
},
16+
"import": {
17+
"types": "./../lib/graphql/index.d.mts",
18+
"default": "./../lib/graphql/index.mjs"
19+
},
20+
"default": {
21+
"types": "./../lib/graphql/index.d.ts",
22+
"default": "./../lib/graphql/index.js"
23+
}
24+
}
25+
}
26+
}

knip.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://unpkg.com/knip@5/schema.json",
33
"entry": [
4-
"src/{core,browser,node,native}/index.ts!",
4+
"src/{core,browser,node,native,graphql}/index.ts!",
55
"src/mockServiceWorker.js!",
66
"cli/index.js!",
77
"config/**/*.{js,ts}!",

package.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,22 @@
123123
"default": "./lib/core/http.js"
124124
}
125125
},
126-
"./core/graphql": {
126+
"./graphql": {
127127
"module-sync": {
128-
"types": "./lib/core/graphql.d.mts",
129-
"default": "./lib/core/graphql.mjs"
128+
"types": "./lib/graphql/index.d.mts",
129+
"default": "./lib/graphql/index.mjs"
130130
},
131131
"module": {
132-
"types": "./lib/core/graphql.d.mts",
133-
"default": "./lib/core/graphql.mjs"
132+
"types": "./lib/graphql/index.d.mts",
133+
"default": "./lib/graphql/index.mjs"
134134
},
135135
"import": {
136-
"types": "./lib/core/graphql.d.mts",
137-
"default": "./lib/core/graphql.mjs"
136+
"types": "./lib/graphql/index.d.mts",
137+
"default": "./lib/graphql/index.mjs"
138138
},
139139
"default": {
140-
"types": "./lib/core/graphql.d.ts",
141-
"default": "./lib/core/graphql.js"
140+
"types": "./lib/graphql/index.d.ts",
141+
"default": "./lib/graphql/index.js"
142142
}
143143
},
144144
"./core/ws": {
@@ -228,6 +228,7 @@
228228
"browser",
229229
"node",
230230
"native",
231+
"graphql",
231232
"LICENSE.md",
232233
"README.md"
233234
],
@@ -252,7 +253,6 @@
252253
"@open-draft/deferred-promise": "^3.0.0",
253254
"@types/statuses": "^2.0.6",
254255
"cookie": "^2.0.1",
255-
"graphql": "^16.13.2",
256256
"headers-polyfill": "^5.0.1",
257257
"is-node-process": "^1.2.0",
258258
"outvariant": "^1.4.3",
@@ -291,6 +291,7 @@
291291
"fastify": "^5.8.5",
292292
"fs-teardown": "^0.3.0",
293293
"glob": "^13.0.6",
294+
"graphql": "^16.13.2",
294295
"jsdom": "^25.0.1",
295296
"json-bigint": "^1.0.0",
296297
"knip": "^6.4.1",
@@ -312,9 +313,13 @@
312313
"webpack-http-server": "^0.5.0"
313314
},
314315
"peerDependencies": {
315-
"typescript": ">= 4.8.x"
316+
"graphql": ">=16",
317+
"typescript": ">=4.8.x"
316318
},
317319
"peerDependenciesMeta": {
320+
"graphql": {
321+
"optional": true
322+
},
318323
"typescript": {
319324
"optional": true
320325
}

pnpm-lock.yaml

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

src/core/experimental/frames/http-frame.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { http } from '../../http'
2-
import { graphql } from '../../graphql'
2+
import { graphql } from '../../../graphql'
33
import { ws } from '../../ws'
44
import { bypass } from '../../bypass'
55
import type { HttpNetworkFrameEventMap } from './http-frame'

src/core/experimental/frames/websocket-frame.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { http } from '../../http'
2-
import { graphql } from '../../graphql'
2+
import { graphql } from '../../../graphql'
33
import { ws } from '../../ws'
44
import type { WebSocketNetworkFrameEventMap } from './websocket-frame'
55
import { WebSocketNetworkFrame } from './websocket-frame'

0 commit comments

Comments
 (0)