File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed
docs/lib/content/commands Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,13 @@ Returned values are always in **json** format.
135
135
npm pkg delete scripts.build
136
136
```
137
137
138
+ * `npm pkg fix`
139
+
140
+ Auto corrects common errors in your `package.json`. npm already
141
+ does this during `publish`, which leads to subtle (mostly harmless)
142
+ differences between the contents of your `package.json` file and the
143
+ manifest that npm uses during installation.
144
+
138
145
### Workspaces support
139
146
140
147
You can set/get/delete items across your configured workspaces by using the
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ class Pkg extends BaseCommand {
11
11
'delete <key> [<key> ...]' ,
12
12
'set [<array>[<index>].<key>=<value> ...]' ,
13
13
'set [<array>[].<key>=<value> ...]' ,
14
+ 'fix' ,
14
15
]
15
16
16
17
static params = [
@@ -45,6 +46,8 @@ class Pkg extends BaseCommand {
45
46
return this . set ( _args )
46
47
case 'delete' :
47
48
return this . delete ( _args )
49
+ case 'fix' :
50
+ return this . fix ( _args )
48
51
default :
49
52
throw this . usageError ( )
50
53
}
@@ -136,6 +139,11 @@ class Pkg extends BaseCommand {
136
139
pkgJson . update ( q . toJSON ( ) )
137
140
await pkgJson . save ( )
138
141
}
142
+
143
+ async fix ( ) {
144
+ const pkgJson = await PackageJson . fix ( this . prefix )
145
+ await pkgJson . save ( )
146
+ }
139
147
}
140
148
141
149
module . exports = Pkg
Original file line number Diff line number Diff line change @@ -3660,6 +3660,7 @@ npm pkg get [<key> [<key> ...]]
3660
3660
npm pkg delete <key> [<key> ...]
3661
3661
npm pkg set [<array>[<index>].<key>=<value> ...]
3662
3662
npm pkg set [<array>[].<key>=<value> ...]
3663
+ npm pkg fix
3663
3664
3664
3665
Options:
3665
3666
[-f|--force] [--json]
@@ -3674,6 +3675,7 @@ npm pkg get [<key> [<key> ...]]
3674
3675
npm pkg delete <key> [<key> ...]
3675
3676
npm pkg set [<array>[<index>].<key>=<value> ...]
3676
3677
npm pkg set [<array>[].<key>=<value> ...]
3678
+ npm pkg fix
3677
3679
\`\`\`
3678
3680
3679
3681
#### \`force\`
Original file line number Diff line number Diff line change @@ -617,3 +617,21 @@ t.test('workspaces', async t => {
617
617
'should delete version field from workspace b'
618
618
)
619
619
} )
620
+
621
+ t . test ( 'fix' , async t => {
622
+ const { pkg, readPackageJson } = await mockNpm ( t , {
623
+ prefixDir : {
624
+ 'package.json' : JSON . stringify ( {
625
+ name : 'foo ' ,
626
+ version : 'v1.1.1' ,
627
+ } ) ,
628
+ } ,
629
+ } )
630
+
631
+ await pkg ( 'fix' )
632
+ t . strictSame (
633
+ readPackageJson ( ) ,
634
+ { name : 'foo' , version : '1.1.1' } ,
635
+ 'fixes package.json issues'
636
+ )
637
+ } )
You can’t perform that action at this time.
0 commit comments