@@ -7,20 +7,18 @@ import { join } from "path"
7
7
* Minify all the given JSON files in place. It minifies the files in parallel.
8
8
*
9
9
* @param files An array of paths to the files
10
- * @param hasComment A boolean to support comments in json. Default `false `.
10
+ * @param hasComment A boolean to support comments in json. Default `true `.
11
11
* @returns {Promise<void> } Returns a void promise that resolves when all the files are minified
12
12
* @throws {Promise<string | Error> } The promise is rejected with the reason for failure
13
13
*/
14
- export async function minifyFiles ( files : string [ ] , hasComment = false ) : Promise < void > {
14
+ export async function minifyFiles ( files : readonly string [ ] , hasComment = true ) : Promise < void > {
15
15
try {
16
16
const filesNum = files . length
17
17
if ( filesNum === 0 ) {
18
18
return Promise . resolve ( )
19
19
}
20
20
21
- const minijsonArgs = hasComment ? [ "--comment" , ...files ] : files
22
-
23
- await spawnMinijson ( minijsonArgs )
21
+ await spawnMinijson ( [ ...files , hasComment ? "--comment=true" : "--comment=false" ] )
24
22
} catch ( e ) {
25
23
console . error ( e , "Falling back to jsonminify" )
26
24
await minifyFilesFallback ( files )
@@ -48,7 +46,7 @@ export function spawnMinijson(args: string[]): Promise<string> {
48
46
} )
49
47
}
50
48
51
- async function minifyFilesFallback ( files : string [ ] ) {
49
+ async function minifyFilesFallback ( files : readonly string [ ] ) {
52
50
const jsonminify = require ( "jsonminify" )
53
51
await Promise . all (
54
52
files . map ( async ( file ) => {
@@ -64,11 +62,11 @@ async function minifyFilesFallback(files: string[]) {
64
62
* Minify the given JSON string
65
63
*
66
64
* @param jsonString The json string you want to minify
67
- * @param hasComment A boolean to support comments in json. Default `false `.
65
+ * @param hasComment A boolean to support comments in json. Default `true `.
68
66
* @returns {Promise<string> } The minified json string
69
67
* @throws {Promise<string | Error> } The promise is rejected with the reason for failure
70
68
*/
71
- export async function minifyString ( jsonString : string , hasComment = false ) : Promise < string > {
69
+ export async function minifyString ( jsonString : string , hasComment = true ) : Promise < string > {
72
70
const args = [ "--str" , jsonString ]
73
71
if ( hasComment ) {
74
72
args . push ( "--comment" )
0 commit comments