Skip to content

Commit

Permalink
fix: apply object key sort to npm view deps output (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Aug 6, 2024
1 parent 6a29f1c commit 106229b
Show file tree
Hide file tree
Showing 5 changed files with 1,303 additions and 1,262 deletions.
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,41 @@
"packages/*"
],
"dependencies": {
"@types/fs-extra": "^11.0.1",
"@types/lodash-es": "^4.17.8",
"@types/semver": "^7.5.0",
"@types/yarnpkg__lockfile": "^1.1.6",
"@types/fs-extra": "^11.0.4",
"@types/lodash-es": "^4.17.12",
"@types/semver": "^7.5.8",
"@types/yarnpkg__lockfile": "^1.1.9",
"@yarnpkg/lockfile": "^1.1.0",
"chalk": "^5.3.0",
"commander": "^11.0.0",
"fast-glob": "^3.3.1",
"fs-extra": "^11.1.1",
"fast-glob": "^3.3.2",
"fs-extra": "^11.2.0",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"semver": "^7.5.4",
"synp": "^1.9.10"
"semver": "^7.6.3",
"synp": "^1.9.13"
},
"devDependencies": {
"@jest/globals": "^29.6.2",
"@types/jest": "^29.5.3",
"@types/js-yaml": "^4.0.5",
"@types/node": "^20.4.8",
"concurrently": "^8.2.0",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.9",
"@types/node": "^22.1.0",
"concurrently": "^8.2.2",
"cpy-cli": "^5.0.0",
"esbuild": "^0.20.0",
"esbuild-node-externals": "^1.8.0",
"esbuild": "^0.23.0",
"esbuild-node-externals": "^1.14.0",
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-qiwi": "^2.1.3",
"jest": "^29.6.2",
"jest": "^29.7.0",
"minimist": "^1.2.8",
"mkdirp": "^3.0.1",
"npm": "^9.8.1",
"prettier": "^3.0.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"prettier": "^3.3.3",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"typedoc": "^0.26.5",
"typescript": "5.4.5"
"typescript": "5.5.4"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/main/ts/lockfile/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
TLockfileEntry,
TLockfileObject,
} from '../ifaces'
import {addHiddenProp, formatFlags, formatYaml, invoke, mapFlags, parseYaml} from '../util'
import { addHiddenProp, formatFlags, formatYaml, invoke, mapFlags, parseYaml, sortObject } from '../util'

export const parse = (raw: string): TLockfileObject => {
const data = parseYaml(raw)
Expand Down Expand Up @@ -33,15 +33,15 @@ export const patchEntry = (

// NOTE seems like deps are not updated by `yarn mode='--update-lockfile'`, only checksums
entry.dependencies =
JSON.parse(
sortObject(JSON.parse(
invoke(
npmBin,
['view', `${name}@${newVersion}`, 'dependencies', '--json'],
process.cwd(),
true,
false,
) || 'null',
) || undefined
) || undefined)

delete entry.checksum

Expand Down
6 changes: 6 additions & 0 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,9 @@ const findClosest = (target: string, cwd = __dirname): string | null => {
? path.join(found, target)
: null
}

export const sortObject = <T extends Record<any, any>>(obj: T): T =>
obj ? Object.keys(obj).sort().reduce((result, key) => {
result[key] = obj[key]
return result
}, Object.create(null)) : obj
9 changes: 5 additions & 4 deletions src/test/ts/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const yarnLockAfter = readFixture('lockfile/legacy/yarn.lock.after')

const cwd = process.cwd()

const shell = true
const temp = resolve(__dirname, '../../../.temp')
const stdio = ['inherit', 'inherit', 'inherit']
const stdionull = [null, null, null] // eslint-disable-line
Expand Down Expand Up @@ -186,7 +187,7 @@ describe('yarn-audit-fix', () => {
'--prefix',
expect.stringMatching(temp),
].filter((v) => v !== undefined),
{ cwd: expect.stringMatching(temp), stdio },
{ cwd: expect.stringMatching(temp), stdio, shell },
)

// Updating yarn.lock from package-lock.json...
Expand All @@ -204,7 +205,7 @@ describe('yarn-audit-fix', () => {
registryUrl,
'--ignore-engines',
],
{ cwd, stdio },
{ cwd, stdio, shell },
)
expect(fs.emptyDirSync).toHaveBeenCalledWith(expect.stringMatching(temp))
}
Expand Down Expand Up @@ -251,7 +252,7 @@ describe('yarn-audit-fix', () => {
expect(cp.spawnSync).toHaveBeenCalledWith(
getYarn(),
['audit', '--json'],
{ cwd: temp, stdio: stdionull },
{ cwd: temp, stdio: stdionull, shell },
)
expect(lfPatch).toHaveBeenCalledTimes(1)
expect(lfFormat).toHaveBeenCalledTimes(1)
Expand All @@ -268,7 +269,7 @@ describe('yarn-audit-fix', () => {
expect(cp.spawnSync).toHaveBeenCalledWith(
getYarn(),
['install', '--update-checksums'],
{ cwd, stdio },
{ cwd, stdio, shell },
)
})
})
Expand Down
Loading

0 comments on commit 106229b

Please sign in to comment.