ember-codemod-pod-to-octane 1.0.1 → 1.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.
- package/README.md +4 -4
- package/bin/ember-codemod-pod-to-octane.js +2 -2
- package/package.json +10 -8
- package/src/index.js +6 -6
- package/src/migration/ember-addon/index.js +6 -3
- package/src/migration/ember-addon/steps/create-options.js +46 -0
- package/src/migration/ember-addon/steps/index.js +1 -0
- package/src/migration/ember-app/index.js +4 -1
- package/src/migration/ember-app/steps/create-options.js +46 -0
- package/src/migration/ember-app/steps/index.js +1 -0
- package/src/migration/ember-engine/index.js +23 -5
- package/src/migration/ember-engine/steps/create-options.js +46 -0
- package/src/migration/ember-engine/steps/index.js +4 -0
- package/src/migration/ember-engine/steps/update-absolute-paths.js +104 -0
- package/src/migration/ember-engine/steps/use-absolute-paths.js +60 -0
- package/src/migration/ember-engine/steps/use-relative-paths.js +116 -0
- package/src/utils/ember-addon/app/components.js +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ npx ember-codemod-pod-to-octane --test
|
|
|
47
47
|
<details>
|
|
48
48
|
<summary>Optional: Specify the project root</summary>
|
|
49
49
|
|
|
50
|
-
Pass `--root` to run the codemod
|
|
50
|
+
Pass `--root` to run the codemod on a project somewhere else (i.e. not in the current directory).
|
|
51
51
|
|
|
52
52
|
```sh
|
|
53
53
|
npx ember-codemod-pod-to-octane --root=<your/project/path>
|
|
@@ -105,11 +105,11 @@ The codemod assumes that an engine is used to define routes and route-specific c
|
|
|
105
105
|
</details>
|
|
106
106
|
|
|
107
107
|
|
|
108
|
-
To better meet your needs, consider
|
|
108
|
+
To better meet your needs, consider cloning the repo and running the codemod locally.
|
|
109
109
|
|
|
110
110
|
```sh
|
|
111
|
-
cd <your/
|
|
112
|
-
./bin/ember-codemod-pod-to-octane.js
|
|
111
|
+
cd <your/cloned/repo>
|
|
112
|
+
./bin/ember-codemod-pod-to-octane.js --root=<your/project/path>
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
|
|
@@ -32,11 +32,11 @@ const { argv } = yargs(hideBin(process.argv))
|
|
|
32
32
|
type: 'string',
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
const
|
|
35
|
+
const codemodOptions = {
|
|
36
36
|
podPath: argv['pod-path'],
|
|
37
37
|
projectRoot: argv['root'] ?? process.cwd(),
|
|
38
38
|
projectType: argv['type'],
|
|
39
39
|
testRun: argv['test'],
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
runCodemod(
|
|
42
|
+
runCodemod(codemodOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-pod-to-octane",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Codemod to un-pod Ember apps, addons, and engines",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-codemod",
|
|
@@ -25,26 +25,28 @@
|
|
|
25
25
|
],
|
|
26
26
|
"scripts": {
|
|
27
27
|
"changelog": "lerna-changelog",
|
|
28
|
-
"lint": "eslint . --cache
|
|
29
|
-
"lint:fix": "eslint . --
|
|
28
|
+
"lint": "eslint . --cache",
|
|
29
|
+
"lint:fix": "eslint . --fix",
|
|
30
30
|
"start": "node ./src/index.js",
|
|
31
31
|
"test": "mt tests --quiet"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@babel/core": "^7.
|
|
34
|
+
"@babel/core": "^7.21.0",
|
|
35
35
|
"@babel/eslint-parser": "^7.19.1",
|
|
36
36
|
"glob": "^8.1.0",
|
|
37
|
-
"yargs": "^17.
|
|
37
|
+
"yargs": "^17.7.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@sondr3/minitest": "^0.1.1",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^8.34.0",
|
|
42
42
|
"eslint-config-prettier": "^8.6.0",
|
|
43
|
+
"eslint-plugin-import": "^2.27.5",
|
|
44
|
+
"eslint-plugin-n": "^15.6.1",
|
|
43
45
|
"eslint-plugin-prettier": "^4.2.1",
|
|
44
|
-
"eslint-plugin-simple-import-sort": "^
|
|
46
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
45
47
|
"fixturify": "^3.0.0",
|
|
46
48
|
"lerna-changelog": "^2.2.0",
|
|
47
|
-
"prettier": "^2.8.
|
|
49
|
+
"prettier": "^2.8.4"
|
|
48
50
|
},
|
|
49
51
|
"engines": {
|
|
50
52
|
"node": ">= 16"
|
package/src/index.js
CHANGED
|
@@ -4,25 +4,25 @@ import {
|
|
|
4
4
|
migrateEmberEngine,
|
|
5
5
|
} from './migration/index.js';
|
|
6
6
|
|
|
7
|
-
export function runCodemod(
|
|
8
|
-
switch (
|
|
7
|
+
export function runCodemod(codemodOptions) {
|
|
8
|
+
switch (codemodOptions.projectType) {
|
|
9
9
|
case 'addon': {
|
|
10
|
-
migrateEmberAddon(
|
|
10
|
+
migrateEmberAddon(codemodOptions);
|
|
11
11
|
break;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
case 'app': {
|
|
15
|
-
migrateEmberApp(
|
|
15
|
+
migrateEmberApp(codemodOptions);
|
|
16
16
|
break;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
case 'engine': {
|
|
20
|
-
migrateEmberEngine(
|
|
20
|
+
migrateEmberEngine(codemodOptions);
|
|
21
21
|
break;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
default: {
|
|
25
|
-
console.error(`Unknown project type: ${
|
|
25
|
+
console.error(`Unknown project type: ${codemodOptions.projectType}`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { updatePathsInAppFolder } from '../../utils/ember-addon/app/components.js';
|
|
2
2
|
import { moveFiles } from '../../utils/files.js';
|
|
3
3
|
import { migrationStrategyForAddonFolder } from './addon/index.js';
|
|
4
4
|
import { migrationStrategyForAppFolder } from './app/index.js';
|
|
5
|
+
import { createOptions } from './steps/index.js';
|
|
5
6
|
import { migrationStrategyForTestsFolder } from './tests/index.js';
|
|
6
7
|
|
|
7
|
-
export function migrateEmberAddon(
|
|
8
|
+
export function migrateEmberAddon(codemodOptions) {
|
|
9
|
+
const options = createOptions(codemodOptions);
|
|
10
|
+
|
|
8
11
|
const migrationStrategyAddon = migrationStrategyForAddonFolder(options);
|
|
9
12
|
const migrationStrategyApp = migrationStrategyForAppFolder(options);
|
|
10
13
|
const migrationStrategyTests = migrationStrategyForTestsFolder(options);
|
|
@@ -23,5 +26,5 @@ export function migrateEmberAddon(options) {
|
|
|
23
26
|
moveFiles(migrationStrategyApp, options);
|
|
24
27
|
moveFiles(migrationStrategyTests, options);
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
updatePathsInAppFolder(migrationStrategyApp, options);
|
|
27
30
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
function analyzePackageJson(codemodOptions) {
|
|
5
|
+
const { projectRoot } = codemodOptions;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const packageJsonFile = readFileSync(
|
|
9
|
+
join(projectRoot, 'package.json'),
|
|
10
|
+
'utf8'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const { name } = JSON.parse(packageJsonFile);
|
|
14
|
+
|
|
15
|
+
if (!name) {
|
|
16
|
+
throw new SyntaxError('Package name is missing.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (name.includes('/')) {
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
const [scope, packageName] = name.split('/');
|
|
22
|
+
|
|
23
|
+
if (!packageName) {
|
|
24
|
+
throw new SyntaxError('Package name is missing.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return name;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new SyntaxError(
|
|
31
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createOptions(codemodOptions) {
|
|
37
|
+
const projectName = analyzePackageJson(codemodOptions);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
podPath: codemodOptions.podPath,
|
|
41
|
+
projectName,
|
|
42
|
+
projectRoot: codemodOptions.projectRoot,
|
|
43
|
+
projectType: codemodOptions.projectType,
|
|
44
|
+
testRun: codemodOptions.testRun,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-options.js';
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { moveFiles } from '../../utils/files.js';
|
|
2
2
|
import { migrationStrategyForAppFolder } from './app/index.js';
|
|
3
|
+
import { createOptions } from './steps/index.js';
|
|
3
4
|
import { migrationStrategyForTestsFolder } from './tests/index.js';
|
|
4
5
|
|
|
5
|
-
export function migrateEmberApp(
|
|
6
|
+
export function migrateEmberApp(codemodOptions) {
|
|
7
|
+
const options = createOptions(codemodOptions);
|
|
8
|
+
|
|
6
9
|
const migrationStrategyApp = migrationStrategyForAppFolder(options);
|
|
7
10
|
const migrationStrategyTests = migrationStrategyForTestsFolder(options);
|
|
8
11
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
function analyzePackageJson(codemodOptions) {
|
|
5
|
+
const { projectRoot } = codemodOptions;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const packageJsonFile = readFileSync(
|
|
9
|
+
join(projectRoot, 'package.json'),
|
|
10
|
+
'utf8'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const { name } = JSON.parse(packageJsonFile);
|
|
14
|
+
|
|
15
|
+
if (!name) {
|
|
16
|
+
throw new SyntaxError('Package name is missing.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (name.includes('/')) {
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
const [scope, packageName] = name.split('/');
|
|
22
|
+
|
|
23
|
+
if (!packageName) {
|
|
24
|
+
throw new SyntaxError('Package name is missing.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return name;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new SyntaxError(
|
|
31
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createOptions(codemodOptions) {
|
|
37
|
+
const projectName = analyzePackageJson(codemodOptions);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
podPath: codemodOptions.podPath,
|
|
41
|
+
projectName,
|
|
42
|
+
projectRoot: codemodOptions.projectRoot,
|
|
43
|
+
projectType: codemodOptions.projectType,
|
|
44
|
+
testRun: codemodOptions.testRun,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-options.js';
|
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
import { moveFiles } from '../../utils/files.js';
|
|
2
2
|
import { migrationStrategyForAddonFolder } from './addon/index.js';
|
|
3
|
+
import {
|
|
4
|
+
createOptions,
|
|
5
|
+
updateAbsolutePaths,
|
|
6
|
+
useAbsolutePaths,
|
|
7
|
+
useRelativePaths,
|
|
8
|
+
} from './steps/index.js';
|
|
3
9
|
import { migrationStrategyForTestsFolder } from './tests/index.js';
|
|
4
10
|
|
|
5
|
-
export function migrateEmberEngine(
|
|
11
|
+
export function migrateEmberEngine(codemodOptions) {
|
|
12
|
+
const options = createOptions(codemodOptions);
|
|
13
|
+
|
|
6
14
|
const migrationStrategyAddon = migrationStrategyForAddonFolder(options);
|
|
7
15
|
const migrationStrategyTests = migrationStrategyForTestsFolder(options);
|
|
8
16
|
|
|
17
|
+
const migrationStrategy = new Map([
|
|
18
|
+
...migrationStrategyAddon,
|
|
19
|
+
...migrationStrategyTests,
|
|
20
|
+
]);
|
|
21
|
+
|
|
9
22
|
if (options.testRun) {
|
|
10
|
-
console.log(
|
|
11
|
-
migrationStrategyAddon,
|
|
12
|
-
migrationStrategyTests,
|
|
13
|
-
});
|
|
23
|
+
console.log(migrationStrategy);
|
|
14
24
|
|
|
15
25
|
return;
|
|
16
26
|
}
|
|
17
27
|
|
|
28
|
+
// Prepare for migration
|
|
29
|
+
useAbsolutePaths(options);
|
|
30
|
+
|
|
31
|
+
// Preserve code
|
|
18
32
|
moveFiles(migrationStrategyAddon, options);
|
|
19
33
|
moveFiles(migrationStrategyTests, options);
|
|
34
|
+
|
|
35
|
+
// Update import paths
|
|
36
|
+
updateAbsolutePaths(migrationStrategy, options);
|
|
37
|
+
useRelativePaths(options);
|
|
20
38
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
function analyzePackageJson(codemodOptions) {
|
|
5
|
+
const { projectRoot } = codemodOptions;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const packageJsonFile = readFileSync(
|
|
9
|
+
join(projectRoot, 'package.json'),
|
|
10
|
+
'utf8'
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const { name } = JSON.parse(packageJsonFile);
|
|
14
|
+
|
|
15
|
+
if (!name) {
|
|
16
|
+
throw new SyntaxError('Package name is missing.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (name.includes('/')) {
|
|
20
|
+
// eslint-disable-next-line no-unused-vars
|
|
21
|
+
const [scope, packageName] = name.split('/');
|
|
22
|
+
|
|
23
|
+
if (!packageName) {
|
|
24
|
+
throw new SyntaxError('Package name is missing.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return name;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
throw new SyntaxError(
|
|
31
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createOptions(codemodOptions) {
|
|
37
|
+
const projectName = analyzePackageJson(codemodOptions);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
podPath: codemodOptions.podPath,
|
|
41
|
+
projectName,
|
|
42
|
+
projectRoot: codemodOptions.projectRoot,
|
|
43
|
+
projectType: codemodOptions.projectType,
|
|
44
|
+
testRun: codemodOptions.testRun,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join, parse } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import glob from 'glob';
|
|
5
|
+
|
|
6
|
+
function removeFileExtension(path) {
|
|
7
|
+
const { dir, name } = parse(path);
|
|
8
|
+
|
|
9
|
+
return `${dir}/${name}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function createMapping(migrationStrategy) {
|
|
13
|
+
return new Map(
|
|
14
|
+
[...migrationStrategy].map(([oldPath, newPath]) => {
|
|
15
|
+
const before = removeFileExtension(oldPath);
|
|
16
|
+
const after = removeFileExtension(newPath);
|
|
17
|
+
|
|
18
|
+
return [before, after];
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function updatePathsToAddonFiles(oldFile, { mapping, projectName }) {
|
|
24
|
+
const regex = new RegExp(`(?:'|")(${projectName}/(.*))(?:'|")`, 'g');
|
|
25
|
+
const matchResults = [...oldFile.matchAll(regex)];
|
|
26
|
+
|
|
27
|
+
let newFile = oldFile;
|
|
28
|
+
|
|
29
|
+
matchResults.forEach((matchResult) => {
|
|
30
|
+
// eslint-disable-next-line no-unused-vars
|
|
31
|
+
const [_, oldPath, remainingPath] = matchResult;
|
|
32
|
+
const before = join('addon', remainingPath);
|
|
33
|
+
|
|
34
|
+
if (!mapping.has(before)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const after = mapping.get(before).replace(new RegExp('^addon/'), '');
|
|
39
|
+
const newPath = join(projectName, after);
|
|
40
|
+
|
|
41
|
+
newFile = newFile.replace(oldPath, newPath);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return newFile;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function updatePathsToTestFiles(oldFile, { mapping, projectName }) {
|
|
48
|
+
const regex = new RegExp(`(?:'|")(${projectName}/(.*))(?:'|")`, 'g');
|
|
49
|
+
const matchResults = [...oldFile.matchAll(regex)];
|
|
50
|
+
|
|
51
|
+
let newFile = oldFile;
|
|
52
|
+
|
|
53
|
+
matchResults.forEach((matchResult) => {
|
|
54
|
+
// eslint-disable-next-line no-unused-vars
|
|
55
|
+
const [_, oldPath, remainingPath] = matchResult;
|
|
56
|
+
const before = remainingPath;
|
|
57
|
+
|
|
58
|
+
if (!mapping.has(before)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const after = mapping.get(before);
|
|
63
|
+
const newPath = join(projectName, after);
|
|
64
|
+
|
|
65
|
+
newFile = newFile.replace(oldPath, newPath);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return newFile;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function updatePaths(mapping, options) {
|
|
72
|
+
const { projectName, projectRoot } = options;
|
|
73
|
+
|
|
74
|
+
// File extensions had been specified, partly to encode assumptions
|
|
75
|
+
// about Ember, and partly to avoid corrupting non-text files
|
|
76
|
+
const filePaths = glob.sync('{addon,tests}/**/*.{d.ts,js,ts}', {
|
|
77
|
+
cwd: projectRoot,
|
|
78
|
+
dot: true,
|
|
79
|
+
nodir: true,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
filePaths.forEach((filePath) => {
|
|
83
|
+
const oldPath = join(projectRoot, filePath);
|
|
84
|
+
const oldFile = readFileSync(oldPath, 'utf8');
|
|
85
|
+
|
|
86
|
+
let newFile = updatePathsToAddonFiles(oldFile, {
|
|
87
|
+
mapping,
|
|
88
|
+
projectName,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
newFile = updatePathsToTestFiles(newFile, {
|
|
92
|
+
mapping,
|
|
93
|
+
projectName: 'dummy',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
writeFileSync(oldPath, newFile, 'utf8');
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function updateAbsolutePaths(migrationStrategy, options) {
|
|
101
|
+
const mapping = createMapping(migrationStrategy);
|
|
102
|
+
|
|
103
|
+
updatePaths(mapping, options);
|
|
104
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import glob from 'glob';
|
|
5
|
+
|
|
6
|
+
function removeRelativePaths(oldFile, { filePath, projectName, projectRoot }) {
|
|
7
|
+
const regex = new RegExp(`(?:'|")(.{1,2}/(.*))(?:'|")`, 'g');
|
|
8
|
+
const matchResults = [...oldFile.matchAll(regex)];
|
|
9
|
+
|
|
10
|
+
let newFile = oldFile;
|
|
11
|
+
|
|
12
|
+
matchResults.forEach((matchResult) => {
|
|
13
|
+
// eslint-disable-next-line no-unused-vars
|
|
14
|
+
const [_, oldPath, remainingPath] = matchResult;
|
|
15
|
+
|
|
16
|
+
let newPath = relative(
|
|
17
|
+
projectRoot,
|
|
18
|
+
resolve(projectRoot, dirname(filePath), oldPath)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (newPath.startsWith('addon')) {
|
|
22
|
+
newPath = join(projectName, newPath.replace(new RegExp('^addon/'), ''));
|
|
23
|
+
} else if (newPath.startsWith('tests')) {
|
|
24
|
+
newPath = join('dummy', newPath);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
newFile = newFile.replace(oldPath, newPath);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return newFile;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function updatePaths(options) {
|
|
34
|
+
const { projectName, projectRoot } = options;
|
|
35
|
+
|
|
36
|
+
// File extensions had been specified, partly to encode assumptions
|
|
37
|
+
// about Ember, and partly to avoid corrupting non-text files
|
|
38
|
+
const filePaths = glob.sync('{addon,tests}/**/*.{d.ts,js,ts}', {
|
|
39
|
+
cwd: projectRoot,
|
|
40
|
+
dot: true,
|
|
41
|
+
nodir: true,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
filePaths.forEach((filePath) => {
|
|
45
|
+
const oldPath = join(projectRoot, filePath);
|
|
46
|
+
const oldFile = readFileSync(oldPath, 'utf8');
|
|
47
|
+
|
|
48
|
+
const newFile = removeRelativePaths(oldFile, {
|
|
49
|
+
filePath,
|
|
50
|
+
projectName,
|
|
51
|
+
projectRoot,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
writeFileSync(oldPath, newFile, 'utf8');
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function useAbsolutePaths(options) {
|
|
59
|
+
updatePaths(options);
|
|
60
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative } from 'node:path';
|
|
3
|
+
|
|
4
|
+
import glob from 'glob';
|
|
5
|
+
|
|
6
|
+
function normalizeRelativePath(relativePath) {
|
|
7
|
+
if (relativePath.startsWith('..')) {
|
|
8
|
+
return relativePath;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return `./${relativePath}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function updateFile(oldFile, { filePath, projectName, projectRoot }) {
|
|
15
|
+
const regex = new RegExp(`(?:'|")(${projectName}/(.*/)*(.*))(?:'|")`, 'g');
|
|
16
|
+
const matchResults = [...oldFile.matchAll(regex)];
|
|
17
|
+
|
|
18
|
+
let newFile = oldFile;
|
|
19
|
+
|
|
20
|
+
matchResults.forEach((matchResult) => {
|
|
21
|
+
// eslint-disable-next-line no-unused-vars
|
|
22
|
+
const [_, oldPath, remainingDirectories, fileName] = matchResult;
|
|
23
|
+
|
|
24
|
+
const from = dirname(filePath);
|
|
25
|
+
const to = join(projectRoot, remainingDirectories);
|
|
26
|
+
|
|
27
|
+
const relativePath = join(relative(from, to), fileName);
|
|
28
|
+
const newPath = normalizeRelativePath(relativePath);
|
|
29
|
+
|
|
30
|
+
newFile = newFile.replace(oldPath, newPath);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return newFile;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function useRelativePathInAddonFolder(options) {
|
|
37
|
+
const { projectName, projectRoot } = options;
|
|
38
|
+
|
|
39
|
+
// File extensions had been specified, partly to encode assumptions
|
|
40
|
+
// about Ember, and partly to avoid corrupting non-text files
|
|
41
|
+
const filePaths = glob.sync('addon/**/*.{d.ts,js,ts}', {
|
|
42
|
+
cwd: projectRoot,
|
|
43
|
+
dot: true,
|
|
44
|
+
nodir: true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
filePaths.forEach((filePath) => {
|
|
48
|
+
const oldPath = join(projectRoot, filePath);
|
|
49
|
+
const oldFile = readFileSync(oldPath, 'utf8');
|
|
50
|
+
|
|
51
|
+
const newFile = updateFile(oldFile, {
|
|
52
|
+
filePath,
|
|
53
|
+
projectName,
|
|
54
|
+
projectRoot: 'addon',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
writeFileSync(oldPath, newFile, 'utf8');
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function useRelativePathInTestsFolder(options) {
|
|
62
|
+
const { projectRoot } = options;
|
|
63
|
+
|
|
64
|
+
// File extensions had been specified, partly to encode assumptions
|
|
65
|
+
// about Ember, and partly to avoid corrupting non-text files
|
|
66
|
+
const filePaths = glob.sync('tests/**/*.{d.ts,js,ts}', {
|
|
67
|
+
cwd: projectRoot,
|
|
68
|
+
dot: true,
|
|
69
|
+
ignore: 'tests/dummy/**/*',
|
|
70
|
+
nodir: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
filePaths.forEach((filePath) => {
|
|
74
|
+
const oldPath = join(projectRoot, filePath);
|
|
75
|
+
const oldFile = readFileSync(oldPath, 'utf8');
|
|
76
|
+
|
|
77
|
+
const newFile = updateFile(oldFile, {
|
|
78
|
+
filePath,
|
|
79
|
+
projectName: 'dummy',
|
|
80
|
+
projectRoot: '',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
writeFileSync(oldPath, newFile, 'utf8');
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function useRelativePathInTestsDummyFolder(options) {
|
|
88
|
+
const { projectRoot } = options;
|
|
89
|
+
|
|
90
|
+
// File extensions had been specified, partly to encode assumptions
|
|
91
|
+
// about Ember, and partly to avoid corrupting non-text files
|
|
92
|
+
const filePaths = glob.sync('tests/dummy/**/*.{d.ts,js,ts}', {
|
|
93
|
+
cwd: projectRoot,
|
|
94
|
+
dot: true,
|
|
95
|
+
nodir: true,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
filePaths.forEach((filePath) => {
|
|
99
|
+
const oldPath = join(projectRoot, filePath);
|
|
100
|
+
const oldFile = readFileSync(oldPath, 'utf8');
|
|
101
|
+
|
|
102
|
+
const newFile = updateFile(oldFile, {
|
|
103
|
+
filePath,
|
|
104
|
+
projectName: 'dummy',
|
|
105
|
+
projectRoot: 'tests/dummy/app',
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
writeFileSync(oldPath, newFile, 'utf8');
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function useRelativePaths(options) {
|
|
113
|
+
useRelativePathInAddonFolder(options);
|
|
114
|
+
useRelativePathInTestsFolder(options);
|
|
115
|
+
useRelativePathInTestsDummyFolder(options);
|
|
116
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
|
-
export function
|
|
4
|
+
export function updatePathsInAppFolder(migrationStrategy, options) {
|
|
5
5
|
const { projectRoot } = options;
|
|
6
6
|
|
|
7
7
|
migrationStrategy.forEach((newPath, oldPath) => {
|