@i18n-micro/route-strategy 1.1.16 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +106 -106
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("node:path"),k=require("node:fs"),_=require("@i18n-micro/core"),C=l=>l.map(e=>({...e})),M=l=>!!(l.redirect&&!l.file),j=(l,e,t,a="localized-")=>t?`${a}${l}-${e}`:`${a}${l}`,b=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,""),T=(l,e,t)=>t&&l!==e.code,V=(l,e)=>(typeof l=="string"?l:l.code)===e.code,J=[/^\/sitemap.*\.xml$/,/^\/sitemap\.xml$/,/^\/robots\.txt$/,/^\/favicon\.ico$/,/^\/apple-touch-icon.*\.png$/,/^\/manifest\.json$/,/^\/sw\.js$/,/^\/workbox-.*\.js$/,/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/];function K(l,e){if(/(?:^|\/)__[^/]+/.test(l))return!0;for(const t of J)if(t.test(l))return!0;if(e){for(const t of e)if(typeof t=="string"){if(t.includes("*")||t.includes("?")){if(new RegExp(t.replace(/\*/g,".*").replace(/\?/g,".")).test(l))return!0}else if(l===t||l.startsWith(t))return!0}else if(t instanceof RegExp&&t.test(l))return!0}return!1}function Q(l,e){const t=l.reduce((o,s)=>{const r=o.find(i=>i.code===s.code);return r?Object.assign(r,s):o.push(s),o},[]).filter(o=>!o.disabled),a=t.find(o=>o.code===e)??{code:e};return{locales:t,defaultLocale:a}}function A(l){return l.split("/").map(e=>e.startsWith("[...")&&e.endsWith("]")?`:${e.substring(4,e.length-1)}(.*)*`:e.startsWith("[")&&e.endsWith("]")?`:${e.substring(1,e.length-1)}`:e).join("/")}const R=l=>{if(!l)return"";const e=w.posix.normalize(l).replace(/\/+$/,"");return e==="."?"":e},z=l=>l.startsWith("/")?l.slice(1):l;function G(...l){return w.posix.join(...l)}function X(l){if(!(typeof l>"u"))return l.startsWith("/")&&l.endsWith("/")?l?.slice(1,-1):l}function Y(l){return!l||!/[\u0080-\uFFFF]/.test(l)?l:l.split("/").map(e=>!e||e.startsWith(":")||!/[\u0080-\uFFFF]/.test(e)?e:encodeURI(e)).join("/")}function q(l){const e=Y(l);return e!==l?[e]:[]}function N(l,e,t){const a=X(t?.toString()),o=a||(Array.isArray(l)?l.join("|"):l),s=e;return R(w.posix.join("/",`:locale(${o})`,s))}function B(l){const e=l;return R(e)}const Z=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,"");function F(l){return z(l)||"/"}function W(l,e,t,a=""){const o={};return l.forEach(s=>{const r=Z(s.name,s.path),i=R(G(a,s.path??"")),n=F(i),f=A(i),c=e[n]||e[f]||e[r];if(c)typeof c=="object"&&(o[n]=c);else{const h=t[r];h&&typeof h=="object"&&!Array.isArray(h)&&(o[n]=h)}if(s.children?.length){const h=R(G(a,s.path??""));Object.assign(o,W(s.children,e,t,h))}}),o}function v(l,e,t){const a=A(e),o=F(e);return l[t]===!1||l[a]===!1||l[o]===!1||l[z(a)]===!1}function ee(l,e,t,a){if(!l||Object.keys(l).length===0)return!0;const o=A(t),s=z(o)||"/",r=s==="/"?"/":s,i=l[o]??l[t]??l[s]??l[r]??(s!=="/"?l[`/${s}`]:void 0);if(!Array.isArray(i)||i.length===0)return!0;const n=e.map(c=>c.code),f=i.filter(c=>n.includes(c));return f.length===0?!0:f.includes(a)}function te(l){const e={};if(!l)return e;for(const t in l){const a=A(t),o=l[t];if(typeof o=="object"){const s={};for(const r in o){const i=o[r];i&&(s[r]=A(i))}e[a]=s}else e[a]=o}return e}class ae{constructor(e){this.locales=e.locales,this.defaultLocale=this.findLocaleByCode(e.locales,e.defaultLocaleCode)??{code:e.defaultLocaleCode},this.strategy=e.strategy,this.globalLocaleRoutes=te(e.globalLocaleRoutes??{}),this.filesLocaleRoutes=e.filesLocaleRoutes??{},this.routeLocales=e.routeLocales??{},this.localizedPaths=W(e.pages,this.globalLocaleRoutes,this.filesLocaleRoutes),this.activeLocaleCodes=this.locales.filter(t=>t.code!==this.defaultLocale.code||_.isPrefixAndDefaultStrategy(this.strategy)||_.isPrefixStrategy(this.strategy)).map(t=>t.code),this.excludePatterns=e.excludePatterns,this.customRegex=e.customRegex,this.noPrefixRedirect=e.noPrefixRedirect??!1,this.localizedRouteNamePrefix=e.localizedRouteNamePrefix??"localized-",this.fallbackRedirectComponentPath=e.fallbackRedirectComponentPath,this.rawGlobalLocaleRoutes=e.rawGlobalLocaleRoutes}findLocaleByCode(e,t){return e.find(a=>a.code===t)}getAllowedLocales(e,t){const a=this.routeLocales[e]??this.routeLocales[t];return a?.length?a.filter(o=>this.locales.some(s=>s.code===o)):this.locales.map(o=>o.code)}getCustomPath(e,t){const a=F(e);return this.localizedPaths[a]?.[t]}getCustomPathsForPage(e,t){const a=F(e);return this.localizedPaths[a]??this.localizedPaths[t]}hasLocaleRestrictions(e,t){return!!(this.routeLocales[e]??this.routeLocales[t])}filterLocaleCodesWithoutCustomPaths(e){const t=F(e);return this.activeLocaleCodes.filter(a=>!this.localizedPaths[t]?.[a])}}function y(l,e){const t=(e??"").trim();return t.startsWith("/")?R(t):R(w.posix.join(l||"",t))}function g(l,e){const{path:t,name:a,children:o,meta:s,alias:r}=e,i={...l,path:t};return a!==void 0&&(i.name=a),o!==void 0&&(i.children=o),s!==void 0&&(i.meta={...l.meta,...s}),r!==void 0?(i.alias=r,i.meta={...i.meta,alias:r}):"alias"in e&&(i.alias=void 0,i.meta={...i.meta,alias:void 0}),i}function se(l){const e=l.alias,t=l.meta?.alias,a=e??t;return Array.isArray(a)?a:[]}function O(l,e,t,a="localized-"){const o=se(l);if(!o.length)return[];const s=[];for(const r of o){const i=N(e,r,t);s.push(g(l,{path:i,name:`${a}${l.name??""}`,alias:void 0,meta:{alias:void 0},children:l.children}))}return s}class E{processPage(e,t){if(e.path===void 0)throw new Error("page.path is required");if(M(e))return[e];if(e.path&&K(e.path,t.excludePatterns))return[e];const a=e.path??"",o=b(e.name,e.path);return v(t.globalLocaleRoutes,a,o)?[e]:this.generateVariants(e,t)}postProcess(e,t){return e}localizeChildren(e,t,a,o,s,r){return e.flatMap(i=>this.localizeChild(i,t,a,o,s,r))}localizeChildrenAllLocales(e,t,a,o,s){return e.flatMap(r=>this.localizeChildAllLocales(r,t,a,o,s))}localizeChildAllLocales(e,t,a,o,s){const r=y(a,e.path??""),i=b(e.name,e.path);if(v(s.globalLocaleRoutes,r,i))return[e];const n=y(t,e.path??""),f=F(n),c=s.localizedPaths[f];if(c)return o.flatMap(P=>{const L=c[P]??y(t,e.path??"");return this.localizeChild(e,L,a,P,s,!0)});const h=R(e.path??""),u=z(h),m=this.localizeChildrenAllLocales(C(e.children??[]),n,r,o,s),d=`${s.localizedRouteNamePrefix}${e.name??""}`;return[g(e,{path:u,name:d,children:m})]}localizeChild(e,t,a,o,s,r){const i=y(a,e.path??""),n=b(e.name,e.path);if(v(s.globalLocaleRoutes,i,n))return[e];const f=s.getCustomPath(i,o),c=z(R(f||(e.path??""))),h=f??y(t,e.path??""),u=this.localizeChildren(C(e.children??[]),h,i,o,s,r),m=b(e.name,e.path),d=`${s.localizedRouteNamePrefix}${m}-${o}`;return[g(e,{path:c,name:d,children:u})]}buildRoutePathForLocales(e,t,a,o,s,r,i){if(o){const n=e.includes(i);return r||!n?N(e,a,s):R(a)}return N(e,t,s)}}class oe extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[];if(n.push(e),r)for(const f of s){const c=r[f];if(!c)continue;const h=R(c),u=R(a);if(h===u)continue;const m=B(c),d=j(o,f,!0),P=this.localizeChildrenForNoPrefix(i,h,a,a,f,t,1);n.push(g(e,{path:m,name:d,children:P,alias:[],meta:{alias:[]}})),t.noPrefixRedirect&&f===t.defaultLocale.code&&h!==u&&(e.redirect=h)}return n.push(...O(e,s,t.customRegex,t.localizedRouteNamePrefix)),n}localizeChildrenForNoPrefix(e,t,a,o,s,r,i){return e.map(n=>{const f=y(a,n.path??"");let c,h;if(i===1){const P=r.getCustomPath(f,s);if(P){const L=R(P);c=z(L),h=L}else{const L=R(n.path??"");c=z(L),h=y(t,n.path??"")}}else{const P=R(n.path??"");c=z(P),h=y(t,n.path??"")}const u=this.localizeChildrenForNoPrefix(C(n.children??[]),h,f,o,s,r,i+1),m=b(n.name,n.path),d=j(m,s,!0);return g(n,{path:c,name:d,children:u})})}}function le(l){const e=l.alias??l.meta?.alias;return Array.isArray(e)?e:[]}class ie extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[];if(r)for(const c of s){const h=r[c],u=h?R(h):a,m=N(c,u,t.customRegex),d=j(o,c,!!h,t.localizedRouteNamePrefix),P=h??a,L=this.localizeChildren(i,P,a,c,t,!0),p=q(m);n.push(g(e,{path:m,name:d,children:L,alias:p.length?p:void 0,meta:{alias:p.length?p:[]}}))}else{const c=N(s,a,t.customRegex),h=j(o,s[0],!1,t.localizedRouteNamePrefix),u=this.localizeChildrenAllLocales(i,a,a,s,t);n.push(g(e,{path:c,name:h,children:u,alias:[],meta:{alias:[]}}))}const f=le(e);if(f.length)for(const c of f){const h=N(s,c,t.customRegex);n.push(g(e,{path:h,name:`${t.localizedRouteNamePrefix}${e.name??""}`,alias:void 0,meta:{alias:void 0}}))}return n}postProcess(e,t){const a=e.filter(s=>{if(s.name==="index"&&s.path==="/")return!1;const r=s.path??"";return!!(r&&K(r,t.excludePatterns)||v(t.globalLocaleRoutes,r,s.name??"")||/^\/:locale/.test(r)||r==="/")}),o=t.defaultLocale.code;for(const[s,r]of Object.entries(t.globalLocaleRoutes)){if(r===!1||typeof r!="object")continue;const i=r[o];if(!i)continue;const n=s.startsWith("/")?s:`/${s}`,f=`/${o}${i.startsWith("/")?i:`/${i}`}`;n!==f&&a.push({path:n,name:`redirect-${s.replace(/\//g,"-")}`,redirect:f})}return t.fallbackRedirectComponentPath&&a.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),a}}class re extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[],f=t.defaultLocale.code;n.push(e);const c=t.locales.filter(u=>s.includes(u.code));if(c.length>0)if(r)for(const u of c){const m=r[u.code];if(m)if(u.code===f){const d=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,a,t);d&&n.push(d);const P=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!0,u.code,a,t);P&&n.push(P)}else{const d=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,a,t);d&&n.push(d)}else{const d=this.createLocalizedRoute(e,[u.code],i,!1,"",t.customRegex,!1,u.code,a,t);d&&n.push(d)}}else{const u=c.map(d=>d.code),m=this.createLocalizedRoute(e,u,i,!1,"",t.customRegex,!1,!0,a,t);m&&n.push(m)}const h=O(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const a=[],o=[];for(const s of e){const r=s.name??"";typeof r=="string"&&r.startsWith(t.localizedRouteNamePrefix)?o.push(s):a.push(s)}return[...a,...o]}createLocalizedRoute(e,t,a,o,s="",r,i=!1,n=!1,f,c){const h=this.buildRoutePathForLocales(t,e.path??"",s,o,r,i,c.defaultLocale.code);if(!h||!(o&&s)&&h===e.path||t.length===0)return null;const m=t[0];if(!m)return null;const d=f??e.path??"",P=j(b(e.name??"",d),m,o,c.localizedRouteNamePrefix),L=i||m!==c.defaultLocale.code,p=t.length===1?this.localizeChildren(a,h,d,m,c,L):this.localizeChildrenAllLocales(a,h,d,t,c);return g(e,{path:h,name:P,children:p,alias:[],meta:{alias:[]}})}}class ne extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[],f=t.defaultLocale.code;if(s.includes(f)){const u=r?.[f],m=u?R(u):a,d=u?{[f]:u}:{},P=this.createLocalizedChildren(i,a,[f],!1,!1,!1,d,t);n.push(g(e,{path:m,name:e.name,children:P}))}const c=t.locales.filter(u=>s.includes(u.code)&&u.code!==f);if(c.length)if(r)for(const u of c){const m=r[u.code];if(m){const d=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,a,t);d&&n.push(d)}else{const d=this.createLocalizedRoute(e,[u.code],i,!1,"",t.customRegex,!1,u.code,a,t);d&&n.push(d)}}else{const u=c.map(d=>d.code),m=this.createLocalizedRoute(e,u,i,!1,"",t.customRegex,!1,!0,a,t);m&&n.push(m)}const h=O(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const a=[],o=[];for(const r of e){const i=r.name??"";typeof i=="string"&&i.startsWith(t.localizedRouteNamePrefix)?o.push(r):a.push(r)}const s=[...a,...o];return t.fallbackRedirectComponentPath&&s.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),s}createLocalizedChildren(e,t,a,o=!0,s=!1,r=!1,i={},n){return e.flatMap(f=>this.createLocalizedVariants(f,t,a,o,s,r,i,n))}createLocalizedVariants(e,t,a,o,s,r=!1,i,n){const f=R(e.path??""),c=y(t,e.path??""),h=F(c),u=n.localizedPaths[h],m=!!u,d=[];if(!m){const P=z(f),L=this.createLocalizedChildren(C(e.children??[]),y(t,e.path??""),a,o,s,r,i,n),p=this.buildChildRouteName(e.name,r,n);return d.push(g(e,{path:P,name:p,children:L})),d}for(const P of a){const L=i?.[P],p=!!L,$=u?.[P];let x=R($||(e.path??""));p&&L&&($?x=R($):x=y(L,e.path??""));const S=T(P,n.defaultLocale,s)?N(P,x,n.customRegex):x,I=z(S),D=$?R($):p?L:y(t,e.path??""),U=this.createLocalizedChildren(C(e.children??[]),D,[P],o,s,P,{...i,[P]:D},n),H=this.buildLocalizedRouteName(b(e.name,e.path),P,o,!!u,n);d.push(g(e,{path:I,name:H,children:U}))}return d}buildChildRouteName(e,t,a){return t===!0?`${a.localizedRouteNamePrefix}${e}`:typeof t=="string"?`${a.localizedRouteNamePrefix}${e}-${t}`:e}createLocalizedRoute(e,t,a,o,s="",r,i=!1,n=!1,f,c){const h=this.buildRoutePathForLocales(t,e.path??"",s,o,r,i,c.defaultLocale.code);if(!h||h===e.path||t.length===0)return null;const u=t[0];if(!u)return null;const m=f??e.path??"",d=j(b(e.name??"",m),u,o,c.localizedRouteNamePrefix);return g(e,{path:h,name:d,children:this.createLocalizedChildren(a,m,t,!0,!1,n,{[u]:s},c),alias:[],meta:{alias:[]}})}buildLocalizedRouteName(e,t,a,o=!1,s){return a?o?`${s.localizedRouteNamePrefix}${e}-${t}`:t&&!V(t,s.defaultLocale)?`${s.localizedRouteNamePrefix}${e}-${t}`:`${s.localizedRouteNamePrefix}${e}`:e}}function ce(l){switch(l){case"no_prefix":return new oe;case"prefix":return new ie;case"prefix_and_default":return new re;case"prefix_except_default":return new ne;default:throw new Error(`Unknown route strategy: ${l}`)}}class ue{constructor(e){this.localizedPaths={};const{locales:t,defaultLocaleCode:a,strategy:o,globalLocaleRoutes:s,filesLocaleRoutes:r={},routeLocales:i={},noPrefixRedirect:n,excludePatterns:f,localizedRouteNamePrefix:c="localized-",customRegexMatcher:h,fallbackRedirectComponentPath:u}=e,m=Q(t,a);this.locales=m.locales,this.defaultLocale=m.defaultLocale,this.strategy=o,this.noPrefixRedirect=n,this.excludePatterns=f,this.localizedRouteNamePrefix=c,this.customRegex=h,this.fallbackRedirectComponentPath=u,this.activeLocaleCodes=this.computeActiveLocaleCodes();const d={};for(const P in s){const L=A(P),p=s[P];if(typeof p=="object"){const $={};for(const x in p){const S=p[x];S&&($[x]=A(S))}d[L]=$}else d[L]=p}this.globalLocaleRoutes=d,this.rawGlobalLocaleRoutes=s??{},this.filesLocaleRoutes=r??{},this.routeLocales=i??{}}computeActiveLocaleCodes(){return this.locales.filter(e=>e.code!==this.defaultLocale.code||_.isPrefixAndDefaultStrategy(this.strategy)||_.isPrefixStrategy(this.strategy)).map(e=>e.code)}extendPages(e){const t=new ae({locales:this.locales,defaultLocaleCode:this.defaultLocale.code,strategy:this.strategy,globalLocaleRoutes:this.globalLocaleRoutes,filesLocaleRoutes:this.filesLocaleRoutes,routeLocales:this.routeLocales,pages:e,excludePatterns:this.excludePatterns,customRegex:this.customRegex,noPrefixRedirect:this.noPrefixRedirect,localizedRouteNamePrefix:this.localizedRouteNamePrefix,fallbackRedirectComponentPath:this.fallbackRedirectComponentPath,rawGlobalLocaleRoutes:this.rawGlobalLocaleRoutes});this.localizedPaths=t.localizedPaths;const a=ce(this.strategy),o=[...e],s=[];for(const i of o)s.push(...a.processPage(i,t));const r=a.postProcess(s,t);e.length=0,e.push(...r)}extractLocalizedPaths(e,t=""){return W(e,this.globalLocaleRoutes,this.filesLocaleRoutes,t)}ensureTranslationFilesExist(e,t,a,o){this.locales.forEach(s=>{const r=w.join(a,t,`${s.code}.json`);this.ensureFileExists(r),o||e.forEach(i=>{const n=w.join(a,t,"pages",`${i}/${s.code}.json`);this.ensureFileExists(n)})})}ensureFileExists(e){try{const t=w.dirname(e);k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),k.existsSync(e)||k.writeFileSync(e,JSON.stringify({}),"utf-8")}catch{}}resolveLocalizedPath(e,t){const a=A(e),o=z(a)||"/";let s;const r=this.globalLocaleRoutes[o],i=this.globalLocaleRoutes[a];r&&typeof r=="object"&&!Array.isArray(r)?s=r[t]:i&&typeof i=="object"&&!Array.isArray(i)&&(s=i[t]);const n=!!s,f=s?R(s):R(a)||"";let c=!1;if(this.strategy==="no_prefix"?c=!1:this.strategy==="prefix"||this.strategy==="prefix_and_default"?c=!0:this.strategy==="prefix_except_default"&&(c=t!==this.defaultLocale.code),t===this.defaultLocale.code&&!n&&(this.strategy==="prefix_except_default"||this.strategy==="no_prefix")&&(c=!1),!c)return R(f)||"/";const h=z(f);return h?R(`/${t}/${h}`):`/${t}`}generateDataRoutes(e,t,a){const o=[],s=this.collectPageNames(e);for(const r of this.locales)if(o.push(`/${t}/index/${r.code}/data.json`),!a)for(const i of s)o.push(`/${t}/${i}/${r.code}/data.json`);return o}collectPageNames(e){const t=new Set,a=o=>{for(const s of o)typeof s.name=="string"&&s.name.length>0&&t.add(s.name),s.children&&s.children.length>0&&a(s.children)};return a(e),[...t]}}exports.RouteGenerator=ue;exports.buildEncodedPathAliases=q;exports.buildFullPath=N;exports.buildFullPathNoPrefix=B;exports.buildRouteName=j;exports.cloneArray=C;exports.extractLocalizedPaths=W;exports.isInternalPath=K;exports.isLocaleAllowedForUnlocalizedRoute=ee;exports.isLocaleDefault=V;exports.isLocalizationDisabledForPage=v;exports.isPageRedirectOnly=M;exports.normalizePath=R;exports.normalizeRouteKey=A;exports.removeLeadingSlash=z;exports.shouldAddLocalePrefix=T;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("node:path"),k=require("node:fs"),_=require("@i18n-micro/core"),C=l=>l.map(e=>({...e})),M=l=>!!(l.redirect&&!l.file),j=(l,e,t,a="localized-")=>t?`${a}${l}-${e}`:`${a}${l}`,b=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,""),T=(l,e,t)=>t&&l!==e.code,V=(l,e)=>(typeof l=="string"?l:l.code)===e.code,J=[/^\/sitemap.*\.xml$/,/^\/sitemap\.xml$/,/^\/robots\.txt$/,/^\/favicon\.ico$/,/^\/apple-touch-icon.*\.png$/,/^\/manifest\.json$/,/^\/sw\.js$/,/^\/workbox-.*\.js$/,/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/];function K(l,e){if(/(?:^|\/)__[^/]+/.test(l))return!0;for(const t of J)if(t.test(l))return!0;if(e){for(const t of e)if(typeof t=="string"){if(t.includes("*")||t.includes("?")){if(new RegExp(t.replace(/\*/g,".*").replace(/\?/g,".")).test(l))return!0}else if(l===t||l.startsWith(t))return!0}else if(t instanceof RegExp&&t.test(l))return!0}return!1}function Q(l,e){const t=l.reduce((o,s)=>{const r=o.find(i=>i.code===s.code);return r?Object.assign(r,s):o.push(s),o},[]).filter(o=>!o.disabled),a=t.find(o=>o.code===e)??{code:e};return{locales:t,defaultLocale:a}}function A(l){return l.split("/").map(e=>e.startsWith("[...")&&e.endsWith("]")?`:${e.substring(4,e.length-1)}(.*)*`:e.startsWith("[")&&e.endsWith("]")?`:${e.substring(1,e.length-1)}`:e.replace(/:([^()/]+)\(\)/g,":$1")).join("/")}const R=l=>{if(!l)return"";const e=w.posix.normalize(l).replace(/\/+$/,"");return e==="."?"":e},z=l=>l.startsWith("/")?l.slice(1):l;function G(...l){return w.posix.join(...l)}function X(l){if(!(typeof l>"u"))return l.startsWith("/")&&l.endsWith("/")?l?.slice(1,-1):l}function Y(l){return!l||!/[\u0080-\uFFFF]/.test(l)?l:l.split("/").map(e=>!e||e.startsWith(":")||!/[\u0080-\uFFFF]/.test(e)?e:encodeURI(e)).join("/")}function q(l){const e=Y(l);return e!==l?[e]:[]}function N(l,e,t){const a=X(t?.toString()),o=a||(Array.isArray(l)?l.join("|"):l),s=e;return R(w.posix.join("/",`:locale(${o})`,s))}function B(l){const e=l;return R(e)}const Z=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,"");function F(l){return z(l)||"/"}function W(l,e,t,a=""){const o={};return l.forEach(s=>{const r=Z(s.name,s.path),i=R(G(a,s.path??"")),n=F(i),f=A(i),u=z(f)||"/",h=e[n]||e[f]||e[u]||e[r];if(h)typeof h=="object"&&(o[n]=h);else{const c=t[r];c&&typeof c=="object"&&!Array.isArray(c)&&(o[n]=c)}if(s.children?.length){const c=R(G(a,s.path??""));Object.assign(o,W(s.children,e,t,c))}}),o}function v(l,e,t){const a=A(e),o=F(e);return l[t]===!1||l[a]===!1||l[o]===!1||l[z(a)]===!1}function ee(l,e,t,a){if(!l||Object.keys(l).length===0)return!0;const o=A(t),s=z(o)||"/",r=s==="/"?"/":s,i=l[o]??l[t]??l[s]??l[r]??(s!=="/"?l[`/${s}`]:void 0);if(!Array.isArray(i)||i.length===0)return!0;const n=e.map(u=>u.code),f=i.filter(u=>n.includes(u));return f.length===0?!0:f.includes(a)}function te(l){const e={};if(!l)return e;for(const t in l){const a=A(t),o=l[t];if(typeof o=="object"){const s={};for(const r in o){const i=o[r];i&&(s[r]=A(i))}e[a]=s}else e[a]=o}return e}class ae{constructor(e){this.locales=e.locales,this.defaultLocale=this.findLocaleByCode(e.locales,e.defaultLocaleCode)??{code:e.defaultLocaleCode},this.strategy=e.strategy,this.globalLocaleRoutes=te(e.globalLocaleRoutes??{}),this.filesLocaleRoutes=e.filesLocaleRoutes??{},this.routeLocales=e.routeLocales??{},this.localizedPaths=W(e.pages,this.globalLocaleRoutes,this.filesLocaleRoutes),this.activeLocaleCodes=this.locales.filter(t=>t.code!==this.defaultLocale.code||_.isPrefixAndDefaultStrategy(this.strategy)||_.isPrefixStrategy(this.strategy)).map(t=>t.code),this.excludePatterns=e.excludePatterns,this.customRegex=e.customRegex,this.noPrefixRedirect=e.noPrefixRedirect??!1,this.localizedRouteNamePrefix=e.localizedRouteNamePrefix??"localized-",this.fallbackRedirectComponentPath=e.fallbackRedirectComponentPath,this.rawGlobalLocaleRoutes=e.rawGlobalLocaleRoutes}findLocaleByCode(e,t){return e.find(a=>a.code===t)}getAllowedLocales(e,t){const a=this.routeLocales[e]??this.routeLocales[t];return a?.length?a.filter(o=>this.locales.some(s=>s.code===o)):this.locales.map(o=>o.code)}getCustomPath(e,t){const a=F(e);return this.localizedPaths[a]?.[t]}getCustomPathsForPage(e,t){const a=F(e);return this.localizedPaths[a]??this.localizedPaths[t]}hasLocaleRestrictions(e,t){return!!(this.routeLocales[e]??this.routeLocales[t])}filterLocaleCodesWithoutCustomPaths(e){const t=F(e);return this.activeLocaleCodes.filter(a=>!this.localizedPaths[t]?.[a])}}function y(l,e){const t=(e??"").trim();return t.startsWith("/")?R(t):R(w.posix.join(l||"",t))}function g(l,e){const{path:t,name:a,children:o,meta:s,alias:r}=e,i={...l,path:t};return a!==void 0&&(i.name=a),o!==void 0&&(i.children=o),s!==void 0&&(i.meta={...l.meta,...s}),r!==void 0?(i.alias=r,i.meta={...i.meta,alias:r}):"alias"in e&&(i.alias=void 0,i.meta={...i.meta,alias:void 0}),i}function se(l){const e=l.alias,t=l.meta?.alias,a=e??t;return Array.isArray(a)?a:[]}function O(l,e,t,a="localized-"){const o=se(l);if(!o.length)return[];const s=[];for(const r of o){const i=N(e,r,t);s.push(g(l,{path:i,name:`${a}${l.name??""}`,alias:void 0,meta:{alias:void 0},children:l.children}))}return s}class E{processPage(e,t){if(e.path===void 0)throw new Error("page.path is required");if(M(e))return[e];if(e.path&&K(e.path,t.excludePatterns))return[e];const a=e.path??"",o=b(e.name,e.path);return v(t.globalLocaleRoutes,a,o)?[e]:this.generateVariants(e,t)}postProcess(e,t){return e}localizeChildren(e,t,a,o,s,r){return e.flatMap(i=>this.localizeChild(i,t,a,o,s,r))}localizeChildrenAllLocales(e,t,a,o,s){return e.flatMap(r=>this.localizeChildAllLocales(r,t,a,o,s))}localizeChildAllLocales(e,t,a,o,s){const r=y(a,e.path??""),i=b(e.name,e.path);if(v(s.globalLocaleRoutes,r,i))return[e];const n=y(t,e.path??""),f=F(n),u=s.localizedPaths[f];if(u)return o.flatMap(P=>{const L=u[P]??y(t,e.path??"");return this.localizeChild(e,L,a,P,s,!0)});const h=R(e.path??""),c=z(h),m=this.localizeChildrenAllLocales(C(e.children??[]),n,r,o,s),d=`${s.localizedRouteNamePrefix}${e.name??""}`;return[g(e,{path:c,name:d,children:m})]}localizeChild(e,t,a,o,s,r){const i=y(a,e.path??""),n=b(e.name,e.path);if(v(s.globalLocaleRoutes,i,n))return[e];const f=s.getCustomPath(i,o),u=z(R(f||(e.path??""))),h=f??y(t,e.path??""),c=this.localizeChildren(C(e.children??[]),h,i,o,s,r),m=b(e.name,e.path),d=`${s.localizedRouteNamePrefix}${m}-${o}`;return[g(e,{path:u,name:d,children:c})]}buildRoutePathForLocales(e,t,a,o,s,r,i){if(o){const n=e.includes(i);return r||!n?N(e,a,s):R(a)}return N(e,t,s)}}class oe extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[];if(n.push(e),r)for(const f of s){const u=r[f];if(!u)continue;const h=R(u),c=R(a);if(h===c)continue;const m=B(u),d=j(o,f,!0),P=this.localizeChildrenForNoPrefix(i,h,a,a,f,t,1);n.push(g(e,{path:m,name:d,children:P,alias:[],meta:{alias:[]}})),t.noPrefixRedirect&&f===t.defaultLocale.code&&h!==c&&(e.redirect=h)}return n.push(...O(e,s,t.customRegex,t.localizedRouteNamePrefix)),n}localizeChildrenForNoPrefix(e,t,a,o,s,r,i){return e.map(n=>{const f=y(a,n.path??"");let u,h;if(i===1){const P=r.getCustomPath(f,s);if(P){const L=R(P);u=z(L),h=L}else{const L=R(n.path??"");u=z(L),h=y(t,n.path??"")}}else{const P=R(n.path??"");u=z(P),h=y(t,n.path??"")}const c=this.localizeChildrenForNoPrefix(C(n.children??[]),h,f,o,s,r,i+1),m=b(n.name,n.path),d=j(m,s,!0);return g(n,{path:u,name:d,children:c})})}}function le(l){const e=l.alias??l.meta?.alias;return Array.isArray(e)?e:[]}class ie extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[];if(r)for(const u of s){const h=r[u],c=h?R(h):a,m=N(u,c,t.customRegex),d=j(o,u,!!h,t.localizedRouteNamePrefix),P=h??a,L=this.localizeChildren(i,P,a,u,t,!0),p=q(m);n.push(g(e,{path:m,name:d,children:L,alias:p.length?p:void 0,meta:{alias:p.length?p:[]}}))}else{const u=N(s,a,t.customRegex),h=j(o,s[0],!1,t.localizedRouteNamePrefix),c=this.localizeChildrenAllLocales(i,a,a,s,t);n.push(g(e,{path:u,name:h,children:c,alias:[],meta:{alias:[]}}))}const f=le(e);if(f.length)for(const u of f){const h=N(s,u,t.customRegex);n.push(g(e,{path:h,name:`${t.localizedRouteNamePrefix}${e.name??""}`,alias:void 0,meta:{alias:void 0}}))}return n}postProcess(e,t){const a=e.filter(s=>{if(s.name==="index"&&s.path==="/")return!1;const r=s.path??"";return!!(r&&K(r,t.excludePatterns)||v(t.globalLocaleRoutes,r,s.name??"")||/^\/:locale/.test(r)||r==="/")}),o=t.defaultLocale.code;for(const[s,r]of Object.entries(t.globalLocaleRoutes)){if(r===!1||typeof r!="object")continue;const i=r[o];if(!i)continue;const n=s.startsWith("/")?s:`/${s}`,f=`/${o}${i.startsWith("/")?i:`/${i}`}`;n!==f&&a.push({path:n,name:`redirect-${s.replace(/\//g,"-")}`,redirect:f})}return t.fallbackRedirectComponentPath&&a.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),a}}class re extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[],f=t.defaultLocale.code;n.push(e);const u=t.locales.filter(c=>s.includes(c.code));if(u.length>0)if(r)for(const c of u){const m=r[c.code];if(m)if(c.code===f){const d=this.createLocalizedRoute(e,[c.code],i,!0,m,t.customRegex,!1,c.code,a,t);d&&n.push(d);const P=this.createLocalizedRoute(e,[c.code],i,!0,m,t.customRegex,!0,c.code,a,t);P&&n.push(P)}else{const d=this.createLocalizedRoute(e,[c.code],i,!0,m,t.customRegex,!1,c.code,a,t);d&&n.push(d)}else{const d=this.createLocalizedRoute(e,[c.code],i,!1,"",t.customRegex,!1,c.code,a,t);d&&n.push(d)}}else{const c=u.map(d=>d.code),m=this.createLocalizedRoute(e,c,i,!1,"",t.customRegex,!1,!0,a,t);m&&n.push(m)}const h=O(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const a=[],o=[];for(const s of e){const r=s.name??"";typeof r=="string"&&r.startsWith(t.localizedRouteNamePrefix)?o.push(s):a.push(s)}return[...a,...o]}createLocalizedRoute(e,t,a,o,s="",r,i=!1,n=!1,f,u){const h=this.buildRoutePathForLocales(t,e.path??"",s,o,r,i,u.defaultLocale.code);if(!h||!(o&&s)&&h===e.path||t.length===0)return null;const m=t[0];if(!m)return null;const d=f??e.path??"",P=j(b(e.name??"",d),m,o,u.localizedRouteNamePrefix),L=i||m!==u.defaultLocale.code,p=t.length===1?this.localizeChildren(a,h,d,m,u,L):this.localizeChildrenAllLocales(a,h,d,t,u);return g(e,{path:h,name:P,children:p,alias:[],meta:{alias:[]}})}}class ne extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[],f=t.defaultLocale.code;if(s.includes(f)){const c=r?.[f],m=c?R(c):a,d=c?{[f]:c}:{},P=this.createLocalizedChildren(i,a,[f],!1,!1,!1,d,t);n.push(g(e,{path:m,name:e.name,children:P}))}const u=t.locales.filter(c=>s.includes(c.code)&&c.code!==f);if(u.length)if(r)for(const c of u){const m=r[c.code];if(m){const d=this.createLocalizedRoute(e,[c.code],i,!0,m,t.customRegex,!1,c.code,a,t);d&&n.push(d)}else{const d=this.createLocalizedRoute(e,[c.code],i,!1,"",t.customRegex,!1,c.code,a,t);d&&n.push(d)}}else{const c=u.map(d=>d.code),m=this.createLocalizedRoute(e,c,i,!1,"",t.customRegex,!1,!0,a,t);m&&n.push(m)}const h=O(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const a=[],o=[];for(const r of e){const i=r.name??"";typeof i=="string"&&i.startsWith(t.localizedRouteNamePrefix)?o.push(r):a.push(r)}const s=[...a,...o];return t.fallbackRedirectComponentPath&&s.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),s}createLocalizedChildren(e,t,a,o=!0,s=!1,r=!1,i={},n){return e.flatMap(f=>this.createLocalizedVariants(f,t,a,o,s,r,i,n))}createLocalizedVariants(e,t,a,o,s,r=!1,i,n){const f=R(e.path??""),u=y(t,e.path??""),h=F(u),c=n.localizedPaths[h],m=!!c,d=[];if(!m){const P=z(f),L=this.createLocalizedChildren(C(e.children??[]),y(t,e.path??""),a,o,s,r,i,n),p=this.buildChildRouteName(e.name,r,n);return d.push(g(e,{path:P,name:p,children:L})),d}for(const P of a){const L=i?.[P],p=!!L,$=c?.[P];let x=R($||(e.path??""));p&&L&&($?x=R($):x=y(L,e.path??""));const S=T(P,n.defaultLocale,s)?N(P,x,n.customRegex):x,I=z(S),D=$?R($):p?L:y(t,e.path??""),U=this.createLocalizedChildren(C(e.children??[]),D,[P],o,s,P,{...i,[P]:D},n),H=this.buildLocalizedRouteName(b(e.name,e.path),P,o,!!c,n);d.push(g(e,{path:I,name:H,children:U}))}return d}buildChildRouteName(e,t,a){return t===!0?`${a.localizedRouteNamePrefix}${e}`:typeof t=="string"?`${a.localizedRouteNamePrefix}${e}-${t}`:e}createLocalizedRoute(e,t,a,o,s="",r,i=!1,n=!1,f,u){const h=this.buildRoutePathForLocales(t,e.path??"",s,o,r,i,u.defaultLocale.code);if(!h||h===e.path||t.length===0)return null;const c=t[0];if(!c)return null;const m=f??e.path??"",d=j(b(e.name??"",m),c,o,u.localizedRouteNamePrefix);return g(e,{path:h,name:d,children:this.createLocalizedChildren(a,m,t,!0,!1,n,{[c]:s},u),alias:[],meta:{alias:[]}})}buildLocalizedRouteName(e,t,a,o=!1,s){return a?o?`${s.localizedRouteNamePrefix}${e}-${t}`:t&&!V(t,s.defaultLocale)?`${s.localizedRouteNamePrefix}${e}-${t}`:`${s.localizedRouteNamePrefix}${e}`:e}}function ce(l){switch(l){case"no_prefix":return new oe;case"prefix":return new ie;case"prefix_and_default":return new re;case"prefix_except_default":return new ne;default:throw new Error(`Unknown route strategy: ${l}`)}}class ue{constructor(e){this.localizedPaths={};const{locales:t,defaultLocaleCode:a,strategy:o,globalLocaleRoutes:s,filesLocaleRoutes:r={},routeLocales:i={},noPrefixRedirect:n,excludePatterns:f,localizedRouteNamePrefix:u="localized-",customRegexMatcher:h,fallbackRedirectComponentPath:c}=e,m=Q(t,a);this.locales=m.locales,this.defaultLocale=m.defaultLocale,this.strategy=o,this.noPrefixRedirect=n,this.excludePatterns=f,this.localizedRouteNamePrefix=u,this.customRegex=h,this.fallbackRedirectComponentPath=c,this.activeLocaleCodes=this.computeActiveLocaleCodes();const d={};for(const P in s){const L=A(P),p=s[P];if(typeof p=="object"){const $={};for(const x in p){const S=p[x];S&&($[x]=A(S))}d[L]=$}else d[L]=p}this.globalLocaleRoutes=d,this.rawGlobalLocaleRoutes=s??{},this.filesLocaleRoutes=r??{},this.routeLocales=i??{}}computeActiveLocaleCodes(){return this.locales.filter(e=>e.code!==this.defaultLocale.code||_.isPrefixAndDefaultStrategy(this.strategy)||_.isPrefixStrategy(this.strategy)).map(e=>e.code)}extendPages(e){const t=new ae({locales:this.locales,defaultLocaleCode:this.defaultLocale.code,strategy:this.strategy,globalLocaleRoutes:this.globalLocaleRoutes,filesLocaleRoutes:this.filesLocaleRoutes,routeLocales:this.routeLocales,pages:e,excludePatterns:this.excludePatterns,customRegex:this.customRegex,noPrefixRedirect:this.noPrefixRedirect,localizedRouteNamePrefix:this.localizedRouteNamePrefix,fallbackRedirectComponentPath:this.fallbackRedirectComponentPath,rawGlobalLocaleRoutes:this.rawGlobalLocaleRoutes});this.localizedPaths=t.localizedPaths;const a=ce(this.strategy),o=[...e],s=[];for(const i of o)s.push(...a.processPage(i,t));const r=a.postProcess(s,t);e.length=0,e.push(...r)}extractLocalizedPaths(e,t=""){return W(e,this.globalLocaleRoutes,this.filesLocaleRoutes,t)}ensureTranslationFilesExist(e,t,a,o){this.locales.forEach(s=>{const r=w.join(a,t,`${s.code}.json`);this.ensureFileExists(r),o||e.forEach(i=>{const n=w.join(a,t,"pages",`${i}/${s.code}.json`);this.ensureFileExists(n)})})}ensureFileExists(e){try{const t=w.dirname(e);k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),k.existsSync(e)||k.writeFileSync(e,JSON.stringify({}),"utf-8")}catch{}}resolveLocalizedPath(e,t){const a=A(e),o=z(a)||"/";let s;const r=this.globalLocaleRoutes[o],i=this.globalLocaleRoutes[a];r&&typeof r=="object"&&!Array.isArray(r)?s=r[t]:i&&typeof i=="object"&&!Array.isArray(i)&&(s=i[t]);const n=!!s,f=s?R(s):R(a)||"";let u=!1;if(this.strategy==="no_prefix"?u=!1:this.strategy==="prefix"||this.strategy==="prefix_and_default"?u=!0:this.strategy==="prefix_except_default"&&(u=t!==this.defaultLocale.code),t===this.defaultLocale.code&&!n&&(this.strategy==="prefix_except_default"||this.strategy==="no_prefix")&&(u=!1),!u)return R(f)||"/";const h=z(f);return h?R(`/${t}/${h}`):`/${t}`}generateDataRoutes(e,t,a){const o=[],s=this.collectPageNames(e);for(const r of this.locales)if(o.push(`/${t}/index/${r.code}/data.json`),!a)for(const i of s)o.push(`/${t}/${i}/${r.code}/data.json`);return o}collectPageNames(e){const t=new Set,a=o=>{for(const s of o)typeof s.name=="string"&&s.name.length>0&&t.add(s.name),s.children&&s.children.length>0&&a(s.children)};return a(e),[...t]}}exports.RouteGenerator=ue;exports.buildEncodedPathAliases=q;exports.buildFullPath=N;exports.buildFullPathNoPrefix=B;exports.buildRouteName=j;exports.cloneArray=C;exports.extractLocalizedPaths=W;exports.isInternalPath=K;exports.isLocaleAllowedForUnlocalizedRoute=ee;exports.isLocaleDefault=V;exports.isLocalizationDisabledForPage=v;exports.isPageRedirectOnly=M;exports.normalizePath=R;exports.normalizeRouteKey=A;exports.removeLeadingSlash=z;exports.shouldAddLocalePrefix=T;
|
package/dist/index.mjs
CHANGED
|
@@ -38,14 +38,14 @@ function X(l, e) {
|
|
|
38
38
|
return { locales: t, defaultLocale: a };
|
|
39
39
|
}
|
|
40
40
|
function N(l) {
|
|
41
|
-
return l.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `:${e.substring(4, e.length - 1)}(.*)*` : e.startsWith("[") && e.endsWith("]") ? `:${e.substring(1, e.length - 1)}` : e).join("/");
|
|
41
|
+
return l.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `:${e.substring(4, e.length - 1)}(.*)*` : e.startsWith("[") && e.endsWith("]") ? `:${e.substring(1, e.length - 1)}` : e.replace(/:([^()/]+)\(\)/g, ":$1")).join("/");
|
|
42
42
|
}
|
|
43
43
|
const R = (l) => {
|
|
44
44
|
if (!l)
|
|
45
45
|
return "";
|
|
46
46
|
const e = w.posix.normalize(l).replace(/\/+$/, "");
|
|
47
47
|
return e === "." ? "" : e;
|
|
48
|
-
},
|
|
48
|
+
}, z = (l) => l.startsWith("/") ? l.slice(1) : l;
|
|
49
49
|
function G(...l) {
|
|
50
50
|
return w.posix.join(...l);
|
|
51
51
|
}
|
|
@@ -70,35 +70,35 @@ function te(l) {
|
|
|
70
70
|
}
|
|
71
71
|
const ae = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
|
|
72
72
|
function F(l) {
|
|
73
|
-
return
|
|
73
|
+
return z(l) || "/";
|
|
74
74
|
}
|
|
75
75
|
function _(l, e, t, a = "") {
|
|
76
76
|
const o = {};
|
|
77
77
|
return l.forEach((s) => {
|
|
78
|
-
const r = ae(s.name, s.path), i = R(G(a, s.path ?? "")), n = F(i), f = N(i),
|
|
79
|
-
if (
|
|
80
|
-
typeof
|
|
78
|
+
const r = ae(s.name, s.path), i = R(G(a, s.path ?? "")), n = F(i), f = N(i), u = z(f) || "/", h = e[n] || e[f] || e[u] || e[r];
|
|
79
|
+
if (h)
|
|
80
|
+
typeof h == "object" && (o[n] = h);
|
|
81
81
|
else {
|
|
82
|
-
const
|
|
83
|
-
|
|
82
|
+
const c = t[r];
|
|
83
|
+
c && typeof c == "object" && !Array.isArray(c) && (o[n] = c);
|
|
84
84
|
}
|
|
85
85
|
if (s.children?.length) {
|
|
86
|
-
const
|
|
87
|
-
Object.assign(o, _(s.children, e, t,
|
|
86
|
+
const c = R(G(a, s.path ?? ""));
|
|
87
|
+
Object.assign(o, _(s.children, e, t, c));
|
|
88
88
|
}
|
|
89
89
|
}), o;
|
|
90
90
|
}
|
|
91
91
|
function S(l, e, t) {
|
|
92
92
|
const a = N(e), o = F(e);
|
|
93
|
-
return l[t] === !1 || l[a] === !1 || l[o] === !1 || l[
|
|
93
|
+
return l[t] === !1 || l[a] === !1 || l[o] === !1 || l[z(a)] === !1;
|
|
94
94
|
}
|
|
95
95
|
function Pe(l, e, t, a) {
|
|
96
96
|
if (!l || Object.keys(l).length === 0)
|
|
97
97
|
return !0;
|
|
98
|
-
const o = N(t), s =
|
|
98
|
+
const o = N(t), s = z(o) || "/", r = s === "/" ? "/" : s, i = l[o] ?? l[t] ?? l[s] ?? l[r] ?? (s !== "/" ? l[`/${s}`] : void 0);
|
|
99
99
|
if (!Array.isArray(i) || i.length === 0)
|
|
100
100
|
return !0;
|
|
101
|
-
const n = e.map((
|
|
101
|
+
const n = e.map((u) => u.code), f = i.filter((u) => n.includes(u));
|
|
102
102
|
return f.length === 0 ? !0 : f.includes(a);
|
|
103
103
|
}
|
|
104
104
|
function se(l) {
|
|
@@ -158,7 +158,7 @@ function y(l, e) {
|
|
|
158
158
|
const t = (e ?? "").trim();
|
|
159
159
|
return t.startsWith("/") ? R(t) : R(w.posix.join(l || "", t));
|
|
160
160
|
}
|
|
161
|
-
function
|
|
161
|
+
function g(l, e) {
|
|
162
162
|
const { path: t, name: a, children: o, meta: s, alias: r } = e, i = {
|
|
163
163
|
...l,
|
|
164
164
|
path: t
|
|
@@ -176,7 +176,7 @@ function W(l, e, t, a = "localized-") {
|
|
|
176
176
|
for (const r of o) {
|
|
177
177
|
const i = x(e, r, t);
|
|
178
178
|
s.push(
|
|
179
|
-
|
|
179
|
+
g(l, {
|
|
180
180
|
path: i,
|
|
181
181
|
name: `${a}${l.name ?? ""}`,
|
|
182
182
|
alias: void 0,
|
|
@@ -224,16 +224,16 @@ class k {
|
|
|
224
224
|
const r = y(a, e.path ?? ""), i = b(e.name, e.path);
|
|
225
225
|
if (S(s.globalLocaleRoutes, r, i))
|
|
226
226
|
return [e];
|
|
227
|
-
const n = y(t, e.path ?? ""), f = F(n),
|
|
228
|
-
if (
|
|
227
|
+
const n = y(t, e.path ?? ""), f = F(n), u = s.localizedPaths[f];
|
|
228
|
+
if (u)
|
|
229
229
|
return o.flatMap((P) => {
|
|
230
|
-
const p =
|
|
230
|
+
const p = u[P] ?? y(t, e.path ?? "");
|
|
231
231
|
return this.localizeChild(e, p, a, P, s, !0);
|
|
232
232
|
});
|
|
233
|
-
const h = R(e.path ?? ""),
|
|
233
|
+
const h = R(e.path ?? ""), c = z(h), m = this.localizeChildrenAllLocales($(e.children ?? []), n, r, o, s), d = `${s.localizedRouteNamePrefix}${e.name ?? ""}`;
|
|
234
234
|
return [
|
|
235
|
-
|
|
236
|
-
path:
|
|
235
|
+
g(e, {
|
|
236
|
+
path: c,
|
|
237
237
|
name: d,
|
|
238
238
|
children: m
|
|
239
239
|
})
|
|
@@ -243,12 +243,12 @@ class k {
|
|
|
243
243
|
const i = y(a, e.path ?? ""), n = b(e.name, e.path);
|
|
244
244
|
if (S(s.globalLocaleRoutes, i, n))
|
|
245
245
|
return [e];
|
|
246
|
-
const f = s.getCustomPath(i, o),
|
|
246
|
+
const f = s.getCustomPath(i, o), u = z(R(f || (e.path ?? ""))), h = f ?? y(t, e.path ?? ""), c = this.localizeChildren($(e.children ?? []), h, i, o, s, r), m = b(e.name, e.path), d = `${s.localizedRouteNamePrefix}${m}-${o}`;
|
|
247
247
|
return [
|
|
248
|
-
|
|
249
|
-
path:
|
|
248
|
+
g(e, {
|
|
249
|
+
path: u,
|
|
250
250
|
name: d,
|
|
251
|
-
children:
|
|
251
|
+
children: c
|
|
252
252
|
})
|
|
253
253
|
];
|
|
254
254
|
}
|
|
@@ -272,21 +272,21 @@ class ie extends k {
|
|
|
272
272
|
const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [];
|
|
273
273
|
if (n.push(e), r)
|
|
274
274
|
for (const f of s) {
|
|
275
|
-
const
|
|
276
|
-
if (!
|
|
277
|
-
const h = R(
|
|
278
|
-
if (h ===
|
|
275
|
+
const u = r[f];
|
|
276
|
+
if (!u) continue;
|
|
277
|
+
const h = R(u), c = R(a);
|
|
278
|
+
if (h === c)
|
|
279
279
|
continue;
|
|
280
|
-
const m = te(
|
|
280
|
+
const m = te(u), d = j(o, f, !0), P = this.localizeChildrenForNoPrefix(i, h, a, a, f, t, 1);
|
|
281
281
|
n.push(
|
|
282
|
-
|
|
282
|
+
g(e, {
|
|
283
283
|
path: m,
|
|
284
284
|
name: d,
|
|
285
285
|
children: P,
|
|
286
286
|
alias: [],
|
|
287
287
|
meta: { alias: [] }
|
|
288
288
|
})
|
|
289
|
-
), t.noPrefixRedirect && f === t.defaultLocale.code && h !==
|
|
289
|
+
), t.noPrefixRedirect && f === t.defaultLocale.code && h !== c && (e.redirect = h);
|
|
290
290
|
}
|
|
291
291
|
return n.push(...W(e, s, t.customRegex, t.localizedRouteNamePrefix)), n;
|
|
292
292
|
}
|
|
@@ -299,21 +299,21 @@ class ie extends k {
|
|
|
299
299
|
localizeChildrenForNoPrefix(e, t, a, o, s, r, i) {
|
|
300
300
|
return e.map((n) => {
|
|
301
301
|
const f = y(a, n.path ?? "");
|
|
302
|
-
let
|
|
302
|
+
let u, h;
|
|
303
303
|
if (i === 1) {
|
|
304
304
|
const P = r.getCustomPath(f, s);
|
|
305
305
|
if (P) {
|
|
306
306
|
const p = R(P);
|
|
307
|
-
|
|
307
|
+
u = z(p), h = p;
|
|
308
308
|
} else {
|
|
309
309
|
const p = R(n.path ?? "");
|
|
310
|
-
|
|
310
|
+
u = z(p), h = y(t, n.path ?? "");
|
|
311
311
|
}
|
|
312
312
|
} else {
|
|
313
313
|
const P = R(n.path ?? "");
|
|
314
|
-
|
|
314
|
+
u = z(P), h = y(t, n.path ?? "");
|
|
315
315
|
}
|
|
316
|
-
const
|
|
316
|
+
const c = this.localizeChildrenForNoPrefix(
|
|
317
317
|
$(n.children ?? []),
|
|
318
318
|
h,
|
|
319
319
|
f,
|
|
@@ -322,10 +322,10 @@ class ie extends k {
|
|
|
322
322
|
r,
|
|
323
323
|
i + 1
|
|
324
324
|
), m = b(n.name, n.path), d = j(m, s, !0);
|
|
325
|
-
return
|
|
326
|
-
path:
|
|
325
|
+
return g(n, {
|
|
326
|
+
path: u,
|
|
327
327
|
name: d,
|
|
328
|
-
children:
|
|
328
|
+
children: c
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
331
|
}
|
|
@@ -338,10 +338,10 @@ class ne extends k {
|
|
|
338
338
|
generateVariants(e, t) {
|
|
339
339
|
const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [];
|
|
340
340
|
if (r)
|
|
341
|
-
for (const
|
|
342
|
-
const h = r[
|
|
341
|
+
for (const u of s) {
|
|
342
|
+
const h = r[u], c = h ? R(h) : a, m = x(u, c, t.customRegex), d = j(o, u, !!h, t.localizedRouteNamePrefix), P = h ?? a, p = this.localizeChildren(i, P, a, u, t, !0), L = ee(m);
|
|
343
343
|
n.push(
|
|
344
|
-
|
|
344
|
+
g(e, {
|
|
345
345
|
path: m,
|
|
346
346
|
name: d,
|
|
347
347
|
children: p,
|
|
@@ -351,12 +351,12 @@ class ne extends k {
|
|
|
351
351
|
);
|
|
352
352
|
}
|
|
353
353
|
else {
|
|
354
|
-
const
|
|
354
|
+
const u = x(s, a, t.customRegex), h = j(o, s[0], !1, t.localizedRouteNamePrefix), c = this.localizeChildrenAllLocales(i, a, a, s, t);
|
|
355
355
|
n.push(
|
|
356
|
-
|
|
357
|
-
path:
|
|
356
|
+
g(e, {
|
|
357
|
+
path: u,
|
|
358
358
|
name: h,
|
|
359
|
-
children:
|
|
359
|
+
children: c,
|
|
360
360
|
alias: [],
|
|
361
361
|
meta: { alias: [] }
|
|
362
362
|
})
|
|
@@ -364,10 +364,10 @@ class ne extends k {
|
|
|
364
364
|
}
|
|
365
365
|
const f = re(e);
|
|
366
366
|
if (f.length)
|
|
367
|
-
for (const
|
|
368
|
-
const h = x(s,
|
|
367
|
+
for (const u of f) {
|
|
368
|
+
const h = x(s, u, t.customRegex);
|
|
369
369
|
n.push(
|
|
370
|
-
|
|
370
|
+
g(e, {
|
|
371
371
|
path: h,
|
|
372
372
|
name: `${t.localizedRouteNamePrefix}${e.name ?? ""}`,
|
|
373
373
|
alias: void 0,
|
|
@@ -408,35 +408,35 @@ class ce extends k {
|
|
|
408
408
|
generateVariants(e, t) {
|
|
409
409
|
const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
|
|
410
410
|
n.push(e);
|
|
411
|
-
const
|
|
412
|
-
if (
|
|
411
|
+
const u = t.locales.filter((c) => s.includes(c.code));
|
|
412
|
+
if (u.length > 0)
|
|
413
413
|
if (r)
|
|
414
|
-
for (const
|
|
415
|
-
const m = r[
|
|
414
|
+
for (const c of u) {
|
|
415
|
+
const m = r[c.code];
|
|
416
416
|
if (m)
|
|
417
|
-
if (
|
|
417
|
+
if (c.code === f) {
|
|
418
418
|
const d = this.createLocalizedRoute(
|
|
419
419
|
e,
|
|
420
|
-
[
|
|
420
|
+
[c.code],
|
|
421
421
|
i,
|
|
422
422
|
!0,
|
|
423
423
|
m,
|
|
424
424
|
t.customRegex,
|
|
425
425
|
!1,
|
|
426
|
-
|
|
426
|
+
c.code,
|
|
427
427
|
a,
|
|
428
428
|
t
|
|
429
429
|
);
|
|
430
430
|
d && n.push(d);
|
|
431
431
|
const P = this.createLocalizedRoute(
|
|
432
432
|
e,
|
|
433
|
-
[
|
|
433
|
+
[c.code],
|
|
434
434
|
i,
|
|
435
435
|
!0,
|
|
436
436
|
m,
|
|
437
437
|
t.customRegex,
|
|
438
438
|
!0,
|
|
439
|
-
|
|
439
|
+
c.code,
|
|
440
440
|
a,
|
|
441
441
|
t
|
|
442
442
|
);
|
|
@@ -444,13 +444,13 @@ class ce extends k {
|
|
|
444
444
|
} else {
|
|
445
445
|
const d = this.createLocalizedRoute(
|
|
446
446
|
e,
|
|
447
|
-
[
|
|
447
|
+
[c.code],
|
|
448
448
|
i,
|
|
449
449
|
!0,
|
|
450
450
|
m,
|
|
451
451
|
t.customRegex,
|
|
452
452
|
!1,
|
|
453
|
-
|
|
453
|
+
c.code,
|
|
454
454
|
a,
|
|
455
455
|
t
|
|
456
456
|
);
|
|
@@ -459,13 +459,13 @@ class ce extends k {
|
|
|
459
459
|
else {
|
|
460
460
|
const d = this.createLocalizedRoute(
|
|
461
461
|
e,
|
|
462
|
-
[
|
|
462
|
+
[c.code],
|
|
463
463
|
i,
|
|
464
464
|
!1,
|
|
465
465
|
"",
|
|
466
466
|
t.customRegex,
|
|
467
467
|
!1,
|
|
468
|
-
|
|
468
|
+
c.code,
|
|
469
469
|
a,
|
|
470
470
|
t
|
|
471
471
|
);
|
|
@@ -473,9 +473,9 @@ class ce extends k {
|
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
else {
|
|
476
|
-
const
|
|
476
|
+
const c = u.map((d) => d.code), m = this.createLocalizedRoute(
|
|
477
477
|
e,
|
|
478
|
-
|
|
478
|
+
c,
|
|
479
479
|
i,
|
|
480
480
|
!1,
|
|
481
481
|
"",
|
|
@@ -498,7 +498,7 @@ class ce extends k {
|
|
|
498
498
|
}
|
|
499
499
|
return [...a, ...o];
|
|
500
500
|
}
|
|
501
|
-
createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f,
|
|
501
|
+
createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f, u) {
|
|
502
502
|
const h = this.buildRoutePathForLocales(
|
|
503
503
|
t,
|
|
504
504
|
e.path ?? "",
|
|
@@ -506,7 +506,7 @@ class ce extends k {
|
|
|
506
506
|
o,
|
|
507
507
|
r,
|
|
508
508
|
i,
|
|
509
|
-
|
|
509
|
+
u.defaultLocale.code
|
|
510
510
|
);
|
|
511
511
|
if (!h || !(o && s) && h === e.path || t.length === 0) return null;
|
|
512
512
|
const m = t[0];
|
|
@@ -515,9 +515,9 @@ class ce extends k {
|
|
|
515
515
|
b(e.name ?? "", d),
|
|
516
516
|
m,
|
|
517
517
|
o,
|
|
518
|
-
|
|
519
|
-
), p = i || m !==
|
|
520
|
-
return
|
|
518
|
+
u.localizedRouteNamePrefix
|
|
519
|
+
), p = i || m !== u.defaultLocale.code, L = t.length === 1 ? this.localizeChildren(a, h, d, m, u, p) : this.localizeChildrenAllLocales(a, h, d, t, u);
|
|
520
|
+
return g(e, {
|
|
521
521
|
path: h,
|
|
522
522
|
name: P,
|
|
523
523
|
children: L,
|
|
@@ -530,7 +530,7 @@ class ue extends k {
|
|
|
530
530
|
generateVariants(e, t) {
|
|
531
531
|
const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
|
|
532
532
|
if (s.includes(f)) {
|
|
533
|
-
const
|
|
533
|
+
const c = r?.[f], m = c ? R(c) : a, d = c ? { [f]: c } : {}, P = this.createLocalizedChildren(
|
|
534
534
|
i,
|
|
535
535
|
a,
|
|
536
536
|
[f],
|
|
@@ -541,28 +541,28 @@ class ue extends k {
|
|
|
541
541
|
t
|
|
542
542
|
);
|
|
543
543
|
n.push(
|
|
544
|
-
|
|
544
|
+
g(e, {
|
|
545
545
|
path: m,
|
|
546
546
|
name: e.name,
|
|
547
547
|
children: P
|
|
548
548
|
})
|
|
549
549
|
);
|
|
550
550
|
}
|
|
551
|
-
const
|
|
552
|
-
if (
|
|
551
|
+
const u = t.locales.filter((c) => s.includes(c.code) && c.code !== f);
|
|
552
|
+
if (u.length)
|
|
553
553
|
if (r)
|
|
554
|
-
for (const
|
|
555
|
-
const m = r[
|
|
554
|
+
for (const c of u) {
|
|
555
|
+
const m = r[c.code];
|
|
556
556
|
if (m) {
|
|
557
557
|
const d = this.createLocalizedRoute(
|
|
558
558
|
e,
|
|
559
|
-
[
|
|
559
|
+
[c.code],
|
|
560
560
|
i,
|
|
561
561
|
!0,
|
|
562
562
|
m,
|
|
563
563
|
t.customRegex,
|
|
564
564
|
!1,
|
|
565
|
-
|
|
565
|
+
c.code,
|
|
566
566
|
a,
|
|
567
567
|
t
|
|
568
568
|
);
|
|
@@ -570,13 +570,13 @@ class ue extends k {
|
|
|
570
570
|
} else {
|
|
571
571
|
const d = this.createLocalizedRoute(
|
|
572
572
|
e,
|
|
573
|
-
[
|
|
573
|
+
[c.code],
|
|
574
574
|
i,
|
|
575
575
|
!1,
|
|
576
576
|
"",
|
|
577
577
|
t.customRegex,
|
|
578
578
|
!1,
|
|
579
|
-
|
|
579
|
+
c.code,
|
|
580
580
|
a,
|
|
581
581
|
t
|
|
582
582
|
);
|
|
@@ -584,9 +584,9 @@ class ue extends k {
|
|
|
584
584
|
}
|
|
585
585
|
}
|
|
586
586
|
else {
|
|
587
|
-
const
|
|
587
|
+
const c = u.map((d) => d.code), m = this.createLocalizedRoute(
|
|
588
588
|
e,
|
|
589
|
-
|
|
589
|
+
c,
|
|
590
590
|
i,
|
|
591
591
|
!1,
|
|
592
592
|
"",
|
|
@@ -623,9 +623,9 @@ class ue extends k {
|
|
|
623
623
|
);
|
|
624
624
|
}
|
|
625
625
|
createLocalizedVariants(e, t, a, o, s, r = !1, i, n) {
|
|
626
|
-
const f = R(e.path ?? ""),
|
|
626
|
+
const f = R(e.path ?? ""), u = y(t, e.path ?? ""), h = F(u), c = n.localizedPaths[h], m = !!c, d = [];
|
|
627
627
|
if (!m) {
|
|
628
|
-
const P =
|
|
628
|
+
const P = z(f), p = this.createLocalizedChildren(
|
|
629
629
|
$(e.children ?? []),
|
|
630
630
|
y(t, e.path ?? ""),
|
|
631
631
|
a,
|
|
@@ -636,7 +636,7 @@ class ue extends k {
|
|
|
636
636
|
n
|
|
637
637
|
), L = this.buildChildRouteName(e.name, r, n);
|
|
638
638
|
return d.push(
|
|
639
|
-
|
|
639
|
+
g(e, {
|
|
640
640
|
path: P,
|
|
641
641
|
name: L,
|
|
642
642
|
children: p
|
|
@@ -644,10 +644,10 @@ class ue extends k {
|
|
|
644
644
|
), d;
|
|
645
645
|
}
|
|
646
646
|
for (const P of a) {
|
|
647
|
-
const p = i?.[P], L = !!p, C =
|
|
647
|
+
const p = i?.[P], L = !!p, C = c?.[P];
|
|
648
648
|
let A = R(C || (e.path ?? ""));
|
|
649
649
|
L && p && (C ? A = R(C) : A = y(p, e.path ?? ""));
|
|
650
|
-
const v = H(P, n.defaultLocale, s) ? x(P, A, n.customRegex) : A, T =
|
|
650
|
+
const v = H(P, n.defaultLocale, s) ? x(P, A, n.customRegex) : A, T = z(v), E = C ? R(C) : L ? p : y(t, e.path ?? ""), V = this.createLocalizedChildren(
|
|
651
651
|
$(e.children ?? []),
|
|
652
652
|
E,
|
|
653
653
|
[P],
|
|
@@ -663,11 +663,11 @@ class ue extends k {
|
|
|
663
663
|
b(e.name, e.path),
|
|
664
664
|
P,
|
|
665
665
|
o,
|
|
666
|
-
!!
|
|
666
|
+
!!c,
|
|
667
667
|
n
|
|
668
668
|
);
|
|
669
669
|
d.push(
|
|
670
|
-
|
|
670
|
+
g(e, {
|
|
671
671
|
path: T,
|
|
672
672
|
name: B,
|
|
673
673
|
children: V
|
|
@@ -679,7 +679,7 @@ class ue extends k {
|
|
|
679
679
|
buildChildRouteName(e, t, a) {
|
|
680
680
|
return t === !0 ? `${a.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${a.localizedRouteNamePrefix}${e}-${t}` : e;
|
|
681
681
|
}
|
|
682
|
-
createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f,
|
|
682
|
+
createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f, u) {
|
|
683
683
|
const h = this.buildRoutePathForLocales(
|
|
684
684
|
t,
|
|
685
685
|
e.path ?? "",
|
|
@@ -687,18 +687,18 @@ class ue extends k {
|
|
|
687
687
|
o,
|
|
688
688
|
r,
|
|
689
689
|
i,
|
|
690
|
-
|
|
690
|
+
u.defaultLocale.code
|
|
691
691
|
);
|
|
692
692
|
if (!h || h === e.path || t.length === 0) return null;
|
|
693
|
-
const
|
|
694
|
-
if (!
|
|
693
|
+
const c = t[0];
|
|
694
|
+
if (!c) return null;
|
|
695
695
|
const m = f ?? e.path ?? "", d = j(
|
|
696
696
|
b(e.name ?? "", m),
|
|
697
|
-
|
|
697
|
+
c,
|
|
698
698
|
o,
|
|
699
|
-
|
|
699
|
+
u.localizedRouteNamePrefix
|
|
700
700
|
);
|
|
701
|
-
return
|
|
701
|
+
return g(e, {
|
|
702
702
|
path: h,
|
|
703
703
|
name: d,
|
|
704
704
|
children: this.createLocalizedChildren(
|
|
@@ -708,8 +708,8 @@ class ue extends k {
|
|
|
708
708
|
!0,
|
|
709
709
|
!1,
|
|
710
710
|
n,
|
|
711
|
-
{ [
|
|
712
|
-
|
|
711
|
+
{ [c]: s },
|
|
712
|
+
u
|
|
713
713
|
),
|
|
714
714
|
alias: [],
|
|
715
715
|
meta: { alias: [] }
|
|
@@ -745,11 +745,11 @@ class Re {
|
|
|
745
745
|
routeLocales: i = {},
|
|
746
746
|
noPrefixRedirect: n,
|
|
747
747
|
excludePatterns: f,
|
|
748
|
-
localizedRouteNamePrefix:
|
|
748
|
+
localizedRouteNamePrefix: u = "localized-",
|
|
749
749
|
customRegexMatcher: h,
|
|
750
|
-
fallbackRedirectComponentPath:
|
|
750
|
+
fallbackRedirectComponentPath: c
|
|
751
751
|
} = e, m = X(t, a);
|
|
752
|
-
this.locales = m.locales, this.defaultLocale = m.defaultLocale, this.strategy = o, this.noPrefixRedirect = n, this.excludePatterns = f, this.localizedRouteNamePrefix =
|
|
752
|
+
this.locales = m.locales, this.defaultLocale = m.defaultLocale, this.strategy = o, this.noPrefixRedirect = n, this.excludePatterns = f, this.localizedRouteNamePrefix = u, this.customRegex = h, this.fallbackRedirectComponentPath = c, this.activeLocaleCodes = this.computeActiveLocaleCodes();
|
|
753
753
|
const d = {};
|
|
754
754
|
for (const P in s) {
|
|
755
755
|
const p = N(P), L = s[P];
|
|
@@ -819,15 +819,15 @@ class Re {
|
|
|
819
819
|
* Used by nitro:config and prerender so route rules work with custom paths (e.g. /de/ueber-uns).
|
|
820
820
|
*/
|
|
821
821
|
resolveLocalizedPath(e, t) {
|
|
822
|
-
const a = N(e), o =
|
|
822
|
+
const a = N(e), o = z(a) || "/";
|
|
823
823
|
let s;
|
|
824
824
|
const r = this.globalLocaleRoutes[o], i = this.globalLocaleRoutes[a];
|
|
825
825
|
r && typeof r == "object" && !Array.isArray(r) ? s = r[t] : i && typeof i == "object" && !Array.isArray(i) && (s = i[t]);
|
|
826
826
|
const n = !!s, f = s ? R(s) : R(a) || "";
|
|
827
|
-
let
|
|
828
|
-
if (this.strategy === "no_prefix" ?
|
|
827
|
+
let u = !1;
|
|
828
|
+
if (this.strategy === "no_prefix" ? u = !1 : this.strategy === "prefix" || this.strategy === "prefix_and_default" ? u = !0 : this.strategy === "prefix_except_default" && (u = t !== this.defaultLocale.code), t === this.defaultLocale.code && !n && (this.strategy === "prefix_except_default" || this.strategy === "no_prefix") && (u = !1), !u)
|
|
829
829
|
return R(f) || "/";
|
|
830
|
-
const h =
|
|
830
|
+
const h = z(f);
|
|
831
831
|
return h ? R(`/${t}/${h}`) : `/${t}`;
|
|
832
832
|
}
|
|
833
833
|
/**
|
|
@@ -866,6 +866,6 @@ export {
|
|
|
866
866
|
q as isPageRedirectOnly,
|
|
867
867
|
R as normalizePath,
|
|
868
868
|
N as normalizeRouteKey,
|
|
869
|
-
|
|
869
|
+
z as removeLeadingSlash,
|
|
870
870
|
H as shouldAddLocalePrefix
|
|
871
871
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/route-strategy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"description": "Locale-aware route generator for Nuxt i18n micro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@nuxt/schema": "^3.18.1 || ^4.0.0",
|
|
66
|
-
"@i18n-micro/core": "^1.3.
|
|
67
|
-
"@i18n-micro/types": "^1.2.
|
|
66
|
+
"@i18n-micro/core": "^1.3.15",
|
|
67
|
+
"@i18n-micro/types": "^1.2.12"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"publint": "^0.3.17",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"build": "vite build",
|
|
80
80
|
"check:package": "publint",
|
|
81
81
|
"test": "vitest run",
|
|
82
|
+
"typecheck": "tsc --noEmit -p tsconfig.build.json",
|
|
82
83
|
"test:dist": "vitest run --config vitest.dist.config.ts"
|
|
83
84
|
}
|
|
84
85
|
}
|