@farm.js/cli 0.1.0-beta.56 → 0.1.0-beta.58

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 CHANGED
@@ -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) {
@@ -1378,18 +1379,18 @@ function renderPrismaModel(model) {
1378
1379
  const defaultAttribute = getPrismaDefaultAttribute(field);
1379
1380
  if (defaultAttribute) attributes.push(defaultAttribute);
1380
1381
  if (field.meta?.autoUpdate && field.type === "datetime") attributes.push("@updatedAt");
1381
- if (field.name !== fieldKey) attributes.push(`@map("${escapeString(field.name)}")`);
1382
+ if (field.name !== fieldKey) attributes.push(`@map("${escapeDoubleQuoted(field.name)}")`);
1382
1383
  if (attributes.length) parts.push(attributes.join(" "));
1383
1384
  lines.push(` ${parts.join(" ")}`);
1384
- if (field.index) modelLevelConstraints.push(`@@index([${fieldKey}], map: "${escapeString(`${model.modelName}_${field.name}_idx`)}")`);
1385
+ if (field.index) modelLevelConstraints.push(`@@index([${fieldKey}], map: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}")`);
1385
1386
  }
1386
1387
  for (const constraint of model.model.constraints || []) {
1387
1388
  const fields = constraint.fields.join(", ");
1388
1389
  const attribute = constraint.type === "unique" ? "@@unique" : "@@index";
1389
- const suffix = constraint.name ? `, map: "${escapeString(constraint.name)}"` : "";
1390
+ const suffix = constraint.name ? `, map: "${escapeDoubleQuoted(constraint.name)}"` : "";
1390
1391
  modelLevelConstraints.push(`${attribute}([${fields}]${suffix})`);
1391
1392
  }
1392
- lines.push(` @@map("${escapeString(model.modelName)}")`);
1393
+ lines.push(` @@map("${escapeDoubleQuoted(model.modelName)}")`);
1393
1394
  for (const constraint of modelLevelConstraints) lines.push(` ${constraint}`);
1394
1395
  lines.push("}");
1395
1396
  return lines.join("\n");
@@ -1407,7 +1408,7 @@ function getPrismaFieldType(field) {
1407
1408
  function getPrismaDefaultAttribute(field) {
1408
1409
  if (field.default === void 0) return null;
1409
1410
  if (field.type === "datetime" && field.default === "now") return "@default(now())";
1410
- if (typeof field.default === "string") return `@default("${escapeString(field.default)}")`;
1411
+ if (typeof field.default === "string") return `@default("${escapeDoubleQuoted(field.default)}")`;
1411
1412
  if (typeof field.default === "number" || typeof field.default === "boolean") return `@default(${String(field.default)})`;
1412
1413
  return null;
1413
1414
  }
@@ -1445,12 +1446,12 @@ function renderDrizzleModel(model, dialect, tableFactoryName) {
1445
1446
  lines.push(` ${fieldKey}: ${renderDrizzleColumn(field, dialect)},`);
1446
1447
  }
1447
1448
  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}),`);
1449
+ 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
1450
  for (const constraint of model.model.constraints || []) {
1450
1451
  const builder = constraint.type === "unique" ? "uniqueIndex" : "index";
1451
1452
  const accessor = constraint.fields.map((fieldKey) => `table.${fieldKey}`).join(", ");
1452
1453
  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}),`);
1454
+ lines.push(` ${toCamelCase(name)}: ${builder}("${escapeDoubleQuoted(name)}").on(${accessor}),`);
1454
1455
  }
1455
1456
  lines.push("}));");
1456
1457
  return lines.join("\n");
@@ -1528,7 +1529,7 @@ function renderSqliteDrizzleColumn(field) {
1528
1529
  function getDrizzleDefaultExpression(field, dialect) {
1529
1530
  if (field.default === void 0) return "";
1530
1531
  if (field.type === "datetime" && field.default === "now") return dialect === "sqlite" ? "" : ".defaultNow()";
1531
- if (typeof field.default === "string") return `.default("${escapeString(field.default)}")`;
1532
+ if (typeof field.default === "string") return `.default("${escapeDoubleQuoted(field.default)}")`;
1532
1533
  if (typeof field.default === "number" || typeof field.default === "boolean") return `.default(${String(field.default)})`;
1533
1534
  return "";
1534
1535
  }
@@ -1619,7 +1620,7 @@ function getSqlColumnType(field, dialect) {
1619
1620
  function getSqlDefaultExpression(field, dialect) {
1620
1621
  if (field.default === void 0) return null;
1621
1622
  if (field.type === "datetime" && field.default === "now") return "CURRENT_TIMESTAMP";
1622
- if (typeof field.default === "string") return `'${escapeString(field.default)}'`;
1623
+ if (typeof field.default === "string") return `'${escapeSqlString(field.default)}'`;
1623
1624
  if (typeof field.default === "number") return String(field.default);
1624
1625
  if (typeof field.default === "boolean") {
1625
1626
  if (dialect === "sqlite") return field.default ? "1" : "0";
@@ -1636,20 +1637,20 @@ function generateMongoBootstrap(models) {
1636
1637
  ];
1637
1638
  for (const model of models) {
1638
1639
  lines.push(` // Integration "${model.integrationKey}" model "${model.modelKey}"`);
1639
- lines.push(` const ${model.exportName} = db.collection("${escapeString(model.modelName)}");`);
1640
+ lines.push(` const ${model.exportName} = db.collection("${escapeDoubleQuoted(model.modelName)}");`);
1640
1641
  for (const [fieldKey, field] of Object.entries(model.model.fields)) {
1641
1642
  if (field.unique) {
1642
1643
  const options = ["unique: true"];
1643
1644
  if (isNullableField(field)) options.push("sparse: true");
1644
- options.push(`name: "${escapeString(`${model.modelName}_${field.name}_unique`)}"`);
1645
+ options.push(`name: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_unique`)}"`);
1645
1646
  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`)}" });`);
1647
+ } else if (field.index) lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { name: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}" });`);
1647
1648
  if (field.reference) lines.push(` // ${fieldKey} references ${field.reference.model}.${field.reference.field}${field.reference.onDelete ? ` (onDelete: ${field.reference.onDelete})` : ""}`);
1648
1649
  }
1649
1650
  for (const constraint of model.model.constraints || []) {
1650
1651
  const indexSpec = constraint.fields.map((fieldKey) => `${JSON.stringify(model.model.fields[fieldKey]?.name || fieldKey)}: 1`).join(", ");
1651
1652
  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)}" }`;
1653
+ const options = constraint.type === "unique" ? `{ unique: true, name: "${escapeDoubleQuoted(indexName)}" }` : `{ name: "${escapeDoubleQuoted(indexName)}" }`;
1653
1654
  lines.push(` await ${model.exportName}.createIndex({ ${indexSpec} }, ${options});`);
1654
1655
  }
1655
1656
  lines.push("");
@@ -1681,8 +1682,11 @@ function toCamelCase(value) {
1681
1682
  const pascal = toPascalCase(value);
1682
1683
  return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : pascal;
1683
1684
  }
1684
- function escapeString(value) {
1685
- return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "''");
1685
+ function escapeDoubleQuoted(value) {
1686
+ return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
1687
+ }
1688
+ function escapeSqlString(value) {
1689
+ return value.replace(/'/g, "''");
1686
1690
  }
1687
1691
  function escapeRegExp$1(value) {
1688
1692
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -1792,6 +1796,10 @@ async function fetchLiveSnapshot(baseUrl, options) {
1792
1796
  clearTimeout(timeout);
1793
1797
  }
1794
1798
  }
1799
+ /** Reported paths are shown to the user, so keep them POSIX on every platform. */
1800
+ function toPosix$1(value) {
1801
+ return value.split(node_path.default.sep).join("/");
1802
+ }
1795
1803
  function createLiveReport(snapshot, baseUrl, now) {
1796
1804
  const checks = [
1797
1805
  {
@@ -1875,7 +1883,7 @@ async function createProjectReport(root, options) {
1875
1883
  status: "pass",
1876
1884
  code: "CONFIG_VALID",
1877
1885
  title: "Farm config loads successfully",
1878
- message: configFile ? node_path.default.relative(root, configFile) || node_path.default.basename(configFile) : "Resolved config"
1886
+ message: configFile ? toPosix$1(node_path.default.relative(root, configFile)) || node_path.default.basename(configFile) : "Resolved config"
1879
1887
  });
1880
1888
  }
1881
1889
  } catch (error) {
@@ -1921,7 +1929,7 @@ function applySafeProjectFixes(root, config, checks) {
1921
1929
  fixes.push({
1922
1930
  code: "ROOT_LAYOUT_CREATED",
1923
1931
  title: "Created the missing root layout",
1924
- filePath: node_path.default.relative(root, layoutPath)
1932
+ filePath: toPosix$1(node_path.default.relative(root, layoutPath))
1925
1933
  });
1926
1934
  }
1927
1935
  }
@@ -3322,11 +3330,13 @@ function getDependencySectionFlags(packageManager, section) {
3322
3330
  }
3323
3331
  function runFarmUpgradeCommand(command) {
3324
3332
  return new Promise((resolve, reject) => {
3325
- const executable = process.platform === "win32" ? `${command.command}.cmd` : command.command;
3333
+ const isWindows = process.platform === "win32";
3334
+ const executable = isWindows ? `${command.command}.cmd` : command.command;
3326
3335
  const child = (0, node_child_process.spawn)(executable, command.args, {
3327
3336
  cwd: command.cwd,
3328
3337
  env: process.env,
3329
- stdio: "inherit"
3338
+ stdio: "inherit",
3339
+ shell: isWindows
3330
3340
  });
3331
3341
  child.on("error", reject);
3332
3342
  child.on("close", (code, signal) => {
@@ -3372,6 +3382,8 @@ Object.defineProperty(exports, "createServer", {
3372
3382
  });
3373
3383
  exports.deployFarm = deployFarm;
3374
3384
  exports.detectFarmPackageManager = detectFarmPackageManager;
3385
+ exports.escapeDoubleQuoted = escapeDoubleQuoted;
3386
+ exports.escapeSqlString = escapeSqlString;
3375
3387
  exports.explainFarmRoute = explainFarmRoute;
3376
3388
  exports.formatFarmCronJobs = formatFarmCronJobs;
3377
3389
  exports.formatFarmDeployPlan = formatFarmDeployPlan;