const resolvableExtensions = () => [`.ts`, `.tsx`]

function onCreateBabelConfig({ actions }, options) {
  actions.setBabelPreset({
    name: require.resolve(`@babel/preset-typescript`),
    options,
  })
  actions.setBabelPlugin({
    name: require.resolve(`@babel/plugin-proposal-optional-chaining`),
  })
  actions.setBabelPlugin({
    name: require.resolve(`@babel/plugin-proposal-nullish-coalescing-operator`),
  })
  actions.setBabelPlugin({
    name: require.resolve(`@babel/plugin-proposal-numeric-separator`),
  })
}

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),
    jsxPragma: Joi.string()
      .description(`Replace the function used when compiling JSX expressions.`)
      .default(`React`),
    jsxPragmaFrag: Joi.string()
      .description(
        `Replace the function used when compiling JSX fragment expressions.`
      )
      .optional(),
    allExtensions: Joi.boolean()
      .description(`Indicates that every file should be parsed as TS or TSX.`)
      .default(false)
      .when(`isTSX`, { is: true, then: Joi.valid(true) }),
    allowNamespaces: Joi.boolean()
      .description(`Enables compilation of TypeScript namespaces.`)
      .optional(),
    allowDeclareFields: Joi.boolean()
      .description(
        `When enabled, type-only class fields are only removed if they are prefixed with the declare modifier.`
      )
      .optional(),
    onlyRemoveTypeImports: Joi.boolean()
      .description(
        `When set to true, the transform will only remove type-only imports (introduced in TypeScript 3.8).` +
          `This should only be used if you are using TypeScript >= 3.8.`
      )
      .optional(),
  })

exports.resolvableExtensions = resolvableExtensions
exports.onCreateBabelConfig = onCreateBabelConfig
exports.onCreateWebpackConfig = onCreateWebpackConfig

@@ -638,343 +638,8 @@
  %7D%0A%0A
-  let doesUsedGatsbyVersionSupportResourceQuery%0A  try %7B%0A    const %7B version %7D = require(%60gatsby/package.json%60)%0A    const %5Bmajor, minor%5D = version.split(%60.%60).map(Number)%0A    doesUsedGatsbyVersionSupportResourceQuery =%0A      (major === 4 && minor %3E= 19) %7C%7C major %3E 4%0A  %7D catch %7B%0A    doesUsedGatsbyVersionSupportResourceQuery = true%0A  %7D%0A%0A
   ac
@@ -804,83 +804,8 @@
 .js(
-%0A              doesUsedGatsbyVersionSupportResourceQuery%0A                ? 
 %7B%0A  
@@ -816,22 +816,16 @@
         
- 
-     
 isPageTe
@@ -877,22 +877,16 @@
         
-      
 resource
@@ -908,56 +908,9 @@
     
-      %7D%0A                : undefined%0A            
+%7D
 ),%0A 

Remove version check (#36889)