Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: tidy up #708

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 6 additions & 8 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -137,12 +136,11 @@ export function resolveAliases (_aliases: Record<string, string>) {
// 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
Expand Down