From 8cc4beb959bb0a4f95954d24c08dc8dfdb7ab01a Mon Sep 17 00:00:00 2001 From: moarcaffeine <58535532+moarcaffeine@users.noreply.github.com> Date: Wed, 4 Dec 2019 18:09:59 -0600 Subject: [PATCH 1/2] fix: resolve module before comparison Current check is comparing names to resolved modules. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8afe681..2e0c77f 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const generateDeclaration = require('./generateDeclaration'); function hasEntryContaining(list, check) { return list .map((v) => Array.isArray(v) ? v[0] : v) - .some((x) => x.includes(check[0])); + .some((x) => x.includes(require.resolve(check[0]))); } function addIfAbsent(list, entry) { From fa146a4a4665b636701bae9c4f5fe18117e1fa07 Mon Sep 17 00:00:00 2001 From: David Evans Date: Sat, 7 Dec 2019 13:51:56 +0000 Subject: [PATCH 2/2] Use simpler comparison for resolved paths Use full string equality rather than partial matches, and resolve each path only once. --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2e0c77f..a8df907 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,16 @@ const applyNeutrinoPatches = require('neutrino-patch'); const generateDeclaration = require('./generateDeclaration'); -function hasEntryContaining(list, check) { +function hasEntry(list, resolvedPath) { return list .map((v) => Array.isArray(v) ? v[0] : v) - .some((x) => x.includes(require.resolve(check[0]))); + .includes(resolvedPath); } function addIfAbsent(list, entry) { - if (!hasEntryContaining(list, entry)) { - entry[0] = require.resolve(entry[0]); + entry[0] = require.resolve(entry[0]); + + if (!hasEntry(list, entry[0])) { list.push(entry); } }