Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle namespaces on lwc markup #669

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contributing/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <projectname> --defaultpackagedir <directory> -x`
2. An authorised devhub org must exists
2. An authorized devhub org must exists
`sfdx force:auth:web:login -a <alias> -r <localhost url> -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)
Expand Down
4 changes: 2 additions & 2 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 85 additions & 0 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<MetadataApiDeployStatus> = {
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<MetadataApiDeployStatus> = {
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]);
Expand Down