elit 3.0.4 → 3.0.6
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 +30 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +29 -3
- package/dist/server.mjs +29 -3
- package/package.json +1 -1
- package/src/server.ts +43 -3
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.6",
|
|
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",
|
|
@@ -3660,12 +3660,12 @@ function createDevServer(options) {
|
|
|
3660
3660
|
return send403(res, "403 Forbidden");
|
|
3661
3661
|
}
|
|
3662
3662
|
await stat(indexPath);
|
|
3663
|
-
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3663
|
+
return serveFile(indexPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3664
3664
|
} catch {
|
|
3665
3665
|
return send404(res, "404 Not Found");
|
|
3666
3666
|
}
|
|
3667
3667
|
}
|
|
3668
|
-
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3668
|
+
await serveFile(fullPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3669
3669
|
} catch (error) {
|
|
3670
3670
|
if (!res.headersSent) {
|
|
3671
3671
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
@@ -3673,7 +3673,10 @@ function createDevServer(options) {
|
|
|
3673
3673
|
}
|
|
3674
3674
|
}
|
|
3675
3675
|
});
|
|
3676
|
-
async function serveFile(filePath, res, client, isNodeModulesOrDist = false) {
|
|
3676
|
+
async function serveFile(filePath, req, res, client, isNodeModulesOrDist = false) {
|
|
3677
|
+
function escapeForTemplateLiteral(input) {
|
|
3678
|
+
return input.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
3679
|
+
}
|
|
3677
3680
|
try {
|
|
3678
3681
|
const rootDir = await realpath(resolve(client.root));
|
|
3679
3682
|
const unresolvedPath = resolve(filePath);
|
|
@@ -3700,6 +3703,21 @@ function createDevServer(options) {
|
|
|
3700
3703
|
let content = await readFile(resolvedPath);
|
|
3701
3704
|
const ext = extname(resolvedPath);
|
|
3702
3705
|
let mimeType = lookup(resolvedPath) || "application/octet-stream";
|
|
3706
|
+
const urlQuery = req.url?.split("?")[1] || "";
|
|
3707
|
+
const isInlineCSS = urlQuery.includes("inline");
|
|
3708
|
+
if (ext === ".css" && isInlineCSS) {
|
|
3709
|
+
const cssContent = escapeForTemplateLiteral(content.toString());
|
|
3710
|
+
const jsModule = `
|
|
3711
|
+
const css = \`${cssContent}\`;
|
|
3712
|
+
const style = document.createElement('style');
|
|
3713
|
+
style.setAttribute('data-file', '${filePath}');
|
|
3714
|
+
style.textContent = css;
|
|
3715
|
+
document.head.appendChild(style);
|
|
3716
|
+
export default css;
|
|
3717
|
+
`;
|
|
3718
|
+
content = Buffer.from(jsModule);
|
|
3719
|
+
mimeType = "application/javascript";
|
|
3720
|
+
}
|
|
3703
3721
|
if (ext === ".ts" || ext === ".tsx") {
|
|
3704
3722
|
try {
|
|
3705
3723
|
let transpiled;
|
|
@@ -3748,6 +3766,14 @@ function createDevServer(options) {
|
|
|
3748
3766
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
3749
3767
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
3750
3768
|
);
|
|
3769
|
+
transpiled = transpiled.replace(
|
|
3770
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
3771
|
+
(_, path) => `import "${path}?inline"`
|
|
3772
|
+
);
|
|
3773
|
+
transpiled = transpiled.replace(
|
|
3774
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
3775
|
+
(_, path) => `from "${path}?inline"`
|
|
3776
|
+
);
|
|
3751
3777
|
content = Buffer.from(transpiled);
|
|
3752
3778
|
mimeType = "application/javascript";
|
|
3753
3779
|
} catch (error) {
|
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,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;CACxD;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACnF,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAStG,qBAAa,YAAY;IACvB,OA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AAI;IAI7C,cAAc,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAInC,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAKhD,IAAI,IAAI,MAAM,EAAE;IAIhB,KAAK,IAAI,IAAI;CAId;AA0BD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA0tBpE"}
|
package/dist/server.js
CHANGED
|
@@ -3500,12 +3500,12 @@ function createDevServer(options) {
|
|
|
3500
3500
|
return send403(res, "403 Forbidden");
|
|
3501
3501
|
}
|
|
3502
3502
|
await stat(indexPath);
|
|
3503
|
-
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3503
|
+
return serveFile(indexPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3504
3504
|
} catch {
|
|
3505
3505
|
return send404(res, "404 Not Found");
|
|
3506
3506
|
}
|
|
3507
3507
|
}
|
|
3508
|
-
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3508
|
+
await serveFile(fullPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3509
3509
|
} catch (error) {
|
|
3510
3510
|
if (!res.headersSent) {
|
|
3511
3511
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
@@ -3513,7 +3513,10 @@ function createDevServer(options) {
|
|
|
3513
3513
|
}
|
|
3514
3514
|
}
|
|
3515
3515
|
});
|
|
3516
|
-
async function serveFile(filePath, res, client, isNodeModulesOrDist = false) {
|
|
3516
|
+
async function serveFile(filePath, req, res, client, isNodeModulesOrDist = false) {
|
|
3517
|
+
function escapeForTemplateLiteral(input) {
|
|
3518
|
+
return input.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
3519
|
+
}
|
|
3517
3520
|
try {
|
|
3518
3521
|
const rootDir = await realpath(resolve(client.root));
|
|
3519
3522
|
const unresolvedPath = resolve(filePath);
|
|
@@ -3540,6 +3543,21 @@ function createDevServer(options) {
|
|
|
3540
3543
|
let content = await readFile(resolvedPath);
|
|
3541
3544
|
const ext = extname(resolvedPath);
|
|
3542
3545
|
let mimeType = lookup(resolvedPath) || "application/octet-stream";
|
|
3546
|
+
const urlQuery = req.url?.split("?")[1] || "";
|
|
3547
|
+
const isInlineCSS = urlQuery.includes("inline");
|
|
3548
|
+
if (ext === ".css" && isInlineCSS) {
|
|
3549
|
+
const cssContent = escapeForTemplateLiteral(content.toString());
|
|
3550
|
+
const jsModule = `
|
|
3551
|
+
const css = \`${cssContent}\`;
|
|
3552
|
+
const style = document.createElement('style');
|
|
3553
|
+
style.setAttribute('data-file', '${filePath}');
|
|
3554
|
+
style.textContent = css;
|
|
3555
|
+
document.head.appendChild(style);
|
|
3556
|
+
export default css;
|
|
3557
|
+
`;
|
|
3558
|
+
content = Buffer.from(jsModule);
|
|
3559
|
+
mimeType = "application/javascript";
|
|
3560
|
+
}
|
|
3543
3561
|
if (ext === ".ts" || ext === ".tsx") {
|
|
3544
3562
|
try {
|
|
3545
3563
|
let transpiled;
|
|
@@ -3588,6 +3606,14 @@ function createDevServer(options) {
|
|
|
3588
3606
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
3589
3607
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
3590
3608
|
);
|
|
3609
|
+
transpiled = transpiled.replace(
|
|
3610
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
3611
|
+
(_, path) => `import "${path}?inline"`
|
|
3612
|
+
);
|
|
3613
|
+
transpiled = transpiled.replace(
|
|
3614
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
3615
|
+
(_, path) => `from "${path}?inline"`
|
|
3616
|
+
);
|
|
3591
3617
|
content = Buffer.from(transpiled);
|
|
3592
3618
|
mimeType = "application/javascript";
|
|
3593
3619
|
} catch (error) {
|
package/dist/server.mjs
CHANGED
|
@@ -3474,12 +3474,12 @@ function createDevServer(options) {
|
|
|
3474
3474
|
return send403(res, "403 Forbidden");
|
|
3475
3475
|
}
|
|
3476
3476
|
await stat(indexPath);
|
|
3477
|
-
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3477
|
+
return serveFile(indexPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3478
3478
|
} catch {
|
|
3479
3479
|
return send404(res, "404 Not Found");
|
|
3480
3480
|
}
|
|
3481
3481
|
}
|
|
3482
|
-
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3482
|
+
await serveFile(fullPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
3483
3483
|
} catch (error) {
|
|
3484
3484
|
if (!res.headersSent) {
|
|
3485
3485
|
if (config.logging) console.log(`[404] ${filePath}`);
|
|
@@ -3487,7 +3487,10 @@ function createDevServer(options) {
|
|
|
3487
3487
|
}
|
|
3488
3488
|
}
|
|
3489
3489
|
});
|
|
3490
|
-
async function serveFile(filePath, res, client, isNodeModulesOrDist = false) {
|
|
3490
|
+
async function serveFile(filePath, req, res, client, isNodeModulesOrDist = false) {
|
|
3491
|
+
function escapeForTemplateLiteral(input) {
|
|
3492
|
+
return input.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
3493
|
+
}
|
|
3491
3494
|
try {
|
|
3492
3495
|
const rootDir = await realpath(resolve(client.root));
|
|
3493
3496
|
const unresolvedPath = resolve(filePath);
|
|
@@ -3514,6 +3517,21 @@ function createDevServer(options) {
|
|
|
3514
3517
|
let content = await readFile(resolvedPath);
|
|
3515
3518
|
const ext = extname(resolvedPath);
|
|
3516
3519
|
let mimeType = lookup(resolvedPath) || "application/octet-stream";
|
|
3520
|
+
const urlQuery = req.url?.split("?")[1] || "";
|
|
3521
|
+
const isInlineCSS = urlQuery.includes("inline");
|
|
3522
|
+
if (ext === ".css" && isInlineCSS) {
|
|
3523
|
+
const cssContent = escapeForTemplateLiteral(content.toString());
|
|
3524
|
+
const jsModule = `
|
|
3525
|
+
const css = \`${cssContent}\`;
|
|
3526
|
+
const style = document.createElement('style');
|
|
3527
|
+
style.setAttribute('data-file', '${filePath}');
|
|
3528
|
+
style.textContent = css;
|
|
3529
|
+
document.head.appendChild(style);
|
|
3530
|
+
export default css;
|
|
3531
|
+
`;
|
|
3532
|
+
content = Buffer.from(jsModule);
|
|
3533
|
+
mimeType = "application/javascript";
|
|
3534
|
+
}
|
|
3517
3535
|
if (ext === ".ts" || ext === ".tsx") {
|
|
3518
3536
|
try {
|
|
3519
3537
|
let transpiled;
|
|
@@ -3562,6 +3580,14 @@ function createDevServer(options) {
|
|
|
3562
3580
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
3563
3581
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
3564
3582
|
);
|
|
3583
|
+
transpiled = transpiled.replace(
|
|
3584
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
3585
|
+
(_, path) => `import "${path}?inline"`
|
|
3586
|
+
);
|
|
3587
|
+
transpiled = transpiled.replace(
|
|
3588
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
3589
|
+
(_, path) => `from "${path}?inline"`
|
|
3590
|
+
);
|
|
3565
3591
|
content = Buffer.from(transpiled);
|
|
3566
3592
|
mimeType = "application/javascript";
|
|
3567
3593
|
} catch (error) {
|
package/package.json
CHANGED
package/src/server.ts
CHANGED
|
@@ -1164,13 +1164,13 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1164
1164
|
return send403(res, '403 Forbidden');
|
|
1165
1165
|
}
|
|
1166
1166
|
await stat(indexPath);
|
|
1167
|
-
return serveFile(indexPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
1167
|
+
return serveFile(indexPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
1168
1168
|
} catch {
|
|
1169
1169
|
return send404(res, '404 Not Found');
|
|
1170
1170
|
}
|
|
1171
1171
|
}
|
|
1172
1172
|
|
|
1173
|
-
await serveFile(fullPath, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
1173
|
+
await serveFile(fullPath, req, res, matchedClient, isDistRequest || isNodeModulesRequest);
|
|
1174
1174
|
} catch (error) {
|
|
1175
1175
|
// Only send 404 if response hasn't been sent yet
|
|
1176
1176
|
if (!res.headersSent) {
|
|
@@ -1181,7 +1181,16 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1181
1181
|
});
|
|
1182
1182
|
|
|
1183
1183
|
// Serve file helper
|
|
1184
|
-
async function serveFile(filePath: string, res: ServerResponse, client: NormalizedClient, isNodeModulesOrDist: boolean = false) {
|
|
1184
|
+
async function serveFile(filePath: string, req: IncomingMessage, res: ServerResponse, client: NormalizedClient, isNodeModulesOrDist: boolean = false) {
|
|
1185
|
+
// Escape arbitrary text for safe embedding inside a JavaScript template literal.
|
|
1186
|
+
// This ensures that backslashes, backticks and `${` sequences are correctly escaped.
|
|
1187
|
+
function escapeForTemplateLiteral(input: string): string {
|
|
1188
|
+
return input
|
|
1189
|
+
.replace(/\\/g, '\\\\')
|
|
1190
|
+
.replace(/`/g, '\\`')
|
|
1191
|
+
.replace(/\$\{/g, '\\${');
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1185
1194
|
try {
|
|
1186
1195
|
const rootDir = await realpath(resolve(client.root));
|
|
1187
1196
|
|
|
@@ -1221,6 +1230,26 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1221
1230
|
const ext = extname(resolvedPath);
|
|
1222
1231
|
let mimeType = lookup(resolvedPath) || 'application/octet-stream';
|
|
1223
1232
|
|
|
1233
|
+
// Handle CSS imports as JavaScript modules (like Vite)
|
|
1234
|
+
// When CSS is imported in JS/TS with ?inline query, transform it to a JS module that injects styles
|
|
1235
|
+
const urlQuery = req.url?.split('?')[1] || '';
|
|
1236
|
+
const isInlineCSS = urlQuery.includes('inline');
|
|
1237
|
+
|
|
1238
|
+
if (ext === '.css' && isInlineCSS) {
|
|
1239
|
+
// Transform CSS to JavaScript module that injects styles
|
|
1240
|
+
const cssContent = escapeForTemplateLiteral(content.toString());
|
|
1241
|
+
const jsModule = `
|
|
1242
|
+
const css = \`${cssContent}\`;
|
|
1243
|
+
const style = document.createElement('style');
|
|
1244
|
+
style.setAttribute('data-file', '${filePath}');
|
|
1245
|
+
style.textContent = css;
|
|
1246
|
+
document.head.appendChild(style);
|
|
1247
|
+
export default css;
|
|
1248
|
+
`;
|
|
1249
|
+
content = Buffer.from(jsModule);
|
|
1250
|
+
mimeType = 'application/javascript';
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1224
1253
|
// Handle TypeScript files - transpile only (no bundling)
|
|
1225
1254
|
if (ext === '.ts' || ext === '.tsx') {
|
|
1226
1255
|
try {
|
|
@@ -1286,6 +1315,17 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1286
1315
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
1287
1316
|
);
|
|
1288
1317
|
|
|
1318
|
+
// Rewrite CSS imports to add ?inline query parameter
|
|
1319
|
+
// This tells the server to return CSS as a JavaScript module
|
|
1320
|
+
transpiled = transpiled.replace(
|
|
1321
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
1322
|
+
(_, path) => `import "${path}?inline"`
|
|
1323
|
+
);
|
|
1324
|
+
transpiled = transpiled.replace(
|
|
1325
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
1326
|
+
(_, path) => `from "${path}?inline"`
|
|
1327
|
+
);
|
|
1328
|
+
|
|
1289
1329
|
content = Buffer.from(transpiled);
|
|
1290
1330
|
mimeType = 'application/javascript';
|
|
1291
1331
|
} catch (error) {
|