uidex 0.8.0 → 0.9.0
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/cli/cli.cjs +88 -13
- package/dist/cli/cli.cjs.map +1 -1
- package/dist/scan/index.cjs +88 -13
- package/dist/scan/index.cjs.map +1 -1
- package/dist/scan/index.d.cts +31 -4
- package/dist/scan/index.d.ts +31 -4
- package/dist/scan/index.js +88 -13
- package/dist/scan/index.js.map +1 -1
- package/package.json +17 -17
package/dist/scan/index.cjs
CHANGED
|
@@ -202,7 +202,13 @@ function validateConfig(raw) {
|
|
|
202
202
|
fail(`conventions.features must be a string or false`);
|
|
203
203
|
}
|
|
204
204
|
if (c.pages !== void 0 && c.pages !== false && c.pages !== "auto") {
|
|
205
|
-
|
|
205
|
+
const p2 = c.pages;
|
|
206
|
+
const routesDir = typeof p2 === "object" && p2 !== null && !Array.isArray(p2) ? p2.routesDir : void 0;
|
|
207
|
+
if (typeof p2 !== "object" || p2 === null || Array.isArray(p2) || Object.keys(p2).some((k) => k !== "routesDir") || typeof routesDir !== "string" || routesDir.length === 0) {
|
|
208
|
+
fail(
|
|
209
|
+
`conventions.pages must be "auto", false, or { routesDir: string }`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
206
212
|
}
|
|
207
213
|
if (c.flows !== void 0 && c.flows !== false) {
|
|
208
214
|
assertStringArray(c.flows, "conventions.flows");
|
|
@@ -1887,13 +1893,26 @@ var path4 = __toESM(require("path"), 1);
|
|
|
1887
1893
|
var PAGE_BASENAME = /^page\.(tsx|ts|jsx|js|mjs|cjs)$/;
|
|
1888
1894
|
var PAGES_ROUTER_BASENAME = /\.(tsx|ts|jsx|js|mjs|cjs)$/;
|
|
1889
1895
|
var ROUTE_BASENAME = /^route\.(tsx|ts|jsx|js|mjs|cjs)$/;
|
|
1890
|
-
function detectRoutes(files) {
|
|
1896
|
+
function detectRoutes(files, options = {}) {
|
|
1891
1897
|
const out2 = [];
|
|
1892
1898
|
const seen = /* @__PURE__ */ new Set();
|
|
1899
|
+
const routesDir = options.routesDir ? options.routesDir.replace(/^\.?\/+/, "").replace(/\/+$/, "") : null;
|
|
1900
|
+
const routesDirParts = routesDir ? routesDir.split("/") : null;
|
|
1893
1901
|
for (const f of files) {
|
|
1894
1902
|
const rel = f.displayPath;
|
|
1895
1903
|
const parts = rel.split("/");
|
|
1896
1904
|
const base = parts[parts.length - 1];
|
|
1905
|
+
if (routesDirParts) {
|
|
1906
|
+
const end = dirEndIndex(parts, routesDirParts);
|
|
1907
|
+
if (end === -1 || end > parts.length - 1) continue;
|
|
1908
|
+
if (!PAGES_ROUTER_BASENAME.test(base)) continue;
|
|
1909
|
+
const routePath = routesStylePath(
|
|
1910
|
+
parts.slice(end, parts.length - 1),
|
|
1911
|
+
base
|
|
1912
|
+
);
|
|
1913
|
+
if (routePath !== null) push(out2, seen, routePath, f.displayPath);
|
|
1914
|
+
continue;
|
|
1915
|
+
}
|
|
1897
1916
|
const appIdx = parts.indexOf("app");
|
|
1898
1917
|
if (appIdx !== -1 && PAGE_BASENAME.test(base)) {
|
|
1899
1918
|
const routeSegments = parts.slice(appIdx + 1, parts.length - 1);
|
|
@@ -1920,15 +1939,11 @@ function detectRoutes(files) {
|
|
|
1920
1939
|
}
|
|
1921
1940
|
const routesIdx = parts.indexOf("routes");
|
|
1922
1941
|
if (routesIdx !== -1 && PAGES_ROUTER_BASENAME.test(base)) {
|
|
1923
|
-
const
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
base.replace(/\.[^.]+$/, "")
|
|
1929
|
-
].filter((s) => s !== "index" && s !== "__root");
|
|
1930
|
-
const routePath = formatNextAppPath(normalized);
|
|
1931
|
-
push(out2, seen, routePath, f.displayPath);
|
|
1942
|
+
const routePath = routesStylePath(
|
|
1943
|
+
parts.slice(routesIdx + 1, parts.length - 1),
|
|
1944
|
+
base
|
|
1945
|
+
);
|
|
1946
|
+
if (routePath !== null) push(out2, seen, routePath, f.displayPath);
|
|
1932
1947
|
continue;
|
|
1933
1948
|
}
|
|
1934
1949
|
}
|
|
@@ -1944,6 +1959,63 @@ function formatNextAppPath(segments) {
|
|
|
1944
1959
|
if (kept.length === 0) return "/";
|
|
1945
1960
|
return "/" + kept.join("/");
|
|
1946
1961
|
}
|
|
1962
|
+
function dirEndIndex(parts, dirParts) {
|
|
1963
|
+
if (dirParts.length === 0) return 0;
|
|
1964
|
+
for (let i = 0; i + dirParts.length <= parts.length; i++) {
|
|
1965
|
+
let match = true;
|
|
1966
|
+
for (let j = 0; j < dirParts.length; j++) {
|
|
1967
|
+
if (parts[i + j] !== dirParts[j]) {
|
|
1968
|
+
match = false;
|
|
1969
|
+
break;
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
if (match) return i + dirParts.length;
|
|
1973
|
+
}
|
|
1974
|
+
return -1;
|
|
1975
|
+
}
|
|
1976
|
+
function routesStylePath(dirSegs, base) {
|
|
1977
|
+
const fileSegs = splitFlatSegments(base.replace(/\.[^.]+$/, ""));
|
|
1978
|
+
const leaf = fileSegs[fileSegs.length - 1];
|
|
1979
|
+
if (leaf.startsWith("_")) return null;
|
|
1980
|
+
const rawSegs = [...dirSegs, ...fileSegs];
|
|
1981
|
+
if (rawSegs.some((s) => s.startsWith("-"))) return null;
|
|
1982
|
+
if (rawSegs[0] === "api") return null;
|
|
1983
|
+
return formatTanStackPath(rawSegs);
|
|
1984
|
+
}
|
|
1985
|
+
function splitFlatSegments(name) {
|
|
1986
|
+
const segs = [];
|
|
1987
|
+
let cur = "";
|
|
1988
|
+
let depth = 0;
|
|
1989
|
+
for (const ch of name) {
|
|
1990
|
+
if (ch === "[") depth++;
|
|
1991
|
+
else if (ch === "]") depth = Math.max(0, depth - 1);
|
|
1992
|
+
if (ch === "." && depth === 0) {
|
|
1993
|
+
segs.push(cur);
|
|
1994
|
+
cur = "";
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
cur += ch;
|
|
1998
|
+
}
|
|
1999
|
+
segs.push(cur);
|
|
2000
|
+
return segs;
|
|
2001
|
+
}
|
|
2002
|
+
function formatTanStackPath(segments) {
|
|
2003
|
+
const kept = [];
|
|
2004
|
+
for (const seg of segments) {
|
|
2005
|
+
if (!seg) continue;
|
|
2006
|
+
if (seg === "index" || seg === "route" || seg === "__root") continue;
|
|
2007
|
+
if (seg.startsWith("_")) continue;
|
|
2008
|
+
if (seg.startsWith("(") && seg.endsWith(")")) continue;
|
|
2009
|
+
kept.push(normalizeTanStackSegment(seg.replace(/_$/, "")));
|
|
2010
|
+
}
|
|
2011
|
+
if (kept.length === 0) return "/";
|
|
2012
|
+
return "/" + kept.join("/");
|
|
2013
|
+
}
|
|
2014
|
+
function normalizeTanStackSegment(seg) {
|
|
2015
|
+
if (seg === "$") return "[...splat]";
|
|
2016
|
+
if (seg.startsWith("$")) return `[${seg.slice(1)}]`;
|
|
2017
|
+
return seg.replace(/\[([^\]]*)\]/g, "$1");
|
|
2018
|
+
}
|
|
1947
2019
|
function pathToId(routePath) {
|
|
1948
2020
|
if (routePath === "/") return "root";
|
|
1949
2021
|
return routePath.replace(/^\/+/, "").replace(/\[\.{3}([^\]]+)\]/g, "$1").replace(/\[([^\]]+)\]/g, "$1").replace(/\//g, "-").replace(/[^a-zA-Z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
@@ -2039,9 +2111,12 @@ function resolve2(ctx) {
|
|
|
2039
2111
|
function metaWithComposes(kind, id, base) {
|
|
2040
2112
|
const composes = directChildren.get(`${kind}:${id}`);
|
|
2041
2113
|
if (!composes || composes.length === 0) return base;
|
|
2042
|
-
return { ...base
|
|
2114
|
+
return { ...base, composes };
|
|
2043
2115
|
}
|
|
2044
|
-
const routes = conventions.pages ===
|
|
2116
|
+
const routes = conventions.pages === false ? [] : detectRoutes(
|
|
2117
|
+
ctx.extracted.map((e) => e.file),
|
|
2118
|
+
conventions.pages === "auto" ? {} : { routesDir: conventions.pages.routesDir }
|
|
2119
|
+
);
|
|
2045
2120
|
const handledPageFiles = /* @__PURE__ */ new Set();
|
|
2046
2121
|
for (const route of routes) {
|
|
2047
2122
|
const routeDir = path4.posix.dirname(route.file);
|