Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular-devkit/build-angular): ensure ivy extraction file names match sourcemaps #18640

Merged
merged 1 commit into from Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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