@aerobuilt/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -0
- package/dist/chunk-3OZCI7DL.js +238 -0
- package/dist/chunk-5GK7XRII.js +36 -0
- package/dist/chunk-7A3WBPH4.js +97 -0
- package/dist/chunk-F7MXQXLM.js +15 -0
- package/dist/entry-dev.d.ts +34 -0
- package/dist/entry-dev.js +87 -0
- package/dist/entry-prod.d.ts +19 -0
- package/dist/entry-prod.js +19 -0
- package/dist/runtime/index.d.ts +74 -0
- package/dist/runtime/index.js +7 -0
- package/dist/runtime/instance.d.ts +31 -0
- package/dist/runtime/instance.js +10 -0
- package/dist/types.d.ts +202 -0
- package/dist/types.js +0 -0
- package/dist/utils/redirects.d.ts +24 -0
- package/dist/utils/redirects.js +6 -0
- package/dist/vite/index.d.ts +23 -0
- package/dist/vite/index.js +2049 -0
- package/package.json +68 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { MountOptions, AeroRenderInput } from '../types.js';
|
|
2
|
+
import 'vite';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Aero runtime: page registration, route resolution, and HTML rendering.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The `Aero` class holds globals and a map of page/layout modules. `render()` resolves a page name
|
|
9
|
+
* (e.g. from `resolvePageName`), builds template context, and invokes the compiled render function.
|
|
10
|
+
* `mount` is optionally set by the client entry (`core/src/entry-dev.ts`).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
declare class Aero {
|
|
14
|
+
/** Global values merged into template context (e.g. from content modules). */
|
|
15
|
+
private globals;
|
|
16
|
+
/** Map from page name (or path) to module. Keys include both canonical name and full path for lookup. */
|
|
17
|
+
private pagesMap;
|
|
18
|
+
/** Set by client entry when running in the browser; used to attach the app to a DOM root. */
|
|
19
|
+
mount?: (options?: MountOptions) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Register a global value available in all templates as `name`.
|
|
22
|
+
*
|
|
23
|
+
* @param name - Key used in templates (e.g. `site`).
|
|
24
|
+
* @param value - Any value (object, string, etc.).
|
|
25
|
+
*/
|
|
26
|
+
global(name: string, value: any): void;
|
|
27
|
+
/**
|
|
28
|
+
* Register page/layout modules from a Vite glob (e.g. `import.meta.glob('@pages/**\/*.html')`).
|
|
29
|
+
* Derives a lookup key from each path via pagePathToKey; also stores by full path for resolution.
|
|
30
|
+
*
|
|
31
|
+
* @param pages - Record of resolved path → module (default export is the render function).
|
|
32
|
+
*/
|
|
33
|
+
registerPages(pages: Record<string, any>): void;
|
|
34
|
+
/** Type guard: true if value looks like an `AeroRenderInput` (has at least one of props, slots, request, url, params, routePath). */
|
|
35
|
+
private isRenderInput;
|
|
36
|
+
/** Coerce various call signatures into a single `AeroRenderInput` (e.g. plain object → `{ props }`). */
|
|
37
|
+
private normalizeRenderInput;
|
|
38
|
+
/** Convert a page name to a route path (e.g. `index` → `'/'`, `about` → `'/about'`). */
|
|
39
|
+
private toRoutePath;
|
|
40
|
+
/** Build a URL from route path and optional raw URL. Uses `http://localhost` as base when only a path is given. */
|
|
41
|
+
private toURL;
|
|
42
|
+
/** Build template context: globals, props, slots, request, url, params, site, and `renderComponent` / `nextPassDataId`. */
|
|
43
|
+
private createContext;
|
|
44
|
+
/** True if entry params and request params have the same keys and stringified values. */
|
|
45
|
+
private paramsMatch;
|
|
46
|
+
/**
|
|
47
|
+
* Render a page or layout to HTML.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* Resolves `component` (page name string or module) via `pagesMap`, with fallbacks: directory index
|
|
51
|
+
* (`foo` → `foo/index`), `index` → `home`, dynamic routes, and trailing-slash stripping. If the module
|
|
52
|
+
* exports `getStaticPaths` and no props are provided, finds the matching static path and uses its props.
|
|
53
|
+
* For root-level renders, injects accumulated styles and scripts into the document and fixes content
|
|
54
|
+
* that ends up after `</html>` when using layouts (moves it into `</body>`).
|
|
55
|
+
*
|
|
56
|
+
* @param component - Page name (e.g. `'index'`, `'about'`) or the module object.
|
|
57
|
+
* @param input - Render input (props, request, url, params, etc.). Can be a plain object (treated as props).
|
|
58
|
+
* @returns HTML string, or `null` if the page is not found or no static path match.
|
|
59
|
+
*/
|
|
60
|
+
render(component: any, input?: any): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Render a child component (layout or component) with the given props and slots.
|
|
63
|
+
* Used by compiled templates via context.renderComponent.
|
|
64
|
+
*
|
|
65
|
+
* @param component - Render function or module with `default` render function.
|
|
66
|
+
* @param props - Props object for the component.
|
|
67
|
+
* @param slots - Named slot content (key → HTML string).
|
|
68
|
+
* @param input - Optional request/url/params for context; `headScripts` is not passed through.
|
|
69
|
+
* @returns HTML string from the component's render function, or empty string if not invokable.
|
|
70
|
+
*/
|
|
71
|
+
renderComponent(component: any, props?: any, slots?: Record<string, string>, input?: AeroRenderInput): Promise<any>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Aero };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Aero } from './index.js';
|
|
2
|
+
import '../types.js';
|
|
3
|
+
import 'vite';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Singleton Aero instance and HMR update subscription.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Provides a single shared `Aero` instance and a listener set so the client entry can subscribe to
|
|
10
|
+
* "something changed" (e.g. template or glob updates). Uses `globalThis` so the instance survives
|
|
11
|
+
* Vite HMR re-execution. On load, runs Vite-specific `import.meta.glob` for pages, components, and
|
|
12
|
+
* layouts, registers them with the instance, then calls `notify()` so any existing subscribers
|
|
13
|
+
* (e.g. the client `mount()` HMR callback) can re-render. Only used in a Vite app context.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** Global slot for the singleton Aero instance; used so HMR re-execution reuses the same instance. */
|
|
17
|
+
declare global {
|
|
18
|
+
var __AERO_INSTANCE__: Aero | undefined;
|
|
19
|
+
var __AERO_LISTENERS__: Set<() => void> | undefined;
|
|
20
|
+
}
|
|
21
|
+
declare const aero: Aero;
|
|
22
|
+
/**
|
|
23
|
+
* Subscribe to update notifications (e.g. after globs or templates change).
|
|
24
|
+
* Used by the client entry to re-render on HMR.
|
|
25
|
+
*
|
|
26
|
+
* @param cb - Callback invoked when `notify()` runs (e.g. after this module re-executes).
|
|
27
|
+
* @returns Unsubscribe function that removes `cb` from the listener set.
|
|
28
|
+
*/
|
|
29
|
+
declare const onUpdate: (cb: () => void) => () => boolean;
|
|
30
|
+
|
|
31
|
+
export { aero, onUpdate };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared type definitions for the Aero framework (compiler, runtime, Vite plugin).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Grouped roughly by: config/dirs, compile/parse, resolver/aliases, routing, render context.
|
|
8
|
+
*/
|
|
9
|
+
interface AeroDirs {
|
|
10
|
+
/** Site source directory; pages live at `client/pages` (default: `'client'`). */
|
|
11
|
+
client?: string;
|
|
12
|
+
/** Nitro server directory (default: `'server'`). */
|
|
13
|
+
server?: string;
|
|
14
|
+
/** Build output directory (default: `'dist'`). */
|
|
15
|
+
dist?: string;
|
|
16
|
+
}
|
|
17
|
+
/** One redirect rule: from path to URL, optional status (default 302). */
|
|
18
|
+
interface RedirectRule {
|
|
19
|
+
from: string;
|
|
20
|
+
to: string;
|
|
21
|
+
status?: number;
|
|
22
|
+
}
|
|
23
|
+
interface AeroOptions {
|
|
24
|
+
/** Enable Nitro server integration (default: `false`). */
|
|
25
|
+
nitro?: boolean;
|
|
26
|
+
/** API route prefix (default: `'/api'`). */
|
|
27
|
+
apiPrefix?: string;
|
|
28
|
+
/** Directory overrides. */
|
|
29
|
+
dirs?: AeroDirs;
|
|
30
|
+
/**
|
|
31
|
+
* Canonical site URL (e.g. `'https://example.com'`). Exposed as `import.meta.env.SITE` and
|
|
32
|
+
* as `Aero.site` in templates. Used for sitemap, RSS, and canonical links.
|
|
33
|
+
*/
|
|
34
|
+
site?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Redirect rules applied in dev (Vite) and when using the Nitro server (preview:api / production).
|
|
37
|
+
* For static-only deploys use host redirect config (_redirects, vercel.json, etc.).
|
|
38
|
+
*/
|
|
39
|
+
redirects?: RedirectRule[];
|
|
40
|
+
/**
|
|
41
|
+
* Optional request-time middleware (redirects, rewrites, custom responses).
|
|
42
|
+
* Runs in dev before rendering; for production redirects use Nitro server middleware or `redirects` config.
|
|
43
|
+
*/
|
|
44
|
+
middleware?: AeroMiddleware[];
|
|
45
|
+
/**
|
|
46
|
+
* Optional plugins to add to the static render server (e.g. content plugin when using aero:content).
|
|
47
|
+
* Merged after the core Aero plugins so pages that import aero:content resolve during static build.
|
|
48
|
+
*/
|
|
49
|
+
staticServerPlugins?: vite.Plugin[];
|
|
50
|
+
}
|
|
51
|
+
/** Request context passed to middleware (url, request, route path, resolved page name, site). */
|
|
52
|
+
interface AeroRequestContext {
|
|
53
|
+
url: URL;
|
|
54
|
+
request: Request;
|
|
55
|
+
routePath: string;
|
|
56
|
+
pageName: string;
|
|
57
|
+
site?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Result of middleware: redirect, rewrite render input, or send a custom response. */
|
|
60
|
+
type AeroMiddlewareResult = {
|
|
61
|
+
redirect: {
|
|
62
|
+
url: string;
|
|
63
|
+
status?: number;
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
rewrite: Partial<AeroRenderInput> & {
|
|
67
|
+
pageName?: string;
|
|
68
|
+
};
|
|
69
|
+
} | {
|
|
70
|
+
response: Response;
|
|
71
|
+
} | void;
|
|
72
|
+
/** Middleware handler: receives request context; returns redirect/rewrite/response or nothing to continue. */
|
|
73
|
+
type AeroMiddleware = (ctx: AeroRequestContext) => AeroMiddlewareResult | Promise<AeroMiddlewareResult>;
|
|
74
|
+
/** Options for the client-side `mount()` entry (see `core/src/entry-dev.ts`). */
|
|
75
|
+
interface MountOptions {
|
|
76
|
+
/** Root element: CSS selector or `HTMLElement`. Defaults to `#app`. */
|
|
77
|
+
target?: string | HTMLElement;
|
|
78
|
+
/** Called with the root element after mount and after each HMR re-render. */
|
|
79
|
+
onRender?: (root: HTMLElement) => void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Single script entry: attrs (optional), content (body or virtual URL), optional pass:data expression.
|
|
83
|
+
* Used by parser, codegen, Vite plugin, and static build for client/inline/blocking script arrays.
|
|
84
|
+
*/
|
|
85
|
+
interface ScriptEntry {
|
|
86
|
+
attrs?: string;
|
|
87
|
+
content: string;
|
|
88
|
+
passDataExpr?: string;
|
|
89
|
+
/** If true, client script is injected in <head> instead of before </body>. */
|
|
90
|
+
injectInHead?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Input to the codegen compiler for a single template.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* Script arrays come from the parser; `root` and `resolvePath` from the build.
|
|
97
|
+
*/
|
|
98
|
+
interface CompileOptions {
|
|
99
|
+
root: string;
|
|
100
|
+
/** Client script entries (plain `<script>`): after transform, `content` may be virtual URL. */
|
|
101
|
+
clientScripts?: ScriptEntry[];
|
|
102
|
+
/** Inline scripts (`is:inline`) to be emitted in the page. */
|
|
103
|
+
inlineScripts?: ScriptEntry[];
|
|
104
|
+
/** Blocking scripts (`is:blocking`) to be emitted in the page. */
|
|
105
|
+
blockingScripts?: ScriptEntry[];
|
|
106
|
+
/** Resolve import specifiers (e.g. `@components/foo`) to absolute paths. */
|
|
107
|
+
resolvePath?: (specifier: string) => string;
|
|
108
|
+
}
|
|
109
|
+
/** Options for the path resolver (e.g. resolving `@components/foo` to a file path). */
|
|
110
|
+
interface ResolverOptions {
|
|
111
|
+
root: string;
|
|
112
|
+
resolvePath?: (specifier: string) => string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Result of parsing one HTML template.
|
|
116
|
+
*
|
|
117
|
+
* @remarks
|
|
118
|
+
* Produced by `parser.ts`. Extracted script blocks and the remaining template string for codegen.
|
|
119
|
+
*/
|
|
120
|
+
interface ParseResult {
|
|
121
|
+
/** Single `<script is:build>` block, or `null` if none. */
|
|
122
|
+
buildScript: {
|
|
123
|
+
content: string;
|
|
124
|
+
} | null;
|
|
125
|
+
clientScripts: ScriptEntry[];
|
|
126
|
+
inlineScripts: ScriptEntry[];
|
|
127
|
+
blockingScripts: ScriptEntry[];
|
|
128
|
+
/** HTML after script blocks are stripped; used as input to codegen. */
|
|
129
|
+
template: string;
|
|
130
|
+
}
|
|
131
|
+
/** One path alias from tsconfig (e.g. find: `@components`, replacement: `.../src/components`). */
|
|
132
|
+
interface UserAlias {
|
|
133
|
+
find: string;
|
|
134
|
+
replacement: string;
|
|
135
|
+
}
|
|
136
|
+
/** Result of loading project path aliases (`utils/aliases.ts`). */
|
|
137
|
+
interface AliasResult {
|
|
138
|
+
aliases: UserAlias[];
|
|
139
|
+
resolvePath?: (specifier: string) => string;
|
|
140
|
+
}
|
|
141
|
+
/** Head and body HTML fragments (e.g. from `runtime/client` `extractDocumentParts`). */
|
|
142
|
+
interface PageFragments {
|
|
143
|
+
head: string;
|
|
144
|
+
body: string;
|
|
145
|
+
}
|
|
146
|
+
/** Dynamic route segment key → value (e.g. `{ id: '42' }` for `/posts/42`). */
|
|
147
|
+
interface AeroRouteParams {
|
|
148
|
+
[key: string]: string;
|
|
149
|
+
}
|
|
150
|
+
/** One static path for pre-rendering (e.g. from static path discovery). */
|
|
151
|
+
interface StaticPathEntry {
|
|
152
|
+
params: AeroRouteParams;
|
|
153
|
+
props?: Record<string, any>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Input passed into a page or layout render (request, url, params, etc.).
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* Used by the runtime when calling the compiled render function and when rendering child components.
|
|
160
|
+
*/
|
|
161
|
+
interface AeroRenderInput {
|
|
162
|
+
props?: Record<string, any>;
|
|
163
|
+
/** Named slot content (key → HTML string) for layout/page render. */
|
|
164
|
+
slots?: Record<string, string>;
|
|
165
|
+
request?: Request;
|
|
166
|
+
url?: URL | string;
|
|
167
|
+
params?: AeroRouteParams;
|
|
168
|
+
/** Resolved route path pattern (e.g. `'/posts/[id]'`) for the current request. */
|
|
169
|
+
routePath?: string;
|
|
170
|
+
/** Accumulated style URLs/labels for this request. */
|
|
171
|
+
styles?: Set<string>;
|
|
172
|
+
/** Accumulated script URLs/labels for this request. */
|
|
173
|
+
scripts?: Set<string>;
|
|
174
|
+
/** Scripts to inject in <head>. */
|
|
175
|
+
headScripts?: Set<string>;
|
|
176
|
+
/** Canonical site URL from config (e.g. `'https://example.com'`). Exposed as Aero.site in templates. */
|
|
177
|
+
site?: string;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Context object available inside compiled templates (`is:build`) and when rendering components.
|
|
181
|
+
*
|
|
182
|
+
* @remarks
|
|
183
|
+
* Includes `props`, `slots`, `renderComponent`, `request`, `url`, `params`, and optional style/script sets.
|
|
184
|
+
* The index signature allows extra keys (e.g. from content or page data).
|
|
185
|
+
*/
|
|
186
|
+
interface AeroTemplateContext {
|
|
187
|
+
[key: string]: any;
|
|
188
|
+
props: Record<string, any>;
|
|
189
|
+
slots: Record<string, string>;
|
|
190
|
+
/** Used by codegen to emit calls that render a child component and return its HTML. */
|
|
191
|
+
renderComponent: (component: any, props?: Record<string, any>, slots?: Record<string, string>, context?: AeroRenderInput) => Promise<string>;
|
|
192
|
+
request: Request;
|
|
193
|
+
url: URL;
|
|
194
|
+
params: AeroRouteParams;
|
|
195
|
+
/** Canonical site URL from config (e.g. `'https://example.com'`). */
|
|
196
|
+
site?: string;
|
|
197
|
+
styles?: Set<string>;
|
|
198
|
+
scripts?: Set<string>;
|
|
199
|
+
headScripts?: Set<string>;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type { AeroDirs, AeroMiddleware, AeroMiddlewareResult, AeroOptions, AeroRenderInput, AeroRequestContext, AeroRouteParams, AeroTemplateContext, AliasResult, CompileOptions, MountOptions, PageFragments, ParseResult, RedirectRule, ResolverOptions, ScriptEntry, StaticPathEntry, UserAlias };
|
package/dist/types.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RedirectRule } from '../types.js';
|
|
2
|
+
import 'vite';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert Aero redirect rules to Nitro routeRules.
|
|
6
|
+
* Used when generating Nitro config from Aero options (no project nitro.config.ts).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Nitro routeRules redirect value: shorthand (307) or object with statusCode. */
|
|
10
|
+
type NitroRedirectRule = string | {
|
|
11
|
+
to: string;
|
|
12
|
+
statusCode: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Map redirect rules to Nitro's routeRules shape.
|
|
16
|
+
*
|
|
17
|
+
* @param redirects - Array of { from, to, status? } from aero config.
|
|
18
|
+
* @returns Record suitable for Nitro's routeRules.
|
|
19
|
+
*/
|
|
20
|
+
declare function redirectsToRouteRules(redirects: RedirectRule[]): Record<string, {
|
|
21
|
+
redirect: NitroRedirectRule;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
export { redirectsToRouteRules };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AeroOptions } from '../types.js';
|
|
2
|
+
import { PluginOption } from 'vite';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Aero Vite plugin: HTML transform, virtual modules, dev server middleware, and static build.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Split into focused sub-plugins: config, virtuals (resolve/load), transform, SSR middleware.
|
|
9
|
+
* Static build plugin runs after closeBundle; Nitro and image optimizer are composed in the factory.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Aero Vite plugin factory. Returns an array of plugins: config, virtuals, transform, SSR,
|
|
14
|
+
* static-build, image optimizer, and optionally Nitro (serve only).
|
|
15
|
+
* HMR for templates and content is handled by Vite's dependency graph when the app uses a single
|
|
16
|
+
* client entry that imports @aerobuilt/core and calls aero.mount().
|
|
17
|
+
*
|
|
18
|
+
* @param options - AeroOptions (nitro, apiPrefix, dirs). Nitro can be disabled at runtime via AERO_NITRO=false.
|
|
19
|
+
* @returns PluginOption[] to pass to Vite's plugins array.
|
|
20
|
+
*/
|
|
21
|
+
declare function aero(options?: AeroOptions): PluginOption[];
|
|
22
|
+
|
|
23
|
+
export { aero };
|