Skip to content

Commit

Permalink
fix(gatsby): cleanup fullySpecified resolving (#29576)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored Feb 22, 2021
1 parent 919aa07 commit 1343d38
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 56 deletions.
38 changes: 0 additions & 38 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ const ensureWindowsDriveIsUppercase = filePath => {
: filePath
}

const deprecationWarnings = new Set()

const findChildren = initialChildren => {
const children = [...initialChildren]
const queue = [...initialChildren]
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -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 [
Expand Down
6 changes: 0 additions & 6 deletions packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
29 changes: 23 additions & 6 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1343d38

Please sign in to comment.