Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d30325d

Browse files
committed
feat(cli): sort package.json
1 parent ca84eae commit d30325d

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"handlebars": "catalog:prod",
3737
"nano-spawn": "catalog:prod",
3838
"os-locale": "catalog:prod",
39-
"picocolors": "catalog:prod"
39+
"picocolors": "catalog:prod",
40+
"sort-package-json": "catalog:prod"
4041
},
4142
"plume-deps": {
4243
"vuepress": "2.0.0-rc.24",

cli/src/packageJson.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import type { File, ResolvedData } from './types.js'
22
import { kebabCase } from '@pengzhanbo/utils'
33
import spawn from 'nano-spawn'
4+
import _sortPackageJson from 'sort-package-json'
45
import { Mode } from './constants.js'
56
import { readJsonFile, resolve } from './utils/index.js'
67

8+
function sortPackageJson(json: Record<any, any>) {
9+
return _sortPackageJson(json, {
10+
sortOrder: ['name', 'type', 'version', 'private', 'description', 'packageManager', 'author', 'license', 'scripts', 'devDependencies', 'dependencies', 'pnpm'],
11+
})
12+
}
13+
714
export async function createPackageJson(
815
mode: Mode,
916
pkg: Record<string, any>,
@@ -26,8 +33,9 @@ export async function createPackageJson(
2633
if (packageManager !== 'npm') {
2734
let version = await getPackageManagerVersion(packageManager)
2835
if (version) {
29-
if (packageManager === 'yarn' && version.startsWith('1'))
30-
version = '4.6.0'
36+
if (packageManager === 'yarn' && version.startsWith('1')) {
37+
version = '4.10.3'
38+
}
3139
pkg.packageManager = `${packageManager}@${version}`
3240

3341
// pnpm@10 should add `onlyBuiltDependencies`
@@ -84,7 +92,7 @@ export async function createPackageJson(
8492

8593
return {
8694
filepath: 'package.json',
87-
content: JSON.stringify(pkg, null, 2),
95+
content: JSON.stringify(sortPackageJson(pkg), null, 2),
8896
}
8997
}
9098

pnpm-lock.yaml

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ catalogs:
113113
picocolors: ^1.1.1
114114
picomatch: ^4.0.3
115115
shiki: ^3.13.0
116+
sort-package-json: ^3.4.0
116117
tinyglobby: ^0.2.15
117118
tm-grammars: ^1.24.17
118119
tm-themes: ^1.10.9

0 commit comments

Comments
 (0)