@aerobuilt/config 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 ADDED
@@ -0,0 +1,71 @@
1
+ # @aerobuilt/config
2
+
3
+ Typed Aero configuration and Vite config factory. Used by `aero.config.ts` and the dev/build entry to produce the final Vite config (Aero plugin, optional content plugin, and user overrides).
4
+
5
+ ## Exports
6
+
7
+ | Export | Description |
8
+ |--------|-------------|
9
+ | `defineConfig(config)` | Typed helper for `aero.config.ts`. Accepts a static `AeroConfig` or `AeroConfigFunction`. Returns the config unchanged (for IDE/type inference). |
10
+ | `createViteConfig(aeroConfig, options)` | Builds the Vite `UserConfig` from Aero config and env (`command`, `mode`). Merges defaults, Aero + content plugins, and user `vite`; preserves base `minify`/`cssMinify` when user sets them. |
11
+ | `AeroConfig`, `AeroConfigFunction`, `AeroUserConfig` | TypeScript types for config shape and env-aware function. |
12
+
13
+ ## Config shape (`AeroConfig`)
14
+
15
+ | Field | Type | Description |
16
+ |-------|------|-------------|
17
+ | `content` | `boolean \| AeroContentOptions` | Enable content collections. `true` or options (e.g. `config` path). |
18
+ | `server` | `boolean` | Enable Nitro server integration (default: `false`). |
19
+ | `site` | `string` | Canonical site URL (e.g. `'https://example.com'`). Exposed as `import.meta.env.SITE` and `Aero.site` in templates; used for sitemap, RSS, canonical links. |
20
+ | `dirs` | `object` | Overrides: `client`, `serverDir`, `dist`. |
21
+ | `vite` | `UserConfig` | Vite config merged with Aero defaults. |
22
+
23
+ ## Usage
24
+
25
+ **aero.config.ts**
26
+
27
+ ```ts
28
+ import { defineConfig } from 'aerobuilt/config'
29
+
30
+ export default defineConfig({
31
+ content: true,
32
+ server: true,
33
+ site: 'https://example.com', // optional; for sitemap, RSS, canonical URLs
34
+ dirs: { client: 'client', dist: 'dist' },
35
+ vite: { build: { target: 'esnext' } },
36
+ })
37
+ ```
38
+
39
+ **Config as a function (env-aware)**
40
+
41
+ ```ts
42
+ import { defineConfig } from 'aerobuilt/config'
43
+
44
+ export default defineConfig(({ command, mode }) => ({
45
+ content: true,
46
+ server: mode === 'production',
47
+ vite: command === 'build' ? { build: { minify: true } } : {},
48
+ }))
49
+ ```
50
+
51
+ **vite.config.ts (build entry)**
52
+
53
+ ```ts
54
+ import { createViteConfig } from 'aerobuilt/config'
55
+ import aeroConfig from './aero.config'
56
+
57
+ export default createViteConfig(aeroConfig, {
58
+ command: process.argv.includes('build') ? 'build' : 'dev',
59
+ mode: (process.env.NODE_ENV as 'development' | 'production') || 'development',
60
+ })
61
+ ```
62
+
63
+ ## Defaults
64
+
65
+ `createViteConfig` uses a base Vite config from the package: PostCSS (autoprefixer), `build.cssMinify: 'esbuild'`, and rolldown `checks.eval: false`. The Aero plugin (`aero()`) from `aerobuilt/vite` is always included; the content plugin (`aeroContent()`) from `@aerobuilt/content/vite` is added when `content` is enabled.
66
+
67
+ ## Peer dependencies
68
+
69
+ - `vite` ^8.0.0
70
+ - `@aerobuilt/core` (workspace)
71
+ - `@aerobuilt/content` (workspace)
@@ -0,0 +1,85 @@
1
+ import { UserConfig } from 'vite';
2
+ import { AeroContentOptions } from '@aerobuilt/content/vite';
3
+ import { RedirectRule, AeroMiddleware } from '@aerobuilt/core/types';
4
+ export { redirectsToRouteRules } from '@aerobuilt/core/utils/redirects';
5
+
6
+ /**
7
+ * Aero config types: user config shape, env-aware function, and resolved config with env.
8
+ *
9
+ * @remarks
10
+ * Used by `aero.config.ts` and by `createViteConfig` to build the final Vite config.
11
+ */
12
+
13
+ /** User-facing Aero configuration (content, server, dirs, redirects, middleware, optional Vite overrides). */
14
+ interface AeroConfig {
15
+ /** Enable content collections (default: `false`). Pass `true` or `AeroContentOptions`. */
16
+ content?: boolean | AeroContentOptions;
17
+ /** Enable Nitro server integration (default: `false`). */
18
+ server?: boolean;
19
+ /**
20
+ * Canonical site URL (e.g. `'https://example.com'`). Exposed as `import.meta.env.SITE` and
21
+ * `Aero.site` in templates; used for sitemap, RSS, and canonical links.
22
+ */
23
+ site?: string;
24
+ /** Directory overrides. */
25
+ dirs?: {
26
+ /** Site source directory; pages live at `client/pages` (default: `'client'`). */
27
+ client?: string;
28
+ /** Nitro server directory (default: `'server'`). */
29
+ serverDir?: string;
30
+ /** Build output directory (default: `'dist'`). */
31
+ dist?: string;
32
+ };
33
+ /**
34
+ * Redirect rules applied in dev and when using the Nitro server (preview:api / production).
35
+ * For static-only deploys use host redirect config (_redirects, vercel.json, etc.).
36
+ */
37
+ redirects?: RedirectRule[];
38
+ /**
39
+ * Request-time middleware (rewrites, custom responses). Runs in dev only.
40
+ * For redirects use `redirects` so they apply in dev and server.
41
+ */
42
+ middleware?: AeroMiddleware[];
43
+ /** Vite configuration merged with Aero defaults (plugins, build, etc.). */
44
+ vite?: UserConfig;
45
+ }
46
+ /** Config as a function of env (command, mode); allows different settings for dev vs build. */
47
+ type AeroConfigFunction = (env: {
48
+ command: 'dev' | 'build';
49
+ mode: 'development' | 'production';
50
+ }) => AeroConfig;
51
+ /** Either a static config object or a function that returns config. */
52
+ type AeroUserConfig = AeroConfig | AeroConfigFunction;
53
+
54
+ /**
55
+ * Typed helper for aero.config.ts: provides type inference and IDE support for the config object or function.
56
+ */
57
+
58
+ /**
59
+ * Define the Aero config (object or function). Pass-through; used for typing and editor support.
60
+ *
61
+ * @param config - Static `AeroConfig` or `AeroConfigFunction` receiving `{ command, mode }`.
62
+ * @returns The same config (unchanged).
63
+ */
64
+ declare function defineConfig(config: AeroUserConfig): AeroUserConfig;
65
+
66
+ /** Environment passed to createViteConfig (command and mode). */
67
+ interface CreateViteConfigOptions {
68
+ command: 'dev' | 'build';
69
+ mode: 'development' | 'production';
70
+ }
71
+ /** Derive command and mode from argv/NODE_ENV. Use with createViteConfig(aeroConfig, getDefaultOptions()). */
72
+ declare function getDefaultOptions(): CreateViteConfigOptions;
73
+ /**
74
+ * Create the Vite UserConfig from Aero config and env.
75
+ *
76
+ * When called with no arguments, loads aero.config.ts (or .js/.mjs) from process.cwd() if present;
77
+ * otherwise uses empty config. Command and mode are derived from argv and NODE_ENV.
78
+ *
79
+ * @param aeroConfigOrOptions - Optional: static config, config function, or options. Omit to auto-load aero.config.
80
+ * @param options - Optional when first arg is config. Command and mode (defaults from argv/NODE_ENV when using no-arg form).
81
+ * @returns Merged Vite config (defaults + Aero plugins + user vite; minify/cssMinify preserved when user overrides).
82
+ */
83
+ declare function createViteConfig(aeroConfigOrOptions?: AeroConfig | AeroConfigFunction | CreateViteConfigOptions, options?: CreateViteConfigOptions): UserConfig;
84
+
85
+ export { type AeroConfig, type AeroConfigFunction, type AeroUserConfig, createViteConfig, defineConfig, getDefaultOptions };
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ // src/defineConfig.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+
6
+ // src/createViteConfig.ts
7
+ import { mergeConfig } from "vite";
8
+ import { aero } from "@aerobuilt/core/vite";
9
+ import { aeroContent } from "@aerobuilt/content/vite";
10
+
11
+ // src/defaults.ts
12
+ import autoprefixer from "autoprefixer";
13
+ var defaultViteConfig = {
14
+ css: {
15
+ postcss: {
16
+ plugins: [autoprefixer()]
17
+ }
18
+ },
19
+ build: {
20
+ cssMinify: "esbuild",
21
+ rolldownOptions: {
22
+ checks: {
23
+ eval: false
24
+ }
25
+ }
26
+ }
27
+ };
28
+
29
+ // src/loadAeroConfig.ts
30
+ import { createRequire } from "module";
31
+ import { existsSync } from "fs";
32
+ import path from "path";
33
+ var require2 = createRequire(import.meta.url);
34
+ var CONFIG_NAMES = ["aero.config.ts", "aero.config.js", "aero.config.mjs"];
35
+ function loadAeroConfig(root) {
36
+ for (const name of CONFIG_NAMES) {
37
+ const filePath = path.join(root, name);
38
+ if (!existsSync(filePath)) continue;
39
+ try {
40
+ const jiti = require2("jiti")(root, { esmResolve: true });
41
+ const relativePath = "./" + name;
42
+ const mod = jiti(relativePath);
43
+ const config = mod?.default ?? mod;
44
+ if (config && (typeof config === "object" || typeof config === "function")) {
45
+ return config;
46
+ }
47
+ } catch (err) {
48
+ if (process.env.DEBUG?.includes("aero")) {
49
+ console.error("[createViteConfig] loadAeroConfig failed for", filePath, err);
50
+ }
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+
56
+ // src/createViteConfig.ts
57
+ function getDefaultOptions() {
58
+ return {
59
+ command: process.argv.includes("build") ? "build" : "dev",
60
+ mode: process.env.NODE_ENV === "production" ? "production" : "development"
61
+ };
62
+ }
63
+ function createViteConfig(aeroConfigOrOptions, options) {
64
+ let aeroConfig;
65
+ let opts;
66
+ const isOptionsObject = (x) => typeof x === "object" && x !== null && "command" in x && "mode" in x;
67
+ const hasExplicitConfig = aeroConfigOrOptions !== void 0 && (typeof aeroConfigOrOptions === "function" || typeof aeroConfigOrOptions === "object" && !isOptionsObject(aeroConfigOrOptions));
68
+ if (hasExplicitConfig) {
69
+ aeroConfig = aeroConfigOrOptions;
70
+ opts = options ?? getDefaultOptions();
71
+ } else {
72
+ opts = isOptionsObject(aeroConfigOrOptions) ? aeroConfigOrOptions : getDefaultOptions();
73
+ const loaded = loadAeroConfig(process.cwd());
74
+ aeroConfig = loaded ?? {};
75
+ }
76
+ return createViteConfigFromAero(aeroConfig, opts);
77
+ }
78
+ function createViteConfigFromAero(aeroConfig, options) {
79
+ const resolvedConfig = typeof aeroConfig === "function" ? aeroConfig({ command: options.command, mode: options.mode }) : aeroConfig;
80
+ const {
81
+ content,
82
+ server,
83
+ site,
84
+ dirs,
85
+ redirects,
86
+ middleware,
87
+ vite: userViteConfig
88
+ } = resolvedConfig;
89
+ const contentOptions = content === true ? {} : typeof content === "object" ? content : void 0;
90
+ const basePlugins = [
91
+ aero({
92
+ nitro: server ?? false,
93
+ site,
94
+ dirs,
95
+ redirects,
96
+ middleware,
97
+ staticServerPlugins: contentOptions !== void 0 ? [aeroContent(contentOptions)] : void 0
98
+ })
99
+ ];
100
+ if (contentOptions !== void 0) {
101
+ basePlugins.push(aeroContent(contentOptions));
102
+ }
103
+ const baseConfig = {
104
+ ...defaultViteConfig,
105
+ plugins: basePlugins
106
+ };
107
+ if (!userViteConfig) {
108
+ return baseConfig;
109
+ }
110
+ const merged = mergeConfig(baseConfig, userViteConfig);
111
+ if (merged.build) {
112
+ if (merged.build.minify === true || merged.build.minify === null) {
113
+ if (baseConfig.build?.minify !== void 0) {
114
+ merged.build.minify = baseConfig.build.minify;
115
+ }
116
+ }
117
+ if (merged.build.cssMinify === true || merged.build.cssMinify === null) {
118
+ if (baseConfig.build?.cssMinify !== void 0) {
119
+ merged.build.cssMinify = baseConfig.build.cssMinify;
120
+ }
121
+ }
122
+ }
123
+ return merged;
124
+ }
125
+
126
+ // src/redirects.ts
127
+ import { redirectsToRouteRules } from "@aerobuilt/core/utils/redirects";
128
+ export {
129
+ createViteConfig,
130
+ defineConfig,
131
+ getDefaultOptions,
132
+ redirectsToRouteRules
133
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@aerobuilt/config",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "author": "Jamie Wilson",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/aerobuilt/aero.git",
10
+ "directory": "packages/config"
11
+ },
12
+ "homepage": "https://github.com/aerobuilt/aero",
13
+ "private": false,
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "dependencies": {
24
+ "autoprefixer": "^10.4.24",
25
+ "jiti": "^2.4.2"
26
+ },
27
+ "peerDependencies": {
28
+ "vite": "^8.0.0",
29
+ "@aerobuilt/core": "0.1.0",
30
+ "@aerobuilt/content": "0.1.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^25.3.0",
34
+ "tsup": "^8.5.1",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup src/index.ts --format esm --dts --clean --out-dir dist",
39
+ "typecheck": "tsc --noEmit"
40
+ }
41
+ }