Skip to content

Commit 67163a2

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/build-angular): ensure ivy extraction file names match sourcemaps
Not doing so results in a circular sourcemap warning when attempting extraction.
1 parent f3fe6f3 commit 67163a2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

packages/angular_devkit/build_angular/src/extract-i18n/ivy-extract-loader.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,33 @@ export default function localizeExtractLoader(
4444
},
4545
};
4646

47+
let filename = loaderContext.resourcePath;
48+
if (map?.file) {
49+
// The extractor's internal sourcemap handling expects the filenames to match
50+
filename = nodePath.posix.join(loaderContext.context, map.file);
51+
}
52+
4753
// Setup a virtual file system instance for the extractor
4854
// * MessageExtractor itself uses readFile and resolve
4955
// * Internal SourceFileLoader (sourcemap support) uses dirname, exists, readFile, and resolve
5056
const filesystem = {
5157
readFile(path: string): string {
52-
if (path === loaderContext.resourcePath) {
58+
if (path === filename) {
5359
return content;
54-
} else if (path === loaderContext.resourcePath + '.map') {
60+
} else if (path === filename + '.map') {
5561
return typeof map === 'string' ? map : JSON.stringify(map);
5662
} else {
57-
throw new Error('Unknown file requested.');
63+
throw new Error('Unknown file requested: ' + path);
5864
}
5965
},
6066
resolve(...paths: string[]): string {
61-
return nodePath.resolve(...paths);
67+
return nodePath.posix.resolve(...paths);
6268
},
6369
exists(path: string): boolean {
64-
return path === loaderContext.resourcePath || path === loaderContext.resourcePath + '.map';
70+
return path === filename || path === filename + '.map';
6571
},
6672
dirname(path: string): string {
67-
return nodePath.dirname(path);
73+
return nodePath.posix.dirname(path);
6874
},
6975
};
7076

@@ -75,7 +81,7 @@ export default function localizeExtractLoader(
7581
useSourceMaps: !!map,
7682
});
7783

78-
const messages = extractor.extractMessages(loaderContext.resourcePath);
84+
const messages = extractor.extractMessages(filename);
7985
if (messages.length > 0) {
8086
options?.messageHandler(messages);
8187
}

tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export default async function() {
4545
throw new Error('Expected ivy enabled application warning');
4646
}
4747

48+
// Should not show any warnings when extracting
49+
const { stderr: message5 } = await ng('xi18n', '--ivy');
50+
if (message5.includes('WARNING')) {
51+
throw new Error('Expected no warnings to be shown');
52+
}
53+
4854
// Disable Ivy
4955
await updateJsonFile('tsconfig.json', config => {
5056
const { angularCompilerOptions = {} } = config;

0 commit comments

Comments
 (0)