sprint-es 0.0.98 ā 0.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.cjs +90 -4
- package/dist/esm/cli.js +91 -4
- package/dist/types/cli.d.ts +4 -1
- package/dist/types/cli.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
4
|
const fs = require("fs");
|
|
4
5
|
const crypto = require("crypto");
|
|
5
6
|
const path = require("path");
|
|
@@ -39,9 +40,93 @@ const logger = {
|
|
|
39
40
|
dim: (...args2) => console.log(pc.dim(args2.join(" "))),
|
|
40
41
|
break: () => console.log("")
|
|
41
42
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const singleComment = Symbol("singleComment");
|
|
44
|
+
const multiComment = Symbol("multiComment");
|
|
45
|
+
const stripWithoutWhitespace = () => "";
|
|
46
|
+
const stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/[^ \t\r\n]/g, " ");
|
|
47
|
+
const isEscaped = (jsonString, quotePosition) => {
|
|
48
|
+
let index = quotePosition - 1;
|
|
49
|
+
let backslashCount = 0;
|
|
50
|
+
while (jsonString[index] === "\\") {
|
|
51
|
+
index -= 1;
|
|
52
|
+
backslashCount += 1;
|
|
53
|
+
}
|
|
54
|
+
return Boolean(backslashCount % 2);
|
|
55
|
+
};
|
|
56
|
+
function stripJsonComments(jsonString, { whitespace = true, trailingCommas = false } = {}) {
|
|
57
|
+
if (typeof jsonString !== "string")
|
|
58
|
+
throw new TypeError(
|
|
59
|
+
`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``
|
|
60
|
+
);
|
|
61
|
+
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
62
|
+
let isInsideString = false;
|
|
63
|
+
let isInsideComment = false;
|
|
64
|
+
let offset = 0;
|
|
65
|
+
let buffer = "";
|
|
66
|
+
let result = "";
|
|
67
|
+
let commaIndex = -1;
|
|
68
|
+
for (let index = 0; index < jsonString.length; index++) {
|
|
69
|
+
const currentCharacter = jsonString[index];
|
|
70
|
+
const nextCharacter = jsonString[index + 1];
|
|
71
|
+
if (!isInsideComment && currentCharacter === '"') {
|
|
72
|
+
const escaped = isEscaped(jsonString, index);
|
|
73
|
+
if (!escaped) {
|
|
74
|
+
isInsideString = !isInsideString;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isInsideString) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (!isInsideComment && currentCharacter + nextCharacter === "//") {
|
|
81
|
+
buffer += jsonString.slice(offset, index);
|
|
82
|
+
offset = index;
|
|
83
|
+
isInsideComment = singleComment;
|
|
84
|
+
index++;
|
|
85
|
+
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
|
|
86
|
+
index++;
|
|
87
|
+
isInsideComment = false;
|
|
88
|
+
buffer += strip(jsonString, offset, index);
|
|
89
|
+
offset = index;
|
|
90
|
+
continue;
|
|
91
|
+
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
92
|
+
isInsideComment = false;
|
|
93
|
+
buffer += strip(jsonString, offset, index);
|
|
94
|
+
offset = index;
|
|
95
|
+
} else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
|
|
96
|
+
buffer += jsonString.slice(offset, index);
|
|
97
|
+
offset = index;
|
|
98
|
+
isInsideComment = multiComment;
|
|
99
|
+
index++;
|
|
100
|
+
continue;
|
|
101
|
+
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
|
|
102
|
+
index++;
|
|
103
|
+
isInsideComment = false;
|
|
104
|
+
buffer += strip(jsonString, offset, index + 1);
|
|
105
|
+
offset = index + 1;
|
|
106
|
+
continue;
|
|
107
|
+
} else if (trailingCommas && !isInsideComment) {
|
|
108
|
+
if (commaIndex !== -1) {
|
|
109
|
+
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
110
|
+
buffer += jsonString.slice(offset, index);
|
|
111
|
+
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
112
|
+
buffer = "";
|
|
113
|
+
offset = index;
|
|
114
|
+
commaIndex = -1;
|
|
115
|
+
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
116
|
+
buffer += jsonString.slice(offset, index);
|
|
117
|
+
offset = index;
|
|
118
|
+
commaIndex = -1;
|
|
119
|
+
}
|
|
120
|
+
} else if (currentCharacter === ",") {
|
|
121
|
+
result += buffer + jsonString.slice(offset, index);
|
|
122
|
+
buffer = "";
|
|
123
|
+
offset = index;
|
|
124
|
+
commaIndex = index;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const remaining = isInsideComment === singleComment ? strip(jsonString, offset, jsonString.length) : jsonString.slice(offset);
|
|
129
|
+
return result + buffer + remaining;
|
|
45
130
|
}
|
|
46
131
|
if (!command) {
|
|
47
132
|
console.log("\nš Sprint CLI\n");
|
|
@@ -313,7 +398,7 @@ switch (command) {
|
|
|
313
398
|
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
314
399
|
if (isTS) {
|
|
315
400
|
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
316
|
-
const tsconfig =
|
|
401
|
+
const tsconfig = JSON.parse(stripJsonComments(fs.readFileSync(tsconfigPath, "utf-8")));
|
|
317
402
|
const originalInclude = tsconfig.include ?? [];
|
|
318
403
|
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
319
404
|
if (patched.length !== originalInclude.length) {
|
|
@@ -360,3 +445,4 @@ switch (command) {
|
|
|
360
445
|
console.log("Use --help for usage information");
|
|
361
446
|
process.exit(1);
|
|
362
447
|
}
|
|
448
|
+
exports.default = stripJsonComments;
|
package/dist/esm/cli.js
CHANGED
|
@@ -21,9 +21,93 @@ const logger = {
|
|
|
21
21
|
dim: (...args2) => console.log(pc.dim(args2.join(" "))),
|
|
22
22
|
break: () => console.log("")
|
|
23
23
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const singleComment = Symbol("singleComment");
|
|
25
|
+
const multiComment = Symbol("multiComment");
|
|
26
|
+
const stripWithoutWhitespace = () => "";
|
|
27
|
+
const stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/[^ \t\r\n]/g, " ");
|
|
28
|
+
const isEscaped = (jsonString, quotePosition) => {
|
|
29
|
+
let index = quotePosition - 1;
|
|
30
|
+
let backslashCount = 0;
|
|
31
|
+
while (jsonString[index] === "\\") {
|
|
32
|
+
index -= 1;
|
|
33
|
+
backslashCount += 1;
|
|
34
|
+
}
|
|
35
|
+
return Boolean(backslashCount % 2);
|
|
36
|
+
};
|
|
37
|
+
function stripJsonComments(jsonString, { whitespace = true, trailingCommas = false } = {}) {
|
|
38
|
+
if (typeof jsonString !== "string")
|
|
39
|
+
throw new TypeError(
|
|
40
|
+
`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``
|
|
41
|
+
);
|
|
42
|
+
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
43
|
+
let isInsideString = false;
|
|
44
|
+
let isInsideComment = false;
|
|
45
|
+
let offset = 0;
|
|
46
|
+
let buffer = "";
|
|
47
|
+
let result = "";
|
|
48
|
+
let commaIndex = -1;
|
|
49
|
+
for (let index = 0; index < jsonString.length; index++) {
|
|
50
|
+
const currentCharacter = jsonString[index];
|
|
51
|
+
const nextCharacter = jsonString[index + 1];
|
|
52
|
+
if (!isInsideComment && currentCharacter === '"') {
|
|
53
|
+
const escaped = isEscaped(jsonString, index);
|
|
54
|
+
if (!escaped) {
|
|
55
|
+
isInsideString = !isInsideString;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (isInsideString) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (!isInsideComment && currentCharacter + nextCharacter === "//") {
|
|
62
|
+
buffer += jsonString.slice(offset, index);
|
|
63
|
+
offset = index;
|
|
64
|
+
isInsideComment = singleComment;
|
|
65
|
+
index++;
|
|
66
|
+
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
|
|
67
|
+
index++;
|
|
68
|
+
isInsideComment = false;
|
|
69
|
+
buffer += strip(jsonString, offset, index);
|
|
70
|
+
offset = index;
|
|
71
|
+
continue;
|
|
72
|
+
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
73
|
+
isInsideComment = false;
|
|
74
|
+
buffer += strip(jsonString, offset, index);
|
|
75
|
+
offset = index;
|
|
76
|
+
} else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
|
|
77
|
+
buffer += jsonString.slice(offset, index);
|
|
78
|
+
offset = index;
|
|
79
|
+
isInsideComment = multiComment;
|
|
80
|
+
index++;
|
|
81
|
+
continue;
|
|
82
|
+
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
|
|
83
|
+
index++;
|
|
84
|
+
isInsideComment = false;
|
|
85
|
+
buffer += strip(jsonString, offset, index + 1);
|
|
86
|
+
offset = index + 1;
|
|
87
|
+
continue;
|
|
88
|
+
} else if (trailingCommas && !isInsideComment) {
|
|
89
|
+
if (commaIndex !== -1) {
|
|
90
|
+
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
91
|
+
buffer += jsonString.slice(offset, index);
|
|
92
|
+
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
93
|
+
buffer = "";
|
|
94
|
+
offset = index;
|
|
95
|
+
commaIndex = -1;
|
|
96
|
+
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
97
|
+
buffer += jsonString.slice(offset, index);
|
|
98
|
+
offset = index;
|
|
99
|
+
commaIndex = -1;
|
|
100
|
+
}
|
|
101
|
+
} else if (currentCharacter === ",") {
|
|
102
|
+
result += buffer + jsonString.slice(offset, index);
|
|
103
|
+
buffer = "";
|
|
104
|
+
offset = index;
|
|
105
|
+
commaIndex = index;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const remaining = isInsideComment === singleComment ? strip(jsonString, offset, jsonString.length) : jsonString.slice(offset);
|
|
110
|
+
return result + buffer + remaining;
|
|
27
111
|
}
|
|
28
112
|
if (!command) {
|
|
29
113
|
console.log("\nš Sprint CLI\n");
|
|
@@ -295,7 +379,7 @@ switch (command) {
|
|
|
295
379
|
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
296
380
|
if (isTS) {
|
|
297
381
|
const tsconfigPath = join(projectRoot, "tsconfig.json");
|
|
298
|
-
const tsconfig =
|
|
382
|
+
const tsconfig = JSON.parse(stripJsonComments(readFileSync(tsconfigPath, "utf-8")));
|
|
299
383
|
const originalInclude = tsconfig.include ?? [];
|
|
300
384
|
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
301
385
|
if (patched.length !== originalInclude.length) {
|
|
@@ -342,3 +426,6 @@ switch (command) {
|
|
|
342
426
|
console.log("Use --help for usage information");
|
|
343
427
|
process.exit(1);
|
|
344
428
|
}
|
|
429
|
+
export {
|
|
430
|
+
stripJsonComments as default
|
|
431
|
+
};
|
package/dist/types/cli.d.ts
CHANGED
package/dist/types/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAqDA,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,EAAE,UAAiB,EAAE,cAAsB,EAAE;;;CAAK,UAoGrD"}
|