Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2021-05-07 02:06:29 +0300
committerGar <gar+gh@danger.computer>2021-05-10 19:37:12 +0300
commit1d092144eaaabff63ac8424b40b2286822be7677 (patch)
treecfc63a6d91736f3165fcc4d38431ff3a2819b660 /scripts
parent1eb7e5c7d466293b472c2506c64e5a89ec84ac2f (diff)
fix(packages): locale-agnostic string sorting
This adds the 'en' locale to all instances of String.localeCompare within the CLI codebase. Tests added for the cases where we're sorting arbitrary user-generated data. The tests rely on the fact that 'ch' sorts after 'd' in the `'sk'` locale, but ahead of `'d'` in the `'en'` locale. To ensure that this is the default behavior if no locale is specified, `LC_ALL=sk` is set in the test environment. Other instances of `localeCompare` sort data that the cli controls, so no tests were added. Re: https://github.com/npm/cli/issues/2829 PR-URL: https://github.com/npm/cli/pull/3203 Credit: @isaacs Close: #3203 Reviewed-by: @ruyadorno
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bundle-and-gitignore-deps.js4
-rw-r--r--scripts/config-doc.js4
2 files changed, 4 insertions, 4 deletions
diff --git a/scripts/bundle-and-gitignore-deps.js b/scripts/bundle-and-gitignore-deps.js
index 0aedec781..691deb916 100644
--- a/scripts/bundle-and-gitignore-deps.js
+++ b/scripts/bundle-and-gitignore-deps.js
@@ -18,9 +18,9 @@ arb.loadVirtual().then(tree => {
bundle.push(node.name)
}
}
- pkg.bundleDependencies = bundle.sort((a, b) => a.localeCompare(b))
+ pkg.bundleDependencies = bundle.sort((a, b) => a.localeCompare(b, 'en'))
- const ignores = shouldIgnore.sort((a, b) => a.localeCompare(b))
+ const ignores = shouldIgnore.sort((a, b) => a.localeCompare(b, 'en'))
.map(i => `/${i}`)
.join('\n')
const ignoreData = `# Automatically generated to ignore dev deps
diff --git a/scripts/config-doc.js b/scripts/config-doc.js
index 9bb462889..8d8294906 100644
--- a/scripts/config-doc.js
+++ b/scripts/config-doc.js
@@ -35,8 +35,8 @@ const addShorthands = doc => {
const body = Object.entries(shorthands)
.sort(([shorta, expansiona], [shortb, expansionb]) => {
// sort by what they're short FOR
- return expansiona.join(' ').localeCompare(expansionb.join(' ')) ||
- shorta.localeCompare(shortb)
+ return expansiona.join(' ').localeCompare(expansionb.join(' '), 'en') ||
+ shorta.localeCompare(shortb, 'en')
})
.map(([short, expansion]) => {
const dash = short.length === 1 ? '-' : '--'