ember-codemod-v1-to-v2 0.9.1 → 0.10.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.
Files changed (33) hide show
  1. package/README.md +8 -0
  2. package/dist/src/blueprints/ember-addon/__addonLocation__/.prettierignore +9 -0
  3. package/dist/src/blueprints/ember-addon/__addonLocation__/__gitignore__ +7 -0
  4. package/dist/src/blueprints/ember-addon/__addonLocation__/babel.config.json +12 -6
  5. package/dist/src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs +1 -4
  6. package/dist/src/blueprints/ember-addon/__gitignore__ +5 -10
  7. package/dist/src/blueprints/ember-addon/package.json +3 -3
  8. package/dist/src/index.js +20 -2
  9. package/dist/src/{migration/ember-addon/steps → steps}/analyze-addon.js +1 -1
  10. package/dist/src/{migration/ember-addon/steps → steps}/create-files-from-blueprints.js +1 -1
  11. package/dist/src/{migration/ember-addon/steps → steps}/update-addon-package-json/update-dependencies.js +1 -1
  12. package/dist/src/{migration/ember-addon/steps → steps}/update-addon-package-json/update-dev-dependencies.js +1 -1
  13. package/dist/src/{migration/ember-addon/steps → steps}/update-addon-tsconfig-json.js +3 -1
  14. package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-package-json/move-dev-dependencies-to-dependencies.js +1 -1
  15. package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-tsconfig-json.js +1 -1
  16. package/dist/src/utils/blueprints/get-version.js +7 -7
  17. package/package.json +12 -12
  18. package/dist/src/migration/ember-addon/index.js +0 -22
  19. package/dist/src/migration/index.js +0 -1
  20. /package/dist/src/{migration/ember-addon/steps → steps}/create-options.js +0 -0
  21. /package/dist/src/{migration/ember-addon/steps → steps}/index.js +0 -0
  22. /package/dist/src/{migration/ember-addon/steps → steps}/move-addon-files.js +0 -0
  23. /package/dist/src/{migration/ember-addon/steps → steps}/move-project-root-files.js +0 -0
  24. /package/dist/src/{migration/ember-addon/steps → steps}/move-test-app-files.js +0 -0
  25. /package/dist/src/{migration/ember-addon/steps → steps}/update-addon-package-json/index.js +0 -0
  26. /package/dist/src/{migration/ember-addon/steps → steps}/update-addon-package-json/update-other-fields.js +0 -0
  27. /package/dist/src/{migration/ember-addon/steps → steps}/update-addon-package-json/update-scripts.js +0 -0
  28. /package/dist/src/{migration/ember-addon/steps → steps}/update-addon-package-json.js +0 -0
  29. /package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-package-json/index.js +0 -0
  30. /package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-package-json/update-dependencies.js +0 -0
  31. /package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-package-json/update-dev-dependencies.js +0 -0
  32. /package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-package-json/update-other-fields.js +0 -0
  33. /package/dist/src/{migration/ember-addon/steps → steps}/update-test-app-package-json.js +0 -0
package/README.md CHANGED
@@ -27,6 +27,7 @@ npx ember-codemod-v1-to-v2 <arguments>
27
27
  Step 2. Review the addon package.
28
28
 
29
29
  - [x] Update the configuration files.<sup>2</sup>
30
+ - [x] Relative import paths must specify the file extension `.js` or `.ts`.
30
31
  - [x] Colocate stylesheets (if any). Let each component import the relevant stylesheet in the backing class.
31
32
  - [x] Confirm that you can run all scripts in `package.json`.
32
33
 
@@ -48,6 +49,7 @@ Step 4. Review the workspace root including CI/CD.
48
49
  In most cases, I recommend running the codemod without any arguments (i.e. allow the default values). This is to help different Ember projects converge to one layout.
49
50
 
50
51
  <details>
52
+
51
53
  <summary>Optional: Specify the addon location</summary>
52
54
 
53
55
  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.
@@ -58,7 +60,9 @@ npx ember-codemod-v1-to-v2 --addon-location packages/ui/buttons
58
60
 
59
61
  </details>
60
62
 
63
+
61
64
  <details>
65
+
62
66
  <summary>Optional: Specify the project root</summary>
63
67
 
64
68
  Pass `--root` to run the codemod on a project somewhere else (i.e. not in the current directory).
@@ -69,7 +73,9 @@ npx ember-codemod-v1-to-v2 --root <path/to/your/project>
69
73
 
70
74
  </details>
71
75
 
76
+
72
77
  <details>
78
+
73
79
  <summary>Optional: Specify the test-app location</summary>
74
80
 
75
81
  By default, the test-app package lives in the folder `test-app`. Pass `--test-app-location` to override the logic.
@@ -80,7 +86,9 @@ npx ember-codemod-v1-to-v2 --test-app-location docs-app
80
86
 
81
87
  </details>
82
88
 
89
+
83
90
  <details>
91
+
84
92
  <summary>Optional: Specify the test-app name</summary>
85
93
 
86
94
  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.
@@ -0,0 +1,9 @@
1
+ # unconventional js
2
+ /blueprints/*/files/
3
+
4
+ # compiled output
5
+ /declarations/
6
+ /dist/
7
+
8
+ # misc
9
+ /coverage/
@@ -3,3 +3,10 @@
3
3
  # will also appear in published NPM packages.
4
4
  /LICENSE.md
5
5
  /README.md
6
+
7
+ # compiled output
8
+ /declarations
9
+ /dist
10
+
11
+ # npm/pnpm/yarn pack output
12
+ *.tgz
@@ -1,9 +1,15 @@
1
- {
2
- <% if (options.packages.addon.hasTypeScript) { %> "presets": [["@babel/preset-typescript"]],
3
- <% } %> "plugins": [
4
- "@embroider/addon-dev/template-colocation-plugin",<% if (options.packages.addon.hasTypeScript) { %>
5
- ["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],<% } %>
1
+ <% if (options.packages.addon.hasTypeScript) { %>{
2
+ "presets": [["@babel/preset-typescript"]],
3
+ "plugins": [
4
+ "@embroider/addon-dev/template-colocation-plugin",
5
+ ["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
6
6
  ["@babel/plugin-proposal-decorators", { "version": "legacy" }],
7
7
  "@babel/plugin-transform-class-properties"
8
8
  ]
9
- }
9
+ }<% } else { %>{
10
+ "plugins": [
11
+ "@embroider/addon-dev/template-colocation-plugin",
12
+ ["@babel/plugin-proposal-decorators", { "version": "legacy" }],
13
+ "@babel/plugin-transform-class-properties"
14
+ ]
15
+ }<% } %>
@@ -7,9 +7,6 @@ const addon = new Addon({
7
7
  destDir: 'dist',
8
8
  });
9
9
 
10
- // Add extensions here, such as ts, gjs, etc that you may import
11
- const extensions = ['.js'<% if (options.packages.addon.hasTypeScript) { %>, '.ts'<% } %>];
12
-
13
10
  export default {
14
11
  // This provides defaults that work well alongside `publicEntrypoints` below.
15
12
  // You can augment this if you need to.
@@ -38,7 +35,7 @@ export default {
38
35
  // babel.config.json.
39
36
  babel({
40
37
  babelHelpers: 'bundled',
41
- extensions,
38
+ extensions: ['.js'<% if (options.packages.addon.hasTypeScript) { %>, '.ts'<% } %>],
42
39
  }),
43
40
 
44
41
  // Ensure that standalone .hbs files are properly integrated as Javascript.
@@ -1,15 +1,10 @@
1
- # compiled output
2
- declarations/
3
- dist/
4
-
5
- # npm/pnpm/yarn pack output
6
- *.tgz
1
+ # See https://help.github.com/ignore-files/ for more about ignoring files.
7
2
 
8
3
  # dependencies
9
4
  node_modules/
10
5
 
11
6
  # misc
12
- /.env*
13
- /.pnpm-debug.log
14
- /npm-debug.log*
15
- /yarn-error.log
7
+ .env*
8
+ .pnpm-debug.log
9
+ npm-debug.log*
10
+ yarn-error.log
@@ -1,5 +1,5 @@
1
1
  <% if (options.packageManager.isNpm) { %>{
2
- "name": "<%= options.packages.addon.name %>",
2
+ "name": "workspace-root",
3
3
  "version": "<%= options.packages.addon.version %>",
4
4
  "private": true,
5
5
  "repository": "",
@@ -23,7 +23,7 @@
23
23
  "concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
24
24
  }
25
25
  }<% } else if (options.packageManager.isPnpm) { %>{
26
- "name": "<%= options.packages.addon.name %>",
26
+ "name": "workspace-root",
27
27
  "version": "<%= options.packages.addon.version %>",
28
28
  "private": true,
29
29
  "repository": "",
@@ -43,7 +43,7 @@
43
43
  "concurrently": "<%= context.projectRoot.devDependencies['concurrently'] %>"
44
44
  }
45
45
  }<% } else if (options.packageManager.isYarn) { %>{
46
- "name": "<%= options.packages.addon.name %>",
46
+ "name": "workspace-root",
47
47
  "version": "<%= options.packages.addon.version %>",
48
48
  "private": true,
49
49
  "repository": "",
package/dist/src/index.js CHANGED
@@ -1,4 +1,22 @@
1
- import { migrateEmberAddon } from './migration/index.js';
1
+ import { analyzeAddon, createFilesFromBlueprints, createOptions, moveAddonFiles, moveProjectRootFiles, moveTestAppFiles, updateAddonPackageJson, updateAddonTsConfigJson, updateTestAppPackageJson, updateTestAppTsConfigJson, } from './steps/index.js';
2
2
  export function runCodemod(codemodOptions) {
3
- migrateEmberAddon(codemodOptions);
3
+ const options = createOptions(codemodOptions);
4
+ const { isV1Addon } = options.packages.addon;
5
+ // Guarantee idempotency
6
+ if (!isV1Addon) {
7
+ return;
8
+ }
9
+ // Prepare for migration
10
+ const context = analyzeAddon(options);
11
+ // Preserve code
12
+ moveAddonFiles(options);
13
+ moveTestAppFiles(options);
14
+ moveProjectRootFiles(options);
15
+ // Get the latest code from blueprints
16
+ createFilesFromBlueprints(context, options);
17
+ // Fine-tune individual files
18
+ updateAddonPackageJson(context, options);
19
+ updateAddonTsConfigJson(options);
20
+ updateTestAppPackageJson(options);
21
+ updateTestAppTsConfigJson(options);
4
22
  }
@@ -1,5 +1,5 @@
1
1
  import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
2
- import { getVersion } from '../../../utils/blueprints.js';
2
+ import { getVersion } from '../utils/blueprints.js';
3
3
  function getAppReexports(options) {
4
4
  const { projectRoot } = options;
5
5
  const filePaths = findFiles('app/**/*.js', {
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { processTemplate } from '@codemod-utils/blueprints';
4
4
  import { createFiles, findFiles } from '@codemod-utils/files';
5
- import { blueprintsRoot } from '../../../utils/blueprints.js';
5
+ import { blueprintsRoot } from '../utils/blueprints.js';
6
6
  function getFilesToSkip(options) {
7
7
  const { packageManager, packages } = options;
8
8
  const files = new Set();
@@ -1,5 +1,5 @@
1
1
  import { convertToMap, convertToObject } from '@codemod-utils/json';
2
- import { getVersion } from '../../../../utils/blueprints.js';
2
+ import { getVersion } from '../../utils/blueprints.js';
3
3
  export function updateDependencies(packageJson, options) {
4
4
  const dependencies = convertToMap(packageJson['dependencies']);
5
5
  const packagesToDelete = [
@@ -1,5 +1,5 @@
1
1
  import { convertToMap, convertToObject } from '@codemod-utils/json';
2
- import { getVersion } from '../../../../utils/blueprints.js';
2
+ import { getVersion } from '../../utils/blueprints.js';
3
3
  export function updateDevDependencies(packageJson, options) {
4
4
  const { packages } = options;
5
5
  const devDependencies = convertToMap(packageJson['devDependencies']);
@@ -1,16 +1,18 @@
1
1
  import { readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { convertToMap, convertToObject } from '@codemod-utils/json';
4
- import { sanitizeJson } from '../../../utils/json.js';
4
+ import { sanitizeJson } from '../utils/json.js';
5
5
  function updateCompilerOptions(tsConfigJson, options) {
6
6
  const { packages } = options;
7
7
  const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
8
8
  compilerOptions.delete('baseUrl');
9
9
  compilerOptions.delete('paths');
10
10
  if (packages.addon.hasGlint) {
11
+ compilerOptions.set('allowImportingTsExtensions', true);
11
12
  compilerOptions.set('declarationDir', 'declarations');
12
13
  }
13
14
  else {
15
+ compilerOptions.set('allowImportingTsExtensions', true);
14
16
  compilerOptions.set('declaration', true);
15
17
  compilerOptions.set('declarationDir', 'declarations');
16
18
  compilerOptions.set('emitDeclarationOnly', true);
@@ -1,5 +1,5 @@
1
1
  import { convertToMap, convertToObject } from '@codemod-utils/json';
2
- import { getVersion } from '../../../../utils/blueprints.js';
2
+ import { getVersion } from '../../utils/blueprints.js';
3
3
  export function moveDependenciesToDevDependencies(packageJson, options) {
4
4
  const { packages } = options;
5
5
  const dependencies = convertToMap(packageJson['dependencies']);
@@ -1,7 +1,7 @@
1
1
  import { readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { convertToMap, convertToObject } from '@codemod-utils/json';
4
- import { sanitizeJson } from '../../../utils/json.js';
4
+ import { sanitizeJson } from '../utils/json.js';
5
5
  function updateCompilerOptions(tsConfigJson, options) {
6
6
  const { packages } = options;
7
7
  const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
@@ -1,18 +1,18 @@
1
1
  import { decideVersion } from '@codemod-utils/blueprints';
2
2
  const latestVersions = new Map([
3
- ['@babel/core', '7.22.6'],
4
- ['@babel/plugin-proposal-decorators', '7.22.6'],
3
+ ['@babel/core', '7.22.10'],
4
+ ['@babel/plugin-proposal-decorators', '7.22.10'],
5
5
  ['@babel/plugin-transform-class-properties', '7.22.5'],
6
6
  ['@babel/preset-typescript', '7.22.5'],
7
- ['@babel/runtime', '7.22.6'],
8
- ['@embroider/addon-dev', '3.1.1'],
9
- ['@embroider/addon-shim', '1.8.5'],
7
+ ['@babel/runtime', '7.22.10'],
8
+ ['@embroider/addon-dev', '4.1.0'],
9
+ ['@embroider/addon-shim', '1.8.6'],
10
10
  ['@rollup/plugin-babel', '6.0.3'],
11
11
  ['concurrently', '8.2.0'],
12
12
  ['ember-auto-import', '2.6.3'],
13
13
  ['ember-cli-babel', '7.26.11'],
14
- ['ember-cli-htmlbars', '6.2.0'],
15
- ['rollup', '3.26.0'],
14
+ ['ember-cli-htmlbars', '6.3.0'],
15
+ ['rollup', '3.28.0'],
16
16
  ['rollup-plugin-copy', '3.4.0'],
17
17
  ]);
18
18
  export function getVersion(packageName, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-codemod-v1-to-v2",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Codemod to convert Ember addons to v2 addon format",
5
5
  "keywords": [
6
6
  "codemod",
@@ -29,32 +29,32 @@
29
29
  "dependencies": {
30
30
  "@codemod-utils/blueprints": "^0.2.1",
31
31
  "@codemod-utils/files": "^0.5.2",
32
- "@codemod-utils/json": "^0.3.4",
32
+ "@codemod-utils/json": "^0.4.1",
33
33
  "strip-json-comments": "^5.0.1",
34
34
  "yargs": "^17.7.2"
35
35
  },
36
36
  "devDependencies": {
37
- "@babel/core": "^7.22.9",
38
- "@codemod-utils/tests": "^0.2.5",
37
+ "@babel/core": "^7.22.10",
38
+ "@codemod-utils/tests": "^0.3.0",
39
39
  "@sondr3/minitest": "^0.1.1",
40
40
  "@tsconfig/esm": "^1.0.4",
41
41
  "@tsconfig/node16": "^16.1.0",
42
42
  "@tsconfig/strictest": "^2.0.1",
43
- "@types/node": "^16.11.7",
43
+ "@types/node": "^16.18.40",
44
44
  "@types/yargs": "^17.0.24",
45
- "@typescript-eslint/eslint-plugin": "^6.0.0",
46
- "@typescript-eslint/parser": "^6.0.0",
45
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
46
+ "@typescript-eslint/parser": "^6.3.0",
47
47
  "concurrently": "^8.2.0",
48
- "eslint": "^8.45.0",
49
- "eslint-config-prettier": "^8.8.0",
50
- "eslint-import-resolver-typescript": "^3.5.5",
51
- "eslint-plugin-import": "^2.27.5",
48
+ "eslint": "^8.47.0",
49
+ "eslint-config-prettier": "^9.0.0",
50
+ "eslint-import-resolver-typescript": "^3.6.0",
51
+ "eslint-plugin-import": "^2.28.0",
52
52
  "eslint-plugin-n": "^16.0.1",
53
53
  "eslint-plugin-prettier": "^5.0.0",
54
54
  "eslint-plugin-simple-import-sort": "^10.0.0",
55
55
  "eslint-plugin-typescript-sort-keys": "^2.3.0",
56
56
  "lerna-changelog": "^2.2.0",
57
- "prettier": "^3.0.0",
57
+ "prettier": "^3.0.1",
58
58
  "typescript": "^5.1.6"
59
59
  },
60
60
  "engines": {
@@ -1,22 +0,0 @@
1
- import { analyzeAddon, createFilesFromBlueprints, createOptions, moveAddonFiles, moveProjectRootFiles, moveTestAppFiles, updateAddonPackageJson, updateAddonTsConfigJson, updateTestAppPackageJson, updateTestAppTsConfigJson, } from './steps/index.js';
2
- export function migrateEmberAddon(codemodOptions) {
3
- const options = createOptions(codemodOptions);
4
- const { isV1Addon } = options.packages.addon;
5
- // Guarantee idempotency
6
- if (!isV1Addon) {
7
- return;
8
- }
9
- // Prepare for migration
10
- const context = analyzeAddon(options);
11
- // Preserve code
12
- moveAddonFiles(options);
13
- moveTestAppFiles(options);
14
- moveProjectRootFiles(options);
15
- // Get the latest code from blueprints
16
- createFilesFromBlueprints(context, options);
17
- // Fine-tune individual files
18
- updateAddonPackageJson(context, options);
19
- updateAddonTsConfigJson(options);
20
- updateTestAppPackageJson(options);
21
- updateTestAppTsConfigJson(options);
22
- }
@@ -1 +0,0 @@
1
- export * from './ember-addon/index.js';