2018-11-15 20:48:47 +00:00
|
|
|
import path from 'path'
|
2019-01-12 20:21:43 +00:00
|
|
|
import consola from 'consola'
|
2018-11-15 20:48:47 +00:00
|
|
|
|
|
|
|
const localNodeModules = path.resolve(process.cwd(), 'node_modules')
|
|
|
|
|
|
|
|
// Prefer importing modules from local node_modules (for NPX and global bin)
|
|
|
|
async function _import(modulePath) {
|
|
|
|
let m
|
2019-01-12 20:21:43 +00:00
|
|
|
for (const mp of [ path.resolve(localNodeModules, modulePath), modulePath ]) {
|
|
|
|
try {
|
|
|
|
m = await import(mp)
|
|
|
|
} catch (e) {
|
|
|
|
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
|
|
throw e
|
|
|
|
} else if (mp === modulePath) {
|
|
|
|
consola.fatal(
|
|
|
|
`Module ${modulePath} not found.\n\n`,
|
|
|
|
`Please install missing dependency:\n\n`,
|
|
|
|
`Using npm: npm i ${modulePath}\n\n`,
|
|
|
|
`Using yarn: yarn add ${modulePath}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2018-11-15 20:48:47 +00:00
|
|
|
}
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
export const builder = () => _import('@nuxt/builder')
|
|
|
|
export const webpack = () => _import('@nuxt/webpack')
|
|
|
|
export const generator = () => _import('@nuxt/generator')
|
|
|
|
export const core = () => _import('@nuxt/core')
|
2019-01-12 20:21:43 +00:00
|
|
|
export const importModule = _import
|