From efc992bbf3df041cf2da6cc20fc2df31039948f5 Mon Sep 17 00:00:00 2001 From: David Glick Date: Thu, 19 Nov 2020 14:26:27 -0500 Subject: [PATCH 1/2] Support deploying lwc subfolders --- cumulusci/salesforce_api/package_zip.py | 11 ++-- .../salesforce_api/tests/test_package_zip.py | 64 +++++-------------- 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/cumulusci/salesforce_api/package_zip.py b/cumulusci/salesforce_api/package_zip.py index 34872ce63b..f5dc940716 100644 --- a/cumulusci/salesforce_api/package_zip.py +++ b/cumulusci/salesforce_api/package_zip.py @@ -156,8 +156,8 @@ def _include_directory(self, root_parts): if len(root_parts) == 0: return True - # include top level only within lwc - if root_parts[0] == "lwc" and len(root_parts) != 2: + # don't include lwc tests + if root_parts[0] == "lwc" and "__tests__" in root_parts: return False # include everything else @@ -165,10 +165,9 @@ def _include_directory(self, root_parts): def _include_file(self, root_parts, f): """Return boolean for whether this file should be included in the package.""" - if len(root_parts) == 2 and root_parts[0] == "lwc": - # is file of lwc component directory - lower_f = f.lower() - return lower_f.endswith((".js", ".js-meta.xml", ".html", ".css", ".svg")) + if len(root_parts) and root_parts[0] == "lwc": + # only include expected file extensions within lwc components + return f.lower().endswith((".js", ".js-meta.xml", ".html", ".css", ".svg")) return True def _process(self): diff --git a/cumulusci/salesforce_api/tests/test_package_zip.py b/cumulusci/salesforce_api/tests/test_package_zip.py index 4d6fb40e1f..13b5c05c6a 100644 --- a/cumulusci/salesforce_api/tests/test_package_zip.py +++ b/cumulusci/salesforce_api/tests/test_package_zip.py @@ -263,31 +263,18 @@ def test_include_directory(self): assert builder._include_directory([]) is True # not include lwc directory - assert builder._include_directory(["lwc"]) is False + assert builder._include_directory(["lwc"]) is True # include any lwc sub-directory (i.e. lwc component directory) assert builder._include_directory(["lwc", "myComponent"]) is True assert builder._include_directory(["lwc", "lwc"]) is True - - # not include any sub-*-directory of a lwc sub-directory - assert builder._include_directory(["lwc", "myComponent", "__tests__"]) is False - assert ( - builder._include_directory(["lwc", "myComponent", "sub-1", "sub-2"]) - is False - ) - assert ( - builder._include_directory( - ["lwc", "myComponent", "sub-1", "sub-2", "sub-3"] - ) - is False - ) assert ( - builder._include_directory( - ["lwc", "myComponent", "sub-1", "sub-2", "sub-3", "sub-4"] - ) - is False + builder._include_directory(["lwc", "myComponent", "sub-1", "sub-2"]) is True ) + # don't include __tests__ within lwc components + assert builder._include_directory(["lwc", "myComponent", "__tests__"]) is False + # include any non-lwc directory assert builder._include_directory(["not-lwc"]) is True assert builder._include_directory(["classes"]) is True @@ -296,23 +283,18 @@ def test_include_directory(self): # include any sub_* directory of a non-lwc directory assert builder._include_directory(["not-lwc", "sub-1"]) is True assert builder._include_directory(["not-lwc", "sub-1", "sub-2"]) is True - assert ( - builder._include_directory(["not-lwc", "sub-1", "sub-2", "sub-3"]) is True - ) - assert ( - builder._include_directory(["not-lwc", "sub-1", "sub-2", "sub-3", "sub-4"]) - is True - ) def test_include_file(self): builder = MetadataPackageZipBuilder() - lwc_component_directory = ["lwc", "myComponent"] - non_lwc_component_directories = [ - [], + lwc_component_directories = [ ["lwc"], + ["lwc", "myComponent"], ["lwc", "myComponent", "sub-1"], ["lwc", "myComponent", "sub-2"], + ] + non_lwc_component_directories = [ + [], ["classes"], ["objects", "sub-1"], ["objects", "sub-1", "sub-2"], @@ -320,31 +302,17 @@ def test_include_file(self): # file endings in lwc component whitelist for file_ending in [".js", ".js-meta.xml", ".html", ".css", ".svg"]: - # lwc_component_directory - assert ( - builder._include_file( - lwc_component_directory, "file_name" + file_ending - ) - is True - ) - - # non_lwc_component_directories + for d in lwc_component_directories: + assert builder._include_file(d, "file_name" + file_ending) for d in non_lwc_component_directories: - assert builder._include_file(d, "file_name" + file_ending) is True + assert builder._include_file(d, "file_name" + file_ending) # file endings not in lwc component whitelist for file_ending in ["", ".json", ".xml", ".cls", ".cls-meta.xml", ".object"]: - # lwc_component_directory - assert ( - builder._include_file( - lwc_component_directory, "file_name" + file_ending - ) - is False - ) - - # non_lwc_component_directories + for d in lwc_component_directories: + assert not builder._include_file(d, "file_name" + file_ending) for d in non_lwc_component_directories: - assert builder._include_file(d, "file_name" + file_ending) is True + assert builder._include_file(d, "file_name" + file_ending) def test_convert_sfdx(self): with temporary_dir() as path: From f9df03c36b6c0c99e0787af131f634cff4a01d4c Mon Sep 17 00:00:00 2001 From: David Glick Date: Fri, 20 Nov 2020 09:54:40 -0500 Subject: [PATCH 2/2] exclude other __ folders from lwc deployments --- cumulusci/salesforce_api/package_zip.py | 2 +- cumulusci/salesforce_api/tests/test_package_zip.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cumulusci/salesforce_api/package_zip.py b/cumulusci/salesforce_api/package_zip.py index f5dc940716..bf12bf1f84 100644 --- a/cumulusci/salesforce_api/package_zip.py +++ b/cumulusci/salesforce_api/package_zip.py @@ -157,7 +157,7 @@ def _include_directory(self, root_parts): return True # don't include lwc tests - if root_parts[0] == "lwc" and "__tests__" in root_parts: + if root_parts[0] == "lwc" and any(part.startswith("__") for part in root_parts): return False # include everything else diff --git a/cumulusci/salesforce_api/tests/test_package_zip.py b/cumulusci/salesforce_api/tests/test_package_zip.py index 13b5c05c6a..ec799774fa 100644 --- a/cumulusci/salesforce_api/tests/test_package_zip.py +++ b/cumulusci/salesforce_api/tests/test_package_zip.py @@ -273,7 +273,8 @@ def test_include_directory(self): ) # don't include __tests__ within lwc components - assert builder._include_directory(["lwc", "myComponent", "__tests__"]) is False + assert not builder._include_directory(["lwc", "myComponent", "__tests__"]) + assert not builder._include_directory(["lwc", "myComponent", "__mocks__"]) # include any non-lwc directory assert builder._include_directory(["not-lwc"]) is True