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.
135135 npm pkg delete scripts.build
136136 ```
137137
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+
138145### Workspaces support
139146
140147You 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 {
1111 'delete <key> [<key> ...]' ,
1212 'set [<array>[<index>].<key>=<value> ...]' ,
1313 'set [<array>[].<key>=<value> ...]' ,
14+ 'fix' ,
1415 ]
1516
1617 static params = [
@@ -45,6 +46,8 @@ class Pkg extends BaseCommand {
4546 return this . set ( _args )
4647 case 'delete' :
4748 return this . delete ( _args )
49+ case 'fix' :
50+ return this . fix ( _args )
4851 default :
4952 throw this . usageError ( )
5053 }
@@ -136,6 +139,11 @@ class Pkg extends BaseCommand {
136139 pkgJson . update ( q . toJSON ( ) )
137140 await pkgJson . save ( )
138141 }
142+
143+ async fix ( ) {
144+ const pkgJson = await PackageJson . fix ( this . prefix )
145+ await pkgJson . save ( )
146+ }
139147}
140148
141149module . exports = Pkg
Original file line number Diff line number Diff line change @@ -3660,6 +3660,7 @@ npm pkg get [<key> [<key> ...]]
36603660npm pkg delete <key> [<key> ...]
36613661npm pkg set [<array>[<index>].<key>=<value> ...]
36623662npm pkg set [<array>[].<key>=<value> ...]
3663+ npm pkg fix
36633664
36643665Options:
36653666[-f|--force] [--json]
@@ -3674,6 +3675,7 @@ npm pkg get [<key> [<key> ...]]
36743675npm pkg delete <key> [<key> ...]
36753676npm pkg set [<array>[<index>].<key>=<value> ...]
36763677npm pkg set [<array>[].<key>=<value> ...]
3678+ npm pkg fix
36773679\`\`\`
36783680
36793681#### \`force\`
Original file line number Diff line number Diff line change @@ -617,3 +617,21 @@ t.test('workspaces', async t => {
617617 'should delete version field from workspace b'
618618 )
619619} )
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