From 8817545a43f78f7327745e4638c74f6f838fa6ea Mon Sep 17 00:00:00 2001 From: Shane McLaughlin Date: Thu, 21 Jul 2022 12:01:44 -0500 Subject: [PATCH] fix: handle namespaces on lwc markup (#669) * fix: handle namespaces on lwc markup * fix: support capitals in NS * fix: case insensitive version * test: ut for markup/ns/failures --- contributing/metadata.md | 6 +- src/client/metadataApiDeploy.ts | 4 +- test/client/metadataApiDeploy.test.ts | 85 +++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 5 deletions(-) diff --git a/contributing/metadata.md b/contributing/metadata.md index 76214e0dd3..8c7a78bd79 100644 --- a/contributing/metadata.md +++ b/contributing/metadata.md @@ -193,17 +193,17 @@ You can use an existing org for the metadata describe portion of the script by ### Steps to add your metadata in registry -## prerequisites: +## Prerequisites 1. A sfdx project must exists in local. `sfdx force:project:create --projectname --defaultpackagedir -x` - 2. An authorised devhub org must exists + 2. An authorized devhub org must exists `sfdx force:auth:web:login -a -r -d` 3. A scratch org must exists with alias `registryBuilder` 1. Update `project-scratch-def.json` as per your requirements. 2. `sfdx force:org:create -f config/project-scratch-def.json -a registryBuilder -t scratch -s` -## Steps: +## Steps 1. Fork SourceDeployRetrieve github repo (https://github.com/forcedotcom/source-deploy-retrieve) diff --git a/src/client/metadataApiDeploy.ts b/src/client/metadataApiDeploy.ts index 105f352e27..42204c0cbc 100644 --- a/src/client/metadataApiDeploy.ts +++ b/src/client/metadataApiDeploy.ts @@ -231,8 +231,8 @@ export class DeployResult implements MetadataTransferResult { } switch (message.componentType) { case registry.types.lightningcomponentbundle.name: - // remove the markup scheme from fullName - message.fullName = message.fullName.replace(/markup:\/\/c:/, ''); + // remove the markup scheme from fullName, including c: or custom namespaces + message.fullName = message.fullName.replace(/markup:\/\/[a-z|0-9|_]+:/i, ''); break; case registry.types.document.name: // strip document extension from fullName diff --git a/test/client/metadataApiDeploy.test.ts b/test/client/metadataApiDeploy.test.ts index 29d5b842bb..513b4716d0 100644 --- a/test/client/metadataApiDeploy.test.ts +++ b/test/client/metadataApiDeploy.test.ts @@ -322,6 +322,91 @@ describe('MetadataApiDeploy', () => { expect(responses).to.deep.equal(expected); }); + describe('namespaced lwc failures', () => { + const bundlePath = join('path', 'to', 'lwc', 'test'); + const props = { + name: 'test', + type: registry.types.lightningcomponentbundle, + xml: join(bundlePath, 'test.js-meta.xml'), + content: bundlePath, + }; + const component = SourceComponent.createVirtualComponent(props, [ + { + dirPath: bundlePath, + children: [basename(props.xml), 'test.js', 'test.html'], + }, + ]); + const deployedSet = new ComponentSet([component]); + const { fullName, type } = component; + const problem = 'something went wrong'; + const problemType = 'Error'; + const componentSuccesses = { + changed: 'true', + created: 'false', + deleted: 'false', + success: 'true', + fullName, + componentType: type.name, + } as DeployMessage; + + const componentFailures = { + changed: 'false', + created: 'false', + deleted: 'false', + success: 'false', + problem, + problemType, + fileName: join(bundlePath, `${fullName}.html`), + componentType: type.name, + } as DeployMessage; + + it('should handle default namespace failure for "LightningComponentBundle" type', () => { + const apiStatus: Partial = { + details: { + componentSuccesses, + componentFailures: { ...componentFailures, fullName: `markup://c:${fullName}` }, + }, + }; + const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet); + + const responses = result.getFileResponses(); + const expected = [ + { + fullName, + type: type.name, + error: problem, + problemType, + state: ComponentStatus.Failed, + filePath: componentFailures.fileName, + }, + ] as FileResponse[]; + expect(responses).to.deep.equal(expected); + }); + + it('should handle custom namespace failure for "LightningComponentBundle" type', () => { + const apiStatus: Partial = { + details: { + componentSuccesses, + componentFailures: { ...componentFailures, fullName: `markup://my_NS:${fullName}` }, + }, + }; + const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet); + + const responses = result.getFileResponses(); + const expected = [ + { + fullName, + type: type.name, + error: problem, + problemType, + state: ComponentStatus.Failed, + filePath: componentFailures.fileName, + }, + ] as FileResponse[]; + expect(responses).to.deep.equal(expected); + }); + }); + it('should report component as failed if component has success and failure messages', () => { const component = matchingContentFile.COMPONENT; const deployedSet = new ComponentSet([component]);