ember-codemod-pod-to-octane 1.2.2 → 1.2.4

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 CHANGED
@@ -115,10 +115,13 @@ To better meet your needs, consider cloning the repo and running the codemod loc
115
115
 
116
116
  ```sh
117
117
  cd <your/cloned/repo>
118
- npx ts-node ./bin/ember-codemod-pod-to-octane.js --root=<your/project/path>
119
- ```
120
118
 
121
- ⚠️ At the moment, it is not possible to run the codemod locally, because `ts-node@10.9.1` doesn't support `typescript@v5` correctly. You can track the progress in [#32](https://github.com/ijlee2/ember-codemod-pod-to-octane/issues/32).
119
+ # Compile TypeScript
120
+ pnpm build
121
+
122
+ # Run codemod
123
+ ./dist/bin/ember-codemod-pod-to-octane.js --root=<your/project/path>
124
+ ```
122
125
 
123
126
 
124
127
  ## Compatibility
@@ -1,13 +1,6 @@
1
- import { readPackageJson } from '@codemod-utils/json';
2
- function analyzePackageJson(codemodOptions) {
3
- const packageJson = readPackageJson(codemodOptions);
4
- return packageJson.name;
5
- }
6
1
  export function createOptions(codemodOptions) {
7
- const projectName = analyzePackageJson(codemodOptions);
8
2
  return {
9
3
  podPath: codemodOptions.podPath,
10
- projectName,
11
4
  projectRoot: codemodOptions.projectRoot,
12
5
  projectType: codemodOptions.projectType,
13
6
  testRun: codemodOptions.testRun,
@@ -1,13 +1,6 @@
1
- import { readPackageJson } from '@codemod-utils/json';
2
- function analyzePackageJson(codemodOptions) {
3
- const packageJson = readPackageJson(codemodOptions);
4
- return packageJson.name;
5
- }
6
1
  export function createOptions(codemodOptions) {
7
- const projectName = analyzePackageJson(codemodOptions);
8
2
  return {
9
3
  podPath: codemodOptions.podPath,
10
- projectName,
11
4
  projectRoot: codemodOptions.projectRoot,
12
5
  projectType: codemodOptions.projectType,
13
6
  testRun: codemodOptions.testRun,
@@ -1,6 +1,6 @@
1
1
  import { moveFiles } from '@codemod-utils/files';
2
2
  import { migrationStrategyForAddonFolder } from './addon/index.js';
3
- import { createOptions, updateAbsolutePaths, useAbsolutePaths, useRelativePaths, } from './steps/index.js';
3
+ import { createOptions } from './steps/index.js';
4
4
  import { migrationStrategyForTestsFolder } from './tests/index.js';
5
5
  export function migrateEmberEngine(codemodOptions) {
6
6
  const options = createOptions(codemodOptions);
@@ -14,12 +14,7 @@ export function migrateEmberEngine(codemodOptions) {
14
14
  console.log(migrationStrategy);
15
15
  return;
16
16
  }
17
- // Prepare for migration
18
- useAbsolutePaths(options);
19
17
  // Preserve code
20
18
  moveFiles(migrationStrategyAddon, options);
21
19
  moveFiles(migrationStrategyTests, options);
22
- // Update import paths
23
- updateAbsolutePaths(migrationStrategy, options);
24
- useRelativePaths(options);
25
20
  }
@@ -1,14 +1,6 @@
1
- import { readPackageJson, validatePackageJson } from '@codemod-utils/json';
2
- function analyzePackageJson(codemodOptions) {
3
- const packageJson = readPackageJson(codemodOptions);
4
- validatePackageJson(packageJson);
5
- return packageJson.name;
6
- }
7
1
  export function createOptions(codemodOptions) {
8
- const projectName = analyzePackageJson(codemodOptions);
9
2
  return {
10
3
  podPath: codemodOptions.podPath,
11
- projectName,
12
4
  projectRoot: codemodOptions.projectRoot,
13
5
  projectType: codemodOptions.projectType,
14
6
  testRun: codemodOptions.testRun,
@@ -1,4 +1 @@
1
1
  export * from './create-options.js';
2
- export * from './update-absolute-paths.js';
3
- export * from './use-absolute-paths.js';
4
- export * from './use-relative-paths.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-codemod-pod-to-octane",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Codemod to un-pod Ember apps, addons, and engines",
5
5
  "keywords": [
6
6
  "codemod",
@@ -25,7 +25,6 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@codemod-utils/files": "^0.4.1",
28
- "@codemod-utils/json": "^0.3.0",
29
28
  "yargs": "^17.7.2"
30
29
  },
31
30
  "devDependencies": {
@@ -67,7 +66,7 @@
67
66
  }
68
67
  },
69
68
  "scripts": {
70
- "build": "tsc --project tsconfig.build.json",
69
+ "build": "tsc --project tsconfig.build.json && chmod +x dist/bin/ember-codemod-pod-to-octane.js",
71
70
  "changelog": "lerna-changelog",
72
71
  "lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
73
72
  "lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
@@ -1,73 +0,0 @@
1
- import { readFileSync, writeFileSync } from 'node:fs';
2
- import { join, parse } from 'node:path';
3
- import { findFiles } from '@codemod-utils/files';
4
- function removeFileExtension(path) {
5
- const { dir, name } = parse(path);
6
- return `${dir}/${name}`;
7
- }
8
- function createMapping(migrationStrategy) {
9
- return new Map([...migrationStrategy].map(([oldPath, newPath]) => {
10
- const before = removeFileExtension(oldPath);
11
- const after = removeFileExtension(newPath);
12
- return [before, after];
13
- }));
14
- }
15
- function updatePathsToAddonFiles(oldFile, { mapping, projectName }) {
16
- const regex = new RegExp(`(?:'|")(${projectName}/(.*))(?:'|")`, 'g');
17
- const matchResults = [...oldFile.matchAll(regex)];
18
- let newFile = oldFile;
19
- matchResults.forEach((matchResult) => {
20
- const oldPath = matchResult[1];
21
- const remainingPath = matchResult[2];
22
- const before = join('addon', remainingPath);
23
- if (!mapping.has(before)) {
24
- return;
25
- }
26
- const after = mapping.get(before).replace(new RegExp('^addon/'), '');
27
- const newPath = join(projectName, after);
28
- newFile = newFile.replace(oldPath, newPath);
29
- });
30
- return newFile;
31
- }
32
- function updatePathsToTestFiles(oldFile, { mapping, projectName }) {
33
- const regex = new RegExp(`(?:'|")(${projectName}/(.*))(?:'|")`, 'g');
34
- const matchResults = [...oldFile.matchAll(regex)];
35
- let newFile = oldFile;
36
- matchResults.forEach((matchResult) => {
37
- const oldPath = matchResult[1];
38
- const remainingPath = matchResult[2];
39
- const before = remainingPath;
40
- if (!mapping.has(before)) {
41
- return;
42
- }
43
- const after = mapping.get(before);
44
- const newPath = join(projectName, after);
45
- newFile = newFile.replace(oldPath, newPath);
46
- });
47
- return newFile;
48
- }
49
- function updatePaths(mapping, options) {
50
- const { projectName, projectRoot } = options;
51
- // File extensions had been specified, partly to encode assumptions
52
- // about Ember, and partly to avoid corrupting non-text files
53
- const filePaths = findFiles('{addon,tests}/**/*.{d.ts,js,ts}', {
54
- projectRoot,
55
- });
56
- filePaths.forEach((filePath) => {
57
- const oldPath = join(projectRoot, filePath);
58
- const oldFile = readFileSync(oldPath, 'utf8');
59
- let newFile = updatePathsToAddonFiles(oldFile, {
60
- mapping,
61
- projectName,
62
- });
63
- newFile = updatePathsToTestFiles(newFile, {
64
- mapping,
65
- projectName: 'dummy',
66
- });
67
- writeFileSync(oldPath, newFile, 'utf8');
68
- });
69
- }
70
- export function updateAbsolutePaths(migrationStrategy, options) {
71
- const mapping = createMapping(migrationStrategy);
72
- updatePaths(mapping, options);
73
- }
@@ -1,41 +0,0 @@
1
- import { readFileSync, writeFileSync } from 'node:fs';
2
- import { dirname, join, relative, resolve } from 'node:path';
3
- import { findFiles } from '@codemod-utils/files';
4
- function removeRelativePaths(oldFile, { filePath, projectName, projectRoot, }) {
5
- const regex = new RegExp(`(?:'|")(.{1,2}/(.*))(?:'|")`, 'g');
6
- const matchResults = [...oldFile.matchAll(regex)];
7
- let newFile = oldFile;
8
- matchResults.forEach((matchResult) => {
9
- const oldPath = matchResult[1];
10
- let newPath = relative(projectRoot, resolve(projectRoot, dirname(filePath), oldPath));
11
- if (newPath.startsWith('addon')) {
12
- newPath = join(projectName, newPath.replace(new RegExp('^addon/'), ''));
13
- }
14
- else if (newPath.startsWith('tests')) {
15
- newPath = join('dummy', newPath);
16
- }
17
- newFile = newFile.replace(oldPath, newPath);
18
- });
19
- return newFile;
20
- }
21
- function updatePaths(options) {
22
- const { projectName, projectRoot } = options;
23
- // File extensions had been specified, partly to encode assumptions
24
- // about Ember, and partly to avoid corrupting non-text files
25
- const filePaths = findFiles('{addon,tests}/**/*.{d.ts,js,ts}', {
26
- projectRoot,
27
- });
28
- filePaths.forEach((filePath) => {
29
- const oldPath = join(projectRoot, filePath);
30
- const oldFile = readFileSync(oldPath, 'utf8');
31
- const newFile = removeRelativePaths(oldFile, {
32
- filePath,
33
- projectName,
34
- projectRoot,
35
- });
36
- writeFileSync(oldPath, newFile, 'utf8');
37
- });
38
- }
39
- export function useAbsolutePaths(options) {
40
- updatePaths(options);
41
- }
@@ -1,85 +0,0 @@
1
- import { readFileSync, writeFileSync } from 'node:fs';
2
- import { dirname, join, relative } from 'node:path';
3
- import { findFiles } from '@codemod-utils/files';
4
- function normalizeRelativePath(relativePath) {
5
- if (relativePath.startsWith('..')) {
6
- return relativePath;
7
- }
8
- return `./${relativePath}`;
9
- }
10
- function updateFile(oldFile, { filePath, projectName, projectRoot, }) {
11
- const regex = new RegExp(`(?:'|")(${projectName}/(.*/)*(.*))(?:'|")`, 'g');
12
- const matchResults = [...oldFile.matchAll(regex)];
13
- let newFile = oldFile;
14
- matchResults.forEach((matchResult) => {
15
- const oldPath = matchResult[1];
16
- const remainingDirectories = matchResult[2];
17
- const fileName = matchResult[3];
18
- const from = dirname(filePath);
19
- const to = join(projectRoot, remainingDirectories);
20
- const relativePath = join(relative(from, to), fileName);
21
- const newPath = normalizeRelativePath(relativePath);
22
- newFile = newFile.replace(oldPath, newPath);
23
- });
24
- return newFile;
25
- }
26
- function useRelativePathInAddonFolder(options) {
27
- const { projectName, projectRoot } = options;
28
- // File extensions had been specified, partly to encode assumptions
29
- // about Ember, and partly to avoid corrupting non-text files
30
- const filePaths = findFiles('addon/**/*.{d.ts,js,ts}', {
31
- projectRoot,
32
- });
33
- filePaths.forEach((filePath) => {
34
- const oldPath = join(projectRoot, filePath);
35
- const oldFile = readFileSync(oldPath, 'utf8');
36
- const newFile = updateFile(oldFile, {
37
- filePath,
38
- projectName,
39
- projectRoot: 'addon',
40
- });
41
- writeFileSync(oldPath, newFile, 'utf8');
42
- });
43
- }
44
- function useRelativePathInTestsFolder(options) {
45
- const { projectRoot } = options;
46
- // File extensions had been specified, partly to encode assumptions
47
- // about Ember, and partly to avoid corrupting non-text files
48
- const filePaths = findFiles('tests/**/*.{d.ts,js,ts}', {
49
- projectRoot,
50
- ignoreList: ['tests/dummy/**/*'],
51
- });
52
- filePaths.forEach((filePath) => {
53
- const oldPath = join(projectRoot, filePath);
54
- const oldFile = readFileSync(oldPath, 'utf8');
55
- const newFile = updateFile(oldFile, {
56
- filePath,
57
- projectName: 'dummy',
58
- projectRoot: '',
59
- });
60
- writeFileSync(oldPath, newFile, 'utf8');
61
- });
62
- }
63
- function useRelativePathInTestsDummyFolder(options) {
64
- const { projectRoot } = options;
65
- // File extensions had been specified, partly to encode assumptions
66
- // about Ember, and partly to avoid corrupting non-text files
67
- const filePaths = findFiles('tests/dummy/**/*.{d.ts,js,ts}', {
68
- projectRoot,
69
- });
70
- filePaths.forEach((filePath) => {
71
- const oldPath = join(projectRoot, filePath);
72
- const oldFile = readFileSync(oldPath, 'utf8');
73
- const newFile = updateFile(oldFile, {
74
- filePath,
75
- projectName: 'dummy',
76
- projectRoot: 'tests/dummy/app',
77
- });
78
- writeFileSync(oldPath, newFile, 'utf8');
79
- });
80
- }
81
- export function useRelativePaths(options) {
82
- useRelativePathInAddonFolder(options);
83
- useRelativePathInTestsFolder(options);
84
- useRelativePathInTestsDummyFolder(options);
85
- }