Last active
April 27, 2023 21:30
-
-
Save jacobparis/74924ecc70831999f8161f246dc75198 to your computer and use it in GitHub Desktop.
Remix feature folders patch-package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/@remix-run/dev/dist/compiler/assets.js b/node_modules/@remix-run/dev/dist/compiler/assets.js | |
index b01942f..8f90ae1 100644 | |
--- a/node_modules/@remix-run/dev/dist/compiler/assets.js | |
+++ b/node_modules/@remix-run/dev/dist/compiler/assets.js | |
@@ -95,6 +95,7 @@ async function createAssetsManifest({ | |
routes, | |
hmrRoutes: hmr === null || hmr === void 0 ? void 0 : hmr.routes | |
})).slice(0, 8); | |
+ | |
return { | |
version, | |
entry, | |
diff --git a/node_modules/@remix-run/dev/dist/config/flat-routes.js b/node_modules/@remix-run/dev/dist/config/flat-routes.js | |
index ccb836d..9d04746 100644 | |
--- a/node_modules/@remix-run/dev/dist/config/flat-routes.js | |
+++ b/node_modules/@remix-run/dev/dist/config/flat-routes.js | |
@@ -67,40 +67,36 @@ function _findAndRemoveRecursive2(values, node, prefix, filter) { | |
} | |
return values; | |
} | |
-function flatRoutes(appDirectory, ignoredFilePatterns = [], prefix = "routes") { | |
+function flatRoutes(appDirectory, ignoredFilePatterns = []) { | |
let ignoredFileRegex = ignoredFilePatterns.map(pattern => { | |
return globToRegex__default["default"](pattern); | |
}); | |
- let routesDir = path__default["default"].join(appDirectory, prefix); | |
let rootRoute = config.findConfig(appDirectory, "root", routesConvention.routeModuleExts); | |
if (!rootRoute) { | |
throw new Error(`Could not find a root route module in the app directory: ${appDirectory}`); | |
} | |
- if (!fs__default["default"].existsSync(rootRoute)) { | |
- throw new Error(`Could not find the routes directory: ${routesDir}. Did you forget to create it?`); | |
- } | |
// Only read the routes directory | |
- let entries = fs__default["default"].readdirSync(routesDir, { | |
+ let entries = fs__default["default"].readdirSync(appDirectory, { | |
withFileTypes: true, | |
encoding: "utf-8" | |
}); | |
let routes = []; | |
for (let entry of entries) { | |
- let filepath = path__default["default"].join(routesDir, entry.name); | |
let route = null; | |
// If it's a directory, don't recurse into it, instead just look for a route module | |
if (entry.isDirectory()) { | |
- route = findRouteModuleForFolder(appDirectory, filepath, ignoredFileRegex); | |
+ route = findRouteModulesForFolder(appDirectory, entry.name, ignoredFileRegex); | |
+ if (route) routes.push(...route) | |
} else if (entry.isFile()) { | |
- route = findRouteModuleForFile(appDirectory, filepath, ignoredFileRegex); | |
+ route = findRouteModuleForFile(appDirectory, entry.name, ignoredFileRegex); | |
+ if (route) routes.push(route); | |
} | |
- if (route) routes.push(route); | |
} | |
- let routeManifest = flatRoutesUniversal(appDirectory, routes, prefix); | |
+ let routeManifest = flatRoutesUniversal(appDirectory, routes); | |
return routeManifest; | |
} | |
-function flatRoutesUniversal(appDirectory, routes$1, prefix = "routes") { | |
+function flatRoutesUniversal(appDirectory, routes$1) { | |
let urlConflicts = new Map(); | |
let routeManifest = {}; | |
let prefixLookup = new PrefixLookupTrie(); | |
@@ -112,9 +108,10 @@ function flatRoutesUniversal(appDirectory, routes$1, prefix = "routes") { | |
for (let file of routes$1) { | |
let normalizedFile = routes.normalizeSlashes(file); | |
let routeExt = path__default["default"].extname(normalizedFile); | |
- let routeDir = path__default["default"].dirname(normalizedFile); | |
let normalizedApp = routes.normalizeSlashes(appDirectory); | |
- let routeId = routeDir === path__default["default"].posix.join(normalizedApp, prefix) ? path__default["default"].posix.relative(normalizedApp, normalizedFile).slice(0, -routeExt.length) : path__default["default"].posix.relative(normalizedApp, routeDir); | |
+ let basename = path__default["default"].basename(file); | |
+ let routeId = basename.slice(0, -routeExt.length - ".route".length); | |
+ | |
let conflict = routeIds.get(routeId); | |
if (conflict) { | |
let currentConflicts = routeIdConflicts.get(routeId); | |
@@ -129,15 +126,17 @@ function flatRoutesUniversal(appDirectory, routes$1, prefix = "routes") { | |
} | |
let sortedRouteIds = Array.from(routeIds).sort(([a], [b]) => b.length - a.length); | |
for (let [routeId, file] of sortedRouteIds) { | |
- let index = routeId.endsWith("_index"); | |
- let [segments, raw] = getRouteSegments(routeId.slice(prefix.length + 1)); | |
- let pathname = createRoutePath(segments, raw, index); | |
+ let routeIdNoFeature = routeId.slice(0); | |
+ let noRouteEnding = routeIdNoFeature.replace(".route", ""); | |
+ let isIndex = noRouteEnding.endsWith("_index"); | |
+ let [segments, raw] = getRouteSegments(noRouteEnding); | |
+ let pathname = createRoutePath(segments, raw, isIndex); | |
routeManifest[routeId] = { | |
- file: file.slice(appDirectory.length + 1), | |
+ file, | |
id: routeId, | |
path: pathname | |
}; | |
- if (index) routeManifest[routeId].index = true; | |
+ if (isIndex) routeManifest[routeId].index = true; | |
let childRouteIds = prefixLookup.findAndRemove(routeId, value => { | |
return [".", "/"].includes(value.slice(routeId.length).charAt(0)); | |
}); | |
@@ -199,27 +198,46 @@ function flatRoutesUniversal(appDirectory, routes$1, prefix = "routes") { | |
return routeManifest; | |
} | |
function findRouteModuleForFile(appDirectory, filepath, ignoredFileRegex) { | |
- let relativePath = path__default["default"].relative(appDirectory, filepath); | |
- let isIgnored = ignoredFileRegex.some(regex => regex.test(relativePath)); | |
+ let ext = path.extname(filepath); | |
+ let basename = path.basename(filepath, ext); | |
+ if (!basename.endsWith(".route")) return null; | |
+ let isIgnored = ignoredFileRegex.some((regex) => regex.test(filepath)); | |
if (isIgnored) return null; | |
- return filepath; | |
+ | |
+ return filepath | |
} | |
-function findRouteModuleForFolder(appDirectory, filepath, ignoredFileRegex) { | |
- let relativePath = path__default["default"].relative(appDirectory, filepath); | |
- let isIgnored = ignoredFileRegex.some(regex => regex.test(relativePath)); | |
- if (isIgnored) return null; | |
- let routeRouteModule = config.findConfig(filepath, "route", routesConvention.routeModuleExts); | |
- let routeIndexModule = config.findConfig(filepath, "index", routesConvention.routeModuleExts); | |
+function findRouteModulesForFolder(appDirectory, filepath, ignoredFileRegex) { | |
+ let dirEntries = fs.readdirSync(path.join(appDirectory, filepath), { | |
+ withFileTypes: true, | |
+ encoding: "utf-8", | |
+ }); | |
+ | |
+ let filesOrDirs = dirEntries.filter((e) => { | |
+ if (e.isDirectory()) return true; | |
+ | |
+ let ext = path.extname(e.name); | |
+ let base = path.basename(e.name, ext); | |
+ return base.endsWith(".route"); | |
+ }); | |
+ | |
+ let routes = []; | |
+ | |
+ for (let fileOrDir of filesOrDirs) { | |
+ if (!fileOrDir) continue; | |
- // if both a route and index module exist, throw a conflict error | |
- // preferring the route module over the index module | |
- if (routeRouteModule && routeIndexModule) { | |
- let [segments, raw] = getRouteSegments(path__default["default"].relative(appDirectory, filepath)); | |
- let routePath = createRoutePath(segments, raw, false); | |
- console.error(getRoutePathConflictErrorMessage(routePath || "/", [routeRouteModule, routeIndexModule])); | |
+ let isIgnored = ignoredFileRegex.some((regex) => regex.test(fileOrDir.name)); | |
+ if (isIgnored) continue; | |
+ | |
+ if (fileOrDir.isDirectory()) { | |
+ routes.push(...findRouteModulesForFolder(appDirectory, path.join(filepath, fileOrDir.name), ignoredFileRegex)); | |
+ } else { | |
+ routes.push(path.join(filepath, fileOrDir.name)); | |
+ } | |
} | |
- return routeRouteModule || routeIndexModule || null; | |
+ | |
+ return routes; | |
} | |
+ | |
function getRouteSegments(routeId) { | |
let routeSegments = []; | |
let rawRouteSegments = []; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment