ember-codemod-rename-test-modules 2.0.1 → 2.1.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.
@@ -1,7 +1,8 @@
1
1
  import { readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { updateJavaScript } from '@codemod-utils/ast-template-tag';
3
4
  import { findFiles, parseFilePath } from '@codemod-utils/files';
4
- import { parseEntity, renameModule } from '../../utils/rename-tests/index.js';
5
+ import { isTypeScript, parseEntity, renameModule, } from '../../utils/rename-tests/index.js';
5
6
  const folderToEntityType = new Map();
6
7
  function getModuleName(filePath) {
7
8
  let { dir, name } = parseFilePath(filePath);
@@ -14,17 +15,24 @@ function getModuleName(filePath) {
14
15
  }
15
16
  export function renameAcceptanceTests(options) {
16
17
  const { projectRoot } = options;
17
- const filePaths = findFiles('tests/acceptance/**/*-test.{js,ts}', {
18
+ const filePaths = findFiles('tests/acceptance/**/*-test.{gjs,gts,js,ts}', {
18
19
  projectRoot,
19
20
  });
20
21
  filePaths.forEach((filePath) => {
21
22
  const oldPath = join(projectRoot, filePath);
22
- const oldFile = readFileSync(oldPath, 'utf8');
23
+ let newFile = readFileSync(oldPath, 'utf8');
23
24
  const data = {
24
- isTypeScript: filePath.endsWith('.ts'),
25
+ isTypeScript: isTypeScript(filePath),
25
26
  moduleName: getModuleName(filePath),
26
27
  };
27
- const newFile = renameModule(oldFile, data);
28
+ if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
29
+ newFile = renameModule(newFile, data);
30
+ }
31
+ else {
32
+ newFile = updateJavaScript(newFile, (code) => {
33
+ return renameModule(code, data);
34
+ });
35
+ }
28
36
  writeFileSync(oldPath, newFile, 'utf8');
29
37
  });
30
38
  }
@@ -1,7 +1,8 @@
1
1
  import { readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { updateJavaScript } from '@codemod-utils/ast-template-tag';
3
4
  import { findFiles, parseFilePath } from '@codemod-utils/files';
4
- import { parseEntity, renameModule } from '../../utils/rename-tests/index.js';
5
+ import { isTypeScript, parseEntity, renameModule, } from '../../utils/rename-tests/index.js';
5
6
  const folderToEntityType = new Map([
6
7
  ['components', 'Component'],
7
8
  ['helpers', 'Helper'],
@@ -18,17 +19,24 @@ function getModuleName(filePath) {
18
19
  }
19
20
  export function renameIntegrationTests(options) {
20
21
  const { projectRoot } = options;
21
- const filePaths = findFiles('tests/integration/**/*-test.{js,ts}', {
22
+ const filePaths = findFiles('tests/integration/**/*-test.{gjs,gts,js,ts}', {
22
23
  projectRoot,
23
24
  });
24
25
  filePaths.forEach((filePath) => {
25
26
  const oldPath = join(projectRoot, filePath);
26
- const oldFile = readFileSync(oldPath, 'utf8');
27
+ let newFile = readFileSync(oldPath, 'utf8');
27
28
  const data = {
28
- isTypeScript: filePath.endsWith('.ts'),
29
+ isTypeScript: isTypeScript(filePath),
29
30
  moduleName: getModuleName(filePath),
30
31
  };
31
- const newFile = renameModule(oldFile, data);
32
+ if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
33
+ newFile = renameModule(newFile, data);
34
+ }
35
+ else {
36
+ newFile = updateJavaScript(newFile, (code) => {
37
+ return renameModule(code, data);
38
+ });
39
+ }
32
40
  writeFileSync(oldPath, newFile, 'utf8');
33
41
  });
34
42
  }
@@ -1,7 +1,8 @@
1
1
  import { readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import { updateJavaScript } from '@codemod-utils/ast-template-tag';
3
4
  import { findFiles, parseFilePath } from '@codemod-utils/files';
4
- import { parseEntity, renameModule } from '../../utils/rename-tests/index.js';
5
+ import { isTypeScript, parseEntity, renameModule, } from '../../utils/rename-tests/index.js';
5
6
  const folderToEntityType = new Map([
6
7
  ['adapters', 'Adapter'],
7
8
  ['controllers', 'Controller'],
@@ -25,17 +26,24 @@ function getModuleName(filePath) {
25
26
  }
26
27
  export function renameUnitTests(options) {
27
28
  const { projectRoot } = options;
28
- const filePaths = findFiles('tests/unit/**/*-test.{js,ts}', {
29
+ const filePaths = findFiles('tests/unit/**/*-test.{gjs,gts,js,ts}', {
29
30
  projectRoot,
30
31
  });
31
32
  filePaths.forEach((filePath) => {
32
33
  const oldPath = join(projectRoot, filePath);
33
- const oldFile = readFileSync(oldPath, 'utf8');
34
+ let newFile = readFileSync(oldPath, 'utf8');
34
35
  const data = {
35
- isTypeScript: filePath.endsWith('.ts'),
36
+ isTypeScript: isTypeScript(filePath),
36
37
  moduleName: getModuleName(filePath),
37
38
  };
38
- const newFile = renameModule(oldFile, data);
39
+ if (filePath.endsWith('.js') || filePath.endsWith('.ts')) {
40
+ newFile = renameModule(newFile, data);
41
+ }
42
+ else {
43
+ newFile = updateJavaScript(newFile, (code) => {
44
+ return renameModule(code, data);
45
+ });
46
+ }
39
47
  writeFileSync(oldPath, newFile, 'utf8');
40
48
  });
41
49
  }
@@ -1,2 +1,3 @@
1
+ export * from './is-typescript.js';
1
2
  export * from './parse-entity.js';
2
3
  export * from './rename-module.js';
@@ -0,0 +1,3 @@
1
+ export function isTypeScript(filePath) {
2
+ return filePath.endsWith('.gts') || filePath.endsWith('.ts');
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-codemod-rename-test-modules",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Codemod to rename test modules",
5
5
  "keywords": [
6
6
  "codemod",
@@ -23,33 +23,36 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@codemod-utils/ast-javascript": "^2.0.2",
27
- "@codemod-utils/files": "^3.0.2",
26
+ "@codemod-utils/ast-javascript": "^2.0.6",
27
+ "@codemod-utils/ast-template-tag": "^0.1.0",
28
+ "@codemod-utils/files": "^3.0.4",
28
29
  "yargs": "^18.0.0"
29
30
  },
30
31
  "devDependencies": {
31
- "@changesets/cli": "^2.29.4",
32
+ "@changesets/cli": "^2.29.6",
32
33
  "@changesets/get-github-info": "^0.6.0",
33
- "@codemod-utils/tests": "^2.0.1",
34
- "@ijlee2-frontend-configs/eslint-config-node": "^1.2.0",
35
- "@ijlee2-frontend-configs/prettier": "^1.0.0",
34
+ "@codemod-utils/tests": "^2.0.3",
35
+ "@ijlee2-frontend-configs/eslint-config-node": "^2.1.2",
36
+ "@ijlee2-frontend-configs/prettier": "^2.1.1",
36
37
  "@sondr3/minitest": "^0.1.2",
37
- "@tsconfig/node20": "^20.1.5",
38
+ "@tsconfig/node20": "^20.1.6",
38
39
  "@tsconfig/strictest": "^2.0.5",
39
- "@types/node": "^20.17.54",
40
+ "@types/node": "^20.19.13",
40
41
  "@types/yargs": "^17.0.33",
41
- "concurrently": "^9.1.2",
42
- "eslint": "^9.27.0",
43
- "prettier": "^3.5.3",
44
- "typescript": "^5.8.3"
42
+ "concurrently": "^9.2.1",
43
+ "eslint": "^9.35.0",
44
+ "prettier": "^3.6.2",
45
+ "typescript": "^5.9.2"
45
46
  },
46
47
  "engines": {
47
48
  "node": "20.* || >= 22"
48
49
  },
49
50
  "scripts": {
50
51
  "build": "./build.sh --production",
52
+ "format": "prettier . --cache --write",
51
53
  "lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\"",
52
- "lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\"",
54
+ "lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\" && pnpm format",
55
+ "lint:format": "prettier . --cache --check",
53
56
  "lint:js": "eslint . --cache",
54
57
  "lint:js:fix": "eslint . --fix",
55
58
  "lint:types": "tsc --noEmit",