@farm.js/create-app 0.1.0-beta.58 → 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/dist/index.js +129 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/templates/_renderers/preact/package.json +3 -3
- package/templates/_renderers/solid/package.json +3 -3
- package/templates/_renderers/svelte/package.json +3 -3
- package/templates/_renderers/vue/package.json +3 -3
- package/templates/auth/package.json +3 -3
- package/templates/basic/package.json +2 -2
- package/templates/better-auth/package.json +3 -3
- package/templates/react-compiler/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -13,6 +13,8 @@ let node_fs_promises = require("node:fs/promises");
|
|
|
13
13
|
let node_path = require("node:path");
|
|
14
14
|
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
15
15
|
let node_crypto = require("node:crypto");
|
|
16
|
+
let node_http = require("node:http");
|
|
17
|
+
let node_https = require("node:https");
|
|
16
18
|
let node_os = require("node:os");
|
|
17
19
|
node_os = require_rolldown_runtime.__toESM(node_os);
|
|
18
20
|
//#region ../farm-cli/src/ui-feature-registry.ts
|
|
@@ -2529,13 +2531,9 @@ function escapeRegExp(input) {
|
|
|
2529
2531
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2530
2532
|
}
|
|
2531
2533
|
//#endregion
|
|
2532
|
-
//#region ../farm-cli/src/telemetry.ts
|
|
2533
|
-
const
|
|
2534
|
-
const
|
|
2535
|
-
const TELEMETRY_NOTICE_URL = "https://farmjs.dev/docs/telemetry";
|
|
2536
|
-
const REQUEST_TIMEOUT_MS = 750;
|
|
2537
|
-
const CREATE_APP_COMMANDS = ["create", "list-templates"];
|
|
2538
|
-
const FARM_TEMPLATES = [
|
|
2534
|
+
//#region ../farm-cli/src/telemetry-contract.ts
|
|
2535
|
+
const FARM_CREATE_APP_TELEMETRY_COMMANDS = ["create", "list-templates"];
|
|
2536
|
+
const FARM_TELEMETRY_TEMPLATES = [
|
|
2539
2537
|
"basic",
|
|
2540
2538
|
"react-compiler",
|
|
2541
2539
|
"auth",
|
|
@@ -2554,19 +2552,28 @@ const FARM_TEMPLATES = [
|
|
|
2554
2552
|
"unkey",
|
|
2555
2553
|
"workos"
|
|
2556
2554
|
];
|
|
2557
|
-
const
|
|
2555
|
+
const FARM_TELEMETRY_RENDERERS = [
|
|
2558
2556
|
"react",
|
|
2559
2557
|
"preact",
|
|
2560
2558
|
"solid",
|
|
2561
2559
|
"vue",
|
|
2562
2560
|
"svelte"
|
|
2563
2561
|
];
|
|
2564
|
-
const
|
|
2562
|
+
const FARM_TELEMETRY_PACKAGE_MANAGERS = [
|
|
2565
2563
|
"npm",
|
|
2566
2564
|
"pnpm",
|
|
2567
2565
|
"yarn",
|
|
2568
2566
|
"bun"
|
|
2569
2567
|
];
|
|
2568
|
+
//#endregion
|
|
2569
|
+
//#region ../farm-cli/src/telemetry.ts
|
|
2570
|
+
const TELEMETRY_SCHEMA_VERSION = 1;
|
|
2571
|
+
const DEFAULT_TELEMETRY_ENDPOINT = "https://farmjs.dev/api/telemetry/v1/events";
|
|
2572
|
+
const TELEMETRY_NOTICE_URL = "https://farmjs.dev/docs/telemetry";
|
|
2573
|
+
const REQUEST_TIMEOUT_MS = 3e3;
|
|
2574
|
+
const RETRY_DELAYS_MS = [250, 750];
|
|
2575
|
+
const pendingDeliveries = /* @__PURE__ */ new Set();
|
|
2576
|
+
const retryTimers = /* @__PURE__ */ new Set();
|
|
2570
2577
|
function defaultConfig() {
|
|
2571
2578
|
return {
|
|
2572
2579
|
version: TELEMETRY_SCHEMA_VERSION,
|
|
@@ -2735,33 +2742,44 @@ async function showFarmTelemetryNotice() {
|
|
|
2735
2742
|
noticeShown: true
|
|
2736
2743
|
});
|
|
2737
2744
|
}
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2745
|
+
function trackFarmCreateAppCommand(input) {
|
|
2746
|
+
return schedule(async () => {
|
|
2747
|
+
await showFarmTelemetryNotice();
|
|
2748
|
+
const command = allowlisted(input.command, FARM_CREATE_APP_TELEMETRY_COMMANDS);
|
|
2749
|
+
if (!command) return;
|
|
2750
|
+
await track({
|
|
2751
|
+
eventType: "command_invoked",
|
|
2752
|
+
source: "create-app",
|
|
2753
|
+
packageName: "@farm.js/create-app",
|
|
2754
|
+
packageVersion: sanitizeVersion(input.packageVersion),
|
|
2755
|
+
command
|
|
2756
|
+
});
|
|
2747
2757
|
});
|
|
2748
2758
|
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2759
|
+
function trackFarmProjectCreated(input) {
|
|
2760
|
+
return schedule(async () => {
|
|
2761
|
+
const template = allowlisted(input.template, FARM_TELEMETRY_TEMPLATES);
|
|
2762
|
+
const renderer = allowlisted(input.renderer, FARM_TELEMETRY_RENDERERS);
|
|
2763
|
+
const packageManager = allowlisted(input.packageManager, FARM_TELEMETRY_PACKAGE_MANAGERS);
|
|
2764
|
+
await track({
|
|
2765
|
+
eventType: "project_created",
|
|
2766
|
+
source: "create-app",
|
|
2767
|
+
packageName: "@farm.js/create-app",
|
|
2768
|
+
packageVersion: sanitizeVersion(input.packageVersion),
|
|
2769
|
+
...template ? { template } : {},
|
|
2770
|
+
...renderer ? { renderer } : {},
|
|
2771
|
+
...packageManager ? { packageManager } : {},
|
|
2772
|
+
...typeof input.typescript === "boolean" ? { typescript: input.typescript } : {},
|
|
2773
|
+
...typeof input.installedDependencies === "boolean" ? { installedDependencies: input.installedDependencies } : {}
|
|
2774
|
+
});
|
|
2763
2775
|
});
|
|
2764
2776
|
}
|
|
2777
|
+
function schedule(delivery) {
|
|
2778
|
+
const pending = Promise.resolve().then(delivery).catch(() => {});
|
|
2779
|
+
pendingDeliveries.add(pending);
|
|
2780
|
+
pending.finally(() => pendingDeliveries.delete(pending));
|
|
2781
|
+
return Promise.resolve();
|
|
2782
|
+
}
|
|
2765
2783
|
async function track(event) {
|
|
2766
2784
|
try {
|
|
2767
2785
|
const state = await resolveState();
|
|
@@ -2783,20 +2801,85 @@ async function track(event) {
|
|
|
2783
2801
|
} catch {}
|
|
2784
2802
|
}
|
|
2785
2803
|
async function send(payload) {
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2804
|
+
for (let attempt = 0; attempt <= RETRY_DELAYS_MS.length; attempt += 1) {
|
|
2805
|
+
const result = await sendOnce(payload);
|
|
2806
|
+
if (result === "delivered" || result === "rejected") return;
|
|
2807
|
+
const delay = RETRY_DELAYS_MS[attempt];
|
|
2808
|
+
if (delay !== void 0) await wait(delay);
|
|
2809
|
+
}
|
|
2810
|
+
debug("delivery failed after retries");
|
|
2811
|
+
}
|
|
2812
|
+
async function sendOnce(payload) {
|
|
2813
|
+
let endpoint;
|
|
2789
2814
|
try {
|
|
2790
|
-
|
|
2815
|
+
endpoint = new URL(getEndpoint());
|
|
2816
|
+
} catch {
|
|
2817
|
+
debug("invalid endpoint URL");
|
|
2818
|
+
return "rejected";
|
|
2819
|
+
}
|
|
2820
|
+
const requestTransport = endpoint.protocol === "http:" ? node_http.request : node_https.request;
|
|
2821
|
+
if (endpoint.protocol !== "http:" && endpoint.protocol !== "https:") {
|
|
2822
|
+
debug(`unsupported endpoint protocol ${endpoint.protocol}`);
|
|
2823
|
+
return "rejected";
|
|
2824
|
+
}
|
|
2825
|
+
const body = JSON.stringify(payload);
|
|
2826
|
+
return new Promise((resolve) => {
|
|
2827
|
+
let settled = false;
|
|
2828
|
+
const finish = (result) => {
|
|
2829
|
+
if (settled) return;
|
|
2830
|
+
settled = true;
|
|
2831
|
+
clearTimeout(timeout);
|
|
2832
|
+
resolve(result);
|
|
2833
|
+
};
|
|
2834
|
+
const request = requestTransport(endpoint, {
|
|
2791
2835
|
method: "POST",
|
|
2792
|
-
headers: {
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2836
|
+
headers: {
|
|
2837
|
+
"content-type": "application/json",
|
|
2838
|
+
"content-length": Buffer.byteLength(body)
|
|
2839
|
+
}
|
|
2840
|
+
}, (response) => {
|
|
2841
|
+
response.on("error", () => {});
|
|
2842
|
+
response.resume();
|
|
2843
|
+
const status = response.statusCode ?? 0;
|
|
2844
|
+
if (status >= 200 && status < 300) return finish("delivered");
|
|
2845
|
+
if (status === 408 || status === 425 || status === 429) {
|
|
2846
|
+
debug(`temporary HTTP ${status}; retrying`);
|
|
2847
|
+
return finish("retry");
|
|
2848
|
+
}
|
|
2849
|
+
if (status >= 500) {
|
|
2850
|
+
debug(`server HTTP ${status}; retrying`);
|
|
2851
|
+
return finish("retry");
|
|
2852
|
+
}
|
|
2853
|
+
debug(`event rejected with HTTP ${status}`);
|
|
2854
|
+
return finish("rejected");
|
|
2796
2855
|
});
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2856
|
+
const timeout = setTimeout(() => {
|
|
2857
|
+
request.destroy();
|
|
2858
|
+
debug("network request timed out; retrying");
|
|
2859
|
+
finish("retry");
|
|
2860
|
+
}, REQUEST_TIMEOUT_MS);
|
|
2861
|
+
timeout.unref?.();
|
|
2862
|
+
request.once("socket", (socket) => socket.unref());
|
|
2863
|
+
request.once("error", () => {
|
|
2864
|
+
debug("network request failed; retrying");
|
|
2865
|
+
finish("retry");
|
|
2866
|
+
});
|
|
2867
|
+
request.end(body);
|
|
2868
|
+
});
|
|
2869
|
+
}
|
|
2870
|
+
function wait(delay) {
|
|
2871
|
+
return new Promise((resolve) => {
|
|
2872
|
+
const timeout = setTimeout(() => {
|
|
2873
|
+
retryTimers.delete(timeout);
|
|
2874
|
+
resolve();
|
|
2875
|
+
}, delay);
|
|
2876
|
+
retryTimers.add(timeout);
|
|
2877
|
+
timeout.unref?.();
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2880
|
+
function debug(message) {
|
|
2881
|
+
if (!isTrue(process.env.FARM_TELEMETRY_DEBUG)) return;
|
|
2882
|
+
process.stderr.write(`[farm.telemetry] ${message}\n`);
|
|
2800
2883
|
}
|
|
2801
2884
|
function sanitizeVersion(value) {
|
|
2802
2885
|
return /^[0-9A-Za-z.+_-]{1,64}$/.test(value) ? value : "unknown";
|
|
@@ -2955,8 +3038,7 @@ function integrationTemplate(input) {
|
|
|
2955
3038
|
}
|
|
2956
3039
|
async function createApp(projectName, options = {}) {
|
|
2957
3040
|
require_utils.showBanner();
|
|
2958
|
-
|
|
2959
|
-
await trackFarmCreateAppCommand({
|
|
3041
|
+
trackFarmCreateAppCommand({
|
|
2960
3042
|
command: options.listTemplates ? "list-templates" : "create",
|
|
2961
3043
|
packageVersion: options.telemetryPackageVersion ?? "unknown"
|
|
2962
3044
|
});
|
|
@@ -3118,7 +3200,7 @@ async function createApp(projectName, options = {}) {
|
|
|
3118
3200
|
if (integrationResult.env.length) require_utils.logger.info("Copy .env.example to .env.local and add your provider credentials.");
|
|
3119
3201
|
for (const note of integrationResult.notes) require_utils.logger.info(note);
|
|
3120
3202
|
}
|
|
3121
|
-
|
|
3203
|
+
trackFarmProjectCreated({
|
|
3122
3204
|
packageVersion: options.telemetryPackageVersion ?? "unknown",
|
|
3123
3205
|
template,
|
|
3124
3206
|
renderer,
|
|
@@ -3357,7 +3439,7 @@ async function updatePackageJson(projectPath, projectName, packageManager) {
|
|
|
3357
3439
|
try {
|
|
3358
3440
|
const content = await fs_promises.default.readFile(packageJsonPath, "utf-8");
|
|
3359
3441
|
const packageJson = JSON.parse(content);
|
|
3360
|
-
packageJson.name = projectName;
|
|
3442
|
+
packageJson.name = path.default.basename(projectName.replace(/[\\/]+$/, "")) || projectName;
|
|
3361
3443
|
if (packageManager.version) packageJson.packageManager = `${packageManager.name}@${packageManager.version}`;
|
|
3362
3444
|
await fs_promises.default.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
|
|
3363
3445
|
} catch {
|