From 6882821b88da193917983f89beb7dc740904b68a Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 21 Jul 2022 10:03:17 -0500 Subject: [PATCH 1/4] fix: handle namespaces on lwc markup --- contributing/metadata.md | 4 ++-- src/client/metadataApiDeploy.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contributing/metadata.md b/contributing/metadata.md index 76214e0dd3..5add774c47 100644 --- a/contributing/metadata.md +++ b/contributing/metadata.md @@ -193,7 +193,7 @@ 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` @@ -203,7 +203,7 @@ You can use an existing org for the metadata describe portion of the script by 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..a1a5f53bf3 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|_]+:/, ''); break; case registry.types.document.name: // strip document extension from fullName From df6f28dc86d6de2c402855394839fb8f07556098 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 21 Jul 2022 10:18:58 -0500 Subject: [PATCH 2/4] fix: support capitals in NS --- src/client/metadataApiDeploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/metadataApiDeploy.ts b/src/client/metadataApiDeploy.ts index a1a5f53bf3..89f3ea6530 100644 --- a/src/client/metadataApiDeploy.ts +++ b/src/client/metadataApiDeploy.ts @@ -232,7 +232,7 @@ export class DeployResult implements MetadataTransferResult { switch (message.componentType) { case registry.types.lightningcomponentbundle.name: // remove the markup scheme from fullName, including c: or custom namespaces - message.fullName = message.fullName.replace(/markup:\/\/[a-z|0-9|_]+:/, ''); + message.fullName = message.fullName.replace(/markup:\/\/[A-z|a-z|0-9|_]+:/, ''); break; case registry.types.document.name: // strip document extension from fullName From 38f5a74c9b6319f7d027dd339ec25048e12dcd8a Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 21 Jul 2022 10:27:38 -0500 Subject: [PATCH 3/4] fix: case insensitive version --- src/client/metadataApiDeploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/metadataApiDeploy.ts b/src/client/metadataApiDeploy.ts index 89f3ea6530..42204c0cbc 100644 --- a/src/client/metadataApiDeploy.ts +++ b/src/client/metadataApiDeploy.ts @@ -232,7 +232,7 @@ export class DeployResult implements MetadataTransferResult { switch (message.componentType) { case registry.types.lightningcomponentbundle.name: // remove the markup scheme from fullName, including c: or custom namespaces - message.fullName = message.fullName.replace(/markup:\/\/[A-z|a-z|0-9|_]+:/, ''); + message.fullName = message.fullName.replace(/markup:\/\/[a-z|0-9|_]+:/i, ''); break; case registry.types.document.name: // strip document extension from fullName From 90348d5307b3f25805c55307c213d3a2c447d904 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 21 Jul 2022 11:02:57 -0500 Subject: [PATCH 4/4] test: ut for markup/ns/failures --- contributing/metadata.md | 2 +- test/client/metadataApiDeploy.test.ts | 85 +++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/contributing/metadata.md b/contributing/metadata.md index 5add774c47..8c7a78bd79 100644 --- a/contributing/metadata.md +++ b/contributing/metadata.md @@ -197,7 +197,7 @@ You can use an existing org for the metadata describe portion of the script by 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. 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]);