const fs = require('fs')
const { nodeFileTrace } = require('@vercel/nft')
async function computeDependencies(paths: string[] = [], name: string = 'deps') {
const files = paths
const { fileList } = await nodeFileTrace(files)
let packages = {}
fileList.forEach((i) => {
if (i.includes('node_modules/')) {
let temp = i.replace('node_modules/', '')
temp = temp.substring(0, temp.indexOf('/'))
packages[`node_modules/${temp}`] = true
} else {
packages[i] = true
}
})
packages = Object.keys(packages)
.sort()
.reduce((obj, key) => {
obj[key] = packages[key]
return obj
}, {})
fs.writeFileSync(`./${name}.json`, JSON.stringify(packages, null, 2), 'utf-8')
}