Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(arborist): use string-locale-compare #4465

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion workspaces/arborist/bin/license.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Arborist = require('../')
const localeCompare = require('@isaacs/string-locale-compare')('en')
const options = require('./lib/options.js')
require('./lib/logging.js')
require('./lib/timers.js')
Expand All @@ -24,7 +25,7 @@ a.loadVirtual().then(tree => {
}

for (const [count, license] of set.sort((a, b) =>
a[1] && b[1] ? b[0] - a[0] || a[1].localeCompare(b[1], 'en')
a[1] && b[1] ? b[0] - a[0] || localeCompare(a[1], b[1])
: a[1] ? -1
: b[1] ? 1
: 0)) {
Expand Down
5 changes: 3 additions & 2 deletions workspaces/arborist/test/arborist/rebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { resolve, dirname } = require('path')
const fs = require('fs')
const fixtures = resolve(__dirname, '../fixtures')
const relpath = require('../../lib/relpath.js')
const localeCompare = require('@isaacs/string-locale-compare')('en')

const fixture = (t, p) => require(`${fixtures}/reify-cases/${p}`)(t)

Expand Down Expand Up @@ -181,7 +182,7 @@ t.test('verify dep flags in script environments', async t => {
// don't include path or env, because that's going to be platform-specific
const saved = [...arb.scriptsRun]
.sort(({ path: patha, event: eventa }, { path: pathb, event: eventb }) =>
patha.localeCompare(pathb, 'en') || eventa.localeCompare(eventb, 'en'))
localeCompare(patha, pathb) || localeCompare(eventa, eventb))
.map(({ pkg, event, cmd, code, signal, stdout, stderr }) =>
({ pkg, event, cmd, code, signal, stdout, stderr }))
t.matchSnapshot(saved, 'saved script results')
Expand All @@ -191,7 +192,7 @@ t.test('verify dep flags in script environments', async t => {
t.strictSame(flags, fs.readFileSync(file, 'utf8').split('\n'), pkg)
}
t.strictSame(checkLogs().sort((a, b) =>
a[2].localeCompare(b[2], 'en') || (typeof a[4] === 'string' ? -1 : 1)), [
localeCompare(a[2], b[2]) || (typeof a[4] === 'string' ? -1 : 1)), [
['info', 'run', 'devdep@1.0.0', 'postinstall', 'node_modules/devdep', 'node ../../env.js'],
['info', 'run', 'devdep@1.0.0', 'postinstall', { code: 0, signal: null }],
['info', 'run', 'devopt@1.0.0', 'postinstall', 'node_modules/devopt', 'node ../../env.js'],
Expand Down
3 changes: 2 additions & 1 deletion workspaces/arborist/test/arborist/reify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { resolve, basename } = require('path')
const t = require('tap')
const runScript = require('@npmcli/run-script')
const localeCompare = require('@isaacs/string-locale-compare')('en')

// mock rimraf so we can make it fail in rollback tests
const realRimraf = require('rimraf')
Expand Down Expand Up @@ -241,7 +242,7 @@ t.test('omit peer deps', t => {
.then(() => {
process.removeListener('time', onTime)
process.removeListener('timeEnd', onTimeEnd)
finishedTimers.sort((a, b) => a.localeCompare(b, 'en'))
finishedTimers.sort(localeCompare)
t.matchSnapshot(finishedTimers, 'finished timers')
t.strictSame(timers, {}, 'should have no timers in progress now')
})
Expand Down
7 changes: 4 additions & 3 deletions workspaces/arborist/test/audit-report.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const t = require('tap')
const localeCompare = require('@isaacs/string-locale-compare')('en')
const AuditReport = require('../lib/audit-report.js')
const { auditToBulk } = AuditReport
const Node = require('../lib/node.js')
Expand All @@ -24,14 +25,14 @@ const newArb = (path, opts = {}) =>

const sortReport = report => {
const entries = Object.entries(report.vulnerabilities)
const vulns = entries.sort(([a], [b]) => a.localeCompare(b, 'en'))
const vulns = entries.sort(([a], [b]) => localeCompare(a, b))
.map(([name, vuln]) => [
name,
{
...vuln,
via: (vuln.via || []).sort((a, b) =>
String(a.source || a).localeCompare(String(b.source || b), 'en')),
effects: (vuln.effects || []).sort((a, b) => a.localeCompare(b, 'en')),
localeCompare(String(a.source || a), String(b.source || b))),
effects: (vuln.effects || []).sort(localeCompare),
},
])
report.vulnerabilities = vulns.reduce((set, [k, v]) => {
Expand Down
3 changes: 2 additions & 1 deletion workspaces/arborist/test/diff.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const localeCompare = require('@isaacs/string-locale-compare')('en')
const Diff = require('../lib/diff.js')
const t = require('tap')
const Node = require('../lib/node.js')
Expand Down Expand Up @@ -31,7 +32,7 @@ const formatDiff = obj =>
removed: obj.removed.map(d => normalizePath(d.path).split(normalizedCWD).join('{CWD}')),
children: [...obj.children]
.map(formatDiff)
.sort((a, b) => path(a).localeCompare(path(b), 'en')),
.sort((a, b) => localeCompare(path(a), path(b))),
})

t.formatSnapshot = obj => format(formatDiff(obj), { sort: false })
Expand Down
3 changes: 2 additions & 1 deletion workspaces/arborist/test/fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const mkdirp = require('mkdirp').sync
const localeCompare = require('@isaacs/string-locale-compare')('en')
const { unlinkSync, symlinkSync, readFileSync, writeFileSync } = require('fs')
const { relative, resolve, dirname } = require('path')

Expand Down Expand Up @@ -167,7 +168,7 @@ const setup = () => {
`### BEGIN IGNORED SYMLINKS ###
### this list is generated automatically, do not edit directly
### update it by running \`node test/fixtures/index.js\`
${links.sort((a,b) => a.localeCompare(b, 'en')).join('\n')}
${links.sort(localeCompare).join('\n')}
### END IGNORED SYMLINKS ###`)
writeFileSync(gifile, gitignore)
}
Expand Down
3 changes: 2 additions & 1 deletion workspaces/arborist/test/gather-dep-set.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const t = require('tap')
const localeCompare = require('@isaacs/string-locale-compare')('en')
const gatherDepSet = require('../lib/gather-dep-set.js')

const Node = require('../lib/node.js')
Expand Down Expand Up @@ -81,7 +82,7 @@ const tree = new Node({
const normalizePath = path => path.replace(/[A-Z]:/, '').replace(/\\/g, '/')

const printSet = set => [...set]
.sort((a, b) => a.name.localeCompare(b.name, 'en'))
.sort((a, b) => localeCompare(a.name, b.name))
.map(n => n.location)

const cwd = normalizePath(process.cwd())
Expand Down
6 changes: 4 additions & 2 deletions workspaces/arborist/test/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// does not enable it.
process.env.ARBORIST_DEBUG = '1'
const Inventory = require('../lib/inventory.js')
const localeCompare = require('@isaacs/string-locale-compare')('en')

const t = require('tap')

t.test('basic operations', t => {
Expand All @@ -21,7 +23,7 @@ t.test('basic operations', t => {
i.get('y'),
], 'filter returns an iterable of all matching nodes')

t.same([...i.query('license')].sort((a, b) => String(a).localeCompare(String(b), 'en')),
t.same([...i.query('license')].sort((a, b) => localeCompare(String(a), String(b))),
['ISC', 'MIT', undefined])
t.same([...i.query('license', 'MIT')], [
{ location: 'x', name: 'x', package: { licence: 'MIT', funding: 'foo' } },
Expand All @@ -33,7 +35,7 @@ t.test('basic operations', t => {
{ location: 'x', name: 'x', package: { licence: 'MIT', funding: 'foo' } },
{ location: 'y', name: 'x', package: { licenses: [{ type: 'ISC' }], funding: { url: 'foo' } } },
], 'can query by name')
t.same([...i.query('funding')].sort((a, b) => String(a).localeCompare(String(b), 'en')),
t.same([...i.query('funding')].sort((a, b) => localeCompare(String(a), String(b))),
['bar', 'foo', undefined])
t.same([...i.query('funding', 'foo')], [
{ location: 'x', name: 'x', package: { licence: 'MIT', funding: 'foo' } },
Expand Down