2022-01-27 16:48:09 +01:00
|
|
|
import { parse } from '../../swc'
|
2021-10-26 18:50:56 +02:00
|
|
|
|
|
|
|
export default async function transformSource(
|
|
|
|
this: any,
|
|
|
|
source: string
|
|
|
|
): Promise<string> {
|
2022-05-13 19:48:53 +02:00
|
|
|
const { resourcePath } = this
|
2022-02-28 16:00:28 +01:00
|
|
|
|
2022-05-13 19:48:53 +02:00
|
|
|
const ast = await parse(source, {
|
|
|
|
filename: resourcePath,
|
|
|
|
isModule: 'unknown',
|
2022-03-02 19:29:54 +01:00
|
|
|
})
|
2022-05-13 19:48:53 +02:00
|
|
|
const isModule = ast.type === 'Module'
|
|
|
|
|
|
|
|
return (
|
|
|
|
source +
|
|
|
|
(isModule
|
|
|
|
? `
|
|
|
|
export const __next_rsc__ = {
|
|
|
|
__webpack_require__,
|
|
|
|
server: true
|
2022-04-01 18:13:38 +02:00
|
|
|
}
|
2022-05-13 19:48:53 +02:00
|
|
|
`
|
|
|
|
: `
|
|
|
|
exports.__next_rsc__ = {
|
|
|
|
__webpack_require__,
|
|
|
|
server: true
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
)
|
2021-10-26 18:50:56 +02:00
|
|
|
}
|