ember-codemod-v1-to-v2 0.7.4 → 0.8.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.
- package/dist/src/blueprints/ember-addon/__addonLocation__/.eslintignore +1 -0
- package/dist/src/blueprints/ember-addon/__addonLocation__/__gitignore__ +5 -0
- package/dist/src/blueprints/ember-addon/__addonLocation__/rollup.config.mjs +14 -10
- package/dist/src/blueprints/ember-addon/__gitignore__ +7 -16
- package/dist/src/migration/ember-addon/steps/analyze-addon.js +1 -1
- package/dist/src/migration/ember-addon/steps/create-files-from-blueprints.js +1 -1
- package/dist/src/migration/ember-addon/steps/create-options.js +4 -5
- package/dist/src/migration/ember-addon/steps/move-project-root-files.js +5 -7
- package/dist/src/migration/ember-addon/steps/move-test-app-files.js +1 -1
- package/dist/src/migration/ember-addon/steps/update-addon-package-json/index.js +4 -0
- package/dist/src/migration/ember-addon/steps/update-addon-package-json/update-dependencies.js +20 -0
- package/dist/src/migration/ember-addon/steps/update-addon-package-json/update-dev-dependencies.js +37 -0
- package/dist/src/migration/ember-addon/steps/update-addon-package-json/update-other-fields.js +85 -0
- package/dist/src/migration/ember-addon/steps/update-addon-package-json/update-scripts.js +25 -0
- package/dist/src/migration/ember-addon/steps/update-addon-package-json.js +3 -124
- package/dist/src/migration/ember-addon/steps/update-addon-tsconfig-json.js +12 -2
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json/index.js +4 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json/move-dev-dependencies-to-dependencies.js +25 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json/update-dependencies.js +10 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json/update-dev-dependencies.js +7 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json/update-other-fields.js +7 -0
- package/dist/src/migration/ember-addon/steps/update-test-app-package-json.js +2 -47
- package/dist/src/utils/blueprints/get-version.js +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
<% if (options.packages.addon.hasTypeScript) { %>import typescript from 'rollup-plugin-ts';<% } else { %>import { babel } from '@rollup/plugin-babel';<% } %>
|
|
2
|
-
import copy from 'rollup-plugin-copy';
|
|
3
1
|
import { Addon } from '@embroider/addon-dev/rollup';
|
|
2
|
+
import { babel } from '@rollup/plugin-babel';
|
|
3
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
4
|
+
import copy from 'rollup-plugin-copy';
|
|
4
5
|
|
|
5
6
|
const addon = new Addon({
|
|
6
7
|
srcDir: 'src',
|
|
7
8
|
destDir: 'dist',
|
|
8
9
|
});
|
|
9
10
|
|
|
11
|
+
// Add extensions here, such as ts, gjs, etc that you may import
|
|
12
|
+
const extensions = ['.js'<% if (options.packages.addon.hasTypeScript) { %>, '.ts'<% } %>];
|
|
13
|
+
|
|
10
14
|
export default {
|
|
11
15
|
// This provides defaults that work well alongside `publicEntrypoints` below.
|
|
12
16
|
// You can augment this if you need to.
|
|
@@ -27,13 +31,7 @@ export default {
|
|
|
27
31
|
// package names.
|
|
28
32
|
addon.dependencies(),
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
typescript({
|
|
32
|
-
transpiler: 'babel',
|
|
33
|
-
browserslist: false,
|
|
34
|
-
transpileOnly: false,
|
|
35
|
-
}),
|
|
36
|
-
<% } else { %> // This babel config should *not* apply presets or compile away ES modules.
|
|
34
|
+
// This babel config should *not* apply presets or compile away ES modules.
|
|
37
35
|
// It exists only to provide development niceties for you, like automatic
|
|
38
36
|
// template colocation.
|
|
39
37
|
//
|
|
@@ -41,8 +39,14 @@ export default {
|
|
|
41
39
|
// babel.config.json.
|
|
42
40
|
babel({
|
|
43
41
|
babelHelpers: 'bundled',
|
|
42
|
+
extensions,
|
|
44
43
|
}),
|
|
45
|
-
|
|
44
|
+
|
|
45
|
+
// Allows rollup to resolve imports of files with the specified extensions
|
|
46
|
+
nodeResolve({
|
|
47
|
+
extensions,
|
|
48
|
+
}),
|
|
49
|
+
|
|
46
50
|
// Ensure that standalone .hbs files are properly integrated as Javascript.
|
|
47
51
|
addon.hbs(),
|
|
48
52
|
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
# compiled output
|
|
2
|
-
/
|
|
2
|
+
declarations/
|
|
3
|
+
dist/
|
|
4
|
+
|
|
5
|
+
# npm/pnpm/yarn pack output
|
|
6
|
+
*.tgz
|
|
3
7
|
|
|
4
8
|
# dependencies
|
|
5
|
-
|
|
9
|
+
node_modules/
|
|
6
10
|
|
|
7
11
|
# misc
|
|
8
12
|
/.env*
|
|
9
|
-
/.
|
|
10
|
-
/.eslintcache
|
|
11
|
-
/coverage/
|
|
13
|
+
/.pnpm-debug.log
|
|
12
14
|
/npm-debug.log*
|
|
13
|
-
/testem.log
|
|
14
15
|
/yarn-error.log
|
|
15
|
-
|
|
16
|
-
# ember-try
|
|
17
|
-
/.node_modules.ember-try/
|
|
18
|
-
/npm-shrinkwrap.json.ember-try
|
|
19
|
-
/package.json.ember-try
|
|
20
|
-
/package-lock.json.ember-try
|
|
21
|
-
/yarn.lock.ember-try
|
|
22
|
-
|
|
23
|
-
# broccoli-debug
|
|
24
|
-
/DEBUG/
|
|
@@ -13,7 +13,7 @@ function getFilesToSkip(options) {
|
|
|
13
13
|
if (!packageManager.isPnpm) {
|
|
14
14
|
files.add('pnpm-workspace.yaml');
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return Array.from(files);
|
|
17
17
|
}
|
|
18
18
|
function resolveBlueprintFilePath(blueprintFilePath, options) {
|
|
19
19
|
const { locations } = options;
|
|
@@ -14,8 +14,8 @@ function analyzePackageJson(codemodOptions) {
|
|
|
14
14
|
hasGlint: projectDependencies.has('@glint/core'),
|
|
15
15
|
hasTypeScript: projectDependencies.has('typescript'),
|
|
16
16
|
isV1Addon: Boolean(emberAddon),
|
|
17
|
-
name,
|
|
18
|
-
version,
|
|
17
|
+
name: name,
|
|
18
|
+
version: version,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
function analyzePackageManager(codemodOptions) {
|
|
@@ -25,7 +25,7 @@ function analyzePackageManager(codemodOptions) {
|
|
|
25
25
|
['pnpm-lock.yaml', 'pnpm'],
|
|
26
26
|
['yarn.lock', 'yarn'],
|
|
27
27
|
]);
|
|
28
|
-
const lockFiles =
|
|
28
|
+
const lockFiles = Array.from(mapping.keys());
|
|
29
29
|
const filePaths = findFiles(unionize(lockFiles), {
|
|
30
30
|
projectRoot,
|
|
31
31
|
});
|
|
@@ -49,8 +49,7 @@ function deriveAddonLocation(addonPackage) {
|
|
|
49
49
|
if (!hasScope) {
|
|
50
50
|
return addonPackage.name;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
const [_scope, packageName] = addonPackage.name.split('/');
|
|
52
|
+
const packageName = addonPackage.name.split('/')[1];
|
|
54
53
|
return packageName;
|
|
55
54
|
}
|
|
56
55
|
export function createOptions(codemodOptions) {
|
|
@@ -12,8 +12,8 @@ function copyToAddon(options) {
|
|
|
12
12
|
copyFiles(filePathMap, options);
|
|
13
13
|
}
|
|
14
14
|
function moveToAddonAndTestApp(options) {
|
|
15
|
-
const { locations,
|
|
16
|
-
const files =
|
|
15
|
+
const { locations, projectRoot } = options;
|
|
16
|
+
const files = [
|
|
17
17
|
'.eslintignore',
|
|
18
18
|
'.eslintrc.cjs',
|
|
19
19
|
'.eslintrc.js',
|
|
@@ -27,11 +27,9 @@ function moveToAddonAndTestApp(options) {
|
|
|
27
27
|
'.template-lintrc.cjs',
|
|
28
28
|
'.template-lintrc.js',
|
|
29
29
|
'package.json',
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
const filePaths = findFiles(unionize([...files]), {
|
|
30
|
+
'tsconfig.json',
|
|
31
|
+
];
|
|
32
|
+
const filePaths = findFiles(unionize(files), {
|
|
35
33
|
projectRoot,
|
|
36
34
|
});
|
|
37
35
|
let filePathMap = mapFilePaths(filePaths, {
|
|
@@ -54,7 +54,7 @@ function renameDummy(options) {
|
|
|
54
54
|
filePaths.forEach((filePath) => {
|
|
55
55
|
const oldPath = join(projectRoot, filePath);
|
|
56
56
|
const oldFile = readFileSync(oldPath, 'utf8');
|
|
57
|
-
const newFile = oldFile.replace(
|
|
57
|
+
const newFile = oldFile.replace(/dummy/g, packages.testApp.name);
|
|
58
58
|
writeFileSync(oldPath, newFile, 'utf8');
|
|
59
59
|
});
|
|
60
60
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
+
import { getVersion } from '../../../../utils/blueprints.js';
|
|
3
|
+
export function updateDependencies(packageJson, options) {
|
|
4
|
+
const dependencies = convertToMap(packageJson['dependencies']);
|
|
5
|
+
const packagesToDelete = [
|
|
6
|
+
'@embroider/macros',
|
|
7
|
+
'ember-auto-import',
|
|
8
|
+
'ember-cli-babel',
|
|
9
|
+
'ember-cli-htmlbars',
|
|
10
|
+
];
|
|
11
|
+
packagesToDelete.forEach((packageName) => {
|
|
12
|
+
dependencies.delete(packageName);
|
|
13
|
+
});
|
|
14
|
+
const packagesToInstall = ['@embroider/addon-shim'];
|
|
15
|
+
packagesToInstall.forEach((packageName) => {
|
|
16
|
+
const version = getVersion(packageName, options);
|
|
17
|
+
dependencies.set(packageName, version);
|
|
18
|
+
});
|
|
19
|
+
packageJson['dependencies'] = convertToObject(dependencies);
|
|
20
|
+
}
|
package/dist/src/migration/ember-addon/steps/update-addon-package-json/update-dev-dependencies.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
+
import { getVersion } from '../../../../utils/blueprints.js';
|
|
3
|
+
export function updateDevDependencies(packageJson, options) {
|
|
4
|
+
const { packages } = options;
|
|
5
|
+
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
6
|
+
/*
|
|
7
|
+
For the time being, we'll take the approach of starting over and
|
|
8
|
+
adding back the development dependencies that are required. For
|
|
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
|
|
15
|
+
*/
|
|
16
|
+
devDependencies.clear();
|
|
17
|
+
const packagesToInstall = new Set([
|
|
18
|
+
'@babel/core',
|
|
19
|
+
'@babel/plugin-proposal-class-properties',
|
|
20
|
+
'@babel/plugin-proposal-decorators',
|
|
21
|
+
'@babel/runtime',
|
|
22
|
+
'@embroider/addon-dev',
|
|
23
|
+
'@rollup/plugin-babel',
|
|
24
|
+
'@rollup/plugin-node-resolve',
|
|
25
|
+
'concurrently',
|
|
26
|
+
'rollup',
|
|
27
|
+
'rollup-plugin-copy',
|
|
28
|
+
]);
|
|
29
|
+
if (packages.addon.hasTypeScript) {
|
|
30
|
+
packagesToInstall.add('@babel/preset-typescript');
|
|
31
|
+
}
|
|
32
|
+
Array.from(packagesToInstall).forEach((packageName) => {
|
|
33
|
+
const version = getVersion(packageName, options);
|
|
34
|
+
devDependencies.set(packageName, version);
|
|
35
|
+
});
|
|
36
|
+
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
37
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function updateEmberAddon(packageJson, data) {
|
|
2
|
+
const { hasPublicAssets, publicAssetMapping } = data;
|
|
3
|
+
if (!hasPublicAssets) {
|
|
4
|
+
packageJson['ember-addon'] = {
|
|
5
|
+
'app-js': {},
|
|
6
|
+
main: 'addon-main.cjs',
|
|
7
|
+
type: 'addon',
|
|
8
|
+
version: 2,
|
|
9
|
+
};
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
packageJson['ember-addon'] = {
|
|
13
|
+
'app-js': {},
|
|
14
|
+
main: 'addon-main.cjs',
|
|
15
|
+
'public-assets': publicAssetMapping,
|
|
16
|
+
type: 'addon',
|
|
17
|
+
version: 2,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function updateExports(packageJson, data) {
|
|
21
|
+
const { hasTypeScript } = data;
|
|
22
|
+
if (!hasTypeScript) {
|
|
23
|
+
packageJson['exports'] = {
|
|
24
|
+
'.': './dist/index.js',
|
|
25
|
+
'./*': './dist/*.js',
|
|
26
|
+
'./addon-main.js': './addon-main.cjs',
|
|
27
|
+
};
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
packageJson['exports'] = {
|
|
31
|
+
'.': {
|
|
32
|
+
types: './declarations/index.d.ts',
|
|
33
|
+
default: './dist/index.js',
|
|
34
|
+
},
|
|
35
|
+
'./*': {
|
|
36
|
+
/*
|
|
37
|
+
This object has an order dependency. The `default` key must appear last.
|
|
38
|
+
*/
|
|
39
|
+
types: './declarations/*.d.ts',
|
|
40
|
+
default: './dist/*.js',
|
|
41
|
+
},
|
|
42
|
+
'./addon-main.js': './addon-main.cjs',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function updateFiles(packageJson, data) {
|
|
46
|
+
const { hasPublicAssets, hasTypeScript } = data;
|
|
47
|
+
const files = new Set(['addon-main.cjs', 'dist']);
|
|
48
|
+
if (hasPublicAssets) {
|
|
49
|
+
files.add('public');
|
|
50
|
+
}
|
|
51
|
+
if (hasTypeScript) {
|
|
52
|
+
files.add('declarations');
|
|
53
|
+
}
|
|
54
|
+
packageJson['files'] = Array.from(files).sort();
|
|
55
|
+
}
|
|
56
|
+
function updateTypesVersions(packageJson, data) {
|
|
57
|
+
const { hasTypeScript } = data;
|
|
58
|
+
if (!hasTypeScript) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
packageJson['typesVersions'] = {
|
|
62
|
+
'*': {
|
|
63
|
+
'*': ['declarations/*'],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function updateOtherFields(packageJson, context, options) {
|
|
68
|
+
const { packages } = options;
|
|
69
|
+
const publicAssetMapping = context.addon.publicAssets.reduce((accumulator, filePath) => {
|
|
70
|
+
const from = `./public/${filePath}`;
|
|
71
|
+
const to = `/${packages.addon.name}/${filePath}`;
|
|
72
|
+
accumulator[from] = to;
|
|
73
|
+
return accumulator;
|
|
74
|
+
}, {});
|
|
75
|
+
const hasPublicAssets = Object.keys(publicAssetMapping).length > 0;
|
|
76
|
+
const data = {
|
|
77
|
+
hasPublicAssets,
|
|
78
|
+
hasTypeScript: packages.addon.hasTypeScript,
|
|
79
|
+
publicAssetMapping,
|
|
80
|
+
};
|
|
81
|
+
updateEmberAddon(packageJson, data);
|
|
82
|
+
updateExports(packageJson, data);
|
|
83
|
+
updateFiles(packageJson, data);
|
|
84
|
+
updateTypesVersions(packageJson, data);
|
|
85
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
+
export function updateScripts(packageJson, options) {
|
|
3
|
+
const { packages } = options;
|
|
4
|
+
const scripts = convertToMap(packageJson['scripts']);
|
|
5
|
+
if (packages.addon.hasTypeScript) {
|
|
6
|
+
scripts.set('build', 'concurrently "npm:build:*" --names "build:"');
|
|
7
|
+
scripts.set('build:js', 'rollup --config');
|
|
8
|
+
scripts.set('build:types', packages.addon.hasGlint ? 'glint --declaration' : 'tsc');
|
|
9
|
+
scripts.set('lint:types', packages.addon.hasGlint
|
|
10
|
+
? 'glint'
|
|
11
|
+
: 'tsc --emitDeclarationOnly false --noEmit');
|
|
12
|
+
scripts.set('prepack', 'rollup --config');
|
|
13
|
+
scripts.set('start', 'concurrently "npm:start:*" --names "start:"');
|
|
14
|
+
scripts.set('start:js', 'rollup --config --watch --no-watch.clearScreen');
|
|
15
|
+
scripts.set('start:types', packages.addon.hasGlint ? 'glint --declaration --watch' : 'tsc --watch');
|
|
16
|
+
scripts.set('test', "echo 'A v2 addon does not have tests, run tests in test-app'");
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
scripts.set('build', 'rollup --config');
|
|
20
|
+
scripts.set('prepack', 'rollup --config');
|
|
21
|
+
scripts.set('start', 'rollup --config --watch');
|
|
22
|
+
scripts.set('test', "echo 'A v2 addon does not have tests, run tests in test-app'");
|
|
23
|
+
}
|
|
24
|
+
packageJson['scripts'] = convertToObject(scripts);
|
|
25
|
+
}
|
|
@@ -1,128 +1,7 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function updateDependencies(packageJson, options) {
|
|
6
|
-
const dependencies = convertToMap(packageJson['dependencies']);
|
|
7
|
-
const packagesToDelete = [
|
|
8
|
-
'@embroider/macros',
|
|
9
|
-
'ember-auto-import',
|
|
10
|
-
'ember-cli-babel',
|
|
11
|
-
'ember-cli-htmlbars',
|
|
12
|
-
];
|
|
13
|
-
packagesToDelete.forEach((packageName) => {
|
|
14
|
-
dependencies.delete(packageName);
|
|
15
|
-
});
|
|
16
|
-
const packagesToInstall = ['@embroider/addon-shim'];
|
|
17
|
-
packagesToInstall.sort().forEach((packageName) => {
|
|
18
|
-
const version = getVersion(packageName, options);
|
|
19
|
-
dependencies.set(packageName, version);
|
|
20
|
-
});
|
|
21
|
-
packageJson['dependencies'] = convertToObject(dependencies);
|
|
22
|
-
}
|
|
23
|
-
function updateDevDependencies(packageJson, options) {
|
|
24
|
-
const { packages } = options;
|
|
25
|
-
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
26
|
-
/*
|
|
27
|
-
For the time being, we'll take the approach of starting over and
|
|
28
|
-
adding back the development dependencies that are required. For
|
|
29
|
-
a more conservative approach, we could delete only the following:
|
|
30
|
-
|
|
31
|
-
- @embroider/macros
|
|
32
|
-
- ember-auto-import
|
|
33
|
-
- ember-cli-babel
|
|
34
|
-
- ember-cli-htmlbars
|
|
35
|
-
*/
|
|
36
|
-
devDependencies.clear();
|
|
37
|
-
const packagesToInstall = new Set([
|
|
38
|
-
'@babel/core',
|
|
39
|
-
'@babel/plugin-proposal-class-properties',
|
|
40
|
-
'@babel/plugin-proposal-decorators',
|
|
41
|
-
'@babel/runtime',
|
|
42
|
-
'@embroider/addon-dev',
|
|
43
|
-
'@rollup/plugin-babel',
|
|
44
|
-
'rollup',
|
|
45
|
-
'rollup-plugin-copy',
|
|
46
|
-
]);
|
|
47
|
-
if (packages.addon.hasTypeScript) {
|
|
48
|
-
packagesToInstall.add('@babel/preset-typescript');
|
|
49
|
-
packagesToInstall.add('rollup-plugin-ts');
|
|
50
|
-
packagesToInstall.delete('@rollup/plugin-babel');
|
|
51
|
-
}
|
|
52
|
-
[...packagesToInstall].sort().forEach((packageName) => {
|
|
53
|
-
const version = getVersion(packageName, options);
|
|
54
|
-
devDependencies.set(packageName, version);
|
|
55
|
-
});
|
|
56
|
-
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
57
|
-
}
|
|
58
|
-
function updateOtherFields(packageJson, context, options) {
|
|
59
|
-
const { packages } = options;
|
|
60
|
-
const hasPublicAssets = context.addon.publicAssets.length > 0;
|
|
61
|
-
if (hasPublicAssets) {
|
|
62
|
-
const publicAssetMapping = context.addon.publicAssets.reduce((accumulator, filePath) => {
|
|
63
|
-
const from = `./public/${filePath}`;
|
|
64
|
-
const to = `/${packages.addon.name}/${filePath}`;
|
|
65
|
-
accumulator[from] = to;
|
|
66
|
-
return accumulator;
|
|
67
|
-
}, {});
|
|
68
|
-
packageJson['ember-addon'] = {
|
|
69
|
-
'app-js': {},
|
|
70
|
-
main: 'addon-main.cjs',
|
|
71
|
-
'public-assets': publicAssetMapping,
|
|
72
|
-
type: 'addon',
|
|
73
|
-
version: 2,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
packageJson['ember-addon'] = {
|
|
78
|
-
'app-js': {},
|
|
79
|
-
main: 'addon-main.cjs',
|
|
80
|
-
type: 'addon',
|
|
81
|
-
version: 2,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
if (packages.addon.hasTypeScript) {
|
|
85
|
-
packageJson['exports'] = {
|
|
86
|
-
'.': './dist/index.js',
|
|
87
|
-
'./*': {
|
|
88
|
-
/*
|
|
89
|
-
This object has an order dependency. The `default` key must appear last.
|
|
90
|
-
*/
|
|
91
|
-
types: './dist/*.d.ts',
|
|
92
|
-
default: './dist/*.js',
|
|
93
|
-
},
|
|
94
|
-
'./addon-main.js': './addon-main.cjs',
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
packageJson['exports'] = {
|
|
99
|
-
'.': './dist/index.js',
|
|
100
|
-
'./*': './dist/*.js',
|
|
101
|
-
'./addon-main.js': './addon-main.cjs',
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
if (hasPublicAssets) {
|
|
105
|
-
packageJson['files'] = ['addon-main.cjs', 'dist', 'public'];
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
packageJson['files'] = ['addon-main.cjs', 'dist'];
|
|
109
|
-
}
|
|
110
|
-
if (packages.addon.hasTypeScript) {
|
|
111
|
-
packageJson['typesVersions'] = {
|
|
112
|
-
'*': {
|
|
113
|
-
'*': ['dist/*'],
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function updateScripts(packageJson) {
|
|
119
|
-
const scripts = convertToMap(packageJson['scripts']);
|
|
120
|
-
scripts.set('build', 'rollup --config');
|
|
121
|
-
scripts.set('prepack', 'rollup --config');
|
|
122
|
-
scripts.set('start', 'rollup --config --watch');
|
|
123
|
-
scripts.set('test', "echo 'A v2 addon does not have tests, run tests in test-app'");
|
|
124
|
-
packageJson['scripts'] = convertToObject(scripts);
|
|
125
|
-
}
|
|
3
|
+
import { readPackageJson } from '@codemod-utils/json';
|
|
4
|
+
import { updateDependencies, updateDevDependencies, updateOtherFields, updateScripts, } from './update-addon-package-json/index.js';
|
|
126
5
|
export function updateAddonPackageJson(context, options) {
|
|
127
6
|
const { locations, projectRoot } = options;
|
|
128
7
|
const packageJson = readPackageJson({
|
|
@@ -130,7 +9,7 @@ export function updateAddonPackageJson(context, options) {
|
|
|
130
9
|
});
|
|
131
10
|
updateDependencies(packageJson, options);
|
|
132
11
|
updateDevDependencies(packageJson, options);
|
|
133
|
-
updateScripts(packageJson);
|
|
12
|
+
updateScripts(packageJson, options);
|
|
134
13
|
updateOtherFields(packageJson, context, options);
|
|
135
14
|
const destination = join(projectRoot, locations.addon, 'package.json');
|
|
136
15
|
const file = JSON.stringify(packageJson, null, 2) + '\n';
|
|
@@ -2,10 +2,20 @@ 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) {
|
|
5
|
+
function updateCompilerOptions(tsConfigJson, options) {
|
|
6
|
+
const { packages } = options;
|
|
6
7
|
const compilerOptions = convertToMap(tsConfigJson['compilerOptions']);
|
|
7
8
|
compilerOptions.delete('baseUrl');
|
|
8
9
|
compilerOptions.delete('paths');
|
|
10
|
+
if (packages.addon.hasGlint) {
|
|
11
|
+
compilerOptions.set('declarationDir', 'declarations');
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
compilerOptions.set('declaration', true);
|
|
15
|
+
compilerOptions.set('declarationDir', 'declarations');
|
|
16
|
+
compilerOptions.set('emitDeclarationOnly', true);
|
|
17
|
+
compilerOptions.set('noEmit', false);
|
|
18
|
+
}
|
|
9
19
|
tsConfigJson['compilerOptions'] = convertToObject(compilerOptions);
|
|
10
20
|
}
|
|
11
21
|
function updateInclude(tsConfigJson) {
|
|
@@ -19,7 +29,7 @@ export function updateAddonTsConfigJson(options) {
|
|
|
19
29
|
const oldPath = join(projectRoot, locations.addon, 'tsconfig.json');
|
|
20
30
|
const oldFile = readFileSync(oldPath, 'utf8');
|
|
21
31
|
const tsConfigJson = JSON.parse(sanitizeJson(oldFile));
|
|
22
|
-
updateCompilerOptions(tsConfigJson);
|
|
32
|
+
updateCompilerOptions(tsConfigJson, options);
|
|
23
33
|
updateInclude(tsConfigJson);
|
|
24
34
|
const newFile = JSON.stringify(tsConfigJson, null, 2) + '\n';
|
|
25
35
|
writeFileSync(oldPath, newFile, 'utf8');
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
+
import { getVersion } from '../../../../utils/blueprints.js';
|
|
3
|
+
export function moveDependenciesToDevDependencies(packageJson, options) {
|
|
4
|
+
const { packages } = options;
|
|
5
|
+
const dependencies = convertToMap(packageJson['dependencies']);
|
|
6
|
+
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
7
|
+
const packagesToMove = new Set([
|
|
8
|
+
'ember-auto-import',
|
|
9
|
+
'ember-cli-babel',
|
|
10
|
+
'ember-cli-htmlbars',
|
|
11
|
+
]);
|
|
12
|
+
if (packages.addon.hasTypeScript) {
|
|
13
|
+
packagesToMove.add('ember-cli-typescript');
|
|
14
|
+
}
|
|
15
|
+
Array.from(packagesToMove).forEach((packageName) => {
|
|
16
|
+
if (!dependencies.has(packageName)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const version = getVersion(packageName, options);
|
|
20
|
+
dependencies.delete(packageName);
|
|
21
|
+
devDependencies.set(packageName, version);
|
|
22
|
+
});
|
|
23
|
+
packageJson['dependencies'] = convertToObject(dependencies);
|
|
24
|
+
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
25
|
+
}
|
package/dist/src/migration/ember-addon/steps/update-test-app-package-json/update-dependencies.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
+
export function updateDependencies(packageJson) {
|
|
3
|
+
const dependencies = convertToMap(packageJson['dependencies']);
|
|
4
|
+
/*
|
|
5
|
+
For the time being, we'll take the approach of starting over and
|
|
6
|
+
adding back the dependencies that are required.
|
|
7
|
+
*/
|
|
8
|
+
dependencies.clear();
|
|
9
|
+
packageJson['dependencies'] = convertToObject(dependencies);
|
|
10
|
+
}
|
package/dist/src/migration/ember-addon/steps/update-test-app-package-json/update-dev-dependencies.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { convertToMap, convertToObject } from '@codemod-utils/json';
|
|
2
|
+
export function updateDevDependencies(packageJson, options) {
|
|
3
|
+
const { packages } = options;
|
|
4
|
+
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
5
|
+
devDependencies.set(packages.addon.name, packages.addon.version);
|
|
6
|
+
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
7
|
+
}
|
package/dist/src/migration/ember-addon/steps/update-test-app-package-json/update-other-fields.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function updateOtherFields(packageJson, options) {
|
|
2
|
+
const { packages } = options;
|
|
3
|
+
delete packageJson['ember-addon'];
|
|
4
|
+
packageJson['keywords'] = (packageJson['keywords'] ?? []).filter((keyword) => keyword !== 'ember-addon');
|
|
5
|
+
packageJson['name'] = packages.testApp.name;
|
|
6
|
+
packageJson['private'] = true;
|
|
7
|
+
}
|
|
@@ -1,52 +1,7 @@
|
|
|
1
1
|
import { writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function moveDependenciesToDevDependencies(packageJson, options) {
|
|
6
|
-
const { packages } = options;
|
|
7
|
-
const dependencies = convertToMap(packageJson['dependencies']);
|
|
8
|
-
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
9
|
-
const packagesToMove = new Set([
|
|
10
|
-
'ember-auto-import',
|
|
11
|
-
'ember-cli-babel',
|
|
12
|
-
'ember-cli-htmlbars',
|
|
13
|
-
]);
|
|
14
|
-
if (packages.addon.hasTypeScript) {
|
|
15
|
-
packagesToMove.add('ember-cli-typescript');
|
|
16
|
-
}
|
|
17
|
-
[...packagesToMove]
|
|
18
|
-
.filter((packageName) => dependencies.has(packageName))
|
|
19
|
-
.sort()
|
|
20
|
-
.forEach((packageName) => {
|
|
21
|
-
const version = getVersion(packageName, options);
|
|
22
|
-
devDependencies.set(packageName, version);
|
|
23
|
-
dependencies.delete(packageName);
|
|
24
|
-
});
|
|
25
|
-
packageJson['dependencies'] = convertToObject(dependencies);
|
|
26
|
-
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
27
|
-
}
|
|
28
|
-
function updateDependencies(packageJson) {
|
|
29
|
-
const dependencies = convertToMap(packageJson['dependencies']);
|
|
30
|
-
/*
|
|
31
|
-
For the time being, we'll take the approach of starting over and
|
|
32
|
-
adding back the dependencies that are required.
|
|
33
|
-
*/
|
|
34
|
-
dependencies.clear();
|
|
35
|
-
packageJson['dependencies'] = convertToObject(dependencies);
|
|
36
|
-
}
|
|
37
|
-
function updateDevDependencies(packageJson, options) {
|
|
38
|
-
const { packages } = options;
|
|
39
|
-
const devDependencies = convertToMap(packageJson['devDependencies']);
|
|
40
|
-
devDependencies.set(packages.addon.name, packages.addon.version);
|
|
41
|
-
packageJson['devDependencies'] = convertToObject(devDependencies);
|
|
42
|
-
}
|
|
43
|
-
function updateOtherFields(packageJson, options) {
|
|
44
|
-
const { packages } = options;
|
|
45
|
-
delete packageJson['ember-addon'];
|
|
46
|
-
packageJson['keywords'] = (packageJson['keywords'] ?? []).filter((keyword) => keyword !== 'ember-addon');
|
|
47
|
-
packageJson['name'] = packages.testApp.name;
|
|
48
|
-
packageJson['private'] = true;
|
|
49
|
-
}
|
|
3
|
+
import { readPackageJson } from '@codemod-utils/json';
|
|
4
|
+
import { moveDependenciesToDevDependencies, updateDependencies, updateDevDependencies, updateOtherFields, } from './update-test-app-package-json/index.js';
|
|
50
5
|
export function updateTestAppPackageJson(options) {
|
|
51
6
|
const { locations, projectRoot } = options;
|
|
52
7
|
const packageJson = readPackageJson({
|
|
@@ -8,13 +8,13 @@ const latestVersions = new Map([
|
|
|
8
8
|
['@embroider/addon-dev', '3.1.1'],
|
|
9
9
|
['@embroider/addon-shim', '1.8.5'],
|
|
10
10
|
['@rollup/plugin-babel', '6.0.3'],
|
|
11
|
+
['@rollup/plugin-node-resolve', '15.1.0'],
|
|
11
12
|
['concurrently', '8.2.0'],
|
|
12
13
|
['ember-auto-import', '2.6.3'],
|
|
13
14
|
['ember-cli-babel', '7.26.11'],
|
|
14
15
|
['ember-cli-htmlbars', '6.2.0'],
|
|
15
16
|
['rollup', '3.26.0'],
|
|
16
17
|
['rollup-plugin-copy', '3.4.0'],
|
|
17
|
-
['rollup-plugin-ts', '3.2.0'],
|
|
18
18
|
]);
|
|
19
19
|
export function getVersion(packageName, options) {
|
|
20
20
|
const { packages } = options;
|