@jini-ai/devops 0.6.15-rc.2 → 0.6.16
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 +2 -2
- package/dist/agent-jobs/jobs.js +3 -2
- package/dist/checks/hardwiring-node.js +16 -6
- package/dist/checks/hardwiring.js +38 -16
- package/dist/checks/memory-soak.js +2 -1
- package/dist/checks/node.d.ts +0 -1
- package/dist/checks/node.js +7 -1
- package/dist/checks/published-types/index.js +5 -2
- package/dist/core/deploy-types.d.ts +8 -0
- package/dist/deploy/naming.js +4 -5
- package/dist/deploy/node.js +4 -2
- package/dist/deploy/reachability.js +26 -23
- package/dist/dns/plan.js +2 -1
- package/dist/dns/records.js +7 -3
- package/dist/dns/registry.js +4 -2
- package/dist/local-dev/index.js +7 -3
- package/dist/packaging/electron/entry.d.ts +3 -0
- package/dist/packaging/electron/entry.js +3 -0
- package/dist/packaging/electron/imports.js +5 -3
- package/dist/packaging/electron/node.js +7 -1
- package/dist/packaging/electron/optional-peers.d.ts +22 -0
- package/dist/packaging/electron/optional-peers.js +16 -0
- package/dist/packaging/electron/ports.d.ts +16 -0
- package/dist/packaging/electron/staged-closure-node.d.ts +7 -0
- package/dist/packaging/electron/staged-closure-node.js +17 -0
- package/dist/packaging/electron/staged-closure.d.ts +27 -0
- package/dist/packaging/electron/staged-closure.js +128 -0
- package/dist/packaging/electron/staging.d.ts +28 -4
- package/dist/packaging/electron/staging.js +69 -27
- package/dist/packaging/electron/typescript.d.ts +15 -2
- package/dist/packaging/electron/typescript.js +101 -16
- package/dist/source-control/commit.js +23 -5
- package/dist/source-control/contracts.d.ts +11 -1
- package/dist/source-control/entry.d.ts +1 -0
- package/dist/source-control/entry.js +1 -0
- package/dist/source-control/kit.js +2 -0
- package/dist/source-control/registry.d.ts +5 -0
- package/dist/source-control/registry.js +5 -2
- package/dist/source-control/repository-path.d.ts +28 -0
- package/dist/source-control/repository-path.js +52 -0
- package/dist/source-control/repository-target.js +6 -3
- package/dist/static-export/contracts.d.ts +4 -5
- package/dist/static-export/css-urls.d.ts +16 -0
- package/dist/static-export/css-urls.js +66 -0
- package/dist/static-export/html-url-locations.d.ts +2 -1
- package/dist/static-export/html-url-locations.js +23 -3
- package/dist/static-export/node-adapters.js +8 -3
- package/dist/static-export/runner.js +47 -30
- package/dist/static-export/transforms.js +45 -29
- package/package.json +12 -6
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { assertNotRedirected, redirectGuardInit } from '../core/redirect-guard.js';
|
|
2
2
|
import { DeployError } from '../core/deploy-types.js';
|
|
3
|
+
import { normalizeRepositoryFolder, prefixRepositoryPath, repositoryPathContained } from './repository-path.js';
|
|
3
4
|
/** Build a kit without globals or a silently missing guarded HTTP client. */
|
|
4
5
|
export function createSourceControlProviderKit(required, optional = {}) {
|
|
5
6
|
return {
|
|
7
|
+
repositoryPaths: { normalizeFolder: normalizeRepositoryFolder, prefixPath: prefixRepositoryPath, contains: repositoryPathContained },
|
|
6
8
|
fetch: ({ url, init }) => required.fetch({ url }, { init: optional.fetchRedirectPolicy === "caller" ? init : redirectGuardInit({ init }) }),
|
|
7
9
|
redirectGuardInit: ({ init }) => redirectGuardInit({ init }),
|
|
8
10
|
assertNotRedirected: ({ response, hostName }) => assertNotRedirected({ resp: response, providerLabel: hostName }),
|
|
@@ -40,6 +40,7 @@ export interface SharedLoadedProvider<Kit, Operations> {
|
|
|
40
40
|
create(required: {
|
|
41
41
|
kit: Kit;
|
|
42
42
|
}): Operations;
|
|
43
|
+
supportsFolder?: boolean;
|
|
43
44
|
validateTarget?: (required: {
|
|
44
45
|
owner: string;
|
|
45
46
|
repo: string;
|
|
@@ -50,6 +51,7 @@ export declare function buildLoadedSourceControlProvider<Kit, Operations>(requir
|
|
|
50
51
|
loaded: SharedLoadedProvider<Kit, Operations>;
|
|
51
52
|
kit: Kit;
|
|
52
53
|
}, _optional?: {}): Operations & import('./contracts.js').SourceControlHostFacts & {
|
|
54
|
+
supportsFolder: boolean;
|
|
53
55
|
validateTarget?: (required: {
|
|
54
56
|
owner: string;
|
|
55
57
|
repo: string;
|
|
@@ -108,6 +110,7 @@ export declare function buildSourceControlProvider<Kit = SourceControlProviderKi
|
|
|
108
110
|
} | {
|
|
109
111
|
ok: true;
|
|
110
112
|
provider: Operations & import("./contracts.js").SourceControlHostFacts & {
|
|
113
|
+
supportsFolder: boolean;
|
|
111
114
|
validateTarget?: (required: {
|
|
112
115
|
owner: string;
|
|
113
116
|
repo: string;
|
|
@@ -129,6 +132,7 @@ export interface BuildProvidersArgs {
|
|
|
129
132
|
/** Build every enabled provider over the same guarded kit, in catalog order. */
|
|
130
133
|
export declare function buildSourceControlProviders<Kit = SourceControlProviderKit, Operations = SourceControlProviderOperations, Registry extends SharedProviderRegistry<Kit, Operations> = SharedProviderRegistry<Kit, Operations>>(required: SharedBuildProviderArgs<Kit, Operations, Registry>, _optional?: {}): Promise<{
|
|
131
134
|
providers: (Operations & import("./contracts.js").SourceControlHostFacts & {
|
|
135
|
+
supportsFolder: boolean;
|
|
132
136
|
validateTarget?: (required: {
|
|
133
137
|
owner: string;
|
|
134
138
|
repo: string;
|
|
@@ -148,6 +152,7 @@ export declare function buildSourceControlProviderForApi<Kit = SourceControlProv
|
|
|
148
152
|
}): Promise<{
|
|
149
153
|
ok: true;
|
|
150
154
|
provider: Operations & import("./contracts.js").SourceControlHostFacts & {
|
|
155
|
+
supportsFolder: boolean;
|
|
151
156
|
validateTarget?: (required: {
|
|
152
157
|
owner: string;
|
|
153
158
|
repo: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { repositoryPathContained } from './repository-path.js';
|
|
1
2
|
function object(value) { return value !== null && typeof value === 'object' && !Array.isArray(value); }
|
|
2
3
|
/** Shared relative-path rule: no backslash, colon or control character; no empty, `.` or `..` segment. */
|
|
3
4
|
function safeRelativePath(value) {
|
|
4
|
-
return
|
|
5
|
+
return repositoryPathContained({ path: value });
|
|
5
6
|
}
|
|
6
7
|
/** True for `https://host[:port]` exactly — what `new URL(x).origin` gives back. @complexity O(1). */
|
|
7
8
|
function httpsOrigin(value) {
|
|
@@ -92,6 +93,8 @@ export function sourceControlProviderModuleError({ value }, _optional = {}) {
|
|
|
92
93
|
return 'its module has no create() function';
|
|
93
94
|
if (value.validateTarget !== undefined && typeof value.validateTarget !== 'function')
|
|
94
95
|
return "its module's validateTarget is not a function";
|
|
96
|
+
if (value.supportsFolder !== undefined && typeof value.supportsFolder !== 'boolean')
|
|
97
|
+
return "its module's supportsFolder is not a boolean";
|
|
95
98
|
return null;
|
|
96
99
|
}
|
|
97
100
|
function byPluginId(a, b) {
|
|
@@ -157,7 +160,7 @@ export async function loadSourceControlProviderRegistry(required) {
|
|
|
157
160
|
export function buildLoadedSourceControlProvider(required, _optional = {}) {
|
|
158
161
|
const { loaded, kit } = required;
|
|
159
162
|
const { id, label, apiOrigin, maxFileBytes, reservedPaths, workflowPaths } = loaded.descriptor;
|
|
160
|
-
return { ...loaded.module.create({ kit }), ...(loaded.module.validateTarget ? { validateTarget: loaded.module.validateTarget } : {}), id, label, apiOrigin,
|
|
163
|
+
return { ...loaded.module.create({ kit }), supportsFolder: loaded.module.supportsFolder === true, ...(loaded.module.validateTarget ? { validateTarget: loaded.module.validateTarget } : {}), id, label, apiOrigin,
|
|
161
164
|
...(maxFileBytes !== undefined ? { maxFileBytes } : {}), ...(reservedPaths !== undefined ? { reservedPaths } : {}), ...(workflowPaths !== undefined ? { workflowPaths } : {}) };
|
|
162
165
|
}
|
|
163
166
|
/** Operator navigation/copy is supplied by the host, with no descriptor or product defaults. */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Invalid repository destinations fail before any provider I/O. */
|
|
2
|
+
export declare class RepositoryPathError extends Error {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a repository-relative folder, preserving root only when explicitly empty or omitted.
|
|
6
|
+
* @throws RepositoryPathError for malformed values, absolute paths, controls or traversal.
|
|
7
|
+
* @complexity O(folder length), no effects.
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeRepositoryFolder({ folder }: {
|
|
10
|
+
folder?: unknown;
|
|
11
|
+
}, _options?: {}): string;
|
|
12
|
+
/** Prefix one folder-relative file exactly once; rejects unsafe file paths before returning it.
|
|
13
|
+
* @throws RepositoryPathError for invalid folders or noncanonical file paths.
|
|
14
|
+
* @complexity O(folder + path length), no effects.
|
|
15
|
+
*/
|
|
16
|
+
export declare function prefixRepositoryPath({ folder, path }: {
|
|
17
|
+
folder?: string | undefined;
|
|
18
|
+
path: string;
|
|
19
|
+
}, _options?: {}): string;
|
|
20
|
+
/** Exact directory-boundary containment for untrusted persisted repository paths.
|
|
21
|
+
* @returns False for malformed or noncanonical paths, including sibling prefix collisions.
|
|
22
|
+
* @complexity O(folder + path length), no effects.
|
|
23
|
+
*/
|
|
24
|
+
export declare function repositoryPathContained({ folder, path }: {
|
|
25
|
+
folder?: string | undefined;
|
|
26
|
+
path: string;
|
|
27
|
+
}, _options?: {}): boolean;
|
|
28
|
+
//# sourceMappingURL=repository-path.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Invalid repository destinations fail before any provider I/O. */
|
|
2
|
+
export class RepositoryPathError extends Error {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Normalize a repository-relative folder, preserving root only when explicitly empty or omitted.
|
|
6
|
+
* @throws RepositoryPathError for malformed values, absolute paths, controls or traversal.
|
|
7
|
+
* @complexity O(folder length), no effects.
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeRepositoryFolder({ folder = '' }, _options = {}) {
|
|
10
|
+
if (typeof folder !== 'string')
|
|
11
|
+
throw new RepositoryPathError('Target folder must be a string.');
|
|
12
|
+
const value = folder.replaceAll('\\', '/');
|
|
13
|
+
if (value.startsWith('/') || /[:\x00-\x1f\x7f]/.test(value))
|
|
14
|
+
throw new RepositoryPathError('Target folder must be relative and contain no controls or drive prefix.');
|
|
15
|
+
const segments = value.split('/');
|
|
16
|
+
if (segments.some(segment => segment === '.' || segment === '..'))
|
|
17
|
+
throw new RepositoryPathError('Target folder cannot contain . or .. segments.');
|
|
18
|
+
return segments.filter(Boolean).join('/');
|
|
19
|
+
}
|
|
20
|
+
/** Canonical file paths cannot normalize into a different path or into repository root. */
|
|
21
|
+
function canonicalFilePath({ path }, _options = {}) {
|
|
22
|
+
try {
|
|
23
|
+
return path !== '' && normalizeRepositoryFolder({ folder: path }) === path;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Prefix one folder-relative file exactly once; rejects unsafe file paths before returning it.
|
|
30
|
+
* @throws RepositoryPathError for invalid folders or noncanonical file paths.
|
|
31
|
+
* @complexity O(folder + path length), no effects.
|
|
32
|
+
*/
|
|
33
|
+
export function prefixRepositoryPath({ folder, path }, _options = {}) {
|
|
34
|
+
const normalized = normalizeRepositoryFolder({ folder });
|
|
35
|
+
if (!canonicalFilePath({ path }))
|
|
36
|
+
throw new RepositoryPathError('Repository file path must be a canonical relative path.');
|
|
37
|
+
return normalized ? `${normalized}/${path}` : path;
|
|
38
|
+
}
|
|
39
|
+
/** Exact directory-boundary containment for untrusted persisted repository paths.
|
|
40
|
+
* @returns False for malformed or noncanonical paths, including sibling prefix collisions.
|
|
41
|
+
* @complexity O(folder + path length), no effects.
|
|
42
|
+
*/
|
|
43
|
+
export function repositoryPathContained({ folder, path }, _options = {}) {
|
|
44
|
+
try {
|
|
45
|
+
const normalized = normalizeRepositoryFolder({ folder });
|
|
46
|
+
return canonicalFilePath({ path }) && (normalized === '' || path.startsWith(`${normalized}/`));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=repository-path.js.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/** Owner and repo, whatever the host: one URL path segment each, so never empty, never `.`/`..`,
|
|
2
2
|
* never a slash, whitespace or control character. */
|
|
3
|
-
|
|
3
|
+
// \s already covers \x09-\x0d, so the control ranges skip them.
|
|
4
|
+
const GENERIC_SEGMENT_PATTERN = /^[^\s/\\\x00-\x08\x0e-\x1f\x7f]{1,100}$/;
|
|
4
5
|
const BRANCH_PATTERN = /^[A-Za-z0-9._/-]{1,250}$/;
|
|
5
6
|
function isGenericSegment(value) {
|
|
6
|
-
|
|
7
|
+
// The pattern itself refuses whitespace and control characters anywhere in the value.
|
|
8
|
+
return GENERIC_SEGMENT_PATTERN.test(value) && value !== '.' && value !== '..';
|
|
7
9
|
}
|
|
8
10
|
/** Host rules precede the common one-URL-segment rule. Returns caller-safe refusal text. */
|
|
9
11
|
export function repositoryTargetError(required, optional = {}) {
|
|
@@ -21,7 +23,8 @@ export function validateCommitTarget(required, optional = {}) {
|
|
|
21
23
|
const error = repositoryTargetError({ owner: required.owner, repo: required.repo }, optional);
|
|
22
24
|
if (error !== null)
|
|
23
25
|
return error;
|
|
24
|
-
|
|
26
|
+
// BRANCH_PATTERN's allow-list already excludes whitespace and control characters.
|
|
27
|
+
if (optional.branch !== undefined && !BRANCH_PATTERN.test(optional.branch))
|
|
25
28
|
return `invalid branch name '${optional.branch.slice(0, 60)}'`;
|
|
26
29
|
if (required.commitMessage.trim() === '' || required.commitMessage.length > 500)
|
|
27
30
|
return 'commitMessage must be 1-500 characters';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
/** Kinds describe the host's routes; only redirect/not-found/well-known affect writing. */
|
|
2
|
-
export type ManifestRouteKind = string;
|
|
3
1
|
export interface ManifestRoute {
|
|
4
2
|
path: string;
|
|
5
|
-
|
|
3
|
+
/** Kinds describe the host's routes; only redirect/not-found/well-known affect writing. */
|
|
4
|
+
kind: string;
|
|
6
5
|
label: string;
|
|
7
6
|
redirectTarget?: string;
|
|
8
7
|
redirectStatusCode?: number;
|
|
@@ -59,14 +58,14 @@ export interface ThemeLayoutPort {
|
|
|
59
58
|
}
|
|
60
59
|
export interface ExportedRoute {
|
|
61
60
|
path: string;
|
|
62
|
-
kind:
|
|
61
|
+
kind: string;
|
|
63
62
|
outputFile: string;
|
|
64
63
|
data: string;
|
|
65
64
|
contentType?: string | null;
|
|
66
65
|
}
|
|
67
66
|
export interface FailedRoute {
|
|
68
67
|
path: string;
|
|
69
|
-
kind:
|
|
68
|
+
kind: string;
|
|
70
69
|
reason: string;
|
|
71
70
|
}
|
|
72
71
|
export interface ExportedAsset {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** One CSS `url(...)` token: its span in the source, the quote it used ('' when bare) and the raw value. */
|
|
2
|
+
export interface CssUrlToken {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
quote: string;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Every `url(...)` token, exactly as `css.matchAll(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g)` finds them
|
|
10
|
+
* (including that pattern's corner case where `url( )` captures the last space as the value), but
|
|
11
|
+
* scanned in linear time: the regex backtracks quadratically because its whitespace runs and value
|
|
12
|
+
* run overlap.
|
|
13
|
+
* @complexity O(css length).
|
|
14
|
+
*/
|
|
15
|
+
export declare function cssUrlTokens(css: string): CssUrlToken[];
|
|
16
|
+
//# sourceMappingURL=css-urls.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const VALUE_STOP = "'\")";
|
|
2
|
+
const isSpace = (char) => char !== undefined && /\s/.test(char);
|
|
3
|
+
/**
|
|
4
|
+
* Every `url(...)` token, exactly as `css.matchAll(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g)` finds them
|
|
5
|
+
* (including that pattern's corner case where `url( )` captures the last space as the value), but
|
|
6
|
+
* scanned in linear time: the regex backtracks quadratically because its whitespace runs and value
|
|
7
|
+
* run overlap.
|
|
8
|
+
* @complexity O(css length).
|
|
9
|
+
*/
|
|
10
|
+
export function cssUrlTokens(css) {
|
|
11
|
+
const tokens = [];
|
|
12
|
+
const stops = createStopFinder(css);
|
|
13
|
+
let from = css.indexOf('url(');
|
|
14
|
+
while (from !== -1) {
|
|
15
|
+
const token = cssUrlTokenAt(css, from, stops);
|
|
16
|
+
if (token)
|
|
17
|
+
tokens.push(token);
|
|
18
|
+
from = css.indexOf('url(', token ? token.end : from + 1);
|
|
19
|
+
}
|
|
20
|
+
return tokens;
|
|
21
|
+
}
|
|
22
|
+
/** Index of the first `'`, `"` or `)` at or after a position; positions only grow, so one scan serves all. */
|
|
23
|
+
function createStopFinder(css) {
|
|
24
|
+
let found = -1;
|
|
25
|
+
return (position) => {
|
|
26
|
+
if (found >= position)
|
|
27
|
+
return found;
|
|
28
|
+
found = position;
|
|
29
|
+
while (found < css.length && !VALUE_STOP.includes(css.charAt(found)))
|
|
30
|
+
found += 1;
|
|
31
|
+
return found;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function skipSpaces(css, position) {
|
|
35
|
+
let index = position;
|
|
36
|
+
while (isSpace(css[index]))
|
|
37
|
+
index += 1;
|
|
38
|
+
return index;
|
|
39
|
+
}
|
|
40
|
+
function cssUrlTokenAt(css, start, stopAt) {
|
|
41
|
+
const open = start + 'url('.length;
|
|
42
|
+
const valueStart = skipSpaces(css, open);
|
|
43
|
+
const quote = css.charAt(valueStart);
|
|
44
|
+
if (quote === "'" || quote === '"')
|
|
45
|
+
return quotedToken({ css, start, quote, valueStart: valueStart + 1, stopAt });
|
|
46
|
+
const valueEnd = stopAt(valueStart);
|
|
47
|
+
if (css[valueEnd] !== ')')
|
|
48
|
+
return null;
|
|
49
|
+
if (valueEnd > valueStart)
|
|
50
|
+
return { start, end: valueEnd + 1, quote: '', value: css.slice(valueStart, valueEnd) };
|
|
51
|
+
// An empty value can only borrow the last leading space, as the regex's backtracking does.
|
|
52
|
+
if (valueStart > open)
|
|
53
|
+
return { start, end: valueEnd + 1, quote: '', value: css.charAt(valueStart - 1) };
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
function quotedToken(input) {
|
|
57
|
+
const { css, start, quote, valueStart, stopAt } = input;
|
|
58
|
+
const valueEnd = stopAt(valueStart);
|
|
59
|
+
if (valueEnd === valueStart || css[valueEnd] !== quote)
|
|
60
|
+
return null;
|
|
61
|
+
const close = skipSpaces(css, valueEnd + 1);
|
|
62
|
+
if (css[close] !== ')')
|
|
63
|
+
return null;
|
|
64
|
+
return { start, end: close + 1, quote, value: css.slice(valueStart, valueEnd) };
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=css-urls.js.map
|
|
@@ -3,13 +3,14 @@ export interface HtmlUrlLocation {
|
|
|
3
3
|
end: number;
|
|
4
4
|
kind: 'url' | 'srcset' | 'css' | 'action';
|
|
5
5
|
attribute?: string;
|
|
6
|
+
identity?: boolean;
|
|
6
7
|
}
|
|
7
8
|
/** Source ranges from the workspace's HTML parser; no serialization can alter article content.
|
|
8
9
|
* @complexity O(n + a log a) in HTML bytes and source attributes; iterative traversal avoids recursion limits. */
|
|
9
10
|
export declare function htmlUrlLocations({ html }: {
|
|
10
11
|
html: string;
|
|
11
12
|
}, _optional?: {}): HtmlUrlLocation[];
|
|
12
|
-
/** CSS, sitemap and manifest positions use their response format, never an HTML text scan. */
|
|
13
|
+
/** CSS, Markdown indexes, sitemap and manifest positions use their response format, never an HTML text scan. */
|
|
13
14
|
export declare function exportUrlLocations({ body, contentType }: {
|
|
14
15
|
body: string;
|
|
15
16
|
contentType: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parse } from 'parse5';
|
|
2
|
+
import { cssUrlTokens } from './css-urls.js';
|
|
2
3
|
const URL_ATTRIBUTES = new Set(['src', 'href', 'poster']);
|
|
3
4
|
/** The exact attribute value range, preserving quotes, spacing and all surrounding source bytes. */
|
|
4
5
|
function attributeLocation({ html, start, end, kind }, _optional = {}) {
|
|
@@ -41,6 +42,14 @@ function styleLocations({ element }, _optional = {}) {
|
|
|
41
42
|
return element.childNodes.flatMap(child => child.sourceCodeLocation
|
|
42
43
|
? [{ start: child.sourceCodeLocation.startOffset, end: child.sourceCodeLocation.endOffset, kind: 'css' }] : []);
|
|
43
44
|
}
|
|
45
|
+
/** Canonical identity and feed discovery must remain absolute when a download relocates files. */
|
|
46
|
+
function isIdentityLink({ element }, _optional = {}) {
|
|
47
|
+
if (element.tagName !== 'link')
|
|
48
|
+
return false;
|
|
49
|
+
const rel = element.attrs.find(attr => attr.name === 'rel')?.value.toLowerCase().split(/\s+/) ?? [];
|
|
50
|
+
const type = element.attrs.find(attr => attr.name === 'type')?.value.toLowerCase();
|
|
51
|
+
return rel.includes('canonical') || (rel.includes('alternate') && (type === 'application/rss+xml' || type === 'application/atom+xml'));
|
|
52
|
+
}
|
|
44
53
|
/** Collect one element's real URL/style positions, excluding lookalike strings in text and scripts. */
|
|
45
54
|
function elementLocations({ element, html }, _optional = {}) {
|
|
46
55
|
const locations = [];
|
|
@@ -51,7 +60,7 @@ function elementLocations({ element, html }, _optional = {}) {
|
|
|
51
60
|
continue;
|
|
52
61
|
const location = attributeLocation({ html, start: source.startOffset, end: source.endOffset, kind });
|
|
53
62
|
if (location)
|
|
54
|
-
locations.push({ ...location, attribute: attr.name });
|
|
63
|
+
locations.push({ ...location, attribute: attr.name, ...(isIdentityLink({ element }) ? { identity: true } : {}) });
|
|
55
64
|
}
|
|
56
65
|
locations.push(...styleLocations({ element }));
|
|
57
66
|
return locations;
|
|
@@ -73,12 +82,23 @@ export function htmlUrlLocations({ html }, _optional = {}) {
|
|
|
73
82
|
}
|
|
74
83
|
return locations.sort((a, b) => a.start - b.start);
|
|
75
84
|
}
|
|
76
|
-
/**
|
|
85
|
+
/** Generated llms indexes use one Markdown list link per line; prose stays untouched.
|
|
86
|
+
* @complexity O(body bytes), returning destination ranges only; no effects.
|
|
87
|
+
*/
|
|
88
|
+
function markdownLinkLocations({ body }, _optional = {}) {
|
|
89
|
+
return [...body.matchAll(/^- \[[^\r\n]*\]\(([^)\r\n]*)\)/gm)].map(match => ({
|
|
90
|
+
start: match.index + match[0].length - match[1].length - 1,
|
|
91
|
+
end: match.index + match[0].length - 1, kind: 'url',
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
/** CSS, Markdown indexes, sitemap and manifest positions use their response format, never an HTML text scan. */
|
|
77
95
|
export function exportUrlLocations({ body, contentType }, _optional = {}) {
|
|
78
96
|
if (/^text\/html\b/i.test(contentType))
|
|
79
97
|
return htmlUrlLocations({ html: body });
|
|
80
98
|
if (/^text\/css\b/i.test(contentType))
|
|
81
|
-
return
|
|
99
|
+
return cssUrlTokens(body).map(({ start, end }) => ({ start, end, kind: 'css' }));
|
|
100
|
+
if (/^text\/markdown\b/i.test(contentType))
|
|
101
|
+
return markdownLinkLocations({ body });
|
|
82
102
|
if (/\bxml\b/i.test(contentType))
|
|
83
103
|
return [...body.matchAll(/<((?:[\w-]+:)?loc)>([^<]*)<\/\1>/g)].map(match => ({ start: match.index + match[1].length + 2, end: match.index + match[0].length - match[1].length - 3, kind: 'url' }));
|
|
84
104
|
if (!/\bjson\b/i.test(contentType))
|
|
@@ -83,6 +83,9 @@ export function createNodeArtifactWriter(_required, _optional = {}) {
|
|
|
83
83
|
},
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
+
function closeServer(server) {
|
|
87
|
+
return new Promise(resolve => { server.close(() => resolve()); });
|
|
88
|
+
}
|
|
86
89
|
/** Independent Node loopback adapter. The app factory is required and remains owned by the host. */
|
|
87
90
|
export function createNodeAppFactory(required, _optional = {}) {
|
|
88
91
|
return { async open() {
|
|
@@ -93,7 +96,7 @@ export function createNodeAppFactory(required, _optional = {}) {
|
|
|
93
96
|
return;
|
|
94
97
|
closed = true;
|
|
95
98
|
server.closeAllConnections();
|
|
96
|
-
await
|
|
99
|
+
await closeServer(server);
|
|
97
100
|
};
|
|
98
101
|
try {
|
|
99
102
|
server.listen(0, '127.0.0.1');
|
|
@@ -113,9 +116,11 @@ export function createNodeAssetSource(_required, _optional = {}) {
|
|
|
113
116
|
const files = [];
|
|
114
117
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
115
118
|
const relative = prefix + entry.name;
|
|
116
|
-
if (entry.isDirectory())
|
|
119
|
+
if (entry.isDirectory()) {
|
|
117
120
|
files.push(...await list(path.join(directory, entry.name), relative + '/'));
|
|
118
|
-
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (entry.isFile())
|
|
119
124
|
files.push(relative);
|
|
120
125
|
}
|
|
121
126
|
return files;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ExportPathError } from "./contracts.js";
|
|
2
2
|
import { extractAssetUrls, extractHtmlReferences, extractCssUrls, normalizeBasePath, outputFileForUrl, redirectOutcomeFor, renderRedirectStub, rewriteRouteBodyForBasePath, rewriteAssetBodyForBasePath, safeRelativeOutputFile } from './transforms.js';
|
|
3
|
+
import { trimCharsEnd } from '@jini-ai/core/primitives';
|
|
3
4
|
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).";
|
|
4
5
|
async function request(ctx, url) {
|
|
5
6
|
// Redirects are observed, never followed off the caller's app, for routes and assets alike.
|
|
@@ -66,10 +67,11 @@ function enqueueDiscovered(required) {
|
|
|
66
67
|
state.queued.add(next.path);
|
|
67
68
|
if (state.discovered >= MAX_DISCOVERED_ROUTES) {
|
|
68
69
|
state.skipped.push({ reason: 'discovered-route-cap', detail: `${next.path} (over ${MAX_DISCOVERED_ROUTES} discovered routes)` });
|
|
69
|
-
continue;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
else {
|
|
72
|
+
state.discovered += 1;
|
|
73
|
+
state.queue.push(next);
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
/** Discovery uses the response route's format, so prose cannot masquerade as a manifest. */
|
|
@@ -86,18 +88,7 @@ async function writeRoutes(ctx, routes) {
|
|
|
86
88
|
for (let index = 0; index < state.queue.length; index++) {
|
|
87
89
|
const route = state.queue[index];
|
|
88
90
|
try {
|
|
89
|
-
|
|
90
|
-
if ('reason' in outcome) {
|
|
91
|
-
failed.push({ path: route.path, kind: route.kind, reason: outcome.reason });
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
succeeded.push(outcome.route);
|
|
95
|
-
const html = outcome.crawlHtml;
|
|
96
|
-
if (html === undefined)
|
|
97
|
-
continue;
|
|
98
|
-
for (const url of extractAssetUrls({ html, prefixes: ctx.args.assetUrlPrefixes }, { format: routeAssetFormat({ path: route.path }) }))
|
|
99
|
-
assets.add(url);
|
|
100
|
-
enqueueDiscovered({ state, routes: ctx.args.discoverRoutes?.({ path: route.path, html }) ?? [] });
|
|
91
|
+
await writeAndScanRoute({ ctx, route, state }, { succeeded, failed, assets });
|
|
101
92
|
}
|
|
102
93
|
catch (error) {
|
|
103
94
|
failed.push({ path: route.path, kind: route.kind, reason: failureReason(ctx, route.path, error) });
|
|
@@ -105,6 +96,21 @@ async function writeRoutes(ctx, routes) {
|
|
|
105
96
|
}
|
|
106
97
|
return { succeeded, failed, assets, skipped: state.skipped };
|
|
107
98
|
}
|
|
99
|
+
/** Writes one route, then crawls its HTML (when any) for assets and further routes. */
|
|
100
|
+
async function writeAndScanRoute({ ctx, route, state }, out) {
|
|
101
|
+
const outcome = await writeRoute(ctx, route);
|
|
102
|
+
if ('reason' in outcome) {
|
|
103
|
+
out.failed.push({ path: route.path, kind: route.kind, reason: outcome.reason });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
out.succeeded.push(outcome.route);
|
|
107
|
+
const html = outcome.crawlHtml;
|
|
108
|
+
if (html === undefined)
|
|
109
|
+
return;
|
|
110
|
+
for (const url of extractAssetUrls({ html, prefixes: ctx.args.assetUrlPrefixes }, { format: routeAssetFormat({ path: route.path }) }))
|
|
111
|
+
out.assets.add(url);
|
|
112
|
+
enqueueDiscovered({ state, routes: ctx.args.discoverRoutes?.({ path: route.path, html }) ?? [] });
|
|
113
|
+
}
|
|
108
114
|
async function fetchAsset(required) {
|
|
109
115
|
const { ctx, url } = required;
|
|
110
116
|
const outputFile = outputFileForUrl({ url });
|
|
@@ -137,9 +143,22 @@ function assetFailureReason(required) {
|
|
|
137
143
|
const { ctx, url, error } = required;
|
|
138
144
|
return error instanceof ExportPathError && ctx.args.assetPathFailureReason !== undefined ? ctx.args.assetPathFailureReason : failureReason(ctx, url, error);
|
|
139
145
|
}
|
|
146
|
+
/** Fetch one asset and queue its children, returning its physical output claim on success.
|
|
147
|
+
* Failed variants leave the destination available for another URL's retry. */
|
|
148
|
+
async function fetchAndQueueAsset({ ctx, url, crawlCss, queue }, out) {
|
|
149
|
+
const outcome = await fetchAsset({ ctx, url, crawlCss });
|
|
150
|
+
if ('reason' in outcome) {
|
|
151
|
+
out.failed.push({ url, reason: outcome.reason });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
out.succeeded.push(outcome.asset);
|
|
155
|
+
for (const child of outcome.children)
|
|
156
|
+
queue.push({ url: child, crawlCss: false });
|
|
157
|
+
return outcome.asset.outputFile;
|
|
158
|
+
}
|
|
140
159
|
async function writeAssets(ctx, initial) {
|
|
141
160
|
const succeeded = [], failed = [];
|
|
142
|
-
const seen = new Set();
|
|
161
|
+
const seen = new Set(), written = new Set();
|
|
143
162
|
const queue = initial.map(url => ({ url, crawlCss: true }));
|
|
144
163
|
for (let index = 0; index < queue.length; index++) {
|
|
145
164
|
const { url, crawlCss } = queue[index];
|
|
@@ -147,14 +166,12 @@ async function writeAssets(ctx, initial) {
|
|
|
147
166
|
continue;
|
|
148
167
|
seen.add(url);
|
|
149
168
|
try {
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
failed.push({ url, reason: outcome.reason });
|
|
169
|
+
// Query/cache variants share one static filename; report exactly the file the writer owns.
|
|
170
|
+
if (written.has(outputFileForUrl({ url })))
|
|
153
171
|
continue;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
queue.push({ url: child, crawlCss: false });
|
|
172
|
+
const outputFile = await fetchAndQueueAsset({ ctx, url, crawlCss, queue }, { succeeded, failed });
|
|
173
|
+
if (outputFile !== undefined)
|
|
174
|
+
written.add(outputFile);
|
|
158
175
|
}
|
|
159
176
|
catch (error) {
|
|
160
177
|
failed.push({ url, reason: assetFailureReason({ ctx, url, error }) });
|
|
@@ -182,7 +199,7 @@ async function unreferenced(ctx, manifest, assets) {
|
|
|
182
199
|
const MAX_DROPPED_REFERENCES = 200;
|
|
183
200
|
/** Site path normalization shared by written outputs and references: no trailing slashes, root as '/'. */
|
|
184
201
|
function pathNormalizer(required) {
|
|
185
|
-
return url => new URL(url, required.origin).pathname
|
|
202
|
+
return url => trimCharsEnd({ text: new URL(url, required.origin).pathname, chars: '/' }) || '/';
|
|
186
203
|
}
|
|
187
204
|
/** Every path this run wrote: artifact paths (and index.html directory aliases), route paths except the error-page probe, and asset URLs. */
|
|
188
205
|
function writtenPaths(required) {
|
|
@@ -244,11 +261,9 @@ function droppedReference(required) {
|
|
|
244
261
|
function recordDrop(required) {
|
|
245
262
|
const { dropped, drop } = required;
|
|
246
263
|
const key = drop.page + '\n' + drop.url;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
else if (dropped.size < MAX_DROPPED_REFERENCES)
|
|
264
|
+
const replacesEarlier = dropped.has(key) && drop.reason === 'needs-server';
|
|
265
|
+
const addsNew = !dropped.has(key) && dropped.size < MAX_DROPPED_REFERENCES;
|
|
266
|
+
if (replacesEarlier || addsNew)
|
|
252
267
|
dropped.set(key, drop);
|
|
253
268
|
}
|
|
254
269
|
/** Compare written HTML with this run's outputs only; no requests or filesystem reads.
|
|
@@ -272,7 +287,9 @@ function droppedReferences(required) {
|
|
|
272
287
|
/** The app session's origin. Anything but a bare http(s) origin without credentials is refused. */
|
|
273
288
|
function sessionOrigin(required) {
|
|
274
289
|
const origin = new URL(required.baseUrl);
|
|
275
|
-
|
|
290
|
+
const hasCredentials = Boolean(origin.username || origin.password);
|
|
291
|
+
const hasPathOrQuery = origin.pathname !== '/' || Boolean(origin.search || origin.hash);
|
|
292
|
+
if (!['http:', 'https:'].includes(origin.protocol) || hasCredentials || hasPathOrQuery)
|
|
276
293
|
throw new Error('App session baseUrl must be an HTTP origin without credentials.');
|
|
277
294
|
return origin.origin;
|
|
278
295
|
}
|