ember-codemod-add-component-signatures 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/bin/ember-codemod-add-component-signatures.js +1 -1
  2. package/dist/src/index.js +5 -5
  3. package/dist/src/steps/analyze-project/analyze-components/task.js +59 -0
  4. package/dist/src/steps/analyze-project/analyze-components/worker.js +11 -0
  5. package/dist/src/steps/analyze-project/analyze-components.js +10 -63
  6. package/dist/src/steps/analyze-project/filter-components/task.js +29 -0
  7. package/dist/src/steps/analyze-project/filter-components/worker.js +11 -0
  8. package/dist/src/steps/analyze-project/filter-components.js +11 -27
  9. package/dist/src/steps/analyze-project/find-components.js +1 -1
  10. package/dist/src/steps/analyze-project.js +3 -3
  11. package/dist/src/steps/create-registries/task.js +45 -0
  12. package/dist/src/steps/create-registries/worker.js +11 -0
  13. package/dist/src/steps/create-registries.js +9 -45
  14. package/dist/src/steps/create-signatures/task.js +36 -0
  15. package/dist/src/steps/create-signatures/worker.js +11 -0
  16. package/dist/src/steps/create-signatures.js +9 -36
  17. package/dist/src/steps/create-template-only-components.js +1 -1
  18. package/dist/src/steps/update-signatures/task.js +37 -0
  19. package/dist/src/steps/update-signatures/worker.js +11 -0
  20. package/dist/src/steps/update-signatures.js +9 -37
  21. package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-blocks.js +1 -1
  22. package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-element.js +1 -1
  23. package/dist/src/utils/components/index.js +7 -0
  24. package/dist/src/{steps → utils}/create-registries/rename-component.js +1 -1
  25. package/dist/src/{steps → utils}/create-signatures/create-signature.js +1 -1
  26. package/dist/src/{steps → utils}/update-signatures/update-signature.js +1 -1
  27. package/package.json +2 -1
  28. package/dist/src/utils/components.js +0 -7
  29. /package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/find-arguments.js +0 -0
  30. /package/dist/src/{steps/analyze-project/analyze-components → utils/analyze-project}/index.js +0 -0
  31. /package/dist/src/{steps → utils}/create-registries/create-registry.js +0 -0
  32. /package/dist/src/{steps → utils}/create-registries/has-registry.js +0 -0
  33. /package/dist/src/{steps → utils}/create-registries/index.js +0 -0
  34. /package/dist/src/{steps → utils}/create-registries/rename-component/index.js +0 -0
  35. /package/dist/src/{steps → utils}/create-registries/rename-component/pass-component-name-to-base-component.js +0 -0
  36. /package/dist/src/{steps → utils}/create-registries/rename-component/update-references.js +0 -0
  37. /package/dist/src/{steps → utils}/create-signatures/create-signature/builders.js +0 -0
  38. /package/dist/src/{steps → utils}/create-signatures/create-signature/index.js +0 -0
  39. /package/dist/src/{steps → utils}/create-signatures/create-signature/is-signature.js +0 -0
  40. /package/dist/src/{steps → utils}/create-signatures/create-signature/pass-signature-to-base-component.js +0 -0
  41. /package/dist/src/{steps → utils}/create-signatures/create-signature/update-constructor.js +0 -0
  42. /package/dist/src/{steps → utils}/create-signatures/create-signature/update-reference.js +0 -0
  43. /package/dist/src/{steps → utils}/create-signatures/index.js +0 -0
  44. /package/dist/src/{steps → utils}/update-signatures/index.js +0 -0
  45. /package/dist/src/{steps/update-signatures → utils/update-signatures/update-signature}/builders.js +0 -0
@@ -34,4 +34,4 @@ const codemodOptions = {
34
34
  createRegistries: argv['create-registries'],
35
35
  projectRoot: argv['root'] ?? process.cwd(),
36
36
  };
37
- runCodemod(codemodOptions);
37
+ void 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
- export function runCodemod(codemodOptions) {
2
+ export async function runCodemod(codemodOptions) {
3
3
  const options = createOptions(codemodOptions);
4
4
  if (options.convertJavaScript) {
5
5
  convertToTypeScript(options);
6
6
  }
7
- const context = analyzeProject(options);
7
+ const context = await analyzeProject(options);
8
8
  createTemplateOnlyComponents(context, options);
9
- createSignatures(context, options);
9
+ await createSignatures(context, options);
10
10
  if (options.createRegistries) {
11
- createRegistries(context, options);
11
+ await createRegistries(context, options);
12
12
  }
13
- updateSignatures(context, options);
13
+ await updateSignatures(context, options);
14
14
  }
@@ -0,0 +1,59 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { findTemplateTags, toEcma } from '@codemod-utils/ast-template-tag';
4
+ import { findArguments, findBlocks, findElement, } from '../../../utils/analyze-project/index.js';
5
+ import { getClassPath, getTemplatePath, } from '../../../utils/components/index.js';
6
+ function getFiles(componentName, extensions, options) {
7
+ const { projectRoot } = options;
8
+ if (extensions.has('.gts')) {
9
+ const gtsFilePath = getClassPath(componentName, extensions, options);
10
+ const gtsFile = readFileSync(join(projectRoot, gtsFilePath), 'utf8');
11
+ const ecmaFile = toEcma(gtsFile);
12
+ const templateTags = findTemplateTags(gtsFile);
13
+ const templateFile = templateTags.reduce((accumulator, templateTag) => {
14
+ accumulator += templateTag.contents;
15
+ return accumulator;
16
+ }, '');
17
+ return {
18
+ classFile: ecmaFile,
19
+ templateFile,
20
+ };
21
+ }
22
+ let classFile;
23
+ if (extensions.has('.ts')) {
24
+ const classFilePath = getClassPath(componentName, extensions, options);
25
+ classFile = readFileSync(join(projectRoot, classFilePath), 'utf8');
26
+ }
27
+ const templateFilePath = getTemplatePath(componentName, extensions, options);
28
+ const templateFile = readFileSync(join(projectRoot, templateFilePath), 'utf8');
29
+ return {
30
+ classFile,
31
+ templateFile,
32
+ };
33
+ }
34
+ export function task(componentName, extensions, options) {
35
+ const hasTemplate = extensions.has('.hbs') || extensions.has('.gts');
36
+ const signature = {
37
+ Args: undefined,
38
+ Blocks: undefined,
39
+ Element: undefined,
40
+ };
41
+ if (!hasTemplate) {
42
+ return [componentName, signature];
43
+ }
44
+ const { classFile, templateFile } = getFiles(componentName, extensions, options);
45
+ try {
46
+ signature.Args = findArguments(templateFile, classFile);
47
+ signature.Blocks = findBlocks(templateFile);
48
+ signature.Element = findElement(templateFile);
49
+ return [componentName, signature];
50
+ }
51
+ catch (error) {
52
+ let message = `WARNING: analyzeComponents could not parse \`${componentName}\`. Please update the file manually.`;
53
+ if (error instanceof Error) {
54
+ message += ` (${error.message})`;
55
+ }
56
+ console.warn(message);
57
+ return undefined;
58
+ }
59
+ }
@@ -0,0 +1,11 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { runTask } from '@codemod-utils/threads';
3
+ import { task } from './task.js';
4
+ const { datasets } = workerData;
5
+ runTask(task, datasets)
6
+ .then((results) => {
7
+ parentPort?.postMessage(results);
8
+ })
9
+ .catch((error) => {
10
+ throw error;
11
+ });
@@ -1,66 +1,13 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { findTemplateTags, toEcma } from '@codemod-utils/ast-template-tag';
4
- import { getClassPath, getTemplatePath } from '../../utils/components.js';
5
- import { findArguments, findBlocks, findElement, } from './analyze-components/index.js';
6
- function getFiles(componentName, extensions, options) {
7
- const { projectRoot } = options;
8
- if (extensions.has('.gts')) {
9
- const gtsFilePath = getClassPath(componentName, extensions, options);
10
- const gtsFile = readFileSync(join(projectRoot, gtsFilePath), 'utf8');
11
- const ecmaFile = toEcma(gtsFile);
12
- const templateTags = findTemplateTags(gtsFile);
13
- const templateFile = templateTags.reduce((accumulator, templateTag) => {
14
- accumulator += templateTag.contents;
15
- return accumulator;
16
- }, '');
17
- return {
18
- classFile: ecmaFile,
19
- templateFile,
20
- };
21
- }
22
- let classFile;
23
- if (extensions.has('.ts')) {
24
- const classFilePath = getClassPath(componentName, extensions, options);
25
- classFile = readFileSync(join(projectRoot, classFilePath), 'utf8');
26
- }
27
- const templateFilePath = getTemplatePath(componentName, extensions, options);
28
- const templateFile = readFileSync(join(projectRoot, templateFilePath), 'utf8');
29
- return {
30
- classFile,
31
- templateFile,
32
- };
33
- }
34
- export function analyzeComponents(extensionMap, options) {
35
- const signatureMap = new Map();
1
+ import { parallelize } from '@codemod-utils/threads';
2
+ import { task } from './analyze-components/task.js';
3
+ export async function analyzeComponents(extensionMap, options) {
4
+ const datasets = [];
36
5
  for (const [componentName, extensions] of extensionMap) {
37
- const hasTemplate = extensions.has('.hbs') || extensions.has('.gts');
38
- if (!hasTemplate) {
39
- signatureMap.set(componentName, {
40
- Args: undefined,
41
- Blocks: undefined,
42
- Element: undefined,
43
- });
44
- continue;
45
- }
46
- const { classFile, templateFile } = getFiles(componentName, extensions, options);
47
- try {
48
- const Args = findArguments(templateFile, classFile);
49
- const Blocks = findBlocks(templateFile);
50
- const Element = findElement(templateFile);
51
- signatureMap.set(componentName, {
52
- Args,
53
- Blocks,
54
- Element,
55
- });
56
- }
57
- catch (error) {
58
- let message = `WARNING: analyzeComponents could not parse \`${componentName}\`. Please update the file manually.`;
59
- if (error instanceof Error) {
60
- message += ` (${error.message})`;
61
- }
62
- console.warn(message);
63
- }
6
+ datasets.push([componentName, extensions, options]);
64
7
  }
65
- return signatureMap;
8
+ const entries = await parallelize(task, datasets, {
9
+ importMetaUrl: import.meta.url,
10
+ workerFilePath: './analyze-components/worker.js',
11
+ });
12
+ return new Map(entries.filter((entry) => entry !== undefined));
66
13
  }
@@ -0,0 +1,29 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { toEcma } from '@codemod-utils/ast-template-tag';
4
+ import { getBaseComponent, getClassPath, } from '../../../utils/components/index.js';
5
+ function isSupported(file) {
6
+ const { importPath } = getBaseComponent(file);
7
+ const isComponent = importPath !== undefined;
8
+ const isClassicComponent = importPath === '@ember/component';
9
+ return isComponent && !isClassicComponent;
10
+ }
11
+ export function task(componentName, extensions, options) {
12
+ const { projectRoot } = options;
13
+ const hasClassJavaScript = extensions.has('.gjs') || extensions.has('.js');
14
+ if (hasClassJavaScript) {
15
+ return undefined;
16
+ }
17
+ const filteredExtensions = extensions;
18
+ const hasClassTypeScript = filteredExtensions.has('.gts') || filteredExtensions.has('.ts');
19
+ // hbs file only
20
+ if (!hasClassTypeScript) {
21
+ return [componentName, filteredExtensions];
22
+ }
23
+ const filePath = getClassPath(componentName, filteredExtensions, options);
24
+ const file = readFileSync(join(projectRoot, filePath), 'utf8');
25
+ if (!isSupported(toEcma(file))) {
26
+ return undefined;
27
+ }
28
+ return [componentName, filteredExtensions];
29
+ }
@@ -0,0 +1,11 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { runTask } from '@codemod-utils/threads';
3
+ import { task } from './task.js';
4
+ const { datasets } = workerData;
5
+ runTask(task, datasets)
6
+ .then((results) => {
7
+ parentPort?.postMessage(results);
8
+ })
9
+ .catch((error) => {
10
+ throw error;
11
+ });
@@ -1,29 +1,13 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { toEcma } from '@codemod-utils/ast-template-tag';
4
- import { getBaseComponent, getClassPath } from '../../utils/components.js';
5
- function isSupported(file) {
6
- const { importPath } = getBaseComponent(file);
7
- const isComponent = importPath !== undefined;
8
- const isClassicComponent = importPath === '@ember/component';
9
- return isComponent && !isClassicComponent;
10
- }
11
- export function filterComponents(extensionMap, options) {
12
- const { projectRoot } = options;
13
- const filteredEntries = Array.from(extensionMap.entries()).filter(([componentName, extensions]) => {
14
- const hasClassJavaScript = extensions.has('.gjs') || extensions.has('.js');
15
- if (hasClassJavaScript) {
16
- return false;
17
- }
18
- const hasClassTypeScript = extensions.has('.gts') || extensions.has('.ts');
19
- // hbs file only
20
- if (!hasClassTypeScript) {
21
- return true;
22
- }
23
- const filePath = getClassPath(componentName, extensions, options);
24
- const file = readFileSync(join(projectRoot, filePath), 'utf8');
25
- const ecmaFile = toEcma(file);
26
- return isSupported(ecmaFile);
1
+ import { parallelize } from '@codemod-utils/threads';
2
+ import { task } from './filter-components/task.js';
3
+ export async function filterComponents(extensionMap, options) {
4
+ const datasets = [];
5
+ for (const [componentName, extensions] of extensionMap) {
6
+ datasets.push([componentName, extensions, options]);
7
+ }
8
+ const entries = await parallelize(task, datasets, {
9
+ importMetaUrl: import.meta.url,
10
+ workerFilePath: './filter-components/worker.js',
27
11
  });
28
- return new Map(filteredEntries);
12
+ return new Map(entries.filter((entry) => entry !== undefined));
29
13
  }
@@ -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,8 +1,8 @@
1
1
  import { analyzeComponents, filterComponents, findComponents, } from './analyze-project/index.js';
2
- export function analyzeProject(options) {
2
+ export async function analyzeProject(options) {
3
3
  const unfilteredExtensionMap = findComponents(options);
4
- const extensionMap = filterComponents(unfilteredExtensionMap, options);
5
- const signatureMap = analyzeComponents(extensionMap, options);
4
+ const extensionMap = await filterComponents(unfilteredExtensionMap, options);
5
+ const signatureMap = await analyzeComponents(extensionMap, options);
6
6
  return {
7
7
  extensionMap,
8
8
  signatureMap,
@@ -0,0 +1,45 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { toEcma, updateJavaScript } from '@codemod-utils/ast-template-tag';
4
+ import { doubleColonize, pascalize } from '@codemod-utils/ember';
5
+ import { createFiles, } from '@codemod-utils/files';
6
+ import { getClassPath } from '../../utils/components/index.js';
7
+ import { createRegistry, hasRegistry, renameComponent, } from '../../utils/create-registries/index.js';
8
+ export function task(componentName, extensions, options) {
9
+ const { projectRoot } = options;
10
+ const filePath = getClassPath(componentName, extensions, options);
11
+ let file = readFileSync(join(projectRoot, filePath), 'utf8');
12
+ try {
13
+ const ecmaFile = toEcma(file);
14
+ if (hasRegistry(ecmaFile)) {
15
+ return;
16
+ }
17
+ const data = {
18
+ entity: {
19
+ doubleColonizedName: doubleColonize(componentName),
20
+ name: componentName,
21
+ pascalizedName: pascalize(componentName),
22
+ },
23
+ };
24
+ if (extensions.has('.gts')) {
25
+ file = updateJavaScript(file, (code) => {
26
+ code = renameComponent(code, data);
27
+ code = createRegistry(code, data);
28
+ return code;
29
+ });
30
+ }
31
+ else {
32
+ file = renameComponent(file, data);
33
+ file = createRegistry(file, data);
34
+ }
35
+ const fileMap = new Map([[filePath, file]]);
36
+ createFiles(fileMap, options);
37
+ }
38
+ catch (error) {
39
+ let message = `WARNING: createRegistries could not update \`${filePath}\`. Please update the file manually.`;
40
+ if (error instanceof Error) {
41
+ message += ` (${error.message})`;
42
+ }
43
+ console.warn(message);
44
+ }
45
+ }
@@ -0,0 +1,11 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { runTask } from '@codemod-utils/threads';
3
+ import { task } from './task.js';
4
+ const { datasets } = workerData;
5
+ runTask(task, datasets)
6
+ .then((results) => {
7
+ parentPort?.postMessage(results);
8
+ })
9
+ .catch((error) => {
10
+ throw error;
11
+ });
@@ -1,49 +1,13 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { toEcma, updateJavaScript } from '@codemod-utils/ast-template-tag';
4
- import { doubleColonize, pascalize } from '@codemod-utils/ember';
5
- import { createFiles, } from '@codemod-utils/files';
6
- import { getClassPath } from '../utils/components.js';
7
- import { createRegistry, hasRegistry, renameComponent, } from './create-registries/index.js';
8
- export function createRegistries(context, options) {
1
+ import { parallelize } from '@codemod-utils/threads';
2
+ import { task } from './create-registries/task.js';
3
+ export async function createRegistries(context, options) {
9
4
  const { extensionMap } = context;
10
- const { projectRoot } = options;
11
- const fileMap = new Map();
5
+ const datasets = [];
12
6
  for (const [componentName, extensions] of extensionMap) {
13
- const filePath = getClassPath(componentName, extensions, options);
14
- try {
15
- let file = readFileSync(join(projectRoot, filePath), 'utf8');
16
- const ecmaFile = toEcma(file);
17
- if (hasRegistry(ecmaFile)) {
18
- continue;
19
- }
20
- const data = {
21
- entity: {
22
- doubleColonizedName: doubleColonize(componentName),
23
- name: componentName,
24
- pascalizedName: pascalize(componentName),
25
- },
26
- };
27
- if (extensions.has('.gts')) {
28
- file = updateJavaScript(file, (code) => {
29
- code = renameComponent(code, data);
30
- code = createRegistry(code, data);
31
- return code;
32
- });
33
- }
34
- else {
35
- file = renameComponent(file, data);
36
- file = createRegistry(file, data);
37
- }
38
- fileMap.set(filePath, file);
39
- }
40
- catch (error) {
41
- let message = `WARNING: createRegistries could not update \`${filePath}\`. Please update the file manually.`;
42
- if (error instanceof Error) {
43
- message += ` (${error.message})`;
44
- }
45
- console.warn(message);
46
- }
7
+ datasets.push([componentName, extensions, options]);
47
8
  }
48
- createFiles(fileMap, options);
9
+ await parallelize(task, datasets, {
10
+ importMetaUrl: import.meta.url,
11
+ workerFilePath: './create-registries/worker.js',
12
+ });
49
13
  }
@@ -0,0 +1,36 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { updateJavaScript } from '@codemod-utils/ast-template-tag';
4
+ import { pascalize } from '@codemod-utils/ember';
5
+ import { createFiles, } from '@codemod-utils/files';
6
+ import { getClassPath } from '../../utils/components/index.js';
7
+ import { createSignature } from '../../utils/create-signatures/index.js';
8
+ export function task(componentName, extensions, options) {
9
+ const { projectRoot } = options;
10
+ const filePath = getClassPath(componentName, extensions, options);
11
+ let file = readFileSync(join(projectRoot, filePath), 'utf8');
12
+ const data = {
13
+ entity: {
14
+ pascalizedName: pascalize(componentName),
15
+ },
16
+ };
17
+ try {
18
+ if (extensions.has('.gts')) {
19
+ file = updateJavaScript(file, (code) => {
20
+ return createSignature(code, data);
21
+ });
22
+ }
23
+ else {
24
+ file = createSignature(file, data);
25
+ }
26
+ const fileMap = new Map([[filePath, file]]);
27
+ createFiles(fileMap, options);
28
+ }
29
+ catch (error) {
30
+ let message = `WARNING: createSignatures could not update \`${filePath}\`. Please update the file manually.`;
31
+ if (error instanceof Error) {
32
+ message += ` (${error.message})`;
33
+ }
34
+ console.warn(message);
35
+ }
36
+ }
@@ -0,0 +1,11 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { runTask } from '@codemod-utils/threads';
3
+ import { task } from './task.js';
4
+ const { datasets } = workerData;
5
+ runTask(task, datasets)
6
+ .then((results) => {
7
+ parentPort?.postMessage(results);
8
+ })
9
+ .catch((error) => {
10
+ throw error;
11
+ });
@@ -1,40 +1,13 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { updateJavaScript } from '@codemod-utils/ast-template-tag';
4
- import { pascalize } from '@codemod-utils/ember';
5
- import { createFiles, } from '@codemod-utils/files';
6
- import { getClassPath } from '../utils/components.js';
7
- import { createSignature } from './create-signatures/index.js';
8
- export function createSignatures(context, options) {
1
+ import { parallelize } from '@codemod-utils/threads';
2
+ import { task } from './create-signatures/task.js';
3
+ export async function createSignatures(context, options) {
9
4
  const { extensionMap } = context;
10
- const { projectRoot } = options;
11
- const fileMap = new Map();
5
+ const datasets = [];
12
6
  for (const [componentName, extensions] of extensionMap) {
13
- const filePath = getClassPath(componentName, extensions, options);
14
- const data = {
15
- entity: {
16
- pascalizedName: pascalize(componentName),
17
- },
18
- };
19
- try {
20
- let file = readFileSync(join(projectRoot, filePath), 'utf8');
21
- if (extensions.has('.gts')) {
22
- file = updateJavaScript(file, (code) => {
23
- return createSignature(code, data);
24
- });
25
- }
26
- else {
27
- file = createSignature(file, data);
28
- }
29
- fileMap.set(filePath, file);
30
- }
31
- catch (error) {
32
- let message = `WARNING: createSignatures could not update \`${filePath}\`. Please update the file manually.`;
33
- if (error instanceof Error) {
34
- message += ` (${error.message})`;
35
- }
36
- console.warn(message);
37
- }
7
+ datasets.push([componentName, extensions, options]);
38
8
  }
39
- createFiles(fileMap, options);
9
+ await parallelize(task, datasets, {
10
+ importMetaUrl: import.meta.url,
11
+ workerFilePath: './create-signatures/worker.js',
12
+ });
40
13
  }
@@ -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;
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { updateJavaScript } from '@codemod-utils/ast-template-tag';
4
+ import { pascalize } from '@codemod-utils/ember';
5
+ import { createFiles, } from '@codemod-utils/files';
6
+ import { getClassPath } from '../../utils/components/index.js';
7
+ import { updateSignature } from '../../utils/update-signatures/index.js';
8
+ export function task(componentName, extensions, signature, options) {
9
+ const { projectRoot } = options;
10
+ const filePath = getClassPath(componentName, extensions, options);
11
+ let file = readFileSync(join(projectRoot, filePath), 'utf8');
12
+ try {
13
+ const data = {
14
+ entity: {
15
+ pascalizedName: pascalize(componentName),
16
+ },
17
+ signature,
18
+ };
19
+ if (extensions.has('.gts')) {
20
+ file = updateJavaScript(file, (code) => {
21
+ return updateSignature(code, data);
22
+ });
23
+ }
24
+ else {
25
+ file = updateSignature(file, data);
26
+ }
27
+ const fileMap = new Map([[filePath, file]]);
28
+ createFiles(fileMap, options);
29
+ }
30
+ catch (error) {
31
+ let message = `WARNING: updateSignatures could not update \`${filePath}\`. Please update the file manually.`;
32
+ if (error instanceof Error) {
33
+ message += ` (${error.message})`;
34
+ }
35
+ console.warn(message);
36
+ }
37
+ }
@@ -0,0 +1,11 @@
1
+ import { parentPort, workerData } from 'node:worker_threads';
2
+ import { runTask } from '@codemod-utils/threads';
3
+ import { task } from './task.js';
4
+ const { datasets } = workerData;
5
+ runTask(task, datasets)
6
+ .then((results) => {
7
+ parentPort?.postMessage(results);
8
+ })
9
+ .catch((error) => {
10
+ throw error;
11
+ });
@@ -1,42 +1,14 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { updateJavaScript } from '@codemod-utils/ast-template-tag';
4
- import { pascalize } from '@codemod-utils/ember';
5
- import { createFiles, } from '@codemod-utils/files';
6
- import { getClassPath } from '../utils/components.js';
7
- import { updateSignature } from './update-signatures/index.js';
8
- export function updateSignatures(context, options) {
1
+ import { parallelize } from '@codemod-utils/threads';
2
+ import { task } from './update-signatures/task.js';
3
+ export async function updateSignatures(context, options) {
9
4
  const { extensionMap, signatureMap } = context;
10
- const { projectRoot } = options;
11
- const fileMap = new Map();
5
+ const datasets = [];
12
6
  for (const [componentName, signature] of signatureMap) {
13
7
  const extensions = extensionMap.get(componentName);
14
- const filePath = getClassPath(componentName, extensions, options);
15
- try {
16
- let file = readFileSync(join(projectRoot, filePath), 'utf8');
17
- const data = {
18
- entity: {
19
- pascalizedName: pascalize(componentName),
20
- },
21
- signature,
22
- };
23
- if (extensions.has('.gts')) {
24
- file = updateJavaScript(file, (code) => {
25
- return updateSignature(code, data);
26
- });
27
- }
28
- else {
29
- file = updateSignature(file, data);
30
- }
31
- fileMap.set(filePath, file);
32
- }
33
- catch (error) {
34
- let message = `WARNING: updateSignatures could not update \`${filePath}\`. Please update the file manually.`;
35
- if (error instanceof Error) {
36
- message += ` (${error.message})`;
37
- }
38
- console.warn(message);
39
- }
8
+ datasets.push([componentName, extensions, signature, options]);
40
9
  }
41
- createFiles(fileMap, options);
10
+ await parallelize(task, datasets, {
11
+ importMetaUrl: import.meta.url,
12
+ workerFilePath: './update-signatures/worker.js',
13
+ });
42
14
  }
@@ -1,5 +1,5 @@
1
1
  import { AST } from '@codemod-utils/ast-template';
2
- import { getBlockParameterType, normalizeBlockName, } from '../../../utils/components.js';
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();
@@ -1,5 +1,5 @@
1
1
  import { AST } from '@codemod-utils/ast-template';
2
- import { getHtmlInterface } from '../../../utils/components.js';
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,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-codemod-add-component-signatures",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "Codemod to add component signatures",
5
5
  "keywords": [
6
6
  "codemod",
@@ -31,6 +31,7 @@
31
31
  "@codemod-utils/ember": "^4.1.0",
32
32
  "@codemod-utils/files": "^4.0.0",
33
33
  "@codemod-utils/package-json": "^4.0.0",
34
+ "@codemod-utils/threads": "^0.2.0",
34
35
  "yargs": "^18.0.0"
35
36
  },
36
37
  "devDependencies": {
@@ -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';