@farm.js/cli 0.1.0-beta.3 → 0.1.0-beta.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/README.md +12 -0
- package/bin/farm.js +36 -3
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/index.js +191 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1428,7 +1428,7 @@ async function runFarmDoctor(options = {}) {
|
|
|
1428
1428
|
if (!options.offline) try {
|
|
1429
1429
|
return createLiveReport(await fetchLiveSnapshot(liveTarget, options), liveTarget, options.now);
|
|
1430
1430
|
} catch (error) {
|
|
1431
|
-
liveError = formatError$
|
|
1431
|
+
liveError = formatError$2(error);
|
|
1432
1432
|
}
|
|
1433
1433
|
const report = await createProjectReport(root, options);
|
|
1434
1434
|
if (!options.offline && hasExplicitLiveTarget(options) && liveError) {
|
|
@@ -1588,7 +1588,7 @@ async function createProjectReport(root, options) {
|
|
|
1588
1588
|
status: "fail",
|
|
1589
1589
|
code: "CONFIG_INVALID",
|
|
1590
1590
|
title: "Farm config could not be resolved",
|
|
1591
|
-
message: formatError$
|
|
1591
|
+
message: formatError$2(error),
|
|
1592
1592
|
action: "Fix the config or environment validation error, then run farm doctor again."
|
|
1593
1593
|
});
|
|
1594
1594
|
}
|
|
@@ -1651,7 +1651,7 @@ function collectPackageCheck(root, checks) {
|
|
|
1651
1651
|
status: "fail",
|
|
1652
1652
|
code: "PACKAGE_INVALID",
|
|
1653
1653
|
title: "package.json is invalid",
|
|
1654
|
-
message: formatError$
|
|
1654
|
+
message: formatError$2(error),
|
|
1655
1655
|
action: "Fix the package manifest JSON."
|
|
1656
1656
|
});
|
|
1657
1657
|
}
|
|
@@ -1804,7 +1804,7 @@ function finalizeReport(report) {
|
|
|
1804
1804
|
function asRecord(value) {
|
|
1805
1805
|
return value && typeof value === "object" ? value : {};
|
|
1806
1806
|
}
|
|
1807
|
-
function formatError$
|
|
1807
|
+
function formatError$2(error) {
|
|
1808
1808
|
return error instanceof Error ? error.message : String(error);
|
|
1809
1809
|
}
|
|
1810
1810
|
function formatCount$1(value, noun) {
|
|
@@ -1861,7 +1861,7 @@ async function startFarmCronScheduler(options = {}) {
|
|
|
1861
1861
|
logger.warn(`Cron ${job.name} skipped an overlapping run.`);
|
|
1862
1862
|
},
|
|
1863
1863
|
catch: (error) => {
|
|
1864
|
-
logger.error(`Cron ${job.name} failed: ${formatError(error)}`);
|
|
1864
|
+
logger.error(`Cron ${job.name} failed: ${formatError$1(error)}`);
|
|
1865
1865
|
}
|
|
1866
1866
|
}, async () => {
|
|
1867
1867
|
logger.info(`Cron ${job.name} -> ${job.path}`);
|
|
@@ -1950,7 +1950,7 @@ function formatResponseDetail(body) {
|
|
|
1950
1950
|
const detail = typeof body === "string" ? body : JSON.stringify(body);
|
|
1951
1951
|
return detail ? `: ${detail}` : "";
|
|
1952
1952
|
}
|
|
1953
|
-
function formatError(error) {
|
|
1953
|
+
function formatError$1(error) {
|
|
1954
1954
|
return error instanceof Error ? error.message : String(error);
|
|
1955
1955
|
}
|
|
1956
1956
|
//#endregion
|
|
@@ -2067,7 +2067,7 @@ async function createFrameworkMigrationPlan(root, source, options = {}) {
|
|
|
2067
2067
|
};
|
|
2068
2068
|
if (source === "next") await planNextMigration(root, packageJson, plan, options);
|
|
2069
2069
|
else await planTanStackMigration(root, packageJson, plan, options);
|
|
2070
|
-
addSharedFarmFiles(root, packageJson, plan,
|
|
2070
|
+
addSharedFarmFiles(root, packageJson, plan, options);
|
|
2071
2071
|
return plan;
|
|
2072
2072
|
}
|
|
2073
2073
|
async function planNextMigration(root, packageJson, plan, options) {
|
|
@@ -2147,32 +2147,22 @@ async function planTanStackMigration(root, packageJson, plan, options) {
|
|
|
2147
2147
|
plan.manual.push("Review loaders, beforeLoad hooks, search params, and Route.use* calls; Farm page modules should move that logic into props, API routes, or server helpers.");
|
|
2148
2148
|
if (packageJson) addPackageOperation(root, plan, createMigratedPackageJson(packageJson, "tanstack"));
|
|
2149
2149
|
}
|
|
2150
|
-
function addSharedFarmFiles(root, packageJson, plan,
|
|
2150
|
+
function addSharedFarmFiles(root, packageJson, plan, options) {
|
|
2151
2151
|
if (![
|
|
2152
2152
|
"farm.config.ts",
|
|
2153
2153
|
"farm.config.mts",
|
|
2154
2154
|
"farm.config.js",
|
|
2155
2155
|
"farm.config.mjs"
|
|
2156
|
-
].map((file) => path.join(root, file)).find((file) => existsSync(file))) {
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
});
|
|
2162
|
-
` : `import { defineConfig } from "@farm.js/core";
|
|
2156
|
+
].map((file) => path.join(root, file)).find((file) => existsSync(file))) plan.operations.push({
|
|
2157
|
+
kind: "write-file",
|
|
2158
|
+
path: path.join(root, "farm.config.ts"),
|
|
2159
|
+
description: "Create farm.config.ts",
|
|
2160
|
+
content: `import { defineConfig } from "@farm.js/core";
|
|
2163
2161
|
|
|
2164
|
-
export default defineConfig({
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
plan.operations.push({
|
|
2169
|
-
kind: "write-file",
|
|
2170
|
-
path: path.join(root, "farm.config.ts"),
|
|
2171
|
-
description: "Create farm.config.ts",
|
|
2172
|
-
content: output,
|
|
2173
|
-
skipped: false
|
|
2174
|
-
});
|
|
2175
|
-
}
|
|
2162
|
+
export default defineConfig({});
|
|
2163
|
+
`,
|
|
2164
|
+
skipped: false
|
|
2165
|
+
});
|
|
2176
2166
|
const layoutPath = path.join(root, "src", "app", "layout.tsx");
|
|
2177
2167
|
if (!existsSync(layoutPath)) plan.operations.push({
|
|
2178
2168
|
kind: "write-file",
|
|
@@ -2430,6 +2420,176 @@ function toPosix(value) {
|
|
|
2430
2420
|
return value.split(path.sep).join("/");
|
|
2431
2421
|
}
|
|
2432
2422
|
//#endregion
|
|
2433
|
-
|
|
2423
|
+
//#region src/upgrade.ts
|
|
2424
|
+
const DEPENDENCY_SECTIONS = [
|
|
2425
|
+
"dependencies",
|
|
2426
|
+
"devDependencies",
|
|
2427
|
+
"optionalDependencies",
|
|
2428
|
+
"peerDependencies"
|
|
2429
|
+
];
|
|
2430
|
+
const LOCAL_SPECIFIER_PREFIXES = [
|
|
2431
|
+
"workspace:",
|
|
2432
|
+
"file:",
|
|
2433
|
+
"link:",
|
|
2434
|
+
"portal:",
|
|
2435
|
+
"catalog:"
|
|
2436
|
+
];
|
|
2437
|
+
async function createFarmUpgradePlan(options) {
|
|
2438
|
+
assertUpgradeChannel(options.channel);
|
|
2439
|
+
const root = path.resolve(options.root || process.cwd());
|
|
2440
|
+
const packageJsonPath = path.join(root, "package.json");
|
|
2441
|
+
let packageJson;
|
|
2442
|
+
try {
|
|
2443
|
+
packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
|
|
2444
|
+
} catch (error) {
|
|
2445
|
+
if (!existsSync(packageJsonPath)) throw new Error(`No package.json found at ${packageJsonPath}.`);
|
|
2446
|
+
throw new Error(`Could not read ${packageJsonPath}: ${formatError(error)}`);
|
|
2447
|
+
}
|
|
2448
|
+
const packageManager = options.packageManager || detectFarmPackageManager(root, packageJson.packageManager);
|
|
2449
|
+
const packages = [];
|
|
2450
|
+
const skipped = [];
|
|
2451
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2452
|
+
for (const section of DEPENDENCY_SECTIONS) {
|
|
2453
|
+
const dependencies = packageJson[section];
|
|
2454
|
+
if (!dependencies || typeof dependencies !== "object") continue;
|
|
2455
|
+
for (const [name, rawSpecifier] of Object.entries(dependencies)) {
|
|
2456
|
+
if (!name.startsWith("@farm.js/") || seen.has(name)) continue;
|
|
2457
|
+
seen.add(name);
|
|
2458
|
+
const current = typeof rawSpecifier === "string" ? rawSpecifier : String(rawSpecifier);
|
|
2459
|
+
if (isLocalSpecifier(current)) {
|
|
2460
|
+
skipped.push({
|
|
2461
|
+
name,
|
|
2462
|
+
current,
|
|
2463
|
+
section,
|
|
2464
|
+
reason: "local workspace and file dependencies are not published-package upgrades"
|
|
2465
|
+
});
|
|
2466
|
+
continue;
|
|
2467
|
+
}
|
|
2468
|
+
packages.push({
|
|
2469
|
+
name,
|
|
2470
|
+
current,
|
|
2471
|
+
section,
|
|
2472
|
+
target: `${name}@${options.channel}`
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
if (packages.length === 0) {
|
|
2477
|
+
const suffix = skipped.length > 0 ? " The Farm packages in this project use local workspace or file references." : "";
|
|
2478
|
+
throw new Error(`No published @farm.js/* dependencies were found in ${packageJsonPath}.${suffix}`);
|
|
2479
|
+
}
|
|
2480
|
+
packages.sort((left, right) => left.name.localeCompare(right.name));
|
|
2481
|
+
skipped.sort((left, right) => left.name.localeCompare(right.name));
|
|
2482
|
+
return {
|
|
2483
|
+
root,
|
|
2484
|
+
packageJsonPath,
|
|
2485
|
+
packageManager,
|
|
2486
|
+
channel: options.channel,
|
|
2487
|
+
packages,
|
|
2488
|
+
skipped,
|
|
2489
|
+
commands: createUpgradeCommands(root, packageManager, packages)
|
|
2490
|
+
};
|
|
2491
|
+
}
|
|
2492
|
+
async function upgradeFarm(options) {
|
|
2493
|
+
const plan = await createFarmUpgradePlan(options);
|
|
2494
|
+
if (options.dryRun) return {
|
|
2495
|
+
plan,
|
|
2496
|
+
executed: false
|
|
2497
|
+
};
|
|
2498
|
+
const runCommand = options.runCommand || runFarmUpgradeCommand;
|
|
2499
|
+
for (const command of plan.commands) await runCommand(command);
|
|
2500
|
+
return {
|
|
2501
|
+
plan,
|
|
2502
|
+
executed: true
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
function formatFarmUpgradePlan(plan) {
|
|
2506
|
+
const lines = [
|
|
2507
|
+
`Farm upgrade: ${plan.channel === "latest" ? "latest stable" : "latest beta"}`,
|
|
2508
|
+
`Project: ${plan.root}`,
|
|
2509
|
+
`Package manager: ${plan.packageManager}`,
|
|
2510
|
+
"Packages:"
|
|
2511
|
+
];
|
|
2512
|
+
for (const entry of plan.packages) lines.push(` ${entry.name} (${entry.section}): ${entry.current} -> ${plan.channel}`);
|
|
2513
|
+
if (plan.skipped.length > 0) {
|
|
2514
|
+
lines.push("Skipped local packages:");
|
|
2515
|
+
for (const entry of plan.skipped) lines.push(` ${entry.name} (${entry.current})`);
|
|
2516
|
+
}
|
|
2517
|
+
lines.push("Commands:");
|
|
2518
|
+
for (const command of plan.commands) lines.push(` ${command.command} ${command.args.join(" ")}`);
|
|
2519
|
+
return lines.join("\n");
|
|
2520
|
+
}
|
|
2521
|
+
function detectFarmPackageManager(root, packageManagerField) {
|
|
2522
|
+
if (typeof packageManagerField === "string") {
|
|
2523
|
+
const name = packageManagerField.split("@", 1)[0];
|
|
2524
|
+
if (isFarmPackageManager(name)) return name;
|
|
2525
|
+
}
|
|
2526
|
+
for (const [packageManager, lockfiles] of [
|
|
2527
|
+
["pnpm", ["pnpm-lock.yaml"]],
|
|
2528
|
+
["yarn", ["yarn.lock"]],
|
|
2529
|
+
["bun", ["bun.lock", "bun.lockb"]],
|
|
2530
|
+
["npm", ["package-lock.json", "npm-shrinkwrap.json"]]
|
|
2531
|
+
]) if (lockfiles.some((lockfile) => existsSync(path.join(root, lockfile)))) return packageManager;
|
|
2532
|
+
return "npm";
|
|
2533
|
+
}
|
|
2534
|
+
function createUpgradeCommands(root, packageManager, packages) {
|
|
2535
|
+
const command = packageManager === "npm" ? "install" : "add";
|
|
2536
|
+
return DEPENDENCY_SECTIONS.flatMap((section) => {
|
|
2537
|
+
const targets = packages.filter((entry) => entry.section === section).map((entry) => entry.target);
|
|
2538
|
+
if (targets.length === 0) return [];
|
|
2539
|
+
return [{
|
|
2540
|
+
command: packageManager,
|
|
2541
|
+
args: [
|
|
2542
|
+
command,
|
|
2543
|
+
...getDependencySectionFlags(packageManager, section),
|
|
2544
|
+
...targets
|
|
2545
|
+
],
|
|
2546
|
+
cwd: root
|
|
2547
|
+
}];
|
|
2548
|
+
});
|
|
2549
|
+
}
|
|
2550
|
+
function getDependencySectionFlags(packageManager, section) {
|
|
2551
|
+
if (section === "dependencies") return [];
|
|
2552
|
+
if (packageManager === "yarn" || packageManager === "bun") {
|
|
2553
|
+
if (section === "devDependencies") return ["--dev"];
|
|
2554
|
+
if (section === "optionalDependencies") return ["--optional"];
|
|
2555
|
+
return ["--peer"];
|
|
2556
|
+
}
|
|
2557
|
+
if (section === "devDependencies") return ["--save-dev"];
|
|
2558
|
+
if (section === "optionalDependencies") return ["--save-optional"];
|
|
2559
|
+
return ["--save-peer"];
|
|
2560
|
+
}
|
|
2561
|
+
function runFarmUpgradeCommand(command) {
|
|
2562
|
+
return new Promise((resolve, reject) => {
|
|
2563
|
+
const executable = process.platform === "win32" ? `${command.command}.cmd` : command.command;
|
|
2564
|
+
const child = spawn(executable, command.args, {
|
|
2565
|
+
cwd: command.cwd,
|
|
2566
|
+
env: process.env,
|
|
2567
|
+
stdio: "inherit"
|
|
2568
|
+
});
|
|
2569
|
+
child.on("error", reject);
|
|
2570
|
+
child.on("close", (code, signal) => {
|
|
2571
|
+
if (code === 0) {
|
|
2572
|
+
resolve();
|
|
2573
|
+
return;
|
|
2574
|
+
}
|
|
2575
|
+
const termination = signal ? `signal ${signal}` : `exit code ${code ?? "unknown"}`;
|
|
2576
|
+
reject(/* @__PURE__ */ new Error(`${command.command} ${command.args.join(" ")} failed with ${termination}.`));
|
|
2577
|
+
});
|
|
2578
|
+
});
|
|
2579
|
+
}
|
|
2580
|
+
function isLocalSpecifier(specifier) {
|
|
2581
|
+
return LOCAL_SPECIFIER_PREFIXES.some((prefix) => specifier.startsWith(prefix));
|
|
2582
|
+
}
|
|
2583
|
+
function isFarmPackageManager(value) {
|
|
2584
|
+
return value === "npm" || value === "pnpm" || value === "yarn" || value === "bun";
|
|
2585
|
+
}
|
|
2586
|
+
function assertUpgradeChannel(channel) {
|
|
2587
|
+
if (channel !== "latest" && channel !== "beta") throw new Error("Farm upgrade channel must be \"latest\" or \"beta\".");
|
|
2588
|
+
}
|
|
2589
|
+
function formatError(error) {
|
|
2590
|
+
return error instanceof Error ? error.message : String(error);
|
|
2591
|
+
}
|
|
2592
|
+
//#endregion
|
|
2593
|
+
export { addFarmIntegration, buildFarm, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, formatFarmCronJobs, formatFarmDoctorReport, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runPreviewGateway, startDevServer, startFarmCronScheduler, upgradeFarm };
|
|
2434
2594
|
|
|
2435
2595
|
//# sourceMappingURL=index.mjs.map
|