@craft-ts/dev-tools 0.7.0-beta.13
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.
- package/LICENSE +21 -0
- package/README.md +154 -0
- package/generators.json +26 -0
- package/package.json +119 -0
- package/src/bin/craft-architecture-check.d.ts +2 -0
- package/src/bin/craft-architecture-check.js +51 -0
- package/src/bin/craft-architecture-check.js.map +1 -0
- package/src/bin/craft-brand.d.ts +2 -0
- package/src/bin/craft-brand.js +9 -0
- package/src/bin/craft-brand.js.map +1 -0
- package/src/bin/craft-graph.d.ts +2 -0
- package/src/bin/craft-graph.js +72 -0
- package/src/bin/craft-graph.js.map +1 -0
- package/src/bin/craft-migrate-architecture.d.ts +2 -0
- package/src/bin/craft-migrate-architecture.js +64 -0
- package/src/bin/craft-migrate-architecture.js.map +1 -0
- package/src/bin/craft-migrate-components.d.ts +2 -0
- package/src/bin/craft-migrate-components.js +67 -0
- package/src/bin/craft-migrate-components.js.map +1 -0
- package/src/bin/craft-migrate-primitives.d.ts +2 -0
- package/src/bin/craft-migrate-primitives.js +71 -0
- package/src/bin/craft-migrate-primitives.js.map +1 -0
- package/src/bin/craft-migrate-routes.d.ts +2 -0
- package/src/bin/craft-migrate-routes.js +77 -0
- package/src/bin/craft-migrate-routes.js.map +1 -0
- package/src/bin/craft-migrate-services.d.ts +2 -0
- package/src/bin/craft-migrate-services.js +75 -0
- package/src/bin/craft-migrate-services.js.map +1 -0
- package/src/bin/craft-migrate-template.d.ts +2 -0
- package/src/bin/craft-migrate-template.js +68 -0
- package/src/bin/craft-migrate-template.js.map +1 -0
- package/src/bin/craft-migrate.d.ts +2 -0
- package/src/bin/craft-migrate.js +91 -0
- package/src/bin/craft-migrate.js.map +1 -0
- package/src/bin/craft.d.ts +2 -0
- package/src/bin/craft.js +318 -0
- package/src/bin/craft.js.map +1 -0
- package/src/eslint-rules/anchor-has-href.cjs +35 -0
- package/src/eslint-rules/app-start-registry-match.cjs +355 -0
- package/src/eslint-rules/button-has-type.cjs +50 -0
- package/src/eslint-rules/control-has-accessible-name.cjs +56 -0
- package/src/eslint-rules/craft-component-name-match.cjs +8 -0
- package/src/eslint-rules/craft-computed-name-match.cjs +63 -0
- package/src/eslint-rules/craft-css-token-registry.cjs +17 -0
- package/src/eslint-rules/craft-css-var-naming.cjs +18 -0
- package/src/eslint-rules/craft-css-vars-contract.cjs +34 -0
- package/src/eslint-rules/craft-directive-name-match.cjs +8 -0
- package/src/eslint-rules/craft-method-name-match.cjs +8 -0
- package/src/eslint-rules/craft-name-match-utils.cjs +179 -0
- package/src/eslint-rules/craft-primitive-context.cjs +46 -0
- package/src/eslint-rules/craft-signal-source-name-match.cjs +8 -0
- package/src/eslint-rules/craft-source-name-match.cjs +8 -0
- package/src/eslint-rules/craft-styles-scope-safe.cjs +25 -0
- package/src/eslint-rules/css-rule-utils.cjs +109 -0
- package/src/eslint-rules/global-exception-registry-match.cjs +562 -0
- package/src/eslint-rules/heading-has-content.cjs +31 -0
- package/src/eslint-rules/html-helpers.cjs +115 -0
- package/src/eslint-rules/hyperscript-walk.cjs +249 -0
- package/src/eslint-rules/iframe-has-title.cjs +26 -0
- package/src/eslint-rules/img-has-alt.cjs +28 -0
- package/src/eslint-rules/index.cjs +209 -0
- package/src/eslint-rules/index.d.cts +5 -0
- package/src/eslint-rules/label-has-associated-control.cjs +67 -0
- package/src/eslint-rules/no-async-await.cjs +46 -0
- package/src/eslint-rules/no-craft-computed-side-effects.cjs +301 -0
- package/src/eslint-rules/no-craft-use-in-template.cjs +89 -0
- package/src/eslint-rules/no-craft-use.cjs +42 -0
- package/src/eslint-rules/no-direct-temporal-globals.cjs +73 -0
- package/src/eslint-rules/no-effect-in-params.cjs +265 -0
- package/src/eslint-rules/no-effect-outside-loaders.cjs +3 -0
- package/src/eslint-rules/no-ephemeral-template-form-state.cjs +131 -0
- package/src/eslint-rules/no-hardcoded-design-values.cjs +15 -0
- package/src/eslint-rules/no-heading-level-skip.cjs +101 -0
- package/src/eslint-rules/no-imperative-craft-resource-trigger.cjs +291 -0
- package/src/eslint-rules/no-important-in-component-styles.cjs +12 -0
- package/src/eslint-rules/no-injection-token.cjs +173 -0
- package/src/eslint-rules/no-invalid-insertion-pipe.cjs +162 -0
- package/src/eslint-rules/no-manual-route-provider-list.cjs +85 -0
- package/src/eslint-rules/no-noninteractive-element-interactions.cjs +66 -0
- package/src/eslint-rules/no-positive-tabindex.cjs +44 -0
- package/src/eslint-rules/no-redundant-primitive-insertion.cjs +361 -0
- package/src/eslint-rules/no-render-writes.cjs +106 -0
- package/src/eslint-rules/no-throw.cjs +132 -0
- package/src/eslint-rules/no-transition-actions.cjs +133 -0
- package/src/eslint-rules/no-type-assertions-in-template.cjs +211 -0
- package/src/eslint-rules/no-widened-route-provider-context.cjs +39 -0
- package/src/eslint-rules/prefer-browser-boundaries.cjs +92 -0
- package/src/eslint-rules/prefer-craft-http-transport.cjs +103 -0
- package/src/eslint-rules/prefer-craft-template-blocks.cjs +492 -0
- package/src/eslint-rules/prefer-direct-yieldable-callback.cjs +105 -0
- package/src/eslint-rules/prefer-named-html-helpers.cjs +33 -0
- package/src/eslint-rules/prefer-query-method-over-state-trigger.cjs +282 -0
- package/src/eslint-rules/prefer-relative-heading.cjs +43 -0
- package/src/eslint-rules/provide-host-name-match-component.cjs +455 -0
- package/src/eslint-rules/recommended-config.cjs +77 -0
- package/src/eslint-rules/require-assert-exhaustive-route-exceptions.cjs +259 -0
- package/src/eslint-rules/require-cascade-route-di-check.cjs +223 -0
- package/src/eslint-rules/require-child-route-mount-check.cjs +224 -0
- package/src/eslint-rules/require-component-monitoring.cjs +212 -0
- package/src/eslint-rules/require-craft-exception-handler.cjs +142 -0
- package/src/eslint-rules/require-craft-method-for-yieldable-callback.cjs +236 -0
- package/src/eslint-rules/require-craft-resource-trigger-yield.cjs +209 -0
- package/src/eslint-rules/require-effect-adapters.cjs +86 -0
- package/src/eslint-rules/require-exception-component-di-check.cjs +314 -0
- package/src/eslint-rules/require-focus-visible.cjs +36 -0
- package/src/eslint-rules/require-interactive-local-name.cjs +105 -0
- package/src/eslint-rules/require-lazy-load-with-retry.cjs +148 -0
- package/src/eslint-rules/require-outlet-heading-section.cjs +70 -0
- package/src/eslint-rules/require-pending-component-di-check.cjs +490 -0
- package/src/eslint-rules/require-primitive-context.cjs +156 -0
- package/src/eslint-rules/require-primitive-derived-property.cjs +598 -0
- package/src/eslint-rules/require-primitive-generator-unwrap.cjs +274 -0
- package/src/eslint-rules/require-reactive-template-bindings.cjs +305 -0
- package/src/eslint-rules/require-reduced-motion.cjs +38 -0
- package/src/eslint-rules/require-route-heading-outline.cjs +166 -0
- package/src/eslint-rules/require-yieldable-insertion-write.cjs +98 -0
- package/src/eslint-rules/require-yieldable-reactive-read.cjs +102 -0
- package/src/eslint-rules/require-yieldable-template-method.cjs +424 -0
- package/src/eslint-rules/role-has-required-aria.cjs +38 -0
- package/src/eslint-rules/server-function-client-match.cjs +283 -0
- package/src/eslint-rules/target-blank-noopener.cjs +31 -0
- package/src/eslint-rules/template-element-name-unique.cjs +124 -0
- package/src/eslint-rules/valid-aria.cjs +38 -0
- package/src/generators/route/compat.d.ts +3 -0
- package/src/generators/route/compat.js +6 -0
- package/src/generators/route/compat.js.map +1 -0
- package/src/generators/route/generator.d.ts +31 -0
- package/src/generators/route/generator.js +402 -0
- package/src/generators/route/generator.js.map +1 -0
- package/src/generators/route/schema.json +50 -0
- package/src/generators/route/split-schema.json +19 -0
- package/src/index.d.ts +21 -0
- package/src/index.js +23 -0
- package/src/index.js.map +1 -0
- package/src/scripts/angular-brand-codemod.d.ts +139 -0
- package/src/scripts/angular-brand-codemod.js +2318 -0
- package/src/scripts/angular-brand-codemod.js.map +1 -0
- package/src/scripts/angular-brand-codemod.ts +3985 -0
- package/src/scripts/architecture/migrate-architecture.d.ts +14 -0
- package/src/scripts/architecture/migrate-architecture.js +534 -0
- package/src/scripts/architecture/migrate-architecture.js.map +1 -0
- package/src/scripts/architecture/migrate-architecture.ts +653 -0
- package/src/scripts/architecture-graph.d.ts +368 -0
- package/src/scripts/architecture-graph.js +2191 -0
- package/src/scripts/architecture-graph.js.map +1 -0
- package/src/scripts/architecture-graph.ts +3136 -0
- package/src/scripts/components/migrate-components.d.ts +20 -0
- package/src/scripts/components/migrate-components.js +163 -0
- package/src/scripts/components/migrate-components.js.map +1 -0
- package/src/scripts/components/migrate-components.ts +227 -0
- package/src/scripts/components/migration-diagnostic.d.ts +7 -0
- package/src/scripts/components/migration-diagnostic.js +2 -0
- package/src/scripts/components/migration-diagnostic.js.map +1 -0
- package/src/scripts/components/migration-diagnostic.ts +8 -0
- package/src/scripts/create/create-project.d.ts +20 -0
- package/src/scripts/create/create-project.js +783 -0
- package/src/scripts/create/create-project.js.map +1 -0
- package/src/scripts/create/create-project.ts +849 -0
- package/src/scripts/data-flow-graph.d.ts +36 -0
- package/src/scripts/data-flow-graph.js +186 -0
- package/src/scripts/data-flow-graph.js.map +1 -0
- package/src/scripts/data-flow-graph.ts +240 -0
- package/src/scripts/dependency-graph.d.ts +152 -0
- package/src/scripts/dependency-graph.js +4456 -0
- package/src/scripts/dependency-graph.js.map +1 -0
- package/src/scripts/dependency-graph.ts +5908 -0
- package/src/scripts/effect-dependency-graph.d.ts +89 -0
- package/src/scripts/effect-dependency-graph.js +487 -0
- package/src/scripts/effect-dependency-graph.js.map +1 -0
- package/src/scripts/effect-dependency-graph.ts +630 -0
- package/src/scripts/migrate.d.ts +37 -0
- package/src/scripts/migrate.js +98 -0
- package/src/scripts/migrate.js.map +1 -0
- package/src/scripts/migrate.ts +162 -0
- package/src/scripts/migration-workspace.d.ts +2 -0
- package/src/scripts/migration-workspace.js +67 -0
- package/src/scripts/migration-workspace.js.map +1 -0
- package/src/scripts/migration-workspace.ts +93 -0
- package/src/scripts/primitives/migrate-named-primitives.d.ts +50 -0
- package/src/scripts/primitives/migrate-named-primitives.js +487 -0
- package/src/scripts/primitives/migrate-named-primitives.js.map +1 -0
- package/src/scripts/primitives/migrate-named-primitives.ts +627 -0
- package/src/scripts/primitives/migrate-primitive-generators.d.ts +30 -0
- package/src/scripts/primitives/migrate-primitive-generators.js +309 -0
- package/src/scripts/primitives/migrate-primitive-generators.js.map +1 -0
- package/src/scripts/primitives/migrate-primitive-generators.ts +410 -0
- package/src/scripts/primitives/migrate-primitives.d.ts +27 -0
- package/src/scripts/primitives/migrate-primitives.js +427 -0
- package/src/scripts/primitives/migrate-primitives.js.map +1 -0
- package/src/scripts/primitives/migrate-primitives.ts +655 -0
- package/src/scripts/primitives/migrate-yieldable-reactive-reads.d.ts +23 -0
- package/src/scripts/primitives/migrate-yieldable-reactive-reads.js +382 -0
- package/src/scripts/primitives/migrate-yieldable-reactive-reads.js.map +1 -0
- package/src/scripts/primitives/migrate-yieldable-reactive-reads.ts +499 -0
- package/src/scripts/primitives/migration-diagnostic.d.ts +8 -0
- package/src/scripts/primitives/migration-diagnostic.js +2 -0
- package/src/scripts/primitives/migration-diagnostic.js.map +1 -0
- package/src/scripts/primitives/migration-diagnostic.ts +15 -0
- package/src/scripts/routes/migrate-routes.d.ts +34 -0
- package/src/scripts/routes/migrate-routes.js +657 -0
- package/src/scripts/routes/migrate-routes.js.map +1 -0
- package/src/scripts/routes/migrate-routes.ts +895 -0
- package/src/scripts/routes/migration-diagnostic.d.ts +16 -0
- package/src/scripts/routes/migration-diagnostic.js +2 -0
- package/src/scripts/routes/migration-diagnostic.js.map +1 -0
- package/src/scripts/routes/migration-diagnostic.ts +25 -0
- package/src/scripts/routes/route-command.d.ts +75 -0
- package/src/scripts/routes/route-command.js +1169 -0
- package/src/scripts/routes/route-command.js.map +1 -0
- package/src/scripts/routes/route-command.ts +1807 -0
- package/src/scripts/routes/verify-routes.d.ts +60 -0
- package/src/scripts/routes/verify-routes.js +1121 -0
- package/src/scripts/routes/verify-routes.js.map +1 -0
- package/src/scripts/routes/verify-routes.ts +1511 -0
- package/src/scripts/services/config.d.ts +2 -0
- package/src/scripts/services/config.js +38 -0
- package/src/scripts/services/config.js.map +1 -0
- package/src/scripts/services/config.ts +60 -0
- package/src/scripts/services/migrate-services.d.ts +29 -0
- package/src/scripts/services/migrate-services.js +924 -0
- package/src/scripts/services/migrate-services.js.map +1 -0
- package/src/scripts/services/migrate-services.ts +1348 -0
- package/src/scripts/services/migration-diagnostic.d.ts +8 -0
- package/src/scripts/services/migration-diagnostic.js +2 -0
- package/src/scripts/services/migration-diagnostic.js.map +1 -0
- package/src/scripts/services/migration-diagnostic.ts +28 -0
- package/src/scripts/template/migrate-template.d.ts +16 -0
- package/src/scripts/template/migrate-template.js +349 -0
- package/src/scripts/template/migrate-template.js.map +1 -0
- package/src/scripts/template/migrate-template.ts +418 -0
- package/src/template-migration.d.ts +1 -0
- package/src/template-migration.js +2 -0
- package/src/template-migration.js.map +1 -0
- package/src/testing.d.ts +19 -0
- package/src/testing.js +2 -0
- package/src/testing.js.map +1 -0
- package/src/tsconfig.codemod.json +13 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ComponentMigrationDiagnostic } from './migration-diagnostic.js';
|
|
2
|
+
export type MigrateComponentsOptions = {
|
|
3
|
+
rootDir?: string;
|
|
4
|
+
tsConfigFilePath?: string;
|
|
5
|
+
files?: readonly string[];
|
|
6
|
+
write?: boolean;
|
|
7
|
+
check?: boolean;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
failOnManual?: boolean;
|
|
10
|
+
eslint?: boolean;
|
|
11
|
+
log?: (message: string) => void;
|
|
12
|
+
};
|
|
13
|
+
export type MigrateComponentsResult = {
|
|
14
|
+
changedFiles: string[];
|
|
15
|
+
diagnostics: ComponentMigrationDiagnostic[];
|
|
16
|
+
remainingLegacyComponents: number;
|
|
17
|
+
remainingLegacyDirectives: number;
|
|
18
|
+
exitCode: number;
|
|
19
|
+
};
|
|
20
|
+
export declare function runComponentsMigration(options?: MigrateComponentsOptions): Promise<MigrateComponentsResult>;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { Node, Project, QuoteKind, SyntaxKind, } from 'ts-morph';
|
|
4
|
+
export async function runComponentsMigration(options = {}) {
|
|
5
|
+
const rootDir = resolve(options.rootDir ?? process.cwd());
|
|
6
|
+
const tsConfigFilePath = options.tsConfigFilePath
|
|
7
|
+
? resolve(options.tsConfigFilePath)
|
|
8
|
+
: join(rootDir, 'tsconfig.json');
|
|
9
|
+
const project = new Project({
|
|
10
|
+
...(existsSync(tsConfigFilePath) ? { tsConfigFilePath } : {}),
|
|
11
|
+
manipulationSettings: { quoteKind: QuoteKind.Single },
|
|
12
|
+
skipAddingFilesFromTsConfig: false,
|
|
13
|
+
});
|
|
14
|
+
project.addSourceFilesAtPaths([
|
|
15
|
+
join(rootDir, '**/*.ts'),
|
|
16
|
+
`!${join(rootDir, '**/node_modules/**')}`,
|
|
17
|
+
`!${join(rootDir, '**/dist/**')}`,
|
|
18
|
+
`!${join(rootDir, '**/.angular/**')}`,
|
|
19
|
+
`!${join(rootDir, '**/*.d.ts')}`,
|
|
20
|
+
]);
|
|
21
|
+
const selected = options.files?.length
|
|
22
|
+
? new Set(options.files.map((file) => resolve(rootDir, file)))
|
|
23
|
+
: undefined;
|
|
24
|
+
const sourceFiles = project.getSourceFiles().filter((file) => {
|
|
25
|
+
const path = resolve(file.getFilePath());
|
|
26
|
+
return path.startsWith(`${rootDir}/`) && (!selected || selected.has(path));
|
|
27
|
+
});
|
|
28
|
+
const touched = new Set();
|
|
29
|
+
const diagnostics = [];
|
|
30
|
+
const legacyComponentsBeforeMigration = sourceFiles.reduce((count, sourceFile) => count + countLegacyComponentCalls(sourceFile), 0);
|
|
31
|
+
for (const sourceFile of sourceFiles) {
|
|
32
|
+
const componentImport = sourceFile
|
|
33
|
+
.getImportDeclarations()
|
|
34
|
+
.flatMap((declaration) => declaration.getNamedImports())
|
|
35
|
+
.find((specifier) => specifier.getName() === 'component');
|
|
36
|
+
const componentNameNode = componentImport?.getNameNode();
|
|
37
|
+
const componentAliasNode = componentImport?.getAliasNode();
|
|
38
|
+
if (componentImport && componentAliasNode) {
|
|
39
|
+
if (componentAliasNode.getText() !== 'craftComponent') {
|
|
40
|
+
componentAliasNode.rename('craftComponent');
|
|
41
|
+
}
|
|
42
|
+
componentImport.setName('craftComponent').removeAlias();
|
|
43
|
+
touched.add(sourceFile);
|
|
44
|
+
}
|
|
45
|
+
else if (componentNameNode && Node.isIdentifier(componentNameNode)) {
|
|
46
|
+
if (componentNameNode.getText() !== 'craftComponent') {
|
|
47
|
+
componentNameNode.rename('craftComponent');
|
|
48
|
+
touched.add(sourceFile);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const componentCalls = sourceFile
|
|
52
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
53
|
+
.filter((call) => call.getExpression().getText() === 'craftComponent');
|
|
54
|
+
for (const call of componentCalls.sort((a, b) => b.getStart() - a.getStart())) {
|
|
55
|
+
const name = declaredNameFor(call);
|
|
56
|
+
if (!name) {
|
|
57
|
+
diagnostics.push({
|
|
58
|
+
code: 'NAME_NOT_DEDUCIBLE',
|
|
59
|
+
filePath: sourceFile.getFilePath(),
|
|
60
|
+
message: 'Could not infer the name for craftComponent(...).',
|
|
61
|
+
manual: true,
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!isStringLiteral(call.getArguments()[0])) {
|
|
66
|
+
call.insertArgument(0, `'${name}'`);
|
|
67
|
+
touched.add(sourceFile);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const directiveCalls = sourceFile
|
|
71
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
72
|
+
.filter((call) => call.getExpression().getText() === 'craftDirective');
|
|
73
|
+
for (const call of directiveCalls.sort((a, b) => b.getStart() - a.getStart())) {
|
|
74
|
+
const name = declaredNameFor(call);
|
|
75
|
+
if (!name) {
|
|
76
|
+
diagnostics.push({
|
|
77
|
+
code: 'NAME_NOT_DEDUCIBLE',
|
|
78
|
+
filePath: sourceFile.getFilePath(),
|
|
79
|
+
message: 'Could not infer the name for craftDirective(...).',
|
|
80
|
+
manual: true,
|
|
81
|
+
});
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (!isStringLiteral(call.getArguments()[0])) {
|
|
85
|
+
call.insertArgument(0, `'${name}'`);
|
|
86
|
+
call.insertArgument(1, '{}');
|
|
87
|
+
touched.add(sourceFile);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (options.write)
|
|
92
|
+
await Promise.all([...touched].map((file) => file.save()));
|
|
93
|
+
const remainingLegacyComponentsAfterMigration = sourceFiles.reduce((count, sourceFile) => {
|
|
94
|
+
const hasLegacyImport = sourceFile
|
|
95
|
+
.getImportDeclarations()
|
|
96
|
+
.flatMap((declaration) => declaration.getNamedImports())
|
|
97
|
+
.some((specifier) => specifier.getName() === 'component');
|
|
98
|
+
return hasLegacyImport
|
|
99
|
+
? count + countCalls(sourceFile, 'component')
|
|
100
|
+
: count;
|
|
101
|
+
}, 0);
|
|
102
|
+
const remainingLegacyComponents = options.write
|
|
103
|
+
? remainingLegacyComponentsAfterMigration
|
|
104
|
+
: legacyComponentsBeforeMigration;
|
|
105
|
+
const remainingLegacyDirectives = sourceFiles.reduce((count, sourceFile) => count + countCalls(sourceFile, 'craftDirective', true), 0);
|
|
106
|
+
const result = {
|
|
107
|
+
changedFiles: [...touched].map((file) => file.getFilePath()),
|
|
108
|
+
diagnostics,
|
|
109
|
+
remainingLegacyComponents,
|
|
110
|
+
remainingLegacyDirectives,
|
|
111
|
+
exitCode: (options.check &&
|
|
112
|
+
(remainingLegacyComponents > 0 || remainingLegacyDirectives > 0)) ||
|
|
113
|
+
(options.failOnManual && diagnostics.length > 0)
|
|
114
|
+
? 1
|
|
115
|
+
: 0,
|
|
116
|
+
};
|
|
117
|
+
const log = options.log ?? console.log;
|
|
118
|
+
if (options.json)
|
|
119
|
+
log(JSON.stringify(result, null, 2));
|
|
120
|
+
else
|
|
121
|
+
log(`Components migration complete: ${result.changedFiles.length} changed file(s), ${diagnostics.length} manual diagnostic(s).`);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function declaredNameFor(call) {
|
|
125
|
+
let current = call;
|
|
126
|
+
while (current) {
|
|
127
|
+
if (Node.isVariableDeclaration(current) && current.getNameNode()) {
|
|
128
|
+
return current.getName();
|
|
129
|
+
}
|
|
130
|
+
if (Node.isPropertyDeclaration(current) ||
|
|
131
|
+
Node.isPropertyAssignment(current)) {
|
|
132
|
+
return current.getName();
|
|
133
|
+
}
|
|
134
|
+
current = current.getParent();
|
|
135
|
+
}
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
function isStringLiteral(node) {
|
|
139
|
+
return Boolean(node &&
|
|
140
|
+
(Node.isStringLiteral(node) ||
|
|
141
|
+
(Node.isNoSubstitutionTemplateLiteral(node) && node.getLiteralText())));
|
|
142
|
+
}
|
|
143
|
+
function countCalls(sourceFile, name, migrated = false) {
|
|
144
|
+
return sourceFile
|
|
145
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
146
|
+
.filter((call) => {
|
|
147
|
+
const expression = call.getExpression().getText();
|
|
148
|
+
return migrated
|
|
149
|
+
? expression === name && !isStringLiteral(call.getArguments()[0])
|
|
150
|
+
: expression === name;
|
|
151
|
+
}).length;
|
|
152
|
+
}
|
|
153
|
+
function countLegacyComponentCalls(sourceFile) {
|
|
154
|
+
const localNames = new Set(sourceFile
|
|
155
|
+
.getImportDeclarations()
|
|
156
|
+
.flatMap((declaration) => declaration.getNamedImports())
|
|
157
|
+
.filter((specifier) => specifier.getName() === 'component')
|
|
158
|
+
.map((specifier) => specifier.getAliasNode()?.getText() ?? 'component'));
|
|
159
|
+
return sourceFile
|
|
160
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
161
|
+
.filter((call) => localNames.has(call.getExpression().getText())).length;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=migrate-components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-components.js","sourceRoot":"","sources":["../../../../../../libs/dev-tools/src/scripts/components/migrate-components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,IAAI,EACJ,OAAO,EACP,SAAS,EAET,UAAU,GAEX,MAAM,UAAU,CAAC;AAuBlB,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,UAAoC,EAAE;IAEtC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1D,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB;QAC/C,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACnC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC;QAC1B,GAAG,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7D,oBAAoB,EAAE,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE;QACrD,2BAA2B,EAAE,KAAK;KACnC,CAAC,CAAC;IACH,OAAO,CAAC,qBAAqB,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;QACxB,IAAI,IAAI,CAAC,OAAO,EAAE,oBAAoB,CAAC,EAAE;QACzC,IAAI,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE;QACjC,IAAI,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAE;QACrC,IAAI,IAAI,CAAC,OAAO,EAAE,WA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B,CAAC,UAAU,CAAC,cAAc,CAAC;SAC/C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACf,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,CAAC;QAClD,OAAO,QAAQ;YACb,CAAC,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;YACjE,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC;IAC1B,CAAC,CAAC,CAAC,MAAM,CAAC;AACd,CAAC;AAED,SAAS,yBAAyB,CAAC,UAAsB;IACvD,MAAM,UAAU,GAAG,IAAI,GAAG,CACxB,UAAU;SACP,qBAAqB,EAAE;SACvB,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,eAAe,EAAE,CAAC;SACvD,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,WAAW,CAAC;SAC1D,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,CAC1E,CAAC;IACF,OAAO,UAAU;SACd,oBAAoB,CAAC,UAAU,CAAC,cAAc,CAAC;SAC/C,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC7E,CAAC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import {
|
|
4
|
+
Node,
|
|
5
|
+
Project,
|
|
6
|
+
QuoteKind,
|
|
7
|
+
SourceFile,
|
|
8
|
+
SyntaxKind,
|
|
9
|
+
type CallExpression,
|
|
10
|
+
} from 'ts-morph';
|
|
11
|
+
import type { ComponentMigrationDiagnostic } from './migration-diagnostic.js';
|
|
12
|
+
|
|
13
|
+
export type MigrateComponentsOptions = {
|
|
14
|
+
rootDir?: string;
|
|
15
|
+
tsConfigFilePath?: string;
|
|
16
|
+
files?: readonly string[];
|
|
17
|
+
write?: boolean;
|
|
18
|
+
check?: boolean;
|
|
19
|
+
json?: boolean;
|
|
20
|
+
failOnManual?: boolean;
|
|
21
|
+
eslint?: boolean;
|
|
22
|
+
log?: (message: string) => void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type MigrateComponentsResult = {
|
|
26
|
+
changedFiles: string[];
|
|
27
|
+
diagnostics: ComponentMigrationDiagnostic[];
|
|
28
|
+
remainingLegacyComponents: number;
|
|
29
|
+
remainingLegacyDirectives: number;
|
|
30
|
+
exitCode: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export async function runComponentsMigration(
|
|
34
|
+
options: MigrateComponentsOptions = {},
|
|
35
|
+
): Promise<MigrateComponentsResult> {
|
|
36
|
+
const rootDir = resolve(options.rootDir ?? process.cwd());
|
|
37
|
+
const tsConfigFilePath = options.tsConfigFilePath
|
|
38
|
+
? resolve(options.tsConfigFilePath)
|
|
39
|
+
: join(rootDir, 'tsconfig.json');
|
|
40
|
+
const project = new Project({
|
|
41
|
+
...(existsSync(tsConfigFilePath) ? { tsConfigFilePath } : {}),
|
|
42
|
+
manipulationSettings: { quoteKind: QuoteKind.Single },
|
|
43
|
+
skipAddingFilesFromTsConfig: false,
|
|
44
|
+
});
|
|
45
|
+
project.addSourceFilesAtPaths([
|
|
46
|
+
join(rootDir, '**/*.ts'),
|
|
47
|
+
`!${join(rootDir, '**/node_modules/**')}`,
|
|
48
|
+
`!${join(rootDir, '**/dist/**')}`,
|
|
49
|
+
`!${join(rootDir, '**/.angular/**')}`,
|
|
50
|
+
`!${join(rootDir, '**/*.d.ts')}`,
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const selected = options.files?.length
|
|
54
|
+
? new Set(options.files.map((file) => resolve(rootDir, file)))
|
|
55
|
+
: undefined;
|
|
56
|
+
const sourceFiles = project.getSourceFiles().filter((file) => {
|
|
57
|
+
const path = resolve(file.getFilePath());
|
|
58
|
+
return path.startsWith(`${rootDir}/`) && (!selected || selected.has(path));
|
|
59
|
+
});
|
|
60
|
+
const touched = new Set<SourceFile>();
|
|
61
|
+
const diagnostics: ComponentMigrationDiagnostic[] = [];
|
|
62
|
+
const legacyComponentsBeforeMigration = sourceFiles.reduce(
|
|
63
|
+
(count, sourceFile) => count + countLegacyComponentCalls(sourceFile),
|
|
64
|
+
0,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
for (const sourceFile of sourceFiles) {
|
|
68
|
+
const componentImport = sourceFile
|
|
69
|
+
.getImportDeclarations()
|
|
70
|
+
.flatMap((declaration) => declaration.getNamedImports())
|
|
71
|
+
.find((specifier) => specifier.getName() === 'component');
|
|
72
|
+
const componentNameNode = componentImport?.getNameNode();
|
|
73
|
+
const componentAliasNode = componentImport?.getAliasNode();
|
|
74
|
+
if (componentImport && componentAliasNode) {
|
|
75
|
+
if (componentAliasNode.getText() !== 'craftComponent') {
|
|
76
|
+
componentAliasNode.rename('craftComponent');
|
|
77
|
+
}
|
|
78
|
+
componentImport.setName('craftComponent').removeAlias();
|
|
79
|
+
touched.add(sourceFile);
|
|
80
|
+
} else if (componentNameNode && Node.isIdentifier(componentNameNode)) {
|
|
81
|
+
if (componentNameNode.getText() !== 'craftComponent') {
|
|
82
|
+
componentNameNode.rename('craftComponent');
|
|
83
|
+
touched.add(sourceFile);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const componentCalls = sourceFile
|
|
88
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
89
|
+
.filter((call) => call.getExpression().getText() === 'craftComponent');
|
|
90
|
+
for (const call of componentCalls.sort(
|
|
91
|
+
(a, b) => b.getStart() - a.getStart(),
|
|
92
|
+
)) {
|
|
93
|
+
const name = declaredNameFor(call);
|
|
94
|
+
if (!name) {
|
|
95
|
+
diagnostics.push({
|
|
96
|
+
code: 'NAME_NOT_DEDUCIBLE',
|
|
97
|
+
filePath: sourceFile.getFilePath(),
|
|
98
|
+
message: 'Could not infer the name for craftComponent(...).',
|
|
99
|
+
manual: true,
|
|
100
|
+
});
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (!isStringLiteral(call.getArguments()[0])) {
|
|
104
|
+
call.insertArgument(0, `'${name}'`);
|
|
105
|
+
touched.add(sourceFile);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const directiveCalls = sourceFile
|
|
110
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
111
|
+
.filter((call) => call.getExpression().getText() === 'craftDirective');
|
|
112
|
+
for (const call of directiveCalls.sort(
|
|
113
|
+
(a, b) => b.getStart() - a.getStart(),
|
|
114
|
+
)) {
|
|
115
|
+
const name = declaredNameFor(call);
|
|
116
|
+
if (!name) {
|
|
117
|
+
diagnostics.push({
|
|
118
|
+
code: 'NAME_NOT_DEDUCIBLE',
|
|
119
|
+
filePath: sourceFile.getFilePath(),
|
|
120
|
+
message: 'Could not infer the name for craftDirective(...).',
|
|
121
|
+
manual: true,
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (!isStringLiteral(call.getArguments()[0])) {
|
|
126
|
+
call.insertArgument(0, `'${name}'`);
|
|
127
|
+
call.insertArgument(1, '{}');
|
|
128
|
+
touched.add(sourceFile);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (options.write) await Promise.all([...touched].map((file) => file.save()));
|
|
134
|
+
|
|
135
|
+
const remainingLegacyComponentsAfterMigration = sourceFiles.reduce(
|
|
136
|
+
(count, sourceFile) => {
|
|
137
|
+
const hasLegacyImport = sourceFile
|
|
138
|
+
.getImportDeclarations()
|
|
139
|
+
.flatMap((declaration) => declaration.getNamedImports())
|
|
140
|
+
.some((specifier) => specifier.getName() === 'component');
|
|
141
|
+
return hasLegacyImport
|
|
142
|
+
? count + countCalls(sourceFile, 'component')
|
|
143
|
+
: count;
|
|
144
|
+
},
|
|
145
|
+
0,
|
|
146
|
+
);
|
|
147
|
+
const remainingLegacyComponents = options.write
|
|
148
|
+
? remainingLegacyComponentsAfterMigration
|
|
149
|
+
: legacyComponentsBeforeMigration;
|
|
150
|
+
const remainingLegacyDirectives = sourceFiles.reduce(
|
|
151
|
+
(count, sourceFile) =>
|
|
152
|
+
count + countCalls(sourceFile, 'craftDirective', true),
|
|
153
|
+
0,
|
|
154
|
+
);
|
|
155
|
+
const result: MigrateComponentsResult = {
|
|
156
|
+
changedFiles: [...touched].map((file) => file.getFilePath()),
|
|
157
|
+
diagnostics,
|
|
158
|
+
remainingLegacyComponents,
|
|
159
|
+
remainingLegacyDirectives,
|
|
160
|
+
exitCode:
|
|
161
|
+
(options.check &&
|
|
162
|
+
(remainingLegacyComponents > 0 || remainingLegacyDirectives > 0)) ||
|
|
163
|
+
(options.failOnManual && diagnostics.length > 0)
|
|
164
|
+
? 1
|
|
165
|
+
: 0,
|
|
166
|
+
};
|
|
167
|
+
const log = options.log ?? console.log;
|
|
168
|
+
if (options.json) log(JSON.stringify(result, null, 2));
|
|
169
|
+
else
|
|
170
|
+
log(
|
|
171
|
+
`Components migration complete: ${result.changedFiles.length} changed file(s), ${diagnostics.length} manual diagnostic(s).`,
|
|
172
|
+
);
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function declaredNameFor(call: CallExpression): string | undefined {
|
|
177
|
+
let current: Node | undefined = call;
|
|
178
|
+
while (current) {
|
|
179
|
+
if (Node.isVariableDeclaration(current) && current.getNameNode()) {
|
|
180
|
+
return current.getName();
|
|
181
|
+
}
|
|
182
|
+
if (
|
|
183
|
+
Node.isPropertyDeclaration(current) ||
|
|
184
|
+
Node.isPropertyAssignment(current)
|
|
185
|
+
) {
|
|
186
|
+
return current.getName();
|
|
187
|
+
}
|
|
188
|
+
current = current.getParent();
|
|
189
|
+
}
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function isStringLiteral(node: Node | undefined): boolean {
|
|
194
|
+
return Boolean(
|
|
195
|
+
node &&
|
|
196
|
+
(Node.isStringLiteral(node) ||
|
|
197
|
+
(Node.isNoSubstitutionTemplateLiteral(node) && node.getLiteralText())),
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function countCalls(
|
|
202
|
+
sourceFile: SourceFile,
|
|
203
|
+
name: string,
|
|
204
|
+
migrated = false,
|
|
205
|
+
): number {
|
|
206
|
+
return sourceFile
|
|
207
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
208
|
+
.filter((call) => {
|
|
209
|
+
const expression = call.getExpression().getText();
|
|
210
|
+
return migrated
|
|
211
|
+
? expression === name && !isStringLiteral(call.getArguments()[0])
|
|
212
|
+
: expression === name;
|
|
213
|
+
}).length;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function countLegacyComponentCalls(sourceFile: SourceFile): number {
|
|
217
|
+
const localNames = new Set(
|
|
218
|
+
sourceFile
|
|
219
|
+
.getImportDeclarations()
|
|
220
|
+
.flatMap((declaration) => declaration.getNamedImports())
|
|
221
|
+
.filter((specifier) => specifier.getName() === 'component')
|
|
222
|
+
.map((specifier) => specifier.getAliasNode()?.getText() ?? 'component'),
|
|
223
|
+
);
|
|
224
|
+
return sourceFile
|
|
225
|
+
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
226
|
+
.filter((call) => localNames.has(call.getExpression().getText())).length;
|
|
227
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-diagnostic.js","sourceRoot":"","sources":["../../../../../../libs/dev-tools/src/scripts/components/migration-diagnostic.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const CRAFT_TS_STARTER_VERSION = "^0.7.0-beta.11";
|
|
2
|
+
export declare const EFFECT_V4_VERSION = "^4.0.0-rc.110";
|
|
3
|
+
export type CreateAgent = 'codex' | 'cursor' | 'claude-code' | 'cloud-code';
|
|
4
|
+
export type CreateMode = 'effect' | 'plain';
|
|
5
|
+
export type CreateProjectOptions = {
|
|
6
|
+
readonly directory: string;
|
|
7
|
+
readonly rootDir?: string;
|
|
8
|
+
readonly mode?: CreateMode;
|
|
9
|
+
readonly agents?: readonly CreateAgent[];
|
|
10
|
+
readonly force?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type CreateProjectResult = {
|
|
13
|
+
readonly directory: string;
|
|
14
|
+
readonly mode: CreateMode;
|
|
15
|
+
readonly agents: readonly CreateAgent[];
|
|
16
|
+
readonly changedFiles: readonly string[];
|
|
17
|
+
};
|
|
18
|
+
export declare function parseCreateAgents(value: string | undefined): readonly CreateAgent[];
|
|
19
|
+
export declare function createCraftProject(options: CreateProjectOptions): Promise<CreateProjectResult>;
|
|
20
|
+
export declare function createModeFromFlag(value: string | undefined): CreateMode | undefined;
|