Skip to content

Commit

Permalink
fixup: cleanup, get tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Oct 19, 2022
1 parent ee4fb78 commit 9f7ebbf
Show file tree
Hide file tree
Showing 5 changed files with 2,591 additions and 2,586 deletions.
27 changes: 13 additions & 14 deletions workspaces/arborist/lib/yarn-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,22 @@ const yarnEntryPriorities = {
}

const priorityThenLocaleCompare = (a, b) => {
if (yarnEntryPriorities[a] || yarnEntryPriorities[b]) {
return (yarnEntryPriorities[a] || 100) > (yarnEntryPriorities[b] || 100) ? 1 : -1
if (!yarnEntryPriorities[a] && !yarnEntryPriorities[b]) {
return localeCompare(a, b)
}

return localeCompare(a, b)
}

const shouldQuoteString = str => {
return str.indexOf('true') === 0 ||
str.indexOf('false') === 0 ||
/[:\s\n\\",[\]]/g.test(str) ||
/^[0-9]/g.test(str) ||
!/^[a-zA-Z]/g.test(str)
/* istanbul ignore next */
return (yarnEntryPriorities[a] || 100) > (yarnEntryPriorities[b] || 100) ? 1 : -1
}

const quoteIfNeeded = val => {
if (typeof val === 'boolean' || typeof val === 'number' || shouldQuoteString(val)) {
if (
typeof val === 'boolean' ||
typeof val === 'number' ||
val === 'true' ||
val === 'false' ||
/[:\s\n\\",[\]]/g.test(val) ||
!/^[a-zA-Z]/g.test(val)
) {
return JSON.stringify(val)
}

Expand Down Expand Up @@ -205,7 +204,7 @@ class YarnLock {
toString () {
return prefix + [...new Set([...this.entries.values()])]
.map(e => e.toString())
.sort((a, b) => localeCompare(a.replaceAll('"', ''), b.replaceAll('"', ''))).join('\n\n') + '\n'
.sort((a, b) => localeCompare(a.replace(/"/g, ''), b.replaceAll(/"/g, ''))).join('\n\n') + '\n'
}

fromTree (tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46619,15 +46619,15 @@ exports[`test/arborist/reify.js TAP update a yarn.lock file > updated yarn lock
# yarn lockfile v1


"abbrev@^1.1.1":
"integrity" "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
"resolved" "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz"
"version" "1.1.1"
abbrev@^1.1.1:
version "1.1.1"
resolved "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz"
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==

"mkdirp@^1.0.2":
"integrity" "sha512-N2REVrJ/X/jGPfit2d7zea2J1pf7EAR5chIUcfHffAZ7gmlam5U65sAm76+o4ntQbSRdTjYf7qZz3chuHlwXEA=="
"resolved" "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.2.tgz"
"version" "1.0.2"
mkdirp@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.2.tgz"
integrity sha512-N2REVrJ/X/jGPfit2d7zea2J1pf7EAR5chIUcfHffAZ7gmlam5U65sAm76+o4ntQbSRdTjYf7qZz3chuHlwXEA==

`

Expand Down
Loading

0 comments on commit 9f7ebbf

Please sign in to comment.