UNPKG

@arc-fusion/cli

Version:

CLI for running Arc Fusion on your local machine

45 lines (33 loc) 1.12 kB
'use strict' const path = require('path') const { lstat, realpath } = require('fs/promises') const { glob } = require('glob') const isLink = async (filePath) => { const stats = await lstat(filePath.replace(/\/$/, '')) return stats.isSymbolicLink() } async function getLinks (globPattern) { const pattern = globPattern.replace(/\\/g, '/') const entries = await glob(pattern) const links = await Promise.all( entries.map(async (entry) => (await isLink(entry)) ? entry : null ) ) return links.filter(Boolean) } async function getLinkedModules (projectRoot) { const modulesRoot = path.resolve(projectRoot, 'node_modules') const rootLinks = await getLinks(path.join(modulesRoot, '*/')) const scopedLinks = await getLinks(path.join(modulesRoot, '@*', '*/')) const links = await Promise.all( [].concat(rootLinks, scopedLinks).map(async (link) => ({ [path.relative(modulesRoot, link)]: await realpath(link) })) ) return Object.assign({}, ...links) } module.exports = getLinkedModules if (module === require.main) { getLinkedModules('.').then(console.log) }