This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+89
View File
@@ -0,0 +1,89 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
const chalk = _interopDefault(require('chalk'));
const env = _interopDefault(require('std-env'));
const consola = _interopDefault(require('consola'));
const prettyBytes = _interopDefault(require('pretty-bytes'));
function getMemoryUsage () {
// https://nodejs.org/api/process.html#process_process_memoryusage
const { heapUsed, rss } = process.memoryUsage();
return { heap: heapUsed, rss }
}
function getFormattedMemoryUsage () {
const { heap, rss } = getMemoryUsage();
return `Memory usage: ${chalk.bold(prettyBytes(heap))} (RSS: ${prettyBytes(rss)})`
}
function showMemoryUsage () {
consola.info(getFormattedMemoryUsage());
}
function showBanner (nuxt, showMemoryUsage = true) {
if (env.test) {
return
}
if (env.minimalCLI) {
for (const listener of nuxt.server.listeners) {
consola.info('Listening on: ' + listener.url);
}
return
}
const titleLines = [];
const messageLines = [];
// Name and version
const { bannerColor, badgeMessages } = nuxt.options.cli;
titleLines.push(`${chalk[bannerColor].bold('Nuxt.js')} @ ${nuxt.constructor.version || 'exotic'}\n`);
const label = name => chalk.bold.cyan(`${name}:`);
// Environment
const isDev = nuxt.options.dev;
let _env = isDev ? 'development' : 'production';
if (process.env.NODE_ENV !== _env) {
_env += ` (${chalk.cyan(process.env.NODE_ENV)})`;
}
titleLines.push(`${label('Environment')} ${_env}`);
// Rendering
const isSSR = nuxt.options.render.ssr;
const rendering = isSSR ? 'server-side' : 'client-side';
titleLines.push(`${label('Rendering')} ${rendering}`);
// Target
const target = nuxt.options.target || 'server';
titleLines.push(`${label('Target')} ${target}`);
if (showMemoryUsage) {
titleLines.push('\n' + getFormattedMemoryUsage());
}
// Listeners
for (const listener of nuxt.server.listeners) {
messageLines.push(chalk.bold('Listening: ') + chalk.underline.blue(listener.url));
}
// Add custom badge messages
if (badgeMessages.length) {
messageLines.push('', ...badgeMessages);
}
process.stdout.write(index.successBox(messageLines.join('\n'), titleLines.join('\n')));
}
exports.showBanner = showBanner;
exports.showMemoryUsage = showMemoryUsage;
+115
View File
@@ -0,0 +1,115 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
const utils = require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
const consola = _interopDefault(require('consola'));
require('minimist');
require('hable');
require('fs');
require('execa');
const build = {
name: 'build',
description: 'Compiles the application for production deployment',
usage: 'build <dir>',
options: {
...index.common,
...index.locking,
analyze: {
alias: 'a',
type: 'boolean',
description: 'Launch webpack-bundle-analyzer to optimize your bundles',
prepare (cmd, options, argv) {
// Analyze option
options.build = options.build || {};
if (argv.analyze && typeof options.build.analyze !== 'object') {
options.build.analyze = true;
}
}
},
devtools: {
type: 'boolean',
default: false,
description: 'Enable Vue devtools',
prepare (cmd, options, argv) {
options.vue = options.vue || {};
options.vue.config = options.vue.config || {};
if (argv.devtools) {
options.vue.config.devtools = true;
}
}
},
generate: {
type: 'boolean',
default: true,
description: 'Don\'t generate static version for SPA mode (useful for nuxt start)'
},
quiet: {
alias: 'q',
type: 'boolean',
description: 'Disable output except for errors',
prepare (cmd, options, argv) {
// Silence output when using --quiet
options.build = options.build || {};
if (argv.quiet) {
options.build.quiet = Boolean(argv.quiet);
}
}
},
standalone: {
type: 'boolean',
default: false,
description: 'Bundle all server dependencies (useful for nuxt-start)',
prepare (cmd, options, argv) {
if (argv.standalone) {
options.build.standalone = true;
}
}
}
},
async run (cmd) {
const config = await cmd.getNuxtConfig({ dev: false, server: false, _build: true });
config.server = (config.mode === utils.MODES.spa || config.ssr === false) && cmd.argv.generate !== false;
const nuxt = await cmd.getNuxt(config);
if (cmd.argv.lock) {
await cmd.setLock(await index.createLock({
id: 'build',
dir: nuxt.options.buildDir,
root: config.rootDir
}));
}
// TODO: remove if in Nuxt 3
if (nuxt.options.mode === utils.MODES.spa && nuxt.options.target === utils.TARGETS.server && cmd.argv.generate !== false) {
// Build + Generate for static deployment
const generator = await cmd.getGenerator(nuxt);
await generator.generate({ build: true });
} else {
// Build only
const builder = await cmd.getBuilder(nuxt);
await builder.build();
const nextCommand = nuxt.options.target === utils.TARGETS.static ? 'nuxt export' : 'nuxt start';
consola.info('Ready to run `' + (nextCommand) + '`');
}
}
};
exports.default = build;
+139
View File
@@ -0,0 +1,139 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
require('@nuxt/utils');
const chalk = _interopDefault(require('chalk'));
require('std-env');
require('wrap-ansi');
require('boxen');
const consola = _interopDefault(require('consola'));
require('minimist');
require('hable');
require('fs');
require('execa');
require('pretty-bytes');
const banner = require('./cli-banner.js');
const opener = _interopDefault(require('opener'));
const dev = {
name: 'dev',
description: 'Start the application in development mode (e.g. hot-code reloading, error reporting)',
usage: 'dev <dir>',
options: {
...index.common,
...index.server,
open: {
alias: 'o',
type: 'boolean',
description: 'Opens the server listeners url in the default browser'
}
},
async run (cmd) {
const { argv } = cmd;
await this.startDev(cmd, argv, argv.open);
},
async startDev (cmd, argv) {
let nuxt;
try {
nuxt = await this._listenDev(cmd, argv);
} catch (error) {
consola.fatal(error);
return
}
try {
await this._buildDev(cmd, argv, nuxt);
} catch (error) {
await nuxt.callHook('cli:buildError', error);
consola.error(error);
}
return nuxt
},
async _listenDev (cmd, argv) {
const config = await cmd.getNuxtConfig({ dev: true, _build: true });
const nuxt = await cmd.getNuxt(config);
// Setup hooks
nuxt.hook('watch:restart', payload => this.onWatchRestart(payload, { nuxt, cmd, argv }));
nuxt.hook('bundler:change', changedFileName => this.onBundlerChange(changedFileName));
// Wait for nuxt to be ready
await nuxt.ready();
// Start listening
await nuxt.server.listen();
// Show banner when listening
banner.showBanner(nuxt, false);
// Opens the server listeners url in the default browser (only once)
if (argv.open) {
argv.open = false;
const openerPromises = nuxt.server.listeners.map(listener => opener(listener.url));
await Promise.all(openerPromises);
}
// Return instance
return nuxt
},
async _buildDev (cmd, argv, nuxt) {
// Create builder instance
const builder = await cmd.getBuilder(nuxt);
// Start Build
await builder.build();
// Print memory usage
banner.showMemoryUsage();
// Display server urls after the build
for (const listener of nuxt.server.listeners) {
consola.info(chalk.bold('Listening on: ') + listener.url);
}
// Return instance
return nuxt
},
logChanged ({ event, path }) {
const { icon, color, action } = index.eventsMapping[event] || index.eventsMapping.change;
consola.log({
type: event,
icon: chalk[color].bold(icon),
message: `${action} ${chalk.cyan(index.formatPath(path))}`
});
},
async onWatchRestart ({ event, path }, { nuxt, cmd, argv }) {
this.logChanged({ event, path });
await nuxt.close();
await this.startDev(cmd, argv);
},
onBundlerChange (path) {
this.logChanged({ event: 'change', path });
}
};
exports.default = dev;
+73
View File
@@ -0,0 +1,73 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
const path = require('path');
const path__default = _interopDefault(path);
require('@nuxt/config');
require('exit');
const utils = require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
const consola = _interopDefault(require('consola'));
require('minimist');
require('hable');
require('fs');
require('execa');
const _export = {
name: 'export',
description: 'Export a static generated web application',
usage: 'export <dir>',
options: {
...index.common,
...index.locking,
'fail-on-error': {
type: 'boolean',
default: false,
description: 'Exit with non-zero status code if there are errors when exporting pages'
}
},
async run (cmd) {
const config = await cmd.getNuxtConfig({
dev: false,
target: utils.TARGETS.static,
_export: true
});
const nuxt = await cmd.getNuxt(config);
if (cmd.argv.lock) {
await cmd.setLock(await index.createLock({
id: 'export',
dir: nuxt.options.generate.dir,
root: config.rootDir
}));
}
const generator = await cmd.getGenerator(nuxt);
await nuxt.server.listen(0);
const { errors } = await generator.generate({
init: true,
build: false
});
await nuxt.close();
if (cmd.argv['fail-on-error'] && errors.length > 0) {
throw new Error('Error exporting pages, exiting with non-zero code')
}
consola.info('Ready to run `nuxt serve` or deploy `' + path__default.basename(nuxt.options.generate.dir) + '/` directory');
}
};
exports.default = _export;
+132
View File
@@ -0,0 +1,132 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
const utils = require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
require('consola');
require('minimist');
require('hable');
require('fs');
require('execa');
const generate = {
name: 'generate',
description: 'Generate a static web application (server-rendered)',
usage: 'generate <dir>',
options: {
...index.common,
...index.locking,
build: {
type: 'boolean',
default: true,
description: 'Only generate pages for dynamic routes, used for incremental builds. Generate has to be run once without this option before using it'
},
devtools: {
type: 'boolean',
default: false,
description: 'Enable Vue devtools',
prepare (cmd, options, argv) {
options.vue = options.vue || {};
options.vue.config = options.vue.config || {};
if (argv.devtools) {
options.vue.config.devtools = true;
}
}
},
quiet: {
alias: 'q',
type: 'boolean',
description: 'Disable output except for errors',
prepare (cmd, options, argv) {
// Silence output when using --quiet
options.build = options.build || {};
if (argv.quiet) {
options.build.quiet = true;
}
}
},
modern: {
...index.common.modern,
description: 'Generate app in modern build (modern mode can be only client)',
prepare (cmd, options, argv) {
if (index.normalizeArg(argv.modern)) {
options.modern = 'client';
}
}
},
'fail-on-error': {
type: 'boolean',
default: false,
description: 'Exit with non-zero status code if there are errors when generating pages'
}
},
async run (cmd) {
const config = await cmd.getNuxtConfig({
dev: false,
_build: cmd.argv.build,
_generate: true
});
if (config.target === utils.TARGETS.static) {
throw new Error("Please use `nuxt export` when using `target: 'static'`")
}
// Forcing static target anyway
config.target = utils.TARGETS.static;
// Disable analyze if set by the nuxt config
config.build = config.build || {};
config.build.analyze = false;
// Set flag to keep the prerendering behaviour
config._legacyGenerate = true;
const nuxt = await cmd.getNuxt(config);
if (cmd.argv.lock) {
await cmd.setLock(await index.createLock({
id: 'build',
dir: nuxt.options.buildDir,
root: config.rootDir
}));
nuxt.hook('build:done', async () => {
await cmd.releaseLock();
await cmd.setLock(await index.createLock({
id: 'generate',
dir: nuxt.options.generate.dir,
root: config.rootDir
}));
});
}
const generator = await cmd.getGenerator(nuxt);
await nuxt.server.listen(0);
const { errors } = await generator.generate({
init: true,
build: cmd.argv.build
});
await nuxt.close();
if (cmd.argv['fail-on-error'] && errors.length > 0) {
throw new Error('Error generating pages, exiting with non-zero code')
}
}
};
exports.default = generate;
+82
View File
@@ -0,0 +1,82 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
require('@nuxt/utils');
const chalk = _interopDefault(require('chalk'));
require('std-env');
require('wrap-ansi');
require('boxen');
const consola = _interopDefault(require('consola'));
require('minimist');
require('hable');
require('fs');
require('execa');
async function listCommands () {
const commandsOrder = ['dev', 'build', 'generate', 'start', 'help'];
// Load all commands
const _commands = await Promise.all(
commandsOrder.map(cmd => index.getCommand(cmd))
);
let maxLength = 0;
const commandsHelp = [];
for (const command of _commands) {
commandsHelp.push([command.usage, command.description]);
maxLength = Math.max(maxLength, command.usage.length);
}
const _cmds = commandsHelp.map(([cmd, description]) => {
const i = index.indent(maxLength + index.optionSpaces - cmd.length);
return index.foldLines(
chalk.green(cmd) + i + description,
index.startSpaces + maxLength + index.optionSpaces * 2,
index.startSpaces + index.optionSpaces
)
}).join('\n');
const usage = index.foldLines('Usage: nuxt <command> [--help|-h]', index.startSpaces);
const cmds = index.foldLines('Commands:', index.startSpaces) + '\n\n' + _cmds;
process.stderr.write(index.colorize(`${usage}\n\n${cmds}\n\n`));
}
const help = {
name: 'help',
description: 'Shows help for <command>',
usage: 'help <command>',
options: {
help: index.common.help,
version: index.common.version
},
async run (cmd) {
const [name] = cmd._argv;
if (!name) {
return listCommands()
}
const command = await index.getCommand(name);
if (!command) {
consola.info(`Unknown command: ${name}`);
return
}
index.NuxtCommand.from(command).showHelp();
}
};
exports.default = help;
+3104
View File
File diff suppressed because it is too large Load Diff
+108
View File
@@ -0,0 +1,108 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
const path = require('path');
const path__default = _interopDefault(path);
const config = require('@nuxt/config');
require('exit');
const utils = require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
require('consola');
require('minimist');
require('hable');
const fs = require('fs');
const fs__default = _interopDefault(fs);
require('execa');
require('pretty-bytes');
const banner = require('./cli-banner.js');
const connect = _interopDefault(require('connect'));
const serveStatic = _interopDefault(require('serve-static'));
const compression = _interopDefault(require('compression'));
const serve = {
name: 'serve',
description: 'Serve the exported static application (should be compiled with `nuxt build` and `nuxt export` first)',
usage: 'serve <dir>',
options: {
'config-file': index.common['config-file'],
version: index.common.version,
help: index.common.help,
...index.server
},
async run (cmd) {
let options = await cmd.getNuxtConfig({ dev: false });
// add default options
options = config.getNuxtConfig(options);
try {
// overwrites with build config
const buildConfig = require(path.join(options.buildDir, 'nuxt/config.json'));
options.target = buildConfig.target;
} catch (err) {}
if (options.target === utils.TARGETS.server) {
throw new Error('You cannot use `nuxt serve` with ' + utils.TARGETS.server + ' target, please use `nuxt start`')
}
const distStat = await fs.promises.stat(options.generate.dir).catch(err => null); // eslint-disable-line handle-callback-err
if (!distStat || !distStat.isDirectory()) {
throw new Error('Output directory `' + path.basename(options.generate.dir) + '/` does not exists, please run `nuxt export` before `nuxt serve`.')
}
const app = connect();
app.use(compression({ threshold: 0 }));
app.use(
options.router.base,
serveStatic(options.generate.dir, {
extensions: ['html']
})
);
if (options.generate.fallback) {
const fallbackFile = await fs.promises.readFile(path.join(options.generate.dir, options.generate.fallback), 'utf-8');
app.use((req, res, next) => {
const ext = path.extname(req.url) || '.html';
if (ext !== '.html') {
return next()
}
res.writeHeader(200, {
'Content-Type': 'text/html'
});
res.write(fallbackFile);
res.end();
});
}
const { port, host, socket, https } = options.server;
const { Listener } = await index.server$1();
const listener = new Listener({
port,
host,
socket,
https,
app,
dev: true, // try another port if taken
baseURL: options.router.base
});
await listener.listen();
const { Nuxt } = await index.core();
banner.showBanner({
constructor: Nuxt,
options,
server: {
listeners: [listener]
}
}, false);
}
};
exports.default = serve;
+48
View File
@@ -0,0 +1,48 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
const utils = require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
require('consola');
require('minimist');
require('hable');
require('fs');
require('execa');
require('pretty-bytes');
const banner = require('./cli-banner.js');
const start = {
name: 'start',
description: 'Start the application in production mode (the application should be compiled with `nuxt build` first)',
usage: 'start <dir>',
options: {
...index.common,
...index.server
},
async run (cmd) {
const config = await cmd.getNuxtConfig({ dev: false, _start: true });
if (config.target === utils.TARGETS.static) {
throw new Error('You cannot use `nuxt start` with ' + utils.TARGETS.static + ' target, please use `nuxt export` and `nuxt serve`')
}
const nuxt = await cmd.getNuxt(config);
// Listen and show ready banner
await nuxt.server.listen();
banner.showBanner(nuxt);
}
};
exports.default = start;
+488
View File
@@ -0,0 +1,488 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
const consola = _interopDefault(require('consola'));
require('minimist');
require('hable');
require('fs');
require('execa');
const util = _interopDefault(require('util'));
/** `Object#toString` result references. */
var symbolTag = '[object Symbol]';
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(index.isObjectLike_1(value) && index._baseGetTag(value) == symbolTag);
}
var isSymbol_1 = isSymbol;
/** Used to match property names within property paths. */
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
reIsPlainProp = /^\w*$/;
/**
* Checks if `value` is a property name and not a property path.
*
* @private
* @param {*} value The value to check.
* @param {Object} [object] The object to query keys on.
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
*/
function isKey(value, object) {
if (index.isArray_1(value)) {
return false;
}
var type = typeof value;
if (type == 'number' || type == 'symbol' || type == 'boolean' ||
value == null || isSymbol_1(value)) {
return true;
}
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
(object != null && value in Object(object));
}
var _isKey = isKey;
/** Error message constants. */
var FUNC_ERROR_TEXT = 'Expected a function';
/**
* Creates a function that memoizes the result of `func`. If `resolver` is
* provided, it determines the cache key for storing the result based on the
* arguments provided to the memoized function. By default, the first argument
* provided to the memoized function is used as the map cache key. The `func`
* is invoked with the `this` binding of the memoized function.
*
* **Note:** The cache is exposed as the `cache` property on the memoized
* function. Its creation may be customized by replacing the `_.memoize.Cache`
* constructor with one whose instances implement the
* [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
* method interface of `clear`, `delete`, `get`, `has`, and `set`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Function
* @param {Function} func The function to have its output memoized.
* @param {Function} [resolver] The function to resolve the cache key.
* @returns {Function} Returns the new memoized function.
* @example
*
* var object = { 'a': 1, 'b': 2 };
* var other = { 'c': 3, 'd': 4 };
*
* var values = _.memoize(_.values);
* values(object);
* // => [1, 2]
*
* values(other);
* // => [3, 4]
*
* object.a = 2;
* values(object);
* // => [1, 2]
*
* // Modify the result cache.
* values.cache.set(object, ['a', 'b']);
* values(object);
* // => ['a', 'b']
*
* // Replace `_.memoize.Cache`.
* _.memoize.Cache = WeakMap;
*/
function memoize(func, resolver) {
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
var args = arguments,
key = resolver ? resolver.apply(this, args) : args[0],
cache = memoized.cache;
if (cache.has(key)) {
return cache.get(key);
}
var result = func.apply(this, args);
memoized.cache = cache.set(key, result) || cache;
return result;
};
memoized.cache = new (memoize.Cache || index._MapCache);
return memoized;
}
// Expose `MapCache`.
memoize.Cache = index._MapCache;
var memoize_1 = memoize;
/** Used as the maximum memoize cache size. */
var MAX_MEMOIZE_SIZE = 500;
/**
* A specialized version of `_.memoize` which clears the memoized function's
* cache when it exceeds `MAX_MEMOIZE_SIZE`.
*
* @private
* @param {Function} func The function to have its output memoized.
* @returns {Function} Returns the new memoized function.
*/
function memoizeCapped(func) {
var result = memoize_1(func, function(key) {
if (cache.size === MAX_MEMOIZE_SIZE) {
cache.clear();
}
return key;
});
var cache = result.cache;
return result;
}
var _memoizeCapped = memoizeCapped;
/** Used to match property names within property paths. */
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
/** Used to match backslashes in property paths. */
var reEscapeChar = /\\(\\)?/g;
/**
* Converts `string` to a property path array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the property path array.
*/
var stringToPath = _memoizeCapped(function(string) {
var result = [];
if (string.charCodeAt(0) === 46 /* . */) {
result.push('');
}
string.replace(rePropName, function(match, number, quote, subString) {
result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
});
return result;
});
var _stringToPath = stringToPath;
/**
* A specialized version of `_.map` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
*/
function arrayMap(array, iteratee) {
var index = -1,
length = array == null ? 0 : array.length,
result = Array(length);
while (++index < length) {
result[index] = iteratee(array[index], index, array);
}
return result;
}
var _arrayMap = arrayMap;
/** Used as references for various `Number` constants. */
var INFINITY = 1 / 0;
/** Used to convert symbols to primitives and strings. */
var symbolProto = index._Symbol ? index._Symbol.prototype : undefined,
symbolToString = symbolProto ? symbolProto.toString : undefined;
/**
* The base implementation of `_.toString` which doesn't convert nullish
* values to empty strings.
*
* @private
* @param {*} value The value to process.
* @returns {string} Returns the string.
*/
function baseToString(value) {
// Exit early for strings to avoid a performance hit in some environments.
if (typeof value == 'string') {
return value;
}
if (index.isArray_1(value)) {
// Recursively convert values (susceptible to call stack limits).
return _arrayMap(value, baseToString) + '';
}
if (isSymbol_1(value)) {
return symbolToString ? symbolToString.call(value) : '';
}
var result = (value + '');
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
}
var _baseToString = baseToString;
/**
* Converts `value` to a string. An empty string is returned for `null`
* and `undefined` values. The sign of `-0` is preserved.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
* @example
*
* _.toString(null);
* // => ''
*
* _.toString(-0);
* // => '-0'
*
* _.toString([1, 2, 3]);
* // => '1,2,3'
*/
function toString(value) {
return value == null ? '' : _baseToString(value);
}
var toString_1 = toString;
/**
* Casts `value` to a path array if it's not one.
*
* @private
* @param {*} value The value to inspect.
* @param {Object} [object] The object to query keys on.
* @returns {Array} Returns the cast property path array.
*/
function castPath(value, object) {
if (index.isArray_1(value)) {
return value;
}
return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
}
var _castPath = castPath;
/** Used as references for various `Number` constants. */
var INFINITY$1 = 1 / 0;
/**
* Converts `value` to a string key if it's not a string or symbol.
*
* @private
* @param {*} value The value to inspect.
* @returns {string|symbol} Returns the key.
*/
function toKey(value) {
if (typeof value == 'string' || isSymbol_1(value)) {
return value;
}
var result = (value + '');
return (result == '0' && (1 / value) == -INFINITY$1) ? '-0' : result;
}
var _toKey = toKey;
/**
* The base implementation of `_.get` without support for default values.
*
* @private
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @returns {*} Returns the resolved value.
*/
function baseGet(object, path) {
path = _castPath(path, object);
var index = 0,
length = path.length;
while (object != null && index < length) {
object = object[_toKey(path[index++])];
}
return (index && index == length) ? object : undefined;
}
var _baseGet = baseGet;
/**
* Gets the value at `path` of `object`. If the resolved value is
* `undefined`, the `defaultValue` is returned in its place.
*
* @static
* @memberOf _
* @since 3.7.0
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
function get(object, path, defaultValue) {
var result = object == null ? undefined : _baseGet(object, path);
return result === undefined ? defaultValue : result;
}
var get_1 = get;
const webpack = {
name: 'webpack',
description: 'Inspect Nuxt webpack config',
usage: 'webpack [query...]',
options: {
...index.common,
name: {
alias: 'n',
type: 'string',
default: 'client',
description: 'Webpack bundle name: server, client, modern'
},
depth: {
alias: 'd',
type: 'string',
default: 2,
description: 'Inspection depth'
},
colors: {
type: 'boolean',
default: process.stdout.isTTY,
description: 'Output with ANSI colors'
},
dev: {
type: 'boolean',
default: false,
description: 'Inspect development mode webpack config'
}
},
async run (cmd) {
const { name } = cmd.argv;
const queries = [...cmd.argv._];
const config = await cmd.getNuxtConfig({ dev: cmd.argv.dev, server: false });
const nuxt = await cmd.getNuxt(config);
const builder = await cmd.getBuilder(nuxt);
const { bundleBuilder } = builder;
const webpackConfig = bundleBuilder.getWebpackConfig(name);
let queryError;
const match = queries.reduce((result, query) => {
const m = advancedGet(result, query);
if (m === undefined) {
queryError = query;
return result
}
return m
}, webpackConfig);
const serialized = formatObj(match, {
depth: parseInt(cmd.argv.depth),
colors: cmd.argv.colors
});
consola.log(serialized + '\n');
if (serialized.includes('[Object]' )) {
consola.info('You can use `--depth` or add more queries to inspect `[Object]` and `[Array]` fields.');
}
if (queryError) {
consola.warn(`No match in webpack config for \`${queryError}\``);
}
}
};
function advancedGet (obj = {}, query = '') {
let result = obj;
if (!query || !result) {
return result
}
const [l, r] = query.split('=');
if (!Array.isArray(result)) {
return typeof result === 'object' ? get_1(result, l) : result
}
result = result.filter((i) => {
const v = get_1(i, l);
if (!v) {
return
}
if (
(v === r) ||
(typeof v.test === 'function' && v.test(r)) ||
(typeof v.match === 'function' && v.match(r)) ||
(r && r.match(v))
) {
return true
}
});
if (result.length === 1) {
return result[0]
}
return result.length ? result : undefined
}
function formatObj (obj, formatOptions) {
if (!util.formatWithOptions) {
return util.format(obj)
}
return util.formatWithOptions(formatOptions, obj)
}
exports.default = webpack;
+36
View File
@@ -0,0 +1,36 @@
/*!
* @nuxt/cli v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* Website: https://nuxtjs.org
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./cli-index.js');
require('path');
require('@nuxt/config');
require('exit');
require('@nuxt/utils');
require('chalk');
require('std-env');
require('wrap-ansi');
require('boxen');
require('consola');
require('minimist');
require('hable');
require('fs');
require('execa');
exports.NuxtCommand = index.NuxtCommand;
exports.commands = index.index;
exports.getWebpackConfig = index.getWebpackConfig;
exports.imports = index.imports;
exports.loadNuxtConfig = index.loadNuxtConfig;
exports.options = index.index$1;
exports.run = index.run;
exports.setup = index.setup;