@@ -10,7 +10,7 @@ import { BuilderContext, createBuilder, targetFromTargetString } from '@angular-
10
10
import { BuildResult , runWebpack } from '@angular-devkit/build-webpack' ;
11
11
import { JsonObject } from '@angular-devkit/core' ;
12
12
import type { ɵParsedMessage as LocalizeMessage } from '@angular/localize' ;
13
- import type { Diagnostics } from '@angular/localize/src/ tools/src/diagnostics ' ;
13
+ import type { Diagnostics } from '@angular/localize/tools' ;
14
14
import * as fs from 'fs' ;
15
15
import * as path from 'path' ;
16
16
import webpack from 'webpack' ;
@@ -32,24 +32,6 @@ import { Format, Schema } from './schema';
32
32
33
33
export type ExtractI18nBuilderOptions = Schema & JsonObject ;
34
34
35
- /**
36
- * The manually constructed type for the `@angular/localize/tools` module.
37
- * This type only contains the exports that are need for this file.
38
- *
39
- * TODO_ESM: Remove once the `tools` entry point exists in a published package version
40
- */
41
- interface LocalizeToolsModule {
42
- /* eslint-disable max-len */
43
- checkDuplicateMessages : typeof import ( '@angular/localize/src/tools/src/extract/duplicates' ) . checkDuplicateMessages ;
44
- XmbTranslationSerializer : typeof import ( '@angular/localize/src/tools/src/extract/translation_files/xmb_translation_serializer' ) . XmbTranslationSerializer ;
45
- SimpleJsonTranslationSerializer : typeof import ( '@angular/localize/src/tools/src/extract/translation_files/json_translation_serializer' ) . SimpleJsonTranslationSerializer ;
46
- Xliff1TranslationSerializer : typeof import ( '@angular/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer' ) . Xliff1TranslationSerializer ;
47
- Xliff2TranslationSerializer : typeof import ( '@angular/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer' ) . Xliff2TranslationSerializer ;
48
- ArbTranslationSerializer : typeof import ( '@angular/localize/src/tools/src/extract/translation_files/arb_translation_serializer' ) . ArbTranslationSerializer ;
49
- LegacyMessageIdMigrationSerializer : typeof import ( '@angular/localize/src/tools/src/extract/translation_files/legacy_message_id_migration_serializer' ) . LegacyMessageIdMigrationSerializer ;
50
- /* eslint-enable max-len */
51
- }
52
-
53
35
function getI18nOutfile ( format : string | undefined ) {
54
36
switch ( format ) {
55
37
case 'xmb' :
@@ -71,67 +53,40 @@ function getI18nOutfile(format: string | undefined) {
71
53
}
72
54
73
55
async function getSerializer (
74
- localizeToolsModule : LocalizeToolsModule | undefined ,
56
+ localizeToolsModule : typeof import ( '@angular/localize/tools' ) ,
75
57
format : Format ,
76
58
sourceLocale : string ,
77
59
basePath : string ,
78
60
useLegacyIds : boolean ,
79
61
diagnostics : Diagnostics ,
80
62
) {
63
+ const {
64
+ XmbTranslationSerializer,
65
+ LegacyMessageIdMigrationSerializer,
66
+ ArbTranslationSerializer,
67
+ Xliff1TranslationSerializer,
68
+ Xliff2TranslationSerializer,
69
+ SimpleJsonTranslationSerializer,
70
+ } = localizeToolsModule ;
71
+
81
72
switch ( format ) {
82
73
case Format . Xmb :
83
- const { XmbTranslationSerializer } =
84
- localizeToolsModule ??
85
- ( await import (
86
- '@angular/localize/src/tools/src/extract/translation_files/xmb_translation_serializer'
87
- ) ) ;
88
-
89
74
// eslint-disable-next-line @typescript-eslint/no-explicit-any
90
75
return new XmbTranslationSerializer ( basePath as any , useLegacyIds ) ;
91
76
case Format . Xlf :
92
77
case Format . Xlif :
93
78
case Format . Xliff :
94
- const { Xliff1TranslationSerializer } =
95
- localizeToolsModule ??
96
- ( await import (
97
- '@angular/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer'
98
- ) ) ;
99
-
100
79
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101
80
return new Xliff1TranslationSerializer ( sourceLocale , basePath as any , useLegacyIds , { } ) ;
102
81
case Format . Xlf2 :
103
82
case Format . Xliff2 :
104
- const { Xliff2TranslationSerializer } =
105
- localizeToolsModule ??
106
- ( await import (
107
- '@angular/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer'
108
- ) ) ;
109
-
110
83
// eslint-disable-next-line @typescript-eslint/no-explicit-any
111
84
return new Xliff2TranslationSerializer ( sourceLocale , basePath as any , useLegacyIds , { } ) ;
112
85
case Format . Json :
113
- const { SimpleJsonTranslationSerializer } =
114
- localizeToolsModule ??
115
- ( await import (
116
- '@angular/localize/src/tools/src/extract/translation_files/json_translation_serializer'
117
- ) ) ;
118
-
119
86
return new SimpleJsonTranslationSerializer ( sourceLocale ) ;
120
87
case Format . LegacyMigrate :
121
- const { LegacyMessageIdMigrationSerializer } =
122
- localizeToolsModule ??
123
- ( await import (
124
- '@angular/localize/src/tools/src/extract/translation_files/legacy_message_id_migration_serializer'
125
- ) ) ;
126
-
127
88
return new LegacyMessageIdMigrationSerializer ( diagnostics ) ;
128
89
case Format . Arb :
129
- const { ArbTranslationSerializer } =
130
- localizeToolsModule ??
131
- ( await import (
132
- '@angular/localize/src/tools/src/extract/translation_files/arb_translation_serializer'
133
- ) ) ;
134
-
135
90
const fileSystem = {
136
91
relative ( from : string , to : string ) : string {
137
92
return path . relative ( from , to ) ;
@@ -287,15 +242,9 @@ export async function execute(
287
242
288
243
// All the localize usages are setup to first try the ESM entry point then fallback to the deep imports.
289
244
// This provides interim compatibility while the framework is transitioned to bundled ESM packages.
290
- // TODO_ESM: Remove all deep imports once `@angular/localize` is published with the `tools` entry point
291
- let localizeToolsModule ;
292
- try {
293
- // Load ESM `@angular/localize/tools` using the TypeScript dynamic import workaround.
294
- // Once TypeScript provides support for keeping the dynamic import this workaround can be
295
- // changed to a direct dynamic import.
296
- localizeToolsModule = await loadEsmModule < LocalizeToolsModule > ( '@angular/localize/tools' ) ;
297
- } catch { }
298
-
245
+ const localizeToolsModule = await loadEsmModule < typeof import ( '@angular/localize/tools' ) > (
246
+ '@angular/localize/tools' ,
247
+ ) ;
299
248
const webpackResult = await runWebpack (
300
249
( await transforms ?. webpackConfiguration ?.( config ) ) || config ,
301
250
context ,
@@ -315,8 +264,7 @@ export async function execute(
315
264
316
265
const basePath = config . context || projectRoot ;
317
266
318
- const { checkDuplicateMessages } =
319
- localizeToolsModule ?? ( await import ( '@angular/localize/src/tools/src/extract/duplicates' ) ) ;
267
+ const { checkDuplicateMessages } = localizeToolsModule ;
320
268
321
269
// The filesystem is used to create a relative path for each file
322
270
// from the basePath. This relative path is then used in the error message.
0 commit comments