Skip to content

Commit 397416f

Browse files
committed
build: improve package diff script to show new untracked files (#61843)
Fixes that the package diff script did not show newly untracked files in the npm package. PR Close #61843
1 parent 7f1c2b7 commit 397416f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/diff-release-package.mts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ async function main(packageName: string) {
105105
git.run(['add', '-A'], {cwd: tmpDir});
106106
git.run(['commit', '-m', 'Delete skipped files for diff'], {cwd: tmpDir});
107107

108+
// Remove all old content, so that e.g. potential file renames or new files are properly
109+
// detected.
110+
const removeAllOldContentTasks: Promise<void>[] = [];
111+
for (const subentry of await glob('**/*', {
112+
dot: true,
113+
cwd: tmpDir,
114+
onlyFiles: true,
115+
ignore: ['.git'],
116+
})) {
117+
removeAllOldContentTasks.push(fs.promises.rm(path.join(tmpDir, subentry), {maxRetries: 3}));
118+
}
119+
await Promise.all(removeAllOldContentTasks);
120+
108121
const copyTasks: Promise<void>[] = [];
109122
for (const subentry of await glob('**/*', {
110123
dot: true,
@@ -126,7 +139,9 @@ async function main(packageName: string) {
126139

127140
git.run(['config', 'core.filemode', 'false'], {cwd: tmpDir});
128141

129-
const diff = git.run(['diff', '--color'], {cwd: tmpDir}).stdout;
142+
// Add all files so that new untracked files are also visible in the diff.
143+
git.run(['add', '-A'], {cwd: tmpDir});
144+
const diff = git.run(['diff', 'HEAD', '--color'], {cwd: tmpDir}).stdout;
130145

131146
console.info('\n\n----- Diff ------');
132147
console.info(diff);

0 commit comments

Comments
 (0)