Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,33 @@ npx @codemod-utils/cli <your-codemod-name>

- [Main tutorial](./tutorials/main-tutorial/00-introduction.md)
- [Create blueprints](./tutorials/create-blueprints/00-introduction.md)
- [Support Windows](./tutorials/support-windows/00-introduction.md)
- [Update CSS files](./tutorials/update-css-files/00-introduction.md)
- [Update `<template>` tags](./tutorials/update-template-tags/00-introduction.md)


## Codemods written with @codemod-utils

- [`@ember-intl/lint`](https://github.com/ember-intl/ember-intl/tree/main/packages/ember-intl-lint)
- [`analyze-ember-project-dependencies`](https://github.com/ijlee2/analyze-ember-project-dependencies)
- [`blueprints-v2-addon`](https://github.com/ijlee2/create-v2-addon-repo/tree/main/packages/blueprints-v2-addon)
- [`codemod-generate-release-notes`](https://github.com/Ajanth/codemod-generate-release-notes)
- [`create-v2-addon-repo`](https://github.com/ijlee2/create-v2-addon-repo/tree/main/packages/create-v2-addon-repo)
- [`ember-codemod-add-component-signatures`](https://github.com/ijlee2/ember-codemod-add-component-signatures)
- [`ember-codemod-add-missing-tests`](https://github.com/ijlee2/ember-codemod-add-missing-tests)
- [`ember-codemod-add-template-tags`](https://github.com/ijlee2/ember-codemod-add-template-tags)
- [`ember-codemod-css-modules`](https://github.com/simplepractice/ember-codemod-css-modules)
- [`ember-codemod-ember-render-helpers-to-v1`](https://github.com/buschtoens/ember-render-helpers/tree/main/packages/ember-codemod-ember-render-helpers-to-v1)
- [`ember-codemod-pod-to-octane`](https://github.com/ijlee2/ember-codemod-pod-to-octane)
- [`ember-codemod-remove-global-styles`](https://github.com/ijlee2/embroider-css-modules/tree/main/packages/ember-codemod-remove-global-styles)
- [`ember-codemod-remove-ember-css-modules`](https://github.com/ijlee2/embroider-css-modules/tree/main/packages/ember-codemod-remove-ember-css-modules)
- [`ember-codemod-remove-inject-as-service`](https://github.com/ijlee2/ember-codemod-remove-inject-as-service)
- [`ember-codemod-rename-test-modules`](https://github.com/ijlee2/ember-codemod-rename-test-modules)
- [`ember-codemod-sort-invocations`](https://github.com/ijlee2/ember-codemod-sort-invocations)
- [`ember-codemod-v1-to-v2`](https://github.com/ijlee2/ember-codemod-v1-to-v2)
- [`prettier-plugin-ember-hbs-tag`](https://github.com/ijlee2/prettier-plugin-ember-hbs-tag/)
- [`type-css-modules`](https://github.com/ijlee2/embroider-css-modules/tree/main/packages/type-css-modules)
- [`update-workspace-root-version`](https://github.com/ijlee2/update-workspace-root-version)
1. [`@ember-intl/lint`](https://github.com/ember-intl/ember-intl/tree/main/packages/ember-intl-lint)
1. [`analyze-ember-project-dependencies`](https://github.com/ijlee2/analyze-ember-project-dependencies)
1. [`blueprints-v2-addon`](https://github.com/ijlee2/create-v2-addon-repo/tree/main/packages/blueprints-v2-addon)
1. [`codemod-generate-release-notes`](https://github.com/Ajanth/codemod-generate-release-notes)
1. [`create-v2-addon-repo`](https://github.com/ijlee2/create-v2-addon-repo/tree/main/packages/create-v2-addon-repo)
1. [`ember-codemod-add-component-signatures`](https://github.com/ijlee2/ember-codemod-add-component-signatures)
1. [`ember-codemod-add-missing-tests`](https://github.com/ijlee2/ember-codemod-add-missing-tests)
1. [`ember-codemod-add-template-tags`](https://github.com/ijlee2/ember-codemod-add-template-tags)
1. [`ember-codemod-css-modules`](https://github.com/simplepractice/ember-codemod-css-modules)
1. [`ember-codemod-ember-render-helpers-to-v1`](https://github.com/buschtoens/ember-render-helpers/tree/main/packages/ember-codemod-ember-render-helpers-to-v1)
1. [`ember-codemod-pod-to-octane`](https://github.com/ijlee2/ember-codemod-pod-to-octane)
1. [`ember-codemod-remove-global-styles`](https://github.com/ijlee2/embroider-css-modules/tree/main/packages/ember-codemod-remove-global-styles)
1. [`ember-codemod-remove-ember-css-modules`](https://github.com/ijlee2/embroider-css-modules/tree/main/packages/ember-codemod-remove-ember-css-modules)
1. [`ember-codemod-remove-inject-as-service`](https://github.com/ijlee2/ember-codemod-remove-inject-as-service)
1. [`ember-codemod-rename-test-modules`](https://github.com/ijlee2/ember-codemod-rename-test-modules)
1. [`ember-codemod-sort-invocations`](https://github.com/ijlee2/ember-codemod-sort-invocations)
1. [`ember-codemod-v1-to-v2`](https://github.com/ijlee2/ember-codemod-v1-to-v2)
1. [`prettier-plugin-ember-hbs-tag`](https://github.com/ijlee2/prettier-plugin-ember-hbs-tag/)
1. [`type-css-modules`](https://github.com/ijlee2/embroider-css-modules/tree/main/packages/type-css-modules)
1. [`update-workspace-root-version`](https://github.com/ijlee2/update-workspace-root-version)


## Contributing
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ In the example above (an "acceptance" test), `inputProject` and `outputProject`
<summary>Example</summary>

```ts
const oldFile = createFile([
const oldFile = normalizeFile([
`import Component from '@glimmer/component';`,
``,
`export default class Hello extends Component {}`,
Expand All @@ -105,7 +105,7 @@ const newFile = transform(oldFile);

assert.strictEqual(
newFile,
createFile([
normalizeFile([
`import Component from '@glimmer/component';`,
``,
`import styles from './hello.module.css';`,
Expand Down
6 changes: 3 additions & 3 deletions tutorials/create-blueprints/03-define-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ See if you can complete the starter code shown above. The requirements are:
<summary>Solution: <code>src/steps/create-options.ts</code></summary>

```diff
+ import { join } from 'node:path';
+ import { join, sep } from 'node:path';
+
import type { CodemodOptions, Options } from '../types/index.js';

Expand All @@ -296,12 +296,12 @@ export function createOptions(codemodOptions: CodemodOptions): Options {

return {
+ addon: {
+ location: join('packages', addonLocation),
+ location: join('packages', addonLocation).replaceAll(sep, '/'),
+ name: addonName,
+ },
projectRoot,
+ testApp: {
+ location: join('tests', addonLocation),
+ location: join('tests', addonLocation).replaceAll(sep, '/'),
+ name: `test-app-for-${dasherize(addonName)}`,
+ },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,14 @@ Currently, `data.moduleName` is hard-coded. We can derive the test module name f

<summary>Solution: <code>src/steps/rename-acceptance-tests.ts</code></summary>

It's important to note that Windows uses `\` as the file separator, while the entity name uses `/` (independently of the operating system). We can use `relative()` and `sep` to normalize values.

The implementation for `renameModule()` remains unchanged and has been hidden for simplicity.

```diff
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
- import { join } from 'node:path';
+ import { join, relative, sep } from 'node:path';

import { AST } from '@codemod-utils/ast-javascript';
- import { findFiles } from '@codemod-utils/files';
Expand All @@ -614,10 +617,10 @@ type Data = {
+ function getModuleName(filePath: string): string {
+ let { dir, name } = parseFilePath(filePath);
+
+ dir = dir.replace(/^tests\/acceptance(\/)?/, '');
+ dir = relative('tests/acceptance', dir);
+ name = name.replace(/-test$/, '');
+
+ const entityName = join(dir, name);
+ const entityName = join(dir, name).replaceAll(sep, '/');
+
+ // a.k.a. friendlyTestDescription
+ return ['Acceptance', entityName].join(' | ');
Expand Down
36 changes: 19 additions & 17 deletions tutorials/main-tutorial/06-step-2-update-integration-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ type Data = {
function getModuleName(filePath: string): string {
let { dir, name } = parseFilePath(filePath);

dir = dir.replace(/^tests\/acceptance(\/)?/, '');
dir = relative('tests/acceptance', dir);
name = name.replace(/-test$/, '');

const entityName = join(dir, name);
const entityName = join(dir, name).replaceAll(sep, '/');

// a.k.a. friendlyTestDescription
return ['Acceptance', entityName].join(' | ');
Expand Down Expand Up @@ -179,7 +179,7 @@ I highlighted only how `getModuleName()` and `renameModule()` differ between `re

```diff
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { join, relative, sep } from 'node:path';

import { AST } from '@codemod-utils/ast-javascript';
import { findFiles, parseFilePath } from '@codemod-utils/files';
Expand All @@ -194,11 +194,11 @@ type Data = {
function getModuleName(filePath: string): string {
let { dir, name } = parseFilePath(filePath);

- dir = dir.replace(/^tests\/acceptance(\/)?/, '');
+ dir = dir.replace(/^tests\/integration(\/)?/, '');
- dir = relative('tests/acceptance', dir);
+ dir = relative('tests/integration', dir);
name = name.replace(/-test$/, '');

const entityName = join(dir, name);
const entityName = join(dir, name).replaceAll(sep, '/');

// a.k.a. friendlyTestDescription
- return ['Acceptance', entityName].join(' | ');
Expand Down Expand Up @@ -339,10 +339,10 @@ We say that an [iterative method](https://en.wikipedia.org/wiki/Iterative_method
function getModuleName(filePath: string): string {
let { dir, name } = parseFilePath(filePath);

dir = dir.replace(/^tests\/integration(\/)?/, '');
dir = relative('tests/integration', dir);
name = name.replace(/-test$/, '');

const entityName = join(dir, name);
const entityName = join(dir, name).replaceAll(sep, '/');

// a.k.a. friendlyTestDescription
return ['Integration', entityName].join(' | ');
Expand All @@ -355,7 +355,7 @@ Let's correct the overshoot by adding the entity type (here, we represent it as
function getModuleName(filePath: string): string {
let { dir, name } = parseFilePath(filePath);

dir = dir.replace(/^tests\/integration(\/)?/, '');
dir = relative('tests/integration', dir);
name = name.replace(/-test$/, '');

const entityType = /* ... */;
Expand Down Expand Up @@ -387,6 +387,8 @@ const entityName = join(remainingPath, name);
Let me first show you the solution for `parseEntity()`, then explain the particular approach.

```ts
import { sep } from 'node:path';

const folderToEntityType = new Map([
['components', 'Component'],
['helpers', 'Helper'],
Expand All @@ -397,12 +399,12 @@ function parseEntity(dir: string): {
entityType: string | undefined;
remainingPath: string;
} {
const [folder, ...remainingPaths] = dir.split('/');
const [folder, ...remainingPaths] = dir.split(sep);
const entityType = folderToEntityType.get(folder!);

return {
entityType,
remainingPath: remainingPaths.join('/'),
remainingPath: remainingPaths.join(sep),
};
}
```
Expand All @@ -419,7 +421,7 @@ The implementations for `renameModule()` and `renameIntegrationTests()` remain u

```diff
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { join, relative, sep } from 'node:path';

import { AST } from '@codemod-utils/ast-javascript';
import { findFiles, parseFilePath } from '@codemod-utils/files';
Expand All @@ -441,24 +443,24 @@ type Data = {
+ entityType: string | undefined;
+ remainingPath: string;
+ } {
+ const [folder, ...remainingPaths] = dir.split('/');
+ const [folder, ...remainingPaths] = dir.split(sep);
+ const entityType = folderToEntityType.get(folder!);
+
+ return {
+ entityType,
+ remainingPath: remainingPaths.join('/'),
+ remainingPath: remainingPaths.join(sep),
+ };
+ }
+
function getModuleName(filePath: string): string {
let { dir, name } = parseFilePath(filePath);

dir = dir.replace(/^tests\/integration(\/)?/, '');
dir = relative('tests/integration', dir);
name = name.replace(/-test$/, '');

- const entityName = join(dir, name);
- const entityName = join(dir, name).replaceAll(sep, '/');
+ const { entityType, remainingPath } = parseEntity(dir);
+ const entityName = join(remainingPath, name);
+ const entityName = join(remainingPath, name).replaceAll(sep, '/');

// a.k.a. friendlyTestDescription
- return ['Integration', entityName].join(' | ');
Expand Down
12 changes: 6 additions & 6 deletions tutorials/main-tutorial/07-step-3-update-unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Note that, because `'instance-initializers'` and `'utils'` need to be mapped to

```diff
import { readFileSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { join, relative, sep } from 'node:path';

import { AST } from '@codemod-utils/ast-javascript';
import { findFiles, parseFilePath } from '@codemod-utils/files';
Expand Down Expand Up @@ -57,24 +57,24 @@ function parseEntity(dir: string): {
entityType: string | undefined;
remainingPath: string;
} {
const [folder, ...remainingPaths] = dir.split('/');
const [folder, ...remainingPaths] = dir.split(sep);
const entityType = folderToEntityType.get(folder!);

return {
entityType,
remainingPath: remainingPaths.join('/'),
remainingPath: remainingPaths.join(sep),
};
}

function getModuleName(filePath: string): string {
let { dir, name } = parseFilePath(filePath);

- dir = dir.replace(/^tests\/integration(\/)?/, '');
+ dir = dir.replace(/^tests\/unit(\/)?/, '');
- dir = relative('tests/integration', dir);
+ dir = relative('tests/unit', dir);
name = name.replace(/-test$/, '');

const { entityType, remainingPath } = parseEntity(dir);
const entityName = join(remainingPath, name);
const entityName = join(remainingPath, name).replaceAll(sep, '/');

// a.k.a. friendlyTestDescription
- return ['Integration', entityType, entityName].join(' | ');
Expand Down
Loading