Files
react/compiler/forget/scripts/shared/list-changed-files.js
T
mofeiZ 9bd67099d7 [prettier] detect changed files from relative dir
Previously, `yarn prettier` didn't write changed files since `glob` produced 
paths relative to cwd and `git diff --name-only` produced paths relative to git 
root directory. 

This changes `git diff --name-only` to `git diff --name-only --relative`
2023-01-25 15:16:39 -05:00

39 lines
959 B
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
const execFileSync = require("child_process").execFileSync;
const exec = (command, args) => {
console.log("> " + [command].concat(args).join(" "));
const options = {
cwd: process.cwd(),
env: process.env,
stdio: "pipe",
encoding: "utf-8",
};
return execFileSync(command, args, options);
};
const execGitCmd = (args) => exec("git", args).trim().toString().split("\n");
const listChangedFiles = () => {
const mergeBase = execGitCmd(["merge-base", "HEAD", "main"]);
return new Set([
...execGitCmd([
"diff",
"--name-only",
"--relative",
"--diff-filter=ACMRTUB",
mergeBase,
]),
...execGitCmd(["ls-files", "--others", "--exclude-standard"]),
]);
};
module.exports = listChangedFiles;