From 1343d38a6f22e8919eacbfdcb718fbdc409a03dc Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Mon, 22 Feb 2021 07:32:31 +0100 Subject: [PATCH] fix(gatsby): cleanup fullySpecified resolving (#29576) --- packages/gatsby/src/redux/actions/public.js | 38 ------------------- .../__snapshots__/webpack-utils.ts.snap | 6 --- packages/gatsby/src/utils/webpack-utils.ts | 6 --- packages/gatsby/src/utils/webpack.config.js | 29 +++++++++++--- 4 files changed, 23 insertions(+), 56 deletions(-) diff --git a/packages/gatsby/src/redux/actions/public.js b/packages/gatsby/src/redux/actions/public.js index 5a2816b0458aa..5e101b345052c 100644 --- a/packages/gatsby/src/redux/actions/public.js +++ b/packages/gatsby/src/redux/actions/public.js @@ -50,8 +50,6 @@ const ensureWindowsDriveIsUppercase = filePath => { : filePath } -const deprecationWarnings = new Set() - const findChildren = initialChildren => { const children = [...initialChildren] const queue = [...initialChildren] @@ -953,24 +951,6 @@ actions.createParentChildLink = ( * @param {Object} config partial webpack config, to be merged into the current one */ actions.setWebpackConfig = (config: Object, plugin?: ?Plugin = null) => { - if (config.module?.rules) { - config.module.rules.forEach(rule => { - if (!rule.resolve) { - // TODO move message to gatsbyjs.com/docs - change to structured - const key = `${plugin.name}-setWebpackConfig` - if (!deprecationWarnings.has(key)) { - report.warn( - `[deprecation] ${plugin.name} added a new module rule to the webpack config without specyfing the resolve property. This option will become mandatory in the next release. For more information go to https://webpack.js.org/configuration/module/#ruleresolve` - ) - } - deprecationWarnings.add(key) - rule.resolve = { - fullySpecified: false, - } - } - }) - } - return { type: `SET_WEBPACK_CONFIG`, plugin, @@ -988,24 +968,6 @@ actions.setWebpackConfig = (config: Object, plugin?: ?Plugin = null) => { * @param {Object} config complete webpack config */ actions.replaceWebpackConfig = (config: Object, plugin?: ?Plugin = null) => { - if (config.module?.rules && plugin) { - config.module.rules.forEach(rule => { - if (!rule.resolve) { - // TODO move message to gatsbyjs.com/docs - change to structured - const key = `${plugin.name}-setWebpackConfig` - if (!deprecationWarnings.has(key)) { - report.warn( - `[deprecation] ${plugin.name} added a new module rule to the webpack config without specyfing the resolve property. This option will become mandatory in the next release. For more information go to https://webpack.js.org/configuration/module/#ruleresolve` - ) - } - deprecationWarnings.add(key) - rule.resolve = { - fullySpecified: false, - } - } - }) - } - return { type: `REPLACE_WEBPACK_CONFIG`, plugin, diff --git a/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.ts.snap b/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.ts.snap index 35ec3f2d86a81..a2a1f50ac7037 100644 --- a/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.ts.snap +++ b/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.ts.snap @@ -3,9 +3,6 @@ exports[`webpack utils dependencies returns default values without any options 1`] = ` Object { "exclude": [Function], - "resolve": Object { - "fullySpecified": false, - }, "test": /\\\\\\.\\(js\\|mjs\\)\\$/, "type": "javascript/auto", "use": Array [ @@ -35,9 +32,6 @@ Object { exports[`webpack utils js returns default values without any options 1`] = ` Object { "include": [Function], - "resolve": Object { - "fullySpecified": false, - }, "test": /\\\\\\.\\(js\\|mjs\\|jsx\\)\\$/, "type": "javascript/auto", "use": Array [ diff --git a/packages/gatsby/src/utils/webpack-utils.ts b/packages/gatsby/src/utils/webpack-utils.ts index 5e894f03154d6..27f12ef831a48 100644 --- a/packages/gatsby/src/utils/webpack-utils.ts +++ b/packages/gatsby/src/utils/webpack-utils.ts @@ -408,9 +408,6 @@ export const createWebpackUtils = ( } = {}): RuleSetRule => { return { test: /\.(js|mjs|jsx)$/, - resolve: { - fullySpecified: false, - }, include: (modulePath: string): boolean => { // when it's not coming from node_modules we treat it as a source file. if (!vendorRegex.test(modulePath)) { @@ -504,9 +501,6 @@ export const createWebpackUtils = ( return { test: /\.(js|mjs)$/, - resolve: { - fullySpecified: false, - }, exclude: (modulePath: string): boolean => { // If dep is user land code, exclude if (!vendorRegex.test(modulePath)) { diff --git a/packages/gatsby/src/utils/webpack.config.js b/packages/gatsby/src/utils/webpack.config.js index 30eeb71798269..3b138ee74c1dc 100644 --- a/packages/gatsby/src/utils/webpack.config.js +++ b/packages/gatsby/src/utils/webpack.config.js @@ -284,18 +284,35 @@ module.exports = async ( // Common config for every env. // prettier-ignore let configRules = [ - rules.js({ - modulesThatUseGatsby, - }), - // Webpack expects extensions when importing to mimic ESM spec. + // Webpack expects extensions when importing ESM modules as that's what the spec describes. // Not all libraries have adapted so we don't enforce its behaviour // @see https://github.com/webpack/webpack/issues/11467 { - test: /\.m?js/, + test: /\.mjs$/i, resolve: { - fullySpecified: false + byDependency: { + esm: { + fullySpecified: false + } + } } }, + { + test: /\.js$/i, + descriptionData: { + type: `module` + }, + resolve: { + byDependency: { + esm: { + fullySpecified: false + } + } + } + }, + rules.js({ + modulesThatUseGatsby, + }), rules.yaml(), rules.fonts(), rules.images(),