Skip to content

Commit 28d104f

Browse files
authored
Allowed codemod to set linters for the v2 addon (#82)
* feature: Allowed codemod to set development dependencies for addon * feature: Allowed codemod to configure linters for addon * refactor: Removed unused step * chore: Updated move-project-root-files step * chore: Updated fixtures * chore: Updated README --------- Co-authored-by: ijlee2 <[email protected]>
1 parent 6abd672 commit 28d104f

File tree

188 files changed

+1952
-1646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+1952
-1646
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,43 @@ _Codemod to convert Ember addons to v2 addon format_
1515

1616
## Usage
1717

18-
You can check [`ember-container-query`](https://github.com/ijlee2/ember-container-query/pull/151) as a reference.
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).
1919

20-
Step 1. Quickly migrate to [v2 format](https://github.com/embroider-build/embroider/blob/main/ADDON-AUTHOR-GUIDE.md).<sup>1</sup>
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).
2121

2222
```sh
2323
cd <path/to/your/project>
2424
npx ember-codemod-v1-to-v2 <arguments>
2525
```
2626

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+
2738
Step 2. Review the addon package.
2839

29-
- [x] Update the configuration files.<sup>2</sup>
40+
- [x] Update the configuration files.<sup>1</sup>
41+
- [x] Install missing dependencies.
3042
- [x] Relative import paths must specify the file extension `.js` or `.ts`.
3143
- [x] Colocate stylesheets (if any). Let each component import the relevant stylesheet in the backing class.
3244
- [x] Confirm that you can run all scripts in `package.json`.
3345

3446
Step 3. Review the test-app package.
3547

36-
- [x] Update the configuration files.<sup>2</sup>
48+
- [x] Update the configuration files.<sup>1</sup>
3749
- [x] Rename the remaining instances of `dummy` to `test-app`.
3850
- [x] Confirm that you can run all scripts in `package.json`.
3951

4052
Step 4. Review the workspace root including CI/CD.
4153

42-
<sup>1. Before running `ember-codemod-v1-to-v2`, consider [meeting the prerequisites](https://github.com/embroider-build/embroider/blob/v1.8.3/PORTING-ADDONS-TO-V2.md#part-3-prerequisites-for-v2-addon). You can run [`ember-codemod-pod-to-octane`](https://github.com/ijlee2/ember-codemod-pod-to-octane) to un-pod a v1 addon.</sup>
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>
4555

4656

4757
### Arguments
@@ -133,7 +143,7 @@ If you have an open-sourced addon (v1 or v2) that I can use as a reference, reac
133143

134144
## Credits
135145

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/v3.1.3-core/docs/porting-addons-to-v2.md). The blueprints were derived from [`@embroider/addon-blueprint`](https://github.com/embroider-build/addon-blueprint).
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).
137147

138148

139149
## License

src/blueprints/ember-addon/__addonLocation__/.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/blueprints/*/files/
33

44
# compiled output
5-
/declarations/
65
/dist/
6+
/declarations/
77

88
# misc
99
/coverage/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
};

src/blueprints/ember-addon/__addonLocation__/.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/blueprints/*/files/
33

44
# compiled output
5-
/declarations/
65
/dist/
6+
/declarations/
77

88
# misc
99
/coverage/
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# The authoritative copies of these live in the monorepo root (because they're
22
# more useful on github that way), but the build copies them into here so they
33
# will also appear in published NPM packages.
4-
/LICENSE.md
54
/README.md
5+
/LICENSE.md
66

77
# compiled output
8-
/declarations
9-
/dist
8+
dist/
9+
declarations/
1010

1111
# npm/pnpm/yarn pack output
1212
*.tgz
13+
14+
# deps & caches
15+
node_modules/
16+
.eslintcache
17+
.prettiercache
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

src/blueprints/ember-addon/__addonLocation__/unpublished-development-types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// These will *not* be published as part of your addon, so be careful that your published code does not rely on them!
33
<% if (options.packages.addon.hasGlint) { %>
44
import '@glint/environment-ember-loose';
5-
// import '@glint/environment-ember-template-imports';
65

76
declare module '@glint/environment-ember-loose/registry' {
87
// Remove this once entries have been added! 👇

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
moveProjectRootFiles,
77
moveTestAppFiles,
88
updateAddonPackageJson,
9-
updateAddonTsConfigJson,
109
updateTestAppPackageJson,
1110
updateTestAppTsConfigJson,
1211
} from './steps/index.js';
@@ -34,7 +33,6 @@ export function runCodemod(codemodOptions: CodemodOptions): void {
3433

3534
// Fine-tune individual files
3635
updateAddonPackageJson(context, options);
37-
updateAddonTsConfigJson(options);
3836
updateTestAppPackageJson(options);
3937
updateTestAppTsConfigJson(options);
4038
}

0 commit comments

Comments
 (0)