@ethlete/cdk 4.70.0 → 5.0.0-next.0

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.
@@ -0,0 +1,201 @@
1
+ import { logger } from '@nx/devkit';
2
+ import * as ts from 'typescript';
3
+ export default async function migrateIsActiveElement(tree) {
4
+ logger.log('šŸ”„ Migrating IsActiveElementDirective to ScrollableIsActiveChildDirective...');
5
+ const tsFiles = [];
6
+ const htmlFiles = [];
7
+ function findFiles(dir) {
8
+ const children = tree.children(dir);
9
+ for (const child of children) {
10
+ const path = dir === '.' ? child : `${dir}/${child}`;
11
+ if (tree.isFile(path)) {
12
+ if (path.endsWith('.ts')) {
13
+ tsFiles.push(path);
14
+ }
15
+ else if (path.endsWith('.html')) {
16
+ htmlFiles.push(path);
17
+ }
18
+ }
19
+ else {
20
+ findFiles(path);
21
+ }
22
+ }
23
+ }
24
+ findFiles('.');
25
+ let filesModified = 0;
26
+ // Migrate TypeScript files
27
+ for (const filePath of tsFiles) {
28
+ const wasModified = migrateTypeScriptFile(tree, filePath);
29
+ if (wasModified) {
30
+ filesModified++;
31
+ }
32
+ }
33
+ // Migrate HTML templates
34
+ for (const filePath of htmlFiles) {
35
+ const wasModified = migrateHtmlFile(tree, filePath);
36
+ if (wasModified) {
37
+ filesModified++;
38
+ }
39
+ }
40
+ if (filesModified > 0) {
41
+ logger.log(`āœ… Successfully migrated IsActiveElementDirective in ${filesModified} file(s)`);
42
+ }
43
+ else {
44
+ logger.log('ā„¹ļø No files needed migration');
45
+ }
46
+ }
47
+ function migrateTypeScriptFile(tree, filePath) {
48
+ const content = tree.read(filePath, 'utf-8');
49
+ if (!content ||
50
+ (!content.includes('IsActiveElementDirective') &&
51
+ !content.includes('IS_ACTIVE_ELEMENT') &&
52
+ !content.includes('etIsActiveElement'))) {
53
+ return false;
54
+ }
55
+ let updatedContent = content;
56
+ // IMPORTANT: Update imports FIRST (before replacing token/class names)
57
+ // This way we can still detect IS_ACTIVE_ELEMENT in @ethlete/core imports
58
+ const sourceFile = ts.createSourceFile(filePath, updatedContent, ts.ScriptTarget.Latest, true);
59
+ updatedContent = updateImports(sourceFile, updatedContent);
60
+ // Now replace token name (after imports are updated)
61
+ updatedContent = updatedContent.replace(/\bIS_ACTIVE_ELEMENT\b/g, 'SCROLLABLE_IS_ACTIVE_CHILD_TOKEN');
62
+ // Replace selector in inline templates (template strings)
63
+ updatedContent = updatedContent.replace(/\betIsActiveElement\b/g, 'etScrollableIsActiveChild');
64
+ // Replace IsActiveElementDirective usage in component imports array with ScrollableImports
65
+ // This handles: imports: [IsActiveElementDirective] -> imports: [ScrollableImports]
66
+ updatedContent = updatedContent.replace(/\bIsActiveElementDirective\b/g, 'ScrollableImports');
67
+ if (updatedContent !== content) {
68
+ tree.write(filePath, updatedContent);
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ function updateImports(sourceFile, content) {
74
+ let updatedContent = content;
75
+ const importsToUpdate = [];
76
+ const importsToRemove = [];
77
+ let needsCdkImport = false;
78
+ const cdkImportsToAdd = [];
79
+ function visit(node) {
80
+ if (ts.isImportDeclaration(node) &&
81
+ ts.isStringLiteral(node.moduleSpecifier) &&
82
+ node.importClause?.namedBindings &&
83
+ ts.isNamedImports(node.importClause.namedBindings)) {
84
+ const moduleSpecifier = node.moduleSpecifier.text;
85
+ const namedImports = node.importClause.namedBindings;
86
+ const importSpecifiers = namedImports.elements;
87
+ // Handle @ethlete/core imports
88
+ if (moduleSpecifier === '@ethlete/core') {
89
+ const hasIsActiveElement = importSpecifiers.some((spec) => spec.name.text === 'IsActiveElementDirective' || spec.name.text === 'IS_ACTIVE_ELEMENT');
90
+ if (hasIsActiveElement) {
91
+ // Get remaining imports from @ethlete/core
92
+ const remainingCoreImports = importSpecifiers
93
+ .filter((spec) => spec.name.text !== 'IsActiveElementDirective' && spec.name.text !== 'IS_ACTIVE_ELEMENT')
94
+ .map((spec) => spec.name.text);
95
+ const hasToken = importSpecifiers.some((spec) => spec.name.text === 'IS_ACTIVE_ELEMENT');
96
+ const hasDirective = importSpecifiers.some((spec) => spec.name.text === 'IsActiveElementDirective');
97
+ // Mark that we need to add to @ethlete/cdk
98
+ needsCdkImport = true;
99
+ if (hasDirective && !cdkImportsToAdd.includes('ScrollableImports')) {
100
+ cdkImportsToAdd.push('ScrollableImports');
101
+ }
102
+ if (hasToken && !cdkImportsToAdd.includes('SCROLLABLE_IS_ACTIVE_CHILD_TOKEN')) {
103
+ cdkImportsToAdd.push('SCROLLABLE_IS_ACTIVE_CHILD_TOKEN');
104
+ }
105
+ if (remainingCoreImports.length > 0) {
106
+ // Keep @ethlete/core import with remaining imports
107
+ const newCoreImportText = `import { ${remainingCoreImports.sort().join(', ')} } from '@ethlete/core';`;
108
+ importsToUpdate.push({
109
+ originalText: node.getText(sourceFile),
110
+ newText: newCoreImportText,
111
+ });
112
+ }
113
+ else {
114
+ // Remove @ethlete/core import entirely
115
+ importsToRemove.push(node.getText(sourceFile));
116
+ }
117
+ }
118
+ }
119
+ // Handle @ethlete/cdk imports
120
+ if (moduleSpecifier === '@ethlete/cdk') {
121
+ const hasIsActiveElement = importSpecifiers.some((spec) => spec.name.text === 'IsActiveElementDirective' || spec.name.text === 'IS_ACTIVE_ELEMENT');
122
+ if (hasIsActiveElement) {
123
+ // Get all imports except the ones we're replacing
124
+ const otherImports = importSpecifiers
125
+ .filter((spec) => spec.name.text !== 'IsActiveElementDirective' && spec.name.text !== 'IS_ACTIVE_ELEMENT')
126
+ .map((spec) => spec.name.text);
127
+ // Add new imports if not already present
128
+ const hasScrollableImports = otherImports.includes('ScrollableImports');
129
+ const hasToken = importSpecifiers.some((spec) => spec.name.text === 'IS_ACTIVE_ELEMENT');
130
+ const hasScrollableToken = otherImports.includes('SCROLLABLE_IS_ACTIVE_CHILD_TOKEN');
131
+ if (!hasScrollableImports) {
132
+ otherImports.push('ScrollableImports');
133
+ }
134
+ if (hasToken && !hasScrollableToken) {
135
+ otherImports.push('SCROLLABLE_IS_ACTIVE_CHILD_TOKEN');
136
+ }
137
+ const sortedImports = otherImports.sort();
138
+ const newImportText = `import { ${sortedImports.join(', ')} } from '@ethlete/cdk';`;
139
+ importsToUpdate.push({
140
+ originalText: node.getText(sourceFile),
141
+ newText: newImportText,
142
+ });
143
+ }
144
+ else if (needsCdkImport) {
145
+ // Existing @ethlete/cdk import - merge our new imports
146
+ const allImports = [
147
+ ...importSpecifiers.map((spec) => spec.name.text),
148
+ ...cdkImportsToAdd.filter((imp) => !importSpecifiers.some((spec) => spec.name.text === imp)),
149
+ ];
150
+ const sortedImports = allImports.sort();
151
+ const newImportText = `import { ${sortedImports.join(', ')} } from '@ethlete/cdk';`;
152
+ importsToUpdate.push({
153
+ originalText: node.getText(sourceFile),
154
+ newText: newImportText,
155
+ });
156
+ needsCdkImport = false; // Mark as handled
157
+ }
158
+ }
159
+ }
160
+ ts.forEachChild(node, visit);
161
+ }
162
+ visit(sourceFile);
163
+ // Apply import updates
164
+ for (const update of importsToUpdate) {
165
+ updatedContent = updatedContent.replace(update.originalText, update.newText);
166
+ }
167
+ // Remove imports
168
+ for (const importToRemove of importsToRemove) {
169
+ updatedContent = updatedContent.replace(importToRemove + '\n', '');
170
+ }
171
+ // Add new @ethlete/cdk import if needed and not merged with existing
172
+ if (needsCdkImport && cdkImportsToAdd.length > 0) {
173
+ const sortedImports = cdkImportsToAdd.sort();
174
+ const newCdkImport = `import { ${sortedImports.join(', ')} } from '@ethlete/cdk';\n`;
175
+ // Find the last import statement to insert after it
176
+ const importMatches = [...updatedContent.matchAll(/^import .+ from .+;$/gm)];
177
+ if (importMatches.length > 0) {
178
+ const lastImport = importMatches[importMatches.length - 1];
179
+ const insertPosition = (lastImport.index ?? 0) + lastImport[0].length + 1;
180
+ updatedContent = updatedContent.slice(0, insertPosition) + newCdkImport + updatedContent.slice(insertPosition);
181
+ }
182
+ else {
183
+ // No imports found, add at the beginning
184
+ updatedContent = newCdkImport + updatedContent;
185
+ }
186
+ }
187
+ return updatedContent;
188
+ }
189
+ function migrateHtmlFile(tree, filePath) {
190
+ const content = tree.read(filePath, 'utf-8');
191
+ if (!content || !content.includes('etIsActiveElement'))
192
+ return false;
193
+ // Replace selector in templates
194
+ const updatedContent = content.replace(/\betIsActiveElement\b/g, 'etScrollableIsActiveChild');
195
+ if (updatedContent !== content) {
196
+ tree.write(filePath, updatedContent);
197
+ return true;
198
+ }
199
+ return false;
200
+ }
201
+ //# sourceMappingURL=is-active-element.js.map
@@ -0,0 +1,53 @@
1
+ import { formatFiles } from '@nx/devkit';
2
+ import migrateCdkMenu from './cdk-menu.js';
3
+ import migrateColorThemes from './color-themes.js';
4
+ import { migrateCombobox } from './combobox.js';
5
+ import migrateDialogBottomSheet from './dialog-bottom-sheet.js';
6
+ import { migrateEtLet } from './et-let.js';
7
+ import migrateIsActiveElement from './is-active-element.js';
8
+ import migrateOverlayPositions from './overlay-positions.js';
9
+ export default async function migrate(tree, schema) {
10
+ console.log('\nšŸ”„ Starting CDK v5 migration...');
11
+ const shouldMigrateCombobox = schema.migrateCombobox !== false;
12
+ const shouldMigrateEtLet = schema.migrateEtLet !== false;
13
+ const shouldMigrateColorThemes = schema.migrateColorThemes !== false;
14
+ const shouldMigrateCdkMenu = schema.migrateCdkMenu !== false;
15
+ const shouldMigrateIsActiveElement = schema.migrateIsActiveElement !== false;
16
+ const shouldMigrateOverlayPositions = schema.migrateOverlayPositions !== false;
17
+ const shouldMigrateDialogBottomSheet = schema.migrateDialogBottomSheet !== false;
18
+ if (shouldMigrateCombobox) {
19
+ console.log(' • Migrating combobox...');
20
+ migrateCombobox(tree);
21
+ }
22
+ if (shouldMigrateEtLet) {
23
+ console.log(' • Migrating et-let...');
24
+ migrateEtLet(tree);
25
+ }
26
+ if (shouldMigrateColorThemes) {
27
+ console.log(' • Migrating color themes...');
28
+ await migrateColorThemes(tree);
29
+ }
30
+ if (shouldMigrateCdkMenu) {
31
+ console.log(' • Migrating cdk-menu...');
32
+ await migrateCdkMenu(tree);
33
+ }
34
+ if (shouldMigrateIsActiveElement) {
35
+ console.log(' • Migrating is-active-element...');
36
+ await migrateIsActiveElement(tree);
37
+ }
38
+ if (shouldMigrateOverlayPositions) {
39
+ console.log(' • Migrating overlay positions...');
40
+ await migrateOverlayPositions(tree);
41
+ }
42
+ if (shouldMigrateDialogBottomSheet) {
43
+ console.log(' • Migrating dialog & bottom sheet...');
44
+ await migrateDialogBottomSheet(tree);
45
+ }
46
+ if (!schema.skipFormat) {
47
+ console.log(' • Formatting files...');
48
+ await formatFiles(tree);
49
+ }
50
+ console.log('\nāœ… Migration completed successfully!');
51
+ }
52
+ //#endregion
53
+ //# sourceMappingURL=migration.js.map