Skip to content

Commit 6b544f7

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular/build): support reading on-disk files during i18n extraction
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.
1 parent 83b7343 commit 6b544f7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/angular/build/src/builders/extract-i18n/application-extraction.ts

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
1010
import type { MessageExtractor } from '@angular/localize/tools';
1111
import type { BuilderContext } from '@angular-devkit/architect';
12+
import { readFileSync } from 'node:fs';
1213
import nodePath from 'node:path';
1314
import { buildApplicationInternal } from '../application';
1415
import type {
@@ -101,6 +102,8 @@ function setupLocalizeExtractor(
101102
let content;
102103
if (file?.origin === 'memory') {
103104
content = textDecoder.decode(file.contents);
105+
} else if (file?.origin === 'disk') {
106+
content = readFileSync(file.inputPath, 'utf-8');
104107
}
105108
if (content === undefined) {
106109
throw new Error('Unknown file requested: ' + requestedPath);

packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ResultFile, ResultKind, buildApplicationInternal } from '@angular/build
1111
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize';
1212
import type { MessageExtractor } from '@angular/localize/tools';
1313
import type { BuilderContext } from '@angular-devkit/architect';
14+
import { readFileSync } from 'node:fs';
1415
import nodePath from 'node:path';
1516
import { BrowserBuilderOptions, convertBrowserOptions } from '../browser-esbuild';
1617
import type { NormalizedExtractI18nOptions } from './options';
@@ -106,6 +107,8 @@ function setupLocalizeExtractor(
106107
let content;
107108
if (file?.origin === 'memory') {
108109
content = textDecoder.decode(file.contents);
110+
} else if (file?.origin === 'disk') {
111+
content = readFileSync(file.inputPath, 'utf-8');
109112
}
110113
if (content === undefined) {
111114
throw new Error('Unknown file requested: ' + requestedPath);

0 commit comments

Comments
 (0)