@ethlete/core 5.0.0-next.4 → 5.0.0-next.40

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.
@@ -5,10 +5,20 @@
5
5
  "schema": "./migrate-to-v5/schema.json",
6
6
  "description": "Migrate to v5"
7
7
  },
8
- "tailwind-4-theme": {
9
- "factory": "./tailwind-4-theme/generator",
10
- "schema": "./tailwind-4-theme/schema.json",
11
- "description": "Generate theming for Tailwind CSS v4"
8
+ "migrate-provider-shape": {
9
+ "factory": "./migrate-provider-shape/migration",
10
+ "schema": "./migrate-provider-shape/schema.json",
11
+ "description": "Rewrite destructured provider tuples into the tree-shakeable definition shape"
12
+ },
13
+ "tailwind-4-color-theme": {
14
+ "factory": "./tailwind-4-color-theme/generator",
15
+ "schema": "./tailwind-4-color-theme/schema.json",
16
+ "description": "Generate color theming for Tailwind CSS v4"
17
+ },
18
+ "tailwind-4-surface-theme": {
19
+ "factory": "./tailwind-4-surface-theme/generator",
20
+ "schema": "./tailwind-4-surface-theme/schema.json",
21
+ "description": "Generate surface theming for Tailwind CSS v4"
12
22
  }
13
23
  }
14
24
  }
@@ -0,0 +1,35 @@
1
+ import { getProjects, visitNotIgnoredFiles } from '@nx/devkit';
2
+ const stripTrailingSlash = (value) => (value.endsWith('/') ? value.slice(0, -1) : value);
3
+ /**
4
+ * Limits the migration to a set of projects or paths. Unlike the query v3 migration there is no
5
+ * cross-file coupling here - every provider declaration is rewritten on its own - so any scope is safe;
6
+ * this exists to keep the diff reviewable.
7
+ */
8
+ export const createMigrationScope = (tree, options) => {
9
+ const roots = [];
10
+ for (const projectName of options.projects ?? []) {
11
+ const project = getProjects(tree).get(projectName);
12
+ if (!project) {
13
+ throw new Error(`Unknown project "${projectName}". Pass names as they appear in \`nx show projects\`, or use --include with a path prefix.`);
14
+ }
15
+ roots.push(stripTrailingSlash(project.root));
16
+ }
17
+ for (const includePath of options.include ?? []) {
18
+ roots.push(stripTrailingSlash(includePath));
19
+ }
20
+ if (roots.length === 0) {
21
+ return {
22
+ visit: (targetTree, callback) => visitNotIgnoredFiles(targetTree, '', callback),
23
+ describe: () => 'the whole workspace',
24
+ };
25
+ }
26
+ return {
27
+ visit: (targetTree, callback) => {
28
+ for (const root of roots) {
29
+ visitNotIgnoredFiles(targetTree, root, callback);
30
+ }
31
+ },
32
+ describe: () => roots.join(', '),
33
+ };
34
+ };
35
+ //# sourceMappingURL=migration-scope.js.map
@@ -0,0 +1,51 @@
1
+ import { formatFiles } from '@nx/devkit';
2
+ import { createMigrationScope } from './migration-scope.js';
3
+ import { migrateProviderShapeInFile } from './provider-shape.js';
4
+ export const PROVIDER_SHAPE_REPORT_PATH = 'provider-shape-migration-tasks.md';
5
+ const renderReport = (tasks) => [
6
+ '# Provider-shape migration tasks',
7
+ '',
8
+ 'The codemod rewrote every destructured provider declaration into a definition plus one extractor per',
9
+ 'binding. The sites below are **not** plain module-scope declarations, so they were left alone - each',
10
+ 'needs a decision a codemod cannot make.',
11
+ '',
12
+ 'Recipes:',
13
+ '',
14
+ '- A factory of your own that returned a `[provide, inject, token]` tuple: return the definition from',
15
+ ' `define*Provider(…)` directly, and let its callers use the extractors.',
16
+ '- A call inside a function: read `.provide` / `.inject` / `.token` off the definition.',
17
+ '',
18
+ ...tasks.map((task) => [`## \`${task.id}\``, '', `- ${task.file}:${task.line}`, `- ${task.message}`, ''].join('\n')),
19
+ ].join('\n');
20
+ export default async function migrateProviderShape(tree, schema) {
21
+ console.log('\n🔄 Migrating provider tuples to the definition shape...');
22
+ const scope = createMigrationScope(tree, schema);
23
+ console.log(` Scope: ${scope.describe()}`);
24
+ const tasks = [];
25
+ let filesChanged = 0;
26
+ scope.visit(tree, (filePath) => {
27
+ if (!filePath.endsWith('.ts') || filePath.endsWith('.d.ts'))
28
+ return;
29
+ const before = tree.read(filePath, 'utf-8');
30
+ if (!before)
31
+ return;
32
+ const result = migrateProviderShapeInFile(filePath, before);
33
+ tasks.push(...result.tasks);
34
+ if (result.changed) {
35
+ tree.write(filePath, result.content);
36
+ filesChanged++;
37
+ console.log(` ✓ ${filePath}`);
38
+ }
39
+ });
40
+ if (tasks.length > 0) {
41
+ tree.write(PROVIDER_SHAPE_REPORT_PATH, renderReport(tasks));
42
+ }
43
+ if (!schema.skipFormat) {
44
+ await formatFiles(tree);
45
+ }
46
+ console.log(`\n✅ Rewrote ${filesChanged} file(s).`);
47
+ if (tasks.length > 0) {
48
+ console.log(`⚠️ ${tasks.length} site(s) need a manual decision - see ${PROVIDER_SHAPE_REPORT_PATH}.`);
49
+ }
50
+ }
51
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1,217 @@
1
+ import * as ts from 'typescript';
2
+ /**
3
+ * `export const [provideX, injectX] = createRootProvider(…)` is undroppable by construction: array
4
+ * destructuring invokes the iterator protocol, so no bundler will remove the statement, and everything
5
+ * the factory's closure names is retained with it. The definition shape is droppable per binding.
6
+ *
7
+ * Two families need rewriting. The `create*Provider` / `createLabels` helpers were replaced by
8
+ * `define*`, and their declarations take a pure annotation because they sit in library source. The
9
+ * runtime factories below kept their names - only their return shape changed from tuple to definition -
10
+ * and their call sites are application code, where an annotation would be noise.
11
+ */
12
+ const FACTORY_TO_DEFINE = {
13
+ createProvider: 'defineProvider',
14
+ createRootProvider: 'defineRootProvider',
15
+ createStaticProvider: 'defineStaticProvider',
16
+ createStaticRootProvider: 'defineStaticRootProvider',
17
+ createLabels: 'defineLabels',
18
+ };
19
+ const REF_FACTORIES = new Set([
20
+ 'createQueryClient',
21
+ 'createBearerAuthProvider',
22
+ 'createWebSocketClient',
23
+ 'createQueryContext',
24
+ ]);
25
+ const isKnownFactory = (name) => FACTORY_TO_DEFINE[name] !== undefined || REF_FACTORIES.has(name);
26
+ /** Which extractor names the three tuple positions become. */
27
+ const POSITION_TO_EXTRACTOR = ['toProvideFn', 'toInjectFn', 'toToken'];
28
+ const PURE = '/* @__PURE__ */';
29
+ /** `injectFooBar` / `provideFooBar` / `FOO_BAR_TOKEN` → `FOO_BAR`. */
30
+ const toDefinitionBaseName = (bindingName) => {
31
+ const withoutPrefix = bindingName
32
+ .replace(/^ɵ/, '')
33
+ .replace(/^(provide|inject)/i, '')
34
+ .replace(/_TOKEN$/, '');
35
+ const screaming = withoutPrefix
36
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
37
+ .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
38
+ .toUpperCase();
39
+ return screaming.replace(/^_+|_+$/g, '') || 'PROVIDER';
40
+ };
41
+ const uniqueDefinitionName = (bindingNames, taken) => {
42
+ const base = `${toDefinitionBaseName(bindingNames[1] ?? bindingNames[0] ?? bindingNames[2] ?? 'provider')}_DEF`;
43
+ let candidate = base;
44
+ let suffix = 2;
45
+ while (taken.has(candidate)) {
46
+ candidate = `${base}_${suffix++}`;
47
+ }
48
+ taken.add(candidate);
49
+ return candidate;
50
+ };
51
+ const findTupleSites = (sourceFile) => {
52
+ const sites = [];
53
+ for (const statement of sourceFile.statements) {
54
+ if (!ts.isVariableStatement(statement) || statement.declarationList.declarations.length !== 1)
55
+ continue;
56
+ const declaration = statement.declarationList.declarations[0];
57
+ if (!declaration || !ts.isArrayBindingPattern(declaration.name))
58
+ continue;
59
+ const call = declaration.initializer;
60
+ if (!call || !ts.isCallExpression(call) || !ts.isIdentifier(call.expression))
61
+ continue;
62
+ const factory = call.expression.text;
63
+ if (!isKnownFactory(factory))
64
+ continue;
65
+ const bindings = declaration.name.elements.map((element) => {
66
+ if (ts.isOmittedExpression(element) || !ts.isIdentifier(element.name))
67
+ return null;
68
+ return element.name.text;
69
+ });
70
+ sites.push({
71
+ statement,
72
+ call,
73
+ factory,
74
+ bindings,
75
+ isExported: !!statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword),
76
+ });
77
+ }
78
+ return sites;
79
+ };
80
+ /** The offset the replacement starts at: before the declaration's own JSDoc, if it has one. */
81
+ const declarationStart = (content, statement, sourceFile) => {
82
+ const start = statement.getStart(sourceFile);
83
+ const comments = ts.getLeadingCommentRanges(content, statement.getFullStart());
84
+ const first = comments?.[0];
85
+ // Only treat comments as the declaration's own when nothing but whitespace separates them from it.
86
+ if (!first || /\S/.test(content.slice(comments[comments.length - 1].end, start)))
87
+ return start;
88
+ return first.pos;
89
+ };
90
+ const rewriteSite = (content, sourceFile, site, definitionName) => {
91
+ const start = declarationStart(content, site.statement, sourceFile);
92
+ const statementStart = site.statement.getStart(sourceFile);
93
+ const doc = content.slice(start, statementStart);
94
+ const replacement = FACTORY_TO_DEFINE[site.factory];
95
+ const annotation = replacement ? `${PURE} ` : '';
96
+ const callTail = content.slice(site.call.expression.getEnd(), site.call.getEnd());
97
+ const definition = `const ${definitionName} = ${annotation}${replacement ?? site.factory}${callTail};`;
98
+ const exportKeyword = site.isExported ? 'export ' : '';
99
+ const extractions = site.bindings
100
+ .map((binding, index) => binding === null
101
+ ? null
102
+ : `${exportKeyword}const ${binding} = ${annotation}${POSITION_TO_EXTRACTOR[index]}(${definitionName});`)
103
+ .filter((line) => line !== null);
104
+ // The JSDoc documented the pair, so it belongs on the first binding a consumer can reach.
105
+ const documented = extractions.length > 0 ? [definition, '', doc + extractions[0], ...extractions.slice(1)] : [doc + definition];
106
+ return { start, end: site.statement.getEnd(), text: documented.join('\n') };
107
+ };
108
+ const rewriteImports = (sourceFile, factoriesUsed, extractorsUsed) => {
109
+ const rewrites = [];
110
+ const imports = sourceFile.statements.filter(ts.isImportDeclaration);
111
+ /** The declaration the extractors join: the one that already provides them, else any core import. */
112
+ const extractorHost = imports.find((statement) => namedImportsOf(statement, sourceFile)?.some((name) => extractorsUsed.has(name))) ??
113
+ imports.find((statement) => {
114
+ const names = namedImportsOf(statement, sourceFile);
115
+ return names?.some((name) => FACTORY_TO_DEFINE[name] !== undefined) || isCoreImport(statement);
116
+ });
117
+ for (const statement of imports) {
118
+ const bindings = statement.importClause?.namedBindings;
119
+ if (!bindings || !ts.isNamedImports(bindings))
120
+ continue;
121
+ const names = bindings.elements.map((element) => element.getText(sourceFile));
122
+ // A ref factory keeps its name and its import; only a replaced factory is swapped out.
123
+ const replaced = names.filter((name) => factoriesUsed.has(name) && FACTORY_TO_DEFINE[name] !== undefined);
124
+ const extractors = statement === extractorHost ? [...extractorsUsed] : [];
125
+ if (replaced.length === 0 && extractors.length === 0)
126
+ continue;
127
+ const kept = names.filter((name) => !replaced.includes(name));
128
+ const merged = [
129
+ ...new Set([...kept, ...replaced.map((factory) => FACTORY_TO_DEFINE[factory]), ...extractors]),
130
+ ].sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
131
+ rewrites.push({
132
+ start: bindings.getStart(sourceFile),
133
+ end: bindings.getEnd(),
134
+ text: `{ ${merged.join(', ')} }`,
135
+ });
136
+ }
137
+ if (extractorHost)
138
+ return rewrites;
139
+ // Nothing to join - the file only imported a ref factory from another package, so add a core import.
140
+ const anchor = imports[imports.length - 1];
141
+ const position = anchor ? anchor.getEnd() : 0;
142
+ const statement = `import { ${[...extractorsUsed].sort().join(', ')} } from '@ethlete/core';`;
143
+ rewrites.push({ start: position, end: position, text: anchor ? `\n${statement}` : `${statement}\n` });
144
+ return rewrites;
145
+ };
146
+ const namedImportsOf = (statement, sourceFile) => {
147
+ const bindings = statement.importClause?.namedBindings;
148
+ if (!bindings || !ts.isNamedImports(bindings))
149
+ return undefined;
150
+ return bindings.elements.map((element) => element.getText(sourceFile));
151
+ };
152
+ const isCoreImport = (statement) => ts.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === '@ethlete/core';
153
+ /**
154
+ * Rewrites every top-level destructured provider tuple in one file into a descriptor plus one pure
155
+ * extractor per exported binding. Returns the file unchanged when there is nothing to do.
156
+ */
157
+ export const migrateProviderShapeInFile = (filePath, content) => {
158
+ if (![...Object.keys(FACTORY_TO_DEFINE), ...REF_FACTORIES].some((factory) => content.includes(factory))) {
159
+ return { content, changed: false, tasks: [] };
160
+ }
161
+ const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
162
+ const sites = findTupleSites(sourceFile);
163
+ const tasks = collectTasks(filePath, sourceFile, sites);
164
+ if (sites.length === 0)
165
+ return { content, changed: false, tasks };
166
+ const taken = new Set(sourceFile.statements
167
+ .filter(ts.isVariableStatement)
168
+ .flatMap((statement) => statement.declarationList.declarations)
169
+ .flatMap((declaration) => (ts.isIdentifier(declaration.name) ? [declaration.name.text] : [])));
170
+ const factoriesUsed = new Set(sites.map((site) => site.factory));
171
+ const extractorsUsed = new Set(sites.flatMap((site) => site.bindings.flatMap((binding, index) => (binding === null ? [] : [POSITION_TO_EXTRACTOR[index]]))));
172
+ const edits = [
173
+ ...sites.map((site) => rewriteSite(content, sourceFile, site, uniqueDefinitionName(site.bindings.filter((b) => b !== null), taken))),
174
+ ...rewriteImports(sourceFile, factoriesUsed, extractorsUsed),
175
+ ].sort((a, b) => b.start - a.start);
176
+ let updated = content;
177
+ for (const edit of edits) {
178
+ updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end);
179
+ }
180
+ return { content: updated, changed: updated !== content, tasks };
181
+ };
182
+ /** Call sites the codemod cannot safely rewrite - a factory result that is not a plain tuple binding. */
183
+ const collectTasks = (filePath, sourceFile, sites) => {
184
+ const rewritten = new Set(sites.map((site) => site.statement));
185
+ const tasks = [];
186
+ const visit = (node) => {
187
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && isKnownFactory(node.expression.text)) {
188
+ const statement = enclosingStatement(node);
189
+ if (!statement || !rewritten.has(statement)) {
190
+ const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
191
+ const factory = node.expression.text;
192
+ const replacement = FACTORY_TO_DEFINE[factory];
193
+ tasks.push({
194
+ id: `provider-shape:${filePath}:${line + 1}`,
195
+ file: filePath,
196
+ line: line + 1,
197
+ message: replacement
198
+ ? `\`${factory}\` is gone. Replace it with \`${replacement}\` and read the halves with \`toProvideFn\` / \`toInjectFn\` / \`toToken\`.`
199
+ : `\`${factory}\` returns a provider definition now, not a \`[provide, inject, token]\` tuple. Read the halves with \`toProvideFn\` / \`toInjectFn\` / \`toToken\`, or \`.provide\` / \`.inject\` / \`.token\` inside a function.`,
200
+ });
201
+ }
202
+ }
203
+ ts.forEachChild(node, visit);
204
+ };
205
+ visit(sourceFile);
206
+ return tasks;
207
+ };
208
+ const enclosingStatement = (node) => {
209
+ let current = node;
210
+ while (current && !ts.isSourceFile(current)) {
211
+ if (ts.isVariableStatement(current))
212
+ return current;
213
+ current = current.parent;
214
+ }
215
+ return undefined;
216
+ };
217
+ //# sourceMappingURL=provider-shape.js.map
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "migrate-provider-shape",
4
+ "title": "Migrate provider tuples to the definition shape",
5
+ "type": "object",
6
+ "properties": {
7
+ "projects": {
8
+ "type": "array",
9
+ "items": { "type": "string" },
10
+ "description": "Nx projects to migrate. Defaults to every project in the workspace. Every declaration is rewritten independently, so any scope is safe - use this to keep the diff reviewable.",
11
+ "alias": "project"
12
+ },
13
+ "include": {
14
+ "type": "array",
15
+ "items": { "type": "string" },
16
+ "description": "Path prefixes to migrate, relative to the workspace root (e.g. 'libs/ui'). Unioned with `projects`. Defaults to the whole workspace.",
17
+ "alias": "includePath"
18
+ },
19
+ "skipFormat": {
20
+ "type": "boolean",
21
+ "description": "Skip formatting files after migration",
22
+ "default": false
23
+ }
24
+ },
25
+ "required": []
26
+ }
@@ -0,0 +1,175 @@
1
+ import { logger } from '@nx/devkit';
2
+ /**
3
+ * Symbol renames in TypeScript files (imports + usage).
4
+ */
5
+ const TS_SYMBOL_RENAMES = {
6
+ ProvideThemeDirective: 'ProvideColorDirective',
7
+ THEME_PROVIDER: 'COLOR_PROVIDER',
8
+ ColorThemedDirective: 'ColoredDirective',
9
+ ColorThemedStylesComponent: 'ColoredStylesComponent',
10
+ SurfaceThemedDirective: 'SurfacedDirective',
11
+ SurfaceThemedStylesComponent: 'SurfacedStylesComponent',
12
+ injectThemesPrefix: 'injectColorThemesPrefix',
13
+ createCssThemeName: 'createCssColorThemeName',
14
+ };
15
+ /**
16
+ * String replacements applied to HTML templates and inline templates.
17
+ */
18
+ const TEMPLATE_REPLACEMENTS = [
19
+ ['[etProvideTheme]', '[etProvideColor]'],
20
+ ['etProvideTheme', 'etProvideColor'],
21
+ ['[etProvideAltTheme]', '[etProvideAltColor]'],
22
+ ['etProvideAltTheme', 'etProvideAltColor'],
23
+ ['[etColorThemed]', '[etColored]'],
24
+ ['etColorThemed', 'etColored'],
25
+ ['[etSurfaceThemed]', '[etSurfaced]'],
26
+ ['etSurfaceThemed', 'etSurfaced'],
27
+ ['[theme]=', '[color]='],
28
+ ['[altTheme]=', '[altColor]='],
29
+ ['et-theme-alt--', 'et-color-alt--'],
30
+ ['et-theme--', 'et-color--'],
31
+ ];
32
+ /**
33
+ * CSS class name replacements.
34
+ */
35
+ const CSS_REPLACEMENTS = [
36
+ ['.et-color-themed', '.et-colored'],
37
+ ['.et-surface-themed', '.et-surfaced'],
38
+ ['.et-theme--', '.et-color--'],
39
+ ['.et-theme-alt--', '.et-color-alt--'],
40
+ ];
41
+ /**
42
+ * Host directive input alias replacements in TypeScript files.
43
+ */
44
+ const HOST_DIRECTIVE_REPLACEMENTS = [
45
+ ["'etProvideTheme:theme'", "'etProvideColor:color'"],
46
+ ["'etProvideAltTheme:altTheme'", "'etProvideAltColor:altColor'"],
47
+ ["'etProvideTheme:color'", "'etProvideColor:color'"],
48
+ ["'etProvideAltTheme:altColor'", "'etProvideAltColor:altColor'"],
49
+ ['"etProvideTheme:theme"', '"etProvideColor:color"'],
50
+ ['"etProvideAltTheme:altTheme"', '"etProvideAltColor:altColor"'],
51
+ ['"etProvideTheme"', '"etProvideColor"'],
52
+ ['"etProvideAltTheme"', '"etProvideAltColor"'],
53
+ ];
54
+ export default async function migrateColorNaming(tree) {
55
+ logger.log('\n🔄 Migrating theme → color naming...\n');
56
+ const tsFiles = [];
57
+ const htmlFiles = [];
58
+ const cssFiles = [];
59
+ findFiles('.', tree, tsFiles, htmlFiles, cssFiles);
60
+ let filesModified = 0;
61
+ for (const filePath of tsFiles) {
62
+ const wasModified = migrateTypeScriptFile(tree, filePath);
63
+ if (wasModified) {
64
+ filesModified++;
65
+ logger.log(` ✓ ${filePath}`);
66
+ }
67
+ }
68
+ for (const filePath of htmlFiles) {
69
+ const wasModified = migrateTemplateFile(tree, filePath);
70
+ if (wasModified) {
71
+ filesModified++;
72
+ logger.log(` ✓ ${filePath}`);
73
+ }
74
+ }
75
+ for (const filePath of cssFiles) {
76
+ const wasModified = migrateCssFile(tree, filePath);
77
+ if (wasModified) {
78
+ filesModified++;
79
+ logger.log(` ✓ ${filePath}`);
80
+ }
81
+ }
82
+ if (filesModified > 0) {
83
+ logger.log(`\n✅ Successfully migrated color naming in ${filesModified} file(s)\n`);
84
+ }
85
+ else {
86
+ logger.log('\nℹ️ No files needed migration\n');
87
+ }
88
+ }
89
+ function findFiles(dir, tree, tsFiles, htmlFiles, cssFiles) {
90
+ const children = tree.children(dir);
91
+ for (const child of children) {
92
+ const path = dir === '.' ? child : `${dir}/${child}`;
93
+ if (tree.isFile(path)) {
94
+ if (path.includes('node_modules'))
95
+ continue;
96
+ if (path.endsWith('.ts') && !path.endsWith('.spec.ts')) {
97
+ tsFiles.push(path);
98
+ }
99
+ else if (path.endsWith('.html')) {
100
+ htmlFiles.push(path);
101
+ }
102
+ else if (path.endsWith('.css') || path.endsWith('.scss')) {
103
+ cssFiles.push(path);
104
+ }
105
+ }
106
+ else {
107
+ if (child === 'node_modules')
108
+ continue;
109
+ findFiles(path, tree, tsFiles, htmlFiles, cssFiles);
110
+ }
111
+ }
112
+ }
113
+ function migrateTypeScriptFile(tree, filePath) {
114
+ let content = tree.read(filePath, 'utf-8');
115
+ if (!content)
116
+ return false;
117
+ const original = content;
118
+ // Rename symbols
119
+ for (const [oldName, newName] of Object.entries(TS_SYMBOL_RENAMES)) {
120
+ content = replaceWholeWord(content, oldName, newName);
121
+ }
122
+ // Rename host directive input aliases
123
+ for (const [oldStr, newStr] of HOST_DIRECTIVE_REPLACEMENTS) {
124
+ content = content.replaceAll(oldStr, newStr);
125
+ }
126
+ // Handle inline templates in TypeScript files
127
+ for (const [oldStr, newStr] of TEMPLATE_REPLACEMENTS) {
128
+ content = content.replaceAll(oldStr, newStr);
129
+ }
130
+ // Handle CSS in TypeScript files
131
+ for (const [oldStr, newStr] of CSS_REPLACEMENTS) {
132
+ content = content.replaceAll(oldStr, newStr);
133
+ }
134
+ if (content !== original) {
135
+ tree.write(filePath, content);
136
+ return true;
137
+ }
138
+ return false;
139
+ }
140
+ function migrateTemplateFile(tree, filePath) {
141
+ let content = tree.read(filePath, 'utf-8');
142
+ if (!content)
143
+ return false;
144
+ const original = content;
145
+ for (const [oldStr, newStr] of TEMPLATE_REPLACEMENTS) {
146
+ content = content.replaceAll(oldStr, newStr);
147
+ }
148
+ if (content !== original) {
149
+ tree.write(filePath, content);
150
+ return true;
151
+ }
152
+ return false;
153
+ }
154
+ function migrateCssFile(tree, filePath) {
155
+ let content = tree.read(filePath, 'utf-8');
156
+ if (!content)
157
+ return false;
158
+ const original = content;
159
+ for (const [oldStr, newStr] of CSS_REPLACEMENTS) {
160
+ content = content.replaceAll(oldStr, newStr);
161
+ }
162
+ if (content !== original) {
163
+ tree.write(filePath, content);
164
+ return true;
165
+ }
166
+ return false;
167
+ }
168
+ function replaceWholeWord(content, oldWord, newWord) {
169
+ const regex = new RegExp(`\\b${escapeRegex(oldWord)}\\b`, 'g');
170
+ return content.replace(regex, newWord);
171
+ }
172
+ function escapeRegex(str) {
173
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
174
+ }
175
+ //# sourceMappingURL=color-naming.js.map
@@ -40,7 +40,6 @@ function migrateCreateProviderInFile(tree, filePath) {
40
40
  return false;
41
41
  const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
42
42
  let cdkImport;
43
- let coreImport;
44
43
  let hasCreateProviderInCdk = false;
45
44
  // Find relevant imports
46
45
  for (const statement of sourceFile.statements) {
@@ -52,9 +51,6 @@ function migrateCreateProviderInFile(tree, filePath) {
52
51
  hasCreateProviderInCdk = statement.importClause.namedBindings.elements.some((element) => element.name.text === 'createProvider');
53
52
  }
54
53
  }
55
- else if (modulePath === '@ethlete/core') {
56
- coreImport = statement;
57
- }
58
54
  }
59
55
  }
60
56
  // If createProvider is not imported from @ethlete/cdk, nothing to do
@@ -1,4 +1,5 @@
1
1
  import { formatFiles } from '@nx/devkit';
2
+ import migrateColorNaming from './color-naming.js';
2
3
  import migrateCreateProvider from './create-provider.js';
3
4
  import migrateRouterStateService from './router-state-service.js';
4
5
  import migrateViewportService from './viewport-service.js';
@@ -18,6 +19,11 @@ export default async function migrate(tree, schema) {
18
19
  if (shouldMigrateRouterStateService) {
19
20
  await migrateRouterStateService(tree);
20
21
  }
22
+ const shouldMigrateColorNaming = schema.migrateColorNaming !== false;
23
+ if (shouldMigrateColorNaming) {
24
+ console.log(' • Migrating theme → color naming...');
25
+ await migrateColorNaming(tree);
26
+ }
21
27
  if (!schema.skipFormat) {
22
28
  console.log(' • Formatting files...');
23
29
  await formatFiles(tree);
@@ -23,6 +23,11 @@
23
23
  "type": "boolean",
24
24
  "description": "Migrate router state service to v5",
25
25
  "default": true
26
+ },
27
+ "migrateColorNaming": {
28
+ "type": "boolean",
29
+ "description": "Migrate theme naming to color naming (ProvideThemeDirective -> ProvideColorDirective, etc.)",
30
+ "default": true
26
31
  }
27
32
  },
28
33
  "required": []
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
3
2
  import { logger } from '@nx/devkit';
4
3
  import * as ts from 'typescript';
5
4
  export default async function migrateViewportService(tree) {