@tanstack/start-plugin-core 1.166.12 → 1.166.13
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/esm/build-sitemap.js +94 -123
- package/dist/esm/build-sitemap.js.map +1 -1
- package/dist/esm/constants.js +15 -20
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/dev-server-plugin/dev-styles.js +137 -150
- package/dist/esm/dev-server-plugin/dev-styles.js.map +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js +16 -15
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
- package/dist/esm/dev-server-plugin/plugin.js +125 -195
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/ast.js +6 -5
- package/dist/esm/import-protection-plugin/ast.js.map +1 -1
- package/dist/esm/import-protection-plugin/constants.js +20 -22
- package/dist/esm/import-protection-plugin/constants.js.map +1 -1
- package/dist/esm/import-protection-plugin/defaults.js +35 -25
- package/dist/esm/import-protection-plugin/defaults.js.map +1 -1
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js +93 -92
- package/dist/esm/import-protection-plugin/extensionlessAbsoluteIdResolver.js.map +1 -1
- package/dist/esm/import-protection-plugin/matchers.js +23 -24
- package/dist/esm/import-protection-plugin/matchers.js.map +1 -1
- package/dist/esm/import-protection-plugin/plugin.js +1045 -1361
- package/dist/esm/import-protection-plugin/plugin.js.map +1 -1
- package/dist/esm/import-protection-plugin/postCompileUsage.js +58 -55
- package/dist/esm/import-protection-plugin/postCompileUsage.js.map +1 -1
- package/dist/esm/import-protection-plugin/rewriteDeniedImports.js +187 -259
- package/dist/esm/import-protection-plugin/rewriteDeniedImports.js.map +1 -1
- package/dist/esm/import-protection-plugin/sourceLocation.js +238 -248
- package/dist/esm/import-protection-plugin/sourceLocation.js.map +1 -1
- package/dist/esm/import-protection-plugin/trace.js +173 -184
- package/dist/esm/import-protection-plugin/trace.js.map +1 -1
- package/dist/esm/import-protection-plugin/utils.js +132 -111
- package/dist/esm/import-protection-plugin/utils.js.map +1 -1
- package/dist/esm/import-protection-plugin/virtualModules.js +216 -196
- package/dist/esm/import-protection-plugin/virtualModules.js.map +1 -1
- package/dist/esm/index.js +2 -7
- package/dist/esm/load-env-plugin/plugin.js +12 -11
- package/dist/esm/load-env-plugin/plugin.js.map +1 -1
- package/dist/esm/output-directory.js +10 -10
- package/dist/esm/output-directory.js.map +1 -1
- package/dist/esm/plugin.js +275 -355
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/post-server-build.js +39 -53
- package/dist/esm/post-server-build.js.map +1 -1
- package/dist/esm/prerender.js +177 -239
- package/dist/esm/prerender.js.map +1 -1
- package/dist/esm/preview-server-plugin/plugin.js +41 -44
- package/dist/esm/preview-server-plugin/plugin.js.map +1 -1
- package/dist/esm/queue.js +115 -126
- package/dist/esm/queue.js.map +1 -1
- package/dist/esm/resolve-entries.js +31 -32
- package/dist/esm/resolve-entries.js.map +1 -1
- package/dist/esm/schema.js +156 -179
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compiler.js +655 -812
- package/dist/esm/start-compiler-plugin/compiler.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js +25 -8
- package/dist/esm/start-compiler-plugin/handleClientOnlyJSX.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js +22 -19
- package/dist/esm/start-compiler-plugin/handleCreateIsomorphicFn.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js +20 -22
- package/dist/esm/start-compiler-plugin/handleCreateMiddleware.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js +187 -255
- package/dist/esm/start-compiler-plugin/handleCreateServerFn.js.map +1 -1
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js +23 -33
- package/dist/esm/start-compiler-plugin/handleEnvOnly.js.map +1 -1
- package/dist/esm/start-compiler-plugin/plugin.js +247 -291
- package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
- package/dist/esm/start-compiler-plugin/utils.js +27 -27
- package/dist/esm/start-compiler-plugin/utils.js.map +1 -1
- package/dist/esm/start-manifest-plugin/manifestBuilder.js +272 -378
- package/dist/esm/start-manifest-plugin/manifestBuilder.js.map +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +35 -44
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/constants.js +6 -5
- package/dist/esm/start-router-plugin/constants.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js +24 -19
- package/dist/esm/start-router-plugin/generator-plugins/prerender-routes-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +28 -29
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.js +146 -199
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +32 -31
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -1
- package/dist/esm/utils.js +14 -14
- package/dist/esm/utils.js.map +1 -1
- package/package.json +7 -7
- package/dist/esm/index.js.map +0 -1
|
@@ -1,134 +1,105 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLogger } from "./utils.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { writeFileSync } from "node:fs";
|
|
3
4
|
import { create } from "xmlbuilder2";
|
|
4
|
-
|
|
5
|
+
//#region src/build-sitemap.ts
|
|
5
6
|
function buildSitemapJson(pages, host) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return { urls };
|
|
7
|
+
const slash = checkSlash(host);
|
|
8
|
+
return { urls: pages.filter((page) => {
|
|
9
|
+
return page.sitemap?.exclude !== true;
|
|
10
|
+
}).map((page) => ({
|
|
11
|
+
loc: `${host}${slash}${page.path.replace(/^\/+/g, "")}`,
|
|
12
|
+
lastmod: page.sitemap?.lastmod ? new Date(page.sitemap.lastmod).toISOString().split("T")[0] : (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
|
|
13
|
+
priority: page.sitemap?.priority,
|
|
14
|
+
changefreq: page.sitemap?.changefreq,
|
|
15
|
+
alternateRefs: page.sitemap?.alternateRefs,
|
|
16
|
+
images: page.sitemap?.images,
|
|
17
|
+
news: page.sitemap?.news
|
|
18
|
+
})) };
|
|
19
19
|
}
|
|
20
20
|
function jsonToXml(sitemapData) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
imageElement.ele("image:caption").txt(image.caption);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (item.news) {
|
|
55
|
-
const newsElement = page.ele("news:news");
|
|
56
|
-
const publication = newsElement.ele("news:publication");
|
|
57
|
-
publication.ele("news:name").txt(item.news.publication.name);
|
|
58
|
-
publication.ele("news:language").txt(item.news.publication.language);
|
|
59
|
-
newsElement.ele("news:publication_date").txt(new Date(item.news.publicationDate).toISOString().split("T")[0]);
|
|
60
|
-
newsElement.ele("news:title").txt(item.news.title);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return sitemap.end({ prettyPrint: true });
|
|
21
|
+
const sitemap = createXml("urlset");
|
|
22
|
+
for (const item of sitemapData.urls) {
|
|
23
|
+
const page = sitemap.ele("url");
|
|
24
|
+
page.ele("loc").txt(item.loc);
|
|
25
|
+
page.ele("lastmod").txt(item.lastmod);
|
|
26
|
+
if (item.priority !== void 0) page.ele("priority").txt(item.priority.toString());
|
|
27
|
+
if (item.changefreq) page.ele("changefreq").txt(item.changefreq);
|
|
28
|
+
if (item.alternateRefs?.length) for (const ref of item.alternateRefs) {
|
|
29
|
+
const alternateRef = page.ele("xhtml:link");
|
|
30
|
+
alternateRef.att("rel", "alternate");
|
|
31
|
+
alternateRef.att("href", ref.href);
|
|
32
|
+
if (ref.hreflang) alternateRef.att("hreflang", ref.hreflang);
|
|
33
|
+
}
|
|
34
|
+
if (item.images?.length) for (const image of item.images) {
|
|
35
|
+
const imageElement = page.ele("image:image");
|
|
36
|
+
imageElement.ele("image:loc").txt(image.loc);
|
|
37
|
+
if (image.title) imageElement.ele("image:title").txt(image.title);
|
|
38
|
+
if (image.caption) imageElement.ele("image:caption").txt(image.caption);
|
|
39
|
+
}
|
|
40
|
+
if (item.news) {
|
|
41
|
+
const newsElement = page.ele("news:news");
|
|
42
|
+
const publication = newsElement.ele("news:publication");
|
|
43
|
+
publication.ele("news:name").txt(item.news.publication.name);
|
|
44
|
+
publication.ele("news:language").txt(item.news.publication.language);
|
|
45
|
+
newsElement.ele("news:publication_date").txt(new Date(item.news.publicationDate).toISOString().split("T")[0]);
|
|
46
|
+
newsElement.ele("news:title").txt(item.news.title);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return sitemap.end({ prettyPrint: true });
|
|
64
50
|
}
|
|
65
|
-
function buildSitemap({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
writeFileSync(xmlOutputPath, jsonToXml(sitemapData));
|
|
104
|
-
logger.info(`Writing pages data at ${pagesOutputPath}`);
|
|
105
|
-
writeFileSync(
|
|
106
|
-
pagesOutputPath,
|
|
107
|
-
JSON.stringify(
|
|
108
|
-
{
|
|
109
|
-
pages,
|
|
110
|
-
host,
|
|
111
|
-
lastBuilt: (/* @__PURE__ */ new Date()).toISOString()
|
|
112
|
-
},
|
|
113
|
-
null,
|
|
114
|
-
2
|
|
115
|
-
)
|
|
116
|
-
);
|
|
117
|
-
} catch (e) {
|
|
118
|
-
logger.error(`Unable to write sitemap files`, e);
|
|
119
|
-
}
|
|
51
|
+
function buildSitemap({ startConfig, publicDir }) {
|
|
52
|
+
const logger = createLogger("sitemap");
|
|
53
|
+
let sitemapOptions = startConfig.sitemap;
|
|
54
|
+
if (!sitemapOptions && startConfig.pages.length) sitemapOptions = {
|
|
55
|
+
enabled: true,
|
|
56
|
+
outputPath: "sitemap.xml"
|
|
57
|
+
};
|
|
58
|
+
if (!sitemapOptions?.enabled) throw new Error("Sitemap is not enabled");
|
|
59
|
+
const { host, outputPath } = sitemapOptions;
|
|
60
|
+
if (!host) {
|
|
61
|
+
if (!startConfig.sitemap) {
|
|
62
|
+
logger.info("Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option.");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
throw new Error("Sitemap host is not set and required to build the sitemap.");
|
|
66
|
+
}
|
|
67
|
+
if (!outputPath) throw new Error("Sitemap output path is not set");
|
|
68
|
+
const { pages } = startConfig;
|
|
69
|
+
if (!pages.length) {
|
|
70
|
+
logger.info("No pages were found to build the sitemap. Skipping...");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
logger.info("Building Sitemap...");
|
|
74
|
+
const sitemapData = buildSitemapJson(pages, host);
|
|
75
|
+
const xmlOutputPath = path.join(publicDir, outputPath);
|
|
76
|
+
const pagesOutputPath = path.join(publicDir, "pages.json");
|
|
77
|
+
try {
|
|
78
|
+
logger.info(`Writing sitemap XML at ${xmlOutputPath}`);
|
|
79
|
+
writeFileSync(xmlOutputPath, jsonToXml(sitemapData));
|
|
80
|
+
logger.info(`Writing pages data at ${pagesOutputPath}`);
|
|
81
|
+
writeFileSync(pagesOutputPath, JSON.stringify({
|
|
82
|
+
pages,
|
|
83
|
+
host,
|
|
84
|
+
lastBuilt: (/* @__PURE__ */ new Date()).toISOString()
|
|
85
|
+
}, null, 2));
|
|
86
|
+
} catch (e) {
|
|
87
|
+
logger.error(`Unable to write sitemap files`, e);
|
|
88
|
+
}
|
|
120
89
|
}
|
|
121
90
|
function createXml(elementName) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
91
|
+
return create({
|
|
92
|
+
version: "1.0",
|
|
93
|
+
encoding: "UTF-8"
|
|
94
|
+
}).ele(elementName, {
|
|
95
|
+
xmlns: "https://www.sitemaps.org/schemas/sitemap/0.9",
|
|
96
|
+
"xmlns:xhtml": "http://www.w3.org/1999/xhtml"
|
|
97
|
+
}).com(`This file was automatically generated by TanStack Start.`);
|
|
126
98
|
}
|
|
127
99
|
function checkSlash(host) {
|
|
128
|
-
|
|
129
|
-
return finalChar === "/" ? "" : "/";
|
|
100
|
+
return host.slice(-1) === "/" ? "" : "/";
|
|
130
101
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
//# sourceMappingURL=build-sitemap.js.map
|
|
102
|
+
//#endregion
|
|
103
|
+
export { buildSitemap };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=build-sitemap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-sitemap.js","sources":["../../src/build-sitemap.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { create } from 'xmlbuilder2'\nimport { createLogger } from './utils'\nimport type { TanStackStartOutputConfig } from './schema'\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'\n\nexport type SitemapUrl = {\n loc: string\n lastmod: string\n priority?: number\n changefreq?:\n | 'always'\n | 'hourly'\n | 'daily'\n | 'weekly'\n | 'monthly'\n | 'yearly'\n | 'never'\n alternateRefs?: Array<{\n href: string\n hreflang?: string\n }>\n images?: Array<{\n loc: string\n title?: string\n caption?: string\n }>\n news?: {\n publication: {\n name: string\n language: string\n }\n publicationDate: string | Date\n title: string\n }\n}\n\nexport type SitemapData = {\n urls: Array<SitemapUrl>\n}\n\nfunction buildSitemapJson(\n pages: TanStackStartOutputConfig['pages'],\n host: string,\n): SitemapData {\n const slash = checkSlash(host)\n\n const urls: Array<SitemapUrl> = pages\n .filter((page) => {\n return page.sitemap?.exclude !== true\n })\n .map((page) => ({\n loc: `${host}${slash}${page.path.replace(/^\\/+/g, '')}`,\n lastmod: page.sitemap?.lastmod\n ? new Date(page.sitemap.lastmod).toISOString().split('T')[0]!\n : new Date().toISOString().split('T')[0]!,\n priority: page.sitemap?.priority,\n changefreq: page.sitemap?.changefreq,\n alternateRefs: page.sitemap?.alternateRefs,\n images: page.sitemap?.images,\n news: page.sitemap?.news,\n }))\n\n return { urls }\n}\n\nfunction jsonToXml(sitemapData: SitemapData): string {\n const sitemap = createXml('urlset')\n\n for (const item of sitemapData.urls) {\n const page = sitemap.ele('url')\n page.ele('loc').txt(item.loc)\n page.ele('lastmod').txt(item.lastmod)\n\n if (item.priority !== undefined) {\n page.ele('priority').txt(item.priority.toString())\n }\n if (item.changefreq) {\n page.ele('changefreq').txt(item.changefreq)\n }\n\n // Add alternate references\n if (item.alternateRefs?.length) {\n for (const ref of item.alternateRefs) {\n const alternateRef = page.ele('xhtml:link')\n alternateRef.att('rel', 'alternate')\n alternateRef.att('href', ref.href)\n if (ref.hreflang) {\n alternateRef.att('hreflang', ref.hreflang)\n }\n }\n }\n\n // Add images\n if (item.images?.length) {\n for (const image of item.images) {\n const imageElement = page.ele('image:image')\n imageElement.ele('image:loc').txt(image.loc)\n if (image.title) {\n imageElement.ele('image:title').txt(image.title)\n }\n if (image.caption) {\n imageElement.ele('image:caption').txt(image.caption)\n }\n }\n }\n\n // Add news\n if (item.news) {\n const newsElement = page.ele('news:news')\n const publication = newsElement.ele('news:publication')\n publication.ele('news:name').txt(item.news.publication.name)\n publication.ele('news:language').txt(item.news.publication.language)\n newsElement\n .ele('news:publication_date')\n .txt(new Date(item.news.publicationDate).toISOString().split('T')[0]!)\n newsElement.ele('news:title').txt(item.news.title)\n }\n }\n\n return sitemap.end({ prettyPrint: true })\n}\n\nexport function buildSitemap({\n startConfig,\n publicDir,\n}: {\n startConfig: TanStackStartOutputConfig\n publicDir: string\n}) {\n const logger = createLogger('sitemap')\n\n let sitemapOptions = startConfig.sitemap\n\n if (!sitemapOptions && startConfig.pages.length) {\n sitemapOptions = { enabled: true, outputPath: 'sitemap.xml' }\n }\n\n if (!sitemapOptions?.enabled) {\n throw new Error('Sitemap is not enabled')\n }\n\n const { host, outputPath } = sitemapOptions\n\n if (!host) {\n if (!startConfig.sitemap) {\n logger.info(\n 'Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option.',\n )\n return\n }\n throw new Error(\n 'Sitemap host is not set and required to build the sitemap.',\n )\n }\n\n if (!outputPath) {\n throw new Error('Sitemap output path is not set')\n }\n\n const { pages } = startConfig\n\n if (!pages.length) {\n logger.info('No pages were found to build the sitemap. Skipping...')\n return\n }\n\n logger.info('Building Sitemap...')\n\n // Build the sitemap data\n const sitemapData = buildSitemapJson(pages, host)\n\n // Generate output paths\n const xmlOutputPath = path.join(publicDir, outputPath)\n const pagesOutputPath = path.join(publicDir, 'pages.json')\n\n try {\n // Write XML sitemap\n logger.info(`Writing sitemap XML at ${xmlOutputPath}`)\n writeFileSync(xmlOutputPath, jsonToXml(sitemapData))\n\n // Write pages data for runtime use\n logger.info(`Writing pages data at ${pagesOutputPath}`)\n writeFileSync(\n pagesOutputPath,\n JSON.stringify(\n {\n pages,\n host,\n lastBuilt: new Date().toISOString(),\n },\n null,\n 2,\n ),\n )\n } catch (e) {\n logger.error(`Unable to write sitemap files`, e)\n }\n}\n\nfunction createXml(elementName: 'urlset' | 'sitemapindex'): XMLBuilder {\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, {\n xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',\n 'xmlns:xhtml': 'http://www.w3.org/1999/xhtml',\n })\n .com(`This file was automatically generated by TanStack Start.`)\n}\n\nfunction checkSlash(host: string): string {\n const finalChar = host.slice(-1)\n return finalChar === '/' ? '' : '/'\n}\n"],"
|
|
1
|
+
{"version":3,"file":"build-sitemap.js","names":[],"sources":["../../src/build-sitemap.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { create } from 'xmlbuilder2'\nimport { createLogger } from './utils'\nimport type { TanStackStartOutputConfig } from './schema'\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'\n\nexport type SitemapUrl = {\n loc: string\n lastmod: string\n priority?: number\n changefreq?:\n | 'always'\n | 'hourly'\n | 'daily'\n | 'weekly'\n | 'monthly'\n | 'yearly'\n | 'never'\n alternateRefs?: Array<{\n href: string\n hreflang?: string\n }>\n images?: Array<{\n loc: string\n title?: string\n caption?: string\n }>\n news?: {\n publication: {\n name: string\n language: string\n }\n publicationDate: string | Date\n title: string\n }\n}\n\nexport type SitemapData = {\n urls: Array<SitemapUrl>\n}\n\nfunction buildSitemapJson(\n pages: TanStackStartOutputConfig['pages'],\n host: string,\n): SitemapData {\n const slash = checkSlash(host)\n\n const urls: Array<SitemapUrl> = pages\n .filter((page) => {\n return page.sitemap?.exclude !== true\n })\n .map((page) => ({\n loc: `${host}${slash}${page.path.replace(/^\\/+/g, '')}`,\n lastmod: page.sitemap?.lastmod\n ? new Date(page.sitemap.lastmod).toISOString().split('T')[0]!\n : new Date().toISOString().split('T')[0]!,\n priority: page.sitemap?.priority,\n changefreq: page.sitemap?.changefreq,\n alternateRefs: page.sitemap?.alternateRefs,\n images: page.sitemap?.images,\n news: page.sitemap?.news,\n }))\n\n return { urls }\n}\n\nfunction jsonToXml(sitemapData: SitemapData): string {\n const sitemap = createXml('urlset')\n\n for (const item of sitemapData.urls) {\n const page = sitemap.ele('url')\n page.ele('loc').txt(item.loc)\n page.ele('lastmod').txt(item.lastmod)\n\n if (item.priority !== undefined) {\n page.ele('priority').txt(item.priority.toString())\n }\n if (item.changefreq) {\n page.ele('changefreq').txt(item.changefreq)\n }\n\n // Add alternate references\n if (item.alternateRefs?.length) {\n for (const ref of item.alternateRefs) {\n const alternateRef = page.ele('xhtml:link')\n alternateRef.att('rel', 'alternate')\n alternateRef.att('href', ref.href)\n if (ref.hreflang) {\n alternateRef.att('hreflang', ref.hreflang)\n }\n }\n }\n\n // Add images\n if (item.images?.length) {\n for (const image of item.images) {\n const imageElement = page.ele('image:image')\n imageElement.ele('image:loc').txt(image.loc)\n if (image.title) {\n imageElement.ele('image:title').txt(image.title)\n }\n if (image.caption) {\n imageElement.ele('image:caption').txt(image.caption)\n }\n }\n }\n\n // Add news\n if (item.news) {\n const newsElement = page.ele('news:news')\n const publication = newsElement.ele('news:publication')\n publication.ele('news:name').txt(item.news.publication.name)\n publication.ele('news:language').txt(item.news.publication.language)\n newsElement\n .ele('news:publication_date')\n .txt(new Date(item.news.publicationDate).toISOString().split('T')[0]!)\n newsElement.ele('news:title').txt(item.news.title)\n }\n }\n\n return sitemap.end({ prettyPrint: true })\n}\n\nexport function buildSitemap({\n startConfig,\n publicDir,\n}: {\n startConfig: TanStackStartOutputConfig\n publicDir: string\n}) {\n const logger = createLogger('sitemap')\n\n let sitemapOptions = startConfig.sitemap\n\n if (!sitemapOptions && startConfig.pages.length) {\n sitemapOptions = { enabled: true, outputPath: 'sitemap.xml' }\n }\n\n if (!sitemapOptions?.enabled) {\n throw new Error('Sitemap is not enabled')\n }\n\n const { host, outputPath } = sitemapOptions\n\n if (!host) {\n if (!startConfig.sitemap) {\n logger.info(\n 'Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option.',\n )\n return\n }\n throw new Error(\n 'Sitemap host is not set and required to build the sitemap.',\n )\n }\n\n if (!outputPath) {\n throw new Error('Sitemap output path is not set')\n }\n\n const { pages } = startConfig\n\n if (!pages.length) {\n logger.info('No pages were found to build the sitemap. Skipping...')\n return\n }\n\n logger.info('Building Sitemap...')\n\n // Build the sitemap data\n const sitemapData = buildSitemapJson(pages, host)\n\n // Generate output paths\n const xmlOutputPath = path.join(publicDir, outputPath)\n const pagesOutputPath = path.join(publicDir, 'pages.json')\n\n try {\n // Write XML sitemap\n logger.info(`Writing sitemap XML at ${xmlOutputPath}`)\n writeFileSync(xmlOutputPath, jsonToXml(sitemapData))\n\n // Write pages data for runtime use\n logger.info(`Writing pages data at ${pagesOutputPath}`)\n writeFileSync(\n pagesOutputPath,\n JSON.stringify(\n {\n pages,\n host,\n lastBuilt: new Date().toISOString(),\n },\n null,\n 2,\n ),\n )\n } catch (e) {\n logger.error(`Unable to write sitemap files`, e)\n }\n}\n\nfunction createXml(elementName: 'urlset' | 'sitemapindex'): XMLBuilder {\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, {\n xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',\n 'xmlns:xhtml': 'http://www.w3.org/1999/xhtml',\n })\n .com(`This file was automatically generated by TanStack Start.`)\n}\n\nfunction checkSlash(host: string): string {\n const finalChar = host.slice(-1)\n return finalChar === '/' ? '' : '/'\n}\n"],"mappings":";;;;;AA0CA,SAAS,iBACP,OACA,MACa;CAC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CACtD,MAAM,kBAAkB,KAAK,KAAK,WAAW,aAAa;AAE1D,KAAI;AAEF,SAAO,KAAK,0BAA0B,gBAAgB;AACtD,gBAAc,eAAe,UAAU,YAAY,CAAC;AAGpD,SAAO,KAAK,yBAAyB,kBAAkB;AACvD,gBACE,iBACA,KAAK,UACH;GACE;GACA;GACA,4BAAW,IAAI,MAAM,EAAC,aAAa;GACpC,EACD,MACA,EACD,CACF;UACM,GAAG;AACV,SAAO,MAAM,iCAAiC,EAAE;;;AAIpD,SAAS,UAAU,aAAoD;AACrE,QAAO,OAAO;EAAE,SAAS;EAAO,UAAU;EAAS,CAAC,CACjD,IAAI,aAAa;EAChB,OAAO;EACP,eAAe;EAChB,CAAC,CACD,IAAI,2DAA2D;;AAGpE,SAAS,WAAW,MAAsB;AAExC,QADkB,KAAK,MAAM,GAAG,KACX,MAAM,KAAK"}
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
client: "client"
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
var VITE_ENVIRONMENT_NAMES = {
|
|
3
|
+
server: "ssr",
|
|
4
|
+
client: "client"
|
|
6
5
|
};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
router: "#tanstack-router-entry"
|
|
6
|
+
var ENTRY_POINTS = {
|
|
7
|
+
client: "virtual:tanstack-start-client-entry",
|
|
8
|
+
server: "virtual:tanstack-start-server-entry",
|
|
9
|
+
start: "#tanstack-start-entry",
|
|
10
|
+
router: "#tanstack-router-entry"
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
VITE_ENVIRONMENT_NAMES
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=constants.js.map
|
|
12
|
+
var SERVER_FN_LOOKUP = "server-fn-module-lookup";
|
|
13
|
+
var TRANSFORM_ID_REGEX = [/\.[cm]?[tj]sx?($|\?)/];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { ENTRY_POINTS, SERVER_FN_LOOKUP, TRANSFORM_ID_REGEX, VITE_ENVIRONMENT_NAMES };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["export const VITE_ENVIRONMENT_NAMES = {\n // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility\n // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)\n server: 'ssr',\n client: 'client',\n} as const\n\nexport type ViteEnvironmentNames =\n (typeof VITE_ENVIRONMENT_NAMES)[keyof typeof VITE_ENVIRONMENT_NAMES]\n\n// for client and router:\n// if a user has a custom server/client entry point file, resolve.alias will point to this\n// otherwise it will be aliased to the default entry point in the respective framework plugin\nexport const ENTRY_POINTS = {\n client: 'virtual:tanstack-start-client-entry',\n server: 'virtual:tanstack-start-server-entry',\n // the start entry point must always be provided by the user\n start: '#tanstack-start-entry',\n router: '#tanstack-router-entry',\n} as const\n\nexport const SERVER_FN_LOOKUP = 'server-fn-module-lookup'\n\n// matches\n// .ts, .tsx, .cts, .mts, .js, .jsx, .cjs, .mjs\n// with optional query params after\n// but not .json\nexport const TRANSFORM_ID_REGEX = [/\\.[cm]?[tj]sx?($|\\?)/]\n"],"
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../src/constants.ts"],"sourcesContent":["export const VITE_ENVIRONMENT_NAMES = {\n // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility\n // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)\n server: 'ssr',\n client: 'client',\n} as const\n\nexport type ViteEnvironmentNames =\n (typeof VITE_ENVIRONMENT_NAMES)[keyof typeof VITE_ENVIRONMENT_NAMES]\n\n// for client and router:\n// if a user has a custom server/client entry point file, resolve.alias will point to this\n// otherwise it will be aliased to the default entry point in the respective framework plugin\nexport const ENTRY_POINTS = {\n client: 'virtual:tanstack-start-client-entry',\n server: 'virtual:tanstack-start-server-entry',\n // the start entry point must always be provided by the user\n start: '#tanstack-start-entry',\n router: '#tanstack-router-entry',\n} as const\n\nexport const SERVER_FN_LOOKUP = 'server-fn-module-lookup'\n\n// matches\n// .ts, .tsx, .cts, .mts, .js, .jsx, .cjs, .mjs\n// with optional query params after\n// but not .json\nexport const TRANSFORM_ID_REGEX = [/\\.[cm]?[tj]sx?($|\\?)/]\n"],"mappings":";AAAA,IAAa,yBAAyB;CAGpC,QAAQ;CACR,QAAQ;CACT;AAQD,IAAa,eAAe;CAC1B,QAAQ;CACR,QAAQ;CAER,OAAO;CACP,QAAQ;CACT;AAED,IAAa,mBAAmB;AAMhC,IAAa,qBAAqB,CAAC,uBAAuB"}
|