Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move getBabelConfigFile to separate file #54716

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/next/src/build/get-babel-config-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { fileExists } from '../lib/file-exists'
import { join } from 'path'

const BABEL_CONFIG_FILES = [
'.babelrc',
'.babelrc.json',
'.babelrc.js',
'.babelrc.mjs',
'.babelrc.cjs',
'babel.config.js',
'babel.config.json',
'babel.config.mjs',
'babel.config.cjs',
]

export async function getBabelConfigFile(
dir: string
): Promise<string | undefined> {
const babelConfigFile = await BABEL_CONFIG_FILES.reduce(
async (memo: Promise<string | undefined>, filename) => {
const configFilePath = join(dir, filename)
return (
(await memo) ||
((await fileExists(configFilePath)) ? configFilePath : undefined)
)
},
Promise.resolve(undefined)
)
return babelConfigFile
timneutkens marked this conversation as resolved.
Show resolved Hide resolved
}
28 changes: 1 addition & 27 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
RSC_ACTION_VALIDATE_ALIAS,
WEBPACK_RESOURCE_QUERIES,
} from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { CustomRoutes } from '../lib/load-custom-routes.js'
import { isEdgeRuntime } from '../lib/is-edge-runtime'
import {
Expand Down Expand Up @@ -68,6 +67,7 @@ import { SubresourceIntegrityPlugin } from './webpack/plugins/subresource-integr
import { NextFontManifestPlugin } from './webpack/plugins/next-font-manifest-plugin'
import { getSupportedBrowsers } from './utils'
import { MemoryWithGcCachePlugin } from './webpack/plugins/memory-with-gc-cache-plugin'
import { getBabelConfigFile } from './get-babel-config-file'

type ExcludesFalse = <T>(x: T | false) => x is T
type ClientEntries = {
Expand Down Expand Up @@ -118,32 +118,6 @@ const mainFieldsPerCompiler: Record<CompilerNameValues, string[]> = {
[COMPILER_NAMES.edgeServer]: edgeConditionNames,
}

const BABEL_CONFIG_FILES = [
'.babelrc',
'.babelrc.json',
'.babelrc.js',
'.babelrc.mjs',
'.babelrc.cjs',
'babel.config.js',
'babel.config.json',
'babel.config.mjs',
'babel.config.cjs',
]

export const getBabelConfigFile = async (dir: string) => {
const babelConfigFile = await BABEL_CONFIG_FILES.reduce(
async (memo: Promise<string | undefined>, filename) => {
const configFilePath = path.join(dir, filename)
return (
(await memo) ||
((await fileExists(configFilePath)) ? configFilePath : undefined)
)
},
Promise.resolve(undefined)
)
return babelConfigFile
}

// Support for NODE_PATH
const nodePathList = (process.env.NODE_PATH || '')
.split(process.platform === 'win32' ? ';' : ':')
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/lib/turbopack-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function validateTurboNextConfig({
const { getPkgManager } =
require('../lib/helpers/get-pkg-manager') as typeof import('../lib/helpers/get-pkg-manager')
const { getBabelConfigFile } =
require('../build/webpack-config') as typeof import('../build/webpack-config')
require('../build/get-babel-config-file') as typeof import('../build/get-babel-config-file')
const { defaultConfig } =
require('../server/config-shared') as typeof import('../server/config-shared')
const chalk =
Expand Down