Skip to content

Commit

Permalink
build: sanitize postinstall patch markers (#18982)
Browse files Browse the repository at this point in the history
Yarn throws if patch markers with special characters are found
in restored `node_modules`. To fix this, patch markers are now
sanitized to not contain special characters.
  • Loading branch information
devversion authored and mmalerba committed Apr 14, 2020
1 parent 8ab769d commit 30b0122
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/postinstall/apply-patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ Object.keys(PATCHES_PER_FILE).forEach(filePath => {
* not apply cleanly.
*/
function applyPatch(patchFile) {
const patchMarkerFileName = `${path.basename(patchFile)}.patch_marker`;
const patchMarkerPath = path.join(projectDir, 'node_modules/', patchMarkerFileName);
// Note: We replace non-word characters from the patch marker file name.
// This is necessary because Yarn throws if cached node modules are restored
// which contain files with special characters. Below is an example error:
// ENOTDIR: not a directory, scandir '/<...>/node_modules/@angular_bazel_ng_module.<..>'".
const patchMarkerBasename = `${path.basename(patchFile).replace(/[^\w]/, '_')}`;
const patchMarkerPath = path.join(projectDir, 'node_modules/', patchMarkerBasename);

if (hasFileBeenPatched(patchMarkerPath)) {
return;
Expand Down

0 comments on commit 30b0122

Please sign in to comment.