From bb6d791dab5c74ae7571cd68ee7cddf322247dc6 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 30 Dec 2020 17:04:04 +0000 Subject: [PATCH] refactor(localize): update to use new file-system interfaces (#40281) Now that `ReadonlyFileSystem` and `PathManipulation` interfaces are available, this commit updates the localize package to use these more focussed interfaces. PR Close #40281 --- .../src/tools/src/extract/duplicates.ts | 6 +++--- .../src/tools/src/extract/extraction.ts | 4 ++-- .../localize/src/tools/src/extract/main.ts | 4 ++-- .../source_files/es2015_extract_plugin.ts | 4 ++-- .../extract/source_files/es5_extract_plugin.ts | 4 ++-- .../arb_translation_serializer.ts | 6 +++--- .../xliff1_translation_serializer.ts | 4 ++-- .../xliff2_translation_serializer.ts | 4 ++-- .../xmb_translation_serializer.ts | 4 ++-- .../src/tools/src/source_file_utils.ts | 18 +++++++++--------- .../source_files/es2015_translate_plugin.ts | 5 ++--- .../source_files/es5_translate_plugin.ts | 5 ++--- .../translation_files/translation_loader.ts | 4 ++-- .../src/tools/src/translate/translator.ts | 4 ++-- .../arb_translation_serializer_spec.ts | 4 ++-- .../xmb_translation_serializer_spec.ts | 4 ++-- .../src/tools/test/source_file_utils_spec.ts | 4 ++-- .../es2015_translate_plugin_spec.ts | 3 --- .../source_files/es5_translate_plugin_spec.ts | 3 --- 19 files changed, 43 insertions(+), 51 deletions(-) diff --git a/packages/localize/src/tools/src/extract/duplicates.ts b/packages/localize/src/tools/src/extract/duplicates.ts index dfe1eb6f5e..932bda6ed7 100644 --- a/packages/localize/src/tools/src/extract/duplicates.ts +++ b/packages/localize/src/tools/src/extract/duplicates.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵMessageId, ɵParsedMessage} from '@angular/localize'; import {DiagnosticHandlingStrategy, Diagnostics} from '../diagnostics'; @@ -17,7 +17,7 @@ import {serializeLocationPosition} from '../source_file_utils'; * object (as necessary). */ export function checkDuplicateMessages( - fs: FileSystem, messages: ɵParsedMessage[], + fs: PathManipulation, messages: ɵParsedMessage[], duplicateMessageHandling: DiagnosticHandlingStrategy, basePath: AbsoluteFsPath): Diagnostics { const diagnostics = new Diagnostics(); if (duplicateMessageHandling === 'ignore') return diagnostics; @@ -47,7 +47,7 @@ export function checkDuplicateMessages( * Serialize the given `message` object into a string. */ function serializeMessage( - fs: FileSystem, basePath: AbsoluteFsPath, message: ɵParsedMessage): string { + fs: PathManipulation, basePath: AbsoluteFsPath, message: ɵParsedMessage): string { if (message.location === undefined) { return ` - "${message.text}"`; } else { diff --git a/packages/localize/src/tools/src/extract/extraction.ts b/packages/localize/src/tools/src/extract/extraction.ts index ae1644e31a..45144073a0 100644 --- a/packages/localize/src/tools/src/extract/extraction.ts +++ b/packages/localize/src/tools/src/extract/extraction.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, ReadonlyFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {Logger} from '@angular/compiler-cli/src/ngtsc/logging'; import {SourceFile, SourceFileLoader} from '@angular/compiler-cli/src/ngtsc/sourcemaps'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; @@ -33,7 +33,7 @@ export class MessageExtractor { private loader: SourceFileLoader; constructor( - private fs: FileSystem, private logger: Logger, + private fs: ReadonlyFileSystem, private logger: Logger, {basePath, useSourceMaps = true, localizeName = '$localize'}: ExtractionOptions) { this.basePath = basePath; this.useSourceMaps = useSourceMaps; diff --git a/packages/localize/src/tools/src/extract/main.ts b/packages/localize/src/tools/src/extract/main.ts index e68335b4ed..6ece99292c 100644 --- a/packages/localize/src/tools/src/extract/main.ts +++ b/packages/localize/src/tools/src/extract/main.ts @@ -6,7 +6,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {setFileSystem, NodeJSFileSystem, AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {setFileSystem, NodeJSFileSystem, AbsoluteFsPath, FileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ConsoleLogger, Logger, LogLevel} from '@angular/compiler-cli/src/ngtsc/logging'; import {ɵParsedMessage} from '@angular/localize'; import * as glob from 'glob'; @@ -214,7 +214,7 @@ export function extractTranslations({ export function getSerializer( format: string, sourceLocale: string, rootPath: AbsoluteFsPath, useLegacyIds: boolean, - formatOptions: FormatOptions = {}, fs: FileSystem): TranslationSerializer { + formatOptions: FormatOptions = {}, fs: PathManipulation): TranslationSerializer { switch (format) { case 'xlf': case 'xlif': diff --git a/packages/localize/src/tools/src/extract/source_files/es2015_extract_plugin.ts b/packages/localize/src/tools/src/extract/source_files/es2015_extract_plugin.ts index 646a77b285..70e53e7ba5 100644 --- a/packages/localize/src/tools/src/extract/source_files/es2015_extract_plugin.ts +++ b/packages/localize/src/tools/src/extract/source_files/es2015_extract_plugin.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedMessage, ɵparseMessage} from '@angular/localize'; import {NodePath, PluginObj} from '@babel/core'; import {TaggedTemplateExpression} from '@babel/types'; @@ -13,7 +13,7 @@ import {TaggedTemplateExpression} from '@babel/types'; import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapExpressionsFromTemplateLiteral, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils'; export function makeEs2015ExtractPlugin( - fs: FileSystem, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj { + fs: PathManipulation, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj { return { visitor: { TaggedTemplateExpression(path: NodePath) { diff --git a/packages/localize/src/tools/src/extract/source_files/es5_extract_plugin.ts b/packages/localize/src/tools/src/extract/source_files/es5_extract_plugin.ts index fc83d4ca40..732a102636 100644 --- a/packages/localize/src/tools/src/extract/source_files/es5_extract_plugin.ts +++ b/packages/localize/src/tools/src/extract/source_files/es5_extract_plugin.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedMessage, ɵparseMessage} from '@angular/localize'; import {NodePath, PluginObj} from '@babel/core'; import {CallExpression} from '@babel/types'; @@ -13,7 +13,7 @@ import {CallExpression} from '@babel/types'; import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils'; export function makeEs5ExtractPlugin( - fs: FileSystem, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj { + fs: PathManipulation, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj { return { visitor: { CallExpression(callPath: NodePath) { diff --git a/packages/localize/src/tools/src/extract/translation_files/arb_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/arb_translation_serializer.ts index 5577e675e5..765512a439 100644 --- a/packages/localize/src/tools/src/extract/translation_files/arb_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/arb_translation_serializer.ts @@ -5,9 +5,8 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; -import {ArbJsonObject, ArbLocation, ArbMetadata} from '../../translate/translation_files/translation_parsers/arb_translation_parser'; import {TranslationSerializer} from './translation_serializer'; import {consolidateMessages, hasLocation} from './utils'; @@ -45,7 +44,8 @@ import {consolidateMessages, hasLocation} from './utils'; */ export class ArbTranslationSerializer implements TranslationSerializer { constructor( - private sourceLocale: string, private basePath: AbsoluteFsPath, private fs: FileSystem) {} + private sourceLocale: string, private basePath: AbsoluteFsPath, + private fs: PathManipulation) {} serialize(messages: ɵParsedMessage[]): string { const messageGroups = consolidateMessages(messages, message => getMessageId(message)); diff --git a/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts index b2262c7cb0..a71e211e40 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xliff1_translation_serializer.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {FormatOptions, validateOptions} from './format_options'; @@ -29,7 +29,7 @@ const LEGACY_XLIFF_MESSAGE_LENGTH = 40; export class Xliff1TranslationSerializer implements TranslationSerializer { constructor( private sourceLocale: string, private basePath: AbsoluteFsPath, private useLegacyIds: boolean, - private formatOptions: FormatOptions = {}, private fs: FileSystem = getFileSystem()) { + private formatOptions: FormatOptions = {}, private fs: PathManipulation = getFileSystem()) { validateOptions('Xliff1TranslationSerializer', [['xml:space', ['preserve']]], formatOptions); } diff --git a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts index 9b8b807959..a5a75f7ec5 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xliff2_translation_serializer.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {FormatOptions, validateOptions} from './format_options'; @@ -29,7 +29,7 @@ export class Xliff2TranslationSerializer implements TranslationSerializer { private currentPlaceholderId = 0; constructor( private sourceLocale: string, private basePath: AbsoluteFsPath, private useLegacyIds: boolean, - private formatOptions: FormatOptions = {}, private fs: FileSystem = getFileSystem()) { + private formatOptions: FormatOptions = {}, private fs: PathManipulation = getFileSystem()) { validateOptions('Xliff1TranslationSerializer', [['xml:space', ['preserve']]], formatOptions); } diff --git a/packages/localize/src/tools/src/extract/translation_files/xmb_translation_serializer.ts b/packages/localize/src/tools/src/extract/translation_files/xmb_translation_serializer.ts index 183c6c6b7b..8cb33981c3 100644 --- a/packages/localize/src/tools/src/extract/translation_files/xmb_translation_serializer.ts +++ b/packages/localize/src/tools/src/extract/translation_files/xmb_translation_serializer.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {extractIcuPlaceholders} from './icu_parsing'; @@ -24,7 +24,7 @@ import {XmlFile} from './xml_file'; export class XmbTranslationSerializer implements TranslationSerializer { constructor( private basePath: AbsoluteFsPath, private useLegacyIds: boolean, - private fs: FileSystem = getFileSystem()) {} + private fs: PathManipulation = getFileSystem()) {} serialize(messages: ɵParsedMessage[]): string { const messageGroups = consolidateMessages(messages, message => this.getMessageId(message)); diff --git a/packages/localize/src/tools/src/source_file_utils.ts b/packages/localize/src/tools/src/source_file_utils.ts index 9ba2b85837..e0814955e8 100644 --- a/packages/localize/src/tools/src/source_file_utils.ts +++ b/packages/localize/src/tools/src/source_file_utils.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵisMissingTranslationError, ɵmakeTemplateObject, ɵParsedTranslation, ɵSourceLocation, ɵtranslate} from '@angular/localize'; import {NodePath} from '@babel/traverse'; import * as t from '@babel/types'; @@ -74,7 +74,7 @@ export function buildLocalizeReplacement( */ export function unwrapMessagePartsFromLocalizeCall( call: NodePath, - fs: FileSystem = getFileSystem(), + fs: PathManipulation = getFileSystem(), ): [TemplateStringsArray, (ɵSourceLocation | undefined)[]] { let cooked = call.get('arguments')[0]; @@ -160,7 +160,7 @@ export function unwrapMessagePartsFromLocalizeCall( */ export function unwrapSubstitutionsFromLocalizeCall( call: NodePath, - fs: FileSystem = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] { + fs: PathManipulation = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] { const expressions = call.get('arguments').splice(1); if (!isArrayOfExpressions(expressions)) { const badExpression = expressions.find(expression => !expression.isExpression())!; @@ -182,8 +182,8 @@ export function unwrapSubstitutionsFromLocalizeCall( * @publicApi used by CLI */ export function unwrapMessagePartsFromTemplateLiteral( - elements: NodePath[], - fs: FileSystem = getFileSystem()): [TemplateStringsArray, (ɵSourceLocation | undefined)[]] { + elements: NodePath[], fs: PathManipulation = getFileSystem()): + [TemplateStringsArray, (ɵSourceLocation | undefined)[]] { const cooked = elements.map(q => { if (q.node.value.cooked === undefined) { throw new BabelParseError( @@ -207,7 +207,7 @@ export function unwrapMessagePartsFromTemplateLiteral( */ export function unwrapExpressionsFromTemplateLiteral( quasi: NodePath, - fs: FileSystem = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] { + fs: PathManipulation = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] { return [quasi.node.expressions, quasi.get('expressions').map(e => getLocation(fs, e))]; } @@ -235,7 +235,7 @@ export function wrapInParensIfNecessary(expression: t.Expression): t.Expression */ export function unwrapStringLiteralArray( array: NodePath, - fs: FileSystem = getFileSystem()): [string[], (ɵSourceLocation | undefined)[]] { + fs: PathManipulation = getFileSystem()): [string[], (ɵSourceLocation | undefined)[]] { if (!isStringLiteralArray(array.node)) { throw new BabelParseError( array.node, 'Unexpected messageParts for `$localize` (expected an array of strings).'); @@ -400,7 +400,7 @@ export function buildCodeFrameError(path: NodePath, e: BabelParseError): string } export function getLocation( - fs: FileSystem, startPath: NodePath, endPath?: NodePath): ɵSourceLocation|undefined { + fs: PathManipulation, startPath: NodePath, endPath?: NodePath): ɵSourceLocation|undefined { const startLocation = startPath.node.loc; const file = getFileFromPath(fs, startPath); if (!startLocation || !file) { @@ -425,7 +425,7 @@ export function serializeLocationPosition(location: ɵSourceLocation): string { return `${location.start.line + 1}${endLineString}`; } -function getFileFromPath(fs: FileSystem, path: NodePath|undefined): AbsoluteFsPath|null { +function getFileFromPath(fs: PathManipulation, path: NodePath|undefined): AbsoluteFsPath|null { const opts = path?.hub.file.opts; return opts?.filename ? fs.resolve(opts.generatorOpts.sourceRoot ?? opts.cwd, fs.relative(opts.cwd, opts.filename)) : diff --git a/packages/localize/src/tools/src/translate/source_files/es2015_translate_plugin.ts b/packages/localize/src/tools/src/translate/source_files/es2015_translate_plugin.ts index f2b351f88c..be1f351361 100644 --- a/packages/localize/src/tools/src/translate/source_files/es2015_translate_plugin.ts +++ b/packages/localize/src/tools/src/translate/source_files/es2015_translate_plugin.ts @@ -5,13 +5,12 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedTranslation} from '@angular/localize'; import {NodePath, PluginObj} from '@babel/core'; import {TaggedTemplateExpression} from '@babel/types'; import {Diagnostics} from '../../diagnostics'; - import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils'; /** @@ -23,7 +22,7 @@ import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLoca export function makeEs2015TranslatePlugin( diagnostics: Diagnostics, translations: Record, {missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {}, - fs: FileSystem = getFileSystem()): PluginObj { + fs: PathManipulation = getFileSystem()): PluginObj { return { visitor: { TaggedTemplateExpression(path: NodePath) { diff --git a/packages/localize/src/tools/src/translate/source_files/es5_translate_plugin.ts b/packages/localize/src/tools/src/translate/source_files/es5_translate_plugin.ts index 33a7066192..6a98ff8729 100644 --- a/packages/localize/src/tools/src/translate/source_files/es5_translate_plugin.ts +++ b/packages/localize/src/tools/src/translate/source_files/es5_translate_plugin.ts @@ -5,13 +5,12 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵParsedTranslation} from '@angular/localize'; import {NodePath, PluginObj} from '@babel/core'; import {CallExpression} from '@babel/types'; import {Diagnostics} from '../../diagnostics'; - import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils'; /** @@ -23,7 +22,7 @@ import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLoca export function makeEs5TranslatePlugin( diagnostics: Diagnostics, translations: Record, {missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {}, - fs: FileSystem = getFileSystem()): PluginObj { + fs: PathManipulation = getFileSystem()): PluginObj { return { visitor: { CallExpression(callPath: NodePath) { diff --git a/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts b/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts index 8323c0821a..9a9254a6bc 100644 --- a/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts +++ b/packages/localize/src/tools/src/translate/translation_files/translation_loader.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, ReadonlyFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {DiagnosticHandlingStrategy, Diagnostics} from '../../diagnostics'; import {TranslationBundle} from '../translator'; @@ -16,7 +16,7 @@ import {ParseAnalysis, TranslationParser} from './translation_parsers/translatio */ export class TranslationLoader { constructor( - private fs: FileSystem, private translationParsers: TranslationParser[], + private fs: ReadonlyFileSystem, private translationParsers: TranslationParser[], private duplicateTranslation: DiagnosticHandlingStrategy, /** @deprecated */ private diagnostics?: Diagnostics) {} diff --git a/packages/localize/src/tools/src/translate/translator.ts b/packages/localize/src/tools/src/translate/translator.ts index 6c1d1eb3d6..dd5465a8d7 100644 --- a/packages/localize/src/tools/src/translate/translator.ts +++ b/packages/localize/src/tools/src/translate/translator.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {AbsoluteFsPath, FileSystem, PathSegment} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {AbsoluteFsPath, PathSegment, ReadonlyFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {ɵMessageId, ɵParsedTranslation} from '@angular/localize'; import {Diagnostics} from '../diagnostics'; @@ -64,7 +64,7 @@ export interface TranslationHandler { */ export class Translator { constructor( - private fs: FileSystem, private resourceHandlers: TranslationHandler[], + private fs: ReadonlyFileSystem, private resourceHandlers: TranslationHandler[], private diagnostics: Diagnostics) {} translateFiles( diff --git a/packages/localize/src/tools/test/extract/translation_files/arb_translation_serializer_spec.ts b/packages/localize/src/tools/test/extract/translation_files/arb_translation_serializer_spec.ts index 0616434009..e93925dffa 100644 --- a/packages/localize/src/tools/test/extract/translation_files/arb_translation_serializer_spec.ts +++ b/packages/localize/src/tools/test/extract/translation_files/arb_translation_serializer_spec.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {absoluteFrom, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {ɵParsedMessage} from '@angular/localize'; @@ -14,7 +14,7 @@ import {ArbTranslationSerializer} from '../../../src/extract/translation_files/a import {location, mockMessage} from './mock_message'; runInEachFileSystem(() => { - let fs: FileSystem; + let fs: PathManipulation; describe('ArbTranslationSerializer', () => { beforeEach(() => { fs = getFileSystem(); diff --git a/packages/localize/src/tools/test/extract/translation_files/xmb_translation_serializer_spec.ts b/packages/localize/src/tools/test/extract/translation_files/xmb_translation_serializer_spec.ts index 1a4593d783..9570e6e376 100644 --- a/packages/localize/src/tools/test/extract/translation_files/xmb_translation_serializer_spec.ts +++ b/packages/localize/src/tools/test/extract/translation_files/xmb_translation_serializer_spec.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {absoluteFrom, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; @@ -14,7 +14,7 @@ import {XmbTranslationSerializer} from '../../../src/extract/translation_files/x import {location, mockMessage} from './mock_message'; runInEachFileSystem(() => { - let fs: FileSystem; + let fs: PathManipulation; beforeEach(() => fs = getFileSystem()); describe('XmbTranslationSerializer', () => { [false, true].forEach(useLegacyIds => { diff --git a/packages/localize/src/tools/test/source_file_utils_spec.ts b/packages/localize/src/tools/test/source_file_utils_spec.ts index df3db7ede3..1f8421fcd7 100644 --- a/packages/localize/src/tools/test/source_file_utils_spec.ts +++ b/packages/localize/src/tools/test/source_file_utils_spec.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; +import {absoluteFrom, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {ɵmakeTemplateObject} from '@angular/localize'; import {NodePath, TransformOptions, transformSync} from '@babel/core'; @@ -16,7 +16,7 @@ import {Expression, Identifier, TaggedTemplateExpression, ExpressionStatement, C import {isGlobalIdentifier, isNamedIdentifier, isStringLiteralArray, isArrayOfExpressions, unwrapStringLiteralArray, unwrapMessagePartsFromLocalizeCall, wrapInParensIfNecessary, buildLocalizeReplacement, unwrapSubstitutionsFromLocalizeCall, unwrapMessagePartsFromTemplateLiteral, getLocation} from '../src/source_file_utils'; runInEachFileSystem(() => { - let fs: FileSystem; + let fs: PathManipulation; beforeEach(() => fs = getFileSystem()); describe('utils', () => { describe('isNamedIdentifier()', () => { diff --git a/packages/localize/src/tools/test/translate/source_files/es2015_translate_plugin_spec.ts b/packages/localize/src/tools/test/translate/source_files/es2015_translate_plugin_spec.ts index 23a5ed343b..b224924511 100644 --- a/packages/localize/src/tools/test/translate/source_files/es2015_translate_plugin_spec.ts +++ b/packages/localize/src/tools/test/translate/source_files/es2015_translate_plugin_spec.ts @@ -5,7 +5,6 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {ɵcomputeMsgId, ɵparseTranslation} from '@angular/localize'; import {ɵParsedTranslation} from '@angular/localize/private'; @@ -16,8 +15,6 @@ import {TranslatePluginOptions} from '../../../src/source_file_utils'; import {makeEs2015TranslatePlugin} from '../../../src/translate/source_files/es2015_translate_plugin'; runInEachFileSystem(() => { - let fs: FileSystem; - beforeEach(() => fs = getFileSystem()); describe('makeEs2015Plugin', () => { describe('(no translations)', () => { it('should transform `$localize` tags with binary expression', () => { diff --git a/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts b/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts index 088113f405..c89294b5e8 100644 --- a/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts +++ b/packages/localize/src/tools/test/translate/source_files/es5_translate_plugin_spec.ts @@ -5,7 +5,6 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {ɵcomputeMsgId, ɵparseTranslation} from '@angular/localize'; import {ɵParsedTranslation} from '@angular/localize/private'; @@ -16,8 +15,6 @@ import {TranslatePluginOptions} from '../../../src/source_file_utils'; import {makeEs5TranslatePlugin} from '../../../src/translate/source_files/es5_translate_plugin'; runInEachFileSystem(() => { - let fs: FileSystem; - beforeEach(() => fs = getFileSystem()); describe('makeEs5Plugin', () => { describe('(no translations)', () => { it('should transform `$localize` calls with binary expression', () => {