Skip to content

Commit

Permalink
chore(gatsby-plugin-typescript): Remove obsolete `onCreateWebpackConf…
Browse files Browse the repository at this point in the history
…ig` (#36814)
  • Loading branch information
LekoArts authored Oct 17, 2022
1 parent 3c9cf7c commit 7abda34
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 71 deletions.
31 changes: 1 addition & 30 deletions packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const {
resolvableExtensions,
onCreateBabelConfig,
onCreateWebpackConfig,
} = require(`../gatsby-node`)
const { resolvableExtensions, onCreateBabelConfig } = require(`../gatsby-node`)
const path = require(`path`)

const { testPluginOptionsSchema } = require(`gatsby-plugin-utils`)
Expand Down Expand Up @@ -47,31 +43,6 @@ describe(`gatsby-plugin-typescript`, () => {
})
})

describe(`onCreateWebpackConfig`, () => {
it(`sets the correct webpack config`, () => {
const actions = { setWebpackConfig: jest.fn() }
const loaders = { js: jest.fn(() => {}) }
onCreateWebpackConfig({ actions, loaders })
expect(actions.setWebpackConfig).toHaveBeenCalledWith({
module: {
rules: [
{
test: /\.tsx?$/,
use: expect.toBeFunction(),
},
],
},
})
})

it(`does not set the webpack config if there isn't a js loader`, () => {
const actions = { setWebpackConfig: jest.fn() }
const loaders = { js: undefined }
onCreateWebpackConfig({ actions, loaders })
expect(actions.setWebpackConfig).not.toHaveBeenCalled()
})
})

describe(`plugin schema`, () => {
it(`should provide meaningful errors when fields are invalid`, async () => {
const expectedErrors = [
Expand Down
37 changes: 0 additions & 37 deletions packages/gatsby-plugin-typescript/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,6 @@ function onCreateBabelConfig({ actions }, options) {
})
}

function onCreateWebpackConfig({ actions, loaders }) {
if (typeof loaders?.js !== `function`) {
return
}

let doesUsedGatsbyVersionSupportResourceQuery
try {
const { version } = require(`gatsby/package.json`)
const [major, minor] = version.split(`.`).map(Number)
doesUsedGatsbyVersionSupportResourceQuery =
(major === 4 && minor >= 19) || major > 4
} catch {
doesUsedGatsbyVersionSupportResourceQuery = true
}

actions.setWebpackConfig({
module: {
rules: [
{
test: /\.tsx?$/,
use: ({ resourceQuery, issuer }) => [
loaders.js(
doesUsedGatsbyVersionSupportResourceQuery
? {
isPageTemplate: /async-requires/.test(issuer),
resourceQuery,
}
: undefined
),
],
},
],
},
})
}

exports.pluginOptionsSchema = ({ Joi }) =>
Joi.object({
isTSX: Joi.boolean().description(`Enables jsx parsing.`).default(false),
Expand Down Expand Up @@ -85,4 +49,3 @@ exports.pluginOptionsSchema = ({ Joi }) =>

exports.resolvableExtensions = resolvableExtensions
exports.onCreateBabelConfig = onCreateBabelConfig
exports.onCreateWebpackConfig = onCreateWebpackConfig
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ Array [
"pluginOptionsSchema",
"resolvableExtensions",
"onCreateBabelConfig",
"onCreateWebpackConfig",
],
"pluginOptions": Object {
"allExtensions": false,
Expand Down Expand Up @@ -635,7 +634,6 @@ Array [
"pluginOptionsSchema",
"resolvableExtensions",
"onCreateBabelConfig",
"onCreateWebpackConfig",
],
"pluginOptions": Object {
"allExtensions": false,
Expand Down Expand Up @@ -1017,7 +1015,6 @@ Array [
"pluginOptionsSchema",
"resolvableExtensions",
"onCreateBabelConfig",
"onCreateWebpackConfig",
],
"pluginOptions": Object {
"allExtensions": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ describe(`Load plugins`, () => {
`pluginOptionsSchema`,
`resolvableExtensions`,
`onCreateBabelConfig`,
`onCreateWebpackConfig`,
],
pluginOptions: {
allExtensions: false,
Expand Down

0 comments on commit 7abda34

Please sign in to comment.