@farm.js/cli 0.1.0-beta.57 → 0.1.0-beta.59

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/bin/farm.js CHANGED
@@ -54,19 +54,14 @@ function telemetryDeployTarget(commandPath, options) {
54
54
  return undefined;
55
55
  }
56
56
 
57
- program.hook("preAction", async (_command, actionCommand) => {
57
+ program.hook("preAction", (_command, actionCommand) => {
58
58
  const commandPath = telemetryCommandPath(actionCommand);
59
59
  if (commandPath.startsWith("telemetry")) return;
60
- const {
61
- resolveFarmTelemetryCommand,
62
- showFarmTelemetryNotice,
63
- trackFarmCommand,
64
- } = require("../dist/telemetry.js");
65
- await showFarmTelemetryNotice();
60
+ const { resolveFarmTelemetryCommand, trackFarmCommand } = require("../dist/telemetry.js");
66
61
  const command = resolveFarmTelemetryCommand(commandPath);
67
62
  if (!command) return;
68
63
  const options = actionCommand.opts();
69
- await trackFarmCommand({
64
+ void trackFarmCommand({
70
65
  command,
71
66
  packageVersion: version,
72
67
  deployTarget: telemetryDeployTarget(commandPath, options),
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.js");
3
3
  const require_add_integration = require("./add-integration-Bz7WjUfh.js");
4
4
  const require_build = require("./build.js");
5
- const require_telemetry = require("./telemetry.js");
5
+ const require_telemetry = require("./telemetry-9Y6041mK.js");
6
6
  let _farm_js_core_server = require("@farm.js/core/server");
7
7
  let node_fs = require("node:fs");
8
8
  let node_fs_promises = require("node:fs/promises");
@@ -431,8 +431,9 @@ async function deployNetlify(root, outputDir, site) {
431
431
  function formatCommand$1(executable, args) {
432
432
  return [executable, ...args].map(formatCommandArgument).join(" ");
433
433
  }
434
+ const SAFE_ARGUMENT = process.platform === "win32" ? /^[A-Za-z0-9_.\\/:=@+-]+$/ : /^[A-Za-z0-9_./:=@+-]+$/;
434
435
  function formatCommandArgument(argument) {
435
- if (/^[A-Za-z0-9_./:=@+-]+$/.test(argument)) return argument;
436
+ if (SAFE_ARGUMENT.test(argument)) return argument;
436
437
  return `'${argument.replace(/'/g, `'"'"'`)}'`;
437
438
  }
438
439
  function getErrorMessage(error) {
@@ -645,6 +646,9 @@ async function createGatewaySession(plan, timeoutMs) {
645
646
  if (!session.id || !session.token || !session.publicUrl) throw new Error("Preview gateway returned an invalid session.");
646
647
  return session;
647
648
  }
649
+ function getSetCookies(headers) {
650
+ return headers.getSetCookie?.call(headers) || [];
651
+ }
648
652
  async function forwardGatewayRequest(target, request) {
649
653
  const headers = new Headers();
650
654
  for (const [key, value] of Object.entries(request.headers || {})) {
@@ -663,8 +667,10 @@ async function forwardGatewayRequest(target, request) {
663
667
  const responseHeaders = {};
664
668
  response.headers.forEach((value, key) => {
665
669
  const normalized = key.toLowerCase();
666
- if (!HOP_BY_HOP_HEADERS.has(normalized)) responseHeaders[key] = value;
670
+ if (!HOP_BY_HOP_HEADERS.has(normalized) && normalized !== "set-cookie") responseHeaders[key] = value;
667
671
  });
672
+ const setCookies = getSetCookies(response.headers);
673
+ if (setCookies.length > 0) responseHeaders["set-cookie"] = setCookies;
668
674
  return {
669
675
  status: response.status,
670
676
  headers: responseHeaders,
@@ -1378,18 +1384,18 @@ function renderPrismaModel(model) {
1378
1384
  const defaultAttribute = getPrismaDefaultAttribute(field);
1379
1385
  if (defaultAttribute) attributes.push(defaultAttribute);
1380
1386
  if (field.meta?.autoUpdate && field.type === "datetime") attributes.push("@updatedAt");
1381
- if (field.name !== fieldKey) attributes.push(`@map("${escapeString(field.name)}")`);
1387
+ if (field.name !== fieldKey) attributes.push(`@map("${escapeDoubleQuoted(field.name)}")`);
1382
1388
  if (attributes.length) parts.push(attributes.join(" "));
1383
1389
  lines.push(` ${parts.join(" ")}`);
1384
- if (field.index) modelLevelConstraints.push(`@@index([${fieldKey}], map: "${escapeString(`${model.modelName}_${field.name}_idx`)}")`);
1390
+ if (field.index) modelLevelConstraints.push(`@@index([${fieldKey}], map: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}")`);
1385
1391
  }
1386
1392
  for (const constraint of model.model.constraints || []) {
1387
1393
  const fields = constraint.fields.join(", ");
1388
1394
  const attribute = constraint.type === "unique" ? "@@unique" : "@@index";
1389
- const suffix = constraint.name ? `, map: "${escapeString(constraint.name)}"` : "";
1395
+ const suffix = constraint.name ? `, map: "${escapeDoubleQuoted(constraint.name)}"` : "";
1390
1396
  modelLevelConstraints.push(`${attribute}([${fields}]${suffix})`);
1391
1397
  }
1392
- lines.push(` @@map("${escapeString(model.modelName)}")`);
1398
+ lines.push(` @@map("${escapeDoubleQuoted(model.modelName)}")`);
1393
1399
  for (const constraint of modelLevelConstraints) lines.push(` ${constraint}`);
1394
1400
  lines.push("}");
1395
1401
  return lines.join("\n");
@@ -1407,7 +1413,7 @@ function getPrismaFieldType(field) {
1407
1413
  function getPrismaDefaultAttribute(field) {
1408
1414
  if (field.default === void 0) return null;
1409
1415
  if (field.type === "datetime" && field.default === "now") return "@default(now())";
1410
- if (typeof field.default === "string") return `@default("${escapeString(field.default)}")`;
1416
+ if (typeof field.default === "string") return `@default("${escapeDoubleQuoted(field.default)}")`;
1411
1417
  if (typeof field.default === "number" || typeof field.default === "boolean") return `@default(${String(field.default)})`;
1412
1418
  return null;
1413
1419
  }
@@ -1445,12 +1451,12 @@ function renderDrizzleModel(model, dialect, tableFactoryName) {
1445
1451
  lines.push(` ${fieldKey}: ${renderDrizzleColumn(field, dialect)},`);
1446
1452
  }
1447
1453
  lines.push("}, (table) => ({");
1448
- for (const [fieldKey, field] of Object.entries(model.model.fields)) if (field.index) lines.push(` ${fieldKey}Idx: index("${escapeString(`${model.modelName}_${field.name}_idx`)}").on(table.${fieldKey}),`);
1454
+ for (const [fieldKey, field] of Object.entries(model.model.fields)) if (field.index) lines.push(` ${fieldKey}Idx: index("${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}").on(table.${fieldKey}),`);
1449
1455
  for (const constraint of model.model.constraints || []) {
1450
1456
  const builder = constraint.type === "unique" ? "uniqueIndex" : "index";
1451
1457
  const accessor = constraint.fields.map((fieldKey) => `table.${fieldKey}`).join(", ");
1452
1458
  const name = constraint.name || `${model.modelName}_${constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name || fieldKey).join("_")}_${constraint.type}`;
1453
- lines.push(` ${toCamelCase(name)}: ${builder}("${escapeString(name)}").on(${accessor}),`);
1459
+ lines.push(` ${toCamelCase(name)}: ${builder}("${escapeDoubleQuoted(name)}").on(${accessor}),`);
1454
1460
  }
1455
1461
  lines.push("}));");
1456
1462
  return lines.join("\n");
@@ -1528,7 +1534,7 @@ function renderSqliteDrizzleColumn(field) {
1528
1534
  function getDrizzleDefaultExpression(field, dialect) {
1529
1535
  if (field.default === void 0) return "";
1530
1536
  if (field.type === "datetime" && field.default === "now") return dialect === "sqlite" ? "" : ".defaultNow()";
1531
- if (typeof field.default === "string") return `.default("${escapeString(field.default)}")`;
1537
+ if (typeof field.default === "string") return `.default("${escapeDoubleQuoted(field.default)}")`;
1532
1538
  if (typeof field.default === "number" || typeof field.default === "boolean") return `.default(${String(field.default)})`;
1533
1539
  return "";
1534
1540
  }
@@ -1619,7 +1625,7 @@ function getSqlColumnType(field, dialect) {
1619
1625
  function getSqlDefaultExpression(field, dialect) {
1620
1626
  if (field.default === void 0) return null;
1621
1627
  if (field.type === "datetime" && field.default === "now") return "CURRENT_TIMESTAMP";
1622
- if (typeof field.default === "string") return `'${escapeString(field.default)}'`;
1628
+ if (typeof field.default === "string") return `'${escapeSqlString(field.default)}'`;
1623
1629
  if (typeof field.default === "number") return String(field.default);
1624
1630
  if (typeof field.default === "boolean") {
1625
1631
  if (dialect === "sqlite") return field.default ? "1" : "0";
@@ -1636,20 +1642,20 @@ function generateMongoBootstrap(models) {
1636
1642
  ];
1637
1643
  for (const model of models) {
1638
1644
  lines.push(` // Integration "${model.integrationKey}" model "${model.modelKey}"`);
1639
- lines.push(` const ${model.exportName} = db.collection("${escapeString(model.modelName)}");`);
1645
+ lines.push(` const ${model.exportName} = db.collection("${escapeDoubleQuoted(model.modelName)}");`);
1640
1646
  for (const [fieldKey, field] of Object.entries(model.model.fields)) {
1641
1647
  if (field.unique) {
1642
1648
  const options = ["unique: true"];
1643
1649
  if (isNullableField(field)) options.push("sparse: true");
1644
- options.push(`name: "${escapeString(`${model.modelName}_${field.name}_unique`)}"`);
1650
+ options.push(`name: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_unique`)}"`);
1645
1651
  lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { ${options.join(", ")} });`);
1646
- } else if (field.index) lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { name: "${escapeString(`${model.modelName}_${field.name}_idx`)}" });`);
1652
+ } else if (field.index) lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { name: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}" });`);
1647
1653
  if (field.reference) lines.push(` // ${fieldKey} references ${field.reference.model}.${field.reference.field}${field.reference.onDelete ? ` (onDelete: ${field.reference.onDelete})` : ""}`);
1648
1654
  }
1649
1655
  for (const constraint of model.model.constraints || []) {
1650
1656
  const indexSpec = constraint.fields.map((fieldKey) => `${JSON.stringify(model.model.fields[fieldKey]?.name || fieldKey)}: 1`).join(", ");
1651
1657
  const indexName = constraint.name || `${model.modelName}_${constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name || fieldKey).join("_")}_${constraint.type}`;
1652
- const options = constraint.type === "unique" ? `{ unique: true, name: "${escapeString(indexName)}" }` : `{ name: "${escapeString(indexName)}" }`;
1658
+ const options = constraint.type === "unique" ? `{ unique: true, name: "${escapeDoubleQuoted(indexName)}" }` : `{ name: "${escapeDoubleQuoted(indexName)}" }`;
1653
1659
  lines.push(` await ${model.exportName}.createIndex({ ${indexSpec} }, ${options});`);
1654
1660
  }
1655
1661
  lines.push("");
@@ -1681,8 +1687,11 @@ function toCamelCase(value) {
1681
1687
  const pascal = toPascalCase(value);
1682
1688
  return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : pascal;
1683
1689
  }
1684
- function escapeString(value) {
1685
- return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "''");
1690
+ function escapeDoubleQuoted(value) {
1691
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
1692
+ }
1693
+ function escapeSqlString(value) {
1694
+ return value.replace(/'/g, "''");
1686
1695
  }
1687
1696
  function escapeRegExp$1(value) {
1688
1697
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1792,6 +1801,10 @@ async function fetchLiveSnapshot(baseUrl, options) {
1792
1801
  clearTimeout(timeout);
1793
1802
  }
1794
1803
  }
1804
+ /** Reported paths are shown to the user, so keep them POSIX on every platform. */
1805
+ function toPosix$1(value) {
1806
+ return value.split(node_path.default.sep).join("/");
1807
+ }
1795
1808
  function createLiveReport(snapshot, baseUrl, now) {
1796
1809
  const checks = [
1797
1810
  {
@@ -1875,7 +1888,7 @@ async function createProjectReport(root, options) {
1875
1888
  status: "pass",
1876
1889
  code: "CONFIG_VALID",
1877
1890
  title: "Farm config loads successfully",
1878
- message: configFile ? node_path.default.relative(root, configFile) || node_path.default.basename(configFile) : "Resolved config"
1891
+ message: configFile ? toPosix$1(node_path.default.relative(root, configFile)) || node_path.default.basename(configFile) : "Resolved config"
1879
1892
  });
1880
1893
  }
1881
1894
  } catch (error) {
@@ -1921,7 +1934,7 @@ function applySafeProjectFixes(root, config, checks) {
1921
1934
  fixes.push({
1922
1935
  code: "ROOT_LAYOUT_CREATED",
1923
1936
  title: "Created the missing root layout",
1924
- filePath: node_path.default.relative(root, layoutPath)
1937
+ filePath: toPosix$1(node_path.default.relative(root, layoutPath))
1925
1938
  });
1926
1939
  }
1927
1940
  }
@@ -3374,7 +3387,10 @@ Object.defineProperty(exports, "createServer", {
3374
3387
  });
3375
3388
  exports.deployFarm = deployFarm;
3376
3389
  exports.detectFarmPackageManager = detectFarmPackageManager;
3390
+ exports.escapeDoubleQuoted = escapeDoubleQuoted;
3391
+ exports.escapeSqlString = escapeSqlString;
3377
3392
  exports.explainFarmRoute = explainFarmRoute;
3393
+ exports.flushFarmTelemetry = require_telemetry.flushFarmTelemetry;
3378
3394
  exports.formatFarmCronJobs = formatFarmCronJobs;
3379
3395
  exports.formatFarmDeployPlan = formatFarmDeployPlan;
3380
3396
  exports.formatFarmDoctorReport = formatFarmDoctorReport;