Created
November 7, 2023 18:57
-
-
Save BSFishy/f917770acac228565e98d9d819d582e5 to your computer and use it in GitHub Desktop.
Get a list of dependencies required at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { nodeFileTrace } from '@vercel/nft'; | |
import path from 'node:path'; | |
import { lstat } from 'node:fs/promises'; | |
async function run() { | |
const cwd = process.cwd(); | |
const dir = process.argv[2]; | |
if (!dir) { | |
throw 'You must specify the directory'; | |
} | |
const stat = await lstat(path.resolve(cwd, dir)); | |
if (!stat.isDirectory()) { | |
throw 'Not a directory'; | |
} | |
const { fileList } = await nodeFileTrace([path.join(dir, 'src', 'index.js')], { | |
base: dir, | |
ts: true, | |
}); | |
const list = [...fileList] | |
.filter(file => file.startsWith('node_modules')) | |
.map(file => file.split('/')[1]); | |
console.log(new Set(list)); | |
} | |
run().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment