prerender-crawler 0.1.0 → 0.2.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/README.md +152 -35
- package/dist/announce.d.ts +39 -0
- package/dist/announce.js +41 -0
- package/dist/cli-main.d.ts +7 -0
- package/dist/cli-main.js +181 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +6 -0
- package/dist/crawl.js +150 -60
- package/dist/index.d.ts +13 -2
- package/dist/index.js +6 -1
- package/dist/links.d.ts +25 -9
- package/dist/links.js +33 -11
- package/dist/redirects.d.ts +33 -0
- package/dist/redirects.js +33 -0
- package/dist/report.d.ts +55 -0
- package/dist/report.js +46 -0
- package/dist/sitemap.d.ts +56 -0
- package/dist/sitemap.js +88 -0
- package/dist/transports.d.ts +35 -0
- package/dist/transports.js +74 -0
- package/dist/types.d.ts +69 -3
- package/dist/vite.d.ts +10 -18
- package/dist/vite.js +29 -70
- package/package.json +8 -6
- package/dist/file-routes.d.ts +0 -35
- package/dist/file-routes.js +0 -84
package/dist/file-routes.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
// Route-manifest seeding: the static pages a file-system router declares
|
|
10
|
-
// are known before anything renders, so they seed the crawl directly —
|
|
11
|
-
// a page nothing links to still gets built, and the crawl starts wide
|
|
12
|
-
// instead of unwinding from `/`. Dynamic routes (`/posts/:slug`,
|
|
13
|
-
// `/*404`) are left to link discovery: only a render knows their values.
|
|
14
|
-
import { createRequire } from "node:module";
|
|
15
|
-
import path from "node:path";
|
|
16
|
-
import { pathToFileURL } from "node:url";
|
|
17
|
-
/**
|
|
18
|
-
* The statically addressable page paths of a route manifest: pages whose
|
|
19
|
-
* path has no parameter or catch-all segment, with `(group)` segments
|
|
20
|
-
* stripped the way emission adapters strip them. Pure — the seam the
|
|
21
|
-
* plugin and tests share.
|
|
22
|
-
*/
|
|
23
|
-
export function staticRoutePaths(entries) {
|
|
24
|
-
const paths = new Set();
|
|
25
|
-
for (const entry of entries) {
|
|
26
|
-
if (!entry.page)
|
|
27
|
-
continue;
|
|
28
|
-
const segments = entry.path.split("/").filter(segment => segment !== "");
|
|
29
|
-
if (segments.some(segment => segment.startsWith(":") || segment.startsWith("*")))
|
|
30
|
-
continue;
|
|
31
|
-
const concrete = segments.filter(segment => !/^\(.*\)$/.test(segment));
|
|
32
|
-
paths.add("/" + concrete.join("/"));
|
|
33
|
-
}
|
|
34
|
-
return [...paths];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A `pages` source scanning a `filesystem-routing` route directory for its
|
|
38
|
-
* static pages. The package is resolved from the project root (it is the
|
|
39
|
-
* APP's dependency), loaded lazily so projects without it pay nothing.
|
|
40
|
-
*
|
|
41
|
-
* ```ts
|
|
42
|
-
* prerender({ pages: fileRoutePages({ dir: "src/pages" }) })
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* The `prerender()` plugin applies this automatically (`fileRoutes: true`,
|
|
46
|
-
* the default) when the package and the route directory exist.
|
|
47
|
-
*/
|
|
48
|
-
export function fileRoutePages(options = {}) {
|
|
49
|
-
const root = options.root ?? process.cwd();
|
|
50
|
-
const dir = path.resolve(root, options.dir ?? "src/routes");
|
|
51
|
-
const extensions = options.extensions ?? ["js", "jsx", "ts", "tsx"];
|
|
52
|
-
return async () => {
|
|
53
|
-
const routing = await loadFileSystemRouting(root);
|
|
54
|
-
const router = new routing.PageFileSystemRouter({ dir, extensions });
|
|
55
|
-
return staticRoutePaths(await router.getRoutes());
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/** Whether `filesystem-routing` resolves from the project (for the plugin's auto mode). */
|
|
59
|
-
export function hasFileSystemRouting(root) {
|
|
60
|
-
try {
|
|
61
|
-
resolveFileSystemRouting(root);
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function resolveFileSystemRouting(root) {
|
|
69
|
-
// from the project first (the app's copy), then from here (a test or a
|
|
70
|
-
// setup that installed it alongside the plugin)
|
|
71
|
-
for (const from of [path.join(root, "package.json"), import.meta.url]) {
|
|
72
|
-
try {
|
|
73
|
-
return createRequire(from).resolve("filesystem-routing");
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
// try the next base
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
throw new Error(`fileRoutePages needs the "filesystem-routing" package, which could not be resolved from ${root}.`);
|
|
80
|
-
}
|
|
81
|
-
async function loadFileSystemRouting(root) {
|
|
82
|
-
const resolved = resolveFileSystemRouting(root);
|
|
83
|
-
return (await import(__rewriteRelativeImportExtension(pathToFileURL(resolved).href)));
|
|
84
|
-
}
|