ember-codemod-v1-to-v2 1.0.1 → 1.1.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/dist/src/blueprints/ember-addon/__addonLocation__/babel.config.json +19 -11
- package/dist/src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs +16 -3
- package/dist/src/steps/analyze-addon.js +0 -39
- package/dist/src/steps/update-addon-package-json/update-dependencies.js +6 -3
- package/dist/src/steps/update-addon-package-json/update-dev-dependencies.js +5 -1
- package/dist/src/steps/update-addon-package-json/update-scripts.js +3 -0
- package/dist/src/steps/update-addon-tsconfig-json.js +13 -16
- package/dist/src/utils/blueprints/get-version.js +13 -9
- package/package.json +13 -13
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
"presets": [["@babel/preset-typescript"]],
|
|
1
|
+
{
|
|
3
2
|
"plugins": [
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
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([
|
|
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
|
-
|
|
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/
|
|
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
|
|
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(
|
|
8
|
-
compilerOptions.
|
|
9
|
-
compilerOptions.
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
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
|
-
|
|
37
|
-
|
|
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.
|
|
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/
|
|
7
|
-
['@babel/
|
|
8
|
-
['@
|
|
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.
|
|
11
|
-
['@rollup/plugin-babel', '6.0.
|
|
12
|
-
['
|
|
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.
|
|
17
|
+
['ember-cli-babel', '8.1.0'],
|
|
15
18
|
['ember-cli-htmlbars', '6.3.0'],
|
|
16
|
-
['rollup', '3.
|
|
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.
|
|
3
|
+
"version": "1.1.1",
|
|
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": "^1.1.0",
|
|
31
31
|
"@codemod-utils/files": "^1.1.0",
|
|
32
|
-
"@codemod-utils/json": "^1.1.
|
|
32
|
+
"@codemod-utils/json": "^1.1.3",
|
|
33
33
|
"strip-json-comments": "^5.0.1",
|
|
34
34
|
"yargs": "^17.7.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@babel/core": "^7.23.
|
|
37
|
+
"@babel/core": "^7.23.6",
|
|
38
38
|
"@codemod-utils/tests": "^1.1.1",
|
|
39
39
|
"@sondr3/minitest": "^0.1.2",
|
|
40
40
|
"@tsconfig/node18": "^18.2.2",
|
|
41
41
|
"@tsconfig/strictest": "^2.0.2",
|
|
42
|
-
"@types/node": "^18.
|
|
43
|
-
"@types/yargs": "^17.0.
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
45
|
-
"@typescript-eslint/parser": "^6.
|
|
42
|
+
"@types/node": "^18.19.3",
|
|
43
|
+
"@types/yargs": "^17.0.32",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^6.15.0",
|
|
45
|
+
"@typescript-eslint/parser": "^6.15.0",
|
|
46
46
|
"concurrently": "^8.2.2",
|
|
47
|
-
"eslint": "^8.
|
|
48
|
-
"eslint-config-prettier": "^9.
|
|
47
|
+
"eslint": "^8.56.0",
|
|
48
|
+
"eslint-config-prettier": "^9.1.0",
|
|
49
49
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
50
|
-
"eslint-plugin-import": "^2.29.
|
|
51
|
-
"eslint-plugin-n": "^16.
|
|
50
|
+
"eslint-plugin-import": "^2.29.1",
|
|
51
|
+
"eslint-plugin-n": "^16.4.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",
|
|
55
55
|
"lerna-changelog": "^2.2.0",
|
|
56
|
-
"prettier": "^3.
|
|
57
|
-
"typescript": "^5.
|
|
56
|
+
"prettier": "^3.1.1",
|
|
57
|
+
"typescript": "^5.3.3"
|
|
58
58
|
},
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": "18.* || >= 20"
|