Skip to content

Commit ed1973b

Browse files
committed
Add custom gatherFn for telemetry
1 parent ab5fbf7 commit ed1973b

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

transforms/no-implicit-this/helpers/options.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { getOptions as getCodemodOptions, runTransform } from 'codemod-cli';
22
import Debug from 'debug';
3-
import {
4-
analyzeEmberObject,
5-
gatherTelemetryForUrl,
6-
getTelemetry,
7-
} from 'ember-codemods-telemetry-helpers';
3+
import { gatherTelemetryForUrl, getTelemetry } from 'ember-codemods-telemetry-helpers';
84
import fs from 'node:fs';
95
import http from 'node:http';
106
import path from 'node:path';
117
import yargs from 'yargs';
128
import { ZodError, ZodType, z } from 'zod';
139
import { assert } from '../../../helpers/types';
1410
import Resolver, { EmbroiderResolver, MockResolver, RuntimeResolver } from './resolver';
11+
import { RuntimeData } from './telemetry';
1512

1613
const debug = Debug('ember-no-implicit-this-codemod');
1714

@@ -128,7 +125,16 @@ export class Runner {
128125

129126
if (telemetryType === 'runtime') {
130127
debug('Gathering telemetry data from %s ...', this.options.url);
131-
await gatherTelemetryForUrl(this.options.url, analyzeEmberObject);
128+
await gatherTelemetryForUrl(
129+
this.options.url,
130+
(_module: unknown, modulePath: string): RuntimeData | void => {
131+
if (modulePath.startsWith('pyckle/helpers/')) {
132+
return { type: 'Helper' };
133+
} else if (modulePath.startsWith('pyckle/components/')) {
134+
return { type: 'Component' };
135+
}
136+
}
137+
);
132138

133139
const telemetry = getTelemetry() as Record<string, unknown>; // FIXME
134140
debug('Gathered telemetry on %d modules', Object.keys(telemetry).length);

transforms/no-implicit-this/helpers/telemetry.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,10 @@ import { getTelemetry as getRawTelemetry } from 'ember-codemods-telemetry-helper
22
import { z } from 'zod';
33

44
const RuntimeData = z.object({
5-
type: z.string().optional(),
6-
computedProperties: z.array(z.string()).default([]),
7-
offProperties: z.record(z.array(z.string())).default({}),
8-
overriddenActions: z.array(z.string()).default([]),
9-
overriddenProperties: z.array(z.string()).default([]),
10-
unobservedProperties: z.record(z.array(z.string())).default({}),
5+
type: z.union([z.literal('Component'), z.literal('Helper')]),
116
});
127

13-
type RuntimeData = z.infer<typeof RuntimeData>;
8+
export type RuntimeData = z.infer<typeof RuntimeData>;
149

1510
export const Telemetry = z.record(RuntimeData);
1611

types/ember-codemods-telemetry-helpers.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ declare module 'ember-codemods-telemetry-helpers' {
22
export function getTelemetry(): unknown;
33
export function getTelemetryFor(filePath: string): unknown;
44
export function setTelemetry(telemetry: unknown): void;
5-
export function gatherTelemetryForUrl(url: string, gatherFn: () => unknown): Promise<unknown>;
6-
export function analyzeEmberObject(): unknown;
5+
export function gatherTelemetryForUrl<T extends unknown[]>(
6+
url: string,
7+
gatherFn: (module: unknown, path: string, ...args: T) => unknown,
8+
...args: T
9+
): Promise<unknown>;
710
}

0 commit comments

Comments
 (0)