Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ensure ivy extraction file names …
Browse files Browse the repository at this point in the history
…match sourcemaps

Not doing so results in a circular sourcemap warning when attempting extraction.
  • Loading branch information
clydin authored and filipesilva committed Aug 31, 2020
1 parent f3fe6f3 commit 67163a2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Expand Up @@ -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);
},
};

Expand All @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/extract-ivy.ts
Expand Up @@ -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;
Expand Down

0 comments on commit 67163a2

Please sign in to comment.