Skip to content

Commit

Permalink
fix(scripts-prettier): escape file names that are being passed to pre…
Browse files Browse the repository at this point in the history
…ttier bin via shell (#31889)
  • Loading branch information
Hotell authored Jul 2, 2024
1 parent 1e591f2 commit 88db367
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions scripts/prettier/src/prettier-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ function runPrettier(files, config = {}) {

const prettierSupportedFiles = fileIsGlob
? files
: files.filter(file => {
: files.reduce((acc, file) => {
const ext = path.extname(file).replace('.', '');
return prettierSupportedFileExtensions.includes(ext);
});

if (prettierSupportedFileExtensions.includes(ext)) {
// WHY IGNORE IS NEEDED?: prettier removes one of the '\' within replaceValue
// prettier-ignore
const escapedFileName = `"${file.replace(/\$/g, '\\\$')}"`;

acc.push(escapedFileName);
}
return acc;
}, /** @type {string[]} */ ([]));

if (!prettierSupportedFiles.length) {
console.log('prettier: No supported files found');
Expand Down

0 comments on commit 88db367

Please sign in to comment.