sort-package-json
Advanced tools
+55
-1
@@ -35,2 +35,18 @@ import sortObjectKeys from 'sort-object-keys' | ||
| } | ||
| 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() | ||
@@ -307,2 +323,40 @@ const sortURLObject = sortObjectBy(['type', 'url']) | ||
| /* | ||
| - Move `types` and versioned type condition to top | ||
| - Move `default` condition to bottom | ||
| */ | ||
| const sortConditions = (conditions) => { | ||
| const { | ||
| typesConditions = [], | ||
| defaultConditions = [], | ||
| restConditions = [], | ||
| } = objectGroupBy(conditions, (condition) => { | ||
| if (condition === 'types' || condition.startsWith('types@')) { | ||
| return 'typesConditions' | ||
| } | ||
| if (condition === 'default') { | ||
| return 'defaultConditions' | ||
| } | ||
| return 'restConditions' | ||
| }) | ||
| return [...typesConditions, ...restConditions, ...defaultConditions] | ||
| } | ||
| const sortExports = onObject((exports) => { | ||
| const { paths = [], conditions = [] } = objectGroupBy( | ||
| Object.keys(exports), | ||
| (key) => (key.startsWith('.') ? 'paths' : 'conditions'), | ||
| ) | ||
| return Object.fromEntries( | ||
| [...paths, ...sortConditions(conditions)].map((key) => [ | ||
| key, | ||
| sortExports(exports[key]), | ||
| ]), | ||
| ) | ||
| }) | ||
| // fields marked `vscode` are for `Visual Studio Code extension manifest` only | ||
@@ -346,3 +400,3 @@ // https://code.visualstudio.com/api/references/extension-manifest | ||
| { key: 'imports' }, | ||
| { key: 'exports' }, | ||
| { key: 'exports', over: sortExports }, | ||
| { key: 'main' }, | ||
@@ -349,0 +403,0 @@ { key: 'svelte' }, |
+2
-2
| { | ||
| "name": "sort-package-json", | ||
| "version": "3.4.0", | ||
| "version": "3.5.0", | ||
| "description": "Sort an Object or package.json based on the well-known package.json keys", | ||
@@ -82,3 +82,3 @@ "keywords": [ | ||
| "semver": "^7.7.1", | ||
| "sort-object-keys": "^1.1.3", | ||
| "sort-object-keys": "^2.0.0", | ||
| "tinyglobby": "^0.2.12" | ||
@@ -85,0 +85,0 @@ }, |
Sorry, the diff of this file is too big to display
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
120876
2.08%3241
2.76%+ Added
- Removed
Updated