import { execSync } from 'child_process'; import { findImports } from './find-imports.js'; import { getModules } from './get-modules.js'; function getGitDiff(options) { const TARGET_BRANCH = options[2] || 'dev'; const diff = execSync(`git diff --name-only origin/${TARGET_BRANCH}`, { encoding: 'utf-8', }); return diff.split('\n'); } async function getChangedModules() { const FINDED_PATHS = ['src', 'test/cypress/integration']; let changedModules = new Set(); const changes = getGitDiff(process.argv); for (const change of changes) { if (!FINDED_PATHS.some((prefix) => change.startsWith(prefix))) return ''; changedModules = new Set([ ...changedModules, ...new Set(getModules(await findImports(change))), ]); } return [...changedModules].join(' '); } getChangedModules() .then((modules) => console.log(modules)) // return .catch((e) => { console.error(e); process.exit(1); });