@ogygia/compiler 0.0.0 → 0.14.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/LICENSE +21 -0
- package/README.md +62 -1
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/app-spec.d.ts +18 -0
- package/dist/app-spec.js +22 -0
- package/dist/blank-styles.d.ts +1 -0
- package/dist/blank-styles.js +24 -0
- package/dist/bom.d.ts +2 -0
- package/dist/bom.js +7 -0
- package/dist/build-cache.d.ts +13 -0
- package/dist/build-cache.js +65 -0
- package/dist/ctx.d.ts +238 -0
- package/dist/ctx.js +221 -0
- package/dist/dev/css-scope.d.ts +16 -0
- package/dist/dev/css-scope.js +32 -0
- package/dist/dev/dev-hmr.d.ts +24 -0
- package/dist/dev/dev-hmr.js +51 -0
- package/dist/dev/hmr.d.ts +34 -0
- package/dist/dev/hmr.js +52 -0
- package/dist/driver.d.ts +351 -0
- package/dist/driver.js +1402 -0
- package/dist/exports/index.d.ts +77 -0
- package/dist/exports/index.js +349 -0
- package/dist/exports/parse.d.ts +65 -0
- package/dist/exports/parse.js +251 -0
- package/dist/fouc-css.d.ts +112 -0
- package/dist/fouc-css.js +314 -0
- package/dist/free-vars.d.ts +32 -0
- package/dist/free-vars.js +454 -0
- package/dist/fs.d.ts +31 -0
- package/dist/fs.js +82 -0
- package/dist/ids.d.ts +49 -0
- package/dist/ids.js +52 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/kit.d.ts +204 -0
- package/dist/kit.js +554 -0
- package/dist/leg.d.ts +34 -0
- package/dist/leg.js +26 -0
- package/dist/link/analyses.d.ts +26 -0
- package/dist/link/analyses.js +237 -0
- package/dist/link/build-output.d.ts +47 -0
- package/dist/link/build-output.js +168 -0
- package/dist/link/caps.d.ts +32 -0
- package/dist/link/caps.js +39 -0
- package/dist/link/context-detect.d.ts +28 -0
- package/dist/link/context-detect.js +143 -0
- package/dist/link/emit-gate.d.ts +43 -0
- package/dist/link/emit-gate.js +55 -0
- package/dist/link/file-token.d.ts +11 -0
- package/dist/link/file-token.js +15 -0
- package/dist/link/island-deps.d.ts +183 -0
- package/dist/link/island-deps.js +802 -0
- package/dist/link/location-map.d.ts +24 -0
- package/dist/link/location-map.js +51 -0
- package/dist/link/own-reach.d.ts +15 -0
- package/dist/link/own-reach.js +188 -0
- package/dist/link/registry-stub.d.ts +50 -0
- package/dist/link/registry-stub.js +163 -0
- package/dist/link/relocations.d.ts +79 -0
- package/dist/link/relocations.js +204 -0
- package/dist/link/router-css.d.ts +38 -0
- package/dist/link/router-css.js +124 -0
- package/dist/link/runtime-entry.d.ts +103 -0
- package/dist/link/runtime-entry.js +183 -0
- package/dist/link/server-manifest.d.ts +25 -0
- package/dist/link/server-manifest.js +102 -0
- package/dist/link/transport.d.ts +42 -0
- package/dist/link/transport.js +91 -0
- package/dist/macros/dollar.d.ts +24 -0
- package/dist/macros/dollar.js +397 -0
- package/dist/macros/pipeline.d.ts +50 -0
- package/dist/macros/pipeline.js +133 -0
- package/dist/macros/source.d.ts +9 -0
- package/dist/macros/source.js +115 -0
- package/dist/macros/store.d.ts +22 -0
- package/dist/macros/store.js +217 -0
- package/dist/macros/wire.d.ts +17 -0
- package/dist/macros/wire.js +116 -0
- package/dist/map-chain.d.ts +18 -0
- package/dist/map-chain.js +42 -0
- package/dist/messages.d.ts +673 -0
- package/dist/messages.js +938 -0
- package/dist/ownership-stamps.d.ts +11 -0
- package/dist/ownership-stamps.js +112 -0
- package/dist/parse/oxc.d.ts +36 -0
- package/dist/parse/oxc.js +35 -0
- package/dist/parse/roots.d.ts +4 -0
- package/dist/parse/roots.js +27 -0
- package/dist/parse/scan.d.ts +65 -0
- package/dist/parse/scan.js +297 -0
- package/dist/parse/svelte-ast.d.ts +7 -0
- package/dist/parse/svelte-ast.js +99 -0
- package/dist/program.d.ts +140 -0
- package/dist/program.js +304 -0
- package/dist/queries.d.ts +105 -0
- package/dist/queries.js +326 -0
- package/dist/region/emit.d.ts +168 -0
- package/dist/region/emit.js +292 -0
- package/dist/region/identity.d.ts +32 -0
- package/dist/region/identity.js +46 -0
- package/dist/region/ir.d.ts +56 -0
- package/dist/region/ir.js +0 -0
- package/dist/region/marked-imports.d.ts +27 -0
- package/dist/region/marked-imports.js +265 -0
- package/dist/region/transform.d.ts +189 -0
- package/dist/region/transform.js +1565 -0
- package/dist/scan-facts.d.ts +36 -0
- package/dist/scan-facts.js +54 -0
- package/dist/script-request.d.ts +1 -0
- package/dist/script-request.js +33 -0
- package/dist/splice.d.ts +11 -0
- package/dist/splice.js +33 -0
- package/dist/transportables.d.ts +23 -0
- package/dist/transportables.js +144 -0
- package/dist/virtual/core.d.ts +158 -0
- package/dist/virtual/core.js +588 -0
- package/dist/virtual/resolver.d.ts +62 -0
- package/dist/virtual/resolver.js +265 -0
- package/dist/virtual/specifier.d.ts +10 -0
- package/dist/virtual/specifier.js +6 -0
- package/dist/virtual/table.d.ts +120 -0
- package/dist/virtual/table.js +54 -0
- package/dist/virtual/types.d.ts +17 -0
- package/dist/virtual/types.js +100 -0
- package/dist/virtual/value-names.d.ts +2 -0
- package/dist/virtual/value-names.js +18 -0
- package/dist/vite/definers.d.ts +16 -0
- package/dist/vite/definers.js +69 -0
- package/dist/vite/dev-maps.d.ts +34 -0
- package/dist/vite/dev-maps.js +91 -0
- package/dist/vite/index.d.ts +21 -0
- package/dist/vite/index.js +890 -0
- package/dist/vite/kit-dirs.d.ts +6 -0
- package/dist/vite/kit-dirs.js +53 -0
- package/dist/vite/late-island.d.ts +8 -0
- package/dist/vite/late-island.js +18 -0
- package/dist/vite/lazy-files.d.ts +2 -0
- package/dist/vite/lazy-files.js +72 -0
- package/dist/vite/options.d.ts +195 -0
- package/dist/vite/options.js +72 -0
- package/dist/vite/package-files.d.ts +3 -0
- package/dist/vite/package-files.js +88 -0
- package/dist/vite/paths.d.ts +16 -0
- package/dist/vite/paths.js +39 -0
- package/dist/vite/plugin-api.d.ts +316 -0
- package/dist/vite/plugin-api.js +328 -0
- package/dist/vite/route-watch.d.ts +15 -0
- package/dist/vite/route-watch.js +32 -0
- package/dist/vite/session.d.ts +28 -0
- package/dist/vite/session.js +43 -0
- package/dist/vite/sourcemaps.d.ts +19 -0
- package/dist/vite/sourcemaps.js +75 -0
- package/dist/vite/style-preprocess.d.ts +2 -0
- package/dist/vite/style-preprocess.js +84 -0
- package/dist/vite/svelte-entries.d.ts +4 -0
- package/dist/vite/svelte-entries.js +10 -0
- package/dist/vite/svelte-options.d.ts +20 -0
- package/dist/vite/svelte-options.js +22 -0
- package/package.json +87 -12
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { KitConfig } from "../kit.js";
|
|
2
|
+
type PluginOption = unknown;
|
|
3
|
+
/** Read `root`'s Kit config (defaults when absent or unreadable): its dirs and inline-style
|
|
4
|
+
* threshold, for the plugin that asked to hold. `plugins`: the Vite config's plugin list. */
|
|
5
|
+
export declare function load_kit_config(root: string, plugins?: PluginOption): Promise<KitConfig>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DEFAULT_KIT_DIRS } from "../kit.js";
|
|
2
|
+
import { warn } from "../messages.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
// src/vite/kit-dirs.ts
|
|
7
|
+
const CONFIG_FILES = ["svelte.config.js", "svelte.config.mjs"];
|
|
8
|
+
async function flatten_plugins(option) {
|
|
9
|
+
const out = [];
|
|
10
|
+
const walk = async (p) => {
|
|
11
|
+
const v = await p;
|
|
12
|
+
if (!v) return;
|
|
13
|
+
if (Array.isArray(v)) for (const x of v) await walk(x);
|
|
14
|
+
else if (typeof v === "object") out.push(v);
|
|
15
|
+
};
|
|
16
|
+
await walk(option);
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
async function kit_options_from_plugins(plugins) {
|
|
20
|
+
const options = ((await flatten_plugins(plugins)).find((p) => p.name === "vite-plugin-sveltekit-setup")?.api)?.options;
|
|
21
|
+
if (!options) return null;
|
|
22
|
+
return options.kit ?? options;
|
|
23
|
+
}
|
|
24
|
+
async function kit_options_from_file(root) {
|
|
25
|
+
const file = CONFIG_FILES.map((f) => path.join(root, f)).find((f) => existsSync(f));
|
|
26
|
+
if (!file) return null;
|
|
27
|
+
try {
|
|
28
|
+
return (await import(pathToFileURL(file).href)).default?.kit ?? {};
|
|
29
|
+
} catch (e) {
|
|
30
|
+
warn("kit_config_unreadable", {
|
|
31
|
+
file: path.relative(root, file),
|
|
32
|
+
routes: DEFAULT_KIT_DIRS.routes,
|
|
33
|
+
out: DEFAULT_KIT_DIRS.out,
|
|
34
|
+
reason: e instanceof Error ? e.message : String(e)
|
|
35
|
+
});
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Read `root`'s Kit config (defaults when absent or unreadable): its dirs and inline-style
|
|
40
|
+
* threshold, for the plugin that asked to hold. `plugins`: the Vite config's plugin list. */
|
|
41
|
+
async function load_kit_config(root, plugins) {
|
|
42
|
+
const kit = await kit_options_from_plugins(plugins) ?? await kit_options_from_file(root) ?? {};
|
|
43
|
+
const dirs = {
|
|
44
|
+
routes_dir: path.resolve(root, kit.files?.routes ?? DEFAULT_KIT_DIRS.routes),
|
|
45
|
+
out_dir: path.resolve(root, kit.outDir ?? DEFAULT_KIT_DIRS.out)
|
|
46
|
+
};
|
|
47
|
+
const threshold = kit.inlineStyleThreshold;
|
|
48
|
+
return {
|
|
49
|
+
dirs,
|
|
50
|
+
inline_style_threshold: typeof threshold === "number" && Number.isFinite(threshold) && threshold > 0 ? threshold : 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { load_kit_config };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SvelteCompile } from "./svelte-options.js";
|
|
2
|
+
/** Region's twin imports: the file it imports → its awaiting twin (beside it). */
|
|
3
|
+
export declare const ASYNC_TWINS: Readonly<Record<string, string>>;
|
|
4
|
+
/** Does the app compile with Svelte's async mode? */
|
|
5
|
+
export declare function svelte_async_enabled(svelte: SvelteCompile | null): boolean;
|
|
6
|
+
/** The awaiting twin a Region twin import resolves to in an app with async mode on (beside Region,
|
|
7
|
+
* whichever copy imported it), or null for any other import. */
|
|
8
|
+
export declare function async_twin_redirect(source: string, importer: string | undefined, region_modules: ReadonlySet<string>): string | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/vite/late-island.ts
|
|
2
|
+
/** Region's twin imports: the file it imports → its awaiting twin (beside it). */
|
|
3
|
+
const ASYNC_TWINS = {
|
|
4
|
+
"./LateIsland.svelte": "LateIslandAwait.svelte",
|
|
5
|
+
"./PromiseRegion.svelte": "PromiseRegionAwait.svelte"
|
|
6
|
+
};
|
|
7
|
+
/** Does the app compile with Svelte's async mode? */
|
|
8
|
+
function svelte_async_enabled(svelte) {
|
|
9
|
+
return svelte?.compilerOptions?.experimental?.async === true;
|
|
10
|
+
}
|
|
11
|
+
/** The awaiting twin a Region twin import resolves to in an app with async mode on (beside Region,
|
|
12
|
+
* whichever copy imported it), or null for any other import. */
|
|
13
|
+
function async_twin_redirect(source, importer, region_modules) {
|
|
14
|
+
const twin = ASYNC_TWINS[source];
|
|
15
|
+
if (!twin || !importer || !region_modules.has(importer)) return null;
|
|
16
|
+
return importer.slice(0, importer.lastIndexOf("/") + 1) + twin;
|
|
17
|
+
}
|
|
18
|
+
export { ASYNC_TWINS, async_twin_redirect, svelte_async_enabled };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { FILE_TOKEN_RE, file_token, file_token_id } from "../link/file-token.js";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
// src/vite/lazy-files.ts
|
|
4
|
+
const LOADER_RE = /\bimport_again\(\s*\(\)\s*=>\s*import\(\s*(["'`])([^"'`]+)\1\s*\)/g;
|
|
5
|
+
function call_end(code, open) {
|
|
6
|
+
let depth = 0;
|
|
7
|
+
let args = 1;
|
|
8
|
+
let last = "";
|
|
9
|
+
for (let i = open; i < code.length; i++) {
|
|
10
|
+
const c = code[i];
|
|
11
|
+
if (c === "\"" || c === "'" || c === "`") {
|
|
12
|
+
for (i++; i < code.length && code[i] !== c; i++) if (code[i] === "\\") i++;
|
|
13
|
+
last = c;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (c === "/" && (code[i + 1] === "/" || code[i + 1] === "*")) {
|
|
17
|
+
const close = code.indexOf(code[i + 1] === "/" ? "\n" : "*/", i + 2);
|
|
18
|
+
if (close === -1) return null;
|
|
19
|
+
i = code[i + 1] === "/" ? close : close + 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
23
|
+
else if (c === ")" || c === "]" || c === "}") {
|
|
24
|
+
if (--depth === 0) return {
|
|
25
|
+
end: i,
|
|
26
|
+
args: last === "," ? args - 1 : args
|
|
27
|
+
};
|
|
28
|
+
} else if (c === "," && depth === 1) args++;
|
|
29
|
+
if (c.trim()) last = c;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
function dev_url(id) {
|
|
34
|
+
if (id.startsWith("\0")) return null;
|
|
35
|
+
return `/@fs/${id.replace(/^\/+/, "")}`;
|
|
36
|
+
}
|
|
37
|
+
function lazy_files() {
|
|
38
|
+
let dev = false;
|
|
39
|
+
return {
|
|
40
|
+
name: "ogygia:lazy-files",
|
|
41
|
+
configResolved(config) {
|
|
42
|
+
dev = config.command === "serve";
|
|
43
|
+
},
|
|
44
|
+
async transform(code, importer) {
|
|
45
|
+
const loaders = code.includes("import_again(");
|
|
46
|
+
const tokens = dev && code.includes("__OGYGIA_FILE_");
|
|
47
|
+
if (!loaders && !tokens) return null;
|
|
48
|
+
const s = new MagicString(code);
|
|
49
|
+
if (loaders) for (const m of code.matchAll(LOADER_RE)) {
|
|
50
|
+
const [, , spec] = m;
|
|
51
|
+
const call = call_end(code, m.index + 12);
|
|
52
|
+
if (call === null || call.args > 2) continue;
|
|
53
|
+
let file;
|
|
54
|
+
if (dev && spec.startsWith(".")) file = JSON.stringify(spec);
|
|
55
|
+
else {
|
|
56
|
+
const resolved = await this.resolve(spec, importer);
|
|
57
|
+
if (!resolved || resolved.external) file = null;
|
|
58
|
+
else file = dev ? JSON.stringify(dev_url(resolved.id)) : file_token(resolved.id);
|
|
59
|
+
}
|
|
60
|
+
const before = code.slice(0, call.end).trimEnd();
|
|
61
|
+
s.appendLeft(before.endsWith(",") ? before.length - 1 : call.end, `${call.args === 1 ? ", void 0" : ""}, ${file ?? "null"}, import.meta.url`);
|
|
62
|
+
}
|
|
63
|
+
if (tokens) for (const m of code.matchAll(FILE_TOKEN_RE)) s.overwrite(m.index, m.index + m[0].length, JSON.stringify(dev_url(file_token_id(m[2]))));
|
|
64
|
+
if (!s.hasChanged()) return null;
|
|
65
|
+
return {
|
|
66
|
+
code: s.toString(),
|
|
67
|
+
map: s.generateMap({ hires: true })
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export { lazy_files };
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { ImportKeys } from "../region/transform.js";
|
|
2
|
+
/**
|
|
3
|
+
* Named strategy bundle referenced from source via `with { preset: 'name' }`
|
|
4
|
+
* (or the renamed `importKeys.preset` key).
|
|
5
|
+
*
|
|
6
|
+
* A preset speaks the SAME grammar as an inline import: a `render` mode with its timing (`fetch` for
|
|
7
|
+
* a `deferred` hole, `wake` for an island), plus the tuning options that aren't allowed inline
|
|
8
|
+
* (`margin`, `maxAge`, …).
|
|
9
|
+
*/
|
|
10
|
+
export interface OgygiaPreset {
|
|
11
|
+
/**
|
|
12
|
+
* Delivery mode (the `render` import attribute): `'static'` (default — an island that hydrates)
|
|
13
|
+
* | `'deferred'` (a hole whose HTML is fetched, on its `fetch` timing) | `'live'` (a hole that
|
|
14
|
+
* revalidates).
|
|
15
|
+
*/
|
|
16
|
+
render?: "static" | "deferred" | "live";
|
|
17
|
+
/**
|
|
18
|
+
* When an island's JS runs (the `wake` import attribute): `'load'` | `'idle'` | `'visible'` |
|
|
19
|
+
* `'interaction'` | a CSS media query | `'none'` (a frozen lake). With `render: 'live'`, the
|
|
20
|
+
* revalidate schedule. Never a `deferred` hole's timing — that is `fetch`.
|
|
21
|
+
*/
|
|
22
|
+
wake?: string;
|
|
23
|
+
/**
|
|
24
|
+
* A `render: 'deferred'` hole's timing — when its HTML arrives (the `fetch` import attribute):
|
|
25
|
+
* `'load'` (default) | `'idle'` | `'visible'` | `'interaction'` | a CSS media query.
|
|
26
|
+
*/
|
|
27
|
+
fetch?: string;
|
|
28
|
+
/** `IntersectionObserver` `rootMargin` when the schedule is `'visible'`. */
|
|
29
|
+
margin?: string;
|
|
30
|
+
/**
|
|
31
|
+
* A hole (`fetch`) — response cache max-age for the hole's HTML: seconds (number) or a
|
|
32
|
+
* duration string (`'30s'` | `'5m'` | `'1h'`). Absent or `0` → `no-store`: the hole is dynamic,
|
|
33
|
+
* re-rendered on every request. A positive value opts into a `private, max-age` browser cache.
|
|
34
|
+
* Signed into the hole's endpoint so a harvested URL can't be re-pointed at a longer cache.
|
|
35
|
+
*
|
|
36
|
+
* With `render: 'live'` this is instead the client revalidate staleness — use a duration string
|
|
37
|
+
* to stay unit-explicit across both.
|
|
38
|
+
*/
|
|
39
|
+
maxAge?: number | string;
|
|
40
|
+
/** `render: 'live'` — past `maxAge`, whether to clear the hole (`'empty'`) or refetch (`'fetch'`). */
|
|
41
|
+
onExpire?: "empty" | "fetch";
|
|
42
|
+
/**
|
|
43
|
+
* A hole (`fetch`) — warm the hole's HTML into the frame store on this schedule (`'load'` |
|
|
44
|
+
* `'idle'` | `'visible'` | a media query) while `fetch` still decides when it swaps in. An
|
|
45
|
+
* on-demand hole (`fetch: 'interaction'`) then has its bytes before the first hover: the gesture
|
|
46
|
+
* joins the warm frame instead of paying the origin round trip. Never `'interaction'` — that is
|
|
47
|
+
* the swap schedule, `fetch`'s job.
|
|
48
|
+
*/
|
|
49
|
+
prefetch?: string;
|
|
50
|
+
/** `render: 'live'` — the revalidate schedule (`false` disables). Defaults to `wake`. */
|
|
51
|
+
revalidate?: false | string;
|
|
52
|
+
/** Continuity name (the `keep` import attribute): the live island relocates across SPA
|
|
53
|
+
* navigation instead of remounting when the next page carries the same name. */
|
|
54
|
+
keep?: string;
|
|
55
|
+
}
|
|
56
|
+
/** Per-IP budget for the signed deferred-region / lake-remount endpoint. */
|
|
57
|
+
export interface OgygiaRateLimit {
|
|
58
|
+
/** Max requests per window (default `60`). `0` disables allowing any. */
|
|
59
|
+
max?: number;
|
|
60
|
+
/** Sliding window length in milliseconds (default `60_000`). */
|
|
61
|
+
windowMs?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for the {@link ogygia} Vite plugin. The root is the region system itself — its defaults
|
|
65
|
+
* (`visible`), its named presets (referenced from a use site by a LITERAL `preset: 'name'`:
|
|
66
|
+
* `import X from '…' with { preset: 'name' }`), its holes' capability lifetimes — beside the client
|
|
67
|
+
* router. Feature packages are Vite plugins listed beside it (`plugins: [ogygia(), flags(), sveltekit()]`).
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { ogygia } from 'ogygia/vite';
|
|
72
|
+
* export default defineConfig({
|
|
73
|
+
* plugins: [
|
|
74
|
+
* ogygia({
|
|
75
|
+
* visible: { margin: '200px' },
|
|
76
|
+
* presets: { chart: { wake: 'visible', margin: '200px' } },
|
|
77
|
+
* ttl: 3600
|
|
78
|
+
* }),
|
|
79
|
+
* sveltekit()
|
|
80
|
+
* ]
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export interface OgygiaOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Defaults for regions that wake `'visible'` (`wake: 'visible'` / `render` + `wake: 'visible'`)
|
|
87
|
+
* without their own `margin` (via a preset).
|
|
88
|
+
*/
|
|
89
|
+
visible?: {
|
|
90
|
+
/** Default `IntersectionObserver` `rootMargin` (e.g. `'200px'`). */
|
|
91
|
+
margin?: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Named strategy bundles. Reference one from an import:
|
|
95
|
+
* `import Chart from '$lib/Chart.svelte' with { preset: 'chart' };`
|
|
96
|
+
*/
|
|
97
|
+
presets?: Record<string, OgygiaPreset>;
|
|
98
|
+
/**
|
|
99
|
+
* How long a deferred/live hole's signed capability URL stays valid, in seconds (default `3600`).
|
|
100
|
+
* Clamped to `[60, 86400]`. Keep short for harvested-URL risk. Holes outlive this automatically
|
|
101
|
+
* where they must: on prerendered and postrendered pages, and on a page a load marks shared-cacheable
|
|
102
|
+
* (`setHeaders({ 'cache-control': 'public, s-maxage=…' })`), where an anonymous hole is signed for
|
|
103
|
+
* the page's cache life; a hole on an older cached copy renews itself when it wakes.
|
|
104
|
+
*/
|
|
105
|
+
ttl?: number;
|
|
106
|
+
/**
|
|
107
|
+
* The oldest a cached copy of a page can be and still get its holes, in seconds (default
|
|
108
|
+
* `691200`, 8 days). An anonymous hole whose capability expired while a cache kept its page
|
|
109
|
+
* renews itself for up to this long after that expiry; past it, the hole keeps its fallback.
|
|
110
|
+
* Raise it to the longest your CDN may serve a page when the page does not say so in its
|
|
111
|
+
* `cache-control`. `0` turns renewal off. Unlike `ttl` it never lengthens a hole URL's life (a
|
|
112
|
+
* renewed URL lives `ttl`), and a hole bound to a session never renews. A renewable URL replays its
|
|
113
|
+
* props: keep hole props to routing keys (a locale, a page), and read anything sensitive at render.
|
|
114
|
+
*/
|
|
115
|
+
maxPageAge?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Client-side SPA router — app-wide, on by default. It intercepts same-origin links, swaps
|
|
118
|
+
* `<body>`, merges `<head>`, and keeps `data-ogygia-keep` chrome across navigations. No component
|
|
119
|
+
* to place: the server handle injects the runtime + the `ogygia-router` meta into every page.
|
|
120
|
+
*
|
|
121
|
+
* - `true` (default) — router on, View Transitions on, form continuity on.
|
|
122
|
+
* - `false` — router off (the whole feature is tree-shaken out; same-origin links do full MPA
|
|
123
|
+
* loads, and form continuity — which rides SPA navigation — goes with it).
|
|
124
|
+
* - `{ viewTransitions: false }` — router on, but no View Transitions API on navigation.
|
|
125
|
+
* - `{ forms: false }` — router on, but an island's half-filled form fields are NOT carried
|
|
126
|
+
* across SPA navigation (continuity off).
|
|
127
|
+
* - `{ serverDelta: true }` — opt IN to server-delta nav: an SPA nav tells the server (via an
|
|
128
|
+
* `x-ogygia-known` header) which islands it already has live, so the server SKIPS re-rendering
|
|
129
|
+
* the unchanged ones and the client keeps them running. OFF by default (it is a new client↔server
|
|
130
|
+
* protocol); when off the client never sends the header and the server always full-renders.
|
|
131
|
+
*
|
|
132
|
+
* Per-page escape hatch (no second config): a page opts *itself* out of View Transitions by
|
|
133
|
+
* emitting `<svelte:head><meta name="ogygia-router" content="plain" /></svelte:head>` — the handle
|
|
134
|
+
* injects the app default but a page that sets its own meta wins.
|
|
135
|
+
*/
|
|
136
|
+
router?: boolean | {
|
|
137
|
+
viewTransitions?: boolean;
|
|
138
|
+
forms?: boolean;
|
|
139
|
+
serverDelta?: boolean;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Rename the import-attribute keys claimed by the transform.
|
|
143
|
+
* Defaults stay `wake` / `fetch` / `render` / `preset` / `region`. Escape hatch if another
|
|
144
|
+
* tool already uses those names on the same imports.
|
|
145
|
+
*
|
|
146
|
+
* Preset **definitions** ({@link OgygiaOptions.presets}) still use the standard `render` /
|
|
147
|
+
* `wake` / `fetch` / … keys: only the `with { … }` spellings in source change.
|
|
148
|
+
*/
|
|
149
|
+
importKeys?: Partial<ImportKeys>;
|
|
150
|
+
/**
|
|
151
|
+
* Per-IP budget for the signed island endpoint served by `ogygiaHandle()`.
|
|
152
|
+
* Default `{ max: 60, windowMs: 60_000 }`. Pass `false` to disable.
|
|
153
|
+
*/
|
|
154
|
+
rateLimit?: false | OgygiaRateLimit;
|
|
155
|
+
/**
|
|
156
|
+
* Cookie name to seal into the region MAC (opt-in). Empty/prerender stays unbound.
|
|
157
|
+
* Harvested capability URLs then fail verification without that cookie.
|
|
158
|
+
* Default `false` (unbound).
|
|
159
|
+
*/
|
|
160
|
+
sessionCookie?: false | string;
|
|
161
|
+
/**
|
|
162
|
+
* @internal Recreate this plugin instance inside the standalone client build.
|
|
163
|
+
* App authors should not set this.
|
|
164
|
+
*/
|
|
165
|
+
standalone?: boolean;
|
|
166
|
+
}
|
|
167
|
+
/** Every key of `options` is one `ogygia()` has: any other fails the build (`option_unknown`), so
|
|
168
|
+
* a misspelt or removed option never silently does nothing. */
|
|
169
|
+
export declare function assert_known_options(options: OgygiaOptions): void;
|
|
170
|
+
/**
|
|
171
|
+
* Config-time region-preset validation — the transform re-checks on USE (with file/line context), but
|
|
172
|
+
* a broken preset nobody references yet should still fail the build, not lurk.
|
|
173
|
+
*/
|
|
174
|
+
export declare function validate_region_presets(presets: Record<string, unknown>): void;
|
|
175
|
+
/** The router/capability config resolved from `OgygiaOptions` — pure derivation the factory reads. */
|
|
176
|
+
export interface ResolvedOgygiaConfig {
|
|
177
|
+
rate_limit: {
|
|
178
|
+
max: number;
|
|
179
|
+
windowMs: number;
|
|
180
|
+
};
|
|
181
|
+
session_cookie: string;
|
|
182
|
+
region_ttl: number;
|
|
183
|
+
renew_window: number;
|
|
184
|
+
router_enabled: boolean;
|
|
185
|
+
router_view_transitions: boolean;
|
|
186
|
+
continuity_forms: boolean;
|
|
187
|
+
server_delta: boolean;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Normalize the router / rate-limit / session / ttl / continuity / server-delta options into the flat
|
|
191
|
+
* config the factory threads into `CompileCtx` + `Program`. Pure — no defaults leak back into `options`.
|
|
192
|
+
* `defaultRegionTtl` / `defaultRenewWindow` are passed in (the endpoint's DEFAULT_REGION_TTL_SEC,
|
|
193
|
+
* shared-cache's RENEW_WINDOW_SEC) to keep this Vite-free.
|
|
194
|
+
*/
|
|
195
|
+
export declare function resolve_options(options: OgygiaOptions, defaultRegionTtl: number, defaultRenewWindow?: number): ResolvedOgygiaConfig;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { PRESET_KEYS } from "../region/transform.js";
|
|
2
|
+
import { OgygiaError } from "../messages.js";
|
|
3
|
+
// src/vite/options.ts
|
|
4
|
+
const OPTION_KEYS = {
|
|
5
|
+
visible: true,
|
|
6
|
+
presets: true,
|
|
7
|
+
ttl: true,
|
|
8
|
+
maxPageAge: true,
|
|
9
|
+
router: true,
|
|
10
|
+
importKeys: true,
|
|
11
|
+
rateLimit: true,
|
|
12
|
+
sessionCookie: true,
|
|
13
|
+
standalone: true
|
|
14
|
+
};
|
|
15
|
+
/** Every key of `options` is one `ogygia()` has: any other fails the build (`option_unknown`), so
|
|
16
|
+
* a misspelt or removed option never silently does nothing. */
|
|
17
|
+
function assert_known_options(options) {
|
|
18
|
+
for (const key of Object.keys(options)) {
|
|
19
|
+
if (key in OPTION_KEYS) continue;
|
|
20
|
+
if (key === "barrels") throw new OgygiaError("barrels_option_removed");
|
|
21
|
+
throw new OgygiaError("option_unknown", {
|
|
22
|
+
option: key,
|
|
23
|
+
known: Object.keys(OPTION_KEYS).filter((k) => k !== "standalone").join(", ")
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Config-time region-preset validation — the transform re-checks on USE (with file/line context), but
|
|
29
|
+
* a broken preset nobody references yet should still fail the build, not lurk.
|
|
30
|
+
*/
|
|
31
|
+
function validate_region_presets(presets) {
|
|
32
|
+
for (const [name, bag] of Object.entries(presets)) {
|
|
33
|
+
if (!bag || typeof bag !== "object" || Object.keys(bag).length === 0) throw new OgygiaError("preset_empty", { name });
|
|
34
|
+
for (const k of Object.keys(bag)) if (!PRESET_KEYS.has(k)) throw new OgygiaError("preset_key_unknown", {
|
|
35
|
+
name,
|
|
36
|
+
key: k,
|
|
37
|
+
allowed: [...PRESET_KEYS].join(", ")
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Normalize the router / rate-limit / session / ttl / continuity / server-delta options into the flat
|
|
43
|
+
* config the factory threads into `CompileCtx` + `Program`. Pure — no defaults leak back into `options`.
|
|
44
|
+
* `defaultRegionTtl` / `defaultRenewWindow` are passed in (the endpoint's DEFAULT_REGION_TTL_SEC,
|
|
45
|
+
* shared-cache's RENEW_WINDOW_SEC) to keep this Vite-free.
|
|
46
|
+
*/
|
|
47
|
+
function resolve_options(options, defaultRegionTtl, defaultRenewWindow = 691200) {
|
|
48
|
+
const rate_limit = options.rateLimit === false ? {
|
|
49
|
+
max: 0,
|
|
50
|
+
windowMs: 6e4
|
|
51
|
+
} : {
|
|
52
|
+
max: Math.max(0, options.rateLimit?.max ?? 60),
|
|
53
|
+
windowMs: Math.max(1, options.rateLimit?.windowMs ?? 6e4)
|
|
54
|
+
};
|
|
55
|
+
const session_cookie = typeof options.sessionCookie === "string" ? options.sessionCookie : "";
|
|
56
|
+
const region_ttl = Math.min(86400, Math.max(60, Math.floor(options.ttl ?? defaultRegionTtl)));
|
|
57
|
+
const renew_raw = options.maxPageAge;
|
|
58
|
+
if (renew_raw !== void 0 && !(typeof renew_raw === "number" && Number.isFinite(renew_raw) && renew_raw >= 0)) throw new OgygiaError("max_page_age_invalid", { value: String(renew_raw) });
|
|
59
|
+
const renew_window = Math.min(31536e4, Math.floor(renew_raw ?? defaultRenewWindow));
|
|
60
|
+
const router_enabled = options.router !== false;
|
|
61
|
+
return {
|
|
62
|
+
rate_limit,
|
|
63
|
+
session_cookie,
|
|
64
|
+
region_ttl,
|
|
65
|
+
renew_window,
|
|
66
|
+
router_enabled,
|
|
67
|
+
router_view_transitions: typeof options.router === "object" ? options.router.viewTransitions !== false : options.router !== false,
|
|
68
|
+
continuity_forms: router_enabled && (typeof options.router === "object" ? options.router.forms !== false : true),
|
|
69
|
+
server_delta: typeof options.router === "object" && options.router.serverDelta === true
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export { assert_known_options, resolve_options, validate_region_presets };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { OgygiaError, warn } from "../messages.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { OWN_PACKAGE_NAMES } from "@ogygia/core/contract";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { globSync } from "tinyglobby";
|
|
6
|
+
// src/vite/package-files.ts
|
|
7
|
+
const posix = (p) => p.split(path.sep).join("/");
|
|
8
|
+
const GLOB_MAGIC_RE = /[*?{}[\]!]/;
|
|
9
|
+
function read_manifest(dir) {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8"));
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function discover_package_files(app_root) {
|
|
17
|
+
const app = read_manifest(app_root);
|
|
18
|
+
if (!app) return [];
|
|
19
|
+
const deps = [...Object.keys(app.dependencies ?? {}), ...Object.keys(app.devDependencies ?? {})];
|
|
20
|
+
const found = [];
|
|
21
|
+
for (const name of deps) {
|
|
22
|
+
if (OWN_PACKAGE_NAMES.includes(name)) continue;
|
|
23
|
+
let root;
|
|
24
|
+
try {
|
|
25
|
+
root = fs.realpathSync(path.join(app_root, "node_modules", ...name.split("/")));
|
|
26
|
+
} catch {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const declared = (read_manifest(root)?.ogygia)?.files;
|
|
30
|
+
if (declared == null) continue;
|
|
31
|
+
if (!Array.isArray(declared) || !declared.every((p) => typeof p === "string")) throw new OgygiaError("package_files_not_array", {
|
|
32
|
+
package: name,
|
|
33
|
+
got: JSON.stringify(declared)
|
|
34
|
+
});
|
|
35
|
+
const dirs = [];
|
|
36
|
+
const files = /* @__PURE__ */ new Set();
|
|
37
|
+
const inside = (real) => real === root || real.startsWith(root + path.sep);
|
|
38
|
+
for (const entry of declared) {
|
|
39
|
+
if (GLOB_MAGIC_RE.test(entry)) {
|
|
40
|
+
for (const m of globSync(entry, {
|
|
41
|
+
cwd: root,
|
|
42
|
+
absolute: true,
|
|
43
|
+
dot: false
|
|
44
|
+
})) {
|
|
45
|
+
let real;
|
|
46
|
+
try {
|
|
47
|
+
real = fs.realpathSync(m);
|
|
48
|
+
} catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (inside(real)) files.add(posix(real));
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const abs = path.resolve(root, entry);
|
|
56
|
+
if (!inside(abs)) throw new OgygiaError("package_files_escapes", {
|
|
57
|
+
package: name,
|
|
58
|
+
entry
|
|
59
|
+
});
|
|
60
|
+
let real;
|
|
61
|
+
let stat;
|
|
62
|
+
try {
|
|
63
|
+
real = fs.realpathSync(abs);
|
|
64
|
+
stat = fs.statSync(real);
|
|
65
|
+
} catch {
|
|
66
|
+
warn("package_files_missing", {
|
|
67
|
+
package: name,
|
|
68
|
+
entry
|
|
69
|
+
});
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!inside(real)) throw new OgygiaError("package_files_escapes", {
|
|
73
|
+
package: name,
|
|
74
|
+
entry
|
|
75
|
+
});
|
|
76
|
+
if (stat.isDirectory()) dirs.push(posix(real));
|
|
77
|
+
else files.add(posix(real));
|
|
78
|
+
}
|
|
79
|
+
if (dirs.length || files.size) found.push({
|
|
80
|
+
name,
|
|
81
|
+
root: posix(root),
|
|
82
|
+
dirs,
|
|
83
|
+
files: [...files]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return found;
|
|
87
|
+
}
|
|
88
|
+
export { discover_package_files };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** An island file as an `optimizeDeps.entries` pattern, or null for one of ogygia's OWN islands (the
|
|
2
|
+
* profiler UI): ogygia is in `optimizeDeps.exclude`, so the scanner can't resolve inside it, and one
|
|
3
|
+
* unresolved import fails the whole scan (nothing pre-bundles). Its client deps are named up front
|
|
4
|
+
* instead (the plugin's `dev_island_deps`). */
|
|
5
|
+
export declare function scan_entry_pattern(file: string, own_root?: string): string | null;
|
|
6
|
+
export declare const KIT_REMOTE_CLIENT: RegExp;
|
|
7
|
+
export declare const KIT_REMOTE_STATE: RegExp;
|
|
8
|
+
/** The end of every path to Kit's client remote functions (`remote-functions/index.js`). */
|
|
9
|
+
export declare const KIT_REMOTE_INDEX_TAIL = "/client/remote-functions/index.js";
|
|
10
|
+
/** What the runtime chunk is made from: the compiler's runtime entry, core's named inputs, and every
|
|
11
|
+
* `.js` file in `runtime_dir` (none when it is not built yet). */
|
|
12
|
+
export declare function runtime_inputs(runtime_dir?: string): string[];
|
|
13
|
+
/** The first 12 hex of a sha256 over `files`' bytes in order; a file that cannot be read adds nothing. */
|
|
14
|
+
export declare function content_hash(files: readonly string[]): string;
|
|
15
|
+
/** The runtime chunk's source-content hash (the immutable-filename base; feature hash rides on top). */
|
|
16
|
+
export declare const RUNTIME_HASH: string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { CORE_ROOT_ID, RUNTIME_DIR, RUNTIME_INPUTS, real_posix } from "@ogygia/core/contract";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import crypto from "node:crypto";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
// src/vite/paths.ts
|
|
7
|
+
const GLOB_META_RE = /[()[\]{}*?!]/g;
|
|
8
|
+
/** An island file as an `optimizeDeps.entries` pattern, or null for one of ogygia's OWN islands (the
|
|
9
|
+
* profiler UI): ogygia is in `optimizeDeps.exclude`, so the scanner can't resolve inside it, and one
|
|
10
|
+
* unresolved import fails the whole scan (nothing pre-bundles). Its client deps are named up front
|
|
11
|
+
* instead (the plugin's `dev_island_deps`). */
|
|
12
|
+
function scan_entry_pattern(file, own_root = CORE_ROOT_ID) {
|
|
13
|
+
const posix = real_posix(file);
|
|
14
|
+
return posix.startsWith(own_root) ? null : posix.replace(GLOB_META_RE, "\\$&");
|
|
15
|
+
}
|
|
16
|
+
const KIT_REMOTE_CLIENT = /(^|\/)client\.js$/;
|
|
17
|
+
const KIT_REMOTE_STATE = /state\.svelte\.js$/;
|
|
18
|
+
/** The end of every path to Kit's client remote functions (`remote-functions/index.js`). */
|
|
19
|
+
const KIT_REMOTE_INDEX_TAIL = "/client/remote-functions/index.js";
|
|
20
|
+
/** What the runtime chunk is made from: the compiler's runtime entry, core's named inputs, and every
|
|
21
|
+
* `.js` file in `runtime_dir` (none when it is not built yet). */
|
|
22
|
+
function runtime_inputs(runtime_dir = RUNTIME_DIR) {
|
|
23
|
+
const inputs = [fileURLToPath(new URL("../link/runtime-entry.js", import.meta.url)), ...RUNTIME_INPUTS];
|
|
24
|
+
try {
|
|
25
|
+
for (const name of fs.readdirSync(runtime_dir)) if (name.endsWith(".js")) inputs.push(path.join(runtime_dir, name));
|
|
26
|
+
} catch {}
|
|
27
|
+
return inputs;
|
|
28
|
+
}
|
|
29
|
+
/** The first 12 hex of a sha256 over `files`' bytes in order; a file that cannot be read adds nothing. */
|
|
30
|
+
function content_hash(files) {
|
|
31
|
+
const h = crypto.createHash("sha256");
|
|
32
|
+
for (const f of files) try {
|
|
33
|
+
h.update(fs.readFileSync(f));
|
|
34
|
+
} catch {}
|
|
35
|
+
return h.digest("hex").slice(0, 12);
|
|
36
|
+
}
|
|
37
|
+
/** The runtime chunk's source-content hash (the immutable-filename base; feature hash rides on top). */
|
|
38
|
+
const RUNTIME_HASH = content_hash(runtime_inputs());
|
|
39
|
+
export { KIT_REMOTE_CLIENT, KIT_REMOTE_INDEX_TAIL, KIT_REMOTE_STATE, RUNTIME_HASH, content_hash, runtime_inputs, scan_entry_pattern };
|