ember-codemod-v1-to-v2 0.1.1 → 0.1.3
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 +1 -1
- package/src/migration/ember-addon/steps/augment-options.js +19 -17
- package/src/migration/ember-addon/steps/create-files-from-blueprint.js +12 -2
- package/src/migration/ember-addon/steps/update-addon-package-json.js +13 -15
- package/src/migration/ember-addon/steps/update-test-app-package-json.js +7 -4
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
|
@@ -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) {
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
|
|
4
5
|
import glob from 'glob';
|
|
5
6
|
|
|
6
7
|
import { createFiles } from '../../../utils/files.js';
|
|
7
8
|
import { processTemplate } from '../../../utils/process-template.js';
|
|
8
9
|
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = dirname(__filename);
|
|
12
|
+
|
|
13
|
+
function getBlueprintRoot() {
|
|
14
|
+
const codemodRoot = join(__dirname, '../../../..');
|
|
15
|
+
|
|
16
|
+
return join(codemodRoot, 'src/blueprints/ember-addon');
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
function getFilePath(blueprintFilePath, options) {
|
|
10
20
|
const { locations } = options;
|
|
11
21
|
|
|
@@ -36,7 +46,7 @@ function getFilesToSkip(options) {
|
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
export function createFilesFromBlueprint(context, options) {
|
|
39
|
-
const blueprintRoot =
|
|
49
|
+
const blueprintRoot = getBlueprintRoot();
|
|
40
50
|
|
|
41
51
|
const filesToSkip = getFilesToSkip(options);
|
|
42
52
|
|
|
@@ -17,12 +17,12 @@ 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
27
|
const version = decideVersion(packageName, dependencies);
|
|
28
28
|
|
|
@@ -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,13 +70,6 @@ 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
74
|
const version = decideVersion(packageName, devDependencies);
|
|
77
75
|
|
|
@@ -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
|
|