sort-package-json
Advanced tools
Comparing version 2.9.0 to 2.10.0
58
index.js
@@ -6,2 +6,3 @@ import sortObjectKeys from 'sort-object-keys' | ||
import isPlainObject from 'is-plain-obj' | ||
import semver from 'semver' | ||
@@ -58,2 +59,34 @@ const hasOwn = | ||
const sortObjectBySemver = sortObjectBy((a, b) => { | ||
const parseNameAndVersionRange = (specifier) => { | ||
// Ignore anything after > & rely on fallback alphanumeric sorting for that | ||
const [nameAndVersion] = specifier.split('>') | ||
const atMatches = [...nameAndVersion.matchAll('@')] | ||
if ( | ||
!atMatches.length || | ||
(atMatches.length === 1 && atMatches[0].index === 0) | ||
) { | ||
return { name: specifier } | ||
} | ||
const splitIndex = atMatches.pop().index | ||
return { | ||
name: nameAndVersion.substring(0, splitIndex), | ||
range: nameAndVersion.substring(splitIndex + 1), | ||
} | ||
} | ||
const { name: aName, range: aRange } = parseNameAndVersionRange(a) | ||
const { name: bName, range: bRange } = parseNameAndVersionRange(b) | ||
if (aName !== bName) { | ||
return aName.localeCompare(bName) | ||
} | ||
if (!aRange) { | ||
return -1 | ||
} | ||
if (!bRange) { | ||
return 1 | ||
} | ||
return semver.compare(semver.minVersion(aRange), semver.minVersion(bRange)) | ||
}) | ||
// https://github.com/eslint/eslint/blob/acc0e47572a9390292b4e313b4a4bf360d236358/conf/config-schema.js | ||
@@ -133,2 +166,25 @@ const eslintBaseConfigProperties = [ | ||
const pnpmBaseConfigProperties = [ | ||
'peerDependencyRules', | ||
'neverBuiltDependencies', | ||
'onlyBuiltDependencies', | ||
'onlyBuiltDependenciesFile', | ||
'allowedDeprecatedVersions', | ||
'allowNonAppliedPatches', | ||
'updateConfig', | ||
'auditConfig', | ||
'requiredScripts', | ||
'supportedArchitectures', | ||
'overrides', | ||
'patchedDependencies', | ||
'packageExtensions', | ||
] | ||
const sortPnpmConfig = onObject( | ||
pipe([ | ||
sortObjectBy(pnpmBaseConfigProperties, true), | ||
overProperty('overrides', sortObjectBySemver), | ||
]), | ||
) | ||
// See https://docs.npmjs.com/misc/scripts | ||
@@ -318,3 +374,3 @@ const defaultNpmScripts = new Set([ | ||
/* vscode */ { key: 'markdown' }, | ||
{ key: 'pnpm', over: sortObjectBy(undefined, true) }, | ||
{ key: 'pnpm', over: sortPnpmConfig }, | ||
] | ||
@@ -321,0 +377,0 @@ |
{ | ||
"name": "sort-package-json", | ||
"version": "2.9.0", | ||
"version": "2.10.0", | ||
"description": "Sort an Object or package.json based on the well-known package.json keys", | ||
@@ -76,2 +76,3 @@ "keywords": [ | ||
"is-plain-obj": "^4.1.0", | ||
"semver": "^7.6.0", | ||
"sort-object-keys": "^1.1.3" | ||
@@ -78,0 +79,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31670
617
8
+ Addedsemver@^7.6.0
+ Addedsemver@7.6.3(transitive)