From 67163a205e98e87d4472c43c08a334e5bf420f8e Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Thu, 27 Aug 2020 15:42:59 -0400 Subject: [PATCH] fix(@angular-devkit/build-angular): ensure ivy extraction file names match sourcemaps Not doing so results in a circular sourcemap warning when attempting extraction. --- .../src/extract-i18n/ivy-extract-loader.ts | 20 ++++++++++++------- .../legacy-cli/e2e/tests/i18n/extract-ivy.ts | 6 ++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/extract-i18n/ivy-extract-loader.ts b/packages/angular_devkit/build_angular/src/extract-i18n/ivy-extract-loader.ts index fc71e6bc133f..63aef932b2c7 100644 --- a/packages/angular_devkit/build_angular/src/extract-i18n/ivy-extract-loader.ts +++ b/packages/angular_devkit/build_angular/src/extract-i18n/ivy-extract-loader.ts @@ -44,27 +44,33 @@ export default function localizeExtractLoader( }, }; + let filename = loaderContext.resourcePath; + if (map?.file) { + // The extractor's internal sourcemap handling expects the filenames to match + filename = nodePath.posix.join(loaderContext.context, map.file); + } + // Setup a virtual file system instance for the extractor // * MessageExtractor itself uses readFile and resolve // * Internal SourceFileLoader (sourcemap support) uses dirname, exists, readFile, and resolve const filesystem = { readFile(path: string): string { - if (path === loaderContext.resourcePath) { + if (path === filename) { return content; - } else if (path === loaderContext.resourcePath + '.map') { + } else if (path === filename + '.map') { return typeof map === 'string' ? map : JSON.stringify(map); } else { - throw new Error('Unknown file requested.'); + throw new Error('Unknown file requested: ' + path); } }, resolve(...paths: string[]): string { - return nodePath.resolve(...paths); + return nodePath.posix.resolve(...paths); }, exists(path: string): boolean { - return path === loaderContext.resourcePath || path === loaderContext.resourcePath + '.map'; + return path === filename || path === filename + '.map'; }, dirname(path: string): string { - return nodePath.dirname(path); + return nodePath.posix.dirname(path); }, }; @@ -75,7 +81,7 @@ export default function localizeExtractLoader( useSourceMaps: !!map, }); - const messages = extractor.extractMessages(loaderContext.resourcePath); + const messages = extractor.extractMessages(filename); if (messages.length > 0) { options?.messageHandler(messages); } diff --git a/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts b/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts index 6446a402405f..314a0fccb217 100644 --- a/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts +++ b/tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts @@ -45,6 +45,12 @@ export default async function() { throw new Error('Expected ivy enabled application warning'); } + // Should not show any warnings when extracting + const { stderr: message5 } = await ng('xi18n', '--ivy'); + if (message5.includes('WARNING')) { + throw new Error('Expected no warnings to be shown'); + } + // Disable Ivy await updateJsonFile('tsconfig.json', config => { const { angularCompilerOptions = {} } = config;