Skip to content

Commit e0b5797

Browse files
authored
build: sanitize postinstall patch markers (#18982)
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.
1 parent e4cfa2b commit e0b5797

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/postinstall/apply-patches.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ Object.keys(PATCHES_PER_FILE).forEach(filePath => {
161161
* not apply cleanly.
162162
*/
163163
function applyPatch(patchFile) {
164-
const patchMarkerFileName = `${path.basename(patchFile)}.patch_marker`;
165-
const patchMarkerPath = path.join(projectDir, 'node_modules/', patchMarkerFileName);
164+
// Note: We replace non-word characters from the patch marker file name.
165+
// This is necessary because Yarn throws if cached node modules are restored
166+
// which contain files with special characters. Below is an example error:
167+
// ENOTDIR: not a directory, scandir '/<...>/node_modules/@angular_bazel_ng_module.<..>'".
168+
const patchMarkerBasename = `${path.basename(patchFile).replace(/[^\w]/, '_')}`;
169+
const patchMarkerPath = path.join(projectDir, 'node_modules/', patchMarkerBasename);
166170

167171
if (hasFileBeenPatched(patchMarkerPath)) {
168172
return;

0 commit comments

Comments
 (0)