From 7d185c374f36f25e99f666b4a8f488aa9fa1a404 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 10 May 2021 08:59:14 -0700 Subject: [PATCH] fix(add): Specify 'en' locale to String.localeCompare (#3) No test added, since there's nothing in this module that particularly depends on string sorting, but it's a best practice all the same. Re: https://github.com/npm/cli/issues/2829 --- lib/cache-install-dir.js | 2 +- lib/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cache-install-dir.js b/lib/cache-install-dir.js index 1bee289..9e30d62 100644 --- a/lib/cache-install-dir.js +++ b/lib/cache-install-dir.js @@ -12,7 +12,7 @@ const cacheInstallDir = ({ cache, packages }) => { const getHash = (packages) => crypto.createHash('sha512') - .update(packages.sort((a, b) => a.localeCompare(b)).join('\n')) + .update(packages.sort((a, b) => a.localeCompare(b, 'en')).join('\n')) .digest('hex') .slice(0, 16) diff --git a/lib/index.js b/lib/index.js index 0bab753..a48c654 100644 --- a/lib/index.js +++ b/lib/index.js @@ -143,7 +143,7 @@ const exec = async (opts) => { }, })) .map(mani => mani._from) - .sort((a, b) => a.localeCompare(b)) + .sort((a, b) => a.localeCompare(b, 'en')) // no need to install if already present if (add.length) {