Skip to content

Commit b5f68d2

Browse files
committed
feat: enable comment support by default
1 parent 034b4e5 commit b5f68d2

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/native/cli.d

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@ import argparse;
77
88
# Minify the specified files
99
minijson ./dist/**/*.json ./build/a.json
10+
minijson file1_with_comment.json file2_with_comment.json
1011
11-
# Minify the specified files (supports comments)
12-
minijson --comment file1_with_comment.json file2_with_comment.json
12+
# Minify the specified files and disable comment support for faster minification
13+
minijson --comment=false file1_no_comment.json file2_no_comment.json
1314
1415
# Minify the specified json string
1516
minijson --str '{"some_json": "string_here"}'
16-
17-
# Minify the specified json string (supports comments)
18-
minijson --comment --str '{"some_json": "string_here"} //comment'
17+
minijson --str '{"some_json": "string_here"} //comment'
1918
2019
More information at https://github.com/aminya/minijson
2120
`))
2221
struct Options
2322
{
24-
bool comment = false;
23+
bool comment = true;
2524
string[] str;
2625
// (Deprecated) A list of files to minify (for backwards compatiblitity with getopt)
2726
string[] file;

src/native/lib.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const tokenizerNoComment = ctRegex!(`[\n\r"[]]`, "g");
1212
1313
Params:
1414
jsonString = the json string you want to minify
15-
hasComment = a boolean to support comments in json. Default: `false`.
15+
hasComment = a boolean to support comments in json. Default: `true`.
1616
1717
Return:
1818
the minified json string
1919
*/
20-
string minifyString(in string jsonString, in bool hasComment = false) @trusted
20+
string minifyString(in string jsonString, in bool hasComment = true) @trusted
2121
{
2222
return hasComment ? minifyStringWithComments(jsonString) : minifyStringNoComments(jsonString);
2323
}
@@ -227,7 +227,7 @@ private bool hasNoSpace(const ref string str) @trusted
227227
Return:
228228
the minified json strings
229229
*/
230-
string[] minifyStrings(in string[] jsonStrings, in bool hasComment = false) @trusted
230+
string[] minifyStrings(in string[] jsonStrings, in bool hasComment = true) @trusted
231231
{
232232
import std.algorithm : map;
233233
import std.array : array;
@@ -242,7 +242,7 @@ string[] minifyStrings(in string[] jsonStrings, in bool hasComment = false) @tru
242242
paths = the paths to the files. It could be glob patterns.
243243
hasComment = a boolean to support comments in json. Default: `false`.
244244
*/
245-
void minifyFiles(in string[] paths, in bool hasComment = false) @trusted
245+
void minifyFiles(in string[] paths, in bool hasComment = true) @trusted
246246
{
247247
import std.parallelism : parallel;
248248
import std.algorithm;

src/native/libc.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import minijson.lib : minifyString;
77
88
Params:
99
jsonString = the json string you want to minify
10-
hasComment = a boolean to support comments in json. Default: `false`.
10+
hasComment = a boolean to support comments in json. Default: `true`.
1111
1212
Return:
1313
the minified json string
1414
*/
15-
extern (C) auto c_minifyString(char* jsonCString, bool hasComment = false)
15+
extern (C) auto c_minifyString(char* jsonCString, bool hasComment = true)
1616
{
1717
import std : fromStringz, toStringz;
1818

src/node/lib.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@ import { join } from "path"
77
* Minify all the given JSON files in place. It minifies the files in parallel.
88
*
99
* @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`.
1111
* @returns {Promise<void>} Returns a void promise that resolves when all the files are minified
1212
* @throws {Promise<string | Error>} The promise is rejected with the reason for failure
1313
*/
14-
export async function minifyFiles(files: string[], hasComment = false): Promise<void> {
14+
export async function minifyFiles(files: readonly string[], hasComment = true): Promise<void> {
1515
try {
1616
const filesNum = files.length
1717
if (filesNum === 0) {
1818
return Promise.resolve()
1919
}
2020

21-
const minijsonArgs = hasComment ? ["--comment", ...files] : files
22-
23-
await spawnMinijson(minijsonArgs)
21+
await spawnMinijson([...files, hasComment ? "--comment=true" : "--comment=false"])
2422
} catch (e) {
2523
console.error(e, "Falling back to jsonminify")
2624
await minifyFilesFallback(files)
@@ -48,7 +46,7 @@ export function spawnMinijson(args: string[]): Promise<string> {
4846
})
4947
}
5048

51-
async function minifyFilesFallback(files: string[]) {
49+
async function minifyFilesFallback(files: readonly string[]) {
5250
const jsonminify = require("jsonminify")
5351
await Promise.all(
5452
files.map(async (file) => {
@@ -64,11 +62,11 @@ async function minifyFilesFallback(files: string[]) {
6462
* Minify the given JSON string
6563
*
6664
* @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`.
6866
* @returns {Promise<string>} The minified json string
6967
* @throws {Promise<string | Error>} The promise is rejected with the reason for failure
7068
*/
71-
export async function minifyString(jsonString: string, hasComment = false): Promise<string> {
69+
export async function minifyString(jsonString: string, hasComment = true): Promise<string> {
7270
const args = ["--str", jsonString]
7371
if (hasComment) {
7472
args.push("--comment")

0 commit comments

Comments
 (0)