ember-codemod-v1-to-v2 0.6.2 → 0.6.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-codemod-v1-to-v2",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Codemod to convert Ember addons to v2 addon format",
5
5
  "keywords": [
6
6
  "codemod",
@@ -27,16 +27,10 @@
27
27
  "bin/",
28
28
  "src/"
29
29
  ],
30
- "scripts": {
31
- "changelog": "lerna-changelog",
32
- "lint": "eslint . --cache",
33
- "lint:fix": "eslint . --fix",
34
- "test": "mt tests --quiet"
35
- },
36
30
  "dependencies": {
37
31
  "@codemod-utils/blueprints": "^0.1.2",
38
32
  "@codemod-utils/files": "^0.3.1",
39
- "@codemod-utils/json": "^0.1.2",
33
+ "@codemod-utils/json": "^0.2.0",
40
34
  "strip-json-comments": "^5.0.0",
41
35
  "yargs": "^17.7.2"
42
36
  },
@@ -66,5 +60,11 @@
66
60
  "enhance: documentation": "Documentation",
67
61
  "user feedback": "User Feedback"
68
62
  }
63
+ },
64
+ "scripts": {
65
+ "changelog": "lerna-changelog",
66
+ "lint": "eslint . --cache",
67
+ "lint:fix": "eslint . --fix",
68
+ "test": "mt tests --quiet"
69
69
  }
70
- }
70
+ }
@@ -1,14 +1,20 @@
1
1
  import { findFiles, unionize } from '@codemod-utils/files';
2
- import { readPackageJson } from '@codemod-utils/json';
2
+ import { readPackageJson, validatePackageJson } from '@codemod-utils/json';
3
3
 
4
4
  function analyzePackageJson(codemodOptions) {
5
+ const { projectRoot } = codemodOptions;
6
+
7
+ const packageJson = readPackageJson({ projectRoot });
8
+
9
+ validatePackageJson(packageJson);
10
+
5
11
  const {
6
12
  dependencies,
7
13
  devDependencies,
8
14
  'ember-addon': emberAddon,
9
15
  name,
10
16
  version,
11
- } = readPackageJson(codemodOptions);
17
+ } = packageJson;
12
18
 
13
19
  const projectDependencies = new Map([
14
20
  ...Object.entries(dependencies ?? {}),
@@ -1,7 +1,11 @@
1
- import { readFileSync, writeFileSync } from 'node:fs';
1
+ import { writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
 
4
- import { convertToMap, convertToObject } from '@codemod-utils/json';
4
+ import {
5
+ convertToMap,
6
+ convertToObject,
7
+ readPackageJson,
8
+ } from '@codemod-utils/json';
5
9
 
6
10
  import { getVersion } from '../../../utils/blueprints.js';
7
11
 
@@ -158,16 +162,17 @@ function updateScripts(packageJson) {
158
162
  export function updateAddonPackageJson(context, options) {
159
163
  const { locations, projectRoot } = options;
160
164
 
161
- const oldPath = join(projectRoot, locations.addon, 'package.json');
162
- const oldFile = readFileSync(oldPath, 'utf8');
163
- const packageJson = JSON.parse(oldFile);
165
+ const packageJson = readPackageJson({
166
+ projectRoot: join(projectRoot, locations.addon),
167
+ });
164
168
 
165
169
  updateDependencies(packageJson, options);
166
170
  updateDevDependencies(packageJson, options);
167
171
  updateScripts(packageJson);
168
172
  updateOtherFields(packageJson, context, options);
169
173
 
170
- const newFile = JSON.stringify(packageJson, null, 2) + '\n';
174
+ const destination = join(projectRoot, locations.addon, 'package.json');
175
+ const file = JSON.stringify(packageJson, null, 2) + '\n';
171
176
 
172
- writeFileSync(oldPath, newFile, 'utf8');
177
+ writeFileSync(destination, file, 'utf8');
173
178
  }
@@ -1,7 +1,11 @@
1
- import { readFileSync, writeFileSync } from 'node:fs';
1
+ import { writeFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
 
4
- import { convertToMap, convertToObject } from '@codemod-utils/json';
4
+ import {
5
+ convertToMap,
6
+ convertToObject,
7
+ readPackageJson,
8
+ } from '@codemod-utils/json';
5
9
 
6
10
  import { getVersion } from '../../../utils/blueprints.js';
7
11
 
@@ -75,16 +79,17 @@ function updateOtherFields(packageJson, options) {
75
79
  export function updateTestAppPackageJson(options) {
76
80
  const { locations, projectRoot } = options;
77
81
 
78
- const oldPath = join(projectRoot, locations.testApp, 'package.json');
79
- const oldFile = readFileSync(oldPath, 'utf8');
80
- const packageJson = JSON.parse(oldFile);
82
+ const packageJson = readPackageJson({
83
+ projectRoot: join(projectRoot, locations.testApp),
84
+ });
81
85
 
82
86
  moveDependenciesToDevDependencies(packageJson, options);
83
87
  updateDependencies(packageJson);
84
88
  updateDevDependencies(packageJson, options);
85
89
  updateOtherFields(packageJson, options);
86
90
 
87
- const newFile = JSON.stringify(packageJson, null, 2) + '\n';
91
+ const destination = join(projectRoot, locations.testApp, 'package.json');
92
+ const file = JSON.stringify(packageJson, null, 2) + '\n';
88
93
 
89
- writeFileSync(oldPath, newFile, 'utf8');
94
+ writeFileSync(destination, file, 'utf8');
90
95
  }