Skip to content

Commit e9b82d5

Browse files
authored
Merge pull request #534 from gitKrystan/less-telemetry
Only get telemetry if transform is actually needed
2 parents f4d4efb + 2c777c5 commit e9b82d5

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

transforms/helpers/import-helper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { default as j } from 'jscodeshift';
22
import * as AST from '../helpers/ast';
33
import type { DecoratorImportInfoMap } from './decorator-info';
44
import { getDecoratorImportInfo } from './decorator-info';
5-
import type { Options } from './options';
5+
import type { UserOptions } from './options';
66
import {
77
createEmberDecoratorSpecifiers,
88
createImportDeclaration,
@@ -87,11 +87,11 @@ function createNewImportDeclarations(
8787
decoratorsToImport: string[],
8888
/** Already imported paths */
8989
decoratorPathsToIgnore: string[],
90-
options: Options
90+
userOptions: UserOptions
9191
): void {
9292
const firstDeclaration = AST.getFirstDeclaration(root);
9393

94-
if (options.classicDecorator) {
94+
if (userOptions.classicDecorator) {
9595
firstDeclaration.insertBefore(
9696
createImportDeclaration(
9797
[j.importDefaultSpecifier(j.identifier('classic'))],
@@ -236,7 +236,7 @@ function getExistingImportForPath(
236236
export function createDecoratorImportDeclarations(
237237
root: AST.Collection,
238238
decoratorsToImport: string[],
239-
options: Options
239+
userOptions: UserOptions
240240
): void {
241241
// Iterate through existing imports, extract the already imported specifiers
242242
const decoratorPathSpecifierMap = getDecoratorPathSpecifiers(
@@ -272,7 +272,7 @@ export function createDecoratorImportDeclarations(
272272
root,
273273
decoratorsToImport,
274274
decoratorPathsImported,
275-
options
275+
userOptions
276276
);
277277
}
278278

transforms/helpers/transform.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@ export default function maybeTransformEmberObjects(
2020
filePath: string,
2121
userOptions: UserOptions
2222
): boolean {
23-
const options: Options = {
24-
...userOptions,
25-
runtimeData: getRuntimeData(filePath),
26-
};
27-
2823
const { results, decoratorImportSpecs } = _maybeTransformEmberObjects(
2924
root,
3025
filePath,
31-
options
26+
userOptions
3227
);
3328

3429
for (const result of results) {
@@ -44,15 +39,15 @@ export default function maybeTransformEmberObjects(
4439
const decoratorsToImport = Object.keys(decoratorImportSpecs).filter(
4540
(key) => decoratorImportSpecs[key as keyof DecoratorImportSpecs]
4641
);
47-
createDecoratorImportDeclarations(root, decoratorsToImport, options);
42+
createDecoratorImportDeclarations(root, decoratorsToImport, userOptions);
4843

4944
return results.length > 0 && results.every((r) => r.success);
5045
}
5146

5247
function _maybeTransformEmberObjects(
5348
root: AST.Collection,
5449
filePath: string,
55-
options: Options
50+
userOptions: UserOptions
5651
): {
5752
results: TransformResult[];
5853
decoratorImportSpecs: DecoratorImportSpecs;
@@ -79,27 +74,32 @@ function _maybeTransformEmberObjects(
7974
filePath,
8075
info: "UNMODIFIED: Did not find any 'EmberObject.extend()' expressions",
8176
});
82-
}
77+
} else {
78+
const options: Options = {
79+
...userOptions,
80+
runtimeData: getRuntimeData(filePath),
81+
};
8382

84-
// eslint-disable-next-line unicorn/no-array-for-each
85-
eoExtendExpressionPaths.forEach((eoExtendExpressionPath) => {
86-
const extendExpression = new EOExtendExpression(
87-
eoExtendExpressionPath,
88-
filePath,
89-
existingDecoratorImportInfos,
90-
options
91-
);
83+
// eslint-disable-next-line unicorn/no-array-for-each
84+
eoExtendExpressionPaths.forEach((eoExtendExpressionPath) => {
85+
const extendExpression = new EOExtendExpression(
86+
eoExtendExpressionPath,
87+
filePath,
88+
existingDecoratorImportInfos,
89+
options
90+
);
9291

93-
const result = extendExpression.transform();
94-
results.push(result);
92+
const result = extendExpression.transform();
93+
results.push(result);
9594

96-
if (result.success) {
97-
decoratorImportSpecs = mergeDecoratorImportSpecs(
98-
extendExpression.decoratorImportSpecs,
99-
decoratorImportSpecs
100-
);
101-
}
102-
});
95+
if (result.success) {
96+
decoratorImportSpecs = mergeDecoratorImportSpecs(
97+
extendExpression.decoratorImportSpecs,
98+
decoratorImportSpecs
99+
);
100+
}
101+
});
102+
}
103103

104104
return { results, decoratorImportSpecs };
105105
}

0 commit comments

Comments
 (0)