1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  */
    
  7. 'use strict';
    
  8. 
    
  9. const execFileSync = require('child_process').execFileSync;
    
  10. 
    
  11. const exec = (command, args) => {
    
  12.   console.log('> ' + [command].concat(args).join(' '));
    
  13.   const options = {
    
  14.     cwd: process.cwd(),
    
  15.     env: process.env,
    
  16.     stdio: 'pipe',
    
  17.     encoding: 'utf-8',
    
  18.   };
    
  19.   return execFileSync(command, args, options);
    
  20. };
    
  21. 
    
  22. const execGitCmd = args => exec('git', args).trim().toString().split('\n');
    
  23. 
    
  24. const listChangedFiles = () => {
    
  25.   const mergeBase = execGitCmd(['merge-base', 'HEAD', 'main']);
    
  26.   return new Set([
    
  27.     ...execGitCmd(['diff', '--name-only', '--diff-filter=ACMRTUB', mergeBase]),
    
  28.     ...execGitCmd(['ls-files', '--others', '--exclude-standard']),
    
  29.   ]);
    
  30. };
    
  31. 
    
  32. module.exports = listChangedFiles;