ember-codemod-v1-to-v2 0.1.2 → 0.1.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 +1 -1
- package/package.json +2 -2
- package/src/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts +4 -3
- package/src/blueprints/ember-addon/package.json +3 -3
- package/src/migration/ember-addon/steps/augment-options.js +19 -17
- package/src/migration/ember-addon/steps/move-project-root-files.js +2 -1
- package/src/migration/ember-addon/steps/update-addon-package-json.js +17 -19
- package/src/migration/ember-addon/steps/update-addon-tsconfig-json.js +2 -4
- package/src/migration/ember-addon/steps/update-test-app-package-json.js +8 -5
- package/src/migration/ember-addon/steps/update-test-app-tsconfig-json.js +2 -4
- package/src/utils/convert-json-object.js +5 -0
- package/src/utils/decide-version.js +4 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ _Codemod to convert Ember addons to v2 addon format_
|
|
|
11
11
|
- Switches Ember's "magic" import paths to relative paths
|
|
12
12
|
- Preserves your code whenever possible
|
|
13
13
|
- Supports [`ember-cli-typescript`](https://docs.ember-cli-typescript.com/) and [`glint`](https://typed-ember.gitbook.io/glint/)
|
|
14
|
-
- Focuses on
|
|
14
|
+
- Focuses on maintainability and extensibility
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
## Usage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-v1-to-v2",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Codemod to convert Ember addons to v2 addon format",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"eslint": "^8.32.0",
|
|
57
57
|
"eslint-config-prettier": "^8.6.0",
|
|
58
58
|
"eslint-plugin-prettier": "^4.2.1",
|
|
59
|
-
"eslint-plugin-simple-import-sort": "^
|
|
59
|
+
"eslint-plugin-simple-import-sort": "^9.0.0",
|
|
60
60
|
"fixturify": "^3.0.0",
|
|
61
61
|
"lerna-changelog": "^2.2.0",
|
|
62
62
|
"prettier": "^2.8.3"
|
package/src/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Add any types here that you need for local development only.
|
|
2
2
|
// These will *not* be published as part of your addon, so be careful that your published code does not rely on them!
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<% if (options.packages.addon.hasGlint) { %>
|
|
4
|
+
import '@glint/environment-ember-loose';
|
|
5
5
|
|
|
6
6
|
declare module '@glint/environment-ember-loose/registry' {
|
|
7
7
|
// Remove this once entries have been added! 👇
|
|
@@ -10,4 +10,5 @@ declare module '@glint/environment-ember-loose/registry' {
|
|
|
10
10
|
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
|
|
11
11
|
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
|
|
12
12
|
}
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
<% } %>
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"prepare": "npm run build",
|
|
17
17
|
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
18
18
|
"start:addon": "npm start --workspace <%= options.packages.addon.name %>",
|
|
19
|
-
"start:
|
|
19
|
+
"start:test-app": "npm start --workspace <%= options.packages.testApp.name %>",
|
|
20
20
|
"test": "npm run test --workspaces --if-present"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prepare": "pnpm build",
|
|
42
42
|
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
43
43
|
"start:addon": "pnpm --filter <%= options.packages.addon.name %> start",
|
|
44
|
-
"start:test": "pnpm --filter <%= options.packages.testApp.name %> start",
|
|
44
|
+
"start:test-app": "pnpm --filter <%= options.packages.testApp.name %> start",
|
|
45
45
|
"test": "pnpm --filter '*' test"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"prepare": "yarn build",
|
|
67
67
|
"start": "concurrently 'npm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
68
68
|
"start:addon": "yarn workspace <%= options.packages.addon.name %> run start",
|
|
69
|
-
"start:test": "yarn workspace <%= options.packages.testApp.name %> run start",
|
|
69
|
+
"start:test-app": "yarn workspace <%= options.packages.testApp.name %> run start",
|
|
70
70
|
"test": "yarn workspaces run test"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
@@ -20,6 +20,14 @@ function analyzePackageJson(options) {
|
|
|
20
20
|
version,
|
|
21
21
|
} = JSON.parse(packageJsonFile);
|
|
22
22
|
|
|
23
|
+
if (!name) {
|
|
24
|
+
throw new SyntaxError('Package name is missing.');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!version) {
|
|
28
|
+
throw new SyntaxError('Package version is missing.');
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
const projectDependencies = new Map([
|
|
24
32
|
...Object.entries(dependencies ?? {}),
|
|
25
33
|
...Object.entries(devDependencies ?? {}),
|
|
@@ -35,7 +43,7 @@ function analyzePackageJson(options) {
|
|
|
35
43
|
};
|
|
36
44
|
} catch (e) {
|
|
37
45
|
throw new SyntaxError(
|
|
38
|
-
`ERROR: package.json is missing or is not
|
|
46
|
+
`ERROR: package.json is missing or is not valid. (${e.message})\n`
|
|
39
47
|
);
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -67,27 +75,21 @@ function analyzePackageManager(options) {
|
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
function deriveAddonLocation(addonPackage) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
);
|
|
78
|
+
// Package is not scoped
|
|
79
|
+
if (!addonPackage.name.includes('/')) {
|
|
80
|
+
return addonPackage.name;
|
|
74
81
|
}
|
|
75
82
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
// eslint-disable-next-line no-unused-vars
|
|
79
|
-
const [scope, packageName] = addonPackage.name.split('/');
|
|
83
|
+
// eslint-disable-next-line no-unused-vars
|
|
84
|
+
const [scope, packageName] = addonPackage.name.split('/');
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return packageName;
|
|
86
|
+
if (!packageName) {
|
|
87
|
+
throw new SyntaxError(
|
|
88
|
+
`ERROR: In package.json, the package name \`${addonPackage.name}\` is not valid.`
|
|
89
|
+
);
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
return
|
|
92
|
+
return packageName;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
export function augmentOptions(options) {
|
|
@@ -33,6 +33,7 @@ function moveToAddonAndTestApp(options) {
|
|
|
33
33
|
|
|
34
34
|
const files = packages.addon.hasTypeScript
|
|
35
35
|
? [
|
|
36
|
+
'.eslintignore',
|
|
36
37
|
'.eslintrc.js',
|
|
37
38
|
'.gitignore',
|
|
38
39
|
'.prettierignore',
|
|
@@ -43,6 +44,7 @@ function moveToAddonAndTestApp(options) {
|
|
|
43
44
|
'tsconfig.json',
|
|
44
45
|
]
|
|
45
46
|
: [
|
|
47
|
+
'.eslintignore',
|
|
46
48
|
'.eslintrc.js',
|
|
47
49
|
'.gitignore',
|
|
48
50
|
'.prettierignore',
|
|
@@ -83,7 +85,6 @@ function moveToTestApp(options) {
|
|
|
83
85
|
|
|
84
86
|
const files = [
|
|
85
87
|
'.ember-cli',
|
|
86
|
-
'.eslintignore',
|
|
87
88
|
'.watchmanconfig',
|
|
88
89
|
'ember-cli-build.js',
|
|
89
90
|
'testem.js',
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '../../../utils/convert-json-object.js';
|
|
8
8
|
import { decideVersion } from '../../../utils/decide-version.js';
|
|
9
9
|
|
|
10
|
-
function updateDependencies(packageJson) {
|
|
10
|
+
function updateDependencies(packageJson, options) {
|
|
11
11
|
const dependencies = convertToMap(packageJson['dependencies']);
|
|
12
12
|
|
|
13
13
|
const packagesToDelete = [
|
|
@@ -17,14 +17,14 @@ function updateDependencies(packageJson) {
|
|
|
17
17
|
'ember-cli-htmlbars',
|
|
18
18
|
];
|
|
19
19
|
|
|
20
|
-
const packagesToInstall = ['@embroider/addon-shim'];
|
|
21
|
-
|
|
22
20
|
packagesToDelete.forEach((packageName) => {
|
|
23
21
|
dependencies.delete(packageName);
|
|
24
22
|
});
|
|
25
23
|
|
|
24
|
+
const packagesToInstall = ['@embroider/addon-shim'];
|
|
25
|
+
|
|
26
26
|
packagesToInstall.forEach((packageName) => {
|
|
27
|
-
const version = decideVersion(packageName,
|
|
27
|
+
const version = decideVersion(packageName, options);
|
|
28
28
|
|
|
29
29
|
dependencies.set(packageName, version);
|
|
30
30
|
});
|
|
@@ -37,12 +37,17 @@ function updateDevDependencies(packageJson, options) {
|
|
|
37
37
|
|
|
38
38
|
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
'
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
/*
|
|
41
|
+
For the time being, we'll take the approach of starting over and
|
|
42
|
+
adding back the development dependencies that are required. For
|
|
43
|
+
a more conservative approach, we could delete only the following:
|
|
44
|
+
|
|
45
|
+
- @embroider/macros
|
|
46
|
+
- ember-auto-import
|
|
47
|
+
- ember-cli-babel
|
|
48
|
+
- ember-cli-htmlbars
|
|
49
|
+
*/
|
|
50
|
+
devDependencies.clear();
|
|
46
51
|
|
|
47
52
|
const packagesToInstall = packages.addon.hasTypeScript
|
|
48
53
|
? [
|
|
@@ -65,15 +70,8 @@ function updateDevDependencies(packageJson, options) {
|
|
|
65
70
|
'rollup-plugin-copy',
|
|
66
71
|
];
|
|
67
72
|
|
|
68
|
-
// May be easier to start over and add missing dependencies
|
|
69
|
-
devDependencies.clear();
|
|
70
|
-
|
|
71
|
-
packagesToDelete.forEach((packageName) => {
|
|
72
|
-
devDependencies.delete(packageName);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
73
|
packagesToInstall.forEach((packageName) => {
|
|
76
|
-
const version = decideVersion(packageName,
|
|
74
|
+
const version = decideVersion(packageName, options);
|
|
77
75
|
|
|
78
76
|
devDependencies.set(packageName, version);
|
|
79
77
|
});
|
|
@@ -119,7 +117,7 @@ export function updateAddonPackageJson(options) {
|
|
|
119
117
|
const oldFile = readFileSync(oldPath, 'utf8');
|
|
120
118
|
const packageJson = JSON.parse(oldFile);
|
|
121
119
|
|
|
122
|
-
updateDependencies(packageJson);
|
|
120
|
+
updateDependencies(packageJson, options);
|
|
123
121
|
updateDevDependencies(packageJson, options);
|
|
124
122
|
updateScripts(packageJson);
|
|
125
123
|
updateOtherFields(packageJson);
|
|
@@ -4,6 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import {
|
|
5
5
|
convertToMap,
|
|
6
6
|
convertToObject,
|
|
7
|
+
sanitizeJson,
|
|
7
8
|
} from '../../../utils/convert-json-object.js';
|
|
8
9
|
|
|
9
10
|
function updateCompilerOptions(tsconfigJson) {
|
|
@@ -28,10 +29,7 @@ export function updateAddonTsconfigJson(options) {
|
|
|
28
29
|
|
|
29
30
|
const oldPath = join(projectRoot, locations.addon, 'tsconfig.json');
|
|
30
31
|
const oldFile = readFileSync(oldPath, 'utf8');
|
|
31
|
-
const tsconfigJson = JSON.parse(
|
|
32
|
-
// Remove comments
|
|
33
|
-
oldFile.replace(new RegExp('//.*', 'mg'), '')
|
|
34
|
-
);
|
|
32
|
+
const tsconfigJson = JSON.parse(sanitizeJson(oldFile));
|
|
35
33
|
|
|
36
34
|
updateCompilerOptions(tsconfigJson);
|
|
37
35
|
updateInclude(tsconfigJson);
|
|
@@ -23,7 +23,7 @@ function moveDependenciesToDevDependencies(packageJson, options) {
|
|
|
23
23
|
: ['ember-auto-import', 'ember-cli-babel', 'ember-cli-htmlbars'];
|
|
24
24
|
|
|
25
25
|
packagesToMove.forEach((packageName) => {
|
|
26
|
-
const version = decideVersion(packageName,
|
|
26
|
+
const version = decideVersion(packageName, options);
|
|
27
27
|
|
|
28
28
|
devDependencies.set(packageName, version);
|
|
29
29
|
|
|
@@ -37,7 +37,10 @@ function moveDependenciesToDevDependencies(packageJson, options) {
|
|
|
37
37
|
function updateDependencies(packageJson) {
|
|
38
38
|
const dependencies = convertToMap(packageJson['dependencies']);
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
/*
|
|
41
|
+
For the time being, we'll take the approach of starting over and
|
|
42
|
+
adding back the dependencies that are required.
|
|
43
|
+
*/
|
|
41
44
|
dependencies.clear();
|
|
42
45
|
|
|
43
46
|
packageJson['dependencies'] = convertToObject(dependencies);
|
|
@@ -58,9 +61,9 @@ function updateOtherFields(packageJson, options) {
|
|
|
58
61
|
|
|
59
62
|
delete packageJson['ember-addon'];
|
|
60
63
|
|
|
61
|
-
packageJson['keywords'] = packageJson['keywords'].filter(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
packageJson['keywords'] = (packageJson['keywords'] ?? []).filter(
|
|
65
|
+
(keyword) => keyword !== 'ember-addon'
|
|
66
|
+
);
|
|
64
67
|
|
|
65
68
|
packageJson['name'] = packages.testApp.name;
|
|
66
69
|
|
|
@@ -4,6 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import {
|
|
5
5
|
convertToMap,
|
|
6
6
|
convertToObject,
|
|
7
|
+
sanitizeJson,
|
|
7
8
|
} from '../../../utils/convert-json-object.js';
|
|
8
9
|
|
|
9
10
|
function updateCompilerOptions(tsconfigJson, options) {
|
|
@@ -33,10 +34,7 @@ export function updateTestAppTsconfigJson(options) {
|
|
|
33
34
|
|
|
34
35
|
const oldPath = join(projectRoot, locations.testApp, 'tsconfig.json');
|
|
35
36
|
const oldFile = readFileSync(oldPath, 'utf8');
|
|
36
|
-
const tsconfigJson = JSON.parse(
|
|
37
|
-
// Remove comments
|
|
38
|
-
oldFile.replace(new RegExp('//.*', 'mg'), '')
|
|
39
|
-
);
|
|
37
|
+
const tsconfigJson = JSON.parse(sanitizeJson(oldFile));
|
|
40
38
|
|
|
41
39
|
updateCompilerOptions(tsconfigJson, options);
|
|
42
40
|
updateInclude(tsconfigJson);
|
|
@@ -16,8 +16,10 @@ const latestVersions = new Map([
|
|
|
16
16
|
['rollup-plugin-ts', '3.1.1'],
|
|
17
17
|
]);
|
|
18
18
|
|
|
19
|
-
export function decideVersion(packageName,
|
|
20
|
-
const
|
|
19
|
+
export function decideVersion(packageName, options) {
|
|
20
|
+
const { packages } = options;
|
|
21
|
+
|
|
22
|
+
const installedVersion = packages.addon.dependencies.get(packageName);
|
|
21
23
|
const latestVersion = `^${latestVersions.get(packageName)}`;
|
|
22
24
|
|
|
23
25
|
return installedVersion ?? latestVersion;
|