/opt/canhelp/node_modules/next/dist/shared/lib/router/utils
NameSizeModeActions
add-locale.d.ts3650644editdlrm
add-locale.js10490644editdlrm
add-locale.js.map17150644editdlrm
add-path-prefix.d.ts2000644editdlrm
add-path-prefix.js5360644editdlrm
add-path-prefix.js.map8850644editdlrm
add-path-suffix.d.ts2580644editdlrm
add-path-suffix.js5360644editdlrm
add-path-suffix.js.map9440644editdlrm
app-paths.d.ts9000644editdlrm
app-paths.js15040644editdlrm
app-paths.js.map27120644editdlrm
as-path-to-search-params.d.ts790644editdlrm
as-path-to-search-params.js4840644editdlrm
as-path-to-search-params.js.map5650644editdlrm
cache-busting-search-param.d.ts2570644editdlrm
cache-busting-search-param.js8320644editdlrm
cache-busting-search-param.js.map13150644editdlrm
compare-states.d.ts1460644editdlrm
compare-states.js10700644editdlrm
compare-states.js.map19310644editdlrm
disable-smooth-scroll.d.ts3040644editdlrm
disable-smooth-scroll.js25150644editdlrm
disable-smooth-scroll.js.map36210644editdlrm
escape-path-delimiters.d.ts960644editdlrm
escape-path-delimiters.js5080644editdlrm
escape-path-delimiters.js.map7530644editdlrm
format-next-pathname-info.d.ts2610644editdlrm
format-next-pathname-info.js12900644editdlrm
format-next-pathname-info.js.map20900644editdlrm
format-url.d.ts2160644editdlrm
format-url.js39550644editdlrm
format-url.js.map57390644editdlrm
get-asset-path-from-route.d.ts840644editdlrm
get-asset-path-from-route.js6390644editdlrm
get-asset-path-from-route.js.map8460644editdlrm
get-dynamic-param.d.ts27750644editdlrm
get-dynamic-param.js39760644editdlrm
get-dynamic-param.js.map74420644editdlrm
get-next-pathname-info.d.ts14500644editdlrm
get-next-pathname-info.js24790644editdlrm
get-next-pathname-info.js.map51780644editdlrm
get-route-from-asset-path.d.ts880644editdlrm
get-route-from-asset-path.js9310644editdlrm
get-route-from-asset-path.js.map13240644editdlrm
html-bots.d.ts530644editdlrm
html-bots.js11350644editdlrm
html-bots.js.map11450644editdlrm
index.d.ts1210644editdlrm
index.js7660644editdlrm
index.js.map4300644editdlrm
interception-routes.d.ts3120644editdlrm
interception-routes.js43540644editdlrm
interception-routes.js.map50540644editdlrm
interpolate-as.d.ts1950644editdlrm
interpolate-as.js22420644editdlrm
interpolate-as.js.map38010644editdlrm
is-bot.d.ts2910644editdlrm
is-bot.js17640644editdlrm
is-bot.js.map19980644editdlrm
is-dynamic.d.ts3160644editdlrm
is-dynamic.js8670644editdlrm
is-dynamic.js.map14890644editdlrm
is-local-url.d.ts1470644editdlrm
is-local-url.js8540644editdlrm
is-local-url.js.map12710644editdlrm
middleware-route-matcher.d.ts4630644editdlrm
middleware-route-matcher.js9470644editdlrm
middleware-route-matcher.js.map17620644editdlrm
omit.d.ts1260644editdlrm
omit.js4400644editdlrm
omit.js.map7780644editdlrm
parse-path.d.ts3200644editdlrm
parse-path.js10410644editdlrm
parse-path.js.map15100644editdlrm
parse-relative-url.d.ts7450644editdlrm
parse-relative-url.js14760644editdlrm
parse-relative-url.js.map30150644editdlrm
parse-url.d.ts3650644editdlrm
parse-url.js9540644editdlrm
parse-url.js.map18430644editdlrm
path-has-prefix.d.ts3640644editdlrm
path-has-prefix.js5350644editdlrm
path-has-prefix.js.map9960644editdlrm
path-match.d.ts9890644editdlrm
path-match.js19610644editdlrm
path-match.js.map37730644editdlrm
prepare-destination.d.ts15270644editdlrm
prepare-destination.js106370644editdlrm
prepare-destination.js.map171870644editdlrm
querystring.d.ts3480644editdlrm
querystring.js22810644editdlrm
querystring.js.map32870644editdlrm
relativize-url.d.ts6790644editdlrm
relativize-url.js11210644editdlrm
relativize-url.js.map18720644editdlrm
remove-path-prefix.d.ts3890644editdlrm
remove-path-prefix.js12610644editdlrm
remove-path-prefix.js.map20000644editdlrm
remove-trailing-slash.d.ts2590644editdlrm
remove-trailing-slash.js5520644editdlrm
remove-trailing-slash.js.map5980644editdlrm
resolve-rewrites.d.ts6820644editdlrm
resolve-rewrites.js46700644editdlrm
resolve-rewrites.js.map77810644editdlrm
route-match-utils.d.ts15130644editdlrm
route-match-utils.js36750644editdlrm
route-match-utils.js.map57540644editdlrm
route-matcher.d.ts3840644editdlrm
route-matcher.js15090644editdlrm
route-matcher.js.map25580644editdlrm
route-regex.d.ts34920644editdlrm
route-regex.js94980644editdlrm
route-regex.js.map175770644editdlrm
sortable-routes.d.ts42490644editdlrm
sortable-routes.js63210644editdlrm
sortable-routes.js.map125300644editdlrm
sorted-routes.d.ts3440644editdlrm
sorted-routes.js116640644editdlrm
sorted-routes.js.map147880644editdlrm
Edit: /opt/canhelp/node_modules/next/dist/shared/lib/router/utils/sorted-routes.js (11664B)
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 0 && (module.exports = { getSortedRouteObjects: null, getSortedRoutes: null }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { getSortedRouteObjects: function() { return getSortedRouteObjects; }, getSortedRoutes: function() { return getSortedRoutes; } }); class UrlNode { insert(urlPath) { this._insert(urlPath.split('/').filter(Boolean), [], false); } smoosh() { return this._smoosh(); } _smoosh(prefix) { if (prefix === void 0) prefix = '/'; const childrenPaths = [ ...this.children.keys() ].sort(); if (this.slugName !== null) { childrenPaths.splice(childrenPaths.indexOf('[]'), 1); } if (this.restSlugName !== null) { childrenPaths.splice(childrenPaths.indexOf('[...]'), 1); } if (this.optionalRestSlugName !== null) { childrenPaths.splice(childrenPaths.indexOf('[[...]]'), 1); } const routes = childrenPaths.map((c)=>this.children.get(c)._smoosh("" + prefix + c + "/")).reduce((prev, curr)=>[ ...prev, ...curr ], []); if (this.slugName !== null) { routes.push(...this.children.get('[]')._smoosh(prefix + "[" + this.slugName + "]/")); } if (!this.placeholder) { const r = prefix === '/' ? '/' : prefix.slice(0, -1); if (this.optionalRestSlugName != null) { throw Object.defineProperty(new Error('You cannot define a route with the same specificity as a optional catch-all route ("' + r + '" and "' + r + "[[..." + this.optionalRestSlugName + ']]").'), "__NEXT_ERROR_CODE", { value: "E458", enumerable: false, configurable: true }); } routes.unshift(r); } if (this.restSlugName !== null) { routes.push(...this.children.get('[...]')._smoosh(prefix + "[..." + this.restSlugName + "]/")); } if (this.optionalRestSlugName !== null) { routes.push(...this.children.get('[[...]]')._smoosh(prefix + "[[..." + this.optionalRestSlugName + "]]/")); } return routes; } _insert(urlPaths, slugNames, isCatchAll) { if (urlPaths.length === 0) { this.placeholder = false; return; } if (isCatchAll) { throw Object.defineProperty(new Error("Catch-all must be the last part of the URL."), "__NEXT_ERROR_CODE", { value: "E392", enumerable: false, configurable: true }); } // The next segment in the urlPaths list let nextSegment = urlPaths[0]; // Check if the segment matches `[something]` if (nextSegment.startsWith('[') && nextSegment.endsWith(']')) { // Strip `[` and `]`, leaving only `something` let segmentName = nextSegment.slice(1, -1); let isOptional = false; if (segmentName.startsWith('[') && segmentName.endsWith(']')) { // Strip optional `[` and `]`, leaving only `something` segmentName = segmentName.slice(1, -1); isOptional = true; } if (segmentName.startsWith('…')) { throw Object.defineProperty(new Error("Detected a three-dot character ('…') at ('" + segmentName + "'). Did you mean ('...')?"), "__NEXT_ERROR_CODE", { value: "E147", enumerable: false, configurable: true }); } if (segmentName.startsWith('...')) { // Strip `...`, leaving only `something` segmentName = segmentName.substring(3); isCatchAll = true; } if (segmentName.startsWith('[') || segmentName.endsWith(']')) { throw Object.defineProperty(new Error("Segment names may not start or end with extra brackets ('" + segmentName + "')."), "__NEXT_ERROR_CODE", { value: "E421", enumerable: false, configurable: true }); } if (segmentName.startsWith('.')) { throw Object.defineProperty(new Error("Segment names may not start with erroneous periods ('" + segmentName + "')."), "__NEXT_ERROR_CODE", { value: "E288", enumerable: false, configurable: true }); } function handleSlug(previousSlug, nextSlug) { if (previousSlug !== null) { // If the specific segment already has a slug but the slug is not `something` // This prevents collisions like: // pages/[post]/index.js // pages/[id]/index.js // Because currently multiple dynamic params on the same segment level are not supported if (previousSlug !== nextSlug) { // TODO: This error seems to be confusing for users, needs an error link, the description can be based on above comment. throw Object.defineProperty(new Error("You cannot use different slug names for the same dynamic path ('" + previousSlug + "' !== '" + nextSlug + "')."), "__NEXT_ERROR_CODE", { value: "E337", enumerable: false, configurable: true }); } } slugNames.forEach((slug)=>{ if (slug === nextSlug) { throw Object.defineProperty(new Error('You cannot have the same slug name "' + nextSlug + '" repeat within a single dynamic path'), "__NEXT_ERROR_CODE", { value: "E247", enumerable: false, configurable: true }); } if (slug.replace(/\W/g, '') === nextSegment.replace(/\W/g, '')) { throw Object.defineProperty(new Error('You cannot have the slug names "' + slug + '" and "' + nextSlug + '" differ only by non-word symbols within a single dynamic path'), "__NEXT_ERROR_CODE", { value: "E499", enumerable: false, configurable: true }); } }); slugNames.push(nextSlug); } if (isCatchAll) { if (isOptional) { if (this.restSlugName != null) { throw Object.defineProperty(new Error('You cannot use both an required and optional catch-all route at the same level ("[...' + this.restSlugName + ']" and "' + urlPaths[0] + '" ).'), "__NEXT_ERROR_CODE", { value: "E299", enumerable: false, configurable: true }); } handleSlug(this.optionalRestSlugName, segmentName); // slugName is kept as it can only be one particular slugName this.optionalRestSlugName = segmentName; // nextSegment is overwritten to [[...]] so that it can later be sorted specifically nextSegment = '[[...]]'; } else { if (this.optionalRestSlugName != null) { throw Object.defineProperty(new Error('You cannot use both an optional and required catch-all route at the same level ("[[...' + this.optionalRestSlugName + ']]" and "' + urlPaths[0] + '").'), "__NEXT_ERROR_CODE", { value: "E300", enumerable: false, configurable: true }); } handleSlug(this.restSlugName, segmentName); // slugName is kept as it can only be one particular slugName this.restSlugName = segmentName; // nextSegment is overwritten to [...] so that it can later be sorted specifically nextSegment = '[...]'; } } else { if (isOptional) { throw Object.defineProperty(new Error('Optional route parameters are not yet supported ("' + urlPaths[0] + '").'), "__NEXT_ERROR_CODE", { value: "E435", enumerable: false, configurable: true }); } handleSlug(this.slugName, segmentName); // slugName is kept as it can only be one particular slugName this.slugName = segmentName; // nextSegment is overwritten to [] so that it can later be sorted specifically nextSegment = '[]'; } } // If this UrlNode doesn't have the nextSegment yet we create a new child UrlNode if (!this.children.has(nextSegment)) { this.children.set(nextSegment, new UrlNode()); } this.children.get(nextSegment)._insert(urlPaths.slice(1), slugNames, isCatchAll); } constructor(){ this.placeholder = true; this.children = new Map(); this.slugName = null; this.restSlugName = null; this.optionalRestSlugName = null; } } function getSortedRoutes(normalizedPages) { // First the UrlNode is created, and every UrlNode can have only 1 dynamic segment // Eg you can't have pages/[post]/abc.js and pages/[hello]/something-else.js // Only 1 dynamic segment per nesting level // So in the case that is test/integration/dynamic-routing it'll be this: // pages/[post]/comments.js // pages/blog/[post]/comment/[id].js // Both are fine because `pages/[post]` and `pages/blog` are on the same level // So in this case `UrlNode` created here has `this.slugName === 'post'` // And since your PR passed through `slugName` as an array basically it'd including it in too many possibilities // Instead what has to be passed through is the upwards path's dynamic names const root = new UrlNode(); // Here the `root` gets injected multiple paths, and insert will break them up into sublevels normalizedPages.forEach((pagePath)=>root.insert(pagePath)); // Smoosh will then sort those sublevels up to the point where you get the correct route definition priority return root.smoosh(); } function getSortedRouteObjects(objects, getter) { // We're assuming here that all the pathnames are unique, that way we can // sort the list and use the index as the key. const indexes = {}; const pathnames = []; for(let i = 0; i < objects.length; i++){ const pathname = getter(objects[i]); indexes[pathname] = i; pathnames[i] = pathname; } // Sort the pathnames. const sorted = getSortedRoutes(pathnames); // Map the sorted pathnames back to the original objects using the new sorted // index. return sorted.map((pathname)=>objects[indexes[pathname]]); } //# sourceMappingURL=sorted-routes.js.map