Skip to content

Commit fafdc3f

Browse files
author
Vladimir Pouzanov
committed
Run typescript sources through full babel transpiling pipeline
1 parent 2093d75 commit fafdc3f

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ describe(`gatsby-plugin-typescript`, () => {
1414
expect(resolvableExtensions()).toMatchSnapshot()
1515
})
1616

17-
it(`modifies webpack config`, () => {
17+
it(`modifies webpack config`, async () => {
18+
const stage = ``
19+
const program = {
20+
directory: `.`,
21+
browserslist: [],
22+
}
1823
const config = {
1924
loader: jest.fn(),
2025
}
2126

22-
modifyWebpackConfig({ config }, { compilerOptions: {} })
27+
await modifyWebpackConfig({ program, config, stage }, { compilerOptions: {} })
2328

2429
expect(config.loader).toHaveBeenCalledTimes(1)
2530
const lastCall = config.loader.mock.calls.pop()

packages/gatsby-plugin-typescript/src/gatsby-node.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
const genBabelConfig = require(`gatsby/dist/utils/babel-config`)
12
const { transpileModule } = require(`typescript`)
2-
const path = require(`path`)
33

44
const test = /\.tsx?$/
55
const compilerDefaults = {
@@ -10,10 +10,12 @@ const compilerDefaults = {
1010

1111
module.exports.resolvableExtensions = () => [`.ts`, `.tsx`]
1212

13-
module.exports.modifyWebpackConfig = (
14-
{ config },
13+
module.exports.modifyWebpackConfig = async (
14+
{ program, config, stage },
1515
{ compilerOptions, transpileOnly = true }
1616
) => {
17+
const babelConfig = await genBabelConfig(program, stage)
18+
1719
// CommonJS to keep Webpack happy.
1820
const copts = Object.assign({}, compilerDefaults, compilerOptions, {
1921
module: `commonjs`,
@@ -23,16 +25,10 @@ module.exports.modifyWebpackConfig = (
2325
// error (i.e., not build) at something or other.
2426
const opts = { compilerOptions: copts, transpileOnly }
2527

26-
// Load gatsby babel plugin to extract graphql query
27-
const extractQueryPlugin = path.resolve(
28-
__dirname,
29-
`../gatsby/dist/utils/babel-plugin-extract-graphql.js`
30-
)
31-
3228
config.loader(`typescript`, {
3329
test,
3430
loaders: [
35-
`babel?${JSON.stringify({ plugins: [extractQueryPlugin] })}`,
31+
`babel?${JSON.stringify(babelConfig)}`,
3632
`ts-loader?${JSON.stringify(opts)}`,
3733
],
3834
})

packages/gatsby/src/utils/webpack-modify-validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const validationWhitelist = Joi.object({
1717
responsiveLoader: Joi.any(),
1818
})
1919

20-
export default (async function ValidateWebpackConfig(config, stage) {
20+
export default (async function ValidateWebpackConfig(program, config, stage) {
2121
// We don't care about the return as plugins just mutate the config directly.
22-
await apiRunnerNode(`modifyWebpackConfig`, { config, stage })
22+
await apiRunnerNode(`modifyWebpackConfig`, { program, config, stage })
2323

2424
// console.log(JSON.stringify(config, null, 4))
2525

packages/gatsby/src/utils/webpack.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ module.exports = async (
3737
webpackPort = 1500,
3838
pages = []
3939
) => {
40-
const babelStage = suppliedStage
4140
const directoryPath = withBasePath(directory)
4241

4342
// We combine develop & develop-html stages for purposes of generating the
4443
// webpack config.
4544
const stage = suppliedStage
46-
const babelConfig = await genBabelConfig(program, babelStage)
45+
const babelConfig = await genBabelConfig(program, suppliedStage)
4746

4847
function processEnv(stage, defaultNodeEnv) {
4948
debug(`Building env for "${stage}"`)
@@ -556,7 +555,7 @@ module.exports = async (
556555

557556
// Use the suppliedStage again to let plugins distinguish between
558557
// server rendering the html.js and the frontend development config.
559-
const validatedConfig = await webpackModifyValidate(config, suppliedStage)
558+
const validatedConfig = await webpackModifyValidate(program, config, suppliedStage)
560559

561560
return validatedConfig
562561
}

0 commit comments

Comments
 (0)