Skip to content

Commit 255e935

Browse files
committed
fix(codemods): don't generate interfaces for javascript files
1 parent 7b31bc0 commit 255e935

File tree

7 files changed

+135
-315
lines changed

7 files changed

+135
-315
lines changed

packages/codemods/src/legacy-compat-builders/options.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { SharedCodemodOptions } from '../../bin/index.js';
2-
31
import type { LegacyStoreMethod } from './config.js';
2+
import type { SharedCodemodOptions } from '../../bin/index.js';
43

54
export interface Options extends SharedCodemodOptions {
65
storeNames: string[];

packages/codemods/src/schema-migration/utils/schema-generation.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -667,30 +667,31 @@ export function generateMergedSchemaCode(opts: MergedSchemaOptions): string {
667667
// Generate default export
668668
sections.push(`\nexport default ${schemaName};`);
669669

670-
// Generate interface (only for TypeScript)
671-
if (useComposite) {
672-
// Composite pattern: field interface is {Name}Trait, composite is {Name}
673-
const fieldInterfaceName = `${interfaceName}Trait`;
674-
const fieldInterfaceCode = generateInterfaceOnly(fieldInterfaceName, properties);
675-
sections.push('');
676-
sections.push(fieldInterfaceCode);
677-
678-
// Composite interface merges field interface, extension, and trait interfaces
679-
const traitInterfaces = traits.map(traitNameToInterfaceName);
680-
const compositeExtends = [fieldInterfaceName, extensionName, ...traitInterfaces].join(', ');
681-
sections.push('');
682-
sections.push(`export interface ${interfaceName} extends ${compositeExtends} {}`);
683-
} else {
684-
// Standard pattern: single interface with optional trait extends
685-
let extendsClause: string | undefined;
686-
if (traits.length > 0) {
670+
if (isTypeScript) {
671+
if (useComposite) {
672+
// Composite pattern: field interface is {Name}Trait, composite is {Name}
673+
const fieldInterfaceName = `${interfaceName}Trait`;
674+
const fieldInterfaceCode = generateInterfaceOnly(fieldInterfaceName, properties);
675+
sections.push('');
676+
sections.push(fieldInterfaceCode);
677+
678+
// Composite interface merges field interface, extension, and trait interfaces
687679
const traitInterfaces = traits.map(traitNameToInterfaceName);
688-
extendsClause = traitInterfaces.join(', ');
689-
}
680+
const compositeExtends = [fieldInterfaceName, extensionName, ...traitInterfaces].join(', ');
681+
sections.push('');
682+
sections.push(`export interface ${interfaceName} extends ${compositeExtends} {}`);
683+
} else {
684+
// Standard pattern: single interface with optional trait extends
685+
let extendsClause: string | undefined;
686+
if (traits.length > 0) {
687+
const traitInterfaces = traits.map(traitNameToInterfaceName);
688+
extendsClause = traitInterfaces.join(', ');
689+
}
690690

691-
const interfaceCode = generateInterfaceOnly(interfaceName, properties, extendsClause);
692-
sections.push('');
693-
sections.push(interfaceCode);
691+
const interfaceCode = generateInterfaceOnly(interfaceName, properties, extendsClause);
692+
sections.push('');
693+
sections.push(interfaceCode);
694+
}
694695
}
695696

696697
return sections.join('\n');

tests/codemods/tests/schema-migration/__snapshots__/migrate-to-schema.test.ts.snap

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -768,12 +768,7 @@ const JsModelWithMixinSchema = {
768768
]
769769
};
770770
771-
export default JsModelWithMixinSchema;
772-
773-
export interface JsModelWithMixin extends JsTrait {
774-
readonly [Type]: 'js-model-with-mixin';
775-
readonly name: string | null;
776-
}",
771+
export default JsModelWithMixinSchema;",
777772
"resources/ts-model-with-mixin.schema.ts": "
778773
import type { Type } from '@ember-data/core-types/symbols';
779774
import type { TsTrait } from 'test-app/data/traits/ts.schema';
@@ -819,11 +814,7 @@ const JsMixinSchema = {
819814
]
820815
};
821816
822-
export default JsMixinSchema;
823-
824-
export interface JsMixinTrait {
825-
createdAt: Date | null;
826-
}",
817+
export default JsMixinSchema;",
827818
"traits/ts-mixin.ext.ts": "
828819
import Mixin from '@ember/object/mixin';
829820
import { attr } from '@ember-data/model';
@@ -1114,32 +1105,7 @@ const BaseModelWithMethodsTrait = {
11141105
]
11151106
};
11161107
1117-
export default BaseModelWithMethodsTrait;
1118-
1119-
export interface BaseModelWithMethodsTrait {
1120-
id: string | null;
1121-
readonly baseField: string | null;
1122-
readonly isNew: boolean;
1123-
readonly hasDirtyAttributes: boolean;
1124-
readonly isDeleted: boolean;
1125-
readonly isSaving: boolean;
1126-
readonly isValid: boolean;
1127-
readonly isError: boolean;
1128-
readonly isLoaded: boolean;
1129-
readonly isEmpty: boolean;
1130-
save: (options?: Record<string, unknown>) => Promise<this>;
1131-
reload: (options?: Record<string, unknown>) => Promise<this>;
1132-
deleteRecord: () => void;
1133-
unloadRecord: () => void;
1134-
destroyRecord: (options?: Record<string, unknown>) => Promise<void>;
1135-
rollbackAttributes: () => void;
1136-
belongsTo: (propertyName: string) => BelongsToReference;
1137-
hasMany: (propertyName: string) => HasManyReference;
1138-
serialize: (options?: Record<string, unknown>) => unknown;
1139-
readonly errors: Errors;
1140-
readonly adapterError: Error | null;
1141-
readonly isReloading: boolean;
1142-
}",
1108+
export default BaseModelWithMethodsTrait;",
11431109
}
11441110
`;
11451111

@@ -1167,11 +1133,7 @@ const CustomSelectOptionSchema = {
11671133
]
11681134
};
11691135
1170-
export default CustomSelectOptionSchema;
1171-
1172-
export interface CustomSelectOption {
1173-
readonly [Type]: 'custom-select-option';
1174-
}",
1136+
export default CustomSelectOptionSchema;",
11751137
}
11761138
`;
11771139

tests/codemods/tests/schema-migration/transforms/__snapshots__/mixin-to-schema.test.ts.snap

Lines changed: 18 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > gen
2121
]
2222
};
2323
24-
export default SimpleSchema;
25-
26-
export interface SimpleTrait {
27-
title: string | null;
28-
author: Promise<User>;
29-
}"
24+
export default SimpleSchema;"
3025
`;
3126

3227
exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > generates trait and extension artifacts when mixin has computed properties and methods > mixin extension code 1`] = `
@@ -57,11 +52,7 @@ exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > gen
5752
]
5853
};
5954
60-
export default NameableSchema;
61-
62-
export interface NameableTrait {
63-
name: string | null;
64-
}"
55+
export default NameableSchema;"
6556
`;
6657
6758
exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > generates trait artifact with merged types for basic mixins > basic trait type interface 1`] = `
@@ -94,13 +85,7 @@ exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > gen
9485
]
9586
};
9687
97-
export default FileableSchema;
98-
99-
export interface FileableTrait {
100-
files: HasMany<File>;
101-
name: string | null;
102-
isActive: boolean | null;
103-
}"
88+
export default FileableSchema;"
10489
`;
10590
10691
exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > handles custom type mappings in mixin trait type interfaces > mixin custom type mappings interface 1`] = `
@@ -126,13 +111,7 @@ exports[`mixin-to-schema transform (artifacts) > TypeScript type artifacts > han
126111
]
127112
};
128113
129-
export default TypedSchema;
130-
131-
export interface TypedTrait {
132-
id: string | null;
133-
amount: number | null;
134-
metadata: Record<string, unknown> | null;
135-
}"
114+
export default TypedSchema;"
136115
`;
137116
138117
exports[`mixin-to-schema transform (artifacts) > basic functionality > collects the real fileable mixin shape into trait and extension artifacts > artifact metadata 1`] = `
@@ -206,12 +185,7 @@ exports[`mixin-to-schema transform (artifacts) > basic functionality > collects
206185
]
207186
};
208187
209-
export default FileableSchema;
210-
211-
export interface FileableTrait {
212-
files: HasMany<File>;
213-
showFilesRequiringReviewError: boolean | null;
214-
}"
188+
export default FileableSchema;"
215189
`;
216190
217191
exports[`mixin-to-schema transform (artifacts) > basic functionality > converts mixin with no trait fields to extension artifact > code 1`] = `
@@ -307,11 +281,7 @@ exports[`mixin-to-schema transform (artifacts) > basic functionality > supports
307281
]
308282
};
309283
310-
export default AliasedSchema;
311-
312-
export interface AliasedTrait {
313-
name: string | null;
314-
}"
284+
export default AliasedSchema;"
315285
`;
316286
317287
exports[`mixin-to-schema transform (artifacts) > basic functionality > supports alias of Mixin import and still produces a trait artifact > metadata 1`] = `
@@ -356,12 +326,7 @@ export interface File {
356326
]
357327
};
358328
359-
export default CustomSourceSchema;
360-
361-
export interface CustomSourceTrait {
362-
name: string | null;
363-
files: HasMany<File>;
364-
}",
329+
export default CustomSourceSchema;",
365330
"name": "CustomSourceSchema",
366331
"suggestedFileName": "custom-source.schema.js",
367332
"type": "trait",
@@ -408,11 +373,7 @@ export interface File {
408373
]
409374
};
410375
411-
export default RenamedMixedSourcesSchema;
412-
413-
export interface RenamedMixedSourcesTrait {
414-
files: HasMany<File>;
415-
}",
376+
export default RenamedMixedSourcesSchema;",
416377
"name": "RenamedMixedSourcesSchema",
417378
"suggestedFileName": "renamed-mixed-sources.schema.js",
418379
"type": "trait",
@@ -447,11 +408,7 @@ exports[`mixin-to-schema transform (artifacts) > import validation > handles CLI
447408
]
448409
};
449410
450-
export default CliOptionSchema;
451-
452-
export interface CliOptionTrait {
453-
name: string | null;
454-
}",
411+
export default CliOptionSchema;",
455412
"name": "CliOptionSchema",
456413
"suggestedFileName": "cli-option.schema.js",
457414
"type": "trait",
@@ -508,13 +465,7 @@ export interface User {
508465
]
509466
};
510467
511-
export default AliasedImportsSchema;
512-
513-
export interface AliasedImportsTrait {
514-
name: string | null;
515-
files: HasMany<File>;
516-
owner: User | null;
517-
}",
468+
export default AliasedImportsSchema;",
518469
"name": "AliasedImportsSchema",
519470
"suggestedFileName": "aliased-imports.schema.js",
520471
"type": "trait",
@@ -537,11 +488,7 @@ exports[`mixin-to-schema transform (artifacts) > import validation > ignores dec
537488
]
538489
};
539490
540-
export default UnsupportedSourceSchema;
541-
542-
export interface UnsupportedSourceTrait {
543-
name: string | null;
544-
}",
491+
export default UnsupportedSourceSchema;",
545492
"name": "UnsupportedSourceSchema",
546493
"suggestedFileName": "unsupported-source.schema.js",
547494
"type": "trait",
@@ -606,12 +553,7 @@ export interface File {
606553
]
607554
};
608555
609-
export default DefaultSourceSchema;
610-
611-
export interface DefaultSourceTrait {
612-
name: string | null;
613-
files: HasMany<File>;
614-
}",
556+
export default DefaultSourceSchema;",
615557
"import Mixin from '@ember/object/mixin';
616558
import { attr, hasMany } from '@ember-data/model';
617559
import { computed } from '@ember/object';
@@ -652,11 +594,7 @@ export interface User {
652594
]
653595
};
654596
655-
export default BelongsToSchema;
656-
657-
export interface BelongsToTrait {
658-
owner: Promise<User>;
659-
}",
597+
export default BelongsToSchema;",
660598
"name": "BelongsToSchema",
661599
"suggestedFileName": "belongs-to.schema.js",
662600
"type": "trait",
@@ -673,10 +611,7 @@ exports[`mixin-to-schema transform (artifacts) > import validation > produces an
673611
'fields': []
674612
};
675613
676-
export default NoValidImportsSchema;
677-
678-
export interface NoValidImportsTrait {
679-
}",
614+
export default NoValidImportsSchema;",
680615
"name": "NoValidImportsSchema",
681616
"suggestedFileName": "no-valid-imports.schema.js",
682617
"type": "trait",
@@ -729,12 +664,7 @@ export interface File {
729664
]
730665
};
731666
732-
export default AuditboardSourceSchema;
733-
734-
export interface AuditboardSourceTrait {
735-
name: string | null;
736-
files: HasMany<File>;
737-
}",
667+
export default AuditboardSourceSchema;",
738668
"name": "AuditboardSourceSchema",
739669
"suggestedFileName": "auditboard-source.schema.js",
740670
"type": "trait",
@@ -794,12 +724,7 @@ exports[`mixin-to-schema transform (artifacts) > mixin inheritance > produces tr
794724
]
795725
};
796726
797-
export default FileableSchema;
798-
799-
export interface FileableTrait extends BaseModelTrait, TimestampTrait {
800-
description: string | null;
801-
files: HasMany<File>;
802-
}"
727+
export default FileableSchema;"
803728
`;
804729
805730
exports[`mixin-to-schema transform (artifacts) > mixin inheritance > produces trait with single extended trait > single inheritance trait code 1`] = `
@@ -818,11 +743,7 @@ exports[`mixin-to-schema transform (artifacts) > mixin inheritance > produces tr
818743
]
819744
};
820745
821-
export default DescribableSchema;
822-
823-
export interface DescribableTrait extends BaseModelTrait {
824-
description: string | null;
825-
}"
746+
export default DescribableSchema;"
826747
`;
827748
828749
exports[`mixin-to-schema transform (artifacts) > mixin inheritance > produces trait without traits property when no inheritance > no inheritance trait code 1`] = `
@@ -838,9 +759,5 @@ exports[`mixin-to-schema transform (artifacts) > mixin inheritance > produces tr
838759
]
839760
};
840761
841-
export default DescribableSchema;
842-
843-
export interface DescribableTrait {
844-
description: string | null;
845-
}"
762+
export default DescribableSchema;"
846763
`;

0 commit comments

Comments
 (0)