@farm.js/cli 0.1.0-beta.18 → 0.1.0-beta.20
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/index.js +71 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -450,10 +450,12 @@ const HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
|
|
|
450
450
|
function createPreviewGatewayPlan(target, options = {}) {
|
|
451
451
|
const requestedName = sanitizePreviewName$1(options.name || process.env.FARM_PREVIEW_NAME) || randomPreviewName$1();
|
|
452
452
|
const gatewayUrl = normalizeGatewayUrl(options.gatewayUrl || process.env.FARM_PREVIEW_GATEWAY_URL || DEFAULT_GATEWAY_URL);
|
|
453
|
+
const relayUrl = normalizeRelayUrl(process.env.FARM_PREVIEW_RELAY_URL || gatewayUrl);
|
|
453
454
|
const requestedHostname = `${requestedName}.${normalizePreviewDomain$1(process.env.FARM_PREVIEW_DOMAIN || DEFAULT_PREVIEW_DOMAIN)}`;
|
|
454
455
|
return {
|
|
455
456
|
provider: "farm-gateway",
|
|
456
457
|
gatewayUrl,
|
|
458
|
+
relayUrl,
|
|
457
459
|
target,
|
|
458
460
|
requestedName,
|
|
459
461
|
requestedHostname,
|
|
@@ -618,6 +620,7 @@ async function closeGatewaySession(plan, session) {
|
|
|
618
620
|
function formatGatewayPlan(plan) {
|
|
619
621
|
return [
|
|
620
622
|
`Gateway: ${plan.gatewayUrl}`,
|
|
623
|
+
`Relay: ${plan.relayUrl}`,
|
|
621
624
|
`Local: ${plan.target.localUrl}`,
|
|
622
625
|
`Public: ${plan.requestedPublicUrl}`
|
|
623
626
|
].join("\n");
|
|
@@ -629,6 +632,17 @@ function formatRequestPath(path) {
|
|
|
629
632
|
function normalizeGatewayUrl(value) {
|
|
630
633
|
return value.replace(/\/+$/, "");
|
|
631
634
|
}
|
|
635
|
+
function normalizeRelayUrl(value) {
|
|
636
|
+
const url = new URL(value);
|
|
637
|
+
if (url.protocol === "http:") url.protocol = "ws:";
|
|
638
|
+
if (url.protocol === "https:") url.protocol = "wss:";
|
|
639
|
+
if (url.protocol !== "ws:" && url.protocol !== "wss:") throw new Error(`Preview relay must use ws or wss, received ${url.protocol}`);
|
|
640
|
+
const pathname = url.pathname.replace(/\/+$/, "");
|
|
641
|
+
url.pathname = pathname.endsWith("/agent") ? pathname : `${pathname}/agent`;
|
|
642
|
+
url.search = "";
|
|
643
|
+
url.hash = "";
|
|
644
|
+
return url.toString();
|
|
645
|
+
}
|
|
632
646
|
function normalizePreviewDomain$1(value) {
|
|
633
647
|
return value.replace(/^https?:\/\//, "").replace(/^\.*/, "").replace(/\/*$/, "");
|
|
634
648
|
}
|
|
@@ -640,6 +654,39 @@ function randomPreviewName$1() {
|
|
|
640
654
|
return `farm-${Math.random().toString(36).slice(2, 8)}`;
|
|
641
655
|
}
|
|
642
656
|
//#endregion
|
|
657
|
+
//#region src/preview-native.ts
|
|
658
|
+
async function runNativePreviewTunnel(plan, options = {}) {
|
|
659
|
+
const runtime = options.runtime || await loadNativeTunnel();
|
|
660
|
+
const session = await runtime.startPreviewAgent(plan.relayUrl, plan.requestedName, plan.target.localUrl);
|
|
661
|
+
let stopping = false;
|
|
662
|
+
const stop = () => {
|
|
663
|
+
if (stopping) return;
|
|
664
|
+
stopping = true;
|
|
665
|
+
runtime.stopPreviewAgent(session.sessionId);
|
|
666
|
+
};
|
|
667
|
+
process.once("SIGINT", stop);
|
|
668
|
+
process.once("SIGTERM", stop);
|
|
669
|
+
logger.success("Preview URL ready.");
|
|
670
|
+
logger.info(`Public: ${session.publicUrl}`);
|
|
671
|
+
logger.info("Forwarding requests through the native tunnel until Ctrl+C.");
|
|
672
|
+
try {
|
|
673
|
+
if (!await runtime.waitPreviewAgent(session.sessionId)) throw new Error("The native preview tunnel stopped before its lifecycle could be observed.");
|
|
674
|
+
return session;
|
|
675
|
+
} finally {
|
|
676
|
+
process.removeListener("SIGINT", stop);
|
|
677
|
+
process.removeListener("SIGTERM", stop);
|
|
678
|
+
await runtime.stopPreviewAgent(session.sessionId).catch(() => false);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
async function loadNativeTunnel() {
|
|
682
|
+
try {
|
|
683
|
+
return await import("@farm.js/tunnel");
|
|
684
|
+
} catch (error) {
|
|
685
|
+
const reason = error instanceof Error ? ` ${error.message}` : "";
|
|
686
|
+
throw new Error(`Could not load @farm.js/tunnel for this platform. Reinstall @farm.js/cli so its native platform package is restored.${reason}`);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
//#endregion
|
|
643
690
|
//#region src/preview.ts
|
|
644
691
|
const DEFAULT_PREVIEW_PORTS = [
|
|
645
692
|
3e3,
|
|
@@ -663,15 +710,26 @@ async function previewFarm(options = {}) {
|
|
|
663
710
|
plan
|
|
664
711
|
};
|
|
665
712
|
}
|
|
666
|
-
logger.info(`
|
|
667
|
-
logger.info("Opening Farm preview
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
713
|
+
logger.info(`Relay: ${plan.relayUrl}`);
|
|
714
|
+
logger.info("Opening native Farm preview tunnel...");
|
|
715
|
+
try {
|
|
716
|
+
const session = await runNativePreviewTunnel(plan);
|
|
717
|
+
return {
|
|
718
|
+
target,
|
|
719
|
+
plan,
|
|
720
|
+
publicUrl: session.publicUrl,
|
|
721
|
+
session
|
|
722
|
+
};
|
|
723
|
+
} catch (error) {
|
|
724
|
+
logger.warn(`Native preview relay unavailable; using compatibility gateway polling.${formatPreviewError(error)}`);
|
|
725
|
+
const session = await runPreviewGateway(plan, { timeoutMs: options.timeoutMs });
|
|
726
|
+
return {
|
|
727
|
+
target,
|
|
728
|
+
plan,
|
|
729
|
+
publicUrl: session.publicUrl,
|
|
730
|
+
session
|
|
731
|
+
};
|
|
732
|
+
}
|
|
675
733
|
}
|
|
676
734
|
const plan = createPreviewTunnelPlan(target, options);
|
|
677
735
|
if (options.dryRun) {
|
|
@@ -689,6 +747,9 @@ async function previewFarm(options = {}) {
|
|
|
689
747
|
publicUrl: await runPreviewTunnel(plan, options.timeoutMs ?? 3e4)
|
|
690
748
|
};
|
|
691
749
|
}
|
|
750
|
+
function formatPreviewError(error) {
|
|
751
|
+
return error instanceof Error && error.message ? ` ${error.message}` : "";
|
|
752
|
+
}
|
|
692
753
|
function shouldUseManagedGateway(options) {
|
|
693
754
|
if (options.provider === "farm" || process.env.FARM_PREVIEW_PROVIDER === "farm") return true;
|
|
694
755
|
if (options.provider === "local" || process.env.FARM_PREVIEW_PROVIDER === "local") return false;
|
|
@@ -3205,6 +3266,6 @@ function formatError(error) {
|
|
|
3205
3266
|
return error instanceof Error ? error.message : String(error);
|
|
3206
3267
|
}
|
|
3207
3268
|
//#endregion
|
|
3208
|
-
export { FarmDeployError, FarmGeneratedArtifactsStaleError, addFarmIntegration, buildFarm, createFarmDeployPlan, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, explainFarmRoute, formatFarmCronJobs, formatFarmDeployPlan, formatFarmDoctorReport, formatFarmRouteExplanation, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, migrateFarmAuth, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runPreviewGateway, startDevServer, startFarmCronScheduler, upgradeFarm };
|
|
3269
|
+
export { FarmDeployError, FarmGeneratedArtifactsStaleError, addFarmIntegration, buildFarm, createFarmDeployPlan, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, explainFarmRoute, formatFarmCronJobs, formatFarmDeployPlan, formatFarmDoctorReport, formatFarmRouteExplanation, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, migrateFarmAuth, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runNativePreviewTunnel, runPreviewGateway, startDevServer, startFarmCronScheduler, upgradeFarm };
|
|
3209
3270
|
|
|
3210
3271
|
//# sourceMappingURL=index.mjs.map
|