From 2a988b3ef6a342ff8f7fc7df403409a3a3b22321 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Sun, 15 Mar 2020 02:05:31 +0900 Subject: [PATCH 1/4] chore(gatsby): migrate webpack-hmr-hooks-patch to TypeScript --- packages/gatsby/src/utils/webpack-hmr-hooks-patch.js | 6 ------ packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts | 11 +++++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) delete mode 100644 packages/gatsby/src/utils/webpack-hmr-hooks-patch.js create mode 100644 packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts diff --git a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.js b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.js deleted file mode 100644 index 169718284d486..0000000000000 --- a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.js +++ /dev/null @@ -1,6 +0,0 @@ -const originalFetch = global.fetch -delete global.fetch - -module.exports = require(`react-hot-loader/webpack`) - -global.fetch = originalFetch diff --git a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts new file mode 100644 index 0000000000000..b2c94eb34d586 --- /dev/null +++ b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts @@ -0,0 +1,11 @@ +/* eslint-disable @typescript-eslint/ban-ts-ignore */ + +// @ts-ignore: This file assume run at browsers. +const originalFetch = global.fetch +// @ts-ignore +delete global.fetch + +export * from "react-hot-loader/webpack" + +// @ts-ignore +global.fetch = originalFetch From d49470a379669c57fcd566e67c5d138bf1fbd46e Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Sun, 15 Mar 2020 12:28:54 +0900 Subject: [PATCH 2/4] fix test --- packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts index b2c94eb34d586..ba619caceab43 100644 --- a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts +++ b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts @@ -5,7 +5,7 @@ const originalFetch = global.fetch // @ts-ignore delete global.fetch -export * from "react-hot-loader/webpack" +export { default } from "react-hot-loader/webpack" // @ts-ignore global.fetch = originalFetch From 81a92742d867df32af1b768586e3d808a8de0f9e Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Thu, 19 Mar 2020 01:49:00 +0900 Subject: [PATCH 3/4] add guard for webpack-hmr-hooks-patch --- packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts index ba619caceab43..b69b3deba0006 100644 --- a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts +++ b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts @@ -1,9 +1,13 @@ /* eslint-disable @typescript-eslint/ban-ts-ignore */ -// @ts-ignore: This file assume run at browsers. -const originalFetch = global.fetch +let originalFetch: any // @ts-ignore -delete global.fetch +if (global.fetch) { + // @ts-ignore + originalFetch = global.fetch + // @ts-ignore + delete global.fetch +} export { default } from "react-hot-loader/webpack" From 34432d2f8dea40f4b033d2ecfcf89ffb0adc4a29 Mon Sep 17 00:00:00 2001 From: Daiki Ihara Date: Thu, 19 Mar 2020 20:35:55 +0900 Subject: [PATCH 4/4] add description for remaining webpack-hmr-hooks-patch as JS --- .../gatsby/src/utils/webpack-hmr-hooks-patch.js | 10 ++++++++++ .../gatsby/src/utils/webpack-hmr-hooks-patch.ts | 15 --------------- 2 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 packages/gatsby/src/utils/webpack-hmr-hooks-patch.js delete mode 100644 packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts diff --git a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.js b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.js new file mode 100644 index 0000000000000..7aca2012242c2 --- /dev/null +++ b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.js @@ -0,0 +1,10 @@ +/** + * This file should remain as JS because the migration to TypeScript break the patch. + * For more details, https://github.com/gatsbyjs/gatsby/pull/22280 + */ +const originalFetch = global.fetch +delete global.fetch + +module.exports = require(`react-hot-loader/webpack`) + +global.fetch = originalFetch diff --git a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts b/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts deleted file mode 100644 index b69b3deba0006..0000000000000 --- a/packages/gatsby/src/utils/webpack-hmr-hooks-patch.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-ts-ignore */ - -let originalFetch: any -// @ts-ignore -if (global.fetch) { - // @ts-ignore - originalFetch = global.fetch - // @ts-ignore - delete global.fetch -} - -export { default } from "react-hot-loader/webpack" - -// @ts-ignore -global.fetch = originalFetch