From 5a965c9f5bc353ab05f46a87a74aec4084cd7f79 Mon Sep 17 00:00:00 2001 From: Ramiro Silveyra d'Avila Date: Wed, 13 Jan 2021 01:20:16 -0300 Subject: [PATCH] fix: webpack 5 and worker-loader support --- .github/workflows/build_test_deploy.yml | 2 +- package.json | 12 +++++----- .../ReactRefreshWebpackPlugin.ts | 2 ++ test/integration/worker-loader/next.config.js | 2 +- .../worker-loader/test/index.test.js | 3 +-- yarn.lock | 22 ++++++------------- 6 files changed, 18 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 5f0dac3b38b1..9c0eb902e201 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -185,7 +185,7 @@ jobs: - run: yarn list webpack react react-dom if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs-only' }} - - run: xvfb-run node run-tests.js test/integration/{link-ref,production,basic,async-modules,font-optimization,ssr-ctx}/test/index.test.js test/acceptance/*.test.js + - run: xvfb-run node run-tests.js test/integration/{link-ref,production,basic,async-modules,font-optimization,ssr-ctx,worker-loader}/test/index.test.js test/acceptance/*.test.js if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs-only' }} testFirefox: diff --git a/package.json b/package.json index ecca26928ab8..ed63da0c954f 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,11 @@ "@babel/preset-react": "7.12.10", "@fullhuman/postcss-purgecss": "1.3.0", "@mdx-js/loader": "0.18.0", + "@opentelemetry/exporter-zipkin": "0.14.0", + "@opentelemetry/node": "0.14.0", + "@opentelemetry/plugin-http": "0.14.0", + "@opentelemetry/plugin-https": "0.14.0", + "@opentelemetry/tracing": "0.14.0", "@types/cheerio": "0.22.16", "@types/fs-extra": "8.1.0", "@types/http-proxy": "1.17.3", @@ -129,12 +134,7 @@ "wait-port": "0.2.2", "web-streams-polyfill": "2.1.1", "webpack-bundle-analyzer": "4.3.0", - "worker-loader": "2.0.0", - "@opentelemetry/exporter-zipkin": "0.14.0", - "@opentelemetry/node": "0.14.0", - "@opentelemetry/plugin-http": "0.14.0", - "@opentelemetry/plugin-https": "0.14.0", - "@opentelemetry/tracing": "0.14.0" + "worker-loader": "3.0.7" }, "resolutions": { "browserslist": "^4.14.7", diff --git a/packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts b/packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts index 4e01e25669ff..aee6e043b105 100644 --- a/packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts +++ b/packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts @@ -95,6 +95,7 @@ function webpack5(compiler: Compiler) { // @ts-ignore This exists in webpack 5 const { runtimeTemplate } = this.compilation return Template.asString([ + `if (${RuntimeGlobals.interceptModuleExecution}) {`, `${ RuntimeGlobals.interceptModuleExecution }.push(${runtimeTemplate.basicFunction('options', [ @@ -127,6 +128,7 @@ function webpack5(compiler: Compiler) { ] )}`, ])})`, + '}', ]) } } diff --git a/test/integration/worker-loader/next.config.js b/test/integration/worker-loader/next.config.js index 6b94ace03704..da9c5b010455 100644 --- a/test/integration/worker-loader/next.config.js +++ b/test/integration/worker-loader/next.config.js @@ -4,7 +4,7 @@ module.exports = { test: /\.worker\.(js|ts|tsx)$/, loader: 'worker-loader', options: { - name: 'static/[hash].worker.js', + filename: 'static/[hash].worker.js', publicPath: '/_next/', }, }) diff --git a/test/integration/worker-loader/test/index.test.js b/test/integration/worker-loader/test/index.test.js index 53518f11a88e..8526d473397e 100644 --- a/test/integration/worker-loader/test/index.test.js +++ b/test/integration/worker-loader/test/index.test.js @@ -9,8 +9,7 @@ const context = {} jest.setTimeout(1000 * 60 * 2) -// TODO: Upgrade worker-loader when it's published with webpack 5 support -describe.skip('Web Workers with Fast Refresh', () => { +describe('Web Workers with Fast Refresh', () => { beforeAll(async () => { context.appPort = await findPort() context.server = await launchApp(appDir, context.appPort) diff --git a/yarn.lock b/yarn.lock index dda54689a2d5..4447f6483ade 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9840,7 +9840,7 @@ loader-utils@2.0.0, loader-utils@^2.0.0: emojis-list "^3.0.0" json5 "^2.1.2" -loader-utils@^1.0.0, loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3: +loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3: version "1.4.0" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613" dependencies: @@ -13966,14 +13966,6 @@ schema-utils@2.7.1, schema-utils@^2.0.0, schema-utils@^2.6.5, schema-utils@^2.6. ajv "^6.12.4" ajv-keywords "^3.5.2" -schema-utils@^0.4.0: - version "0.4.7" - resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187" - integrity sha512-v/iwU6wvwGK8HbU9yi3/nhGzP0yGSuhQMzL6ySiec1FSrZZDkhm4noOSWzrNFo/jEc+SJY6jRTwuwbSXJPDUnQ== - dependencies: - ajv "^6.1.0" - ajv-keywords "^3.1.0" - schema-utils@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770" @@ -16026,13 +16018,13 @@ worker-farm@^1.7.0: dependencies: errno "~0.1.7" -worker-loader@2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-2.0.0.tgz#45fda3ef76aca815771a89107399ee4119b430ac" - integrity sha512-tnvNp4K3KQOpfRnD20m8xltE3eWh89Ye+5oj7wXEEHKac1P4oZ6p9oTj8/8ExqoSBnk9nu5Pr4nKfQ1hn2APJw== +worker-loader@3.0.7: + version "3.0.7" + resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-3.0.7.tgz#9cf2122a9a781d6742cb873c58c3769591b31988" + integrity sha512-LjYLuYJw6kqQKDoygpoD5vWeR1CbZjuVSW3/8pFsptMlUl8gatNM/pszhasSDAWt+dYxMipWB6695k+1zId+iQ== dependencies: - loader-utils "^1.0.0" - schema-utils "^0.4.0" + loader-utils "^2.0.0" + schema-utils "^3.0.0" wrap-ansi@^2.0.0: version "2.1.0"