@lntvow/sort-package-json 1.0.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/index.cjs ADDED
@@ -0,0 +1,704 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => index_default,
33
+ sortOrder: () => defaultSortOrder,
34
+ sortPackageJson: () => sortPackageJson
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var import_node_fs = __toESM(require("node:fs"), 1);
38
+
39
+ // ../../../.web/.pnpm/v10/links/@/sort-object-keys/2.1.0/d59f1f1e9a401501d250bd875858a7b2613accdbb9cb5537c65fe710e7036ca0/node_modules/sort-object-keys/index.js
40
+ var has = (object, key) => Object.prototype.hasOwnProperty.call(object, key);
41
+ function sortObjectByKeyNameList(object, sortWith) {
42
+ let keys, sortFn, key;
43
+ if (typeof sortWith === "function") {
44
+ sortFn = sortWith;
45
+ } else {
46
+ keys = sortWith;
47
+ }
48
+ const total = {};
49
+ const objectKeys = [...keys ?? [], ...Object.keys(object).sort(sortFn)];
50
+ for (key of objectKeys) {
51
+ if (has(object, key)) {
52
+ total[key] = object[key];
53
+ }
54
+ }
55
+ return total;
56
+ }
57
+
58
+ // ../../../.web/.pnpm/v10/links/@/detect-indent/7.0.2/684a74527ca731cbdd2a51339ebce0d882f23593bb97d49b942ea17568721cf3/node_modules/detect-indent/index.js
59
+ var INDENT_REGEX = /^(?:( )+|\t+)/;
60
+ var INDENT_TYPE_SPACE = "space";
61
+ var INDENT_TYPE_TAB = "tab";
62
+ function shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, value) {
63
+ return ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && value === 1;
64
+ }
65
+ function makeIndentsMap(string, ignoreSingleSpaces) {
66
+ const indents = /* @__PURE__ */ new Map();
67
+ let previousSize = 0;
68
+ let previousIndentType;
69
+ let key;
70
+ for (const line of string.split(/\n/g)) {
71
+ if (!line) {
72
+ continue;
73
+ }
74
+ const matches = line.match(INDENT_REGEX);
75
+ if (matches === null) {
76
+ previousSize = 0;
77
+ previousIndentType = "";
78
+ } else {
79
+ const indent = matches[0].length;
80
+ const indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
81
+ if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, indent)) {
82
+ continue;
83
+ }
84
+ if (indentType !== previousIndentType) {
85
+ previousSize = 0;
86
+ }
87
+ previousIndentType = indentType;
88
+ let use = 1;
89
+ let weight = 0;
90
+ const indentDifference = indent - previousSize;
91
+ previousSize = indent;
92
+ if (indentDifference === 0) {
93
+ use = 0;
94
+ weight = 1;
95
+ } else {
96
+ const absoluteIndentDifference = Math.abs(indentDifference);
97
+ if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, absoluteIndentDifference)) {
98
+ continue;
99
+ }
100
+ key = encodeIndentsKey(indentType, absoluteIndentDifference);
101
+ }
102
+ const entry = indents.get(key);
103
+ indents.set(key, entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight]);
104
+ }
105
+ }
106
+ return indents;
107
+ }
108
+ function encodeIndentsKey(indentType, indentAmount) {
109
+ const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
110
+ return typeCharacter + String(indentAmount);
111
+ }
112
+ function decodeIndentsKey(indentsKey) {
113
+ const keyHasTypeSpace = indentsKey[0] === "s";
114
+ const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
115
+ const amount = Number(indentsKey.slice(1));
116
+ return { type, amount };
117
+ }
118
+ function getMostUsedKey(indents) {
119
+ let result;
120
+ let maxUsed = 0;
121
+ let maxWeight = 0;
122
+ for (const [key, [usedCount, weight]] of indents) {
123
+ if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
124
+ maxUsed = usedCount;
125
+ maxWeight = weight;
126
+ result = key;
127
+ }
128
+ }
129
+ return result;
130
+ }
131
+ function makeIndentString(type, amount) {
132
+ const indentCharacter = type === INDENT_TYPE_SPACE ? " " : " ";
133
+ return indentCharacter.repeat(amount);
134
+ }
135
+ function detectIndent(string) {
136
+ if (typeof string !== "string") {
137
+ throw new TypeError("Expected a string");
138
+ }
139
+ let indents = makeIndentsMap(string, true);
140
+ if (indents.size === 0) {
141
+ indents = makeIndentsMap(string, false);
142
+ }
143
+ const keyOfMostUsedIndent = getMostUsedKey(indents);
144
+ let type;
145
+ let amount = 0;
146
+ let indent = "";
147
+ if (keyOfMostUsedIndent !== void 0) {
148
+ ({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent));
149
+ indent = makeIndentString(type, amount);
150
+ }
151
+ return {
152
+ amount,
153
+ type,
154
+ indent
155
+ };
156
+ }
157
+
158
+ // ../../../.web/.pnpm/v10/links/@/detect-newline/4.0.1/513ad1f85ec5f5f132411c4b761f0b010c65f1a8de94543a0ffefd83f2cdb9da/node_modules/detect-newline/index.js
159
+ function detectNewline(string) {
160
+ if (typeof string !== "string") {
161
+ throw new TypeError("Expected a string");
162
+ }
163
+ const newlines = string.match(/(?:\r?\n)/g) || [];
164
+ if (newlines.length === 0) {
165
+ return;
166
+ }
167
+ const crlf = newlines.filter((newline) => newline === "\r\n").length;
168
+ const lf = newlines.length - crlf;
169
+ return crlf > lf ? "\r\n" : "\n";
170
+ }
171
+ function detectNewlineGraceful(string) {
172
+ return typeof string === "string" && detectNewline(string) || "\n";
173
+ }
174
+
175
+ // index.js
176
+ var import_git_hooks_list = __toESM(require("git-hooks-list"), 1);
177
+
178
+ // ../../../.web/.pnpm/v10/links/@/is-plain-obj/4.1.0/e2501abf16a61e479fb9c49637ed7dbbdb38ea48c9e0a39ae7f44ff089385f5e/node_modules/is-plain-obj/index.js
179
+ function isPlainObject(value) {
180
+ if (typeof value !== "object" || value === null) {
181
+ return false;
182
+ }
183
+ const prototype = Object.getPrototypeOf(value);
184
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
185
+ }
186
+
187
+ // index.js
188
+ var import_compare = __toESM(require("semver/functions/compare.js"), 1);
189
+ var import_min_version = __toESM(require("semver/ranges/min-version.js"), 1);
190
+ var pipe = (fns) => (x, ...args) => fns.reduce((result, fn) => fn(result, ...args), x);
191
+ var onArray = (fn) => (x) => Array.isArray(x) ? fn(x) : x;
192
+ var onStringArray = (fn) => (x) => Array.isArray(x) && x.every((item) => typeof item === "string") ? fn(x) : x;
193
+ var uniq = onStringArray((xs) => [...new Set(xs)]);
194
+ var sortArray = onStringArray((array) => array.toSorted());
195
+ var uniqAndSortArray = pipe([uniq, sortArray]);
196
+ var onObject = (fn) => (x, ...args) => isPlainObject(x) ? fn(x, ...args) : x;
197
+ var sortObjectBy = (comparator, deep) => {
198
+ const over = onObject((object) => {
199
+ if (deep) {
200
+ object = Object.fromEntries(
201
+ Object.entries(object).map(([key, value]) => [key, over(value)])
202
+ );
203
+ }
204
+ return sortObjectByKeyNameList(object, comparator);
205
+ });
206
+ return over;
207
+ };
208
+ var objectGroupBy = (
209
+ // eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax -- Safe
210
+ Object.groupBy || // Remove this when we drop support for Node.js 20
211
+ ((array, callback) => {
212
+ const result = /* @__PURE__ */ Object.create(null);
213
+ for (const value of array) {
214
+ const key = callback(value);
215
+ if (result[key]) {
216
+ result[key].push(value);
217
+ } else {
218
+ result[key] = [value];
219
+ }
220
+ }
221
+ return result;
222
+ })
223
+ );
224
+ var sortObject = sortObjectBy();
225
+ var sortURLObject = sortObjectBy(["type", "url"]);
226
+ var sortPeopleObject = sortObjectBy(["name", "email", "url"]);
227
+ var sortDirectories = sortObjectBy([
228
+ "lib",
229
+ "bin",
230
+ "man",
231
+ "doc",
232
+ "example",
233
+ "test"
234
+ ]);
235
+ var overProperty = (property, over) => onObject(
236
+ (object, ...args) => Object.hasOwn(object, property) ? { ...object, [property]: over(object[property], ...args) } : object
237
+ );
238
+ var sortGitHooks = sortObjectBy(import_git_hooks_list.default);
239
+ var parseNameAndVersionRange = (specifier) => {
240
+ const [nameAndVersion] = specifier.split(">");
241
+ const atMatches = [...nameAndVersion.matchAll("@")];
242
+ if (!atMatches.length || atMatches.length === 1 && atMatches[0].index === 0) {
243
+ return { name: specifier };
244
+ }
245
+ const splitIndex = atMatches.pop().index;
246
+ return {
247
+ name: nameAndVersion.substring(0, splitIndex),
248
+ range: nameAndVersion.substring(splitIndex + 1)
249
+ };
250
+ };
251
+ var sortObjectBySemver = sortObjectBy((a, b) => {
252
+ const { name: aName, range: aRange } = parseNameAndVersionRange(a);
253
+ const { name: bName, range: bRange } = parseNameAndVersionRange(b);
254
+ if (aName !== bName) {
255
+ return aName.localeCompare(bName, "en");
256
+ }
257
+ if (!aRange) {
258
+ return -1;
259
+ }
260
+ if (!bRange) {
261
+ return 1;
262
+ }
263
+ return (0, import_compare.default)((0, import_min_version.default)(aRange), (0, import_min_version.default)(bRange));
264
+ });
265
+ var getPackageName = (ident) => {
266
+ const index = ident.indexOf("@", ident.startsWith("@") ? 1 : 0);
267
+ return index === -1 ? ident : ident.slice(0, index);
268
+ };
269
+ var sortObjectByIdent = (a, b) => {
270
+ const packageNameA = getPackageName(a);
271
+ const packageNameB = getPackageName(b);
272
+ if (packageNameA < packageNameB) return -1;
273
+ if (packageNameA > packageNameB) return 1;
274
+ return 0;
275
+ };
276
+ var cache = /* @__PURE__ */ new Map();
277
+ var hasYarnOrPnpmFiles = () => {
278
+ const cwd = process.cwd();
279
+ if (!cache.has(cwd)) {
280
+ cache.set(
281
+ cwd,
282
+ import_node_fs.default.existsSync("yarn.lock") || import_node_fs.default.existsSync(".yarn/") || import_node_fs.default.existsSync(".yarnrc.yml") || import_node_fs.default.existsSync("pnpm-lock.yaml") || import_node_fs.default.existsSync("pnpm-workspace.yaml")
283
+ );
284
+ }
285
+ return cache.get(cwd);
286
+ };
287
+ function shouldSortDependenciesLikeNpm(packageJson) {
288
+ if (typeof packageJson.packageManager === "string") {
289
+ return packageJson.packageManager.startsWith("npm@");
290
+ }
291
+ if (packageJson.devEngines?.packageManager?.name) {
292
+ return packageJson.devEngines.packageManager.name === "npm";
293
+ }
294
+ if (packageJson.pnpm) {
295
+ return false;
296
+ }
297
+ if (packageJson.engines?.npm) {
298
+ return true;
299
+ }
300
+ if (hasYarnOrPnpmFiles()) {
301
+ return false;
302
+ }
303
+ return true;
304
+ }
305
+ var sortDependencies = onObject((dependencies, packageJson) => {
306
+ if (Object.keys(dependencies).length < 2) {
307
+ return dependencies;
308
+ }
309
+ if (shouldSortDependenciesLikeNpm(packageJson)) {
310
+ return sortObjectByKeyNameList(dependencies, (a, b) => a.localeCompare(b, "en"));
311
+ }
312
+ return sortObjectByKeyNameList(dependencies);
313
+ });
314
+ var sortWorkspaces = pipe([
315
+ sortObjectBy(["packages", "catalog"]),
316
+ overProperty("packages", uniqAndSortArray),
317
+ overProperty("catalog", sortDependencies)
318
+ ]);
319
+ var eslintBaseConfigProperties = [
320
+ // `files` and `excludedFiles` are only on `overrides[]`
321
+ // for easier sort `overrides[]`,
322
+ // add them to here, so we don't need sort `overrides[]` twice
323
+ "files",
324
+ "excludedFiles",
325
+ // baseConfig
326
+ "env",
327
+ "parser",
328
+ "parserOptions",
329
+ "settings",
330
+ "plugins",
331
+ "extends",
332
+ "rules",
333
+ "overrides",
334
+ "globals",
335
+ "processor",
336
+ "noInlineConfig",
337
+ "reportUnusedDisableDirectives"
338
+ ];
339
+ var sortEslintConfig = pipe([
340
+ sortObjectBy(eslintBaseConfigProperties),
341
+ overProperty("env", sortObject),
342
+ overProperty("globals", sortObject),
343
+ overProperty(
344
+ "overrides",
345
+ onArray((overrides) => overrides.map(sortEslintConfig))
346
+ ),
347
+ overProperty("parserOptions", sortObject),
348
+ overProperty(
349
+ "rules",
350
+ sortObjectBy(
351
+ (rule1, rule2) => rule1.split("/").length - rule2.split("/").length || rule1.localeCompare(rule2)
352
+ )
353
+ ),
354
+ overProperty("settings", sortObject)
355
+ ]);
356
+ var sortVSCodeBadgeObject = sortObjectBy(["description", "url", "href"]);
357
+ var sortPrettierConfig = pipe([
358
+ // sort keys alphabetically, but put `overrides` at bottom
359
+ onObject(
360
+ (config) => sortObjectByKeyNameList(config, [
361
+ ...Object.keys(config).filter((key) => key !== "overrides").sort(),
362
+ "overrides"
363
+ ])
364
+ ),
365
+ // if `config.overrides` exists
366
+ overProperty(
367
+ "overrides",
368
+ // and `config.overrides` is an array
369
+ onArray(
370
+ (overrides) => overrides.map(
371
+ pipe([
372
+ // sort `config.overrides[]` alphabetically
373
+ sortObject,
374
+ // sort `config.overrides[].options` alphabetically
375
+ overProperty("options", sortObject)
376
+ ])
377
+ )
378
+ )
379
+ )
380
+ ]);
381
+ var sortVolta = sortObjectBy(["node", "npm", "yarn"]);
382
+ var sortDevEngines = overProperty(
383
+ "packageManager",
384
+ sortObjectBy(["name", "version", "onFail"])
385
+ );
386
+ var pnpmBaseConfigProperties = [
387
+ "peerDependencyRules",
388
+ "neverBuiltDependencies",
389
+ "onlyBuiltDependencies",
390
+ "onlyBuiltDependenciesFile",
391
+ "allowedDeprecatedVersions",
392
+ "allowNonAppliedPatches",
393
+ "updateConfig",
394
+ "auditConfig",
395
+ "requiredScripts",
396
+ "supportedArchitectures",
397
+ "overrides",
398
+ "patchedDependencies",
399
+ "packageExtensions"
400
+ ];
401
+ var sortPnpmConfig = pipe([
402
+ sortObjectBy(pnpmBaseConfigProperties, true),
403
+ overProperty("overrides", sortObjectBySemver)
404
+ ]);
405
+ var defaultNpmScripts = /* @__PURE__ */ new Set([
406
+ "install",
407
+ "pack",
408
+ "prepare",
409
+ "publish",
410
+ "restart",
411
+ "shrinkwrap",
412
+ "start",
413
+ "stop",
414
+ "test",
415
+ "uninstall",
416
+ "version"
417
+ ]);
418
+ var hasDevDependency = (dependency, packageJson) => {
419
+ return Object.hasOwn(packageJson, "devDependencies") && Object.hasOwn(packageJson.devDependencies, dependency);
420
+ };
421
+ var runSRegExp = /(?<=^|[\s&;<>|(])(?:run-s|npm-run-all2? .*(?:--sequential|--serial|-s))(?=$|[\s&;<>|)])/;
422
+ var isSequentialScript = (command) => command.includes("*") && runSRegExp.test(command);
423
+ var hasSequentialScript = (packageJson) => {
424
+ if (!hasDevDependency("npm-run-all", packageJson) && !hasDevDependency("npm-run-all2", packageJson)) {
425
+ return false;
426
+ }
427
+ const scripts = ["scripts", "betterScripts"].flatMap(
428
+ (field) => packageJson[field] ? Object.values(packageJson[field]) : []
429
+ );
430
+ return scripts.some((script) => isSequentialScript(script));
431
+ };
432
+ function sortScriptNames(keys, prefix = "") {
433
+ const groupMap = /* @__PURE__ */ new Map();
434
+ for (const key of keys) {
435
+ const rest = prefix ? key.slice(prefix.length + 1) : key;
436
+ const idx = rest.indexOf(":");
437
+ if (idx > 0) {
438
+ const base = key.slice(0, (prefix ? prefix.length + 1 : 0) + idx);
439
+ if (!groupMap.has(base)) groupMap.set(base, []);
440
+ groupMap.get(base).push(key);
441
+ } else {
442
+ if (!groupMap.has(key)) groupMap.set(key, []);
443
+ groupMap.get(key).push(key);
444
+ }
445
+ }
446
+ return Array.from(groupMap.keys()).sort().flatMap((groupKey) => {
447
+ const children = groupMap.get(groupKey);
448
+ if (children.length > 1 && children.some((k) => k !== groupKey && k.startsWith(groupKey + ":"))) {
449
+ const direct = children.filter((k) => k === groupKey || !k.startsWith(groupKey + ":")).sort();
450
+ const nested = children.filter((k) => k.startsWith(groupKey + ":"));
451
+ return [...direct, ...sortScriptNames(nested, groupKey)];
452
+ }
453
+ return children.sort();
454
+ });
455
+ }
456
+ var sortScripts = onObject((scripts, packageJson) => {
457
+ let names = Object.keys(scripts);
458
+ const prefixable = /* @__PURE__ */ new Set();
459
+ names = names.map((name) => {
460
+ const omitted = name.replace(/^(?:pre|post)/, "");
461
+ if (defaultNpmScripts.has(omitted) || names.includes(omitted)) {
462
+ prefixable.add(omitted);
463
+ return omitted;
464
+ }
465
+ return name;
466
+ });
467
+ if (!hasSequentialScript(packageJson)) {
468
+ names = sortScriptNames(names);
469
+ }
470
+ names = names.flatMap(
471
+ (key) => prefixable.has(key) ? [`pre${key}`, key, `post${key}`] : [key]
472
+ );
473
+ return sortObjectByKeyNameList(scripts, names);
474
+ });
475
+ var sortConditions = (conditions) => {
476
+ const { defaultConditions = [], restConditions = [] } = objectGroupBy(
477
+ conditions,
478
+ (condition) => {
479
+ if (condition === "default") {
480
+ return "defaultConditions";
481
+ }
482
+ return "restConditions";
483
+ }
484
+ );
485
+ return [...restConditions, ...defaultConditions];
486
+ };
487
+ var sortExports = onObject((exports2) => {
488
+ const { paths = [], conditions = [] } = objectGroupBy(
489
+ Object.keys(exports2),
490
+ (key) => key.startsWith(".") ? "paths" : "conditions"
491
+ );
492
+ return Object.fromEntries(
493
+ [...paths, ...sortConditions(conditions)].map((key) => [
494
+ key,
495
+ sortExports(exports2[key])
496
+ ])
497
+ );
498
+ });
499
+ var fields = [
500
+ { key: "$schema" },
501
+ { key: "name" },
502
+ /* vscode */
503
+ { key: "displayName" },
504
+ { key: "version" },
505
+ /* yarn */
506
+ { key: "stableVersion" },
507
+ { key: "private" },
508
+ { key: "description" },
509
+ /* vscode */
510
+ { key: "categories", over: uniq },
511
+ { key: "keywords", over: uniq },
512
+ { key: "homepage" },
513
+ { key: "bugs", over: sortObjectBy(["url", "email"]) },
514
+ { key: "repository", over: sortURLObject },
515
+ { key: "funding", over: sortURLObject },
516
+ { key: "license", over: sortURLObject },
517
+ /* vscode */
518
+ { key: "qna" },
519
+ { key: "author", over: sortPeopleObject },
520
+ {
521
+ key: "maintainers",
522
+ over: onArray((maintainers) => maintainers.map(sortPeopleObject))
523
+ },
524
+ {
525
+ key: "contributors",
526
+ over: onArray((contributors) => contributors.map(sortPeopleObject))
527
+ },
528
+ /* vscode */
529
+ { key: "publisher" },
530
+ { key: "sideEffects" },
531
+ { key: "type" },
532
+ { key: "imports" },
533
+ { key: "exports", over: sortExports },
534
+ { key: "main" },
535
+ { key: "svelte" },
536
+ { key: "umd:main" },
537
+ { key: "jsdelivr" },
538
+ { key: "unpkg" },
539
+ { key: "module" },
540
+ { key: "source" },
541
+ { key: "jsnext:main" },
542
+ { key: "browser" },
543
+ { key: "react-native" },
544
+ { key: "types" },
545
+ { key: "typesVersions" },
546
+ { key: "typings" },
547
+ { key: "style" },
548
+ { key: "example" },
549
+ { key: "examplestyle" },
550
+ { key: "assets" },
551
+ { key: "bin", over: sortObject },
552
+ { key: "man" },
553
+ { key: "directories", over: sortDirectories },
554
+ { key: "files", over: uniq },
555
+ { key: "workspaces", over: sortWorkspaces },
556
+ // node-pre-gyp https://www.npmjs.com/package/node-pre-gyp#1-add-new-entries-to-your-packagejson
557
+ {
558
+ key: "binary",
559
+ over: sortObjectBy([
560
+ "module_name",
561
+ "module_path",
562
+ "remote_path",
563
+ "package_name",
564
+ "host"
565
+ ])
566
+ },
567
+ { key: "scripts", over: sortScripts },
568
+ { key: "betterScripts", over: sortScripts },
569
+ /* vscode */
570
+ { key: "l10n" },
571
+ /* vscode */
572
+ { key: "contributes", over: sortObject },
573
+ /* vscode */
574
+ { key: "activationEvents", over: uniq },
575
+ { key: "husky", over: overProperty("hooks", sortGitHooks) },
576
+ { key: "simple-git-hooks", over: sortGitHooks },
577
+ { key: "pre-commit" },
578
+ { key: "commitlint", over: sortObject },
579
+ { key: "lint-staged" },
580
+ { key: "nano-staged" },
581
+ { key: "config", over: sortObject },
582
+ { key: "nodemonConfig", over: sortObject },
583
+ { key: "browserify", over: sortObject },
584
+ { key: "babel", over: sortObject },
585
+ { key: "browserslist" },
586
+ { key: "xo", over: sortObject },
587
+ { key: "prettier", over: sortPrettierConfig },
588
+ { key: "eslintConfig", over: sortEslintConfig },
589
+ { key: "eslintIgnore" },
590
+ { key: "npmpkgjsonlint", over: sortObject },
591
+ { key: "npmPackageJsonLintConfig", over: sortObject },
592
+ { key: "npmpackagejsonlint", over: sortObject },
593
+ { key: "release", over: sortObject },
594
+ { key: "remarkConfig", over: sortObject },
595
+ { key: "stylelint" },
596
+ { key: "ava", over: sortObject },
597
+ { key: "jest", over: sortObject },
598
+ { key: "jest-junit", over: sortObject },
599
+ { key: "jest-stare", over: sortObject },
600
+ { key: "mocha", over: sortObject },
601
+ { key: "nyc", over: sortObject },
602
+ { key: "c8", over: sortObject },
603
+ { key: "tap", over: sortObject },
604
+ { key: "oclif", over: sortObjectBy(void 0, true) },
605
+ { key: "resolutions", over: sortObject },
606
+ { key: "overrides", over: sortDependencies },
607
+ { key: "dependencies", over: sortDependencies },
608
+ { key: "devDependencies", over: sortDependencies },
609
+ { key: "dependenciesMeta", over: sortObjectBy(sortObjectByIdent, true) },
610
+ { key: "peerDependencies", over: sortDependencies },
611
+ // TODO: only sort depth = 2
612
+ { key: "peerDependenciesMeta", over: sortObjectBy(void 0, true) },
613
+ { key: "optionalDependencies", over: sortDependencies },
614
+ { key: "bundledDependencies", over: uniqAndSortArray },
615
+ { key: "bundleDependencies", over: uniqAndSortArray },
616
+ /* vscode */
617
+ { key: "extensionPack", over: uniqAndSortArray },
618
+ /* vscode */
619
+ { key: "extensionDependencies", over: uniqAndSortArray },
620
+ { key: "flat" },
621
+ { key: "packageManager" },
622
+ { key: "engines", over: sortObject },
623
+ { key: "engineStrict", over: sortObject },
624
+ { key: "devEngines", over: sortDevEngines },
625
+ { key: "volta", over: sortVolta },
626
+ { key: "languageName" },
627
+ { key: "os" },
628
+ { key: "cpu" },
629
+ { key: "preferGlobal", over: sortObject },
630
+ { key: "publishConfig", over: sortObject },
631
+ /* vscode */
632
+ { key: "icon" },
633
+ /* vscode */
634
+ {
635
+ key: "badges",
636
+ over: onArray((badge) => badge.map(sortVSCodeBadgeObject))
637
+ },
638
+ /* vscode */
639
+ { key: "galleryBanner", over: sortObject },
640
+ /* vscode */
641
+ { key: "preview" },
642
+ /* vscode */
643
+ { key: "markdown" },
644
+ { key: "pnpm", over: sortPnpmConfig }
645
+ ];
646
+ var defaultSortOrder = fields.map(({ key }) => key);
647
+ var overFields = pipe(
648
+ fields.map(({ key, over }) => over ? overProperty(key, over) : void 0).filter(Boolean)
649
+ );
650
+ var overFieldsWithoutScripts = pipe(
651
+ fields.map(({ key, over }) => {
652
+ if (!over) {
653
+ return void 0;
654
+ }
655
+ if (key === "scripts" || key === "betterScripts") {
656
+ return void 0;
657
+ }
658
+ return overProperty(key, over);
659
+ }).filter(Boolean)
660
+ );
661
+ function editStringJSON(json, over) {
662
+ if (typeof json === "string") {
663
+ const { indent, type } = detectIndent(json);
664
+ const endCharacters = json.slice(-1) === "\n" ? "\n" : "";
665
+ const newline = detectNewlineGraceful(json);
666
+ json = JSON.parse(json);
667
+ let result = JSON.stringify(over(json), null, type === "tab" ? " " : indent) + endCharacters;
668
+ if (newline === "\r\n") {
669
+ result = result.replace(/\n/g, newline);
670
+ }
671
+ return result;
672
+ }
673
+ return over(json);
674
+ }
675
+ function sortPackageJson(jsonIsh, options = {}) {
676
+ const shouldSortScripts = options.sortScripts ?? false;
677
+ const overFieldsForOptions = shouldSortScripts ? overFields : overFieldsWithoutScripts;
678
+ return editStringJSON(
679
+ jsonIsh,
680
+ onObject((json) => {
681
+ let sortOrder = options.sortOrder || defaultSortOrder;
682
+ if (Array.isArray(sortOrder)) {
683
+ const keys = Object.keys(json);
684
+ const { privateKeys = [], publicKeys = [] } = objectGroupBy(
685
+ keys,
686
+ (key) => key[0] === "_" ? "privateKeys" : "publicKeys"
687
+ );
688
+ sortOrder = [
689
+ ...sortOrder,
690
+ ...defaultSortOrder,
691
+ ...publicKeys.sort(),
692
+ ...privateKeys.sort()
693
+ ];
694
+ }
695
+ return overFieldsForOptions(sortObjectByKeyNameList(json, sortOrder), json);
696
+ })
697
+ );
698
+ }
699
+ var index_default = sortPackageJson;
700
+ // Annotate the CommonJS export names for ESM import in node:
701
+ 0 && (module.exports = {
702
+ sortOrder,
703
+ sortPackageJson
704
+ });