Skip to content

Commit

Permalink
fix(@angular/build): support reading on-disk files during i18n extrac…
Browse files Browse the repository at this point in the history
…tion

If an application has JavaScript files that are sourced directly from disk,
the extraction would previously fail due to the i18n extractor only able
to access the in-memory generated JavaScript files. The extractor can now
access both memory and disk-based JavaScript files.

(cherry picked from commit 6b544f7)
  • Loading branch information
clydin authored and alan-agius4 committed Aug 20, 2024
1 parent a655b92 commit 0be4038
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
import type { MessageExtractor } from '@angular/localize/tools';
import type { BuilderContext } from '@angular-devkit/architect';
import { readFileSync } from 'node:fs';
import nodePath from 'node:path';
import { buildApplicationInternal } from '../application';
import type {
Expand Down Expand Up @@ -101,6 +102,8 @@ function setupLocalizeExtractor(
let content;
if (file?.origin === 'memory') {
content = textDecoder.decode(file.contents);
} else if (file?.origin === 'disk') {
content = readFileSync(file.inputPath, 'utf-8');
}
if (content === undefined) {
throw new Error('Unknown file requested: ' + requestedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ResultFile, ResultKind, buildApplicationInternal } from '@angular/build
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
import type { MessageExtractor } from '@angular/localize/tools';
import type { BuilderContext } from '@angular-devkit/architect';
import { readFileSync } from 'node:fs';
import nodePath from 'node:path';
import { BrowserBuilderOptions, convertBrowserOptions } from '../browser-esbuild';
import type { NormalizedExtractI18nOptions } from './options';
Expand Down Expand Up @@ -106,6 +107,8 @@ function setupLocalizeExtractor(
let content;
if (file?.origin === 'memory') {
content = textDecoder.decode(file.contents);
} else if (file?.origin === 'disk') {
content = readFileSync(file.inputPath, 'utf-8');
}
if (content === undefined) {
throw new Error('Unknown file requested: ' + requestedPath);
Expand Down

0 comments on commit 0be4038

Please sign in to comment.