ember-codemod-v1-to-v2 1.2.4 → 1.3.1
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 +20 -10
- package/dist/bin/ember-codemod-v1-to-v2.js +0 -1
- package/dist/src/blueprints/ember-addon/__addonLocation__/.eslintignore +1 -1
- package/dist/src/blueprints/ember-addon/__addonLocation__/.eslintrc.cjs +68 -0
- package/dist/src/blueprints/ember-addon/__addonLocation__/.prettierignore +1 -1
- package/dist/src/blueprints/ember-addon/__addonLocation__/.prettierrc.cjs +5 -0
- package/dist/src/blueprints/ember-addon/__addonLocation__/.template-lintrc.cjs +5 -0
- package/dist/src/blueprints/ember-addon/__addonLocation__/__gitignore__ +8 -3
- package/dist/src/blueprints/ember-addon/__addonLocation__/tsconfig.json +21 -0
- package/dist/src/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts +0 -1
- package/dist/src/blueprints/ember-addon/package.json +5 -5
- package/dist/src/index.js +1 -2
- package/dist/src/steps/create-files-from-blueprints.js +2 -1
- package/dist/src/steps/create-options.js +9 -17
- package/dist/src/steps/index.js +0 -1
- package/dist/src/steps/move-project-root-files.js +8 -16
- package/dist/src/steps/update-addon-package-json/update-dependencies.js +2 -2
- package/dist/src/steps/update-addon-package-json/update-dev-dependencies.js +24 -10
- package/dist/src/steps/update-addon-package-json/update-scripts.js +27 -14
- package/dist/src/utils/blueprints/get-version.js +35 -12
- package/package.json +15 -15
- package/dist/src/steps/update-addon-tsconfig-json.js +0 -38
package/README.md
CHANGED
|
@@ -15,33 +15,43 @@ _Codemod to convert Ember addons to v2 addon format_
|
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
For examples, see [`ember-container-query`](https://github.com/ijlee2/ember-container-query/pull/151/commits) and [`ember-render-helpers`](https://github.com/buschtoens/ember-render-helpers/pull/447/commits).
|
|
19
19
|
|
|
20
|
-
Step 1. Quickly migrate to [v2 format](https://github.com/embroider-build/embroider/blob/
|
|
20
|
+
Step 1. Quickly migrate to [v2 format](https://github.com/embroider-build/embroider/blob/v4.3.1-%40embroider/addon-dev/docs/addon-author-guide.md).
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
cd <path/to/your/project>
|
|
24
24
|
npx ember-codemod-v1-to-v2 <arguments>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
> [!IMPORTANT]
|
|
28
|
+
>
|
|
29
|
+
> Before you run `ember-codemod-v1-to-v2`, I recommend that you address existing tech debts (one at a time). That is, treat the v2 migration as its own thing.
|
|
30
|
+
>
|
|
31
|
+
> Here are examples of what you may want to work on first:
|
|
32
|
+
>
|
|
33
|
+
> - [Meet prerequisites for v2 addon](https://github.com/embroider-build/embroider/blob/v4.3.1-%40embroider/addon-dev/docs/porting-addons-to-v2.md#part-3-prerequisites-for-v2-addon).
|
|
34
|
+
> - [Un-pod v1 addon](https://github.com/ijlee2/ember-codemod-pod-to-octane).
|
|
35
|
+
> - Update dependencies.
|
|
36
|
+
> - Switch `npm` or `yarn` to `pnpm`.
|
|
37
|
+
|
|
27
38
|
Step 2. Review the addon package.
|
|
28
39
|
|
|
29
|
-
- [x] Update the configuration files.<sup>
|
|
40
|
+
- [x] Update the configuration files.<sup>1</sup>
|
|
41
|
+
- [x] Install missing dependencies.
|
|
30
42
|
- [x] Relative import paths must specify the file extension `.js` or `.ts`.
|
|
31
43
|
- [x] Colocate stylesheets (if any). Let each component import the relevant stylesheet in the backing class.
|
|
32
44
|
- [x] Confirm that you can run all scripts in `package.json`.
|
|
33
45
|
|
|
34
46
|
Step 3. Review the test-app package.
|
|
35
47
|
|
|
36
|
-
- [x] Update the configuration files.<sup>
|
|
48
|
+
- [x] Update the configuration files.<sup>1</sup>
|
|
37
49
|
- [x] Rename the remaining instances of `dummy` to `test-app`.
|
|
38
50
|
- [x] Confirm that you can run all scripts in `package.json`.
|
|
39
51
|
|
|
40
52
|
Step 4. Review the workspace root including CI/CD.
|
|
41
53
|
|
|
42
|
-
<sup>1.
|
|
43
|
-
|
|
44
|
-
<sup>2. Files such as `.eslintrc.js`, `.gitignore`, `babel.config.json` (addon only), `config/environment.js` (test-app only), `ember-cli-build.js` (test-app only), `package.json`, `rollup.config.mjs` (addon only), `tsconfig.json`, etc.</sup>
|
|
54
|
+
<sup>1. Files such as `.eslintrc.js`, `.gitignore`, `babel.config.json` (addon only), `config/environment.js` (test-app only), `ember-cli-build.js` (test-app only), `package.json`, `rollup.config.mjs` (addon only), `tsconfig.json`, etc.</sup>
|
|
45
55
|
|
|
46
56
|
|
|
47
57
|
### Arguments
|
|
@@ -55,7 +65,7 @@ In most cases, I recommend running the codemod without any arguments (i.e. allow
|
|
|
55
65
|
By default, the package name decides where the addon package lives. Pass `--addon-location` to override the logic. This may be useful if you have a workspace with many addons.
|
|
56
66
|
|
|
57
67
|
```sh
|
|
58
|
-
npx ember-codemod-v1-to-v2 --addon-location packages/ui/
|
|
68
|
+
npx ember-codemod-v1-to-v2 --addon-location packages/ui/button
|
|
59
69
|
```
|
|
60
70
|
|
|
61
71
|
</details>
|
|
@@ -94,7 +104,7 @@ npx ember-codemod-v1-to-v2 --test-app-location docs-app
|
|
|
94
104
|
By default, the test-app package is named `test-app`. Pass `--test-app-name` to override the logic. This may be useful if you have a workspace with many addons.
|
|
95
105
|
|
|
96
106
|
```sh
|
|
97
|
-
npx ember-codemod-v1-to-v2 --test-app-name test-app-for-ui-
|
|
107
|
+
npx ember-codemod-v1-to-v2 --test-app-name test-app-for-ui-button
|
|
98
108
|
```
|
|
99
109
|
|
|
100
110
|
</details>
|
|
@@ -133,7 +143,7 @@ If you have an open-sourced addon (v1 or v2) that I can use as a reference, reac
|
|
|
133
143
|
|
|
134
144
|
## Credits
|
|
135
145
|
|
|
136
|
-
The codemod steps were based on [Migrating an Ember addon to the next-gen v2 format](https://www.kaliber5.de/de/blog/v2-addon_en) and [Guide: Porting an Addon to v2](https://github.com/embroider-build/embroider/blob/
|
|
146
|
+
The codemod steps were based on [Migrating an Ember addon to the next-gen v2 format](https://www.kaliber5.de/de/blog/v2-addon_en) and [Guide: Porting an Addon to v2](https://github.com/embroider-build/embroider/blob/v4.3.1-%40embroider/addon-dev/docs/porting-addons-to-v2.md). The blueprints were derived from [`@embroider/addon-blueprint`](https://github.com/embroider-build/addon-blueprint).
|
|
137
147
|
|
|
138
148
|
|
|
139
149
|
## License
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
root: true,
|
|
5
|
+
parser: '<%= options.packages.addon.hasTypeScript ? '@typescript-eslint/parser' : '@babel/eslint-parser' %>',
|
|
6
|
+
parserOptions: {
|
|
7
|
+
ecmaVersion: 'latest',<% if (!options.packages.addon.hasTypeScript) { %>
|
|
8
|
+
sourceType: 'module',
|
|
9
|
+
babelOptions: {
|
|
10
|
+
root: __dirname,
|
|
11
|
+
},<% } %>
|
|
12
|
+
},
|
|
13
|
+
plugins: ['ember'],
|
|
14
|
+
extends: [
|
|
15
|
+
'eslint:recommended',
|
|
16
|
+
'plugin:ember/recommended',
|
|
17
|
+
'plugin:prettier/recommended',
|
|
18
|
+
],
|
|
19
|
+
env: {
|
|
20
|
+
browser: true,
|
|
21
|
+
},
|
|
22
|
+
rules: {},
|
|
23
|
+
overrides: [
|
|
24
|
+
<% if (options.packages.addon.hasTypeScript) { %> // ts files
|
|
25
|
+
{
|
|
26
|
+
files: ['**/*.ts', '**/*.gts'],
|
|
27
|
+
extends: [
|
|
28
|
+
'plugin:@typescript-eslint/eslint-recommended',
|
|
29
|
+
'plugin:@typescript-eslint/recommended',
|
|
30
|
+
],
|
|
31
|
+
rules: {
|
|
32
|
+
// Add any custom rules here
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
// require relative imports use full extensions
|
|
36
|
+
{
|
|
37
|
+
files: ['src/**/*.{js,ts,gjs,gts}'],
|
|
38
|
+
rules: {
|
|
39
|
+
'import/extensions': ['error', 'always', { ignorePackages: true }],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
<% } else { %> // require relative imports use full extensions
|
|
43
|
+
{
|
|
44
|
+
files: ['src/**/*.{js,gjs}'],
|
|
45
|
+
rules: {
|
|
46
|
+
'import/extensions': ['error', 'always', { ignorePackages: true }],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
<% } %> // node files
|
|
50
|
+
{
|
|
51
|
+
files: [
|
|
52
|
+
'./.eslintrc.cjs',
|
|
53
|
+
'./.prettierrc.cjs',
|
|
54
|
+
'./.template-lintrc.cjs',
|
|
55
|
+
'./addon-main.cjs',
|
|
56
|
+
],
|
|
57
|
+
parserOptions: {
|
|
58
|
+
sourceType: 'script',
|
|
59
|
+
},
|
|
60
|
+
env: {
|
|
61
|
+
browser: false,
|
|
62
|
+
node: true,
|
|
63
|
+
},
|
|
64
|
+
plugins: ['n'],
|
|
65
|
+
extends: ['plugin:n/recommended'],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# The authoritative copies of these live in the monorepo root (because they're
|
|
2
2
|
# more useful on github that way), but the build copies them into here so they
|
|
3
3
|
# will also appear in published NPM packages.
|
|
4
|
-
/LICENSE.md
|
|
5
4
|
/README.md
|
|
5
|
+
/LICENSE.md
|
|
6
6
|
|
|
7
7
|
# compiled output
|
|
8
|
-
/
|
|
9
|
-
/
|
|
8
|
+
dist/
|
|
9
|
+
declarations/
|
|
10
10
|
|
|
11
11
|
# npm/pnpm/yarn pack output
|
|
12
12
|
*.tgz
|
|
13
|
+
|
|
14
|
+
# deps & caches
|
|
15
|
+
node_modules/
|
|
16
|
+
.eslintcache
|
|
17
|
+
.prettiercache
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@tsconfig/ember/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"allowImportingTsExtensions": true,
|
|
5
|
+
"allowJs": true,
|
|
6
|
+
"declarationDir": "declarations",
|
|
7
|
+
"emitDeclarationOnly": true,
|
|
8
|
+
"noEmit": false,
|
|
9
|
+
"noEmitOnError": false,
|
|
10
|
+
"rootDir": "./src"
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"src/**/*",
|
|
14
|
+
"unpublished-development-types/**/*"
|
|
15
|
+
]<% if (options.packages.addon.hasGlint) { %>,
|
|
16
|
+
"glint": {
|
|
17
|
+
"environment": [
|
|
18
|
+
"ember-loose"
|
|
19
|
+
]
|
|
20
|
+
}<% } %>
|
|
21
|
+
}
|
package/dist/src/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
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
3
|
<% if (options.packages.addon.hasGlint) { %>
|
|
4
4
|
import '@glint/environment-ember-loose';
|
|
5
|
-
// import '@glint/environment-ember-template-imports';
|
|
6
5
|
|
|
7
6
|
declare module '@glint/environment-ember-loose/registry' {
|
|
8
7
|
// Remove this once entries have been added! 👇
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<% if (options.packageManager
|
|
1
|
+
<% if (options.packageManager === 'npm') { %>{
|
|
2
2
|
"name": "workspace-root",
|
|
3
3
|
"version": "<%= options.packages.addon.version %>",
|
|
4
4
|
"private": true,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
24
24
|
}
|
|
25
|
-
}<% } else if (options.packageManager
|
|
25
|
+
}<% } else if (options.packageManager === 'pnpm') { %>{
|
|
26
26
|
"name": "workspace-root",
|
|
27
27
|
"version": "<%= options.packages.addon.version %>",
|
|
28
28
|
"private": true,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"lint": "pnpm --filter '*' lint",
|
|
35
35
|
"lint:fix": "pnpm --filter '*' lint:fix",
|
|
36
36
|
"prepare": "pnpm build",
|
|
37
|
-
"start": "concurrently '
|
|
37
|
+
"start": "concurrently 'pnpm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
38
38
|
"start:addon": "pnpm --filter <%= options.packages.addon.name %> start",
|
|
39
39
|
"start:test-app": "pnpm --filter <%= options.packages.testApp.name %> start",
|
|
40
40
|
"test": "pnpm --filter '*' test"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
|
|
44
44
|
}
|
|
45
|
-
}<% } else if (options.packageManager
|
|
45
|
+
}<% } else if (options.packageManager === 'yarn') { %>{
|
|
46
46
|
"name": "workspace-root",
|
|
47
47
|
"version": "<%= options.packages.addon.version %>",
|
|
48
48
|
"private": true,
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"lint": "yarn workspaces run lint",
|
|
59
59
|
"lint:fix": "yarn workspaces run lint:fix",
|
|
60
60
|
"prepare": "yarn build",
|
|
61
|
-
"start": "concurrently '
|
|
61
|
+
"start": "concurrently 'yarn:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow",
|
|
62
62
|
"start:addon": "yarn workspace <%= options.packages.addon.name %> run start",
|
|
63
63
|
"start:test-app": "yarn workspace <%= options.packages.testApp.name %> run start",
|
|
64
64
|
"test": "yarn workspaces run test"
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { analyzeAddon, createFilesFromBlueprints, createOptions, moveAddonFiles, moveProjectRootFiles, moveTestAppFiles, updateAddonPackageJson,
|
|
1
|
+
import { analyzeAddon, createFilesFromBlueprints, createOptions, moveAddonFiles, moveProjectRootFiles, moveTestAppFiles, updateAddonPackageJson, updateTestAppPackageJson, updateTestAppTsConfigJson, } from './steps/index.js';
|
|
2
2
|
export function runCodemod(codemodOptions) {
|
|
3
3
|
const options = createOptions(codemodOptions);
|
|
4
4
|
const { isV1Addon } = options.packages.addon;
|
|
@@ -16,7 +16,6 @@ export function runCodemod(codemodOptions) {
|
|
|
16
16
|
createFilesFromBlueprints(context, options);
|
|
17
17
|
// Fine-tune individual files
|
|
18
18
|
updateAddonPackageJson(context, options);
|
|
19
|
-
updateAddonTsConfigJson(options);
|
|
20
19
|
updateTestAppPackageJson(options);
|
|
21
20
|
updateTestAppTsConfigJson(options);
|
|
22
21
|
}
|
|
@@ -7,10 +7,11 @@ function getFilesToSkip(options) {
|
|
|
7
7
|
const { packageManager, packages } = options;
|
|
8
8
|
const files = new Set();
|
|
9
9
|
if (!packages.addon.hasTypeScript) {
|
|
10
|
+
files.add('__addonLocation__/tsconfig.json');
|
|
10
11
|
files.add('__addonLocation__/unpublished-development-types/index.d.ts');
|
|
11
12
|
files.add('__testAppLocation__/types/global.d.ts');
|
|
12
13
|
}
|
|
13
|
-
if (
|
|
14
|
+
if (packageManager !== 'pnpm') {
|
|
14
15
|
files.add('pnpm-workspace.yaml');
|
|
15
16
|
}
|
|
16
17
|
return Array.from(files);
|
|
@@ -20,29 +20,21 @@ function analyzePackageJson(codemodOptions) {
|
|
|
20
20
|
}
|
|
21
21
|
function analyzePackageManager(codemodOptions) {
|
|
22
22
|
const { projectRoot } = codemodOptions;
|
|
23
|
-
const mapping =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const lockFiles =
|
|
23
|
+
const mapping = {
|
|
24
|
+
'package-lock.json': 'npm',
|
|
25
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
26
|
+
'yarn.lock': 'yarn',
|
|
27
|
+
};
|
|
28
|
+
const lockFiles = Object.keys(mapping);
|
|
29
29
|
const filePaths = findFiles(lockFiles, {
|
|
30
30
|
projectRoot,
|
|
31
31
|
});
|
|
32
32
|
if (filePaths.length !== 1) {
|
|
33
33
|
console.warn('WARNING: Package manager is unknown. Yarn will be assumed.');
|
|
34
|
-
return
|
|
35
|
-
isNpm: false,
|
|
36
|
-
isPnpm: false,
|
|
37
|
-
isYarn: true,
|
|
38
|
-
};
|
|
34
|
+
return 'yarn';
|
|
39
35
|
}
|
|
40
|
-
const
|
|
41
|
-
return
|
|
42
|
-
isNpm: packageManager === 'npm',
|
|
43
|
-
isPnpm: packageManager === 'pnpm',
|
|
44
|
-
isYarn: packageManager === 'yarn',
|
|
45
|
-
};
|
|
36
|
+
const lockfile = filePaths[0];
|
|
37
|
+
return mapping[lockfile];
|
|
46
38
|
}
|
|
47
39
|
function deriveAddonLocation(addonPackage) {
|
|
48
40
|
const hasScope = addonPackage.name.includes('/');
|
package/dist/src/steps/index.js
CHANGED
|
@@ -5,6 +5,5 @@ export * from './move-addon-files.js';
|
|
|
5
5
|
export * from './move-project-root-files.js';
|
|
6
6
|
export * from './move-test-app-files.js';
|
|
7
7
|
export * from './update-addon-package-json.js';
|
|
8
|
-
export * from './update-addon-tsconfig-json.js';
|
|
9
8
|
export * from './update-test-app-package-json.js';
|
|
10
9
|
export * from './update-test-app-tsconfig-json.js';
|
|
@@ -13,22 +13,7 @@ function copyToAddon(options) {
|
|
|
13
13
|
}
|
|
14
14
|
function moveToAddonAndTestApp(options) {
|
|
15
15
|
const { locations, projectRoot } = options;
|
|
16
|
-
const files = [
|
|
17
|
-
'.eslintignore',
|
|
18
|
-
'.eslintrc.cjs',
|
|
19
|
-
'.eslintrc.js',
|
|
20
|
-
'.gitignore',
|
|
21
|
-
'.prettierignore',
|
|
22
|
-
'.prettierrc.cjs',
|
|
23
|
-
'.prettierrc.js',
|
|
24
|
-
'.stylelintignore',
|
|
25
|
-
'.stylelintrc.cjs',
|
|
26
|
-
'.stylelintrc.js',
|
|
27
|
-
'.template-lintrc.cjs',
|
|
28
|
-
'.template-lintrc.js',
|
|
29
|
-
'package.json',
|
|
30
|
-
'tsconfig.json',
|
|
31
|
-
];
|
|
16
|
+
const files = ['.stylelintignore', '.stylelintrc.{cjs,js}', 'package.json'];
|
|
32
17
|
const filePaths = findFiles(files, {
|
|
33
18
|
projectRoot,
|
|
34
19
|
});
|
|
@@ -48,9 +33,16 @@ function moveToTestApp(options) {
|
|
|
48
33
|
const { locations, projectRoot } = options;
|
|
49
34
|
const files = [
|
|
50
35
|
'.ember-cli',
|
|
36
|
+
'.eslintignore',
|
|
37
|
+
'.eslintrc.{cjs,js}',
|
|
38
|
+
'.gitignore',
|
|
39
|
+
'.prettierignore',
|
|
40
|
+
'.prettierrc.{cjs,js}',
|
|
41
|
+
'.template-lintrc.{cjs,js}',
|
|
51
42
|
'.watchmanconfig',
|
|
52
43
|
'ember-cli-build.js',
|
|
53
44
|
'testem.js',
|
|
45
|
+
'tsconfig.json',
|
|
54
46
|
];
|
|
55
47
|
const filePaths = findFiles(files, {
|
|
56
48
|
projectRoot,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
-
import {
|
|
2
|
+
import { getLatestVersion } from '../../utils/blueprints.js';
|
|
3
3
|
export function updateDependencies(packageJson, options) {
|
|
4
4
|
const dependencies = convertToMap(packageJson['dependencies']);
|
|
5
5
|
const packagesToDelete = new Set([
|
|
@@ -16,7 +16,7 @@ export function updateDependencies(packageJson, options) {
|
|
|
16
16
|
});
|
|
17
17
|
const packagesToInstall = ['@embroider/addon-shim', 'decorator-transforms'];
|
|
18
18
|
packagesToInstall.forEach((packageName) => {
|
|
19
|
-
const version =
|
|
19
|
+
const version = getLatestVersion(packageName);
|
|
20
20
|
dependencies.set(packageName, version);
|
|
21
21
|
});
|
|
22
22
|
packageJson['dependencies'] = convertToObject(dependencies);
|
|
@@ -1,36 +1,50 @@
|
|
|
1
1
|
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
-
import {
|
|
2
|
+
import { getLatestVersion } from '../../utils/blueprints.js';
|
|
3
3
|
export function updateDevDependencies(packageJson, options) {
|
|
4
4
|
const { packages } = options;
|
|
5
5
|
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
6
6
|
/*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
a more conservative approach, we could delete only the following:
|
|
10
|
-
|
|
11
|
-
- @embroider/macros
|
|
12
|
-
- ember-auto-import
|
|
13
|
-
- ember-cli-babel
|
|
14
|
-
- ember-cli-htmlbars
|
|
7
|
+
The codemod sets the development dependencies that v2 addons need.
|
|
8
|
+
End-developers must add dependencies that their v1 addon needed.
|
|
15
9
|
*/
|
|
16
10
|
devDependencies.clear();
|
|
17
11
|
const packagesToInstall = new Set([
|
|
18
12
|
'@babel/core',
|
|
13
|
+
'@babel/eslint-parser',
|
|
19
14
|
'@babel/runtime',
|
|
20
15
|
'@embroider/addon-dev',
|
|
21
16
|
'@rollup/plugin-babel',
|
|
22
17
|
'babel-plugin-ember-template-compilation',
|
|
23
18
|
'concurrently',
|
|
19
|
+
'ember-template-lint',
|
|
20
|
+
'eslint',
|
|
21
|
+
'eslint-config-prettier',
|
|
22
|
+
'eslint-plugin-ember',
|
|
23
|
+
'eslint-plugin-import',
|
|
24
|
+
'eslint-plugin-n',
|
|
25
|
+
'eslint-plugin-prettier',
|
|
26
|
+
'prettier',
|
|
24
27
|
'rollup',
|
|
25
28
|
'rollup-plugin-copy',
|
|
26
29
|
]);
|
|
27
30
|
if (packages.addon.hasTypeScript) {
|
|
31
|
+
packagesToInstall.delete('@babel/eslint-parser');
|
|
28
32
|
packagesToInstall.add('@babel/plugin-transform-typescript');
|
|
29
33
|
packagesToInstall.add('@tsconfig/ember');
|
|
34
|
+
packagesToInstall.add('@types/ember__component');
|
|
35
|
+
packagesToInstall.add('@types/ember__object');
|
|
36
|
+
packagesToInstall.add('@types/ember__service');
|
|
37
|
+
packagesToInstall.add('@typescript-eslint/eslint-plugin');
|
|
38
|
+
packagesToInstall.add('@typescript-eslint/parser');
|
|
30
39
|
packagesToInstall.add('typescript');
|
|
31
40
|
}
|
|
41
|
+
if (packages.addon.hasGlint) {
|
|
42
|
+
packagesToInstall.add('@glint/core');
|
|
43
|
+
packagesToInstall.add('@glint/environment-ember-loose');
|
|
44
|
+
packagesToInstall.add('@glint/template');
|
|
45
|
+
}
|
|
32
46
|
Array.from(packagesToInstall).forEach((packageName) => {
|
|
33
|
-
const version =
|
|
47
|
+
const version = getLatestVersion(packageName);
|
|
34
48
|
devDependencies.set(packageName, version);
|
|
35
49
|
});
|
|
36
50
|
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
2
|
export function updateScripts(packageJson, options) {
|
|
3
|
-
const { packages } = options;
|
|
3
|
+
const { locations, packageManager, packages } = options;
|
|
4
4
|
const scripts = convertToMap(packageJson['scripts']);
|
|
5
|
+
/*
|
|
6
|
+
The codemod sets the scripts that v2 addons need. End-developers
|
|
7
|
+
must add scripts that their v1 addon needed.
|
|
8
|
+
*/
|
|
9
|
+
scripts.clear();
|
|
10
|
+
scripts.set('lint', `concurrently '${packageManager}:lint:*(!fix)' --names 'lint:'`);
|
|
11
|
+
scripts.set('lint:fix', `concurrently '${packageManager}:lint:*:fix' --names 'fix:'`);
|
|
12
|
+
scripts.set('lint:hbs', 'ember-template-lint . --no-error-on-unmatched-pattern');
|
|
13
|
+
scripts.set('lint:hbs:fix', 'ember-template-lint . --fix --no-error-on-unmatched-pattern');
|
|
14
|
+
scripts.set('lint:js', 'eslint . --cache');
|
|
15
|
+
scripts.set('lint:js:fix', 'eslint . --fix');
|
|
16
|
+
scripts.set('test', `echo 'A v2 addon does not have tests, run tests in ${locations.testApp}'`);
|
|
5
17
|
if (packages.addon.hasTypeScript) {
|
|
6
|
-
scripts.set('build',
|
|
18
|
+
scripts.set('build', `concurrently '${packageManager}:build:*'`);
|
|
7
19
|
scripts.set('build:js', 'rollup --config');
|
|
8
|
-
scripts.
|
|
9
|
-
scripts.set('
|
|
10
|
-
|
|
11
|
-
: 'tsc --emitDeclarationOnly false --noEmit');
|
|
12
|
-
if (scripts.get('postpack') === 'ember ts:clean') {
|
|
13
|
-
scripts.delete('postpack');
|
|
14
|
-
}
|
|
15
|
-
scripts.set('prepack', 'rollup --config');
|
|
16
|
-
scripts.set('start', 'concurrently "npm:start:*" --names "start:"');
|
|
20
|
+
scripts.delete('postpack');
|
|
21
|
+
scripts.set('prepack', `concurrently '${packageManager}:build:*'`);
|
|
22
|
+
scripts.set('start', `concurrently '${packageManager}:start:*'`);
|
|
17
23
|
scripts.set('start:js', 'rollup --config --watch --no-watch.clearScreen');
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
if (packages.addon.hasGlint) {
|
|
25
|
+
scripts.set('build:types', 'glint --declaration');
|
|
26
|
+
scripts.set('lint:types', 'glint');
|
|
27
|
+
scripts.set('start:types', 'glint --declaration --watch');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
scripts.set('build:types', 'tsc');
|
|
31
|
+
scripts.set('lint:types', 'tsc --emitDeclarationOnly false --noEmit');
|
|
32
|
+
scripts.set('start:types', 'tsc --watch');
|
|
33
|
+
}
|
|
20
34
|
}
|
|
21
35
|
else {
|
|
22
36
|
scripts.set('build', 'rollup --config');
|
|
23
37
|
scripts.set('prepack', 'rollup --config');
|
|
24
38
|
scripts.set('start', 'rollup --config --watch');
|
|
25
|
-
scripts.set('test', "echo 'A v2 addon does not have tests, run tests in test-app'");
|
|
26
39
|
}
|
|
27
40
|
packageJson['scripts'] = convertToObject(scripts);
|
|
28
41
|
}
|
|
@@ -1,23 +1,46 @@
|
|
|
1
1
|
import { decideVersion } from '@codemod-utils/blueprints';
|
|
2
2
|
const latestVersions = new Map([
|
|
3
|
-
['@babel/core', '7.24.
|
|
4
|
-
['@babel/
|
|
5
|
-
['@babel/
|
|
6
|
-
['@
|
|
7
|
-
['@embroider/addon-
|
|
8
|
-
['@embroider/
|
|
3
|
+
['@babel/core', '7.24.7'],
|
|
4
|
+
['@babel/eslint-parser', '7.24.7'],
|
|
5
|
+
['@babel/plugin-transform-typescript', '7.24.7'],
|
|
6
|
+
['@babel/runtime', '7.24.7'],
|
|
7
|
+
['@embroider/addon-dev', '4.3.1'],
|
|
8
|
+
['@embroider/addon-shim', '1.8.9'],
|
|
9
|
+
['@embroider/test-setup', '4.0.0'],
|
|
10
|
+
['@glint/core', '1.4.0'],
|
|
11
|
+
['@glint/environment-ember-loose', '1.4.0'],
|
|
12
|
+
['@glint/template', '1.4.0'],
|
|
9
13
|
['@rollup/plugin-babel', '6.0.4'],
|
|
10
|
-
['@tsconfig/ember', '3.0.
|
|
11
|
-
['
|
|
14
|
+
['@tsconfig/ember', '3.0.8'],
|
|
15
|
+
['@types/ember__component', '4.0.22'],
|
|
16
|
+
['@types/ember__object', '4.0.12'],
|
|
17
|
+
['@types/ember__service', '4.0.9'],
|
|
18
|
+
['@typescript-eslint/eslint-plugin', '7.12.0'],
|
|
19
|
+
['@typescript-eslint/parser', '7.12.0'],
|
|
20
|
+
['babel-plugin-ember-template-compilation', '2.2.5'],
|
|
12
21
|
['concurrently', '8.2.2'],
|
|
13
|
-
['decorator-transforms', '
|
|
14
|
-
['ember-auto-import', '2.7.
|
|
22
|
+
['decorator-transforms', '2.0.0'],
|
|
23
|
+
['ember-auto-import', '2.7.3'],
|
|
15
24
|
['ember-cli-babel', '8.1.0'],
|
|
16
25
|
['ember-cli-htmlbars', '6.3.0'],
|
|
17
|
-
['
|
|
26
|
+
['ember-template-lint', '6.0.0'],
|
|
27
|
+
['eslint', '8.57.0'],
|
|
28
|
+
['eslint-config-prettier', '9.1.0'],
|
|
29
|
+
['eslint-plugin-ember', '12.1.1'],
|
|
30
|
+
['eslint-plugin-import', '2.29.1'],
|
|
31
|
+
['eslint-plugin-n', '17.8.1'],
|
|
32
|
+
['eslint-plugin-prettier', '5.1.3'],
|
|
33
|
+
['prettier', '3.3.1'],
|
|
34
|
+
['rollup', '4.18.0'],
|
|
18
35
|
['rollup-plugin-copy', '3.5.0'],
|
|
19
|
-
['typescript', '5.4.
|
|
36
|
+
['typescript', '5.4.5'],
|
|
20
37
|
]);
|
|
38
|
+
export function getLatestVersion(packageName) {
|
|
39
|
+
if (!latestVersions.has(packageName)) {
|
|
40
|
+
throw new RangeError(`ERROR: The latest version of \`${packageName}\` is unknown.\n`);
|
|
41
|
+
}
|
|
42
|
+
return `^${latestVersions.get(packageName)}`;
|
|
43
|
+
}
|
|
21
44
|
export function getVersion(packageName, options) {
|
|
22
45
|
const { packages } = options;
|
|
23
46
|
return decideVersion(packageName, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-codemod-v1-to-v2",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Codemod to convert Ember addons to v2 addon format",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -27,34 +27,34 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@codemod-utils/blueprints": "^1.1.
|
|
31
|
-
"@codemod-utils/files": "^2.0.
|
|
32
|
-
"@codemod-utils/json": "^1.1.
|
|
30
|
+
"@codemod-utils/blueprints": "^1.1.3",
|
|
31
|
+
"@codemod-utils/files": "^2.0.2",
|
|
32
|
+
"@codemod-utils/json": "^1.1.7",
|
|
33
33
|
"strip-json-comments": "^5.0.1",
|
|
34
34
|
"yargs": "^17.7.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/core": "^7.24.
|
|
38
|
-
"@codemod-utils/tests": "^1.1.
|
|
37
|
+
"@babel/core": "^7.24.7",
|
|
38
|
+
"@codemod-utils/tests": "^1.1.5",
|
|
39
39
|
"@sondr3/minitest": "^0.1.2",
|
|
40
|
-
"@tsconfig/node18": "^18.2.
|
|
41
|
-
"@tsconfig/strictest": "^2.0.
|
|
42
|
-
"@types/node": "^18.19.
|
|
40
|
+
"@tsconfig/node18": "^18.2.4",
|
|
41
|
+
"@tsconfig/strictest": "^2.0.5",
|
|
42
|
+
"@types/node": "^18.19.34",
|
|
43
43
|
"@types/yargs": "^17.0.32",
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
45
|
-
"@typescript-eslint/parser": "^7.
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
|
45
|
+
"@typescript-eslint/parser": "^7.12.0",
|
|
46
46
|
"concurrently": "^8.2.2",
|
|
47
47
|
"eslint": "^8.57.0",
|
|
48
48
|
"eslint-config-prettier": "^9.1.0",
|
|
49
49
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
50
50
|
"eslint-plugin-import": "^2.29.1",
|
|
51
|
-
"eslint-plugin-n": "^
|
|
51
|
+
"eslint-plugin-n": "^17.8.1",
|
|
52
52
|
"eslint-plugin-prettier": "^5.1.3",
|
|
53
|
-
"eslint-plugin-simple-import-sort": "^12.
|
|
53
|
+
"eslint-plugin-simple-import-sort": "^12.1.0",
|
|
54
54
|
"eslint-plugin-typescript-sort-keys": "^3.2.0",
|
|
55
55
|
"lerna-changelog": "^2.2.0",
|
|
56
|
-
"prettier": "^3.
|
|
57
|
-
"typescript": "^5.4.
|
|
56
|
+
"prettier": "^3.3.1",
|
|
57
|
+
"typescript": "^5.4.5"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": "18.* || >= 20"
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
4
|
-
import { sanitizeJson } from '../utils/json.js';
|
|
5
|
-
function setExtends(tsConfigJson) {
|
|
6
|
-
tsConfigJson['extends'] = '@tsconfig/ember/tsconfig.json';
|
|
7
|
-
}
|
|
8
|
-
function setCompilerOptions(tsConfigJson, options) {
|
|
9
|
-
const { packages } = options;
|
|
10
|
-
const compilerOptions = convertToMap();
|
|
11
|
-
compilerOptions.set('allowImportingTsExtensions', true);
|
|
12
|
-
compilerOptions.set('allowJs', true);
|
|
13
|
-
compilerOptions.set('declarationDir', 'declarations');
|
|
14
|
-
compilerOptions.set('rootDir', './src');
|
|
15
|
-
if (!packages.addon.hasGlint) {
|
|
16
|
-
compilerOptions.set('declaration', true);
|
|
17
|
-
compilerOptions.set('emitDeclarationOnly', true);
|
|
18
|
-
compilerOptions.set('noEmit', false);
|
|
19
|
-
}
|
|
20
|
-
tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
|
|
21
|
-
}
|
|
22
|
-
function setInclude(tsConfigJson) {
|
|
23
|
-
tsConfigJson['include'] = ['src/**/*', 'unpublished-development-types/**/*'];
|
|
24
|
-
}
|
|
25
|
-
export function updateAddonTsConfigJson(options) {
|
|
26
|
-
const { locations, packages, projectRoot } = options;
|
|
27
|
-
if (!packages.addon.hasTypeScript) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const oldPath = join(projectRoot, locations.addon, 'tsconfig.json');
|
|
31
|
-
const oldFile = readFileSync(oldPath, 'utf8');
|
|
32
|
-
const tsConfigJson = JSON.parse(sanitizeJson(oldFile));
|
|
33
|
-
setExtends(tsConfigJson);
|
|
34
|
-
setCompilerOptions(tsConfigJson, options);
|
|
35
|
-
setInclude(tsConfigJson);
|
|
36
|
-
const newFile = JSON.stringify(tsConfigJson, null, 2) + '\n';
|
|
37
|
-
writeFileSync(oldPath, newFile, 'utf8');
|
|
38
|
-
}
|