import { paginatedArchivePaths } from './page-pagination.js'; import { standaloneDemoPaths } from './standalone-demo-url.js'; /** * @param {{ * redirects?: import('@rocket/js/types.js').RedirectConfig[]; * pages: import('@rocket/js/types.js').PageRegistry; * }} options */ export function validateUrlLifecyclePageCollisions({ redirects = [], pages }) { for (const redirect of redirects) { const page = pages.get(redirect.source); if (!page) { continue; } throw new Error( `Redirect source ${redirect.source} collides with configured Page ${page.file}. ` + `Choose a Redirect source that is not already configured as a Page path.`, ); } } /** * @param {{ * redirects?: import('@rocket/js/types.js').RedirectConfig[]; * pages: import('@rocket/js/types.js').PageRegistry; * staticPages: import('@rocket/js/types.js').PageRegistry; * }} options */ export function validateUrlLifecycleGeneratedOutputCollisions({ redirects = [], pages, staticPages, }) { if (!redirects.length) { return; } const redirectSources = new Set(redirects.map(redirect => redirect.source)); for (const [pagePath, page] of staticPages) { for (const demoPath of standaloneDemoPaths(pagePath, page)) { if (redirectSources.has(demoPath)) { throw new Error( `Redirect source ${demoPath} collides with Standalone Demo URL ${demoPath} ` + `for page ${page.file}. Choose a Redirect source that is not generated by Rocket.`, ); } } for (const archivePath of paginatedArchivePaths({ pages, page, pagePath })) { if (redirectSources.has(archivePath)) { throw new Error( `Redirect source ${archivePath} collides with generated archive Page ${archivePath} ` + `for page ${page.file}. Choose a Redirect source that is not generated by Rocket.`, ); } } } }