@blazediff/agent 0.5.0 → 0.6.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.js +199 -199
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +64 -85
- package/dist/index.mjs +64 -85
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -151,7 +151,7 @@ interface CaptureOptions {
|
|
|
151
151
|
}
|
|
152
152
|
interface DiscoveredRoute {
|
|
153
153
|
url: string;
|
|
154
|
-
source: "
|
|
154
|
+
source: "crawl";
|
|
155
155
|
auth?: string;
|
|
156
156
|
}
|
|
157
157
|
interface CheckReport {
|
|
@@ -271,11 +271,16 @@ interface DiffOutcome {
|
|
|
271
271
|
}
|
|
272
272
|
declare function diffEntry(id: string, baselinePath: string, actualPath: string, opts?: DiffOptions, cwd?: string): Promise<DiffOutcome>;
|
|
273
273
|
|
|
274
|
+
interface TemplateSampling {
|
|
275
|
+
threshold: number;
|
|
276
|
+
samples: number;
|
|
277
|
+
}
|
|
278
|
+
|
|
274
279
|
interface DiscoverOptions {
|
|
275
280
|
baseUrl: string;
|
|
276
281
|
cwd?: string;
|
|
277
282
|
maxRoutes?: number;
|
|
278
|
-
|
|
283
|
+
sampleTemplates?: boolean | TemplateSampling;
|
|
279
284
|
}
|
|
280
285
|
declare function discover(opts: DiscoverOptions): Promise<DiscoveredRoute[]>;
|
|
281
286
|
|
package/dist/index.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ interface CaptureOptions {
|
|
|
151
151
|
}
|
|
152
152
|
interface DiscoveredRoute {
|
|
153
153
|
url: string;
|
|
154
|
-
source: "
|
|
154
|
+
source: "crawl";
|
|
155
155
|
auth?: string;
|
|
156
156
|
}
|
|
157
157
|
interface CheckReport {
|
|
@@ -271,11 +271,16 @@ interface DiffOutcome {
|
|
|
271
271
|
}
|
|
272
272
|
declare function diffEntry(id: string, baselinePath: string, actualPath: string, opts?: DiffOptions, cwd?: string): Promise<DiffOutcome>;
|
|
273
273
|
|
|
274
|
+
interface TemplateSampling {
|
|
275
|
+
threshold: number;
|
|
276
|
+
samples: number;
|
|
277
|
+
}
|
|
278
|
+
|
|
274
279
|
interface DiscoverOptions {
|
|
275
280
|
baseUrl: string;
|
|
276
281
|
cwd?: string;
|
|
277
282
|
maxRoutes?: number;
|
|
278
|
-
|
|
283
|
+
sampleTemplates?: boolean | TemplateSampling;
|
|
279
284
|
}
|
|
280
285
|
declare function discover(opts: DiscoverOptions): Promise<DiscoveredRoute[]>;
|
|
281
286
|
|
package/dist/index.js
CHANGED
|
@@ -878,9 +878,9 @@ function extractInternalLinks(base, target, hrefs) {
|
|
|
878
878
|
try {
|
|
879
879
|
const u = new URL(href, target);
|
|
880
880
|
if (u.origin !== base.origin) continue;
|
|
881
|
-
const
|
|
882
|
-
if (
|
|
883
|
-
out.push(
|
|
881
|
+
const path22 = u.pathname + u.search;
|
|
882
|
+
if (path22.startsWith("/api/")) continue;
|
|
883
|
+
out.push(path22);
|
|
884
884
|
} catch {
|
|
885
885
|
}
|
|
886
886
|
}
|
|
@@ -910,6 +910,8 @@ async function crawlRoutes(opts) {
|
|
|
910
910
|
waitUntil: "domcontentloaded",
|
|
911
911
|
timeout: 15e3
|
|
912
912
|
});
|
|
913
|
+
await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
|
|
914
|
+
});
|
|
913
915
|
const hrefs = await page.evaluate(
|
|
914
916
|
() => Array.from(
|
|
915
917
|
document.querySelectorAll("a[href]")
|
|
@@ -934,74 +936,38 @@ async function crawlRoutes(opts) {
|
|
|
934
936
|
}
|
|
935
937
|
return discovered.slice(0, maxRoutes);
|
|
936
938
|
}
|
|
937
|
-
async function fileExists2(p) {
|
|
938
|
-
try {
|
|
939
|
-
await promises.access(p);
|
|
940
|
-
return true;
|
|
941
|
-
} catch {
|
|
942
|
-
return false;
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
async function readJsonOrNull(file) {
|
|
946
|
-
try {
|
|
947
|
-
return JSON.parse(await promises.readFile(file, "utf8"));
|
|
948
|
-
} catch {
|
|
949
|
-
return null;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
// src/discover/next.ts
|
|
954
|
-
var DYNAMIC_SEGMENT = /\[[^\]]+\]/;
|
|
955
|
-
function isPublicRoute(route) {
|
|
956
|
-
if (DYNAMIC_SEGMENT.test(route)) return false;
|
|
957
|
-
if (route === "/api" || route.startsWith("/api/")) return false;
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
async function discoverFromNextManifest(cwd = process.cwd()) {
|
|
961
|
-
const nextDir = path__default.default.join(cwd, ".next");
|
|
962
|
-
if (!fs.existsSync(nextDir)) return [];
|
|
963
|
-
const seen = /* @__PURE__ */ new Set();
|
|
964
|
-
const out = [];
|
|
965
|
-
const add = (url) => {
|
|
966
|
-
if (seen.has(url)) return;
|
|
967
|
-
seen.add(url);
|
|
968
|
-
out.push({ url, source: "next-manifest" });
|
|
969
|
-
};
|
|
970
|
-
const routes = await readJsonOrNull(
|
|
971
|
-
path__default.default.join(nextDir, "routes-manifest.json")
|
|
972
|
-
);
|
|
973
|
-
for (const r of routes?.staticRoutes ?? []) {
|
|
974
|
-
if (isPublicRoute(r.page)) add(r.page);
|
|
975
|
-
}
|
|
976
|
-
const appPaths = await readJsonOrNull(
|
|
977
|
-
path__default.default.join(nextDir, "server", "app-paths-manifest.json")
|
|
978
|
-
);
|
|
979
|
-
for (const route of Object.keys(appPaths ?? {})) {
|
|
980
|
-
const normalized = route.replace(/\/page$/, "") || "/";
|
|
981
|
-
if (isPublicRoute(normalized)) add(normalized);
|
|
982
|
-
}
|
|
983
|
-
return out;
|
|
984
|
-
}
|
|
985
939
|
|
|
986
|
-
// src/discover/
|
|
987
|
-
var
|
|
988
|
-
var
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
940
|
+
// src/discover/templates.ts
|
|
941
|
+
var DEFAULT_SAMPLE_THRESHOLD = 5;
|
|
942
|
+
var DEFAULT_SAMPLES_PER_TEMPLATE = 2;
|
|
943
|
+
var DEFAULT_SAMPLING = {
|
|
944
|
+
threshold: DEFAULT_SAMPLE_THRESHOLD,
|
|
945
|
+
samples: DEFAULT_SAMPLES_PER_TEMPLATE
|
|
946
|
+
};
|
|
947
|
+
function parentPath(path22) {
|
|
948
|
+
const [pathPart] = path22.split("?", 2);
|
|
949
|
+
const idx = pathPart.lastIndexOf("/");
|
|
950
|
+
return idx <= 0 ? "/" : pathPart.slice(0, idx);
|
|
951
|
+
}
|
|
952
|
+
function collapseTemplates(routes, { threshold, samples } = DEFAULT_SAMPLING) {
|
|
953
|
+
const groups = /* @__PURE__ */ new Map();
|
|
954
|
+
for (const route of routes) {
|
|
955
|
+
const parent = parentPath(route.url);
|
|
956
|
+
const group = groups.get(parent);
|
|
957
|
+
if (group) group.push(route);
|
|
958
|
+
else groups.set(parent, [route]);
|
|
959
|
+
}
|
|
960
|
+
const drop = /* @__PURE__ */ new Set();
|
|
961
|
+
const collapsed = [];
|
|
962
|
+
for (const [parent, group] of groups) {
|
|
963
|
+
if (parent === "/" || group.length < threshold) continue;
|
|
964
|
+
for (const route of group.slice(samples)) drop.add(route.url);
|
|
965
|
+
collapsed.push(`${parent}/* (${group.length} \u2192 ${samples})`);
|
|
1003
966
|
}
|
|
1004
|
-
return
|
|
967
|
+
return {
|
|
968
|
+
routes: drop.size ? routes.filter((r) => !drop.has(r.url)) : routes,
|
|
969
|
+
collapsed
|
|
970
|
+
};
|
|
1005
971
|
}
|
|
1006
972
|
|
|
1007
973
|
// src/discover/index.ts
|
|
@@ -1011,27 +977,23 @@ function normalizePath(url) {
|
|
|
1011
977
|
const normalizedPath = trimmed === "" ? "/" : trimmed;
|
|
1012
978
|
return query ? `${normalizedPath}?${query}` : normalizedPath;
|
|
1013
979
|
}
|
|
1014
|
-
function
|
|
980
|
+
function dedupe(routes) {
|
|
981
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1015
982
|
for (const r of routes) {
|
|
1016
983
|
const key = normalizePath(r.url);
|
|
1017
|
-
if (!
|
|
984
|
+
if (!merged.has(key)) merged.set(key, { ...r, url: key });
|
|
1018
985
|
}
|
|
986
|
+
return Array.from(merged.values());
|
|
1019
987
|
}
|
|
1020
988
|
async function discover(opts) {
|
|
1021
|
-
const
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
await crawlRoutes({ baseUrl: opts.baseUrl, maxRoutes: crawlMax }),
|
|
1030
|
-
merged
|
|
1031
|
-
);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
return Array.from(merged.values()).sort((a, b) => a.url.localeCompare(b.url));
|
|
989
|
+
const crawled = await crawlRoutes({
|
|
990
|
+
baseUrl: opts.baseUrl,
|
|
991
|
+
maxRoutes: opts.maxRoutes ?? 50
|
|
992
|
+
});
|
|
993
|
+
const deduped = dedupe(crawled);
|
|
994
|
+
const sampling = opts.sampleTemplates ?? true;
|
|
995
|
+
const routes = sampling === false ? deduped : collapseTemplates(deduped, sampling === true ? void 0 : sampling).routes;
|
|
996
|
+
return routes.sort((a, b) => a.url.localeCompare(b.url));
|
|
1035
997
|
}
|
|
1036
998
|
function envFiles(cwd) {
|
|
1037
999
|
const root = paths(cwd).root;
|
|
@@ -1909,6 +1871,23 @@ var noneJudge = {
|
|
|
1909
1871
|
return { kind: "judged", verdict: input.heuristicVerdict };
|
|
1910
1872
|
}
|
|
1911
1873
|
};
|
|
1874
|
+
async function fileExists2(p) {
|
|
1875
|
+
try {
|
|
1876
|
+
await promises.access(p);
|
|
1877
|
+
return true;
|
|
1878
|
+
} catch {
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
async function readJsonOrNull(file) {
|
|
1883
|
+
try {
|
|
1884
|
+
return JSON.parse(await promises.readFile(file, "utf8"));
|
|
1885
|
+
} catch {
|
|
1886
|
+
return null;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
// src/report/json.ts
|
|
1912
1891
|
async function writeReport(report, cwd = process.cwd()) {
|
|
1913
1892
|
const file = paths(cwd).report;
|
|
1914
1893
|
await promises.mkdir(path__default.default.dirname(file), { recursive: true });
|
package/dist/index.mjs
CHANGED
|
@@ -850,9 +850,9 @@ function extractInternalLinks(base, target, hrefs) {
|
|
|
850
850
|
try {
|
|
851
851
|
const u = new URL(href, target);
|
|
852
852
|
if (u.origin !== base.origin) continue;
|
|
853
|
-
const
|
|
854
|
-
if (
|
|
855
|
-
out.push(
|
|
853
|
+
const path22 = u.pathname + u.search;
|
|
854
|
+
if (path22.startsWith("/api/")) continue;
|
|
855
|
+
out.push(path22);
|
|
856
856
|
} catch {
|
|
857
857
|
}
|
|
858
858
|
}
|
|
@@ -882,6 +882,8 @@ async function crawlRoutes(opts) {
|
|
|
882
882
|
waitUntil: "domcontentloaded",
|
|
883
883
|
timeout: 15e3
|
|
884
884
|
});
|
|
885
|
+
await page.waitForLoadState("networkidle", { timeout: 5e3 }).catch(() => {
|
|
886
|
+
});
|
|
885
887
|
const hrefs = await page.evaluate(
|
|
886
888
|
() => Array.from(
|
|
887
889
|
document.querySelectorAll("a[href]")
|
|
@@ -906,74 +908,38 @@ async function crawlRoutes(opts) {
|
|
|
906
908
|
}
|
|
907
909
|
return discovered.slice(0, maxRoutes);
|
|
908
910
|
}
|
|
909
|
-
async function fileExists2(p) {
|
|
910
|
-
try {
|
|
911
|
-
await access(p);
|
|
912
|
-
return true;
|
|
913
|
-
} catch {
|
|
914
|
-
return false;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
async function readJsonOrNull(file) {
|
|
918
|
-
try {
|
|
919
|
-
return JSON.parse(await readFile(file, "utf8"));
|
|
920
|
-
} catch {
|
|
921
|
-
return null;
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
// src/discover/next.ts
|
|
926
|
-
var DYNAMIC_SEGMENT = /\[[^\]]+\]/;
|
|
927
|
-
function isPublicRoute(route) {
|
|
928
|
-
if (DYNAMIC_SEGMENT.test(route)) return false;
|
|
929
|
-
if (route === "/api" || route.startsWith("/api/")) return false;
|
|
930
|
-
return true;
|
|
931
|
-
}
|
|
932
|
-
async function discoverFromNextManifest(cwd = process.cwd()) {
|
|
933
|
-
const nextDir = path.join(cwd, ".next");
|
|
934
|
-
if (!existsSync(nextDir)) return [];
|
|
935
|
-
const seen = /* @__PURE__ */ new Set();
|
|
936
|
-
const out = [];
|
|
937
|
-
const add = (url) => {
|
|
938
|
-
if (seen.has(url)) return;
|
|
939
|
-
seen.add(url);
|
|
940
|
-
out.push({ url, source: "next-manifest" });
|
|
941
|
-
};
|
|
942
|
-
const routes = await readJsonOrNull(
|
|
943
|
-
path.join(nextDir, "routes-manifest.json")
|
|
944
|
-
);
|
|
945
|
-
for (const r of routes?.staticRoutes ?? []) {
|
|
946
|
-
if (isPublicRoute(r.page)) add(r.page);
|
|
947
|
-
}
|
|
948
|
-
const appPaths = await readJsonOrNull(
|
|
949
|
-
path.join(nextDir, "server", "app-paths-manifest.json")
|
|
950
|
-
);
|
|
951
|
-
for (const route of Object.keys(appPaths ?? {})) {
|
|
952
|
-
const normalized = route.replace(/\/page$/, "") || "/";
|
|
953
|
-
if (isPublicRoute(normalized)) add(normalized);
|
|
954
|
-
}
|
|
955
|
-
return out;
|
|
956
|
-
}
|
|
957
911
|
|
|
958
|
-
// src/discover/
|
|
959
|
-
var
|
|
960
|
-
var
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
912
|
+
// src/discover/templates.ts
|
|
913
|
+
var DEFAULT_SAMPLE_THRESHOLD = 5;
|
|
914
|
+
var DEFAULT_SAMPLES_PER_TEMPLATE = 2;
|
|
915
|
+
var DEFAULT_SAMPLING = {
|
|
916
|
+
threshold: DEFAULT_SAMPLE_THRESHOLD,
|
|
917
|
+
samples: DEFAULT_SAMPLES_PER_TEMPLATE
|
|
918
|
+
};
|
|
919
|
+
function parentPath(path22) {
|
|
920
|
+
const [pathPart] = path22.split("?", 2);
|
|
921
|
+
const idx = pathPart.lastIndexOf("/");
|
|
922
|
+
return idx <= 0 ? "/" : pathPart.slice(0, idx);
|
|
923
|
+
}
|
|
924
|
+
function collapseTemplates(routes, { threshold, samples } = DEFAULT_SAMPLING) {
|
|
925
|
+
const groups = /* @__PURE__ */ new Map();
|
|
926
|
+
for (const route of routes) {
|
|
927
|
+
const parent = parentPath(route.url);
|
|
928
|
+
const group = groups.get(parent);
|
|
929
|
+
if (group) group.push(route);
|
|
930
|
+
else groups.set(parent, [route]);
|
|
931
|
+
}
|
|
932
|
+
const drop = /* @__PURE__ */ new Set();
|
|
933
|
+
const collapsed = [];
|
|
934
|
+
for (const [parent, group] of groups) {
|
|
935
|
+
if (parent === "/" || group.length < threshold) continue;
|
|
936
|
+
for (const route of group.slice(samples)) drop.add(route.url);
|
|
937
|
+
collapsed.push(`${parent}/* (${group.length} \u2192 ${samples})`);
|
|
975
938
|
}
|
|
976
|
-
return
|
|
939
|
+
return {
|
|
940
|
+
routes: drop.size ? routes.filter((r) => !drop.has(r.url)) : routes,
|
|
941
|
+
collapsed
|
|
942
|
+
};
|
|
977
943
|
}
|
|
978
944
|
|
|
979
945
|
// src/discover/index.ts
|
|
@@ -983,27 +949,23 @@ function normalizePath(url) {
|
|
|
983
949
|
const normalizedPath = trimmed === "" ? "/" : trimmed;
|
|
984
950
|
return query ? `${normalizedPath}?${query}` : normalizedPath;
|
|
985
951
|
}
|
|
986
|
-
function
|
|
952
|
+
function dedupe(routes) {
|
|
953
|
+
const merged = /* @__PURE__ */ new Map();
|
|
987
954
|
for (const r of routes) {
|
|
988
955
|
const key = normalizePath(r.url);
|
|
989
|
-
if (!
|
|
956
|
+
if (!merged.has(key)) merged.set(key, { ...r, url: key });
|
|
990
957
|
}
|
|
958
|
+
return Array.from(merged.values());
|
|
991
959
|
}
|
|
992
960
|
async function discover(opts) {
|
|
993
|
-
const
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
await crawlRoutes({ baseUrl: opts.baseUrl, maxRoutes: crawlMax }),
|
|
1002
|
-
merged
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
return Array.from(merged.values()).sort((a, b) => a.url.localeCompare(b.url));
|
|
961
|
+
const crawled = await crawlRoutes({
|
|
962
|
+
baseUrl: opts.baseUrl,
|
|
963
|
+
maxRoutes: opts.maxRoutes ?? 50
|
|
964
|
+
});
|
|
965
|
+
const deduped = dedupe(crawled);
|
|
966
|
+
const sampling = opts.sampleTemplates ?? true;
|
|
967
|
+
const routes = sampling === false ? deduped : collapseTemplates(deduped, sampling === true ? void 0 : sampling).routes;
|
|
968
|
+
return routes.sort((a, b) => a.url.localeCompare(b.url));
|
|
1007
969
|
}
|
|
1008
970
|
function envFiles(cwd) {
|
|
1009
971
|
const root = paths(cwd).root;
|
|
@@ -1881,6 +1843,23 @@ var noneJudge = {
|
|
|
1881
1843
|
return { kind: "judged", verdict: input.heuristicVerdict };
|
|
1882
1844
|
}
|
|
1883
1845
|
};
|
|
1846
|
+
async function fileExists2(p) {
|
|
1847
|
+
try {
|
|
1848
|
+
await access(p);
|
|
1849
|
+
return true;
|
|
1850
|
+
} catch {
|
|
1851
|
+
return false;
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
async function readJsonOrNull(file) {
|
|
1855
|
+
try {
|
|
1856
|
+
return JSON.parse(await readFile(file, "utf8"));
|
|
1857
|
+
} catch {
|
|
1858
|
+
return null;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1862
|
+
// src/report/json.ts
|
|
1884
1863
|
async function writeReport(report, cwd = process.cwd()) {
|
|
1885
1864
|
const file = paths(cwd).report;
|
|
1886
1865
|
await mkdir(path.dirname(file), { recursive: true });
|
package/package.json
CHANGED