@decantr/verifier 3.5.4 → 3.5.5
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.js +77 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2365,6 +2365,15 @@ var ROUTE_VARIABLE_NAMES = "(?:path|pathname|route|currentPath|currentRoute|loca
|
|
|
2365
2365
|
var ROUTE_ASSET_EXTENSION_RE = /\.(?:avif|bmp|css|gif|ico|jpeg|jpg|js|json|map|mp4|pdf|png|svg|webp|woff2?)$/i;
|
|
2366
2366
|
var JSX_ROUTE_PATH_RE = /<(?:Route|[A-Z][\w.]*Route)\b[^>]*\bpath\s*=\s*(?:"([^"]+)"|'([^']+)'|{\s*"([^"]+)"\s*}|{\s*'([^']+)'\s*}|{\s*`([^`]+)`\s*})/g;
|
|
2367
2367
|
var OBJECT_ROUTE_PATH_RE = /\bpath\s*:\s*(?:"([^"]+)"|'([^']+)'|`([^`]+)`)/g;
|
|
2368
|
+
var STATIC_HTML_ENTRY_FILES = [
|
|
2369
|
+
"index.html",
|
|
2370
|
+
"docs/index.html",
|
|
2371
|
+
"src/index.html",
|
|
2372
|
+
"public/index.html",
|
|
2373
|
+
"dist/index.html"
|
|
2374
|
+
];
|
|
2375
|
+
var STATIC_HTML_ROUTE_DIRS = ["demos", "examples"];
|
|
2376
|
+
var MAX_STATIC_HTML_CANDIDATES = 1e3;
|
|
2368
2377
|
var MAX_FILE_READ_BYTES = 512 * 1024;
|
|
2369
2378
|
var MAX_WALK_FILES = 5e3;
|
|
2370
2379
|
var MAX_REPORT_ROUTES = 80;
|
|
@@ -2462,6 +2471,10 @@ function dependencyVersion(dependencies, names) {
|
|
|
2462
2471
|
function hasAnyFile(projectRoot, paths) {
|
|
2463
2472
|
return paths.some((path) => existsSync3(join3(projectRoot, path)));
|
|
2464
2473
|
}
|
|
2474
|
+
function hasStaticHtmlSurface(projectRoot) {
|
|
2475
|
+
if (hasAnyFile(projectRoot, STATIC_HTML_ENTRY_FILES)) return true;
|
|
2476
|
+
return STATIC_HTML_ROUTE_DIRS.some((dir) => existsSync3(join3(projectRoot, dir, "index.html")));
|
|
2477
|
+
}
|
|
2465
2478
|
function detectPackageManager(projectRoot, pkg) {
|
|
2466
2479
|
const declared = pkg?.packageManager?.split("@")[0];
|
|
2467
2480
|
if (declared === "npm" || declared === "pnpm" || declared === "yarn" || declared === "bun") {
|
|
@@ -2474,12 +2487,12 @@ function detectPackageManager(projectRoot, pkg) {
|
|
|
2474
2487
|
return "unknown";
|
|
2475
2488
|
}
|
|
2476
2489
|
function detectPrimaryLanguage(projectRoot, packageJsonPresent) {
|
|
2477
|
-
if (packageJsonPresent) return "javascript";
|
|
2490
|
+
if (packageJsonPresent) return hasStaticHtmlSurface(projectRoot) ? "html" : "javascript";
|
|
2478
2491
|
if (hasAnyFile(projectRoot, ["pyproject.toml", "requirements.txt", "setup.py", "Pipfile"]))
|
|
2479
2492
|
return "python";
|
|
2480
2493
|
if (hasAnyFile(projectRoot, ["go.mod"])) return "go";
|
|
2481
2494
|
if (hasAnyFile(projectRoot, ["Cargo.toml"])) return "rust";
|
|
2482
|
-
if (
|
|
2495
|
+
if (hasStaticHtmlSurface(projectRoot)) return "html";
|
|
2483
2496
|
return "unknown";
|
|
2484
2497
|
}
|
|
2485
2498
|
function detectProject(projectRoot) {
|
|
@@ -2512,7 +2525,7 @@ function detectProject(projectRoot) {
|
|
|
2512
2525
|
} else if (dependencies.react) {
|
|
2513
2526
|
framework = "react";
|
|
2514
2527
|
frameworkVersion = dependencyVersion(dependencies, ["react"]);
|
|
2515
|
-
} else if (
|
|
2528
|
+
} else if (hasStaticHtmlSurface(projectRoot)) {
|
|
2516
2529
|
framework = "html";
|
|
2517
2530
|
}
|
|
2518
2531
|
return {
|
|
@@ -2701,6 +2714,65 @@ function collectRouteLiterals(pattern, content, routes) {
|
|
|
2701
2714
|
}
|
|
2702
2715
|
return count;
|
|
2703
2716
|
}
|
|
2717
|
+
function htmlRouteFromFile(file) {
|
|
2718
|
+
let withoutExt = file.slice(0, -extname3(file).length).replace(/\\/g, "/");
|
|
2719
|
+
if (withoutExt.endsWith("/index")) withoutExt = withoutExt.slice(0, -"/index".length);
|
|
2720
|
+
if (withoutExt === "index" || withoutExt === "docs" || withoutExt === "src" || withoutExt === "public" || withoutExt === "dist") {
|
|
2721
|
+
return "/";
|
|
2722
|
+
}
|
|
2723
|
+
return `/${withoutExt.split("/").filter(Boolean).join("/")}` || "/";
|
|
2724
|
+
}
|
|
2725
|
+
function collectStaticHtmlFiles(dir, projectRoot, files, depth = 0) {
|
|
2726
|
+
if (depth > 5 || files.length >= MAX_STATIC_HTML_CANDIDATES) return;
|
|
2727
|
+
let entries;
|
|
2728
|
+
try {
|
|
2729
|
+
entries = readdirSync3(dir).sort();
|
|
2730
|
+
} catch {
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
for (const entry of entries) {
|
|
2734
|
+
if (files.length >= MAX_STATIC_HTML_CANDIDATES) return;
|
|
2735
|
+
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
2736
|
+
const fullPath = join3(dir, entry);
|
|
2737
|
+
try {
|
|
2738
|
+
const stat = statSync2(fullPath);
|
|
2739
|
+
if (stat.isDirectory()) {
|
|
2740
|
+
collectStaticHtmlFiles(fullPath, projectRoot, files, depth + 1);
|
|
2741
|
+
} else if (stat.isFile() && /\.(?:html|htm)$/i.test(entry)) {
|
|
2742
|
+
files.push(relative3(projectRoot, fullPath).replace(/\\/g, "/"));
|
|
2743
|
+
}
|
|
2744
|
+
} catch {
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
function staticHtmlFilePriority(file) {
|
|
2749
|
+
const base = file.split("/").pop()?.toLowerCase();
|
|
2750
|
+
if (base === "index.html" || base === "index.htm") return 0;
|
|
2751
|
+
if (base === "default.html" || base === "default.htm") return 1;
|
|
2752
|
+
return 2;
|
|
2753
|
+
}
|
|
2754
|
+
function scanStaticHtmlRoutes(projectRoot) {
|
|
2755
|
+
const routes = /* @__PURE__ */ new Map();
|
|
2756
|
+
for (const file of STATIC_HTML_ENTRY_FILES) {
|
|
2757
|
+
if (!existsSync3(join3(projectRoot, file))) continue;
|
|
2758
|
+
routes.set("/", { path: "/", file, hasLayout: false });
|
|
2759
|
+
break;
|
|
2760
|
+
}
|
|
2761
|
+
for (const dir of STATIC_HTML_ROUTE_DIRS) {
|
|
2762
|
+
const fullDir = join3(projectRoot, dir);
|
|
2763
|
+
if (!existsSync3(fullDir)) continue;
|
|
2764
|
+
const files = [];
|
|
2765
|
+
collectStaticHtmlFiles(fullDir, projectRoot, files);
|
|
2766
|
+
for (const file of files.sort(
|
|
2767
|
+
(a, b) => staticHtmlFilePriority(a) - staticHtmlFilePriority(b) || a.localeCompare(b)
|
|
2768
|
+
)) {
|
|
2769
|
+
const routePath = htmlRouteFromFile(file);
|
|
2770
|
+
if (routes.has(routePath)) continue;
|
|
2771
|
+
routes.set(routePath, { path: routePath, file, hasLayout: false });
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
return [...routes.values()].slice(0, MAX_REPORT_ROUTES);
|
|
2775
|
+
}
|
|
2704
2776
|
function detectPathnameBranchRoutes(content) {
|
|
2705
2777
|
const routes = /* @__PURE__ */ new Set();
|
|
2706
2778
|
const comparison = new RegExp(
|
|
@@ -2760,18 +2832,8 @@ function scanRoutes(projectRoot, detection) {
|
|
|
2760
2832
|
if (reactRouter.routes.length > 0)
|
|
2761
2833
|
return { strategy: "react-router", routes: reactRouter.routes };
|
|
2762
2834
|
if (pagesRoutes.length > 0) return { strategy: "pages-router", routes: pagesRoutes };
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
strategy: "static-html",
|
|
2766
|
-
routes: [{ path: "/", file: "index.html", hasLayout: false }]
|
|
2767
|
-
};
|
|
2768
|
-
}
|
|
2769
|
-
if (existsSync3(join3(projectRoot, "docs", "index.html"))) {
|
|
2770
|
-
return {
|
|
2771
|
-
strategy: "static-html",
|
|
2772
|
-
routes: [{ path: "/", file: "docs/index.html", hasLayout: false }]
|
|
2773
|
-
};
|
|
2774
|
-
}
|
|
2835
|
+
const staticHtmlRoutes = scanStaticHtmlRoutes(projectRoot);
|
|
2836
|
+
if (staticHtmlRoutes.length > 0) return { strategy: "static-html", routes: staticHtmlRoutes };
|
|
2775
2837
|
return { strategy: "none", routes: [] };
|
|
2776
2838
|
}
|
|
2777
2839
|
function countComponents(projectRoot, routes) {
|