@site-index/core 0.1.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.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +158 -0
  3. package/dist/domains/artifacts/artifact.d.ts +16 -0
  4. package/dist/domains/artifacts/artifact.js +20 -0
  5. package/dist/domains/artifacts/make.artifacts.d.ts +3 -0
  6. package/dist/domains/artifacts/make.artifacts.js +26 -0
  7. package/dist/domains/artifacts/robots.artifacts.d.ts +3 -0
  8. package/dist/domains/artifacts/robots.artifacts.js +19 -0
  9. package/dist/domains/artifacts/sitemaps.artifacts.d.ts +4 -0
  10. package/dist/domains/artifacts/sitemaps.artifacts.js +56 -0
  11. package/dist/domains/options/options.resolve.d.ts +11 -0
  12. package/dist/domains/options/options.resolve.js +15 -0
  13. package/dist/domains/options/types.d.ts +8 -0
  14. package/dist/domains/options/types.js +1 -0
  15. package/dist/domains/site-indexes/process/modules.discovery.d.ts +2 -0
  16. package/dist/domains/site-indexes/process/modules.discovery.js +27 -0
  17. package/dist/domains/site-indexes/process/modules.load.d.ts +4 -0
  18. package/dist/domains/site-indexes/process/modules.load.js +22 -0
  19. package/dist/domains/site-indexes/process/modules.resolve.d.ts +4 -0
  20. package/dist/domains/site-indexes/process/modules.resolve.js +17 -0
  21. package/dist/domains/site-indexes/process/site-indexes.resolve.d.ts +5 -0
  22. package/dist/domains/site-indexes/process/site-indexes.resolve.js +24 -0
  23. package/dist/domains/site-indexes/schemas/modules.schema.d.ts +12 -0
  24. package/dist/domains/site-indexes/schemas/modules.schema.js +7 -0
  25. package/dist/domains/site-indexes/schemas/site-indexes.schema.d.ts +8 -0
  26. package/dist/domains/site-indexes/schemas/site-indexes.schema.js +15 -0
  27. package/dist/domains/site-indexes/types.d.ts +17 -0
  28. package/dist/domains/site-indexes/types.js +1 -0
  29. package/dist/index.d.ts +5 -0
  30. package/dist/index.js +2 -0
  31. package/dist/main.d.ts +4 -0
  32. package/dist/main.js +28 -0
  33. package/dist/types.d.ts +8 -0
  34. package/dist/types.js +1 -0
  35. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Deasilsoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # @site-index/core
2
+
3
+ Deterministic site-index pipeline for config resolution, discovery, loading, validation, deduplication, and artifact generation.
4
+
5
+ [Repository README](../../../README.md)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @site-index/core
11
+ ```
12
+
13
+ Requirements:
14
+
15
+ - Node.js `>=22`
16
+
17
+ ## When to use
18
+
19
+ Use `@site-index/core` when you need programmatic control and can provide module loading yourself.
20
+
21
+ ## When not to use
22
+
23
+ - Use [`site-index`](../../site-index/README.md) for CLI-driven workflows.
24
+ - Use [`@site-index/vite-plugin`](../vite-plugin/README.md) for Vite projects.
25
+
26
+ ## Public exports
27
+
28
+ ```ts
29
+ export { Artifact } from "./domains/artifacts/artifact.js";
30
+ export type { LoadModule, Options } from "./domains/options/types.js";
31
+ export type * from "./domains/site-indexes/types.js";
32
+ export type { Warning, Result } from "./types.js";
33
+ export { main } from "./main.js";
34
+ ```
35
+
36
+ ## Main API
37
+
38
+ ```ts
39
+ main(options: Options): Promise<Result<Artifact[]>>
40
+ ```
41
+
42
+ Options:
43
+
44
+ ```ts
45
+ type Options = {
46
+ siteUrl: string;
47
+ rootPath: string;
48
+ extensions?: string[] | undefined;
49
+ loadModule: LoadModule;
50
+ };
51
+ ```
52
+
53
+ `LoadModule`:
54
+
55
+ ```ts
56
+ type LoadModule = (module: Module) => Promise<ModuleExports>;
57
+ ```
58
+
59
+ `Module`:
60
+
61
+ ```ts
62
+ type Module = {
63
+ filePath: string;
64
+ importId: string;
65
+ };
66
+ ```
67
+
68
+ `ModuleExports`:
69
+
70
+ ```ts
71
+ type ModuleExports = {
72
+ siteIndexes: SiteIndex[];
73
+ };
74
+ ```
75
+
76
+ ## Site index type
77
+
78
+ ```ts
79
+ type SiteIndex = {
80
+ url: `/${string}`;
81
+ lastModified?: string | undefined;
82
+ sitemap?: string | undefined;
83
+ index?: boolean | undefined;
84
+ };
85
+ ```
86
+
87
+ Validation rules:
88
+
89
+ - `url` must start with `/`
90
+ - `url` cannot contain query strings or fragments
91
+ - `lastModified` is optional
92
+ - `lastModified` must be an ISO date or an ISO datetime with offset
93
+ - `sitemap` is optional
94
+ - `sitemap` defaults to `pages`
95
+ - `sitemap` must be lowercase and can include hyphens
96
+ - `index` is optional
97
+ - `index` defaults to `true`
98
+ - `index: false` excludes the URL from sitemap artifacts and adds `Disallow: <path>` to `robots.txt`
99
+
100
+ ## Artifacts
101
+
102
+ Generated:
103
+
104
+ - `sitemap.xml`
105
+ - `sitemap-<name>.xml`
106
+ - `robots.txt`
107
+
108
+ Artifact content types:
109
+
110
+ - `.xml` -> `application/xml; charset=utf-8`
111
+ - `.txt` -> `text/plain; charset=utf-8`
112
+
113
+ ## Pipeline behavior
114
+
115
+ `main(...)`:
116
+
117
+ - resolves options
118
+ - discovers `*.site-index.*` modules
119
+ - loads modules via caller-provided `loadModule`
120
+ - validates module exports
121
+ - resolves and deduplicates site index entries
122
+ - sorts output deterministically
123
+ - generates immutable artifacts
124
+ - returns warnings for recoverable issues
125
+
126
+ Warning categories include:
127
+
128
+ - no modules found
129
+ - failed module load
130
+ - invalid module exports
131
+ - duplicate URL entries
132
+
133
+ ## Example
134
+
135
+ Example with a runtime that can import the discovered module files:
136
+
137
+ ```ts
138
+ import { main } from "@site-index/core";
139
+ import type { Module, ModuleExports } from "@site-index/core";
140
+
141
+ const result = await main({
142
+ siteUrl: "https://example.com",
143
+ rootPath: process.cwd(),
144
+ extensions: [".mjs"],
145
+ loadModule: async (module: Module): Promise<ModuleExports> => {
146
+ const loaded = await import(module.filePath);
147
+
148
+ return loaded.default as ModuleExports;
149
+ },
150
+ });
151
+ ```
152
+
153
+ ## Related packages
154
+
155
+ - [`site-index`](../../site-index/README.md)
156
+ - [`@site-index/vite-plugin`](../vite-plugin/README.md)
157
+ - [`@site-index/vite-runtime`](../vite-runtime/README.md)
158
+ - [`@site-index/observability`](../observability/README.md)
@@ -0,0 +1,16 @@
1
+ declare const CONTENT_TYPE_BY_EXT: {
2
+ readonly ".xml": "application/xml; charset=utf-8";
3
+ readonly ".txt": "text/plain; charset=utf-8";
4
+ };
5
+ type FileExtension = keyof typeof CONTENT_TYPE_BY_EXT;
6
+ type ContentType = (typeof CONTENT_TYPE_BY_EXT)[FileExtension];
7
+ export declare class Artifact {
8
+ readonly filePath: string;
9
+ readonly content: string;
10
+ readonly contentType: ContentType;
11
+ constructor(input: {
12
+ filePath: string;
13
+ content: string;
14
+ });
15
+ }
16
+ export {};
@@ -0,0 +1,20 @@
1
+ const CONTENT_TYPE_BY_EXT = {
2
+ ".xml": "application/xml; charset=utf-8",
3
+ ".txt": "text/plain; charset=utf-8",
4
+ };
5
+ const FILE_EXTENSIONS = Object.keys(CONTENT_TYPE_BY_EXT);
6
+ export class Artifact {
7
+ filePath;
8
+ content;
9
+ contentType;
10
+ constructor(input) {
11
+ const extension = FILE_EXTENSIONS.find((extension) => input.filePath.endsWith(extension));
12
+ if (!extension) {
13
+ throw new Error(`Unsupported artifact file extension: ${input.filePath}`);
14
+ }
15
+ this.filePath = input.filePath;
16
+ this.content = input.content;
17
+ this.contentType = CONTENT_TYPE_BY_EXT[extension];
18
+ Object.freeze(this);
19
+ }
20
+ }
@@ -0,0 +1,3 @@
1
+ import type { ResolvedSiteIndex } from "../site-indexes/schemas/site-indexes.schema.js";
2
+ import type { Artifact } from "./artifact.js";
3
+ export declare function makeArtifacts(siteUrl: string, siteIndexes: ResolvedSiteIndex[]): Artifact[];
@@ -0,0 +1,26 @@
1
+ import { makeRobotsArtifact } from "./robots.artifacts.js";
2
+ import { makeSitemapArtifacts, makeSitemapIndexArtifact, } from "./sitemaps.artifacts.js";
3
+ function makeSitemapGroups(siteIndexes) {
4
+ const sitemapGroups = new Map();
5
+ for (const siteIndex of siteIndexes) {
6
+ if (!siteIndex.index)
7
+ continue;
8
+ const sitemapGroup = sitemapGroups.get(siteIndex.sitemap);
9
+ if (sitemapGroup) {
10
+ sitemapGroup.push(siteIndex);
11
+ }
12
+ else {
13
+ sitemapGroups.set(siteIndex.sitemap, [siteIndex]);
14
+ }
15
+ }
16
+ return sitemapGroups;
17
+ }
18
+ export function makeArtifacts(siteUrl, siteIndexes) {
19
+ const sitemapGroups = makeSitemapGroups(siteIndexes);
20
+ const sitemapArtifacts = makeSitemapArtifacts(sitemapGroups, siteUrl);
21
+ return [
22
+ ...sitemapArtifacts,
23
+ makeSitemapIndexArtifact(sitemapArtifacts, siteUrl),
24
+ makeRobotsArtifact(siteIndexes, siteUrl),
25
+ ];
26
+ }
@@ -0,0 +1,3 @@
1
+ import type { ResolvedSiteIndex } from "../site-indexes/schemas/site-indexes.schema.js";
2
+ import { Artifact } from "./artifact.js";
3
+ export declare function makeRobotsArtifact(siteIndexes: ResolvedSiteIndex[], siteUrl: string): Artifact;
@@ -0,0 +1,19 @@
1
+ import { Artifact } from "./artifact.js";
2
+ function renderRobotsTxt(siteUrl, disallowedPaths) {
3
+ const lines = ["User-agent: *"];
4
+ for (const path of disallowedPaths) {
5
+ lines.push(`Disallow: ${path}`);
6
+ }
7
+ lines.push(`Sitemap: ${siteUrl}/sitemap.xml`);
8
+ return lines.join("\n");
9
+ }
10
+ export function makeRobotsArtifact(siteIndexes, siteUrl) {
11
+ const disallowed = siteIndexes
12
+ .filter((siteIndex) => !siteIndex.index)
13
+ .map((siteIndex) => siteIndex.url)
14
+ .toSorted((a, b) => a.localeCompare(b));
15
+ return new Artifact({
16
+ filePath: "robots.txt",
17
+ content: renderRobotsTxt(siteUrl, disallowed),
18
+ });
19
+ }
@@ -0,0 +1,4 @@
1
+ import type { ResolvedSiteIndex } from "../site-indexes/schemas/site-indexes.schema.js";
2
+ import { Artifact } from "./artifact.js";
3
+ export declare function makeSitemapArtifacts(sitemaps: Map<string, ResolvedSiteIndex[]>, siteUrl: string): Artifact[];
4
+ export declare function makeSitemapIndexArtifact(sitemaps: Artifact[], siteUrl: string): Artifact;
@@ -0,0 +1,56 @@
1
+ import { Artifact } from "./artifact.js";
2
+ const XML_VERSION_DECLARATION = '<?xml version="1.0" encoding="UTF-8"?>';
3
+ const SITEMAP_XML_NAMESPACE = "https://www.sitemaps.org/schemas/sitemap/0.9";
4
+ function escapeXml(value) {
5
+ return value
6
+ .replaceAll("&", "&amp;")
7
+ .replaceAll("<", "&lt;")
8
+ .replaceAll(">", "&gt;")
9
+ .replaceAll('"', "&quot;")
10
+ .replaceAll("'", "&apos;");
11
+ }
12
+ function renderSitemapXml(siteIndexes, siteUrl) {
13
+ const lines = [
14
+ XML_VERSION_DECLARATION,
15
+ `<urlset xmlns="${SITEMAP_XML_NAMESPACE}">`,
16
+ ];
17
+ for (const siteIndex of siteIndexes) {
18
+ const loc = escapeXml(`${siteUrl}${siteIndex.url}`);
19
+ lines.push(" <url>", ` <loc>${loc}</loc>`);
20
+ if (siteIndex.lastModified) {
21
+ const lastmod = escapeXml(siteIndex.lastModified);
22
+ lines.push(` <lastmod>${lastmod}</lastmod>`);
23
+ }
24
+ lines.push(" </url>");
25
+ }
26
+ lines.push("</urlset>");
27
+ return lines.join("\n");
28
+ }
29
+ export function makeSitemapArtifacts(sitemaps, siteUrl) {
30
+ const sortedSitemaps = [...sitemaps.entries()].toSorted(([a], [b]) => a.localeCompare(b));
31
+ return sortedSitemaps.map(([sitemap, siteIndexes]) => new Artifact({
32
+ filePath: `sitemap-${sitemap}.xml`,
33
+ content: renderSitemapXml(siteIndexes, siteUrl),
34
+ }));
35
+ }
36
+ function renderSitemapIndexXml(paths, siteUrl) {
37
+ const lines = [
38
+ XML_VERSION_DECLARATION,
39
+ `<sitemapindex xmlns="${SITEMAP_XML_NAMESPACE}">`,
40
+ ];
41
+ for (const path of paths) {
42
+ const loc = escapeXml(`${siteUrl}${path}`);
43
+ lines.push(" <sitemap>", ` <loc>${loc}</loc>`, " </sitemap>");
44
+ }
45
+ lines.push("</sitemapindex>");
46
+ return lines.join("\n");
47
+ }
48
+ export function makeSitemapIndexArtifact(sitemaps, siteUrl) {
49
+ const paths = sitemaps
50
+ .map((artifact) => artifact.filePath)
51
+ .toSorted((a, b) => a.localeCompare(b));
52
+ return new Artifact({
53
+ filePath: "sitemap.xml",
54
+ content: renderSitemapIndexXml(paths, siteUrl),
55
+ });
56
+ }
@@ -0,0 +1,11 @@
1
+ import { z as Zod } from "zod";
2
+ import type { LoadModule, Options } from "./types.js";
3
+ declare const OptionsSchema: Zod.ZodObject<{
4
+ siteUrl: Zod.ZodPipe<Zod.ZodURL, Zod.ZodTransform<string, string>>;
5
+ rootPath: Zod.ZodString;
6
+ extensions: Zod.ZodDefault<Zod.ZodOptional<Zod.ZodArray<Zod.ZodString>>>;
7
+ loadModule: Zod.ZodCustom<LoadModule, LoadModule>;
8
+ }, Zod.core.$strip>;
9
+ type Config = Zod.infer<typeof OptionsSchema>;
10
+ export declare function resolveOptions(options: Options): Config;
11
+ export {};
@@ -0,0 +1,15 @@
1
+ import { z as Zod } from "zod";
2
+ const OptionsSchema = Zod.object({
3
+ siteUrl: Zod.url({
4
+ protocol: /^https?$/,
5
+ hostname: Zod.regexes.domain,
6
+ }).transform((url) => url.trim().replace(/\/+$/, "")),
7
+ rootPath: Zod.string().trim().min(1),
8
+ extensions: Zod.array(Zod.string().regex(/^\.\w+$/))
9
+ .optional()
10
+ .default([".js", ".mjs", ".ts"]),
11
+ loadModule: Zod.custom((value) => typeof value === "function", "loadModule must be a function"),
12
+ });
13
+ export function resolveOptions(options) {
14
+ return OptionsSchema.parse(options);
15
+ }
@@ -0,0 +1,8 @@
1
+ import type { Module, ModuleExports } from "../site-indexes/types.js";
2
+ export type LoadModule = (module: Module) => Promise<ModuleExports>;
3
+ export type Options = {
4
+ siteUrl: string;
5
+ rootPath: string;
6
+ extensions?: string[] | undefined;
7
+ loadModule: LoadModule;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Module } from "../types.js";
2
+ export declare function discoverModules(root: string, supportedExtensions: string[]): Promise<Module[]>;
@@ -0,0 +1,27 @@
1
+ import path from "node:path";
2
+ import { glob } from "tinyglobby";
3
+ const IGNORED_PATHS = [
4
+ "**/node_modules/**",
5
+ "**/dist/**",
6
+ "**/coverage/**",
7
+ "**/.git/**",
8
+ ];
9
+ function makeModule(root, filePath) {
10
+ const relativePath = path.relative(root, filePath);
11
+ const posixPath = relativePath.split(path.sep).join("/");
12
+ return {
13
+ filePath,
14
+ importId: `./${posixPath}`,
15
+ };
16
+ }
17
+ export async function discoverModules(root, supportedExtensions) {
18
+ const filePaths = await glob(supportedExtensions.map((extension) => `**/*.site-index${extension}`), {
19
+ cwd: root,
20
+ absolute: true,
21
+ onlyFiles: true,
22
+ dot: false,
23
+ ignore: IGNORED_PATHS,
24
+ });
25
+ filePaths.sort((a, b) => a.localeCompare(b));
26
+ return filePaths.map((filePath) => makeModule(root, filePath));
27
+ }
@@ -0,0 +1,4 @@
1
+ import type { Result } from "../../../types.js";
2
+ import type { LoadModule } from "../../options/types.js";
3
+ import type { LoadedModule, Module } from "../types.js";
4
+ export declare function loadModules(modules: Module[], loadModule: LoadModule): Promise<Result<LoadedModule[]>>;
@@ -0,0 +1,22 @@
1
+ export async function loadModules(modules, loadModule) {
2
+ const data = [];
3
+ const warnings = [];
4
+ for (const module of modules) {
5
+ try {
6
+ const exports = await loadModule(module);
7
+ data.push({
8
+ importId: module.importId,
9
+ filePath: module.filePath,
10
+ siteIndexes: exports.siteIndexes,
11
+ });
12
+ }
13
+ catch (error) {
14
+ const message = error instanceof Error ? error.message : String(error);
15
+ warnings.push({
16
+ message: `Failed to load module "${module.filePath}" (${module.importId}): ${message}`,
17
+ filePath: module.filePath,
18
+ });
19
+ }
20
+ }
21
+ return { data, warnings };
22
+ }
@@ -0,0 +1,4 @@
1
+ import type { Result } from "../../../types.js";
2
+ import { type ResolvedModule } from "../schemas/modules.schema.js";
3
+ import type { LoadedModule } from "../types.js";
4
+ export declare function resolveModules(modules: LoadedModule[]): Result<ResolvedModule[]>;
@@ -0,0 +1,17 @@
1
+ import { ResolvedModuleSchema, } from "../schemas/modules.schema.js";
2
+ export function resolveModules(modules) {
3
+ const data = [];
4
+ const warnings = [];
5
+ for (const module of modules) {
6
+ const resolved = ResolvedModuleSchema.safeParse(module);
7
+ if (!resolved.success) {
8
+ warnings.push({
9
+ message: `Invalid module: ${resolved.error.message}`,
10
+ filePath: module.filePath,
11
+ });
12
+ continue;
13
+ }
14
+ data.push(resolved.data);
15
+ }
16
+ return { data, warnings };
17
+ }
@@ -0,0 +1,5 @@
1
+ import type { Result } from "../../../types.js";
2
+ import type { ResolvedModule } from "../schemas/modules.schema.js";
3
+ import type { ResolvedSiteIndex } from "../schemas/site-indexes.schema.js";
4
+ import type { WithSource } from "../types.js";
5
+ export declare function resolveSiteIndexes(modules: ResolvedModule[]): Result<WithSource<ResolvedSiteIndex>[]>;
@@ -0,0 +1,24 @@
1
+ export function resolveSiteIndexes(modules) {
2
+ const data = new Map();
3
+ const warnings = [];
4
+ for (const module of modules) {
5
+ for (const siteIndex of module.siteIndexes) {
6
+ const duplicate = data.get(siteIndex.url);
7
+ if (duplicate) {
8
+ warnings.push({
9
+ message: `Duplicate URL "${duplicate.url}" found in "${duplicate.filePath}"`,
10
+ filePath: module.filePath,
11
+ });
12
+ continue;
13
+ }
14
+ data.set(siteIndex.url, {
15
+ ...siteIndex,
16
+ filePath: module.filePath,
17
+ });
18
+ }
19
+ }
20
+ return {
21
+ data: [...data.values()].toSorted((a, b) => a.sitemap.localeCompare(b.sitemap) || a.url.localeCompare(b.url)),
22
+ warnings,
23
+ };
24
+ }
@@ -0,0 +1,12 @@
1
+ import { z as Zod } from "zod";
2
+ export declare const ResolvedModuleSchema: Zod.ZodObject<{
3
+ filePath: Zod.ZodString;
4
+ importId: Zod.ZodString;
5
+ siteIndexes: Zod.ZodArray<Zod.ZodObject<{
6
+ url: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<`/${string}`, string>>;
7
+ lastModified: Zod.ZodOptional<Zod.ZodUnion<readonly [Zod.ZodISODate, Zod.ZodISODateTime]>>;
8
+ sitemap: Zod.ZodDefault<Zod.ZodString>;
9
+ index: Zod.ZodDefault<Zod.ZodBoolean>;
10
+ }, Zod.core.$strict>>;
11
+ }, Zod.core.$strict>;
12
+ export type ResolvedModule = Zod.infer<typeof ResolvedModuleSchema>;
@@ -0,0 +1,7 @@
1
+ import { z as Zod } from "zod";
2
+ import { SiteIndexSchema } from "./site-indexes.schema.js";
3
+ export const ResolvedModuleSchema = Zod.strictObject({
4
+ filePath: Zod.string(),
5
+ importId: Zod.string(),
6
+ siteIndexes: Zod.array(SiteIndexSchema),
7
+ });
@@ -0,0 +1,8 @@
1
+ import { z as Zod } from "zod";
2
+ export declare const SiteIndexSchema: Zod.ZodObject<{
3
+ url: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<`/${string}`, string>>;
4
+ lastModified: Zod.ZodOptional<Zod.ZodUnion<readonly [Zod.ZodISODate, Zod.ZodISODateTime]>>;
5
+ sitemap: Zod.ZodDefault<Zod.ZodString>;
6
+ index: Zod.ZodDefault<Zod.ZodBoolean>;
7
+ }, Zod.core.$strict>;
8
+ export type ResolvedSiteIndex = Zod.infer<typeof SiteIndexSchema>;
@@ -0,0 +1,15 @@
1
+ import { z as Zod } from "zod";
2
+ const LastModifiedSchema = Zod.union([
3
+ Zod.iso.date(),
4
+ Zod.iso.datetime({ offset: true }),
5
+ ]);
6
+ export const SiteIndexSchema = Zod.strictObject({
7
+ url: Zod.string()
8
+ .regex(/^\/[^?#]*$/, "Invalid url (must start with '/' and not contain query/fragment)")
9
+ .transform((path) => path),
10
+ lastModified: LastModifiedSchema.optional(),
11
+ sitemap: Zod.string()
12
+ .regex(/^[a-z0-9]+(-[a-z0-9]+)*$/, "Invalid sitemap name (must be lowercase and can include hyphens)")
13
+ .default("pages"),
14
+ index: Zod.boolean().default(true),
15
+ });
@@ -0,0 +1,17 @@
1
+ export type SiteIndex = {
2
+ url: `/${string}`;
3
+ lastModified?: string | undefined;
4
+ sitemap?: string | undefined;
5
+ index?: boolean | undefined;
6
+ };
7
+ export type WithSource<T> = T & {
8
+ filePath: string;
9
+ };
10
+ export type Module = {
11
+ filePath: string;
12
+ importId: string;
13
+ };
14
+ export type ModuleExports = {
15
+ siteIndexes: SiteIndex[];
16
+ };
17
+ export type LoadedModule = Module & ModuleExports;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export { Artifact } from "./domains/artifacts/artifact.js";
2
+ export type { LoadModule, Options } from "./domains/options/types.js";
3
+ export type * from "./domains/site-indexes/types.js";
4
+ export type { Warning, Result } from "./types.js";
5
+ export { main } from "./main.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Artifact } from "./domains/artifacts/artifact.js";
2
+ export { main } from "./main.js";
package/dist/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Artifact } from "./domains/artifacts/artifact.js";
2
+ import type { Options } from "./domains/options/types.js";
3
+ import type { Result } from "./types.js";
4
+ export declare function main(options: Options): Promise<Result<Artifact[]>>;
package/dist/main.js ADDED
@@ -0,0 +1,28 @@
1
+ import { makeArtifacts } from "./domains/artifacts/make.artifacts.js";
2
+ import { resolveOptions } from "./domains/options/options.resolve.js";
3
+ import { discoverModules } from "./domains/site-indexes/process/modules.discovery.js";
4
+ import { loadModules } from "./domains/site-indexes/process/modules.load.js";
5
+ import { resolveModules } from "./domains/site-indexes/process/modules.resolve.js";
6
+ import { resolveSiteIndexes } from "./domains/site-indexes/process/site-indexes.resolve.js";
7
+ export async function main(options) {
8
+ const warnings = [];
9
+ const config = resolveOptions(options);
10
+ const modules = await discoverModules(config.rootPath, config.extensions);
11
+ if (modules.length === 0) {
12
+ warnings.push({
13
+ message: `No modules found in: ${config.rootPath}`,
14
+ });
15
+ return {
16
+ data: [],
17
+ warnings,
18
+ };
19
+ }
20
+ const loadedModules = await loadModules(modules, config.loadModule);
21
+ const resolvedModules = resolveModules(loadedModules.data);
22
+ const resolvedSiteIndexes = resolveSiteIndexes(resolvedModules.data);
23
+ warnings.push(...loadedModules.warnings, ...resolvedModules.warnings, ...resolvedSiteIndexes.warnings);
24
+ return {
25
+ data: makeArtifacts(config.siteUrl, resolvedSiteIndexes.data),
26
+ warnings,
27
+ };
28
+ }
@@ -0,0 +1,8 @@
1
+ export type Warning = {
2
+ message: string;
3
+ filePath?: string | undefined;
4
+ };
5
+ export type Result<T> = {
6
+ data: T;
7
+ warnings: Warning[];
8
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@site-index/core",
3
+ "version": "0.1.0",
4
+ "description": "Deterministic site-index pipeline: config, discovery, loading, validation, and artifact generation.",
5
+ "keywords": [
6
+ "site-index",
7
+ "sitemap",
8
+ "robots",
9
+ "seo"
10
+ ],
11
+ "homepage": "https://github.com/Deasilsoft/site-index/tree/main/packages/@site-index/core",
12
+ "bugs": {
13
+ "url": "https://github.com/Deasilsoft/site-index/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Deasilsoft/site-index.git",
18
+ "directory": "packages/@site-index/core"
19
+ },
20
+ "license": "MIT",
21
+ "author": "Deasilsoft <contact@deasilsoft.com>",
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/index.js",
26
+ "types": "./dist/index.d.ts"
27
+ }
28
+ },
29
+ "main": "dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist",
33
+ "!dist/**/*.tsbuildinfo"
34
+ ],
35
+ "scripts": {
36
+ "build": "tsc -b",
37
+ "clean": "rm -rf dist coverage",
38
+ "prepack": "npm run clean && npm run build",
39
+ "pretest": "npm pack --dry-run",
40
+ "test": "vitest run --coverage",
41
+ "pretypecheck": "npm run build",
42
+ "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json"
43
+ },
44
+ "dependencies": {
45
+ "tinyglobby": "^0.2.16",
46
+ "zod": "^4.4.3"
47
+ },
48
+ "devDependencies": {
49
+ "@vitest/coverage-v8": "^4.1.6",
50
+ "vitest": "^4.1.6"
51
+ },
52
+ "engines": {
53
+ "node": ">=22"
54
+ }
55
+ }