elit 3.0.2 → 3.0.4
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/cli.js +254 -44
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +713 -150
- package/dist/server.mjs +712 -150
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +5 -13
- package/src/server.ts +339 -38
- package/src/types.ts +0 -6
package/dist/cli.js
CHANGED
|
@@ -1412,7 +1412,7 @@ var require_package = __commonJS({
|
|
|
1412
1412
|
"package.json"(exports2, module2) {
|
|
1413
1413
|
module2.exports = {
|
|
1414
1414
|
name: "elit",
|
|
1415
|
-
version: "3.0.
|
|
1415
|
+
version: "3.0.4",
|
|
1416
1416
|
description: "Optimized lightweight library for creating DOM elements with reactive state",
|
|
1417
1417
|
main: "dist/index.js",
|
|
1418
1418
|
module: "dist/index.mjs",
|
|
@@ -3028,22 +3028,23 @@ var sendError = (res, code, msg) => {
|
|
|
3028
3028
|
var send404 = (res, msg = "Not Found") => sendError(res, 404, msg);
|
|
3029
3029
|
var send403 = (res, msg = "Forbidden") => sendError(res, 403, msg);
|
|
3030
3030
|
var send500 = (res, msg = "Internal Server Error") => sendError(res, 500, msg);
|
|
3031
|
-
var createElitImportMap = (basePath = "", mode = "dev") => {
|
|
3031
|
+
var createElitImportMap = async (rootDir, basePath = "", mode = "dev") => {
|
|
3032
3032
|
const srcPath = mode === "dev" ? basePath ? `${basePath}/node_modules/elit/src` : "/node_modules/elit/src" : basePath ? `${basePath}/node_modules/elit/dist` : "/node_modules/elit/dist";
|
|
3033
3033
|
const fileExt = mode === "dev" ? ".ts" : ".mjs";
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
"elit":
|
|
3037
|
-
"elit/":
|
|
3038
|
-
"elit/
|
|
3039
|
-
"elit/
|
|
3040
|
-
"elit/
|
|
3041
|
-
"elit/
|
|
3042
|
-
"elit/
|
|
3043
|
-
"elit/
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
}
|
|
3034
|
+
const elitImports = {
|
|
3035
|
+
"elit": `${srcPath}/index${fileExt}`,
|
|
3036
|
+
"elit/": `${srcPath}/`,
|
|
3037
|
+
"elit/dom": `${srcPath}/dom${fileExt}`,
|
|
3038
|
+
"elit/state": `${srcPath}/state${fileExt}`,
|
|
3039
|
+
"elit/style": `${srcPath}/style${fileExt}`,
|
|
3040
|
+
"elit/el": `${srcPath}/el${fileExt}`,
|
|
3041
|
+
"elit/router": `${srcPath}/router${fileExt}`,
|
|
3042
|
+
"elit/hmr": `${srcPath}/hmr${fileExt}`,
|
|
3043
|
+
"elit/types": `${srcPath}/types${fileExt}`
|
|
3044
|
+
};
|
|
3045
|
+
const externalImports = await generateExternalImportMaps(rootDir, basePath);
|
|
3046
|
+
const allImports = { ...externalImports, ...elitImports };
|
|
3047
|
+
return `<script type="importmap">${JSON.stringify({ imports: allImports }, null, 2)}</script>`;
|
|
3047
3048
|
};
|
|
3048
3049
|
var createHMRScript = (port, wsPath) => `<script>(function(){let ws;let retries=0;let maxRetries=5;function connect(){ws=new WebSocket('ws://'+window.location.hostname+':${port}${wsPath}');ws.onopen=()=>{console.log('[Elit HMR] Connected');retries=0};ws.onmessage=(e)=>{const d=JSON.parse(e.data);if(d.type==='update'){console.log('[Elit HMR] File updated:',d.path);window.location.reload()}else if(d.type==='reload'){console.log('[Elit HMR] Reloading...');window.location.reload()}else if(d.type==='error')console.error('[Elit HMR] Error:',d.error)};ws.onclose=()=>{if(retries<maxRetries){retries++;setTimeout(connect,1000*retries)}else if(retries===maxRetries){console.log('[Elit HMR] Connection closed. Start dev server to reconnect.')}};ws.onerror=()=>{ws.close()}}connect()})();</script>`;
|
|
3049
3050
|
var rewriteRelativePaths = (html, basePath) => {
|
|
@@ -3071,6 +3072,220 @@ async function findSpecialDir(startDir, targetDir) {
|
|
|
3071
3072
|
}
|
|
3072
3073
|
return null;
|
|
3073
3074
|
}
|
|
3075
|
+
var importMapCache = /* @__PURE__ */ new Map();
|
|
3076
|
+
async function generateExternalImportMaps(rootDir, basePath = "") {
|
|
3077
|
+
const cacheKey = `${rootDir}:${basePath}`;
|
|
3078
|
+
if (importMapCache.has(cacheKey)) {
|
|
3079
|
+
return importMapCache.get(cacheKey);
|
|
3080
|
+
}
|
|
3081
|
+
const importMap = {};
|
|
3082
|
+
const nodeModulesPath = await findNodeModules(rootDir);
|
|
3083
|
+
if (!nodeModulesPath) {
|
|
3084
|
+
importMapCache.set(cacheKey, importMap);
|
|
3085
|
+
return importMap;
|
|
3086
|
+
}
|
|
3087
|
+
try {
|
|
3088
|
+
const { readdir: readdir2 } = await Promise.resolve().then(() => (init_fs(), fs_exports));
|
|
3089
|
+
const packages = await readdir2(nodeModulesPath);
|
|
3090
|
+
for (const pkgEntry of packages) {
|
|
3091
|
+
const pkg = typeof pkgEntry === "string" ? pkgEntry : pkgEntry.name;
|
|
3092
|
+
if (pkg.startsWith(".")) continue;
|
|
3093
|
+
if (pkg.startsWith("@")) {
|
|
3094
|
+
try {
|
|
3095
|
+
const scopedPackages = await readdir2(join(nodeModulesPath, pkg));
|
|
3096
|
+
for (const scopedEntry of scopedPackages) {
|
|
3097
|
+
const scopedPkg = typeof scopedEntry === "string" ? scopedEntry : scopedEntry.name;
|
|
3098
|
+
const fullPkgName = `${pkg}/${scopedPkg}`;
|
|
3099
|
+
await processPackage(nodeModulesPath, fullPkgName, importMap, basePath);
|
|
3100
|
+
}
|
|
3101
|
+
} catch {
|
|
3102
|
+
}
|
|
3103
|
+
} else {
|
|
3104
|
+
await processPackage(nodeModulesPath, pkg, importMap, basePath);
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
} catch (error) {
|
|
3108
|
+
console.error("[Import Maps] Error scanning node_modules:", error);
|
|
3109
|
+
}
|
|
3110
|
+
importMapCache.set(cacheKey, importMap);
|
|
3111
|
+
return importMap;
|
|
3112
|
+
}
|
|
3113
|
+
async function findNodeModules(startDir) {
|
|
3114
|
+
const foundDir = await findSpecialDir(startDir, "node_modules");
|
|
3115
|
+
return foundDir ? join(foundDir, "node_modules") : null;
|
|
3116
|
+
}
|
|
3117
|
+
function isBrowserCompatible(pkgName, pkgJson) {
|
|
3118
|
+
const buildTools = [
|
|
3119
|
+
"typescript",
|
|
3120
|
+
"esbuild",
|
|
3121
|
+
"@esbuild/",
|
|
3122
|
+
"tsx",
|
|
3123
|
+
"tsup",
|
|
3124
|
+
"rollup",
|
|
3125
|
+
"vite",
|
|
3126
|
+
"webpack",
|
|
3127
|
+
"parcel",
|
|
3128
|
+
"terser",
|
|
3129
|
+
"uglify",
|
|
3130
|
+
"babel",
|
|
3131
|
+
"@babel/",
|
|
3132
|
+
"postcss",
|
|
3133
|
+
"autoprefixer",
|
|
3134
|
+
"cssnano",
|
|
3135
|
+
"sass",
|
|
3136
|
+
"less",
|
|
3137
|
+
"stylus"
|
|
3138
|
+
];
|
|
3139
|
+
const nodeOnly = [
|
|
3140
|
+
"node-",
|
|
3141
|
+
"@node-",
|
|
3142
|
+
"fsevents",
|
|
3143
|
+
"chokidar",
|
|
3144
|
+
"express",
|
|
3145
|
+
"koa",
|
|
3146
|
+
"fastify",
|
|
3147
|
+
"nest",
|
|
3148
|
+
"commander",
|
|
3149
|
+
"yargs",
|
|
3150
|
+
"inquirer",
|
|
3151
|
+
"chalk",
|
|
3152
|
+
"ora",
|
|
3153
|
+
"nodemon",
|
|
3154
|
+
"pm2",
|
|
3155
|
+
"dotenv"
|
|
3156
|
+
];
|
|
3157
|
+
const testingTools = [
|
|
3158
|
+
"jest",
|
|
3159
|
+
"vitest",
|
|
3160
|
+
"mocha",
|
|
3161
|
+
"chai",
|
|
3162
|
+
"jasmine",
|
|
3163
|
+
"@jest/",
|
|
3164
|
+
"@testing-library/",
|
|
3165
|
+
"@vitest/",
|
|
3166
|
+
"playwright",
|
|
3167
|
+
"puppeteer",
|
|
3168
|
+
"cypress"
|
|
3169
|
+
];
|
|
3170
|
+
const linters = [
|
|
3171
|
+
"eslint",
|
|
3172
|
+
"@eslint/",
|
|
3173
|
+
"prettier",
|
|
3174
|
+
"tslint",
|
|
3175
|
+
"stylelint",
|
|
3176
|
+
"commitlint"
|
|
3177
|
+
];
|
|
3178
|
+
const typeDefinitions = [
|
|
3179
|
+
"@types/",
|
|
3180
|
+
"@typescript-eslint/"
|
|
3181
|
+
];
|
|
3182
|
+
const utilities = [
|
|
3183
|
+
"get-tsconfig",
|
|
3184
|
+
"resolve-pkg-maps",
|
|
3185
|
+
"pkg-types",
|
|
3186
|
+
"fast-glob",
|
|
3187
|
+
"globby",
|
|
3188
|
+
"micromatch",
|
|
3189
|
+
"execa",
|
|
3190
|
+
"cross-spawn",
|
|
3191
|
+
"shelljs"
|
|
3192
|
+
];
|
|
3193
|
+
const skipPatterns = [
|
|
3194
|
+
...buildTools,
|
|
3195
|
+
...nodeOnly,
|
|
3196
|
+
...testingTools,
|
|
3197
|
+
...linters,
|
|
3198
|
+
...typeDefinitions,
|
|
3199
|
+
...utilities
|
|
3200
|
+
];
|
|
3201
|
+
if (skipPatterns.some((pattern) => pkgName.startsWith(pattern))) {
|
|
3202
|
+
return false;
|
|
3203
|
+
}
|
|
3204
|
+
if (pkgName === "lodash") {
|
|
3205
|
+
return false;
|
|
3206
|
+
}
|
|
3207
|
+
if (pkgJson.browser || pkgJson.module) {
|
|
3208
|
+
return true;
|
|
3209
|
+
}
|
|
3210
|
+
if (pkgJson.exports) {
|
|
3211
|
+
const exportsStr = JSON.stringify(pkgJson.exports);
|
|
3212
|
+
if (exportsStr.includes('"import"') || exportsStr.includes('"browser"')) {
|
|
3213
|
+
return true;
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
if (pkgJson.type === "commonjs" && !pkgJson.module && !pkgJson.browser) {
|
|
3217
|
+
return false;
|
|
3218
|
+
}
|
|
3219
|
+
return !!(pkgJson.exports || pkgJson.type === "module" || pkgJson.module);
|
|
3220
|
+
}
|
|
3221
|
+
async function processPackage(nodeModulesPath, pkgName, importMap, basePath) {
|
|
3222
|
+
const pkgPath = join(nodeModulesPath, pkgName);
|
|
3223
|
+
const pkgJsonPath = join(pkgPath, "package.json");
|
|
3224
|
+
try {
|
|
3225
|
+
const pkgJsonContent = await readFile(pkgJsonPath);
|
|
3226
|
+
const pkgJson = JSON.parse(pkgJsonContent.toString());
|
|
3227
|
+
if (!isBrowserCompatible(pkgName, pkgJson)) {
|
|
3228
|
+
return;
|
|
3229
|
+
}
|
|
3230
|
+
const baseUrl = basePath ? `${basePath}/node_modules/${pkgName}` : `/node_modules/${pkgName}`;
|
|
3231
|
+
if (pkgJson.exports) {
|
|
3232
|
+
processExportsField(pkgName, pkgJson.exports, baseUrl, importMap);
|
|
3233
|
+
} else {
|
|
3234
|
+
const entryPoint = pkgJson.browser || pkgJson.module || pkgJson.main || "index.js";
|
|
3235
|
+
importMap[pkgName] = `${baseUrl}/${entryPoint}`;
|
|
3236
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
3237
|
+
}
|
|
3238
|
+
} catch {
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
function processExportsField(pkgName, exports2, baseUrl, importMap) {
|
|
3242
|
+
if (typeof exports2 === "string") {
|
|
3243
|
+
importMap[pkgName] = `${baseUrl}/${exports2}`;
|
|
3244
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
if (typeof exports2 === "object" && exports2 !== null) {
|
|
3248
|
+
if ("." in exports2) {
|
|
3249
|
+
const dotExport = exports2["."];
|
|
3250
|
+
const resolved = resolveExport(dotExport);
|
|
3251
|
+
if (resolved) {
|
|
3252
|
+
importMap[pkgName] = `${baseUrl}/${resolved}`;
|
|
3253
|
+
}
|
|
3254
|
+
} else if ("import" in exports2) {
|
|
3255
|
+
const resolved = resolveExport(exports2);
|
|
3256
|
+
if (resolved) {
|
|
3257
|
+
importMap[pkgName] = `${baseUrl}/${resolved}`;
|
|
3258
|
+
}
|
|
3259
|
+
}
|
|
3260
|
+
for (const [key, value] of Object.entries(exports2)) {
|
|
3261
|
+
if (key === "." || key === "import" || key === "require" || key === "types" || key === "default") {
|
|
3262
|
+
continue;
|
|
3263
|
+
}
|
|
3264
|
+
const resolved = resolveExport(value);
|
|
3265
|
+
if (resolved) {
|
|
3266
|
+
const cleanKey = key.startsWith("./") ? key.slice(2) : key;
|
|
3267
|
+
const importName = cleanKey ? `${pkgName}/${cleanKey}` : pkgName;
|
|
3268
|
+
importMap[importName] = `${baseUrl}/${resolved}`;
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
importMap[`${pkgName}/`] = `${baseUrl}/`;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
function resolveExport(exportValue) {
|
|
3275
|
+
if (typeof exportValue === "string") {
|
|
3276
|
+
return exportValue.startsWith("./") ? exportValue.slice(2) : exportValue;
|
|
3277
|
+
}
|
|
3278
|
+
if (typeof exportValue === "object" && exportValue !== null) {
|
|
3279
|
+
const resolved = exportValue.import || exportValue.browser || exportValue.default || exportValue.require;
|
|
3280
|
+
if (typeof resolved === "object" && resolved !== null) {
|
|
3281
|
+
return resolveExport(resolved);
|
|
3282
|
+
}
|
|
3283
|
+
if (typeof resolved === "string") {
|
|
3284
|
+
return resolved.startsWith("./") ? resolved.slice(2) : resolved;
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
return null;
|
|
3288
|
+
}
|
|
3074
3289
|
function rewritePath(path, pathRewrite) {
|
|
3075
3290
|
if (!pathRewrite) return path;
|
|
3076
3291
|
for (const [from, to] of Object.entries(pathRewrite)) {
|
|
@@ -3109,8 +3324,9 @@ function createProxyHandler(proxyConfigs) {
|
|
|
3109
3324
|
}
|
|
3110
3325
|
if (changeOrigin) {
|
|
3111
3326
|
proxyReqHeaders.host = targetUrl.host;
|
|
3327
|
+
} else {
|
|
3328
|
+
delete proxyReqHeaders["host"];
|
|
3112
3329
|
}
|
|
3113
|
-
delete proxyReqHeaders["host"];
|
|
3114
3330
|
const proxyReqOptions = {
|
|
3115
3331
|
method: req.method,
|
|
3116
3332
|
headers: proxyReqHeaders
|
|
@@ -3247,7 +3463,6 @@ var defaultOptions = {
|
|
|
3247
3463
|
watch: ["**/*.ts", "**/*.js", "**/*.html", "**/*.css"],
|
|
3248
3464
|
ignore: ["node_modules/**", "dist/**", ".git/**", "**/*.d.ts"],
|
|
3249
3465
|
logging: true,
|
|
3250
|
-
middleware: [],
|
|
3251
3466
|
worker: [],
|
|
3252
3467
|
mode: "dev"
|
|
3253
3468
|
};
|
|
@@ -3319,7 +3534,7 @@ function createDevServer(options) {
|
|
|
3319
3534
|
}
|
|
3320
3535
|
let filePath;
|
|
3321
3536
|
if (url === "/" && matchedClient.ssr && !matchedClient.index) {
|
|
3322
|
-
return serveSSR(res, matchedClient);
|
|
3537
|
+
return await serveSSR(res, matchedClient);
|
|
3323
3538
|
} else {
|
|
3324
3539
|
filePath = url === "/" ? matchedClient.index || "/index.html" : url;
|
|
3325
3540
|
}
|
|
@@ -3401,7 +3616,7 @@ function createDevServer(options) {
|
|
|
3401
3616
|
if (!resolvedPath) {
|
|
3402
3617
|
if (!res.headersSent) {
|
|
3403
3618
|
if (filePath === "/index.html" && matchedClient.ssr) {
|
|
3404
|
-
return serveSSR(res, matchedClient);
|
|
3619
|
+
return await serveSSR(res, matchedClient);
|
|
3405
3620
|
}
|
|
3406
3621
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
3407
3622
|
return send404(res, "404 Not Found");
|
|
@@ -3425,7 +3640,7 @@ function createDevServer(options) {
|
|
|
3425
3640
|
} catch {
|
|
3426
3641
|
if (config.logging) console.log(`[DEBUG] No index file found in directory`);
|
|
3427
3642
|
if (matchedClient.ssr) {
|
|
3428
|
-
return serveSSR(res, matchedClient);
|
|
3643
|
+
return await serveSSR(res, matchedClient);
|
|
3429
3644
|
}
|
|
3430
3645
|
return send404(res, "404 Not Found");
|
|
3431
3646
|
}
|
|
@@ -3445,12 +3660,12 @@ function createDevServer(options) {
|
|
|
3445
3660
|
return send403(res, "403 Forbidden");
|
|
3446
3661
|
}
|
|
3447
3662
|
await stat(indexPath);
|
|
3448
|
-
return serveFile(indexPath, res, matchedClient);
|
|
3663
|
+
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3449
3664
|
} catch {
|
|
3450
3665
|
return send404(res, "404 Not Found");
|
|
3451
3666
|
}
|
|
3452
3667
|
}
|
|
3453
|
-
await serveFile(fullPath, res, matchedClient);
|
|
3668
|
+
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3454
3669
|
} catch (error) {
|
|
3455
3670
|
if (!res.headersSent) {
|
|
3456
3671
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
@@ -3458,16 +3673,12 @@ function createDevServer(options) {
|
|
|
3458
3673
|
}
|
|
3459
3674
|
}
|
|
3460
3675
|
});
|
|
3461
|
-
async function serveFile(filePath, res, client) {
|
|
3676
|
+
async function serveFile(filePath, res, client, isNodeModulesOrDist = false) {
|
|
3462
3677
|
try {
|
|
3463
3678
|
const rootDir = await realpath(resolve(client.root));
|
|
3464
3679
|
const unresolvedPath = resolve(filePath);
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
const projectRoot = await realpath(resolve(client.root, ".."));
|
|
3468
|
-
const isInProjectRoot = unresolvedPath.startsWith(projectRoot + sep) || unresolvedPath === projectRoot;
|
|
3469
|
-
if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir && !isInProjectRoot) {
|
|
3470
|
-
if (!isNodeModules && !isDist) {
|
|
3680
|
+
if (!isNodeModulesOrDist) {
|
|
3681
|
+
if (!unresolvedPath.startsWith(rootDir + sep) && unresolvedPath !== rootDir) {
|
|
3471
3682
|
if (config.logging) console.log(`[403] Attempted to serve file outside allowed directories: ${filePath}`);
|
|
3472
3683
|
return send403(res, "403 Forbidden");
|
|
3473
3684
|
}
|
|
@@ -3475,9 +3686,14 @@ function createDevServer(options) {
|
|
|
3475
3686
|
let resolvedPath;
|
|
3476
3687
|
try {
|
|
3477
3688
|
resolvedPath = await realpath(unresolvedPath);
|
|
3689
|
+
if (isNodeModulesOrDist && resolvedPath) {
|
|
3690
|
+
if (config.logging && !resolvedPath.startsWith(rootDir + sep)) {
|
|
3691
|
+
console.log(`[DEBUG] Serving symlinked file: ${resolvedPath}`);
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3478
3694
|
} catch {
|
|
3479
3695
|
if (filePath.endsWith("index.html") && client.ssr) {
|
|
3480
|
-
return serveSSR(res, client);
|
|
3696
|
+
return await serveSSR(res, client);
|
|
3481
3697
|
}
|
|
3482
3698
|
return send404(res, "404 Not Found");
|
|
3483
3699
|
}
|
|
@@ -3581,7 +3797,7 @@ ${error}`);
|
|
|
3581
3797
|
}
|
|
3582
3798
|
}
|
|
3583
3799
|
}
|
|
3584
|
-
const elitImportMap = createElitImportMap(basePath, client.mode);
|
|
3800
|
+
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
3585
3801
|
const headInjection = ssrStyles ? `${ssrStyles}
|
|
3586
3802
|
${elitImportMap}` : elitImportMap;
|
|
3587
3803
|
html = html.includes("</head>") ? html.replace("</head>", `${headInjection}</head>`) : html;
|
|
@@ -3611,7 +3827,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3611
3827
|
send500(res, "500 Internal Server Error");
|
|
3612
3828
|
}
|
|
3613
3829
|
}
|
|
3614
|
-
function serveSSR(res, client) {
|
|
3830
|
+
async function serveSSR(res, client) {
|
|
3615
3831
|
try {
|
|
3616
3832
|
if (!client.ssr) {
|
|
3617
3833
|
return send500(res, "SSR function not configured");
|
|
@@ -3633,7 +3849,7 @@ ${elitImportMap}` : elitImportMap;
|
|
|
3633
3849
|
const basePath = normalizeBasePath(client.basePath);
|
|
3634
3850
|
html = rewriteRelativePaths(html, basePath);
|
|
3635
3851
|
const hmrScript = createHMRScript(config.port, basePath);
|
|
3636
|
-
const elitImportMap = createElitImportMap(basePath, client.mode);
|
|
3852
|
+
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
3637
3853
|
html = html.includes("</head>") ? html.replace("</head>", `${elitImportMap}</head>`) : html;
|
|
3638
3854
|
html = html.includes("</body>") ? html.replace("</body>", `${hmrScript}</body>`) : html + hmrScript;
|
|
3639
3855
|
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-cache, no-store, must-revalidate" });
|
|
@@ -4174,9 +4390,6 @@ async function runPreview(args) {
|
|
|
4174
4390
|
if (mergedOptions.https) {
|
|
4175
4391
|
options.https = mergedOptions.https;
|
|
4176
4392
|
}
|
|
4177
|
-
if (mergedOptions.middleware) {
|
|
4178
|
-
options.middleware = mergedOptions.middleware;
|
|
4179
|
-
}
|
|
4180
4393
|
if (mergedOptions.ssr) {
|
|
4181
4394
|
options.ssr = mergedOptions.ssr;
|
|
4182
4395
|
}
|
|
@@ -4385,23 +4598,20 @@ Worker Configuration:
|
|
|
4385
4598
|
2. Global workers (defined in dev.worker or preview.worker)
|
|
4386
4599
|
Both global and client-specific workers will be loaded.
|
|
4387
4600
|
|
|
4388
|
-
API
|
|
4389
|
-
Configure REST API endpoints
|
|
4601
|
+
API Configuration:
|
|
4602
|
+
Configure REST API endpoints per client or globally.
|
|
4390
4603
|
Supports both global configuration and client-specific configuration.
|
|
4391
4604
|
|
|
4392
|
-
Client-specific API
|
|
4605
|
+
Client-specific API:
|
|
4393
4606
|
- Each client can have its own API router (clients[].api)
|
|
4394
|
-
- Each client can have its own middleware chain (clients[].middleware)
|
|
4395
4607
|
- Client-specific configuration is isolated to that client's routes
|
|
4396
4608
|
- API paths are automatically prefixed with the client's basePath
|
|
4397
4609
|
Example: If basePath is '/app1' and route is '/api/health',
|
|
4398
4610
|
the full path will be '/app1/api/health'
|
|
4399
4611
|
|
|
4400
4612
|
Priority:
|
|
4401
|
-
1. Client-specific
|
|
4402
|
-
2. Global
|
|
4403
|
-
3. Client-specific API routes are matched (defined in clients[].api)
|
|
4404
|
-
4. Global API routes are matched (defined in dev.api or preview.api)
|
|
4613
|
+
1. Client-specific API routes are matched first (defined in clients[].api)
|
|
4614
|
+
2. Global API routes are matched second (defined in dev.api or preview.api)
|
|
4405
4615
|
|
|
4406
4616
|
Examples:
|
|
4407
4617
|
elit dev
|
package/dist/server.d.ts
CHANGED
|
@@ -39,6 +39,10 @@ export declare const json: (res: ServerResponse, data: any, status?: number) =>
|
|
|
39
39
|
export declare const text: (res: ServerResponse, data: string, status?: number) => ServerResponse;
|
|
40
40
|
export declare const html: (res: ServerResponse, data: string, status?: number) => ServerResponse;
|
|
41
41
|
export declare const status: (res: ServerResponse, code: number, message?: string) => ServerResponse;
|
|
42
|
+
/**
|
|
43
|
+
* Clear import map cache (useful when packages are added/removed)
|
|
44
|
+
*/
|
|
45
|
+
export declare function clearImportMapCache(): void;
|
|
42
46
|
export declare function cors(options?: {
|
|
43
47
|
origin?: string | string[];
|
|
44
48
|
methods?: string[];
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,eAAe,EAAE,cAAc,EAA0B,MAAM,QAAQ,CAAC;AAE/F,OAAO,EAAmB,SAAS,EAAc,MAAM,MAAM,CAAC;AAM9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAA4B,WAAW,EAAE,MAAM,SAAS,CAAC;AAKlG,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAE1F,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,eAAe,CAAC;IACrB,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC,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