Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
nuxtConfigFile = require.resolve(path.resolve(rootDir, argv['config-file']))
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw (e)
} else if (argv['config-file'] !== defaultNuxtConfigFile) {
consola.fatal('Could not load config file: ' + argv['config-file'])
}
}
if (nuxtConfigFile) {
// Clear cache
clearRequireCache(nuxtConfigFile)
options = esm(module)(nuxtConfigFile) || {}
if (options.default) {
options = options.default
}
if (typeof options === 'function') {
try {
options = await options()
if (options.default) {
options = options.default
}
} catch (error) {
consola.error(error)
consola.fatal('Error while fetching async configuration')
}
}
function readJavascriptConfig(path: string) {
// eslint-disable-next-line
require = esm(module, {
cjs: {
dedefault: true,
},
});
delete require.cache[require.resolve(path)];
const config = require(path);
return config || {};
}
function readJavascriptManifest(path: string, target: string) {
// eslint-disable-next-line
require = esm(module, {
cjs: {
dedefault: true,
},
});
delete require.cache[require.resolve(path)];
const config =
require(path)[target] || require(path).default || require(path);
return config;
}
this._hooks = {}
this.hook = this.hook.bind(this)
// Create instance of core components
this.moduleContainer = new ModuleContainer(this)
this.renderer = new Renderer(this)
// Backward compatibility
this.render = this.renderer.app
this.renderRoute = this.renderer.renderRoute.bind(this.renderer)
this.renderAndGetWindow = this.renderer.renderAndGetWindow.bind(
this.renderer
)
// ESM Loader
this.esm = esm(module, {})
this._ready = this.ready().catch(err => {
consola.fatal(err)
})
}
function readTypescriptManifest(path: string, target: string) {
require('@babel/register')({
presets: [
['@babel/preset-env', { modules: 'commonjs' }],
'@babel/preset-typescript',
],
extensions: ['.ts'],
cache: false,
});
// eslint-disable-next-line
require = esm(module, {
cjs: {
dedefault: true,
},
});
delete require.cache[require.resolve(path)];
const config =
require(path)[target] || require(path).default || require(path);
return config;
}
constructor (nuxt) {
this.nuxt = nuxt
this.options = this.nuxt.options
// Binds
this.resolvePath = this.resolvePath.bind(this)
this.resolveAlias = this.resolveAlias.bind(this)
this.resolveModule = this.resolveModule.bind(this)
this.requireModule = this.requireModule.bind(this)
// ESM Loader
this.esm = esm(module)
this._resolve = require.resolve
}
import React from 'react';
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
import { render } from 'ink';
import esm from 'esm';
import { Maybe } from 'brookjs-types';
import { RC, RCError, RCResult } from '../RC';
import { Command } from './Command';
import Commands from './Commands';
import ErrorBoundary, {
CommandValidationError,
LoadDirError,
Root
} from './components';
const loadEsm = esm(module);
const loaders = {
...defaultLoaders,
'.js': (filename: string) => loadEsm(filename)
};
export class App {
static create(name: string, commands?: Commands) {
return new App(name, commands);
}
private constructor(
private name: string,
private commands: Commands = new Commands(),
private errors: JSX.Element[] = []
) {}
export default R.curry(function main (name, args, options, logger) {
const store = createStore(
combineReducers({ app, command, env, mocha, webpack }),
applyMiddleware(observeDelta(
envDelta({ process, require: loader(module, { mode: 'auto', cjs: true }) }),
scaffoldDelta({ logger }),
terminalDelta({ ui: ui(logger) }),
testRunnerDelta({ glob }),
webpackDelta({ webpack: WebpackService })
))
);
store.dispatch(run(name, args, options));
});