From c49edc386244c5272339bb8c0c741403bfe5fdf4 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 17 Sep 2019 11:04:12 -0400 Subject: [PATCH] fix(@angular-devkit/build-angular): workaround Node.js copyFile defect on macOS Fixes #15544 --- .../build_angular/src/browser/index.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/angular_devkit/build_angular/src/browser/index.ts b/packages/angular_devkit/build_angular/src/browser/index.ts index 5eb820ac4d62..84abd3852729 100644 --- a/packages/angular_devkit/build_angular/src/browser/index.ts +++ b/packages/angular_devkit/build_angular/src/browser/index.ts @@ -471,7 +471,27 @@ export function buildWebpackBrowser( } } + // Workaround Node.js issue prior to 10.16 with copyFile on macOS + // https://github.com/angular/angular-cli/issues/15544 & https://github.com/nodejs/node/pull/27241 + let copyFileWorkaround = false; + if (process.platform === 'darwin') { + const version = process.versions.node.split('.').map(part => Number(part)); + if ( + version[0] < 10 || + version[0] === 11 || + (version[0] === 10 && version[1] < 16) + ) { + copyFileWorkaround = true; + } + } + for (const action of cacheActions) { + if (copyFileWorkaround) { + try { + fs.unlinkSync(action.dest); + } catch {} + } + fs.copyFileSync(action.src, action.dest, fs.constants.COPYFILE_FICLONE); if (process.platform !== 'win32') { // The cache writes entries as readonly and when using copyFile the permissions will also be copied.