@taiga-ui/prettier-config 0.490.0 → 0.492.0
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/package.json
CHANGED
|
@@ -5,7 +5,7 @@ const originalPostcssPrinter = postcss.printers.postcss;
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {unknown} node
|
|
8
|
-
* @returns {node is {type: string; prop: string}}
|
|
8
|
+
* @returns {node is {type: string; prop: string; value: string}}
|
|
9
9
|
*/
|
|
10
10
|
function isCustomPropertyDeclaration(node) {
|
|
11
11
|
return (
|
|
@@ -19,6 +19,44 @@ function isCustomPropertyDeclaration(node) {
|
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Returns true when a Prettier doc contains comment text (`//` or `/*`).
|
|
24
|
+
* Checking the printed doc is more reliable than checking `node.value` because
|
|
25
|
+
* postcss may store inline comments in `node.raws` rather than `node.value`.
|
|
26
|
+
*
|
|
27
|
+
* @param {import('prettier').Doc} doc
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
function docContainsComment(doc) {
|
|
31
|
+
if (typeof doc === 'string') {
|
|
32
|
+
return doc.includes('//') || doc.includes('/*');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (Array.isArray(doc)) {
|
|
36
|
+
return doc.some(docContainsComment);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof doc !== 'object' || doc === null) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (doc.type === 'fill') {
|
|
44
|
+
return doc.parts.some(docContainsComment);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (doc.type === 'if-break') {
|
|
48
|
+
return (
|
|
49
|
+
docContainsComment(doc.breakContents) || docContainsComment(doc.flatContents)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if ('contents' in doc) {
|
|
54
|
+
return docContainsComment(doc.contents);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
22
60
|
/**
|
|
23
61
|
* Converts a Prettier doc to its flat representation so custom properties are
|
|
24
62
|
* not wrapped by printWidth.
|
|
@@ -88,7 +126,11 @@ exports.printers = {
|
|
|
88
126
|
print(path, options, print) {
|
|
89
127
|
const printed = originalPostcssPrinter.print(path, options, print);
|
|
90
128
|
|
|
91
|
-
|
|
129
|
+
if (!isCustomPropertyDeclaration(path.node)) {
|
|
130
|
+
return printed;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return docContainsComment(printed) ? printed : flattenDoc(printed);
|
|
92
134
|
},
|
|
93
135
|
},
|
|
94
136
|
};
|
package/project.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
3
|
-
"name": "prettier-config",
|
|
4
|
-
"prefix": "tui",
|
|
5
|
-
"projectType": "library",
|
|
6
|
-
"sourceRoot": "projects/prettier-config",
|
|
7
|
-
"targets": {
|
|
8
|
-
"publish": {
|
|
9
|
-
"executor": "nx:run-commands",
|
|
10
|
-
"options": {
|
|
11
|
-
"command": "npm publish ./projects/{projectName} --access=public --ignore-scripts"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|