ember-codemod-add-component-signatures 5.1.0 → 5.2.1
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/README.md +14 -2
- package/dist/bin/ember-codemod-add-component-signatures.js +6 -0
- package/dist/src/index.js +6 -6
- package/dist/src/steps/analyze-project/analyze-components.js +2 -2
- package/dist/src/steps/analyze-project/filter-components.js +14 -10
- package/dist/src/steps/analyze-project/find-components.js +1 -1
- package/dist/src/steps/convert-to-typescript.js +1 -4
- package/dist/src/steps/create-options.js +2 -1
- package/dist/src/steps/create-registries.js +2 -2
- package/dist/src/steps/create-signatures.js +2 -2
- package/dist/src/steps/create-template-only-components.js +1 -1
- package/dist/src/steps/update-signatures.js +2 -2
- package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-blocks.js +1 -1
- package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-element.js +1 -1
- package/dist/src/utils/components/index.js +7 -0
- package/dist/src/{steps → utils}/create-registries/rename-component.js +1 -1
- package/dist/src/{steps → utils}/create-signatures/create-signature.js +1 -1
- package/dist/src/{steps → utils}/update-signatures/update-signature.js +1 -1
- package/package.json +1 -1
- package/dist/src/utils/components.js +0 -7
- /package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-arguments.js +0 -0
- /package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/index.js +0 -0
- /package/dist/src/{steps → utils}/create-registries/create-registry.js +0 -0
- /package/dist/src/{steps → utils}/create-registries/has-registry.js +0 -0
- /package/dist/src/{steps → utils}/create-registries/index.js +0 -0
- /package/dist/src/{steps → utils}/create-registries/rename-component/index.js +0 -0
- /package/dist/src/{steps → utils}/create-registries/rename-component/pass-component-name-to-base-component.js +0 -0
- /package/dist/src/{steps → utils}/create-registries/rename-component/update-references.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/create-signature/builders.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/create-signature/index.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/create-signature/is-signature.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/create-signature/pass-signature-to-base-component.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/create-signature/update-constructor.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/create-signature/update-reference.js +0 -0
- /package/dist/src/{steps → utils}/create-signatures/index.js +0 -0
- /package/dist/src/{steps → utils}/update-signatures/index.js +0 -0
- /package/dist/src/{steps/update-signatures → utils/update-signatures/update-signature}/builders.js +0 -0
package/README.md
CHANGED
|
@@ -15,8 +15,8 @@ You can run this codemod to get started.
|
|
|
15
15
|
## Features
|
|
16
16
|
|
|
17
17
|
- Scaffolds signature for components
|
|
18
|
-
- Adds template registry for components
|
|
19
|
-
- Supports `<template>` tag
|
|
18
|
+
- Adds template registry for components (Glint v1)
|
|
19
|
+
- Supports `<template>` tag (Glint v2)
|
|
20
20
|
|
|
21
21
|
<div align="center">
|
|
22
22
|
<figure>
|
|
@@ -90,6 +90,18 @@ pnpx ember-codemod-add-component-signatures --convert-javascript
|
|
|
90
90
|
|
|
91
91
|
<details>
|
|
92
92
|
|
|
93
|
+
<summary>Optional: Create registries</summary>
|
|
94
|
+
|
|
95
|
+
By default, the codemod doesn't add registries to component classes, because these registries are unnecessary for Glint v2 (strict mode templates). Pass `--create-registries` if you use Glint v1 (loose mode templates).
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
pnpx ember-codemod-add-component-signatures --create-registries
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
</details>
|
|
102
|
+
|
|
103
|
+
<details>
|
|
104
|
+
|
|
93
105
|
<summary>Optional: Specify the project root</summary>
|
|
94
106
|
|
|
95
107
|
Pass `--root` to run the codemod on a project somewhere else (i.e. not in the current directory).
|
|
@@ -17,6 +17,11 @@ const argv = yargs(hideBin(process.argv))
|
|
|
17
17
|
default: false,
|
|
18
18
|
describe: 'Convert *.{js,gjs} files?',
|
|
19
19
|
type: 'boolean',
|
|
20
|
+
})
|
|
21
|
+
.option('create-registries', {
|
|
22
|
+
default: false,
|
|
23
|
+
describe: 'Create registries for Glint v1?',
|
|
24
|
+
type: 'boolean',
|
|
20
25
|
})
|
|
21
26
|
.option('root', {
|
|
22
27
|
describe: 'Location of your Ember project',
|
|
@@ -26,6 +31,7 @@ const argv = yargs(hideBin(process.argv))
|
|
|
26
31
|
const codemodOptions = {
|
|
27
32
|
componentStructure: argv['component-structure'],
|
|
28
33
|
convertJavaScript: argv['convert-javascript'],
|
|
34
|
+
createRegistries: argv['create-registries'],
|
|
29
35
|
projectRoot: argv['root'] ?? process.cwd(),
|
|
30
36
|
};
|
|
31
37
|
runCodemod(codemodOptions);
|
package/dist/src/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { analyzeProject, convertToTypeScript, createOptions, createRegistries, createSignatures, createTemplateOnlyComponents, updateSignatures, } from './steps/index.js';
|
|
2
2
|
export function runCodemod(codemodOptions) {
|
|
3
3
|
const options = createOptions(codemodOptions);
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
if (options.convertJavaScript) {
|
|
5
|
+
convertToTypeScript(options);
|
|
6
|
+
}
|
|
6
7
|
const context = analyzeProject(options);
|
|
7
|
-
// Update components without backing class
|
|
8
8
|
createTemplateOnlyComponents(context, options);
|
|
9
|
-
// Update components with backing class
|
|
10
9
|
createSignatures(context, options);
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
if (options.createRegistries) {
|
|
11
|
+
createRegistries(context, options);
|
|
12
|
+
}
|
|
13
13
|
updateSignatures(context, options);
|
|
14
14
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { findTemplateTags, toEcma } from '@codemod-utils/ast-template-tag';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { findArguments, findBlocks, findElement, } from '../../utils/analyze-project/index.js';
|
|
5
|
+
import { getClassPath, getTemplatePath } from '../../utils/components/index.js';
|
|
6
6
|
function getFiles(componentName, extensions, options) {
|
|
7
7
|
const { projectRoot } = options;
|
|
8
8
|
if (extensions.has('.gts')) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { toEcma } from '@codemod-utils/ast-template-tag';
|
|
4
|
-
import { getBaseComponent, getClassPath } from '../../utils/components.js';
|
|
4
|
+
import { getBaseComponent, getClassPath, } from '../../utils/components/index.js';
|
|
5
5
|
function isSupported(file) {
|
|
6
6
|
const { importPath } = getBaseComponent(file);
|
|
7
7
|
const isComponent = importPath !== undefined;
|
|
@@ -10,20 +10,24 @@ function isSupported(file) {
|
|
|
10
10
|
}
|
|
11
11
|
export function filterComponents(extensionMap, options) {
|
|
12
12
|
const { projectRoot } = options;
|
|
13
|
-
const
|
|
13
|
+
const newExtensionMap = new Map();
|
|
14
|
+
for (const [componentName, extensions] of extensionMap) {
|
|
14
15
|
const hasClassJavaScript = extensions.has('.gjs') || extensions.has('.js');
|
|
15
16
|
if (hasClassJavaScript) {
|
|
16
|
-
|
|
17
|
+
continue;
|
|
17
18
|
}
|
|
18
|
-
const
|
|
19
|
+
const filteredExtensions = extensions;
|
|
20
|
+
const hasClassTypeScript = filteredExtensions.has('.gts') || filteredExtensions.has('.ts');
|
|
19
21
|
// hbs file only
|
|
20
22
|
if (!hasClassTypeScript) {
|
|
21
|
-
|
|
23
|
+
newExtensionMap.set(componentName, filteredExtensions);
|
|
24
|
+
continue;
|
|
22
25
|
}
|
|
23
|
-
const filePath = getClassPath(componentName,
|
|
26
|
+
const filePath = getClassPath(componentName, filteredExtensions, options);
|
|
24
27
|
const file = readFileSync(join(projectRoot, filePath), 'utf8');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
if (isSupported(toEcma(file))) {
|
|
29
|
+
newExtensionMap.set(componentName, filteredExtensions);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return newExtensionMap;
|
|
29
33
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
|
|
2
|
-
import { getExtensionMap } from '../../utils/components.js';
|
|
2
|
+
import { getExtensionMap } from '../../utils/components/index.js';
|
|
3
3
|
function normalizeComponentNames(extensionMap) {
|
|
4
4
|
return new Map(Array.from(extensionMap.entries()).map(([oldName, extensions]) => {
|
|
5
5
|
const newName = oldName.replace(/\/index$/, '');
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { findFiles, moveFiles } from '@codemod-utils/files';
|
|
2
2
|
export function convertToTypeScript(options) {
|
|
3
|
-
const {
|
|
4
|
-
if (!convertJavaScript) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
3
|
+
const { projectRoot, src } = options;
|
|
7
4
|
const filePaths = findFiles(`${src}/components/**/*.{gjs,js}`, {
|
|
8
5
|
projectRoot,
|
|
9
6
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getPackageType, readPackageJson } from '@codemod-utils/package-json';
|
|
2
2
|
import { SOURCE_DIRECTORY } from '../utils/ember.js';
|
|
3
3
|
export function createOptions(codemodOptions) {
|
|
4
|
-
const { componentStructure, convertJavaScript, projectRoot } = codemodOptions;
|
|
4
|
+
const { componentStructure, convertJavaScript, createRegistries, projectRoot, } = codemodOptions;
|
|
5
5
|
const packageJson = readPackageJson({ projectRoot });
|
|
6
6
|
const packageType = getPackageType(packageJson);
|
|
7
7
|
if (packageType === 'node') {
|
|
@@ -11,6 +11,7 @@ export function createOptions(codemodOptions) {
|
|
|
11
11
|
return {
|
|
12
12
|
componentStructure,
|
|
13
13
|
convertJavaScript,
|
|
14
|
+
createRegistries,
|
|
14
15
|
projectRoot,
|
|
15
16
|
src,
|
|
16
17
|
};
|
|
@@ -3,8 +3,8 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { toEcma, updateJavaScript } from '@codemod-utils/ast-template-tag';
|
|
4
4
|
import { doubleColonize, pascalize } from '@codemod-utils/ember';
|
|
5
5
|
import { createFiles, } from '@codemod-utils/files';
|
|
6
|
-
import { getClassPath } from '../utils/components.js';
|
|
7
|
-
import { createRegistry, hasRegistry, renameComponent, } from '
|
|
6
|
+
import { getClassPath } from '../utils/components/index.js';
|
|
7
|
+
import { createRegistry, hasRegistry, renameComponent, } from '../utils/create-registries/index.js';
|
|
8
8
|
export function createRegistries(context, options) {
|
|
9
9
|
const { extensionMap } = context;
|
|
10
10
|
const { projectRoot } = options;
|
|
@@ -3,8 +3,8 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { updateJavaScript } from '@codemod-utils/ast-template-tag';
|
|
4
4
|
import { pascalize } from '@codemod-utils/ember';
|
|
5
5
|
import { createFiles, } from '@codemod-utils/files';
|
|
6
|
-
import { getClassPath } from '../utils/components.js';
|
|
7
|
-
import { createSignature } from '
|
|
6
|
+
import { getClassPath } from '../utils/components/index.js';
|
|
7
|
+
import { createSignature } from '../utils/create-signatures/index.js';
|
|
8
8
|
export function createSignatures(context, options) {
|
|
9
9
|
const { extensionMap } = context;
|
|
10
10
|
const { projectRoot } = options;
|
|
@@ -4,7 +4,7 @@ import { processTemplate } from '@codemod-utils/blueprints';
|
|
|
4
4
|
import { pascalize } from '@codemod-utils/ember';
|
|
5
5
|
import { createFiles, } from '@codemod-utils/files';
|
|
6
6
|
import { blueprintsRoot } from '../utils/blueprints.js';
|
|
7
|
-
import { getClassPath } from '../utils/components.js';
|
|
7
|
+
import { getClassPath } from '../utils/components/index.js';
|
|
8
8
|
const blueprintFile = readFileSync(join(blueprintsRoot, 'ember-cli/template-only-component.ts'), 'utf8');
|
|
9
9
|
export function createTemplateOnlyComponents(context, options) {
|
|
10
10
|
const { extensionMap } = context;
|
|
@@ -3,8 +3,8 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { updateJavaScript } from '@codemod-utils/ast-template-tag';
|
|
4
4
|
import { pascalize } from '@codemod-utils/ember';
|
|
5
5
|
import { createFiles, } from '@codemod-utils/files';
|
|
6
|
-
import { getClassPath } from '../utils/components.js';
|
|
7
|
-
import { updateSignature } from '
|
|
6
|
+
import { getClassPath } from '../utils/components/index.js';
|
|
7
|
+
import { updateSignature } from '../utils/update-signatures/index.js';
|
|
8
8
|
export function updateSignatures(context, options) {
|
|
9
9
|
const { extensionMap, signatureMap } = context;
|
|
10
10
|
const { projectRoot } = options;
|
package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-blocks.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AST } from '@codemod-utils/ast-template';
|
|
2
|
-
import { getBlockParameterType, normalizeBlockName, } from '
|
|
2
|
+
import { getBlockParameterType, normalizeBlockName, } from '../components/index.js';
|
|
3
3
|
export function findBlocks(templateFile) {
|
|
4
4
|
const traverse = AST.traverse();
|
|
5
5
|
const blocksMap = new Map();
|
package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-element.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AST } from '@codemod-utils/ast-template';
|
|
2
|
-
import { getHtmlInterface } from '
|
|
2
|
+
import { getHtmlInterface } from '../components/index.js';
|
|
3
3
|
export function findElement(templateFile) {
|
|
4
4
|
const traverse = AST.traverse();
|
|
5
5
|
const htmlInterfaces = new Set();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './get-base-component.js';
|
|
2
|
+
export * from './get-block-parameter.type.js';
|
|
3
|
+
export * from './get-class-path.js';
|
|
4
|
+
export * from './get-extension-map.js';
|
|
5
|
+
export * from './get-html-interface.js';
|
|
6
|
+
export * from './get-template-path.js';
|
|
7
|
+
export * from './normalize-block-name.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getBaseComponent } from '../../utils/components.js';
|
|
1
|
+
import { getBaseComponent } from '../../utils/components/index.js';
|
|
2
2
|
import { passComponentNameToBaseComponent, updateReferences, } from './rename-component/index.js';
|
|
3
3
|
export function renameComponent(file, data) {
|
|
4
4
|
const { baseComponentName } = getBaseComponent(file);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getBaseComponent } from '../../utils/components.js';
|
|
1
|
+
import { getBaseComponent } from '../../utils/components/index.js';
|
|
2
2
|
import { passSignatureToBaseComponent, updateConstructor, updateReferences, } from './create-signature/index.js';
|
|
3
3
|
export function createSignature(file, data) {
|
|
4
4
|
const { baseComponentName } = getBaseComponent(file);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AST } from '@codemod-utils/ast-javascript';
|
|
2
|
-
import { builderCreateArgsNode, builderCreateBlocksNode, builderCreateElementNode, } from './builders.js';
|
|
2
|
+
import { builderCreateArgsNode, builderCreateBlocksNode, builderCreateElementNode, } from './update-signature/builders.js';
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
4
4
|
function getBodyNode(node, key) {
|
|
5
5
|
// @ts-expect-error: Assume that types from external packages are correct
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from './components/get-base-component.js';
|
|
2
|
-
export * from './components/get-block-parameter.type.js';
|
|
3
|
-
export * from './components/get-class-path.js';
|
|
4
|
-
export * from './components/get-extension-map.js';
|
|
5
|
-
export * from './components/get-html-interface.js';
|
|
6
|
-
export * from './components/get-template-path.js';
|
|
7
|
-
export * from './components/normalize-block-name.js';
|
|
File without changes
|
/package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/src/{steps/update-signatures → utils/update-signatures/update-signature}/builders.js
RENAMED
|
File without changes
|