@flight-framework/cli 0.4.8 → 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
@@ -510,7 +510,7 @@ Happy flying!
510
510
  }
511
511
 
512
512
  // src/commands/dev.ts
513
- import { resolve as resolve3, join as join3, relative } from "path";
513
+ import { resolve as resolve3, join as join3 } from "path";
514
514
  import { readFileSync as readFileSync3, existsSync as existsSync3 } from "fs";
515
515
  import { consola as consola2 } from "consola";
516
516
  import { loadConfig } from "@flight-framework/core/config";
@@ -914,114 +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 { createRequire } = await import("module");
922
- const indexHtmlPath = path.join(root, "index.html");
923
- const publicIndexPath = path.join(root, "public", "index.html");
924
- const require2 = createRequire(root + "/");
925
- const server = http.createServer(async (req, res) => {
926
- const url = req.url || "/";
927
- const isSpaRoute = url === "/" || url === "/index.html" || !url.includes(".") && !url.startsWith("/@") && !url.startsWith("/__") && !url.startsWith("/src/") && !url.startsWith("/node_modules/");
928
- if (isSpaRoute) {
929
- try {
930
- let htmlContent;
931
- try {
932
- htmlContent = await fs.readFile(indexHtmlPath, "utf-8");
933
- } catch {
934
- htmlContent = await fs.readFile(publicIndexPath, "utf-8");
935
- }
936
- if (!htmlContent.includes("/__flightpack/hmr-runtime.js")) {
937
- htmlContent = htmlContent.replace(
938
- "</body>",
939
- `<script src="/__flightpack/hmr-runtime.js"></script>
940
- </body>`
941
- );
942
- }
943
- res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
944
- res.end(htmlContent);
945
- } catch (err) {
946
- res.writeHead(404, { "Content-Type": "text/plain" });
947
- res.end(`index.html not found in ${root}`);
948
- }
949
- return;
950
- }
951
- const proxyRequest = async (targetUrl, originalRes, retry = true) => {
952
- const proxyReq = http.request(
953
- {
954
- hostname: "localhost",
955
- port: transformPort,
956
- path: targetUrl,
957
- method: req.method,
958
- headers: req.headers
959
- },
960
- async (proxyRes) => {
961
- if (proxyRes.statusCode !== 404 || !retry) {
962
- res.writeHead(proxyRes.statusCode || 200, proxyRes.headers);
963
- proxyRes.pipe(res);
964
- return;
965
- }
966
- proxyRes.resume();
967
- try {
968
- let resolvedUrl = null;
969
- if (targetUrl.startsWith("/node_modules/")) {
970
- const importPath = targetUrl.replace("/node_modules/", "");
971
- try {
972
- const resolvedPath = require2.resolve(importPath);
973
- if (resolvedPath.startsWith(root)) {
974
- let rel = relative(root, resolvedPath);
975
- resolvedUrl = "/" + rel.replace(/\\/g, "/");
976
- }
977
- } catch (e) {
978
- }
979
- }
980
- if (!resolvedUrl && !targetUrl.includes(".")) {
981
- const commonExtensions = [".mjs", ".js", ".ts", ".tsx", ".jsx", "/index.js"];
982
- const relPath = targetUrl.startsWith("/") ? targetUrl.slice(1) : targetUrl;
983
- const absBase = join3(root, relPath);
984
- for (const ext of commonExtensions) {
985
- if (existsSync3(absBase + ext)) {
986
- resolvedUrl = targetUrl + ext;
987
- break;
988
- }
989
- }
990
- }
991
- if (resolvedUrl && resolvedUrl !== targetUrl) {
992
- return proxyRequest(resolvedUrl, originalRes, false);
993
- }
994
- res.writeHead(404, proxyRes.headers);
995
- res.end("Not Found");
996
- } catch (resolveError) {
997
- res.writeHead(404, proxyRes.headers);
998
- res.end("Not Found");
999
- }
1000
- }
1001
- );
1002
- proxyReq.on("error", (err) => {
1003
- console.error("[CLI Proxy Error]", err.message);
1004
- if (!res.headersSent) {
1005
- res.writeHead(502, { "Content-Type": "text/plain" });
1006
- res.end("FlightPack transform server unavailable");
1007
- }
1008
- });
1009
- if (req.method !== "GET" && req.method !== "HEAD") {
1010
- req.pipe(proxyReq);
1011
- } else {
1012
- proxyReq.end();
1013
- }
1014
- };
1015
- proxyRequest(url, res);
1016
- });
1017
- const cliPort = port;
1018
- await new Promise((resolve10) => server.listen(cliPort, () => resolve10()));
1019
- console.log(`
1020
- \u26A1 Flight dev server running
1021
- `);
1022
- console.log(` Bundler: FlightPack`);
1023
- console.log(` Local: http://localhost:${cliPort}`);
1024
- console.log(``);
1025
917
  const elapsed = Date.now() - startTime;
1026
918
  consola2.success(`Flight dev server ready in ${elapsed}ms`);
1027
919
  devServer.printUrls?.();