diff options
author | nlf <quitlahok@gmail.com> | 2020-12-14 19:47:25 +0300 |
---|---|---|
committer | nlf <quitlahok@gmail.com> | 2020-12-15 22:16:37 +0300 |
commit | d6817f062e62d987c729a12770e0346a9a9d561b (patch) | |
tree | ad59a4f4f8d2de6f01868349e865e58fe5dfbb9e /lib | |
parent | a9c4b158c46dd0d0c8d8744a97750ffd0c30cc09 (diff) |
move splitPackageNames to its own module
Diffstat (limited to 'lib')
-rw-r--r-- | lib/utils/split-package-names.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/utils/split-package-names.js b/lib/utils/split-package-names.js new file mode 100644 index 000000000..bb6e449ba --- /dev/null +++ b/lib/utils/split-package-names.js @@ -0,0 +1,23 @@ +'use strict' + +const splitPackageNames = (path) => { + return path.split('/') + // combine scoped parts + .reduce((parts, part) => { + if (parts.length === 0) + return [part] + + const lastPart = parts[parts.length - 1] + // check if previous part is the first part of a scoped package + if (lastPart[0] === '@' && !lastPart.includes('/')) + parts[parts.length - 1] += '/' + part + else + parts.push(part) + + return parts + }, []) + .join('/node_modules/') + .replace(/(\/node_modules)+/, '/node_modules') +} + +module.exports = splitPackageNames |