@flight-framework/cli 0.4.7 → 0.4.9

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/bin.js CHANGED
@@ -914,104 +914,6 @@ async function devCommand(options) {
914
914
  if (bundler && typeof bundler.createDevServer === "function") {
915
915
  consola2.info(`Using bundler: ${bundler.name || bundler.bundler || "custom"}`);
916
916
  const devServer = await bundler.createDevServer(config);
917
- const transformPort = devServer.port;
918
- const http = await import("http");
919
- const fs = await import("fs/promises");
920
- const path = await import("path");
921
- const indexHtmlPath = path.join(root, "index.html");
922
- const publicIndexPath = path.join(root, "public", "index.html");
923
- const server = http.createServer(async (req, res) => {
924
- const url = req.url || "/";
925
- const isSpaRoute = url === "/" || url === "/index.html" || !url.includes(".") && !url.startsWith("/@") && !url.startsWith("/__") && !url.startsWith("/src/") && !url.startsWith("/node_modules/");
926
- if (isSpaRoute) {
927
- try {
928
- let htmlContent;
929
- try {
930
- htmlContent = await fs.readFile(indexHtmlPath, "utf-8");
931
- } catch {
932
- htmlContent = await fs.readFile(publicIndexPath, "utf-8");
933
- }
934
- if (!htmlContent.includes("/__flightpack/hmr-runtime.js")) {
935
- htmlContent = htmlContent.replace(
936
- "</body>",
937
- `<script src="/__flightpack/hmr-runtime.js"></script>
938
- </body>`
939
- );
940
- }
941
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
942
- res.end(htmlContent);
943
- } catch (err) {
944
- res.writeHead(404, { "Content-Type": "text/plain" });
945
- res.end(`index.html not found in ${root}`);
946
- }
947
- return;
948
- }
949
- const proxyRequest = async (targetUrl, originalRes) => {
950
- const proxyReq = http.request(
951
- {
952
- hostname: "localhost",
953
- port: transformPort,
954
- path: targetUrl,
955
- method: req.method,
956
- headers: req.headers
957
- },
958
- async (proxyRes) => {
959
- if (proxyRes.statusCode !== 404) {
960
- res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
961
- proxyRes.pipe(res);
962
- return;
963
- }
964
- if (targetUrl.startsWith("/node_modules/")) {
965
- proxyRes.resume();
966
- try {
967
- const { createRequire } = await import("module");
968
- const require2 = createRequire(root + "/");
969
- const importPath = targetUrl.replace("/node_modules/", "");
970
- const resolvedPath = require2.resolve(importPath);
971
- const content = await fs.readFile(resolvedPath);
972
- let contentType = "application/javascript";
973
- if (resolvedPath.endsWith(".json")) contentType = "application/json";
974
- if (resolvedPath.endsWith(".css")) contentType = "text/css";
975
- res.writeHead(200, {
976
- "Content-Type": contentType,
977
- "Access-Control-Allow-Origin": "*",
978
- "Cache-Control": "no-cache"
979
- });
980
- res.end(content);
981
- return;
982
- } catch (resolveError) {
983
- res.writeHead(404, proxyRes.headers);
984
- res.end("Not Found");
985
- return;
986
- }
987
- }
988
- res.writeHead(proxyRes.statusCode || 404, proxyRes.headers);
989
- proxyRes.pipe(res);
990
- }
991
- );
992
- proxyReq.on("error", (err) => {
993
- console.error("[CLI Proxy Error]", err.message);
994
- if (!res.headersSent) {
995
- res.writeHead(502, { "Content-Type": "text/plain" });
996
- res.end("FlightPack transform server unavailable");
997
- }
998
- });
999
- if (req.method !== "GET" && req.method !== "HEAD") {
1000
- req.pipe(proxyReq);
1001
- } else {
1002
- proxyReq.end();
1003
- }
1004
- };
1005
- proxyRequest(url, res);
1006
- });
1007
- const cliPort = port;
1008
- await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));
1009
- console.log(`
1010
- \u26A1 Flight dev server running
1011
- `);
1012
- console.log(` Bundler: FlightPack`);
1013
- console.log(` Local: http://localhost:${cliPort}`);
1014
- console.log(``);
1015
917
  const elapsed = Date.now() - startTime;
1016
918
  consola2.success(`Flight dev server ready in ${elapsed}ms`);
1017
919
  devServer.printUrls?.();