Skip to content

Commit 6c1b806

Browse files
author
Adolph-WSY
authored
chore: handle package.json with fs-extra (#77)
1 parent ed5d9bd commit 6c1b806

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@vue/compiler-core": "^3.0.5",
3434
"@vue/compiler-dom": "^3.0.5",
3535
"debug": "^4.1.1",
36+
"fs-extra": "^10.0.0",
3637
"globby": "^11.0.2",
3738
"jscodeshift": "^0.11.0",
3839
"lru-cache": "^6.0.0",
@@ -47,6 +48,7 @@
4748
"@types/debug": "^4.1.5",
4849
"@types/eslint-scope": "^3.7.0",
4950
"@types/eslint-visitor-keys": "^1.0.0",
51+
"@types/fs-extra": "^9.0.12",
5052
"@types/jest": "^26.0.3",
5153
"@types/lodash": "^4.14.170",
5254
"@types/node": "^12.12.47",
@@ -56,6 +58,7 @@
5658
"eslint": "^7.29.0",
5759
"jest": "^26.1.0",
5860
"npm-run-all": "^4.1.5",
61+
"prettier": "^2.3.2",
5962
"ts-jest": "^26.1.1",
6063
"typescript": "^4.1.3"
6164
},

src/packageTransformation.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import * as fs from 'fs'
21
import * as globby from 'globby'
3-
import * as prettier from 'prettier'
42
import createDebug from 'debug'
3+
import * as fsExtra from 'fs-extra'
54

65
const debug = createDebug('vue-codemod:rule')
76

@@ -60,18 +59,11 @@ export function transform(): boolean {
6059
return false
6160
}
6261

63-
let packageObj: any = JSON.parse(fs.readFileSync(resolvedPaths[0]).toString())
62+
let packageObj: JSON = fsExtra.readJsonSync(resolvedPaths[0])
6463

6564
packageObj = process(packageObj)
6665

67-
let formatted = prettier.format(
68-
JSON.stringify(packageObj),
69-
Object.assign(
70-
{ parser: 'json' },
71-
packageObj?.prettier ? packageObj?.prettier : {}
72-
)
73-
)
74-
fs.writeFileSync(resolvedPaths[0], formatted)
66+
fsExtra.writeJsonSync(resolvedPaths[0], packageObj, { spaces: 2 })
7567
return true
7668
}
7769
/**

0 commit comments

Comments
 (0)