elit 3.0.0 → 3.0.2
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/dist/build.d.ts +4 -12
- package/dist/build.d.ts.map +1 -0
- package/dist/chokidar.d.ts +7 -9
- package/dist/chokidar.d.ts.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +17 -4
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/dom.d.ts +7 -14
- package/dist/dom.d.ts.map +1 -0
- package/dist/el.d.ts +19 -191
- package/dist/el.d.ts.map +1 -0
- package/dist/fs.d.ts +35 -35
- package/dist/fs.d.ts.map +1 -0
- package/dist/hmr.d.ts +3 -3
- package/dist/hmr.d.ts.map +1 -0
- package/dist/http.d.ts +20 -22
- package/dist/http.d.ts.map +1 -0
- package/dist/https.d.ts +12 -15
- package/dist/https.d.ts.map +1 -0
- package/dist/index.d.ts +10 -629
- package/dist/index.d.ts.map +1 -0
- package/dist/mime-types.d.ts +9 -9
- package/dist/mime-types.d.ts.map +1 -0
- package/dist/path.d.ts +22 -19
- package/dist/path.d.ts.map +1 -0
- package/dist/router.d.ts +10 -17
- package/dist/router.d.ts.map +1 -0
- package/dist/runtime.d.ts +5 -6
- package/dist/runtime.d.ts.map +1 -0
- package/dist/server.d.ts +105 -7
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +14 -2
- package/dist/server.mjs +14 -2
- package/dist/state.d.ts +21 -27
- package/dist/state.d.ts.map +1 -0
- package/dist/style.d.ts +14 -55
- package/dist/style.d.ts.map +1 -0
- package/dist/types.d.ts +26 -240
- package/dist/types.d.ts.map +1 -0
- package/dist/ws.d.ts +14 -17
- package/dist/ws.d.ts.map +1 -0
- package/dist/wss.d.ts +16 -16
- package/dist/wss.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/build.ts +337 -0
- package/src/chokidar.ts +401 -0
- package/src/cli.ts +638 -0
- package/src/config.ts +205 -0
- package/src/dom.ts +817 -0
- package/src/el.ts +164 -0
- package/src/fs.ts +727 -0
- package/src/hmr.ts +137 -0
- package/src/http.ts +775 -0
- package/src/https.ts +411 -0
- package/src/index.ts +14 -0
- package/src/mime-types.ts +222 -0
- package/src/path.ts +493 -0
- package/src/router.ts +237 -0
- package/src/runtime.ts +97 -0
- package/src/server.ts +1290 -0
- package/src/state.ts +468 -0
- package/src/style.ts +524 -0
- package/{dist/types-Du6kfwTm.d.ts → src/types.ts} +58 -141
- package/src/ws.ts +506 -0
- package/src/wss.ts +241 -0
- package/dist/build.d.mts +0 -20
- package/dist/chokidar.d.mts +0 -134
- package/dist/dom.d.mts +0 -87
- package/dist/el.d.mts +0 -207
- package/dist/fs.d.mts +0 -255
- package/dist/hmr.d.mts +0 -38
- package/dist/http.d.mts +0 -163
- package/dist/https.d.mts +0 -108
- package/dist/index.d.mts +0 -629
- package/dist/mime-types.d.mts +0 -48
- package/dist/path.d.mts +0 -163
- package/dist/router.d.mts +0 -47
- package/dist/runtime.d.mts +0 -97
- package/dist/server.d.mts +0 -7
- package/dist/state.d.mts +0 -111
- package/dist/style.d.mts +0 -159
- package/dist/types-C0nGi6MX.d.mts +0 -346
- package/dist/types.d.mts +0 -452
- package/dist/ws.d.mts +0 -195
- package/dist/wss.d.mts +0 -108
package/src/config.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config loader for elit.config.{ts,js,json}
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { existsSync, readFileSync } from './fs';
|
|
6
|
+
import { resolve } from './path';
|
|
7
|
+
import type { DevServerOptions, BuildOptions, PreviewOptions } from './types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Helper: Read file and ensure string output (eliminates duplication in file reading)
|
|
11
|
+
*/
|
|
12
|
+
function readFileAsString(filePath: string): string {
|
|
13
|
+
const contentBuffer = readFileSync(filePath, 'utf-8');
|
|
14
|
+
return typeof contentBuffer === 'string' ? contentBuffer : contentBuffer.toString('utf-8');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Helper: Remove surrounding quotes from string (eliminates duplication in env parsing)
|
|
19
|
+
*/
|
|
20
|
+
function removeQuotes(value: string): string {
|
|
21
|
+
const trimmed = value.trim();
|
|
22
|
+
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
23
|
+
(trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
|
24
|
+
return trimmed.slice(1, -1);
|
|
25
|
+
}
|
|
26
|
+
return trimmed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Helper: Import config module and return default or module (eliminates duplication in config loading)
|
|
31
|
+
*/
|
|
32
|
+
async function importConfigModule(configPath: string): Promise<ElitConfig> {
|
|
33
|
+
const { pathToFileURL } = await import('url');
|
|
34
|
+
const configModule = await import(pathToFileURL(configPath).href);
|
|
35
|
+
return configModule.default || configModule;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Helper: Safe file cleanup (eliminates duplication in temp file cleanup)
|
|
40
|
+
*/
|
|
41
|
+
async function safeCleanup(filePath: string): Promise<void> {
|
|
42
|
+
try {
|
|
43
|
+
const { unlinkSync } = await import('./fs');
|
|
44
|
+
unlinkSync(filePath);
|
|
45
|
+
} catch {
|
|
46
|
+
// Ignore cleanup errors
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ElitConfig {
|
|
51
|
+
/** Development server configuration */
|
|
52
|
+
dev?: DevServerOptions;
|
|
53
|
+
/** Build configuration - supports single build or multiple builds */
|
|
54
|
+
build?: BuildOptions | BuildOptions[];
|
|
55
|
+
/** Preview server configuration */
|
|
56
|
+
preview?: PreviewOptions;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Helper function for type-safe config definition
|
|
61
|
+
*/
|
|
62
|
+
export function defineConfig(config: ElitConfig): ElitConfig {
|
|
63
|
+
return config;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const CONFIG_FILES = [
|
|
67
|
+
'elit.config.ts',
|
|
68
|
+
'elit.config.js',
|
|
69
|
+
'elit.config.mjs',
|
|
70
|
+
'elit.config.cjs',
|
|
71
|
+
'elit.config.json'
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Load environment variables from .env files
|
|
76
|
+
*/
|
|
77
|
+
export function loadEnv(mode: string = 'development', cwd: string = process.cwd()): Record<string, string> {
|
|
78
|
+
const env: Record<string, string> = { MODE: mode };
|
|
79
|
+
|
|
80
|
+
// Load .env files in priority order
|
|
81
|
+
const envFiles = [
|
|
82
|
+
`.env.${mode}.local`,
|
|
83
|
+
`.env.${mode}`,
|
|
84
|
+
`.env.local`,
|
|
85
|
+
`.env`
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
for (const file of envFiles) {
|
|
89
|
+
const filePath = resolve(cwd, file);
|
|
90
|
+
if (existsSync(filePath)) {
|
|
91
|
+
const content = readFileAsString(filePath);
|
|
92
|
+
const lines = content.split('\n');
|
|
93
|
+
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
const trimmed = line.trim();
|
|
96
|
+
// Skip empty lines and comments
|
|
97
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
98
|
+
|
|
99
|
+
const match = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/);
|
|
100
|
+
if (match) {
|
|
101
|
+
const [, key, value] = match;
|
|
102
|
+
const cleanValue = removeQuotes(value);
|
|
103
|
+
// Only set if not already set (priority order)
|
|
104
|
+
if (!(key in env)) {
|
|
105
|
+
env[key] = cleanValue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return env;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Load elit config from current directory
|
|
117
|
+
*/
|
|
118
|
+
export async function loadConfig(cwd: string = process.cwd()): Promise<ElitConfig | null> {
|
|
119
|
+
for (const configFile of CONFIG_FILES) {
|
|
120
|
+
const configPath = resolve(cwd, configFile);
|
|
121
|
+
|
|
122
|
+
if (existsSync(configPath)) {
|
|
123
|
+
try {
|
|
124
|
+
return await loadConfigFile(configPath);
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(`Error loading config file: ${configFile}`);
|
|
127
|
+
console.error(error);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function loadConfigFile(configPath: string): Promise<ElitConfig> {
|
|
137
|
+
const ext = configPath.split('.').pop();
|
|
138
|
+
|
|
139
|
+
if (ext === 'json') {
|
|
140
|
+
// Load JSON config
|
|
141
|
+
const content = readFileAsString(configPath);
|
|
142
|
+
return JSON.parse(content);
|
|
143
|
+
} else if (ext === 'ts') {
|
|
144
|
+
// Load TypeScript config by transpiling it with esbuild
|
|
145
|
+
try {
|
|
146
|
+
const { build } = await import('esbuild');
|
|
147
|
+
const { tmpdir } = await import('os');
|
|
148
|
+
const { join, dirname } = await import('./path');
|
|
149
|
+
|
|
150
|
+
// Create temporary output file
|
|
151
|
+
const tempFile = join(tmpdir(), `elit-config-${Date.now()}.mjs`);
|
|
152
|
+
|
|
153
|
+
// Bundle the TypeScript config with proper path resolution
|
|
154
|
+
const configDir = dirname(configPath);
|
|
155
|
+
await build({
|
|
156
|
+
entryPoints: [configPath],
|
|
157
|
+
bundle: true,
|
|
158
|
+
format: 'esm',
|
|
159
|
+
platform: 'node',
|
|
160
|
+
outfile: tempFile,
|
|
161
|
+
write: true,
|
|
162
|
+
target: 'es2020',
|
|
163
|
+
// Bundle everything including elit/* so config can use elit modules
|
|
164
|
+
// Only mark Node.js built-ins as external
|
|
165
|
+
external: ['node:*'],
|
|
166
|
+
// Use the config directory as the working directory for resolution
|
|
167
|
+
absWorkingDir: configDir,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Import the compiled config
|
|
171
|
+
const config = await importConfigModule(tempFile);
|
|
172
|
+
|
|
173
|
+
// Clean up temp file
|
|
174
|
+
await safeCleanup(tempFile);
|
|
175
|
+
|
|
176
|
+
return config;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
console.error('Failed to load TypeScript config file.');
|
|
179
|
+
console.error('You can use a .js, .mjs, or .json config file instead.');
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
// Load JS config
|
|
184
|
+
return await importConfigModule(configPath);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Merge CLI args with config file
|
|
190
|
+
*/
|
|
191
|
+
export function mergeConfig<T extends Record<string, any>>(
|
|
192
|
+
config: T | undefined,
|
|
193
|
+
cliArgs: Partial<T>
|
|
194
|
+
): T {
|
|
195
|
+
if (!config) {
|
|
196
|
+
return cliArgs as T;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
...config,
|
|
201
|
+
...Object.fromEntries(
|
|
202
|
+
Object.entries(cliArgs).filter(([_, v]) => v !== undefined)
|
|
203
|
+
)
|
|
204
|
+
} as T;
|
|
205
|
+
}
|