diff --git a/src/prerender.ts b/src/prerender.ts index 1d70d958a4..159cc3f0f6 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -64,12 +64,10 @@ export async function prerender (nitro: Nitro) { // Start prerendering const generatedRoutes = new Set() const canPrerender = (route: string = '/') => { - if (generatedRoutes.has(route)) { return false } - if (route.length > 250) { return false } - for (const ignore of nitro.options.prerender.ignore) { - if (route.startsWith(ignore)) { return false } - } - if (_getRouteRules(route).prerender === false) { return false } + if (generatedRoutes.has(route) || + route.length > 250 || + nitro.options.prerender.ignore.some(ignore => route.startsWith(ignore)) || + _getRouteRules(route).prerender === false) { return false } return true } diff --git a/src/utils/index.ts b/src/utils/index.ts index f243fd82b7..2c60150939 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -114,13 +114,12 @@ export function readPackageJson ( return _require(`${packageName}/package.json`) } catch (error) { if (error.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') { - const pkgModulePaths = /^(.*\/node_modules\/).*$/.exec(_require.resolve(packageName)) - for (const pkgModulePath of pkgModulePaths || []) { + const pkgModulePaths = /^(.*\/node_modules\/).*$/.exec(_require.resolve(packageName)) || [] + for (const pkgModulePath of pkgModulePaths) { const path = resolve(pkgModulePath, packageName, 'package.json') if (fse.existsSync(path)) { return fse.readJSONSync(path) } - continue } throw error @@ -137,12 +136,11 @@ export function resolveAliases (_aliases: Record) { // Resolve alias values in relation to each other for (const key in aliases) { for (const alias in aliases) { - if (!['~', '@', '#'].includes(alias[0])) { continue } - if (alias === '@' && !aliases[key].startsWith('@/')) { continue } // Don't resolve @foo/bar + if (!['~', '@', '#'].includes(alias[0]) || + (alias === '@' && !aliases[key].startsWith('@/')) || // Don't resolve @foo/bar + !aliases[key].startsWith(alias)) { continue } - if (aliases[key].startsWith(alias)) { - aliases[key] = aliases[alias] + aliases[key].slice(alias.length) - } + aliases[key] = aliases[alias] + aliases[key].slice(alias.length) } } return aliases