@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 +3 -8
- package/dist/index.js +36 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -21
- package/dist/index.mjs.map +1 -1
- package/dist/telemetry-9Y6041mK.js +513 -0
- package/dist/telemetry-9Y6041mK.js.map +1 -0
- package/dist/telemetry-DjbMk2du.mjs +451 -0
- package/dist/telemetry-DjbMk2du.mjs.map +1 -0
- package/dist/telemetry.js +11 -364
- package/dist/telemetry.mjs +2 -353
- package/package.json +2 -2
- package/dist/telemetry.js.map +0 -1
- package/dist/telemetry.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as listFarmIntegrationProviders, t as addFarmIntegration } from "./add-integration-7hf9WI7e.mjs";
|
|
2
2
|
import { buildFarm } from "./build.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { a as resolveFarmTelemetryCommand, c as trackFarmCommand, i as resolveFarmCreateAppTelemetryCommand, l as trackFarmCreateAppCommand, n as getFarmTelemetryConfigFile, o as setFarmTelemetryEnabled, r as getFarmTelemetryStatus, s as showFarmTelemetryNotice, t as flushFarmTelemetry, u as trackFarmProjectCreated } from "./telemetry-DjbMk2du.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { createServer, startDevServer } from "@farm.js/core/server";
|
|
6
6
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
@@ -429,8 +429,9 @@ async function deployNetlify(root, outputDir, site) {
|
|
|
429
429
|
function formatCommand$1(executable, args) {
|
|
430
430
|
return [executable, ...args].map(formatCommandArgument).join(" ");
|
|
431
431
|
}
|
|
432
|
+
const SAFE_ARGUMENT = process.platform === "win32" ? /^[A-Za-z0-9_.\\/:=@+-]+$/ : /^[A-Za-z0-9_./:=@+-]+$/;
|
|
432
433
|
function formatCommandArgument(argument) {
|
|
433
|
-
if (
|
|
434
|
+
if (SAFE_ARGUMENT.test(argument)) return argument;
|
|
434
435
|
return `'${argument.replace(/'/g, `'"'"'`)}'`;
|
|
435
436
|
}
|
|
436
437
|
function getErrorMessage(error) {
|
|
@@ -643,6 +644,9 @@ async function createGatewaySession(plan, timeoutMs) {
|
|
|
643
644
|
if (!session.id || !session.token || !session.publicUrl) throw new Error("Preview gateway returned an invalid session.");
|
|
644
645
|
return session;
|
|
645
646
|
}
|
|
647
|
+
function getSetCookies(headers) {
|
|
648
|
+
return headers.getSetCookie?.call(headers) || [];
|
|
649
|
+
}
|
|
646
650
|
async function forwardGatewayRequest(target, request) {
|
|
647
651
|
const headers = new Headers();
|
|
648
652
|
for (const [key, value] of Object.entries(request.headers || {})) {
|
|
@@ -661,8 +665,10 @@ async function forwardGatewayRequest(target, request) {
|
|
|
661
665
|
const responseHeaders = {};
|
|
662
666
|
response.headers.forEach((value, key) => {
|
|
663
667
|
const normalized = key.toLowerCase();
|
|
664
|
-
if (!HOP_BY_HOP_HEADERS.has(normalized)) responseHeaders[key] = value;
|
|
668
|
+
if (!HOP_BY_HOP_HEADERS.has(normalized) && normalized !== "set-cookie") responseHeaders[key] = value;
|
|
665
669
|
});
|
|
670
|
+
const setCookies = getSetCookies(response.headers);
|
|
671
|
+
if (setCookies.length > 0) responseHeaders["set-cookie"] = setCookies;
|
|
666
672
|
return {
|
|
667
673
|
status: response.status,
|
|
668
674
|
headers: responseHeaders,
|
|
@@ -1376,18 +1382,18 @@ function renderPrismaModel(model) {
|
|
|
1376
1382
|
const defaultAttribute = getPrismaDefaultAttribute(field);
|
|
1377
1383
|
if (defaultAttribute) attributes.push(defaultAttribute);
|
|
1378
1384
|
if (field.meta?.autoUpdate && field.type === "datetime") attributes.push("@updatedAt");
|
|
1379
|
-
if (field.name !== fieldKey) attributes.push(`@map("${
|
|
1385
|
+
if (field.name !== fieldKey) attributes.push(`@map("${escapeDoubleQuoted(field.name)}")`);
|
|
1380
1386
|
if (attributes.length) parts.push(attributes.join(" "));
|
|
1381
1387
|
lines.push(` ${parts.join(" ")}`);
|
|
1382
|
-
if (field.index) modelLevelConstraints.push(`@@index([${fieldKey}], map: "${
|
|
1388
|
+
if (field.index) modelLevelConstraints.push(`@@index([${fieldKey}], map: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}")`);
|
|
1383
1389
|
}
|
|
1384
1390
|
for (const constraint of model.model.constraints || []) {
|
|
1385
1391
|
const fields = constraint.fields.join(", ");
|
|
1386
1392
|
const attribute = constraint.type === "unique" ? "@@unique" : "@@index";
|
|
1387
|
-
const suffix = constraint.name ? `, map: "${
|
|
1393
|
+
const suffix = constraint.name ? `, map: "${escapeDoubleQuoted(constraint.name)}"` : "";
|
|
1388
1394
|
modelLevelConstraints.push(`${attribute}([${fields}]${suffix})`);
|
|
1389
1395
|
}
|
|
1390
|
-
lines.push(` @@map("${
|
|
1396
|
+
lines.push(` @@map("${escapeDoubleQuoted(model.modelName)}")`);
|
|
1391
1397
|
for (const constraint of modelLevelConstraints) lines.push(` ${constraint}`);
|
|
1392
1398
|
lines.push("}");
|
|
1393
1399
|
return lines.join("\n");
|
|
@@ -1405,7 +1411,7 @@ function getPrismaFieldType(field) {
|
|
|
1405
1411
|
function getPrismaDefaultAttribute(field) {
|
|
1406
1412
|
if (field.default === void 0) return null;
|
|
1407
1413
|
if (field.type === "datetime" && field.default === "now") return "@default(now())";
|
|
1408
|
-
if (typeof field.default === "string") return `@default("${
|
|
1414
|
+
if (typeof field.default === "string") return `@default("${escapeDoubleQuoted(field.default)}")`;
|
|
1409
1415
|
if (typeof field.default === "number" || typeof field.default === "boolean") return `@default(${String(field.default)})`;
|
|
1410
1416
|
return null;
|
|
1411
1417
|
}
|
|
@@ -1443,12 +1449,12 @@ function renderDrizzleModel(model, dialect, tableFactoryName) {
|
|
|
1443
1449
|
lines.push(` ${fieldKey}: ${renderDrizzleColumn(field, dialect)},`);
|
|
1444
1450
|
}
|
|
1445
1451
|
lines.push("}, (table) => ({");
|
|
1446
|
-
for (const [fieldKey, field] of Object.entries(model.model.fields)) if (field.index) lines.push(` ${fieldKey}Idx: index("${
|
|
1452
|
+
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}),`);
|
|
1447
1453
|
for (const constraint of model.model.constraints || []) {
|
|
1448
1454
|
const builder = constraint.type === "unique" ? "uniqueIndex" : "index";
|
|
1449
1455
|
const accessor = constraint.fields.map((fieldKey) => `table.${fieldKey}`).join(", ");
|
|
1450
1456
|
const name = constraint.name || `${model.modelName}_${constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name || fieldKey).join("_")}_${constraint.type}`;
|
|
1451
|
-
lines.push(` ${toCamelCase(name)}: ${builder}("${
|
|
1457
|
+
lines.push(` ${toCamelCase(name)}: ${builder}("${escapeDoubleQuoted(name)}").on(${accessor}),`);
|
|
1452
1458
|
}
|
|
1453
1459
|
lines.push("}));");
|
|
1454
1460
|
return lines.join("\n");
|
|
@@ -1526,7 +1532,7 @@ function renderSqliteDrizzleColumn(field) {
|
|
|
1526
1532
|
function getDrizzleDefaultExpression(field, dialect) {
|
|
1527
1533
|
if (field.default === void 0) return "";
|
|
1528
1534
|
if (field.type === "datetime" && field.default === "now") return dialect === "sqlite" ? "" : ".defaultNow()";
|
|
1529
|
-
if (typeof field.default === "string") return `.default("${
|
|
1535
|
+
if (typeof field.default === "string") return `.default("${escapeDoubleQuoted(field.default)}")`;
|
|
1530
1536
|
if (typeof field.default === "number" || typeof field.default === "boolean") return `.default(${String(field.default)})`;
|
|
1531
1537
|
return "";
|
|
1532
1538
|
}
|
|
@@ -1617,7 +1623,7 @@ function getSqlColumnType(field, dialect) {
|
|
|
1617
1623
|
function getSqlDefaultExpression(field, dialect) {
|
|
1618
1624
|
if (field.default === void 0) return null;
|
|
1619
1625
|
if (field.type === "datetime" && field.default === "now") return "CURRENT_TIMESTAMP";
|
|
1620
|
-
if (typeof field.default === "string") return `'${
|
|
1626
|
+
if (typeof field.default === "string") return `'${escapeSqlString(field.default)}'`;
|
|
1621
1627
|
if (typeof field.default === "number") return String(field.default);
|
|
1622
1628
|
if (typeof field.default === "boolean") {
|
|
1623
1629
|
if (dialect === "sqlite") return field.default ? "1" : "0";
|
|
@@ -1634,20 +1640,20 @@ function generateMongoBootstrap(models) {
|
|
|
1634
1640
|
];
|
|
1635
1641
|
for (const model of models) {
|
|
1636
1642
|
lines.push(` // Integration "${model.integrationKey}" model "${model.modelKey}"`);
|
|
1637
|
-
lines.push(` const ${model.exportName} = db.collection("${
|
|
1643
|
+
lines.push(` const ${model.exportName} = db.collection("${escapeDoubleQuoted(model.modelName)}");`);
|
|
1638
1644
|
for (const [fieldKey, field] of Object.entries(model.model.fields)) {
|
|
1639
1645
|
if (field.unique) {
|
|
1640
1646
|
const options = ["unique: true"];
|
|
1641
1647
|
if (isNullableField(field)) options.push("sparse: true");
|
|
1642
|
-
options.push(`name: "${
|
|
1648
|
+
options.push(`name: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_unique`)}"`);
|
|
1643
1649
|
lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { ${options.join(", ")} });`);
|
|
1644
|
-
} else if (field.index) lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { name: "${
|
|
1650
|
+
} else if (field.index) lines.push(` await ${model.exportName}.createIndex({ ${JSON.stringify(field.name)}: 1 }, { name: "${escapeDoubleQuoted(`${model.modelName}_${field.name}_idx`)}" });`);
|
|
1645
1651
|
if (field.reference) lines.push(` // ${fieldKey} references ${field.reference.model}.${field.reference.field}${field.reference.onDelete ? ` (onDelete: ${field.reference.onDelete})` : ""}`);
|
|
1646
1652
|
}
|
|
1647
1653
|
for (const constraint of model.model.constraints || []) {
|
|
1648
1654
|
const indexSpec = constraint.fields.map((fieldKey) => `${JSON.stringify(model.model.fields[fieldKey]?.name || fieldKey)}: 1`).join(", ");
|
|
1649
1655
|
const indexName = constraint.name || `${model.modelName}_${constraint.fields.map((fieldKey) => model.model.fields[fieldKey]?.name || fieldKey).join("_")}_${constraint.type}`;
|
|
1650
|
-
const options = constraint.type === "unique" ? `{ unique: true, name: "${
|
|
1656
|
+
const options = constraint.type === "unique" ? `{ unique: true, name: "${escapeDoubleQuoted(indexName)}" }` : `{ name: "${escapeDoubleQuoted(indexName)}" }`;
|
|
1651
1657
|
lines.push(` await ${model.exportName}.createIndex({ ${indexSpec} }, ${options});`);
|
|
1652
1658
|
}
|
|
1653
1659
|
lines.push("");
|
|
@@ -1679,8 +1685,11 @@ function toCamelCase(value) {
|
|
|
1679
1685
|
const pascal = toPascalCase(value);
|
|
1680
1686
|
return pascal ? pascal.charAt(0).toLowerCase() + pascal.slice(1) : pascal;
|
|
1681
1687
|
}
|
|
1682
|
-
function
|
|
1683
|
-
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")
|
|
1688
|
+
function escapeDoubleQuoted(value) {
|
|
1689
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
1690
|
+
}
|
|
1691
|
+
function escapeSqlString(value) {
|
|
1692
|
+
return value.replace(/'/g, "''");
|
|
1684
1693
|
}
|
|
1685
1694
|
function escapeRegExp$1(value) {
|
|
1686
1695
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1790,6 +1799,10 @@ async function fetchLiveSnapshot(baseUrl, options) {
|
|
|
1790
1799
|
clearTimeout(timeout);
|
|
1791
1800
|
}
|
|
1792
1801
|
}
|
|
1802
|
+
/** Reported paths are shown to the user, so keep them POSIX on every platform. */
|
|
1803
|
+
function toPosix$1(value) {
|
|
1804
|
+
return value.split(path.sep).join("/");
|
|
1805
|
+
}
|
|
1793
1806
|
function createLiveReport(snapshot, baseUrl, now) {
|
|
1794
1807
|
const checks = [
|
|
1795
1808
|
{
|
|
@@ -1873,7 +1886,7 @@ async function createProjectReport(root, options) {
|
|
|
1873
1886
|
status: "pass",
|
|
1874
1887
|
code: "CONFIG_VALID",
|
|
1875
1888
|
title: "Farm config loads successfully",
|
|
1876
|
-
message: configFile ? path.relative(root, configFile) || path.basename(configFile) : "Resolved config"
|
|
1889
|
+
message: configFile ? toPosix$1(path.relative(root, configFile)) || path.basename(configFile) : "Resolved config"
|
|
1877
1890
|
});
|
|
1878
1891
|
}
|
|
1879
1892
|
} catch (error) {
|
|
@@ -1919,7 +1932,7 @@ function applySafeProjectFixes(root, config, checks) {
|
|
|
1919
1932
|
fixes.push({
|
|
1920
1933
|
code: "ROOT_LAYOUT_CREATED",
|
|
1921
1934
|
title: "Created the missing root layout",
|
|
1922
|
-
filePath: path.relative(root, layoutPath)
|
|
1935
|
+
filePath: toPosix$1(path.relative(root, layoutPath))
|
|
1923
1936
|
});
|
|
1924
1937
|
}
|
|
1925
1938
|
}
|
|
@@ -3352,6 +3365,6 @@ function formatError(error) {
|
|
|
3352
3365
|
return error instanceof Error ? error.message : String(error);
|
|
3353
3366
|
}
|
|
3354
3367
|
//#endregion
|
|
3355
|
-
export { FarmDeployError, FarmGeneratedArtifactsStaleError, FarmStartError, addFarmIntegration, buildFarm, createFarmDeployPlan, createFarmStartPlan, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, explainFarmRoute, formatFarmCronJobs, formatFarmDeployPlan, formatFarmDoctorReport, formatFarmRouteExplanation, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, getFarmTelemetryConfigFile, getFarmTelemetryStatus, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, migrateFarmAuth, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolveFarmCreateAppTelemetryCommand, resolveFarmTelemetryCommand, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runNativePreviewTunnel, runPreviewGateway, setFarmTelemetryEnabled, showFarmTelemetryNotice, startDevServer, startFarm, startFarmCronScheduler, trackFarmCommand, trackFarmCreateAppCommand, trackFarmProjectCreated, upgradeFarm };
|
|
3368
|
+
export { FarmDeployError, FarmGeneratedArtifactsStaleError, FarmStartError, addFarmIntegration, buildFarm, createFarmDeployPlan, createFarmStartPlan, createFarmUpgradePlan, createFrameworkMigrationPlan, createGatewaySession, createPreviewGatewayPlan, createPreviewTunnelPlan, createServer, deployFarm, detectFarmPackageManager, escapeDoubleQuoted, escapeSqlString, explainFarmRoute, flushFarmTelemetry, formatFarmCronJobs, formatFarmDeployPlan, formatFarmDoctorReport, formatFarmRouteExplanation, formatFarmUpgradePlan, forwardGatewayRequest, generateFarmArtifacts, getFarmTelemetryConfigFile, getFarmTelemetryStatus, inspectFrameworkMigrations, listFarmCronJobs, listFarmIntegrationProviders, loadFarmCronConfig, migrateFarm, migrateFarmAuth, parsePreviewPublicUrl, previewFarm, resolveCloudflareAgentDeployPlan, resolveFarmCreateAppTelemetryCommand, resolveFarmTelemetryCommand, resolvePreviewTarget, runFarmCronJob, runFarmDoctor, runNativePreviewTunnel, runPreviewGateway, setFarmTelemetryEnabled, showFarmTelemetryNotice, startDevServer, startFarm, startFarmCronScheduler, trackFarmCommand, trackFarmCreateAppCommand, trackFarmProjectCreated, upgradeFarm };
|
|
3356
3369
|
|
|
3357
3370
|
//# sourceMappingURL=index.mjs.map
|