Skip to content

Commit 25899bd

Browse files
fix: W-18991079 - filter out empty dirs when resolving components from path (#1589)
* fix: filter out empty dirs when resolving components from path * chore: fix for windows tests
1 parent dd8ab72 commit 25899bd

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/resolve/metadataResolver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export class MetadataResolver {
8888

8989
if (this.tree.isDirectory(fsPath)) {
9090
if (resolveDirectoryAsComponent(this.registry)(this.tree)(fsPath)) {
91+
// Filter out empty directories to prevent deployment issues
92+
if (this.tree.readDirectory(fsPath).length === 0) {
93+
continue;
94+
}
95+
9196
const component = this.resolveComponent(fsPath, true);
9297
if (component && (!inclusiveFilter || inclusiveFilter.has(component))) {
9398
components.push(component);

test/collections/componentSet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('ComponentSet', () => {
220220

221221
let preAndPostRetrieveEventCount = 0;
222222
lifecycleEmitStub.args.forEach((event) => {
223-
if (event[0] === ('scopedPreRetrieve' || 'scopedPostRetrieve')) {
223+
if (event[0] === 'scopedPreRetrieve' || event[0] === 'scopedPostRetrieve') {
224224
preAndPostRetrieveEventCount = preAndPostRetrieveEventCount + 1;
225225
}
226226
});

test/resolve/metadataResolver.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,5 +979,40 @@ describe('MetadataResolver', () => {
979979
expect(result).to.deep.equal([]);
980980
});
981981
});
982+
983+
it('should filter out empty directories when resolving components', () => {
984+
const resolver = testUtil.createMetadataResolver([
985+
{
986+
dirPath: bundle.TYPE_DIRECTORY,
987+
children: ['myComponent', 'emptyComponent'],
988+
},
989+
{
990+
dirPath: bundle.CONTENT_PATH,
991+
children: [bundle.XML_NAME, ...bundle.COMPONENTS],
992+
},
993+
{
994+
dirPath: join(bundle.TYPE_DIRECTORY, 'emptyComponent'),
995+
children: [], // Empty directory
996+
},
997+
]);
998+
999+
testUtil.stubAdapters([
1000+
{
1001+
type: registry.types.auradefinitionbundle,
1002+
componentMappings: [
1003+
{
1004+
path: bundle.CONTENT_PATH,
1005+
component: bundle.COMPONENT,
1006+
},
1007+
],
1008+
},
1009+
]);
1010+
1011+
const components = resolver.getComponentsFromPath(bundle.TYPE_DIRECTORY);
1012+
1013+
// Should only return the non-empty component
1014+
expect(components).to.have.length(1);
1015+
expect(components[0].name).to.equal('myComponent');
1016+
});
9821017
});
9831018
});

0 commit comments

Comments
 (0)