@easy-web/core 1.6.0 → 1.7.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 +58 -1
- package/dist/seo/build-info-manifest.d.ts +45 -0
- package/dist/seo/build-info-manifest.d.ts.map +1 -0
- package/dist/seo/build-info-manifest.js +39 -0
- package/dist/seo/build-info-manifest.js.map +1 -0
- package/dist/seo/build-info.d.ts +3 -0
- package/dist/seo/build-info.d.ts.map +1 -0
- package/dist/seo/build-info.js +45 -0
- package/dist/seo/build-info.js.map +1 -0
- package/dist/seo/index.d.ts +4 -0
- package/dist/seo/index.d.ts.map +1 -1
- package/dist/seo/index.js +25 -2
- package/dist/seo/index.js.map +1 -1
- package/dist/seo/routes/robots-txt.d.ts.map +1 -1
- package/dist/seo/routes/robots-txt.js +3 -1
- package/dist/seo/routes/robots-txt.js.map +1 -1
- package/dist/seo/routes/version-json.d.ts +4 -0
- package/dist/seo/routes/version-json.d.ts.map +1 -0
- package/dist/seo/routes/version-json.js +11 -0
- package/dist/seo/routes/version-json.js.map +1 -0
- package/package.json +1 -1
- package/src/seo/__tests__/build-info-html.test.ts +19 -0
- package/src/seo/__tests__/build-info-integration.test.ts +107 -0
- package/src/seo/__tests__/build-info.test.ts +86 -0
- package/src/seo/__tests__/robots-txt.test.ts +8 -0
- package/src/seo/build-info-manifest.ts +49 -0
- package/src/seo/build-info.ts +44 -0
- package/src/seo/index.ts +28 -3
- package/src/seo/routes/robots-txt.ts +3 -1
- package/src/seo/routes/version-json.ts +13 -0
- package/src/seo/routes/version.astro +42 -0
package/README.md
CHANGED
|
@@ -20,6 +20,63 @@ The base package for the `@easy-web/*` family. It owns the shared content contra
|
|
|
20
20
|
|
|
21
21
|
Four concerns remain separate because they depend on a specific platform or runtime: `@easy-web/swa` for Azure Static Web Apps, the `cms-adapters` package for Decap CMS, `@easy-web/auth` for React and MSAL authentication, and `@easy-web/brand` for brand tooling.
|
|
22
22
|
|
|
23
|
+
## Public build information (opt-in)
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import easyWebSeo from '@easy-web/core/seo';
|
|
27
|
+
|
|
28
|
+
easyWebSeo({
|
|
29
|
+
buildInfo: {
|
|
30
|
+
site: 'Public site name',
|
|
31
|
+
packages: ['cms-adapters', 'swa'],
|
|
32
|
+
releaseId: 'public-release-label',
|
|
33
|
+
json: true,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`buildInfo` accepts `site`, optional `packages`, optional `releaseId`, and optional
|
|
39
|
+
`json`. The HTML route is the safe default. Set `json: true` only when the deployment
|
|
40
|
+
host can preserve a path-specific `X-Robots-Tag` response header for `/version.json`.
|
|
41
|
+
Labels must already be trimmed, printable text of 1–120 UTF-16 code units, with
|
|
42
|
+
no controls or invisible formatting characters. Supply only deliberately public
|
|
43
|
+
labels: validation cannot determine whether a label contains a secret.
|
|
44
|
+
`releaseId` is an optional opaque public label, not an automatically collected
|
|
45
|
+
commit, pipeline identifier or timestamp.
|
|
46
|
+
|
|
47
|
+
Allowed package IDs are `core`, `auth`, `cms-adapters`, and `swa`. Core is always
|
|
48
|
+
included; selections are deduplicated and sorted. The integration reads core's
|
|
49
|
+
own package artifact and resolves enabled add-on manifests from the site's Node
|
|
50
|
+
package search paths at configuration time, without executing their code. Missing,
|
|
51
|
+
invalid or differently versioned add-ons fail the build. Package ranges from the
|
|
52
|
+
site manifest are never reported. UI components are not independently versioned.
|
|
53
|
+
|
|
54
|
+
`/version` is always prerendered as standalone English HTML using core
|
|
55
|
+
components/tokens without hydration. `/version.json` is also prerendered only
|
|
56
|
+
when `json: true`. Their shared manifest has this
|
|
57
|
+
closed shape (the version below is illustrative):
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{"schema":"easy-web/build-info","schemaVersion":1,"site":"Public site name","easyWeb":{"version":"1.2.3","packages":["core"]}}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
JSON is compact with a final newline; when supplied, `releaseId` appears after
|
|
64
|
+
`site`. No framework/runtime/third-party inventory, host details, environment,
|
|
65
|
+
build time or arbitrary metadata is collected. HTML escapes the public labels.
|
|
66
|
+
Both routes are excluded from the sitemap. Public `robots.txt` deliberately does
|
|
67
|
+
not disallow them: a crawler must be able to fetch a route before it can observe
|
|
68
|
+
its `noindex` directive. Site-wide `noIndex` remains one global rule. HTML always includes
|
|
69
|
+
`<meta name="robots" content="noindex,nofollow">`. The optional JSON response sets
|
|
70
|
+
`application/json; charset=utf-8`, `Cache-Control: no-store`,
|
|
71
|
+
`X-Content-Type-Options: nosniff` and
|
|
72
|
+
`X-Robots-Tag: noindex, nofollow` where Astro/the deployment preserves response
|
|
73
|
+
headers. Ordinary static file hosts do not retain endpoint response headers
|
|
74
|
+
automatically, which is why JSON generation is off by default. This integration
|
|
75
|
+
does not modify deployment-platform configuration.
|
|
76
|
+
|
|
77
|
+
These routes are intentionally public. Robots rules and noindex are **not access
|
|
78
|
+
control**. Omitting `buildInfo` injects neither route and retains prior crawl output.
|
|
79
|
+
|
|
23
80
|
## Recipe protocol version 1
|
|
24
81
|
|
|
25
82
|
Recipes declare `provides`, `requires`, `conflicts`, compatibility ranges, output
|
|
@@ -58,4 +115,4 @@ Only a money-enabled selection accepts `currency`, validated by the shared ISO
|
|
|
58
115
|
4217 input schema. `homepage` requires `featured`, so a type cannot occupy that
|
|
59
116
|
featured presentation slot merely by defining an image.
|
|
60
117
|
|
|
61
|
-
This package is
|
|
118
|
+
This package is published as part of the fixed `@easy-web/*` family through the Changesets and npm Trusted Publishing workflow.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'astro/zod';
|
|
2
|
+
declare const packageIdSchema: z.ZodEnum<{
|
|
3
|
+
core: "core";
|
|
4
|
+
auth: "auth";
|
|
5
|
+
"cms-adapters": "cms-adapters";
|
|
6
|
+
swa: "swa";
|
|
7
|
+
}>;
|
|
8
|
+
export declare const buildInfoOptionsSchema: z.ZodReadonly<z.ZodObject<{
|
|
9
|
+
site: z.ZodString;
|
|
10
|
+
packages: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
11
|
+
core: "core";
|
|
12
|
+
auth: "auth";
|
|
13
|
+
"cms-adapters": "cms-adapters";
|
|
14
|
+
swa: "swa";
|
|
15
|
+
}>>>>;
|
|
16
|
+
releaseId: z.ZodOptional<z.ZodString>;
|
|
17
|
+
json: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
+
}, z.core.$strict>>;
|
|
19
|
+
export type BuildInfoPackageId = z.infer<typeof packageIdSchema>;
|
|
20
|
+
export type BuildInfoOptions = z.infer<typeof buildInfoOptionsSchema>;
|
|
21
|
+
export declare const exactVersionSchema: z.ZodString;
|
|
22
|
+
declare const manifestSchema: z.ZodReadonly<z.ZodObject<{
|
|
23
|
+
schema: z.ZodLiteral<"easy-web/build-info">;
|
|
24
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
25
|
+
site: z.ZodString;
|
|
26
|
+
releaseId: z.ZodOptional<z.ZodString>;
|
|
27
|
+
easyWeb: z.ZodReadonly<z.ZodObject<{
|
|
28
|
+
version: z.ZodString;
|
|
29
|
+
packages: z.ZodReadonly<z.ZodArray<z.ZodEnum<{
|
|
30
|
+
core: "core";
|
|
31
|
+
auth: "auth";
|
|
32
|
+
"cms-adapters": "cms-adapters";
|
|
33
|
+
swa: "swa";
|
|
34
|
+
}>>>;
|
|
35
|
+
}, z.core.$strict>>;
|
|
36
|
+
}, z.core.$strict>>;
|
|
37
|
+
export type BuildInfoManifest = z.infer<typeof manifestSchema>;
|
|
38
|
+
export declare class BuildInfoError extends Error {
|
|
39
|
+
readonly detail: string;
|
|
40
|
+
constructor(detail: string);
|
|
41
|
+
}
|
|
42
|
+
export declare function serializeBuildInfo(manifest: BuildInfoManifest): string;
|
|
43
|
+
export declare function readBuildInfo(): BuildInfoManifest;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=build-info-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-info-manifest.d.ts","sourceRoot":"","sources":["../../src/seo/build-info-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,WAAW,CAAC;AAE9B,QAAA,MAAM,eAAe;;;;;EAAkD,CAAC;AAIxE,eAAO,MAAM,sBAAsB;;;;;;;;;;mBAKtB,CAAC;AAEd,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE,eAAO,MAAM,kBAAkB,aAE9B,CAAC;AAEF,QAAA,MAAM,cAAc;;;;;;;;;;;;;;mBASP,CAAC;AAEd,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE/D,qBAAa,cAAe,SAAQ,KAAK;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;CAItC;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAEtE;AAED,wBAAgB,aAAa,IAAI,iBAAiB,CAIjD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from 'astro/zod';
|
|
2
|
+
const packageIdSchema = z.enum(['core', 'auth', 'cms-adapters', 'swa']);
|
|
3
|
+
const publicLabelSchema = z.string().min(1).max(120)
|
|
4
|
+
.refine((value) => value === value.trim() && !/[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u.test(value), 'must be trimmed printable text');
|
|
5
|
+
export const buildInfoOptionsSchema = z.strictObject({
|
|
6
|
+
site: publicLabelSchema,
|
|
7
|
+
packages: z.array(packageIdSchema).readonly().optional(),
|
|
8
|
+
releaseId: publicLabelSchema.optional(),
|
|
9
|
+
json: z.boolean().optional(),
|
|
10
|
+
}).readonly();
|
|
11
|
+
export const exactVersionSchema = z.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/);
|
|
12
|
+
const manifestSchema = z.strictObject({
|
|
13
|
+
schema: z.literal('easy-web/build-info'),
|
|
14
|
+
schemaVersion: z.literal(1),
|
|
15
|
+
site: publicLabelSchema,
|
|
16
|
+
releaseId: publicLabelSchema.optional(),
|
|
17
|
+
easyWeb: z.strictObject({
|
|
18
|
+
version: exactVersionSchema,
|
|
19
|
+
packages: z.array(packageIdSchema).readonly(),
|
|
20
|
+
}).readonly(),
|
|
21
|
+
}).readonly();
|
|
22
|
+
export class BuildInfoError extends Error {
|
|
23
|
+
detail;
|
|
24
|
+
constructor(detail) {
|
|
25
|
+
super(`@easy-web/core: buildInfo ${detail}`);
|
|
26
|
+
this.detail = detail;
|
|
27
|
+
this.name = 'BuildInfoError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function serializeBuildInfo(manifest) {
|
|
31
|
+
return `${JSON.stringify(manifest)}\n`;
|
|
32
|
+
}
|
|
33
|
+
export function readBuildInfo() {
|
|
34
|
+
const serialized = process.env.EASY_WEB_SEO_BUILD_INFO;
|
|
35
|
+
if (!serialized)
|
|
36
|
+
throw new BuildInfoError('manifest is unavailable; enable easyWebSeo({ buildInfo }).');
|
|
37
|
+
return manifestSchema.parse(JSON.parse(serialized));
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=build-info-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-info-manifest.js","sourceRoot":"","sources":["../../src/seo/build-info-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAA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C,CAAC,QAAQ,EAAE;CAChB,CAAC,CAAC,QAAQ,EAAE,CAAC;AAId,MAAM,OAAO,cAAe,SAAQ,KAAK;IAChB;IAArB,YAAqB,MAAc;QAC/B,KAAK,CAAC,6BAA6B,MAAM,EAAE,CAAC,CAAC;QAD5B,WAAM,GAAN,MAAM,CAAQ;QAE/B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IACjC,CAAC;CACJ;AAED,MAAM,UAAU,kBAAkB,CAAC,QAA2B;IAC1D,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,aAAa;IACzB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACvD,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,cAAc,CAAC,4DAA4D,CAAC,CAAC;IACxG,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-info.d.ts","sourceRoot":"","sources":["../../src/seo/build-info.ts"],"names":[],"mappings":"AAIA,OAAO,EAEH,KAAK,iBAAiB,EACzB,MAAM,0BAA0B,CAAC;AAmBlC,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,GAAG,iBAAiB,CAiB9E"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { z } from 'astro/zod';
|
|
5
|
+
import { BuildInfoError, buildInfoOptionsSchema, exactVersionSchema, } from './build-info-manifest.js';
|
|
6
|
+
const packageSchema = z.object({ name: z.string(), version: exactVersionSchema });
|
|
7
|
+
function installedPackage(id, root) {
|
|
8
|
+
const name = `@easy-web/${id}`;
|
|
9
|
+
let folder = fileURLToPath(root);
|
|
10
|
+
let manifestPath = join(folder, 'node_modules', name, 'package.json');
|
|
11
|
+
while (!existsSync(manifestPath)) {
|
|
12
|
+
const parent = dirname(folder);
|
|
13
|
+
if (parent === folder)
|
|
14
|
+
throw new BuildInfoError(`${name} must be installed in the site before it can be enabled.`);
|
|
15
|
+
folder = parent;
|
|
16
|
+
manifestPath = join(folder, 'node_modules', name, 'package.json');
|
|
17
|
+
}
|
|
18
|
+
const result = packageSchema.safeParse(JSON.parse(readFileSync(manifestPath, 'utf8')));
|
|
19
|
+
if (!result.success || result.data.name !== name)
|
|
20
|
+
throw new BuildInfoError(`${name} artifact must contain its package identity and an exact version.`);
|
|
21
|
+
return result.data;
|
|
22
|
+
}
|
|
23
|
+
export function buildInfoManifest(input, root) {
|
|
24
|
+
const parsed = buildInfoOptionsSchema.safeParse(input);
|
|
25
|
+
if (!parsed.success)
|
|
26
|
+
throw new BuildInfoError(`options are invalid: ${parsed.error.message}`);
|
|
27
|
+
const options = parsed.data;
|
|
28
|
+
const core = packageSchema.parse(JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')));
|
|
29
|
+
if (core.name !== '@easy-web/core')
|
|
30
|
+
throw new BuildInfoError('core artifact identity is invalid.');
|
|
31
|
+
const packages = Object.freeze([...new Set(['core', ...(options.packages ?? [])])].sort());
|
|
32
|
+
for (const id of packages) {
|
|
33
|
+
if (id === 'core')
|
|
34
|
+
continue;
|
|
35
|
+
const installed = installedPackage(id, root);
|
|
36
|
+
if (installed.version !== core.version)
|
|
37
|
+
throw new BuildInfoError(`${installed.name} version must match core version ${core.version}.`);
|
|
38
|
+
}
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
schema: 'easy-web/build-info', schemaVersion: 1, site: options.site,
|
|
41
|
+
...(options.releaseId === undefined ? {} : { releaseId: options.releaseId }),
|
|
42
|
+
easyWeb: Object.freeze({ version: core.version, packages }),
|
|
43
|
+
});
|
|
44
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AAM,IAAI,cAAc,CAAC,GAAG,SAAS,CAAC,IAAI,oCAAoC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IAC3I,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,MAAM,EAAE,qBAAqB,EAAE,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI;QACnE,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;QAC5E,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;KAC9D,CAAC,CAAC;AACP,CAAC"}
|
package/dist/seo/index.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { AstroIntegration } from 'astro';
|
|
2
2
|
import { type LocalizedPathGroup } from '../i18n/index.js';
|
|
3
|
+
import { type BuildInfoOptions } from './build-info-manifest.js';
|
|
4
|
+
export type { BuildInfoOptions, BuildInfoPackageId, BuildInfoManifest } from './build-info-manifest.js';
|
|
3
5
|
export type { LocalizedPathGroup };
|
|
4
6
|
export type Options = {
|
|
7
|
+
/** Public labels only; these routes are public, not protected by crawler directives. */
|
|
8
|
+
readonly buildInfo?: BuildInfoOptions;
|
|
5
9
|
noIndex?: boolean;
|
|
6
10
|
sitemapLocales?: Record<string, string>;
|
|
7
11
|
/**
|
package/dist/seo/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,gBAAgB,EAAE,MAAM,OAAO,CAAA;AAE1D,OAAO,EAIL,KAAK,kBAAkB,EAExB,MAAM,kBAAkB,CAAA;AAIzB,YAAY,EAAE,kBAAkB,EAAE,CAAA;A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GED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import sitemap from '@astrojs/sitemap';
|
|
2
2
|
import { normalizeLocalizedPath, toServedPath, validateLocalizedPaths, } from '../i18n/index.js';
|
|
3
3
|
import { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js';
|
|
4
|
+
import { buildInfoManifest } from './build-info.js';
|
|
5
|
+
import { buildInfoOptionsSchema, serializeBuildInfo } from './build-info-manifest.js';
|
|
4
6
|
function localeIdsOf(config) {
|
|
5
7
|
return (config.i18n?.locales ?? []).map((locale) => typeof locale === 'string' ? locale : locale.path);
|
|
6
8
|
}
|
|
@@ -38,6 +40,9 @@ function pathnameOf(page, config) {
|
|
|
38
40
|
}
|
|
39
41
|
return pathname;
|
|
40
42
|
}
|
|
43
|
+
function isBuildInfoPath(pathname) {
|
|
44
|
+
return pathname === '/version' || pathname === '/version.json';
|
|
45
|
+
}
|
|
41
46
|
export default function easyWebSeo(options = {}) {
|
|
42
47
|
return {
|
|
43
48
|
name: '@easy-web/seo',
|
|
@@ -49,6 +54,13 @@ export default function easyWebSeo(options = {}) {
|
|
|
49
54
|
throw new Error('@easy-web/seo: `site` is required in astro.config.mjs');
|
|
50
55
|
}
|
|
51
56
|
const noIndex = options.noIndex ?? false;
|
|
57
|
+
const buildInfoOptions = options.buildInfo === undefined ? undefined : buildInfoOptionsSchema.parse(options.buildInfo);
|
|
58
|
+
const manifest = buildInfoOptions === undefined ? undefined : buildInfoManifest(buildInfoOptions, config.root);
|
|
59
|
+
if (manifest)
|
|
60
|
+
process.env.EASY_WEB_SEO_BUILD_INFO = serializeBuildInfo(manifest);
|
|
61
|
+
else
|
|
62
|
+
delete process.env.EASY_WEB_SEO_BUILD_INFO;
|
|
63
|
+
process.env.EASY_WEB_SEO_BUILD_INFO_JSON = String(buildInfoOptions?.json === true);
|
|
52
64
|
const policy = createCrawlPolicy(noIndex);
|
|
53
65
|
let sitemapI18n;
|
|
54
66
|
if (config.i18n && config.i18n.locales.length > 0) {
|
|
@@ -99,8 +111,12 @@ export default function easyWebSeo(options = {}) {
|
|
|
99
111
|
const sitemapIntegration = sitemap({
|
|
100
112
|
...(sitemapI18n ? { i18n: sitemapI18n } : {}),
|
|
101
113
|
namespaces: { xhtml: true },
|
|
102
|
-
filter: (page) =>
|
|
103
|
-
(
|
|
114
|
+
filter: (page) => {
|
|
115
|
+
const pathname = pathnameOf(page, config);
|
|
116
|
+
return !isDisallowedPath(pathname, policy) &&
|
|
117
|
+
!(manifest && isBuildInfoPath(pathname)) &&
|
|
118
|
+
(options.filter?.(page) ?? true);
|
|
119
|
+
},
|
|
104
120
|
serialize: (item) => {
|
|
105
121
|
// Re-render every <loc> through the same helper that produces the
|
|
106
122
|
// canonical, so the two agree byte-for-byte. @astrojs/sitemap
|
|
@@ -154,6 +170,7 @@ export default function easyWebSeo(options = {}) {
|
|
|
154
170
|
updateConfig({ integrations: [sitemapIntegration, validatorIntegration] });
|
|
155
171
|
}
|
|
156
172
|
process.env.EASY_WEB_SEO_NO_INDEX = String(noIndex);
|
|
173
|
+
process.env.EASY_WEB_SEO_BASE = config.base;
|
|
157
174
|
// <SeoHead> is a component and cannot read astro.config, so the style
|
|
158
175
|
// the sitemap uses is published here for it to reuse. Both surfaces
|
|
159
176
|
// therefore derive the canonical URL form from one resolver.
|
|
@@ -163,6 +180,12 @@ export default function easyWebSeo(options = {}) {
|
|
|
163
180
|
entrypoint: new URL('./routes/robots-txt.js', import.meta.url),
|
|
164
181
|
prerender: true,
|
|
165
182
|
});
|
|
183
|
+
if (manifest) {
|
|
184
|
+
injectRoute({ pattern: '/version', entrypoint: new URL('../../src/seo/routes/version.astro', import.meta.url), prerender: true });
|
|
185
|
+
if (buildInfoOptions?.json === true) {
|
|
186
|
+
injectRoute({ pattern: '/version.json', entrypoint: new URL('./routes/version-json.js', import.meta.url), prerender: true });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
166
189
|
},
|
|
167
190
|
},
|
|
168
191
|
};
|
package/dist/seo/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,kBAAkB,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,sBAAsB,GAGvB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/seo/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,kBAAkB,CAAA;AACtC,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,sBAAsB,GAGvB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAyB,MAAM,0BAA0B,CAAA;AA8B5G,SAAS,WAAW,CAAC,MAAmB;IACtC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACjD,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAClD,CAAA;AACH,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAAmB,EACnB,MAAwC;IAExC,8EAA8E;IAC9E,8EAA8E;IAC9E,yBAAyB;IACzB,IAAI,MAAM,CAAC,aAAa,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAA;IACtD,IAAI,MAAM,CAAC,aAAa,KAAK,OAAO;QAAE,OAAO,OAAO,CAAA;IAEpD,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO,OAAO,CAAA;IAClD,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,GAAG,CAAC,2BAA2B,GAAG,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;gBAE9E,WAAW,CAAC;oBACV,OAAO,EAAE,aAAa;oBACtB,UAAU,EAAE,IAAI,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;oBAC9D,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAA;gBACF,IAAI,QAAQ,EAAE,CAAC;oBACb,WAAW,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,GAAG,CAAC,oCAAoC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;oBACjI,IAAI,gBAAgB,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;wBACpC,WAAW,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,IAAI,GAAG,CAAC,0BAA0B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;oBAC9H,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC;AAED,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAoB,MAAM,mBAAmB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"robots-txt.d.ts","sourceRoot":"","sources":["../../../src/seo/routes/robots-txt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"robots-txt.d.ts","sourceRoot":"","sources":["../../../src/seo/routes/robots-txt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAwBrC,eAAO,MAAM,GAAG,EAAE,QAajB,CAAA"}
|
|
@@ -8,8 +8,10 @@ function render(policy, site) {
|
|
|
8
8
|
lines.push(`Allow: ${path}`);
|
|
9
9
|
}
|
|
10
10
|
if (policy.sitemap && site) {
|
|
11
|
+
const configuredBase = process.env.EASY_WEB_SEO_BASE ?? '/';
|
|
12
|
+
const base = `/${configuredBase.replace(/^\/+|\/+$/g, '')}`.replace(/^\/$/, '');
|
|
11
13
|
lines.push('');
|
|
12
|
-
lines.push(`Sitemap: ${new URL(
|
|
14
|
+
lines.push(`Sitemap: ${new URL(`${base}/sitemap-index.xml`, site).href}`);
|
|
13
15
|
}
|
|
14
16
|
return `${lines.join('\n')}\n`;
|
|
15
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"robots-txt.js","sourceRoot":"","sources":["../../../src/seo/routes/robots-txt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,oBAAoB,CAAA;AAExE,SAAS,MAAM,CAAC,MAAmB,EAAE,IAAqB;IACxD,MAAM,KAAK,GAAG,CAAC,eAAe,CAAC,CAAA;IAE/B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACnC,KAAK,CAAC,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC,CAAA;IACjC,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAA;IAC9B,CAAC;IAED,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;QAC3B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,CAAC,YAAY,IAAI,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"robots-txt.js","sourceRoot":"","sources":["../../../src/seo/routes/robots-txt.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,oBAAoB,CAAA;AAExE,SAAS,MAAM,CAAC,MAAmB,EAAE,IAAqB;IACxD,M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E9E,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE;QACxC,OAAO,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE;KACzD,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-json.d.ts","sourceRoot":"","sources":["../../../src/seo/routes/version-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtC,eAAO,MAAM,SAAS,OAAO,CAAC;AAE9B,eAAO,MAAM,GAAG,EAAE,QAOhB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readBuildInfo, serializeBuildInfo } from '../build-info-manifest.js';
|
|
2
|
+
export const prerender = true;
|
|
3
|
+
export const GET = () => new Response(serializeBuildInfo(readBuildInfo()), {
|
|
4
|
+
headers: {
|
|
5
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
6
|
+
'Cache-Control': 'no-store',
|
|
7
|
+
'X-Content-Type-Options': 'nosniff',
|
|
8
|
+
'X-Robots-Tag': 'noindex, nofollow',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=version-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-json.js","sourceRoot":"","sources":["../../../src/seo/routes/version-json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE9E,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAE9B,MAAM,CAAC,MAAM,GAAG,GAAa,GAAG,EAAE,CAAC,IAAI,QAAQ,CAAC,kBAAkB,CAAC,aAAa,EAAE,CAAC,EAAE;IACjF,OAAO,EAAE;QACL,cAAc,EAAE,iCAAiC;QACjD,eAAe,EAAE,UAAU;QAC3B,wBAAwB,EAAE,SAAS;QACnC,cAAc,EAAE,mBAAmB;KACtC;CACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { experimental_AstroContainer as AstroContainer } from 'astro/container';
|
|
2
|
+
import { afterEach, expect, it, vi } from 'vitest';
|
|
3
|
+
import VersionPage from '../routes/version.astro';
|
|
4
|
+
|
|
5
|
+
afterEach(() => vi.unstubAllEnvs());
|
|
6
|
+
|
|
7
|
+
it('renders escaped manifest values in an accessible zero-hydration document', async () => {
|
|
8
|
+
// Given a manifest whose public labels need HTML escaping
|
|
9
|
+
vi.stubEnv('EASY_WEB_SEO_BUILD_INFO', JSON.stringify({ schema: 'easy-web/build-info', schemaVersion: 1, site: '<script>alert(1)</script>', releaseId: 'release<&>', easyWeb: { version: '1.2.3', packages: ['core'] } }));
|
|
10
|
+
const container = await AstroContainer.create();
|
|
11
|
+
// When rendering the actual shipped route
|
|
12
|
+
const html = await container.renderToString(VersionPage);
|
|
13
|
+
// Then structured document semantics and safe text survive without client code
|
|
14
|
+
expect(html).toMatch(/<meta name="robots" content="noindex,nofollow"/);
|
|
15
|
+
expect(html).toMatch(/<h1[^>]*>Build information<\/h1>/);
|
|
16
|
+
expect(html).toContain('<script>');
|
|
17
|
+
expect(html).toContain('@easy-web/core');
|
|
18
|
+
expect(html).not.toMatch(/<script|astro-island/);
|
|
19
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import easyWebSeo, { type Options } from '../index.js';
|
|
3
|
+
import { GET as robots } from '../routes/robots-txt.js';
|
|
4
|
+
import { GET as version } from '../routes/version-json.js';
|
|
5
|
+
|
|
6
|
+
const { sitemapSpy } = vi.hoisted(() => ({ sitemapSpy: vi.fn() }));
|
|
7
|
+
vi.mock('@astrojs/sitemap', () => ({ default: (options: unknown) => {
|
|
8
|
+
sitemapSpy(options);
|
|
9
|
+
return { name: '@astrojs/sitemap', hooks: {} };
|
|
10
|
+
} }));
|
|
11
|
+
|
|
12
|
+
function setup(options: Options = {}, base = '/') {
|
|
13
|
+
const integration = easyWebSeo(options);
|
|
14
|
+
const injectRoute = vi.fn();
|
|
15
|
+
const hook = integration.hooks['astro:config:setup'];
|
|
16
|
+
if (!hook) throw new Error('Missing setup hook');
|
|
17
|
+
Reflect.apply(hook, undefined, [{
|
|
18
|
+
config: { root: new URL('../../../../../apps/contract-fixture/', import.meta.url), site: 'https://example.com', base, trailingSlash: 'ignore', build: { format: 'directory' }, integrations: [] },
|
|
19
|
+
updateConfig: vi.fn(), injectRoute, logger: { warn: vi.fn(), error: vi.fn() },
|
|
20
|
+
}]);
|
|
21
|
+
return injectRoute;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.unstubAllEnvs();
|
|
26
|
+
delete process.env.EASY_WEB_SEO_BUILD_INFO;
|
|
27
|
+
delete process.env.EASY_WEB_SEO_BUILD_INFO_JSON;
|
|
28
|
+
delete process.env.EASY_WEB_SEO_BASE;
|
|
29
|
+
delete process.env.EASY_WEB_SEO_NO_INDEX;
|
|
30
|
+
delete process.env.EASY_WEB_SEO_TRAILING_SLASH;
|
|
31
|
+
sitemapSpy.mockClear();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('opt-in build-info routes', () => {
|
|
35
|
+
it('injects both routes as prerendered when enabled', () => {
|
|
36
|
+
// Given explicit opt-in
|
|
37
|
+
const options = { buildInfo: { site: 'Public', json: true } };
|
|
38
|
+
// When setting up SEO
|
|
39
|
+
const routes = setup(options).mock.calls.map(([route]) => route);
|
|
40
|
+
// Then Astro receives both static route declarations
|
|
41
|
+
expect(routes).toEqual(expect.arrayContaining([
|
|
42
|
+
expect.objectContaining({ pattern: '/version', prerender: true }),
|
|
43
|
+
expect.objectContaining({ pattern: '/version.json', prerender: true }),
|
|
44
|
+
]));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('serves the exact shared manifest with safe JSON headers', async () => {
|
|
48
|
+
// Given opt-in setup and unrelated private environment state
|
|
49
|
+
vi.stubEnv('PRIVATE_TENANT', 'secret-tenant');
|
|
50
|
+
setup({ buildInfo: { site: 'Public', releaseId: 'release-42', json: true } });
|
|
51
|
+
const expected = process.env.EASY_WEB_SEO_BUILD_INFO;
|
|
52
|
+
// When requesting the machine endpoint
|
|
53
|
+
const response = await Reflect.apply(version, undefined, [{}]);
|
|
54
|
+
// Then bytes match the immutable handoff, with no framework/private additions
|
|
55
|
+
expect(await response.text()).toBe(expected);
|
|
56
|
+
expect(response.headers.get('Content-Type')).toBe('application/json; charset=utf-8');
|
|
57
|
+
expect(response.headers.get('Cache-Control')).toBe('no-store');
|
|
58
|
+
expect(response.headers.get('X-Content-Type-Options')).toBe('nosniff');
|
|
59
|
+
expect(response.headers.get('X-Robots-Tag')).toBe('noindex, nofollow');
|
|
60
|
+
expect(expected).not.toContain('secret-tenant');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('retains prior robots bytes and route set when omitted after an enabled build', async () => {
|
|
64
|
+
// Given an earlier enabled build in the same process
|
|
65
|
+
setup({ buildInfo: { site: 'Earlier' } });
|
|
66
|
+
// When setting up a site without the feature
|
|
67
|
+
const routes = setup().mock.calls.map(([route]) => route.pattern);
|
|
68
|
+
const response = await Reflect.apply(robots, undefined, [{ site: new URL('https://example.com') }]);
|
|
69
|
+
// Then the old public behavior is byte-equivalent and no manifest survives
|
|
70
|
+
expect(routes).toEqual(['/robots.txt']);
|
|
71
|
+
expect(process.env.EASY_WEB_SEO_BUILD_INFO).toBeUndefined();
|
|
72
|
+
expect(await response.text()).toBe('User-agent: *\nDisallow: /admin/\nAllow: /\n\nSitemap: https://example.com/sitemap-index.xml\n');
|
|
73
|
+
const filter = sitemapSpy.mock.lastCall?.[0].filter;
|
|
74
|
+
expect(filter('https://example.com/version/')).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('keeps JSON disabled unless the host explicitly supports its response headers', () => {
|
|
78
|
+
const routes = setup({ buildInfo: { site: 'Public' } }).mock.calls.map(([route]) => route.pattern);
|
|
79
|
+
|
|
80
|
+
expect(routes).toContain('/version');
|
|
81
|
+
expect(routes).not.toContain('/version.json');
|
|
82
|
+
expect(process.env.EASY_WEB_SEO_BUILD_INFO_JSON).toBe('false');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it.each(['/', '/sub/'])('excludes both routes from the sitemap while leaving noindex discoverable under base %s', async (base) => {
|
|
86
|
+
// Given public opt-in with a caller filter that allows everything
|
|
87
|
+
setup({ buildInfo: { site: 'Public' }, filter: () => true }, base);
|
|
88
|
+
// When evaluating sitemap URLs and robots
|
|
89
|
+
const filter = sitemapSpy.mock.lastCall?.[0].filter;
|
|
90
|
+
const response = await Reflect.apply(robots, undefined, [{ site: new URL('https://example.com') }]);
|
|
91
|
+
// Then neither version surface is advertised, but robots does not hide
|
|
92
|
+
// the routes from crawlers that must read their noindex directives.
|
|
93
|
+
for (const route of ['version', 'version/', 'version.json']) expect(filter(`https://example.com${base}${route}`)).toBe(false);
|
|
94
|
+
expect(filter(`https://example.com${base}version-history/`)).toBe(true);
|
|
95
|
+
expect(await response.text()).toBe(`User-agent: *\nDisallow: /admin/\nAllow: /\n\nSitemap: https://example.com${base}sitemap-index.xml\n`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('keeps noIndex policy global without redundant route rules', async () => {
|
|
99
|
+
// Given a wholly unindexed site
|
|
100
|
+
setup({ noIndex: true, buildInfo: { site: 'Public' } });
|
|
101
|
+
// When rendering robots
|
|
102
|
+
const response = await Reflect.apply(robots, undefined, [{ site: new URL('https://example.com') }]);
|
|
103
|
+
// Then the global rule is unchanged
|
|
104
|
+
expect(await response.text()).toBe('User-agent: *\nDisallow: /\n');
|
|
105
|
+
expect(sitemapSpy).not.toHaveBeenCalled();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import { buildInfoManifest } from '../build-info.js';
|
|
7
|
+
import { serializeBuildInfo } from '../build-info-manifest.js';
|
|
8
|
+
|
|
9
|
+
const core = JSON.parse(readFileSync(new URL('../../../package.json', import.meta.url), 'utf8'));
|
|
10
|
+
const roots: string[] = [];
|
|
11
|
+
function fixture(packages: Readonly<Record<string, string>> = {}): URL {
|
|
12
|
+
const root = mkdtempSync(join(tmpdir(), 'easy-web-build-info-'));
|
|
13
|
+
roots.push(root);
|
|
14
|
+
writeFileSync(join(root, 'package.json'), JSON.stringify({ dependencies: { '@easy-web/core': '^0.0.1' } }));
|
|
15
|
+
for (const [id, version] of Object.entries(packages)) {
|
|
16
|
+
const folder = join(root, 'node_modules', '@easy-web', id);
|
|
17
|
+
mkdirSync(folder, { recursive: true });
|
|
18
|
+
writeFileSync(join(folder, 'package.json'), JSON.stringify({ name: `@easy-web/${id}`, version, exports: { '.': { import: './index.js' } } }));
|
|
19
|
+
writeFileSync(join(folder, 'index.js'), 'throw new Error("must not execute packages");');
|
|
20
|
+
}
|
|
21
|
+
return pathToFileURL(`${root}/`);
|
|
22
|
+
}
|
|
23
|
+
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true }); });
|
|
24
|
+
|
|
25
|
+
describe('public build-info manifest', () => {
|
|
26
|
+
it('uses the core artifact version rather than the site dependency range', () => {
|
|
27
|
+
// Given a consumer claiming a different dependency range
|
|
28
|
+
const root = fixture();
|
|
29
|
+
// When building the default manifest
|
|
30
|
+
const manifest = buildInfoManifest({ site: 'Public site' }, root);
|
|
31
|
+
// Then only the exact public contract is emitted
|
|
32
|
+
expect(serializeBuildInfo(manifest)).toBe(`{"schema":"easy-web/build-info","schemaVersion":1,"site":"Public site","easyWeb":{"version":"${core.version}","packages":["core"]}}\n`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('sorts and deduplicates configured packages and freezes every container', () => {
|
|
36
|
+
// Given installed fixed-family add-ons, with no executable code allowed
|
|
37
|
+
const root = fixture({ swa: core.version, auth: core.version, 'cms-adapters': core.version });
|
|
38
|
+
// When options are supplied out of order
|
|
39
|
+
const manifest = buildInfoManifest({ site: 'Public', releaseId: 'release-42', packages: ['swa', 'core', 'auth', 'cms-adapters', 'auth'] }, root);
|
|
40
|
+
// Then a single family version and immutable package selection are published
|
|
41
|
+
expect(manifest).toEqual({ schema: 'easy-web/build-info', schemaVersion: 1, site: 'Public', releaseId: 'release-42', easyWeb: { version: core.version, packages: ['auth', 'cms-adapters', 'core', 'swa'] } });
|
|
42
|
+
expect([manifest, manifest.easyWeb, manifest.easyWeb.packages].every(Object.isFrozen)).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it.each(['brand', 'cli', 'create', 'seo', 'Card', 'react'])('rejects forbidden package %s', (id) => {
|
|
46
|
+
// Given an unsupported package id
|
|
47
|
+
const options = { site: 'Public', packages: [id] };
|
|
48
|
+
// When crossing the configuration boundary, then reject it
|
|
49
|
+
expect(() => buildInfoManifest(options, fixture())).toThrow(/buildInfo/);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it.each(['version', 'metadata', 'timestamp', 'gitSha', 'branch', 'pipelineUrl', 'tenant', 'environment'])('rejects forbidden option %s', (field) => {
|
|
53
|
+
// Given extra data that must never be copied into public output
|
|
54
|
+
const options = { site: 'Public', [field]: 'private' };
|
|
55
|
+
// When crossing the configuration boundary, then reject it
|
|
56
|
+
expect(() => buildInfoManifest(options, fixture())).toThrow(/buildInfo/);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it.each(['', ' leading', 'trailing ', 'line\nbreak', 'tab\t', 'nul\0', '\u007f', '\u0085', '\u202e', 'x'.repeat(121)])('rejects unsafe or unbounded site strings %j', (site) => {
|
|
60
|
+
// Given a non-public-label string
|
|
61
|
+
const root = fixture();
|
|
62
|
+
// When building, then validation fails
|
|
63
|
+
expect(() => buildInfoManifest({ site }, root)).toThrow(/buildInfo/);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it.each(['', ' release', 'release\n42', 'x'.repeat(121)])('rejects unsafe release labels %j', (releaseId) => {
|
|
67
|
+
// Given an invalid optional opaque label
|
|
68
|
+
const root = fixture();
|
|
69
|
+
// When building, then validation fails
|
|
70
|
+
expect(() => buildInfoManifest({ site: 'Public', releaseId }, root)).toThrow(/buildInfo/);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('fails clearly when a configured add-on is not installed', () => {
|
|
74
|
+
// Given a site without auth
|
|
75
|
+
const root = fixture();
|
|
76
|
+
// When enabling auth, then fail instead of claiming it is enabled
|
|
77
|
+
expect(() => buildInfoManifest({ site: 'Public', packages: ['auth'] }, root)).toThrow(/@easy-web\/auth.*installed/);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it.each(['0.0.1', '^1.6.0', 'not-a-version'])('rejects mismatched or inexact installed versions %s', (version) => {
|
|
81
|
+
// Given an incompatible artifact
|
|
82
|
+
const root = fixture({ swa: version });
|
|
83
|
+
// When enabling it, then fixed-family drift is a configuration failure
|
|
84
|
+
expect(() => buildInfoManifest({ site: 'Public', packages: ['swa'] }, root)).toThrow(/@easy-web\/swa.*version/);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -13,6 +13,7 @@ const runGET = (ctx: Partial<APIContext>): Response => {
|
|
|
13
13
|
describe('robots-txt GET handler', () => {
|
|
14
14
|
afterEach(() => {
|
|
15
15
|
delete process.env.EASY_WEB_SEO_NO_INDEX;
|
|
16
|
+
delete process.env.EASY_WEB_SEO_BASE;
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
it('returns public robots.txt with Sitemap when EASY_WEB_SEO_NO_INDEX is "false"', async () => {
|
|
@@ -63,4 +64,11 @@ describe('robots-txt GET handler', () => {
|
|
|
63
64
|
expect(text).toContain('Sitemap: https://example.com/sitemap-index.xml');
|
|
64
65
|
expect(text).toContain('Disallow: /admin/');
|
|
65
66
|
});
|
|
67
|
+
|
|
68
|
+
it('includes Astro base in the sitemap URL', async () => {
|
|
69
|
+
process.env.EASY_WEB_SEO_BASE = '/easy-web/';
|
|
70
|
+
const response = runGET({ site: new URL('https://example.com') });
|
|
71
|
+
|
|
72
|
+
expect(await response.text()).toContain('Sitemap: https://example.com/easy-web/sitemap-index.xml');
|
|
73
|
+
});
|
|
66
74
|
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from 'astro/zod';
|
|
2
|
+
|
|
3
|
+
const packageIdSchema = z.enum(['core', 'auth', 'cms-adapters', 'swa']);
|
|
4
|
+
const publicLabelSchema = z.string().min(1).max(120)
|
|
5
|
+
.refine((value) => value === value.trim() && !/[\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u.test(value), 'must be trimmed printable text');
|
|
6
|
+
|
|
7
|
+
export const buildInfoOptionsSchema = z.strictObject({
|
|
8
|
+
site: publicLabelSchema,
|
|
9
|
+
packages: z.array(packageIdSchema).readonly().optional(),
|
|
10
|
+
releaseId: publicLabelSchema.optional(),
|
|
11
|
+
json: z.boolean().optional(),
|
|
12
|
+
}).readonly();
|
|
13
|
+
|
|
14
|
+
export type BuildInfoPackageId = z.infer<typeof packageIdSchema>;
|
|
15
|
+
export type BuildInfoOptions = z.infer<typeof buildInfoOptionsSchema>;
|
|
16
|
+
|
|
17
|
+
export const exactVersionSchema = z.string().regex(
|
|
18
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(?:\+[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*)?$/,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const manifestSchema = z.strictObject({
|
|
22
|
+
schema: z.literal('easy-web/build-info'),
|
|
23
|
+
schemaVersion: z.literal(1),
|
|
24
|
+
site: publicLabelSchema,
|
|
25
|
+
releaseId: publicLabelSchema.optional(),
|
|
26
|
+
easyWeb: z.strictObject({
|
|
27
|
+
version: exactVersionSchema,
|
|
28
|
+
packages: z.array(packageIdSchema).readonly(),
|
|
29
|
+
}).readonly(),
|
|
30
|
+
}).readonly();
|
|
31
|
+
|
|
32
|
+
export type BuildInfoManifest = z.infer<typeof manifestSchema>;
|
|
33
|
+
|
|
34
|
+
export class BuildInfoError extends Error {
|
|
35
|
+
constructor(readonly detail: string) {
|
|
36
|
+
super(`@easy-web/core: buildInfo ${detail}`);
|
|
37
|
+
this.name = 'BuildInfoError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function serializeBuildInfo(manifest: BuildInfoManifest): string {
|
|
42
|
+
return `${JSON.stringify(manifest)}\n`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function readBuildInfo(): BuildInfoManifest {
|
|
46
|
+
const serialized = process.env.EASY_WEB_SEO_BUILD_INFO;
|
|
47
|
+
if (!serialized) throw new BuildInfoError('manifest is unavailable; enable easyWebSeo({ buildInfo }).');
|
|
48
|
+
return manifestSchema.parse(JSON.parse(serialized));
|
|
49
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { z } from 'astro/zod';
|
|
5
|
+
import {
|
|
6
|
+
BuildInfoError, buildInfoOptionsSchema, exactVersionSchema,
|
|
7
|
+
type BuildInfoManifest, type BuildInfoPackageId,
|
|
8
|
+
} from './build-info-manifest.js';
|
|
9
|
+
|
|
10
|
+
const packageSchema = z.object({ name: z.string(), version: exactVersionSchema });
|
|
11
|
+
|
|
12
|
+
function installedPackage(id: BuildInfoPackageId, root: URL) {
|
|
13
|
+
const name = `@easy-web/${id}`;
|
|
14
|
+
let folder = fileURLToPath(root);
|
|
15
|
+
let manifestPath = join(folder, 'node_modules', name, 'package.json');
|
|
16
|
+
while (!existsSync(manifestPath)) {
|
|
17
|
+
const parent = dirname(folder);
|
|
18
|
+
if (parent === folder) throw new BuildInfoError(`${name} must be installed in the site before it can be enabled.`);
|
|
19
|
+
folder = parent;
|
|
20
|
+
manifestPath = join(folder, 'node_modules', name, 'package.json');
|
|
21
|
+
}
|
|
22
|
+
const result = packageSchema.safeParse(JSON.parse(readFileSync(manifestPath, 'utf8')));
|
|
23
|
+
if (!result.success || result.data.name !== name) throw new BuildInfoError(`${name} artifact must contain its package identity and an exact version.`);
|
|
24
|
+
return result.data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function buildInfoManifest(input: unknown, root: URL): BuildInfoManifest {
|
|
28
|
+
const parsed = buildInfoOptionsSchema.safeParse(input);
|
|
29
|
+
if (!parsed.success) throw new BuildInfoError(`options are invalid: ${parsed.error.message}`);
|
|
30
|
+
const options = parsed.data;
|
|
31
|
+
const core = packageSchema.parse(JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')));
|
|
32
|
+
if (core.name !== '@easy-web/core') throw new BuildInfoError('core artifact identity is invalid.');
|
|
33
|
+
const packages = Object.freeze([...new Set<BuildInfoPackageId>(['core', ...(options.packages ?? [])])].sort());
|
|
34
|
+
for (const id of packages) {
|
|
35
|
+
if (id === 'core') continue;
|
|
36
|
+
const installed = installedPackage(id, root);
|
|
37
|
+
if (installed.version !== core.version) throw new BuildInfoError(`${installed.name} version must match core version ${core.version}.`);
|
|
38
|
+
}
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
schema: 'easy-web/build-info', schemaVersion: 1, site: options.site,
|
|
41
|
+
...(options.releaseId === undefined ? {} : { releaseId: options.releaseId }),
|
|
42
|
+
easyWeb: Object.freeze({ version: core.version, packages }),
|
|
43
|
+
});
|
|
44
|
+
}
|
package/src/seo/index.ts
CHANGED
|
@@ -9,10 +9,16 @@ import {
|
|
|
9
9
|
} from '../i18n/index.js'
|
|
10
10
|
|
|
11
11
|
import { createCrawlPolicy, isDisallowedPath } from './crawl-policy.js'
|
|
12
|
+
import { buildInfoManifest } from './build-info.js'
|
|
13
|
+
import { buildInfoOptionsSchema, serializeBuildInfo, type BuildInfoOptions } from './build-info-manifest.js'
|
|
14
|
+
|
|
15
|
+
export type { BuildInfoOptions, BuildInfoPackageId, BuildInfoManifest } from './build-info-manifest.js'
|
|
12
16
|
|
|
13
17
|
export type { LocalizedPathGroup }
|
|
14
18
|
|
|
15
19
|
export type Options = {
|
|
20
|
+
/** Public labels only; these routes are public, not protected by crawler directives. */
|
|
21
|
+
readonly buildInfo?: BuildInfoOptions
|
|
16
22
|
noIndex?: boolean
|
|
17
23
|
sitemapLocales?: Record<string, string>
|
|
18
24
|
/**
|
|
@@ -87,6 +93,10 @@ function pathnameOf(page: string, config: AstroConfig): string {
|
|
|
87
93
|
return pathname
|
|
88
94
|
}
|
|
89
95
|
|
|
96
|
+
function isBuildInfoPath(pathname: string): boolean {
|
|
97
|
+
return pathname === '/version' || pathname === '/version.json'
|
|
98
|
+
}
|
|
99
|
+
|
|
90
100
|
export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
91
101
|
return {
|
|
92
102
|
name: '@easy-web/seo',
|
|
@@ -101,6 +111,11 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
const noIndex = options.noIndex ?? false
|
|
114
|
+
const buildInfoOptions = options.buildInfo === undefined ? undefined : buildInfoOptionsSchema.parse(options.buildInfo)
|
|
115
|
+
const manifest = buildInfoOptions === undefined ? undefined : buildInfoManifest(buildInfoOptions, config.root)
|
|
116
|
+
if (manifest) process.env.EASY_WEB_SEO_BUILD_INFO = serializeBuildInfo(manifest)
|
|
117
|
+
else delete process.env.EASY_WEB_SEO_BUILD_INFO
|
|
118
|
+
process.env.EASY_WEB_SEO_BUILD_INFO_JSON = String(buildInfoOptions?.json === true)
|
|
104
119
|
const policy = createCrawlPolicy(noIndex)
|
|
105
120
|
|
|
106
121
|
let sitemapI18n: { defaultLocale: string; locales: Record<string, string> } | undefined
|
|
@@ -166,9 +181,12 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
166
181
|
const sitemapIntegration = sitemap({
|
|
167
182
|
...(sitemapI18n ? { i18n: sitemapI18n } : {}),
|
|
168
183
|
namespaces: { xhtml: true },
|
|
169
|
-
filter: (page: string): boolean =>
|
|
170
|
-
|
|
171
|
-
(
|
|
184
|
+
filter: (page: string): boolean => {
|
|
185
|
+
const pathname = pathnameOf(page, config)
|
|
186
|
+
return !isDisallowedPath(pathname, policy) &&
|
|
187
|
+
!(manifest && isBuildInfoPath(pathname)) &&
|
|
188
|
+
(options.filter?.(page) ?? true)
|
|
189
|
+
},
|
|
172
190
|
serialize: (item: SitemapItem): SitemapItem => {
|
|
173
191
|
// Re-render every <loc> through the same helper that produces the
|
|
174
192
|
// canonical, so the two agree byte-for-byte. @astrojs/sitemap
|
|
@@ -236,6 +254,7 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
236
254
|
}
|
|
237
255
|
|
|
238
256
|
process.env.EASY_WEB_SEO_NO_INDEX = String(noIndex)
|
|
257
|
+
process.env.EASY_WEB_SEO_BASE = config.base
|
|
239
258
|
// <SeoHead> is a component and cannot read astro.config, so the style
|
|
240
259
|
// the sitemap uses is published here for it to reuse. Both surfaces
|
|
241
260
|
// therefore derive the canonical URL form from one resolver.
|
|
@@ -246,6 +265,12 @@ export default function easyWebSeo(options: Options = {}): AstroIntegration {
|
|
|
246
265
|
entrypoint: new URL('./routes/robots-txt.js', import.meta.url),
|
|
247
266
|
prerender: true,
|
|
248
267
|
})
|
|
268
|
+
if (manifest) {
|
|
269
|
+
injectRoute({ pattern: '/version', entrypoint: new URL('../../src/seo/routes/version.astro', import.meta.url), prerender: true })
|
|
270
|
+
if (buildInfoOptions?.json === true) {
|
|
271
|
+
injectRoute({ pattern: '/version.json', entrypoint: new URL('./routes/version-json.js', import.meta.url), prerender: true })
|
|
272
|
+
}
|
|
273
|
+
}
|
|
249
274
|
},
|
|
250
275
|
},
|
|
251
276
|
}
|
|
@@ -13,8 +13,10 @@ function render(policy: CrawlPolicy, site: URL | undefined): string {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (policy.sitemap && site) {
|
|
16
|
+
const configuredBase = process.env.EASY_WEB_SEO_BASE ?? '/'
|
|
17
|
+
const base = `/${configuredBase.replace(/^\/+|\/+$/g, '')}`.replace(/^\/$/, '')
|
|
16
18
|
lines.push('')
|
|
17
|
-
lines.push(`Sitemap: ${new URL(
|
|
19
|
+
lines.push(`Sitemap: ${new URL(`${base}/sitemap-index.xml`, site).href}`)
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
return `${lines.join('\n')}\n`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
import { readBuildInfo, serializeBuildInfo } from '../build-info-manifest.js';
|
|
3
|
+
|
|
4
|
+
export const prerender = true;
|
|
5
|
+
|
|
6
|
+
export const GET: APIRoute = () => new Response(serializeBuildInfo(readBuildInfo()), {
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
9
|
+
'Cache-Control': 'no-store',
|
|
10
|
+
'X-Content-Type-Options': 'nosniff',
|
|
11
|
+
'X-Robots-Tag': 'noindex, nofollow',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
import Hero from '../../components/Hero.astro';
|
|
3
|
+
import Section from '../../components/Section.astro';
|
|
4
|
+
import '../../../styles/tokens.css';
|
|
5
|
+
import { readBuildInfo } from '../build-info-manifest.js';
|
|
6
|
+
|
|
7
|
+
export const prerender = true;
|
|
8
|
+
const manifest = readBuildInfo();
|
|
9
|
+
const hasJson = process.env.EASY_WEB_SEO_BUILD_INFO_JSON === 'true';
|
|
10
|
+
---
|
|
11
|
+
<!doctype html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8" />
|
|
15
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
16
|
+
<meta name="robots" content="noindex,nofollow" />
|
|
17
|
+
<title>Build information - {manifest.site}</title>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<main>
|
|
21
|
+
<Hero title="Build information" subtitle={manifest.site} />
|
|
22
|
+
<Section title="easy-web family">
|
|
23
|
+
<dl>
|
|
24
|
+
<dt>Version</dt><dd>{manifest.easyWeb.version}</dd>
|
|
25
|
+
{manifest.releaseId !== undefined && <><dt>Release</dt><dd>{manifest.releaseId}</dd></>}
|
|
26
|
+
</dl>
|
|
27
|
+
<p>All displayed packages share one easy-web family version. Individual UI components are not independently versioned.</p>
|
|
28
|
+
<ul>{manifest.easyWeb.packages.map((id) => <li><code>@easy-web/{id}</code></li>)}</ul>
|
|
29
|
+
{hasJson && <p><a href={`${import.meta.env.BASE_URL.replace(/\/$/, '')}/version.json`}>Machine-readable build information (JSON)</a></p>}
|
|
30
|
+
</Section>
|
|
31
|
+
</main>
|
|
32
|
+
</body>
|
|
33
|
+
</html>
|
|
34
|
+
|
|
35
|
+
<style>
|
|
36
|
+
body { margin: 0; background: var(--ew-surface); color: var(--ew-on-surface); font-family: var(--ew-font-sans); line-height: var(--ew-leading-normal); }
|
|
37
|
+
dt { font-weight: 700; }
|
|
38
|
+
dd { margin: 0 0 var(--ew-space-4); overflow-wrap: anywhere; }
|
|
39
|
+
code { font-family: var(--ew-font-mono); }
|
|
40
|
+
a { color: var(--ew-link); }
|
|
41
|
+
a:focus-visible { outline: 2px solid var(--ew-primary); outline-offset: var(--ew-space-1); }
|
|
42
|
+
</style>
|