This commit is contained in:
2022-07-18 02:50:52 +00:00
parent befd344ab0
commit 06181b34d6
8569 changed files with 818704 additions and 352705 deletions
+72 -293
View File
@@ -1,26 +1,32 @@
/*!
* @nuxt/core v2.13.3 (c) 2016-2020
* - All the amazing contributors
* Released under the MIT License.
* @nuxt/core v2.15.8 (c) 2016-2021
* Released under the MIT License
* Repository: https://github.com/nuxt/nuxt.js
* Website: https://nuxtjs.org
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
const path = require('path');
const path__default = _interopDefault(path);
const fs = _interopDefault(require('fs'));
const hash = _interopDefault(require('hash-sum'));
const consola = _interopDefault(require('consola'));
const fs = require('fs');
const hash = require('hash-sum');
const consola = require('consola');
const utils = require('@nuxt/utils');
const Hookable = _interopDefault(require('hable'));
const lodash = require('lodash');
const Hookable = require('hable');
const config = require('@nuxt/config');
const server = require('@nuxt/server');
const fs$1 = _interopDefault(require('fs-extra'));
const fs$1 = require('fs-extra');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
const hash__default = /*#__PURE__*/_interopDefaultLegacy(hash);
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
const Hookable__default = /*#__PURE__*/_interopDefaultLegacy(Hookable);
const fs__default$1 = /*#__PURE__*/_interopDefaultLegacy(fs$1);
class ModuleContainer {
constructor (nuxt) {
@@ -56,7 +62,7 @@ class ModuleContainer {
}
addVendor () {
consola.warn('addVendor has been deprecated due to webpack4 optimization');
consola__default['default'].warn('addVendor has been deprecated due to webpack4 optimization');
}
addTemplate (template) {
@@ -66,16 +72,16 @@ class ModuleContainer {
// Validate & parse source
const src = template.src || template;
const srcPath = path__default.parse(src);
const srcPath = path__default['default'].parse(src);
if (typeof src !== 'string' || !fs.existsSync(src)) {
if (typeof src !== 'string' || !fs__default['default'].existsSync(src)) {
throw new Error('Template src not found: ' + src)
}
// Mostly for DX, some people prefers `filename` vs `fileName`
const fileName = template.fileName || template.filename;
// Generate unique and human readable dst filename if not provided
const dst = fileName || `${path__default.basename(srcPath.dir)}.${srcPath.name}.${hash(src)}${srcPath.ext}`;
const dst = fileName || `${path__default['default'].basename(srcPath.dir)}.${srcPath.name}.${hash__default['default'](src)}${srcPath.ext}`;
// Add to templates list
const templateObj = {
src,
@@ -93,7 +99,7 @@ class ModuleContainer {
// Add to nuxt plugins
this.options.plugins.unshift({
src: path__default.join(this.options.buildDir, dst),
src: path__default['default'].join(this.options.buildDir, dst),
// TODO: remove deprecated option in Nuxt 3
ssr: template.ssr,
mode: template.mode
@@ -102,11 +108,11 @@ class ModuleContainer {
addLayout (template, name) {
const { dst, src } = this.addTemplate(template);
const layoutName = name || path__default.parse(src).name;
const layoutName = name || path__default['default'].parse(src).name;
const layout = this.options.layouts[layoutName];
if (layout) {
consola.warn(`Duplicate layout registration, "${layoutName}" has been registered as "${layout}"`);
consola__default['default'].warn(`Duplicate layout registration, "${layoutName}" has been registered as "${layout}"`);
}
// Add to nuxt layouts
@@ -119,7 +125,7 @@ class ModuleContainer {
}
addErrorLayout (dst) {
const relativeBuildDir = path__default.relative(this.options.rootDir, this.options.buildDir);
const relativeBuildDir = path__default['default'].relative(this.options.rootDir, this.options.buildDir);
this.options.ErrorPage = `~/${relativeBuildDir}/${dst}`;
}
@@ -138,11 +144,13 @@ class ModuleContainer {
);
}
requireModule (moduleOpts) {
return this.addModule(moduleOpts)
requireModule (moduleOpts, { paths } = {}) {
return this.addModule(moduleOpts, undefined, { paths })
}
async addModule (moduleOpts) {
async addModule (moduleOpts, arg2, arg3) {
// Arg2 was previously used for requireOnce which is ignored now
const { paths } = { ...arg2, ...arg3 };
let src;
let options;
let handler;
@@ -171,7 +179,9 @@ class ModuleContainer {
// Resolve handler
if (!handler) {
try {
handler = this.nuxt.resolver.requireModule(src, { useESM: true });
handler = this.nuxt.resolver.requireModule(src, { paths });
// pnp support
try { (global.__NUXT_PATHS__ || []).push(this.nuxt.resolver.resolvePath(src, { paths })); } catch (_err) {}
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
throw error
@@ -189,14 +199,14 @@ class ModuleContainer {
message = message.replace(/{name}/g, src);
consola.warn(message);
consola__default['default'].warn(message);
}
if (this.options._cli) {
throw error
} else {
// TODO: Remove in next major version
consola.warn('Silently ignoring module as programatic usage detected.');
consola__default['default'].warn('Silently ignoring module as programatic usage detected.');
return
}
}
@@ -214,7 +224,7 @@ class ModuleContainer {
if (this.requiredModules[key]) {
if (!metaKey) {
// TODO: Skip with nuxt3
consola.warn('Modules should be only specified once:', key);
consola__default['default'].warn('Modules should be only specified once:', key);
} else {
return
}
@@ -231,230 +241,7 @@ class ModuleContainer {
}
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
var _freeGlobal = freeGlobal;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = _freeGlobal || freeSelf || Function('return this')();
var _root = root;
/** Built-in value references. */
var Symbol = _root.Symbol;
var _Symbol = Symbol;
/** Used for built-in method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/** Built-in value references. */
var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag),
tag = value[symToStringTag];
try {
value[symToStringTag] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}
var _getRawTag = getRawTag;
/** Used for built-in method references. */
var objectProto$1 = Object.prototype;
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString$1 = objectProto$1.toString;
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString$1.call(value);
}
var _objectToString = objectToString;
/** `Object#toString` result references. */
var nullTag = '[object Null]',
undefinedTag = '[object Undefined]';
/** Built-in value references. */
var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag$1 && symToStringTag$1 in Object(value))
? _getRawTag(value)
: _objectToString(value);
}
var _baseGetTag = baseGetTag;
/**
* Creates a unary function that invokes `func` with its argument transformed.
*
* @private
* @param {Function} func The function to wrap.
* @param {Function} transform The argument transform.
* @returns {Function} Returns the new function.
*/
function overArg(func, transform) {
return function(arg) {
return func(transform(arg));
};
}
var _overArg = overArg;
/** Built-in value references. */
var getPrototype = _overArg(Object.getPrototypeOf, Object);
var _getPrototype = getPrototype;
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
var isObjectLike_1 = isObjectLike;
/** `Object#toString` result references. */
var objectTag = '[object Object]';
/** Used for built-in method references. */
var funcProto = Function.prototype,
objectProto$2 = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
/** Used to infer the `Object` constructor. */
var objectCtorString = funcToString.call(Object);
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @static
* @memberOf _
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
function isPlainObject(value) {
if (!isObjectLike_1(value) || _baseGetTag(value) != objectTag) {
return false;
}
var proto = _getPrototype(value);
if (proto === null) {
return true;
}
var Ctor = hasOwnProperty$1.call(proto, 'constructor') && proto.constructor;
return typeof Ctor == 'function' && Ctor instanceof Ctor &&
funcToString.call(Ctor) == objectCtorString;
}
var isPlainObject_1 = isPlainObject;
var version = "2.13.3";
var version = "2.15.8";
class Resolver {
constructor (nuxt) {
@@ -467,23 +254,17 @@ class Resolver {
this.resolveModule = this.resolveModule.bind(this);
this.requireModule = this.requireModule.bind(this);
const { createRequire } = this.options;
this._require = createRequire ? createRequire(module) : module.require;
this._resolve = require.resolve;
this._createRequire = this.options.createRequire || utils.createRequire;
this._require = this._createRequire(__filename);
}
resolveModule (path) {
resolveModule (path, { paths } = {}) {
try {
return this._resolve(path, {
paths: this.options.modulesDir
return this._require.resolve(path, {
paths: [].concat(global.__NUXT_PREPATHS__ || [], paths || [], this.options.modulesDir, global.__NUXT_PATHS__ || [], process.cwd())
})
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
// TODO: remove after https://github.com/facebook/jest/pull/8487 released
if (process.env.NODE_ENV === 'test' && error.message.startsWith('Cannot resolve module')) {
return
}
throw error
}
}
@@ -501,17 +282,17 @@ class Resolver {
return path.resolve(this.options.srcDir, path$1)
}
resolvePath (path$1, { alias, isAlias = alias, module, isModule = module, isStyle } = {}) {
resolvePath (path$1, { alias, isAlias = alias, module, isModule = module, isStyle, paths } = {}) {
// TODO: Remove in Nuxt 3
if (alias) {
consola.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.');
consola__default['default'].warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.');
}
if (module) {
consola.warn('Using module is deprecated and will be removed in Nuxt 3. Use `isModule` instead.');
consola__default['default'].warn('Using module is deprecated and will be removed in Nuxt 3. Use `isModule` instead.');
}
// Fast return in case of path exists
if (fs$1.existsSync(path$1)) {
if (fs__default$1['default'].existsSync(path$1)) {
return path$1
}
@@ -519,7 +300,7 @@ class Resolver {
// Try to resolve it as a regular module
if (isModule !== false) {
resolvedPath = this.resolveModule(path$1);
resolvedPath = this.resolveModule(path$1, { paths });
}
// Try to resolve alias
@@ -535,8 +316,8 @@ class Resolver {
let isDirectory;
// Check if resolvedPath exits and is not a directory
if (fs$1.existsSync(resolvedPath)) {
isDirectory = fs$1.lstatSync(resolvedPath).isDirectory();
if (fs__default$1['default'].existsSync(resolvedPath)) {
isDirectory = fs__default$1['default'].lstatSync(resolvedPath).isDirectory();
if (!isDirectory) {
return resolvedPath
@@ -547,12 +328,12 @@ class Resolver {
// Check if any resolvedPath.[ext] or resolvedPath/index.[ext] exists
for (const ext of extensions) {
if (!isDirectory && fs$1.existsSync(resolvedPath + '.' + ext)) {
if (!isDirectory && fs__default$1['default'].existsSync(resolvedPath + '.' + ext)) {
return resolvedPath + '.' + ext
}
const resolvedPathwithIndex = path.join(resolvedPath, 'index.' + ext);
if (isDirectory && fs$1.existsSync(resolvedPathwithIndex)) {
if (isDirectory && fs__default$1['default'].existsSync(resolvedPathwithIndex)) {
return resolvedPathwithIndex
}
}
@@ -566,26 +347,23 @@ class Resolver {
throw new Error(`Cannot resolve "${path$1}" from "${resolvedPath}"`)
}
requireModule (path, { esm, useESM = esm, alias, isAlias = alias, intropDefault, interopDefault = intropDefault } = {}) {
requireModule (path, { alias, isAlias = alias, intropDefault, interopDefault = intropDefault, paths } = {}) {
let resolvedPath = path;
let requiredModule;
// TODO: Remove in Nuxt 3
if (intropDefault) {
consola.warn('Using intropDefault is deprecated and will be removed in Nuxt 3. Use `interopDefault` instead.');
consola__default['default'].warn('Using intropDefault is deprecated and will be removed in Nuxt 3. Use `interopDefault` instead.');
}
if (alias) {
consola.warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.');
}
if (esm) {
consola.warn('Using esm is deprecated and will be removed in Nuxt 3. Use `useESM` instead.');
consola__default['default'].warn('Using alias is deprecated and will be removed in Nuxt 3. Use `isAlias` instead.');
}
let lastError;
// Try to resolve path
try {
resolvedPath = this.resolvePath(path, { isAlias });
resolvedPath = this.resolvePath(path, { isAlias, paths });
} catch (e) {
lastError = e;
}
@@ -598,18 +376,9 @@ class Resolver {
utils.clearRequireCache(resolvedPath);
}
// By default use esm only for js,mjs files outside of node_modules
if (useESM === undefined) {
useESM = !isExternal && /.(js|mjs)$/.test(resolvedPath);
}
// Try to require
try {
if (useESM) {
requiredModule = this._require(resolvedPath);
} else {
requiredModule = require(resolvedPath);
}
requiredModule = this._require(resolvedPath);
} catch (e) {
lastError = e;
}
@@ -628,9 +397,9 @@ class Resolver {
}
}
class Nuxt extends Hookable {
class Nuxt extends Hookable__default['default'] {
constructor (options = {}) {
super(consola);
super(consola__default['default']);
// Assign options and apply defaults
this.options = config.getNuxtConfig(options);
@@ -651,7 +420,17 @@ class Nuxt extends Hookable {
to: '_render:context',
message: '`render:routeContext(nuxt)` is deprecated, Please use `vue-renderer:ssr:context(context)`'
},
showReady: 'webpack:done'
showReady: 'webpack:done',
// Introduced in 2.13
'export:done': 'generate:done',
'export:before': 'generate:before',
'export:extendRoutes': 'generate:extendRoutes',
'export:distRemoved': 'generate:distRemoved',
'export:distCopied': 'generate:distCopied',
'export:route': 'generate:route',
'export:routeFailed': 'generate:routeFailed',
'export:page': 'generate:page',
'export:routeCreated': 'generate:routeCreated'
});
// Add Legacy aliases
@@ -666,7 +445,7 @@ class Nuxt extends Hookable {
// Call ready
if (this.options._ready !== false) {
this.ready().catch((err) => {
consola.fatal(err);
consola__default['default'].fatal(err);
});
}
}
@@ -689,7 +468,7 @@ class Nuxt extends Hookable {
this._initCalled = true;
// Add hooks
if (isPlainObject_1(this.options.hooks)) {
if (lodash.isPlainObject(this.options.hooks)) {
this.addHooks(this.options.hooks);
} else if (typeof this.options.hooks === 'function') {
this.options.hooks(this.hook);