elit 3.0.4 → 3.0.5
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 +27 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +26 -3
- package/dist/server.mjs +26 -3
- package/package.json +1 -1
- package/src/server.ts +34 -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.5",
|
|
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,7 @@ 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
3677
|
try {
|
|
3678
3678
|
const rootDir = await realpath(resolve(client.root));
|
|
3679
3679
|
const unresolvedPath = resolve(filePath);
|
|
@@ -3700,6 +3700,21 @@ function createDevServer(options) {
|
|
|
3700
3700
|
let content = await readFile(resolvedPath);
|
|
3701
3701
|
const ext = extname(resolvedPath);
|
|
3702
3702
|
let mimeType = lookup(resolvedPath) || "application/octet-stream";
|
|
3703
|
+
const urlQuery = req.url?.split("?")[1] || "";
|
|
3704
|
+
const isInlineCSS = urlQuery.includes("inline");
|
|
3705
|
+
if (ext === ".css" && isInlineCSS) {
|
|
3706
|
+
const cssContent = content.toString().replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
3707
|
+
const jsModule = `
|
|
3708
|
+
const css = \`${cssContent}\`;
|
|
3709
|
+
const style = document.createElement('style');
|
|
3710
|
+
style.setAttribute('data-file', '${filePath}');
|
|
3711
|
+
style.textContent = css;
|
|
3712
|
+
document.head.appendChild(style);
|
|
3713
|
+
export default css;
|
|
3714
|
+
`;
|
|
3715
|
+
content = Buffer.from(jsModule);
|
|
3716
|
+
mimeType = "application/javascript";
|
|
3717
|
+
}
|
|
3703
3718
|
if (ext === ".ts" || ext === ".tsx") {
|
|
3704
3719
|
try {
|
|
3705
3720
|
let transpiled;
|
|
@@ -3748,6 +3763,14 @@ function createDevServer(options) {
|
|
|
3748
3763
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
3749
3764
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
3750
3765
|
);
|
|
3766
|
+
transpiled = transpiled.replace(
|
|
3767
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
3768
|
+
(_, path) => `import "${path}?inline"`
|
|
3769
|
+
);
|
|
3770
|
+
transpiled = transpiled.replace(
|
|
3771
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
3772
|
+
(_, path) => `from "${path}?inline"`
|
|
3773
|
+
);
|
|
3751
3774
|
content = Buffer.from(transpiled);
|
|
3752
3775
|
mimeType = "application/javascript";
|
|
3753
3776
|
} 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,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,WAAW,CAAoB;IAEvC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;I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EAAE,GAAG,GAAG,IAAI;IAKhD,IAAI,IAAI,MAAM,EAAE;IAIhB,KAAK,IAAI,IAAI;CAId;AA0BD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAitBpE"}
|
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,7 @@ 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
3517
|
try {
|
|
3518
3518
|
const rootDir = await realpath(resolve(client.root));
|
|
3519
3519
|
const unresolvedPath = resolve(filePath);
|
|
@@ -3540,6 +3540,21 @@ function createDevServer(options) {
|
|
|
3540
3540
|
let content = await readFile(resolvedPath);
|
|
3541
3541
|
const ext = extname(resolvedPath);
|
|
3542
3542
|
let mimeType = lookup(resolvedPath) || "application/octet-stream";
|
|
3543
|
+
const urlQuery = req.url?.split("?")[1] || "";
|
|
3544
|
+
const isInlineCSS = urlQuery.includes("inline");
|
|
3545
|
+
if (ext === ".css" && isInlineCSS) {
|
|
3546
|
+
const cssContent = content.toString().replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
3547
|
+
const jsModule = `
|
|
3548
|
+
const css = \`${cssContent}\`;
|
|
3549
|
+
const style = document.createElement('style');
|
|
3550
|
+
style.setAttribute('data-file', '${filePath}');
|
|
3551
|
+
style.textContent = css;
|
|
3552
|
+
document.head.appendChild(style);
|
|
3553
|
+
export default css;
|
|
3554
|
+
`;
|
|
3555
|
+
content = Buffer.from(jsModule);
|
|
3556
|
+
mimeType = "application/javascript";
|
|
3557
|
+
}
|
|
3543
3558
|
if (ext === ".ts" || ext === ".tsx") {
|
|
3544
3559
|
try {
|
|
3545
3560
|
let transpiled;
|
|
@@ -3588,6 +3603,14 @@ function createDevServer(options) {
|
|
|
3588
3603
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
3589
3604
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
3590
3605
|
);
|
|
3606
|
+
transpiled = transpiled.replace(
|
|
3607
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
3608
|
+
(_, path) => `import "${path}?inline"`
|
|
3609
|
+
);
|
|
3610
|
+
transpiled = transpiled.replace(
|
|
3611
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
3612
|
+
(_, path) => `from "${path}?inline"`
|
|
3613
|
+
);
|
|
3591
3614
|
content = Buffer.from(transpiled);
|
|
3592
3615
|
mimeType = "application/javascript";
|
|
3593
3616
|
} 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,7 @@ 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
3491
|
try {
|
|
3492
3492
|
const rootDir = await realpath(resolve(client.root));
|
|
3493
3493
|
const unresolvedPath = resolve(filePath);
|
|
@@ -3514,6 +3514,21 @@ function createDevServer(options) {
|
|
|
3514
3514
|
let content = await readFile(resolvedPath);
|
|
3515
3515
|
const ext = extname(resolvedPath);
|
|
3516
3516
|
let mimeType = lookup(resolvedPath) || "application/octet-stream";
|
|
3517
|
+
const urlQuery = req.url?.split("?")[1] || "";
|
|
3518
|
+
const isInlineCSS = urlQuery.includes("inline");
|
|
3519
|
+
if (ext === ".css" && isInlineCSS) {
|
|
3520
|
+
const cssContent = content.toString().replace(/`/g, "\\`").replace(/\$/g, "\\$");
|
|
3521
|
+
const jsModule = `
|
|
3522
|
+
const css = \`${cssContent}\`;
|
|
3523
|
+
const style = document.createElement('style');
|
|
3524
|
+
style.setAttribute('data-file', '${filePath}');
|
|
3525
|
+
style.textContent = css;
|
|
3526
|
+
document.head.appendChild(style);
|
|
3527
|
+
export default css;
|
|
3528
|
+
`;
|
|
3529
|
+
content = Buffer.from(jsModule);
|
|
3530
|
+
mimeType = "application/javascript";
|
|
3531
|
+
}
|
|
3517
3532
|
if (ext === ".ts" || ext === ".tsx") {
|
|
3518
3533
|
try {
|
|
3519
3534
|
let transpiled;
|
|
@@ -3562,6 +3577,14 @@ function createDevServer(options) {
|
|
|
3562
3577
|
/import\s+["']([^"']+)\.ts(x?)["']/g,
|
|
3563
3578
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
3564
3579
|
);
|
|
3580
|
+
transpiled = transpiled.replace(
|
|
3581
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
3582
|
+
(_, path) => `import "${path}?inline"`
|
|
3583
|
+
);
|
|
3584
|
+
transpiled = transpiled.replace(
|
|
3585
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
3586
|
+
(_, path) => `from "${path}?inline"`
|
|
3587
|
+
);
|
|
3565
3588
|
content = Buffer.from(transpiled);
|
|
3566
3589
|
mimeType = "application/javascript";
|
|
3567
3590
|
} 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,7 @@ 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
1185
|
try {
|
|
1186
1186
|
const rootDir = await realpath(resolve(client.root));
|
|
1187
1187
|
|
|
@@ -1221,6 +1221,26 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1221
1221
|
const ext = extname(resolvedPath);
|
|
1222
1222
|
let mimeType = lookup(resolvedPath) || 'application/octet-stream';
|
|
1223
1223
|
|
|
1224
|
+
// Handle CSS imports as JavaScript modules (like Vite)
|
|
1225
|
+
// When CSS is imported in JS/TS with ?inline query, transform it to a JS module that injects styles
|
|
1226
|
+
const urlQuery = req.url?.split('?')[1] || '';
|
|
1227
|
+
const isInlineCSS = urlQuery.includes('inline');
|
|
1228
|
+
|
|
1229
|
+
if (ext === '.css' && isInlineCSS) {
|
|
1230
|
+
// Transform CSS to JavaScript module that injects styles
|
|
1231
|
+
const cssContent = content.toString().replace(/`/g, '\\`').replace(/\$/g, '\\$');
|
|
1232
|
+
const jsModule = `
|
|
1233
|
+
const css = \`${cssContent}\`;
|
|
1234
|
+
const style = document.createElement('style');
|
|
1235
|
+
style.setAttribute('data-file', '${filePath}');
|
|
1236
|
+
style.textContent = css;
|
|
1237
|
+
document.head.appendChild(style);
|
|
1238
|
+
export default css;
|
|
1239
|
+
`;
|
|
1240
|
+
content = Buffer.from(jsModule);
|
|
1241
|
+
mimeType = 'application/javascript';
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1224
1244
|
// Handle TypeScript files - transpile only (no bundling)
|
|
1225
1245
|
if (ext === '.ts' || ext === '.tsx') {
|
|
1226
1246
|
try {
|
|
@@ -1286,6 +1306,17 @@ export function createDevServer(options: DevServerOptions): DevServer {
|
|
|
1286
1306
|
(_, path, tsx) => `import "${path}.js${tsx}"`
|
|
1287
1307
|
);
|
|
1288
1308
|
|
|
1309
|
+
// Rewrite CSS imports to add ?inline query parameter
|
|
1310
|
+
// This tells the server to return CSS as a JavaScript module
|
|
1311
|
+
transpiled = transpiled.replace(
|
|
1312
|
+
/import\s+["']([^"']+\.css)["']/g,
|
|
1313
|
+
(_, path) => `import "${path}?inline"`
|
|
1314
|
+
);
|
|
1315
|
+
transpiled = transpiled.replace(
|
|
1316
|
+
/from\s+["']([^"']+\.css)["']/g,
|
|
1317
|
+
(_, path) => `from "${path}?inline"`
|
|
1318
|
+
);
|
|
1319
|
+
|
|
1289
1320
|
content = Buffer.from(transpiled);
|
|
1290
1321
|
mimeType = 'application/javascript';
|
|
1291
1322
|
} catch (error) {
|