cli-index.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /*!
  2. * @nuxt/cli v2.15.8 (c) 2016-2021
  3. * Released under the MIT License
  4. * Repository: https://github.com/nuxt/nuxt.js
  5. * Website: https://nuxtjs.org
  6. */
  7. 'use strict';
  8. const utils = require('@nuxt/utils');
  9. const config = require('@nuxt/config');
  10. const path = require('path');
  11. const exit = require('exit');
  12. const chalk = require('chalk');
  13. const env = require('std-env');
  14. const wrapAnsi = require('wrap-ansi');
  15. const boxen = require('boxen');
  16. const consola = require('consola');
  17. const minimist = require('minimist');
  18. const Hookable = require('hable');
  19. const defu = require('defu');
  20. const semver = require('semver');
  21. const fs = require('fs');
  22. const execa = require('execa');
  23. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  24. const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  25. const exit__default = /*#__PURE__*/_interopDefaultLegacy(exit);
  26. const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
  27. const env__default = /*#__PURE__*/_interopDefaultLegacy(env);
  28. const wrapAnsi__default = /*#__PURE__*/_interopDefaultLegacy(wrapAnsi);
  29. const boxen__default = /*#__PURE__*/_interopDefaultLegacy(boxen);
  30. const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
  31. const minimist__default = /*#__PURE__*/_interopDefaultLegacy(minimist);
  32. const Hookable__default = /*#__PURE__*/_interopDefaultLegacy(Hookable);
  33. const defu__default = /*#__PURE__*/_interopDefaultLegacy(defu);
  34. const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
  35. const execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
  36. const commands = {
  37. start: () => Promise.resolve().then(function () { return require('./cli-start.js'); }),
  38. serve: () => Promise.resolve().then(function () { return require('./cli-serve.js'); }),
  39. dev: () => Promise.resolve().then(function () { return require('./cli-dev.js'); }),
  40. build: () => Promise.resolve().then(function () { return require('./cli-build.js'); }),
  41. generate: () => Promise.resolve().then(function () { return require('./cli-generate.js'); }),
  42. export: () => Promise.resolve().then(function () { return require('./cli-export.js'); }),
  43. webpack: () => Promise.resolve().then(function () { return require('./cli-webpack.js'); }),
  44. help: () => Promise.resolve().then(function () { return require('./cli-help.js'); })
  45. };
  46. function getCommand (name) {
  47. if (!commands[name]) {
  48. return Promise.resolve(null)
  49. }
  50. return commands[name]().then(m => m.default)
  51. }
  52. const index$1 = /*#__PURE__*/Object.freeze({
  53. __proto__: null,
  54. 'default': getCommand
  55. });
  56. const importModule = (id) => {
  57. try {
  58. return Promise.resolve(utils.requireModule(id))
  59. } catch (err) {
  60. if (err.code === 'MODULE_NOT_FOUND') {
  61. err.message = `Cannot import module '${id}'`;
  62. }
  63. return Promise.reject(err)
  64. }
  65. };
  66. const builder = () => importModule('@nuxt/builder');
  67. const webpack = () => importModule('@nuxt/webpack');
  68. const generator = () => importModule('@nuxt/generator');
  69. const core = () => importModule('@nuxt/core');
  70. const server$1 = () => importModule('@nuxt/server');
  71. const imports = /*#__PURE__*/Object.freeze({
  72. __proto__: null,
  73. importModule: importModule,
  74. builder: builder,
  75. webpack: webpack,
  76. generator: generator,
  77. core: core,
  78. server: server$1
  79. });
  80. const forceExitTimeout = 5;
  81. const startSpaces = 2;
  82. const optionSpaces = 2;
  83. // 80% of terminal column width
  84. // this is a fn because console width can have changed since startup
  85. const maxCharsPerLine = () => (process.stdout.columns || 100) * 80 / 100;
  86. function indent (count, chr = ' ') {
  87. return chr.repeat(count)
  88. }
  89. function indentLines (string, spaces, firstLineSpaces) {
  90. const lines = Array.isArray(string) ? string : string.split('\n');
  91. let s = '';
  92. if (lines.length) {
  93. const i0 = indent(firstLineSpaces === undefined ? spaces : firstLineSpaces);
  94. s = i0 + lines.shift();
  95. }
  96. if (lines.length) {
  97. const i = indent(spaces);
  98. s += '\n' + lines.map(l => i + l).join('\n');
  99. }
  100. return s
  101. }
  102. function foldLines (string, spaces, firstLineSpaces, charsPerLine = maxCharsPerLine()) {
  103. return indentLines(wrapAnsi__default['default'](string, charsPerLine), spaces, firstLineSpaces)
  104. }
  105. function colorize (text) {
  106. return text
  107. .replace(/\[[^ ]+]/g, m => chalk__default['default'].grey(m))
  108. .replace(/<[^ ]+>/g, m => chalk__default['default'].green(m))
  109. .replace(/ (-[-\w,]+)/g, m => chalk__default['default'].bold(m))
  110. .replace(/`([^`]+)`/g, (_, m) => chalk__default['default'].bold.cyan(m))
  111. }
  112. function box (message, title, options) {
  113. return boxen__default['default']([
  114. title || chalk__default['default'].white('Nuxt Message'),
  115. '',
  116. chalk__default['default'].white(foldLines(message, 0, 0, maxCharsPerLine()))
  117. ].join('\n'), Object.assign({
  118. borderColor: 'white',
  119. borderStyle: 'round',
  120. padding: 1,
  121. margin: 1
  122. }, options)) + '\n'
  123. }
  124. function successBox (message, title) {
  125. return box(message, title || chalk__default['default'].green('✔ Nuxt Success'), {
  126. borderColor: 'green'
  127. })
  128. }
  129. function warningBox (message, title) {
  130. return box(message, title || chalk__default['default'].yellow('⚠ Nuxt Warning'), {
  131. borderColor: 'yellow'
  132. })
  133. }
  134. function errorBox (message, title) {
  135. return box(message, title || chalk__default['default'].red('✖ Nuxt Error'), {
  136. borderColor: 'red'
  137. })
  138. }
  139. function fatalBox (message, title) {
  140. return errorBox(message, title || chalk__default['default'].red('✖ Nuxt Fatal Error'))
  141. }
  142. const eventsMapping = {
  143. add: { icon: '+', color: 'green', action: 'Created' },
  144. change: { icon: env__default['default'].windows ? '»' : '↻', color: 'blue', action: 'Updated' },
  145. unlink: { icon: '-', color: 'red', action: 'Removed' }
  146. };
  147. function formatPath (filePath) {
  148. if (!filePath) {
  149. return
  150. }
  151. return filePath.replace(process.cwd() + path__default['default'].sep, '')
  152. }
  153. /**
  154. * Normalize string argument in command
  155. *
  156. * @export
  157. * @param {String} argument
  158. * @param {*} defaultValue
  159. * @returns formatted argument
  160. */
  161. function normalizeArg (arg, defaultValue) {
  162. switch (arg) {
  163. case 'true': arg = true; break
  164. case '': arg = true; break
  165. case 'false': arg = false; break
  166. case undefined: arg = defaultValue; break
  167. }
  168. return arg
  169. }
  170. function forceExit (cmdName, timeout) {
  171. if (timeout !== false) {
  172. const exitTimeout = setTimeout(() => {
  173. const msg = `The command 'nuxt ${cmdName}' finished but did not exit after ${timeout}s
  174. This is most likely not caused by a bug in Nuxt
  175. Make sure to cleanup all timers and listeners you or your plugins/modules start.
  176. Nuxt will now force exit
  177. ${chalk__default['default'].bold('DeprecationWarning: Starting with Nuxt version 3 this will be a fatal error')}`;
  178. // TODO: Change this to a fatal error in v3
  179. process.stderr.write(warningBox(msg));
  180. exit__default['default'](0);
  181. }, timeout * 1000);
  182. exitTimeout.unref();
  183. } else {
  184. exit__default['default'](0);
  185. }
  186. }
  187. // An immediate export throws an error when mocking with jest
  188. // TypeError: Cannot set property createLock of #<Object> which has only a getter
  189. function createLock (...args) {
  190. return utils.lock(...args)
  191. }
  192. const common = {
  193. spa: {
  194. alias: 's',
  195. type: 'boolean',
  196. description: 'Launch in SPA mode'
  197. },
  198. universal: {
  199. alias: 'u',
  200. type: 'boolean',
  201. description: 'Launch in Universal mode (default)'
  202. },
  203. 'config-file': {
  204. alias: 'c',
  205. type: 'string',
  206. default: config.defaultNuxtConfigFile,
  207. description: `Path to Nuxt config file (default: \`${config.defaultNuxtConfigFile}\`)`
  208. },
  209. modern: {
  210. alias: 'm',
  211. type: 'string',
  212. description: 'Build/Start app for modern browsers, e.g. server, client and false',
  213. prepare (cmd, options, argv) {
  214. if (argv.modern !== undefined) {
  215. options.modern = normalizeArg(argv.modern);
  216. }
  217. }
  218. },
  219. target: {
  220. alias: 't',
  221. type: 'string',
  222. description: 'Build/start app for a different target, e.g. server, serverless and static',
  223. prepare (cmd, options, argv) {
  224. if (argv.target) {
  225. options.target = argv.target;
  226. }
  227. }
  228. },
  229. 'force-exit': {
  230. type: 'boolean',
  231. default (cmd) {
  232. return ['build', 'generate', 'export'].includes(cmd.name)
  233. },
  234. description: 'Whether Nuxt should force exit after the command has finished'
  235. },
  236. version: {
  237. alias: 'v',
  238. type: 'boolean',
  239. description: 'Display the Nuxt version'
  240. },
  241. help: {
  242. alias: 'h',
  243. type: 'boolean',
  244. description: 'Display this message'
  245. },
  246. processenv: {
  247. type: 'boolean',
  248. default: true,
  249. description: 'Disable reading from `process.env` and updating it with dotenv'
  250. },
  251. dotenv: {
  252. type: 'string',
  253. default: '.env',
  254. description: 'Specify path to dotenv file (default: `.env`). Use `false` to disable'
  255. }
  256. };
  257. const server = {
  258. port: {
  259. alias: 'p',
  260. type: 'string',
  261. description: 'Port number on which to start the application',
  262. prepare (cmd, options, argv) {
  263. if (argv.port) {
  264. options.server.port = +argv.port;
  265. }
  266. }
  267. },
  268. hostname: {
  269. alias: 'H',
  270. type: 'string',
  271. description: 'Hostname on which to start the application',
  272. prepare (cmd, options, argv) {
  273. if (argv.hostname === '') {
  274. consola__default['default'].fatal('Provided hostname argument has no value');
  275. }
  276. }
  277. },
  278. 'unix-socket': {
  279. alias: 'n',
  280. type: 'string',
  281. description: 'Path to a UNIX socket'
  282. }
  283. };
  284. const locking = {
  285. lock: {
  286. type: 'boolean',
  287. default: true,
  288. description: 'Do not set a lock on the project when building'
  289. }
  290. };
  291. const index = /*#__PURE__*/Object.freeze({
  292. __proto__: null,
  293. common: common,
  294. server: server,
  295. locking: locking
  296. });
  297. var name = "@nuxt/cli";
  298. var version = "2.15.8";
  299. async function loadNuxtConfig (argv, configContext) {
  300. const rootDir = path__default['default'].resolve(argv._[0] || '.');
  301. const configFile = argv['config-file'];
  302. // Load config
  303. const options = await config.loadNuxtConfig({
  304. rootDir,
  305. configFile,
  306. configContext,
  307. envConfig: {
  308. dotenv: argv.dotenv === 'false' ? false : argv.dotenv,
  309. env: argv.processenv ? process.env : {}
  310. }
  311. });
  312. if (argv.spa === true) {
  313. options.ssr = false;
  314. } else if (argv.universal === true) {
  315. options.ssr = true;
  316. }
  317. // Server options
  318. options.server = defu__default['default']({
  319. port: argv.port || null,
  320. host: argv.hostname || null,
  321. socket: argv['unix-socket'] || null
  322. }, options.server || {}, config.getDefaultNuxtConfig().server);
  323. return options
  324. }
  325. class NuxtCommand extends Hookable__default['default'] {
  326. constructor (cmd = { name: '', usage: '', description: '' }, argv = process.argv.slice(2), hooks = {}) {
  327. super(consola__default['default']);
  328. this.addHooks(hooks);
  329. if (!cmd.options) {
  330. cmd.options = {};
  331. }
  332. this.cmd = cmd;
  333. this._argv = Array.from(argv);
  334. this._parsedArgv = null; // Lazy evaluate
  335. }
  336. static run (cmd, argv, hooks) {
  337. return NuxtCommand.from(cmd, argv, hooks).run()
  338. }
  339. static from (cmd, argv, hooks) {
  340. if (cmd instanceof NuxtCommand) {
  341. return cmd
  342. }
  343. return new NuxtCommand(cmd, argv, hooks)
  344. }
  345. async run () {
  346. await this.callHook('run:before', {
  347. argv: this._argv,
  348. cmd: this.cmd,
  349. rootDir: path__default['default'].resolve(this.argv._[0] || '.')
  350. });
  351. if (this.argv.help) {
  352. this.showHelp();
  353. return
  354. }
  355. if (this.argv.version) {
  356. this.showVersion();
  357. return
  358. }
  359. if (typeof this.cmd.run !== 'function') {
  360. throw new TypeError('Invalid command! Commands should at least implement run() function.')
  361. }
  362. let cmdError;
  363. try {
  364. await this.cmd.run(this);
  365. } catch (e) {
  366. cmdError = e;
  367. }
  368. if (this.argv.lock) {
  369. await this.releaseLock();
  370. }
  371. if (this.argv['force-exit']) {
  372. const forceExitByUser = this.isUserSuppliedArg('force-exit');
  373. if (cmdError) {
  374. consola__default['default'].fatal(cmdError);
  375. }
  376. forceExit(this.cmd.name, forceExitByUser ? false : forceExitTimeout);
  377. if (forceExitByUser) {
  378. return
  379. }
  380. }
  381. if (cmdError) {
  382. throw cmdError
  383. }
  384. }
  385. showVersion () {
  386. process.stdout.write(`${name} v${version}\n`);
  387. }
  388. showHelp () {
  389. process.stdout.write(this._getHelp());
  390. }
  391. get argv () {
  392. if (!this._parsedArgv) {
  393. const minimistOptions = this._getMinimistOptions();
  394. this._parsedArgv = minimist__default['default'](this._argv, minimistOptions);
  395. }
  396. return this._parsedArgv
  397. }
  398. async getNuxtConfig (extraOptions = {}) {
  399. // Flag to indicate nuxt is running with CLI (not programmatic)
  400. extraOptions._cli = true;
  401. const context = {
  402. command: this.cmd.name,
  403. dev: !!extraOptions.dev
  404. };
  405. const config = await loadNuxtConfig(this.argv, context);
  406. const options = Object.assign(config, extraOptions);
  407. for (const name of Object.keys(this.cmd.options)) {
  408. this.cmd.options[name].prepare && this.cmd.options[name].prepare(this, options, this.argv);
  409. }
  410. await this.callHook('config', options);
  411. return options
  412. }
  413. async getNuxt (options) {
  414. const { Nuxt } = await core();
  415. const nuxt = new Nuxt(options);
  416. await nuxt.ready();
  417. return nuxt
  418. }
  419. async getBuilder (nuxt) {
  420. const { Builder } = await builder();
  421. const { BundleBuilder } = await webpack();
  422. return new Builder(nuxt, BundleBuilder)
  423. }
  424. async getGenerator (nuxt) {
  425. const { Generator } = await generator();
  426. const builder = await this.getBuilder(nuxt);
  427. return new Generator(nuxt, builder)
  428. }
  429. async setLock (lockRelease) {
  430. if (lockRelease) {
  431. if (this._lockRelease) {
  432. consola__default['default'].warn(`A previous unreleased lock was found, this shouldn't happen and is probably an error in 'nuxt ${this.cmd.name}' command. The lock will be removed but be aware of potential strange results`);
  433. await this.releaseLock();
  434. this._lockRelease = lockRelease;
  435. } else {
  436. this._lockRelease = lockRelease;
  437. }
  438. }
  439. }
  440. async releaseLock () {
  441. if (this._lockRelease) {
  442. await this._lockRelease();
  443. this._lockRelease = undefined;
  444. }
  445. }
  446. isUserSuppliedArg (option) {
  447. return this._argv.includes(`--${option}`) || this._argv.includes(`--no-${option}`)
  448. }
  449. _getDefaultOptionValue (option) {
  450. return typeof option.default === 'function' ? option.default(this.cmd) : option.default
  451. }
  452. _getMinimistOptions () {
  453. const minimistOptions = {
  454. alias: {},
  455. boolean: [],
  456. string: [],
  457. default: {}
  458. };
  459. for (const name of Object.keys(this.cmd.options)) {
  460. const option = this.cmd.options[name];
  461. if (option.alias) {
  462. minimistOptions.alias[option.alias] = name;
  463. }
  464. if (option.type) {
  465. minimistOptions[option.type].push(option.alias || name);
  466. }
  467. if (option.default) {
  468. minimistOptions.default[option.alias || name] = this._getDefaultOptionValue(option);
  469. }
  470. }
  471. return minimistOptions
  472. }
  473. _getHelp () {
  474. const options = [];
  475. let maxOptionLength = 0;
  476. for (const name in this.cmd.options) {
  477. const option = this.cmd.options[name];
  478. let optionHelp = '--';
  479. optionHelp += option.type === 'boolean' && this._getDefaultOptionValue(option) ? 'no-' : '';
  480. optionHelp += name;
  481. if (option.alias) {
  482. optionHelp += `, -${option.alias}`;
  483. }
  484. maxOptionLength = Math.max(maxOptionLength, optionHelp.length);
  485. options.push([optionHelp, option.description]);
  486. }
  487. const _opts = options.map(([option, description]) => {
  488. const i = indent(maxOptionLength + optionSpaces - option.length);
  489. return foldLines(
  490. option + i + description,
  491. startSpaces + maxOptionLength + optionSpaces * 2,
  492. startSpaces + optionSpaces
  493. )
  494. }).join('\n');
  495. const usage = foldLines(`Usage: nuxt ${this.cmd.usage} [options]`, startSpaces);
  496. const description = foldLines(this.cmd.description, startSpaces);
  497. const opts = foldLines('Options:', startSpaces) + '\n\n' + _opts;
  498. let helpText = colorize(`${usage}\n\n`);
  499. if (this.cmd.description) {
  500. helpText += colorize(`${description}\n\n`);
  501. }
  502. if (options.length) {
  503. helpText += colorize(`${opts}\n\n`);
  504. }
  505. return helpText
  506. }
  507. }
  508. const dependencies = {
  509. webpack: '^4.46.0',
  510. 'css-loader': '>=4.2.0',
  511. 'sass-loader': '^10.1.1'
  512. };
  513. const nodeVersion = '>=12.0.0';
  514. function getInstalledVersion (name) {
  515. try {
  516. return utils.getPKG(name).version
  517. } catch { }
  518. }
  519. function checkDependencies () {
  520. for (const name in dependencies) {
  521. const installedVersion = getInstalledVersion(name);
  522. if (!installedVersion) {
  523. continue // Ignore to avoid false-positive warnings
  524. }
  525. const expectedRange = dependencies[name];
  526. if (!semver.satisfies(installedVersion, expectedRange)) {
  527. consola__default['default'].warn(`${name}@${installedVersion} is installed but ${expectedRange} is expected`);
  528. }
  529. }
  530. // Check Node versions
  531. if (!semver.satisfies(process.version, nodeVersion)) {
  532. consola__default['default'].warn(`You are using an unsupported version of Node.js (${process.version}). It is recommended to use the latest LTS version (https://nodejs.org/en/about/releases)`);
  533. }
  534. }
  535. let _setup = false;
  536. function setup ({ dev }) {
  537. // Apply default NODE_ENV if not provided
  538. if (!process.env.NODE_ENV) {
  539. process.env.NODE_ENV = dev ? 'development' : 'production';
  540. }
  541. if (_setup) {
  542. return
  543. }
  544. _setup = true;
  545. checkDependencies();
  546. // Global error handler
  547. /* istanbul ignore next */
  548. process.on('unhandledRejection', (err) => {
  549. consola__default['default'].error(err);
  550. });
  551. // Exit process on fatal errors
  552. /* istanbul ignore next */
  553. consola__default['default'].addReporter({
  554. log (logObj) {
  555. if (logObj.type === 'fatal') {
  556. const errorMessage = String(logObj.args[0]);
  557. process.stderr.write(fatalBox(errorMessage));
  558. exit__default['default'](1);
  559. }
  560. }
  561. });
  562. // Wrap all console logs with consola for better DX
  563. consola__default['default'].wrapConsole();
  564. }
  565. function isNuxtDir (rootDir) {
  566. if (fs__default['default'].existsSync(path__default['default'].join(rootDir, 'nuxt.config.js')) ||
  567. fs__default['default'].existsSync(path__default['default'].join(rootDir, 'pages')) ||
  568. fs__default['default'].existsSync(path__default['default'].join(rootDir, 'nuxt.config.ts'))) {
  569. return true
  570. }
  571. return false
  572. }
  573. async function run (_argv, hooks = {}) {
  574. // Check for not installing both nuxt and nuxt-edge
  575. const dupPkg = 'cli-edge';
  576. const dupPkgJSON = path.resolve(__dirname, '../..' /* dist/../.. */, dupPkg, 'package.json');
  577. if (fs.existsSync(dupPkgJSON) && utils.requireModule(dupPkgJSON).name !== '@nuxt/' + dupPkg) {
  578. consola__default['default'].warn('Both `nuxt` and `nuxt-edge` dependencies are installed! Please choose one and remove the other one from dependencies.');
  579. }
  580. // Read from process.argv
  581. const argv = _argv ? Array.from(_argv) : process.argv.slice(2);
  582. // Check for internal command
  583. let cmd = await getCommand(argv[0]);
  584. // Matching `nuxt` or `nuxt [dir]` or `nuxt -*` for `nuxt dev` shortcut
  585. if (!cmd && (!argv[0] || argv[0][0] === '-' || isNuxtDir(argv[0]))) {
  586. argv.unshift('dev');
  587. cmd = await getCommand('dev');
  588. }
  589. // Check for dev
  590. const dev = argv[0] === 'dev';
  591. // Setup env
  592. setup({ dev });
  593. // Try internal command
  594. if (cmd) {
  595. return NuxtCommand.run(cmd, argv.slice(1), hooks)
  596. }
  597. // Try external command
  598. try {
  599. await execa__default['default'](`nuxt-${argv[0]}`, argv.slice(1), {
  600. stdout: process.stdout,
  601. stderr: process.stderr,
  602. stdin: process.stdin
  603. });
  604. } catch (error) {
  605. if (error.exitCode === 2) {
  606. throw String(`Command not found: nuxt-${argv[0]}`)
  607. }
  608. throw String(`Failed to run command \`nuxt-${argv[0]}\`:\n${error}`)
  609. }
  610. }
  611. async function getWebpackConfig (name = 'client', loadOptions = {}) {
  612. const { loadNuxt } = await core();
  613. const { getBuilder } = await builder();
  614. const nuxt = await loadNuxt(loadOptions);
  615. const builder$1 = await getBuilder(nuxt);
  616. const { bundleBuilder } = builder$1;
  617. return bundleBuilder.getWebpackConfig(name)
  618. }
  619. exports.NuxtCommand = NuxtCommand;
  620. exports.colorize = colorize;
  621. exports.common = common;
  622. exports.core = core;
  623. exports.createLock = createLock;
  624. exports.eventsMapping = eventsMapping;
  625. exports.foldLines = foldLines;
  626. exports.formatPath = formatPath;
  627. exports.getCommand = getCommand;
  628. exports.getWebpackConfig = getWebpackConfig;
  629. exports.imports = imports;
  630. exports.indent = indent;
  631. exports.index = index$1;
  632. exports.index$1 = index;
  633. exports.isNuxtDir = isNuxtDir;
  634. exports.loadNuxtConfig = loadNuxtConfig;
  635. exports.locking = locking;
  636. exports.normalizeArg = normalizeArg;
  637. exports.optionSpaces = optionSpaces;
  638. exports.run = run;
  639. exports.server = server$1;
  640. exports.server$1 = server;
  641. exports.setup = setup;
  642. exports.startSpaces = startSpaces;
  643. exports.successBox = successBox;