@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,69 @@
|
|
|
1
|
+
import { parse_module } from "../parse/oxc.js";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
// src/vite/definers.ts
|
|
4
|
+
const WRAP = "__og_define";
|
|
5
|
+
function* nodes(node) {
|
|
6
|
+
if (Array.isArray(node)) {
|
|
7
|
+
for (const child of node) yield* nodes(child);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
11
|
+
yield node;
|
|
12
|
+
for (const key in node) if (key !== "type") yield* nodes(node[key]);
|
|
13
|
+
}
|
|
14
|
+
/** `code` with every definer call marked, and its map; null when it calls none (or does not parse:
|
|
15
|
+
* a module mid-edit is left alone). */
|
|
16
|
+
function mark_definer_calls(code, id, definers) {
|
|
17
|
+
const { program, ok } = parse_module(code, id);
|
|
18
|
+
if (!ok) return null;
|
|
19
|
+
const named = /* @__PURE__ */ new Set();
|
|
20
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
21
|
+
for (const node of nodes(program)) {
|
|
22
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
23
|
+
const from = node.source.value;
|
|
24
|
+
const d = definers.find((x) => x.module === from);
|
|
25
|
+
if (!d) continue;
|
|
26
|
+
for (const s of node.specifiers) {
|
|
27
|
+
const local = s.local.name;
|
|
28
|
+
if (s.type === "ImportNamespaceSpecifier") namespaces.set(local, d.names);
|
|
29
|
+
else if (s.type === "ImportSpecifier") {
|
|
30
|
+
const imported = s.imported;
|
|
31
|
+
if (d.names.includes(imported.name ?? imported.value)) named.add(local);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!named.size && !namespaces.size) return null;
|
|
36
|
+
const s = new MagicString(code);
|
|
37
|
+
let marked = 0;
|
|
38
|
+
for (const node of nodes(program)) {
|
|
39
|
+
if (node.type !== "CallExpression") continue;
|
|
40
|
+
const callee = node.callee;
|
|
41
|
+
if (!(callee.type === "Identifier" ? named.has(callee.name) : callee.type === "MemberExpression" && !callee.computed && callee.object.type === "Identifier" && (namespaces.get(callee.object.name)?.includes(callee.property.name) ?? false))) continue;
|
|
42
|
+
s.appendLeft(callee.start, `${WRAP}(`).prependRight(callee.end, ")");
|
|
43
|
+
marked++;
|
|
44
|
+
}
|
|
45
|
+
if (!marked) return null;
|
|
46
|
+
s.prepend(`const ${WRAP} = globalThis[Symbol.for('ogygia.define')]?.run?.(${JSON.stringify(id)}) ?? ((fn) => fn);\n`);
|
|
47
|
+
return {
|
|
48
|
+
code: s.toString(),
|
|
49
|
+
map: s.generateMap({
|
|
50
|
+
hires: "boundary",
|
|
51
|
+
source: id
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** The dev transform: every server module that imports a definer has its definer calls marked. A
|
|
56
|
+
* normal-order plugin (plain JS, imports as written). Inert in a build. */
|
|
57
|
+
function definers_plugin(definers) {
|
|
58
|
+
return {
|
|
59
|
+
name: "ogygia:definers",
|
|
60
|
+
apply: "serve",
|
|
61
|
+
transform(code, id, options) {
|
|
62
|
+
if (!options?.ssr) return null;
|
|
63
|
+
const list = definers();
|
|
64
|
+
if (!list.length || !list.some((d) => code.includes(d.module))) return null;
|
|
65
|
+
return mark_definer_calls(code, id, list);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export { definers_plugin, mark_definer_calls };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PageReads } from "./plugin-api.js";
|
|
2
|
+
import { ViteDevServer } from "vite";
|
|
3
|
+
export declare const DEV_MAPS: unique symbol;
|
|
4
|
+
export declare const DEV_PAGE_KEYS: unique symbol;
|
|
5
|
+
/** what an island's code reads of `page.data`, as the build would say: its keys, or `'all'` with
|
|
6
|
+
* the lines that make it so; `null` when nothing in it reads the page */
|
|
7
|
+
export interface DevPageKeys {
|
|
8
|
+
keys: string[] | "all" | null;
|
|
9
|
+
why: {
|
|
10
|
+
file: string;
|
|
11
|
+
line: number | null;
|
|
12
|
+
why: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* THE BUILD'S SEED ANSWER, ON THE DEV SERVER: the build pins which `page.data` keys each island's
|
|
17
|
+
* code reads (seed shaping); the dev server does not — every island reads "everything" there, so
|
|
18
|
+
* the profiler could not tell a late island's data or point at the line that ships it all. This
|
|
19
|
+
* puts the same analysis behind a global the profiler (same process) asks: the island id's
|
|
20
|
+
* component and the app modules it imports (the SSR graph, eight deep), read together by the
|
|
21
|
+
* seed-shaping plugin (`PageReads.dev`), a helper handed the page followed like the build does.
|
|
22
|
+
* Only what the report says changes: the dev seed itself still ships whole.
|
|
23
|
+
*/
|
|
24
|
+
export declare function install_dev_page_keys(server: ViteDevServer, component_of: (iid: string) => string | null | undefined, root: string, reads: PageReads): void;
|
|
25
|
+
/**
|
|
26
|
+
* THE BROWSER'S MODULES, TOO: a CPU trace from the browser names a frame by the URL the dev server
|
|
27
|
+
* served (`/src/lib/Save.svelte?t=…`) at the SERVED code's lines — a `.svelte` file's compiled output,
|
|
28
|
+
* not its source. The client module graph holds each served module's map (the browser runs the code
|
|
29
|
+
* as served: no header to shift by). Looked up by the URL's path, then with its query minus Vite's
|
|
30
|
+
* `t=` / `v=` stamps (a virtual island id keeps its own query).
|
|
31
|
+
*/
|
|
32
|
+
export declare const DEV_CLIENT_MAPS: unique symbol;
|
|
33
|
+
export declare function install_dev_client_maps(server: ViteDevServer): void;
|
|
34
|
+
export declare function install_dev_maps(server: ViteDevServer): void;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// src/vite/dev-maps.ts
|
|
2
|
+
const DEV_MAPS = Symbol.for("ogygia.profiler.dev-maps");
|
|
3
|
+
const DEV_PAGE_KEYS = Symbol.for("ogygia.profiler.dev-page-keys");
|
|
4
|
+
/**
|
|
5
|
+
* THE BUILD'S SEED ANSWER, ON THE DEV SERVER: the build pins which `page.data` keys each island's
|
|
6
|
+
* code reads (seed shaping); the dev server does not — every island reads "everything" there, so
|
|
7
|
+
* the profiler could not tell a late island's data or point at the line that ships it all. This
|
|
8
|
+
* puts the same analysis behind a global the profiler (same process) asks: the island id's
|
|
9
|
+
* component and the app modules it imports (the SSR graph, eight deep), read together by the
|
|
10
|
+
* seed-shaping plugin (`PageReads.dev`), a helper handed the page followed like the build does.
|
|
11
|
+
* Only what the report says changes: the dev seed itself still ships whole.
|
|
12
|
+
*/
|
|
13
|
+
function install_dev_page_keys(server, component_of, root, reads) {
|
|
14
|
+
const ssr = () => server.environments?.ssr?.moduleGraph;
|
|
15
|
+
const app_file = (f) => !!f && f.startsWith(root) && !f.includes("/node_modules/");
|
|
16
|
+
globalThis[DEV_PAGE_KEYS] = async (iid) => {
|
|
17
|
+
const component = component_of(iid)?.split("?")[0];
|
|
18
|
+
const graph = ssr();
|
|
19
|
+
if (!component || !graph) return void 0;
|
|
20
|
+
const files = [];
|
|
21
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22
|
+
let level = [component];
|
|
23
|
+
for (let depth = 0; depth < 8 && level.length; depth++) {
|
|
24
|
+
const next = [];
|
|
25
|
+
for (const f of level) {
|
|
26
|
+
if (seen.has(f)) continue;
|
|
27
|
+
seen.add(f);
|
|
28
|
+
files.push(f);
|
|
29
|
+
for (const node of graph.getModulesByFile(f) ?? []) for (const dep of node.importedModules ?? []) {
|
|
30
|
+
const df = dep.file?.split("?")[0];
|
|
31
|
+
if (app_file(df) && !seen.has(df)) next.push(df);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
level = next;
|
|
35
|
+
}
|
|
36
|
+
const a = await reads.dev(files, async (specifier, importer) => {
|
|
37
|
+
const id = (await server.pluginContainer.resolveId(specifier, importer, { ssr: true }).catch(() => null))?.id?.split("?")[0];
|
|
38
|
+
return id && app_file(id) ? { id } : null;
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
keys: a.keys === "unknown" ? "all" : a.keys,
|
|
42
|
+
why: a.why
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function runner_offset() {
|
|
47
|
+
const AsyncFunction = async function() {}.constructor;
|
|
48
|
+
const src = new AsyncFunction("a", "b", "/*code*/").toString();
|
|
49
|
+
return src.slice(0, src.indexOf("/*code*/")).split("\n").length - 1 + 1;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* THE BROWSER'S MODULES, TOO: a CPU trace from the browser names a frame by the URL the dev server
|
|
53
|
+
* served (`/src/lib/Save.svelte?t=…`) at the SERVED code's lines — a `.svelte` file's compiled output,
|
|
54
|
+
* not its source. The client module graph holds each served module's map (the browser runs the code
|
|
55
|
+
* as served: no header to shift by). Looked up by the URL's path, then with its query minus Vite's
|
|
56
|
+
* `t=` / `v=` stamps (a virtual island id keeps its own query).
|
|
57
|
+
*/
|
|
58
|
+
const DEV_CLIENT_MAPS = Symbol.for("ogygia.profiler.dev-client-maps");
|
|
59
|
+
function install_dev_client_maps(server) {
|
|
60
|
+
const graph = () => server.environments?.client?.moduleGraph;
|
|
61
|
+
globalThis[DEV_CLIENT_MAPS] = (url) => {
|
|
62
|
+
const by_url = graph()?.urlToModuleMap;
|
|
63
|
+
if (!by_url) return void 0;
|
|
64
|
+
const q = url.indexOf("?");
|
|
65
|
+
const path = q === -1 ? url : url.slice(0, q);
|
|
66
|
+
const keys = [path];
|
|
67
|
+
if (q !== -1) {
|
|
68
|
+
const kept = url.slice(q + 1).split("&").filter((p) => !p.startsWith("t=") && !p.startsWith("v="));
|
|
69
|
+
if (kept.length) keys.unshift(`${path}?${kept.join("&")}`);
|
|
70
|
+
}
|
|
71
|
+
for (const k of keys) {
|
|
72
|
+
const map = by_url.get(k)?.transformResult?.map;
|
|
73
|
+
if (map && typeof map.mappings === "string") return JSON.stringify(map);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function install_dev_maps(server) {
|
|
78
|
+
const offset = runner_offset();
|
|
79
|
+
const graph = () => {
|
|
80
|
+
return server.environments?.ssr?.moduleGraph;
|
|
81
|
+
};
|
|
82
|
+
globalThis[DEV_MAPS] = (id) => {
|
|
83
|
+
const map = graph()?.getModuleById(id)?.transformResult?.map;
|
|
84
|
+
if (!map || typeof map.mappings !== "string") return void 0;
|
|
85
|
+
return JSON.stringify({
|
|
86
|
+
...map,
|
|
87
|
+
mappings: ";".repeat(offset) + map.mappings
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export { DEV_CLIENT_MAPS, DEV_MAPS, DEV_PAGE_KEYS, install_dev_client_maps, install_dev_maps, install_dev_page_keys };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { regionId, regionIdentity, strategyKey } from "../region/identity.js";
|
|
2
|
+
import { wrapperVirtualId } from "../ids.js";
|
|
3
|
+
import { CLIENT_BINDING_STUB, DEFAULT_IMPORT_KEYS, ImportKeys, import_keys_hint, islandChunkFileName, islandId, islandPublicUrl, normalize_import_keys } from "../region/transform.js";
|
|
4
|
+
import { rewrite_lake_import_to_placeholder } from "../region/emit.js";
|
|
5
|
+
import { MacroContext } from "../macros/pipeline.js";
|
|
6
|
+
import { PrescanHook } from "../ctx.js";
|
|
7
|
+
import { BuildContext, ExportsSeam, MacroHandler, MarkupRegions, MarkupSource, OgygiaPlugin, PageReadWhy, PageReads, PageReadsResolve, PinnedDecl, PluginDefinition, RegionsSeam, StageTransform, StayedAnswer, TransformContext, TransformStage, definePlugin } from "./plugin-api.js";
|
|
8
|
+
import { Entry, ExportMap, Leaf, Policy } from "../exports/index.js";
|
|
9
|
+
import { OgygiaOptions, OgygiaPreset, OgygiaRateLimit } from "./options.js";
|
|
10
|
+
import { Plugin } from "vite";
|
|
11
|
+
/**
|
|
12
|
+
* Vite plugin: transforms `with { hydrate | defer | preset }` imports into islands,
|
|
13
|
+
* serves virtual island modules, and wires signed region endpoints for deferred HTML.
|
|
14
|
+
*
|
|
15
|
+
* Place **before** `sveltekit()` in `vite.config`.
|
|
16
|
+
*
|
|
17
|
+
* @param options - Plugin configuration. See {@link OgygiaOptions}.
|
|
18
|
+
* @returns Vite plugins (`ogygia` pre + island sourcemap fix post). Vite flattens the array.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ogygia(options?: OgygiaOptions): Plugin[];
|
|
21
|
+
export { type BuildContext, CLIENT_BINDING_STUB, DEFAULT_IMPORT_KEYS, type Entry as ExportEntry, type Leaf as ExportLeaf, type ExportMap, type Policy as ExportPolicy, type ExportsSeam, type ImportKeys, type MacroContext, type MacroHandler, type MarkupRegions, type MarkupSource, type OgygiaOptions, type OgygiaPlugin, type OgygiaPreset, type OgygiaRateLimit, type PageReadWhy, type PageReads, type PageReadsResolve, type PinnedDecl, type PluginDefinition, type PrescanHook, type RegionsSeam, type StageTransform, type StayedAnswer, type TransformContext, type TransformStage, definePlugin, import_keys_hint, islandChunkFileName, islandId, islandPublicUrl, normalize_import_keys, regionId, regionIdentity, rewrite_lake_import_to_placeholder, strategyKey, wrapperVirtualId };
|