Skip to content

Commit 87d1095

Browse files
committed
Add NO_TELEMETRY config
1 parent e689b90 commit 87d1095

File tree

11 files changed

+34
-19
lines changed

11 files changed

+34
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
*.log
33
.eslintcache
4+
transforms/**/*.js
5+
!transforms/ember-object/__testfixtures__/**/*.js

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ If you have any _lazily loaded_ modules, such as modules from Ember Engines,
5050
you'll need to make sure that the URL you provide loads these modules as well.
5151
Otherwise, the codemod will not be able to detect them or analyze them.
5252

53+
To disable this feature, run with `NO_TELEMETRY=true` and omit the path to your local server:
54+
55+
```shell
56+
NO_TELEMETRY=true npx ember-native-class-codemod [OPTIONS] path/of/files/ or/some**/*glob.js
57+
```
58+
5359
### Types
5460

5561
The `type` option can be used to further narrow down transforms to a particular type of

bin/cli.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
const { gatherTelemetryForUrl, analyzeEmberObject } = require('ember-codemods-telemetry-helpers');
55

66
(async () => {
7-
await gatherTelemetryForUrl(process.argv[2], analyzeEmberObject);
7+
let args = process.argv.slice(2);
8+
if (process.env['NO_TELEMETRY'] !== 'true') {
9+
await gatherTelemetryForUrl(process.argv[2], analyzeEmberObject);
10+
args = process.argv.slice(1);
11+
}
812

9-
require('codemod-cli').runTransform(
10-
__dirname,
11-
'ember-object',
12-
process.argv.slice(2) /* paths or globs */
13-
);
13+
require('codemod-cli').runTransform(__dirname, 'ember-object', args);
1414
})();

transforms/helpers/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export default function getConfig(dir = process.cwd()): UserOptions {
2222
getFileConfig(dir),
2323
getCliConfig()
2424
);
25+
if (process.env['NO_TELEMETRY'] === 'true') {
26+
config.noTelemetry = true;
27+
}
2528
return UserOptionsSchema.parse(config);
2629
}
2730

transforms/helpers/decorator-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { assert } from './util/types';
2-
import { COMPUTED_DECORATOR_NAME, METHOD_DECORATORS } from './util/index';
31
import type * as AST from '../helpers/ast';
2+
import { COMPUTED_DECORATOR_NAME, METHOD_DECORATORS } from './util/index';
3+
import { assert } from './util/types';
44

55
export interface DecoratorImportInfo {
66
name: string;

transforms/helpers/eo-prop/private/abstract.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default abstract class AbstractEOProp<
3636

3737
protected decorators: DecoratorImportInfo[] = [];
3838

39-
protected readonly runtimeData: RuntimeData;
39+
protected readonly runtimeData: RuntimeData | null;
4040

4141
/**
4242
* Override to `true` if the property type supports object literal decorators
@@ -55,7 +55,7 @@ export default abstract class AbstractEOProp<
5555
protected readonly options: Options
5656
) {
5757
this.runtimeData = options.runtimeData;
58-
if (this.runtimeData.type) {
58+
if (this.runtimeData) {
5959
const { offProperties, unobservedProperties } = this.runtimeData;
6060

6161
const unobservedArgs = unobservedProperties[this.name];
@@ -163,15 +163,15 @@ export default abstract class AbstractEOProp<
163163
}
164164

165165
protected get isOverridden(): boolean {
166-
return this.runtimeData.overriddenProperties.includes(this.name);
166+
return this.runtimeData?.overriddenProperties.includes(this.name) ?? false;
167167
}
168168

169169
protected get replaceSuperWithUndefined(): boolean {
170170
return this.hasRuntimeData && !this.isOverridden;
171171
}
172172

173173
private get hasRuntimeData(): boolean {
174-
return !!this.runtimeData.type;
174+
return this.runtimeData !== null;
175175
}
176176

177177
protected get hasDecorators(): boolean {

transforms/helpers/eo-prop/private/actions/method.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ export default class EOActionMethod extends EOMethod implements Action {
8787
}
8888

8989
protected override get isOverridden(): boolean {
90-
return this.runtimeData.overriddenActions.includes(this.name);
90+
return this.runtimeData?.overriddenActions.includes(this.name) ?? false;
9191
}
9292
}

transforms/helpers/eo-prop/private/computed/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function getDecorators(
9999
const decoratorImportInfo = existingDecoratorImportInfos.get(calleeName);
100100
if (decoratorImportInfo) {
101101
decorators.push(decoratorImportInfo);
102-
} else if (options.runtimeData.computedProperties.includes(raw.key.name)) {
102+
} else if (options.runtimeData?.computedProperties.includes(raw.key.name)) {
103103
decorators.push({ name: calleeName });
104104
}
105105
return decorators;

transforms/helpers/options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export const UserOptionsSchema = z.object({
9797
ignoreLeakingState: StringArraySchema.describe(
9898
'Allow-list for ObjectExpression or ArrayExpression properties to ignore issues detailed in eslint-plugin-ember/avoid-leaking-state-in-ember-objects.'
9999
),
100+
noTelemetry: StringBooleanSchema.describe(
101+
'Disable telemetry. Enabled by default.'
102+
),
100103
type: TypeSchema.describe(
101104
'Apply transformation to only passed type.'
102105
).optional(),
@@ -145,7 +148,7 @@ function logConfigError(
145148

146149
interface PrivateOptions {
147150
/** @private */
148-
runtimeData: RuntimeData;
151+
runtimeData: RuntimeData | null;
149152
}
150153

151154
export type Options = UserOptions & PrivateOptions;
@@ -156,6 +159,7 @@ export const DEFAULT_OPTIONS: UserOptions = {
156159
classicDecorator: true,
157160
quote: 'single',
158161
ignoreLeakingState: ['queryParams'],
162+
noTelemetry: false,
159163
};
160164

161165
class ConfigError extends Error {

transforms/helpers/runtime-data.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ export type RuntimeData = z.infer<typeof RuntimeDataSchema>;
1818
* Gets telemetry data for the file and parses it into a valid `RuntimeData`
1919
* object.
2020
*/
21-
export function getRuntimeData(filePath: string): RuntimeData {
22-
let rawTelemetry = getTelemetryFor(path.resolve(filePath));
21+
export function getRuntimeData(filePath: string): RuntimeData | null {
22+
const rawTelemetry = getTelemetryFor(path.resolve(filePath));
2323
if (!rawTelemetry) {
2424
// Do not re-throw. The most likely reason this happened was because
2525
// the user's app threw an error. We still want the codemod to work if so.
2626
logger.error({
2727
filePath,
2828
error: new RuntimeDataError('Could not find runtime data'),
2929
});
30-
rawTelemetry = {};
30+
return null;
3131
}
3232

3333
const result = RuntimeDataSchema.safeParse(rawTelemetry);

0 commit comments

Comments
 (0)