@ethlete/cdk 5.0.0-next.25 → 5.0.0-next.27

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.
@@ -49,15 +49,22 @@ export const rewriteCdkImports = (content, filePath, rewrites) => {
49
49
  return { content, renames: new Map(), moved: [] };
50
50
  }
51
51
  const mergeTargets = new Map();
52
- const importedNames = new Map();
52
+ /** Non-cdk module → (exported name → local binding already in scope for it, aliased or not). */
53
+ const existingBindings = new Map();
53
54
  for (const declaration of declarations) {
54
55
  const module = moduleOf(declaration);
55
56
  const named = namedImportsOf(declaration);
56
57
  if (!named)
57
58
  continue;
58
- const names = importedNames.get(module) ?? new Set();
59
- named.elements.forEach((element) => names.add(element.name.text));
60
- importedNames.set(module, names);
59
+ if (module !== CDK_PACKAGE) {
60
+ const bindings = existingBindings.get(module) ?? new Map();
61
+ named.elements.forEach((element) => {
62
+ const exportedName = (element.propertyName ?? element.name).text;
63
+ if (!bindings.has(exportedName))
64
+ bindings.set(exportedName, element.name.text);
65
+ });
66
+ existingBindings.set(module, bindings);
67
+ }
61
68
  if (module !== CDK_PACKAGE && !declaration.importClause?.isTypeOnly && !mergeTargets.has(module)) {
62
69
  mergeTargets.set(module, named);
63
70
  }
@@ -82,6 +89,12 @@ export const rewriteCdkImports = (content, filePath, rewrites) => {
82
89
  }
83
90
  changed = true;
84
91
  moved.push(importedName);
92
+ const existingLocalName = existingBindings.get(rewrite.package)?.get(rewrite.to);
93
+ if (existingLocalName) {
94
+ if (existingLocalName !== localName)
95
+ renames.set(localName, existingLocalName);
96
+ continue;
97
+ }
85
98
  const typePrefix = declaration.importClause?.isTypeOnly || element.isTypeOnly ? 'type ' : '';
86
99
  const isAliased = !!element.propertyName;
87
100
  const specifier = isAliased ? `${typePrefix}${rewrite.to} as ${localName}` : `${typePrefix}${rewrite.to}`;
@@ -89,11 +102,13 @@ export const rewriteCdkImports = (content, filePath, rewrites) => {
89
102
  if (!isAliased && rewrite.to !== localName) {
90
103
  renames.set(localName, rewrite.to);
91
104
  }
92
- const alreadyImported = importedNames.get(rewrite.package)?.has(finalLocalName);
93
105
  const pending = additions.get(rewrite.package) ?? [];
94
- if (!alreadyImported && !pending.includes(specifier)) {
106
+ if (!pending.includes(specifier)) {
95
107
  additions.set(rewrite.package, [...pending, specifier]);
96
108
  }
109
+ const bindings = existingBindings.get(rewrite.package) ?? new Map();
110
+ bindings.set(rewrite.to, finalLocalName);
111
+ existingBindings.set(rewrite.package, bindings);
97
112
  }
98
113
  if (changed) {
99
114
  declarationEdits.push({ declaration, kept });
@@ -1,10 +1,11 @@
1
1
  import { formatFiles } from '@nx/devkit';
2
+ import { posix } from 'node:path';
2
3
  import { readCdkImportedSymbols, renameReferences, rewriteCdkImports } from './imports.js';
3
4
  import { isSinceSatisfied, readInstalledVersion } from './installed-version.js';
4
5
  import { JUDGMENT_KINDS, loadMigrationMap, MECHANICAL_KINDS } from './migration-map.js';
5
6
  import { createMigrationScope } from './migration-scope.js';
6
7
  import { addSymbolSite, createEmptyReport, isReportEmpty, renderReport, scanStyleSheet, scanTemplate, } from './report.js';
7
- import { findInlineStyleSpans, findInlineTemplateSpans, lineOfIndex, rewriteStyleSheet, rewriteTemplate, transformInlineSpans, } from './templates.js';
8
+ import { findInlineStyleSpans, findInlineTemplateSpans, lineOfIndex, readTemplateUrl, rewriteStyleSheet, rewriteTemplate, transformInlineSpans, } from './templates.js';
8
9
  export const MIGRATE_FROM_CDK_REPORT_PATH = 'migrate-from-cdk-tasks.md';
9
10
  const TARGET_PACKAGES = ['@ethlete/components', '@ethlete/core'];
10
11
  /**
@@ -13,6 +14,8 @@ const TARGET_PACKAGES = ['@ethlete/components', '@ethlete/core'];
13
14
  * left for the report.
14
15
  */
15
16
  const SPINNER_SYMBOL = 'ProgressSpinnerComponent';
17
+ /** `reshape`, so never in `rewrites` - a cdk import for it never moves on its own. */
18
+ const PICTURE_SYMBOL = 'PictureComponent';
16
19
  const isTypeScript = (filePath) => filePath.endsWith('.ts') && !filePath.endsWith('.d.ts');
17
20
  const isTemplate = (filePath) => filePath.endsWith('.html');
18
21
  const isStyleSheet = (filePath) => /\.(css|scss)$/.test(filePath);
@@ -58,14 +61,43 @@ const scanFile = (report, filePath, content, map, isAvailable) => {
58
61
  }
59
62
  }
60
63
  };
61
- const rewriteFile = (filePath, content, rewrites) => {
62
- if (isTemplate(filePath))
63
- return rewriteTemplate(content);
64
+ /**
65
+ * The template file a `.ts` file's own markup ends up in - `templateUrl`'s target, or the file itself
66
+ * when the template is inline.
67
+ */
68
+ const templateFileFor = (filePath, content) => {
69
+ const templateUrl = readTemplateUrl(content, filePath);
70
+ return templateUrl ? posix.normalize(posix.join(posix.dirname(filePath), templateUrl)) : filePath;
71
+ };
72
+ /**
73
+ * Whether each template file's `<et-picture>` markup is safe to rewrite - only once the `.ts` file that
74
+ * owns it no longer imports cdk's `PictureComponent`. That row is a `reshape`, so the generator never
75
+ * moves it on its own; a template still bound to cdk's component must keep cdk's attribute names, or the
76
+ * rewrite produces a binding (`(imgLoad)`) the actually-bound component doesn't have.
77
+ */
78
+ const collectPictureImportStatus = (tree, files) => {
79
+ const movedByTemplateFile = new Map();
80
+ for (const filePath of files) {
81
+ if (!isTypeScript(filePath))
82
+ continue;
83
+ const content = tree.read(filePath, 'utf-8');
84
+ if (!content)
85
+ continue;
86
+ const stillOnCdk = readCdkImportedSymbols(content, filePath).some(({ name }) => name === PICTURE_SYMBOL);
87
+ movedByTemplateFile.set(templateFileFor(filePath, content), !stillOnCdk);
88
+ }
89
+ return movedByTemplateFile;
90
+ };
91
+ const rewriteFile = (filePath, content, rewrites, pictureImportMovedByFile) => {
92
+ if (isTemplate(filePath)) {
93
+ return rewriteTemplate(content, { pictureImportMoved: pictureImportMovedByFile.get(filePath) });
94
+ }
64
95
  if (isStyleSheet(filePath))
65
96
  return rewriteStyleSheet(content);
66
97
  const { content: withImports, renames } = rewriteCdkImports(content, filePath, rewrites);
67
98
  const withReferences = renameReferences(withImports, filePath, renames);
68
- const withTemplates = transformInlineSpans(withReferences, findInlineTemplateSpans(withReferences, filePath), rewriteTemplate);
99
+ const pictureImportMoved = pictureImportMovedByFile.get(filePath);
100
+ const withTemplates = transformInlineSpans(withReferences, findInlineTemplateSpans(withReferences, filePath), (template) => rewriteTemplate(template, { pictureImportMoved }));
69
101
  return transformInlineSpans(withTemplates, findInlineStyleSpans(withTemplates, filePath), rewriteStyleSheet);
70
102
  };
71
103
  export default async function migrateFromCdk(tree, schema) {
@@ -89,12 +121,13 @@ export default async function migrateFromCdk(tree, schema) {
89
121
  continue;
90
122
  scanFile(report, filePath, content, map, isAvailable);
91
123
  }
124
+ const pictureImportMovedByFile = collectPictureImportStatus(tree, files);
92
125
  let rewrittenFiles = 0;
93
126
  for (const filePath of files) {
94
127
  const content = tree.read(filePath, 'utf-8');
95
128
  if (!content)
96
129
  continue;
97
- const next = rewriteFile(filePath, content, rewrites);
130
+ const next = rewriteFile(filePath, content, rewrites, pictureImportMovedByFile);
98
131
  if (next !== content) {
99
132
  tree.write(filePath, next);
100
133
  rewrittenFiles += 1;
@@ -24,6 +24,25 @@ const inlineSpansFor = (content, filePath, propertyName) => {
24
24
  };
25
25
  export const findInlineTemplateSpans = (content, filePath) => inlineSpansFor(content, filePath, 'template');
26
26
  export const findInlineStyleSpans = (content, filePath) => inlineSpansFor(content, filePath, 'styles');
27
+ /** A `@Component`'s `templateUrl`, so an external template file can be traced back to the class that owns it. */
28
+ export const readTemplateUrl = (content, filePath) => {
29
+ const sourceFile = createSourceFile(content, filePath);
30
+ let templateUrl = null;
31
+ const visit = (node) => {
32
+ if (templateUrl)
33
+ return;
34
+ if (ts.isPropertyAssignment(node) &&
35
+ ts.isIdentifier(node.name) &&
36
+ node.name.text === 'templateUrl' &&
37
+ ts.isStringLiteralLike(node.initializer)) {
38
+ templateUrl = node.initializer.text;
39
+ return;
40
+ }
41
+ ts.forEachChild(node, visit);
42
+ };
43
+ visit(sourceFile);
44
+ return templateUrl;
45
+ };
27
46
  export const transformInlineSpans = (content, spans, transform) => {
28
47
  const replacements = [];
29
48
  for (const span of spans) {
@@ -62,9 +81,11 @@ const rewritePictureAttributes = (template) => mapOpeningTags(template, PICTURE_
62
81
  const rewriteTooltipAttributes = (template) => template
63
82
  .replace(/(\s)\[tooltipAriaDescription\]/g, '$1[etTooltipAriaDescription]')
64
83
  .replace(/(\s)tooltipAriaDescription(?=[\s=/>])/g, '$1etTooltipAriaDescription');
65
- export const rewriteTemplate = (template) => {
84
+ export const rewriteTemplate = (template, options = {}) => {
66
85
  const withSpinnerTags = rewriteSpinnerTags(template);
67
- return rewriteTooltipAttributes(rewritePictureAttributes(rewriteSpinnerAttributes(rewriteSkeletonItems(withSpinnerTags))));
86
+ const withSkeletonAndSpinner = rewriteSpinnerAttributes(rewriteSkeletonItems(withSpinnerTags));
87
+ const withPicture = options.pictureImportMoved === false ? withSkeletonAndSpinner : rewritePictureAttributes(withSkeletonAndSpinner);
88
+ return rewriteTooltipAttributes(withPicture);
68
89
  };
69
90
  export const LEGACY_SPINNER_COLOR_VARIABLE = '--et-progress-spinner-color';
70
91
  export const rewriteStyleSheet = (styles) => styles.replace(new RegExp(`${LEGACY_SPINNER_COLOR_VARIABLE}(?![\\w-])`, 'g'), '--et-spinner-color');
@@ -23,7 +23,6 @@ const ET_MENU_SYMBOLS = new Set([
23
23
  ]);
24
24
  export default async function migrateCdkMenu(tree) {
25
25
  console.log('\n🔄 Migrating from CDK menu to et menu');
26
- const files = tree.children('.');
27
26
  const warnings = new Map();
28
27
  function walkFiles(path) {
29
28
  const entries = tree.children(path);
@@ -63,7 +62,6 @@ export default async function migrateCdkMenu(tree) {
63
62
  return;
64
63
  // Process imports and build replacement
65
64
  let hasMenuSymbols = false;
66
- let hasMenuImports = false;
67
65
  const importedSymbols = new Set();
68
66
  imports.forEach((match) => {
69
67
  const importList = match[1];
@@ -76,9 +74,6 @@ export default async function migrateCdkMenu(tree) {
76
74
  if (CDK_MENU_SYMBOLS.includes(symbol)) {
77
75
  hasMenuSymbols = true;
78
76
  }
79
- if (symbol === 'MenuImports') {
80
- hasMenuImports = true;
81
- }
82
77
  });
83
78
  });
84
79
  if (!hasMenuSymbols && !Array.from(importedSymbols).some((s) => ET_MENU_SYMBOLS.has(s)))
@@ -130,7 +125,7 @@ export default async function migrateCdkMenu(tree) {
130
125
  return result;
131
126
  });
132
127
  // Replace imports
133
- content = content.replace(importRegex, (match, importList) => {
128
+ content = content.replace(importRegex, (_match, importList) => {
134
129
  const symbols = importList
135
130
  .split(',')
136
131
  .map((s) => s.trim())
@@ -223,7 +218,7 @@ export default async function migrateCdkMenu(tree) {
223
218
  // 4. Replace cdkMenuItemCheckbox with et-menu-checkbox-item
224
219
  if (content.includes('cdkMenuItemCheckbox')) {
225
220
  const checkboxRegex = /<(\w+)([^>]*?)\bcdkMenuItemCheckbox\b([^>]*)>([\s\S]*?)<\/\1>/g;
226
- content = content.replace(checkboxRegex, (match, tagName, beforeAttrs, afterAttrs, inner) => {
221
+ content = content.replace(checkboxRegex, (_match, _tagName, beforeAttrs, afterAttrs, inner) => {
227
222
  const allAttrs = (beforeAttrs + afterAttrs)
228
223
  .replace(/\s+cdkMenuItemCheckbox\s+/, ' ')
229
224
  .replace(/\bcdkMenuItemCheckbox\b/, '')
@@ -235,7 +230,7 @@ export default async function migrateCdkMenu(tree) {
235
230
  // 5. Replace cdkMenuItemRadio with et-menu-radio-item and add warning
236
231
  if (content.includes('cdkMenuItemRadio')) {
237
232
  const radioRegex = /<(\w+)([^>]*?)\bcdkMenuItemRadio\b([^>]*)>([\s\S]*?)<\/\1>/g;
238
- content = content.replace(radioRegex, (match, tagName, beforeAttrs, afterAttrs, inner) => {
233
+ content = content.replace(radioRegex, (_match, _tagName, beforeAttrs, afterAttrs, inner) => {
239
234
  const allAttrs = (beforeAttrs + afterAttrs)
240
235
  .replace(/\s+cdkMenuItemRadio\s+/, ' ')
241
236
  .replace(/\bcdkMenuItemRadio\b/, '')
@@ -151,8 +151,6 @@ export default async function migrateColorThemes(tree) {
151
151
  imports.forEach((imp) => {
152
152
  // Extract the actual import name (without 'type' keyword and alias)
153
153
  // Handle patterns like: "type Theme as EthleteTheme", "Theme", "type Theme"
154
- const typeKeywordMatch = imp.match(/^type\s+/);
155
- const hasTypeKeyword = !!typeKeywordMatch;
156
154
  const withoutType = imp.replace(/^type\s+/, '').trim();
157
155
  const importName = withoutType.split(/\s+as\s+/)[0]?.trim() || withoutType;
158
156
  if (THEMING_EXPORTS.has(importName)) {
@@ -1,5 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
3
1
  import { getProjects, logger, visitNotIgnoredFiles } from '@nx/devkit';
4
2
  import * as ts from 'typescript';
5
3
  // Symbol mappings
@@ -327,14 +327,14 @@ export function migrateEtLet(tree) {
327
327
  if (variable !== originalVariable) {
328
328
  // Pattern 1: Attribute values - match the full pattern [attr]="value"
329
329
  // and only replace the variable in the value part, never in attribute names
330
- innerContent = innerContent.replace(/\[([^\]]+)\]="([^"]*)"/g, (match, attrName, attrValue) => {
330
+ innerContent = innerContent.replace(/\[([^\]]+)\]="([^"]*)"/g, (_match, attrName, attrValue) => {
331
331
  // Don't rename the attribute name, only references in the value
332
332
  const pattern = new RegExp(`\\b${originalVariable}\\b`, 'g');
333
333
  const newValue = attrValue.replace(pattern, variable);
334
334
  return `[${attrName}]="${newValue}"`;
335
335
  });
336
336
  // Pattern 2: Event bindings like (click)="method(variable)"
337
- innerContent = innerContent.replace(/\(([^)]+)\)="([^"]*)"/g, (match, eventName, eventHandler) => {
337
+ innerContent = innerContent.replace(/\(([^)]+)\)="([^"]*)"/g, (_match, eventName, eventHandler) => {
338
338
  const pattern = new RegExp(`\\b${originalVariable}\\b`, 'g');
339
339
  const newHandler = eventHandler.replace(pattern, variable);
340
340
  return `(${eventName})="${newHandler}"`;
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
1
  import { formatFiles, getProjects, logger, visitNotIgnoredFiles } from '@nx/devkit';
3
2
  import * as ts from 'typescript';
4
3
  const STRATEGY_MAP = {
@@ -201,7 +200,7 @@ function processFile(filePath, content) {
201
200
  bodyCode = func.body.getText(sourceFile);
202
201
  }
203
202
  // Transform the body - replace builder.DEFAULTS.X with strategy calls
204
- const { code: transformedBody, usesMergeConfigs, strategiesUsed, } = transformBuilderBodyForDefaults(bodyCode, builderParamName, sourceFile);
203
+ const { code: transformedBody, usesMergeConfigs, strategiesUsed, } = transformBuilderBodyForDefaults(bodyCode, builderParamName);
205
204
  if (usesMergeConfigs) {
206
205
  importsToAdd.add('mergeOverlayBreakpointConfigs');
207
206
  }
@@ -482,7 +481,7 @@ function transformNodeTextForDefaults(node, sourceFile) {
482
481
  text = text.replace(defaultsPattern, `${varName}.build()`);
483
482
  });
484
483
  // Now handle mergeConfigs - do this AFTER replacing DEFAULTS
485
- Object.entries(STRATEGY_INJECT_MAP).forEach(([strategyName, injectFn]) => {
484
+ Object.entries(STRATEGY_INJECT_MAP).forEach(([_strategyName, injectFn]) => {
486
485
  const varName = getStrategyVariableName(injectFn);
487
486
  // Pattern: overlayService.positions.mergeConfigs(dialogStrategy.build(), ...args)
488
487
  // We want to extract just the args after the first argument and comma
@@ -608,14 +607,6 @@ function updateImportsInContent(content, importsToAdd, importsToRemove) {
608
607
  return content.replace(importRegex, newImportStatement);
609
608
  }
610
609
  // Type guards
611
- function isInjectOverlayServiceCall(node) {
612
- return (ts.isCallExpression(node) &&
613
- ts.isIdentifier(node.expression) &&
614
- node.expression.text === 'inject' &&
615
- node.arguments.length === 1 &&
616
- ts.isIdentifier(node.arguments[0]) &&
617
- node.arguments[0].text === 'OverlayService');
618
- }
619
610
  function isPositionMethodCall(node) {
620
611
  return (ts.isCallExpression(node) &&
621
612
  ts.isPropertyAccessExpression(node.expression) &&
@@ -627,37 +618,6 @@ function isOverlayBreakpointConfigEntryType(node) {
627
618
  ts.isIdentifier(node.typeName) &&
628
619
  node.typeName.text === 'OverlayBreakpointConfigEntry');
629
620
  }
630
- // Helper functions
631
- function checkIfOverlayRelated(node) {
632
- // First check: Are we inside createOverlayHandler call?
633
- if (isInsideOverlayHandlerCall(node)) {
634
- return true;
635
- }
636
- // Check for overlay-related patterns that need migration using AST
637
- let isOverlayRelated = false;
638
- function visit(n) {
639
- if (isOverlayRelated)
640
- return;
641
- if (isPositionMethodCall(n)) {
642
- isOverlayRelated = true;
643
- return;
644
- }
645
- if (isDefaultsUsage(n)) {
646
- isOverlayRelated = true;
647
- return;
648
- }
649
- if (ts.isCallExpression(n)) {
650
- const callText = n.getText();
651
- if (callText.includes('getConfig') || callText.includes('getPositions') || callText.includes('getStrategies')) {
652
- isOverlayRelated = true;
653
- return;
654
- }
655
- }
656
- ts.forEachChild(n, visit);
657
- }
658
- visit(node);
659
- return isOverlayRelated;
660
- }
661
621
  function isDefaultsUsage(node) {
662
622
  return (ts.isPropertyAccessExpression(node) &&
663
623
  ts.isPropertyAccessExpression(node.expression) &&
@@ -760,7 +720,7 @@ function isInsideOverlayHandlerCall(node) {
760
720
  }
761
721
  return false;
762
722
  }
763
- function transformBuilderBodyForDefaults(bodyCode, builderParamName, sourceFile) {
723
+ function transformBuilderBodyForDefaults(bodyCode, builderParamName) {
764
724
  let code = bodyCode;
765
725
  let usesMergeConfigs = false;
766
726
  const strategiesUsed = new Set();
@@ -780,7 +740,7 @@ function transformBuilderBodyForDefaults(bodyCode, builderParamName, sourceFile)
780
740
  }
781
741
  });
782
742
  // Replace builder.mergeConfigs(Xstrategy.build(), ...args) with Xstrategy.build(mergeOverlayBreakpointConfigs(...args))
783
- Object.entries(STRATEGY_INJECT_MAP).forEach(([strategyName, injectFn]) => {
743
+ Object.entries(STRATEGY_INJECT_MAP).forEach(([_strategyName, injectFn]) => {
784
744
  const varName = getStrategyVariableName(injectFn);
785
745
  // Pattern: builder.mergeConfigs(dialogStrategy.build(), {...})
786
746
  const pattern = new RegExp(`${builderParamName}\\.mergeConfigs\\(\\s*${varName}\\.build\\(\\)\\s*,\\s*`, 'g');
@@ -2805,8 +2805,8 @@
2805
2805
  },
2806
2806
  "TabImports": {
2807
2807
  "docs": "/components/tabs",
2808
- "kind": "rename",
2809
- "note": "NAV_TAB_IMPORTS for the router nav tabs",
2808
+ "kind": "rename+reshape",
2809
+ "note": "et-inline-tabs/et-inline-tab become et-tab-group/et-tab (NAV_TAB_IMPORTS for the router nav tabs); [selectedIndex]/(selectedIndexChange) is now the two-way [(selectedIndex)] model, and renderButtons/renderMasks/renderScrollbars have no equivalent",
2810
2810
  "package": "@ethlete/components",
2811
2811
  "to": "TAB_IMPORTS"
2812
2812
  },
@@ -2852,7 +2852,8 @@
2852
2852
  },
2853
2853
  "TableImports": {
2854
2854
  "docs": "/components/table",
2855
- "kind": "rename",
2855
+ "kind": "rename+reshape",
2856
+ "note": "bundles TableComponent plus the [data]/[columns] cell and footer directives, not the *Def structural-directive kit (etColumnDef/etCellDef/etHeaderCellDef/etRowDef/etHeaderRowDef) - a template still using those compiles to nothing",
2856
2857
  "package": "@ethlete/components",
2857
2858
  "to": "TABLE_IMPORTS"
2858
2859
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/cdk",
3
- "version": "5.0.0-next.25",
3
+ "version": "5.0.0-next.27",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "exports": {