mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
perf(read-project-manifest): optimize normalize function (#6763)
This commit is contained in:
5
.changeset/hot-cobras-fix.md
Normal file
5
.changeset/hot-cobras-fix.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/read-project-manifest": patch
|
||||
---
|
||||
|
||||
Optimizing project manifest normalization, reducing amoung of data copying
|
||||
@@ -38,6 +38,7 @@
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"is-windows": "^1.0.2",
|
||||
"json5": "^2.2.3",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"parse-json": "^5.2.0",
|
||||
"read-yaml-file": "^2.1.0",
|
||||
"sort-keys": "^4.2.0",
|
||||
@@ -46,6 +47,7 @@
|
||||
"devDependencies": {
|
||||
"@pnpm/read-project-manifest": "workspace:*",
|
||||
"@types/is-windows": "^1.0.0",
|
||||
"@types/lodash.clonedeep": "^4.5.7",
|
||||
"@types/parse-json": "^4.0.0",
|
||||
"tempy": "^1.0.1"
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import readYamlFile from 'read-yaml-file'
|
||||
import detectIndent from '@gwhitney/detect-indent'
|
||||
import equal from 'fast-deep-equal'
|
||||
import isWindows from 'is-windows'
|
||||
import sortKeys from 'sort-keys'
|
||||
import cloneDeep from 'lodash.clonedeep'
|
||||
import {
|
||||
readJson5File,
|
||||
readJsonFile,
|
||||
@@ -214,14 +214,24 @@ const dependencyKeys = new Set([
|
||||
])
|
||||
|
||||
function normalize (manifest: ProjectManifest) {
|
||||
manifest = JSON.parse(JSON.stringify(manifest))
|
||||
const result: Record<string, any> = {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
|
||||
for (const [key, value] of Object.entries(manifest)) {
|
||||
if (!dependencyKeys.has(key)) {
|
||||
result[key] = value
|
||||
} else if (Object.keys(value).length !== 0) {
|
||||
result[key] = sortKeys(value)
|
||||
const result: Record<string, unknown> = {} // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
for (const key in manifest) {
|
||||
if (Object.prototype.hasOwnProperty.call(manifest, key)) {
|
||||
const value = manifest[key as keyof ProjectManifest]
|
||||
if (typeof value !== 'object' || !dependencyKeys.has(key)) {
|
||||
result[key] = cloneDeep(value)
|
||||
} else {
|
||||
const keys = Object.keys(value)
|
||||
if (keys.length !== 0) {
|
||||
keys.sort()
|
||||
const sortedValue: Record<string, unknown> = {}
|
||||
for (const k of keys) {
|
||||
// @ts-expect-error this is fine
|
||||
sortedValue[k] = value[k]
|
||||
}
|
||||
result[key] = sortedValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@@ -4135,6 +4135,9 @@ importers:
|
||||
json5:
|
||||
specifier: ^2.2.3
|
||||
version: 2.2.3
|
||||
lodash.clonedeep:
|
||||
specifier: ^4.5.0
|
||||
version: 4.5.0
|
||||
parse-json:
|
||||
specifier: ^5.2.0
|
||||
version: 5.2.0
|
||||
@@ -4154,6 +4157,9 @@ importers:
|
||||
'@types/is-windows':
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
'@types/lodash.clonedeep':
|
||||
specifier: ^4.5.7
|
||||
version: 4.5.7
|
||||
'@types/parse-json':
|
||||
specifier: ^4.0.0
|
||||
version: 4.0.0
|
||||
@@ -9124,6 +9130,12 @@ packages:
|
||||
dependencies:
|
||||
'@types/node': 14.18.52
|
||||
|
||||
/@types/lodash.clonedeep@4.5.7:
|
||||
resolution: {integrity: sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==}
|
||||
dependencies:
|
||||
'@types/lodash': 4.14.195
|
||||
dev: true
|
||||
|
||||
/@types/lodash@4.14.181:
|
||||
resolution: {integrity: sha512-n3tyKthHJbkiWhDZs3DkhkCzt2MexYHXlX0td5iMplyfwketaOeKboEVBqzceH7juqvEg3q5oUoBFxSLu7zFag==}
|
||||
|
||||
@@ -13847,6 +13859,10 @@ packages:
|
||||
resolution: {integrity: sha512-GhrVeweiTD6uTmmn5hV/lzgCQhccwReIVRLHp7LT4SopOjqEZ5BbX8b5WWEtAKasjmy8hR7ZPwsYlxRCku5odg==}
|
||||
dev: true
|
||||
|
||||
/lodash.clonedeep@4.5.0:
|
||||
resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==}
|
||||
dev: false
|
||||
|
||||
/lodash.deburr@4.1.0:
|
||||
resolution: {integrity: sha512-m/M1U1f3ddMCs6Hq2tAsYThTBDaAKFDX3dwDo97GEYzamXi9SqUpjWi/Rrj/gf3X2n8ktwgZrlP1z6E3v/IExQ==}
|
||||
dev: false
|
||||
|
||||
Reference in New Issue
Block a user