@taiga-ui/prettier-config 0.531.0 → 0.533.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
|
@@ -12,6 +12,7 @@ const jsonStringifyParser = parsers['json-stringify'];
|
|
|
12
12
|
* Keys listed here appear first (in this order); remaining keys are sorted alphabetically.
|
|
13
13
|
*/
|
|
14
14
|
const COMPILER_OPTIONS_KEY_ORDER = ['baseUrl', 'rootDir', 'strict'];
|
|
15
|
+
const EXPORT_CONDITION_KEY_ORDER = ['types', 'import', 'require', 'default'];
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Top-level key order for tsconfig files.
|
|
@@ -57,6 +58,39 @@ function sortAlphabetically(value) {
|
|
|
57
58
|
return value;
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Sorts package.json `exports` while preserving condition priority.
|
|
63
|
+
* Node and TypeScript resolve condition objects in key order, so `types`
|
|
64
|
+
* must stay before runtime conditions.
|
|
65
|
+
*
|
|
66
|
+
* @param {unknown} value
|
|
67
|
+
* @returns {unknown}
|
|
68
|
+
*/
|
|
69
|
+
function sortPackageExports(value) {
|
|
70
|
+
if (Array.isArray(value)) {
|
|
71
|
+
return value.map(sortPackageExports);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (typeof value === 'object' && value !== null) {
|
|
75
|
+
/** @type {Record<string, unknown>} */
|
|
76
|
+
const exportMap = value;
|
|
77
|
+
const hasKnownExportCondition = EXPORT_CONDITION_KEY_ORDER.some((key) =>
|
|
78
|
+
Object.prototype.hasOwnProperty.call(exportMap, key),
|
|
79
|
+
);
|
|
80
|
+
const sorted = hasKnownExportCondition
|
|
81
|
+
? sortKeysByOrder(exportMap, EXPORT_CONDITION_KEY_ORDER)
|
|
82
|
+
: sortAlphabetically(exportMap);
|
|
83
|
+
|
|
84
|
+
for (const key of Object.keys(sorted)) {
|
|
85
|
+
sorted[key] = sortPackageExports(sorted[key]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return sorted;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
|
|
60
94
|
/**
|
|
61
95
|
* Reorders the top-level keys of a plain object according to `keyOrder`.
|
|
62
96
|
* Keys not listed in `keyOrder` are appended afterward, sorted alphabetically.
|
|
@@ -137,13 +171,20 @@ exports.parsers = {
|
|
|
137
171
|
}
|
|
138
172
|
|
|
139
173
|
if (typeof sorted[key] === 'object' && sorted[key] !== null) {
|
|
140
|
-
|
|
141
|
-
key
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
174
|
+
if (key === 'exports' && filepath.endsWith('package.json')) {
|
|
175
|
+
sorted[key] = sortPackageExports(sorted[key]);
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (key === 'compilerOptions') {
|
|
180
|
+
sorted[key] = sortKeysByOrder(
|
|
181
|
+
/** @type {Record<string, unknown>} */ sorted[key],
|
|
182
|
+
COMPILER_OPTIONS_KEY_ORDER,
|
|
183
|
+
);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
sorted[key] = sortAlphabetically(sorted[key]);
|
|
147
188
|
}
|
|
148
189
|
}
|
|
149
190
|
|