@farm.js/cli 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/telemetry.js CHANGED
@@ -1,365 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.js");
3
- let node_fs_promises = require("node:fs/promises");
4
- let node_path = require("node:path");
5
- node_path = require_rolldown_runtime.__toESM(node_path);
6
- let node_crypto = require("node:crypto");
7
- let node_os = require("node:os");
8
- node_os = require_rolldown_runtime.__toESM(node_os);
9
- //#region src/telemetry.ts
10
- const TELEMETRY_SCHEMA_VERSION = 1;
11
- const DEFAULT_TELEMETRY_ENDPOINT = "https://farmjs.dev/api/telemetry/v1/events";
12
- const TELEMETRY_NOTICE_URL = "https://farmjs.dev/docs/telemetry";
13
- const REQUEST_TIMEOUT_MS = 750;
14
- const FARM_COMMANDS = [
15
- "dev",
16
- "build",
17
- "start",
18
- "auth:migrate",
19
- "upgrade",
20
- "generate",
21
- "doctor",
22
- "explain",
23
- "preview",
24
- "migrate",
25
- "cron:list",
26
- "cron:run",
27
- "add:integration",
28
- "deploy"
29
- ];
30
- const CREATE_APP_COMMANDS = ["create", "list-templates"];
31
- const FARM_TEMPLATES = [
32
- "basic",
33
- "react-compiler",
34
- "auth",
35
- "better-auth",
36
- "ai",
37
- "auth0",
38
- "authjs",
39
- "autumn",
40
- "clerk",
41
- "jobs-inngest",
42
- "jobs-trigger",
43
- "polar",
44
- "resend",
45
- "stripe",
46
- "supabase",
47
- "unkey",
48
- "workos"
49
- ];
50
- const RENDERERS = [
51
- "react",
52
- "preact",
53
- "solid",
54
- "vue",
55
- "svelte"
56
- ];
57
- const PACKAGE_MANAGERS = [
58
- "npm",
59
- "pnpm",
60
- "yarn",
61
- "bun"
62
- ];
63
- const DEPLOY_TARGETS = [
64
- "vercel",
65
- "cloudflare",
66
- "netlify",
67
- "node",
68
- "custom"
69
- ];
70
- function defaultConfig() {
71
- return {
72
- version: TELEMETRY_SCHEMA_VERSION,
73
- enabled: true,
74
- noticeShown: false
75
- };
76
- }
77
- function configDirectory() {
78
- if (process.env.FARM_TELEMETRY_CONFIG_DIR) return node_path.default.resolve(process.env.FARM_TELEMETRY_CONFIG_DIR);
79
- if (process.platform === "win32") return node_path.default.join(process.env.APPDATA || node_path.default.join(node_os.default.homedir(), "AppData", "Roaming"), "farmjs");
80
- if (process.platform === "darwin") return node_path.default.join(node_os.default.homedir(), "Library", "Application Support", "farmjs");
81
- return node_path.default.join(process.env.XDG_CONFIG_HOME || node_path.default.join(node_os.default.homedir(), ".config"), "farmjs");
82
- }
83
- function getFarmTelemetryConfigFile() {
84
- return node_path.default.join(configDirectory(), "telemetry.json");
85
- }
86
- async function readConfig() {
87
- try {
88
- const parsed = JSON.parse(await (0, node_fs_promises.readFile)(getFarmTelemetryConfigFile(), "utf8"));
89
- if (parsed.version !== TELEMETRY_SCHEMA_VERSION) return {
90
- config: defaultConfig(),
91
- stored: false
92
- };
93
- return {
94
- config: {
95
- version: TELEMETRY_SCHEMA_VERSION,
96
- enabled: parsed.enabled === true,
97
- noticeShown: parsed.noticeShown === true,
98
- anonymousId: isUuid(parsed.anonymousId) ? parsed.anonymousId : void 0
99
- },
100
- stored: true
101
- };
102
- } catch {
103
- return {
104
- config: defaultConfig(),
105
- stored: false
106
- };
107
- }
108
- }
109
- async function writeConfig(config) {
110
- const file = getFarmTelemetryConfigFile();
111
- const directory = node_path.default.dirname(file);
112
- const temporaryFile = `${file}.${process.pid}.${(0, node_crypto.randomUUID)()}.tmp`;
113
- try {
114
- await (0, node_fs_promises.mkdir)(directory, {
115
- recursive: true,
116
- mode: 448
117
- });
118
- await (0, node_fs_promises.writeFile)(temporaryFile, `${JSON.stringify(config, null, 2)}\n`, { mode: 384 });
119
- await (0, node_fs_promises.rename)(temporaryFile, file);
120
- await (0, node_fs_promises.chmod)(file, 384).catch(() => void 0);
121
- } catch {
122
- await (0, node_fs_promises.unlink)(temporaryFile).catch(() => void 0);
123
- }
124
- }
125
- function isUuid(value) {
126
- return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
127
- }
128
- function isTrue(value) {
129
- return value !== void 0 && [
130
- "1",
131
- "true",
132
- "yes",
133
- "on"
134
- ].includes(value.toLowerCase());
135
- }
136
- function isFalse(value) {
137
- return value !== void 0 && [
138
- "0",
139
- "false",
140
- "no",
141
- "off"
142
- ].includes(value.toLowerCase());
143
- }
144
- function environmentDecision() {
145
- if (process.env.DO_NOT_TRACK !== void 0 && !isFalse(process.env.DO_NOT_TRACK)) return {
146
- enabled: false,
147
- reason: "DO_NOT_TRACK is set"
148
- };
149
- if (isTrue(process.env.FARM_TELEMETRY_DISABLED)) return {
150
- enabled: false,
151
- reason: "FARM_TELEMETRY_DISABLED is set"
152
- };
153
- if (isTrue(process.env.FARM_TELEMETRY)) return { enabled: true };
154
- if (isFalse(process.env.FARM_TELEMETRY)) return {
155
- enabled: false,
156
- reason: "FARM_TELEMETRY disables collection"
157
- };
158
- return {};
159
- }
160
- function isContinuousIntegration() {
161
- return isTrue(process.env.CI) || isTrue(process.env.GITHUB_ACTIONS) || isTrue(process.env.BUILDKITE) || isTrue(process.env.CIRCLECI);
162
- }
163
- function isInteractive() {
164
- return process.stdin.isTTY === true && process.stdout.isTTY === true;
165
- }
166
- function getEndpoint() {
167
- const candidate = process.env.FARM_TELEMETRY_ENDPOINT || DEFAULT_TELEMETRY_ENDPOINT;
168
- try {
169
- const url = new URL(candidate);
170
- const isLocal = [
171
- "localhost",
172
- "127.0.0.1",
173
- "::1"
174
- ].includes(url.hostname);
175
- if (url.protocol !== "https:" && !(url.protocol === "http:" && isLocal)) return DEFAULT_TELEMETRY_ENDPOINT;
176
- return url.toString();
177
- } catch {
178
- return DEFAULT_TELEMETRY_ENDPOINT;
179
- }
180
- }
181
- async function resolveState() {
182
- const { config, stored } = await readConfig();
183
- const environment = environmentDecision();
184
- const enabled = environment.enabled ?? config.enabled;
185
- const source = environment.enabled !== void 0 ? "environment" : stored ? "configuration" : "default";
186
- if (!enabled) return {
187
- config,
188
- enabled,
189
- active: false,
190
- source,
191
- reason: environment.reason
192
- };
193
- if (environment.enabled === true) return {
194
- config,
195
- enabled,
196
- active: true,
197
- source
198
- };
199
- if (process.env.NODE_ENV === "test") return {
200
- config,
201
- enabled,
202
- active: false,
203
- source,
204
- reason: "test environments are skipped"
205
- };
206
- if (isContinuousIntegration()) return {
207
- config,
208
- enabled,
209
- active: false,
210
- source,
211
- reason: "CI environments are skipped"
212
- };
213
- if (!isInteractive()) return {
214
- config,
215
- enabled,
216
- active: false,
217
- source,
218
- reason: "non-interactive commands are skipped"
219
- };
220
- return {
221
- config,
222
- enabled,
223
- active: true,
224
- source
225
- };
226
- }
227
- async function getFarmTelemetryStatus() {
228
- const state = await resolveState();
229
- return {
230
- enabled: state.enabled,
231
- active: state.active,
232
- source: state.source,
233
- endpoint: getEndpoint(),
234
- configFile: getFarmTelemetryConfigFile(),
235
- anonymousId: state.config.anonymousId,
236
- reason: state.reason
237
- };
238
- }
239
- async function setFarmTelemetryEnabled(enabled) {
240
- const { config: current } = await readConfig();
241
- await writeConfig({
242
- version: TELEMETRY_SCHEMA_VERSION,
243
- enabled,
244
- noticeShown: true,
245
- anonymousId: enabled ? current.anonymousId || (0, node_crypto.randomUUID)() : void 0
246
- });
247
- return getFarmTelemetryStatus();
248
- }
249
- async function showFarmTelemetryNotice() {
250
- if (!isInteractive() || isContinuousIntegration() || process.env.NODE_ENV === "test") return;
251
- if (environmentDecision().enabled !== void 0) return;
252
- const { config } = await readConfig();
253
- if (config.noticeShown) return;
254
- process.stderr.write(`Farm.js collects anonymous CLI telemetry by default. Run "farm telemetry disable" to opt out.\nLearn more: ${TELEMETRY_NOTICE_URL}\n`);
255
- await writeConfig({
256
- ...config,
257
- noticeShown: true
258
- });
259
- }
260
- function resolveFarmTelemetryCommand(value) {
261
- return FARM_COMMANDS.includes(value) ? value : void 0;
262
- }
263
- function resolveFarmCreateAppTelemetryCommand(value) {
264
- return CREATE_APP_COMMANDS.includes(value) ? value : void 0;
265
- }
266
- async function trackFarmCommand(input) {
267
- const deployTarget = allowlisted(input.deployTarget, DEPLOY_TARGETS);
268
- await track({
269
- eventType: "command_invoked",
270
- source: "cli",
271
- packageName: "@farm.js/cli",
272
- packageVersion: sanitizeVersion(input.packageVersion),
273
- command: input.command,
274
- ...deployTarget ? { deployTarget } : {}
275
- });
276
- }
277
- async function trackFarmCreateAppCommand(input) {
278
- const command = allowlisted(input.command, CREATE_APP_COMMANDS);
279
- if (!command) return;
280
- await track({
281
- eventType: "command_invoked",
282
- source: "create-app",
283
- packageName: "@farm.js/create-app",
284
- packageVersion: sanitizeVersion(input.packageVersion),
285
- command
286
- });
287
- }
288
- async function trackFarmProjectCreated(input) {
289
- const template = allowlisted(input.template, FARM_TEMPLATES);
290
- const renderer = allowlisted(input.renderer, RENDERERS);
291
- const packageManager = allowlisted(input.packageManager, PACKAGE_MANAGERS);
292
- await track({
293
- eventType: "project_created",
294
- source: "create-app",
295
- packageName: "@farm.js/create-app",
296
- packageVersion: sanitizeVersion(input.packageVersion),
297
- ...template ? { template } : {},
298
- ...renderer ? { renderer } : {},
299
- ...packageManager ? { packageManager } : {},
300
- ...typeof input.typescript === "boolean" ? { typescript: input.typescript } : {},
301
- ...typeof input.installedDependencies === "boolean" ? { installedDependencies: input.installedDependencies } : {}
302
- });
303
- }
304
- async function track(event) {
305
- try {
306
- const state = await resolveState();
307
- if (!state.active) return;
308
- const anonymousId = state.config.anonymousId || (0, node_crypto.randomUUID)();
309
- if (!state.config.anonymousId) await writeConfig({
310
- ...state.config,
311
- anonymousId
312
- });
313
- await send({
314
- schemaVersion: TELEMETRY_SCHEMA_VERSION,
315
- eventId: (0, node_crypto.randomUUID)(),
316
- anonymousId,
317
- nodeMajor: Number.parseInt(process.versions.node.split(".")[0] || "0", 10),
318
- platform: normalizePlatform(process.platform),
319
- architecture: normalizeArchitecture(process.arch),
320
- ...event
321
- });
322
- } catch {}
323
- }
324
- async function send(payload) {
325
- const controller = new AbortController();
326
- const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
327
- timeout.unref?.();
328
- try {
329
- await fetch(getEndpoint(), {
330
- method: "POST",
331
- headers: { "content-type": "application/json" },
332
- body: JSON.stringify(payload),
333
- signal: controller.signal,
334
- keepalive: true
335
- });
336
- } catch {} finally {
337
- clearTimeout(timeout);
338
- }
339
- }
340
- function sanitizeVersion(value) {
341
- return /^[0-9A-Za-z.+_-]{1,64}$/.test(value) ? value : "unknown";
342
- }
343
- function allowlisted(value, values) {
344
- return value && values.includes(value) ? value : void 0;
345
- }
346
- function normalizePlatform(value) {
347
- if (value === "darwin" || value === "linux") return value;
348
- if (value === "win32") return "windows";
349
- return "other";
350
- }
351
- function normalizeArchitecture(value) {
352
- return value === "arm64" || value === "x64" ? value : "other";
353
- }
354
- //#endregion
355
- exports.getFarmTelemetryConfigFile = getFarmTelemetryConfigFile;
356
- exports.getFarmTelemetryStatus = getFarmTelemetryStatus;
357
- exports.resolveFarmCreateAppTelemetryCommand = resolveFarmCreateAppTelemetryCommand;
358
- exports.resolveFarmTelemetryCommand = resolveFarmTelemetryCommand;
359
- exports.setFarmTelemetryEnabled = setFarmTelemetryEnabled;
360
- exports.showFarmTelemetryNotice = showFarmTelemetryNotice;
361
- exports.trackFarmCommand = trackFarmCommand;
362
- exports.trackFarmCreateAppCommand = trackFarmCreateAppCommand;
363
- exports.trackFarmProjectCreated = trackFarmProjectCreated;
364
-
365
- //# sourceMappingURL=telemetry.js.map
2
+ const require_telemetry = require("./telemetry-9Y6041mK.js");
3
+ exports.flushFarmTelemetry = require_telemetry.flushFarmTelemetry;
4
+ exports.getFarmTelemetryConfigFile = require_telemetry.getFarmTelemetryConfigFile;
5
+ exports.getFarmTelemetryStatus = require_telemetry.getFarmTelemetryStatus;
6
+ exports.resolveFarmCreateAppTelemetryCommand = require_telemetry.resolveFarmCreateAppTelemetryCommand;
7
+ exports.resolveFarmTelemetryCommand = require_telemetry.resolveFarmTelemetryCommand;
8
+ exports.setFarmTelemetryEnabled = require_telemetry.setFarmTelemetryEnabled;
9
+ exports.showFarmTelemetryNotice = require_telemetry.showFarmTelemetryNotice;
10
+ exports.trackFarmCommand = require_telemetry.trackFarmCommand;
11
+ exports.trackFarmCreateAppCommand = require_telemetry.trackFarmCreateAppCommand;
12
+ exports.trackFarmProjectCreated = require_telemetry.trackFarmProjectCreated;