9fa8baa03a
* Uses the PnP API when available * Moves the resolution into an helper * Update packages/next/lib/resolve-request.ts Co-Authored-By: Joe Haddad <joe.haddad@zeit.co> * Apply Prettier
19 lines
694 B
TypeScript
19 lines
694 B
TypeScript
import resolve from 'next/dist/compiled/resolve/index.js'
|
|
import path from 'path'
|
|
|
|
export function resolveRequest(req: string, issuer: string) {
|
|
// The `resolve` package is prebuilt through ncc, which prevents
|
|
// PnP from being able to inject itself into it. To circumvent
|
|
// this, we simply use PnP directly when available.
|
|
// @ts-ignore
|
|
if (process.versions.pnp) {
|
|
const { resolveRequest } = require(`pnpapi`)
|
|
return resolveRequest(req, issuer, { considerBuiltins: false })
|
|
} else {
|
|
const basedir =
|
|
issuer.endsWith(path.posix.sep) || issuer.endsWith(path.win32.sep)
|
|
? issuer
|
|
: path.dirname(issuer)
|
|
return resolve.sync(req, { basedir })
|
|
}
|
|
}
|