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

Fix 2023 01 #807

Merged
merged 2 commits into from
Apr 20, 2023
Merged
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
5 changes: 0 additions & 5 deletions .changeset/bright-impalas-swim.md

This file was deleted.

60 changes: 30 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 0 additions & 52 deletions packages/cli/src/lib/missing-routes.test.ts

This file was deleted.

25 changes: 10 additions & 15 deletions packages/cli/src/lib/missing-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ const REQUIRED_ROUTES = [
// 'opening_soon',
];

export function findMissingRoutes(
config: {routes: RemixConfig['routes']},
requiredRoutes = REQUIRED_ROUTES,
) {
export function findMissingRoutes(config: RemixConfig) {
const userRoutes = Object.values(config.routes);
const missingRoutes = new Set(requiredRoutes);
const requiredRoutes = new Set(REQUIRED_ROUTES);

for (const requiredRoute of requiredRoutes) {
for (const userRoute of userRoutes) {
if (!requiredRoute && !userRoute.path) {
missingRoutes.delete(requiredRoute);
requiredRoutes.delete(requiredRoute);
} else if (requiredRoute && userRoute.path) {
const currentRoute = {
path: userRoute.path,
Expand All @@ -70,23 +67,21 @@ export function findMissingRoutes(
currentRoute.parentId = parentRoute.parentId;
}

const optionalSegment = ':?[^\\/\\?]+\\?';
const reString =
`^(${optionalSegment}\\/)?` + // Starts with an optional segment
requiredRoute
.replaceAll('.', '\\.') // Escape dots
.replace(/\//g, `\\/(${optionalSegment}\\/)?`) // Has optional segments in the middle
.replace(/:[^/)?]+/g, ':[^\\/]+') + // Replace params with regex
`(\\/${optionalSegment})?$`; // Ends with an optional segment
// Starts with optional params
'^(:[^\\/\\?]+\\?\\/)?' +
// Escape dots and replace params with regex
requiredRoute.replaceAll('.', '\\.').replace(/:[^/]+/g, ':[^\\/]+') +
'$';

if (new RegExp(reString).test(currentRoute.path)) {
missingRoutes.delete(requiredRoute);
requiredRoutes.delete(requiredRoute);
}
}
}
}

return [...missingRoutes];
return [...requiredRoutes];
}

const LINE_LIMIT = 100;
Expand Down