8221c180a5
This upgrades to ncc@0.25.0 and fixes the previous bugs including: * ncc not referenced correctly in build * Babel type errors * node-fetch, etag, chalk and raw-body dependencies not building with ncc - these have been "un-ncc'd" for now. As they are relatively small dependencies, this doesn't seem too much of an issue and we can follow up in the tracking ncc issue at https://github.com/vercel/ncc/issues/612. * `yarn dev` issues Took a lot of bisecting, but the overall diff isn't too bad here in the end.
29 lines
939 B
TypeScript
29 lines
939 B
TypeScript
import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core'
|
|
import commonjsPlugin from 'next/dist/compiled/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)
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|