Skip to content

Commit afd09d1

Browse files
author
Vladimir Pouzanov
committed
Pass the babel config around to simplify the pipelines that need to use babel
1 parent fafdc3f commit afd09d1

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

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

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

17-
it(`modifies webpack config`, async () => {
18-
const stage = ``
19-
const program = {
20-
directory: `.`,
21-
browserslist: [],
22-
}
17+
it(`modifies webpack config`, () => {
18+
const babelConfig = { "plugins":[``] }
2319
const config = {
2420
loader: jest.fn(),
2521
}
2622

27-
await modifyWebpackConfig({ program, config, stage }, { compilerOptions: {} })
23+
modifyWebpackConfig({ config, babelConfig }, { compilerOptions: {} })
2824

2925
expect(config.loader).toHaveBeenCalledTimes(1)
3026
const lastCall = config.loader.mock.calls.pop()
3127
expect(lastCall).toMatchSnapshot()
3228
})
3329

3430
it(`passes the configuration to the ts-loader plugin`, () => {
31+
const babelConfig = { "plugins":[``] }
3532
const config = {
3633
loader: jest.fn(),
3734
}
3835
const options = { compilerOptions: { foo: `bar` }, transpileOnly: false }
3936

40-
modifyWebpackConfig({ config }, options)
37+
modifyWebpackConfig({ config, babelConfig }, options)
4138

4239
const expectedOptions = {
4340
compilerOptions: {
@@ -60,10 +57,11 @@ describe(`gatsby-plugin-typescript`, () => {
6057
})
6158

6259
it(`uses default configuration for the ts-loader plugin when no config is provided`, () => {
60+
const babelConfig = { "plugins":[``] }
6361
const config = {
6462
loader: jest.fn(),
6563
}
66-
modifyWebpackConfig({ config }, { compilerOptions: {} })
64+
modifyWebpackConfig({ config, babelConfig }, { compilerOptions: {} })
6765

6866
const expectedOptions = {
6967
compilerOptions: {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const genBabelConfig = require(`gatsby/dist/utils/babel-config`)
21
const { transpileModule } = require(`typescript`)
32

43
const test = /\.tsx?$/
@@ -10,12 +9,10 @@ const compilerDefaults = {
109

1110
module.exports.resolvableExtensions = () => [`.ts`, `.tsx`]
1211

13-
module.exports.modifyWebpackConfig = async (
14-
{ program, config, stage },
12+
module.exports.modifyWebpackConfig = (
13+
{ config, babelConfig },
1514
{ compilerOptions, transpileOnly = true }
1615
) => {
17-
const babelConfig = await genBabelConfig(program, stage)
18-
1916
// CommonJS to keep Webpack happy.
2017
const copts = Object.assign({}, compilerDefaults, compilerOptions, {
2118
module: `commonjs`,

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ module.exports = async (
555555

556556
// Use the suppliedStage again to let plugins distinguish between
557557
// server rendering the html.js and the frontend development config.
558-
const validatedConfig = await webpackModifyValidate(program, config, suppliedStage)
558+
const validatedConfig = await webpackModifyValidate(program, config, babelConfig, suppliedStage)
559559

560560
return validatedConfig
561561
}

0 commit comments

Comments
 (0)