@jini-ai/devops 0.4.0 → 0.5.1
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/CHANGELOG.md +125 -0
- package/README.md +62 -2
- package/dist/agent-jobs/entry.d.ts +4 -0
- package/dist/agent-jobs/entry.js +4 -0
- package/dist/agent-jobs/jobs.d.ts +25 -0
- package/dist/agent-jobs/jobs.js +115 -0
- package/dist/agent-jobs/node.d.ts +12 -0
- package/dist/agent-jobs/node.js +53 -0
- package/dist/agent-jobs/ports.d.ts +69 -0
- package/dist/agent-jobs/ports.js +2 -0
- package/dist/checks/coverage/diff.d.ts +57 -0
- package/dist/checks/coverage/diff.js +48 -0
- package/dist/checks/coverage/disk.d.ts +65 -0
- package/dist/checks/coverage/disk.js +136 -0
- package/dist/checks/coverage/floors.d.ts +31 -0
- package/dist/checks/coverage/floors.js +24 -0
- package/dist/checks/coverage/index.d.ts +7 -0
- package/dist/checks/coverage/index.js +6 -0
- package/dist/checks/coverage/integrity.d.ts +79 -0
- package/dist/checks/coverage/integrity.js +140 -0
- package/dist/checks/coverage/lcov.d.ts +65 -0
- package/dist/checks/coverage/lcov.js +64 -0
- package/dist/checks/node.d.ts +19 -0
- package/dist/checks/node.js +40 -0
- package/dist/checks/ports.d.ts +67 -0
- package/dist/checks/ports.js +2 -0
- package/dist/checks/published-types/index.d.ts +77 -0
- package/dist/checks/published-types/index.js +186 -0
- package/dist/deploy/host-kit.d.ts +27 -10
- package/dist/deploy/naming.d.ts +8 -4
- package/dist/deploy/naming.js +4 -5
- package/dist/deploy/node.d.ts +18 -0
- package/dist/deploy/node.js +57 -0
- package/dist/deploy/reachability.d.ts +42 -12
- package/dist/deploy/reachability.js +75 -69
- package/dist/deploy/redirect-guard.d.ts +7 -2
- package/dist/deploy/redirect-guard.js +3 -3
- package/dist/deploy/tokens.d.ts +14 -11
- package/dist/deploy/tokens.js +13 -13
- package/dist/deploy/tool.d.ts +9 -5
- package/dist/deploy/tool.js +5 -6
- package/dist/deploy/types.d.ts +22 -10
- package/dist/deploy/types.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/local-dev/index.d.ts +55 -0
- package/dist/local-dev/index.js +68 -0
- package/dist/packaging/electron/archive.d.ts +41 -0
- package/dist/packaging/electron/archive.js +77 -0
- package/dist/packaging/electron/asar-adapter.d.ts +13 -0
- package/dist/packaging/electron/asar-adapter.js +5 -0
- package/dist/packaging/electron/entry.d.ts +9 -0
- package/dist/packaging/electron/entry.js +9 -0
- package/dist/packaging/electron/imports.d.ts +13 -0
- package/dist/packaging/electron/imports.js +44 -0
- package/dist/packaging/electron/node.d.ts +8 -0
- package/dist/packaging/electron/node.js +51 -0
- package/dist/packaging/electron/policies.d.ts +64 -0
- package/dist/packaging/electron/policies.js +63 -0
- package/dist/packaging/electron/ports.d.ts +113 -0
- package/dist/packaging/electron/ports.js +2 -0
- package/dist/packaging/electron/stability.d.ts +9 -0
- package/dist/packaging/electron/stability.js +12 -0
- package/dist/packaging/electron/staging.d.ts +108 -0
- package/dist/packaging/electron/staging.js +249 -0
- package/dist/packaging/electron/typescript.d.ts +7 -0
- package/dist/packaging/electron/typescript.js +18 -0
- package/dist/source-control/commit.d.ts +11 -0
- package/dist/source-control/commit.js +71 -0
- package/dist/source-control/contracts.d.ts +327 -0
- package/dist/source-control/contracts.js +2 -0
- package/dist/source-control/entry.d.ts +6 -0
- package/dist/source-control/entry.js +6 -0
- package/dist/source-control/kit.d.ts +15 -0
- package/dist/source-control/kit.js +17 -0
- package/dist/source-control/registry.d.ts +100 -0
- package/dist/source-control/registry.js +174 -0
- package/dist/source-control/repository-target.d.ts +13 -0
- package/dist/source-control/repository-target.js +28 -0
- package/dist/static-export/contracts.d.ts +138 -0
- package/dist/static-export/contracts.js +5 -0
- package/dist/static-export/entry.d.ts +6 -0
- package/dist/static-export/entry.js +6 -0
- package/dist/static-export/failure-summary.d.ts +12 -0
- package/dist/static-export/failure-summary.js +12 -0
- package/dist/static-export/fetch-adapter.d.ts +6 -0
- package/dist/static-export/fetch-adapter.js +5 -0
- package/dist/static-export/node-adapters.d.ts +11 -0
- package/dist/static-export/node-adapters.js +111 -0
- package/dist/static-export/runner.d.ts +6 -0
- package/dist/static-export/runner.js +135 -0
- package/dist/static-export/transforms.d.ts +53 -0
- package/dist/static-export/transforms.js +154 -0
- package/package.json +82 -5
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const GENERIC_SEGMENT_PATTERN = /^[^\s/\\\x00-\x1f\x7f]{1,100}$/;
|
|
2
|
+
const BRANCH_PATTERN = /^[A-Za-z0-9._/-]{1,250}$/;
|
|
3
|
+
function isGenericSegment(value) {
|
|
4
|
+
return GENERIC_SEGMENT_PATTERN.test(value) && !/[\s\x00-\x1f\x7f]/.test(value) && value !== '.' && value !== '..';
|
|
5
|
+
}
|
|
6
|
+
/** Host rules precede the common one-URL-segment rule. Returns caller-safe refusal text. */
|
|
7
|
+
export function repositoryTargetError(required, optional = {}) {
|
|
8
|
+
const hostError = optional.validateTarget?.(required) ?? null;
|
|
9
|
+
if (hostError !== null)
|
|
10
|
+
return hostError;
|
|
11
|
+
if (!isGenericSegment(required.owner))
|
|
12
|
+
return `invalid owner '${required.owner.slice(0, 60)}'`;
|
|
13
|
+
if (!isGenericSegment(required.repo))
|
|
14
|
+
return `invalid repo '${required.repo.slice(0, 100)}'`;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
/** Validate before resolving credentials or exporting bytes. */
|
|
18
|
+
export function validateCommitTarget(required, optional = {}) {
|
|
19
|
+
const error = repositoryTargetError({ owner: required.owner, repo: required.repo }, optional);
|
|
20
|
+
if (error !== null)
|
|
21
|
+
return error;
|
|
22
|
+
if (optional.branch !== undefined && (!BRANCH_PATTERN.test(optional.branch) || /[\s\x00-\x1f\x7f]/.test(optional.branch)))
|
|
23
|
+
return `invalid branch name '${optional.branch.slice(0, 60)}'`;
|
|
24
|
+
if (required.commitMessage.trim() === '' || required.commitMessage.length > 500)
|
|
25
|
+
return 'commitMessage must be 1-500 characters';
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=repository-target.js.map
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** Kinds describe the host's routes; only redirect/not-found/well-known affect writing. */
|
|
2
|
+
export type ManifestRouteKind = string;
|
|
3
|
+
export interface ManifestRoute {
|
|
4
|
+
path: string;
|
|
5
|
+
kind: ManifestRouteKind;
|
|
6
|
+
label: string;
|
|
7
|
+
redirectTarget?: string;
|
|
8
|
+
redirectStatusCode?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ManifestActiveTheme {
|
|
11
|
+
id: string;
|
|
12
|
+
dir: string;
|
|
13
|
+
apiVersion?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ManifestSkip {
|
|
16
|
+
reason: string;
|
|
17
|
+
detail: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RouteManifest {
|
|
20
|
+
routes: ManifestRoute[];
|
|
21
|
+
skipped: ManifestSkip[];
|
|
22
|
+
activeTheme?: ManifestActiveTheme;
|
|
23
|
+
}
|
|
24
|
+
export interface RouteManifestPort {
|
|
25
|
+
build(required: Record<string, never>): Promise<RouteManifest>;
|
|
26
|
+
}
|
|
27
|
+
export interface AppSession {
|
|
28
|
+
baseUrl: string;
|
|
29
|
+
close(required: Record<string, never>): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface AppFactoryPort {
|
|
32
|
+
open(required: Record<string, never>): Promise<AppSession>;
|
|
33
|
+
}
|
|
34
|
+
export interface ArtifactWriterPort {
|
|
35
|
+
prepare(required: {
|
|
36
|
+
outputDir: string;
|
|
37
|
+
}, optional?: {
|
|
38
|
+
clean?: boolean;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
/** The runner validates outputFile; an adapter must also protect its storage root/symlink boundary. */
|
|
41
|
+
write(required: {
|
|
42
|
+
outputDir: string;
|
|
43
|
+
outputFile: string;
|
|
44
|
+
data: string | Buffer;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export interface AssetSourcePort {
|
|
48
|
+
listThemeFiles(required: {
|
|
49
|
+
theme: ManifestActiveTheme;
|
|
50
|
+
}): Promise<readonly string[]>;
|
|
51
|
+
}
|
|
52
|
+
export interface ThemeLayoutPort {
|
|
53
|
+
resolve(required: {
|
|
54
|
+
theme: ManifestActiveTheme;
|
|
55
|
+
}): {
|
|
56
|
+
pagesDir: string;
|
|
57
|
+
assetUrlPrefix: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface ExportedRoute {
|
|
61
|
+
path: string;
|
|
62
|
+
kind: ManifestRouteKind;
|
|
63
|
+
outputFile: string;
|
|
64
|
+
data: string;
|
|
65
|
+
contentType?: string | null;
|
|
66
|
+
}
|
|
67
|
+
export interface FailedRoute {
|
|
68
|
+
path: string;
|
|
69
|
+
kind: ManifestRouteKind;
|
|
70
|
+
reason: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ExportedAsset {
|
|
73
|
+
url: string;
|
|
74
|
+
outputFile: string;
|
|
75
|
+
data: Buffer;
|
|
76
|
+
contentType?: string | null;
|
|
77
|
+
}
|
|
78
|
+
export interface FailedAsset {
|
|
79
|
+
url: string;
|
|
80
|
+
reason: string;
|
|
81
|
+
}
|
|
82
|
+
export interface ExportReport {
|
|
83
|
+
outputDir: string;
|
|
84
|
+
routes: {
|
|
85
|
+
succeeded: ExportedRoute[];
|
|
86
|
+
failed: FailedRoute[];
|
|
87
|
+
};
|
|
88
|
+
assets: {
|
|
89
|
+
succeeded: ExportedAsset[];
|
|
90
|
+
failed: FailedAsset[];
|
|
91
|
+
};
|
|
92
|
+
skippedManifestEntries: ManifestSkip[];
|
|
93
|
+
unreferencedThemeFiles: string[];
|
|
94
|
+
basePath?: string;
|
|
95
|
+
basePathRewriteWarning?: string;
|
|
96
|
+
}
|
|
97
|
+
/** The host selects the transport; the runner supplies redirect and timeout policy. */
|
|
98
|
+
export type ExportFetchPort = (required: {
|
|
99
|
+
url: string;
|
|
100
|
+
}, optional?: {
|
|
101
|
+
init?: RequestInit;
|
|
102
|
+
}) => Promise<Response>;
|
|
103
|
+
export interface ExportSiteArgs {
|
|
104
|
+
outputDir: string;
|
|
105
|
+
manifest: RouteManifestPort;
|
|
106
|
+
app: AppFactoryPort;
|
|
107
|
+
writer: ArtifactWriterPort;
|
|
108
|
+
fetch: ExportFetchPort;
|
|
109
|
+
assetSource: AssetSourcePort;
|
|
110
|
+
themeLayout: ThemeLayoutPort;
|
|
111
|
+
assetUrlPrefixes: readonly string[];
|
|
112
|
+
requestHeaders: Readonly<Record<string, string>>;
|
|
113
|
+
security: {
|
|
114
|
+
transformHtml(required: {
|
|
115
|
+
html: string;
|
|
116
|
+
}): string;
|
|
117
|
+
};
|
|
118
|
+
errorPage: {
|
|
119
|
+
outputFile: string;
|
|
120
|
+
acceptStatus(required: {
|
|
121
|
+
status: number;
|
|
122
|
+
}): boolean;
|
|
123
|
+
};
|
|
124
|
+
/** Caller-safe error description; used for failed network, body or artifact writes. */
|
|
125
|
+
describeError(required: {
|
|
126
|
+
error: unknown;
|
|
127
|
+
}): string;
|
|
128
|
+
}
|
|
129
|
+
export interface ExportSiteOptions {
|
|
130
|
+
clean?: boolean;
|
|
131
|
+
basePath?: string;
|
|
132
|
+
fetchTimeoutMs?: number;
|
|
133
|
+
}
|
|
134
|
+
export declare class ExportOutputNotEmptyError extends Error {
|
|
135
|
+
}
|
|
136
|
+
export declare class ExportPathError extends Error {
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExportReport } from './contracts.js';
|
|
2
|
+
export interface ExportFailureSummary {
|
|
3
|
+
kind: 'route' | 'asset';
|
|
4
|
+
identifier: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
count: number;
|
|
7
|
+
}
|
|
8
|
+
/** Runtime-leaf check of routes AND assets. Routes take precedence; the count is per collection. */
|
|
9
|
+
export declare function firstExportFailure(required: {
|
|
10
|
+
report: ExportReport;
|
|
11
|
+
}): ExportFailureSummary | undefined;
|
|
12
|
+
//# sourceMappingURL=failure-summary.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Runtime-leaf check of routes AND assets. Routes take precedence; the count is per collection. */
|
|
2
|
+
export function firstExportFailure(required) {
|
|
3
|
+
const { report } = required;
|
|
4
|
+
const route = report.routes.failed[0];
|
|
5
|
+
if (route)
|
|
6
|
+
return { kind: 'route', identifier: route.path, reason: route.reason, count: report.routes.failed.length };
|
|
7
|
+
const asset = report.assets.failed[0];
|
|
8
|
+
if (asset)
|
|
9
|
+
return { kind: 'asset', identifier: asset.url, reason: asset.reason, count: report.assets.failed.length };
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=failure-summary.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExportFetchPort } from './contracts.js';
|
|
2
|
+
/** Adapt a host-selected native/guarded fetch; no global transport is selected. */
|
|
3
|
+
export declare function createExportFetchAdapter(required: {
|
|
4
|
+
fetch: typeof fetch;
|
|
5
|
+
}): ExportFetchPort;
|
|
6
|
+
//# sourceMappingURL=fetch-adapter.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RequestListener } from 'node:http';
|
|
2
|
+
import { type AppFactoryPort, type ArtifactWriterPort, type AssetSourcePort } from './contracts.js';
|
|
3
|
+
/** Caller-owned output directory, explicit clean, and no-follow regular-file writes. */
|
|
4
|
+
export declare function createNodeArtifactWriter(_required: Record<string, never>): ArtifactWriterPort;
|
|
5
|
+
/** Independent Node loopback adapter. The app factory is required and remains owned by the host. */
|
|
6
|
+
export declare function createNodeAppFactory(required: {
|
|
7
|
+
createApp(required: Record<string, never>): RequestListener | Promise<RequestListener>;
|
|
8
|
+
}): AppFactoryPort;
|
|
9
|
+
/** Inventory only regular theme files. Rendering and API-version layout stay injected. */
|
|
10
|
+
export declare function createNodeAssetSource(_required: Record<string, never>): AssetSourcePort;
|
|
11
|
+
//# sourceMappingURL=node-adapters.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { once } from 'node:events';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { lstat, mkdir, open, readdir, rm } from 'node:fs/promises';
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { ExportOutputNotEmptyError, ExportPathError } from './contracts.js';
|
|
7
|
+
import { safeRelativeOutputFile } from './transforms.js';
|
|
8
|
+
/** Require regular directories at every ancestor. Hosts must use canonical absolute storage paths.
|
|
9
|
+
* The storage hierarchy must be caller-owned; cross-process hostile ancestor swaps require host isolation.
|
|
10
|
+
*/
|
|
11
|
+
async function ensureDirectory({ directory, label }, optional = {}) {
|
|
12
|
+
if (!path.isAbsolute(directory))
|
|
13
|
+
throw new ExportPathError(`${label} path must be absolute.`);
|
|
14
|
+
const resolved = path.resolve(directory);
|
|
15
|
+
const segments = resolved.slice(path.parse(resolved).root.length).split(path.sep).filter(Boolean);
|
|
16
|
+
let current = path.parse(resolved).root;
|
|
17
|
+
for (const segment of segments) {
|
|
18
|
+
current = path.join(current, segment);
|
|
19
|
+
if (optional.create) {
|
|
20
|
+
try {
|
|
21
|
+
await mkdir(current);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code !== 'EEXIST')
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const info = await lstat(current);
|
|
29
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
30
|
+
throw new ExportPathError(`${label} path must be a regular directory.`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Caller-owned output directory, explicit clean, and no-follow regular-file writes. */
|
|
34
|
+
export function createNodeArtifactWriter(_required) {
|
|
35
|
+
return {
|
|
36
|
+
async prepare({ outputDir }, optional = {}) {
|
|
37
|
+
await ensureDirectory({ directory: outputDir, label: 'Output' }, { create: true });
|
|
38
|
+
const entries = await readdir(outputDir);
|
|
39
|
+
if (entries.length && !optional.clean)
|
|
40
|
+
throw new ExportOutputNotEmptyError(`export output directory '${outputDir}' is not empty (${entries.length} existing ${entries.length === 1 ? 'entry' : 'entries'}) — pass clean: true to remove its contents first, or select an empty/new directory`);
|
|
41
|
+
if (optional.clean)
|
|
42
|
+
for (const entry of entries)
|
|
43
|
+
await rm(path.join(outputDir, entry), { recursive: true, force: true });
|
|
44
|
+
},
|
|
45
|
+
async write({ outputDir, outputFile, data }) {
|
|
46
|
+
safeRelativeOutputFile({ value: outputFile });
|
|
47
|
+
await ensureDirectory({ directory: outputDir, label: 'Output' }, { create: true });
|
|
48
|
+
const destination = path.join(outputDir, outputFile);
|
|
49
|
+
await ensureDirectory({ directory: path.dirname(destination), label: 'Artifact' }, { create: true });
|
|
50
|
+
try {
|
|
51
|
+
const info = await lstat(destination);
|
|
52
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
53
|
+
throw new ExportPathError('Artifact output must be a regular file.');
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.code !== 'ENOENT')
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
const handle = await open(destination, constants.O_WRONLY | constants.O_CREAT | constants.O_NOFOLLOW, 0o600);
|
|
60
|
+
try {
|
|
61
|
+
if (!(await handle.stat()).isFile())
|
|
62
|
+
throw new ExportPathError('Artifact output must be a regular file.');
|
|
63
|
+
await handle.truncate(0);
|
|
64
|
+
await handle.writeFile(data);
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
await handle.close();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/** Independent Node loopback adapter. The app factory is required and remains owned by the host. */
|
|
73
|
+
export function createNodeAppFactory(required) {
|
|
74
|
+
return { async open() {
|
|
75
|
+
const server = createServer(await required.createApp({}));
|
|
76
|
+
let closed = false;
|
|
77
|
+
const close = async () => {
|
|
78
|
+
if (closed)
|
|
79
|
+
return;
|
|
80
|
+
closed = true;
|
|
81
|
+
server.closeAllConnections();
|
|
82
|
+
await new Promise(resolve => { server.close(() => resolve()); });
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
server.listen(0, '127.0.0.1');
|
|
86
|
+
await once(server, 'listening');
|
|
87
|
+
const address = server.address();
|
|
88
|
+
return { baseUrl: `http://127.0.0.1:${address.port}`, close };
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
await close();
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
} };
|
|
95
|
+
}
|
|
96
|
+
/** Inventory only regular theme files. Rendering and API-version layout stay injected. */
|
|
97
|
+
export function createNodeAssetSource(_required) {
|
|
98
|
+
async function list(directory, prefix) {
|
|
99
|
+
const files = [];
|
|
100
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
101
|
+
const relative = prefix + entry.name;
|
|
102
|
+
if (entry.isDirectory())
|
|
103
|
+
files.push(...await list(path.join(directory, entry.name), relative + '/'));
|
|
104
|
+
else if (entry.isFile())
|
|
105
|
+
files.push(relative);
|
|
106
|
+
}
|
|
107
|
+
return files;
|
|
108
|
+
}
|
|
109
|
+
return { async listThemeFiles({ theme }) { await ensureDirectory({ directory: theme.dir, label: 'Theme' }); return (await list(theme.dir, '')).sort(); } };
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=node-adapters.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExportReport, ExportSiteArgs, ExportSiteOptions } from './contracts.js';
|
|
2
|
+
/** Drive the caller's actual app, retaining exact written bytes and reporting each failed item.
|
|
3
|
+
* Startup/output/inventory errors throw; an opened app always closes. No singleton state is used.
|
|
4
|
+
*/
|
|
5
|
+
export declare function exportSite(required: ExportSiteArgs, optional?: ExportSiteOptions): Promise<ExportReport>;
|
|
6
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { extractAssetUrls, extractCssUrls, normalizeBasePath, outputFileForUrl, redirectOutcomeFor, renderRedirectStub, rewriteRouteBodyForBasePath, safeRelativeOutputFile } from './transforms.js';
|
|
2
|
+
const BASE_PATH_REWRITE_WARNING = "base-path rewriting is a best-effort TEXT rewrite over already-rendered responses — it cannot rewrite a path a theme's own JavaScript constructs at runtime from a string (same category of gap as the unreferenced-theme-file warning, just invisible to this rewrite instead of to the asset crawl).";
|
|
3
|
+
async function request(ctx, url) {
|
|
4
|
+
// Redirects are observed, never followed off the caller's app, for routes and assets alike.
|
|
5
|
+
return ctx.args.fetch({ url: ctx.baseUrl + url }, { init: { redirect: 'manual', headers: new Headers(ctx.args.requestHeaders), signal: AbortSignal.timeout(ctx.timeoutMs) } });
|
|
6
|
+
}
|
|
7
|
+
function failureReason(ctx, url, error) {
|
|
8
|
+
if (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError'))
|
|
9
|
+
return `GET ${ctx.baseUrl}${url} timed out after ${ctx.timeoutMs}ms`;
|
|
10
|
+
return `GET ${ctx.baseUrl}${url} failed: ${ctx.args.describeError({ error })}`;
|
|
11
|
+
}
|
|
12
|
+
async function writeRoute(ctx, route) {
|
|
13
|
+
// Validate the request path even when the error-page policy supplies a different artifact path.
|
|
14
|
+
const regularOutput = outputFileForUrl({ url: route.path }, { contentRoute: route.kind !== 'well-known' });
|
|
15
|
+
const outputFile = route.kind === 'not-found' ? safeRelativeOutputFile({ value: ctx.args.errorPage.outputFile }) : regularOutput;
|
|
16
|
+
const response = await request(ctx, route.path);
|
|
17
|
+
let body;
|
|
18
|
+
let rawBody;
|
|
19
|
+
let contentType = response.headers.get('content-type');
|
|
20
|
+
if (route.kind === 'redirect') {
|
|
21
|
+
const decision = redirectOutcomeFor({ status: response.status, locationHeader: response.headers.get('location') }, { ...(route.redirectTarget !== undefined ? { manifestTarget: route.redirectTarget } : {}) });
|
|
22
|
+
if (decision.kind === 'failed')
|
|
23
|
+
return { reason: decision.reason };
|
|
24
|
+
body = ctx.args.security.transformHtml({ html: renderRedirectStub({ location: decision.location }, { basePath: ctx.basePath }) });
|
|
25
|
+
contentType = 'text/html; charset=utf-8';
|
|
26
|
+
await response.body?.cancel();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (route.kind === 'not-found' ? !ctx.args.errorPage.acceptStatus({ status: response.status }) : response.status !== 200) {
|
|
30
|
+
await response.body?.cancel();
|
|
31
|
+
return { reason: route.kind === 'not-found' ? `expected an accepted response for the error-page probe, got ${response.status}` : `expected 200, got ${response.status}` };
|
|
32
|
+
}
|
|
33
|
+
rawBody = await response.text();
|
|
34
|
+
body = rewriteRouteBodyForBasePath({ path: route.path, body: rawBody, basePath: ctx.basePath });
|
|
35
|
+
if (route.kind === 'not-found' || /^text\/html\b/i.test(contentType ?? ''))
|
|
36
|
+
body = ctx.args.security.transformHtml({ html: body });
|
|
37
|
+
}
|
|
38
|
+
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data: body });
|
|
39
|
+
return { route: { path: route.path, kind: route.kind, outputFile, data: body, contentType }, ...(rawBody !== undefined && route.kind !== 'not-found' ? { crawlHtml: rawBody } : {}) };
|
|
40
|
+
}
|
|
41
|
+
async function writeRoutes(ctx, routes) {
|
|
42
|
+
const succeeded = [], failed = [];
|
|
43
|
+
const assets = new Set();
|
|
44
|
+
for (const route of routes) {
|
|
45
|
+
try {
|
|
46
|
+
const outcome = await writeRoute(ctx, route);
|
|
47
|
+
if ('reason' in outcome) {
|
|
48
|
+
failed.push({ path: route.path, kind: route.kind, reason: outcome.reason });
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
succeeded.push(outcome.route);
|
|
52
|
+
if (outcome.crawlHtml !== undefined)
|
|
53
|
+
for (const url of extractAssetUrls({ html: outcome.crawlHtml, prefixes: ctx.args.assetUrlPrefixes }))
|
|
54
|
+
assets.add(url);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
failed.push({ path: route.path, kind: route.kind, reason: failureReason(ctx, route.path, error) });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { succeeded, failed, assets };
|
|
61
|
+
}
|
|
62
|
+
async function writeAssets(ctx, initial) {
|
|
63
|
+
const succeeded = [], failed = [];
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const queue = initial.map(url => ({ url, crawlCss: true }));
|
|
66
|
+
for (let index = 0; index < queue.length; index++) {
|
|
67
|
+
const { url, crawlCss } = queue[index];
|
|
68
|
+
if (seen.has(url))
|
|
69
|
+
continue;
|
|
70
|
+
seen.add(url);
|
|
71
|
+
try {
|
|
72
|
+
const outputFile = outputFileForUrl({ url });
|
|
73
|
+
const response = await request(ctx, url);
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
await response.body?.cancel();
|
|
76
|
+
failed.push({ url, reason: `GET ${url} -> ${response.status}` });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const data = Buffer.from(await response.arrayBuffer());
|
|
80
|
+
const contentType = response.headers.get('content-type');
|
|
81
|
+
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data });
|
|
82
|
+
succeeded.push({ url, outputFile, data, contentType });
|
|
83
|
+
if (crawlCss && url.split('?')[0].endsWith('.css')) {
|
|
84
|
+
for (const child of extractCssUrls({ css: data.toString('utf8'), cssUrl: url, prefixes: ctx.args.assetUrlPrefixes }))
|
|
85
|
+
queue.push({ url: child, crawlCss: false });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
failed.push({ url, reason: failureReason(ctx, url, error) });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { succeeded, failed };
|
|
93
|
+
}
|
|
94
|
+
async function unreferenced(ctx, manifest, assets) {
|
|
95
|
+
if (!manifest.activeTheme)
|
|
96
|
+
return [];
|
|
97
|
+
const theme = manifest.activeTheme;
|
|
98
|
+
const layout = ctx.args.themeLayout.resolve({ theme });
|
|
99
|
+
const accounted = new Set([`${layout.pagesDir}/index.html`, `${layout.pagesDir}/404.html`]);
|
|
100
|
+
for (const route of manifest.routes)
|
|
101
|
+
if (route.kind === 'theme-page')
|
|
102
|
+
accounted.add(`${layout.pagesDir}/${route.label}.html`);
|
|
103
|
+
for (const asset of assets) {
|
|
104
|
+
const pathname = decodeURIComponent(asset.url.split(/[?#]/)[0]);
|
|
105
|
+
if (pathname.startsWith(layout.assetUrlPrefix))
|
|
106
|
+
accounted.add(pathname.slice(layout.assetUrlPrefix.length));
|
|
107
|
+
}
|
|
108
|
+
return [...await ctx.args.assetSource.listThemeFiles({ theme })].filter(file => !accounted.has(file)).sort();
|
|
109
|
+
}
|
|
110
|
+
/** Drive the caller's actual app, retaining exact written bytes and reporting each failed item.
|
|
111
|
+
* Startup/output/inventory errors throw; an opened app always closes. No singleton state is used.
|
|
112
|
+
*/
|
|
113
|
+
export async function exportSite(required, optional = {}) {
|
|
114
|
+
const basePath = normalizeBasePath({ raw: optional.basePath ?? '' });
|
|
115
|
+
const timeoutMs = optional.fetchTimeoutMs ?? 30_000;
|
|
116
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
|
|
117
|
+
throw new RangeError('fetchTimeoutMs must be a positive integer');
|
|
118
|
+
await required.writer.prepare({ outputDir: required.outputDir }, { clean: optional.clean ?? false });
|
|
119
|
+
const manifest = await required.manifest.build({});
|
|
120
|
+
const session = await required.app.open({});
|
|
121
|
+
try {
|
|
122
|
+
const origin = new URL(session.baseUrl);
|
|
123
|
+
if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash)
|
|
124
|
+
throw new Error('App session baseUrl must be an HTTP origin without credentials.');
|
|
125
|
+
const ctx = { args: required, baseUrl: origin.origin, basePath, timeoutMs };
|
|
126
|
+
const routes = await writeRoutes(ctx, manifest.routes);
|
|
127
|
+
const assets = await writeAssets(ctx, [...routes.assets]);
|
|
128
|
+
return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: manifest.skipped,
|
|
129
|
+
unreferencedThemeFiles: await unreferenced(ctx, manifest, assets.succeeded), ...(basePath ? { basePath, basePathRewriteWarning: BASE_PATH_REWRITE_WARNING } : {}) };
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
await session.close({});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Normalize the optional output URL prefix; no product layout is implied. */
|
|
2
|
+
export declare function normalizeBasePath(required: {
|
|
3
|
+
raw: string;
|
|
4
|
+
}): string;
|
|
5
|
+
/** Same bounded text transforms as the exporter origin; crawl the raw body before applying these. */
|
|
6
|
+
export declare function rewriteRouteBodyForBasePath(required: {
|
|
7
|
+
path: string;
|
|
8
|
+
body: string;
|
|
9
|
+
basePath: string;
|
|
10
|
+
}): string;
|
|
11
|
+
type RedirectDecision = {
|
|
12
|
+
kind: 'failed';
|
|
13
|
+
reason: string;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'redirect-to';
|
|
16
|
+
location: string;
|
|
17
|
+
};
|
|
18
|
+
/** Live Location wins; a manifest target is a fallback only for a genuine 3xx. */
|
|
19
|
+
export declare function redirectOutcomeFor(required: {
|
|
20
|
+
status: number;
|
|
21
|
+
locationHeader: string | null;
|
|
22
|
+
}, optional?: {
|
|
23
|
+
manifestTarget?: string;
|
|
24
|
+
}): RedirectDecision;
|
|
25
|
+
/** Scheme-check before escaping all three URL sinks. Unsafe destinations degrade to '#'. */
|
|
26
|
+
export declare function renderRedirectStub(required: {
|
|
27
|
+
location: string;
|
|
28
|
+
}, optional?: {
|
|
29
|
+
basePath?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/** Quoted href/src/srcset scan, preserving data-URL commas and ignoring external references. */
|
|
32
|
+
export declare function extractAssetUrls(required: {
|
|
33
|
+
html: string;
|
|
34
|
+
prefixes: readonly string[];
|
|
35
|
+
}): string[];
|
|
36
|
+
/** A single CSS hop, resolved against the stylesheet URL and restricted to the same synthetic origin. */
|
|
37
|
+
export declare function extractCssUrls(required: {
|
|
38
|
+
css: string;
|
|
39
|
+
cssUrl: string;
|
|
40
|
+
prefixes: readonly string[];
|
|
41
|
+
}): string[];
|
|
42
|
+
/** Reject path escapes and separators before HTTP or writing; returns forward-slash relative output. */
|
|
43
|
+
export declare function safeRelativeOutputFile(required: {
|
|
44
|
+
value: string;
|
|
45
|
+
}): string;
|
|
46
|
+
/** URL request path to portable artifact path, with decoded traversal refusal. */
|
|
47
|
+
export declare function outputFileForUrl(required: {
|
|
48
|
+
url: string;
|
|
49
|
+
}, optional?: {
|
|
50
|
+
contentRoute?: boolean;
|
|
51
|
+
}): string;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=transforms.d.ts.map
|