Skip to content

Commit

Permalink
Fix 2023 01 (#807)
Browse files Browse the repository at this point in the history
* Revert "Support optional segments in `check routes` CLI command (#774)"

This reverts commit 2039a4a.

* update package.lock
  • Loading branch information
lordofthecactus authored Apr 20, 2023
1 parent 1443b67 commit 53e6dbf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 102 deletions.
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

0 comments on commit 53e6dbf

Please sign in to comment.