@cedarjs/telemetry 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Cedar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Telemetry
2
+
3
+ RedwoodJS collects completely anonymous telemetry data about general usage.
4
+
5
+ Here is an example JSON packet containing the telemetry data for running yarn rw info:
6
+
7
+ ```json
8
+ {
9
+ "type": "command",
10
+ "command": "info", // actual CLI command that was invoked, including flags
11
+ "ci": false, // whether or not this is running in a CI environment
12
+ "duration": 2353, // how long the process took, in milliseconds
13
+ "NODE_ENV": "development", // the value of NODE_ENV, if set
14
+ "complexity": "4.2.6.3", // a measure of how complex the app is (route, service, cell and page counts)
15
+ "system": "8.32", // cpu core count, memory in GB
16
+ "sides": "web,api", // sides that are in use
17
+ "shell": "zsh",
18
+ "nodeVersion": "14.17.1",
19
+ "yarnVersion": "14.17.1",
20
+ "npmVersion": "14.17.1",
21
+ "vsCodeVersion": "1.58.0",
22
+ "redwoodVersion": "0.35.1",
23
+ "os": "macOS",
24
+ "osVersion": "11.4",
25
+ "system": "8.32" // number of cpu cores and system memory
26
+ }
27
+ ```
28
+
29
+ ## How do I turn it off?
30
+
31
+ Set an environment variable, either in your app's .env file, or anywhere that creates variables for your user space, like `.bashrc` or `.bash_profile`:
32
+
33
+ ```terminal
34
+ REDWOOD_DISABLE_TELEMETRY=1
35
+ ```
36
+
37
+ ## About
38
+
39
+ See: https://telemetry.redwoodjs.com
40
+
41
+ ## Troubleshooting
42
+
43
+ If you suspect problems with telemetry when running CRWA, you can set the verbose flag to help diagnose issues.
44
+
45
+ For example,
46
+
47
+ ```terminal
48
+ REDWOOD_VERBOSE_TELEMETRY=true yarn create-cedar-app bazinga
49
+ ```
@@ -0,0 +1,2 @@
1
+ export * from './telemetry';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./telemetry"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./telemetry")
22
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../src/scripts/invoke.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ var import_sendTelemetry = require("../sendTelemetry");
3
+ (async function() {
4
+ await (0, import_sendTelemetry.sendTelemetry)();
5
+ })();
@@ -0,0 +1,36 @@
1
+ interface SensitiveArgPositions {
2
+ exec: {
3
+ positions: number[];
4
+ options?: never;
5
+ redactWith: string[];
6
+ allowOnly: string[];
7
+ };
8
+ g: {
9
+ positions: number[];
10
+ options?: never;
11
+ redactWith: string[];
12
+ allowOnly?: string[];
13
+ };
14
+ generate: {
15
+ positions: number[];
16
+ options?: never;
17
+ redactWith: string[];
18
+ allowOnly?: string[];
19
+ };
20
+ prisma: {
21
+ positions?: never;
22
+ options: string[];
23
+ redactWith: string[];
24
+ allowOnly?: string[];
25
+ };
26
+ lint: {
27
+ positions?: number[];
28
+ options?: never;
29
+ redactWith: string[];
30
+ allowOnly: string[];
31
+ };
32
+ }
33
+ export declare const sanitizeArgv: (argv: [string, string, keyof SensitiveArgPositions, ...string[]]) => string;
34
+ export declare const sendTelemetry: () => Promise<void>;
35
+ export {};
36
+ //# sourceMappingURL=sendTelemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendTelemetry.d.ts","sourceRoot":"","sources":["../src/sendTelemetry.ts"],"names":[],"mappings":"AAkBA,UAAU,qBAAqB;IAC7B,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,EAAE,MAAM,EAAE,CAAA;KACpB,CAAA;IACD,CAAC,EAAE;QACD,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,EAAE,CAAA;QACnB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,MAAM,EAAE;QACN,SAAS,CAAC,EAAE,KAAK,CAAA;QACjB,OAAO,EAAE,MAAM,EAAE,CAAA;QACjB,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;KACrB,CAAA;IACD,IAAI,EAAE;QACJ,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;QACpB,OAAO,CAAC,EAAE,KAAK,CAAA;QACf,UAAU,EAAE,MAAM,EAAE,CAAA;QACpB,SAAS,EAAE,MAAM,EAAE,CAAA;KACpB,CAAA;CACF;AA+ED,eAAO,MAAM,YAAY,SACjB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,qBAAqB,EAAE,GAAG,MAAM,EAAE,CAAC,WAyCjE,CAAA;AA4GD,eAAO,MAAM,aAAa,qBAmCzB,CAAA"}
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var sendTelemetry_exports = {};
30
+ __export(sendTelemetry_exports, {
31
+ sanitizeArgv: () => sanitizeArgv,
32
+ sendTelemetry: () => sendTelemetry
33
+ });
34
+ module.exports = __toCommonJS(sendTelemetry_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_os = __toESM(require("os"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_fetch = require("@whatwg-node/fetch");
39
+ var import_ci_info = __toESM(require("ci-info"));
40
+ var import_envinfo = __toESM(require("envinfo"));
41
+ var import_systeminformation = __toESM(require("systeminformation"));
42
+ var import_uuid = require("uuid");
43
+ var import_project_config = require("@cedarjs/project-config");
44
+ const { DefaultHost } = require("@cedarjs/structure/dist/hosts");
45
+ const { RWProject } = require("@cedarjs/structure/dist/model/RWProject");
46
+ const SENSITIVE_ARG_POSITIONS = {
47
+ exec: {
48
+ positions: [1],
49
+ redactWith: ["[script]"],
50
+ allowOnly: ["exec"]
51
+ },
52
+ g: {
53
+ positions: [2, 3],
54
+ redactWith: ["[name]", "[path]"]
55
+ },
56
+ generate: {
57
+ positions: [2, 3],
58
+ redactWith: ["[name]", "[path]"]
59
+ },
60
+ prisma: {
61
+ options: ["--name"],
62
+ redactWith: ["[name]"]
63
+ },
64
+ lint: {
65
+ allowOnly: ["lint", "--fix"],
66
+ redactWith: ["[path]"]
67
+ }
68
+ };
69
+ const getInfo = async (presets = {}) => {
70
+ const info = JSON.parse(
71
+ await import_envinfo.default.run(
72
+ {
73
+ System: ["OS", "Shell"],
74
+ Binaries: ["Node", "Yarn", "npm"],
75
+ npmPackages: "@cedarjs/*",
76
+ IDEs: ["VSCode"]
77
+ },
78
+ { json: true }
79
+ )
80
+ );
81
+ const shell = info.System?.Shell;
82
+ if (shell?.path?.match("/")) {
83
+ info.System.Shell.name = info.System.Shell.path.split("/").pop();
84
+ } else if (shell?.path.match("\\")) {
85
+ info.System.Shell.name = info.System.Shell.path.split("\\").pop();
86
+ }
87
+ const cpu = await import_systeminformation.default.cpu();
88
+ const mem = await import_systeminformation.default.mem();
89
+ const experiments = Object.keys((0, import_project_config.getRawConfig)()["experimental"] || {});
90
+ return {
91
+ os: info.System?.OS?.split(" ")[0],
92
+ osVersion: info.System?.OS?.split(" ")[1],
93
+ shell: info.System?.Shell?.name,
94
+ nodeVersion: info.Binaries?.Node?.version,
95
+ yarnVersion: info.Binaries?.Yarn?.version,
96
+ npmVersion: info.Binaries?.npm?.version,
97
+ vsCodeVersion: info.IDEs?.VSCode?.version,
98
+ redwoodVersion: presets.redwoodVersion || info.npmPackages?.["@cedarjs/core"]?.installed,
99
+ system: `${cpu.physicalCores}.${Math.round(mem.total / 1073741824)}`,
100
+ webBundler: "vite",
101
+ // Hardcoded as this is now the only supported bundler
102
+ experiments
103
+ };
104
+ };
105
+ const sanitizeArgv = (argv) => {
106
+ const name = argv[2];
107
+ const sensitiveCommand = SENSITIVE_ARG_POSITIONS[name];
108
+ const args = argv.slice(2);
109
+ if (sensitiveCommand) {
110
+ if (sensitiveCommand.positions) {
111
+ sensitiveCommand.positions.forEach((pos, index) => {
112
+ if (args[pos] && !args[pos].includes("--")) {
113
+ args[pos] = sensitiveCommand.redactWith[index];
114
+ }
115
+ });
116
+ }
117
+ if (sensitiveCommand.options) {
118
+ sensitiveCommand.options.forEach((option, index) => {
119
+ const argIndex = args.indexOf(option);
120
+ if (argIndex !== -1) {
121
+ args[argIndex + 1] = sensitiveCommand.redactWith[index];
122
+ }
123
+ });
124
+ }
125
+ if (sensitiveCommand.allowOnly) {
126
+ args.forEach((arg, index) => {
127
+ if (!sensitiveCommand.allowOnly?.includes(arg) && !sensitiveCommand.redactWith.includes(arg)) {
128
+ args[index] = sensitiveCommand.redactWith[0];
129
+ }
130
+ });
131
+ }
132
+ }
133
+ return args.join(" ");
134
+ };
135
+ const buildPayload = async () => {
136
+ let payload = {};
137
+ let project;
138
+ const processArgv = [...process.argv];
139
+ if (import_os.default.type() === "Windows_NT") {
140
+ const argvIndex = processArgv.findIndex((arg) => arg === "--argv") + 1;
141
+ let argvFormatted = argvIndex !== 0 ? processArgv[argvIndex] : null;
142
+ if (argvFormatted) {
143
+ argvFormatted = "[" + argvFormatted.substring(1, argvFormatted.length - 1).split(",").map((arg) => {
144
+ return arg.startsWith('"') || arg.startsWith("'") ? arg : `"${arg}"`;
145
+ }).join(",") + "]";
146
+ processArgv[argvIndex] = argvFormatted;
147
+ }
148
+ }
149
+ const argv = require("yargs/yargs")(processArgv.slice(2)).parse();
150
+ const rootDir = argv.root;
151
+ const command = argv.argv ? sanitizeArgv(JSON.parse(argv.argv)) : "";
152
+ payload = {
153
+ type: argv.type || "command",
154
+ command,
155
+ duration: argv.duration ? parseInt(argv.duration) : null,
156
+ uid: uniqueId(rootDir) || null,
157
+ ci: import_ci_info.default.isCI,
158
+ redwoodCi: !!process.env.REDWOOD_CI,
159
+ NODE_ENV: process.env.NODE_ENV || null,
160
+ ...await getInfo({ redwoodVersion: argv.rwVersion, command })
161
+ };
162
+ if (argv.error) {
163
+ payload.type = "error";
164
+ payload.error = argv.error.split("\n")[0].replace(/(\/[@\-\.\w]+)/g, "[path]");
165
+ }
166
+ if (rootDir) {
167
+ project = new RWProject({
168
+ projectRoot: rootDir,
169
+ host: new DefaultHost()
170
+ });
171
+ }
172
+ const routes = project.getRouter().routes;
173
+ const prerenderedRoutes = routes.filter((route) => route.hasPrerender);
174
+ payload = {
175
+ ...payload,
176
+ complexity: `${routes.length}.${prerenderedRoutes.length}.${project.services.length}.${project.cells.length}.${project.pages.length}`,
177
+ sides: project.sides.join(",")
178
+ };
179
+ return payload;
180
+ };
181
+ const uniqueId = (rootDir) => {
182
+ const telemetryCachePath = import_path.default.join(
183
+ rootDir || "/tmp",
184
+ ".redwood",
185
+ "telemetry.txt"
186
+ );
187
+ const now = Date.now();
188
+ const expires = now - 24 * 60 * 60 * 1e3;
189
+ let uuid;
190
+ if (!import_fs.default.existsSync(telemetryCachePath) || import_fs.default.statSync(telemetryCachePath).mtimeMs < expires) {
191
+ uuid = (0, import_uuid.v4)();
192
+ try {
193
+ if (!import_fs.default.existsSync(import_path.default.dirname(telemetryCachePath))) {
194
+ import_fs.default.mkdirSync(import_path.default.dirname(telemetryCachePath), { recursive: true });
195
+ }
196
+ import_fs.default.writeFileSync(telemetryCachePath, uuid);
197
+ } catch {
198
+ console.error("\nCould not create telemetry.txt file\n");
199
+ }
200
+ } else {
201
+ uuid = import_fs.default.readFileSync(telemetryCachePath).toString();
202
+ }
203
+ return uuid;
204
+ };
205
+ const sendTelemetry = async () => {
206
+ const telemetryUrl = process.env.REDWOOD_REDIRECT_TELEMETRY || "https://telemetry.redwoodjs.com/api/v1/telemetry";
207
+ try {
208
+ const payload = await buildPayload();
209
+ if (process.env.REDWOOD_VERBOSE_TELEMETRY) {
210
+ console.info("Redwood Telemetry Payload", payload);
211
+ }
212
+ const response = await (0, import_fetch.fetch)(telemetryUrl, {
213
+ method: "post",
214
+ body: JSON.stringify(payload),
215
+ headers: { "Content-Type": "application/json" }
216
+ });
217
+ if (process.env.REDWOOD_VERBOSE_TELEMETRY) {
218
+ console.info("Redwood Telemetry Response:", response);
219
+ }
220
+ if (process.env.REDWOOD_VERBOSE_TELEMETRY && response.status !== 200) {
221
+ console.error("Error from telemetry insert:", await response.text());
222
+ }
223
+ } catch (e) {
224
+ if (process.env.REDWOOD_VERBOSE_TELEMETRY) {
225
+ console.error("Uncaught error in telemetry:", e);
226
+ }
227
+ }
228
+ };
229
+ // Annotate the CommonJS export names for ESM import in node:
230
+ 0 && (module.exports = {
231
+ sanitizeArgv,
232
+ sendTelemetry
233
+ });
@@ -0,0 +1,4 @@
1
+ export declare const timedTelemetry: (argv: string[], options: Record<string, unknown>, func: (...args: any[]) => any) => Promise<any>;
2
+ export declare const errorTelemetry: (argv: string[], error: any) => Promise<void>;
3
+ export declare const telemetryMiddleware: () => Promise<void>;
4
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AA2CA,eAAO,MAAM,cAAc,SACnB,MAAM,EAAE,WACL,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QAC1B,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,iBAoB9B,CAAA;AAED,eAAO,MAAM,cAAc,SAAgB,MAAM,EAAE,SAAS,GAAG,kBAM9D,CAAA;AAGD,eAAO,MAAM,mBAAmB,qBAM/B,CAAA"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var telemetry_exports = {};
30
+ __export(telemetry_exports, {
31
+ errorTelemetry: () => errorTelemetry,
32
+ telemetryMiddleware: () => telemetryMiddleware,
33
+ timedTelemetry: () => timedTelemetry
34
+ });
35
+ module.exports = __toCommonJS(telemetry_exports);
36
+ var import_child_process = require("child_process");
37
+ var import_os = __toESM(require("os"));
38
+ var import_path = __toESM(require("path"));
39
+ var import_project_config = require("@cedarjs/project-config");
40
+ const spawnProcess = (...args) => {
41
+ const execPath = import_os.default.type() === "Windows_NT" ? `"${process.execPath}"` : process.execPath;
42
+ const spawnOptions = import_os.default.type() === "Windows_NT" ? {
43
+ stdio: process.env.REDWOOD_VERBOSE_TELEMETRY ? ["ignore", "inherit", "inherit"] : "ignore",
44
+ // The following options run the process in the background without a console window, even though they don't look like they would.
45
+ // See https://github.com/nodejs/node/issues/21825#issuecomment-503766781 for information
46
+ detached: false,
47
+ windowsHide: false,
48
+ shell: true
49
+ } : {
50
+ stdio: process.env.REDWOOD_VERBOSE_TELEMETRY ? ["ignore", "inherit", "inherit"] : "ignore",
51
+ detached: process.env.REDWOOD_VERBOSE_TELEMETRY ? false : true,
52
+ windowsHide: true
53
+ };
54
+ (0, import_child_process.spawn)(
55
+ execPath,
56
+ [
57
+ import_path.default.join(__dirname, "scripts", "invoke.js"),
58
+ ...args,
59
+ "--root",
60
+ (0, import_project_config.getPaths)().base
61
+ ],
62
+ spawnOptions
63
+ ).unref();
64
+ };
65
+ const timedTelemetry = async (argv, options, func) => {
66
+ if (process.env.REDWOOD_DISABLE_TELEMETRY) {
67
+ return func.call(void 0);
68
+ }
69
+ const start = /* @__PURE__ */ new Date();
70
+ const result = await func.call(void 0);
71
+ const duration = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
72
+ spawnProcess(
73
+ "--argv",
74
+ JSON.stringify(argv),
75
+ "--duration",
76
+ duration.toString(),
77
+ "--type",
78
+ JSON.stringify(options.type)
79
+ );
80
+ return result;
81
+ };
82
+ const errorTelemetry = async (argv, error) => {
83
+ if (process.env.REDWOOD_DISABLE_TELEMETRY) {
84
+ return;
85
+ }
86
+ spawnProcess("--argv", JSON.stringify(argv), "--error", JSON.stringify(error));
87
+ };
88
+ const telemetryMiddleware = async () => {
89
+ if (process.env.REDWOOD_DISABLE_TELEMETRY) {
90
+ return;
91
+ }
92
+ spawnProcess("--argv", JSON.stringify(process.argv));
93
+ };
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ errorTelemetry,
97
+ telemetryMiddleware,
98
+ timedTelemetry
99
+ });
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@cedarjs/telemetry",
3
+ "version": "0.0.4",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/cedarjs/cedar.git",
7
+ "directory": "packages/telemetry"
8
+ },
9
+ "license": "MIT",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsx build.mts && yarn build:types",
17
+ "build:pack": "yarn pack -o cedar-telemetry.tgz",
18
+ "build:types": "tsc --build --verbose",
19
+ "prepublishOnly": "NODE_ENV=production yarn build",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest watch"
22
+ },
23
+ "dependencies": {
24
+ "@cedarjs/project-config": "0.0.4",
25
+ "@cedarjs/structure": "0.0.4",
26
+ "@whatwg-node/fetch": "0.9.21",
27
+ "ci-info": "4.0.0",
28
+ "envinfo": "7.14.0",
29
+ "systeminformation": "5.23.8",
30
+ "uuid": "10.0.0",
31
+ "yargs": "17.7.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/envinfo": "7.8.4",
35
+ "@types/uuid": "10.0.0",
36
+ "@types/yargs": "17.0.33",
37
+ "tsx": "4.19.3",
38
+ "typescript": "5.6.2",
39
+ "vitest": "2.1.9"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "gitHead": "5b4f77f985bd86ee31ee7338312627accf0cb85b"
45
+ }