Skip to content

Instantly share code, notes, and snippets.

@cdimitroulas
Created December 7, 2022 17:33
Show Gist options
  • Save cdimitroulas/caf930091aa7c63fc696e6521ade465a to your computer and use it in GitHub Desktop.
Save cdimitroulas/caf930091aa7c63fc696e6521ade465a to your computer and use it in GitHub Desktop.
Patch file for msw/interceptors showing changes to split browser/node builds
diff --git a/package.json b/package.json
index d3055f6..9e40a29 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,7 @@
"test:integration:node": "jest --c test/jest.node.config.js --runInBand",
"test:integration:browser": "jest --c test/jest.browser.config.js",
"clean": "rimraf lib",
- "build": "yarn clean && cross-env NODE_ENV=production tsup --splitting",
+ "build": "yarn clean && cross-env NODE_ENV=production tsup",
"prepare": "yarn simple-git-hooks init",
"release": "release publish",
"prepublishOnly": "yarn build && yarn test"
@@ -36,7 +36,6 @@
"@commitlint/config-conventional": "^16.0.0",
"@open-draft/test-server": "^0.4.2",
"@ossjs/release": "^0.3.0",
- "@remix-run/web-fetch": "^4.3.1",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/express-rate-limit": "^6.0.0",
@@ -70,6 +69,7 @@
},
"dependencies": {
"@open-draft/until": "^1.0.3",
+ "@remix-run/web-fetch": "^4.3.1",
"@types/debug": "^4.1.7",
"debug": "^4.3.3",
"headers-polyfill": "^3.1.0",
diff --git a/test/modules/XMLHttpRequest/intercept/XMLHttpRequest.browser.runtime.js b/test/modules/XMLHttpRequest/intercept/XMLHttpRequest.browser.runtime.js
index d6870fb..623b5f4 100644
--- a/test/modules/XMLHttpRequest/intercept/XMLHttpRequest.browser.runtime.js
+++ b/test/modules/XMLHttpRequest/intercept/XMLHttpRequest.browser.runtime.js
@@ -1,4 +1,4 @@
-import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest'
+import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/XMLHttpRequest'
const interceptor = new XMLHttpRequestInterceptor()
interceptor.on('request', async (request, requestId) => {
diff --git a/test/modules/XMLHttpRequest/response/xhr-response-patching.browser.runtime.js b/test/modules/XMLHttpRequest/response/xhr-response-patching.browser.runtime.js
index 7201278..cb6ad9d 100644
--- a/test/modules/XMLHttpRequest/response/xhr-response-patching.browser.runtime.js
+++ b/test/modules/XMLHttpRequest/response/xhr-response-patching.browser.runtime.js
@@ -1,4 +1,4 @@
-import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest'
+import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/XMLHttpRequest'
const interceptor = new XMLHttpRequestInterceptor()
diff --git a/test/modules/XMLHttpRequest/response/xhr.browser.runtime.js b/test/modules/XMLHttpRequest/response/xhr.browser.runtime.js
index 95efb39..24691dc 100644
--- a/test/modules/XMLHttpRequest/response/xhr.browser.runtime.js
+++ b/test/modules/XMLHttpRequest/response/xhr.browser.runtime.js
@@ -1,4 +1,4 @@
-import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/interceptors/XMLHttpRequest'
+import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/XMLHttpRequest'
const interceptor = new XMLHttpRequestInterceptor()
diff --git a/test/modules/fetch/fetch-modify-request.runtime.js b/test/modules/fetch/fetch-modify-request.runtime.js
index ceee542..7c4a815 100644
--- a/test/modules/fetch/fetch-modify-request.runtime.js
+++ b/test/modules/fetch/fetch-modify-request.runtime.js
@@ -1,4 +1,4 @@
-import { FetchInterceptor } from '@mswjs/interceptors/lib/interceptors/fetch'
+import { FetchInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/fetch'
const interceptor = new FetchInterceptor()
diff --git a/test/modules/fetch/intercept/fetch.body.runtime.js b/test/modules/fetch/intercept/fetch.body.runtime.js
index 2191afe..c7926a5 100644
--- a/test/modules/fetch/intercept/fetch.body.runtime.js
+++ b/test/modules/fetch/intercept/fetch.body.runtime.js
@@ -1,4 +1,4 @@
-import { FetchInterceptor } from '@mswjs/interceptors/lib/interceptors/fetch'
+import { FetchInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/fetch'
const interceptor = new FetchInterceptor()
interceptor.on('request', (request) => {
diff --git a/test/modules/fetch/intercept/fetch.browser.runtime.js b/test/modules/fetch/intercept/fetch.browser.runtime.js
index 9778b68..7eda2d0 100644
--- a/test/modules/fetch/intercept/fetch.browser.runtime.js
+++ b/test/modules/fetch/intercept/fetch.browser.runtime.js
@@ -1,4 +1,4 @@
-import { FetchInterceptor } from '@mswjs/interceptors/lib/interceptors/fetch'
+import { FetchInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/fetch'
const interceptor = new FetchInterceptor()
interceptor.on('request', async (request, requestId) => {
diff --git a/test/modules/fetch/intercept/fetch.clone.runtime.js b/test/modules/fetch/intercept/fetch.clone.runtime.js
index b70743c..6a3cab5 100644
--- a/test/modules/fetch/intercept/fetch.clone.runtime.js
+++ b/test/modules/fetch/intercept/fetch.clone.runtime.js
@@ -1,4 +1,4 @@
-import { FetchInterceptor } from '@mswjs/interceptors/lib/interceptors/fetch'
+import { FetchInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/fetch'
// Intentionally don't mock any responses
// so that the original responses are sent.
diff --git a/test/modules/fetch/response/fetch-response-patching.runtime.js b/test/modules/fetch/response/fetch-response-patching.runtime.js
index 87cebb1..bc271a3 100644
--- a/test/modules/fetch/response/fetch-response-patching.runtime.js
+++ b/test/modules/fetch/response/fetch-response-patching.runtime.js
@@ -1,4 +1,4 @@
-import { FetchInterceptor } from '@mswjs/interceptors/lib/interceptors/fetch'
+import { FetchInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/fetch'
const interceptor = new FetchInterceptor()
diff --git a/test/modules/fetch/response/fetch.browser.runtime.js b/test/modules/fetch/response/fetch.browser.runtime.js
index 9a0f652..c78e1e3 100644
--- a/test/modules/fetch/response/fetch.browser.runtime.js
+++ b/test/modules/fetch/response/fetch.browser.runtime.js
@@ -1,4 +1,4 @@
-import { FetchInterceptor } from '@mswjs/interceptors/lib/interceptors/fetch'
+import { FetchInterceptor } from '@mswjs/interceptors/lib/browser/interceptors/fetch'
const interceptor = new FetchInterceptor()
diff --git a/tsup.config.ts b/tsup.config.ts
index a7a5ab4..189ff6b 100644
--- a/tsup.config.ts
+++ b/tsup.config.ts
@@ -1,6 +1,25 @@
-import { defineConfig } from 'tsup'
+import { defineConfig, Options } from 'tsup'
-export default defineConfig({
+const commonConfig: Options = {
+ format: ['cjs', 'esm'],
+ dts: true,
+}
+
+const browserConfig: Options = {
+ ...commonConfig,
+ entry: [
+ './src/index.ts',
+ // './src/RemoteHttpInterceptor.ts',
+ // './src/interceptors/ClientRequest/index.ts',
+ './src/interceptors/fetch/index.ts',
+ './src/interceptors/XMLHttpRequest/index.ts',
+ ],
+ outDir: './lib/browser',
+ platform: 'browser'
+}
+
+const nodeConfig: Options = {
+ ...commonConfig,
entry: [
'./src/index.ts',
'./src/RemoteHttpInterceptor.ts',
@@ -8,7 +27,8 @@ export default defineConfig({
'./src/interceptors/fetch/index.ts',
'./src/interceptors/XMLHttpRequest/index.ts',
],
- outDir: './lib',
- format: ['cjs', 'esm'],
- dts: true,
-})
+ outDir: './lib/node',
+ platform: 'node'
+}
+
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment