You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

sort-package-json

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-package-json - npm Package Compare versions

Comparing version
3.4.0
to
3.5.0
+55
-1
index.js

@@ -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