rsnext/packages/next/build/babel/plugins/commonjs.ts
Guy Bedford 4dbb65d0f1
yarn dev regression fix, ncc revert (#18861)
This fixes the current regression with an ncc revert for now.

I will continue to follow up with the ncc upgrade in https://github.com/vercel/next.js/pull/18860.
2020-11-06 00:47:31 +00:00

29 lines
903 B
TypeScript

import { NodePath, PluginObj, types } from '@babel/core'
import commonjsPlugin from '@babel/plugin-transform-modules-commonjs'
// Rewrite imports using next/<something> to next-server/<something>
export default function NextToNextServer(...args: any): PluginObj {
const commonjs = commonjsPlugin(...args)
return {
visitor: {
Program: {
exit(path: NodePath<types.Program>, state) {
let foundModuleExports = false
path.traverse({
MemberExpression(expressionPath: any) {
if (expressionPath.node.object.name !== 'module') return
if (expressionPath.node.property.name !== 'exports') return
foundModuleExports = true
},
})
if (!foundModuleExports) {
return
}
commonjs.visitor.Program.exit.call(this, path, state)
},
},
},
}
}