node/deps/npm/lib/utils/split-package-names.js
Myles Borins d0b1b135b2 deps: upgrade npm to 7.2.0
PR-URL: https://github.com/nodejs/node/pull/36543
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruy Adorno <ruyadorno@github.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2020-12-17 01:05:51 +00:00

24 lines
594 B
JavaScript

'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