Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getExternals(packageName, installPath) {
const packageJSONPath = path.join(
installPath,
'node_modules',
packageName,
'package.json'
)
const packageJSON = require(packageJSONPath)
const dependencies = Object.keys(packageJSON.dependencies || {})
const peerDependencies = Object.keys(packageJSON.peerDependencies || {})
// All packages with name same as a built-in node module, but
// haven't explicitly been added as an npm dependency are externals
const builtInExternals = builtInModules.filter(mod => !dependencies.includes(mod))
return {
externalPackages: peerDependencies,
externalBuiltIns: builtInExternals
}
}