rsnext/packages/next/build/babel/loader/index.ts
Tim Neutkens 53c19ff185
Test fixes for Babel mode (#24312)
* Try enabling Babel turbo mode

* Pass config file explicitly to babel turbo loader.

* Update NextBabelLoaderOptions to use `configFile` instead of `babelrc`.

* Re-add support for options passed to next/babel preset with new babel loader.

* Load babel config files depending on their file extension.

* Include `next/babel` if no Babel config is provided.

* Minor cleanup.

* Avoid duplicate `next/babel` entries.

* No need to pass configFile anymore.

* Fix multiple small issues in merging loader opts with cached config.

* Remove redundant logging (that also breaks a test).

* Include file extension CharacteristicsGermaneToCaching.

* bump

* Disable turboMode now that tests pass

Co-authored-by: Dale Bustad <dale@divmain.com>
2021-04-28 11:51:57 +02:00

59 lines
1.5 KiB
TypeScript

import { getOptions } from 'next/dist/compiled/loader-utils'
import { trace } from '../../../telemetry/trace'
import { Span } from '../../../telemetry/trace'
import transform from './transform'
import { NextJsLoaderContext } from './types'
async function nextBabelLoader(
this: NextJsLoaderContext,
parentTrace: Span,
inputSource: string,
inputSourceMap: object | null | undefined
) {
const filename = this.resourcePath
const target = this.target
const loaderOptions = parentTrace
.traceChild('get-options')
.traceFn(() => getOptions(this))
const loaderSpanInner = parentTrace.traceChild('next-babel-turbo-transform')
const {
code: transformedSource,
map: outputSourceMap,
} = loaderSpanInner.traceFn(() =>
transform.call(
this,
inputSource,
inputSourceMap,
loaderOptions,
filename,
target,
loaderSpanInner
)
)
return [transformedSource, outputSourceMap]
}
const nextBabelLoaderOuter = function nextBabelLoaderOuter(
this: NextJsLoaderContext,
inputSource: string,
inputSourceMap: object | null | undefined
) {
const callback = this.async()
const loaderSpan = trace('next-babel-turbo-loader', this.currentTraceSpan?.id)
loaderSpan
.traceAsyncFn(() =>
nextBabelLoader.call(this, loaderSpan, inputSource, inputSourceMap)
)
.then(
([transformedSource, outputSourceMap]) =>
callback?.(null, transformedSource, outputSourceMap || inputSourceMap),
(err) => {
callback?.(err)
}
)
}
export default nextBabelLoaderOuter