sort-package-json
Advanced tools
+42
-51
@@ -175,33 +175,4 @@ var __create = Object.create; | ||
| // node_modules/git-hooks-list/index.json | ||
| var git_hooks_list_default = [ | ||
| "applypatch-msg", | ||
| "pre-applypatch", | ||
| "post-applypatch", | ||
| "pre-commit", | ||
| "pre-merge-commit", | ||
| "prepare-commit-msg", | ||
| "commit-msg", | ||
| "post-commit", | ||
| "pre-rebase", | ||
| "post-checkout", | ||
| "post-merge", | ||
| "pre-push", | ||
| "pre-receive", | ||
| "update", | ||
| "proc-receive", | ||
| "post-receive", | ||
| "post-update", | ||
| "reference-transaction", | ||
| "push-to-checkout", | ||
| "pre-auto-gc", | ||
| "post-rewrite", | ||
| "sendemail-validate", | ||
| "fsmonitor-watchman", | ||
| "p4-changelist", | ||
| "p4-prepare-changelist", | ||
| "p4-post-changelist", | ||
| "p4-pre-submit", | ||
| "post-index-change" | ||
| ]; | ||
| // index.js | ||
| var import_git_hooks_list = __toESM(require("git-hooks-list"), 1); | ||
@@ -238,18 +209,2 @@ // node_modules/is-plain-obj/index.js | ||
| }; | ||
| var objectGroupBy = ( | ||
| // eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax -- Safe | ||
| Object.groupBy || // Remove this when we drop support for Node.js 20 | ||
| ((array, callback) => { | ||
| const result = /* @__PURE__ */ Object.create(null); | ||
| for (const value of array) { | ||
| const key = callback(value); | ||
| if (result[key]) { | ||
| result[key].push(value); | ||
| } else { | ||
| result[key] = [value]; | ||
| } | ||
| } | ||
| return result; | ||
| }) | ||
| ); | ||
| var sortObject = sortObjectBy(); | ||
@@ -269,3 +224,3 @@ var sortURLObject = sortObjectBy(["type", "url"]); | ||
| ); | ||
| var sortGitHooks = sortObjectBy(git_hooks_list_default); | ||
| var sortGitHooks = sortObjectBy(import_git_hooks_list.default); | ||
| var parseNameAndVersionRange = (specifier) => { | ||
@@ -414,2 +369,37 @@ const [nameAndVersion] = specifier.split(">"); | ||
| var sortVolta = sortObjectBy(["node", "npm", "yarn"]); | ||
| var wireitScriptProperties = ["command", "dependencies", "files", "output"]; | ||
| var sortWireitScript = pipe([ | ||
| sortObjectBy(wireitScriptProperties), | ||
| overProperty( | ||
| "dependencies", | ||
| onArray((deps) => deps.map(sortObjectBy(["script", "cascade"]))) | ||
| ), | ||
| overProperty( | ||
| "env", | ||
| onObject( | ||
| (env) => sortObjectByKeyNameList( | ||
| Object.fromEntries( | ||
| Object.entries(env).map(([key, value]) => [ | ||
| key, | ||
| sortObjectBy(["external", "default"])(value) | ||
| ]) | ||
| ) | ||
| ) | ||
| ) | ||
| ), | ||
| overProperty( | ||
| "service", | ||
| pipe([sortObjectBy(["readyWhen"]), overProperty("readyWhen", sortObject)]) | ||
| ) | ||
| ]); | ||
| var sortWireit = onObject( | ||
| (wireit) => sortObjectByKeyNameList( | ||
| Object.fromEntries( | ||
| Object.entries(wireit).map(([name, config]) => [ | ||
| name, | ||
| sortWireitScript(config) | ||
| ]) | ||
| ) | ||
| ) | ||
| ); | ||
| var sortDevEngines = overProperty( | ||
@@ -509,3 +499,3 @@ "packageManager", | ||
| var sortConditions = (conditions) => { | ||
| const { defaultConditions = [], restConditions = [] } = objectGroupBy( | ||
| const { defaultConditions = [], restConditions = [] } = Object.groupBy( | ||
| conditions, | ||
@@ -522,3 +512,3 @@ (condition) => { | ||
| var sortExports = onObject((exports2) => { | ||
| const { paths = [], conditions = [] } = objectGroupBy( | ||
| const { paths = [], conditions = [] } = Object.groupBy( | ||
| Object.keys(exports2), | ||
@@ -604,2 +594,3 @@ (key) => key.startsWith(".") ? "paths" : "conditions" | ||
| { key: "betterScripts", over: sortScripts }, | ||
| { key: "wireit", over: sortWireit }, | ||
| /* vscode */ | ||
@@ -707,3 +698,3 @@ { key: "l10n" }, | ||
| const keys = Object.keys(json); | ||
| const { privateKeys = [], publicKeys = [] } = objectGroupBy( | ||
| const { privateKeys = [], publicKeys = [] } = Object.groupBy( | ||
| keys, | ||
@@ -710,0 +701,0 @@ (key) => key[0] === "_" ? "privateKeys" : "publicKeys" |
+41
-19
@@ -37,18 +37,2 @@ import fs from 'node:fs' | ||
| } | ||
| const objectGroupBy = | ||
| // eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax -- Safe | ||
| Object.groupBy || | ||
| // Remove this when we drop support for Node.js 20 | ||
| ((array, callback) => { | ||
| const result = Object.create(null) | ||
| for (const value of array) { | ||
| const key = callback(value) | ||
| if (result[key]) { | ||
| result[key].push(value) | ||
| } else { | ||
| result[key] = [value] | ||
| } | ||
| } | ||
| return result | ||
| }) | ||
| const sortObject = sortObjectBy() | ||
@@ -272,2 +256,39 @@ const sortURLObject = sortObjectBy(['type', 'url']) | ||
| const sortVolta = sortObjectBy(['node', 'npm', 'yarn']) | ||
| // https://github.com/google/wireit | ||
| const wireitScriptProperties = ['command', 'dependencies', 'files', 'output'] | ||
| const sortWireitScript = pipe([ | ||
| sortObjectBy(wireitScriptProperties), | ||
| overProperty( | ||
| 'dependencies', | ||
| onArray((deps) => deps.map(sortObjectBy(['script', 'cascade']))), | ||
| ), | ||
| overProperty( | ||
| 'env', | ||
| onObject((env) => | ||
| sortObjectKeys( | ||
| Object.fromEntries( | ||
| Object.entries(env).map(([key, value]) => [ | ||
| key, | ||
| sortObjectBy(['external', 'default'])(value), | ||
| ]), | ||
| ), | ||
| ), | ||
| ), | ||
| ), | ||
| overProperty( | ||
| 'service', | ||
| pipe([sortObjectBy(['readyWhen']), overProperty('readyWhen', sortObject)]), | ||
| ), | ||
| ]) | ||
| const sortWireit = onObject((wireit) => | ||
| sortObjectKeys( | ||
| Object.fromEntries( | ||
| Object.entries(wireit).map(([name, config]) => [ | ||
| name, | ||
| sortWireitScript(config), | ||
| ]), | ||
| ), | ||
| ), | ||
| ) | ||
| const sortDevEngines = overProperty( | ||
@@ -398,3 +419,3 @@ 'packageManager', | ||
| const sortConditions = (conditions) => { | ||
| const { defaultConditions = [], restConditions = [] } = objectGroupBy( | ||
| const { defaultConditions = [], restConditions = [] } = Object.groupBy( | ||
| conditions, | ||
@@ -414,3 +435,3 @@ (condition) => { | ||
| const sortExports = onObject((exports) => { | ||
| const { paths = [], conditions = [] } = objectGroupBy( | ||
| const { paths = [], conditions = [] } = Object.groupBy( | ||
| Object.keys(exports), | ||
@@ -502,2 +523,3 @@ (key) => (key.startsWith('.') ? 'paths' : 'conditions'), | ||
| { key: 'betterScripts', over: sortScripts }, | ||
| { key: 'wireit', over: sortWireit }, | ||
| /* vscode */ { key: 'l10n' }, | ||
@@ -605,3 +627,3 @@ /* vscode */ { key: 'contributes', over: sortObject }, | ||
| const keys = Object.keys(json) | ||
| const { privateKeys = [], publicKeys = [] } = objectGroupBy( | ||
| const { privateKeys = [], publicKeys = [] } = Object.groupBy( | ||
| keys, | ||
@@ -608,0 +630,0 @@ (key) => (key[0] === '_' ? 'privateKeys' : 'publicKeys'), |
+3
-3
| { | ||
| "name": "sort-package-json", | ||
| "version": "3.6.1", | ||
| "version": "3.7.0", | ||
| "description": "Sort an Object or package.json based on the well-known package.json keys", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
| "scripts": { | ||
| "build": "esbuild index.js --bundle --platform=node --outfile=index.cjs --external:semver", | ||
| "build": "esbuild index.js --bundle --platform=node --outfile=index.cjs --external:semver --external:git-hooks-list", | ||
| "fix": "eslint . --fix && prettier . --write && node cli.js \"package.json\"", | ||
@@ -107,4 +107,4 @@ "lint": "eslint . && prettier . \"!**/*.js\" --check && node cli.js \"package.json\" --check", | ||
| "engines": { | ||
| "node": ">=20" | ||
| "node": ">=22" | ||
| } | ||
| } |
63103
0.58%1534
0.79%