Bug 1752968 - Minify Fluent `.ftl` files in addition to `.properties` files. r=eemeli

Depends on D138365

Differential Revision: https://phabricator.services.mozilla.com/D138572
This commit is contained in:
Nick Alexander 2022-03-02 17:43:49 +00:00
Родитель 1288cd82fa
Коммит 38725ef570
2 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -773,10 +773,10 @@ class ManifestFile(BaseFile):
return len(self._entries) + len(self._interfaces) == 0
class MinifiedProperties(BaseFile):
class MinifiedCommentStripped(BaseFile):
"""
File class for minified properties. This wraps around a BaseFile instance,
and removes lines starting with a # from its content.
File class for content minified by stripping comments. This wraps around a
BaseFile instance, and removes lines starting with a # from its content.
"""
def __init__(self, file):
@ -786,7 +786,7 @@ class MinifiedProperties(BaseFile):
def open(self):
"""
Return a file-like object allowing to read() the minified content of
the properties file.
the underlying file.
"""
content = "".join(
l
@ -935,8 +935,8 @@ class BaseFinder(object):
if not self._minify or isinstance(file, ExecutableFile):
return file
if path.endswith(".properties"):
return MinifiedProperties(file)
if path.endswith((".ftl", ".properties")):
return MinifiedCommentStripped(file)
if self._minify_js and path.endswith((".js", ".jsm")):
return MinifiedJavaScript(file, self._minify_js_verify_command)

Просмотреть файл

@ -30,7 +30,7 @@ from mozpack.files import (
MercurialFile,
MercurialRevisionFinder,
MinifiedJavaScript,
MinifiedProperties,
MinifiedCommentStripped,
PreprocessedFile,
)
@ -875,8 +875,8 @@ foo2_xpt = GeneratedFile(
)
class TestMinifiedProperties(TestWithTmpDir):
def test_minified_properties(self):
class TestMinifiedCommentStripped(TestWithTmpDir):
def test_minified_comment_stripped(self):
propLines = [
"# Comments are removed",
"foo = bar",
@ -885,10 +885,10 @@ class TestMinifiedProperties(TestWithTmpDir):
]
prop = GeneratedFile("\n".join(propLines))
self.assertEqual(
MinifiedProperties(prop).open().readlines(), [b"foo = bar\n", b"\n"]
MinifiedCommentStripped(prop).open().readlines(), [b"foo = bar\n", b"\n"]
)
open(self.tmppath("prop"), "w").write("\n".join(propLines))
MinifiedProperties(File(self.tmppath("prop"))).copy(self.tmppath("prop2"))
MinifiedCommentStripped(File(self.tmppath("prop"))).copy(self.tmppath("prop2"))
self.assertEqual(open(self.tmppath("prop2")).readlines(), ["foo = bar\n", "\n"])