ember-codemod-v1-to-v2 1.0.1 → 1.1.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.
@@ -1,15 +1,23 @@
1
- <% if (options.packages.addon.hasTypeScript) { %>{
2
- "presets": [["@babel/preset-typescript"]],
1
+ {
3
2
  "plugins": [
4
- "@embroider/addon-dev/template-colocation-plugin",
5
- ["@babel/plugin-transform-typescript", { "allowDeclareFields": true }],
3
+ <% if (options.packages.addon.hasTypeScript) { %> [
4
+ "@babel/plugin-transform-typescript",
5
+ {
6
+ "allExtensions": true,
7
+ "allowDeclareFields": true,
8
+ "onlyRemoveTypeImports": true
9
+ }
10
+ ],
11
+ <% } %> "@embroider/addon-dev/template-colocation-plugin",
12
+ "@babel/plugin-transform-class-static-block",
13
+ [
14
+ "babel-plugin-ember-template-compilation",
15
+ {
16
+ "targetFormat": "hbs",
17
+ "transforms": []
18
+ }
19
+ ],
6
20
  ["@babel/plugin-proposal-decorators", { "version": "legacy" }],
7
21
  "@babel/plugin-transform-class-properties"
8
22
  ]
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
- }<% } %>
23
+ }
@@ -15,12 +15,22 @@ export default {
15
15
  plugins: [
16
16
  // These are the modules that users should be able to import from your
17
17
  // addon. Anything not listed here may get optimized away.
18
- addon.publicEntrypoints([<%= context.addon.publicEntrypoints.map((filePath) => `'${filePath}'`).join(', ') %>]),
18
+ // By default all your JavaScript modules (**/*.js) will be importable.
19
+ // But you are encouraged to tweak this to only cover the modules that make
20
+ // up your addon's public API. Also make sure your package.json#exports
21
+ // is aligned to the config here.
22
+ // See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon
23
+ addon.publicEntrypoints(['**/*.js', 'index.js'<% if (options.packages.addon.hasGlint) {%>, 'template-registry.js'<% } %>]),
19
24
 
20
25
  // These are the modules that should get reexported into the traditional
21
26
  // "app" tree. Things in here should also be in publicEntrypoints above, but
22
27
  // not everything in publicEntrypoints necessarily needs to go here.
23
- addon.appReexports([<%= context.addon.appReexports.map((filePath) => `'${filePath}'`).join(', ') %>]),
28
+ addon.appReexports([
29
+ 'components/**/*.js',
30
+ 'helpers/**/*.js',
31
+ 'modifiers/**/*.js',
32
+ 'services/**/*.js',
33
+ ]),
24
34
 
25
35
  // Follow the V2 Addon rules about dependencies. Your code can import from
26
36
  // `dependencies` and `peerDependencies` as well as standard Ember-provided
@@ -35,12 +45,15 @@ export default {
35
45
  // babel.config.json.
36
46
  babel({
37
47
  babelHelpers: 'bundled',
38
- extensions: ['.js'<% if (options.packages.addon.hasTypeScript) { %>, '.ts'<% } %>],
48
+ extensions: ['.js', '.gjs'<% if (options.packages.addon.hasTypeScript) { %>, '.ts', '.gts'<% } %>],
39
49
  }),
40
50
 
41
51
  // Ensure that standalone .hbs files are properly integrated as Javascript.
42
52
  addon.hbs(),
43
53
 
54
+ // Ensure that .gjs files are properly integrated as Javascript
55
+ addon.gjs(),
56
+
44
57
  // addons are allowed to contain imports of .css files, which we want rollup
45
58
  // to leave alone and keep in the published output.
46
59
  addon.keepAssets(['**/*.css']),
@@ -1,19 +1,5 @@
1
1
  import { findFiles, renamePathByDirectory } from '@codemod-utils/files';
2
2
  import { getVersion } from '../utils/blueprints.js';
3
- function getAppReexports(options) {
4
- const { projectRoot } = options;
5
- const filePaths = findFiles('app/**/*.js', {
6
- projectRoot,
7
- });
8
- return filePaths
9
- .map((filePath) => {
10
- return renamePathByDirectory(filePath, {
11
- from: 'app',
12
- to: '',
13
- });
14
- })
15
- .sort();
16
- }
17
3
  function getProjectRootDevDependencies(options) {
18
4
  return {
19
5
  concurrently: getVersion('concurrently', options),
@@ -33,35 +19,10 @@ function getPublicAssets(options) {
33
19
  })
34
20
  .sort();
35
21
  }
36
- function getPublicEntrypoints(options) {
37
- const { projectRoot } = options;
38
- const filePaths = findFiles('{addon,addon-test-support}/**/*.{js,ts}', {
39
- projectRoot,
40
- });
41
- return filePaths
42
- .map((filePath) => {
43
- return renamePathByDirectory(filePath, {
44
- from: 'addon',
45
- to: '',
46
- });
47
- })
48
- .map((filePath) => {
49
- return renamePathByDirectory(filePath, {
50
- from: 'addon-test-support',
51
- to: 'test-support',
52
- });
53
- })
54
- .map((filePath) => {
55
- return filePath.replace(/(?<!\.d)\.ts$/, '.js');
56
- })
57
- .sort();
58
- }
59
22
  export function analyzeAddon(options) {
60
23
  return {
61
24
  addon: {
62
- appReexports: getAppReexports(options),
63
25
  publicAssets: getPublicAssets(options),
64
- publicEntrypoints: getPublicEntrypoints(options),
65
26
  },
66
27
  projectRoot: {
67
28
  devDependencies: getProjectRootDevDependencies(options),
@@ -2,13 +2,16 @@ import { convertToMap, convertToObject } from '@codemod-utils/json';
2
2
  import { getVersion } from '../../utils/blueprints.js';
3
3
  export function updateDependencies(packageJson, options) {
4
4
  const dependencies = convertToMap(packageJson['dependencies']);
5
- const packagesToDelete = [
5
+ const packagesToDelete = new Set([
6
6
  '@embroider/macros',
7
7
  'ember-auto-import',
8
8
  'ember-cli-babel',
9
9
  'ember-cli-htmlbars',
10
- ];
11
- packagesToDelete.forEach((packageName) => {
10
+ ]);
11
+ if (options.packages.addon.hasTypeScript) {
12
+ packagesToDelete.add('ember-cli-typescript');
13
+ }
14
+ Array.from(packagesToDelete).forEach((packageName) => {
12
15
  dependencies.delete(packageName);
13
16
  });
14
17
  const packagesToInstall = ['@embroider/addon-shim'];
@@ -18,15 +18,19 @@ export function updateDevDependencies(packageJson, options) {
18
18
  '@babel/core',
19
19
  '@babel/plugin-proposal-decorators',
20
20
  '@babel/plugin-transform-class-properties',
21
+ '@babel/plugin-transform-class-static-block',
21
22
  '@babel/runtime',
22
23
  '@embroider/addon-dev',
23
24
  '@rollup/plugin-babel',
25
+ 'babel-plugin-ember-template-compilation',
24
26
  'concurrently',
25
27
  'rollup',
26
28
  'rollup-plugin-copy',
27
29
  ]);
28
30
  if (packages.addon.hasTypeScript) {
29
- packagesToInstall.add('@babel/preset-typescript');
31
+ packagesToInstall.add('@babel/plugin-transform-typescript');
32
+ packagesToInstall.add('@tsconfig/ember');
33
+ packagesToInstall.add('typescript');
30
34
  }
31
35
  Array.from(packagesToInstall).forEach((packageName) => {
32
36
  const version = getVersion(packageName, options);
@@ -9,6 +9,9 @@ export function updateScripts(packageJson, options) {
9
9
  scripts.set('lint:types', packages.addon.hasGlint
10
10
  ? 'glint'
11
11
  : 'tsc --emitDeclarationOnly false --noEmit');
12
+ if (scripts.get('postpack') === 'ember ts:clean') {
13
+ scripts.delete('postpack');
14
+ }
12
15
  scripts.set('prepack', 'rollup --config');
13
16
  scripts.set('start', 'concurrently "npm:start:*" --names "start:"');
14
17
  scripts.set('start:js', 'rollup --config --watch --no-watch.clearScreen');
@@ -2,27 +2,23 @@ import { readFileSync, writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import { convertToMap, convertToObject } from '@codemod-utils/json';
4
4
  import { sanitizeJson } from '../utils/json.js';
5
- function updateCompilerOptions(tsConfigJson, options) {
5
+ function setExtends(tsConfigJson) {
6
+ tsConfigJson['extends'] = '@tsconfig/ember/tsconfig.json';
7
+ }
8
+ function setCompilerOptions(tsConfigJson, options) {
6
9
  const { packages } = options;
7
- const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
8
- compilerOptions.delete('baseUrl');
9
- compilerOptions.delete('paths');
10
- if (packages.addon.hasGlint) {
11
- compilerOptions.set('allowImportingTsExtensions', true);
12
- compilerOptions.set('allowJs', true);
13
- compilerOptions.set('declarationDir', 'declarations');
14
- }
15
- else {
16
- compilerOptions.set('allowImportingTsExtensions', true);
17
- compilerOptions.set('allowJs', true);
10
+ const compilerOptions = convertToMap();
11
+ compilerOptions.set('allowImportingTsExtensions', true);
12
+ compilerOptions.set('allowJs', true);
13
+ compilerOptions.set('declarationDir', 'declarations');
14
+ if (!packages.addon.hasGlint) {
18
15
  compilerOptions.set('declaration', true);
19
- compilerOptions.set('declarationDir', 'declarations');
20
16
  compilerOptions.set('emitDeclarationOnly', true);
21
17
  compilerOptions.set('noEmit', false);
22
18
  }
23
19
  tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
24
20
  }
25
- function updateInclude(tsConfigJson) {
21
+ function setInclude(tsConfigJson) {
26
22
  tsConfigJson['include'] = ['src/**/*', 'unpublished-development-types/**/*'];
27
23
  }
28
24
  export function updateAddonTsConfigJson(options) {
@@ -33,8 +29,9 @@ export function updateAddonTsConfigJson(options) {
33
29
  const oldPath = join(projectRoot, locations.addon, 'tsconfig.json');
34
30
  const oldFile = readFileSync(oldPath, 'utf8');
35
31
  const tsConfigJson = JSON.parse(sanitizeJson(oldFile));
36
- updateCompilerOptions(tsConfigJson, options);
37
- updateInclude(tsConfigJson);
32
+ setExtends(tsConfigJson);
33
+ setCompilerOptions(tsConfigJson, options);
34
+ setInclude(tsConfigJson);
38
35
  const newFile = JSON.stringify(tsConfigJson, null, 2) + '\n';
39
36
  writeFileSync(oldPath, newFile, 'utf8');
40
37
  }
@@ -1,20 +1,24 @@
1
1
  import { decideVersion } from '@codemod-utils/blueprints';
2
2
  const latestVersions = new Map([
3
- ['@babel/core', '7.22.17'],
3
+ ['@babel/core', '7.23.2'],
4
4
  ['@babel/plugin-proposal-decorators', '7.22.15'],
5
5
  ['@babel/plugin-transform-class-properties', '7.22.5'],
6
- ['@babel/preset-typescript', '7.22.15'],
7
- ['@babel/runtime', '7.22.15'],
8
- ['@embroider/addon-dev', '4.1.0'],
6
+ ['@babel/plugin-transform-class-static-block', '7.22.11'],
7
+ ['@babel/plugin-transform-typescript', '7.22.15'],
8
+ ['@babel/runtime', '7.23.2'],
9
+ ['@embroider/addon-dev', '4.1.1'],
9
10
  ['@embroider/addon-shim', '1.8.6'],
10
- ['@embroider/test-setup', '3.0.1'],
11
- ['@rollup/plugin-babel', '6.0.3'],
12
- ['concurrently', '8.2.1'],
11
+ ['@embroider/test-setup', '3.0.2'],
12
+ ['@rollup/plugin-babel', '6.0.4'],
13
+ ['@tsconfig/ember', '3.0.2'],
14
+ ['babel-plugin-ember-template-compilation', '2.2.1'],
15
+ ['concurrently', '8.2.2'],
13
16
  ['ember-auto-import', '2.6.3'],
14
- ['ember-cli-babel', '8.0.0'],
17
+ ['ember-cli-babel', '8.1.0'],
15
18
  ['ember-cli-htmlbars', '6.3.0'],
16
- ['rollup', '3.29.1'],
19
+ ['rollup', '4.3.0'],
17
20
  ['rollup-plugin-copy', '3.5.0'],
21
+ ['typescript', '5.2.2'],
18
22
  ]);
19
23
  export function getVersion(packageName, options) {
20
24
  const { packages } = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-codemod-v1-to-v2",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Codemod to convert Ember addons to v2 addon format",
5
5
  "keywords": [
6
6
  "codemod",
@@ -40,15 +40,15 @@
40
40
  "@tsconfig/node18": "^18.2.2",
41
41
  "@tsconfig/strictest": "^2.0.2",
42
42
  "@types/node": "^18.18.7",
43
- "@types/yargs": "^17.0.29",
44
- "@typescript-eslint/eslint-plugin": "^6.9.1",
45
- "@typescript-eslint/parser": "^6.9.1",
43
+ "@types/yargs": "^17.0.30",
44
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
45
+ "@typescript-eslint/parser": "^6.10.0",
46
46
  "concurrently": "^8.2.2",
47
- "eslint": "^8.52.0",
47
+ "eslint": "^8.53.0",
48
48
  "eslint-config-prettier": "^9.0.0",
49
49
  "eslint-import-resolver-typescript": "^3.6.1",
50
50
  "eslint-plugin-import": "^2.29.0",
51
- "eslint-plugin-n": "^16.2.0",
51
+ "eslint-plugin-n": "^16.3.0",
52
52
  "eslint-plugin-prettier": "^5.0.1",
53
53
  "eslint-plugin-simple-import-sort": "^10.0.0",
54
54
  "eslint-plugin-typescript-sort-keys": "^3.1.0",