2018-11-15 20:48:47 +00:00
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
const localNodeModules = path.resolve(process.cwd(), 'node_modules')
|
|
|
|
|
|
|
|
// Prefer importing modules from local node_modules (for NPX and global bin)
|
|
|
|
async function _import(modulePath) {
|
2019-04-15 16:13:27 +00:00
|
|
|
for (const mp of [
|
|
|
|
path.resolve(localNodeModules, modulePath),
|
|
|
|
modulePath
|
|
|
|
]) {
|
2019-01-12 20:21:43 +00:00
|
|
|
try {
|
2019-04-15 16:13:27 +00:00
|
|
|
return await import(mp)
|
2019-01-12 20:21:43 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
|
|
throw e
|
|
|
|
}
|
|
|
|
}
|
2018-11-15 20:48:47 +00:00
|
|
|
}
|
2019-04-15 16:13:27 +00:00
|
|
|
|
|
|
|
const error = new Error(`Cannot import module '${modulePath}'`)
|
|
|
|
error.code = 'MODULE_NOT_FOUND'
|
|
|
|
throw error
|
2018-11-15 20:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-29 19:19:30 +00:00
|
|
|
|
|
|
|
export const tsNode = () => _import('ts-node')
|
|
|
|
export const nuxtTypescript = () => _import('@nuxt/typescript')
|
|
|
|
|
2019-01-12 20:21:43 +00:00
|
|
|
export const importModule = _import
|